pn62.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 "pn62.h"
  26. static int get_serial_number (char *string, int size);
  27. static int get_mac_address (int id, u8 * mac, char *string, int size);
  28. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  29. void show_boot_progress (int phase)
  30. {
  31. /*
  32. * Show phases of the bootm command on the front panel
  33. * LEDs and the scratchpad register #3 as well. We use
  34. * blinking LEDs for logical "1".
  35. */
  36. if (phase > 0) {
  37. set_led (8, (phase & 0x1) ? LED_SLOW_CLOCK : LED_0);
  38. set_led (9, (phase & 0x2) ? LED_SLOW_CLOCK : LED_0);
  39. set_led (10, (phase & 0x4) ? LED_SLOW_CLOCK : LED_0);
  40. set_led (11, (phase & 0x8) ? LED_SLOW_CLOCK : LED_0);
  41. }
  42. i2155x_write_scrapad (BOOT_STATUS, phase);
  43. if (phase < 0)
  44. i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR);
  45. }
  46. #endif
  47. void show_startup_phase (int phase)
  48. {
  49. /*
  50. * Show the phase of U-Boot startup on the front panel
  51. * LEDs and the scratchpad register #3 as well.
  52. */
  53. if (phase > 0) {
  54. set_led (8, (phase & 0x1) ? LED_1 : LED_0);
  55. set_led (9, (phase & 0x2) ? LED_1 : LED_0);
  56. set_led (10, (phase & 0x4) ? LED_1 : LED_0);
  57. set_led (11, (phase & 0x8) ? LED_1 : LED_0);
  58. }
  59. i2155x_write_scrapad (BOOT_STATUS, phase);
  60. if (phase < 0)
  61. i2155x_write_scrapad (BOOT_DONE, BOOT_DONE_ERROR);
  62. }
  63. int checkboard (void)
  64. {
  65. show_startup_phase (1);
  66. puts ("Board: PN62\n");
  67. return 0;
  68. }
  69. long int initdram (int board_type)
  70. {
  71. long size;
  72. long new_bank0_end;
  73. long mear1;
  74. long emear1;
  75. show_startup_phase (2);
  76. size = get_ram_size(CFG_SDRAM_BASE, CFG_MAX_RAM_SIZE);
  77. new_bank0_end = size - 1;
  78. mear1 = mpc824x_mpc107_getreg (MEAR1);
  79. emear1 = mpc824x_mpc107_getreg (EMEAR1);
  80. mear1 = (mear1 & 0xFFFFFF00) |
  81. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
  82. emear1 = (emear1 & 0xFFFFFF00) |
  83. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
  84. mpc824x_mpc107_setreg (MEAR1, mear1);
  85. mpc824x_mpc107_setreg (EMEAR1, emear1);
  86. return (size);
  87. }
  88. /*
  89. * Initialize PCI Devices. We rely on auto-configuration.
  90. */
  91. #ifndef CONFIG_PCI_PNP
  92. #error "CONFIG_PCI_PNP is not defined, please correct!"
  93. #endif
  94. struct pci_controller hose = {
  95. };
  96. void pci_init_board (void)
  97. {
  98. show_startup_phase (4);
  99. pci_mpc824x_init (&hose);
  100. show_startup_phase (5);
  101. i2155x_init ();
  102. show_startup_phase (6);
  103. am79c95x_init ();
  104. show_startup_phase (7);
  105. }
  106. int misc_init_r (void)
  107. {
  108. DECLARE_GLOBAL_DATA_PTR;
  109. char str[20];
  110. u8 mac[6];
  111. show_startup_phase (8);
  112. /*
  113. * Get serial number and ethernet addresses if not already defined
  114. * and update the board info structure and the environment.
  115. */
  116. if (getenv ("serial#") == NULL &&
  117. get_serial_number (str, strlen (str)) > 0) {
  118. setenv ("serial#", str);
  119. }
  120. show_startup_phase (9);
  121. if (getenv ("ethaddr") == NULL &&
  122. get_mac_address (0, mac, str, sizeof (str)) > 0) {
  123. setenv ("ethaddr", str);
  124. memcpy (gd->bd->bi_enetaddr, mac, 6);
  125. }
  126. show_startup_phase (10);
  127. #ifdef CONFIG_HAS_ETH1
  128. if (getenv ("eth1addr") == NULL &&
  129. get_mac_address (1, mac, str, sizeof (str)) > 0) {
  130. setenv ("eth1addr", str);
  131. memcpy (gd->bd->bi_enet1addr, mac, 6);
  132. }
  133. #endif /* CONFIG_HAS_ETH1 */
  134. show_startup_phase (11);
  135. /* Tell everybody that U-Boot is up and runnig */
  136. i2155x_write_scrapad (0, 0x12345678);
  137. return (0);
  138. }
  139. static int get_serial_number (char *string, int size)
  140. {
  141. int i;
  142. char c;
  143. if (size < I2155X_VPD_SN_SIZE)
  144. size = I2155X_VPD_SN_SIZE;
  145. for (i = 0; i < (size - 1); i++) {
  146. i2155x_read_vpd (I2155X_VPD_SN_START + i, 1, (uchar *)&c);
  147. if (c == '\0')
  148. break;
  149. string[i] = c;
  150. }
  151. string[i] = '\0'; /* make sure it's terminated */
  152. return i;
  153. }
  154. static int get_mac_address (int id, u8 * mac, char *string, int size)
  155. {
  156. if (size < 6 * 3)
  157. return -1;
  158. i2155x_read_vpd (I2155X_VPD_MAC0_START + 6 * id, 6, mac);
  159. return sprintf (string, "%02x:%02x:%02x:%02x:%02x:%02x",
  160. mac[0], mac[1], mac[2],
  161. mac[3], mac[4], mac[5]);
  162. }