Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 2000, 2001 Wolfgang Denk, wd@denx.de |
| 3 | * Modified for direct IDE interface |
| 4 | * by Thomas Lange, thomas@corelatus.com |
| 5 | * Modified for direct IDE interface on 8xx without using the PCMCIA |
| 6 | * controller |
| 7 | * by Steven.Scholz@imc-berlin.de |
| 8 | * Moved out of arch/ppc/kernel/m8xx_setup.c, other minor cleanups |
| 9 | * by Mathew Locke <mattl@mvista.com> |
| 10 | */ |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/kernel.h> |
| 14 | #include <linux/mm.h> |
| 15 | #include <linux/stddef.h> |
| 16 | #include <linux/unistd.h> |
| 17 | #include <linux/ptrace.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/user.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/tty.h> |
| 21 | #include <linux/major.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/reboot.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/ioport.h> |
| 26 | #include <linux/ide.h> |
| 27 | #include <linux/bootmem.h> |
| 28 | |
| 29 | #include <asm/mpc8xx.h> |
| 30 | #include <asm/mmu.h> |
| 31 | #include <asm/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <asm/io.h> |
| 33 | #include <asm/pgtable.h> |
| 34 | #include <asm/ide.h> |
| 35 | #include <asm/8xx_immap.h> |
| 36 | #include <asm/machdep.h> |
| 37 | #include <asm/irq.h> |
| 38 | |
| 39 | static int identify (volatile u8 *p); |
| 40 | static void print_fixed (volatile u8 *p); |
| 41 | static void print_funcid (int func); |
| 42 | static int check_ide_device (unsigned long base); |
| 43 | |
| 44 | static void ide_interrupt_ack (void *dev); |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 45 | static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
| 47 | typedef struct ide_ioport_desc { |
| 48 | unsigned long base_off; /* Offset to PCMCIA memory */ |
| 49 | unsigned long reg_off[IDE_NR_PORTS]; /* controller register offsets */ |
| 50 | int irq; /* IRQ */ |
| 51 | } ide_ioport_desc_t; |
| 52 | |
| 53 | ide_ioport_desc_t ioport_dsc[MAX_HWIFS] = { |
| 54 | #ifdef IDE0_BASE_OFFSET |
| 55 | { IDE0_BASE_OFFSET, |
| 56 | { |
| 57 | IDE0_DATA_REG_OFFSET, |
| 58 | IDE0_ERROR_REG_OFFSET, |
| 59 | IDE0_NSECTOR_REG_OFFSET, |
| 60 | IDE0_SECTOR_REG_OFFSET, |
| 61 | IDE0_LCYL_REG_OFFSET, |
| 62 | IDE0_HCYL_REG_OFFSET, |
| 63 | IDE0_SELECT_REG_OFFSET, |
| 64 | IDE0_STATUS_REG_OFFSET, |
| 65 | IDE0_CONTROL_REG_OFFSET, |
| 66 | IDE0_IRQ_REG_OFFSET, |
| 67 | }, |
| 68 | IDE0_INTERRUPT, |
| 69 | }, |
| 70 | #ifdef IDE1_BASE_OFFSET |
| 71 | { IDE1_BASE_OFFSET, |
| 72 | { |
| 73 | IDE1_DATA_REG_OFFSET, |
| 74 | IDE1_ERROR_REG_OFFSET, |
| 75 | IDE1_NSECTOR_REG_OFFSET, |
| 76 | IDE1_SECTOR_REG_OFFSET, |
| 77 | IDE1_LCYL_REG_OFFSET, |
| 78 | IDE1_HCYL_REG_OFFSET, |
| 79 | IDE1_SELECT_REG_OFFSET, |
| 80 | IDE1_STATUS_REG_OFFSET, |
| 81 | IDE1_CONTROL_REG_OFFSET, |
| 82 | IDE1_IRQ_REG_OFFSET, |
| 83 | }, |
| 84 | IDE1_INTERRUPT, |
| 85 | }, |
| 86 | #endif /* IDE1_BASE_OFFSET */ |
| 87 | #endif /* IDE0_BASE_OFFSET */ |
| 88 | }; |
| 89 | |
| 90 | ide_pio_timings_t ide_pio_clocks[6]; |
| 91 | int hold_time[6] = {30, 20, 15, 10, 10, 10 }; /* PIO Mode 5 with IORDY (nonstandard) */ |
| 92 | |
| 93 | /* |
| 94 | * Warning: only 1 (ONE) PCMCIA slot supported here, |
| 95 | * which must be correctly initialized by the firmware (PPCBoot). |
| 96 | */ |
| 97 | static int _slot_ = -1; /* will be read from PCMCIA registers */ |
| 98 | |
| 99 | /* Make clock cycles and always round up */ |
| 100 | #define PCMCIA_MK_CLKS( t, T ) (( (t) * ((T)/1000000) + 999U ) / 1000U ) |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | #define M8XX_PCMCIA_CD2(slot) (0x10000000 >> (slot << 4)) |
| 103 | #define M8XX_PCMCIA_CD1(slot) (0x08000000 >> (slot << 4)) |
| 104 | |
| 105 | /* |
| 106 | * The TQM850L hardware has two pins swapped! Grrrrgh! |
| 107 | */ |
| 108 | #ifdef CONFIG_TQM850L |
| 109 | #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXOE |
| 110 | #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXRESET |
| 111 | #else |
| 112 | #define __MY_PCMCIA_GCRX_CXRESET PCMCIA_GCRX_CXRESET |
| 113 | #define __MY_PCMCIA_GCRX_CXOE PCMCIA_GCRX_CXOE |
| 114 | #endif |
| 115 | |
| 116 | #if defined(CONFIG_BLK_DEV_MPC8xx_IDE) && defined(CONFIG_IDE_8xx_PCCARD) |
| 117 | #define PCMCIA_SCHLVL IDE0_INTERRUPT /* Status Change Interrupt Level */ |
| 118 | static int pcmcia_schlvl = PCMCIA_SCHLVL; |
| 119 | #endif |
| 120 | |
| 121 | /* |
| 122 | * See include/linux/ide.h for definition of hw_regs_t (p, base) |
| 123 | */ |
| 124 | |
| 125 | /* |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 126 | * m8xx_ide_init_ports() for a direct IDE interface _using_ |
| 127 | * MPC8xx's internal PCMCIA interface |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | */ |
| 129 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 130 | static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
| 132 | unsigned long *p = hw->io_ports; |
| 133 | int i; |
| 134 | |
| 135 | typedef struct { |
| 136 | ulong br; |
| 137 | ulong or; |
| 138 | } pcmcia_win_t; |
| 139 | volatile pcmcia_win_t *win; |
| 140 | volatile pcmconf8xx_t *pcmp; |
| 141 | |
| 142 | uint *pgcrx; |
| 143 | u32 pcmcia_phy_base; |
| 144 | u32 pcmcia_phy_end; |
| 145 | static unsigned long pcmcia_base = 0; |
| 146 | unsigned long base; |
| 147 | |
| 148 | *p = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia)); |
| 151 | |
| 152 | if (!pcmcia_base) { |
| 153 | /* |
| 154 | * Read out PCMCIA registers. Since the reset values |
| 155 | * are undefined, we sure hope that they have been |
| 156 | * set up by firmware |
| 157 | */ |
| 158 | |
| 159 | /* Scan all registers for valid settings */ |
| 160 | pcmcia_phy_base = 0xFFFFFFFF; |
| 161 | pcmcia_phy_end = 0; |
| 162 | /* br0 is start of brX and orX regs */ |
| 163 | win = (pcmcia_win_t *) \ |
| 164 | (&(((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pbr0)); |
| 165 | for (i = 0; i < 8; i++) { |
| 166 | if (win->or & 1) { /* This bank is marked as valid */ |
| 167 | if (win->br < pcmcia_phy_base) { |
| 168 | pcmcia_phy_base = win->br; |
| 169 | } |
| 170 | if ((win->br + PCMCIA_MEM_SIZE) > pcmcia_phy_end) { |
| 171 | pcmcia_phy_end = win->br + PCMCIA_MEM_SIZE; |
| 172 | } |
| 173 | /* Check which slot that has been defined */ |
| 174 | _slot_ = (win->or >> 2) & 1; |
| 175 | |
| 176 | } /* Valid bank */ |
| 177 | win++; |
| 178 | } /* for */ |
| 179 | |
| 180 | printk ("PCMCIA slot %c: phys mem %08x...%08x (size %08x)\n", |
| 181 | 'A' + _slot_, |
| 182 | pcmcia_phy_base, pcmcia_phy_end, |
| 183 | pcmcia_phy_end - pcmcia_phy_base); |
| 184 | |
| 185 | pcmcia_base=(unsigned long)ioremap(pcmcia_phy_base, |
| 186 | pcmcia_phy_end-pcmcia_phy_base); |
| 187 | |
| 188 | #ifdef DEBUG |
| 189 | printk ("PCMCIA virt base: %08lx\n", pcmcia_base); |
| 190 | #endif |
| 191 | /* Compute clock cycles for PIO timings */ |
| 192 | for (i=0; i<6; ++i) { |
| 193 | bd_t *binfo = (bd_t *)__res; |
| 194 | |
| 195 | hold_time[i] = |
| 196 | PCMCIA_MK_CLKS (hold_time[i], |
| 197 | binfo->bi_busfreq); |
| 198 | ide_pio_clocks[i].setup_time = |
| 199 | PCMCIA_MK_CLKS (ide_pio_timings[i].setup_time, |
| 200 | binfo->bi_busfreq); |
| 201 | ide_pio_clocks[i].active_time = |
| 202 | PCMCIA_MK_CLKS (ide_pio_timings[i].active_time, |
| 203 | binfo->bi_busfreq); |
| 204 | ide_pio_clocks[i].cycle_time = |
| 205 | PCMCIA_MK_CLKS (ide_pio_timings[i].cycle_time, |
| 206 | binfo->bi_busfreq); |
| 207 | #if 0 |
| 208 | printk ("PIO mode %d timings: %d/%d/%d => %d/%d/%d\n", |
| 209 | i, |
| 210 | ide_pio_clocks[i].setup_time, |
| 211 | ide_pio_clocks[i].active_time, |
| 212 | ide_pio_clocks[i].hold_time, |
| 213 | ide_pio_clocks[i].cycle_time, |
| 214 | ide_pio_timings[i].setup_time, |
| 215 | ide_pio_timings[i].active_time, |
| 216 | ide_pio_timings[i].hold_time, |
| 217 | ide_pio_timings[i].cycle_time); |
| 218 | #endif |
| 219 | } |
| 220 | } |
| 221 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (_slot_ == -1) { |
| 223 | printk ("PCMCIA slot has not been defined! Using A as default\n"); |
| 224 | _slot_ = 0; |
| 225 | } |
| 226 | |
| 227 | #ifdef CONFIG_IDE_8xx_PCCARD |
| 228 | |
| 229 | #ifdef DEBUG |
| 230 | printk ("PIPR = 0x%08X slot %c ==> mask = 0x%X\n", |
| 231 | pcmp->pcmc_pipr, |
| 232 | 'A' + _slot_, |
| 233 | M8XX_PCMCIA_CD1(_slot_) | M8XX_PCMCIA_CD2(_slot_) ); |
| 234 | #endif /* DEBUG */ |
| 235 | |
| 236 | if (pcmp->pcmc_pipr & (M8XX_PCMCIA_CD1(_slot_)|M8XX_PCMCIA_CD2(_slot_))) { |
| 237 | printk ("No card in slot %c: PIPR=%08x\n", |
| 238 | 'A' + _slot_, (u32) pcmp->pcmc_pipr); |
| 239 | return; /* No card in slot */ |
| 240 | } |
| 241 | |
| 242 | check_ide_device (pcmcia_base); |
| 243 | |
| 244 | #endif /* CONFIG_IDE_8xx_PCCARD */ |
| 245 | |
| 246 | base = pcmcia_base + ioport_dsc[data_port].base_off; |
| 247 | #ifdef DEBUG |
| 248 | printk ("base: %08x + %08x = %08x\n", |
| 249 | pcmcia_base, ioport_dsc[data_port].base_off, base); |
| 250 | #endif |
| 251 | |
| 252 | for (i = 0; i < IDE_NR_PORTS; ++i) { |
| 253 | #ifdef DEBUG |
| 254 | printk ("port[%d]: %08x + %08x = %08x\n", |
| 255 | i, |
| 256 | base, |
| 257 | ioport_dsc[data_port].reg_off[i], |
| 258 | i, base + ioport_dsc[data_port].reg_off[i]); |
| 259 | #endif |
| 260 | *p++ = base + ioport_dsc[data_port].reg_off[i]; |
| 261 | } |
| 262 | |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 263 | hw->irq = ioport_dsc[data_port].irq; |
| 264 | hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack; |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | #ifdef CONFIG_IDE_8xx_PCCARD |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 267 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | unsigned int reg; |
| 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | if (_slot_) |
| 271 | pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcrb; |
| 272 | else |
| 273 | pgcrx = &((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pgcra; |
| 274 | |
| 275 | reg = *pgcrx; |
| 276 | reg |= mk_int_int_mask (pcmcia_schlvl) << 24; |
| 277 | reg |= mk_int_int_mask (pcmcia_schlvl) << 16; |
| 278 | *pgcrx = reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 280 | #endif /* CONFIG_IDE_8xx_PCCARD */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 282 | ide_hwifs[data_port].pio_mask = ATA_PIO4; |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 283 | ide_hwifs[data_port].set_pio_mode = m8xx_ide_set_pio_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | /* Enable Harddisk Interrupt, |
| 286 | * and make it edge sensitive |
| 287 | */ |
| 288 | /* (11-18) Set edge detect for irq, no wakeup from low power mode */ |
| 289 | ((immap_t *)IMAP_ADDR)->im_siu_conf.sc_siel |= |
| 290 | (0x80000000 >> ioport_dsc[data_port].irq); |
| 291 | |
| 292 | #ifdef CONFIG_IDE_8xx_PCCARD |
| 293 | /* Make sure we don't get garbage irq */ |
| 294 | ((immap_t *) IMAP_ADDR)->im_pcmcia.pcmc_pscr = 0xFFFF; |
| 295 | |
| 296 | /* Enable falling edge irq */ |
| 297 | pcmp->pcmc_per = 0x100000 >> (16 * _slot_); |
| 298 | #endif /* CONFIG_IDE_8xx_PCCARD */ |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 299 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | #endif /* CONFIG_IDE_8xx_PCCARD || CONFIG_IDE_8xx_DIRECT */ |
| 301 | |
| 302 | /* |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 303 | * m8xx_ide_init_ports() for a direct IDE interface _not_ using |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | * MPC8xx's internal PCMCIA interface |
| 305 | */ |
| 306 | #if defined(CONFIG_IDE_EXT_DIRECT) |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 307 | static void __init m8xx_ide_init_ports(hw_regs_t *hw, unsigned long data_port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
| 309 | unsigned long *p = hw->io_ports; |
| 310 | int i; |
| 311 | |
| 312 | u32 ide_phy_base; |
| 313 | u32 ide_phy_end; |
| 314 | static unsigned long ide_base = 0; |
| 315 | unsigned long base; |
| 316 | |
| 317 | *p = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | if (!ide_base) { |
| 320 | |
| 321 | /* TODO: |
| 322 | * - add code to read ORx, BRx |
| 323 | */ |
| 324 | ide_phy_base = CFG_ATA_BASE_ADDR; |
| 325 | ide_phy_end = CFG_ATA_BASE_ADDR + 0x200; |
| 326 | |
| 327 | printk ("IDE phys mem : %08x...%08x (size %08x)\n", |
| 328 | ide_phy_base, ide_phy_end, |
| 329 | ide_phy_end - ide_phy_base); |
| 330 | |
| 331 | ide_base=(unsigned long)ioremap(ide_phy_base, |
| 332 | ide_phy_end-ide_phy_base); |
| 333 | |
| 334 | #ifdef DEBUG |
| 335 | printk ("IDE virt base: %08lx\n", ide_base); |
| 336 | #endif |
| 337 | } |
| 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | base = ide_base + ioport_dsc[data_port].base_off; |
| 340 | #ifdef DEBUG |
| 341 | printk ("base: %08x + %08x = %08x\n", |
| 342 | ide_base, ioport_dsc[data_port].base_off, base); |
| 343 | #endif |
| 344 | |
| 345 | for (i = 0; i < IDE_NR_PORTS; ++i) { |
| 346 | #ifdef DEBUG |
| 347 | printk ("port[%d]: %08x + %08x = %08x\n", |
| 348 | i, |
| 349 | base, |
| 350 | ioport_dsc[data_port].reg_off[i], |
| 351 | i, base + ioport_dsc[data_port].reg_off[i]); |
| 352 | #endif |
| 353 | *p++ = base + ioport_dsc[data_port].reg_off[i]; |
| 354 | } |
| 355 | |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 356 | /* direct connected IDE drive, i.e. external IRQ */ |
| 357 | hw->irq = ioport_dsc[data_port].irq; |
| 358 | hw->ack_intr = (ide_ack_intr_t *)ide_interrupt_ack; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Bartlomiej Zolnierkiewicz | 4099d14 | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 360 | ide_hwifs[data_port].pio_mask = ATA_PIO4; |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 361 | ide_hwifs[data_port].set_pio_mode = m8xx_ide_set_pio_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | /* Enable Harddisk Interrupt, |
| 364 | * and make it edge sensitive |
| 365 | */ |
| 366 | /* (11-18) Set edge detect for irq, no wakeup from low power mode */ |
| 367 | ((immap_t *) IMAP_ADDR)->im_siu_conf.sc_siel |= |
| 368 | (0x80000000 >> ioport_dsc[data_port].irq); |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 369 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | #endif /* CONFIG_IDE_8xx_DIRECT */ |
| 371 | |
| 372 | |
| 373 | /* -------------------------------------------------------------------- */ |
| 374 | |
| 375 | |
| 376 | /* PCMCIA Timing */ |
| 377 | #ifndef PCMCIA_SHT |
| 378 | #define PCMCIA_SHT(t) ((t & 0x0F)<<16) /* Strobe Hold Time */ |
| 379 | #define PCMCIA_SST(t) ((t & 0x0F)<<12) /* Strobe Setup Time */ |
| 380 | #define PCMCIA_SL(t) ((t==32) ? 0 : ((t & 0x1F)<<7)) /* Strobe Length */ |
| 381 | #endif |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* Calculate PIO timings */ |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 384 | static void m8xx_ide_set_pio_mode(ide_drive_t *drive, const u8 pio) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | #if defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_DIRECT) |
| 387 | volatile pcmconf8xx_t *pcmp; |
| 388 | ulong timing, mask, reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | pcmp = (pcmconf8xx_t *)(&(((immap_t *)IMAP_ADDR)->im_pcmcia)); |
| 391 | |
| 392 | mask = ~(PCMCIA_SHT(0xFF) | PCMCIA_SST(0xFF) | PCMCIA_SL(0xFF)); |
| 393 | |
| 394 | timing = PCMCIA_SHT(hold_time[pio] ) |
| 395 | | PCMCIA_SST(ide_pio_clocks[pio].setup_time ) |
| 396 | | PCMCIA_SL (ide_pio_clocks[pio].active_time) |
| 397 | ; |
| 398 | |
| 399 | #if 1 |
| 400 | printk ("Setting timing bits 0x%08lx in PCMCIA controller\n", timing); |
| 401 | #endif |
| 402 | if ((reg = pcmp->pcmc_por0 & mask) != 0) |
| 403 | pcmp->pcmc_por0 = reg | timing; |
| 404 | |
| 405 | if ((reg = pcmp->pcmc_por1 & mask) != 0) |
| 406 | pcmp->pcmc_por1 = reg | timing; |
| 407 | |
| 408 | if ((reg = pcmp->pcmc_por2 & mask) != 0) |
| 409 | pcmp->pcmc_por2 = reg | timing; |
| 410 | |
| 411 | if ((reg = pcmp->pcmc_por3 & mask) != 0) |
| 412 | pcmp->pcmc_por3 = reg | timing; |
| 413 | |
| 414 | if ((reg = pcmp->pcmc_por4 & mask) != 0) |
| 415 | pcmp->pcmc_por4 = reg | timing; |
| 416 | |
| 417 | if ((reg = pcmp->pcmc_por5 & mask) != 0) |
| 418 | pcmp->pcmc_por5 = reg | timing; |
| 419 | |
| 420 | if ((reg = pcmp->pcmc_por6 & mask) != 0) |
| 421 | pcmp->pcmc_por6 = reg | timing; |
| 422 | |
| 423 | if ((reg = pcmp->pcmc_por7 & mask) != 0) |
| 424 | pcmp->pcmc_por7 = reg | timing; |
| 425 | |
| 426 | #elif defined(CONFIG_IDE_EXT_DIRECT) |
| 427 | |
| 428 | printk("%s[%d] %s: not implemented yet!\n", |
| 429 | __FILE__,__LINE__,__FUNCTION__); |
| 430 | #endif /* defined(CONFIG_IDE_8xx_PCCARD) || defined(CONFIG_IDE_8xx_PCMCIA */ |
| 431 | } |
| 432 | |
| 433 | static void |
| 434 | ide_interrupt_ack (void *dev) |
| 435 | { |
| 436 | #ifdef CONFIG_IDE_8xx_PCCARD |
| 437 | u_int pscr, pipr; |
| 438 | |
| 439 | #if (PCMCIA_SOCKETS_NO == 2) |
| 440 | u_int _slot_; |
| 441 | #endif |
| 442 | |
| 443 | /* get interrupt sources */ |
| 444 | |
| 445 | pscr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr; |
| 446 | pipr = ((volatile immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pipr; |
| 447 | |
| 448 | /* |
| 449 | * report only if both card detect signals are the same |
| 450 | * not too nice done, |
| 451 | * we depend on that CD2 is the bit to the left of CD1... |
| 452 | */ |
| 453 | |
| 454 | if(_slot_==-1){ |
| 455 | printk("PCMCIA slot has not been defined! Using A as default\n"); |
| 456 | _slot_=0; |
| 457 | } |
| 458 | |
| 459 | if(((pipr & M8XX_PCMCIA_CD2(_slot_)) >> 1) ^ |
| 460 | (pipr & M8XX_PCMCIA_CD1(_slot_)) ) { |
| 461 | printk ("card detect interrupt\n"); |
| 462 | } |
| 463 | /* clear the interrupt sources */ |
| 464 | ((immap_t *)IMAP_ADDR)->im_pcmcia.pcmc_pscr = pscr; |
| 465 | |
| 466 | #else /* ! CONFIG_IDE_8xx_PCCARD */ |
| 467 | /* |
| 468 | * Only CONFIG_IDE_8xx_PCCARD is using the interrupt of the |
| 469 | * MPC8xx's PCMCIA controller, so there is nothing to be done here |
| 470 | * for CONFIG_IDE_8xx_DIRECT and CONFIG_IDE_EXT_DIRECT. |
| 471 | * The interrupt is handled somewhere else. -- Steven |
| 472 | */ |
| 473 | #endif /* CONFIG_IDE_8xx_PCCARD */ |
| 474 | } |
| 475 | |
| 476 | |
| 477 | |
| 478 | /* |
| 479 | * CIS Tupel codes |
| 480 | */ |
| 481 | #define CISTPL_NULL 0x00 |
| 482 | #define CISTPL_DEVICE 0x01 |
| 483 | #define CISTPL_LONGLINK_CB 0x02 |
| 484 | #define CISTPL_INDIRECT 0x03 |
| 485 | #define CISTPL_CONFIG_CB 0x04 |
| 486 | #define CISTPL_CFTABLE_ENTRY_CB 0x05 |
| 487 | #define CISTPL_LONGLINK_MFC 0x06 |
| 488 | #define CISTPL_BAR 0x07 |
| 489 | #define CISTPL_PWR_MGMNT 0x08 |
| 490 | #define CISTPL_EXTDEVICE 0x09 |
| 491 | #define CISTPL_CHECKSUM 0x10 |
| 492 | #define CISTPL_LONGLINK_A 0x11 |
| 493 | #define CISTPL_LONGLINK_C 0x12 |
| 494 | #define CISTPL_LINKTARGET 0x13 |
| 495 | #define CISTPL_NO_LINK 0x14 |
| 496 | #define CISTPL_VERS_1 0x15 |
| 497 | #define CISTPL_ALTSTR 0x16 |
| 498 | #define CISTPL_DEVICE_A 0x17 |
| 499 | #define CISTPL_JEDEC_C 0x18 |
| 500 | #define CISTPL_JEDEC_A 0x19 |
| 501 | #define CISTPL_CONFIG 0x1a |
| 502 | #define CISTPL_CFTABLE_ENTRY 0x1b |
| 503 | #define CISTPL_DEVICE_OC 0x1c |
| 504 | #define CISTPL_DEVICE_OA 0x1d |
| 505 | #define CISTPL_DEVICE_GEO 0x1e |
| 506 | #define CISTPL_DEVICE_GEO_A 0x1f |
| 507 | #define CISTPL_MANFID 0x20 |
| 508 | #define CISTPL_FUNCID 0x21 |
| 509 | #define CISTPL_FUNCE 0x22 |
| 510 | #define CISTPL_SWIL 0x23 |
| 511 | #define CISTPL_END 0xff |
| 512 | |
| 513 | /* |
| 514 | * CIS Function ID codes |
| 515 | */ |
| 516 | #define CISTPL_FUNCID_MULTI 0x00 |
| 517 | #define CISTPL_FUNCID_MEMORY 0x01 |
| 518 | #define CISTPL_FUNCID_SERIAL 0x02 |
| 519 | #define CISTPL_FUNCID_PARALLEL 0x03 |
| 520 | #define CISTPL_FUNCID_FIXED 0x04 |
| 521 | #define CISTPL_FUNCID_VIDEO 0x05 |
| 522 | #define CISTPL_FUNCID_NETWORK 0x06 |
| 523 | #define CISTPL_FUNCID_AIMS 0x07 |
| 524 | #define CISTPL_FUNCID_SCSI 0x08 |
| 525 | |
| 526 | /* |
| 527 | * Fixed Disk FUNCE codes |
| 528 | */ |
| 529 | #define CISTPL_IDE_INTERFACE 0x01 |
| 530 | |
| 531 | #define CISTPL_FUNCE_IDE_IFACE 0x01 |
| 532 | #define CISTPL_FUNCE_IDE_MASTER 0x02 |
| 533 | #define CISTPL_FUNCE_IDE_SLAVE 0x03 |
| 534 | |
| 535 | /* First feature byte */ |
| 536 | #define CISTPL_IDE_SILICON 0x04 |
| 537 | #define CISTPL_IDE_UNIQUE 0x08 |
| 538 | #define CISTPL_IDE_DUAL 0x10 |
| 539 | |
| 540 | /* Second feature byte */ |
| 541 | #define CISTPL_IDE_HAS_SLEEP 0x01 |
| 542 | #define CISTPL_IDE_HAS_STANDBY 0x02 |
| 543 | #define CISTPL_IDE_HAS_IDLE 0x04 |
| 544 | #define CISTPL_IDE_LOW_POWER 0x08 |
| 545 | #define CISTPL_IDE_REG_INHIBIT 0x10 |
| 546 | #define CISTPL_IDE_HAS_INDEX 0x20 |
| 547 | #define CISTPL_IDE_IOIS16 0x40 |
| 548 | |
| 549 | |
| 550 | /* -------------------------------------------------------------------- */ |
| 551 | |
| 552 | |
| 553 | #define MAX_TUPEL_SZ 512 |
| 554 | #define MAX_FEATURES 4 |
| 555 | |
| 556 | static int check_ide_device (unsigned long base) |
| 557 | { |
| 558 | volatile u8 *ident = NULL; |
| 559 | volatile u8 *feature_p[MAX_FEATURES]; |
| 560 | volatile u8 *p, *start; |
| 561 | int n_features = 0; |
| 562 | u8 func_id = ~0; |
| 563 | u8 code, len; |
| 564 | unsigned short config_base = 0; |
| 565 | int found = 0; |
| 566 | int i; |
| 567 | |
| 568 | #ifdef DEBUG |
| 569 | printk ("PCMCIA MEM: %08lX\n", base); |
| 570 | #endif |
| 571 | start = p = (volatile u8 *) base; |
| 572 | |
| 573 | while ((p - start) < MAX_TUPEL_SZ) { |
| 574 | |
| 575 | code = *p; p += 2; |
| 576 | |
| 577 | if (code == 0xFF) { /* End of chain */ |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | len = *p; p += 2; |
| 582 | #ifdef DEBUG_PCMCIA |
| 583 | { volatile u8 *q = p; |
| 584 | printk ("\nTuple code %02x length %d\n\tData:", |
| 585 | code, len); |
| 586 | |
| 587 | for (i = 0; i < len; ++i) { |
| 588 | printk (" %02x", *q); |
| 589 | q+= 2; |
| 590 | } |
| 591 | } |
| 592 | #endif /* DEBUG_PCMCIA */ |
| 593 | switch (code) { |
| 594 | case CISTPL_VERS_1: |
| 595 | ident = p + 4; |
| 596 | break; |
| 597 | case CISTPL_FUNCID: |
| 598 | func_id = *p; |
| 599 | break; |
| 600 | case CISTPL_FUNCE: |
| 601 | if (n_features < MAX_FEATURES) |
| 602 | feature_p[n_features++] = p; |
| 603 | break; |
| 604 | case CISTPL_CONFIG: |
| 605 | config_base = (*(p+6) << 8) + (*(p+4)); |
| 606 | default: |
| 607 | break; |
| 608 | } |
| 609 | p += 2 * len; |
| 610 | } |
| 611 | |
| 612 | found = identify (ident); |
| 613 | |
| 614 | if (func_id != ((u8)~0)) { |
| 615 | print_funcid (func_id); |
| 616 | |
| 617 | if (func_id == CISTPL_FUNCID_FIXED) |
| 618 | found = 1; |
| 619 | else |
| 620 | return (1); /* no disk drive */ |
| 621 | } |
| 622 | |
| 623 | for (i=0; i<n_features; ++i) { |
| 624 | print_fixed (feature_p[i]); |
| 625 | } |
| 626 | |
| 627 | if (!found) { |
| 628 | printk ("unknown card type\n"); |
| 629 | return (1); |
| 630 | } |
| 631 | |
| 632 | /* set level mode irq and I/O mapped device in config reg*/ |
| 633 | *((u8 *)(base + config_base)) = 0x41; |
| 634 | |
| 635 | return (0); |
| 636 | } |
| 637 | |
| 638 | /* ------------------------------------------------------------------------- */ |
| 639 | |
| 640 | static void print_funcid (int func) |
| 641 | { |
| 642 | switch (func) { |
| 643 | case CISTPL_FUNCID_MULTI: |
| 644 | printk (" Multi-Function"); |
| 645 | break; |
| 646 | case CISTPL_FUNCID_MEMORY: |
| 647 | printk (" Memory"); |
| 648 | break; |
| 649 | case CISTPL_FUNCID_SERIAL: |
| 650 | printk (" Serial Port"); |
| 651 | break; |
| 652 | case CISTPL_FUNCID_PARALLEL: |
| 653 | printk (" Parallel Port"); |
| 654 | break; |
| 655 | case CISTPL_FUNCID_FIXED: |
| 656 | printk (" Fixed Disk"); |
| 657 | break; |
| 658 | case CISTPL_FUNCID_VIDEO: |
| 659 | printk (" Video Adapter"); |
| 660 | break; |
| 661 | case CISTPL_FUNCID_NETWORK: |
| 662 | printk (" Network Adapter"); |
| 663 | break; |
| 664 | case CISTPL_FUNCID_AIMS: |
| 665 | printk (" AIMS Card"); |
| 666 | break; |
| 667 | case CISTPL_FUNCID_SCSI: |
| 668 | printk (" SCSI Adapter"); |
| 669 | break; |
| 670 | default: |
| 671 | printk (" Unknown"); |
| 672 | break; |
| 673 | } |
| 674 | printk (" Card\n"); |
| 675 | } |
| 676 | |
| 677 | /* ------------------------------------------------------------------------- */ |
| 678 | |
| 679 | static void print_fixed (volatile u8 *p) |
| 680 | { |
| 681 | if (p == NULL) |
| 682 | return; |
| 683 | |
| 684 | switch (*p) { |
| 685 | case CISTPL_FUNCE_IDE_IFACE: |
| 686 | { u8 iface = *(p+2); |
| 687 | |
| 688 | printk ((iface == CISTPL_IDE_INTERFACE) ? " IDE" : " unknown"); |
| 689 | printk (" interface "); |
| 690 | break; |
| 691 | } |
| 692 | case CISTPL_FUNCE_IDE_MASTER: |
| 693 | case CISTPL_FUNCE_IDE_SLAVE: |
| 694 | { u8 f1 = *(p+2); |
| 695 | u8 f2 = *(p+4); |
| 696 | |
| 697 | printk ((f1 & CISTPL_IDE_SILICON) ? " [silicon]" : " [rotating]"); |
| 698 | |
| 699 | if (f1 & CISTPL_IDE_UNIQUE) |
| 700 | printk (" [unique]"); |
| 701 | |
| 702 | printk ((f1 & CISTPL_IDE_DUAL) ? " [dual]" : " [single]"); |
| 703 | |
| 704 | if (f2 & CISTPL_IDE_HAS_SLEEP) |
| 705 | printk (" [sleep]"); |
| 706 | |
| 707 | if (f2 & CISTPL_IDE_HAS_STANDBY) |
| 708 | printk (" [standby]"); |
| 709 | |
| 710 | if (f2 & CISTPL_IDE_HAS_IDLE) |
| 711 | printk (" [idle]"); |
| 712 | |
| 713 | if (f2 & CISTPL_IDE_LOW_POWER) |
| 714 | printk (" [low power]"); |
| 715 | |
| 716 | if (f2 & CISTPL_IDE_REG_INHIBIT) |
| 717 | printk (" [reg inhibit]"); |
| 718 | |
| 719 | if (f2 & CISTPL_IDE_HAS_INDEX) |
| 720 | printk (" [index]"); |
| 721 | |
| 722 | if (f2 & CISTPL_IDE_IOIS16) |
| 723 | printk (" [IOis16]"); |
| 724 | |
| 725 | break; |
| 726 | } |
| 727 | } |
| 728 | printk ("\n"); |
| 729 | } |
| 730 | |
| 731 | /* ------------------------------------------------------------------------- */ |
| 732 | |
| 733 | |
| 734 | #define MAX_IDENT_CHARS 64 |
| 735 | #define MAX_IDENT_FIELDS 4 |
| 736 | |
| 737 | static u8 *known_cards[] = { |
| 738 | "ARGOSY PnPIDE D5", |
| 739 | NULL |
| 740 | }; |
| 741 | |
| 742 | static int identify (volatile u8 *p) |
| 743 | { |
| 744 | u8 id_str[MAX_IDENT_CHARS]; |
| 745 | u8 data; |
| 746 | u8 *t; |
| 747 | u8 **card; |
| 748 | int i, done; |
| 749 | |
| 750 | if (p == NULL) |
| 751 | return (0); /* Don't know */ |
| 752 | |
| 753 | t = id_str; |
| 754 | done =0; |
| 755 | |
| 756 | for (i=0; i<=4 && !done; ++i, p+=2) { |
| 757 | while ((data = *p) != '\0') { |
| 758 | if (data == 0xFF) { |
| 759 | done = 1; |
| 760 | break; |
| 761 | } |
| 762 | *t++ = data; |
| 763 | if (t == &id_str[MAX_IDENT_CHARS-1]) { |
| 764 | done = 1; |
| 765 | break; |
| 766 | } |
| 767 | p += 2; |
| 768 | } |
| 769 | if (!done) |
| 770 | *t++ = ' '; |
| 771 | } |
| 772 | *t = '\0'; |
| 773 | while (--t > id_str) { |
| 774 | if (*t == ' ') |
| 775 | *t = '\0'; |
| 776 | else |
| 777 | break; |
| 778 | } |
| 779 | printk ("Card ID: %s\n", id_str); |
| 780 | |
| 781 | for (card=known_cards; *card; ++card) { |
| 782 | if (strcmp(*card, id_str) == 0) { /* found! */ |
| 783 | return (1); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | return (0); /* don't know */ |
| 788 | } |
| 789 | |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 790 | static int __init mpc8xx_ide_probe(void) |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 791 | { |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 792 | hw_regs_t hw; |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 793 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
| 794 | |
| 795 | #ifdef IDE0_BASE_OFFSET |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 796 | memset(&hw, 0, sizeof(hw)); |
| 797 | m8xx_ide_init_ports(&hw, 0); |
| 798 | ide_init_port_hw(&ide_hwifs[0], &hw); |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 799 | idx[0] = 0; |
| 800 | #ifdef IDE1_BASE_OFFSET |
Bartlomiej Zolnierkiewicz | 2661b13 | 2008-04-18 00:46:29 +0200 | [diff] [blame] | 801 | memset(&hw, 0, sizeof(hw)); |
| 802 | m8xx_ide_init_ports(&hw, 1); |
| 803 | ide_init_port_hw(&ide_hwifs[1], &hw); |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 804 | idx[1] = 1; |
| 805 | #endif |
| 806 | #endif |
| 807 | |
Bartlomiej Zolnierkiewicz | c413b9b | 2008-02-02 19:56:31 +0100 | [diff] [blame] | 808 | ide_device_add(idx, NULL); |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 809 | |
| 810 | return 0; |
Bartlomiej Zolnierkiewicz | 8ac4ce7 | 2008-01-26 20:13:06 +0100 | [diff] [blame] | 811 | } |
Bartlomiej Zolnierkiewicz | ade2daf | 2008-01-26 20:13:07 +0100 | [diff] [blame] | 812 | |
| 813 | module_init(mpc8xx_ide_probe); |
Adrian Bunk | 20e3dd8 | 2008-04-02 21:22:03 +0200 | [diff] [blame] | 814 | |
| 815 | MODULE_LICENSE("GPL"); |