reset.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. struct clk *clk;
  67. if (!of_device_is_compatible(ltq_rcu_np, "lantiq,rcu-xrx200")) {
  68. dev_err(dev, "this SoC has no GPHY\n");
  69. return -EINVAL;
  70. }
  71. clk = clk_get_sys("1f203000.rcu", "gphy");
  72. if (IS_ERR(clk))
  73. return PTR_ERR(clk);
  74. clk_enable(clk);
  75. if (id > 1) {
  76. dev_err(dev, "%u is an invalid gphy id\n", id);
  77. return -EINVAL;
  78. }
  79. dev_info(dev, "booting GPHY%u firmware at %X\n", id, dev_addr);
  80. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | xrx200_gphy[id].rd,
  81. RCU_RST_REQ);
  82. ltq_rcu_w32(dev_addr, xrx200_gphy[id].addr);
  83. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~xrx200_gphy[id].rd,
  84. RCU_RST_REQ);
  85. return 0;
  86. }
  87. /* reset a io domain for u micro seconds */
  88. void ltq_reset_once(unsigned int module, ulong u)
  89. {
  90. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | module, RCU_RST_REQ);
  91. udelay(u);
  92. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) & ~module, RCU_RST_REQ);
  93. }
  94. static void ltq_machine_restart(char *command)
  95. {
  96. local_irq_disable();
  97. ltq_rcu_w32(ltq_rcu_r32(RCU_RST_REQ) | RCU_RD_SRST, RCU_RST_REQ);
  98. unreachable();
  99. }
  100. static void ltq_machine_halt(void)
  101. {
  102. local_irq_disable();
  103. unreachable();
  104. }
  105. static void ltq_machine_power_off(void)
  106. {
  107. local_irq_disable();
  108. unreachable();
  109. }
  110. static int __init mips_reboot_setup(void)
  111. {
  112. struct resource res;
  113. ltq_rcu_np = of_find_compatible_node(NULL, NULL, "lantiq,rcu-xway");
  114. if (!ltq_rcu_np)
  115. ltq_rcu_np = of_find_compatible_node(NULL, NULL,
  116. "lantiq,rcu-xrx200");
  117. /* check if all the reset register range is available */
  118. if (!ltq_rcu_np)
  119. panic("Failed to load reset resources from devicetree");
  120. if (of_address_to_resource(ltq_rcu_np, 0, &res))
  121. panic("Failed to get rcu memory range");
  122. if (request_mem_region(res.start, resource_size(&res), res.name) < 0)
  123. pr_err("Failed to request rcu memory");
  124. ltq_rcu_membase = ioremap_nocache(res.start, resource_size(&res));
  125. if (!ltq_rcu_membase)
  126. panic("Failed to remap core memory");
  127. _machine_restart = ltq_machine_restart;
  128. _machine_halt = ltq_machine_halt;
  129. pm_power_off = ltq_machine_power_off;
  130. return 0;
  131. }
  132. arch_initcall(mips_reboot_setup);