mvblue.c 5.6 KB

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