hc
2024-05-10 61598093bbdd283a7edc367d900f223070ead8d2
kernel/drivers/power/reset/syscon-reboot.c
....@@ -1,18 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Generic Syscon Reboot Driver
34 *
45 * Copyright (c) 2013, Applied Micro Circuits Corporation
56 * Author: Feng Kan <fkan@apm.com>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License as
9
- * published by the Free Software Foundation; either version 2 of
10
- * the License, or (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
167 */
178 #include <linux/delay.h>
189 #include <linux/io.h>
....@@ -27,6 +18,7 @@
2718 struct syscon_reboot_context {
2819 struct regmap *map;
2920 u32 offset;
21
+ u32 value;
3022 u32 mask;
3123 struct notifier_block restart_handler;
3224 };
....@@ -39,7 +31,7 @@
3931 restart_handler);
4032
4133 /* Issue the reboot */
42
- regmap_write(ctx->map, ctx->offset, ctx->mask);
34
+ regmap_update_bits(ctx->map, ctx->offset, ctx->mask, ctx->value);
4335
4436 mdelay(1000);
4537
....@@ -51,6 +43,7 @@
5143 {
5244 struct syscon_reboot_context *ctx;
5345 struct device *dev = &pdev->dev;
46
+ int mask_err, value_err;
5447 int err;
5548
5649 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
....@@ -58,14 +51,30 @@
5851 return -ENOMEM;
5952
6053 ctx->map = syscon_regmap_lookup_by_phandle(dev->of_node, "regmap");
61
- if (IS_ERR(ctx->map))
62
- return PTR_ERR(ctx->map);
54
+ if (IS_ERR(ctx->map)) {
55
+ ctx->map = syscon_node_to_regmap(dev->parent->of_node);
56
+ if (IS_ERR(ctx->map))
57
+ return PTR_ERR(ctx->map);
58
+ }
6359
6460 if (of_property_read_u32(pdev->dev.of_node, "offset", &ctx->offset))
6561 return -EINVAL;
6662
67
- if (of_property_read_u32(pdev->dev.of_node, "mask", &ctx->mask))
63
+ value_err = of_property_read_u32(pdev->dev.of_node, "value", &ctx->value);
64
+ mask_err = of_property_read_u32(pdev->dev.of_node, "mask", &ctx->mask);
65
+ if (value_err && mask_err) {
66
+ dev_err(dev, "unable to read 'value' and 'mask'");
6867 return -EINVAL;
68
+ }
69
+
70
+ if (value_err) {
71
+ /* support old binding */
72
+ ctx->value = ctx->mask;
73
+ ctx->mask = 0xFFFFFFFF;
74
+ } else if (mask_err) {
75
+ /* support value without mask*/
76
+ ctx->mask = 0xFFFFFFFF;
77
+ }
6978
7079 ctx->restart_handler.notifier_call = syscon_restart_handle;
7180 ctx->restart_handler.priority = 192;