diff options
Diffstat (limited to 'drivers/ide/pci/cmd640.c')
-rw-r--r-- | drivers/ide/pci/cmd640.c | 188 |
1 files changed, 93 insertions, 95 deletions
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c index a1cfe033a55f..b076dbfc43a7 100644 --- a/drivers/ide/pci/cmd640.c +++ b/drivers/ide/pci/cmd640.c | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | /* | 5 | /* |
6 | * Original authors: abramov@cecmow.enet.dec.com (Igor Abramov) | 6 | * Original authors: abramov@cecmow.enet.dec.com (Igor Abramov) |
7 | * mlord@pobox.com (Mark Lord) | 7 | * mlord@pobox.com (Mark Lord) |
8 | * | 8 | * |
9 | * See linux/MAINTAINERS for address of current maintainer. | 9 | * See linux/MAINTAINERS for address of current maintainer. |
10 | * | 10 | * |
@@ -98,7 +98,7 @@ | |||
98 | 98 | ||
99 | #define CMD640_PREFETCH_MASKS 1 | 99 | #define CMD640_PREFETCH_MASKS 1 |
100 | 100 | ||
101 | //#define CMD640_DUMP_REGS | 101 | /*#define CMD640_DUMP_REGS */ |
102 | 102 | ||
103 | #include <linux/types.h> | 103 | #include <linux/types.h> |
104 | #include <linux/kernel.h> | 104 | #include <linux/kernel.h> |
@@ -112,7 +112,7 @@ | |||
112 | /* | 112 | /* |
113 | * This flag is set in ide.c by the parameter: ide0=cmd640_vlb | 113 | * This flag is set in ide.c by the parameter: ide0=cmd640_vlb |
114 | */ | 114 | */ |
115 | int cmd640_vlb = 0; | 115 | int cmd640_vlb; |
116 | 116 | ||
117 | /* | 117 | /* |
118 | * CMD640 specific registers definition. | 118 | * CMD640 specific registers definition. |
@@ -185,7 +185,6 @@ static DEFINE_SPINLOCK(cmd640_lock); | |||
185 | * These are initialized to point at the devices we control | 185 | * These are initialized to point at the devices we control |
186 | */ | 186 | */ |
187 | static ide_hwif_t *cmd_hwif0, *cmd_hwif1; | 187 | static ide_hwif_t *cmd_hwif0, *cmd_hwif1; |
188 | static ide_drive_t *cmd_drives[4]; | ||
189 | 188 | ||
190 | /* | 189 | /* |
191 | * Interface to access cmd640x registers | 190 | * Interface to access cmd640x registers |
@@ -207,13 +206,13 @@ static unsigned int cmd640_chip_version; | |||
207 | 206 | ||
208 | /* PCI method 1 access */ | 207 | /* PCI method 1 access */ |
209 | 208 | ||
210 | static void put_cmd640_reg_pci1 (u16 reg, u8 val) | 209 | static void put_cmd640_reg_pci1(u16 reg, u8 val) |
211 | { | 210 | { |
212 | outl_p((reg & 0xfc) | cmd640_key, 0xcf8); | 211 | outl_p((reg & 0xfc) | cmd640_key, 0xcf8); |
213 | outb_p(val, (reg & 3) | 0xcfc); | 212 | outb_p(val, (reg & 3) | 0xcfc); |
214 | } | 213 | } |
215 | 214 | ||
216 | static u8 get_cmd640_reg_pci1 (u16 reg) | 215 | static u8 get_cmd640_reg_pci1(u16 reg) |
217 | { | 216 | { |
218 | outl_p((reg & 0xfc) | cmd640_key, 0xcf8); | 217 | outl_p((reg & 0xfc) | cmd640_key, 0xcf8); |
219 | return inb_p((reg & 3) | 0xcfc); | 218 | return inb_p((reg & 3) | 0xcfc); |
@@ -221,14 +220,14 @@ static u8 get_cmd640_reg_pci1 (u16 reg) | |||
221 | 220 | ||
222 | /* PCI method 2 access (from CMD datasheet) */ | 221 | /* PCI method 2 access (from CMD datasheet) */ |
223 | 222 | ||
224 | static void put_cmd640_reg_pci2 (u16 reg, u8 val) | 223 | static void put_cmd640_reg_pci2(u16 reg, u8 val) |
225 | { | 224 | { |
226 | outb_p(0x10, 0xcf8); | 225 | outb_p(0x10, 0xcf8); |
227 | outb_p(val, cmd640_key + reg); | 226 | outb_p(val, cmd640_key + reg); |
228 | outb_p(0, 0xcf8); | 227 | outb_p(0, 0xcf8); |
229 | } | 228 | } |
230 | 229 | ||
231 | static u8 get_cmd640_reg_pci2 (u16 reg) | 230 | static u8 get_cmd640_reg_pci2(u16 reg) |
232 | { | 231 | { |
233 | u8 b; | 232 | u8 b; |
234 | 233 | ||
@@ -240,13 +239,13 @@ static u8 get_cmd640_reg_pci2 (u16 reg) | |||
240 | 239 | ||
241 | /* VLB access */ | 240 | /* VLB access */ |
242 | 241 | ||
243 | static void put_cmd640_reg_vlb (u16 reg, u8 val) | 242 | static void put_cmd640_reg_vlb(u16 reg, u8 val) |
244 | { | 243 | { |
245 | outb_p(reg, cmd640_key); | 244 | outb_p(reg, cmd640_key); |
246 | outb_p(val, cmd640_key + 4); | 245 | outb_p(val, cmd640_key + 4); |
247 | } | 246 | } |
248 | 247 | ||
249 | static u8 get_cmd640_reg_vlb (u16 reg) | 248 | static u8 get_cmd640_reg_vlb(u16 reg) |
250 | { | 249 | { |
251 | outb_p(reg, cmd640_key); | 250 | outb_p(reg, cmd640_key); |
252 | return inb_p(cmd640_key + 4); | 251 | return inb_p(cmd640_key + 4); |
@@ -268,11 +267,11 @@ static void put_cmd640_reg(u16 reg, u8 val) | |||
268 | unsigned long flags; | 267 | unsigned long flags; |
269 | 268 | ||
270 | spin_lock_irqsave(&cmd640_lock, flags); | 269 | spin_lock_irqsave(&cmd640_lock, flags); |
271 | __put_cmd640_reg(reg,val); | 270 | __put_cmd640_reg(reg, val); |
272 | spin_unlock_irqrestore(&cmd640_lock, flags); | 271 | spin_unlock_irqrestore(&cmd640_lock, flags); |
273 | } | 272 | } |
274 | 273 | ||
275 | static int __init match_pci_cmd640_device (void) | 274 | static int __init match_pci_cmd640_device(void) |
276 | { | 275 | { |
277 | const u8 ven_dev[4] = {0x95, 0x10, 0x40, 0x06}; | 276 | const u8 ven_dev[4] = {0x95, 0x10, 0x40, 0x06}; |
278 | unsigned int i; | 277 | unsigned int i; |
@@ -292,7 +291,7 @@ static int __init match_pci_cmd640_device (void) | |||
292 | /* | 291 | /* |
293 | * Probe for CMD640x -- pci method 1 | 292 | * Probe for CMD640x -- pci method 1 |
294 | */ | 293 | */ |
295 | static int __init probe_for_cmd640_pci1 (void) | 294 | static int __init probe_for_cmd640_pci1(void) |
296 | { | 295 | { |
297 | __get_cmd640_reg = get_cmd640_reg_pci1; | 296 | __get_cmd640_reg = get_cmd640_reg_pci1; |
298 | __put_cmd640_reg = put_cmd640_reg_pci1; | 297 | __put_cmd640_reg = put_cmd640_reg_pci1; |
@@ -308,7 +307,7 @@ static int __init probe_for_cmd640_pci1 (void) | |||
308 | /* | 307 | /* |
309 | * Probe for CMD640x -- pci method 2 | 308 | * Probe for CMD640x -- pci method 2 |
310 | */ | 309 | */ |
311 | static int __init probe_for_cmd640_pci2 (void) | 310 | static int __init probe_for_cmd640_pci2(void) |
312 | { | 311 | { |
313 | __get_cmd640_reg = get_cmd640_reg_pci2; | 312 | __get_cmd640_reg = get_cmd640_reg_pci2; |
314 | __put_cmd640_reg = put_cmd640_reg_pci2; | 313 | __put_cmd640_reg = put_cmd640_reg_pci2; |
@@ -322,7 +321,7 @@ static int __init probe_for_cmd640_pci2 (void) | |||
322 | /* | 321 | /* |
323 | * Probe for CMD640x -- vlb | 322 | * Probe for CMD640x -- vlb |
324 | */ | 323 | */ |
325 | static int __init probe_for_cmd640_vlb (void) | 324 | static int __init probe_for_cmd640_vlb(void) |
326 | { | 325 | { |
327 | u8 b; | 326 | u8 b; |
328 | 327 | ||
@@ -343,7 +342,7 @@ static int __init probe_for_cmd640_vlb (void) | |||
343 | * Returns 1 if an IDE interface/drive exists at 0x170, | 342 | * Returns 1 if an IDE interface/drive exists at 0x170, |
344 | * Returns 0 otherwise. | 343 | * Returns 0 otherwise. |
345 | */ | 344 | */ |
346 | static int __init secondary_port_responding (void) | 345 | static int __init secondary_port_responding(void) |
347 | { | 346 | { |
348 | unsigned long flags; | 347 | unsigned long flags; |
349 | 348 | ||
@@ -367,7 +366,7 @@ static int __init secondary_port_responding (void) | |||
367 | /* | 366 | /* |
368 | * Dump out all cmd640 registers. May be called from ide.c | 367 | * Dump out all cmd640 registers. May be called from ide.c |
369 | */ | 368 | */ |
370 | static void cmd640_dump_regs (void) | 369 | static void cmd640_dump_regs(void) |
371 | { | 370 | { |
372 | unsigned int reg = cmd640_vlb ? 0x50 : 0x00; | 371 | unsigned int reg = cmd640_vlb ? 0x50 : 0x00; |
373 | 372 | ||
@@ -386,9 +385,8 @@ static void cmd640_dump_regs (void) | |||
386 | * Check whether prefetch is on for a drive, | 385 | * Check whether prefetch is on for a drive, |
387 | * and initialize the unmask flags for safe operation. | 386 | * and initialize the unmask flags for safe operation. |
388 | */ | 387 | */ |
389 | static void __init check_prefetch (unsigned int index) | 388 | static void __init check_prefetch(ide_drive_t *drive, unsigned int index) |
390 | { | 389 | { |
391 | ide_drive_t *drive = cmd_drives[index]; | ||
392 | u8 b = get_cmd640_reg(prefetch_regs[index]); | 390 | u8 b = get_cmd640_reg(prefetch_regs[index]); |
393 | 391 | ||
394 | if (b & prefetch_masks[index]) { /* is prefetch off? */ | 392 | if (b & prefetch_masks[index]) { /* is prefetch off? */ |
@@ -404,28 +402,13 @@ static void __init check_prefetch (unsigned int index) | |||
404 | } | 402 | } |
405 | } | 403 | } |
406 | 404 | ||
407 | /* | ||
408 | * Figure out which devices we control | ||
409 | */ | ||
410 | static void __init setup_device_ptrs (void) | ||
411 | { | ||
412 | cmd_hwif0 = &ide_hwifs[0]; | ||
413 | cmd_hwif1 = &ide_hwifs[1]; | ||
414 | |||
415 | cmd_drives[0] = &cmd_hwif0->drives[0]; | ||
416 | cmd_drives[1] = &cmd_hwif0->drives[1]; | ||
417 | cmd_drives[2] = &cmd_hwif1->drives[0]; | ||
418 | cmd_drives[3] = &cmd_hwif1->drives[1]; | ||
419 | } | ||
420 | |||
421 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | 405 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED |
422 | 406 | ||
423 | /* | 407 | /* |
424 | * Sets prefetch mode for a drive. | 408 | * Sets prefetch mode for a drive. |
425 | */ | 409 | */ |
426 | static void set_prefetch_mode (unsigned int index, int mode) | 410 | static void set_prefetch_mode(ide_drive_t *drive, unsigned int index, int mode) |
427 | { | 411 | { |
428 | ide_drive_t *drive = cmd_drives[index]; | ||
429 | unsigned long flags; | 412 | unsigned long flags; |
430 | int reg = prefetch_regs[index]; | 413 | int reg = prefetch_regs[index]; |
431 | u8 b; | 414 | u8 b; |
@@ -452,7 +435,7 @@ static void set_prefetch_mode (unsigned int index, int mode) | |||
452 | /* | 435 | /* |
453 | * Dump out current drive clocks settings | 436 | * Dump out current drive clocks settings |
454 | */ | 437 | */ |
455 | static void display_clocks (unsigned int index) | 438 | static void display_clocks(unsigned int index) |
456 | { | 439 | { |
457 | u8 active_count, recovery_count; | 440 | u8 active_count, recovery_count; |
458 | 441 | ||
@@ -471,7 +454,7 @@ static void display_clocks (unsigned int index) | |||
471 | * Pack active and recovery counts into single byte representation | 454 | * Pack active and recovery counts into single byte representation |
472 | * used by controller | 455 | * used by controller |
473 | */ | 456 | */ |
474 | static inline u8 pack_nibbles (u8 upper, u8 lower) | 457 | static inline u8 pack_nibbles(u8 upper, u8 lower) |
475 | { | 458 | { |
476 | return ((upper & 0x0f) << 4) | (lower & 0x0f); | 459 | return ((upper & 0x0f) << 4) | (lower & 0x0f); |
477 | } | 460 | } |
@@ -479,7 +462,7 @@ static inline u8 pack_nibbles (u8 upper, u8 lower) | |||
479 | /* | 462 | /* |
480 | * This routine retrieves the initial drive timings from the chipset. | 463 | * This routine retrieves the initial drive timings from the chipset. |
481 | */ | 464 | */ |
482 | static void __init retrieve_drive_counts (unsigned int index) | 465 | static void __init retrieve_drive_counts(unsigned int index) |
483 | { | 466 | { |
484 | u8 b; | 467 | u8 b; |
485 | 468 | ||
@@ -488,10 +471,10 @@ static void __init retrieve_drive_counts (unsigned int index) | |||
488 | */ | 471 | */ |
489 | b = get_cmd640_reg(arttim_regs[index]) & ~0x3f; | 472 | b = get_cmd640_reg(arttim_regs[index]) & ~0x3f; |
490 | switch (b) { | 473 | switch (b) { |
491 | case 0x00: b = 4; break; | 474 | case 0x00: b = 4; break; |
492 | case 0x80: b = 3; break; | 475 | case 0x80: b = 3; break; |
493 | case 0x40: b = 2; break; | 476 | case 0x40: b = 2; break; |
494 | default: b = 5; break; | 477 | default: b = 5; break; |
495 | } | 478 | } |
496 | setup_counts[index] = b; | 479 | setup_counts[index] = b; |
497 | 480 | ||
@@ -508,7 +491,7 @@ static void __init retrieve_drive_counts (unsigned int index) | |||
508 | * This routine writes the prepared setup/active/recovery counts | 491 | * This routine writes the prepared setup/active/recovery counts |
509 | * for a drive into the cmd640 chipset registers to active them. | 492 | * for a drive into the cmd640 chipset registers to active them. |
510 | */ | 493 | */ |
511 | static void program_drive_counts (unsigned int index) | 494 | static void program_drive_counts(ide_drive_t *drive, unsigned int index) |
512 | { | 495 | { |
513 | unsigned long flags; | 496 | unsigned long flags; |
514 | u8 setup_count = setup_counts[index]; | 497 | u8 setup_count = setup_counts[index]; |
@@ -522,8 +505,11 @@ static void program_drive_counts (unsigned int index) | |||
522 | * so we merge the timings, using the slowest value for each timing. | 505 | * so we merge the timings, using the slowest value for each timing. |
523 | */ | 506 | */ |
524 | if (index > 1) { | 507 | if (index > 1) { |
525 | unsigned int mate; | 508 | ide_hwif_t *hwif = drive->hwif; |
526 | if (cmd_drives[mate = index ^ 1]->present) { | 509 | ide_drive_t *peer = &hwif->drives[!drive->select.b.unit]; |
510 | unsigned int mate = index ^ 1; | ||
511 | |||
512 | if (peer->present) { | ||
527 | if (setup_count < setup_counts[mate]) | 513 | if (setup_count < setup_counts[mate]) |
528 | setup_count = setup_counts[mate]; | 514 | setup_count = setup_counts[mate]; |
529 | if (active_count < active_counts[mate]) | 515 | if (active_count < active_counts[mate]) |
@@ -537,11 +523,11 @@ static void program_drive_counts (unsigned int index) | |||
537 | * Convert setup_count to internal chipset representation | 523 | * Convert setup_count to internal chipset representation |
538 | */ | 524 | */ |
539 | switch (setup_count) { | 525 | switch (setup_count) { |
540 | case 4: setup_count = 0x00; break; | 526 | case 4: setup_count = 0x00; break; |
541 | case 3: setup_count = 0x80; break; | 527 | case 3: setup_count = 0x80; break; |
542 | case 1: | 528 | case 1: |
543 | case 2: setup_count = 0x40; break; | 529 | case 2: setup_count = 0x40; break; |
544 | default: setup_count = 0xc0; /* case 5 */ | 530 | default: setup_count = 0xc0; /* case 5 */ |
545 | } | 531 | } |
546 | 532 | ||
547 | /* | 533 | /* |
@@ -562,7 +548,8 @@ static void program_drive_counts (unsigned int index) | |||
562 | /* | 548 | /* |
563 | * Set a specific pio_mode for a drive | 549 | * Set a specific pio_mode for a drive |
564 | */ | 550 | */ |
565 | static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle_time) | 551 | static void cmd640_set_mode(ide_drive_t *drive, unsigned int index, |
552 | u8 pio_mode, unsigned int cycle_time) | ||
566 | { | 553 | { |
567 | int setup_time, active_time, recovery_time, clock_time; | 554 | int setup_time, active_time, recovery_time, clock_time; |
568 | u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count; | 555 | u8 setup_count, active_count, recovery_count, recovery_count2, cycle_count; |
@@ -574,15 +561,15 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle | |||
574 | active_time = ide_pio_timings[pio_mode].active_time; | 561 | active_time = ide_pio_timings[pio_mode].active_time; |
575 | recovery_time = cycle_time - (setup_time + active_time); | 562 | recovery_time = cycle_time - (setup_time + active_time); |
576 | clock_time = 1000 / bus_speed; | 563 | clock_time = 1000 / bus_speed; |
577 | cycle_count = (cycle_time + clock_time - 1) / clock_time; | 564 | cycle_count = DIV_ROUND_UP(cycle_time, clock_time); |
578 | 565 | ||
579 | setup_count = (setup_time + clock_time - 1) / clock_time; | 566 | setup_count = DIV_ROUND_UP(setup_time, clock_time); |
580 | 567 | ||
581 | active_count = (active_time + clock_time - 1) / clock_time; | 568 | active_count = DIV_ROUND_UP(active_time, clock_time); |
582 | if (active_count < 2) | 569 | if (active_count < 2) |
583 | active_count = 2; /* minimum allowed by cmd640 */ | 570 | active_count = 2; /* minimum allowed by cmd640 */ |
584 | 571 | ||
585 | recovery_count = (recovery_time + clock_time - 1) / clock_time; | 572 | recovery_count = DIV_ROUND_UP(recovery_time, clock_time); |
586 | recovery_count2 = cycle_count - (setup_count + active_count); | 573 | recovery_count2 = cycle_count - (setup_count + active_count); |
587 | if (recovery_count2 > recovery_count) | 574 | if (recovery_count2 > recovery_count) |
588 | recovery_count = recovery_count2; | 575 | recovery_count = recovery_count2; |
@@ -611,7 +598,7 @@ static void cmd640_set_mode (unsigned int index, u8 pio_mode, unsigned int cycle | |||
611 | * 1) this is the wrong place to do it (proper is do_special() in ide.c) | 598 | * 1) this is the wrong place to do it (proper is do_special() in ide.c) |
612 | * 2) in practice this is rarely, if ever, necessary | 599 | * 2) in practice this is rarely, if ever, necessary |
613 | */ | 600 | */ |
614 | program_drive_counts (index); | 601 | program_drive_counts(drive, index); |
615 | } | 602 | } |
616 | 603 | ||
617 | static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) | 604 | static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) |
@@ -619,32 +606,26 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio) | |||
619 | unsigned int index = 0, cycle_time; | 606 | unsigned int index = 0, cycle_time; |
620 | u8 b; | 607 | u8 b; |
621 | 608 | ||
622 | while (drive != cmd_drives[index]) { | ||
623 | if (++index > 3) { | ||
624 | printk(KERN_ERR "%s: bad news in %s\n", | ||
625 | drive->name, __FUNCTION__); | ||
626 | return; | ||
627 | } | ||
628 | } | ||
629 | switch (pio) { | 609 | switch (pio) { |
630 | case 6: /* set fast-devsel off */ | 610 | case 6: /* set fast-devsel off */ |
631 | case 7: /* set fast-devsel on */ | 611 | case 7: /* set fast-devsel on */ |
632 | b = get_cmd640_reg(CNTRL) & ~0x27; | 612 | b = get_cmd640_reg(CNTRL) & ~0x27; |
633 | if (pio & 1) | 613 | if (pio & 1) |
634 | b |= 0x27; | 614 | b |= 0x27; |
635 | put_cmd640_reg(CNTRL, b); | 615 | put_cmd640_reg(CNTRL, b); |
636 | printk("%s: %sabled cmd640 fast host timing (devsel)\n", drive->name, (pio & 1) ? "en" : "dis"); | 616 | printk("%s: %sabled cmd640 fast host timing (devsel)\n", |
637 | return; | 617 | drive->name, (pio & 1) ? "en" : "dis"); |
638 | 618 | return; | |
639 | case 8: /* set prefetch off */ | 619 | case 8: /* set prefetch off */ |
640 | case 9: /* set prefetch on */ | 620 | case 9: /* set prefetch on */ |
641 | set_prefetch_mode(index, pio & 1); | 621 | set_prefetch_mode(drive, index, pio & 1); |
642 | printk("%s: %sabled cmd640 prefetch\n", drive->name, (pio & 1) ? "en" : "dis"); | 622 | printk("%s: %sabled cmd640 prefetch\n", |
643 | return; | 623 | drive->name, (pio & 1) ? "en" : "dis"); |
624 | return; | ||
644 | } | 625 | } |
645 | 626 | ||
646 | cycle_time = ide_pio_cycle_time(drive, pio); | 627 | cycle_time = ide_pio_cycle_time(drive, pio); |
647 | cmd640_set_mode(index, pio, cycle_time); | 628 | cmd640_set_mode(drive, index, pio, cycle_time); |
648 | 629 | ||
649 | printk("%s: selected cmd640 PIO mode%d (%dns)", | 630 | printk("%s: selected cmd640 PIO mode%d (%dns)", |
650 | drive->name, pio, cycle_time); | 631 | drive->name, pio, cycle_time); |
@@ -749,7 +730,7 @@ static int __init cmd640x_init(void) | |||
749 | cfr = get_cmd640_reg(CFR); | 730 | cfr = get_cmd640_reg(CFR); |
750 | cmd640_chip_version = cfr & CFR_DEVREV; | 731 | cmd640_chip_version = cfr & CFR_DEVREV; |
751 | if (cmd640_chip_version == 0) { | 732 | if (cmd640_chip_version == 0) { |
752 | printk ("ide: bad cmd640 revision: %d\n", cmd640_chip_version); | 733 | printk("ide: bad cmd640 revision: %d\n", cmd640_chip_version); |
753 | return 0; | 734 | return 0; |
754 | } | 735 | } |
755 | 736 | ||
@@ -764,17 +745,19 @@ static int __init cmd640x_init(void) | |||
764 | printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x" | 745 | printk(KERN_INFO "cmd640: buggy cmd640%c interface on %s, config=0x%02x" |
765 | "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr); | 746 | "\n", 'a' + cmd640_chip_version - 1, bus_type, cfr); |
766 | 747 | ||
748 | cmd_hwif0 = ide_find_port(); | ||
749 | |||
767 | /* | 750 | /* |
768 | * Initialize data for primary port | 751 | * Initialize data for primary port |
769 | */ | 752 | */ |
770 | setup_device_ptrs (); | 753 | if (cmd_hwif0) { |
771 | 754 | ide_init_port_hw(cmd_hwif0, &hw[0]); | |
772 | ide_init_port_hw(cmd_hwif0, &hw[0]); | ||
773 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | 755 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED |
774 | cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode; | 756 | cmd_hwif0->set_pio_mode = &cmd640_set_pio_mode; |
775 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | 757 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ |
776 | 758 | ||
777 | idx[0] = cmd_hwif0->index; | 759 | idx[0] = cmd_hwif0->index; |
760 | } | ||
778 | 761 | ||
779 | /* | 762 | /* |
780 | * Ensure compatibility by always using the slowest timings | 763 | * Ensure compatibility by always using the slowest timings |
@@ -786,10 +769,13 @@ static int __init cmd640x_init(void) | |||
786 | put_cmd640_reg(CMDTIM, 0); | 769 | put_cmd640_reg(CMDTIM, 0); |
787 | put_cmd640_reg(BRST, 0x40); | 770 | put_cmd640_reg(BRST, 0x40); |
788 | 771 | ||
772 | cmd_hwif1 = ide_find_port(); | ||
773 | |||
789 | /* | 774 | /* |
790 | * Try to enable the secondary interface, if not already enabled | 775 | * Try to enable the secondary interface, if not already enabled |
791 | */ | 776 | */ |
792 | if (cmd_hwif1->drives[0].noprobe && cmd_hwif1->drives[1].noprobe) { | 777 | if (cmd_hwif1 && |
778 | cmd_hwif1->drives[0].noprobe && cmd_hwif1->drives[1].noprobe) { | ||
793 | port2 = "not probed"; | 779 | port2 = "not probed"; |
794 | } else { | 780 | } else { |
795 | b = get_cmd640_reg(CNTRL); | 781 | b = get_cmd640_reg(CNTRL); |
@@ -820,7 +806,7 @@ static int __init cmd640x_init(void) | |||
820 | /* | 806 | /* |
821 | * Initialize data for secondary cmd640 port, if enabled | 807 | * Initialize data for secondary cmd640 port, if enabled |
822 | */ | 808 | */ |
823 | if (second_port_cmd640) { | 809 | if (second_port_cmd640 && cmd_hwif1) { |
824 | ide_init_port_hw(cmd_hwif1, &hw[1]); | 810 | ide_init_port_hw(cmd_hwif1, &hw[1]); |
825 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | 811 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED |
826 | cmd_hwif1->set_pio_mode = &cmd640_set_pio_mode; | 812 | cmd_hwif1->set_pio_mode = &cmd640_set_pio_mode; |
@@ -828,7 +814,7 @@ static int __init cmd640x_init(void) | |||
828 | 814 | ||
829 | idx[1] = cmd_hwif1->index; | 815 | idx[1] = cmd_hwif1->index; |
830 | } | 816 | } |
831 | printk(KERN_INFO "%s: %sserialized, secondary interface %s\n", cmd_hwif1->name, | 817 | printk(KERN_INFO "cmd640: %sserialized, secondary interface %s\n", |
832 | second_port_cmd640 ? "" : "not ", port2); | 818 | second_port_cmd640 ? "" : "not ", port2); |
833 | 819 | ||
834 | /* | 820 | /* |
@@ -836,18 +822,30 @@ static int __init cmd640x_init(void) | |||
836 | * Do not unnecessarily disturb any prior BIOS setup of these. | 822 | * Do not unnecessarily disturb any prior BIOS setup of these. |
837 | */ | 823 | */ |
838 | for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) { | 824 | for (index = 0; index < (2 + (second_port_cmd640 << 1)); index++) { |
839 | ide_drive_t *drive = cmd_drives[index]; | 825 | ide_drive_t *drive; |
826 | |||
827 | if (index > 1) { | ||
828 | if (cmd_hwif1 == NULL) | ||
829 | continue; | ||
830 | drive = &cmd_hwif1->drives[index & 1]; | ||
831 | } else { | ||
832 | if (cmd_hwif0 == NULL) | ||
833 | continue; | ||
834 | drive = &cmd_hwif0->drives[index & 1]; | ||
835 | } | ||
836 | |||
840 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED | 837 | #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED |
841 | if (drive->autotune || ((index > 1) && second_port_toggled)) { | 838 | if (drive->autotune || ((index > 1) && second_port_toggled)) { |
842 | /* | 839 | /* |
843 | * Reset timing to the slowest speed and turn off prefetch. | 840 | * Reset timing to the slowest speed and turn off |
844 | * This way, the drive identify code has a better chance. | 841 | * prefetch. This way, the drive identify code has |
842 | * a better chance. | ||
845 | */ | 843 | */ |
846 | setup_counts [index] = 4; /* max possible */ | 844 | setup_counts [index] = 4; /* max possible */ |
847 | active_counts [index] = 16; /* max possible */ | 845 | active_counts [index] = 16; /* max possible */ |
848 | recovery_counts [index] = 16; /* max possible */ | 846 | recovery_counts [index] = 16; /* max possible */ |
849 | program_drive_counts (index); | 847 | program_drive_counts(drive, index); |
850 | set_prefetch_mode (index, 0); | 848 | set_prefetch_mode(drive, index, 0); |
851 | printk("cmd640: drive%d timings/prefetch cleared\n", index); | 849 | printk("cmd640: drive%d timings/prefetch cleared\n", index); |
852 | } else { | 850 | } else { |
853 | /* | 851 | /* |
@@ -855,7 +853,7 @@ static int __init cmd640x_init(void) | |||
855 | * This preserves any prior BIOS setup. | 853 | * This preserves any prior BIOS setup. |
856 | */ | 854 | */ |
857 | retrieve_drive_counts (index); | 855 | retrieve_drive_counts (index); |
858 | check_prefetch (index); | 856 | check_prefetch(drive, index); |
859 | printk("cmd640: drive%d timings/prefetch(%s) preserved", | 857 | printk("cmd640: drive%d timings/prefetch(%s) preserved", |
860 | index, drive->no_io_32bit ? "off" : "on"); | 858 | index, drive->no_io_32bit ? "off" : "on"); |
861 | display_clocks(index); | 859 | display_clocks(index); |
@@ -864,7 +862,7 @@ static int __init cmd640x_init(void) | |||
864 | /* | 862 | /* |
865 | * Set the drive unmask flags to match the prefetch setting | 863 | * Set the drive unmask flags to match the prefetch setting |
866 | */ | 864 | */ |
867 | check_prefetch (index); | 865 | check_prefetch(drive, index); |
868 | printk("cmd640: drive%d timings/prefetch(%s) preserved\n", | 866 | printk("cmd640: drive%d timings/prefetch(%s) preserved\n", |
869 | index, drive->no_io_32bit ? "off" : "on"); | 867 | index, drive->no_io_32bit ? "off" : "on"); |
870 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ | 868 | #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ |