sunxi.c 2.2 KB

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