setup.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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/bmips.h>
  39. #include <asm/bootinfo.h>
  40. #include <asm/idle.h>
  41. #include <asm/prom.h>
  42. #include <asm/reboot.h>
  43. #include <asm/time.h>
  44. #include <bcm47xx.h>
  45. #include <bcm47xx_board.h>
  46. /*
  47. * CBR addr doesn't change and we can cache it.
  48. * For broken SoC/Bootloader CBR addr might also be provided via DT
  49. * with "brcm,bmips-cbr-reg" in the "cpus" node.
  50. */
  51. void __iomem *bmips_cbr_addr __read_mostly;
  52. union bcm47xx_bus bcm47xx_bus;
  53. EXPORT_SYMBOL(bcm47xx_bus);
  54. enum bcm47xx_bus_type bcm47xx_bus_type;
  55. EXPORT_SYMBOL(bcm47xx_bus_type);
  56. static void bcm47xx_machine_restart(char *command)
  57. {
  58. pr_alert("Please stand by while rebooting the system...\n");
  59. local_irq_disable();
  60. /* Set the watchdog timer to reset immediately */
  61. switch (bcm47xx_bus_type) {
  62. #ifdef CONFIG_BCM47XX_SSB
  63. case BCM47XX_BUS_TYPE_SSB:
  64. if (bcm47xx_bus.ssb.chip_id == 0x4785)
  65. write_c0_diag4(1 << 22);
  66. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
  67. if (bcm47xx_bus.ssb.chip_id == 0x4785) {
  68. __asm__ __volatile__(
  69. ".set\tmips3\n\t"
  70. "sync\n\t"
  71. "wait\n\t"
  72. ".set\tmips0");
  73. }
  74. break;
  75. #endif
  76. #ifdef CONFIG_BCM47XX_BCMA
  77. case BCM47XX_BUS_TYPE_BCMA:
  78. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
  79. break;
  80. #endif
  81. }
  82. while (1)
  83. cpu_relax();
  84. }
  85. static void bcm47xx_machine_halt(void)
  86. {
  87. /* Disable interrupts and watchdog and spin forever */
  88. local_irq_disable();
  89. switch (bcm47xx_bus_type) {
  90. #ifdef CONFIG_BCM47XX_SSB
  91. case BCM47XX_BUS_TYPE_SSB:
  92. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
  93. break;
  94. #endif
  95. #ifdef CONFIG_BCM47XX_BCMA
  96. case BCM47XX_BUS_TYPE_BCMA:
  97. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
  98. break;
  99. #endif
  100. }
  101. while (1)
  102. cpu_relax();
  103. }
  104. #ifdef CONFIG_BCM47XX_SSB
  105. static void __init bcm47xx_register_ssb(void)
  106. {
  107. int err;
  108. char buf[100];
  109. struct ssb_mipscore *mcore;
  110. err = ssb_bus_host_soc_register(&bcm47xx_bus.ssb, SSB_ENUM_BASE);
  111. if (err)
  112. panic("Failed to initialize SSB bus (err %d)", err);
  113. mcore = &bcm47xx_bus.ssb.mipscore;
  114. if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
  115. if (strstr(buf, "console=ttyS1")) {
  116. struct ssb_serial_port port;
  117. pr_debug("Swapping serial ports!\n");
  118. /* swap serial ports */
  119. memcpy(&port, &mcore->serial_ports[0], sizeof(port));
  120. memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
  121. sizeof(port));
  122. memcpy(&mcore->serial_ports[1], &port, sizeof(port));
  123. }
  124. }
  125. }
  126. #endif
  127. #ifdef CONFIG_BCM47XX_BCMA
  128. static void __init bcm47xx_register_bcma(void)
  129. {
  130. int err;
  131. err = bcma_host_soc_register(&bcm47xx_bus.bcma);
  132. if (err)
  133. panic("Failed to register BCMA bus (err %d)", err);
  134. }
  135. #endif
  136. /*
  137. * Memory setup is done in the early part of MIPS's arch_mem_init. It's supposed
  138. * to detect memory and record it with memblock_add.
  139. * Any extra initializaion performed here must not use kmalloc or bootmem.
  140. */
  141. void __init plat_mem_setup(void)
  142. {
  143. struct cpuinfo_mips *c = &current_cpu_data;
  144. if (c->cputype == CPU_74K) {
  145. pr_info("Using bcma bus\n");
  146. #ifdef CONFIG_BCM47XX_BCMA
  147. bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
  148. bcm47xx_register_bcma();
  149. bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
  150. #ifdef CONFIG_HIGHMEM
  151. bcm47xx_prom_highmem_init();
  152. #endif
  153. #endif
  154. } else {
  155. pr_info("Using ssb bus\n");
  156. #ifdef CONFIG_BCM47XX_SSB
  157. bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
  158. bcm47xx_sprom_register_fallbacks();
  159. bcm47xx_register_ssb();
  160. bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
  161. #endif
  162. }
  163. _machine_restart = bcm47xx_machine_restart;
  164. _machine_halt = bcm47xx_machine_halt;
  165. pm_power_off = bcm47xx_machine_halt;
  166. }
  167. #ifdef CONFIG_BCM47XX_BCMA
  168. static struct device * __init bcm47xx_setup_device(void)
  169. {
  170. struct device *dev;
  171. int err;
  172. dev = kzalloc_obj(*dev);
  173. if (!dev)
  174. return NULL;
  175. err = dev_set_name(dev, "bcm47xx_soc");
  176. if (err) {
  177. pr_err("Failed to set SoC device name: %d\n", err);
  178. kfree(dev);
  179. return NULL;
  180. }
  181. err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
  182. if (err)
  183. pr_err("Failed to set SoC DMA mask: %d\n", err);
  184. return dev;
  185. }
  186. #endif
  187. /*
  188. * This finishes bus initialization doing things that were not possible without
  189. * kmalloc. Make sure to call it late enough (after mm_init).
  190. */
  191. void __init bcm47xx_bus_setup(void)
  192. {
  193. #ifdef CONFIG_BCM47XX_BCMA
  194. if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA) {
  195. int err;
  196. bcm47xx_bus.bcma.dev = bcm47xx_setup_device();
  197. if (!bcm47xx_bus.bcma.dev)
  198. panic("Failed to setup SoC device\n");
  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 int __init bcm47xx_register_bus_complete(void)
  233. {
  234. switch (bcm47xx_bus_type) {
  235. #ifdef CONFIG_BCM47XX_SSB
  236. case BCM47XX_BUS_TYPE_SSB:
  237. /* Nothing to do */
  238. break;
  239. #endif
  240. #ifdef CONFIG_BCM47XX_BCMA
  241. case BCM47XX_BUS_TYPE_BCMA:
  242. if (device_register(bcm47xx_bus.bcma.dev))
  243. pr_err("Failed to register SoC device\n");
  244. bcma_bus_register(&bcm47xx_bus.bcma.bus);
  245. break;
  246. #endif
  247. }
  248. bcm47xx_buttons_register();
  249. bcm47xx_leds_register();
  250. bcm47xx_workarounds();
  251. return 0;
  252. }
  253. device_initcall(bcm47xx_register_bus_complete);