sunxi.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 (1 << 0)
  27. #define SUN4I_WATCHDOG_MODE_REG 0x04
  28. #define SUN4I_WATCHDOG_MODE_ENABLE (1 << 0)
  29. #define SUN4I_WATCHDOG_MODE_RESET_ENABLE (1 << 1)
  30. static void __iomem *wdt_base;
  31. static void sun4i_restart(enum reboot_mode mode, const char *cmd)
  32. {
  33. if (!wdt_base)
  34. return;
  35. /* Enable timer and set reset bit in the watchdog */
  36. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  37. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  38. /*
  39. * Restart the watchdog. The default (and lowest) interval
  40. * value for the watchdog is 0.5s.
  41. */
  42. writel(SUN4I_WATCHDOG_CTRL_RESTART, wdt_base + SUN4I_WATCHDOG_CTRL_REG);
  43. while (1) {
  44. mdelay(5);
  45. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  46. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  47. }
  48. }
  49. static struct of_device_id sunxi_restart_ids[] = {
  50. { .compatible = "allwinner,sun4i-wdt", .data = sun4i_restart },
  51. { /*sentinel*/ }
  52. };
  53. static void sunxi_setup_restart(void)
  54. {
  55. const struct of_device_id *of_id;
  56. struct device_node *np;
  57. np = of_find_matching_node(NULL, sunxi_restart_ids);
  58. if (WARN(!np, "unable to setup watchdog restart"))
  59. return;
  60. wdt_base = of_iomap(np, 0);
  61. WARN(!wdt_base, "failed to map watchdog base address");
  62. of_id = of_match_node(sunxi_restart_ids, np);
  63. WARN(!of_id, "restart function not available");
  64. arm_pm_restart = of_id->data;
  65. }
  66. static void __init sunxi_timer_init(void)
  67. {
  68. sunxi_init_clocks();
  69. clocksource_of_init();
  70. }
  71. static void __init sunxi_dt_init(void)
  72. {
  73. sunxi_setup_restart();
  74. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  75. }
  76. static const char * const sunxi_board_dt_compat[] = {
  77. "allwinner,sun4i-a10",
  78. "allwinner,sun5i-a10s",
  79. "allwinner,sun5i-a13",
  80. NULL,
  81. };
  82. DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
  83. .init_machine = sunxi_dt_init,
  84. .init_time = sunxi_timer_init,
  85. .dt_compat = sunxi_board_dt_compat,
  86. MACHINE_END