Alan Stern | db5bd1e | 2010-06-17 10:36:49 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * scsi_pm.c Copyright (C) 2010 Alan Stern |
| 3 | * |
| 4 | * SCSI dynamic Power Management |
| 5 | * Initial version: Alan Stern <stern@rowland.harvard.edu> |
| 6 | */ |
| 7 | |
| 8 | #include <linux/pm_runtime.h> |
| 9 | |
| 10 | #include <scsi/scsi.h> |
| 11 | #include <scsi/scsi_device.h> |
| 12 | #include <scsi/scsi_driver.h> |
| 13 | #include <scsi/scsi_host.h> |
| 14 | |
| 15 | #include "scsi_priv.h" |
| 16 | |
| 17 | static int scsi_dev_type_suspend(struct device *dev, pm_message_t msg) |
| 18 | { |
| 19 | struct device_driver *drv; |
| 20 | int err; |
| 21 | |
| 22 | err = scsi_device_quiesce(to_scsi_device(dev)); |
| 23 | if (err == 0) { |
| 24 | drv = dev->driver; |
| 25 | if (drv && drv->suspend) |
| 26 | err = drv->suspend(dev, msg); |
| 27 | } |
| 28 | dev_dbg(dev, "scsi suspend: %d\n", err); |
| 29 | return err; |
| 30 | } |
| 31 | |
| 32 | static int scsi_dev_type_resume(struct device *dev) |
| 33 | { |
| 34 | struct device_driver *drv; |
| 35 | int err = 0; |
| 36 | |
| 37 | drv = dev->driver; |
| 38 | if (drv && drv->resume) |
| 39 | err = drv->resume(dev); |
| 40 | scsi_device_resume(to_scsi_device(dev)); |
| 41 | dev_dbg(dev, "scsi resume: %d\n", err); |
| 42 | return err; |
| 43 | } |
| 44 | |
| 45 | #ifdef CONFIG_PM_SLEEP |
| 46 | |
| 47 | static int scsi_bus_suspend_common(struct device *dev, pm_message_t msg) |
| 48 | { |
| 49 | int err = 0; |
| 50 | |
| 51 | if (scsi_is_sdev_device(dev)) |
| 52 | err = scsi_dev_type_suspend(dev, msg); |
| 53 | return err; |
| 54 | } |
| 55 | |
| 56 | static int scsi_bus_resume_common(struct device *dev) |
| 57 | { |
| 58 | int err = 0; |
| 59 | |
| 60 | if (scsi_is_sdev_device(dev)) |
| 61 | err = scsi_dev_type_resume(dev); |
| 62 | return err; |
| 63 | } |
| 64 | |
| 65 | static int scsi_bus_suspend(struct device *dev) |
| 66 | { |
| 67 | return scsi_bus_suspend_common(dev, PMSG_SUSPEND); |
| 68 | } |
| 69 | |
| 70 | static int scsi_bus_freeze(struct device *dev) |
| 71 | { |
| 72 | return scsi_bus_suspend_common(dev, PMSG_FREEZE); |
| 73 | } |
| 74 | |
| 75 | static int scsi_bus_poweroff(struct device *dev) |
| 76 | { |
| 77 | return scsi_bus_suspend_common(dev, PMSG_HIBERNATE); |
| 78 | } |
| 79 | |
| 80 | #else /* CONFIG_PM_SLEEP */ |
| 81 | |
| 82 | #define scsi_bus_resume_common NULL |
| 83 | #define scsi_bus_suspend NULL |
| 84 | #define scsi_bus_freeze NULL |
| 85 | #define scsi_bus_poweroff NULL |
| 86 | |
| 87 | #endif /* CONFIG_PM_SLEEP */ |
| 88 | |
| 89 | const struct dev_pm_ops scsi_bus_pm_ops = { |
| 90 | .suspend = scsi_bus_suspend, |
| 91 | .resume = scsi_bus_resume_common, |
| 92 | .freeze = scsi_bus_freeze, |
| 93 | .thaw = scsi_bus_resume_common, |
| 94 | .poweroff = scsi_bus_poweroff, |
| 95 | .restore = scsi_bus_resume_common, |
| 96 | }; |