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