Merge branch 'linus' into tracing/mmiotrace
[firefly-linux-kernel-4.4.55.git] / drivers / ide / ppc / pmac.c
index 177961edc430b890609f198c04a2da7bbdf83ac8..ba2d58727964f2bfa6a527b683535035da2da3b1 100644 (file)
@@ -59,7 +59,6 @@ typedef struct pmac_ide_hwif {
        int                             irq;
        int                             kind;
        int                             aapl_bus_id;
-       unsigned                        cable_80 : 1;
        unsigned                        mediabay : 1;
        unsigned                        broken_dma : 1;
        unsigned                        broken_dma_warn : 1;
@@ -409,7 +408,7 @@ kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
  */
 #define IDE_WAKEUP_DELAY       (1*HZ)
 
-static int pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif);
+static int pmac_ide_init_dma(ide_hwif_t *, const struct ide_port_info *);
 static int pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq);
 static void pmac_ide_selectproc(ide_drive_t *drive);
 static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
@@ -417,7 +416,7 @@ static void pmac_ide_kauai_selectproc(ide_drive_t *drive);
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
 
 #define PMAC_IDE_REG(x) \
-       ((void __iomem *)((drive)->hwif->io_ports[IDE_DATA_OFFSET] + (x)))
+       ((void __iomem *)((drive)->hwif->io_ports.data_addr + (x)))
 
 /*
  * Apply the timings of the proper unit (master/slave) to the shared
@@ -918,11 +917,60 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
        return 0;
 }
 
+static u8 pmac_ide_cable_detect(ide_hwif_t *hwif)
+{
+       pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)ide_get_hwifdata(hwif);
+       struct device_node *np = pmif->node;
+       const char *cable = of_get_property(np, "cable-type", NULL);
+
+       /* Get cable type from device-tree. */
+       if (cable && !strncmp(cable, "80-", 3))
+               return ATA_CBL_PATA80;
+
+       /*
+        * G5's seem to have incorrect cable type in device-tree.
+        * Let's assume they have a 80 conductor cable, this seem
+        * to be always the case unless the user mucked around.
+        */
+       if (of_device_is_compatible(np, "K2-UATA") ||
+           of_device_is_compatible(np, "shasta-ata"))
+               return ATA_CBL_PATA80;
+
+       return ATA_CBL_PATA40;
+}
+
+static const struct ide_port_ops pmac_ide_ata6_port_ops = {
+       .set_pio_mode           = pmac_ide_set_pio_mode,
+       .set_dma_mode           = pmac_ide_set_dma_mode,
+       .selectproc             = pmac_ide_kauai_selectproc,
+       .cable_detect           = pmac_ide_cable_detect,
+};
+
+static const struct ide_port_ops pmac_ide_ata4_port_ops = {
+       .set_pio_mode           = pmac_ide_set_pio_mode,
+       .set_dma_mode           = pmac_ide_set_dma_mode,
+       .selectproc             = pmac_ide_selectproc,
+       .cable_detect           = pmac_ide_cable_detect,
+};
+
+static const struct ide_port_ops pmac_ide_port_ops = {
+       .set_pio_mode           = pmac_ide_set_pio_mode,
+       .set_dma_mode           = pmac_ide_set_dma_mode,
+       .selectproc             = pmac_ide_selectproc,
+};
+
+static const struct ide_dma_ops pmac_dma_ops;
+
 static const struct ide_port_info pmac_port_info = {
+       .init_dma               = pmac_ide_init_dma,
        .chipset                = ide_pmac,
+#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
+       .dma_ops                = &pmac_dma_ops,
+#endif
+       .port_ops               = &pmac_ide_port_ops,
        .host_flags             = IDE_HFLAG_SET_PIO_MODE_KEEP_DMA |
                                  IDE_HFLAG_POST_SET_MODE |
-                                 IDE_HFLAG_NO_DMA | /* no SFF-style DMA */
+                                 IDE_HFLAG_MMIO |
                                  IDE_HFLAG_UNMASK_IRQS,
        .pio_mask               = ATA_PIO4,
        .mwdma_mask             = ATA_MWDMA2,
@@ -930,10 +978,7 @@ static const struct ide_port_info pmac_port_info = {
 
 /*
  * Setup, register & probe an IDE channel driven by this driver, this is
- * called by one of the 2 probe functions (macio or PCI). Note that a channel
- * that ends up beeing free of any device is not kept around by this driver
- * (it is kept in 2.4). This introduce an interface numbering change on some
- * rare machines unfortunately, but it's better this way.
+ * called by one of the 2 probe functions (macio or PCI).
  */
 static int __devinit
 pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
@@ -943,20 +988,23 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
        u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
        struct ide_port_info d = pmac_port_info;
 
-       pmif->cable_80 = 0;
        pmif->broken_dma = pmif->broken_dma_warn = 0;
        if (of_device_is_compatible(np, "shasta-ata")) {
                pmif->kind = controller_sh_ata6;
+               d.port_ops = &pmac_ide_ata6_port_ops;
                d.udma_mask = ATA_UDMA6;
        } else if (of_device_is_compatible(np, "kauai-ata")) {
                pmif->kind = controller_un_ata6;
+               d.port_ops = &pmac_ide_ata6_port_ops;
                d.udma_mask = ATA_UDMA5;
        } else if (of_device_is_compatible(np, "K2-UATA")) {
                pmif->kind = controller_k2_ata6;
+               d.port_ops = &pmac_ide_ata6_port_ops;
                d.udma_mask = ATA_UDMA5;
        } else if (of_device_is_compatible(np, "keylargo-ata")) {
                if (strcmp(np->name, "ata-4") == 0) {
                        pmif->kind = controller_kl_ata4;
+                       d.port_ops = &pmac_ide_ata4_port_ops;
                        d.udma_mask = ATA_UDMA4;
                } else
                        pmif->kind = controller_kl_ata3;
@@ -970,22 +1018,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
        bidp = of_get_property(np, "AAPL,bus-id", NULL);
        pmif->aapl_bus_id =  bidp ? *bidp : 0;
 
-       /* Get cable type from device-tree */
-       if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6
-           || pmif->kind == controller_k2_ata6
-           || pmif->kind == controller_sh_ata6) {
-               const char* cable = of_get_property(np, "cable-type", NULL);
-               if (cable && !strncmp(cable, "80-", 3))
-                       pmif->cable_80 = 1;
-       }
-       /* G5's seem to have incorrect cable type in device-tree. Let's assume
-        * they have a 80 conductor cable, this seem to be always the case unless
-        * the user mucked around
-        */
-       if (of_device_is_compatible(np, "K2-UATA") ||
-           of_device_is_compatible(np, "shasta-ata"))
-               pmif->cable_80 = 1;
-
        /* On Kauai-type controllers, we make sure the FCR is correct */
        if (pmif->kauai_fcr)
                writel(KAUAI_FCR_UATA_MAGIC |
@@ -1029,37 +1061,23 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif, hw_regs_t *hw)
        default_hwif_mmiops(hwif);
                hwif->OUTBSYNC = pmac_outbsync;
 
-       /* Tell common code _not_ to mess with resources */
-       hwif->mmio = 1;
        hwif->hwif_data = pmif;
        ide_init_port_hw(hwif, hw);
-       hwif->noprobe = pmif->mediabay;
-       hwif->cbl = pmif->cable_80 ? ATA_CBL_PATA80 : ATA_CBL_PATA40;
-       hwif->set_pio_mode = pmac_ide_set_pio_mode;
-       if (pmif->kind == controller_un_ata6
-           || pmif->kind == controller_k2_ata6
-           || pmif->kind == controller_sh_ata6)
-               hwif->selectproc = pmac_ide_kauai_selectproc;
-       else
-               hwif->selectproc = pmac_ide_selectproc;
-       hwif->set_dma_mode = pmac_ide_set_dma_mode;
 
        printk(KERN_INFO "ide%d: Found Apple %s controller, bus ID %d%s, irq %d\n",
               hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
               pmif->mediabay ? " (mediabay)" : "", hwif->irq);
-                       
-#ifdef CONFIG_PMAC_MEDIABAY
-       if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0)
-               hwif->noprobe = 0;
-#endif /* CONFIG_PMAC_MEDIABAY */
 
-#ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
-       if (pmif->cable_80 == 0)
-               d.udma_mask &= ATA_UDMA2;
-       /* has a DBDMA controller channel */
-       if (pmif->dma_regs == 0 || pmac_ide_setup_dma(pmif, hwif) < 0)
+       if (pmif->mediabay) {
+#ifdef CONFIG_PMAC_MEDIABAY
+               if (check_media_bay_by_base(pmif->regbase, MB_CD)) {
+#else
+               if (1) {
 #endif
-               d.udma_mask = d.mwdma_mask = 0;
+                       hwif->drives[0].noprobe = 1;
+                       hwif->drives[1].noprobe = 1;
+               }
+       }
 
        idx[0] = hwif->index;
 
@@ -1073,8 +1091,9 @@ static void __devinit pmac_ide_init_ports(hw_regs_t *hw, unsigned long base)
        int i;
 
        for (i = 0; i < 8; ++i)
-               hw->io_ports[i] = base + i * 0x10;
-       hw->io_ports[8] = base + 0x160;
+               hw->io_ports_array[i] = base + i * 0x10;
+
+       hw->io_ports.ctl_addr = base + 0x160;
 }
 
 /*
@@ -1662,18 +1681,31 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
        printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
 }
 
+static const struct ide_dma_ops pmac_dma_ops = {
+       .dma_host_set           = pmac_ide_dma_host_set,
+       .dma_setup              = pmac_ide_dma_setup,
+       .dma_exec_cmd           = pmac_ide_dma_exec_cmd,
+       .dma_start              = pmac_ide_dma_start,
+       .dma_end                = pmac_ide_dma_end,
+       .dma_test_irq           = pmac_ide_dma_test_irq,
+       .dma_timeout            = ide_dma_timeout,
+       .dma_lost_irq           = pmac_ide_dma_lost_irq,
+};
+
 /*
  * Allocate the data structures needed for using DMA with an interface
  * and fill the proper list of functions pointers
  */
-static int __devinit pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
+static int __devinit pmac_ide_init_dma(ide_hwif_t *hwif,
+                                      const struct ide_port_info *d)
 {
+       pmac_ide_hwif_t *pmif = (pmac_ide_hwif_t *)hwif->hwif_data;
        struct pci_dev *dev = to_pci_dev(hwif->dev);
 
        /* We won't need pci_dev if we switch to generic consistent
         * DMA routines ...
         */
-       if (dev == NULL)
+       if (dev == NULL || pmif->dma_regs == 0)
                return -ENODEV;
        /*
         * Allocate space for the DBDMA commands.
@@ -1692,18 +1724,14 @@ static int __devinit pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
 
        hwif->sg_max_nents = MAX_DCMDS;
 
-       hwif->dma_host_set = &pmac_ide_dma_host_set;
-       hwif->dma_setup = &pmac_ide_dma_setup;
-       hwif->dma_exec_cmd = &pmac_ide_dma_exec_cmd;
-       hwif->dma_start = &pmac_ide_dma_start;
-       hwif->ide_dma_end = &pmac_ide_dma_end;
-       hwif->ide_dma_test_irq = &pmac_ide_dma_test_irq;
-       hwif->dma_timeout = &ide_dma_timeout;
-       hwif->dma_lost_irq = &pmac_ide_dma_lost_irq;
-
        return 0;
 }
-
+#else
+static int __devinit pmac_ide_init_dma(ide_hwif_t *hwif,
+                                      const struct ide_port_info *d)
+{
+       return -EOPNOTSUPP;
+}
 #endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
 
 module_init(pmac_ide_probe);