ide: cable detection fixes (take 2)
[firefly-linux-kernel-4.4.55.git] / drivers / ide / pci / pdc202xx_new.c
index 77a9aaa7dab988377b78df4a86829e543c4b1f93..65b1e124edf773731cd21250b03a3780d8674bfb 100644 (file)
@@ -37,8 +37,6 @@
 #include <asm/pci-bridge.h>
 #endif
 
-#define PDC202_DEBUG_CABLE     0
-
 #undef DEBUG
 
 #ifdef DEBUG
@@ -82,36 +80,6 @@ static u8 max_dma_rate(struct pci_dev *pdev)
        return mode;
 }
 
-static u8 pdcnew_ratemask(ide_drive_t *drive)
-{
-       u8 mode = max_dma_rate(HWIF(drive)->pci_dev);
-
-       if (!eighty_ninty_three(drive))
-               mode = min_t(u8, mode, 1);
-
-       return  mode;
-}
-
-static int check_in_drive_lists(ide_drive_t *drive, const char **list)
-{
-       struct hd_driveid *id = drive->id;
-
-       if (pdc_quirk_drives == list) {
-               while (*list) {
-                       if (strstr(id->model, *list++)) {
-                               return 2;
-                       }
-               }
-       } else {
-               while (*list) {
-                       if (!strcmp(*list++,id->model)) {
-                               return 1;
-                       }
-               }
-       }
-       return 0;
-}
-
 /**
  * get_indexed_reg - Get indexed register
  * @hwif: for the port address
@@ -121,8 +89,8 @@ static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
 {
        u8 value;
 
-       hwif->OUTB(index, hwif->dma_vendor1);
-       value = hwif->INB(hwif->dma_vendor3);
+       outb(index, hwif->dma_vendor1);
+       value = inb(hwif->dma_vendor3);
 
        DBG("index[%02X] value[%02X]\n", index, value);
        return value;
@@ -135,8 +103,8 @@ static u8 get_indexed_reg(ide_hwif_t *hwif, u8 index)
  */
 static void set_indexed_reg(ide_hwif_t *hwif, u8 index, u8 value)
 {
-       hwif->OUTB(index, hwif->dma_vendor1);
-       hwif->OUTB(value, hwif->dma_vendor3);
+       outb(index, hwif->dma_vendor1);
+       outb(value, hwif->dma_vendor3);
        DBG("index[%02X] value[%02X]\n", index, value);
 }
 
@@ -184,7 +152,7 @@ static int pdcnew_tune_chipset(ide_drive_t *drive, u8 speed)
        u8 adj                  = (drive->dn & 1) ? 0x08 : 0x00;
        int                     err;
 
