@@ -2845,18 +2845,18 @@ static void sd_shutdown(struct device *dev)
if (!sdkp)
return; /* this can happen */
- if (pm_runtime_suspended(dev))
+ if (pm_runtime_suspended(dev)
+ && (sdkp->device->manage_start_stop || sdkp->device->powered_off))
goto exit;
+ scsi_autopm_get_device(sdkp->device);
+
if (sdkp->WCE) {
sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
sd_sync_cache(sdkp);
}
- if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) {
- sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
- sd_start_stop_device(sdkp, 0);
- }
+ scsi_autopm_put_device(sdkp->device);
exit:
scsi_disk_put(sdkp);
@@ -2870,16 +2870,18 @@ static int sd_suspend(struct device *dev, pm_message_t mesg)
if (!sdkp)
return 0; /* this can happen */
- if (sdkp->WCE) {
- sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
- ret = sd_sync_cache(sdkp);
- if (ret)
- goto done;
- }
-
- if ((mesg.event & PM_EVENT_SLEEP) && sdkp->device->manage_start_stop) {
+ if (sdkp->device->manage_start_stop) {
sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
ret = sd_start_stop_device(sdkp, 0);
+ goto done;
+ }
+
+ if (sdkp->WCE) {
+ if ((PMSG_IS_AUTO(mesg) && sdkp->device->may_power_off) ||
+ (mesg.event & PM_EVENT_SLEEP)) {
+ sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
+ ret = sd_sync_cache(sdkp);
+ }
}
done: