reset.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * This program is free software; you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License version 2 as published
  4. * by the Free Software Foundation.
  5. *
  6. * Copyright (C) 2010 John Crispin <blogic@openwrt.org>
  7. */
  8. #include <linux/init.h>
  9. #include <linux/io.h>
  10. #include <linux/ioport.h>
  11. #include <linux/pm.h>
  12. #include <linux/export.h>
  13. #include <linux/delay.h>
  14. #include <linux/of_address.h>
  15. #include <linux/of_platform.h>
  16. #include <asm/reboot.h>
  17. #include <lantiq_soc.h>
  18. #include "../prom.h"
  19. #define ltq_rcu_w32(x, y) ltq_w32((x), ltq_rcu_membase + (y))
  20. #define ltq_rcu_r32(x) ltq_r32(ltq_rcu_membase + (x))
  21. /* reset request register */
  22. #define RCU_RST_REQ 0x0010
  23. /* reset status register */
  24. #define RCU_RST_STAT 0x0014
  25. /* reboot bit */
  26. #define RCU_RD_SRST BIT(30)
  27. /* reset cause */
  28. #define RCU_STAT_SHIFT 26
  29. /* boot selection */
  30. #define RCU_BOOT_SEL(x) ((x >> 18) & 0x7)
  31. #define RCU_BOOT_SEL_XRX200(x) (((x >> 17) & 0xf) | ((x >> 8) & 0x10))
  32. /* remapped base addr of the reset control unit */
  33. static void __iomem *ltq_rcu_membase;
  34. static struct device_node *ltq_rcu_np;
  35. /* This function is used by the watchdog driver */
  36. int ltq_reset_cause(void)
  37. {
  38. u32 val = ltq_rcu_r32(RCU_RST_STAT);
  39. return val >> RCU_STAT_SHIFT;
  40. }
  41. EXPORT_SYMBOL_GPL(ltq_reset_cause);
  42. /* allow platform code to find out what source we booted from */
  43. unsigned char ltq_boot_select(void)
  44. {
  45. u32 val = ltq_rcu_r32(RCU_RST_STAT);
  46. if (of_device_is_compatible(ltq_rcu_np, "lantiq,rcu-xrx200"))
  47. return RCU_BOOT_SEL_XRX200(val);
  48. return RCU_BOOT_SEL(val);
  49. }
  50. /* reset a io domain for u micro seconds */
  51. void ltq_reset_once(unsigned int module, ulong u)
  52. {
  53. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | module, RCU_RST_REQ);
  54. udelay(u);
  55. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~module, RCU_RST_REQ);
  56. }
  57. static void ltq_machine_restart(char *command)
  58. {
  59. local_irq_disable();
  60. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | RCU_RD_SRST, RCU_RST_REQ);
  61. unreachable();
  62. }
  63. static void ltq_machine_halt(void)
  64. {
  65. local_irq_disable();
  66. unreachable();
  67. }
  68. static void ltq_machine_power_off(void)
  69. {
  70. local_irq_disable();
  71. unreachable();
  72. }
  73. static int __init mips_reboot_setup(void)
  74. {
  75. struct resource res;
  76. ltq_rcu_np = of_find_compatible_node(NULL, NULL, "lantiq,rcu-xway");
  77. if (!ltq_rcu_np)
  78. ltq_rcu_np = of_find_compatible_node(NULL, NULL,
  79. "lantiq,rcu-xrx200");
  80. /* check if all the reset register range is available */
  81. if (!ltq_rcu_np)
  82. panic("Failed to load reset resources from devicetree");
  83. if (of_address_to_resource(ltq_rcu_np, 0, &res))
  84. panic("Failed to get rcu memory range");
  85. if (request_mem_region(res.start, resource_size(&res), res.name) < 0)
  86. pr_err("Failed to request rcu memory");
  87. ltq_rcu_membase = ioremap_nocache(res.start, resource_size(&res));
  88. if (!ltq_rcu_membase)
  89. panic("Failed to remap core memory");
  90. _machine_restart = ltq_machine_restart;
  91. _machine_halt = ltq_machine_halt;
  92. pm_power_off = ltq_machine_power_off;
  93. return 0;
  94. }
  95. arch_initcall(mips_reboot_setup);