oxc.c 4.8 KB

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