1e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#include <linux/kernel.h> 25a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/gfp.h> 3e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#include <linux/ide.h> 4e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 5e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewiczint generic_ide_suspend(struct device *dev, pm_message_t mesg) 6e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz{ 7fcb5207723919ad85178420633d55efea80b652dGreg Kroah-Hartman ide_drive_t *drive = dev_get_drvdata(dev); 8fcb5207723919ad85178420633d55efea80b652dGreg Kroah-Hartman ide_drive_t *pair = ide_get_pair_dev(drive); 9898ec223fea2a2df88035e58dbf50f493577e225Bartlomiej Zolnierkiewicz ide_hwif_t *hwif = drive->hwif; 10e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz struct request *rq; 11e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz struct request_pm_state rqpm; 12e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz int ret; 13e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 142bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz if (ide_port_acpi(hwif)) { 152bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz /* call ACPI _GTM only once */ 162bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz if ((drive->dn & 1) == 0 || pair == NULL) 172bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz ide_acpi_get_timing(hwif); 182bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz } 19e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 20e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz memset(&rqpm, 0, sizeof(rqpm)); 21e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 22e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rq->cmd_type = REQ_TYPE_PM_SUSPEND; 23fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo rq->special = &rqpm; 24e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rqpm.pm_step = IDE_PM_START_SUSPEND; 25e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (mesg.event == PM_EVENT_PRETHAW) 26e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz mesg.event = PM_EVENT_FREEZE; 27e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rqpm.pm_state = mesg.event; 28e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 29e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz ret = blk_execute_rq(drive->queue, NULL, rq, 0); 30e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz blk_put_request(rq); 31e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 322bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz if (ret == 0 && ide_port_acpi(hwif)) { 332bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz /* call ACPI _PS3 only after both devices are suspended */ 342bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz if ((drive->dn & 1) || pair == NULL) 352bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz ide_acpi_set_state(hwif, 0); 362bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz } 37e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 38e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz return ret; 39e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz} 40e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 41e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewiczint generic_ide_resume(struct device *dev) 42e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz{ 43fcb5207723919ad85178420633d55efea80b652dGreg Kroah-Hartman ide_drive_t *drive = dev_get_drvdata(dev); 44fcb5207723919ad85178420633d55efea80b652dGreg Kroah-Hartman ide_drive_t *pair = ide_get_pair_dev(drive); 45898ec223fea2a2df88035e58dbf50f493577e225Bartlomiej Zolnierkiewicz ide_hwif_t *hwif = drive->hwif; 46e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz struct request *rq; 47e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz struct request_pm_state rqpm; 48e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz int err; 49e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 502bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz if (ide_port_acpi(hwif)) { 512bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz /* call ACPI _PS0 / _STM only once */ 522bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz if ((drive->dn & 1) == 0 || pair == NULL) { 532bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz ide_acpi_set_state(hwif, 1); 542bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz ide_acpi_push_timing(hwif); 552bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz } 56e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 572bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz ide_acpi_exec_tfs(drive); 582bf427b25b79eb7cea27963a66c3d4684cae0e0cBartlomiej Zolnierkiewicz } 59e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 60e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz memset(&rqpm, 0, sizeof(rqpm)); 61e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 62e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rq->cmd_type = REQ_TYPE_PM_RESUME; 63e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rq->cmd_flags |= REQ_PREEMPT; 64fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo rq->special = &rqpm; 65e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rqpm.pm_step = IDE_PM_START_RESUME; 66e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rqpm.pm_state = PM_EVENT_ON; 67e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 68e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz err = blk_execute_rq(drive->queue, NULL, rq, 1); 69e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz blk_put_request(rq); 70e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 71e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (err == 0 && dev->driver) { 727f3c868ba78e486bd9d7569f884dd46d8f59bb18Bartlomiej Zolnierkiewicz struct ide_driver *drv = to_ide_driver(dev->driver); 73e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 74e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (drv->resume) 75e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz drv->resume(drive); 76e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz } 77e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 78e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz return err; 79e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz} 80e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 81e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewiczvoid ide_complete_power_step(ide_drive_t *drive, struct request *rq) 82e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz{ 83fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo struct request_pm_state *pm = rq->special; 84e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 85e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#ifdef DEBUG_PM 86e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz printk(KERN_INFO "%s: complete_power_step(step: %d)\n", 87e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz drive->name, pm->pm_step); 88e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#endif 89e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (drive->media != ide_disk) 90e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz return; 91e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 92e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz switch (pm->pm_step) { 93e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */ 94e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (pm->pm_state == PM_EVENT_FREEZE) 95e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step = IDE_PM_COMPLETED; 96e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz else 97e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step = IDE_PM_STANDBY; 98e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz break; 99e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_STANDBY: /* Suspend step 2 (standby) */ 100e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step = IDE_PM_COMPLETED; 101e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz break; 102e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */ 103e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step = IDE_PM_IDLE; 104e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz break; 105e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_IDLE: /* Resume step 2 (idle)*/ 106e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step = IDE_PM_RESTORE_DMA; 107e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz break; 108e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz } 109e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz} 110e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 111e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewiczide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq) 112e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz{ 113fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo struct request_pm_state *pm = rq->special; 114fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo struct ide_cmd cmd = { }; 115e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 116e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz switch (pm->pm_step) { 117e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */ 118e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (drive->media != ide_disk) 119e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz break; 120e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz /* Not supported? Switch to next step now. */ 121e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (ata_id_flush_enabled(drive->id) == 0 || 122e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) { 123e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz ide_complete_power_step(drive, rq); 124e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz return ide_stopped; 125e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz } 126e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (ata_id_flush_ext_enabled(drive->id)) 127fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo cmd.tf.command = ATA_CMD_FLUSH_EXT; 128e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz else 129fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo cmd.tf.command = ATA_CMD_FLUSH; 130e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz goto out_do_tf; 131e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_STANDBY: /* Suspend step 2 (standby) */ 132fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo cmd.tf.command = ATA_CMD_STANDBYNOW1; 133e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz goto out_do_tf; 134e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */ 135e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz ide_set_max_pio(drive); 136e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz /* 137e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * skip IDE_PM_IDLE for ATAPI devices 138e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz */ 139e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (drive->media != ide_disk) 140e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step = IDE_PM_RESTORE_DMA; 141e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz else 142e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz ide_complete_power_step(drive, rq); 143e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz return ide_stopped; 144e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_IDLE: /* Resume step 2 (idle) */ 145fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo cmd.tf.command = ATA_CMD_IDLEIMMEDIATE; 146e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz goto out_do_tf; 147e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */ 148e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz /* 149e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * Right now, all we do is call ide_set_dma(drive), 150e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * we could be smarter and check for current xfer_speed 151e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * in struct drive etc... 152e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz */ 153e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (drive->hwif->dma_ops == NULL) 154e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz break; 155e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz /* 156e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * TODO: respect IDE_DFLAG_USING_DMA 157e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz */ 158e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz ide_set_dma(drive); 159e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz break; 160e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz } 161e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 162e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step = IDE_PM_COMPLETED; 16322aa4b32a19b1f231d4ce7e9af6354b577a22a35Bartlomiej Zolnierkiewicz 164e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz return ide_stopped; 165e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 166e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewiczout_do_tf: 167fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; 168fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; 169fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo cmd.protocol = ATA_PROT_NODATA; 17022aa4b32a19b1f231d4ce7e9af6354b577a22a35Bartlomiej Zolnierkiewicz 171fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo return do_rw_taskfile(drive, &cmd); 172e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz} 173e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 174e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz/** 1753616b6536a74ff1c56029c17cbb3575c69c0a574Bartlomiej Zolnierkiewicz * ide_complete_pm_rq - end the current Power Management request 176e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * @drive: target drive 177e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * @rq: request 178e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * 179e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * This function cleans up the current PM request and stops the queue 180e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * if necessary. 181e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz */ 1823616b6536a74ff1c56029c17cbb3575c69c0a574Bartlomiej Zolnierkiewiczvoid ide_complete_pm_rq(ide_drive_t *drive, struct request *rq) 183e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz{ 184e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz struct request_queue *q = drive->queue; 185fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo struct request_pm_state *pm = rq->special; 186e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz unsigned long flags; 187e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 1883616b6536a74ff1c56029c17cbb3575c69c0a574Bartlomiej Zolnierkiewicz ide_complete_power_step(drive, rq); 1893616b6536a74ff1c56029c17cbb3575c69c0a574Bartlomiej Zolnierkiewicz if (pm->pm_step != IDE_PM_COMPLETED) 1903616b6536a74ff1c56029c17cbb3575c69c0a574Bartlomiej Zolnierkiewicz return; 1913616b6536a74ff1c56029c17cbb3575c69c0a574Bartlomiej Zolnierkiewicz 192e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#ifdef DEBUG_PM 193e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz printk("%s: completing PM request, %s\n", drive->name, 19433659ebbae262228eef4e0fe990f393d1f0ed941Christoph Hellwig (rq->cmd_type == REQ_TYPE_PM_SUSPEND) ? "suspend" : "resume"); 195e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#endif 196e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz spin_lock_irqsave(q->queue_lock, flags); 19733659ebbae262228eef4e0fe990f393d1f0ed941Christoph Hellwig if (rq->cmd_type == REQ_TYPE_PM_SUSPEND) 198e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz blk_stop_queue(q); 1992ea5521022ac8f4f528dcbae02668e02a3501a5aBartlomiej Zolnierkiewicz else 200e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz drive->dev_flags &= ~IDE_DFLAG_BLOCKED; 201e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz spin_unlock_irqrestore(q->queue_lock, flags); 202e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 203b65fac32cfe3b2f98cd472fef400bd1c1340de23Bartlomiej Zolnierkiewicz drive->hwif->rq = NULL; 204e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 205e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (blk_end_request(rq, 0, 0)) 206e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz BUG(); 207e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz} 208e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 209e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewiczvoid ide_check_pm_state(ide_drive_t *drive, struct request *rq) 210e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz{ 211fc38b521dcffcb07447cd98fedc56f495c10b90dTejun Heo struct request_pm_state *pm = rq->special; 212e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz 21333659ebbae262228eef4e0fe990f393d1f0ed941Christoph Hellwig if (rq->cmd_type == REQ_TYPE_PM_SUSPEND && 214e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step == IDE_PM_START_SUSPEND) 215e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz /* Mark drive blocked when starting the suspend sequence. */ 216e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz drive->dev_flags |= IDE_DFLAG_BLOCKED; 21733659ebbae262228eef4e0fe990f393d1f0ed941Christoph Hellwig else if (rq->cmd_type == REQ_TYPE_PM_RESUME && 218e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz pm->pm_step == IDE_PM_START_RESUME) { 219e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz /* 220e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * The first thing we do on wakeup is to wait for BSY bit to 221e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * go away (with a looong timeout) as a drive on this hwif may 222e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * just be POSTing itself. 223e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * We do that before even selecting as the "other" device on 224e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * the bus may be broken enough to walk on our toes at this 225e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz * point. 226e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz */ 227e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz ide_hwif_t *hwif = drive->hwif; 228fdd88f0af616db59a6a36bdf0185181d2b779f53Sergei Shtylyov const struct ide_tp_ops *tp_ops = hwif->tp_ops; 2292ea5521022ac8f4f528dcbae02668e02a3501a5aBartlomiej Zolnierkiewicz struct request_queue *q = drive->queue; 2302ea5521022ac8f4f528dcbae02668e02a3501a5aBartlomiej Zolnierkiewicz unsigned long flags; 231e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz int rc; 232e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#ifdef DEBUG_PM 233e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name); 234e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz#endif 235e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rc = ide_wait_not_busy(hwif, 35000); 236e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (rc) 237e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name); 238fdd88f0af616db59a6a36bdf0185181d2b779f53Sergei Shtylyov tp_ops->dev_select(drive); 239fdd88f0af616db59a6a36bdf0185181d2b779f53Sergei Shtylyov tp_ops->write_devctl(hwif, ATA_DEVCTL_OBS); 240e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz rc = ide_wait_not_busy(hwif, 100000); 241e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz if (rc) 242e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name); 2432ea5521022ac8f4f528dcbae02668e02a3501a5aBartlomiej Zolnierkiewicz 2442ea5521022ac8f4f528dcbae02668e02a3501a5aBartlomiej Zolnierkiewicz spin_lock_irqsave(q->queue_lock, flags); 2452ea5521022ac8f4f528dcbae02668e02a3501a5aBartlomiej Zolnierkiewicz blk_start_queue(q); 2462ea5521022ac8f4f528dcbae02668e02a3501a5aBartlomiej Zolnierkiewicz spin_unlock_irqrestore(q->queue_lock, flags); 247e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz } 248e2984c628c924442132304ae662da433f41c05c9Bartlomiej Zolnierkiewicz} 249