Commit f89cbc39 authored by Dmitry Torokhov's avatar Dmitry Torokhov Committed by Greg Kroah-Hartman

Driver core: add suspend() and resume() to struct device_type

Driver core: add suspend() and resume() to struct device_type

In cases when there are devices of different types in the same class
we can't use class's implementation of suspend and resume methods and
we need to add them to struct device_type instead.

Also fix error handling in resume code (we should not try to call
class's resume method iof bus's resume method for the device failed.
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent bf62456e
...@@ -26,7 +26,9 @@ int resume_device(struct device * dev) ...@@ -26,7 +26,9 @@ int resume_device(struct device * dev)
TRACE_DEVICE(dev); TRACE_DEVICE(dev);
TRACE_RESUME(0); TRACE_RESUME(0);
down(&dev->sem); down(&dev->sem);
if (dev->power.pm_parent if (dev->power.pm_parent
&& dev->power.pm_parent->power.power_state.event) { && dev->power.pm_parent->power.power_state.event) {
dev_err(dev, "PM: resume from %d, parent %s still %d\n", dev_err(dev, "PM: resume from %d, parent %s still %d\n",
...@@ -34,15 +36,24 @@ int resume_device(struct device * dev) ...@@ -34,15 +36,24 @@ int resume_device(struct device * dev)
dev->power.pm_parent->bus_id, dev->power.pm_parent->bus_id,
dev->power.pm_parent->power.power_state.event); dev->power.pm_parent->power.power_state.event);
} }
if (dev->bus && dev->bus->resume) { if (dev->bus && dev->bus->resume) {
dev_dbg(dev,"resuming\n"); dev_dbg(dev,"resuming\n");
error = dev->bus->resume(dev); error = dev->bus->resume(dev);
} }
if (dev->class && dev->class->resume) {
if (!error && dev->type && dev->type->resume) {
dev_dbg(dev,"resuming\n");
error = dev->type->resume(dev);
}
if (!error && dev->class && dev->class->resume) {
dev_dbg(dev,"class resume\n"); dev_dbg(dev,"class resume\n");
error = dev->class->resume(dev); error = dev->class->resume(dev);
} }
up(&dev->sem); up(&dev->sem);
TRACE_RESUME(error); TRACE_RESUME(error);
return error; return error;
} }
......
...@@ -78,6 +78,18 @@ int suspend_device(struct device * dev, pm_message_t state) ...@@ -78,6 +78,18 @@ int suspend_device(struct device * dev, pm_message_t state)
suspend_report_result(dev->class->suspend, error); suspend_report_result(dev->class->suspend, error);
} }
if (!error && dev->type && dev->type->suspend && !dev->power.power_state.event) {
dev_dbg(dev, "%s%s\n",
suspend_verb(state.event),
((state.event == PM_EVENT_SUSPEND)
&& device_may_wakeup(dev))
? ", may wakeup"
: ""
);
error = dev->type->suspend(dev, state);
suspend_report_result(dev->type->suspend, error);
}
if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) { if (!error && dev->bus && dev->bus->suspend && !dev->power.power_state.event) {
dev_dbg(dev, "%s%s\n", dev_dbg(dev, "%s%s\n",
suspend_verb(state.event), suspend_verb(state.event),
......
...@@ -344,6 +344,8 @@ struct device_type { ...@@ -344,6 +344,8 @@ struct device_type {
int (*uevent)(struct device *dev, char **envp, int num_envp, int (*uevent)(struct device *dev, char **envp, int num_envp,
char *buffer, int buffer_size); char *buffer, int buffer_size);
void (*release)(struct device *dev); void (*release)(struct device *dev);
int (*suspend)(struct device * dev, pm_message_t state);
int (*resume)(struct device * dev);
}; };
/* interface for exporting device attributes */ /* interface for exporting device attributes */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment