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