ide: add ide_tune_dma() helper
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Wed, 9 May 2007 22:01:09 +0000 (00:01 +0200)
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Wed, 9 May 2007 22:01:09 +0000 (00:01 +0200)
After reworking the code responsible for selecting the best DMA
transfer mode it is now possible to add generic ide_tune_dma() helper.

Convert some IDE PCI host drivers to use it (the ones left need more work).

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
14 files changed:
drivers/ide/ide-dma.c
drivers/ide/pci/aec62xx.c
drivers/ide/pci/atiixp.c
drivers/ide/pci/cs5535.c
drivers/ide/pci/hpt34x.c
drivers/ide/pci/hpt366.c
drivers/ide/pci/it8213.c
drivers/ide/pci/jmicron.c
drivers/ide/pci/piix.c
drivers/ide/pci/sis5513.c
drivers/ide/pci/slc90e66.c
drivers/ide/pci/tc86c001.c
drivers/ide/pci/triflex.c
include/linux/ide.h

index f28fabb791fef6c377bf88256c15d8ed06375dbe..5fe85191d49c1f05cffc34aeb429dbbb54971f80 100644 (file)
@@ -779,6 +779,26 @@ u8 ide_max_dma_mode(ide_drive_t *drive)
 
 EXPORT_SYMBOL_GPL(ide_max_dma_mode);
 
+int ide_tune_dma(ide_drive_t *drive)
+{
+       u8 speed;
+
+       /* TODO: use only ide_max_dma_mode() */
+       if (!ide_use_dma(drive))
+               return 0;
+
+       speed = ide_max_dma_mode(drive);
+
+       if (!speed)
+               return 0;
+
+       drive->hwif->speedproc(drive, speed);
+
+       return ide_dma_enable(drive);
+}
+
+EXPORT_SYMBOL_GPL(ide_tune_dma);
+
 void ide_dma_verbose(ide_drive_t *drive)
 {
        struct hd_driveid *id   = drive->id;
index 099539e8c7a3aff923fd2126cd2ea1b5bfd0de6d..b173bc66ce1e19ae25efef18e8361864c850a877 100644 (file)
@@ -155,17 +155,6 @@ static int aec62xx_tune_chipset (ide_drive_t *drive, u8 speed)
        }
 }
 
-static int config_chipset_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!(speed))
-               return 0;
-
-       (void) aec62xx_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
 {
        pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
@@ -174,7 +163,7 @@ static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
 
 static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
 {
-       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive))
index f7e80d6076d76971e0a1d1e4d8ea35c41ee112ab..0e52ad722a72ab23bf7e399a210fa87052f8dddb 100644 (file)
@@ -206,26 +206,6 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
        return ide_config_drive_speed(drive, speed);
 }
 
-/**
- *     atiixp_config_drive_for_dma     -       configure drive for DMA
- *     @drive: IDE drive to configure
- *
- *     Set up a ATIIXP interface channel for the best available speed.
- *     We prefer UDMA if it is available and then MWDMA. If DMA is
- *     not available we switch to PIO and return 0.
- */
-
-static int atiixp_config_drive_for_dma(ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!speed)
-               return 0;
-
-       (void) atiixp_speedproc(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 /**
  *     atiixp_dma_check        -       set up an IDE device
  *     @drive: IDE drive to configure
@@ -240,7 +220,7 @@ static int atiixp_dma_check(ide_drive_t *drive)
 
        drive->init_speed = 0;
 
-       if (ide_use_dma(drive) && atiixp_config_drive_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive)) {
index 66a101e470d01d5af0a78c8a54e39a5f9d8c558a..41925c47ef05968d484107b34b7c22b1e53373c4 100644 (file)
@@ -164,26 +164,13 @@ static void cs5535_tuneproc(ide_drive_t *drive, u8 xferspeed)
        cs5535_set_speed(drive, xferspeed);
 }
 
-static int cs5535_config_drive_for_dma(ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       /* If no DMA speed was available then let dma_check hit pio */
-       if (!speed) {
-               return 0;
-       }
-
-       cs5535_set_drive(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 static int cs5535_dma_check(ide_drive_t *drive)
 {
        u8 speed;
 
        drive->init_speed = 0;
 
-       if (ide_use_dma(drive) && cs5535_config_drive_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive)) {
index 473e1b33dbf7830ec756df6be1079a378c2464d5..2c24c3de8846f0aaee3dafee2d6c3d0730077ac0 100644 (file)
@@ -84,29 +84,11 @@ static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio)
        (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio));
 }
 
