oxc.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * (C) Copyright 2000
  3. * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <mpc824x.h>
  25. #include <pci.h>
  26. #include <i2c.h>
  27. #include <netdev.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. int checkboard (void)
  30. {
  31. puts ( "Board: OXC8240\n" );
  32. return 0;
  33. }
  34. phys_size_t initdram (int board_type)
  35. {
  36. #ifndef CONFIG_SYS_RAMBOOT
  37. long size;
  38. long new_bank0_end;
  39. long mear1;
  40. long emear1;
  41. size = get_ram_size(CONFIG_SYS_SDRAM_BASE, CONFIG_SYS_MAX_RAM_SIZE);
  42. new_bank0_end = size - 1;
  43. mear1 = mpc824x_mpc107_getreg(MEAR1);
  44. emear1 = mpc824x_mpc107_getreg(EMEAR1);
  45. mear1 = (mear1 & 0xFFFFFF00) |
  46. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
  47. emear1 = (emear1 & 0xFFFFFF00) |
  48. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
  49. mpc824x_mpc107_setreg(MEAR1, mear1);
  50. mpc824x_mpc107_setreg(EMEAR1, emear1);
  51. return (size);
  52. #else
  53. /* if U-Boot starts from RAM, then suppose we have 16Mb of RAM */
  54. return (16 << 20);
  55. #endif
  56. }
  57. /*
  58. * Initialize PCI Devices, report devices found.
  59. */
  60. #ifndef CONFIG_PCI_PNP
  61. static struct pci_config_table pci_oxc_config_table[] = {
  62. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x14, PCI_ANY_ID,
  63. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  64. PCI_ENET0_MEMADDR,
  65. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  66. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x15, PCI_ANY_ID,
  67. pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
  68. PCI_ENET1_MEMADDR,
  69. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  70. { }
  71. };
  72. #endif
  73. static struct pci_controller hose = {
  74. #ifndef CONFIG_PCI_PNP
  75. config_table: pci_oxc_config_table,
  76. #endif
  77. };
  78. void pci_init_board (void)
  79. {
  80. pci_mpc824x_init(&hose);
  81. }
  82. int board_early_init_f (void)
  83. {
  84. *(volatile unsigned char *)(CONFIG_SYS_CPLD_RESET) = 0x89;
  85. return 0;
  86. }
  87. #ifdef CONFIG_WATCHDOG
  88. void oxc_wdt_reset(void)
  89. {
  90. *(volatile unsigned char *)(CONFIG_SYS_CPLD_WATCHDOG) = 0xff;
  91. }
  92. void watchdog_reset(void)
  93. {
  94. int re_enable = disable_interrupts();
  95. oxc_wdt_reset();
  96. if (re_enable)
  97. enable_interrupts();
  98. }
  99. #endif
  100. static int oxc_get_expander(unsigned char addr, unsigned char * val)
  101. {
  102. return i2c_read(addr, 0, 0, val, 1);
  103. }
  104. static int oxc_set_expander(unsigned char addr, unsigned char val)
  105. {
  106. return i2c_write(addr, 0, 0, &val, 1);
  107. }
  108. static int expander0alive = 0;
  109. #ifdef CONFIG_SHOW_ACTIVITY
  110. static int ledtoggle = 0;
  111. static int ledstatus = 1;
  112. void oxc_toggle_activeled(void)
  113. {
  114. ledtoggle++;
  115. }
  116. void board_show_activity (ulong timestamp)
  117. {
  118. if ((timestamp % (CONFIG_SYS_HZ / 10)) == 0)
  119. oxc_toggle_activeled ();
  120. }
  121. void show_activity(int arg)
  122. {
  123. static unsigned char led = 0;
  124. unsigned char val;
  125. if (!expander0alive) return;
  126. if ((ledtoggle > (2 * arg)) && ledstatus) {
  127. led ^= 0x80;
  128. oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
  129. udelay(200);
  130. oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, (val & 0x7F) | led);
  131. ledtoggle = 0;
  132. }
  133. }
  134. #endif
  135. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  136. void show_boot_progress(int arg)
  137. {
  138. unsigned char val;
  139. if (!expander0alive) return;
  140. if (arg > 0 && ledstatus) {
  141. ledstatus = 0;
  142. oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
  143. udelay(200);
  144. oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, val | 0x80);
  145. } else if (arg < 0) {
  146. oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val);
  147. udelay(200);
  148. oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, val & 0x7F);
  149. ledstatus = 1;
  150. }
  151. }
  152. #endif
  153. int misc_init_r (void)
  154. {
  155. /* check whether the i2c expander #0 is accessible */
  156. if (!oxc_set_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, 0x7F)) {
  157. udelay(200);
  158. expander0alive = 1;
  159. }
  160. #ifdef CONFIG_SYS_OXC_GENERATE_IP
  161. {
  162. char str[32];
  163. unsigned long ip = CONFIG_SYS_OXC_IPMASK;
  164. bd_t *bd = gd->bd;
  165. if (expander0alive) {
  166. unsigned char val;
  167. if (!oxc_get_expander(CONFIG_SYS_I2C_EXPANDER0_ADDR, &val)) {
  168. ip = (ip & 0xffffff00) | ((val & 0x7c) >> 2);
  169. }
  170. }
  171. if ((ip & 0xff) < 3) {
  172. /* if fail, set x.x.x.254 */
  173. ip = (ip & 0xffffff00) | 0xfe;
  174. }
  175. bd->bi_ip_addr = ip;
  176. sprintf(str, "%ld.%ld.%ld.%ld",
  177. (bd->bi_ip_addr & 0xff000000) >> 24,
  178. (bd->bi_ip_addr & 0x00ff0000) >> 16,
  179. (bd->bi_ip_addr & 0x0000ff00) >> 8,
  180. (bd->bi_ip_addr & 0x000000ff));
  181. setenv("ipaddr", str);
  182. printf("ip: %s\n", str);
  183. }
  184. #endif
  185. return (0);
  186. }
  187. int board_eth_init(bd_t *bis)
  188. {
  189. return pci_eth_init(bis);
  190. }