bcm2835.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2010 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. */
  14. #include <linux/delay.h>
  15. #include <linux/init.h>
  16. #include <linux/irqchip/bcm2835.h>
  17. #include <linux/of_address.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/clk/bcm2835.h>
  20. #include <linux/clocksource.h>
  21. #include <asm/mach/arch.h>
  22. #include <asm/mach/map.h>
  23. #define PM_RSTC 0x1c
  24. #define PM_RSTS 0x20
  25. #define PM_WDOG 0x24
  26. #define PM_PASSWORD 0x5a000000
  27. #define PM_RSTC_WRCFG_MASK 0x00000030
  28. #define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  29. #define PM_RSTS_HADWRH_SET 0x00000040
  30. #define BCM2835_PERIPH_PHYS 0x20000000
  31. #define BCM2835_PERIPH_VIRT 0xf0000000
  32. #define BCM2835_PERIPH_SIZE SZ_16M
  33. static void __iomem *wdt_regs;
  34. /*
  35. * The machine restart method can be called from an atomic context so we won't
  36. * be able to ioremap the regs then.
  37. */
  38. static void bcm2835_setup_restart(void)
  39. {
  40. struct device_node *np = of_find_compatible_node(NULL, NULL,
  41. "brcm,bcm2835-pm-wdt");
  42. if (WARN(!np, "unable to setup watchdog restart"))
  43. return;
  44. wdt_regs = of_iomap(np, 0);
  45. WARN(!wdt_regs, "failed to remap watchdog regs");
  46. }
  47. static void bcm2835_restart(enum reboot_mode mode, const char *cmd)
  48. {
  49. u32 val;
  50. if (!wdt_regs)
  51. return;
  52. /* use a timeout of 10 ticks (~150us) */
  53. writel_relaxed(10 | PM_PASSWORD, wdt_regs + PM_WDOG);
  54. val = readl_relaxed(wdt_regs + PM_RSTC);
  55. val &= ~PM_RSTC_WRCFG_MASK;
  56. val |= PM_PASSWORD | PM_RSTC_WRCFG_FULL_RESET;
  57. writel_relaxed(val, wdt_regs + PM_RSTC);
  58. /* No sleeping, possibly atomic. */
  59. mdelay(1);
  60. }
  61. /*
  62. * We can't really power off, but if we do the normal reset scheme, and
  63. * indicate to bootcode.bin not to reboot, then most of the chip will be
  64. * powered off.
  65. */
  66. static void bcm2835_power_off(void)
  67. {
  68. u32 val;
  69. /*
  70. * We set the watchdog hard reset bit here to distinguish this reset
  71. * from the normal (full) reset. bootcode.bin will not reboot after a
  72. * hard reset.
  73. */
  74. val = readl_relaxed(wdt_regs + PM_RSTS);
  75. val &= ~PM_RSTC_WRCFG_MASK;
  76. val |= PM_PASSWORD | PM_RSTS_HADWRH_SET;
  77. writel_relaxed(val, wdt_regs + PM_RSTS);
  78. /* Continue with normal reset mechanism */
  79. bcm2835_restart(REBOOT_HARD, "");
  80. }
  81. static struct map_desc io_map __initdata = {
  82. .virtual = BCM2835_PERIPH_VIRT,
  83. .pfn = __phys_to_pfn(BCM2835_PERIPH_PHYS),
  84. .length = BCM2835_PERIPH_SIZE,
  85. .type = MT_DEVICE
  86. };
  87. static void __init bcm2835_map_io(void)
  88. {
  89. iotable_init(&io_map, 1);
  90. }
  91. static void __init bcm2835_init(void)
  92. {
  93. int ret;
  94. bcm2835_setup_restart();
  95. if (wdt_regs)
  96. pm_power_off = bcm2835_power_off;
  97. bcm2835_init_clocks();
  98. ret = of_platform_populate(NULL, of_default_bus_match_table, NULL,
  99. NULL);
  100. if (ret) {
  101. pr_err("of_platform_populate failed: %d\n", ret);
  102. BUG();
  103. }
  104. }
  105. static const char * const bcm2835_compat[] = {
  106. "brcm,bcm2835",
  107. NULL
  108. };
  109. DT_MACHINE_START(BCM2835, "BCM2835")
  110. .map_io = bcm2835_map_io,
  111. .init_irq = bcm2835_init_irq,
  112. .handle_irq = bcm2835_handle_irq,
  113. .init_machine = bcm2835_init,
  114. .init_time = clocksource_of_init,
  115. .restart = bcm2835_restart,
  116. .dt_compat = bcm2835_compat
  117. MACHINE_END