14d455be105c77c4daa6e96134f876217eabeb9c
[openwrt/staging/mans0n.git] /
1 From a2628fc52798fe36a9505f0814da25562c2604af 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 553/782] bcm2835-pm: Move bcm2835-watchdog's DT probe to an
5 MFD.
6
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.
10
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)
16 ---
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
24
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
35 --- /dev/null
36 +++ b/drivers/mfd/bcm2835-pm.c
37 @@ -0,0 +1,64 @@
38 +// SPDX-License-Identifier: GPL-2.0+
39 +/*
40 + * PM MFD driver for Broadcom BCM2835
41 + *
42 + * This driver binds to the PM block and creates the MFD device for
43 + * the WDT driver.
44 + */
45 +
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>
56 +
57 +static const struct mfd_cell bcm2835_pm_devs[] = {
58 + { .name = "bcm2835-wdt" },
59 +};
60 +
61 +static int bcm2835_pm_probe(struct platform_device *pdev)
62 +{
63 + struct resource *res;
64 + struct device *dev = &pdev->dev;
65 + struct bcm2835_pm *pm;
66 +
67 + pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
68 + if (!pm)
69 + return -ENOMEM;
70 + platform_set_drvdata(pdev, pm);
71 +
72 + pm->dev = dev;
73 +
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);
78 +
79 + return devm_mfd_add_devices(dev, -1,
80 + bcm2835_pm_devs, ARRAY_SIZE(bcm2835_pm_devs),
81 + NULL, 0, NULL);
82 +}
83 +
84 +static const struct of_device_id bcm2835_pm_of_match[] = {
85 + { .compatible = "brcm,bcm2835-pm-wdt", },
86 + {},
87 +};
88 +MODULE_DEVICE_TABLE(of, bcm2835_pm_of_match);
89 +
90 +static struct platform_driver bcm2835_pm_driver = {
91 + .probe = bcm2835_pm_probe,
92 + .driver = {
93 + .name = "bcm2835-pm",
94 + .of_match_table = bcm2835_pm_of_match,
95 + },
96 +};
97 +module_platform_driver(bcm2835_pm_driver);
98 +
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
104 @@ -12,6 +12,7 @@
105
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 {
113 spinlock_t lock;
114 };
115
116 +static struct bcm2835_wdt *bcm2835_power_off_wdt;
117 +
118 static unsigned int heartbeat;
119 static bool nowayout = WATCHDOG_NOWAYOUT;
120
121 @@ -163,10 +166,7 @@ static struct watchdog_device bcm2835_wd
122 */
123 static void bcm2835_power_off(void)
124 {
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;
130
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)
134
135 static int bcm2835_wdt_probe(struct platform_device *pdev)
136 {
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;
141 int err;
142 @@ -186,10 +186,7 @@ static int bcm2835_wdt_probe(struct plat
143
144 spin_lock_init(&wdt->lock);
145
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;
151
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
155 return err;
156 }
157
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;
162 + }
163
164 dev_info(dev, "Broadcom BCM2835 watchdog timer");
165 return 0;
166 @@ -231,18 +230,11 @@ static int bcm2835_wdt_remove(struct pla
167 return 0;
168 }
169
170 -static const struct of_device_id bcm2835_wdt_of_match[] = {
171 - { .compatible = "brcm,bcm2835-pm-wdt", },
172 - {},
173 -};
174 -MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match);
175 -
176 static struct platform_driver bcm2835_wdt_driver = {
177 .probe = bcm2835_wdt_probe,
178 .remove = bcm2835_wdt_remove,
179 .driver = {
180 .name = "bcm2835-wdt",
181 - .of_match_table = bcm2835_wdt_of_match,
182 },
183 };
184 module_platform_driver(bcm2835_wdt_driver);
185 --- /dev/null
186 +++ b/include/linux/mfd/bcm2835-pm.h
187 @@ -0,0 +1,13 @@
188 +/* SPDX-License-Identifier: GPL-2.0+ */
189 +
190 +#ifndef BCM2835_MFD_PM_H
191 +#define BCM2835_MFD_PM_H
192 +
193 +#include <linux/regmap.h>
194 +
195 +struct bcm2835_pm {
196 + struct device *dev;
197 + void __iomem *base;
198 +};
199 +
200 +#endif /* BCM2835_MFD_PM_H */