diff options
author | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2018-01-16 05:12:35 -0500 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2018-02-12 05:23:46 -0500 |
commit | 6ab739bc1d00bfd10ed87a2f1fdc00ebdc0d7ff1 (patch) | |
tree | 0b6b1b79f4d25174a19fc3f5768329877bc510c6 | |
parent | 5e195f120138a7ab8245a5e64296c16f8e48527f (diff) |
power: reset: Add a driver for the Microsemi Ocelot reset
The Microsemi Ocelot SoC has a register allowing to reset the MIPS core.
Unfortunately, the syscon-reboot driver can't be used directly (but almost)
as the reset control may be disabled using another register.
Cc: linux-pm@vger.kernel.org
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
-rw-r--r-- | drivers/power/reset/Kconfig | 7 | ||||
-rw-r--r-- | drivers/power/reset/Makefile | 1 | ||||
-rw-r--r-- | drivers/power/reset/ocelot-reset.c | 88 |
3 files changed, 96 insertions, 0 deletions
diff --git a/drivers/power/reset/Kconfig b/drivers/power/reset/Kconfig index a102e74ab24e..176bd6df1238 100644 --- a/drivers/power/reset/Kconfig +++ b/drivers/power/reset/Kconfig | |||
@@ -104,6 +104,13 @@ config POWER_RESET_MSM | |||
104 | help | 104 | help |
105 | Power off and restart support for Qualcomm boards. | 105 | Power off and restart support for Qualcomm boards. |
106 | 106 | ||
107 | config POWER_RESET_OCELOT_RESET | ||
108 | bool "Microsemi Ocelot reset driver" | ||
109 | depends on MSCC_OCELOT || COMPILE_TEST | ||
110 | select MFD_SYSCON | ||
111 | help | ||
112 | This driver supports restart for Microsemi Ocelot SoC. | ||
113 | |||
107 | config POWER_RESET_PIIX4_POWEROFF | 114 | config POWER_RESET_PIIX4_POWEROFF |
108 | tristate "Intel PIIX4 power-off driver" | 115 | tristate "Intel PIIX4 power-off driver" |
109 | depends on PCI | 116 | depends on PCI |
diff --git a/drivers/power/reset/Makefile b/drivers/power/reset/Makefile index dcc92f5f7a37..6b9eb1393179 100644 --- a/drivers/power/reset/Makefile +++ b/drivers/power/reset/Makefile | |||
@@ -11,6 +11,7 @@ obj-$(CONFIG_POWER_RESET_GPIO) += gpio-poweroff.o | |||
11 | obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o | 11 | obj-$(CONFIG_POWER_RESET_GPIO_RESTART) += gpio-restart.o |
12 | obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o | 12 | obj-$(CONFIG_POWER_RESET_HISI) += hisi-reboot.o |
13 | obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o | 13 | obj-$(CONFIG_POWER_RESET_MSM) += msm-poweroff.o |
14 | obj-$(CONFIG_POWER_RESET_OCELOT_RESET) += ocelot-reset.o | ||
14 | obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o | 15 | obj-$(CONFIG_POWER_RESET_PIIX4_POWEROFF) += piix4-poweroff.o |
15 | obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o | 16 | obj-$(CONFIG_POWER_RESET_LTC2952) += ltc2952-poweroff.o |
16 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o | 17 | obj-$(CONFIG_POWER_RESET_QNAP) += qnap-poweroff.o |
diff --git a/drivers/power/reset/ocelot-reset.c b/drivers/power/reset/ocelot-reset.c new file mode 100644 index 000000000000..5a13a5cc8188 --- /dev/null +++ b/drivers/power/reset/ocelot-reset.c | |||
@@ -0,0 +1,88 @@ | |||
1 | // SPDX-License-Identifier: (GPL-2.0 OR MIT) | ||
2 | /* | ||
3 | * Microsemi MIPS SoC reset driver | ||
4 | * | ||
5 | * License: Dual MIT/GPL | ||
6 | * Copyright (c) 2017 Microsemi Corporation | ||
7 | */ | ||
8 | #include <linux/delay.h> | ||
9 | #include <linux/io.h> | ||
10 | #include <linux/notifier.h> | ||
11 | #include <linux/mfd/syscon.h> | ||
12 | #include <linux/of_address.h> | ||
13 | #include <linux/of_device.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/reboot.h> | ||
16 | #include <linux/regmap.h> | ||
17 | |||
18 | struct ocelot_reset_context { | ||
19 | void __iomem *base; | ||
20 | struct regmap *cpu_ctrl; | ||
21 | struct notifier_block restart_handler; | ||
22 | }; | ||
23 | |||
24 | #define ICPU_CFG_CPU_SYSTEM_CTRL_RESET 0x20 | ||
25 | #define CORE_RST_PROTECT BIT(2) | ||
26 | |||
27 | #define SOFT_CHIP_RST BIT(0) | ||
28 | |||
29 | static int ocelot_restart_handle(struct notifier_block *this, | ||
30 | unsigned long mode, void *cmd) | ||
31 | { | ||
32 | struct ocelot_reset_context *ctx = container_of(this, struct | ||
33 | ocelot_reset_context, | ||
34 | restart_handler); | ||
35 | |||
36 | /* 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); | ||
39 | |||
40 | writel(SOFT_CHIP_RST, ctx->base); | ||
41 | |||
42 | pr_emerg("Unable to restart system\n"); | ||
43 | return NOTIFY_DONE; | ||
44 | } | ||
45 | |||
46 | static int ocelot_reset_probe(struct platform_device *pdev) | ||
47 | { | ||
48 | struct ocelot_reset_context *ctx; | ||
49 | struct resource *res; | ||
50 | |||
51 | struct device *dev = &pdev->dev; | ||
52 | int err; | ||
53 | |||
54 | ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL); | ||
55 | if (!ctx) | ||
56 | return -ENOMEM; | ||
57 | |||
58 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
59 | ctx->base = devm_ioremap_resource(dev, res); | ||
60 | if (IS_ERR(ctx->base)) | ||
61 | return PTR_ERR(ctx->base); | ||
62 | |||
63 | ctx->cpu_ctrl = syscon_regmap_lookup_by_compatible("mscc,ocelot-cpu-syscon"); | ||
64 | if (IS_ERR(ctx->cpu_ctrl)) | ||
65 | return PTR_ERR(ctx->cpu_ctrl); | ||
66 | |||
67 | ctx->restart_handler.notifier_call = ocelot_restart_handle; | ||
68 | ctx->restart_handler.priority = 192; | ||
69 | err = register_restart_handler(&ctx->restart_handler); | ||
70 | if (err) | ||
71 | dev_err(dev, "can't register restart notifier (err=%d)\n", err); | ||
72 | |||
73 | return err; | ||
74 | } | ||
75 | |||
76 | static const struct of_device_id ocelot_reset_of_match[] = { | ||
77 | { .compatible = "mscc,ocelot-chip-reset" }, | ||
78 | {} | ||
79 | }; | ||
80 | |||
81 | static struct platform_driver ocelot_reset_driver = { | ||
82 | .probe = ocelot_reset_probe, | ||
83 | .driver = { | ||
84 | .name = "ocelot-chip-reset", | ||
85 | .of_match_table = ocelot_reset_of_match, | ||
86 | }, | ||
87 | }; | ||
88 | builtin_platform_driver(ocelot_reset_driver); | ||