sunxi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/irqchip.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_irq.h>
  19. #include <linux/of_platform.h>
  20. #include <linux/io.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. #include "sunxi.h"
  26. #define SUN4I_WATCHDOG_CTRL_REG 0x00
  27. #define SUN4I_WATCHDOG_CTRL_RESTART (1 << 0)
  28. #define SUN4I_WATCHDOG_MODE_REG 0x04
  29. #define SUN4I_WATCHDOG_MODE_ENABLE (1 << 0)
  30. #define SUN4I_WATCHDOG_MODE_RESET_ENABLE (1 << 1)
  31. static void __iomem *wdt_base;
  32. static void sun4i_restart(char mode, const char *cmd)
  33. {
  34. if (!wdt_base)
  35. return;
  36. /* Enable timer and set reset bit in the watchdog */
  37. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  38. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  39. /*
  40. * Restart the watchdog. The default (and lowest) interval
  41. * value for the watchdog is 0.5s.
  42. */
  43. writel(SUN4I_WATCHDOG_CTRL_RESTART, wdt_base + SUN4I_WATCHDOG_CTRL_REG);
  44. while (1) {
  45. mdelay(5);
  46. writel(SUN4I_WATCHDOG_MODE_ENABLE | SUN4I_WATCHDOG_MODE_RESET_ENABLE,
  47. wdt_base + SUN4I_WATCHDOG_MODE_REG);
  48. }
  49. }
  50. static struct of_device_id sunxi_restart_ids[] = {
  51. { .compatible = "allwinner,sun4i-wdt", .data = sun4i_restart },
  52. { /*sentinel*/ }
  53. };
  54. static void sunxi_setup_restart(void)
  55. {
  56. const struct of_device_id *of_id;
  57. struct device_node *np;
  58. np = of_find_matching_node(NULL, sunxi_restart_ids);
  59. if (WARN(!np, "unable to setup watchdog restart"))
  60. return;
  61. wdt_base = of_iomap(np, 0);
  62. WARN(!wdt_base, "failed to map watchdog base address");
  63. of_id = of_match_node(sunxi_restart_ids, np);
  64. WARN(!of_id, "restart function not available");
  65. arm_pm_restart = of_id->data;
  66. }
  67. static struct map_desc sunxi_io_desc[] __initdata = {
  68. {
  69. .virtual = (unsigned long) SUNXI_REGS_VIRT_BASE,
  70. .pfn = __phys_to_pfn(SUNXI_REGS_PHYS_BASE),
  71. .length = SUNXI_REGS_SIZE,
  72. .type = MT_DEVICE,
  73. },
  74. };
  75. void __init sunxi_map_io(void)
  76. {
  77. iotable_init(sunxi_io_desc, ARRAY_SIZE(sunxi_io_desc));
  78. }
  79. static void __init sunxi_timer_init(void)
  80. {
  81. sunxi_init_clocks();
  82. clocksource_of_init();
  83. }
  84. static void __init sunxi_dt_init(void)
  85. {
  86. sunxi_setup_restart();
  87. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  88. }
  89. static const char * const sunxi_board_dt_compat[] = {
  90. "allwinner,sun4i-a10",
  91. "allwinner,sun5i-a13",
  92. NULL,
  93. };
  94. DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
  95. .init_machine = sunxi_dt_init,
  96. .map_io = sunxi_map_io,
  97. .init_irq = irqchip_init,
  98. .init_time = sunxi_timer_init,
  99. .dt_compat = sunxi_board_dt_compat,
  100. MACHINE_END