mvblue.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * GNU General Public License for more details.
  3. *
  4. * MATRIX Vision GmbH / June 2002-Nov 2003
  5. * Andre Schwarz
  6. */
  7. #include <common.h>
  8. #include <mpc824x.h>
  9. #include <asm/io.h>
  10. #include <ns16550.h>
  11. #ifdef CONFIG_PCI
  12. #include <pci.h>
  13. #endif
  14. u32 get_BoardType(void);
  15. #define PCI_CONFIG(b,d,f,r) cpu_to_le32(0x80000000 | ((b&0xff)<<16) \
  16. | ((d&0x1f)<<11) \
  17. | ((f&0x7)<<7) \
  18. | (r&0xfc) )
  19. int mv_pci_read( int bus, int dev, int func, int reg )
  20. {
  21. *(u32*)(0xfec00cf8) = PCI_CONFIG(bus,dev,func,reg);
  22. asm("sync");
  23. return cpu_to_le32( *(u32*)(0xfee00cfc) );
  24. }
  25. u32 get_BoardType() {
  26. return ( mv_pci_read(0,0xe,0,0) == 0x06801095 ? 0 : 1 );
  27. }
  28. void init_2nd_DUART(void)
  29. {
  30. NS16550_t console = (NS16550_t)CFG_NS16550_COM2;
  31. int clock_divisor = CFG_NS16550_CLK / 16 / CONFIG_BAUDRATE;
  32. *(u8*)(0xfc004511) = 0x1;
  33. NS16550_init(console, clock_divisor);
  34. }
  35. void hw_watchdog_reset(void)
  36. {
  37. if (get_BoardType() == 0 ) {
  38. *(u32*)(0xff000005) = 0;
  39. asm("sync");
  40. }
  41. }
  42. int checkboard (void)
  43. {
  44. DECLARE_GLOBAL_DATA_PTR;
  45. ulong busfreq = get_bus_freq(0);
  46. char buf[32];
  47. u32 BoardType = get_BoardType();
  48. char *BoardName[2] = { "mvBlueBOX", "mvBlueLYNX" };
  49. char *p;
  50. bd_t *bd = gd->bd;
  51. hw_watchdog_reset();
  52. printf("U-Boot (%s) running on mvBLUE device.\n", MV_VERSION);
  53. printf(" Found %s running at %s MHz memory clock.\n", BoardName[BoardType], strmhz(buf, busfreq) );
  54. init_2nd_DUART();
  55. if ( (p = getenv("console_nr")) != NULL ) {
  56. unsigned long con_nr = simple_strtoul( p, NULL, 10) & 3;
  57. bd->bi_baudrate &= ~3;
  58. bd->bi_baudrate |= con_nr & 3;
  59. }
  60. return 0;
  61. }
  62. long int initdram (int board_type)
  63. {
  64. int i, cnt;
  65. volatile uchar * base= CFG_SDRAM_BASE;
  66. volatile ulong * addr;
  67. ulong save[32];
  68. ulong val, ret = 0;
  69. for (i=0, cnt=(CFG_MAX_RAM_SIZE / sizeof(long)) >> 1; cnt > 0; cnt >>= 1) {
  70. addr = (volatile ulong *)base + cnt;
  71. save[i++] = *addr;
  72. *addr = ~cnt;
  73. }
  74. addr = (volatile ulong *)base;
  75. save[i] = *addr;
  76. *addr = 0;
  77. if (*addr != 0) {
  78. *addr = save[i];
  79. goto Done;
  80. }
  81. for (cnt = 1; cnt <= CFG_MAX_RAM_SIZE / sizeof(long); cnt <<= 1) {
  82. addr = (volatile ulong *)base + cnt;
  83. val = *addr;
  84. *addr = save[--i];
  85. if (val != ~cnt) {
  86. ulong new_bank0_end = cnt * sizeof(long) - 1;
  87. ulong mear1 = mpc824x_mpc107_getreg(MEAR1);
  88. ulong emear1 = mpc824x_mpc107_getreg(EMEAR1);
  89. mear1 = (mear1 & 0xFFFFFF00) |
  90. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_ADDR_SHIFT);
  91. emear1 = (emear1 & 0xFFFFFF00) |
  92. ((new_bank0_end & MICR_ADDR_MASK) >> MICR_EADDR_SHIFT);
  93. mpc824x_mpc107_setreg(MEAR1, mear1);
  94. mpc824x_mpc107_setreg(EMEAR1, emear1);
  95. ret = cnt * sizeof(long);
  96. goto Done;
  97. }
  98. }
  99. ret = CFG_MAX_RAM_SIZE;
  100. Done:
  101. return ret;
  102. }
  103. /* ------------------------------------------------------------------------- */
  104. u8 *dhcp_vendorex_prep(u8 *e)
  105. {
  106. char *ptr;
  107. /* DHCP vendor-class-identifier = 60 */
  108. if ((ptr = getenv("dhcp_vendor-class-identifier"))) {
  109. *e++ = 60;
  110. *e++ = strlen(ptr);
  111. while (*ptr)
  112. *e++ = *ptr++;
  113. }
  114. /* my DHCP_CLIENT_IDENTIFIER = 61 */
  115. if ((ptr = getenv("dhcp_client_id"))) {
  116. *e++ = 61;
  117. *e++ = strlen(ptr);
  118. while (*ptr)
  119. *e++ = *ptr++;
  120. }
  121. return e;
  122. }
  123. u8 *dhcp_vendorex_proc(u8 *popt)
  124. {
  125. return NULL;
  126. }
  127. /* ------------------------------------------------------------------------- */
  128. /*
  129. * Initialize PCI Devices
  130. */
  131. #ifdef CONFIG_PCI
  132. void pci_mvblue_clear_base( struct pci_controller *hose, pci_dev_t dev )
  133. {
  134. u32 cnt;
  135. printf("clear base @ dev/func 0x%02x/0x%02x ... ", PCI_DEV(dev), PCI_FUNC(dev) );
  136. for( cnt = 0; cnt < 6; cnt++ )
  137. pci_hose_write_config_dword( hose, dev, 0x10 + (4*cnt), 0x0 );
  138. printf("done\n");
  139. }
  140. void duart_setup( u32 base, u16 divisor )
  141. {
  142. printf("duart setup ...");
  143. out_8( (u8*)( CFG_ISA_IO+base+3), 0x80);
  144. out_8( (u8*)( CFG_ISA_IO+base+0), divisor & 0xff);
  145. out_8( (u8*)( CFG_ISA_IO+base+1), divisor >> 8 );
  146. out_8( (u8*)( CFG_ISA_IO+base+3), 0x03);
  147. out_8( (u8*)( CFG_ISA_IO+base+4), 0x03);
  148. out_8( (u8*)( CFG_ISA_IO+base+2), 0x07);
  149. printf("done\n");
  150. }
  151. void pci_mvblue_fixup_irq_behind_bridge( struct pci_controller *hose, pci_dev_t bridge, unsigned char irq)
  152. {
  153. pci_dev_t d;
  154. unsigned char bus;
  155. unsigned short vendor,
  156. class;
  157. pci_hose_read_config_byte( hose, bridge, PCI_SECONDARY_BUS, &bus );
  158. for (d = PCI_BDF(bus,0,0);
  159. d < PCI_BDF(bus,PCI_MAX_PCI_DEVICES-1,PCI_MAX_PCI_FUNCTIONS-1);
  160. d += PCI_BDF(0,0,1))
  161. {
  162. pci_hose_read_config_word(hose, d, PCI_VENDOR_ID, &vendor);
  163. if (vendor != 0xffff && vendor != 0x0000)
  164. {
  165. pci_hose_read_config_word( hose, d, PCI_CLASS_DEVICE, &class );
  166. if ( class == PCI_CLASS_BRIDGE_PCI )
  167. pci_mvblue_fixup_irq_behind_bridge( hose, d, irq );
  168. else
  169. pci_hose_write_config_byte( hose, d, PCI_INTERRUPT_LINE, irq );
  170. }
  171. }
  172. }
  173. #define MV_MAX_PCI_BUSSES 3
  174. #define SLOT0_IRQ 3
  175. #define SLOT1_IRQ 4
  176. void pci_mvblue_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
  177. {
  178. unsigned char line=0xff;
  179. unsigned short class;
  180. if( PCI_BUS(dev) == 0 ) {
  181. switch(PCI_DEV(dev)) {
  182. case 0xd:
  183. if ( get_BoardType() == 0 ) {
  184. line = 1;
  185. } else
  186. /* mvBL */
  187. line = 2;
  188. break;
  189. case 0xe:
  190. /* mvBB: IDE */
  191. line = 2;
  192. pci_hose_write_config_byte(hose, dev, 0x8a, 0x20 );
  193. break;
  194. case 0xf:
  195. /* mvBB: Slot0 (Grabber) */
  196. pci_hose_read_config_word( hose, dev, PCI_CLASS_DEVICE, &class );
  197. if ( class == PCI_CLASS_BRIDGE_PCI ) {
  198. pci_mvblue_fixup_irq_behind_bridge( hose, dev, SLOT0_IRQ );
  199. line = 0xff;
  200. } else
  201. line = SLOT0_IRQ;
  202. break;
  203. case 0x10:
  204. /* mvBB: Slot1 */
  205. pci_hose_read_config_word( hose, dev, PCI_CLASS_DEVICE, &class );
  206. if ( class == PCI_CLASS_BRIDGE_PCI ) {
  207. pci_mvblue_fixup_irq_behind_bridge( hose, dev, SLOT1_IRQ );
  208. line = 0xff;
  209. } else
  210. line = SLOT1_IRQ;
  211. break;
  212. default:
  213. printf("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV(dev) );
  214. line = 0xff;
  215. break;
  216. }
  217. pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line );
  218. }
  219. }
  220. struct pci_controller hose = {
  221. fixup_irq: pci_mvblue_fixup_irq
  222. };
  223. void pci_init_board(void)
  224. {
  225. pci_mpc824x_init(&hose);
  226. }
  227. #endif