mvblue.c 5.7 KB

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