Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 583c377f authored by David Brownell's avatar David Brownell Committed by Len Brown
Browse files

ACPI: acpi_pci_set_power_state() cleanups



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: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 39273b58
Loading
Loading
Loading
Loading
+16 −8
Original line number Original line Diff line number Diff line
@@ -272,21 +272,29 @@ static int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
{
{
	acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
	acpi_handle handle = DEVICE_ACPI_HANDLE(&dev->dev);
	acpi_handle tmp;
	acpi_handle tmp;
	static int state_conv[] = {
	static const u8 state_conv[] = {
		[0] = 0,
		[PCI_D0] = ACPI_STATE_D0,
		[1] = 1,
		[PCI_D1] = ACPI_STATE_D1,
		[2] = 2,
		[PCI_D2] = ACPI_STATE_D2,
		[3] = 3,
		[PCI_D3hot] = ACPI_STATE_D3,
		[4] = 3
		[PCI_D3cold] = ACPI_STATE_D3
	};
	};
	int acpi_state = state_conv[(int __force) state];


	if (!handle)
	if (!handle)
		return -ENODEV;
		return -ENODEV;
	/* If the ACPI device has _EJ0, ignore the device */
	/* If the ACPI device has _EJ0, ignore the device */
	if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
	if (ACPI_SUCCESS(acpi_get_handle(handle, "_EJ0", &tmp)))
		return 0;
		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;
}
}