sunxi.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Device Tree support for Allwinner A1X SoCs
  3. *
  4. * Copyright (C) 2012 Maxime Ripard
  5. *
  6. * Maxime Ripard <maxime.ripard@free-electrons.com>
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/delay.h>
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/of_address.h>
  16. #include <linux/of_irq.h>
  17. #include <linux/of_platform.h>
  18. #include <linux/io.h>
  19. #include <linux/reboot.h>
  20. #include <asm/mach/arch.h>
  21. #include <asm/mach/map.h>
  22. #include <asm/system_misc.h>
  23. #define SUN4I_WATCHDOG_CTRL_REG 0x00
  24. #define SUN4I_WATCHDOG_CTRL_RESTART BIT(0)
  25. #define SUN4I_WATCHDOG_MODE_REG 0x04
  26. #define SUN4I_WATCHDOG_MODE_ENABLE BIT(0)
  27. #define SUN4I_WATCHDOG_MODE_RESET_ENABLE BIT(1)
  28. #define SUN6I_WATCHDOG1_IRQ_REG 0x00
  29. #define SUN6I_WATCHDOG1_CTRL_REG 0x10
  30. #define SUN6I_WATCHDOG1_CTRL_RESTART BIT(0)
  31. #define SUN6I_WATCHDOG1_CONFIG_REG 0x14
  32. #define SUN6I_WATCHDOG1_CONFIG_RESTART BIT(0)
  33. #define SUN6I_WATCHDOG1_CONFIG_IRQ BIT(1)
  34. #define SUN6I_WATCHDOG1_MODE_REG 0x18
  35. #define SUN6I_WATCHDOG1_MODE_ENABLE BIT(0)
  36. static void __iomem *wdt_base;
  37. static void sun4i_restart(enum reboot_mode mode, const char *cmd)
  38. {
  39. if (!wdt_base)
  40. return;
  41. /* Enable timer and set reset bit in the watchdog */
  42. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  43. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  44. /*
  45. * Restart the watchdog. The default (and lowest) interval
  46. * value for the watchdog is 0.5s.
  47. */
  48. writel(SUN4I_WATCHDOG_CTRL_RESTART, wdt_base + SUN4I_WATCHDOG_CTRL_REG);
  49. while (1) {
  50. mdelay(5);
  51. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  52. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  53. }
  54. }
  55. static void sun6i_restart(enum reboot_mode mode, const char *cmd)
  56. {
  57. if (!wdt_base)
  58. return;
  59. /* Disable interrupts */
  60. writel(0, wdt_base + SUN6I_WATCHDOG1_IRQ_REG);
  61. /* We want to disable the IRQ and just reset the whole system */
  62. writel(SUN6I_WATCHDOG1_CONFIG_RESTART,
  63. wdt_base + SUN6I_WATCHDOG1_CONFIG_REG);
  64. /* Enable timer. The default and lowest interval value is 0.5s */
  65. writel(SUN6I_WATCHDOG1_MODE_ENABLE,
  66. wdt_base + SUN6I_WATCHDOG1_MODE_REG);
  67. /* Restart the watchdog. */
  68. writel(SUN6I_WATCHDOG1_CTRL_RESTART,
  69. wdt_base + SUN6I_WATCHDOG1_CTRL_REG);
  70. while (1) {
  71. mdelay(5);
  72. writel(SUN6I_WATCHDOG1_MODE_ENABLE,
  73. wdt_base + SUN6I_WATCHDOG1_MODE_REG);
  74. }
  75. }
  76. static struct of_device_id sunxi_restart_ids[] = {
  77. { .compatible = "allwinner,sun4i-wdt" },
  78. { .compatible = "allwinner,sun6i-wdt" },
  79. { /*sentinel*/ }
  80. };
  81. static void sunxi_setup_restart(void)
  82. {
  83. struct device_node *np;
  84. np = of_find_matching_node(NULL, sunxi_restart_ids);
  85. if (WARN(!np, "unable to setup watchdog restart"))
  86. return;
  87. wdt_base = of_iomap(np, 0);
  88. WARN(!wdt_base, "failed to map watchdog base address");
  89. }
  90. static void __init sunxi_dt_init(void)
  91. {
  92. sunxi_setup_restart();
  93. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  94. }
  95. static const char * const sunxi_board_dt_compat[] = {
  96. "allwinner,sun4i-a10",
  97. "allwinner,sun5i-a10s",
  98. "allwinner,sun5i-a13",
  99. NULL,
  100. };
  101. DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
  102. .init_machine = sunxi_dt_init,
  103. .dt_compat = sunxi_board_dt_compat,
  104. .restart = sun4i_restart,
  105. MACHINE_END
  106. static const char * const sun6i_board_dt_compat[] = {
  107. "allwinner,sun6i-a31",
  108. NULL,
  109. };
  110. DT_MACHINE_START(SUN6I_DT, "Allwinner sun6i (A31) Family")
  111. .init_machine = sunxi_dt_init,
  112. .dt_compat = sun6i_board_dt_compat,
  113. .restart = sun6i_restart,
  114. MACHINE_END
  115. static const char * const sun7i_board_dt_compat[] = {
  116. "allwinner,sun7i-a20",
  117. NULL,
  118. };
  119. DT_MACHINE_START(SUN7I_DT, "Allwinner sun7i (A20) Family")
  120. .init_machine = sunxi_dt_init,
  121. .dt_compat = sun7i_board_dt_compat,
  122. .restart = sun4i_restart,
  123. MACHINE_END