1 From 90964ab2d00546a59086ffd08964da3d2a5cefc9 Mon Sep 17 00:00:00 2001
2 From: Eric Anholt <eric@anholt.net>
3 Date: Wed, 12 Dec 2018 15:51:47 -0800
4 Subject: [PATCH] bcm2835-pm: Move bcm2835-watchdog's DT probe to an
7 The PM block that the wdt driver was binding to actually has multiple
8 features we want to expose (power domains, reset, watchdog). Move the
9 DT attachment to a MFD driver and make WDT probe against MFD.
11 Signed-off-by: Eric Anholt <eric@anholt.net>
12 Reviewed-by: Guenter Roeck <linux@roeck-us.net>
13 Acked-by: Stefan Wahren <stefan.wahren@i2se.com>
14 Signed-off-by: Stefan Wahren <stefan.wahren@i2se.com>
15 (cherry picked from commit 5e6acc3e678ed3db746ab4fb53a980861cd711b6)
17 drivers/mfd/Makefile | 1 +
18 drivers/mfd/bcm2835-pm.c | 64 ++++++++++++++++++++++++++++++++++
19 drivers/watchdog/bcm2835_wdt.c | 26 +++++---------
20 include/linux/mfd/bcm2835-pm.h | 13 +++++++
21 4 files changed, 87 insertions(+), 17 deletions(-)
22 create mode 100644 drivers/mfd/bcm2835-pm.c
23 create mode 100644 include/linux/mfd/bcm2835-pm.h
25 --- a/drivers/mfd/Makefile
26 +++ b/drivers/mfd/Makefile
27 @@ -10,6 +10,7 @@ obj-$(CONFIG_MFD_88PM805) += 88pm805.o 8
28 obj-$(CONFIG_MFD_ACT8945A) += act8945a.o
29 obj-$(CONFIG_MFD_SM501) += sm501.o
30 obj-$(CONFIG_MFD_ASIC3) += asic3.o tmio_core.o
31 +obj-$(CONFIG_ARCH_BCM2835) += bcm2835-pm.o
32 obj-$(CONFIG_MFD_BCM590XX) += bcm590xx.o
33 obj-$(CONFIG_MFD_BD9571MWV) += bd9571mwv.o
34 cros_ec_core-objs := cros_ec.o
36 +++ b/drivers/mfd/bcm2835-pm.c
38 +// SPDX-License-Identifier: GPL-2.0+
40 + * PM MFD driver for Broadcom BCM2835
42 + * This driver binds to the PM block and creates the MFD device for
46 +#include <linux/delay.h>
47 +#include <linux/io.h>
48 +#include <linux/mfd/bcm2835-pm.h>
49 +#include <linux/mfd/core.h>
50 +#include <linux/module.h>
51 +#include <linux/of_address.h>
52 +#include <linux/of_platform.h>
53 +#include <linux/platform_device.h>
54 +#include <linux/types.h>
55 +#include <linux/watchdog.h>
57 +static const struct mfd_cell bcm2835_pm_devs[] = {
58 + { .name = "bcm2835-wdt" },
61 +static int bcm2835_pm_probe(struct platform_device *pdev)
63 + struct resource *res;
64 + struct device *dev = &pdev->dev;
65 + struct bcm2835_pm *pm;
67 + pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
70 + platform_set_drvdata(pdev, pm);
74 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
75 + pm->base = devm_ioremap_resource(dev, res);
76 + if (IS_ERR(pm->base))
77 + return PTR_ERR(pm->base);
79 + return devm_mfd_add_devices(dev, -1,
80 + bcm2835_pm_devs, ARRAY_SIZE(bcm2835_pm_devs),
84 +static const struct of_device_id bcm2835_pm_of_match[] = {
85 + { .compatible = "brcm,bcm2835-pm-wdt", },
88 +MODULE_DEVICE_TABLE(of, bcm2835_pm_of_match);
90 +static struct platform_driver bcm2835_pm_driver = {
91 + .probe = bcm2835_pm_probe,
93 + .name = "bcm2835-pm",
94 + .of_match_table = bcm2835_pm_of_match,
97 +module_platform_driver(bcm2835_pm_driver);
99 +MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
100 +MODULE_DESCRIPTION("Driver for Broadcom BCM2835 PM MFD");
101 +MODULE_LICENSE("GPL");
102 --- a/drivers/watchdog/bcm2835_wdt.c
103 +++ b/drivers/watchdog/bcm2835_wdt.c
106 #include <linux/delay.h>
107 #include <linux/types.h>
108 +#include <linux/mfd/bcm2835-pm.h>
109 #include <linux/module.h>
110 #include <linux/io.h>
111 #include <linux/watchdog.h>
112 @@ -41,6 +42,8 @@ struct bcm2835_wdt {
116 +static struct bcm2835_wdt *bcm2835_power_off_wdt;
118 static unsigned int heartbeat;
119 static bool nowayout = WATCHDOG_NOWAYOUT;
121 @@ -163,10 +166,7 @@ static struct watchdog_device bcm2835_wd
123 static void bcm2835_power_off(void)
125 - struct device_node *np =
126 - of_find_compatible_node(NULL, NULL, "brcm,bcm2835-pm-wdt");
127 - struct platform_device *pdev = of_find_device_by_node(np);
128 - struct bcm2835_wdt *wdt = platform_get_drvdata(pdev);
129 + struct bcm2835_wdt *wdt = bcm2835_power_off_wdt;
131 /* Partition 63 tells the firmware that this is a halt */
132 __bcm2835_restart(wdt, 63);
133 @@ -174,7 +174,7 @@ static void bcm2835_power_off(void)
135 static int bcm2835_wdt_probe(struct platform_device *pdev)
137 - struct resource *res;
138 + struct bcm2835_pm *pm = dev_get_drvdata(pdev->dev.parent);
139 struct device *dev = &pdev->dev;
140 struct bcm2835_wdt *wdt;
142 @@ -186,10 +186,7 @@ static int bcm2835_wdt_probe(struct plat
144 spin_lock_init(&wdt->lock);
146 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
147 - wdt->base = devm_ioremap_resource(dev, res);
148 - if (IS_ERR(wdt->base))
149 - return PTR_ERR(wdt->base);
150 + wdt->base = pm->base;
152 watchdog_set_drvdata(&bcm2835_wdt_wdd, wdt);
153 watchdog_init_timeout(&bcm2835_wdt_wdd, heartbeat, dev);
154 @@ -216,8 +213,10 @@ static int bcm2835_wdt_probe(struct plat
158 - if (pm_power_off == NULL)
159 + if (pm_power_off == NULL) {
160 pm_power_off = bcm2835_power_off;
161 + bcm2835_power_off_wdt = wdt;
164 dev_info(dev, "Broadcom BCM2835 watchdog timer");
166 @@ -231,18 +230,11 @@ static int bcm2835_wdt_remove(struct pla
170 -static const struct of_device_id bcm2835_wdt_of_match[] = {
171 - { .compatible = "brcm,bcm2835-pm-wdt", },
174 -MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match);
176 static struct platform_driver bcm2835_wdt_driver = {
177 .probe = bcm2835_wdt_probe,
178 .remove = bcm2835_wdt_remove,
180 .name = "bcm2835-wdt",
181 - .of_match_table = bcm2835_wdt_of_match,
184 module_platform_driver(bcm2835_wdt_driver);
186 +++ b/include/linux/mfd/bcm2835-pm.h
188 +/* SPDX-License-Identifier: GPL-2.0+ */
190 +#ifndef BCM2835_MFD_PM_H
191 +#define BCM2835_MFD_PM_H
193 +#include <linux/regmap.h>
196 + struct device *dev;
197 + void __iomem *base;
200 +#endif /* BCM2835_MFD_PM_H */