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

Commit f33ce568 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki
Browse files

ACPI / scan: Move power state initialization to a separate routine



To reduce indentation level and improve code readability, move the
initialization code related to device power states from
acpi_bus_get_power_flags() to a new routine,
acpi_bus_init_power_state().

Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 993cbe59
Loading
Loading
Loading
Loading
+46 −41
Original line number Original line Diff line number Diff line
@@ -1041,44 +1041,18 @@ static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device)
				"error in _DSW or _PSW evaluation\n"));
				"error in _DSW or _PSW evaluation\n"));
}
}


static void acpi_bus_get_power_flags(struct acpi_device *device)
static void acpi_bus_init_power_state(struct acpi_device *device, int state)
{
{
	acpi_status status = 0;
	struct acpi_device_power_state *ps = &device->power.states[state];
	acpi_handle handle = NULL;
	char object_name[5] = { '_', 'P', 'R', '0' + state, '\0' };
	u32 i = 0;

	/* Presence of _PS0|_PR0 indicates 'power manageable' */
	status = acpi_get_handle(device->handle, "_PS0", &handle);
	if (ACPI_FAILURE(status)) {
		status = acpi_get_handle(device->handle, "_PR0", &handle);
		if (ACPI_FAILURE(status))
			return;
	}

	device->flags.power_manageable = 1;

	/*
	 * Power Management Flags
	 */
	status = acpi_get_handle(device->handle, "_PSC", &handle);
	if (ACPI_SUCCESS(status))
		device->power.flags.explicit_get = 1;
	status = acpi_get_handle(device->handle, "_IRC", &handle);
	if (ACPI_SUCCESS(status))
		device->power.flags.inrush_current = 1;

	/*
	 * Enumerate supported power management states
	 */
	for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) {
		struct acpi_device_power_state *ps = &device->power.states[i];
		char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' };
	struct acpi_handle_list resources;
	struct acpi_handle_list resources;
	acpi_handle handle;
	acpi_status status;


	INIT_LIST_HEAD(&ps->resources);
	INIT_LIST_HEAD(&ps->resources);

	/* Evaluate "_PRx" to se if power resources are referenced */
	/* Evaluate "_PRx" to se if power resources are referenced */
		acpi_evaluate_reference(device->handle, object_name, NULL,
	acpi_evaluate_reference(device->handle, object_name, NULL, &resources);
					&resources);
	if (resources.count) {
	if (resources.count) {
		int j;
		int j;


@@ -1087,8 +1061,7 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
			acpi_handle rhandle = resources.handles[j];
			acpi_handle rhandle = resources.handles[j];


			acpi_add_power_resource(rhandle);
			acpi_add_power_resource(rhandle);
				acpi_power_resources_list_add(rhandle,
			acpi_power_resources_list_add(rhandle, &ps->resources);
							      &ps->resources);
		}
		}
	}
	}


@@ -1102,8 +1075,8 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
	 * State is valid if there are means to put the device into it.
	 * State is valid if there are means to put the device into it.
	 * D3hot is only valid if _PR3 present.
	 * D3hot is only valid if _PR3 present.
	 */
	 */
		if (resources.count ||
	if (resources.count
		    (ps->flags.explicit_set && i < ACPI_STATE_D3_HOT)) {
	    || (ps->flags.explicit_set && state < ACPI_STATE_D3_HOT)) {
		ps->flags.valid = 1;
		ps->flags.valid = 1;
		ps->flags.os_accessible = 1;
		ps->flags.os_accessible = 1;
	}
	}
@@ -1112,6 +1085,38 @@ static void acpi_bus_get_power_flags(struct acpi_device *device)
	ps->latency = -1;	/* Unknown - driver assigned */
	ps->latency = -1;	/* Unknown - driver assigned */
}
}


static void acpi_bus_get_power_flags(struct acpi_device *device)
{
	acpi_status status = 0;
	acpi_handle handle = NULL;
	u32 i = 0;

	/* Presence of _PS0|_PR0 indicates 'power manageable' */
	status = acpi_get_handle(device->handle, "_PS0", &handle);
	if (ACPI_FAILURE(status)) {
		status = acpi_get_handle(device->handle, "_PR0", &handle);
		if (ACPI_FAILURE(status))
			return;
	}

	device->flags.power_manageable = 1;

	/*
	 * Power Management Flags
	 */
	status = acpi_get_handle(device->handle, "_PSC", &handle);
	if (ACPI_SUCCESS(status))
		device->power.flags.explicit_get = 1;
	status = acpi_get_handle(device->handle, "_IRC", &handle);
	if (ACPI_SUCCESS(status))
		device->power.flags.inrush_current = 1;

	/*
	 * Enumerate supported power management states
	 */
	for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++)
		acpi_bus_init_power_state(device, i);

	INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);
	INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources);


	/* Set defaults for D0 and D3 states (always valid) */
	/* Set defaults for D0 and D3 states (always valid) */