oxc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. int checkboard (void)
  28. {
  29. puts ( "Board: OXC8240\n" );
  30. return 0;
  31. }
  32. long int initdram (int board_type)
  33. {
  34. #ifndef CFG_RAMBOOT
  35. int i, cnt;
  36. volatile uchar * base= CFG_SDRAM_BASE;
  37. volatile ulong * addr;
  38. ulong save[32];
  39. ulong val, ret = 0;
  40. for (i=0, cnt=(CFG_MAX_RAM_SIZE / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) {
  41. addr = (volatile ulong *)base + cnt;
  42. save[i++] = *addr;
  43. *addr = ~cnt;
  44. }
  45. addr = (volatile ulong *)base;
  46. save[i] = *addr;
  47. *addr = 0;
  48. if (*addr != 0) {
  49. *addr = save[i];
  50. goto Done;
  51. }
  52. for (cnt = 1; cnt <= CFG_MAX_RAM_SIZE / sizeof(long); cnt <<= 1) {
  53. addr = (volatile ulong *)base + cnt;
  54. val = *addr;
  55. *addr = save[--i];
  56. if (val != ~cnt) {
  57. ulong new_bank0_end = cnt * sizeof(long) - 1;
  58. ulong mear1 = mpc824x_mpc107_getreg(MEAR1);
  59. ulong emear1 = mpc824x_mpc107_getreg(EMEAR1);
  60. mear1 = (mear1 & 0xFFFFFF00) |
  61. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
  62. emear1 = (emear1 & 0xFFFFFF00) |
  63. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
  64. mpc824x_mpc107_setreg(MEAR1, mear1);
  65. mpc824x_mpc107_setreg(EMEAR1, emear1);
  66. ret = cnt * sizeof(long);
  67. goto Done;
  68. }
  69. }
  70. ret = CFG_MAX_RAM_SIZE;
  71. Done:
  72. return ret;
  73. #else
  74. /* if U-Boot starts from RAM, then suppose we have 16Mb of RAM */
  75. return (16 << 20);
  76. #endif
  77. }
  78. /*
  79. * Initialize PCI Devices, report devices found.
  80. */
  81. #ifndef CONFIG_PCI_PNP
  82. static struct pci_config_table pci_oxc_config_table[] = {
  83. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x14, PCI_ANY_ID,
  84. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  85. PCI_ENET0_MEMADDR,
  86. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  87. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x15, PCI_ANY_ID,
  88. pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
  89. PCI_ENET1_MEMADDR,
  90. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  91. { }
  92. };
  93. #endif
  94. static struct pci_controller hose = {
  95. #ifndef CONFIG_PCI_PNP
  96. config_table: pci_oxc_config_table,
  97. #endif
  98. };
  99. void pci_init_board (void)
  100. {
  101. pci_mpc824x_init(&hose);
  102. }
  103. int board_pre_init (void)
  104. {
  105. *(volatile unsigned char *)(CFG_CPLD_RESET) = 0x89;
  106. return 0;
  107. }
  108. #ifdef CONFIG_WATCHDOG
  109. void oxc_wdt_reset(void)
  110. {
  111. *(volatile unsigned char *)(CFG_CPLD_WATCHDOG) = 0xff;
  112. }
  113. void watchdog_reset(void)
  114. {
  115. int re_enable = disable_interrupts();
  116. oxc_wdt_reset();
  117. if (re_enable)
  118. enable_interrupts();
  119. }
  120. #endif
  121. static int oxc_get_expander(unsigned char addr, unsigned char * val)
  122. {
  123. return i2c_read(addr, 0, 0, val, 1);
  124. }
  125. static int oxc_set_expander(unsigned char addr, unsigned char val)
  126. {
  127. return i2c_write(addr, 0, 0, &val, 1);
  128. }
  129. static int expander0alive = 0;
  130. #ifdef CONFIG_SHOW_ACTIVITY
  131. static int ledtoggle = 0;
  132. static int ledstatus = 1;
  133. void oxc_toggle_activeled(void)
  134. {
  135. ledtoggle++;
  136. }
  137. void show_activity(int arg)
  138. {
  139. static unsigned char led = 0;
  140. unsigned char val;
  141. if (!expander0alive) return;
  142. if ((ledtoggle > (2 * arg)) && ledstatus) {
  143. led ^= 0x80;
  144. oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
  145. udelay(200);
  146. oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, (val & 0x7F) | led);
  147. ledtoggle = 0;
  148. }
  149. }
  150. #endif
  151. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  152. void show_boot_progress(int arg)
  153. {
  154. unsigned char val;
  155. if (!expander0alive) return;
  156. if (arg > 0 && ledstatus) {
  157. ledstatus = 0;
  158. oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
  159. udelay(200);
  160. oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val | 0x80);
  161. } else if (arg < 0) {
  162. oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
  163. udelay(200);
  164. oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val & 0x7F);
  165. ledstatus = 1;
  166. }
  167. }
  168. #endif
  169. int misc_init_r (void)
  170. {
  171. /* check whether the i2c expander #0 is accessible */
  172. if (!oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, 0x7F)) {
  173. udelay(200);
  174. expander0alive = 1;
  175. }
  176. #ifdef CFG_OXC_GENERATE_IP
  177. {
  178. DECLARE_GLOBAL_DATA_PTR;
  179. char str[32];
  180. unsigned long ip = CFG_OXC_IPMASK;
  181. bd_t *bd = gd->bd;
  182. if (expander0alive) {
  183. unsigned char val;
  184. if (!oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val)) {
  185. ip = (ip & 0xffffff00) | ((val & 0x7c) >> 2);
  186. }
  187. }
  188. if ((ip & 0xff) < 3) {
  189. /* if fail, set x.x.x.254 */
  190. ip = (ip & 0xffffff00) | 0xfe;
  191. }
  192. bd->bi_ip_addr = ip;
  193. sprintf(str, "%ld.%ld.%ld.%ld",
  194. (bd->bi_ip_addr & 0xff000000) >> 24,
  195. (bd->bi_ip_addr & 0x00ff0000) >> 16,
  196. (bd->bi_ip_addr & 0x0000ff00) >> 8,
  197. (bd->bi_ip_addr & 0x000000ff));
  198. setenv("ipaddr", str);
  199. printf("ip: %s\n", str);
  200. }
  201. #endif
  202. return (0);
  203. }