setup.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. 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 int bcm47xx_get_sprom_ssb(struct ssb_bus *bus, struct ssb_sprom *out)
  99. {
  100. char prefix[10];
  101. if (bus->bustype == SSB_BUSTYPE_PCI) {
  102. memset(out, 0, sizeof(struct ssb_sprom));
  103. snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
  104. bus->host_pci->bus->number + 1,
  105. PCI_SLOT(bus->host_pci->devfn));
  106. bcm47xx_fill_sprom(out, prefix, false);
  107. return 0;
  108. } else {
  109. printk(KERN_WARNING "bcm47xx: unable to fill SPROM for given bustype.\n");
  110. return -EINVAL;
  111. }
  112. }
  113. static int bcm47xx_get_invariants(struct ssb_bus *bus,
  114. struct ssb_init_invariants *iv)
  115. {
  116. char buf[20];
  117. /* Fill boardinfo structure */
  118. memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
  119. bcm47xx_fill_ssb_boardinfo(&iv->boardinfo, NULL);
  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_arch_register_fallback_sprom(&bcm47xx_get_sprom_ssb);
  132. if (err)
  133. printk(KERN_WARNING "bcm47xx: someone else already registered"
  134. " a ssb SPROM callback handler (err %d)\n", err);
  135. err = ssb_bus_ssbbus_register(&(bcm47xx_bus.ssb), SSB_ENUM_BASE,
  136. bcm47xx_get_invariants);
  137. if (err)
  138. panic("Failed to initialize SSB bus (err %d)", err);
  139. mcore = &bcm47xx_bus.ssb.mipscore;
  140. if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
  141. if (strstr(buf, "console=ttyS1")) {
  142. struct ssb_serial_port port;
  143. printk(KERN_DEBUG "Swapping serial ports!\n");
  144. /* swap serial ports */
  145. memcpy(&port, &mcore->serial_ports[0], sizeof(port));
  146. memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1],
  147. sizeof(port));
  148. memcpy(&mcore->serial_ports[1], &port, sizeof(port));
  149. }
  150. }
  151. }
  152. #endif
  153. #ifdef CONFIG_BCM47XX_BCMA
  154. static int bcm47xx_get_sprom_bcma(struct bcma_bus *bus, struct ssb_sprom *out)
  155. {
  156. char prefix[10];
  157. struct bcma_device *core;
  158. switch (bus->hosttype) {
  159. case BCMA_HOSTTYPE_PCI:
  160. memset(out, 0, sizeof(struct ssb_sprom));
  161. snprintf(prefix, sizeof(prefix), "pci/%u/%u/",
  162. bus->host_pci->bus->number + 1,
  163. PCI_SLOT(bus->host_pci->devfn));
  164. bcm47xx_fill_sprom(out, prefix, false);
  165. return 0;
  166. case BCMA_HOSTTYPE_SOC:
  167. memset(out, 0, sizeof(struct ssb_sprom));
  168. core = bcma_find_core(bus, BCMA_CORE_80211);
  169. if (core) {
  170. snprintf(prefix, sizeof(prefix), "sb/%u/",
  171. core->core_index);
  172. bcm47xx_fill_sprom(out, prefix, true);
  173. } else {
  174. bcm47xx_fill_sprom(out, NULL, false);
  175. }
  176. return 0;
  177. default:
  178. pr_warn("bcm47xx: unable to fill SPROM for given bustype.\n");
  179. return -EINVAL;
  180. }
  181. }
  182. static void __init bcm47xx_register_bcma(void)
  183. {
  184. int err;
  185. err = bcma_arch_register_fallback_sprom(&bcm47xx_get_sprom_bcma);
  186. if (err)
  187. pr_warn("bcm47xx: someone else already registered a bcma SPROM callback handler (err %d)\n", err);
  188. err = bcma_host_soc_register(&bcm47xx_bus.bcma);
  189. if (err)
  190. panic("Failed to register BCMA bus (err %d)", err);
  191. err = bcma_host_soc_init(&bcm47xx_bus.bcma);
  192. if (err)
  193. panic("Failed to initialize BCMA bus (err %d)", err);
  194. bcm47xx_fill_bcma_boardinfo(&bcm47xx_bus.bcma.bus.boardinfo, NULL);
  195. }
  196. #endif
  197. void __init plat_mem_setup(void)
  198. {
  199. struct cpuinfo_mips *c = &current_cpu_data;
  200. if ((c->cputype == CPU_74K) || (c->cputype == CPU_1074K)) {
  201. printk(KERN_INFO "bcm47xx: using bcma bus\n");
  202. #ifdef CONFIG_BCM47XX_BCMA
  203. bcm47xx_bus_type = BCM47XX_BUS_TYPE_BCMA;
  204. bcm47xx_register_bcma();
  205. bcm47xx_set_system_type(bcm47xx_bus.bcma.bus.chipinfo.id);
  206. #ifdef CONFIG_HIGHMEM
  207. bcm47xx_prom_highmem_init();
  208. #endif
  209. #endif
  210. } else {
  211. printk(KERN_INFO "bcm47xx: using ssb bus\n");
  212. #ifdef CONFIG_BCM47XX_SSB
  213. bcm47xx_bus_type = BCM47XX_BUS_TYPE_SSB;
  214. bcm47xx_register_ssb();
  215. bcm47xx_set_system_type(bcm47xx_bus.ssb.chip_id);
  216. #endif
  217. }
  218. _machine_restart = bcm47xx_machine_restart;
  219. _machine_halt = bcm47xx_machine_halt;
  220. pm_power_off = bcm47xx_machine_halt;
  221. bcm47xx_board_detect();
  222. mips_set_machine_name(bcm47xx_board_get_name());
  223. }
  224. static int __init bcm47xx_cpu_fixes(void)
  225. {
  226. switch (bcm47xx_bus_type) {
  227. #ifdef CONFIG_BCM47XX_SSB
  228. case BCM47XX_BUS_TYPE_SSB:
  229. /* Nothing to do */
  230. break;
  231. #endif
  232. #ifdef CONFIG_BCM47XX_BCMA
  233. case BCM47XX_BUS_TYPE_BCMA:
  234. /* The BCM4706 has a problem with the CPU wait instruction.
  235. * When r4k_wait or r4k_wait_irqoff is used will just hang and
  236. * not return from a msleep(). Removing the cpu_wait
  237. * functionality is a workaround for this problem. The BCM4716
  238. * does not have this problem.
  239. */
  240. if (bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4706)
  241. cpu_wait = NULL;
  242. break;
  243. #endif
  244. }
  245. return 0;
  246. }
  247. arch_initcall(bcm47xx_cpu_fixes);
  248. static struct fixed_phy_status bcm47xx_fixed_phy_status __initdata = {
  249. .link = 1,
  250. .speed = SPEED_100,
  251. .duplex = DUPLEX_FULL,
  252. };
  253. static int __init bcm47xx_register_bus_complete(void)
  254. {
  255. switch (bcm47xx_bus_type) {
  256. #ifdef CONFIG_BCM47XX_SSB
  257. case BCM47XX_BUS_TYPE_SSB:
  258. /* Nothing to do */
  259. break;
  260. #endif
  261. #ifdef CONFIG_BCM47XX_BCMA
  262. case BCM47XX_BUS_TYPE_BCMA:
  263. bcma_bus_register(&bcm47xx_bus.bcma.bus);
  264. break;
  265. #endif
  266. }
  267. bcm47xx_buttons_register();
  268. bcm47xx_leds_register();
  269. bcm47xx_workarounds();
  270. fixed_phy_add(PHY_POLL, 0, &bcm47xx_fixed_phy_status);
  271. return 0;
  272. }
  273. device_initcall(bcm47xx_register_bus_complete);