sunxi.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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/sunxi_timer.h>
  20. #include <linux/irqchip/sunxi.h>
  21. #include <asm/mach/arch.h>
  22. #include <asm/mach/map.h>
  23. #include "sunxi.h"
  24. #define WATCHDOG_CTRL_REG 0x00
  25. #define WATCHDOG_CTRL_RESTART (1 << 0)
  26. #define WATCHDOG_MODE_REG 0x04
  27. #define WATCHDOG_MODE_ENABLE (1 << 0)
  28. #define WATCHDOG_MODE_RESET_ENABLE (1 << 1)
  29. static void __iomem *wdt_base;
  30. static void sunxi_setup_restart(void)
  31. {
  32. struct device_node *np = of_find_compatible_node(NULL, NULL,
  33. "allwinner,sunxi-wdt");
  34. if (WARN(!np, "unable to setup watchdog restart"))
  35. return;
  36. wdt_base = of_iomap(np, 0);
  37. WARN(!wdt_base, "failed to map watchdog base address");
  38. }
  39. static void sunxi_restart(char mode, const char *cmd)
  40. {
  41. if (!wdt_base)
  42. return;
  43. /* Enable timer and set reset bit in the watchdog */
  44. writel(WATCHDOG_MODE_ENABLE | WATCHDOG_MODE_RESET_ENABLE,
  45. wdt_base + WATCHDOG_MODE_REG);
  46. /*
  47. * Restart the watchdog. The default (and lowest) interval
  48. * value for the watchdog is 0.5s.
  49. */
  50. writel(WATCHDOG_CTRL_RESTART, wdt_base + WATCHDOG_CTRL_REG);
  51. while (1) {
  52. mdelay(5);
  53. writel(WATCHDOG_MODE_ENABLE | WATCHDOG_MODE_RESET_ENABLE,
  54. wdt_base + WATCHDOG_MODE_REG);
  55. }
  56. }
  57. static struct map_desc sunxi_io_desc[] __initdata = {
  58. {
  59. .virtual = (unsigned long) SUNXI_REGS_VIRT_BASE,
  60. .pfn = __phys_to_pfn(SUNXI_REGS_PHYS_BASE),
  61. .length = SUNXI_REGS_SIZE,
  62. .type = MT_DEVICE,
  63. },
  64. };
  65. void __init sunxi_map_io(void)
  66. {
  67. iotable_init(sunxi_io_desc, ARRAY_SIZE(sunxi_io_desc));
  68. }
  69. static void __init sunxi_dt_init(void)
  70. {
  71. sunxi_setup_restart();
  72. of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
  73. }
  74. static const char * const sunxi_board_dt_compat[] = {
  75. "allwinner,sun4i-a10",
  76. "allwinner,sun5i-a13",
  77. NULL,
  78. };
  79. DT_MACHINE_START(SUNXI_DT, "Allwinner A1X (Device Tree)")
  80. .init_machine = sunxi_dt_init,
  81. .map_io = sunxi_map_io,
  82. .init_irq = sunxi_init_irq,
  83. .handle_irq = sunxi_handle_irq,
  84. .restart = sunxi_restart,
  85. .init_time = &sunxi_timer_init,
  86. .dt_compat = sunxi_board_dt_compat,
  87. MACHINE_END