starfive-wdt.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Starfive Watchdog driver
  4. *
  5. * Copyright (C) 2022 StarFive Technology Co., Ltd.
  6. */
  7. #include <linux/clk.h>
  8. #include <linux/iopoll.h>
  9. #include <linux/module.h>
  10. #include <linux/of.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/pm_runtime.h>
  13. #include <linux/reset.h>
  14. #include <linux/watchdog.h>
  15. /* JH7100 Watchdog register define */
  16. #define STARFIVE_WDT_JH7100_INTSTAUS 0x000
  17. #define STARFIVE_WDT_JH7100_CONTROL 0x104
  18. #define STARFIVE_WDT_JH7100_LOAD 0x108
  19. #define STARFIVE_WDT_JH7100_EN 0x110
  20. #define STARFIVE_WDT_JH7100_RELOAD 0x114 /* Write 0 or 1 to reload preset value */
  21. #define STARFIVE_WDT_JH7100_VALUE 0x118
  22. #define STARFIVE_WDT_JH7100_INTCLR 0x120 /*
  23. * [0]: Write 1 to clear interrupt
  24. * [1]: 1 mean clearing and 0 mean complete
  25. * [31:2]: reserved.
  26. */
  27. #define STARFIVE_WDT_JH7100_LOCK 0x13c /* write 0x378f0765 to unlock */
  28. /* JH7110 Watchdog register define */
  29. #define STARFIVE_WDT_JH7110_LOAD 0x000
  30. #define STARFIVE_WDT_JH7110_VALUE 0x004
  31. #define STARFIVE_WDT_JH7110_CONTROL 0x008 /*
  32. * [0]: reset enable;
  33. * [1]: interrupt enable && watchdog enable
  34. * [31:2]: reserved.
  35. */
  36. #define STARFIVE_WDT_JH7110_INTCLR 0x00c /* clear intterupt and reload the counter */
  37. #define STARFIVE_WDT_JH7110_IMS 0x014
  38. #define STARFIVE_WDT_JH7110_LOCK 0xc00 /* write 0x1ACCE551 to unlock */
  39. /* WDOGCONTROL */
  40. #define STARFIVE_WDT_ENABLE 0x1
  41. #define STARFIVE_WDT_EN_SHIFT 0
  42. #define STARFIVE_WDT_RESET_EN 0x1
  43. #define STARFIVE_WDT_JH7100_RST_EN_SHIFT 0
  44. #define STARFIVE_WDT_JH7110_RST_EN_SHIFT 1
  45. /* WDOGLOCK */
  46. #define STARFIVE_WDT_JH7100_UNLOCK_KEY 0x378f0765
  47. #define STARFIVE_WDT_JH7110_UNLOCK_KEY 0x1acce551
  48. /* WDOGINTCLR */
  49. #define STARFIVE_WDT_INTCLR 0x1
  50. #define STARFIVE_WDT_JH7100_INTCLR_AVA_SHIFT 1 /* Watchdog can clear interrupt when 0 */
  51. #define STARFIVE_WDT_MAXCNT 0xffffffff
  52. #define STARFIVE_WDT_DEFAULT_TIME (15)
  53. #define STARFIVE_WDT_DELAY_US 0
  54. #define STARFIVE_WDT_TIMEOUT_US 10000
  55. /* module parameter */
  56. #define STARFIVE_WDT_EARLY_ENA 0
  57. static bool nowayout = WATCHDOG_NOWAYOUT;
  58. static int heartbeat;
  59. static bool early_enable = STARFIVE_WDT_EARLY_ENA;
  60. module_param(heartbeat, int, 0);
  61. module_param(early_enable, bool, 0);
  62. module_param(nowayout, bool, 0);
  63. MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (default="
  64. __MODULE_STRING(STARFIVE_WDT_DEFAULT_TIME) ")");
  65. MODULE_PARM_DESC(early_enable,
  66. "Watchdog is started at boot time if set to 1, default="
  67. __MODULE_STRING(STARFIVE_WDT_EARLY_ENA));
  68. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
  69. __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  70. struct starfive_wdt_variant {
  71. unsigned int control; /* Watchdog Control Resgister for reset enable */
  72. unsigned int load; /* Watchdog Load register */
  73. unsigned int reload; /* Watchdog Reload Control register */
  74. unsigned int enable; /* Watchdog Enable Register */
  75. unsigned int value; /* Watchdog Counter Value Register */
  76. unsigned int int_clr; /* Watchdog Interrupt Clear Register */
  77. unsigned int unlock; /* Watchdog Lock Register */
  78. unsigned int int_status; /* Watchdog Interrupt Status Register */
  79. u32 unlock_key;
  80. char enrst_shift;
  81. char en_shift;
  82. bool intclr_check; /* whether need to check it before clearing interrupt */
  83. char intclr_ava_shift;
  84. bool double_timeout; /* The watchdog need twice timeout to reboot */
  85. };
  86. struct starfive_wdt {
  87. struct watchdog_device wdd;
  88. spinlock_t lock; /* spinlock for register handling */
  89. void __iomem *base;
  90. struct clk *core_clk;
  91. struct clk *apb_clk;
  92. const struct starfive_wdt_variant *variant;
  93. unsigned long freq;
  94. u32 count; /* count of timeout */
  95. u32 reload; /* restore the count */
  96. };
  97. /* Register layout and configuration for the JH7100 */
  98. static const struct starfive_wdt_variant starfive_wdt_jh7100_variant = {
  99. .control = STARFIVE_WDT_JH7100_CONTROL,
  100. .load = STARFIVE_WDT_JH7100_LOAD,
  101. .reload = STARFIVE_WDT_JH7100_RELOAD,
  102. .enable = STARFIVE_WDT_JH7100_EN,
  103. .value = STARFIVE_WDT_JH7100_VALUE,
  104. .int_clr = STARFIVE_WDT_JH7100_INTCLR,
  105. .unlock = STARFIVE_WDT_JH7100_LOCK,
  106. .unlock_key = STARFIVE_WDT_JH7100_UNLOCK_KEY,
  107. .int_status = STARFIVE_WDT_JH7100_INTSTAUS,
  108. .enrst_shift = STARFIVE_WDT_JH7100_RST_EN_SHIFT,
  109. .en_shift = STARFIVE_WDT_EN_SHIFT,
  110. .intclr_check = true,
  111. .intclr_ava_shift = STARFIVE_WDT_JH7100_INTCLR_AVA_SHIFT,
  112. .double_timeout = false,
  113. };
  114. /* Register layout and configuration for the JH7110 */
  115. static const struct starfive_wdt_variant starfive_wdt_jh7110_variant = {
  116. .control = STARFIVE_WDT_JH7110_CONTROL,
  117. .load = STARFIVE_WDT_JH7110_LOAD,
  118. .enable = STARFIVE_WDT_JH7110_CONTROL,
  119. .value = STARFIVE_WDT_JH7110_VALUE,
  120. .int_clr = STARFIVE_WDT_JH7110_INTCLR,
  121. .unlock = STARFIVE_WDT_JH7110_LOCK,
  122. .unlock_key = STARFIVE_WDT_JH7110_UNLOCK_KEY,
  123. .int_status = STARFIVE_WDT_JH7110_IMS,
  124. .enrst_shift = STARFIVE_WDT_JH7110_RST_EN_SHIFT,
  125. .en_shift = STARFIVE_WDT_EN_SHIFT,
  126. .intclr_check = false,
  127. .double_timeout = true,
  128. };
  129. static int starfive_wdt_enable_clock(struct starfive_wdt *wdt)
  130. {
  131. int ret;
  132. ret = clk_prepare_enable(wdt->apb_clk);
  133. if (ret)
  134. return dev_err_probe(wdt->wdd.parent, ret, "failed to enable apb clock\n");
  135. ret = clk_prepare_enable(wdt->core_clk);
  136. if (ret) {
  137. clk_disable_unprepare(wdt->apb_clk);
  138. return dev_err_probe(wdt->wdd.parent, ret, "failed to enable core clock\n");
  139. }
  140. return 0;
  141. }
  142. static void starfive_wdt_disable_clock(struct starfive_wdt *wdt)
  143. {
  144. clk_disable_unprepare(wdt->core_clk);
  145. clk_disable_unprepare(wdt->apb_clk);
  146. }
  147. static inline int starfive_wdt_get_clock(struct starfive_wdt *wdt)
  148. {
  149. struct device *dev = wdt->wdd.parent;
  150. wdt->apb_clk = devm_clk_get(dev, "apb");
  151. if (IS_ERR(wdt->apb_clk))
  152. return dev_err_probe(dev, PTR_ERR(wdt->apb_clk), "failed to get apb clock\n");
  153. wdt->core_clk = devm_clk_get(dev, "core");
  154. if (IS_ERR(wdt->core_clk))
  155. return dev_err_probe(dev, PTR_ERR(wdt->core_clk), "failed to get core clock\n");
  156. return 0;
  157. }
  158. static inline int starfive_wdt_reset_init(struct device *dev)
  159. {
  160. struct reset_control *rsts;
  161. int ret;
  162. rsts = devm_reset_control_array_get_exclusive(dev);
  163. if (IS_ERR(rsts))
  164. return dev_err_probe(dev, PTR_ERR(rsts), "failed to get resets\n");
  165. ret = reset_control_deassert(rsts);
  166. if (ret)
  167. return dev_err_probe(dev, ret, "failed to deassert resets\n");
  168. return 0;
  169. }
  170. static u32 starfive_wdt_ticks_to_sec(struct starfive_wdt *wdt, u32 ticks)
  171. {
  172. return DIV_ROUND_CLOSEST(ticks, wdt->freq);
  173. }
  174. /* Write unlock-key to unlock. Write other value to lock. */
  175. static void starfive_wdt_unlock(struct starfive_wdt *wdt)
  176. __acquires(&wdt->lock)
  177. {
  178. spin_lock(&wdt->lock);
  179. writel(wdt->variant->unlock_key, wdt->base + wdt->variant->unlock);
  180. }
  181. static void starfive_wdt_lock(struct starfive_wdt *wdt)
  182. __releases(&wdt->lock)
  183. {
  184. writel(~wdt->variant->unlock_key, wdt->base + wdt->variant->unlock);
  185. spin_unlock(&wdt->lock);
  186. }
  187. /* enable watchdog interrupt to reset/reboot */
  188. static void starfive_wdt_enable_reset(struct starfive_wdt *wdt)
  189. {
  190. u32 val;
  191. val = readl(wdt->base + wdt->variant->control);
  192. val |= STARFIVE_WDT_RESET_EN << wdt->variant->enrst_shift;
  193. writel(val, wdt->base + wdt->variant->control);
  194. }
  195. /* interrupt status whether has been raised from the counter */
  196. static bool starfive_wdt_raise_irq_status(struct starfive_wdt *wdt)
  197. {
  198. return !!readl(wdt->base + wdt->variant->int_status);
  199. }
  200. /* waiting interrupt can be free to clear */
  201. static int starfive_wdt_wait_int_free(struct starfive_wdt *wdt)
  202. {
  203. u32 value;
  204. return readl_poll_timeout_atomic(wdt->base + wdt->variant->int_clr, value,
  205. !(value & BIT(wdt->variant->intclr_ava_shift)),
  206. STARFIVE_WDT_DELAY_US, STARFIVE_WDT_TIMEOUT_US);
  207. }
  208. /* clear interrupt signal before initialization or reload */
  209. static int starfive_wdt_int_clr(struct starfive_wdt *wdt)
  210. {
  211. int ret;
  212. if (wdt->variant->intclr_check) {
  213. ret = starfive_wdt_wait_int_free(wdt);
  214. if (ret)
  215. return dev_err_probe(wdt->wdd.parent, ret,
  216. "watchdog is not ready to clear interrupt.\n");
  217. }
  218. writel(STARFIVE_WDT_INTCLR, wdt->base + wdt->variant->int_clr);
  219. return 0;
  220. }
  221. static inline void starfive_wdt_set_count(struct starfive_wdt *wdt, u32 val)
  222. {
  223. writel(val, wdt->base + wdt->variant->load);
  224. }
  225. static inline u32 starfive_wdt_get_count(struct starfive_wdt *wdt)
  226. {
  227. return readl(wdt->base + wdt->variant->value);
  228. }
  229. /* enable watchdog */
  230. static inline void starfive_wdt_enable(struct starfive_wdt *wdt)
  231. {
  232. u32 val;
  233. val = readl(wdt->base + wdt->variant->enable);
  234. val |= STARFIVE_WDT_ENABLE << wdt->variant->en_shift;
  235. writel(val, wdt->base + wdt->variant->enable);
  236. }
  237. /* disable watchdog */
  238. static inline void starfive_wdt_disable(struct starfive_wdt *wdt)
  239. {
  240. u32 val;
  241. val = readl(wdt->base + wdt->variant->enable);
  242. val &= ~(STARFIVE_WDT_ENABLE << wdt->variant->en_shift);
  243. writel(val, wdt->base + wdt->variant->enable);
  244. }
  245. static inline void starfive_wdt_set_reload_count(struct starfive_wdt *wdt, u32 count)
  246. {
  247. starfive_wdt_set_count(wdt, count);
  248. /* 7100 need set any value to reload register and could reload value to counter */
  249. if (wdt->variant->reload)
  250. writel(0x1, wdt->base + wdt->variant->reload);
  251. }
  252. static unsigned int starfive_wdt_max_timeout(struct starfive_wdt *wdt)
  253. {
  254. if (wdt->variant->double_timeout)
  255. return DIV_ROUND_UP(STARFIVE_WDT_MAXCNT, (wdt->freq / 2)) - 1;
  256. return DIV_ROUND_UP(STARFIVE_WDT_MAXCNT, wdt->freq) - 1;
  257. }
  258. static unsigned int starfive_wdt_get_timeleft(struct watchdog_device *wdd)
  259. {
  260. struct starfive_wdt *wdt = watchdog_get_drvdata(wdd);
  261. u32 count;
  262. /*
  263. * If the watchdog takes twice timeout and set half count value,
  264. * timeleft value should add the count value before first timeout.
  265. */
  266. count = starfive_wdt_get_count(wdt);
  267. if (wdt->variant->double_timeout && !starfive_wdt_raise_irq_status(wdt))
  268. count += wdt->count;
  269. return starfive_wdt_ticks_to_sec(wdt, count);
  270. }
  271. static int starfive_wdt_keepalive(struct watchdog_device *wdd)
  272. {
  273. struct starfive_wdt *wdt = watchdog_get_drvdata(wdd);
  274. int ret;
  275. starfive_wdt_unlock(wdt);
  276. ret = starfive_wdt_int_clr(wdt);
  277. if (ret)
  278. goto exit;
  279. starfive_wdt_set_reload_count(wdt, wdt->count);
  280. exit:
  281. /* exit with releasing spinlock and locking registers */
  282. starfive_wdt_lock(wdt);
  283. return ret;
  284. }
  285. static int starfive_wdt_start(struct starfive_wdt *wdt)
  286. {
  287. int ret;
  288. starfive_wdt_unlock(wdt);
  289. /* disable watchdog, to be safe */
  290. starfive_wdt_disable(wdt);
  291. starfive_wdt_enable_reset(wdt);
  292. ret = starfive_wdt_int_clr(wdt);
  293. if (ret)
  294. goto exit;
  295. starfive_wdt_set_count(wdt, wdt->count);
  296. starfive_wdt_enable(wdt);
  297. exit:
  298. starfive_wdt_lock(wdt);
  299. return ret;
  300. }
  301. static void starfive_wdt_stop(struct starfive_wdt *wdt)
  302. {
  303. starfive_wdt_unlock(wdt);
  304. starfive_wdt_disable(wdt);
  305. starfive_wdt_lock(wdt);
  306. }
  307. static int starfive_wdt_pm_start(struct watchdog_device *wdd)
  308. {
  309. struct starfive_wdt *wdt = watchdog_get_drvdata(wdd);
  310. int ret = pm_runtime_get_sync(wdd->parent);
  311. if (ret < 0)
  312. return ret;
  313. return starfive_wdt_start(wdt);
  314. }
  315. static int starfive_wdt_pm_stop(struct watchdog_device *wdd)
  316. {
  317. struct starfive_wdt *wdt = watchdog_get_drvdata(wdd);
  318. starfive_wdt_stop(wdt);
  319. return pm_runtime_put_sync(wdd->parent);
  320. }
  321. static int starfive_wdt_set_timeout(struct watchdog_device *wdd,
  322. unsigned int timeout)
  323. {
  324. struct starfive_wdt *wdt = watchdog_get_drvdata(wdd);
  325. unsigned long count = timeout * wdt->freq;
  326. /* some watchdogs take two timeouts to reset */
  327. if (wdt->variant->double_timeout)
  328. count /= 2;
  329. wdt->count = count;
  330. wdd->timeout = timeout;
  331. starfive_wdt_unlock(wdt);
  332. starfive_wdt_disable(wdt);
  333. starfive_wdt_set_reload_count(wdt, wdt->count);
  334. starfive_wdt_enable(wdt);
  335. starfive_wdt_lock(wdt);
  336. return 0;
  337. }
  338. #define STARFIVE_WDT_OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE)
  339. static const struct watchdog_info starfive_wdt_info = {
  340. .options = STARFIVE_WDT_OPTIONS,
  341. .identity = "StarFive Watchdog",
  342. };
  343. static const struct watchdog_ops starfive_wdt_ops = {
  344. .owner = THIS_MODULE,
  345. .start = starfive_wdt_pm_start,
  346. .stop = starfive_wdt_pm_stop,
  347. .ping = starfive_wdt_keepalive,
  348. .set_timeout = starfive_wdt_set_timeout,
  349. .get_timeleft = starfive_wdt_get_timeleft,
  350. };
  351. static int starfive_wdt_probe(struct platform_device *pdev)
  352. {
  353. struct starfive_wdt *wdt;
  354. int ret;
  355. wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
  356. if (!wdt)
  357. return -ENOMEM;
  358. wdt->base = devm_platform_ioremap_resource(pdev, 0);
  359. if (IS_ERR(wdt->base))
  360. return dev_err_probe(&pdev->dev, PTR_ERR(wdt->base), "error mapping registers\n");
  361. wdt->wdd.parent = &pdev->dev;
  362. ret = starfive_wdt_get_clock(wdt);
  363. if (ret)
  364. return ret;
  365. platform_set_drvdata(pdev, wdt);
  366. pm_runtime_enable(&pdev->dev);
  367. if (pm_runtime_enabled(&pdev->dev)) {
  368. ret = pm_runtime_get_sync(&pdev->dev);
  369. if (ret < 0)
  370. return ret;
  371. } else {
  372. /* runtime PM is disabled but clocks need to be enabled */
  373. ret = starfive_wdt_enable_clock(wdt);
  374. if (ret)
  375. return ret;
  376. }
  377. ret = starfive_wdt_reset_init(&pdev->dev);
  378. if (ret)
  379. goto err_exit;
  380. watchdog_set_drvdata(&wdt->wdd, wdt);
  381. wdt->wdd.info = &starfive_wdt_info;
  382. wdt->wdd.ops = &starfive_wdt_ops;
  383. wdt->variant = of_device_get_match_data(&pdev->dev);
  384. spin_lock_init(&wdt->lock);
  385. wdt->freq = clk_get_rate(wdt->core_clk);
  386. if (!wdt->freq) {
  387. dev_err(&pdev->dev, "get clock rate failed.\n");
  388. ret = -EINVAL;
  389. goto err_exit;
  390. }
  391. wdt->wdd.min_timeout = 1;
  392. wdt->wdd.max_timeout = starfive_wdt_max_timeout(wdt);
  393. wdt->wdd.timeout = STARFIVE_WDT_DEFAULT_TIME;
  394. watchdog_init_timeout(&wdt->wdd, heartbeat, &pdev->dev);
  395. starfive_wdt_set_timeout(&wdt->wdd, wdt->wdd.timeout);
  396. watchdog_set_nowayout(&wdt->wdd, nowayout);
  397. watchdog_stop_on_reboot(&wdt->wdd);
  398. watchdog_stop_on_unregister(&wdt->wdd);
  399. if (early_enable) {
  400. ret = starfive_wdt_start(wdt);
  401. if (ret)
  402. goto err_exit;
  403. set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);
  404. } else {
  405. starfive_wdt_stop(wdt);
  406. }
  407. ret = watchdog_register_device(&wdt->wdd);
  408. if (ret)
  409. goto err_exit;
  410. if (!early_enable) {
  411. if (pm_runtime_enabled(&pdev->dev)) {
  412. ret = pm_runtime_put_sync(&pdev->dev);
  413. if (ret)
  414. goto err_exit;
  415. }
  416. }
  417. return 0;
  418. err_exit:
  419. starfive_wdt_disable_clock(wdt);
  420. pm_runtime_disable(&pdev->dev);
  421. return ret;
  422. }
  423. static void starfive_wdt_remove(struct platform_device *pdev)
  424. {
  425. struct starfive_wdt *wdt = platform_get_drvdata(pdev);
  426. starfive_wdt_stop(wdt);
  427. watchdog_unregister_device(&wdt->wdd);
  428. if (pm_runtime_enabled(&pdev->dev))
  429. pm_runtime_disable(&pdev->dev);
  430. else
  431. /* disable clock without PM */
  432. starfive_wdt_disable_clock(wdt);
  433. }
  434. static void starfive_wdt_shutdown(struct platform_device *pdev)
  435. {
  436. struct starfive_wdt *wdt = platform_get_drvdata(pdev);
  437. starfive_wdt_pm_stop(&wdt->wdd);
  438. }
  439. static int starfive_wdt_suspend(struct device *dev)
  440. {
  441. struct starfive_wdt *wdt = dev_get_drvdata(dev);
  442. /* Save watchdog state, and turn it off. */
  443. wdt->reload = starfive_wdt_get_count(wdt);
  444. /* Note that WTCNT doesn't need to be saved. */
  445. starfive_wdt_stop(wdt);
  446. return pm_runtime_force_suspend(dev);
  447. }
  448. static int starfive_wdt_resume(struct device *dev)
  449. {
  450. struct starfive_wdt *wdt = dev_get_drvdata(dev);
  451. int ret;
  452. ret = pm_runtime_force_resume(dev);
  453. if (ret)
  454. return ret;
  455. starfive_wdt_unlock(wdt);
  456. /* Restore watchdog state. */
  457. starfive_wdt_set_reload_count(wdt, wdt->reload);
  458. starfive_wdt_lock(wdt);
  459. if (watchdog_active(&wdt->wdd))
  460. return starfive_wdt_start(wdt);
  461. return 0;
  462. }
  463. static int starfive_wdt_runtime_suspend(struct device *dev)
  464. {
  465. struct starfive_wdt *wdt = dev_get_drvdata(dev);
  466. starfive_wdt_disable_clock(wdt);
  467. return 0;
  468. }
  469. static int starfive_wdt_runtime_resume(struct device *dev)
  470. {
  471. struct starfive_wdt *wdt = dev_get_drvdata(dev);
  472. return starfive_wdt_enable_clock(wdt);
  473. }
  474. static const struct dev_pm_ops starfive_wdt_pm_ops = {
  475. RUNTIME_PM_OPS(starfive_wdt_runtime_suspend, starfive_wdt_runtime_resume, NULL)
  476. SYSTEM_SLEEP_PM_OPS(starfive_wdt_suspend, starfive_wdt_resume)
  477. };
  478. static const struct of_device_id starfive_wdt_match[] = {
  479. { .compatible = "starfive,jh7100-wdt", .data = &starfive_wdt_jh7100_variant },
  480. { .compatible = "starfive,jh7110-wdt", .data = &starfive_wdt_jh7110_variant },
  481. { /* sentinel */ }
  482. };
  483. MODULE_DEVICE_TABLE(of, starfive_wdt_match);
  484. static struct platform_driver starfive_wdt_driver = {
  485. .probe = starfive_wdt_probe,
  486. .remove_new = starfive_wdt_remove,
  487. .shutdown = starfive_wdt_shutdown,
  488. .driver = {
  489. .name = "starfive-wdt",
  490. .pm = pm_ptr(&starfive_wdt_pm_ops),
  491. .of_match_table = starfive_wdt_match,
  492. },
  493. };
  494. module_platform_driver(starfive_wdt_driver);
  495. MODULE_AUTHOR("Xingyu Wu <xingyu.wu@starfivetech.com>");
  496. MODULE_AUTHOR("Samin Guo <samin.guo@starfivetech.com>");
  497. MODULE_DESCRIPTION("StarFive Watchdog Device Driver");
  498. MODULE_LICENSE("GPL");