0056-watchdog-add-MT7621-support.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. From 6a42dd698ddf91b6e9902b17e21dc13c6ae412ff Mon Sep 17 00:00:00 2001
  2. From: John Crispin <blogic@openwrt.org>
  3. Date: Sun, 16 Mar 2014 05:24:42 +0000
  4. Subject: [PATCH 56/57] watchdog: add MT7621 support
  5. Signed-off-by: John Crispin <blogic@openwrt.org>
  6. ---
  7. drivers/watchdog/Kconfig | 7 ++
  8. drivers/watchdog/Makefile | 1 +
  9. drivers/watchdog/mt7621_wdt.c | 185 +++++++++++++++++++++++++++++++++++++++++
  10. 3 files changed, 193 insertions(+)
  11. create mode 100644 drivers/watchdog/mt7621_wdt.c
  12. --- a/drivers/watchdog/Kconfig
  13. +++ b/drivers/watchdog/Kconfig
  14. @@ -1257,6 +1257,13 @@ config RALINK_WDT
  15. help
  16. Hardware driver for the Ralink SoC Watchdog Timer.
  17. +config MT7621_WDT
  18. + tristate "Mediatek SoC watchdog"
  19. + select WATCHDOG_CORE
  20. + depends on SOC_MT7620 || SOC_MT7621
  21. + help
  22. + Hardware driver for the Ralink SoC Watchdog Timer.
  23. +
  24. # PARISC Architecture
  25. # POWERPC Architecture
  26. --- a/drivers/watchdog/Makefile
  27. +++ b/drivers/watchdog/Makefile
  28. @@ -143,6 +143,7 @@ obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o
  29. octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o
  30. obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o
  31. obj-$(CONFIG_RALINK_WDT) += rt2880_wdt.o
  32. +obj-$(CONFIG_MT7621_WDT) += mt7621_wdt.o
  33. # PARISC Architecture
  34. --- /dev/null
  35. +++ b/drivers/watchdog/mt7621_wdt.c
  36. @@ -0,0 +1,185 @@
  37. +/*
  38. + * Ralink RT288x/RT3xxx/MT76xx built-in hardware watchdog timer
  39. + *
  40. + * Copyright (C) 2011 Gabor Juhos <juhosg@openwrt.org>
  41. + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
  42. + *
  43. + * This driver was based on: drivers/watchdog/softdog.c
  44. + *
  45. + * This program is free software; you can redistribute it and/or modify it
  46. + * under the terms of the GNU General Public License version 2 as published
  47. + * by the Free Software Foundation.
  48. + */
  49. +
  50. +#include <linux/clk.h>
  51. +#include <linux/reset.h>
  52. +#include <linux/module.h>
  53. +#include <linux/kernel.h>
  54. +#include <linux/watchdog.h>
  55. +#include <linux/miscdevice.h>
  56. +#include <linux/moduleparam.h>
  57. +#include <linux/platform_device.h>
  58. +
  59. +#include <asm/mach-ralink/ralink_regs.h>
  60. +
  61. +#define SYSC_RSTSTAT 0x38
  62. +#define WDT_RST_CAUSE BIT(1)
  63. +
  64. +#define RALINK_WDT_TIMEOUT 30
  65. +
  66. +#define TIMER_REG_TMRSTAT 0x00
  67. +#define TIMER_REG_TMR1LOAD 0x24
  68. +#define TIMER_REG_TMR1CTL 0x20
  69. +
  70. +#define TMR1CTL_ENABLE BIT(7)
  71. +#define TMR1CTL_RESTART BIT(9)
  72. +
  73. +static void __iomem *mt762x_wdt_base;
  74. +
  75. +static bool nowayout = WATCHDOG_NOWAYOUT;
  76. +module_param(nowayout, bool, 0);
  77. +MODULE_PARM_DESC(nowayout,
  78. + "Watchdog cannot be stopped once started (default="
  79. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  80. +
  81. +static inline void rt_wdt_w32(unsigned reg, u32 val)
  82. +{
  83. + iowrite32(val, mt762x_wdt_base + reg);
  84. +}
  85. +
  86. +static inline u32 rt_wdt_r32(unsigned reg)
  87. +{
  88. + return ioread32(mt762x_wdt_base + reg);
  89. +}
  90. +
  91. +static int mt762x_wdt_ping(struct watchdog_device *w)
  92. +{
  93. + rt_wdt_w32(TIMER_REG_TMRSTAT, TMR1CTL_RESTART);
  94. +
  95. + return 0;
  96. +}
  97. +
  98. +static int mt762x_wdt_set_timeout(struct watchdog_device *w, unsigned int t)
  99. +{
  100. + w->timeout = t;
  101. + rt_wdt_w32(TIMER_REG_TMR1LOAD, t * 1000);
  102. + mt762x_wdt_ping(w);
  103. +
  104. + return 0;
  105. +}
  106. +
  107. +static int mt762x_wdt_start(struct watchdog_device *w)
  108. +{
  109. + u32 t;
  110. +
  111. + rt_wdt_w32(TIMER_REG_TMR1CTL, 1000 << 16);
  112. + mt762x_wdt_set_timeout(w, w->timeout);
  113. +
  114. + t = rt_wdt_r32(TIMER_REG_TMR1CTL);
  115. + t |= TMR1CTL_ENABLE;
  116. + rt_wdt_w32(TIMER_REG_TMR1CTL, t);
  117. +
  118. + return 0;
  119. +}
  120. +
  121. +static int mt762x_wdt_stop(struct watchdog_device *w)
  122. +{
  123. + u32 t;
  124. +
  125. + mt762x_wdt_ping(w);
  126. +
  127. + t = rt_wdt_r32(TIMER_REG_TMR1CTL);
  128. + t &= ~TMR1CTL_ENABLE;
  129. + rt_wdt_w32(TIMER_REG_TMR1CTL, t);
  130. +
  131. + return 0;
  132. +}
  133. +
  134. +static int mt762x_wdt_bootcause(void)
  135. +{
  136. + if (rt_sysc_r32(SYSC_RSTSTAT) & WDT_RST_CAUSE)
  137. + return WDIOF_CARDRESET;
  138. +
  139. + return 0;
  140. +}
  141. +
  142. +static struct watchdog_info mt762x_wdt_info = {
  143. + .identity = "Mediatek Watchdog",
  144. + .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
  145. +};
  146. +
  147. +static struct watchdog_ops mt762x_wdt_ops = {
  148. + .owner = THIS_MODULE,
  149. + .start = mt762x_wdt_start,
  150. + .stop = mt762x_wdt_stop,
  151. + .ping = mt762x_wdt_ping,
  152. + .set_timeout = mt762x_wdt_set_timeout,
  153. +};
  154. +
  155. +static struct watchdog_device mt762x_wdt_dev = {
  156. + .info = &mt762x_wdt_info,
  157. + .ops = &mt762x_wdt_ops,
  158. + .min_timeout = 1,
  159. +};
  160. +
  161. +static int mt762x_wdt_probe(struct platform_device *pdev)
  162. +{
  163. + struct resource *res;
  164. + int ret;
  165. +
  166. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  167. + mt762x_wdt_base = devm_ioremap_resource(&pdev->dev, res);
  168. + if (IS_ERR(mt762x_wdt_base))
  169. + return PTR_ERR(mt762x_wdt_base);
  170. +
  171. + device_reset(&pdev->dev);
  172. +
  173. + mt762x_wdt_dev.dev = &pdev->dev;
  174. + mt762x_wdt_dev.bootstatus = mt762x_wdt_bootcause();
  175. + mt762x_wdt_dev.max_timeout = (0xfffful / 1000);
  176. + mt762x_wdt_dev.timeout = mt762x_wdt_dev.max_timeout;
  177. +
  178. + watchdog_set_nowayout(&mt762x_wdt_dev, nowayout);
  179. +
  180. + ret = watchdog_register_device(&mt762x_wdt_dev);
  181. + if (!ret)
  182. + dev_info(&pdev->dev, "Initialized\n");
  183. +
  184. + return 0;
  185. +}
  186. +
  187. +static int mt762x_wdt_remove(struct platform_device *pdev)
  188. +{
  189. + watchdog_unregister_device(&mt762x_wdt_dev);
  190. +
  191. + return 0;
  192. +}
  193. +
  194. +static void mt762x_wdt_shutdown(struct platform_device *pdev)
  195. +{
  196. + mt762x_wdt_stop(&mt762x_wdt_dev);
  197. +}
  198. +
  199. +static const struct of_device_id mt762x_wdt_match[] = {
  200. + { .compatible = "mtk,mt7621-wdt" },
  201. + {},
  202. +};
  203. +MODULE_DEVICE_TABLE(of, mt762x_wdt_match);
  204. +
  205. +static struct platform_driver mt762x_wdt_driver = {
  206. + .probe = mt762x_wdt_probe,
  207. + .remove = mt762x_wdt_remove,
  208. + .shutdown = mt762x_wdt_shutdown,
  209. + .driver = {
  210. + .name = KBUILD_MODNAME,
  211. + .owner = THIS_MODULE,
  212. + .of_match_table = mt762x_wdt_match,
  213. + },
  214. +};
  215. +
  216. +module_platform_driver(mt762x_wdt_driver);
  217. +
  218. +MODULE_DESCRIPTION("MediaTek MT762x hardware watchdog driver");
  219. +MODULE_AUTHOR("John Crispin <blogic@openwrt.org");
  220. +MODULE_LICENSE("GPL v2");
  221. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);