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