public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 2.6.25-rc2-git] acpi_pci_set_power_state() cleanups
@ 2008-02-23  5:41 David Brownell
  2008-02-23  6:30 ` Len Brown
  0 siblings, 1 reply; 2+ messages in thread
From: David Brownell @ 2008-02-23  5:41 UTC (permalink / raw)
  To: linux-acpi; +Cc: linux-pm

Minor cleanups to acpi_pci_set_power_state():  use the ACPI and PCI
state symbols to make clear that a mapping is being done between PCI
and ACPI states, instead of using magic numbers.  For paranoia's sake,
report any errors.  Save five bytes (x86_64) too.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---
Extracted from the "teach ACPI how to use driver model wakeup flags"
patch series ... who knows, maybe that could be merged someday.

 drivers/pci/pci-acpi.c |   24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

--- g26.orig/drivers/pci/pci-acpi.c	2008-02-22 19:26:58.000000000 -0800
+++ g26/drivers/pci/pci-acpi.c	2008-02-22 20:37:14.000000000 -0800
@@ -272,21 +272,29 @@ static int acpi_pci_set_power_state(stru
 {
 	acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
 	acpi_handle tmp;
-	static int state_conv[] = {
-		[0] = 0,
-		[1] = 1,
-		[2] = 2,
-		[3] = 3,
-		[4] = 3
+	static const u8 state_conv[] = {
+		[PCI_D0] = ACPI_STATE_D0,
+		[PCI_D1] = ACPI_STATE_D1,
+		[PCI_D2] = ACPI_STATE_D2,
+		[PCI_D3hot] = ACPI_STATE_D3,
+		[PCI_D3cold] = ACPI_STATE_D3
 	};
-	int acpi_state = state_conv[(int __force) state];
 
 	if (!handle)
 		return -ENODEV;
 	/* If the ACPI device has _EJ0, ignore the device */
 	if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
 		return 0;
-	return acpi_bus_set_power(handle, acpi_state);
+
+	switch (state) {
+	case PCI_D0:
+	case PCI_D1:
+	case PCI_D2:
+	case PCI_D3hot:
+	case PCI_D3cold:
+		return acpi_bus_set_power(handle, state_conv[state]);
+	}
+	return -EINVAL;
 }
 
 

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

* Re: [patch 2.6.25-rc2-git] acpi_pci_set_power_state() cleanups
  2008-02-23  5:41 [patch 2.6.25-rc2-git] acpi_pci_set_power_state() cleanups David Brownell
@ 2008-02-23  6:30 ` Len Brown
  0 siblings, 0 replies; 2+ messages in thread
From: Len Brown @ 2008-02-23  6:30 UTC (permalink / raw)
  To: David Brownell; +Cc: linux-acpi, linux-pm

applied.

thanks,
-len

On Saturday 23 February 2008 00:41, David Brownell wrote:
> Minor cleanups to acpi_pci_set_power_state():  use the ACPI and PCI
> state symbols to make clear that a mapping is being done between PCI
> and ACPI states, instead of using magic numbers.  For paranoia's sake,
> report any errors.  Save five bytes (x86_64) too.
> 
> Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
> ---
> Extracted from the "teach ACPI how to use driver model wakeup flags"
> patch series ... who knows, maybe that could be merged someday.
> 
>  drivers/pci/pci-acpi.c |   24 ++++++++++++++++--------
>  1 file changed, 16 insertions(+), 8 deletions(-)
> 
> --- g26.orig/drivers/pci/pci-acpi.c	2008-02-22 19:26:58.000000000 -0800
> +++ g26/drivers/pci/pci-acpi.c	2008-02-22 20:37:14.000000000 -0800
> @@ -272,21 +272,29 @@ static int acpi_pci_set_power_state(stru
>  {
>  	acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
>  	acpi_handle tmp;
> -	static int state_conv[] = {
> -		[0] = 0,
> -		[1] = 1,
> -		[2] = 2,
> -		[3] = 3,
> -		[4] = 3
> +	static const u8 state_conv[] = {
> +		[PCI_D0] = ACPI_STATE_D0,
> +		[PCI_D1] = ACPI_STATE_D1,
> +		[PCI_D2] = ACPI_STATE_D2,
> +		[PCI_D3hot] = ACPI_STATE_D3,
> +		[PCI_D3cold] = ACPI_STATE_D3
>  	};
> -	int acpi_state = state_conv[(int __force) state];
>  
>  	if (!handle)
>  		return -ENODEV;
>  	/* If the ACPI device has _EJ0, ignore the device */
>  	if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
>  		return 0;
> -	return acpi_bus_set_power(handle, acpi_state);
> +
> +	switch (state) {
> +	case PCI_D0:
> +	case PCI_D1:
> +	case PCI_D2:
> +	case PCI_D3hot:
> +	case PCI_D3cold:
> +		return acpi_bus_set_power(handle, state_conv[state]);
> +	}
> +	return -EINVAL;
>  }
>  
>  
> -
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

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

end of thread, other threads:[~2008-02-23  6:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-23  5:41 [patch 2.6.25-rc2-git] acpi_pci_set_power_state() cleanups David Brownell
2008-02-23  6:30 ` Len Brown

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