reset.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. /* vr9 gphy registers */
  26. #define RCU_GFS_ADD0_XRX200 0x0020
  27. #define RCU_GFS_ADD1_XRX200 0x0068
  28. /* reboot bit */
  29. #define RCU_RD_GPHY0_XRX200 BIT(31)
  30. #define RCU_RD_SRST BIT(30)
  31. #define RCU_RD_GPHY1_XRX200 BIT(29)
  32. /* reset cause */
  33. #define RCU_STAT_SHIFT 26
  34. /* boot selection */
  35. #define RCU_BOOT_SEL(x) ((x >> 18) & 0x7)
  36. #define RCU_BOOT_SEL_XRX200(x) (((x >> 17) & 0xf) | ((x >> 8) & 0x10))
  37. /* remapped base addr of the reset control unit */
  38. static void __iomem *ltq_rcu_membase;
  39. static struct device_node *ltq_rcu_np;
  40. /* This function is used by the watchdog driver */
  41. int ltq_reset_cause(void)
  42. {
  43. u32 val = ltq_rcu_r32(RCU_RST_STAT);
  44. return val >> RCU_STAT_SHIFT;
  45. }
  46. EXPORT_SYMBOL_GPL(ltq_reset_cause);
  47. /* allow platform code to find out what source we booted from */
  48. unsigned char ltq_boot_select(void)
  49. {
  50. u32 val = ltq_rcu_r32(RCU_RST_STAT);
  51. if (of_device_is_compatible(ltq_rcu_np, "lantiq,rcu-xrx200"))
  52. return RCU_BOOT_SEL_XRX200(val);
  53. return RCU_BOOT_SEL(val);
  54. }
  55. /* reset / boot a gphy */
  56. static struct ltq_xrx200_gphy_reset {
  57. u32 rd;
  58. u32 addr;
  59. } xrx200_gphy[] = {
  60. {RCU_RD_GPHY0_XRX200, RCU_GFS_ADD0_XRX200},
  61. {RCU_RD_GPHY1_XRX200, RCU_GFS_ADD1_XRX200},
  62. };
  63. /* reset and boot a gphy. these phys only exist on xrx200 SoC */
  64. int xrx200_gphy_boot(struct device *dev, unsigned int id, dma_addr_t dev_addr)
  65. {
  66. if (!of_device_is_compatible(ltq_rcu_np, "lantiq,rcu-xrx200")) {
  67. dev_err(dev, "this SoC has no GPHY\n");
  68. return -EINVAL;
  69. }
  70. if (id > 1) {
  71. dev_err(dev, "%u is an invalid gphy id\n", id);
  72. return -EINVAL;
  73. }
  74. dev_info(dev, "booting GPHY%u firmware at %X\n", id, dev_addr);
  75. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | xrx200_gphy[id].rd,
  76. RCU_RST_REQ);
  77. ltq_rcu_w32(dev_addr, xrx200_gphy[id].addr);
  78. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~xrx200_gphy[id].rd,
  79. RCU_RST_REQ);
  80. return 0;
  81. }
  82. /* reset a io domain for u micro seconds */
  83. void ltq_reset_once(unsigned int module, ulong u)
  84. {
  85. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | module, RCU_RST_REQ);
  86. udelay(u);
  87. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~module, RCU_RST_REQ);
  88. }
  89. static void ltq_machine_restart(char *command)
  90. {
  91. local_irq_disable();
  92. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | RCU_RD_SRST, RCU_RST_REQ);
  93. unreachable();
  94. }
  95. static void ltq_machine_halt(void)
  96. {
  97. local_irq_disable();
  98. unreachable();
  99. }
  100. static void ltq_machine_power_off(void)
  101. {
  102. local_irq_disable();
  103. unreachable();
  104. }
  105. static int __init mips_reboot_setup(void)
  106. {
  107. struct resource res;
  108. ltq_rcu_np = of_find_compatible_node(NULL, NULL, "lantiq,rcu-xway");
  109. if (!ltq_rcu_np)
  110. ltq_rcu_np = of_find_compatible_node(NULL, NULL,
  111. "lantiq,rcu-xrx200");
  112. /* check if all the reset register range is available */
  113. if (!ltq_rcu_np)
  114. panic("Failed to load reset resources from devicetree");
  115. if (of_address_to_resource(ltq_rcu_np, 0, &res))
  116. panic("Failed to get rcu memory range");
  117. if (request_mem_region(res.start, resource_size(&res), res.name) < 0)
  118. pr_err("Failed to request rcu memory");
  119. ltq_rcu_membase = ioremap_nocache(res.start, resource_size(&res));
  120. if (!ltq_rcu_membase)
  121. panic("Failed to remap core memory");
  122. _machine_restart = ltq_machine_restart;
  123. _machine_halt = ltq_machine_halt;
  124. pm_power_off = ltq_machine_power_off;
  125. return 0;
  126. }
  127. arch_initcall(mips_reboot_setup);