The watchdog driver is now a platform device driver and reads its gpio line
[openwrt-10.03/.git] / target / linux / au1000 / patches / 016-watchdog_pdev_gpio.patch
1 diff --git a/drivers/char/watchdog/mtx-1_wdt.c b/drivers/char/watchdog/mtx-1_wdt.c
2 index dcfd401..5d8c51f 100644
3 --- a/drivers/char/watchdog/mtx-1_wdt.c
4 +++ b/drivers/char/watchdog/mtx-1_wdt.c
5 @@ -45,10 +45,13 @@
6  #include <linux/completion.h>
7  #include <linux/jiffies.h>
8  #include <linux/watchdog.h>
9 +#include <linux/platform_device.h>
10 +
11  #include <asm/io.h>
12  #include <asm/uaccess.h>
13  
14  #include <asm/mach-au1x00/au1000.h>
15 +#include <asm/gpio.h>
16  
17  #define MTX1_WDT_INTERVAL      (5 * HZ)
18  
19 @@ -61,6 +64,7 @@ static struct {
20         volatile int queue;
21         int default_ticks;
22         unsigned long inuse;
23 +       unsigned gpio;
24  } mtx1_wdt_device;
25  
26  static void mtx1_wdt_trigger(unsigned long unused)
27 @@ -73,7 +77,7 @@ static void mtx1_wdt_trigger(unsigned long unused)
28          * toggle GPIO2_15
29          */
30         tmp = au_readl(GPIO2_DIR);
31 -       tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
32 +       tmp = (tmp & ~(1<< mtx1_wdt_device.gpio)) | ((~tmp) & (1<< mtx1_wdt_device.gpio));
33         au_writel (tmp, GPIO2_DIR);
34  
35         if (mtx1_wdt_device.queue && ticks)
36 @@ -93,7 +97,7 @@ static void mtx1_wdt_start(void)
37  {
38         if (!mtx1_wdt_device.queue) {
39                 mtx1_wdt_device.queue = 1;
40 -               au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
41 +               gpio_set_value(mtx1_wdt_device.gpio, 1);
42                 mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL);
43         }
44         mtx1_wdt_device.running++;
45 @@ -103,7 +107,7 @@ static int mtx1_wdt_stop(void)
46  {
47         if (mtx1_wdt_device.queue) {
48                 mtx1_wdt_device.queue = 0;
49 -               au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
50 +               gpio_set_value(mtx1_wdt_device.gpio, 0);
51         }
52  
53         ticks = mtx1_wdt_device.default_ticks;
54 @@ -197,10 +201,12 @@ static struct miscdevice mtx1_wdt_misc = {
55  };
56  
57  
58 -static int __init mtx1_wdt_init(void)
59 +static int mtx1_wdt_probe(struct platform_device *pdev)
60  {
61         int ret;
62  
63 +       mtx1_wdt_device.gpio = pdev->resource[0].start; 
64 +
65         if ((ret = misc_register(&mtx1_wdt_misc)) < 0) {
66                 printk(KERN_ERR " mtx-1_wdt : failed to register\n");
67                 return ret;
68 @@ -222,13 +228,30 @@ static int __init mtx1_wdt_init(void)
69         return 0;
70  }
71  
72 -static void __exit mtx1_wdt_exit(void)
73 +static int mtx1_wdt_remove(struct platform_device *pdev)
74  {
75         if (mtx1_wdt_device.queue) {
76                 mtx1_wdt_device.queue = 0;
77                 wait_for_completion(&mtx1_wdt_device.stop);
78         }
79         misc_deregister(&mtx1_wdt_misc);
80 +       return 0;
81 +}
82 +
83 +static struct platform_driver mtx1_wdt = {
84 +       .probe = mtx1_wdt_probe,
85 +       .remove = mtx1_wdt_remove,
86 +       .driver.name = "mtx1-wdt",
87 +};
88 +
89 +static int __init mtx1_wdt_init(void)
90 +{
91 +       return platform_driver_register(&mtx1_wdt);
92 +}
93 +
94 +static void __exit mtx1_wdt_exit(void)
95 +{
96 +       platform_driver_unregister(&mtx1_wdt);
97  }
98  
99  module_init(mtx1_wdt_init);
100 @@ -237,3 +260,4 @@ module_exit(mtx1_wdt_exit);
101  MODULE_AUTHOR("Michael Stickel, Florian Fainelli");
102  MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
103  MODULE_LICENSE("GPL");
104 +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);