ide: factor out adding drive to hwgroup from init_irq()
[deliverable/linux.git] / drivers / ide / ide-probe.c
index 4c3d2cf3be5b583ec72ffaa4c07bba4ec73ffdbe..4d940d1a80edd4dc836620fb3afb98c336c15aa7 100644 (file)
@@ -822,7 +822,7 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
        for (unit = 0; unit < MAX_DRIVES; ++unit) {
                ide_drive_t *drive = &hwif->drives[unit];
 
-               if (hwif->no_io_32bit)
+               if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
                        drive->no_io_32bit = 1;
                else
                        drive->no_io_32bit = drive->id->dword_io ? 1 : 0;
@@ -881,13 +881,6 @@ static int ide_init_queue(ide_drive_t *drive)
        q->queuedata = drive;
        blk_queue_segment_boundary(q, 0xffff);
 
-       if (!hwif->rqsize) {
-               if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
-                   (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
-                       hwif->rqsize = 256;
-               else
-                       hwif->rqsize = 65536;
-       }
        if (hwif->rqsize < max_sectors)
                max_sectors = hwif->rqsize;
        blk_queue_max_sectors(q, max_sectors);
@@ -918,6 +911,23 @@ static int ide_init_queue(ide_drive_t *drive)
        return 0;
 }
 
+static void ide_add_drive_to_hwgroup(ide_drive_t *drive)
+{
+       ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
+
+       spin_lock_irq(&ide_lock);
+       if (!hwgroup->drive) {
+               /* first drive for hwgroup. */
+               drive->next = drive;
+               hwgroup->drive = drive;
+               hwgroup->hwif = HWIF(hwgroup->drive);
+       } else {
+               drive->next = hwgroup->drive->next;
+               hwgroup->drive->next = drive;
+       }
+       spin_unlock_irq(&ide_lock);
+}
+
 /*
  * This routine sets up the irq for an ide interface, and creates a new
  * hwgroup for the irq/hwif if none was previously assigned.
@@ -1019,6 +1029,14 @@ static int init_irq (ide_hwif_t *hwif)
                        goto out_unlink;
        }
 
+       if (!hwif->rqsize) {
+               if ((hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
+                   (hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA))
+                       hwif->rqsize = 256;
+               else
+                       hwif->rqsize = 65536;
+       }
+
        /*
         * For any present drive:
         * - allocate the block device queue
@@ -1032,17 +1050,7 @@ static int init_irq (ide_hwif_t *hwif)
                        printk(KERN_ERR "ide: failed to init %s\n",drive->name);
                        continue;
                }
-               spin_lock_irq(&ide_lock);
-               if (!hwgroup->drive) {
-                       /* first drive for hwgroup. */
-                       drive->next = drive;
-                       hwgroup->drive = drive;
-                       hwgroup->hwif = HWIF(hwgroup->drive);
-               } else {
-                       drive->next = hwgroup->drive->next;
-                       hwgroup->drive->next = drive;
-               }
-               spin_unlock_irq(&ide_lock);
+               ide_add_drive_to_hwgroup(drive);
        }
 
 #if !defined(__mc68000__) && !defined(CONFIG_APUS)
@@ -1182,30 +1190,6 @@ static void drive_release_dev (struct device *dev)
        complete(&drive->gendev_rel_comp);
 }
 
-/*
- * init_gendisk() (as opposed to ide_geninit) is called for each major device,
- * after probing for drives, to allocate partition tables and other data
- * structures needed for the routines in genhd.c.  ide_geninit() gets called
- * somewhat later, during the partition check.
- */
-static void init_gendisk (ide_hwif_t *hwif)
-{
-       unsigned int unit;
-
-       for (unit = 0; unit < MAX_DRIVES; ++unit) {
-               ide_drive_t * drive = &hwif->drives[unit];
-               ide_add_generic_settings(drive);
-               snprintf(drive->gendev.bus_id,BUS_ID_SIZE,"%u.%u",
-                        hwif->index,unit);
-               drive->gendev.parent = &hwif->gendev;
-               drive->gendev.bus = &ide_bus_type;
-               drive->gendev.driver_data = drive;
-               drive->gendev.release = drive_release_dev;
-       }
-       blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
-                       THIS_MODULE, ata_probe, ata_lock, hwif);
-}
-
 static int hwif_init(ide_hwif_t *hwif)
 {
        int old_irq;
@@ -1262,7 +1246,8 @@ static int hwif_init(ide_hwif_t *hwif)
                hwif->name, hwif->irq);
 
 done:
