setup.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 <mb@bu3sch.de>
  5. * Copyright (C) 2010 Waldemar Brodkorb <wbx@openadk.org>
  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/types.h>
  28. #include <linux/ssb/ssb.h>
  29. #include <linux/ssb/ssb_embedded.h>
  30. #include <asm/bootinfo.h>
  31. #include <asm/reboot.h>
  32. #include <asm/time.h>
  33. #include <bcm47xx.h>
  34. #include <asm/fw/cfe/cfe_api.h>
  35. #include <asm/mach-bcm47xx/nvram.h>
  36. struct ssb_bus ssb_bcm47xx;
  37. EXPORT_SYMBOL(ssb_bcm47xx);
  38. static void bcm47xx_machine_restart(char *command)
  39. {
  40. printk(KERN_ALERT "Please stand by while rebooting the system...\n");
  41. local_irq_disable();
  42. /* Set the watchdog timer to reset immediately */
  43. ssb_watchdog_timer_set(&ssb_bcm47xx, 1);
  44. while (1)
  45. cpu_relax();
  46. }
  47. static void bcm47xx_machine_halt(void)
  48. {
  49. /* Disable interrupts and watchdog and spin forever */
  50. local_irq_disable();
  51. ssb_watchdog_timer_set(&ssb_bcm47xx, 0);
  52. while (1)
  53. cpu_relax();
  54. }
  55. static void str2eaddr(char *str, char *dest)
  56. {
  57. int i = 0;
  58. if (str == NULL) {
  59. memset(dest, 0, 6);
  60. return;
  61. }
  62. for (;;) {
  63. dest[i++] = (char) simple_strtoul(str, NULL, 16);
  64. str += 2;
  65. if (!*str++ || i == 6)
  66. break;
  67. }
  68. }
  69. static int bcm47xx_get_invariants(struct ssb_bus *bus,
  70. struct ssb_init_invariants *iv)
  71. {
  72. char buf[100];
  73. /* Fill boardinfo structure */
  74. memset(&(iv->boardinfo), 0 , sizeof(struct ssb_boardinfo));
  75. if (cfe_getenv("boardvendor", buf, sizeof(buf)) >= 0 ||
  76. nvram_getenv("boardvendor", buf, sizeof(buf)) >= 0)
  77. iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
  78. if (cfe_getenv("boardtype", buf, sizeof(buf)) >= 0 ||
  79. nvram_getenv("boardtype", buf, sizeof(buf)) >= 0)
  80. iv->boardinfo.type = (u16)simple_strtoul(buf, NULL, 0);
  81. if (cfe_getenv("boardrev", buf, sizeof(buf)) >= 0 ||
  82. nvram_getenv("boardrev", buf, sizeof(buf)) >= 0)
  83. iv->boardinfo.rev = (u16)simple_strtoul(buf, NULL, 0);
  84. /* Fill sprom structure */
  85. memset(&(iv->sprom), 0, sizeof(struct ssb_sprom));
  86. iv->sprom.revision = 3;
  87. if (cfe_getenv("et0macaddr", buf, sizeof(buf)) >= 0 ||
  88. nvram_getenv("et0macaddr", buf, sizeof(buf)) >= 0)
  89. str2eaddr(buf, iv->sprom.et0mac);
  90. if (cfe_getenv("et1macaddr", buf, sizeof(buf)) >= 0 ||
  91. nvram_getenv("et1macaddr", buf, sizeof(buf)) >= 0)
  92. str2eaddr(buf, iv->sprom.et1mac);
  93. if (cfe_getenv("et0phyaddr", buf, sizeof(buf)) >= 0 ||
  94. nvram_getenv("et0phyaddr", buf, sizeof(buf)) >= 0)
  95. iv->sprom.et0phyaddr = simple_strtoul(buf, NULL, 0);
  96. if (cfe_getenv("et1phyaddr", buf, sizeof(buf)) >= 0 ||
  97. nvram_getenv("et1phyaddr", buf, sizeof(buf)) >= 0)
  98. iv->sprom.et1phyaddr = simple_strtoul(buf, NULL, 0);
  99. if (cfe_getenv("et0mdcport", buf, sizeof(buf)) >= 0 ||
  100. nvram_getenv("et0mdcport", buf, sizeof(buf)) >= 0)
  101. iv->sprom.et0mdcport = simple_strtoul(buf, NULL, 10);
  102. if (cfe_getenv("et1mdcport", buf, sizeof(buf)) >= 0 ||
  103. nvram_getenv("et1mdcport", buf, sizeof(buf)) >= 0)
  104. iv->sprom.et1mdcport = simple_strtoul(buf, NULL, 10);
  105. return 0;
  106. }
  107. void __init plat_mem_setup(void)
  108. {
  109. int err;
  110. err = ssb_bus_ssbbus_register(&ssb_bcm47xx, SSB_ENUM_BASE,
  111. bcm47xx_get_invariants);
  112. if (err)
  113. panic("Failed to initialize SSB bus (err %d)\n", err);
  114. _machine_restart = bcm47xx_machine_restart;
  115. _machine_halt = bcm47xx_machine_halt;
  116. pm_power_off = bcm47xx_machine_halt;
  117. }