pn62.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * (C) Copyright 2002 Wolfgang Grandegger <wg@denx.de>
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <mpc824x.h>
  24. #include <pci.h>
  25. #include <netdev.h>
  26. #include "pn62.h"
  27. DECLARE_GLOBAL_DATA_PTR;
  28. static int get_serial_number (char *string, int size);
  29. static int get_mac_address (int id, u8 * mac, char *string, int size);
  30. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  31. void show_boot_progress (int phase)
  32. {
  33. /*
  34. * Show phases of the bootm command on the front panel
  35. * LEDs and the scratchpad register #3 as well. We use
  36. * blinking LEDs for logical "1".
  37. */
  38. if (phase > 0) {
  39. set_led (8, (phase & 0x1) ? LED_SLOW_CLOCK : LED_0);
  40. set_led (9, (phase & 0x2) ? LED_SLOW_CLOCK : LED_0);
  41. set_led (10, (phase & 0x4) ? LED_SLOW_CLOCK : LED_0);
  42. set_led (11, (phase & 0x8) ? LED_SLOW_CLOCK : LED_0);
  43. }
  44. i2155x_write_scrapad (BOOT_STATUS, phase);
  45. if (phase < 0)
  46. i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR);
  47. }
  48. #endif
  49. void show_startup_phase (int phase)
  50. {
  51. /*
  52. * Show the phase of U-Boot startup on the front panel
  53. * LEDs and the scratchpad register #3 as well.
  54. */
  55. if (phase > 0) {
  56. set_led (8, (phase & 0x1) ? LED_1 : LED_0);
  57. set_led (9, (phase & 0x2) ? LED_1 : LED_0);
  58. set_led (10, (phase & 0x4) ? LED_1 : LED_0);
  59. set_led (11, (phase & 0x8) ? LED_1 : LED_0);
  60. }
  61. i2155x_write_scrapad (BOOT_STATUS, phase);
  62. if (phase < 0)
  63. i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR);
  64. }
  65. int checkboard (void)
  66. {
  67. show_startup_phase (1);
  68. puts ("Board: PN62\n");
  69. return 0;
  70. }
  71. phys_size_t initdram (int board_type)
  72. {
  73. long size;
  74. long new_bank0_end;
  75. long mear1;
  76. long emear1;
  77. show_startup_phase (2);
  78. size = get_ram_size(CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_MAX_RAM_SIZE);
  79. new_bank0_end = size - 1;
  80. mear1 = mpc824x_mpc107_getreg (MEAR1);
  81. emear1 = mpc824x_mpc107_getreg (EMEAR1);
  82. mear1 = (mear1 & 0xFFFFFF00) |
  83. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
  84. emear1 = (emear1 & 0xFFFFFF00) |
  85. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
  86. mpc824x_mpc107_setreg (MEAR1, mear1);
  87. mpc824x_mpc107_setreg (EMEAR1, emear1);
  88. return (size);
  89. }
  90. /*
  91. * Initialize PCI Devices. We rely on auto-configuration.
  92. */
  93. #ifndef CONFIG_PCI_PNP
  94. #error "CONFIG_PCI_PNP is not defined, please correct!"
  95. #endif
  96. struct pci_controller hose = {
  97. };
  98. void pci_init_board (void)
  99. {
  100. show_startup_phase (4);
  101. pci_mpc824x_init (&hose);
  102. show_startup_phase (5);
  103. i2155x_init ();
  104. show_startup_phase (6);
  105. am79c95x_init ();
  106. show_startup_phase (7);
  107. }
  108. int misc_init_r (void)
  109. {
  110. char str[20];
  111. u8 mac[6];
  112. show_startup_phase (8);
  113. /*
  114. * Get serial number and ethernet addresses if not already defined
  115. * and update the board info structure and the environment.
  116. */
  117. if (getenv ("serial#") == NULL &&
  118. get_serial_number (str, strlen (str)) > 0) {
  119. setenv ("serial#", str);
  120. }
  121. show_startup_phase (9);
  122. if (getenv ("ethaddr") == NULL &&
  123. get_mac_address (0, mac, str, sizeof (str)) > 0) {
  124. setenv ("ethaddr", str);
  125. memcpy (gd->bd->bi_enetaddr, mac, 6);
  126. }
  127. show_startup_phase (10);
  128. #ifdef CONFIG_HAS_ETH1
  129. if (getenv ("eth1addr") == NULL &&
  130. get_mac_address (1, mac, str, sizeof (str)) > 0) {
  131. setenv ("eth1addr", str);
  132. memcpy (gd->bd->bi_enet1addr, mac, 6);
  133. }
  134. #endif /* CONFIG_HAS_ETH1 */
  135. show_startup_phase (11);
  136. /* Tell everybody that U-Boot is up and runnig */
  137. i2155x_write_scrapad (0, 0x12345678);
  138. return (0);
  139. }
  140. static int get_serial_number (char *string, int size)
  141. {
  142. int i;
  143. char c;
  144. if (size < I2155X_VPD_SN_SIZE)
  145. size = I2155X_VPD_SN_SIZE;
  146. for (i = 0; i < (size - 1); i++) {
  147. i2155x_read_vpd (I2155X_VPD_SN_START + i, 1, (uchar *)&c);
  148. if (c == '\0')
  149. break;
  150. string[i] = c;
  151. }
  152. string[i] = '\0'; /* make sure it's terminated */
  153. return i;
  154. }
  155. static int get_mac_address (int id, u8 * mac, char *string, int size)
  156. {
  157. if (size < 6 * 3)
  158. return -1;
  159. i2155x_read_vpd (I2155X_VPD_MAC0_START + 6 * id, 6, mac);
  160. return sprintf (string, "%02x:%02x:%02x:%02x:%02x:%02x",
  161. mac[0], mac[1], mac[2],
  162. mac[3], mac[4], mac[5]);
  163. }
  164. int board_eth_init(bd_t *bis)
  165. {
  166. return pci_eth_init(bis);
  167. }