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/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. #ifdef CONFIG_BCM47XX_BCMA
  161. static struct device * __init bcm47xx_setup_device(void)
  162. {
  163. struct device *dev;
  164. int err;
  165. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  166. if (!dev)
  167. return NULL;
  168. err = dev_set_name(dev, "bcm47xx_soc");
  169. if (err) {
  170. pr_err("Failed to set SoC device name: %d\n", err);
  171. kfree(dev);
  172. return NULL;
  173. }
  174. err = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
  175. if (err)
  176. pr_err("Failed to set SoC DMA mask: %d\n", err);
  177. return dev;
  178. }
  179. #endif
  180. /*
  181. * This finishes bus initialization doing things that were not possible without
  182. * kmalloc. Make sure to call it late enough (after mm_init).
  183. */
  184. void __init bcm47xx_bus_setup(void)
  185. {
  186. #ifdef CONFIG_BCM47XX_BCMA
  187. if (bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA) {
  188. int err;
  189. bcm47xx_bus.bcma.dev = bcm47xx_setup_device();
  190. if (!bcm47xx_bus.bcma.dev)
  191. panic("Failed to setup SoC device\n");
  192. err = bcma_host_soc_init(&bcm47xx_bus.bcma);
  193. if (err)
  194. panic("Failed to initialize BCMA bus (err %d)", err);
  195. }
  196. #endif
  197. /* With bus initialized we can access NVRAM and detect the board */
  198. bcm47xx_board_detect();
  199. mips_set_machine_name(bcm47xx_board_get_name());
  200. }
  201. static int __init bcm47xx_cpu_fixes(void)
  202. {
  203. switch (bcm47xx_bus_type) {
  204. #ifdef CONFIG_BCM47XX_SSB
  205. case BCM47XX_BUS_TYPE_SSB:
  206. /* Nothing to do */
  207. break;
  208. #endif
  209. #ifdef CONFIG_BCM47XX_BCMA
  210. case BCM47XX_BUS_TYPE_BCMA:
  211. /* The BCM4706 has a problem with the CPU wait instruction.
  212. * When r4k_wait or r4k_wait_irqoff is used will just hang and
  213. * not return from a msleep(). Removing the cpu_wait
  214. * functionality is a workaround for this problem. The BCM4716
  215. * does not have this problem.
  216. */
  217. if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
  218. cpu_wait = NULL;
  219. break;
  220. #endif
  221. }
  222. return 0;
  223. }
  224. arch_initcall(bcm47xx_cpu_fixes);
  225. static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
  226. .link = 1,
  227. .speed = SPEED_100,
  228. .duplex = DUPLEX_FULL,
  229. };
  230. static int __init bcm47xx_register_bus_complete(void)
  231. {
  232. switch (bcm47xx_bus_type) {
  233. #ifdef CONFIG_BCM47XX_SSB
  234. case BCM47XX_BUS_TYPE_SSB:
  235. /* Nothing to do */
  236. break;
  237. #endif
  238. #ifdef CONFIG_BCM47XX_BCMA
  239. case BCM47XX_BUS_TYPE_BCMA:
  240. if (device_register(bcm47xx_bus.bcma.dev))
  241. pr_err("Failed to register SoC device\n");
  242. bcma_bus_register(&bcm47xx_bus.bcma.bus);
  243. break;
  244. #endif
  245. }
  246. bcm47xx_buttons_register();
  247. bcm47xx_leds_register();
  248. bcm47xx_workarounds();
  249. fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status, -1);
  250. return 0;
  251. }
  252. device_initcall(bcm47xx_register_bus_complete);