]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide-disk.c
ide-disk: add ide_do_setfeature() helper
[linux-2.6-omap-h63xx.git] / drivers / ide / ide-disk.c
index 01846f244b40156b3822bcb504f05f7c18b12bd5..7ea075299bd9b59aa4feeedce7ebaaf20b65569e 100644 (file)
@@ -580,6 +580,19 @@ static int set_nowerr(ide_drive_t *drive, int arg)
        return 0;
 }
 
+static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
+{
+       ide_task_t task;
+
+       memset(&task, 0, sizeof(task));
+       task.tf.feature = feature;
+       task.tf.nsect   = nsect;
+       task.tf.command = ATA_CMD_SET_FEATURES;
+       task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
+
+       return ide_no_data_taskfile(drive, &task);
+}
+
 static void update_ordered(ide_drive_t *drive)
 {
        u16 *id = drive->id;
@@ -619,19 +632,14 @@ ide_devset_get(wcache, wcache);
 
 static int set_wcache(ide_drive_t *drive, int arg)
 {
-       ide_task_t args;
        int err = 1;
 
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
        if (ata_id_flush_enabled(drive->id)) {
-               memset(&args, 0, sizeof(ide_task_t));
-               args.tf.feature = arg ?
-                       SETFEATURES_WC_ON : SETFEATURES_WC_OFF;
-               args.tf.command = ATA_CMD_SET_FEATURES;
-               args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-               err = ide_no_data_taskfile(drive, &args);
+               err = ide_do_setfeature(drive,
+                       arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0);
                if (err == 0)
                        drive->wcache = arg;
        }
@@ -658,18 +666,14 @@ ide_devset_get(acoustic, acoustic);
 
 static int set_acoustic(ide_drive_t *drive, int arg)
 {
-       ide_task_t args;
-
        if (arg < 0 || arg > 254)
                return -EINVAL;
 
-       memset(&args, 0, sizeof(ide_task_t));
-       args.tf.feature = arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF;
-       args.tf.nsect   = arg;
-       args.tf.command = ATA_CMD_SET_FEATURES;
-       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-       ide_no_data_taskfile(drive, &args);
+       ide_do_setfeature(drive,
+               arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg);
+
        drive->acoustic = arg;
+
        return 0;
 }
 
@@ -686,14 +690,13 @@ static int set_addressing(ide_drive_t *drive, int arg)
        if (arg < 0 || arg > 2)
                return -EINVAL;
 
-       drive->addressing =  0;
-
-       if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48)
-               return 0;
-
-       if (ata_id_lba48_enabled(drive->id) == 0)
+       if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
+           ata_id_lba48_enabled(drive->id) == 0))
                return -EIO;
 
+       if (arg == 2)
+               arg = 0;
+
        drive->addressing = arg;
 
        return 0;