setup.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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_nvram.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. printk(KERN_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. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 1);
  58. break;
  59. #endif
  60. #ifdef CONFIG_BCM47XX_BCMA
  61. case BCM47XX_BUS_TYPE_BCMA:
  62. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 1);
  63. break;
  64. #endif
  65. }
  66. while (1)
  67. cpu_relax();
  68. }
  69. static void bcm47xx_machine_halt(void)
  70. {
  71. /* Disable interrupts and watchdog and spin forever */
  72. local_irq_disable();
  73. switch (bcm47xx_bus_type) {
  74. #ifdef CONFIG_BCM47XX_SSB
  75. case BCM47XX_BUS_TYPE_SSB:
  76. ssb_watchdog_timer_set(&bcm47xx_bus.ssb, 0);
  77. break;
  78. #endif
  79. #ifdef CONFIG_BCM47XX_BCMA
  80. case BCM47XX_BUS_TYPE_BCMA:
  81. bcma_chipco_watchdog_timer_set(&bcm47xx_bus.bcma.bus.drv_cc, 0);
  82. break;
  83. #endif
  84. }
  85. while (1)
  86. cpu_relax();
  87. }
  88. #ifdef CONFIG_BCM47XX_SSB
  89. static int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
  90. {
  91. char prefix[10];
  92. if (bus->bustype == SSB_BUSTYPE_PCI) {
  93. memset(out, 0, sizeof(struct ssb_sprom));
  94. snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
  95. bus->host_pci->bus->number + 1,
  96. PCI_SLOT(bus->host_pci->devfn));
  97. bcm47xx_fill_sprom(out, prefix, false);
  98. return 0;
  99. } else {
  100. printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
  101. return -EINVAL;
  102. }
  103. }
  104. static int bcm47xx_get_invariants(struct ssb_bus *bus,
  105. struct ssb_init_invariants *iv)
  106. {
  107. char buf[20];
  108. /* Fill boardinfo structure */
  109. memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
  110. bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL);
  111. memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
  112. bcm47xx_fill_sprom(&iv->sprom, NULL, false);
  113. if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
  114. iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
  115. return 0;
  116. }
  117. static void __init bcm47xx_register_ssb(void)
  118. {
  119. int err;
  120. char buf[100];
  121. struct ssb_mipscore *mcore;
  122. err = ssb_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb);
  123. if (err)
  124. printk(KERN_WARNING "bcm47xx: someone else already registered"
  125. " a ssb SPROM callback handler (err %d)\n", err);
  126. err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
  127. bcm47xx_get_invariants);
  128. if (err)
  129. panic("Failed to initialize SSB bus (err %d)", err);
  130. mcore = &bcm47xx_bus.ssb.mipscore;
  131. if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
  132. if (strstr(buf, "console=ttyS1")) {
  133. struct ssb_serial_port port;
  134. printk(KERN_DEBUG "Swapping serial ports!\n");
  135. /* swap serial ports */
  136. memcpy(&port, &mcore->serial_ports[0], sizeof(port));
  137. memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
  138. sizeof(port));
  139. memcpy(&mcore->serial_ports[1], &port, sizeof(port));
  140. }
  141. }
  142. }
  143. #endif
  144. #ifdef CONFIG_BCM47XX_BCMA
  145. static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
  146. {
  147. char prefix[10];
  148. struct bcma_device *core;
  149. switch (bus->hosttype) {
  150. case BCMA_HOSTTYPE_PCI:
  151. memset(out, 0, sizeof(struct ssb_sprom));
  152. snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
  153. bus->host_pci->bus->number + 1,
  154. PCI_SLOT(bus->host_pci->devfn));
  155. bcm47xx_fill_sprom(out, prefix, false);
  156. return 0;
  157. case BCMA_HOSTTYPE_SOC:
  158. memset(out, 0, sizeof(struct ssb_sprom));
  159. core = bcma_find_core(bus, BCMA_CORE_80211);
  160. if (core) {
  161. snprintf(prefix, sizeof(prefix), "sb/%u/",
  162. core->core_index);
  163. bcm47xx_fill_sprom(out, prefix, true);
  164. } else {
  165. bcm47xx_fill_sprom(out, NULL, false);
  166. }
  167. return 0;
  168. default:
  169. pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n");
  170. return -EINVAL;
  171. }
  172. }
  173. static void __init bcm47xx_register_bcma(void)
  174. {
  175. int err;
  176. err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma);
  177. if (err)
  178. pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err);
  179. err = bcma_host_soc_register(&bcm47xx_bus.bcma);
  180. if (err)
  181. panic("Failed to initialize BCMA bus (err %d)", err);
  182. bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL);
  183. }
  184. #endif
  185. void __init plat_mem_setup(void)
  186. {
  187. struct cpuinfo_mips *c = &current_cpu_data;
  188. if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
  189. printk(KERN_INFO "bcm47xx: using bcma bus\n");
  190. #ifdef CONFIG_BCM47XX_BCMA
  191. bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
  192. bcm47xx_register_bcma();
  193. bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
  194. #endif
  195. } else {
  196. printk(KERN_INFO "bcm47xx: using ssb bus\n");
  197. #ifdef CONFIG_BCM47XX_SSB
  198. bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
  199. bcm47xx_register_ssb();
  200. bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
  201. #endif
  202. }
  203. _machine_restart = bcm47xx_machine_restart;
  204. _machine_halt = bcm47xx_machine_halt;
  205. pm_power_off = bcm47xx_machine_halt;
  206. bcm47xx_board_detect();
  207. mips_set_machine_name(bcm47xx_board_get_name());
  208. }
  209. static int __init bcm47xx_cpu_fixes(void)
  210. {
  211. switch (bcm47xx_bus_type) {
  212. #ifdef CONFIG_BCM47XX_SSB
  213. case BCM47XX_BUS_TYPE_SSB:
  214. /* Nothing to do */
  215. break;
  216. #endif
  217. #ifdef CONFIG_BCM47XX_BCMA
  218. case BCM47XX_BUS_TYPE_BCMA:
  219. /* The BCM4706 has a problem with the CPU wait instruction.
  220. * When r4k_wait or r4k_wait_irqoff is used will just hang and
  221. * not return from a msleep(). Removing the cpu_wait
  222. * functionality is a workaround for this problem. The BCM4716
  223. * does not have this problem.
  224. */
  225. if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
  226. cpu_wait = NULL;
  227. break;
  228. #endif
  229. }
  230. return 0;
  231. }
  232. arch_initcall(bcm47xx_cpu_fixes);
  233. static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
  234. .link = 1,
  235. .speed = SPEED_100,
  236. .duplex = DUPLEX_FULL,
  237. };
  238. static int __init bcm47xx_register_bus_complete(void)
  239. {
  240. switch (bcm47xx_bus_type) {
  241. #ifdef CONFIG_BCM47XX_SSB
  242. case BCM47XX_BUS_TYPE_SSB:
  243. /* Nothing to do */
  244. break;
  245. #endif
  246. #ifdef CONFIG_BCM47XX_BCMA
  247. case BCM47XX_BUS_TYPE_BCMA:
  248. bcma_bus_register(&bcm47xx_bus.bcma.bus);
  249. break;
  250. #endif
  251. }
  252. bcm47xx_buttons_register();
  253. bcm47xx_leds_register();
  254. bcm47xx_workarounds();
  255. fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status);
  256. return 0;
  257. }
  258. device_initcall(bcm47xx_register_bus_complete);