]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
ide: move Power Management support to ide-pm.c
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Mon, 29 Dec 2008 19:27:37 +0000 (20:27 +0100)
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Mon, 29 Dec 2008 19:27:37 +0000 (20:27 +0100)
There should be no functional changes caused by this patch.

Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
drivers/ide/Makefile
drivers/ide/ide-io.c
drivers/ide/ide-pm.c [new file with mode: 0644]
drivers/ide/ide.c
include/linux/ide.h

index 7818d402b188ff88a84f51b901bbee13962565aa..bdc7b81bc04410e2b07c0ce0e453416a76beb2e6 100644 (file)
@@ -5,7 +5,7 @@
 EXTRA_CFLAGS                           += -Idrivers/ide
 
 ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
-             ide-taskfile.o ide-park.o ide-pio-blacklist.o
+             ide-taskfile.o ide-pm.o ide-park.o ide-pio-blacklist.o
 
 # core IDE code
 ide-core-$(CONFIG_IDE_TIMINGS)         += ide-timings.o
index 26d3f3cacc8a30c59d6789233970701c3858cae4..ecacc008fdafec71175fddfc73199acb302f0110 100644 (file)
@@ -120,98 +120,6 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
 }
 EXPORT_SYMBOL(ide_end_request);
 
-static void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
-{
-       struct request_pm_state *pm = rq->data;
-
-#ifdef DEBUG_PM
-       printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
-               drive->name, pm->pm_step);
-#endif
-       if (drive->media != ide_disk)
-               return;
-
-       switch (pm->pm_step) {
-       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
-               if (pm->pm_state == PM_EVENT_FREEZE)
-                       pm->pm_step = IDE_PM_COMPLETED;
-               else
-                       pm->pm_step = IDE_PM_STANDBY;
-               break;
-       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
-               pm->pm_step = IDE_PM_COMPLETED;
-               break;
-       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
-               pm->pm_step = IDE_PM_IDLE;
-               break;
-       case IDE_PM_IDLE:               /* Resume step 2 (idle)*/
-               pm->pm_step = IDE_PM_RESTORE_DMA;
-               break;
-       }
-}
-
-static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
-{
-       struct request_pm_state *pm = rq->data;
-       ide_task_t *args = rq->special;
-
-       memset(args, 0, sizeof(*args));
-
-       switch (pm->pm_step) {
-       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
-               if (drive->media != ide_disk)
-                       break;
-               /* Not supported? Switch to next step now. */
-               if (ata_id_flush_enabled(drive->id) == 0 ||
-                   (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
-                       ide_complete_power_step(drive, rq);
-                       return ide_stopped;
-               }
-               if (ata_id_flush_ext_enabled(drive->id))
-                       args->tf.command = ATA_CMD_FLUSH_EXT;
-               else
-                       args->tf.command = ATA_CMD_FLUSH;
-               goto out_do_tf;
-       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
-               args->tf.command = ATA_CMD_STANDBYNOW1;
-               goto out_do_tf;
-       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
-               ide_set_max_pio(drive);
-               /*
-                * skip IDE_PM_IDLE for ATAPI devices
-                */
-               if (drive->media != ide_disk)
-                       pm->pm_step = IDE_PM_RESTORE_DMA;
-               else
-                       ide_complete_power_step(drive, rq);
-               return ide_stopped;
-       case IDE_PM_IDLE:               /* Resume step 2 (idle) */
-               args->tf.command = ATA_CMD_IDLEIMMEDIATE;
-               goto out_do_tf;
-       case IDE_PM_RESTORE_DMA:        /* Resume step 3 (restore DMA) */
-               /*
-                * Right now, all we do is call ide_set_dma(drive),
-                * we could be smarter and check for current xfer_speed
-                * in struct drive etc...
-                */
-               if (drive->hwif->dma_ops == NULL)
-                       break;
-               /*
-                * TODO: respect IDE_DFLAG_USING_DMA
-                */
-               ide_set_dma(drive);
-               break;
-       }
-
-       pm->pm_step = IDE_PM_COMPLETED;
-       return ide_stopped;
-
-out_do_tf:
-       args->tf_flags   = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-       args->data_phase = TASKFILE_NO_DATA;
-       return do_rw_taskfile(drive, args);
-}
-
 /**
  *     ide_end_dequeued_request        -       complete an IDE I/O
  *     @drive: IDE device for the I/O
@@ -236,39 +144,6 @@ int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
 }
 EXPORT_SYMBOL_GPL(ide_end_dequeued_request);
 
-
-/**
- *     ide_complete_pm_request - end the current Power Management request
- *     @drive: target drive
- *     @rq: request
- *
- *     This function cleans up the current PM request and stops the queue
- *     if necessary.
- */
-static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
-{
-       struct request_queue *q = drive->queue;
-       unsigned long flags;
-
-#ifdef DEBUG_PM
-       printk("%s: completing PM request, %s\n", drive->name,
-              blk_pm_suspend_request(rq) ? "suspend" : "resume");
-#endif
-       spin_lock_irqsave(q->queue_lock, flags);
-       if (blk_pm_suspend_request(rq)) {
-               blk_stop_queue(q);
-       } else {
-               drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
-               blk_start_queue(q);
-       }
-       spin_unlock_irqrestore(q->queue_lock, flags);
-
-       drive->hwif->hwgroup->rq = NULL;
-
-       if (blk_end_request(rq, 0, 0))
-               BUG();
-}
-
 /**
  *     ide_end_drive_cmd       -       end an explicit drive command
  *     @drive: command 
@@ -697,40 +572,6 @@ static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
        }
 }
 
-static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
-{
-       struct request_pm_state *pm = rq->data;
-
-       if (blk_pm_suspend_request(rq) &&
-           pm->pm_step == IDE_PM_START_SUSPEND)
-               /* Mark drive blocked when starting the suspend sequence. */
-               drive->dev_flags |= IDE_DFLAG_BLOCKED;
-       else if (blk_pm_resume_request(rq) &&
-                pm->pm_step == IDE_PM_START_RESUME) {
-               /* 
-                * The first thing we do on wakeup is to wait for BSY bit to
-                * go away (with a looong timeout) as a drive on this hwif may
-                * just be POSTing itself.
-                * We do that before even selecting as the "other" device on
-                * the bus may be broken enough to walk on our toes at this
-                * point.
-                */
-               ide_hwif_t *hwif = drive->hwif;
-               int rc;
-#ifdef DEBUG_PM
-               printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
-#endif
-               rc = ide_wait_not_busy(hwif, 35000);
-               if (rc)
-                       printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
-               SELECT_DRIVE(drive);
-               hwif->tp_ops->set_irq(hwif, 1);
-               rc = ide_wait_not_busy(hwif, 100000);
-               if (rc)
-                       printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
-       }
-}
-
 /**
  *     start_request   -       start of I/O and command issuing for IDE
  *
diff --git a/drivers/ide/ide-pm.c b/drivers/ide/ide-pm.c
new file mode 100644 (file)
index 0000000..8282c60
--- /dev/null
@@ -0,0 +1,235 @@
+#include <linux/kernel.h>
+#include <linux/ide.h>
+#include <linux/hdreg.h>
+
+int generic_ide_suspend(struct device *dev, pm_message_t mesg)
+{
+       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
+       ide_hwif_t *hwif = HWIF(drive);
+       struct request *rq;
+       struct request_pm_state rqpm;
+       ide_task_t args;
+       int ret;
+
+       /* call ACPI _GTM only once */
+       if ((drive->dn & 1) == 0 || pair == NULL)
+               ide_acpi_get_timing(hwif);
+
+       memset(&rqpm, 0, sizeof(rqpm));
+       memset(&args, 0, sizeof(args));
+       rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
+       rq->cmd_type = REQ_TYPE_PM_SUSPEND;
+       rq->special = &args;
+       rq->data = &rqpm;
+       rqpm.pm_step = IDE_PM_START_SUSPEND;
+       if (mesg.event == PM_EVENT_PRETHAW)
+               mesg.event = PM_EVENT_FREEZE;
+       rqpm.pm_state = mesg.event;
+
+       ret = blk_execute_rq(drive->queue, NULL, rq, 0);
+       blk_put_request(rq);
+
+       /* call ACPI _PS3 only after both devices are suspended */
+       if (ret == 0 && ((drive->dn & 1) || pair == NULL))
+               ide_acpi_set_state(hwif, 0);
+
+       return ret;
+}
+
+int generic_ide_resume(struct device *dev)
+{
+       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
+       ide_hwif_t *hwif = HWIF(drive);
+       struct request *rq;
+       struct request_pm_state rqpm;
+       ide_task_t args;
+       int err;
+
+       /* call ACPI _PS0 / _STM only once */
+       if ((drive->dn & 1) == 0 || pair == NULL) {
+               ide_acpi_set_state(hwif, 1);
+               ide_acpi_push_timing(hwif);
+       }
+
+       ide_acpi_exec_tfs(drive);
+
+       memset(&rqpm, 0, sizeof(rqpm));
+       memset(&args, 0, sizeof(args));
+       rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
+       rq->cmd_type = REQ_TYPE_PM_RESUME;
+       rq->cmd_flags |= REQ_PREEMPT;
+       rq->special = &args;
+       rq->data = &rqpm;
+       rqpm.pm_step = IDE_PM_START_RESUME;
+       rqpm.pm_state = PM_EVENT_ON;
+
+       err = blk_execute_rq(drive->queue, NULL, rq, 1);
+       blk_put_request(rq);
+
+       if (err == 0 && dev->driver) {
+               ide_driver_t *drv = to_ide_driver(dev->driver);
+
+               if (drv->resume)
+                       drv->resume(drive);
+       }
+
+       return err;
+}
+
+void ide_complete_power_step(ide_drive_t *drive, struct request *rq)
+{
+       struct request_pm_state *pm = rq->data;
+
+#ifdef DEBUG_PM
+       printk(KERN_INFO "%s: complete_power_step(step: %d)\n",
+               drive->name, pm->pm_step);
+#endif
+       if (drive->media != ide_disk)
+               return;
+
+       switch (pm->pm_step) {
+       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
+               if (pm->pm_state == PM_EVENT_FREEZE)
+                       pm->pm_step = IDE_PM_COMPLETED;
+               else
+                       pm->pm_step = IDE_PM_STANDBY;
+               break;
+       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
+               pm->pm_step = IDE_PM_COMPLETED;
+               break;
+       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
+               pm->pm_step = IDE_PM_IDLE;
+               break;
+       case IDE_PM_IDLE:               /* Resume step 2 (idle)*/
+               pm->pm_step = IDE_PM_RESTORE_DMA;
+               break;
+       }
+}
+
+ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
+{
+       struct request_pm_state *pm = rq->data;
+       ide_task_t *args = rq->special;
+
+       memset(args, 0, sizeof(*args));
+
+       switch (pm->pm_step) {
+       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
+               if (drive->media != ide_disk)
+                       break;
+               /* Not supported? Switch to next step now. */
+               if (ata_id_flush_enabled(drive->id) == 0 ||
+                   (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
+                       ide_complete_power_step(drive, rq);
+                       return ide_stopped;
+               }
+               if (ata_id_flush_ext_enabled(drive->id))
+                       args->tf.command = ATA_CMD_FLUSH_EXT;
+               else
+                       args->tf.command = ATA_CMD_FLUSH;
+               goto out_do_tf;
+       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
+               args->tf.command = ATA_CMD_STANDBYNOW1;
+               goto out_do_tf;
+       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
+               ide_set_max_pio(drive);
+               /*
+                * skip IDE_PM_IDLE for ATAPI devices
+                */
+               if (drive->media != ide_disk)
+                       pm->pm_step = IDE_PM_RESTORE_DMA;
+               else
+                       ide_complete_power_step(drive, rq);
+               return ide_stopped;
+       case IDE_PM_IDLE:               /* Resume step 2 (idle) */
+               args->tf.command = ATA_CMD_IDLEIMMEDIATE;
+               goto out_do_tf;
+       case IDE_PM_RESTORE_DMA:        /* Resume step 3 (restore DMA) */
+               /*
+                * Right now, all we do is call ide_set_dma(drive),
+                * we could be smarter and check for current xfer_speed
+                * in struct drive etc...
+                */
+               if (drive->hwif->dma_ops == NULL)
+                       break;
+               /*
+                * TODO: respect IDE_DFLAG_USING_DMA
+                */
+               ide_set_dma(drive);
+               break;
+       }
+
+       pm->pm_step = IDE_PM_COMPLETED;
+       return ide_stopped;
+
+out_do_tf:
+       args->tf_flags   = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
+       args->data_phase = TASKFILE_NO_DATA;
+       return do_rw_taskfile(drive, args);
+}
+
+/**
+ *     ide_complete_pm_request - end the current Power Management request
+ *     @drive: target drive
+ *     @rq: request
+ *
+ *     This function cleans up the current PM request and stops the queue
+ *     if necessary.
+ */
+void ide_complete_pm_request(ide_drive_t *drive, struct request *rq)
+{
+       struct request_queue *q = drive->queue;
+       unsigned long flags;
+
+#ifdef DEBUG_PM
+       printk("%s: completing PM request, %s\n", drive->name,
+              blk_pm_suspend_request(rq) ? "suspend" : "resume");
+#endif
+       spin_lock_irqsave(q->queue_lock, flags);
+       if (blk_pm_suspend_request(rq)) {
+               blk_stop_queue(q);
+       } else {
+               drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
+               blk_start_queue(q);
+       }
+       spin_unlock_irqrestore(q->queue_lock, flags);
+
+       drive->hwif->hwgroup->rq = NULL;
+
+       if (blk_end_request(rq, 0, 0))
+               BUG();
+}
+
+void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
+{
+       struct request_pm_state *pm = rq->data;
+
+       if (blk_pm_suspend_request(rq) &&
+           pm->pm_step == IDE_PM_START_SUSPEND)
+               /* Mark drive blocked when starting the suspend sequence. */
+               drive->dev_flags |= IDE_DFLAG_BLOCKED;
+       else if (blk_pm_resume_request(rq) &&
+                pm->pm_step == IDE_PM_START_RESUME) {
+               /*
+                * The first thing we do on wakeup is to wait for BSY bit to
+                * go away (with a looong timeout) as a drive on this hwif may
+                * just be POSTing itself.
+                * We do that before even selecting as the "other" device on
+                * the bus may be broken enough to walk on our toes at this
+                * point.
+                */
+               ide_hwif_t *hwif = drive->hwif;
+               int rc;
+#ifdef DEBUG_PM
+               printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
+#endif
+               rc = ide_wait_not_busy(hwif, 35000);
+               if (rc)
+                       printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
+               SELECT_DRIVE(drive);
+               hwif->tp_ops->set_irq(hwif, 1);
+               rc = ide_wait_not_busy(hwif, 100000);
+               if (rc)
+                       printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
+       }
+}
index 41d042053548afd8658deff9376a6ac5ed179beb..f0f09f702e9ccf54b20f7ed85d1c9d00b6326275 100644 (file)
@@ -388,80 +388,6 @@ ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
 ide_ext_devset_rw_sync(using_dma, using_dma);
 __IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
 
-static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
-{
-       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
-       ide_hwif_t *hwif = HWIF(drive);
-       struct request *rq;
-       struct request_pm_state rqpm;
-       ide_task_t args;
-       int ret;
-
-       /* call ACPI _GTM only once */
-       if ((drive->dn & 1) == 0 || pair == NULL)
-               ide_acpi_get_timing(hwif);
-
-       memset(&rqpm, 0, sizeof(rqpm));
-       memset(&args, 0, sizeof(args));
-       rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
-       rq->cmd_type = REQ_TYPE_PM_SUSPEND;
-       rq->special = &args;
-       rq->data = &rqpm;
-       rqpm.pm_step = IDE_PM_START_SUSPEND;
-       if (mesg.event == PM_EVENT_PRETHAW)
-               mesg.event = PM_EVENT_FREEZE;
-       rqpm.pm_state = mesg.event;
-
-       ret = blk_execute_rq(drive->queue, NULL, rq, 0);
-       blk_put_request(rq);
-
-       /* call ACPI _PS3 only after both devices are suspended */
-       if (ret == 0 && ((drive->dn & 1) || pair == NULL))
-               ide_acpi_set_state(hwif, 0);
-
-       return ret;
-}
-
-static int generic_ide_resume(struct device *dev)
-{
-       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
-       ide_hwif_t *hwif = HWIF(drive);
-       struct request *rq;
-       struct request_pm_state rqpm;
-       ide_task_t args;
-       int err;
-
-       /* call ACPI _PS0 / _STM only once */
-       if ((drive->dn & 1) == 0 || pair == NULL) {
-               ide_acpi_set_state(hwif, 1);
-               ide_acpi_push_timing(hwif);
-       }
-
-       ide_acpi_exec_tfs(drive);
-
-       memset(&rqpm, 0, sizeof(rqpm));
-       memset(&args, 0, sizeof(args));
-       rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
-       rq->cmd_type = REQ_TYPE_PM_RESUME;
-       rq->cmd_flags |= REQ_PREEMPT;
-       rq->special = &args;
-       rq->data = &rqpm;
-       rqpm.pm_step = IDE_PM_START_RESUME;
-       rqpm.pm_state = PM_EVENT_ON;
-
-       err = blk_execute_rq(drive->queue, NULL, rq, 1);
-       blk_put_request(rq);
-
-       if (err == 0 && dev->driver) {
-               ide_driver_t *drv = to_ide_driver(dev->driver);
-
-               if (drv->resume)
-                       drv->resume(drive);
-       }
-
-       return err;
-}
-
 /**
  * ide_device_get      -       get an additional reference to a ide_drive_t
  * @drive:     device to get a reference to
index 9b89cab6d4935bfc02bd6d28dbd2bd2d9ce86de5..e99c56de7f56e23a71e0a4b7daca0537c75b3012 100644 (file)
@@ -1116,6 +1116,14 @@ enum {
        IDE_PM_COMPLETED,
 };
 
+int generic_ide_suspend(struct device *, pm_message_t);
+int generic_ide_resume(struct device *);
+
+void ide_complete_power_step(ide_drive_t *, struct request *);
+ide_startstop_t ide_start_power_step(ide_drive_t *, struct request *);
+void ide_complete_pm_request(ide_drive_t *, struct request *);
+void ide_check_pm_state(ide_drive_t *, struct request *);
+
 /*
  * Subdrivers support.
  *