linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / ide / ppc / pmac.c
index 011d3f2..5013b12 100644 (file)
@@ -52,7 +52,7 @@
 
 #include "ide-timing.h"
 
-#define IDE_PMAC_DEBUG
+#undef IDE_PMAC_DEBUG
 
 #define DMA_WAIT_TIMEOUT       50
 
@@ -68,6 +68,7 @@ typedef struct pmac_ide_hwif {
        struct device_node*             node;
        struct macio_dev                *mdev;
        u32                             timings[4];
+       volatile u32 __iomem *          *kauai_fcr;
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
        /* Those fields are duplicating what is in hwif. We currently
         * can't use the hwif ones because of some assumptions that are
@@ -80,7 +81,7 @@ typedef struct pmac_ide_hwif {
        
 } pmac_ide_hwif_t;
 
-static pmac_ide_hwif_t pmac_ide[MAX_HWIFS] __pmacdata;
+static pmac_ide_hwif_t pmac_ide[MAX_HWIFS];
 static int pmac_ide_count;
 
 enum {
@@ -89,7 +90,8 @@ enum {
        controller_kl_ata3,     /* KeyLargo ATA-3 */
        controller_kl_ata4,     /* KeyLargo ATA-4 */
        controller_un_ata6,     /* UniNorth2 ATA-6 */
-       controller_k2_ata6      /* K2 ATA-6 */
+       controller_k2_ata6,     /* K2 ATA-6 */
+       controller_sh_ata6,     /* Shasta ATA-6 */
 };
 
 static const char* model_name[] = {
@@ -99,6 +101,7 @@ static const char* model_name[] = {
        "KeyLargo ATA-4",       /* KeyLargo ATA-4 (UDMA/66) */
        "UniNorth ATA-6",       /* UniNorth2 ATA-6 (UDMA/100) */
        "K2 ATA-6",             /* K2 ATA-6 (UDMA/100) */
+       "Shasta ATA-6",         /* Shasta ATA-6 (UDMA/133) */
 };
 
 /*
@@ -122,6 +125,15 @@ static const char* model_name[] = {
 #define IDE_SYSCLK_NS          30      /* 33Mhz cell */
 #define IDE_SYSCLK_66_NS       15      /* 66Mhz cell */
 
+/* 133Mhz cell, found in shasta.
+ * See comments about 100 Mhz Uninorth 2...
+ * Note that PIO_MASK and MDMA_MASK seem to overlap
+ */
+#define TR_133_PIOREG_PIO_MASK         0xff000fff
+#define TR_133_PIOREG_MDMA_MASK                0x00fff800
+#define TR_133_UDMAREG_UDMA_MASK       0x0003ffff
+#define TR_133_UDMAREG_UDMA_EN         0x00000001
+
 /* 100Mhz cell, found in Uninorth 2. I don't have much infos about
  * this one yet, it appears as a pci device (106b/0033) on uninorth
  * internal PCI bus and it's clock is controlled like gem or fw. It
@@ -209,6 +221,13 @@ static const char* model_name[] = {
 #define IDE_INTR_DMA                   0x80000000
 #define IDE_INTR_DEVICE                        0x40000000
 
+/*
+ * FCR Register on Kauai. Not sure what bit 0x4 is  ...
+ */
+#define KAUAI_FCR_UATA_MAGIC           0x00000004
+#define KAUAI_FCR_UATA_RESET_N         0x00000002
+#define KAUAI_FCR_UATA_ENABLE          0x00000001
+
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
 
 /* Rounded Multiword DMA timings
@@ -223,7 +242,7 @@ struct mdma_timings_t {
        int     cycleTime;
 };
 
-struct mdma_timings_t mdma_timings_33[] __pmacdata =
+struct mdma_timings_t mdma_timings_33[] =
 {
     { 240, 240, 480 },
     { 180, 180, 360 },
@@ -236,7 +255,7 @@ struct mdma_timings_t mdma_timings_33[] __pmacdata =
     {   0,   0,   0 }
 };
 
-struct mdma_timings_t mdma_timings_33k[] __pmacdata =
+struct mdma_timings_t mdma_timings_33k[] =
 {
     { 240, 240, 480 },
     { 180, 180, 360 },
@@ -249,7 +268,7 @@ struct mdma_timings_t mdma_timings_33k[] __pmacdata =
     {   0,   0,   0 }
 };
 
-struct mdma_timings_t mdma_timings_66[] __pmacdata =
+struct mdma_timings_t mdma_timings_66[] =
 {
     { 240, 240, 480 },
     { 180, 180, 360 },
@@ -267,7 +286,7 @@ struct {
        int     addrSetup; /* ??? */
        int     rdy2pause;
        int     wrDataSetup;
-} kl66_udma_timings[] __pmacdata =
+} kl66_udma_timings[] =
 {
     {   0, 180,  120 },        /* Mode 0 */
     {   0, 150,  90 }, /*      1 */
@@ -282,7 +301,7 @@ struct kauai_timing {
        u32     timing_reg;
 };
 
-static struct kauai_timing     kauai_pio_timings[] __pmacdata =
+static struct kauai_timing     kauai_pio_timings[] =
 {
        { 930   , 0x08000fff },
        { 600   , 0x08000a92 },
@@ -297,7 +316,7 @@ static struct kauai_timing  kauai_pio_timings[] __pmacdata =
        { 120   , 0x04000148 }
 };
 
-static struct kauai_timing     kauai_mdma_timings[] __pmacdata =
+static struct kauai_timing     kauai_mdma_timings[] =
 {
        { 1260  , 0x00fff000 },
        { 480   , 0x00618000 },
@@ -311,7 +330,7 @@ static struct kauai_timing  kauai_mdma_timings[] __pmacdata =
        { 0     , 0 },
 };
 
-static struct kauai_timing     kauai_udma_timings[] __pmacdata =
+static struct kauai_timing     kauai_udma_timings[] =
 {
        { 120   , 0x000070c0 },
        { 90    , 0x00005d80 },
@@ -322,6 +341,48 @@ static struct kauai_timing kauai_udma_timings[] __pmacdata =
        { 0     , 0 },
 };
 
+static struct kauai_timing     shasta_pio_timings[] =
+{
+       { 930   , 0x08000fff },
+       { 600   , 0x0A000c97 },
+       { 383   , 0x07000712 },
+       { 360   , 0x040003cd },
+       { 330   , 0x040003cd },
+       { 300   , 0x040003cd },
+       { 270   , 0x040003cd },
+       { 240   , 0x040003cd },
+       { 239   , 0x040003cd },
+       { 180   , 0x0400028b },
+       { 120   , 0x0400010a }
+};
+
+static struct kauai_timing     shasta_mdma_timings[] =
+{
+       { 1260  , 0x00fff000 },
+       { 480   , 0x00820800 },
+       { 360   , 0x00820800 },
+       { 270   , 0x00820800 },
+       { 240   , 0x00820800 },
+       { 210   , 0x00820800 },
+       { 180   , 0x00820800 },
+       { 150   , 0x0028b000 },
+       { 120   , 0x001ca000 },
+       { 0     , 0 },
+};
+
+static struct kauai_timing     shasta_udma133_timings[] =
+{
+       { 120   , 0x00035901, },
+       { 90    , 0x000348b1, },
+       { 60    , 0x00033881, },
+       { 45    , 0x00033861, },
+       { 30    , 0x00033841, },
+       { 20    , 0x00033031, },
+       { 15    , 0x00033021, },
+       { 0     , 0 },
+};
+
+
 static inline u32
 kauai_lookup_timing(struct kauai_timing* table, int cycle_time)
 {
@@ -436,16 +497,19 @@ pmu_hd_blink_init(void)
        if (pmu_get_model() != PMU_KEYLARGO_BASED)
                return 0;
        
-       dt = find_devices("device-tree");
+       dt = of_find_node_by_path("/");
        if (dt == NULL)
                return 0;
        model = (const char *)get_property(dt, "model", NULL);
        if (model == NULL)
                return 0;
        if (strncmp(model, "PowerBook", strlen("PowerBook")) != 0 &&
-           strncmp(model, "iBook", strlen("iBook")) != 0)
+           strncmp(model, "iBook", strlen("iBook")) != 0) {
+               of_node_put(dt);
                return 0;
-       
+       }
+       of_node_put(dt);
+
        pmu_blink_on.complete = 1;
        pmu_blink_off.complete = 1;
        spin_lock_init(&pmu_blink_lock);
@@ -461,7 +525,7 @@ pmu_hd_blink_init(void)
  * N.B. this can't be an initfunc, because the media-bay task can
  * call ide_[un]register at any time.
  */
-void __pmac
+void
 pmac_ide_init_hwif_ports(hw_regs_t *hw,
                              unsigned long data_port, unsigned long ctrl_port,
                              int *irq)
@@ -498,7 +562,7 @@ pmac_ide_init_hwif_ports(hw_regs_t *hw,
  * timing register when selecting that unit. This version is for
  * ASICs with a single timing register
  */
-static void __pmac
+static void
 pmac_ide_selectproc(ide_drive_t *drive)
 {
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -518,7 +582,7 @@ pmac_ide_selectproc(ide_drive_t *drive)
  * timing register when selecting that unit. This version is for
  * ASICs with a dual timing register (Kauai)
  */
-static void __pmac
+static void
 pmac_ide_kauai_selectproc(ide_drive_t *drive)
 {
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -539,7 +603,7 @@ pmac_ide_kauai_selectproc(ide_drive_t *drive)
 /*
  * Force an update of controller timing values for a given drive
  */
-static void __pmac
+static void
 pmac_ide_do_update_timings(ide_drive_t *drive)
 {
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -547,7 +611,9 @@ pmac_ide_do_update_timings(ide_drive_t *drive)
        if (pmif == NULL)
                return;
 
-       if (pmif->kind == controller_un_ata6 || pmif->kind == controller_k2_ata6)
+       if (pmif->kind == controller_sh_ata6 ||
+           pmif->kind == controller_un_ata6 ||
+           pmif->kind == controller_k2_ata6)
                pmac_ide_kauai_selectproc(drive);
        else
                pmac_ide_selectproc(drive);
@@ -570,7 +636,7 @@ pmac_outbsync(ide_drive_t *drive, u8 value, unsigned long port)
  * to sort that out sooner or later and see if I can finally get the
  * common version to work properly in all cases
  */
-static int __pmac
+static int
 pmac_ide_do_setfeature(ide_drive_t *drive, u8 command)
 {
        ide_hwif_t *hwif = HWIF(drive);
@@ -647,7 +713,7 @@ out:
 /*
  * Old tuning functions (called on hdparm -p), sets up drive PIO timings
  */
-static void __pmac
+static void
 pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
 {
        ide_pio_data_t d;
@@ -665,6 +731,14 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
        pio = ide_get_best_pio_mode(drive, pio, 4, &d);
 
        switch (pmif->kind) {
+       case controller_sh_ata6: {
+               /* 133Mhz cell */
+               u32 tr = kauai_lookup_timing(shasta_pio_timings, d.cycle_time);
+               if (tr == 0)
+                       return;
+               *timings = ((*timings) & ~TR_133_PIOREG_PIO_MASK) | tr;
+               break;
+               }
        case controller_un_ata6:
        case controller_k2_ata6: {
                /* 100Mhz cell */
@@ -730,7 +804,7 @@ pmac_ide_tuneproc(ide_drive_t *drive, u8 pio)
 /*
  * Calculate KeyLargo ATA/66 UDMA timings
  */
-static int __pmac
+static int
 set_timings_udma_ata4(u32 *timings, u8 speed)
 {
        unsigned rdyToPauseTicks, wrDataSetupTicks, addrTicks;
@@ -758,7 +832,7 @@ set_timings_udma_ata4(u32 *timings, u8 speed)
 /*
  * Calculate Kauai ATA/100 UDMA timings
  */
-static int __pmac
+static int
 set_timings_udma_ata6(u32 *pio_timings, u32 *ultra_timings, u8 speed)
 {
        struct ide_timing *t = ide_timing_find_mode(speed);
@@ -775,10 +849,30 @@ set_timings_udma_ata6(u32 *pio_timings, u32 *ultra_timings, u8 speed)
        return 0;
 }
 
+/*
+ * Calculate Shasta ATA/133 UDMA timings
+ */
+static int
+set_timings_udma_shasta(u32 *pio_timings, u32 *ultra_timings, u8 speed)
+{
+       struct ide_timing *t = ide_timing_find_mode(speed);
+       u32 tr;
+
+       if (speed > XFER_UDMA_6 || t == NULL)
+               return 1;
+       tr = kauai_lookup_timing(shasta_udma133_timings, (int)t->udma);
+       if (tr == 0)
+               return 1;
+       *ultra_timings = ((*ultra_timings) & ~TR_133_UDMAREG_UDMA_MASK) | tr;
+       *ultra_timings = (*ultra_timings) | TR_133_UDMAREG_UDMA_EN;
+
+       return 0;
+}
+
 /*
  * Calculate MDMA timings for all cells
  */
-static int __pmac
+static int
 set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
                        u8 speed, int drive_cycle_time)
 {
@@ -803,6 +897,7 @@ set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
                cycleTime = 150;
        /* Get the proper timing array for this controller */
        switch(intf_type) {
+               case controller_sh_ata6:
                case controller_un_ata6:
                case controller_k2_ata6:
                        break;
@@ -836,6 +931,14 @@ set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
 #endif
        }
        switch(intf_type) {
+       case controller_sh_ata6: {
+               /* 133Mhz cell */
+               u32 tr = kauai_lookup_timing(shasta_mdma_timings, cycleTime);
+               if (tr == 0)
+                       return 1;
+               *timings = ((*timings) & ~TR_133_PIOREG_MDMA_MASK) | tr;
+               *timings2 = (*timings2) & ~TR_133_UDMAREG_UDMA_EN;
+               }
        case controller_un_ata6:
        case controller_k2_ata6: {
                /* 100Mhz cell */
@@ -914,7 +1017,7 @@ set_timings_mdma(ide_drive_t *drive, int intf_type, u32 *timings, u32 *timings2,
  * our dedicated function is more precise as it uses the drive provided
  * cycle time value. We should probably fix this one to deal with that too...
  */
-static int __pmac
+static int
 pmac_ide_tune_chipset (ide_drive_t *drive, byte speed)
 {
        int unit = (drive->select.b.unit & 0x01);
@@ -930,9 +1033,13 @@ pmac_ide_tune_chipset (ide_drive_t *drive, byte speed)
        
        switch(speed) {
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
+               case XFER_UDMA_6:
+                       if (pmif->kind != controller_sh_ata6)
+                               return 1;
                case XFER_UDMA_5:
                        if (pmif->kind != controller_un_ata6 &&
-                           pmif->kind != controller_k2_ata6)
+                           pmif->kind != controller_k2_ata6 &&
+                           pmif->kind != controller_sh_ata6)
                                return 1;
                case XFER_UDMA_4:
                case XFER_UDMA_3:
@@ -946,6 +1053,8 @@ pmac_ide_tune_chipset (ide_drive_t *drive, byte speed)
                        else if (pmif->kind == controller_un_ata6
                                 || pmif->kind == controller_k2_ata6)
                                ret = set_timings_udma_ata6(timings, timings2, speed);
+                       else if (pmif->kind == controller_sh_ata6)
+                               ret = set_timings_udma_shasta(timings, timings2, speed);
                        else
                                ret = 1;                
                        break;
@@ -986,12 +1095,16 @@ pmac_ide_tune_chipset (ide_drive_t *drive, byte speed)
  * Blast some well known "safe" values to the timing registers at init or
  * wakeup from sleep time, before we do real calculation
  */
-static void __pmac
+static void
 sanitize_timings(pmac_ide_hwif_t *pmif)
 {
        unsigned int value, value2 = 0;
        
        switch(pmif->kind) {
+               case controller_sh_ata6:
+                       value = 0x0a820c97;
+                       value2 = 0x00033031;
+                       break;
                case controller_un_ata6:
                case controller_k2_ata6:
                        value = 0x08618a92;
@@ -1013,13 +1126,13 @@ sanitize_timings(pmac_ide_hwif_t *pmif)
        pmif->timings[2] = pmif->timings[3] = value2;
 }
 
-unsigned long __pmac
+unsigned long
 pmac_ide_get_base(int index)
 {
        return pmac_ide[index].regbase;
 }
 
-int __pmac
+int
 pmac_ide_check_base(unsigned long base)
 {
        int ix;
@@ -1030,7 +1143,7 @@ pmac_ide_check_base(unsigned long base)
        return -1;
 }
 
-int __pmac
+int
 pmac_ide_get_irq(unsigned long base)
 {
        int ix;
@@ -1041,7 +1154,7 @@ pmac_ide_get_irq(unsigned long base)
        return 0;
 }
 
-static int ide_majors[]  __pmacdata = { 3, 22, 33, 34, 56, 57 };
+static int ide_majors[] = { 3, 22, 33, 34, 56, 57 };
 
 dev_t __init
 pmac_find_ide_boot(char *bootdevice, int n)
@@ -1094,12 +1207,22 @@ pmac_ide_do_suspend(ide_hwif_t *hwif)
        }
 #endif /* CONFIG_BLK_DEV_IDE_PMAC_BLINK */
 
+       disable_irq(pmif->irq);
+
        /* The media bay will handle itself just fine */
        if (pmif->mediabay)
                return 0;
        
-       /* Disable the bus */
-       ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id, 0);
+       /* Kauai has bus control FCRs directly here */
+       if (pmif->kauai_fcr) {
+               u32 fcr = readl(pmif->kauai_fcr);
+               fcr &= ~(KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE);
+               writel(fcr, pmif->kauai_fcr);
+       }
+
+       /* Disable the bus on older machines and the cell on kauai */
+       ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id,
+                           0);
 
        return 0;
 }
@@ -1118,12 +1241,22 @@ pmac_ide_do_resume(ide_hwif_t *hwif)
                ppc_md.feature_call(PMAC_FTR_IDE_ENABLE, pmif->node, pmif->aapl_bus_id, 1);
                msleep(10);
                ppc_md.feature_call(PMAC_FTR_IDE_RESET, pmif->node, pmif->aapl_bus_id, 0);
+
+               /* Kauai has it different */
+               if (pmif->kauai_fcr) {
+                       u32 fcr = readl(pmif->kauai_fcr);
+                       fcr |= KAUAI_FCR_UATA_RESET_N | KAUAI_FCR_UATA_ENABLE;
+                       writel(fcr, pmif->kauai_fcr);
+               }
+
                msleep(jiffies_to_msecs(IDE_WAKEUP_DELAY));
        }
 
        /* Sanitize drive timings */
        sanitize_timings(pmif);
 
+       enable_irq(pmif->irq);
+
        return 0;
 }
 
@@ -1138,11 +1271,13 @@ static int
 pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
 {
        struct device_node *np = pmif->node;
-       int *bidp, i;
+       int *bidp;
 
        pmif->cable_80 = 0;
        pmif->broken_dma = pmif->broken_dma_warn = 0;
-       if (device_is_compatible(np, "kauai-ata"))
+       if (device_is_compatible(np, "shasta-ata"))
+               pmif->kind = controller_sh_ata6;
+       else if (device_is_compatible(np, "kauai-ata"))
                pmif->kind = controller_un_ata6;
        else if (device_is_compatible(np, "K2-UATA"))
                pmif->kind = controller_k2_ata6;
@@ -1163,11 +1298,25 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
 
        /* 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_k2_ata6
+           || pmif->kind == controller_sh_ata6) {
                char* cable = 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 (device_is_compatible(np, "K2-UATA") ||
+           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 |
+                      KAUAI_FCR_UATA_RESET_N |
+                      KAUAI_FCR_UATA_ENABLE, pmif->kauai_fcr);
 
        pmif->mediabay = 0;
        
@@ -1178,9 +1327,9 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        /* XXX FIXME: Media bay stuff need re-organizing */
        if (np->parent && np->parent->name
            && strcasecmp(np->parent->name, "media-bay") == 0) {
-#ifdef CONFIG_PMAC_PBOOK
+#ifdef CONFIG_PMAC_MEDIABAY
                media_bay_set_ide_infos(np->parent, pmif->regbase, pmif->irq, hwif->index);
-#endif /* CONFIG_PMAC_PBOOK */
+#endif /* CONFIG_PMAC_MEDIABAY */
                pmif->mediabay = 1;
                if (!bidp)
                        pmif->aapl_bus_id = 1;
@@ -1217,7 +1366,9 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        hwif->drives[0].unmask = 1;
        hwif->drives[1].unmask = 1;
        hwif->tuneproc = pmac_ide_tuneproc;
-       if (pmif->kind == controller_un_ata6 || pmif->kind == controller_k2_ata6)
+       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;
@@ -1234,10 +1385,10 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
               hwif->index, model_name[pmif->kind], pmif->aapl_bus_id,
               pmif->mediabay ? " (mediabay)" : "", hwif->irq);
                        
-#ifdef CONFIG_PMAC_PBOOK
+#ifdef CONFIG_PMAC_MEDIABAY
        if (pmif->mediabay && check_media_bay_by_base(pmif->regbase, MB_CD) == 0)
                hwif->noprobe = 0;
-#endif /* CONFIG_PMAC_PBOOK */
+#endif /* CONFIG_PMAC_MEDIABAY */
 
        hwif->sg_max_nents = MAX_DCMDS;
 
@@ -1250,20 +1401,6 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
        /* We probe the hwif now */
        probe_hwif_init(hwif);
 
-       /* The code IDE code will have set hwif->present if we have devices attached,
-        * if we don't, the discard the interface except if we are on a media bay slot
-        */
-       if (!hwif->present && !pmif->mediabay) {
-               printk(KERN_INFO "ide%d: Bus empty, interface released.\n",
-                       hwif->index);
-               default_hwif_iops(hwif);
-               for (i = IDE_DATA_OFFSET; i <= IDE_CONTROL_OFFSET; ++i)
-                       hwif->io_ports[i] = 0;
-               hwif->chipset = ide_unknown;
-               hwif->noprobe = 1;
-               return -ENODEV;
-       }
-
        return 0;
 }
 
@@ -1271,7 +1408,7 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
  * Attach to a macio probed interface
  */
 static int __devinit
-pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match)
+pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
 {
        void __iomem *base;
        unsigned long regbase;
@@ -1293,7 +1430,7 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match)
        pmif = &pmac_ide[i];
        hwif = &ide_hwifs[i];
 
-       if (mdev->ofdev.node->n_addrs == 0) {
+       if (macio_resource_count(mdev) == 0) {
                printk(KERN_WARNING "ide%d: no address for %s\n",
                       i, mdev->ofdev.node->full_name);
                return -ENXIO;
@@ -1327,6 +1464,7 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match)
        pmif->node = mdev->ofdev.node;
        pmif->regbase = regbase;
        pmif->irq = irq;
+       pmif->kauai_fcr = NULL;
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
        if (macio_resource_count(mdev) >= 2) {
                if (macio_request_resource(mdev, 1, "ide-pmac (dma)"))
@@ -1355,12 +1493,12 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_match *match)
 }
 
 static int
-pmac_ide_macio_suspend(struct macio_dev *mdev, u32 state)
+pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t state)
 {
        ide_hwif_t      *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
        int             rc = 0;
 
-       if (state != mdev->ofdev.dev.power.power_state && state >= 2) {
+       if (state.event != mdev->ofdev.dev.power.power_state.event && state.event >= PM_EVENT_SUSPEND) {
                rc = pmac_ide_do_suspend(hwif);
                if (rc == 0)
                        mdev->ofdev.dev.power.power_state = state;
@@ -1375,10 +1513,10 @@ pmac_ide_macio_resume(struct macio_dev *mdev)
        ide_hwif_t      *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
        int             rc = 0;
        
-       if (mdev->ofdev.dev.power.power_state != 0) {
+       if (mdev->ofdev.dev.power.power_state.event != PM_EVENT_ON) {
                rc = pmac_ide_do_resume(hwif);
                if (rc == 0)
-                       mdev->ofdev.dev.power.power_state = 0;
+                       mdev->ofdev.dev.power.power_state = PMSG_ON;
        }
 
        return rc;
@@ -1440,13 +1578,9 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
        pmif->regbase = (unsigned long) base + 0x2000;
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
        pmif->dma_regs = base + 0x1000;
-#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */        
-
-       /* We use the OF node irq mapping */
-       if (np->n_intrs == 0)
-               pmif->irq = pdev->irq;
-       else
-               pmif->irq = np->intrs[0].line;
+#endif /* CONFIG_BLK_DEV_IDEDMA_PMAC */
+       pmif->kauai_fcr = base;
+       pmif->irq = pdev->irq;
 
        pci_set_drvdata(pdev, hwif);
 
@@ -1463,12 +1597,12 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
 }
 
 static int
-pmac_ide_pci_suspend(struct pci_dev *pdev, u32 state)
+pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t state)
 {
        ide_hwif_t      *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
        int             rc = 0;
        
-       if (state != pdev->dev.power.power_state && state >= 2) {
+       if (state.event != pdev->dev.power.power_state.event && state.event >= 2) {
                rc = pmac_ide_do_suspend(hwif);
                if (rc == 0)
                        pdev->dev.power.power_state = state;
@@ -1483,36 +1617,28 @@ pmac_ide_pci_resume(struct pci_dev *pdev)
        ide_hwif_t      *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
        int             rc = 0;
        
-       if (pdev->dev.power.power_state != 0) {
+       if (pdev->dev.power.power_state.event != PM_EVENT_ON) {
                rc = pmac_ide_do_resume(hwif);
                if (rc == 0)
-                       pdev->dev.power.power_state = 0;
+                       pdev->dev.power.power_state = PMSG_ON;
        }
 
        return rc;
 }
 
-static struct of_match pmac_ide_macio_match[] = 
+static struct of_device_id pmac_ide_macio_match[] = 
 {
        {
        .name           = "IDE",
-       .type           = OF_ANY_MATCH,
-       .compatible     = OF_ANY_MATCH
        },
        {
        .name           = "ATA",
-       .type           = OF_ANY_MATCH,
-       .compatible     = OF_ANY_MATCH
        },
        {
-       .name           = OF_ANY_MATCH,
        .type           = "ide",
-       .compatible     = OF_ANY_MATCH
        },
        {
-       .name           = OF_ANY_MATCH,
        .type           = "ata",
-       .compatible     = OF_ANY_MATCH
        },
        {},
 };
@@ -1527,9 +1653,16 @@ static struct macio_driver pmac_ide_macio_driver =
 };
 
 static struct pci_device_id pmac_ide_pci_match[] = {
-       { PCI_VENDOR_ID_APPLE, PCI_DEVIEC_ID_APPLE_UNI_N_ATA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_UNI_N_ATA,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_IPID_ATA100,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_K2_ATA100,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_SH_ATA,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+       { PCI_VENDOR_ID_APPLE, PCI_DEVICE_ID_APPLE_IPID2_ATA,
+         PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
 };
 
 static struct pci_driver pmac_ide_pci_driver = {
@@ -1539,6 +1672,7 @@ static struct pci_driver pmac_ide_pci_driver = {
        .suspend        = pmac_ide_pci_suspend,
        .resume         = pmac_ide_pci_resume,
 };
+MODULE_DEVICE_TABLE(pci, pmac_ide_pci_match);
 
 void __init
 pmac_ide_probe(void)
@@ -1552,7 +1686,7 @@ pmac_ide_probe(void)
 #else
        macio_register_driver(&pmac_ide_macio_driver);
        pci_register_driver(&pmac_ide_pci_driver);
-#endif 
+#endif
 }
 
 #ifdef CONFIG_BLK_DEV_IDEDMA_PMAC
@@ -1561,7 +1695,7 @@ pmac_ide_probe(void)
  * pmac_ide_build_dmatable builds the DBDMA command list
  * for a transfer and sets the DBDMA channel to point to it.
  */
-static int __pmac
+static int
 pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
 {
        struct dbdma_cmd *table;
@@ -1645,7 +1779,7 @@ pmac_ide_build_dmatable(ide_drive_t *drive, struct request *rq)
 }
 
 /* Teardown mappings after DMA has completed.  */
-static void __pmac
+static void
 pmac_ide_destroy_dmatable (ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
@@ -1662,7 +1796,7 @@ pmac_ide_destroy_dmatable (ide_drive_t *drive)
 /*
  * Pick up best MDMA timing for the drive and apply it
  */
-static int __pmac
+static int
 pmac_ide_mdma_enable(ide_drive_t *drive, u16 mode)
 {
        ide_hwif_t *hwif = HWIF(drive);
@@ -1719,7 +1853,7 @@ pmac_ide_mdma_enable(ide_drive_t *drive, u16 mode)
 /*
  * Pick up best UDMA timing for the drive and apply it
  */
-static int __pmac
+static int
 pmac_ide_udma_enable(ide_drive_t *drive, u16 mode)
 {
        ide_hwif_t *hwif = HWIF(drive);
@@ -1737,10 +1871,15 @@ pmac_ide_udma_enable(ide_drive_t *drive, u16 mode)
        timing_local[1] = *timings2;
        
        /* Calculate timings for interface */
-       if (pmif->kind == controller_un_ata6 || pmif->kind == controller_k2_ata6)
+       if (pmif->kind == controller_un_ata6
+           || pmif->kind == controller_k2_ata6)
                ret = set_timings_udma_ata6(    &timing_local[0],
                                                &timing_local[1],
                                                mode);
+       else if (pmif->kind == controller_sh_ata6)
+               ret = set_timings_udma_shasta(  &timing_local[0],
+                                               &timing_local[1],
+                                               mode);
        else
                ret = set_timings_udma_ata4(&timing_local[0], mode);
        if (ret)
@@ -1770,7 +1909,7 @@ pmac_ide_udma_enable(ide_drive_t *drive, u16 mode)
  * Check what is the best DMA timing setting for the drive and
  * call appropriate functions to apply it.
  */
-static int __pmac
+static int
 pmac_ide_dma_check(ide_drive_t *drive)
 {
        struct hd_driveid *id = drive->id;
@@ -1791,14 +1930,19 @@ pmac_ide_dma_check(ide_drive_t *drive)
                short mode;
                
                map = XFER_MWDMA;
-               if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6
-                   || pmif->kind == controller_k2_ata6) {
+               if (pmif->kind == controller_kl_ata4
+                   || pmif->kind == controller_un_ata6
+                   || pmif->kind == controller_k2_ata6
+                   || pmif->kind == controller_sh_ata6) {
                        map |= XFER_UDMA;
                        if (pmif->cable_80) {
                                map |= XFER_UDMA_66;
                                if (pmif->kind == controller_un_ata6 ||
-                                   pmif->kind == controller_k2_ata6)
+                                   pmif->kind == controller_k2_ata6 ||
+                                   pmif->kind == controller_sh_ata6)
                                        map |= XFER_UDMA_100;
+                               if (pmif->kind == controller_sh_ata6)
+                                       map |= XFER_UDMA_133;
                        }
                }
                mode = ide_find_best_mode(drive, map);
@@ -1817,7 +1961,7 @@ pmac_ide_dma_check(ide_drive_t *drive)
  * Prepare a DMA transfer. We build the DMA table, adjust the timings for
  * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
  */
-static int __pmac
+static int
 pmac_ide_dma_setup(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = HWIF(drive);
@@ -1847,7 +1991,7 @@ pmac_ide_dma_setup(ide_drive_t *drive)
        return 0;
 }
 
-static void __pmac
+static void
 pmac_ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
 {
        /* issue cmd to drive */
@@ -1858,7 +2002,7 @@ pmac_ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
  * Kick the DMA controller into life after the DMA command has been issued
  * to the drive.
  */
-static void __pmac
+static void
 pmac_ide_dma_start(ide_drive_t *drive)
 {
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -1874,7 +2018,7 @@ pmac_ide_dma_start(ide_drive_t *drive)
 /*
  * After a DMA transfer, make sure the controller is stopped
  */
-static int __pmac
+static int
 pmac_ide_dma_end (ide_drive_t *drive)
 {
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -1902,7 +2046,7 @@ pmac_ide_dma_end (ide_drive_t *drive)
  * that's not implemented yet), on the other hand, we don't have shared interrupts
  * so it's not really a problem
  */
-static int __pmac
+static int
 pmac_ide_dma_test_irq (ide_drive_t *drive)
 {
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -1958,19 +2102,19 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
        return 1;
 }
 
-static int __pmac
+static int
 pmac_ide_dma_host_off (ide_drive_t *drive)
 {
        return 0;
 }
 
-static int __pmac
+static int
 pmac_ide_dma_host_on (ide_drive_t *drive)
 {
        return 0;
 }
 
-static int __pmac
+static int
 pmac_ide_dma_lostirq (ide_drive_t *drive)
 {
        pmac_ide_hwif_t* pmif = (pmac_ide_hwif_t *)HWIF(drive)->hwif_data;
@@ -2028,6 +2172,11 @@ pmac_ide_setup_dma(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
 
        hwif->atapi_dma = 1;
        switch(pmif->kind) {
+               case controller_sh_ata6:
+                       hwif->ultra_mask = pmif->cable_80 ? 0x7f : 0x07;
+                       hwif->mwdma_mask = 0x07;
+                       hwif->swdma_mask = 0x00;
+                       break;
                case controller_un_ata6:
                case controller_k2_ata6:
                        hwif->ultra_mask = pmif->cable_80 ? 0x3f : 0x07;