-       init_gendisk(hwif);
+       blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
+                           THIS_MODULE, ata_probe, ata_lock, hwif);
        ide_acpi_init(hwif);
        return 1;
 
@@ -1277,16 +1262,46 @@ static void hwif_register_devices(ide_hwif_t *hwif)
 
        for (i = 0; i < MAX_DRIVES; i++) {
                ide_drive_t *drive = &hwif->drives[i];
+               struct device *dev = &drive->gendev;
+               int ret;
 
-               if (drive->present) {
-                       int ret = device_register(&drive->gendev);
+               if (!drive->present)
+                       continue;
 
-                       if (ret < 0)
-                               printk(KERN_WARNING "IDE: %s: "
-                                       "device_register error: %d\n",
-                                       __FUNCTION__, ret);
-               }
+               ide_add_generic_settings(drive);
+
+               snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
+               dev->parent = &hwif->gendev;
+               dev->bus = &ide_bus_type;
+               dev->driver_data = drive;
+               dev->release = drive_release_dev;
+
+               ret = device_register(dev);
+               if (ret < 0)
+                       printk(KERN_WARNING "IDE: %s: device_register error: "
+                                           "%d\n", __func__, ret);
+       }
+}
+
+static void ide_port_init_devices(ide_hwif_t *hwif)
+{
+       int i;
+
+       for (i = 0; i < MAX_DRIVES; i++) {
+               ide_drive_t *drive = &hwif->drives[i];
+
+               if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
+                       drive->io_32bit = 1;
+               if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
+                       drive->unmask = 1;
+               if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
+                       drive->no_unmask = 1;
+               if ((hwif->host_flags & IDE_HFLAG_NO_AUTOTUNE) == 0)
+                       drive->autotune = 1;
        }
+
+       if (hwif->port_init_devs)
+               hwif->port_init_devs(hwif);
 }
 
 static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
@@ -1314,16 +1329,6 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
        if ((d->host_flags & IDE_HFLAG_SERIALIZE) && hwif->mate)
                hwif->mate->serialized = hwif->serialized = 1;
 
-       if (d->host_flags & IDE_HFLAG_IO_32BIT) {
-               hwif->drives[0].io_32bit = 1;
-               hwif->drives[1].io_32bit = 1;
-       }
-
-       if (d->host_flags & IDE_HFLAG_UNMASK_IRQS) {
-               hwif->drives[0].unmask = 1;
-               hwif->drives[1].unmask = 1;
-       }
-
        hwif->swdma_mask = d->swdma_mask;
        hwif->mwdma_mask = d->mwdma_mask;
        hwif->ultra_mask = d->udma_mask;
@@ -1332,17 +1337,17 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
        if ((d->host_flags && IDE_HFLAG_NO_DMA) == 0 && hwif->dma_base == 0)
                hwif->swdma_mask = hwif->mwdma_mask = hwif->ultra_mask = 0;
 
-       if ((d->host_flags & IDE_HFLAG_NO_AUTOTUNE) == 0) {
-               hwif->drives[0].autotune = 1;
-               hwif->drives[1].autotune = 1;
-       }
-
        if (d->host_flags & IDE_HFLAG_RQSIZE_256)
                hwif->rqsize = 256;
 
        /* call chipset specific routine for each enabled port */
        if (d->init_hwif)
                d->init_hwif(hwif);
+
+       if (hwif->cable_detect && (hwif->ultra_mask & 0x78)) {
+               if (hwif->cbl != ATA_CBL_PATA40_SHORT)
+                       hwif->cbl = hwif->cable_detect(hwif);
+       }
 }
 
 int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
@@ -1366,6 +1371,7 @@ int ide_device_add_all(u8 *idx, const struct ide_port_info *d)
                mate = (i & 1) ? NULL : hwif;
 
                ide_init_port(hwif, i & 1, d);
+               ide_port_init_devices(hwif);
        }
 
        for (i = 0; i < MAX_HWIFS; i++) {
This page took 0.040714 seconds and 5 git commands to generate.