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. 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. long size;
  36. long new_bank0_end;
  37. long mear1;
  38. long emear1;
  39. size = get_ram_size(CFG_SDRAM_BASE, CFG_MAX_RAM_SIZE);
  40. new_bank0_end = size - 1;
  41. mear1 = mpc824x_mpc107_getreg(MEAR1);
  42. emear1 = mpc824x_mpc107_getreg(EMEAR1);
  43. mear1 = (mear1 & 0xFFFFFF00) |
  44. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
  45. emear1 = (emear1 & 0xFFFFFF00) |
  46. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
  47. mpc824x_mpc107_setreg(MEAR1, mear1);
  48. mpc824x_mpc107_setreg(EMEAR1, emear1);
  49. return (size);
  50. #else
  51. /* if U-Boot starts from RAM, then suppose we have 16Mb of RAM */
  52. return (16 << 20);
  53. #endif
  54. }
  55. /*
  56. * Initialize PCI Devices, report devices found.
  57. */
  58. #ifndef CONFIG_PCI_PNP
  59. static struct pci_config_table pci_oxc_config_table[] = {
  60. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x14, PCI_ANY_ID,
  61. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  62. PCI_ENET0_MEMADDR,
  63. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  64. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x15, PCI_ANY_ID,
  65. pci_cfgfunc_config_device, { PCI_ENET1_IOADDR,
  66. PCI_ENET1_MEMADDR,
  67. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  68. { }
  69. };
  70. #endif
  71. static struct pci_controller hose = {
  72. #ifndef CONFIG_PCI_PNP
  73. config_table: pci_oxc_config_table,
  74. #endif
  75. };
  76. void pci_init_board (void)
  77. {
  78. pci_mpc824x_init(&hose);
  79. }
  80. int board_pre_init (void)
  81. {
  82. *(volatile unsigned char *)(CFG_CPLD_RESET) = 0x89;
  83. return 0;
  84. }
  85. #ifdef CONFIG_WATCHDOG
  86. void oxc_wdt_reset(void)
  87. {
  88. *(volatile unsigned char *)(CFG_CPLD_WATCHDOG) = 0xff;
  89. }
  90. void watchdog_reset(void)
  91. {
  92. int re_enable = disable_interrupts();
  93. oxc_wdt_reset();
  94. if (re_enable)
  95. enable_interrupts();
  96. }
  97. #endif
  98. static int oxc_get_expander(unsigned char addr, unsigned char * val)
  99. {
  100. return i2c_read(addr, 0, 0, val, 1);
  101. }
  102. static int oxc_set_expander(unsigned char addr, unsigned char val)
  103. {
  104. return i2c_write(addr, 0, 0, &val, 1);
  105. }
  106. static int expander0alive = 0;
  107. #ifdef CONFIG_SHOW_ACTIVITY
  108. static int ledtoggle = 0;
  109. static int ledstatus = 1;
  110. void oxc_toggle_activeled(void)
  111. {
  112. ledtoggle++;
  113. }
  114. void board_show_activity (ulong timestamp)
  115. {
  116. if ((timestamp % (CFG_HZ / 10)) == 0)
  117. oxc_toggle_activeled ();
  118. }
  119. void show_activity(int arg)
  120. {
  121. static unsigned char led = 0;
  122. unsigned char val;
  123. if (!expander0alive) return;
  124. if ((ledtoggle > (2 * arg)) && ledstatus) {
  125. led ^= 0x80;
  126. oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
  127. udelay(200);
  128. oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, (val & 0x7F) | led);
  129. ledtoggle = 0;
  130. }
  131. }
  132. #endif
  133. #ifdef CONFIG_SHOW_BOOT_PROGRESS
  134. void show_boot_progress(int arg)
  135. {
  136. unsigned char val;
  137. if (!expander0alive) return;
  138. if (arg > 0 && ledstatus) {
  139. ledstatus = 0;
  140. oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
  141. udelay(200);
  142. oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val | 0x80);
  143. } else if (arg < 0) {
  144. oxc_get_expander(CFG_I2C_EXPANDER0_ADDR, &val);
  145. udelay(200);
  146. oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, val & 0x7F);
  147. ledstatus = 1;
  148. }
  149. }
  150. #endif
  151. int misc_init_r (void)
  152. {
  153. /* check whether the i2c expander #0 is accessible */
  154. if (!oxc_set_expander(CFG_I2C_EXPANDER0_ADDR, 0x7F)) {
  155. udelay(200);
  156. expander0alive = 1;
  157. }
  158. #ifdef CFG_OXC_GENERATE_IP
  159. {
  160. DECLARE_GLOBAL_DATA_PTR;
  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. }