diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2013-06-18 13:44:48 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2013-07-11 16:17:30 -0400 |
commit | 938d0a840d0f97b627111fd038a735f3924fd987 (patch) | |
tree | 8a543e6f5c8d4983ceffc7e6e3adb7ee5abda48f /drivers/watchdog | |
parent | 6e63a3a294fdf91eaaac1061a9c7a5f53d16ac25 (diff) |
watchdog: Add Broadcom BCM2835 watchdog timer driver
This adds a driver for watchdog timer hardware present on Broadcom BCM2835 SoC,
used in Raspberry Pi and Roku 2 devices.
Signed-off-by: Lubomir Rintel <lkundrak@v3.sk>
Tested-by: Stephen Warren <swarren@wwwdotorg.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Cc: linux-rpi-kernel@lists.infradead.org
Cc: linux-watchdog@vger.kernel.org
Cc: devicetree-discuss@lists.ozlabs.org
Diffstat (limited to 'drivers/watchdog')
-rw-r--r-- | drivers/watchdog/Kconfig | 11 | ||||
-rw-r--r-- | drivers/watchdog/Makefile | 1 | ||||
-rw-r--r-- | drivers/watchdog/bcm2835_wdt.c | 189 |
3 files changed, 201 insertions, 0 deletions
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 6042e9ed542c..f17ffdb75bb0 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig | |||
@@ -1100,6 +1100,17 @@ config BCM63XX_WDT | |||
1100 | To compile this driver as a loadable module, choose M here. | 1100 | To compile this driver as a loadable module, choose M here. |
1101 | The module will be called bcm63xx_wdt. | 1101 | The module will be called bcm63xx_wdt. |
1102 | 1102 | ||
1103 | config BCM2835_WDT | ||
1104 | tristate "Broadcom BCM2835 hardware watchdog" | ||
1105 | depends on ARCH_BCM2835 | ||
1106 | select WATCHDOG_CORE | ||
1107 | help | ||
1108 | Watchdog driver for the built in watchdog hardware in Broadcom | ||
1109 | BCM2835 SoC. | ||
1110 | |||
1111 | To compile this driver as a loadable module, choose M here. | ||
1112 | The module will be called bcm2835_wdt. | ||
1113 | |||
1103 | config LANTIQ_WDT | 1114 | config LANTIQ_WDT |
1104 | tristate "Lantiq SoC watchdog" | 1115 | tristate "Lantiq SoC watchdog" |
1105 | depends on LANTIQ | 1116 | depends on LANTIQ |
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 291828b356c5..c443f6247fa6 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile | |||
@@ -53,6 +53,7 @@ obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o | |||
53 | obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o | 53 | obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o |
54 | obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o | 54 | obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o |
55 | obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o | 55 | obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o |
56 | obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o | ||
56 | 57 | ||
57 | # AVR32 Architecture | 58 | # AVR32 Architecture |
58 | obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o | 59 | obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o |
diff --git a/drivers/watchdog/bcm2835_wdt.c b/drivers/watchdog/bcm2835_wdt.c new file mode 100644 index 000000000000..61566fc47f84 --- /dev/null +++ b/drivers/watchdog/bcm2835_wdt.c | |||
@@ -0,0 +1,189 @@ | |||
1 | /* | ||
2 | * Watchdog driver for Broadcom BCM2835 | ||
3 | * | ||
4 | * "bcm2708_wdog" driver written by Luke Diamand that was obtained from | ||
5 | * branch "rpi-3.6.y" of git://github.com/raspberrypi/linux.git was used | ||
6 | * as a hardware reference for the Broadcom BCM2835 watchdog timer. | ||
7 | * | ||
8 | * Copyright (C) 2013 Lubomir Rintel <lkundrak@v3.sk> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify it | ||
11 | * under the terms of the GNU General Public License as published by the | ||
12 | * Free Software Foundation; either version 2 of the License, or (at your | ||
13 | * option) any later version. | ||
14 | */ | ||
15 | |||
16 | #include <linux/types.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/io.h> | ||
19 | #include <linux/watchdog.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/of_address.h> | ||
22 | #include <linux/miscdevice.h> | ||
23 | |||
24 | #define PM_RSTC 0x1c | ||
25 | #define PM_WDOG 0x24 | ||
26 | |||
27 | #define PM_PASSWORD 0x5a000000 | ||
28 | |||
29 | #define PM_WDOG_TIME_SET 0x000fffff | ||
30 | #define PM_RSTC_WRCFG_CLR 0xffffffcf | ||
31 | #define PM_RSTC_WRCFG_SET 0x00000030 | ||
32 | #define PM_RSTC_WRCFG_FULL_RESET 0x00000020 | ||
33 | #define PM_RSTC_RESET 0x00000102 | ||
34 | |||
35 | #define SECS_TO_WDOG_TICKS(x) ((x) << 16) | ||
36 | #define WDOG_TICKS_TO_SECS(x) ((x) >> 16) | ||
37 | |||
38 | struct bcm2835_wdt { | ||
39 | void __iomem *base; | ||
40 | spinlock_t lock; | ||
41 | }; | ||
42 | |||
43 | static unsigned int heartbeat; | ||
44 | static bool nowayout = WATCHDOG_NOWAYOUT; | ||
45 | |||
46 | static int bcm2835_wdt_start(struct watchdog_device *wdog) | ||
47 | { | ||
48 | struct bcm2835_wdt *wdt = watchdog_get_drvdata(wdog); | ||
49 | uint32_t cur; | ||
50 | unsigned long flags; | ||
51 | |||
52 | spin_lock_irqsave(&wdt->lock, flags); | ||
53 | |||
54 | writel_relaxed(PM_PASSWORD | (SECS_TO_WDOG_TICKS(wdog->timeout) & | ||
55 | PM_WDOG_TIME_SET), wdt->base + PM_WDOG); | ||
56 | cur = readl_relaxed(wdt->base + PM_RSTC); | ||
57 | writel_relaxed(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) | | ||
58 | PM_RSTC_WRCFG_FULL_RESET, wdt->base + PM_RSTC); | ||
59 | |||
60 | spin_unlock_irqrestore(&wdt->lock, flags); | ||
61 | |||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | static int bcm2835_wdt_stop(struct watchdog_device *wdog) | ||
66 | { | ||
67 | struct bcm2835_wdt *wdt = watchdog_get_drvdata(wdog); | ||
68 | |||
69 | writel_relaxed(PM_PASSWORD | PM_RSTC_RESET, wdt->base + PM_RSTC); | ||
70 | dev_info(wdog->dev, "Watchdog timer stopped"); | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static int bcm2835_wdt_set_timeout(struct watchdog_device *wdog, unsigned int t) | ||
75 | { | ||
76 | wdog->timeout = t; | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | static unsigned int bcm2835_wdt_get_timeleft(struct watchdog_device *wdog) | ||
81 | { | ||
82 | struct bcm2835_wdt *wdt = watchdog_get_drvdata(wdog); | ||
83 | |||
84 | uint32_t ret = readl_relaxed(wdt->base + PM_WDOG); | ||
85 | return WDOG_TICKS_TO_SECS(ret & PM_WDOG_TIME_SET); | ||
86 | } | ||
87 | |||
88 | static struct watchdog_ops bcm2835_wdt_ops = { | ||
89 | .owner = THIS_MODULE, | ||
90 | .start = bcm2835_wdt_start, | ||
91 | .stop = bcm2835_wdt_stop, | ||
92 | .set_timeout = bcm2835_wdt_set_timeout, | ||
93 | .get_timeleft = bcm2835_wdt_get_timeleft, | ||
94 | }; | ||
95 | |||
96 | static struct watchdog_info bcm2835_wdt_info = { | ||
97 | .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | | ||
98 | WDIOF_KEEPALIVEPING, | ||
99 | .identity = "Broadcom BCM2835 Watchdog timer", | ||
100 | }; | ||
101 | |||
102 | static struct watchdog_device bcm2835_wdt_wdd = { | ||
103 | .info = &bcm2835_wdt_info, | ||
104 | .ops = &bcm2835_wdt_ops, | ||
105 | .min_timeout = 1, | ||
106 | .max_timeout = WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET), | ||
107 | .timeout = WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET), | ||
108 | }; | ||
109 | |||
110 | static int bcm2835_wdt_probe(struct platform_device *pdev) | ||
111 | { | ||
112 | struct device *dev = &pdev->dev; | ||
113 | struct device_node *np = dev->of_node; | ||
114 | struct bcm2835_wdt *wdt; | ||
115 | int err; | ||
116 | |||
117 | wdt = devm_kzalloc(dev, sizeof(struct bcm2835_wdt), GFP_KERNEL); | ||
118 | if (!wdt) { | ||
119 | dev_err(dev, "Failed to allocate memory for watchdog device"); | ||
120 | return -ENOMEM; | ||
121 | } | ||
122 | platform_set_drvdata(pdev, wdt); | ||
123 | |||
124 | spin_lock_init(&wdt->lock); | ||
125 | |||
126 | wdt->base = of_iomap(np, 0); | ||
127 | if (!wdt->base) { | ||
128 | dev_err(dev, "Failed to remap watchdog regs"); | ||
129 | return -ENODEV; | ||
130 | } | ||
131 | |||
132 | watchdog_set_drvdata(&bcm2835_wdt_wdd, wdt); | ||
133 | watchdog_init_timeout(&bcm2835_wdt_wdd, heartbeat, dev); | ||
134 | watchdog_set_nowayout(&bcm2835_wdt_wdd, nowayout); | ||
135 | err = watchdog_register_device(&bcm2835_wdt_wdd); | ||
136 | if (err) { | ||
137 | dev_err(dev, "Failed to register watchdog device"); | ||
138 | iounmap(wdt->base); | ||
139 | return err; | ||
140 | } | ||
141 | |||
142 | dev_info(dev, "Broadcom BCM2835 watchdog timer"); | ||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | static int bcm2835_wdt_remove(struct platform_device *pdev) | ||
147 | { | ||
148 | struct bcm2835_wdt *wdt = platform_get_drvdata(pdev); | ||
149 | |||
150 | watchdog_unregister_device(&bcm2835_wdt_wdd); | ||
151 | iounmap(wdt->base); | ||
152 | |||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | static void bcm2835_wdt_shutdown(struct platform_device *pdev) | ||
157 | { | ||
158 | bcm2835_wdt_stop(&bcm2835_wdt_wdd); | ||
159 | } | ||
160 | |||
161 | static const struct of_device_id bcm2835_wdt_of_match[] = { | ||
162 | { .compatible = "brcm,bcm2835-pm-wdt", }, | ||
163 | {}, | ||
164 | }; | ||
165 | MODULE_DEVICE_TABLE(of, bcm2835_wdt_of_match); | ||
166 | |||
167 | static struct platform_driver bcm2835_wdt_driver = { | ||
168 | .probe = bcm2835_wdt_probe, | ||
169 | .remove = bcm2835_wdt_remove, | ||
170 | .shutdown = bcm2835_wdt_shutdown, | ||
171 | .driver = { | ||
172 | .name = "bcm2835-wdt", | ||
173 | .owner = THIS_MODULE, | ||
174 | .of_match_table = bcm2835_wdt_of_match, | ||
175 | }, | ||
176 | }; | ||
177 | module_platform_driver(bcm2835_wdt_driver); | ||
178 | |||
179 | module_param(heartbeat, uint, 0); | ||
180 | MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds"); | ||
181 | |||
182 | module_param(nowayout, bool, 0); | ||
183 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" | ||
184 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | ||
185 | |||
186 | MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>"); | ||
187 | MODULE_DESCRIPTION("Driver for Broadcom BCM2835 watchdog timer"); | ||
188 | MODULE_LICENSE("GPL"); | ||
189 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | ||