reset.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_SHIFT 26
  31. #define RCU_BOOT_SEL_MASK 0x7
  32. /* remapped base addr of the reset control unit */
  33. static void __iomem *ltq_rcu_membase;
  34. /* This function is used by the watchdog driver */
  35. int ltq_reset_cause(void)
  36. {
  37. u32 val = ltq_rcu_r32(RCU_RST_STAT);
  38. return val >> RCU_STAT_SHIFT;
  39. }
  40. EXPORT_SYMBOL_GPL(ltq_reset_cause);
  41. /* allow platform code to find out what source we booted from */
  42. unsigned char ltq_boot_select(void)
  43. {
  44. u32 val = ltq_rcu_r32(RCU_RST_STAT);
  45. return (val >> RCU_BOOT_SEL_SHIFT) & RCU_BOOT_SEL_MASK;
  46. }
  47. /* reset a io domain for u micro seconds */
  48. void ltq_reset_once(unsigned int module, ulong u)
  49. {
  50. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | module, RCU_RST_REQ);
  51. udelay(u);
  52. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~module, RCU_RST_REQ);
  53. }
  54. static void ltq_machine_restart(char *command)
  55. {
  56. local_irq_disable();
  57. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | RCU_RD_SRST, RCU_RST_REQ);
  58. unreachable();
  59. }
  60. static void ltq_machine_halt(void)
  61. {
  62. local_irq_disable();
  63. unreachable();
  64. }
  65. static void ltq_machine_power_off(void)
  66. {
  67. local_irq_disable();
  68. unreachable();
  69. }
  70. static int __init mips_reboot_setup(void)
  71. {
  72. struct resource res;
  73. struct device_node *np =
  74. of_find_compatible_node(NULL, NULL, "lantiq,rcu-xway");
  75. /* check if all the reset register range is available */
  76. if (!np)
  77. panic("Failed to load reset resources from devicetree");
  78. if (of_address_to_resource(np, 0, &res))
  79. panic("Failed to get rcu memory range");
  80. if (request_mem_region(res.start, resource_size(&res), res.name) < 0)
  81. pr_err("Failed to request rcu memory");
  82. ltq_rcu_membase = ioremap_nocache(res.start, resource_size(&res));
  83. if (!ltq_rcu_membase)
  84. panic("Failed to remap core memory");
  85. _machine_restart = ltq_machine_restart;
  86. _machine_halt = ltq_machine_halt;
  87. pm_power_off = ltq_machine_power_off;
  88. return 0;
  89. }
  90. arch_initcall(mips_reboot_setup);