sunxi.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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/clocksource.h>
  13. #include <linux/delay.h>
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/io.h>
  20. #include <linux/reboot.h>
  21. #include <linux/clk/sunxi.h>
  22. #include <asm/mach/arch.h>
  23. #include <asm/mach/map.h>
  24. #include <asm/system_misc.h>
  25. #define SUN4I_WATCHDOG_CTRL_REG 0x00
  26. #define SUN4I_WATCHDOG_CTRL_RESTART BIT(0)
  27. #define SUN4I_WATCHDOG_MODE_REG 0x04
  28. #define SUN4I_WATCHDOG_MODE_ENABLE BIT(0)
  29. #define SUN4I_WATCHDOG_MODE_RESET_ENABLE BIT(1)
  30. #define SUN6I_WATCHDOG1_IRQ_REG 0x00
  31. #define SUN6I_WATCHDOG1_CTRL_REG 0x10
  32. #define SUN6I_WATCHDOG1_CTRL_RESTART BIT(0)
  33. #define SUN6I_WATCHDOG1_CONFIG_REG 0x14
  34. #define SUN6I_WATCHDOG1_CONFIG_RESTART BIT(0)
  35. #define SUN6I_WATCHDOG1_CONFIG_IRQ BIT(1)
  36. #define SUN6I_WATCHDOG1_MODE_REG 0x18
  37. #define SUN6I_WATCHDOG1_MODE_ENABLE BIT(0)
  38. static void __iomem *wdt_base;
  39. static void sun4i_restart(enum reboot_mode mode, const char *cmd)
  40. {
  41. if (!wdt_base)
  42. return;
  43. /* Enable timer and set reset bit in the watchdog */
  44. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  45. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  46. /*
  47. * Restart the watchdog. The default (and lowest) interval
  48. * value for the watchdog is 0.5s.
  49. */
  50. writel(SUN4I_WATCHDOG_CTRL_RESTART, wdt_base + SUN4I_WATCHDOG_CTRL_REG);
  51. while (1) {
  52. mdelay(5);
  53. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  54. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  55. }
  56. }
  57. static void sun6i_restart(enum reboot_mode mode, const char *cmd)
  58. {
  59. if (!wdt_base)
  60. return;
  61. /* Disable interrupts */
  62. writel(0, wdt_base + SUN6I_WATCHDOG1_IRQ_REG);
  63. /* We want to disable the IRQ and just reset the whole system */
  64. writel(SUN6I_WATCHDOG1_CONFIG_RESTART,
  65. wdt_base + SUN6I_WATCHDOG1_CONFIG_REG);
  66. /* Enable timer. The default and lowest interval value is 0.5s */
  67. writel(SUN6I_WATCHDOG1_MODE_ENABLE,
  68. wdt_base + SUN6I_WATCHDOG1_MODE_REG);
  69. /* Restart the watchdog. */
  70. writel(SUN6I_WATCHDOG1_CTRL_RESTART,
  71. wdt_base + SUN6I_WATCHDOG1_CTRL_REG);
  72. while (1) {
  73. mdelay(5);
  74. writel(SUN6I_WATCHDOG1_MODE_ENABLE,
  75. wdt_base + SUN6I_WATCHDOG1_MODE_REG);
  76. }
  77. }
  78. static struct of_device_id sunxi_restart_ids[] = {
  79. { .compatible = "allwinner,sun4i-wdt", .data = sun4i_restart },
  80. { .compatible = "allwinner,sun6i-wdt", .data = sun6i_restart },
  81. { /*sentinel*/ }
  82. };
  83. static void sunxi_setup_restart(void)
  84. {
  85. const struct of_device_id *of_id;
  86. struct device_node *np;
  87. np = of_find_matching_node(NULL, sunxi_restart_ids);
  88. if (WARN(!np, "unable to setup watchdog restart"))
  89. return;
  90. wdt_base = of_iomap(np, 0);
  91. WARN(!wdt_base, "failed to map watchdog base address");
  92. of_id = of_match_node(sunxi_restart_ids, np);
  93. WARN(!of_id, "restart function not available");
  94. arm_pm_restart = of_id->data;
  95. }
  96. static void __init sunxi_timer_init(void)
  97. {
  98. sunxi_init_clocks();
  99. clocksource_of_init();
  100. }
  101. static void __init sunxi_dt_init(void)
  102. {
  103. sunxi_setup_restart();
  104. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  105. }
  106. static const char * const sunxi_board_dt_compat[] = {
  107. "allwinner,sun4i-a10",
  108. "allwinner,sun5i-a10s",
  109. "allwinner,sun5i-a13",
  110. "allwinner,sun6i-a31",
  111. "allwinner,sun7i-a20",
  112. NULL,
  113. };
  114. DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
  115. .init_machine = sunxi_dt_init,
  116. .init_time = sunxi_timer_init,
  117. .dt_compat = sunxi_board_dt_compat,
  118. MACHINE_END