setup.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. int len, err;
  102. /* Fill boardinfo structure */
  103. memset(&iv->boardinfo, 0 , sizeof(struct ssb_boardinfo));
  104. len = bcm47xx_nvram_getenv("boardvendor", buf, sizeof(buf));
  105. if (len > 0) {
  106. err = kstrtou16(strim(buf), 0, &iv->boardinfo.vendor);
  107. if (err)
  108. pr_warn("Couldn't parse nvram board vendor entry with value \"%s\"\n",
  109. buf);
  110. }
  111. if (!iv->boardinfo.vendor)
  112. iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
  113. len = bcm47xx_nvram_getenv("boardtype", buf, sizeof(buf));
  114. if (len > 0) {
  115. err = kstrtou16(strim(buf), 0, &iv->boardinfo.type);
  116. if (err)
  117. pr_warn("Couldn't parse nvram board type entry with value \"%s\"\n",
  118. buf);
  119. }
  120. memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
  121. bcm47xx_fill_sprom(&iv->sprom, NULL, false);
  122. if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
  123. iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
  124. return 0;
  125. }
  126. static void __init bcm47xx_register_ssb(void)
  127. {
  128. int err;
  129. char buf[100];
  130. struct ssb_mipscore *mcore;
  131. err = ssb_bus_ssbbus_register(&bcm47xx_bus.ssb, SSB_ENUM_BASE,
  132. bcm47xx_get_invariants);
  133. if (err)
  134. panic("Failed to initialize SSB bus (err %d)", err);
  135. mcore = &bcm47xx_bus.ssb.mipscore;
  136. if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
  137. if (strstr(buf, "console=ttyS1")) {
  138. struct ssb_serial_port port;
  139. pr_debug("Swapping serial ports!\n");
  140. /* swap serial ports */
  141. memcpy(&port, &mcore->serial_ports[0], sizeof(port));
  142. memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
  143. sizeof(port));
  144. memcpy(&mcore->serial_ports[1], &port, sizeof(port));
  145. }
  146. }
  147. }
  148. #endif
  149. #ifdef CONFIG_BCM47XX_BCMA
  150. static void __init bcm47xx_register_bcma(void)
  151. {
  152. int err;
  153. err = bcma_host_soc_register(&bcm47xx_bus.bcma);
  154. if (err)
  155. panic("Failed to register BCMA bus (err %d)", err);
  156. }
  157. #endif
  158. /*
  159. * Memory setup is done in the early part of MIPS's arch_mem_init. It's supposed
  160. * to detect memory and record it with add_memory_region.
  161. * Any extra initializaion performed here must not use kmalloc or bootmem.
  162. */
  163. void __init plat_mem_setup(void)
  164. {
  165. struct cpuinfo_mips *c = &current_cpu_data;
  166. if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
  167. pr_info("Using bcma bus\n");
  168. #ifdef CONFIG_BCM47XX_BCMA
  169. bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
  170. bcm47xx_sprom_register_fallbacks();
  171. bcm47xx_register_bcma();
  172. bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
  173. #ifdef CONFIG_HIGHMEM
  174. bcm47xx_prom_highmem_init();
  175. #endif
  176. #endif
  177. } else {
  178. pr_info("Using ssb bus\n");
  179. #ifdef CONFIG_BCM47XX_SSB
  180. bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
  181. bcm47xx_sprom_register_fallbacks();
  182. bcm47xx_register_ssb();
  183. bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
  184. #endif
  185. }
  186. _machine_restart = bcm47xx_machine_restart;
  187. _machine_halt = bcm47xx_machine_halt;
  188. pm_power_off = bcm47xx_machine_halt;
  189. }
  190. /*
  191. * This finishes bus initialization doing things that were not possible without
  192. * kmalloc. Make sure to call it late enough (after mm_init).
  193. */
  194. void __init bcm47xx_bus_setup(void)
  195. {
  196. #ifdef CONFIG_BCM47XX_BCMA
  197. if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA) {
  198. int err;
  199. err = bcma_host_soc_init(&bcm47xx_bus.bcma);
  200. if (err)
  201. panic("Failed to initialize BCMA bus (err %d)", err);
  202. }
  203. #endif
  204. /* With bus initialized we can access NVRAM and detect the board */
  205. bcm47xx_board_detect();
  206. mips_set_machine_name(bcm47xx_board_get_name());
  207. }
  208. static int __init bcm47xx_cpu_fixes(void)
  209. {
  210. switch (bcm47xx_bus_type) {
  211. #ifdef CONFIG_BCM47XX_SSB
  212. case BCM47XX_BUS_TYPE_SSB:
  213. /* Nothing to do */
  214. break;
  215. #endif
  216. #ifdef CONFIG_BCM47XX_BCMA
  217. case BCM47XX_BUS_TYPE_BCMA:
  218. /* The BCM4706 has a problem with the CPU wait instruction.
  219. * When r4k_wait or r4k_wait_irqoff is used will just hang and
  220. * not return from a msleep(). Removing the cpu_wait
  221. * functionality is a workaround for this problem. The BCM4716
  222. * does not have this problem.
  223. */
  224. if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
  225. cpu_wait = NULL;
  226. break;
  227. #endif
  228. }
  229. return 0;
  230. }
  231. arch_initcall(bcm47xx_cpu_fixes);
  232. static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
  233. .link = 1,
  234. .speed = SPEED_100,
  235. .duplex = DUPLEX_FULL,
  236. };
  237. static int __init bcm47xx_register_bus_complete(void)
  238. {
  239. switch (bcm47xx_bus_type) {
  240. #ifdef CONFIG_BCM47XX_SSB
  241. case BCM47XX_BUS_TYPE_SSB:
  242. /* Nothing to do */
  243. break;
  244. #endif
  245. #ifdef CONFIG_BCM47XX_BCMA
  246. case BCM47XX_BUS_TYPE_BCMA:
  247. bcma_bus_register(&bcm47xx_bus.bcma.bus);
  248. break;
  249. #endif
  250. }
  251. bcm47xx_buttons_register();
  252. bcm47xx_leds_register();
  253. bcm47xx_workarounds();
  254. fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status, -1);
  255. return 0;
  256. }
  257. device_initcall(bcm47xx_register_bus_complete);