250-watchdog.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. --- a/drivers/watchdog/Kconfig
  2. +++ b/drivers/watchdog/Kconfig
  3. @@ -930,6 +930,12 @@
  4. To compile this driver as a loadable module, choose M here.
  5. The module will be called bcm63xx_wdt.
  6. +config LANTIQ_WDT
  7. + bool "Lantiq SoC watchdog"
  8. + depends on LANTIQ
  9. + help
  10. + Hardware driver for the Lantiq SoC Watchdog Timer.
  11. +
  12. # PARISC Architecture
  13. # POWERPC Architecture
  14. --- a/drivers/watchdog/Makefile
  15. +++ b/drivers/watchdog/Makefile
  16. @@ -119,6 +119,7 @@
  17. obj-$(CONFIG_TXX9_WDT) += txx9wdt.o
  18. obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
  19. octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
  20. +obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
  21. # PARISC Architecture
  22. --- /dev/null
  23. +++ b/drivers/watchdog/lantiq_wdt.c
  24. @@ -0,0 +1,218 @@
  25. +/*
  26. + * This program is free software; you can redistribute it and/or modify it
  27. + * under the terms of the GNU General Public License version 2 as published
  28. + * by the Free Software Foundation.
  29. + *
  30. + * Copyright (C) 2010 John Crispin <[email protected]>
  31. + * Based on EP93xx wdt driver
  32. + */
  33. +
  34. +#include <linux/module.h>
  35. +#include <linux/fs.h>
  36. +#include <linux/miscdevice.h>
  37. +#include <linux/miscdevice.h>
  38. +#include <linux/watchdog.h>
  39. +#include <linux/platform_device.h>
  40. +#include <linux/uaccess.h>
  41. +#include <linux/clk.h>
  42. +
  43. +#include <lantiq.h>
  44. +
  45. +#define LQ_WDT_PW1 0x00BE0000
  46. +#define LQ_WDT_PW2 0x00DC0000
  47. +
  48. +#define LQ_BIU_WDT_CR 0x3F0
  49. +#define LQ_BIU_WDT_SR 0x3F8
  50. +
  51. +#ifndef CONFIG_WATCHDOG_NOWAYOUT
  52. +static int wdt_ok_to_close;
  53. +#endif
  54. +
  55. +static int wdt_timeout = 30;
  56. +static __iomem void *wdt_membase = NULL;
  57. +static unsigned long io_region_clk = 0;
  58. +
  59. +static int
  60. +lq_wdt_enable(unsigned int timeout)
  61. +{
  62. +/* printk("%s:%s[%d] %08X\n",
  63. + __FILE__, __func__, __LINE__,
  64. + lq_r32(wdt_membase + LQ_BIU_WDT_SR));
  65. + if(!lq_r32(wdt_membase + LQ_BIU_WDT_SR))
  66. + {
  67. +*/ lq_w32(LQ_WDT_PW1, wdt_membase + LQ_BIU_WDT_CR);
  68. + lq_w32(LQ_WDT_PW2 |
  69. + (0x3 << 26) | /* PWL */
  70. + (0x3 << 24) | /* CLKDIV */
  71. + (0x1 << 31) | /* enable */
  72. + ((timeout * (io_region_clk / 0x40000)) + 0x1000), /* reload */
  73. + wdt_membase + LQ_BIU_WDT_CR);
  74. +// }
  75. + return 0;
  76. +}
  77. +
  78. +static void
  79. +lq_wdt_disable(void)
  80. +{
  81. +#ifndef CONFIG_WATCHDOG_NOWAYOUT
  82. + wdt_ok_to_close = 0;
  83. +#endif
  84. + lq_w32(LQ_WDT_PW1, wdt_membase + LQ_BIU_WDT_CR);
  85. + lq_w32(LQ_WDT_PW2, wdt_membase+ LQ_BIU_WDT_CR);
  86. +}
  87. +
  88. +static ssize_t
  89. +lq_wdt_write(struct file *file, const char __user *data,
  90. + size_t len, loff_t *ppos)
  91. +{
  92. + size_t i;
  93. +
  94. + if (!len)
  95. + return 0;
  96. +
  97. +#ifndef CONFIG_WATCHDOG_NOWAYOUT
  98. + for (i = 0; i != len; i++) {
  99. + char c;
  100. + if (get_user(c, data + i))
  101. + return -EFAULT;
  102. + if (c == 'V')
  103. + wdt_ok_to_close = 1;
  104. + }
  105. +#endif
  106. + lq_wdt_enable(wdt_timeout);
  107. + return len;
  108. +}
  109. +
  110. +static struct watchdog_info ident = {
  111. + .options = WDIOF_MAGICCLOSE,
  112. + .identity = "lq_wdt",
  113. +};
  114. +
  115. +static int
  116. +lq_wdt_ioctl(struct inode *inode, struct file *file,
  117. + unsigned int cmd, unsigned long arg)
  118. +{
  119. + int ret = -ENOTTY;
  120. +
  121. + switch (cmd) {
  122. + case WDIOC_GETSUPPORT:
  123. + ret = copy_to_user((struct watchdog_info __user *)arg, &ident,
  124. + sizeof(ident)) ? -EFAULT : 0;
  125. + break;
  126. +
  127. + case WDIOC_GETTIMEOUT:
  128. + ret = put_user(wdt_timeout, (int __user *)arg);
  129. + break;
  130. +
  131. + case WDIOC_SETTIMEOUT:
  132. + ret = get_user(wdt_timeout, (int __user *)arg);
  133. + break;
  134. +
  135. + case WDIOC_KEEPALIVE:
  136. + lq_wdt_enable(wdt_timeout);
  137. + ret = 0;
  138. + break;
  139. + }
  140. + return ret;
  141. +}
  142. +
  143. +static int
  144. +lq_wdt_open(struct inode *inode, struct file *file)
  145. +{
  146. + lq_wdt_enable(wdt_timeout);
  147. + return nonseekable_open(inode, file);
  148. +}
  149. +
  150. +static int
  151. +lq_wdt_release(struct inode *inode, struct file *file)
  152. +{
  153. +#ifndef CONFIG_WATCHDOG_NOWAYOUT
  154. + if (wdt_ok_to_close)
  155. + lq_wdt_disable();
  156. + else
  157. +#endif
  158. + printk(KERN_ERR "lq_wdt: watchdog closed without warning,"
  159. + " rebooting system\n");
  160. + return 0;
  161. +}
  162. +
  163. +static const struct file_operations lq_wdt_fops = {
  164. + .owner = THIS_MODULE,
  165. + .write = lq_wdt_write,
  166. + .unlocked_ioctl = lq_wdt_ioctl,
  167. + .open = lq_wdt_open,
  168. + .release = lq_wdt_release,
  169. +};
  170. +
  171. +static struct miscdevice lq_wdt_miscdev = {
  172. + .minor = WATCHDOG_MINOR,
  173. + .name = "watchdog",
  174. + .fops = &lq_wdt_fops,
  175. +};
  176. +
  177. +static int
  178. +lq_wdt_probe(struct platform_device *pdev)
  179. +{
  180. + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  181. + struct clk *clk;
  182. + int ret = 0;
  183. + if(!res)
  184. + return -ENOENT;
  185. + res = request_mem_region(res->start, resource_size(res),
  186. + dev_name(&pdev->dev));
  187. + if(!res)
  188. + return -EBUSY;
  189. + wdt_membase = ioremap_nocache(res->start, resource_size(res));
  190. + if(!wdt_membase)
  191. + {
  192. + ret = -ENOMEM;
  193. + goto err_release_mem_region;
  194. + }
  195. + clk = clk_get(&pdev->dev, "io");
  196. + io_region_clk = clk_get_rate(clk);;
  197. + ret = misc_register(&lq_wdt_miscdev);
  198. + if(!ret)
  199. + return 0;
  200. +
  201. + iounmap(wdt_membase);
  202. +err_release_mem_region:
  203. + release_mem_region(res->start, resource_size(res));
  204. + return ret;
  205. +}
  206. +
  207. +static int
  208. +lq_wdt_remove(struct platform_device *dev)
  209. +{
  210. + lq_wdt_disable();
  211. + misc_deregister(&lq_wdt_miscdev);
  212. + return 0;
  213. +}
  214. +
  215. +static struct platform_driver lq_wdt_driver = {
  216. + .probe = lq_wdt_probe,
  217. + .remove = lq_wdt_remove,
  218. + .driver = {
  219. + .name = "lq_wdt",
  220. + .owner = THIS_MODULE,
  221. + },
  222. +};
  223. +
  224. +static int __init
  225. +init_lq_wdt(void)
  226. +{
  227. + return platform_driver_register(&lq_wdt_driver);
  228. +}
  229. +
  230. +static void __exit
  231. +exit_lq_wdt(void)
  232. +{
  233. + platform_driver_unregister(&lq_wdt_driver);
  234. +}
  235. +
  236. +module_init(init_lq_wdt);
  237. +module_exit(exit_lq_wdt);
  238. +
  239. +MODULE_AUTHOR("John Crispin <[email protected]>");
  240. +MODULE_DESCRIPTION("ifxmips Watchdog");
  241. +MODULE_LICENSE("GPL");
  242. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);