forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/power/reset/ocelot-reset.c
....@@ -15,16 +15,27 @@
1515 #include <linux/reboot.h>
1616 #include <linux/regmap.h>
1717
18
+struct reset_props {
19
+ const char *syscon;
20
+ u32 protect_reg;
21
+ u32 vcore_protect;
22
+ u32 if_si_owner_bit;
23
+};
24
+
1825 struct ocelot_reset_context {
1926 void __iomem *base;
2027 struct regmap *cpu_ctrl;
28
+ const struct reset_props *props;
2129 struct notifier_block restart_handler;
2230 };
2331
24
-#define ICPU_CFG_CPU_SYSTEM_CTRL_RESET 0x20
25
-#define CORE_RST_PROTECT BIT(2)
26
-
2732 #define SOFT_CHIP_RST BIT(0)
33
+
34
+#define ICPU_CFG_CPU_SYSTEM_CTRL_GENERAL_CTRL 0x24
35
+#define IF_SI_OWNER_MASK GENMASK(1, 0)
36
+#define IF_SI_OWNER_SISL 0
37
+#define IF_SI_OWNER_SIBM 1
38
+#define IF_SI_OWNER_SIMC 2
2839
2940 static int ocelot_restart_handle(struct notifier_block *this,
3041 unsigned long mode, void *cmd)
....@@ -32,10 +43,18 @@
3243 struct ocelot_reset_context *ctx = container_of(this, struct
3344 ocelot_reset_context,
3445 restart_handler);
46
+ u32 if_si_owner_bit = ctx->props->if_si_owner_bit;
3547
3648 /* Make sure the core is not protected from reset */
37
- regmap_update_bits(ctx->cpu_ctrl, ICPU_CFG_CPU_SYSTEM_CTRL_RESET,
38
- CORE_RST_PROTECT, 0);
49
+ regmap_update_bits(ctx->cpu_ctrl, ctx->props->protect_reg,
50
+ ctx->props->vcore_protect, 0);
51
+
52
+ /* Make the SI back to boot mode */
53
+ regmap_update_bits(ctx->cpu_ctrl, ICPU_CFG_CPU_SYSTEM_CTRL_GENERAL_CTRL,
54
+ IF_SI_OWNER_MASK << if_si_owner_bit,
55
+ IF_SI_OWNER_SIBM << if_si_owner_bit);
56
+
57
+ pr_emerg("Resetting SoC\n");
3958
4059 writel(SOFT_CHIP_RST, ctx->base);
4160
....@@ -60,9 +79,13 @@
6079 if (IS_ERR(ctx->base))
6180 return PTR_ERR(ctx->base);
6281
63
- ctx->cpu_ctrl = syscon_regmap_lookup_by_compatible("mscc,ocelot-cpu-syscon");
64
- if (IS_ERR(ctx->cpu_ctrl))
82
+ ctx->props = device_get_match_data(dev);
83
+
84
+ ctx->cpu_ctrl = syscon_regmap_lookup_by_compatible(ctx->props->syscon);
85
+ if (IS_ERR(ctx->cpu_ctrl)) {
86
+ dev_err(dev, "No syscon map: %s\n", ctx->props->syscon);
6587 return PTR_ERR(ctx->cpu_ctrl);
88
+ }
6689
6790 ctx->restart_handler.notifier_call = ocelot_restart_handle;
6891 ctx->restart_handler.priority = 192;
....@@ -73,9 +96,29 @@
7396 return err;
7497 }
7598
99
+static const struct reset_props reset_props_ocelot = {
100
+ .syscon = "mscc,ocelot-cpu-syscon",
101
+ .protect_reg = 0x20,
102
+ .vcore_protect = BIT(2),
103
+ .if_si_owner_bit = 4,
104
+};
105
+
106
+static const struct reset_props reset_props_sparx5 = {
107
+ .syscon = "microchip,sparx5-cpu-syscon",
108
+ .protect_reg = 0x84,
109
+ .vcore_protect = BIT(10),
110
+ .if_si_owner_bit = 6,
111
+};
112
+
76113 static const struct of_device_id ocelot_reset_of_match[] = {
77
- { .compatible = "mscc,ocelot-chip-reset" },
78
- {}
114
+ {
115
+ .compatible = "mscc,ocelot-chip-reset",
116
+ .data = &reset_props_ocelot
117
+ }, {
118
+ .compatible = "microchip,sparx5-chip-reset",
119
+ .data = &reset_props_sparx5
120
+ },
121
+ { /*sentinel*/ }
79122 };
80123
81124 static struct platform_driver ocelot_reset_driver = {