-/*
- * This allows the configuration of ide_pci chipset registers
- * for cards that learn about the drive's UDMA, DMA, PIO capabilities
- * after the drive is reported by the OS.  Initially for designed for
- * HPT343 UDMA chipset by HighPoint|Triones Technologies, Inc.
- */
-
-static int config_chipset_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!(speed))
-               return 0;
-
-       (void) hpt34x_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive)
 {
        drive->init_speed = 0;
 
-       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+       if (ide_tune_dma(drive))
 #ifndef CONFIG_HPT34X_AUTODMA
                return -1;
 #else
index de5ad9c35dc6a2786e94bf2daaa57ddf95b5e094..fcbc5605b38ef28210d11bdf7f33051bad56312d 100644 (file)
@@ -669,24 +669,6 @@ static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio)
        (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio);
 }
 
-/*
- * This allows the configuration of ide_pci chipset registers
- * for cards that learn about the drive's UDMA, DMA, PIO capabilities
- * after the drive is reported by the OS.  Initially designed for
- * HPT366 UDMA chipset by HighPoint|Triones Technologies, Inc.
- *
- */
-static int config_chipset_for_dma(ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!speed)
-               return 0;
-
-       (void) hpt3xx_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 static int hpt3xx_quirkproc(ide_drive_t *drive)
 {
        struct hd_driveid *id   = drive->id;
@@ -741,7 +723,7 @@ static int hpt366_config_drive_xfer_rate(ide_drive_t *drive)
 {
        drive->init_speed = 0;
 
-       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive))
index 02b56cb7bb1b83dee9cf553de8df5395c44f418a..c04a02687b95ec91c3687761c6f3e4e318b380c5 100644 (file)
@@ -197,25 +197,6 @@ static int it8213_tune_chipset (ide_drive_t *drive, u8 xferspeed)
        return ide_config_drive_speed(drive, speed);
 }
 
-/*
- *     config_chipset_for_dma  -       configure for DMA
- *     @drive: drive to configure
- *
- *     Called by the IDE layer when it wants the timings set up.
- */
-
-static int config_chipset_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!speed)
-               return 0;
-
-       it8213_tune_chipset(drive, speed);
-
-       return ide_dma_enable(drive);
-}
-
 /**
  *     it8213_configure_drive_for_dma  -       set up for DMA transfers
  *     @drive: drive we are going to set up
@@ -230,7 +211,7 @@ static int it8213_config_drive_for_dma (ide_drive_t *drive)
 {
        u8 pio;
 
-       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        pio = ide_get_best_pio_mode(drive, 255, 4, NULL);
index dbb3c199cba9ae4fb45b8fa8b2bcde7a8a0b4a0b..76ed251472298682a516c0b6699dc0c07a7618d4 100644 (file)
@@ -118,25 +118,6 @@ static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed)
        return ide_config_drive_speed(drive, speed);
 }
 
-/**
- *     config_chipset_for_dma  -       configure for DMA
- *     @drive: drive to configure
- *
- *     As the JMicron snoops for timings all we actually need to do is
- *     make sure we don't set an invalid mode.
- */
-
-static int config_chipset_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!speed)
-               return 0;
-
-       jmicron_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 /**
  *     jmicron_configure_drive_for_dma -       set up for DMA transfers
  *     @drive: drive we are going to set up
@@ -147,7 +128,7 @@ static int config_chipset_for_dma (ide_drive_t *drive)
 
 static int jmicron_config_drive_for_dma (ide_drive_t *drive)
 {
-       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        config_jmicron_chipset_for_pio(drive, 1);
index 84d3938a430a571d9308a657792b2037e2182562..8b219dd630241f4285512e61a9b417872c5147e8 100644 (file)
@@ -303,30 +303,6 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
        return ide_config_drive_speed(drive, speed);
 }
 
-/**
- *     piix_config_drive_for_dma       -       configure drive for DMA
- *     @drive: IDE drive to configure
- *
- *     Set up a PIIX interface channel for the best available speed.
- *     We prefer UDMA if it is available and then MWDMA.  If DMA is
- *     not available we switch to PIO and return 0.
- */
-static int piix_config_drive_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       /*
-        * If no DMA speed was available or the chipset has DMA bugs
-        * then disable DMA and use PIO
-        */
-       if (!speed)
-               return 0;
-
-       (void) piix_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 /**
  *     piix_config_drive_xfer_rate     -       set up an IDE device
  *     @drive: IDE drive to configure
@@ -339,7 +315,7 @@ static int piix_config_drive_xfer_rate (ide_drive_t *drive)
 {
        drive->init_speed = 0;
 
-       if (ide_use_dma(drive) && piix_config_drive_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive))
index 83c80ed73e99be9b2d0efb84e3acf65c48a0878c..41953fe4fa6bc4afbfdfa6dac010e6866dff8e8d 100644 (file)
@@ -638,32 +638,13 @@ static void sis5513_tune_drive (ide_drive_t *drive, u8 pio)
        (void) config_chipset_for_pio(drive, pio);
 }
 
-/*
- * ((id->hw_config & 0x4000|0x2000) && (HWIF(drive)->udma_four))
- */
-static int config_chipset_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-#ifdef DEBUG
-       printk("SIS5513: config_chipset_for_dma, drive %d, ultra %x\n",
-              drive->dn, drive->id->dma_ultra);
-#endif
-
-       if (!(speed))
-               return 0;
-
-       sis5513_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 static int sis5513_config_xfer_rate(ide_drive_t *drive)
 {
        config_art_rwp_pio(drive, 5);
 
        drive->init_speed = 0;
 
-       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive))
index 9e95a5cbf984c9789b855db62cafbb8cc2332302..c40f291f91e04c62cce013882abcc67ef53ad05d 100644 (file)
@@ -160,22 +160,11 @@ static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed)
        return ide_config_drive_speed(drive, speed);
 }
 
