cpc45.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * (C) Copyright 2001
  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 <asm/processor.h>
  26. #include <asm/io.h>
  27. #include <pci.h>
  28. #include <i2c.h>
  29. #include <netdev.h>
  30. int sysControlDisplay(int digit, uchar ascii_code);
  31. extern void Plx9030Init(void);
  32. extern void SPD67290Init(void);
  33. /* We have to clear the initial data area here. Couldn't have done it
  34. * earlier because DRAM had not been initialized.
  35. */
  36. int board_early_init_f(void)
  37. {
  38. /* enable DUAL UART Mode on CPC45 */
  39. *(uchar*)DUART_DCR |= 0x1; /* set DCM bit */
  40. return 0;
  41. }
  42. int checkboard(void)
  43. {
  44. /*
  45. char revision = BOARD_REV;
  46. */
  47. ulong busfreq = get_bus_freq(0);
  48. char buf[32];
  49. puts ("CPC45 ");
  50. /*
  51. printf("Revision %d ", revision);
  52. */
  53. printf("Local Bus at %s MHz\n", strmhz(buf, busfreq));
  54. return 0;
  55. }
  56. phys_size_t initdram (int board_type)
  57. {
  58. int m, row, col, bank, i, ref;
  59. unsigned long start, end;
  60. uint32_t mccr1, mccr2;
  61. uint32_t mear1 = 0, emear1 = 0, msar1 = 0, emsar1 = 0;
  62. uint32_t mear2 = 0, emear2 = 0, msar2 = 0, emsar2 = 0;
  63. uint8_t mber = 0;
  64. unsigned int tmp;
  65. i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
  66. if (i2c_reg_read (0x50, 2) != 0x04)
  67. return 0; /* Memory type */
  68. m = i2c_reg_read (0x50, 5); /* # of physical banks */
  69. row = i2c_reg_read (0x50, 3); /* # of rows */
  70. col = i2c_reg_read (0x50, 4); /* # of columns */
  71. bank = i2c_reg_read (0x50, 17); /* # of logical banks */
  72. ref = i2c_reg_read (0x50, 12); /* refresh rate / type */
  73. CONFIG_READ_WORD(MCCR1, mccr1);
  74. mccr1 &= 0xffff0000;
  75. CONFIG_READ_WORD(MCCR2, mccr2);
  76. mccr2 &= 0xffff0000;
  77. start = CONFIG_SYS_SDRAM_BASE;
  78. end = start + (1 << (col + row + 3) ) * bank - 1;
  79. for (i = 0; i < m; i++) {
  80. mccr1 |= ((row == 13)? 2 : (bank == 4)? 0 : 3) << i * 2;
  81. if (i < 4) {
  82. msar1 |= ((start >> 20) & 0xff) << i * 8;
  83. emsar1 |= ((start >> 28) & 0xff) << i * 8;
  84. mear1 |= ((end >> 20) & 0xff) << i * 8;
  85. emear1 |= ((end >> 28) & 0xff) << i * 8;
  86. } else {
  87. msar2 |= ((start >> 20) & 0xff) << (i-4) * 8;
  88. emsar2 |= ((start >> 28) & 0xff) << (i-4) * 8;
  89. mear2 |= ((end >> 20) & 0xff) << (i-4) * 8;
  90. emear2 |= ((end >> 28) & 0xff) << (i-4) * 8;
  91. }
  92. mber |= 1 << i;
  93. start += (1 << (col + row + 3) ) * bank;
  94. end += (1 << (col + row + 3) ) * bank;
  95. }
  96. for (; i < 8; i++) {
  97. if (i < 4) {
  98. msar1 |= 0xff << i * 8;
  99. emsar1 |= 0x30 << i * 8;
  100. mear1 |= 0xff << i * 8;
  101. emear1 |= 0x30 << i * 8;
  102. } else {
  103. msar2 |= 0xff << (i-4) * 8;
  104. emsar2 |= 0x30 << (i-4) * 8;
  105. mear2 |= 0xff << (i-4) * 8;
  106. emear2 |= 0x30 << (i-4) * 8;
  107. }
  108. }
  109. switch(ref) {
  110. case 0x00:
  111. case 0x80:
  112. tmp = get_bus_freq(0) / 1000000 * 15625 / 1000 - 22;
  113. break;
  114. case 0x01:
  115. case 0x81:
  116. tmp = get_bus_freq(0) / 1000000 * 3900 / 1000 - 22;
  117. break;
  118. case 0x02:
  119. case 0x82:
  120. tmp = get_bus_freq(0) / 1000000 * 7800 / 1000 - 22;
  121. break;
  122. case 0x03:
  123. case 0x83:
  124. tmp = get_bus_freq(0) / 1000000 * 31300 / 1000 - 22;
  125. break;
  126. case 0x04:
  127. case 0x84:
  128. tmp = get_bus_freq(0) / 1000000 * 62500 / 1000 - 22;
  129. break;
  130. case 0x05:
  131. case 0x85:
  132. tmp = get_bus_freq(0) / 1000000 * 125000 / 1000 - 22;
  133. break;
  134. default:
  135. tmp = 0x512;
  136. break;
  137. }
  138. CONFIG_WRITE_WORD(MCCR1, mccr1);
  139. CONFIG_WRITE_WORD(MCCR2, tmp << MCCR2_REFINT_SHIFT);
  140. CONFIG_WRITE_WORD(MSAR1, msar1);
  141. CONFIG_WRITE_WORD(EMSAR1, emsar1);
  142. CONFIG_WRITE_WORD(MEAR1, mear1);
  143. CONFIG_WRITE_WORD(EMEAR1, emear1);
  144. CONFIG_WRITE_WORD(MSAR2, msar2);
  145. CONFIG_WRITE_WORD(EMSAR2, emsar2);
  146. CONFIG_WRITE_WORD(MEAR2, mear2);
  147. CONFIG_WRITE_WORD(EMEAR2, emear2);
  148. CONFIG_WRITE_BYTE(MBER, mber);
  149. return (1 << (col + row + 3) ) * bank * m;
  150. }
  151. /*
  152. * Initialize PCI Devices, report devices found.
  153. */
  154. static struct pci_config_table pci_cpc45_config_table[] = {
  155. #ifndef CONFIG_PCI_PNP
  156. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0F, PCI_ANY_ID,
  157. pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
  158. PCI_ENET0_MEMADDR,
  159. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  160. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0D, PCI_ANY_ID,
  161. pci_cfgfunc_config_device, { PCI_PLX9030_IOADDR,
  162. PCI_PLX9030_MEMADDR,
  163. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER }},
  164. { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 0x0E, PCI_ANY_ID,
  165. pci_cfgfunc_config_device, { PCMCIA_IO_BASE,
  166. PCMCIA_IO_BASE,
  167. PCI_COMMAND_MEMORY | PCI_COMMAND_IO }},
  168. #endif /*CONFIG_PCI_PNP*/
  169. { }
  170. };
  171. struct pci_controller hose = {
  172. #ifndef CONFIG_PCI_PNP
  173. config_table: pci_cpc45_config_table,
  174. #endif
  175. };
  176. void pci_init_board(void)
  177. {
  178. pci_mpc824x_init(&hose);
  179. /* init PCI_to_LOCAL Bus BRIDGE */
  180. Plx9030Init();
  181. /* Clear Display */
  182. DISP_CWORD = 0x0;
  183. sysControlDisplay(0,' ');
  184. sysControlDisplay(1,'C');
  185. sysControlDisplay(2,'P');
  186. sysControlDisplay(3,'C');
  187. sysControlDisplay(4,' ');
  188. sysControlDisplay(5,'4');
  189. sysControlDisplay(6,'5');
  190. sysControlDisplay(7,' ');
  191. }
  192. /**************************************************************************
  193. *
  194. * sysControlDisplay - controls one of the Alphanum. Display digits.
  195. *
  196. * This routine will write an ASCII character to the display digit requested.
  197. *
  198. * SEE ALSO:
  199. *
  200. * RETURNS: NA
  201. */
  202. int sysControlDisplay (int digit, /* number of digit 0..7 */
  203. uchar ascii_code /* ASCII code */
  204. )
  205. {
  206. if ((digit < 0) || (digit > 7))
  207. return (-1);
  208. *((volatile uchar *) (DISP_CHR_RAM + digit)) = ascii_code;
  209. return (0);
  210. }
  211. #if defined(CONFIG_CMD_PCMCIA)
  212. #ifdef CONFIG_SYS_PCMCIA_MEM_ADDR
  213. volatile unsigned char *pcmcia_mem = (unsigned char*)CONFIG_SYS_PCMCIA_MEM_ADDR;
  214. #endif
  215. int pcmcia_init(void)
  216. {
  217. u_int rc;
  218. debug ("Enable PCMCIA " PCMCIA_SLOT_MSG "\n");
  219. rc = i82365_init();
  220. return rc;
  221. }
  222. #endif
  223. # ifdef CONFIG_IDE_LED
  224. void ide_led (uchar led, uchar status)
  225. {
  226. u_char val;
  227. /* We have one PCMCIA slot and use LED H4 for the IDE Interface */
  228. val = readb(BCSR_BASE + 0x04);
  229. if (status) { /* led on */
  230. val |= B_CTRL_LED0;
  231. } else {
  232. val &= ~B_CTRL_LED0;
  233. }
  234. writeb(val, BCSR_BASE + 0x04);
  235. }
  236. # endif
  237. int board_eth_init(bd_t *bis)
  238. {
  239. return pci_eth_init(bis);
  240. }