diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-01-17 08:11:06 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-01-17 08:11:06 -0500 |
commit | f33ce568366ab61b5685bae07306e40f17beb943 (patch) | |
tree | 12fa57fadb9b44e71639474d09a1807146c2fcbf /drivers/acpi/scan.c | |
parent | 993cbe595dda731471a07f4f65575fadedc570dc (diff) |
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: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/acpi/scan.c')
-rw-r--r-- | drivers/acpi/scan.c | 87 |
1 files changed, 46 insertions, 41 deletions
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c index e4ac46a9c664..10c98ff6b026 100644 --- a/drivers/acpi/scan.c +++ b/drivers/acpi/scan.c | |||
@@ -1041,6 +1041,50 @@ static void acpi_bus_get_wakeup_device_flags(struct acpi_device *device) | |||
1041 | "error in _DSW or _PSW evaluation\n")); | 1041 | "error in _DSW or _PSW evaluation\n")); |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | static void acpi_bus_init_power_state(struct acpi_device *device, int state) | ||
1045 | { | ||
1046 | struct acpi_device_power_state *ps = &device->power.states[state]; | ||
1047 | char object_name[5] = { '_', 'P', 'R', '0' + state, '\0' }; | ||
1048 | struct acpi_handle_list resources; | ||
1049 | acpi_handle handle; | ||
1050 | acpi_status status; | ||
1051 | |||
1052 | INIT_LIST_HEAD(&ps->resources); | ||
1053 | |||
1054 | /* Evaluate "_PRx" to se if power resources are referenced */ | ||
1055 | acpi_evaluate_reference(device->handle, object_name, NULL, &resources); | ||
1056 | if (resources.count) { | ||
1057 | int j; | ||
1058 | |||
1059 | device->power.flags.power_resources = 1; | ||
1060 | for (j = 0; j < resources.count; j++) { | ||
1061 | acpi_handle rhandle = resources.handles[j]; | ||
1062 | |||
1063 | acpi_add_power_resource(rhandle); | ||
1064 | acpi_power_resources_list_add(rhandle, &ps->resources); | ||
1065 | } | ||
1066 | } | ||
1067 | |||
1068 | /* Evaluate "_PSx" to see if we can do explicit sets */ | ||
1069 | object_name[2] = 'S'; | ||
1070 | status = acpi_get_handle(device->handle, object_name, &handle); | ||
1071 | if (ACPI_SUCCESS(status)) | ||
1072 | ps->flags.explicit_set = 1; | ||
1073 | |||
1074 | /* | ||
1075 | * State is valid if there are means to put the device into it. | ||
1076 | * D3hot is only valid if _PR3 present. | ||
1077 | */ | ||
1078 | if (resources.count | ||
1079 | || (ps->flags.explicit_set && state < ACPI_STATE_D3_HOT)) { | ||
1080 | ps->flags.valid = 1; | ||
1081 | ps->flags.os_accessible = 1; | ||
1082 | } | ||
1083 | |||
1084 | ps->power = -1; /* Unknown - driver assigned */ | ||
1085 | ps->latency = -1; /* Unknown - driver assigned */ | ||
1086 | } | ||
1087 | |||
1044 | static void acpi_bus_get_power_flags(struct acpi_device *device) | 1088 | static void acpi_bus_get_power_flags(struct acpi_device *device) |
1045 | { | 1089 | { |
1046 | acpi_status status = 0; | 1090 | acpi_status status = 0; |
@@ -1070,47 +1114,8 @@ static void acpi_bus_get_power_flags(struct acpi_device *device) | |||
1070 | /* | 1114 | /* |
1071 | * Enumerate supported power management states | 1115 | * Enumerate supported power management states |
1072 | */ | 1116 | */ |
1073 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) { | 1117 | for (i = ACPI_STATE_D0; i <= ACPI_STATE_D3_HOT; i++) |
1074 | struct acpi_device_power_state *ps = &device->power.states[i]; | 1118 | acpi_bus_init_power_state(device, i); |
1075 | char object_name[5] = { '_', 'P', 'R', '0' + i, '\0' }; | ||
1076 | struct acpi_handle_list resources; | ||
1077 | |||
1078 | INIT_LIST_HEAD(&ps->resources); | ||
1079 | /* Evaluate "_PRx" to se if power resources are referenced */ | ||
1080 | acpi_evaluate_reference(device->handle, object_name, NULL, | ||
1081 | &resources); | ||
1082 | if (resources.count) { | ||
1083 | int j; | ||
1084 | |||
1085 | device->power.flags.power_resources = 1; | ||
1086 | for (j = 0; j < resources.count; j++) { | ||
1087 | acpi_handle rhandle = resources.handles[j]; | ||
1088 | |||
1089 | acpi_add_power_resource(rhandle); | ||
1090 | acpi_power_resources_list_add(rhandle, | ||
1091 | &ps->resources); | ||
1092 | } | ||
1093 | } | ||
1094 | |||
1095 | /* Evaluate "_PSx" to see if we can do explicit sets */ | ||
1096 | object_name[2] = 'S'; | ||
1097 | status = acpi_get_handle(device->handle, object_name, &handle); | ||
1098 | if (ACPI_SUCCESS(status)) | ||
1099 | ps->flags.explicit_set = 1; | ||
1100 | |||
1101 | /* | ||
1102 | * State is valid if there are means to put the device into it. | ||
1103 | * D3hot is only valid if _PR3 present. | ||
1104 | */ | ||
1105 | if (resources.count || | ||
1106 | (ps->flags.explicit_set && i < ACPI_STATE_D3_HOT)) { | ||
1107 | ps->flags.valid = 1; | ||
1108 | ps->flags.os_accessible = 1; | ||
1109 | } | ||
1110 | |||
1111 | ps->power = -1; /* Unknown - driver assigned */ | ||
1112 | ps->latency = -1; /* Unknown - driver assigned */ | ||
1113 | } | ||
1114 | 1119 | ||
1115 | INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources); | 1120 | INIT_LIST_HEAD(&device->power.states[ACPI_STATE_D3_COLD].resources); |
1116 | 1121 | ||