sunxi.c 2.1 KB

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