1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
3 * Microsemi MIPS SoC reset driver
5 * License: Dual MIT/GPL
6 * Copyright (c) 2017 Microsemi Corporation
8 #include <linux/delay.h>
10 #include <linux/notifier.h>
11 #include <linux/mod_devicetable.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/platform_device.h>
14 #include <linux/property.h>
15 #include <linux/reboot.h>
16 #include <linux/regmap.h>
25 struct ocelot_reset_context
{
27 struct regmap
*cpu_ctrl
;
28 const struct reset_props
*props
;
29 struct notifier_block restart_handler
;
32 #define BIT_OFF_INVALID 32
34 #define SOFT_CHIP_RST BIT(0)
36 #define ICPU_CFG_CPU_SYSTEM_CTRL_GENERAL_CTRL 0x24
37 #define IF_SI_OWNER_MASK GENMASK(1, 0)
38 #define IF_SI_OWNER_SISL 0
39 #define IF_SI_OWNER_SIBM 1
40 #define IF_SI_OWNER_SIMC 2
42 static int ocelot_restart_handle(struct notifier_block
*this,
43 unsigned long mode
, void *cmd
)
45 struct ocelot_reset_context
*ctx
= container_of(this, struct
48 u32 if_si_owner_bit
= ctx
->props
->if_si_owner_bit
;
50 /* Make sure the core is not protected from reset */
51 regmap_update_bits(ctx
->cpu_ctrl
, ctx
->props
->protect_reg
,
52 ctx
->props
->vcore_protect
, 0);
54 /* Make the SI back to boot mode */
55 if (if_si_owner_bit
!= BIT_OFF_INVALID
)
56 regmap_update_bits(ctx
->cpu_ctrl
,
57 ICPU_CFG_CPU_SYSTEM_CTRL_GENERAL_CTRL
,
58 IF_SI_OWNER_MASK
<< if_si_owner_bit
,
59 IF_SI_OWNER_SIBM
<< if_si_owner_bit
);
61 pr_emerg("Resetting SoC\n");
63 writel(SOFT_CHIP_RST
, ctx
->base
);
65 pr_emerg("Unable to restart system\n");
69 static int ocelot_reset_probe(struct platform_device
*pdev
)
71 struct ocelot_reset_context
*ctx
;
72 struct device
*dev
= &pdev
->dev
;
75 ctx
= devm_kzalloc(&pdev
->dev
, sizeof(*ctx
), GFP_KERNEL
);
79 ctx
->base
= devm_platform_ioremap_resource(pdev
, 0);
80 if (IS_ERR(ctx
->base
))
81 return PTR_ERR(ctx
->base
);
83 ctx
->props
= device_get_match_data(dev
);
85 ctx
->cpu_ctrl
= syscon_regmap_lookup_by_compatible(ctx
->props
->syscon
);
86 if (IS_ERR(ctx
->cpu_ctrl
)) {
87 dev_err(dev
, "No syscon map: %s\n", ctx
->props
->syscon
);
88 return PTR_ERR(ctx
->cpu_ctrl
);
91 ctx
->restart_handler
.notifier_call
= ocelot_restart_handle
;
92 ctx
->restart_handler
.priority
= 192;
93 err
= register_restart_handler(&ctx
->restart_handler
);
95 dev_err(dev
, "can't register restart notifier (err=%d)\n", err
);
100 static const struct reset_props reset_props_jaguar2
= {
101 .syscon
= "mscc,ocelot-cpu-syscon",
103 .vcore_protect
= BIT(2),
104 .if_si_owner_bit
= 6,
107 static const struct reset_props reset_props_luton
= {
108 .syscon
= "mscc,ocelot-cpu-syscon",
110 .vcore_protect
= BIT(2),
111 .if_si_owner_bit
= BIT_OFF_INVALID
, /* n/a */
114 static const struct reset_props reset_props_ocelot
= {
115 .syscon
= "mscc,ocelot-cpu-syscon",
117 .vcore_protect
= BIT(2),
118 .if_si_owner_bit
= 4,
121 static const struct reset_props reset_props_sparx5
= {
122 .syscon
= "microchip,sparx5-cpu-syscon",
124 .vcore_protect
= BIT(10),
125 .if_si_owner_bit
= 6,
128 static const struct of_device_id ocelot_reset_of_match
[] = {
130 .compatible
= "mscc,jaguar2-chip-reset",
131 .data
= &reset_props_jaguar2
133 .compatible
= "mscc,luton-chip-reset",
134 .data
= &reset_props_luton
136 .compatible
= "mscc,ocelot-chip-reset",
137 .data
= &reset_props_ocelot
139 .compatible
= "microchip,sparx5-chip-reset",
140 .data
= &reset_props_sparx5
145 static struct platform_driver ocelot_reset_driver
= {
146 .probe
= ocelot_reset_probe
,
148 .name
= "ocelot-chip-reset",
149 .of_match_table
= ocelot_reset_of_match
,
152 builtin_platform_driver(ocelot_reset_driver
);