From: Dmitry Torokhov <dtor@insightbb.com>
To: Greg KH <gregkh@suse.de>
Cc: Kay Sievers <kay.sievers@vrfy.org>, linux-kernel@vger.kernel.org
Subject: [PATCH] Driver core: add suspend() and resume() to struct device_type
Date: Tue, 3 Apr 2007 01:08:40 -0400 [thread overview]
Message-ID: <200704030108.40947.dtor@insightbb.com> (raw)
Hi Greg,
Here is another patch extending struct device_type. I need it to
implement generic suspend/resume routines for input devices.
As you may remember input core devices and interface devices are
mixed in the same class and because suspend/resume only applies
to core devices so I can't define these methods on class level.
--
Dmitry
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: Dmitry Torokhov <dtor@mail.ru>
---
drivers/base/power/resume.c | 13 ++++++++++++-
drivers/base/power/suspend.c | 12 ++++++++++++
include/linux/device.h | 2 ++
3 files changed, 26 insertions(+), 1 deletion(-)
Index: work/drivers/base/power/resume.c
===================================================================
--- work.orig/drivers/base/power/resume.c
+++ work/drivers/base/power/resume.c
@@ -26,7 +26,9 @@ int resume_device(struct device * dev)
TRACE_DEVICE(dev);
TRACE_RESUME(0);
+
down(&dev->sem);
+
if (dev->power.pm_parent
&& dev->power.pm_parent->power.power_state.event) {
dev_err(dev, "PM: resume from %d, parent %s still %d\n",
@@ -34,15 +36,24 @@ int resume_device(struct device * dev)
dev->power.pm_parent->bus_id,
dev->power.pm_parent->power.power_state.event);
}
+
if (dev->bus && dev->bus->resume) {
dev_dbg(dev,"resuming\n");
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");
error = dev->class->resume(dev);
}
+
up(&dev->sem);
+
TRACE_RESUME(error);
return error;
}
Index: work/drivers/base/power/suspend.c
===================================================================
--- work.orig/drivers/base/power/suspend.c
+++ work/drivers/base/power/suspend.c
@@ -78,6 +78,18 @@ int suspend_device(struct device * dev,
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) {
dev_dbg(dev, "%s%s\n",
suspend_verb(state.event),
Index: work/include/linux/device.h
===================================================================
--- work.orig/include/linux/device.h
+++ work/include/linux/device.h
@@ -332,6 +332,8 @@ struct device_type {
int (*uevent)(struct device *dev, char **envp, int num_envp,
char *buffer, int buffer_size);
void (*release)(struct device *dev);
+ int (*suspend)(struct device * dev, pm_message_t state);
+ int (*resume)(struct device * dev);
};
/* interface for exporting device attributes */
reply other threads:[~2007-04-03 5:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200704030108.40947.dtor@insightbb.com \
--to=dtor@insightbb.com \
--cc=gregkh@suse.de \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox