hostapd: remove old button hotplug script
[openwrt.git] / target / linux / ar71xx / patches-3.8 / 041-watchdog-ath79_wdt-get-register-base-from-platform-d.patch
1 From 9c0785757dacd1aaf9e6e58b4f559e345093f1d4 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Thu, 27 Dec 2012 15:38:26 +0100
4 Subject: [PATCH] watchdog: ath79_wdt: get register base from platform
5  device's resources
6
7 commit 09f5100a592d11dad06b218f41d560ff1f87f666 upstream.
8
9 The ath79_wdt driver uses a fixed memory address
10 currently. Although this is working with each
11 currently supported SoCs, but this may change
12 in the future. Additionally, the driver includes
13 platform specific header files in order to be
14 able to get the memory base of the watchdog
15 device.
16
17 The patch adds a memory resource to the platform
18 device, and converts the driver to get the base
19 address of the watchdog device from that.
20
21 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
22 Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
23 ---
24  arch/mips/ath79/dev-common.c |   10 ++++++++-
25  drivers/watchdog/ath79_wdt.c |   48 +++++++++++++++++++++++++++++++++---------
26  2 files changed, 47 insertions(+), 11 deletions(-)
27
28 --- a/arch/mips/ath79/dev-common.c
29 +++ b/arch/mips/ath79/dev-common.c
30 @@ -104,5 +104,13 @@ void __init ath79_register_uart(void)
31  
32  void __init ath79_register_wdt(void)
33  {
34 -       platform_device_register_simple("ath79-wdt", -1, NULL, 0);
35 +       struct resource res;
36 +
37 +       memset(&res, 0, sizeof(res));
38 +
39 +       res.flags = IORESOURCE_MEM;
40 +       res.start = AR71XX_RESET_BASE + AR71XX_RESET_REG_WDOG_CTRL;
41 +       res.end = res.start + 0x8 - 1;
42 +
43 +       platform_device_register_simple("ath79-wdt", -1, &res, 1);
44  }
45 --- a/drivers/watchdog/ath79_wdt.c
46 +++ b/drivers/watchdog/ath79_wdt.c
47 @@ -23,6 +23,7 @@
48  #include <linux/errno.h>
49  #include <linux/fs.h>
50  #include <linux/init.h>
51 +#include <linux/io.h>
52  #include <linux/kernel.h>
53  #include <linux/miscdevice.h>
54  #include <linux/module.h>
55 @@ -33,13 +34,13 @@
56  #include <linux/clk.h>
57  #include <linux/err.h>
58  
59 -#include <asm/mach-ath79/ath79.h>
60 -#include <asm/mach-ath79/ar71xx_regs.h>
61 -
62  #define DRIVER_NAME    "ath79-wdt"
63  
64  #define WDT_TIMEOUT    15      /* seconds */
65  
66 +#define WDOG_REG_CTRL          0x00
67 +#define WDOG_REG_TIMER         0x04
68 +
69  #define WDOG_CTRL_LAST_RESET   BIT(31)
70  #define WDOG_CTRL_ACTION_MASK  3
71  #define WDOG_CTRL_ACTION_NONE  0       /* no action */
72 @@ -66,27 +67,38 @@ static struct clk *wdt_clk;
73  static unsigned long wdt_freq;
74  static int boot_status;
75  static int max_timeout;
76 +static void __iomem *wdt_base;
77 +
78 +static inline void ath79_wdt_wr(unsigned reg, u32 val)
79 +{
80 +       iowrite32(val, wdt_base + reg);
81 +}
82 +
83 +static inline u32 ath79_wdt_rr(unsigned reg)
84 +{
85 +       return ioread32(wdt_base + reg);
86 +}
87  
88  static inline void ath79_wdt_keepalive(void)
89  {
90 -       ath79_reset_wr(AR71XX_RESET_REG_WDOG, wdt_freq * timeout);
91 +       ath79_wdt_wr(WDOG_REG_TIMER, wdt_freq * timeout);
92         /* flush write */
93 -       ath79_reset_rr(AR71XX_RESET_REG_WDOG);
94 +       ath79_wdt_rr(WDOG_REG_TIMER);
95  }
96  
97  static inline void ath79_wdt_enable(void)
98  {
99         ath79_wdt_keepalive();
100 -       ath79_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_FCR);
101 +       ath79_wdt_wr(WDOG_REG_CTRL, WDOG_CTRL_ACTION_FCR);
102         /* flush write */
103 -       ath79_reset_rr(AR71XX_RESET_REG_WDOG_CTRL);
104 +       ath79_wdt_rr(WDOG_REG_CTRL);
105  }
106  
107  static inline void ath79_wdt_disable(void)
108  {
109 -       ath79_reset_wr(AR71XX_RESET_REG_WDOG_CTRL, WDOG_CTRL_ACTION_NONE);
110 +       ath79_wdt_wr(WDOG_REG_CTRL, WDOG_CTRL_ACTION_NONE);
111         /* flush write */
112 -       ath79_reset_rr(AR71XX_RESET_REG_WDOG_CTRL);
113 +       ath79_wdt_rr(WDOG_REG_CTRL);
114  }
115  
116  static int ath79_wdt_set_timeout(int val)
117 @@ -226,9 +238,25 @@ static struct miscdevice ath79_wdt_miscd
118  
119  static int ath79_wdt_probe(struct platform_device *pdev)
120  {
121 +       struct resource *res;
122         u32 ctrl;
123         int err;
124  
125 +       if (wdt_base)
126 +               return -EBUSY;
127 +
128 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
129 +       if (!res) {
130 +               dev_err(&pdev->dev, "no memory resource found\n");
131 +               return -EINVAL;
132 +       }
133 +
134 +       wdt_base = devm_request_and_ioremap(&pdev->dev, res);
135 +       if (!wdt_base) {
136 +               dev_err(&pdev->dev, "unable to remap memory region\n");
137 +               return -ENOMEM;
138 +       }
139 +
140         wdt_clk = devm_clk_get(&pdev->dev, "wdt");
141         if (IS_ERR(wdt_clk))
142                 return PTR_ERR(wdt_clk);
143 @@ -251,7 +279,7 @@ static int ath79_wdt_probe(struct platfo
144                         max_timeout, timeout);
145         }
146  
147 -       ctrl = ath79_reset_rr(AR71XX_RESET_REG_WDOG_CTRL);
148 +       ctrl = ath79_wdt_rr(WDOG_REG_CTRL);
149         boot_status = (ctrl & WDOG_CTRL_LAST_RESET) ? WDIOF_CARDRESET : 0;
150  
151         err = misc_register(&ath79_wdt_miscdev);