setup.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (C) 2004 Florian Schirmer ([email protected])
  3. * Copyright (C) 2005 Waldemar Brodkorb <[email protected]>
  4. * Copyright (C) 2006 Felix Fietkau <[email protected]>
  5. * Copyright (C) 2006-2008 Michael Buesch <[email protected]>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  13. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  14. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
  15. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  18. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  19. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. *
  23. * You should have received a copy of the GNU General Public License along
  24. * with this program; if not, write to the Free Software Foundation, Inc.,
  25. * 675 Mass Ave, Cambridge, MA 02139, USA.
  26. */
  27. #include <linux/init.h>
  28. #include <linux/types.h>
  29. #include <linux/tty.h>
  30. #include <linux/serial.h>
  31. #include <linux/serial_core.h>
  32. #include <linux/serial_reg.h>
  33. #include <linux/serial_8250.h>
  34. #include <asm/bootinfo.h>
  35. #include <asm/time.h>
  36. #include <asm/reboot.h>
  37. #include <asm/cfe.h>
  38. #include <linux/pm.h>
  39. #include <linux/ssb/ssb.h>
  40. #include <linux/ssb/ssb_embedded.h>
  41. #include <nvram.h>
  42. extern void bcm47xx_pci_init(void);
  43. extern void bcm47xx_time_init(void);
  44. struct ssb_bus ssb;
  45. int pcibios_plat_dev_init(struct pci_dev *dev)
  46. {
  47. int err;
  48. err = ssb_pcibios_plat_dev_init(dev);
  49. if (err) {
  50. printk(KERN_ALERT "PCI: Failed to init device %s\n",
  51. pci_name(dev));
  52. }
  53. return err;
  54. }
  55. static void bcm47xx_machine_restart(char *command)
  56. {
  57. printk(KERN_ALERT "Please stand by while rebooting the system...\n");
  58. local_irq_disable();
  59. /* CFE has a reboot callback, but that does not work.
  60. * Oopses with: Reserved instruction in kernel code.
  61. */
  62. /* Set the watchdog timer to reset immediately */
  63. if (ssb_watchdog_timer_set(&ssb, 1))
  64. printk(KERN_EMERG "SSB watchdog-triggered reboot failed!\n");
  65. while (1)
  66. cpu_relax();
  67. }
  68. static void bcm47xx_machine_halt(void)
  69. {
  70. /* Disable interrupts and watchdog and spin forever */
  71. local_irq_disable();
  72. if (ssb_watchdog_timer_set(&ssb, 0))
  73. printk(KERN_EMERG "Failed to disable SSB watchdog!\n");
  74. while (1)
  75. cpu_relax();
  76. }
  77. static void e_aton(char *str, char *dest)
  78. {
  79. int i = 0;
  80. if (str == NULL) {
  81. memset(dest, 0, 6);
  82. return;
  83. }
  84. for (;;) {
  85. dest[i++] = (char) simple_strtoul(str, NULL, 16);
  86. str += 2;
  87. if (!*str++ || i == 6)
  88. break;
  89. }
  90. }
  91. static void bcm47xx_fill_sprom(struct ssb_sprom *sprom)
  92. {
  93. char *s;
  94. memset(sprom, 0xFF, sizeof(struct ssb_sprom));
  95. sprom->revision = 1;
  96. if ((s = nvram_get("il0macaddr")))
  97. e_aton(s, sprom->il0mac);
  98. if ((s = nvram_get("et0macaddr")))
  99. e_aton(s, sprom->et0mac);
  100. if ((s = nvram_get("et1macaddr")))
  101. e_aton(s, sprom->et1mac);
  102. if ((s = nvram_get("et0phyaddr")))
  103. sprom->et0phyaddr = simple_strtoul(s, NULL, 0);
  104. if ((s = nvram_get("et1phyaddr")))
  105. sprom->et1phyaddr = simple_strtoul(s, NULL, 0);
  106. if ((s = nvram_get("et0mdcport")))
  107. sprom->et0mdcport = !!simple_strtoul(s, NULL, 10);
  108. if ((s = nvram_get("et1mdcport")))
  109. sprom->et1mdcport = !!simple_strtoul(s, NULL, 10);
  110. if ((s = nvram_get("pa0b0")))
  111. sprom->pa0b0 = simple_strtoul(s, NULL, 0);
  112. if ((s = nvram_get("pa0b1")))
  113. sprom->pa0b1 = simple_strtoul(s, NULL, 0);
  114. if ((s = nvram_get("pa0b2")))
  115. sprom->pa0b2 = simple_strtoul(s, NULL, 0);
  116. if ((s = nvram_get("pa1b0")))
  117. sprom->pa1b0 = simple_strtoul(s, NULL, 0);
  118. if ((s = nvram_get("pa1b1")))
  119. sprom->pa1b1 = simple_strtoul(s, NULL, 0);
  120. if ((s = nvram_get("pa1b2")))
  121. sprom->pa1b2 = simple_strtoul(s, NULL, 0);
  122. if ((s = nvram_get("wl0gpio0")))
  123. sprom->gpio0 = simple_strtoul(s, NULL, 0);
  124. if ((s = nvram_get("wl0gpio1")))
  125. sprom->gpio1 = simple_strtoul(s, NULL, 0);
  126. if ((s = nvram_get("wl0gpio2")))
  127. sprom->gpio2 = simple_strtoul(s, NULL, 0);
  128. if ((s = nvram_get("wl0gpio3")))
  129. sprom->gpio3 = simple_strtoul(s, NULL, 0);
  130. if ((s = nvram_get("pa0maxpwr")))
  131. sprom->maxpwr_bg = simple_strtoul(s, NULL, 0);
  132. if ((s = nvram_get("pa1maxpwr")))
  133. sprom->maxpwr_a = simple_strtoul(s, NULL, 0);
  134. if ((s = nvram_get("pa0itssit")))
  135. sprom->itssi_bg = simple_strtoul(s, NULL, 0);
  136. if ((s = nvram_get("pa1itssit")))
  137. sprom->itssi_a = simple_strtoul(s, NULL, 0);
  138. sprom->boardflags_lo = 0;
  139. if ((s = nvram_get("boardflags")))
  140. sprom->boardflags_lo = simple_strtoul(s, NULL, 0);
  141. sprom->boardflags_hi = 0;
  142. if ((s = nvram_get("boardflags2")))
  143. sprom->boardflags_hi = simple_strtoul(s, NULL, 0);
  144. }
  145. static int bcm47xx_get_invariants(struct ssb_bus *bus, struct ssb_init_invariants *iv)
  146. {
  147. char *s;
  148. iv->boardinfo.vendor = SSB_BOARDVENDOR_BCM;
  149. if ((s = nvram_get("boardtype")))
  150. iv->boardinfo.type = (u16)simple_strtoul(s, NULL, 0);
  151. if ((s = nvram_get("boardrev")))
  152. iv->boardinfo.rev = (u16)simple_strtoul(s, NULL, 0);
  153. bcm47xx_fill_sprom(&iv->sprom);
  154. if ((s = nvram_get("cardbus")))
  155. iv->has_cardbus_slot = !!simple_strtoul(s, NULL, 10);
  156. return 0;
  157. }
  158. void __init plat_mem_setup(void)
  159. {
  160. int i, err;
  161. char *s;
  162. struct ssb_mipscore *mcore;
  163. err = ssb_bus_ssbbus_register(&ssb, SSB_ENUM_BASE, bcm47xx_get_invariants);
  164. if (err) {
  165. const char *msg = "Failed to initialize SSB bus (err %d)\n";
  166. cfe_printk(msg, err); /* Make sure the message gets out of the box. */
  167. panic(msg, err);
  168. }
  169. mcore = &ssb.mipscore;
  170. s = nvram_get("kernel_args");
  171. if (s && !strncmp(s, "console=ttyS1", 13)) {
  172. struct ssb_serial_port port;
  173. cfe_printk("Swapping serial ports!\n");
  174. /* swap serial ports */
  175. memcpy(&port, &mcore->serial_ports[0], sizeof(port));
  176. memcpy(&mcore->serial_ports[0], &mcore->serial_ports[1], sizeof(port));
  177. memcpy(&mcore->serial_ports[1], &port, sizeof(port));
  178. }
  179. for (i = 0; i < mcore->nr_serial_ports; i++) {
  180. struct ssb_serial_port *port = &(mcore->serial_ports[i]);
  181. struct uart_port s;
  182. memset(&s, 0, sizeof(s));
  183. s.line = i;
  184. s.membase = port->regs;
  185. s.irq = port->irq + 2;
  186. s.uartclk = port->baud_base;
  187. s.flags = UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
  188. s.iotype = SERIAL_IO_MEM;
  189. s.regshift = port->reg_shift;
  190. early_serial_setup(&s);
  191. }
  192. cfe_printk("Serial init done.\n");
  193. _machine_restart = bcm47xx_machine_restart;
  194. _machine_halt = bcm47xx_machine_halt;
  195. pm_power_off = bcm47xx_machine_halt;
  196. board_time_init = bcm47xx_time_init;
  197. }
  198. static int __init bcm47xx_register_gpiodev(void)
  199. {
  200. static struct resource res = {
  201. .start = 0xFFFFFFFF,
  202. };
  203. struct platform_device *pdev;
  204. pdev = platform_device_register_simple("GPIODEV", 0, &res, 1);
  205. if (!pdev) {
  206. printk(KERN_ERR "bcm47xx: GPIODEV init failed\n");
  207. return -ENODEV;
  208. }
  209. return 0;
  210. }
  211. device_initcall(bcm47xx_register_gpiodev);
  212. EXPORT_SYMBOL(ssb);