aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/pci/cmd64x.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2007-10-11 17:54:00 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2007-10-11 17:54:00 -0400
commit26bcb879c03254545a19c6700fe5bcef6f21e7b1 (patch)
treedc35f1a7d7860fe0de268ff92189ff0884b689d3 /drivers/ide/pci/cmd64x.c
parent842c19ad6fc0dbd9ac9d2f8527466201802934cf (diff)
ide: add ide_set{_max}_pio() (take 4)
* Add IDE_HFLAG_ABUSE_{PREFETCH,FAST_DEVSEL,DMA_MODES} flags and set them in ht6560, cmd640, cmd64x and sc1200 host drivers. * Add set_pio_mode_abuse() for checking if host driver has a non-standard ->tuneproc() implementation and use it in do_special(). * Add ide_set_pio() for setting PIO mode (it uses hwif->pio_mask to find the maximum PIO mode supported by the host), also add ide_set_max_pio() wrapper for ide_set_pio() to use for auto-tuning. Convert users of ->tuneproc to use ide_set{_max}_pio() where possible. This leaves only do_special(), set_using_pio(), ide_hwif_restore() and ide_set_pio() as a direct users of ->tuneproc. * Remove no longer needed ide_get_best_pio_mode() calls and printk-s reporting PIO mode selected from ->tuneproc implementations. * Rename ->tuneproc hook to ->set_pio_mode and make 'pio' argument const. * Remove stale comment from ide_config_drive_speed(). v2: * Fix "ata_" prefix (Noticed by Jeff). v3: * Minor cleanups/fixups per Sergei's suggestions. v4: * Fix compile problem in drivers/ide/pci/cmd640.c (Noticed by Andrew Morton). * Improve some ->set_pio_mode comments. Reviewed-by: Sergei Shtylyov <sshtylyov@ru.mvista.com> Cc: Jeff Garzik <jeff@garzik.org> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/pci/cmd64x.c')
-rw-r--r--drivers/ide/pci/cmd64x.c39
1 files changed, 19 insertions, 20 deletions
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 5fe50a234ce1..85f5e42eb831 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -214,28 +214,25 @@ static void program_cycle_times (ide_drive_t *drive, int cycle_time, int active_
214} 214}
215 215
216/* 216/*
217 * This routine selects drive's best PIO mode and writes into the chipset 217 * This routine writes into the chipset registers
218 * registers setup/active/recovery timings. 218 * PIO setup/active/recovery timings.
219 */ 219 */
220static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted) 220static void cmd64x_tune_pio(ide_drive_t *drive, const u8 pio)
221{ 221{
222 ide_hwif_t *hwif = HWIF(drive); 222 ide_hwif_t *hwif = HWIF(drive);
223 struct pci_dev *dev = hwif->pci_dev; 223 struct pci_dev *dev = hwif->pci_dev;
224 unsigned int cycle_time; 224 unsigned int cycle_time;
225 u8 pio_mode, setup_count, arttim = 0; 225 u8 setup_count, arttim = 0;
226
226 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0}; 227 static const u8 setup_values[] = {0x40, 0x40, 0x40, 0x80, 0, 0xc0};
227 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23}; 228 static const u8 arttim_regs[4] = {ARTTIM0, ARTTIM1, ARTTIM23, ARTTIM23};
228 229
229 pio_mode = ide_get_best_pio_mode(drive, mode_wanted, 5); 230 cycle_time = ide_pio_cycle_time(drive, pio);
230 cycle_time = ide_pio_cycle_time(drive, pio_mode);
231
232 cmdprintk("%s: PIO mode wanted %d, selected %d (%d ns)\n",
233 drive->name, mode_wanted, pio_mode, cycle_time);
234 231
235 program_cycle_times(drive, cycle_time, 232 program_cycle_times(drive, cycle_time,
236 ide_pio_timings[pio_mode].active_time); 233 ide_pio_timings[pio].active_time);
237 234
238 setup_count = quantize_timing(ide_pio_timings[pio_mode].setup_time, 235 setup_count = quantize_timing(ide_pio_timings[pio].setup_time,
239 1000 / system_bus_clock()); 236 1000 / system_bus_clock());
240 237
241 /* 238 /*
@@ -266,16 +263,14 @@ static u8 cmd64x_tune_pio (ide_drive_t *drive, u8 mode_wanted)
266 arttim |= setup_values[setup_count]; 263 arttim |= setup_values[setup_count];
267 (void) pci_write_config_byte(dev, arttim_regs[drive->dn], arttim); 264 (void) pci_write_config_byte(dev, arttim_regs[drive->dn], arttim);
268 cmdprintk("Write 0x%02x to reg 0x%x\n", arttim, arttim_regs[drive->dn]); 265 cmdprintk("Write 0x%02x to reg 0x%x\n", arttim, arttim_regs[drive->dn]);
269
270 return pio_mode;
271} 266}
272 267
273/* 268/*
274 * Attempts to set drive's PIO mode. 269 * Attempts to set drive's PIO mode.
275 * Special cases are 8: prefetch off, 9: prefetch on (both never worked), 270 * Special cases are 8: prefetch off, 9: prefetch on (both never worked)
276 * and 255: auto-select best mode (used at boot time).
277 */ 271 */
278static void cmd64x_tune_drive (ide_drive_t *drive, u8 pio) 272
273static void cmd64x_set_pio_mode(ide_drive_t *drive, const u8 pio)
279{ 274{
280 /* 275 /*
281 * Filter out the prefetch control values 276 * Filter out the prefetch control values
@@ -284,7 +279,7 @@ static void cmd64x_tune_drive (ide_drive_t *drive, u8 pio)
284 if (pio == 8 || pio == 9) 279 if (pio == 8 || pio == 9)
285 return; 280 return;
286 281
287 pio = cmd64x_tune_pio(drive, pio); 282 cmd64x_tune_pio(drive, pio);
288 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 283 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
289} 284}
290 285
@@ -334,7 +329,7 @@ static int cmd64x_tune_chipset(ide_drive_t *drive, const u8 speed)
334 case XFER_PIO_2: 329 case XFER_PIO_2:
335 case XFER_PIO_1: 330 case XFER_PIO_1:
336 case XFER_PIO_0: 331 case XFER_PIO_0:
337 (void) cmd64x_tune_pio(drive, speed - XFER_PIO_0); 332 cmd64x_tune_pio(drive, speed - XFER_PIO_0);
338 break; 333 break;
339 default: 334 default:
340 return 1; 335 return 1;
@@ -352,7 +347,7 @@ static int cmd64x_config_drive_for_dma (ide_drive_t *drive)
352 return 0; 347 return 0;
353 348
354 if (ide_use_fast_pio(drive)) 349 if (ide_use_fast_pio(drive))
355 cmd64x_tune_drive(drive, 255); 350 ide_set_max_pio(drive);
356 351
357 return -1; 352 return -1;
358} 353}
@@ -536,7 +531,7 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
536 531
537 pci_read_config_byte(dev, PCI_REVISION_ID, &rev); 532 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
538 533
539 hwif->tuneproc = &cmd64x_tune_drive; 534 hwif->set_pio_mode = &cmd64x_set_pio_mode;
540 hwif->speedproc = &cmd64x_tune_chipset; 535 hwif->speedproc = &cmd64x_tune_chipset;
541 536
542 hwif->drives[0].autotune = hwif->drives[1].autotune = 1; 537 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
@@ -620,6 +615,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
620 .autodma = AUTODMA, 615 .autodma = AUTODMA,
621 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 616 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
622 .bootable = ON_BOARD, 617 .bootable = ON_BOARD,
618 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
623 .pio_mask = ATA_PIO5, 619 .pio_mask = ATA_PIO5,
624 .udma_mask = 0x00, /* no udma */ 620 .udma_mask = 0x00, /* no udma */
625 },{ /* 1 */ 621 },{ /* 1 */
@@ -630,6 +626,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
630 .autodma = AUTODMA, 626 .autodma = AUTODMA,
631 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 627 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
632 .bootable = ON_BOARD, 628 .bootable = ON_BOARD,
629 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
633 .pio_mask = ATA_PIO5, 630 .pio_mask = ATA_PIO5,
634 .udma_mask = 0x07, /* udma0-2 */ 631 .udma_mask = 0x07, /* udma0-2 */
635 },{ /* 2 */ 632 },{ /* 2 */
@@ -640,6 +637,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
640 .autodma = AUTODMA, 637 .autodma = AUTODMA,
641 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 638 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
642 .bootable = ON_BOARD, 639 .bootable = ON_BOARD,
640 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
643 .pio_mask = ATA_PIO5, 641 .pio_mask = ATA_PIO5,
644 .udma_mask = 0x1f, /* udma0-4 */ 642 .udma_mask = 0x1f, /* udma0-4 */
645 },{ /* 3 */ 643 },{ /* 3 */
@@ -650,6 +648,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
650 .autodma = AUTODMA, 648 .autodma = AUTODMA,
651 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 649 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
652 .bootable = ON_BOARD, 650 .bootable = ON_BOARD,
651 .host_flags = IDE_HFLAG_ABUSE_PREFETCH,
653 .pio_mask = ATA_PIO5, 652 .pio_mask = ATA_PIO5,
654 .udma_mask = 0x3f, /* udma0-5 */ 653 .udma_mask = 0x3f, /* udma0-5 */
655 } 654 }