common.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2011 Picochip Ltd., Jamie Iles
  4. *
  5. * All enquiries to support@picochip.com
  6. */
  7. #include <linux/delay.h>
  8. #include <linux/of.h>
  9. #include <linux/of_address.h>
  10. #include <linux/reboot.h>
  11. #include <asm/mach/arch.h>
  12. #include <asm/mach/map.h>
  13. #define PHYS_TO_IO(x) (((x) & 0x00ffffff) | 0xfe000000)
  14. #define PICOXCELL_PERIPH_BASE 0x80000000
  15. #define PICOXCELL_PERIPH_LENGTH SZ_4M
  16. #define WDT_CTRL_REG_EN_MASK (1 << 0)
  17. #define WDT_CTRL_REG_OFFS (0x00)
  18. #define WDT_TIMEOUT_REG_OFFS (0x04)
  19. static void __iomem *wdt_regs;
  20. /*
  21. * The machine restart method can be called from an atomic context so we won't
  22. * be able to ioremap the regs then.
  23. */
  24. static void picoxcell_setup_restart(void)
  25. {
  26. struct device_node *np = of_find_compatible_node(NULL, NULL,
  27. "snps,dw-apb-wdg");
  28. if (WARN(!np, "unable to setup watchdog restart"))
  29. return;
  30. wdt_regs = of_iomap(np, 0);
  31. WARN(!wdt_regs, "failed to remap watchdog regs");
  32. }
  33. static struct map_desc io_map __initdata = {
  34. .virtual = PHYS_TO_IO(PICOXCELL_PERIPH_BASE),
  35. .pfn = __phys_to_pfn(PICOXCELL_PERIPH_BASE),
  36. .length = PICOXCELL_PERIPH_LENGTH,
  37. .type = MT_DEVICE,
  38. };
  39. static void __init picoxcell_map_io(void)
  40. {
  41. iotable_init(&io_map, 1);
  42. }
  43. static void __init picoxcell_init_machine(void)
  44. {
  45. picoxcell_setup_restart();
  46. }
  47. static const char *picoxcell_dt_match[] = {
  48. "picochip,pc3x2",
  49. "picochip,pc3x3",
  50. NULL
  51. };
  52. static void picoxcell_wdt_restart(enum reboot_mode mode, const char *cmd)
  53. {
  54. /*
  55. * Configure the watchdog to reset with the shortest possible timeout
  56. * and give it chance to do the reset.
  57. */
  58. if (wdt_regs) {
  59. writel_relaxed(WDT_CTRL_REG_EN_MASK, wdt_regs + WDT_CTRL_REG_OFFS);
  60. writel_relaxed(0, wdt_regs + WDT_TIMEOUT_REG_OFFS);
  61. /* No sleeping, possibly atomic. */
  62. mdelay(500);
  63. }
  64. }
  65. DT_MACHINE_START(PICOXCELL, "Picochip picoXcell")
  66. .map_io = picoxcell_map_io,
  67. .init_machine = picoxcell_init_machine,
  68. .dt_compat = picoxcell_dt_match,
  69. .restart = picoxcell_wdt_restart,
  70. MACHINE_END