common.c 2.6 KB

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