common.c 2.4 KB

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