setup.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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/export.h>
  30. #include <linux/types.h>
  31. #include <linux/ethtool.h>
  32. #include <linux/phy.h>
  33. #include <linux/phy_fixed.h>
  34. #include <linux/ssb/ssb.h>
  35. #include <linux/ssb/ssb_embedded.h>
  36. #include <linux/bcma/bcma_soc.h>
  37. #include <asm/bootinfo.h>
  38. #include <asm/idle.h>
  39. #include <asm/prom.h>
  40. #include <asm/reboot.h>
  41. #include <asm/time.h>
  42. #include <bcm47xx.h>
  43. #include <bcm47xx_board.h>
  44. union bcm47xx_bus bcm47xx_bus;
  45. EXPORT_SYMBOL(bcm47xx_bus);
  46. enum bcm47xx_bus_type bcm47xx_bus_type;
  47. EXPORT_SYMBOL(bcm47xx_bus_type);
  48. static void bcm47xx_machine_restart(char *command)
  49. {
  50. pr_alert("Please stand by while rebooting the system...\n");
  51. local_irq_disable();
  52. /* Set the watchdog timer to reset immediately */
  53. switch (bcm47xx_bus_type) {
  54. #ifdef CONFIG_BCM47XX_SSB
  55. case BCM47XX_BUS_TYPE_SSB:
  56. if (bcm47xx_bus.ssb.chip_id == 0x4785)
  57. write_c0_diag4(1 << 22);
  58. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
  59. if (bcm47xx_bus.ssb.chip_id == 0x4785) {
  60. __asm__ __volatile__(
  61. ".set\tmips3\n\t"
  62. "sync\n\t"
  63. "wait\n\t"
  64. ".set\tmips0");
  65. }
  66. break;
  67. #endif
  68. #ifdef CONFIG_BCM47XX_BCMA
  69. case BCM47XX_BUS_TYPE_BCMA:
  70. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
  71. break;
  72. #endif
  73. }
  74. while (1)
  75. cpu_relax();
  76. }
  77. static void bcm47xx_machine_halt(void)
  78. {
  79. /* Disable interrupts and watchdog and spin forever */
  80. local_irq_disable();
  81. switch (bcm47xx_bus_type) {
  82. #ifdef CONFIG_BCM47XX_SSB
  83. case BCM47XX_BUS_TYPE_SSB:
  84. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
  85. break;
  86. #endif
  87. #ifdef CONFIG_BCM47XX_BCMA
  88. case BCM47XX_BUS_TYPE_BCMA:
  89. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
  90. break;
  91. #endif
  92. }
  93. while (1)
  94. cpu_relax();
  95. }
  96. #ifdef CONFIG_BCM47XX_SSB
  97. static int bcm47xx_get_invariants(struct ssb_bus *bus,
  98. struct ssb_init_invariants *iv)
  99. {
  100. char buf[20];
  101. /* Fill boardinfo structure */
  102. memset(&iv->boardinfo, 0 , sizeof(struct ssb_boardinfo));
  103. bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL);
  104. memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
  105. bcm47xx_fill_sprom(&iv->sprom, NULL, false);
  106. if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
  107. iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
  108. return 0;
  109. }
  110. static void __init bcm47xx_register_ssb(void)
  111. {
  112. int err;
  113. char buf[100];
  114. struct ssb_mipscore *mcore;
  115. err = ssb_bus_ssbbus_register(&bcm47xx_bus.ssb, SSB_ENUM_BASE,
  116. bcm47xx_get_invariants);
  117. if (err)
  118. panic("Failed to initialize SSB bus (err %d)", err);
  119. mcore = &bcm47xx_bus.ssb.mipscore;
  120. if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
  121. if (strstr(buf, "console=ttyS1")) {
  122. struct ssb_serial_port port;
  123. pr_debug("Swapping serial ports!\n");
  124. /* swap serial ports */
  125. memcpy(&port, &mcore->serial_ports[0], sizeof(port));
  126. memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
  127. sizeof(port));
  128. memcpy(&mcore->serial_ports[1], &port, sizeof(port));
  129. }
  130. }
  131. }
  132. #endif
  133. #ifdef CONFIG_BCM47XX_BCMA
  134. static void __init bcm47xx_register_bcma(void)
  135. {
  136. int err;
  137. err = bcma_host_soc_register(&bcm47xx_bus.bcma);
  138. if (err)
  139. panic("Failed to register BCMA bus (err %d)", err);
  140. }
  141. #endif
  142. /*
  143. * Memory setup is done in the early part of MIPS's arch_mem_init. It's supposed
  144. * to detect memory and record it with add_memory_region.
  145. * Any extra initializaion performed here must not use kmalloc or bootmem.
  146. */
  147. void __init plat_mem_setup(void)
  148. {
  149. struct cpuinfo_mips *c = &current_cpu_data;
  150. if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
  151. pr_info("Using bcma bus\n");
  152. #ifdef CONFIG_BCM47XX_BCMA
  153. bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
  154. bcm47xx_sprom_register_fallbacks();
  155. bcm47xx_register_bcma();
  156. bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
  157. #ifdef CONFIG_HIGHMEM
  158. bcm47xx_prom_highmem_init();
  159. #endif
  160. #endif
  161. } else {
  162. pr_info("Using ssb bus\n");
  163. #ifdef CONFIG_BCM47XX_SSB
  164. bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
  165. bcm47xx_sprom_register_fallbacks();
  166. bcm47xx_register_ssb();
  167. bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
  168. #endif
  169. }
  170. _machine_restart = bcm47xx_machine_restart;
  171. _machine_halt = bcm47xx_machine_halt;
  172. pm_power_off = bcm47xx_machine_halt;
  173. }
  174. /*
  175. * This finishes bus initialization doing things that were not possible without
  176. * kmalloc. Make sure to call it late enough (after mm_init).
  177. */
  178. void __init bcm47xx_bus_setup(void)
  179. {
  180. #ifdef CONFIG_BCM47XX_BCMA
  181. if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA) {
  182. int err;
  183. err = bcma_host_soc_init(&bcm47xx_bus.bcma);
  184. if (err)
  185. panic("Failed to initialize BCMA bus (err %d)", err);
  186. }
  187. #endif
  188. /* With bus initialized we can access NVRAM and detect the board */
  189. bcm47xx_board_detect();
  190. mips_set_machine_name(bcm47xx_board_get_name());
  191. }
  192. static int __init bcm47xx_cpu_fixes(void)
  193. {
  194. switch (bcm47xx_bus_type) {
  195. #ifdef CONFIG_BCM47XX_SSB
  196. case BCM47XX_BUS_TYPE_SSB:
  197. /* Nothing to do */
  198. break;
  199. #endif
  200. #ifdef CONFIG_BCM47XX_BCMA
  201. case BCM47XX_BUS_TYPE_BCMA:
  202. /* The BCM4706 has a problem with the CPU wait instruction.
  203. * When r4k_wait or r4k_wait_irqoff is used will just hang and
  204. * not return from a msleep(). Removing the cpu_wait
  205. * functionality is a workaround for this problem. The BCM4716
  206. * does not have this problem.
  207. */
  208. if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
  209. cpu_wait = NULL;
  210. break;
  211. #endif
  212. }
  213. return 0;
  214. }
  215. arch_initcall(bcm47xx_cpu_fixes);
  216. static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
  217. .link = 1,
  218. .speed = SPEED_100,
  219. .duplex = DUPLEX_FULL,
  220. };
  221. static int __init bcm47xx_register_bus_complete(void)
  222. {
  223. switch (bcm47xx_bus_type) {
  224. #ifdef CONFIG_BCM47XX_SSB
  225. case BCM47XX_BUS_TYPE_SSB:
  226. /* Nothing to do */
  227. break;
  228. #endif
  229. #ifdef CONFIG_BCM47XX_BCMA
  230. case BCM47XX_BUS_TYPE_BCMA:
  231. bcma_bus_register(&bcm47xx_bus.bcma.bus);
  232. break;
  233. #endif
  234. }
  235. bcm47xx_buttons_register();
  236. bcm47xx_leds_register();
  237. bcm47xx_workarounds();
  238. fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status);
  239. return 0;
  240. }
  241. device_initcall(bcm47xx_register_bus_complete);