common.c 2.2 KB

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