orion_wdt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * drivers/watchdog/orion_wdt.c
  4. *
  5. * Watchdog driver for Orion/Kirkwood processors
  6. *
  7. * Author: Sylver Bruneau <sylver.bruneau@googlemail.com>
  8. *
  9. */
  10. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/watchdog.h>
  17. #include <linux/interrupt.h>
  18. #include <linux/io.h>
  19. #include <linux/clk.h>
  20. #include <linux/err.h>
  21. #include <linux/of.h>
  22. #include <linux/of_device.h>
  23. /* RSTOUT mask register physical address for Orion5x, Kirkwood and Dove */
  24. #define ORION_RSTOUT_MASK_OFFSET 0x20108
  25. /* Internal registers can be configured at any 1 MiB aligned address */
  26. #define INTERNAL_REGS_MASK ~(SZ_1M - 1)
  27. /*
  28. * Watchdog timer block registers.
  29. */
  30. #define TIMER_CTRL 0x0000
  31. #define TIMER1_FIXED_ENABLE_BIT BIT(12)
  32. #define WDT_AXP_FIXED_ENABLE_BIT BIT(10)
  33. #define TIMER1_ENABLE_BIT BIT(2)
  34. #define TIMER_A370_STATUS 0x0004
  35. #define WDT_A370_EXPIRED BIT(31)
  36. #define TIMER1_STATUS_BIT BIT(8)
  37. #define TIMER1_VAL_OFF 0x001c
  38. #define WDT_MAX_CYCLE_COUNT 0xffffffff
  39. #define WDT_A370_RATIO_MASK(v) ((v) << 16)
  40. #define WDT_A370_RATIO_SHIFT 5
  41. #define WDT_A370_RATIO (1 << WDT_A370_RATIO_SHIFT)
  42. static bool nowayout = WATCHDOG_NOWAYOUT;
  43. static int heartbeat; /* module parameter (seconds) */
  44. struct orion_watchdog;
  45. struct orion_watchdog_data {
  46. int wdt_counter_offset;
  47. int wdt_enable_bit;
  48. int rstout_enable_bit;
  49. int rstout_mask_bit;
  50. int (*clock_init)(struct platform_device *,
  51. struct orion_watchdog *);
  52. int (*enabled)(struct orion_watchdog *);
  53. int (*start)(struct watchdog_device *);
  54. int (*stop)(struct watchdog_device *);
  55. };
  56. struct orion_watchdog {
  57. struct watchdog_device wdt;
  58. void __iomem *reg;
  59. void __iomem *rstout;
  60. void __iomem *rstout_mask;
  61. unsigned long clk_rate;
  62. struct clk *clk;
  63. const struct orion_watchdog_data *data;
  64. };
  65. static int orion_wdt_clock_init(struct platform_device *pdev,
  66. struct orion_watchdog *dev)
  67. {
  68. int ret;
  69. dev->clk = clk_get(&pdev->dev, NULL);
  70. if (IS_ERR(dev->clk))
  71. return PTR_ERR(dev->clk);
  72. ret = clk_prepare_enable(dev->clk);
  73. if (ret) {
  74. clk_put(dev->clk);
  75. return ret;
  76. }
  77. dev->clk_rate = clk_get_rate(dev->clk);
  78. return 0;
  79. }
  80. static int armada370_wdt_clock_init(struct platform_device *pdev,
  81. struct orion_watchdog *dev)
  82. {
  83. int ret;
  84. dev->clk = clk_get(&pdev->dev, NULL);
  85. if (IS_ERR(dev->clk))
  86. return PTR_ERR(dev->clk);
  87. ret = clk_prepare_enable(dev->clk);
  88. if (ret) {
  89. clk_put(dev->clk);
  90. return ret;
  91. }
  92. /* Setup watchdog input clock */
  93. atomic_io_modify(dev->reg + TIMER_CTRL,
  94. WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT),
  95. WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT));
  96. dev->clk_rate = clk_get_rate(dev->clk) / WDT_A370_RATIO;
  97. return 0;
  98. }
  99. static int armada375_wdt_clock_init(struct platform_device *pdev,
  100. struct orion_watchdog *dev)
  101. {
  102. int ret;
  103. dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed");
  104. if (!IS_ERR(dev->clk)) {
  105. ret = clk_prepare_enable(dev->clk);
  106. if (ret) {
  107. clk_put(dev->clk);
  108. return ret;
  109. }
  110. atomic_io_modify(dev->reg + TIMER_CTRL,
  111. WDT_AXP_FIXED_ENABLE_BIT,
  112. WDT_AXP_FIXED_ENABLE_BIT);
  113. dev->clk_rate = clk_get_rate(dev->clk);
  114. return 0;
  115. }
  116. /* Mandatory fallback for proper devicetree backward compatibility */
  117. dev->clk = clk_get(&pdev->dev, NULL);
  118. if (IS_ERR(dev->clk))
  119. return PTR_ERR(dev->clk);
  120. ret = clk_prepare_enable(dev->clk);
  121. if (ret) {
  122. clk_put(dev->clk);
  123. return ret;
  124. }
  125. atomic_io_modify(dev->reg + TIMER_CTRL,
  126. WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT),
  127. WDT_A370_RATIO_MASK(WDT_A370_RATIO_SHIFT));
  128. dev->clk_rate = clk_get_rate(dev->clk) / WDT_A370_RATIO;
  129. return 0;
  130. }
  131. static int armadaxp_wdt_clock_init(struct platform_device *pdev,
  132. struct orion_watchdog *dev)
  133. {
  134. int ret;
  135. u32 val;
  136. dev->clk = of_clk_get_by_name(pdev->dev.of_node, "fixed");
  137. if (IS_ERR(dev->clk))
  138. return PTR_ERR(dev->clk);
  139. ret = clk_prepare_enable(dev->clk);
  140. if (ret) {
  141. clk_put(dev->clk);
  142. return ret;
  143. }
  144. /* Fix the wdt and timer1 clock frequency to 25MHz */
  145. val = WDT_AXP_FIXED_ENABLE_BIT | TIMER1_FIXED_ENABLE_BIT;
  146. atomic_io_modify(dev->reg + TIMER_CTRL, val, val);
  147. dev->clk_rate = clk_get_rate(dev->clk);
  148. return 0;
  149. }
  150. static int orion_wdt_ping(struct watchdog_device *wdt_dev)
  151. {
  152. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  153. /* Reload watchdog duration */
  154. writel(dev->clk_rate * wdt_dev->timeout,
  155. dev->reg + dev->data->wdt_counter_offset);
  156. if (dev->wdt.info->options & WDIOF_PRETIMEOUT)
  157. writel(dev->clk_rate * (wdt_dev->timeout - wdt_dev->pretimeout),
  158. dev->reg + TIMER1_VAL_OFF);
  159. return 0;
  160. }
  161. static int armada375_start(struct watchdog_device *wdt_dev)
  162. {
  163. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  164. u32 reg;
  165. /* Set watchdog duration */
  166. writel(dev->clk_rate * wdt_dev->timeout,
  167. dev->reg + dev->data->wdt_counter_offset);
  168. if (dev->wdt.info->options & WDIOF_PRETIMEOUT)
  169. writel(dev->clk_rate * (wdt_dev->timeout - wdt_dev->pretimeout),
  170. dev->reg + TIMER1_VAL_OFF);
  171. /* Clear the watchdog expiration bit */
  172. atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0);
  173. /* Enable watchdog timer */
  174. reg = dev->data->wdt_enable_bit;
  175. if (dev->wdt.info->options & WDIOF_PRETIMEOUT)
  176. reg |= TIMER1_ENABLE_BIT;
  177. atomic_io_modify(dev->reg + TIMER_CTRL, reg, reg);
  178. /* Enable reset on watchdog */
  179. reg = readl(dev->rstout);
  180. reg |= dev->data->rstout_enable_bit;
  181. writel(reg, dev->rstout);
  182. atomic_io_modify(dev->rstout_mask, dev->data->rstout_mask_bit, 0);
  183. return 0;
  184. }
  185. static int armada370_start(struct watchdog_device *wdt_dev)
  186. {
  187. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  188. u32 reg;
  189. /* Set watchdog duration */
  190. writel(dev->clk_rate * wdt_dev->timeout,
  191. dev->reg + dev->data->wdt_counter_offset);
  192. /* Clear the watchdog expiration bit */
  193. atomic_io_modify(dev->reg + TIMER_A370_STATUS, WDT_A370_EXPIRED, 0);
  194. /* Enable watchdog timer */
  195. reg = dev->data->wdt_enable_bit;
  196. if (dev->wdt.info->options & WDIOF_PRETIMEOUT)
  197. reg |= TIMER1_ENABLE_BIT;
  198. atomic_io_modify(dev->reg + TIMER_CTRL, reg, reg);
  199. /* Enable reset on watchdog */
  200. reg = readl(dev->rstout);
  201. reg |= dev->data->rstout_enable_bit;
  202. writel(reg, dev->rstout);
  203. return 0;
  204. }
  205. static int orion_start(struct watchdog_device *wdt_dev)
  206. {
  207. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  208. /* Set watchdog duration */
  209. writel(dev->clk_rate * wdt_dev->timeout,
  210. dev->reg + dev->data->wdt_counter_offset);
  211. /* Enable watchdog timer */
  212. atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit,
  213. dev->data->wdt_enable_bit);
  214. /* Enable reset on watchdog */
  215. atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit,
  216. dev->data->rstout_enable_bit);
  217. return 0;
  218. }
  219. static int orion_wdt_start(struct watchdog_device *wdt_dev)
  220. {
  221. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  222. /* There are some per-SoC quirks to handle */
  223. return dev->data->start(wdt_dev);
  224. }
  225. static int orion_stop(struct watchdog_device *wdt_dev)
  226. {
  227. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  228. /* Disable reset on watchdog */
  229. atomic_io_modify(dev->rstout, dev->data->rstout_enable_bit, 0);
  230. /* Disable watchdog timer */
  231. atomic_io_modify(dev->reg + TIMER_CTRL, dev->data->wdt_enable_bit, 0);
  232. return 0;
  233. }
  234. static int armada375_stop(struct watchdog_device *wdt_dev)
  235. {
  236. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  237. u32 reg, mask;
  238. /* Disable reset on watchdog */
  239. atomic_io_modify(dev->rstout_mask, dev->data->rstout_mask_bit,
  240. dev->data->rstout_mask_bit);
  241. reg = readl(dev->rstout);
  242. reg &= ~dev->data->rstout_enable_bit;
  243. writel(reg, dev->rstout);
  244. /* Disable watchdog timer */
  245. mask = dev->data->wdt_enable_bit;
  246. if (wdt_dev->info->options & WDIOF_PRETIMEOUT)
  247. mask |= TIMER1_ENABLE_BIT;
  248. atomic_io_modify(dev->reg + TIMER_CTRL, mask, 0);
  249. return 0;
  250. }
  251. static int armada370_stop(struct watchdog_device *wdt_dev)
  252. {
  253. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  254. u32 reg, mask;
  255. /* Disable reset on watchdog */
  256. reg = readl(dev->rstout);
  257. reg &= ~dev->data->rstout_enable_bit;
  258. writel(reg, dev->rstout);
  259. /* Disable watchdog timer */
  260. mask = dev->data->wdt_enable_bit;
  261. if (wdt_dev->info->options & WDIOF_PRETIMEOUT)
  262. mask |= TIMER1_ENABLE_BIT;
  263. atomic_io_modify(dev->reg + TIMER_CTRL, mask, 0);
  264. return 0;
  265. }
  266. static int orion_wdt_stop(struct watchdog_device *wdt_dev)
  267. {
  268. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  269. return dev->data->stop(wdt_dev);
  270. }
  271. static int orion_enabled(struct orion_watchdog *dev)
  272. {
  273. bool enabled, running;
  274. enabled = readl(dev->rstout) & dev->data->rstout_enable_bit;
  275. running = readl(dev->reg + TIMER_CTRL) & dev->data->wdt_enable_bit;
  276. return enabled && running;
  277. }
  278. static int armada375_enabled(struct orion_watchdog *dev)
  279. {
  280. bool masked, enabled, running;
  281. masked = readl(dev->rstout_mask) & dev->data->rstout_mask_bit;
  282. enabled = readl(dev->rstout) & dev->data->rstout_enable_bit;
  283. running = readl(dev->reg + TIMER_CTRL) & dev->data->wdt_enable_bit;
  284. return !masked && enabled && running;
  285. }
  286. static int orion_wdt_enabled(struct watchdog_device *wdt_dev)
  287. {
  288. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  289. return dev->data->enabled(dev);
  290. }
  291. static unsigned int orion_wdt_get_timeleft(struct watchdog_device *wdt_dev)
  292. {
  293. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  294. return readl(dev->reg + dev->data->wdt_counter_offset) / dev->clk_rate;
  295. }
  296. static struct watchdog_info orion_wdt_info = {
  297. .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
  298. .identity = "Orion Watchdog",
  299. };
  300. static const struct watchdog_ops orion_wdt_ops = {
  301. .owner = THIS_MODULE,
  302. .start = orion_wdt_start,
  303. .stop = orion_wdt_stop,
  304. .ping = orion_wdt_ping,
  305. .get_timeleft = orion_wdt_get_timeleft,
  306. };
  307. static irqreturn_t orion_wdt_irq(int irq, void *devid)
  308. {
  309. panic("Watchdog Timeout");
  310. return IRQ_HANDLED;
  311. }
  312. static irqreturn_t orion_wdt_pre_irq(int irq, void *devid)
  313. {
  314. struct orion_watchdog *dev = devid;
  315. atomic_io_modify(dev->reg + TIMER_A370_STATUS,
  316. TIMER1_STATUS_BIT, 0);
  317. watchdog_notify_pretimeout(&dev->wdt);
  318. return IRQ_HANDLED;
  319. }
  320. /*
  321. * The original devicetree binding for this driver specified only
  322. * one memory resource, so in order to keep DT backwards compatibility
  323. * we try to fallback to a hardcoded register address, if the resource
  324. * is missing from the devicetree.
  325. */
  326. static void __iomem *orion_wdt_ioremap_rstout(struct platform_device *pdev,
  327. phys_addr_t internal_regs)
  328. {
  329. struct resource *res;
  330. phys_addr_t rstout;
  331. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  332. if (res)
  333. return devm_ioremap(&pdev->dev, res->start,
  334. resource_size(res));
  335. rstout = internal_regs + ORION_RSTOUT_MASK_OFFSET;
  336. WARN(1, FW_BUG "falling back to hardcoded RSTOUT reg %pa\n", &rstout);
  337. return devm_ioremap(&pdev->dev, rstout, 0x4);
  338. }
  339. static const struct orion_watchdog_data orion_data = {
  340. .rstout_enable_bit = BIT(1),
  341. .wdt_enable_bit = BIT(4),
  342. .wdt_counter_offset = 0x24,
  343. .clock_init = orion_wdt_clock_init,
  344. .enabled = orion_enabled,
  345. .start = orion_start,
  346. .stop = orion_stop,
  347. };
  348. static const struct orion_watchdog_data armada370_data = {
  349. .rstout_enable_bit = BIT(8),
  350. .wdt_enable_bit = BIT(8),
  351. .wdt_counter_offset = 0x34,
  352. .clock_init = armada370_wdt_clock_init,
  353. .enabled = orion_enabled,
  354. .start = armada370_start,
  355. .stop = armada370_stop,
  356. };
  357. static const struct orion_watchdog_data armadaxp_data = {
  358. .rstout_enable_bit = BIT(8),
  359. .wdt_enable_bit = BIT(8),
  360. .wdt_counter_offset = 0x34,
  361. .clock_init = armadaxp_wdt_clock_init,
  362. .enabled = orion_enabled,
  363. .start = armada370_start,
  364. .stop = armada370_stop,
  365. };
  366. static const struct orion_watchdog_data armada375_data = {
  367. .rstout_enable_bit = BIT(8),
  368. .rstout_mask_bit = BIT(10),
  369. .wdt_enable_bit = BIT(8),
  370. .wdt_counter_offset = 0x34,
  371. .clock_init = armada375_wdt_clock_init,
  372. .enabled = armada375_enabled,
  373. .start = armada375_start,
  374. .stop = armada375_stop,
  375. };
  376. static const struct orion_watchdog_data armada380_data = {
  377. .rstout_enable_bit = BIT(8),
  378. .rstout_mask_bit = BIT(10),
  379. .wdt_enable_bit = BIT(8),
  380. .wdt_counter_offset = 0x34,
  381. .clock_init = armadaxp_wdt_clock_init,
  382. .enabled = armada375_enabled,
  383. .start = armada375_start,
  384. .stop = armada375_stop,
  385. };
  386. static const struct of_device_id orion_wdt_of_match_table[] = {
  387. {
  388. .compatible = "marvell,orion-wdt",
  389. .data = &orion_data,
  390. },
  391. {
  392. .compatible = "marvell,armada-370-wdt",
  393. .data = &armada370_data,
  394. },
  395. {
  396. .compatible = "marvell,armada-xp-wdt",
  397. .data = &armadaxp_data,
  398. },
  399. {
  400. .compatible = "marvell,armada-375-wdt",
  401. .data = &armada375_data,
  402. },
  403. {
  404. .compatible = "marvell,armada-380-wdt",
  405. .data = &armada380_data,
  406. },
  407. {},
  408. };
  409. MODULE_DEVICE_TABLE(of, orion_wdt_of_match_table);
  410. static int orion_wdt_get_regs(struct platform_device *pdev,
  411. struct orion_watchdog *dev)
  412. {
  413. struct device_node *node = pdev->dev.of_node;
  414. struct resource *res;
  415. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  416. if (!res)
  417. return -ENODEV;
  418. dev->reg = devm_ioremap(&pdev->dev, res->start,
  419. resource_size(res));
  420. if (!dev->reg)
  421. return -ENOMEM;
  422. /* Each supported compatible has some RSTOUT register quirk */
  423. if (of_device_is_compatible(node, "marvell,orion-wdt")) {
  424. dev->rstout = orion_wdt_ioremap_rstout(pdev, res->start &
  425. INTERNAL_REGS_MASK);
  426. if (!dev->rstout)
  427. return -ENODEV;
  428. } else if (of_device_is_compatible(node, "marvell,armada-370-wdt") ||
  429. of_device_is_compatible(node, "marvell,armada-xp-wdt")) {
  430. /* Dedicated RSTOUT register, can be requested. */
  431. dev->rstout = devm_platform_ioremap_resource(pdev, 1);
  432. if (IS_ERR(dev->rstout))
  433. return PTR_ERR(dev->rstout);
  434. } else if (of_device_is_compatible(node, "marvell,armada-375-wdt") ||
  435. of_device_is_compatible(node, "marvell,armada-380-wdt")) {
  436. /* Dedicated RSTOUT register, can be requested. */
  437. dev->rstout = devm_platform_ioremap_resource(pdev, 1);
  438. if (IS_ERR(dev->rstout))
  439. return PTR_ERR(dev->rstout);
  440. res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
  441. if (!res)
  442. return -ENODEV;
  443. dev->rstout_mask = devm_ioremap(&pdev->dev, res->start,
  444. resource_size(res));
  445. if (!dev->rstout_mask)
  446. return -ENOMEM;
  447. } else {
  448. return -ENODEV;
  449. }
  450. return 0;
  451. }
  452. static int orion_wdt_probe(struct platform_device *pdev)
  453. {
  454. struct orion_watchdog *dev;
  455. const struct of_device_id *match;
  456. unsigned int wdt_max_duration; /* (seconds) */
  457. int ret, irq;
  458. dev = devm_kzalloc(&pdev->dev, sizeof(struct orion_watchdog),
  459. GFP_KERNEL);
  460. if (!dev)
  461. return -ENOMEM;
  462. match = of_match_device(orion_wdt_of_match_table, &pdev->dev);
  463. if (!match)
  464. /* Default legacy match */
  465. match = &orion_wdt_of_match_table[0];
  466. dev->wdt.info = &orion_wdt_info;
  467. dev->wdt.ops = &orion_wdt_ops;
  468. dev->wdt.min_timeout = 1;
  469. dev->data = match->data;
  470. ret = orion_wdt_get_regs(pdev, dev);
  471. if (ret)
  472. return ret;
  473. ret = dev->data->clock_init(pdev, dev);
  474. if (ret) {
  475. dev_err(&pdev->dev, "cannot initialize clock\n");
  476. return ret;
  477. }
  478. wdt_max_duration = WDT_MAX_CYCLE_COUNT / dev->clk_rate;
  479. dev->wdt.timeout = wdt_max_duration;
  480. dev->wdt.max_timeout = wdt_max_duration;
  481. dev->wdt.parent = &pdev->dev;
  482. watchdog_init_timeout(&dev->wdt, heartbeat, &pdev->dev);
  483. platform_set_drvdata(pdev, &dev->wdt);
  484. watchdog_set_drvdata(&dev->wdt, dev);
  485. /*
  486. * Let's make sure the watchdog is fully stopped, unless it's
  487. * explicitly enabled. This may be the case if the module was
  488. * removed and re-inserted, or if the bootloader explicitly
  489. * set a running watchdog before booting the kernel.
  490. */
  491. if (!orion_wdt_enabled(&dev->wdt))
  492. orion_wdt_stop(&dev->wdt);
  493. else
  494. set_bit(WDOG_HW_RUNNING, &dev->wdt.status);
  495. /* Request the IRQ only after the watchdog is disabled */
  496. irq = platform_get_irq_optional(pdev, 0);
  497. if (irq > 0) {
  498. /*
  499. * Not all supported platforms specify an interrupt for the
  500. * watchdog, so let's make it optional.
  501. */
  502. ret = devm_request_irq(&pdev->dev, irq, orion_wdt_irq, 0,
  503. pdev->name, dev);
  504. if (ret < 0) {
  505. dev_err(&pdev->dev, "failed to request IRQ\n");
  506. goto disable_clk;
  507. }
  508. }
  509. /* Optional 2nd interrupt for pretimeout */
  510. irq = platform_get_irq_optional(pdev, 1);
  511. if (irq > 0) {
  512. orion_wdt_info.options |= WDIOF_PRETIMEOUT;
  513. ret = devm_request_irq(&pdev->dev, irq, orion_wdt_pre_irq,
  514. 0, pdev->name, dev);
  515. if (ret < 0) {
  516. dev_err(&pdev->dev, "failed to request IRQ\n");
  517. goto disable_clk;
  518. }
  519. }
  520. watchdog_set_nowayout(&dev->wdt, nowayout);
  521. ret = watchdog_register_device(&dev->wdt);
  522. if (ret)
  523. goto disable_clk;
  524. pr_info("Initial timeout %d sec%s\n",
  525. dev->wdt.timeout, nowayout ? ", nowayout" : "");
  526. return 0;
  527. disable_clk:
  528. clk_disable_unprepare(dev->clk);
  529. clk_put(dev->clk);
  530. return ret;
  531. }
  532. static void orion_wdt_remove(struct platform_device *pdev)
  533. {
  534. struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
  535. struct orion_watchdog *dev = watchdog_get_drvdata(wdt_dev);
  536. watchdog_unregister_device(wdt_dev);
  537. clk_disable_unprepare(dev->clk);
  538. clk_put(dev->clk);
  539. }
  540. static void orion_wdt_shutdown(struct platform_device *pdev)
  541. {
  542. struct watchdog_device *wdt_dev = platform_get_drvdata(pdev);
  543. orion_wdt_stop(wdt_dev);
  544. }
  545. static struct platform_driver orion_wdt_driver = {
  546. .probe = orion_wdt_probe,
  547. .remove = orion_wdt_remove,
  548. .shutdown = orion_wdt_shutdown,
  549. .driver = {
  550. .name = "orion_wdt",
  551. .of_match_table = orion_wdt_of_match_table,
  552. },
  553. };
  554. module_platform_driver(orion_wdt_driver);
  555. MODULE_AUTHOR("Sylver Bruneau <sylver.bruneau@googlemail.com>");
  556. MODULE_DESCRIPTION("Orion Processor Watchdog");
  557. module_param(heartbeat, int, 0);
  558. MODULE_PARM_DESC(heartbeat, "Initial watchdog heartbeat in seconds");
  559. module_param(nowayout, bool, 0);
  560. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
  561. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  562. MODULE_LICENSE("GPL v2");
  563. MODULE_ALIAS("platform:orion_wdt");