-       speed = ide_rate_filter(pdcnew_ratemask(drive), speed);
+       speed = ide_rate_filter(drive, speed);
 
        /*
         * Issue SETFEATURES_XFER to the drive first. PDC202xx hardware will
@@ -249,13 +217,6 @@ static int pdcnew_tune_chipset(ide_drive_t *drive, u8 speed)
        return err;
 }
 
-/*   0    1    2    3    4    5    6   7   8
- * 960, 480, 390, 300, 240, 180, 120, 90, 60
- *           180, 150, 120,  90,  60
- * DMA_Speed
- * 180, 120,  90,  90,  90,  60,  30
- *  11,   5,   4,   3,   2,   1,   0
- */
 static void pdcnew_tune_drive(ide_drive_t *drive, u8 pio)
 {
        pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
@@ -271,20 +232,8 @@ static int config_chipset_for_dma(ide_drive_t *drive)
 {
        struct hd_driveid *id   = drive->id;
        ide_hwif_t *hwif        = HWIF(drive);
-       u8 ultra_66             = (id->dma_ultra & 0x0078) ? 1 : 0;
-       u8 cable                = pdcnew_cable_detect(hwif);
        u8 speed;
 
-       if (ultra_66 && cable) {
-               printk(KERN_WARNING "Warning: %s channel "
-                      "requires an 80-pin cable for operation.\n",
-                      hwif->channel ? "Secondary" : "Primary");
-               printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
-       }
-
-       if (drive->media != ide_disk)
-               return 0;
-
        if (id->capability & 4) {
                /*
                 * Set IORDY_EN & PREFETCH_EN (this seems to have
@@ -297,7 +246,7 @@ static int config_chipset_for_dma(ide_drive_t *drive)
                set_indexed_reg(hwif, 0x13 + adj, tmp | 0x03);
        }
 
-       speed = ide_dma_speed(drive, pdcnew_ratemask(drive));
+       speed = ide_max_dma_mode(drive);
 
        if (!speed)
                return 0;
@@ -308,46 +257,25 @@ static int config_chipset_for_dma(ide_drive_t *drive)
 
 static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif        = HWIF(drive);
-       struct hd_driveid *id   = drive->id;
-
        drive->init_speed = 0;
 
-       if (id && (id->capability & 1) && drive->autodma) {
-
-               if (ide_use_dma(drive)) {
-                       if (config_chipset_for_dma(drive))
-                               return hwif->ide_dma_on(drive);
-               }
+       if (ide_use_dma(drive) && config_chipset_for_dma(drive))
+               return 0;
 
-               goto fast_ata_pio;
+       if (ide_use_fast_pio(drive))
+               pdcnew_tune_drive(drive, 255);
 
-       } else if ((id->capability & 8) || (id->field_valid & 2)) {
-fast_ata_pio:
-               hwif->tuneproc(drive, 255);
-               return hwif->ide_dma_off_quietly(drive);
-       }
-       /* IORDY not supported */
-       return 0;
+       return -1;
 }
 
 static int pdcnew_quirkproc(ide_drive_t *drive)
 {
-       return check_in_drive_lists(drive, pdc_quirk_drives);
-}
-
-static int pdcnew_ide_dma_lostirq(ide_drive_t *drive)
-{
-       if (HWIF(drive)->resetproc != NULL)
-               HWIF(drive)->resetproc(drive);
-       return __ide_dma_lostirq(drive);
-}
+       const char **list, *model = drive->id->model;
 
-static int pdcnew_ide_dma_timeout(ide_drive_t *drive)
-{
-       if (HWIF(drive)->resetproc != NULL)
-               HWIF(drive)->resetproc(drive);
-       return __ide_dma_timeout(drive);
+       for (list = pdc_quirk_drives; *list != NULL; list++)
+               if (strstr(model, *list) != NULL)
+                       return 2;
+       return 0;
 }
 
 static void pdcnew_reset(ide_drive_t *drive)
@@ -446,7 +374,7 @@ static void __devinit apple_kiwi_init(struct pci_dev *pdev)
        unsigned int class_rev = 0;
        u8 conf;
 
-       if (np == NULL || !device_is_compatible(np, "kiwi-root"))
+       if (np == NULL || !of_device_is_compatible(np, "kiwi-root"))
                return;
 
        pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev);
@@ -593,14 +521,14 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
 
        hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
 
-       hwif->ultra_mask = 0x7f;
+       hwif->atapi_dma  = 1;
+
+       hwif->ultra_mask = hwif->cds->udma_mask;
        hwif->mwdma_mask = 0x07;
 
        hwif->err_stops_fifo = 1;
 
        hwif->ide_dma_check = &pdcnew_config_drive_xfer_rate;
-       hwif->ide_dma_lostirq = &pdcnew_ide_dma_lostirq;
-       hwif->ide_dma_timeout = &pdcnew_ide_dma_timeout;
 
        if (!hwif->udma_four)
                hwif->udma_four = pdcnew_cable_detect(hwif) ? 0 : 1;
@@ -608,11 +536,6 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
        if (!noautodma)
                hwif->autodma = 1;
        hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
-
-#if PDC202_DEBUG_CABLE
-       printk(KERN_DEBUG "%s: %s-pin cable\n",
-               hwif->name, hwif->udma_four ? "80" : "40");
-#endif /* PDC202_DEBUG_CABLE */
 }
 
 static int __devinit init_setup_pdcnew(struct pci_dev *dev, ide_pci_device_t *d)
@@ -671,6 +594,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = OFF_BOARD,
+               .udma_mask      = 0x3f, /* udma0-5 */
        },{     /* 1 */
                .name           = "PDC20269",
                .init_setup     = init_setup_pdcnew,
@@ -679,6 +603,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = OFF_BOARD,
+               .udma_mask      = 0x7f, /* udma0-6*/
        },{     /* 2 */
                .name           = "PDC20270",
                .init_setup     = init_setup_pdc20270,
@@ -687,6 +612,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = OFF_BOARD,
+               .udma_mask      = 0x3f, /* udma0-5 */
        },{     /* 3 */
                .name           = "PDC20271",
                .init_setup     = init_setup_pdcnew,
@@ -695,6 +621,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = OFF_BOARD,
+               .udma_mask      = 0x7f, /* udma0-6*/
        },{     /* 4 */
                .name           = "PDC20275",
                .init_setup     = init_setup_pdcnew,
@@ -703,6 +630,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = OFF_BOARD,
+               .udma_mask      = 0x7f, /* udma0-6*/
        },{     /* 5 */
                .name           = "PDC20276",
                .init_setup     = init_setup_pdc20276,
@@ -711,6 +639,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = OFF_BOARD,
+               .udma_mask      = 0x7f, /* udma0-6*/
        },{     /* 6 */
                .name           = "PDC20277",
                .init_setup     = init_setup_pdcnew,
@@ -719,6 +648,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
                .channels       = 2,
                .autodma        = AUTODMA,
                .bootable       = OFF_BOARD,
+               .udma_mask      = 0x7f, /* udma0-6*/
        }
 };