-static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!speed)
-               return 0;
-
-       (void) slc90e66_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive)
 {
        drive->init_speed = 0;
 
-       if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive))
index 168f035caa3fc1e582d565b35a15d93384499668..cee619bb2eaf8a7713ccc7582acb48b22f4c10e8 100644 (file)
@@ -167,20 +167,9 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
        return 0;
 }
 
-static int config_chipset_for_dma(ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!speed)
-               return 0;
-
-       (void) tc86c001_tune_chipset(drive, speed);
-       return ide_dma_enable(drive);
-}
-
 static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive)
 {
-       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        if (ide_use_fast_pio(drive))
index 8a877235b949f045a5fd06f485632be0239d08a8..35e8c612638f687509c42311c38d13973f92752c 100644 (file)
@@ -100,20 +100,9 @@ static void triflex_tune_drive(ide_drive_t *drive, u8 pio)
        (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio));
 }
 
-static int triflex_config_drive_for_dma(ide_drive_t *drive)
-{
-       u8 speed = ide_max_dma_mode(drive);
-
-       if (!speed)
-               return 0;
-
-       (void) triflex_tune_chipset(drive, speed);
-        return ide_dma_enable(drive);
-}
-
 static int triflex_config_drive_xfer_rate(ide_drive_t *drive)
 {
-       if (ide_use_dma(drive) && triflex_config_drive_for_dma(drive))
+       if (ide_tune_dma(drive))
                return 0;
 
        triflex_tune_drive(drive, 255);
index 23ab4dc0500957efb5ba8375977709228e5720a2..d03fa2d5d75a8cd17b076bce4cda42d012473258 100644 (file)
@@ -1277,6 +1277,7 @@ int __ide_dma_bad_drive(ide_drive_t *);
 int __ide_dma_good_drive(ide_drive_t *);
 int ide_use_dma(ide_drive_t *);
 u8 ide_max_dma_mode(ide_drive_t *);
+int ide_tune_dma(ide_drive_t *);
 void ide_dma_off(ide_drive_t *);
 void ide_dma_verbose(ide_drive_t *);
 int ide_set_dma(ide_drive_t *);
@@ -1304,6 +1305,7 @@ extern int __ide_dma_timeout(ide_drive_t *);
 #else
 static inline int ide_use_dma(ide_drive_t *drive) { return 0; }
 static inline u8 ide_max_dma_mode(ide_drive_t *drive) { return 0; }
+static inline int ide_tune_dma(ide_drive_t *drive) { return 0; }
 static inline void ide_dma_off(ide_drive_t *drive) { ; }
 static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
 static inline int ide_set_dma(ide_drive_t *drive) { return 1; }