setup.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright (C) 2004 Florian Schirmer <jolt@tuxbox.org>
  3. * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
  4. * Copyright (C) 2006 Michael Buesch <m@bues.ch>
  5. * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
  6. * Copyright (C) 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  16. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  17. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  18. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  19. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  22. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. *
  24. * You should have received a copy of the GNU General Public License along
  25. * with this program; if not, write to the Free Software Foundation, Inc.,
  26. * 675 Mass Ave, Cambridge, MA 02139, USA.
  27. */
  28. #include "bcm47xx_private.h"
  29. #include <linux/bcm47xx_sprom.h>
  30. #include <linux/export.h>
  31. #include <linux/types.h>
  32. #include <linux/ethtool.h>
  33. #include <linux/phy.h>
  34. #include <linux/phy_fixed.h>
  35. #include <linux/ssb/ssb.h>
  36. #include <linux/ssb/ssb_embedded.h>
  37. #include <linux/bcma/bcma_soc.h>
  38. #include <asm/bootinfo.h>
  39. #include <asm/idle.h>
  40. #include <asm/prom.h>
  41. #include <asm/reboot.h>
  42. #include <asm/time.h>
  43. #include <bcm47xx.h>
  44. #include <bcm47xx_board.h>
  45. union bcm47xx_bus bcm47xx_bus;
  46. EXPORT_SYMBOL(bcm47xx_bus);
  47. enum bcm47xx_bus_type bcm47xx_bus_type;
  48. EXPORT_SYMBOL(bcm47xx_bus_type);
  49. static void bcm47xx_machine_restart(char *command)
  50. {
  51. pr_alert("Please stand by while rebooting the system...\n");
  52. local_irq_disable();
  53. /* Set the watchdog timer to reset immediately */
  54. switch (bcm47xx_bus_type) {
  55. #ifdef CONFIG_BCM47XX_SSB
  56. case BCM47XX_BUS_TYPE_SSB:
  57. if (bcm47xx_bus.ssb.chip_id == 0x4785)
  58. write_c0_diag4(1 << 22);
  59. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
  60. if (bcm47xx_bus.ssb.chip_id == 0x4785) {
  61. __asm__ __volatile__(
  62. ".set\tmips3\n\t"
  63. "sync\n\t"
  64. "wait\n\t"
  65. ".set\tmips0");
  66. }
  67. break;
  68. #endif
  69. #ifdef CONFIG_BCM47XX_BCMA
  70. case BCM47XX_BUS_TYPE_BCMA:
  71. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
  72. break;
  73. #endif
  74. }
  75. while (1)
  76. cpu_relax();
  77. }
  78. static void bcm47xx_machine_halt(void)
  79. {
  80. /* Disable interrupts and watchdog and spin forever */
  81. local_irq_disable();
  82. switch (bcm47xx_bus_type) {
  83. #ifdef CONFIG_BCM47XX_SSB
  84. case BCM47XX_BUS_TYPE_SSB:
  85. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
  86. break;
  87. #endif
  88. #ifdef CONFIG_BCM47XX_BCMA
  89. case BCM47XX_BUS_TYPE_BCMA:
  90. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
  91. break;
  92. #endif
  93. }
  94. while (1)
  95. cpu_relax();
  96. }
  97. #ifdef CONFIG_BCM47XX_SSB
  98. static void __init bcm47xx_register_ssb(void)
  99. {
  100. int err;
  101. char buf[100];
  102. struct ssb_mipscore *mcore;
  103. err = ssb_bus_host_soc_register(&bcm47xx_bus.ssb, SSB_ENUM_BASE);
  104. if (err)
  105. panic("Failed to initialize SSB bus (err %d)", err);
  106. mcore = &bcm47xx_bus.ssb.mipscore;
  107. if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
  108. if (strstr(buf, "console=ttyS1")) {
  109. struct ssb_serial_port port;
  110. pr_debug("Swapping serial ports!\n");
  111. /* swap serial ports */
  112. memcpy(&port, &mcore->serial_ports[0], sizeof(port));
  113. memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
  114. sizeof(port));
  115. memcpy(&mcore->serial_ports[1], &port, sizeof(port));
  116. }
  117. }
  118. }
  119. #endif
  120. #ifdef CONFIG_BCM47XX_BCMA
  121. static void __init bcm47xx_register_bcma(void)
  122. {
  123. int err;
  124. err = bcma_host_soc_register(&bcm47xx_bus.bcma);
  125. if (err)
  126. panic("Failed to register BCMA bus (err %d)", err);
  127. }
  128. #endif
  129. /*
  130. * Memory setup is done in the early part of MIPS's arch_mem_init. It's supposed
  131. * to detect memory and record it with add_memory_region.
  132. * Any extra initializaion performed here must not use kmalloc or bootmem.
  133. */
  134. void __init plat_mem_setup(void)
  135. {
  136. struct cpuinfo_mips *c = &current_cpu_data;
  137. if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
  138. pr_info("Using bcma bus\n");
  139. #ifdef CONFIG_BCM47XX_BCMA
  140. bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
  141. bcm47xx_register_bcma();
  142. bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
  143. #ifdef CONFIG_HIGHMEM
  144. bcm47xx_prom_highmem_init();
  145. #endif
  146. #endif
  147. } else {
  148. pr_info("Using ssb bus\n");
  149. #ifdef CONFIG_BCM47XX_SSB
  150. bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
  151. bcm47xx_sprom_register_fallbacks();
  152. bcm47xx_register_ssb();
  153. bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
  154. #endif
  155. }
  156. _machine_restart = bcm47xx_machine_restart;
  157. _machine_halt = bcm47xx_machine_halt;
  158. pm_power_off = bcm47xx_machine_halt;
  159. }
  160. /*
  161. * This finishes bus initialization doing things that were not possible without
  162. * kmalloc. Make sure to call it late enough (after mm_init).
  163. */
  164. void __init bcm47xx_bus_setup(void)
  165. {
  166. #ifdef CONFIG_BCM47XX_BCMA
  167. if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA) {
  168. int err;
  169. err = bcma_host_soc_init(&bcm47xx_bus.bcma);
  170. if (err)
  171. panic("Failed to initialize BCMA bus (err %d)", err);
  172. }
  173. #endif
  174. /* With bus initialized we can access NVRAM and detect the board */
  175. bcm47xx_board_detect();
  176. mips_set_machine_name(bcm47xx_board_get_name());
  177. }
  178. static int __init bcm47xx_cpu_fixes(void)
  179. {
  180. switch (bcm47xx_bus_type) {
  181. #ifdef CONFIG_BCM47XX_SSB
  182. case BCM47XX_BUS_TYPE_SSB:
  183. /* Nothing to do */
  184. break;
  185. #endif
  186. #ifdef CONFIG_BCM47XX_BCMA
  187. case BCM47XX_BUS_TYPE_BCMA:
  188. /* The BCM4706 has a problem with the CPU wait instruction.
  189. * When r4k_wait or r4k_wait_irqoff is used will just hang and
  190. * not return from a msleep(). Removing the cpu_wait
  191. * functionality is a workaround for this problem. The BCM4716
  192. * does not have this problem.
  193. */
  194. if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
  195. cpu_wait = NULL;
  196. /*
  197. * BCM47XX Erratum "R10: PCIe Transactions Periodically Fail"
  198. * Enable ExternalSync for sync instruction to take effect
  199. */
  200. set_c0_config7(MIPS_CONF7_ES);
  201. break;
  202. #endif
  203. }
  204. return 0;
  205. }
  206. arch_initcall(bcm47xx_cpu_fixes);
  207. static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
  208. .link = 1,
  209. .speed = SPEED_100,
  210. .duplex = DUPLEX_FULL,
  211. };
  212. static int __init bcm47xx_register_bus_complete(void)
  213. {
  214. switch (bcm47xx_bus_type) {
  215. #ifdef CONFIG_BCM47XX_SSB
  216. case BCM47XX_BUS_TYPE_SSB:
  217. /* Nothing to do */
  218. break;
  219. #endif
  220. #ifdef CONFIG_BCM47XX_BCMA
  221. case BCM47XX_BUS_TYPE_BCMA:
  222. bcma_bus_register(&bcm47xx_bus.bcma.bus);
  223. break;
  224. #endif
  225. }
  226. bcm47xx_buttons_register();
  227. bcm47xx_leds_register();
  228. bcm47xx_workarounds();
  229. fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status, -1);
  230. return 0;
  231. }
  232. device_initcall(bcm47xx_register_bus_complete);