common.c 2.1 KB

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