watchdog-reset.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-2.0
  2. //
  3. // Copyright (c) 2008 Simtec Electronics
  4. // Ben Dooks <ben@simtec.co.uk>
  5. //
  6. // Copyright (c) 2013 Tomasz Figa <tomasz.figa@gmail.com>
  7. //
  8. // Watchdog reset support for Samsung SoCs.
  9. #include <linux/clk.h>
  10. #include <linux/err.h>
  11. #include <linux/io.h>
  12. #include <linux/delay.h>
  13. #include <linux/of.h>
  14. #include <linux/of_address.h>
  15. #define S3C2410_WTCON 0x00
  16. #define S3C2410_WTDAT 0x04
  17. #define S3C2410_WTCNT 0x08
  18. #define S3C2410_WTCON_ENABLE (1 << 5)
  19. #define S3C2410_WTCON_DIV16 (0 << 3)
  20. #define S3C2410_WTCON_RSTEN (1 << 0)
  21. #define S3C2410_WTCON_PRESCALE(x) ((x) << 8)
  22. static void __iomem *wdt_base;
  23. static struct clk *wdt_clock;
  24. void samsung_wdt_reset(void)
  25. {
  26. if (!wdt_base) {
  27. pr_err("%s: wdt reset not initialized\n", __func__);
  28. /* delay to allow the serial port to show the message */
  29. mdelay(50);
  30. return;
  31. }
  32. if (!IS_ERR(wdt_clock))
  33. clk_prepare_enable(wdt_clock);
  34. /* disable watchdog, to be safe */
  35. __raw_writel(0, wdt_base + S3C2410_WTCON);
  36. /* put initial values into count and data */
  37. __raw_writel(0x80, wdt_base + S3C2410_WTCNT);
  38. __raw_writel(0x80, wdt_base + S3C2410_WTDAT);
  39. /* set the watchdog to go and reset... */
  40. __raw_writel(S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV16 |
  41. S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE(0x20),
  42. wdt_base + S3C2410_WTCON);
  43. /* wait for reset to assert... */
  44. mdelay(500);
  45. pr_err("Watchdog reset failed to assert reset\n");
  46. /* delay to allow the serial port to show the message */
  47. mdelay(50);
  48. }
  49. #ifdef CONFIG_OF
  50. static const struct of_device_id s3c2410_wdt_match[] = {
  51. { .compatible = "samsung,s3c2410-wdt" },
  52. { .compatible = "samsung,s3c6410-wdt" },
  53. {},
  54. };
  55. void __init samsung_wdt_reset_of_init(void)
  56. {
  57. struct device_node *np;
  58. np = of_find_matching_node(NULL, s3c2410_wdt_match);
  59. if (!np) {
  60. pr_err("%s: failed to find watchdog node\n", __func__);
  61. return;
  62. }
  63. wdt_base = of_iomap(np, 0);
  64. if (!wdt_base) {
  65. pr_err("%s: failed to map watchdog registers\n", __func__);
  66. return;
  67. }
  68. wdt_clock = of_clk_get(np, 0);
  69. }
  70. #endif
  71. void __init samsung_wdt_reset_init(void __iomem *base)
  72. {
  73. wdt_base = base;
  74. wdt_clock = clk_get(NULL, "watchdog");
  75. }