public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
@ 2004-10-04 21:00 David Brownell
  2004-10-05 19:37 ` Pavel Machek
  0 siblings, 1 reply; 13+ messages in thread
From: David Brownell @ 2004-10-04 21:00 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 136 bytes --]

This lets drivers standardize how they present their ability to issue
wakeups, and how they manage whether that ability should be used.

[-- Attachment #2: wake-core.patch --]
[-- Type: text/x-diff, Size: 4495 bytes --]

This adds basic driver model and sysfs support for device wakeup
capabilities.

 - adds two driver model pmcore wakeup bits:
     * can_wakeup, initialized using device_init_wakeup() in bus
       or device driver code
     * should_wakeup, tested by device_may_wakeup() during device
       power state transitions

 - make that new state observable and manageable by letting sysfs
   change the should_wakeup policy by writing the "wakeup" attribute

This patch doesn't add callers or change existing wakeup code like:

 - USB (these bits replace two existing usb-internal bits)
 - PCI (can_wakeup coming from PCI PM capability)
 - ACPI (this should probably replace the new /proc/acpi/wakeup)
 - Ethtool should just set WOL policies
 - ... probably there are others.

Patches for the USB and PCI exist already.

[ against 2.6.9-rc3 ]


--- 1.4/drivers/base/power/sysfs.c	Wed Jun  9 23:34:24 2004
+++ edited/drivers/base/power/sysfs.c	Mon Oct  4 12:22:13 2004
@@ -48,8 +48,71 @@
 static DEVICE_ATTR(state, 0644, state_show, state_store);
 
 
+/*
+ *	wakeup - Report/change current wakeup option for device
+ *
+ *	Some devices support "wakeup" events, which are hardware signals
+ *	used to activate devices in suspended or low power states.  Such
+ *	devices have one of two wakeup options:  "enabled" to issue the
+ *	events, otherwise "disabled".  The value is effective at the next
+ *	state change.  (Other devices have no value for this option.)
+ *
+ *	Familiar examples of devices that can issue wakeup events include
+ *	keyboards and mice (both PS2 and USB styles), power buttons, clocks,
+ *	"Wake-On-LAN" Ethernet links, modems, and more.  Sometimes these
+ *	events will wake the system from a suspend state, but often they
+ *	just wake up a single device that's been selectively suspended.
+ *
+ *	It is the responsibility of device drivers to enable (or disable)
+ *	wakeup signaling as part of changing device suspend or power states,
+ *	respecting the policy choice provided through the driver model.
+ *
+ *	Devices may not be able to generate wakeup events from all power
+ *	states.  Also, the events may be ignored in some configurations;
+ *	for example, they might need help from other devices.  Some drivers
+ *	use wakeup events internally, keeping their hardware in a low power
+ *	mode most of the time (even without a system-wide suspend state),
+ *	unless wakeup is disabled.
+ */
+
+static const char enabled[] = "enabled";
+static const char disabled[] = "disabled";
+
+static ssize_t wake_show(struct device * dev, char * buf)
+{
+	return sprintf(buf, "%s\n", device_can_wakeup(dev)
+		? (device_may_wakeup(dev) ? enabled : disabled)
+		: "");
+}
+
+static ssize_t wake_store(struct device * dev, const char * buf, size_t n)
+{
+	char *cp;
+	int len = n;
+
+	if (!device_can_wakeup(dev))
+		return -EINVAL;
+
+	cp = memchr(buf, '\n', n);
+	if (cp)
+		len = cp - buf;
+	if (len == sizeof enabled - 1
+			&& strncmp(buf, enabled, sizeof enabled - 1) == 0)
+		device_set_wakeup_enable(dev, 1);
+	else if (len == sizeof disabled - 1
+			&& strncmp(buf, disabled, sizeof disabled - 1) == 0)
+		device_set_wakeup_enable(dev, 0);
+	else
+		return -EINVAL;
+	return n;
+}
+
+static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store);
+
+
 static struct attribute * power_attrs[] = {
 	&dev_attr_state.attr,
+	&dev_attr_wakeup.attr,
 	NULL,
 };
 static struct attribute_group pm_attr_group = {
--- 1.19/include/linux/pm.h	Thu Sep 30 11:23:17 2004
+++ edited/include/linux/pm.h	Mon Oct  4 12:22:13 2004
@@ -237,6 +237,8 @@
 	atomic_t		pm_users;
 	struct device		* pm_parent;
 	struct list_head	entry;
+	unsigned		can_wakeup:1;
+	unsigned		should_wakeup:1;
 #endif
 };
 
@@ -247,6 +249,23 @@
 extern void device_power_up(void);
 extern void device_resume(void);
 
+/* wakeup changes take effect on device's next pm state change */
+#ifdef CONFIG_PM
+#define device_init_wakeup(dev,val) \
+	((dev)->power.can_wakeup = ((dev)->power.should_wakeup = !!(val)))
+#define device_set_wakeup_enable(dev,val) \
+	((dev)->power.should_wakeup = (dev)->power.can_wakeup ? !!(val) : 0)
+#define device_can_wakeup(dev) \
+	((dev)->power.can_wakeup)
+#define device_may_wakeup(dev) \
+	(device_can_wakeup(dev) && (dev)->power.should_wakeup)
+
+#else /* !CONFIG_PM */
+#define device_init_wakeup(dev,val)		do()while(0)
+#define device_set_wakeup_enable(dev,val)	do()while(0)
+#define device_can_wakeup(dev)			(0)
+#define device_may_wakeup(dev)			(0)
+#endif
 
 #endif /* __KERNEL__ */
 

^ permalink raw reply	[flat|nested] 13+ messages in thread
* RE: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
@ 2004-10-19  9:11 Li, Shaohua
  2004-10-20  3:51 ` [ACPI] " Dmitry Torokhov
  0 siblings, 1 reply; 13+ messages in thread
