All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] acpi choose sleep state help
@ 2007-06-19  2:33 Shaohua Li
  2007-06-19 11:52 ` Rafael J. Wysocki
  0 siblings, 1 reply; 111+ messages in thread
From: Shaohua Li @ 2007-06-19  2:33 UTC (permalink / raw)
  To: linux acpi; +Cc: Len Brown, dbrownell

Based on David's patch
http://marc.info/?l=linux-acpi&m=117873972806360&w=2
I slightly changed it.

Add a helper routine, which gets the sleep state of a ACPI device.

Index: 2.6.22-rc2/drivers/acpi/sleep/main.c
===================================================================
--- 2.6.22-rc2.orig/drivers/acpi/sleep/main.c	2007-05-23 09:15:14.000000000 +0800
+++ 2.6.22-rc2/drivers/acpi/sleep/main.c	2007-06-19 09:19:09.000000000 +0800
@@ -34,6 +34,8 @@ static u32 acpi_suspend_states[] = {
 
 static int init_8259A_after_S1;
 
+static int acpi_target_sleep_state = ACPI_STATE_S0;
+
 /**
  *	acpi_pm_prepare - Do preliminary suspend work.
  *	@pm_state:		suspend state we're entering.
@@ -54,6 +56,7 @@ static int acpi_pm_prepare(suspend_state
 		printk("acpi_pm_prepare does not support %d \n", pm_state);
 		return -EPERM;
 	}
+	acpi_target_sleep_state = acpi_state;
 	return acpi_sleep_prepare(acpi_state);
 }
 
@@ -140,6 +143,7 @@ static int acpi_pm_finish(suspend_state_
 		printk("Broken toshiba laptop -> kicking interrupts\n");
 		init_8259A(0);
 	}
+	acpi_target_sleep_state = ACPI_STATE_S0;
 	return 0;
 }
 
@@ -184,6 +188,7 @@ static struct pm_ops acpi_pm_ops = {
 #ifdef CONFIG_SOFTWARE_SUSPEND
 static int acpi_hibernation_prepare(void)
 {
+	acpi_target_sleep_state = ACPI_STATE_S4;
 	return acpi_sleep_prepare(ACPI_STATE_S4);
 }
 
@@ -215,6 +220,7 @@ static void acpi_hibernation_finish(void
 		printk("Broken toshiba laptop -> kicking interrupts\n");
 		init_8259A(0);
 	}
+	acpi_target_sleep_state = ACPI_STATE_S0;
 }
 
 static struct hibernation_ops acpi_hibernation_ops = {
@@ -224,6 +230,49 @@ static struct hibernation_ops acpi_hiber
 };
 #endif				/* CONFIG_SOFTWARE_SUSPEND */
 
+int acpi_pm_choose_sleep_state(acpi_handle handle, pm_message_t state)
+{
+	char sxd[] = "_SxD";
+	unsigned long d_min, d_max;
+	struct acpi_device *dev;
+
+	/*
+	 * If the sleep state is S0, we will return D3, but if the device has
+	 * _S0W, we will use the value from _S0W
+	 */
+	d_min = ACPI_STATE_D3;
+	d_max = ACPI_STATE_D3;
+
+	/* If present, _SxD methods give the minimum D-state we may use
+	 * for each S-state ... with lowest latency state switching.
+	 *
+	 * We rely on acpi_evaluate_integer() not clobbering the integer
+	 * provided -- that's our fault recovery, we ignore retval.
+	 */
+	sxd[2] = '0' + acpi_target_sleep_state;
+	if (acpi_target_sleep_state > ACPI_STATE_S0)
+		acpi_evaluate_integer(handle, sxd, NULL, &d_min);
+
+	/*
+	 * If _PRW says we can wake from the upcoming system state, the _SxD
+	 * value can wake ... and we'll assume a wakeup-aware driver.  If _SxW
+	 * methods exist (ACPI 3.x), they give the lowest power D-state that
+	 * can also wake the system.  _S0W can be valid.
+	 */
+	if (acpi_bus_get_device(handle, &dev)) {
+		printk(KERN_ERR"ACPI handle hasn't context\n");
+		return d_max;
+	}
+	if (acpi_target_sleep_state == ACPI_STATE_S0 ||
+	    (dev->wakeup.state.enabled &&
+	     dev->wakeup.sleep_state <= acpi_target_sleep_state)) {
+		sxd[3] = 'W';
+		acpi_evaluate_integer(handle, sxd, NULL, &d_max);
+	}
+	/* choose a state within d_min to d_max, we just choose the max */
+	return d_max;
+}
+
 /*
  * Toshiba fails to preserve interrupts over S1, reinitialization
  * of 8259 is needed after S1 resume.
Index: 2.6.22-rc2/include/acpi/acpi_bus.h
===================================================================
--- 2.6.22-rc2.orig/include/acpi/acpi_bus.h	2007-05-23 09:15:14.000000000 +0800
+++ 2.6.22-rc2/include/acpi/acpi_bus.h	2007-06-19 09:23:54.000000000 +0800
@@ -364,6 +364,8 @@ acpi_handle acpi_get_child(acpi_handle, 
 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int, unsigned int);
 #define DEVICE_ACPI_HANDLE(dev) ((acpi_handle)((dev)->archdata.acpi_handle))
 
+int acpi_pm_choose_sleep_state(acpi_handle handle, pm_message_t state);
+
 #endif				/* CONFIG_ACPI */
 
 #endif /*__ACPI_BUS_H__*/

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

end of thread, other threads:[~2007-06-25 23:04 UTC | newest]

Thread overview: 111+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-19  2:33 [PATCH 1/2] acpi choose sleep state help Shaohua Li
2007-06-19 11:52 ` Rafael J. Wysocki
2007-06-19 22:00   ` Rafael J. Wysocki
2007-06-20  6:18   ` Shaohua Li
2007-06-20 11:32     ` [RFD] How to tell ACPI drivers what the target sleep state is (was: Re: [PATCH 1/2] acpi choose sleep state help) Rafael J. Wysocki
2007-06-20 11:32     ` Rafael J. Wysocki
2007-06-20 14:08       ` Alan Stern
2007-06-20 14:08       ` [linux-pm] " Alan Stern
2007-06-20 14:36         ` Rafael J. Wysocki
2007-06-20 14:36         ` [linux-pm] " Rafael J. Wysocki
2007-06-21  6:57         ` David Brownell
2007-06-21  1:51       ` Len Brown
2007-06-21  1:51       ` Len Brown
2007-06-21  7:10         ` David Brownell
2007-06-21  7:04       ` David Brownell
2007-06-21 12:42         ` Rafael J. Wysocki
2007-06-21 13:03           ` Pavel Machek
2007-06-21 14:46             ` Rafael J. Wysocki
2007-06-21 15:23               ` Alan Stern
2007-06-21 15:23               ` [linux-pm] " Alan Stern
2007-06-21 19:41                 ` Rafael J. Wysocki
2007-06-21 19:41                 ` [linux-pm] " Rafael J. Wysocki
2007-06-21 16:35               ` David Brownell
2007-06-21 16:35               ` David Brownell
2007-06-21 19:42                 ` Rafael J. Wysocki
2007-06-21 19:42                 ` Rafael J. Wysocki
2007-06-21 14:46             ` Rafael J. Wysocki
2007-06-21 15:37             ` David Brownell
2007-06-21 15:37             ` David Brownell
2007-06-21 18:59               ` Pavel Machek
2007-06-21 18:59               ` [linux-pm] " Pavel Machek
2007-06-21 20:03                 ` David Brownell
2007-06-21 20:37                   ` Rafael J. Wysocki
2007-06-21 20:37                   ` [linux-pm] " Rafael J. Wysocki
2007-06-21 20:03                 ` David Brownell
2007-06-21 19:52               ` Rafael J. Wysocki
2007-06-21 19:52               ` Rafael J. Wysocki
2007-06-21 13:03           ` Pavel Machek
2007-06-21 14:48           ` David Brownell
2007-06-21 14:48           ` David Brownell
2007-06-21 20:04             ` Rafael J. Wysocki
2007-06-21 20:22               ` David Brownell
2007-06-21 20:22               ` David Brownell
2007-06-21 20:41                 ` Rafael J. Wysocki
2007-06-21 20:41                 ` Rafael J. Wysocki
2007-06-21 20:04             ` Rafael J. Wysocki
2007-06-21 12:42         ` Rafael J. Wysocki
2007-06-21 15:56         ` Alan Stern
2007-06-21 16:35           ` David Brownell
2007-06-21 16:35           ` [linux-pm] " David Brownell
2007-06-21 17:11             ` Alan Stern
2007-06-21 18:02               ` David Brownell
2007-06-21 18:51                 ` Alan Stern
2007-06-21 18:51                 ` [linux-pm] " Alan Stern
2007-06-21 19:51                   ` David Brownell
2007-06-21 19:51                   ` [linux-pm] " David Brownell
2007-06-21 20:35                     ` Rafael J. Wysocki
2007-06-21 20:35                     ` [linux-pm] " Rafael J. Wysocki
2007-06-21 20:46                       ` David Brownell
2007-06-21 20:46                       ` [linux-pm] " David Brownell
2007-06-21 21:02                         ` Rafael J. Wysocki
2007-06-21 21:02                         ` [linux-pm] " Rafael J. Wysocki
2007-06-21 21:04                           ` Alan Stern
2007-06-23 22:00                             ` [RFC][PATCH -mm] PM: Introduce set_target method in pm_ops Rafael J. Wysocki
2007-06-23 23:46                               ` Alan Stern
2007-06-24  0:03                                 ` Rafael J. Wysocki
2007-06-24  0:28                                   ` Alan Stern
2007-06-24  0:28                                   ` Alan Stern
2007-06-24  9:52                                     ` [linux-pm] " Johannes Berg
2007-06-24  9:52                                     ` Johannes Berg
2007-06-24 11:49                                     ` [linux-pm] " Igor Stoppa
2007-06-24 13:04                                       ` Rafael J. Wysocki
2007-06-24 13:04                                       ` [linux-pm] " Rafael J. Wysocki
2007-06-24 11:49                                     ` Igor Stoppa
2007-06-24 12:57                                     ` Rafael J. Wysocki
2007-06-24 12:57                                     ` Rafael J. Wysocki
2007-06-25  0:01                                       ` David Brownell
2007-06-25 22:14                                         ` Rafael J. Wysocki
2007-06-25 22:14                                         ` Rafael J. Wysocki
2007-06-25  0:01                                       ` David Brownell
2007-06-25 13:04                                   ` Pavel Machek
2007-06-25 13:04                                   ` Pavel Machek
2007-06-25 13:57                                     ` Dmitry Krivoschekov
2007-06-25 13:57                                     ` [linux-pm] " Dmitry Krivoschekov
2007-06-25 19:28                                       ` Pavel Machek
2007-06-25 22:16                                         ` Rafael J. Wysocki
2007-06-25 22:16                                         ` Rafael J. Wysocki
2007-06-25 19:28                                       ` Pavel Machek
2007-06-24  0:03                                 ` Rafael J. Wysocki
2007-06-23 23:46                               ` Alan Stern
2007-06-23 22:00                             ` Rafael J. Wysocki
2007-06-21 21:04                           ` Re: [RFD] How to tell ACPI drivers what the target sleep state is (was: Re: [PATCH 1/2] acpi choose sleep state help) Alan Stern
2007-06-21 21:00                     ` Platform-specific system power states Alan Stern
2007-06-22 19:49                       ` David Brownell
2007-06-22 21:30                         ` Rafael J. Wysocki
2007-06-23  1:32                           ` Alan Stern
2007-06-23 20:20                             ` Rafael J. Wysocki
2007-06-25  0:10                               ` David Brownell
2007-06-25 22:59                                 ` Rafael J. Wysocki
2007-06-25  0:26                           ` David Brownell
2007-06-25 23:04                             ` Rafael J. Wysocki
2007-06-21 20:19                   ` [linux-pm] Re: [RFD] How to tell ACPI drivers what the target sleep state is (was: Re: [PATCH 1/2] acpi choose sleep state help) Rafael J. Wysocki
2007-06-21 20:32                     ` David Brownell
2007-06-21 20:32                     ` [linux-pm] " David Brownell
2007-06-21 20:50                       ` Rafael J. Wysocki
2007-06-21 20:50                       ` [linux-pm] " Rafael J. Wysocki
2007-06-21 20:19                   ` Rafael J. Wysocki
2007-06-21 18:02               ` David Brownell
2007-06-21 17:11             ` Alan Stern
2007-06-20 11:32     ` Rafael J. Wysocki
2007-06-21  7:14     ` [PATCH 1/2] acpi choose sleep state help David Brownell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.