cpc45.c 6.6 KB

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