From: Li, Shaohua @ 2004-10-19  9:11 UTC (permalink / raw)
  To: David Brownell, Brown, Len; +Cc: Pavel Machek, linux-kernel, ACPI Developers

A final solution is device core adds an ACPI layer. That is we can link
ACPI device and physical device. This way, the PCI device can know which
ACPI is linked with it, so the PCI API can use specific ACPI method. 
You are right, we currently haven't a method to reach the goal. To match
a physical device and ACPI device, we need to know the ACPI device's
_ADR and bus.
I have a toy to link the PCI device and ACPI device, and some PCI
function can use _SxD method and _PSx method to get some information for
suspend/resume.

Thanks,
Shaohua
>-----Original Message-----
>From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
>owner@vger.kernel.org] On Behalf Of David Brownell
>Sent: Tuesday, October 19, 2004 11:41 AM
>To: Brown, Len
>Cc: Pavel Machek; linux-kernel@vger.kernel.org; ACPI Developers
>Subject: Re: PATCH/RFC: driver model/pmcore wakeup hooks (1/4)
>
>On Friday 15 October 2004 11:03 pm, Len Brown wrote:
>> > - ACPI (this should probably replace the new /proc/acpi/wakeup)
>>
>> Agreed.  That file is a temporary solution.
>> The right solution is for the devices to appear in the right
>> place in the device tree and to hang the wakeup capabilities
>> off of them there.
>
>So what would that patch need before ACPI could convert to use it?
>
>I didn't notice any obvious associations between the strings in
>the acpi/wakeup file and anything in sysfs.  Which of USB1..USB4
>was which of the three controllers shown by "lspci" (and which
>one was "extra"!), as one head-scratcher.
>
>For PCI, I'd kind of expect pci_enable_wake() to trigger the
>additional ACPI-specific work to make sure the device can
>actually wake that system.   Seems like dev->platform_data
>might need to combine with some platform-specific API hook.
>
>- Dave
>-
>To unsubscribe from this list: send the line "unsubscribe linux-kernel"
in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html
>Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2004-10-21  1:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-04 21:00 PATCH/RFC: driver model/pmcore wakeup hooks (1/4) David Brownell
2004-10-05 19:37 ` Pavel Machek
2004-10-05 20:09   ` David Brownell
2004-10-05 20:15     ` Pavel Machek
2004-10-05 21:53       ` David Brownell
2004-10-16  6:03     ` Len Brown
2004-10-19  3:41       ` David Brownell
2004-10-19  4:55         ` [ACPI] " Hiroshi 2 Itoh
2004-10-19  5:18           ` David Brownell
2004-10-20  6:16         ` Len Brown
  -- strict thread matches above, loose matches on Subject: below --
2004-10-19  9:11 Li, Shaohua
2004-10-20  3:51 ` [ACPI] " Dmitry Torokhov
2004-10-20 17:02   ` David Brownell
2004-10-21  1:33     ` Li Shaohua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox