Skip to content

Commit 40e7fcb

Browse files
Lan Tianyurafaeljw
authored andcommitted
ACPI: Add _DEP support to fix battery issue on Asus T100TA
ACPI 5.0 introduces _DEP (Operation Region Dependencies) to designate device objects that OSPM should assign a higher priority in start ordering due to future operation region accesses. On Asus T100TA, ACPI battery info are read from a I2C slave device via I2C operation region. Before I2C operation region handler is installed, battery _STA always returns 0. There is a _DEP method of designating start order under battery device node. This patch is to implement _DEP feature to fix battery issue on the Asus T100TA. Introducing acpi_dep_list and adding dep_unmet count in struct acpi_device. During ACPI namespace scan, create struct acpi_dep_data for a valid pair of master (device pointed to by _DEP)/ slave(device with _DEP), record master's and slave's ACPI handle in it and put it into acpi_dep_list. The dep_unmet count will increase by one if there is a device under its _DEP. Driver's probe() should return EPROBE_DEFER when find dep_unmet is larger than 0. When I2C operation region handler is installed, remove all struct acpi_dep_data on the acpi_dep_list whose master is pointed to I2C host controller and decrease slave's dep_unmet. When dep_unmet decreases to 0, all _DEP conditions are met and then do acpi_bus_attach() for the device in order to resolve battery _STA issue on the Asus T100TA. Link: https://bugzilla.kernel.org/show_bug.cgi?id=69011 Tested-by: Jan-Michael Brummer <jan.brummer@tabos.org> Tested-by: Adam Williamson <adamw@happyassassin.net> Tested-by: Michael Shigorin <shigorin@gmail.com> Acked-by: Wolfram Sang <wsa@the-dreams.de> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 5d01410 commit 40e7fcb

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

drivers/acpi/battery.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,10 @@ static int acpi_battery_add(struct acpi_device *device)
11801180

11811181
if (!device)
11821182
return -EINVAL;
1183+
1184+
if (device->dep_unmet)
1185+
return -EPROBE_DEFER;
1186+
11831187
battery = kzalloc(sizeof(struct acpi_battery), GFP_KERNEL);
11841188
if (!battery)
11851189
return -ENOMEM;

drivers/acpi/scan.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@ bool acpi_force_hot_remove;
3636

3737
static const char *dummy_hid = "device";
3838

39+
static LIST_HEAD(acpi_dep_list);
40+
static DEFINE_MUTEX(acpi_dep_list_lock);
3941
static LIST_HEAD(acpi_bus_id_list);
4042
static DEFINE_MUTEX(acpi_scan_lock);
4143
static LIST_HEAD(acpi_scan_handlers_list);
4244
DEFINE_MUTEX(acpi_device_lock);
4345
LIST_HEAD(acpi_wakeup_device_list);
4446
static DEFINE_MUTEX(acpi_hp_context_lock);
4547

48+
struct acpi_dep_data {
49+
struct list_head node;
50+
acpi_handle master;
51+
acpi_handle slave;
52+
};
53+
4654
struct acpi_device_bus_id{
4755
char bus_id[15];
4856
unsigned int instance_no;
@@ -2086,6 +2094,59 @@ static void acpi_scan_init_hotplug(struct acpi_device *adev)
20862094
}
20872095
}
20882096

2097+
static void acpi_device_dep_initialize(struct acpi_device *adev)
2098+
{
2099+
struct acpi_dep_data *dep;
2100+
struct acpi_handle_list dep_devices;
2101+
acpi_status status;
2102+
int i;
2103+
2104+
if (!acpi_has_method(adev->handle, "_DEP"))
2105+
return;
2106+
2107+
status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
2108+
&dep_devices);
2109+
if (ACPI_FAILURE(status)) {
2110+
dev_err(&adev->dev, "Failed to evaluate _DEP.\n");
2111+
return;
2112+
}
2113+
2114+
for (i = 0; i < dep_devices.count; i++) {
2115+
struct acpi_device_info *info;
2116+
int skip;
2117+
2118+
status = acpi_get_object_info(dep_devices.handles[i], &info);
2119+
if (ACPI_FAILURE(status)) {
2120+
dev_err(&adev->dev, "Error reading device info\n");
2121+
continue;
2122+
}
2123+
2124+
/*
2125+
* Skip the dependency of Windows System Power
2126+
* Management Controller
2127+
*/
2128+
skip = info->valid & ACPI_VALID_HID &&
2129+
!strcmp(info->hardware_id.string, "INT3396");
2130+
2131+
kfree(info);
2132+
2133+
if (skip)
2134+
continue;
2135+
2136+
dep = kzalloc(sizeof(struct acpi_dep_data), GFP_KERNEL);
2137+
if (!dep)
2138+
return;
2139+
2140+
dep->master = dep_devices.handles[i];
2141+
dep->slave = adev->handle;
2142+
adev->dep_unmet++;
2143+
2144+
mutex_lock(&acpi_dep_list_lock);
2145+
list_add_tail(&dep->node , &acpi_dep_list);
2146+
mutex_unlock(&acpi_dep_list_lock);
2147+
}
2148+
}
2149+
20892150
static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
20902151
void *not_used, void **return_value)
20912152
{
@@ -2112,6 +2173,7 @@ static acpi_status acpi_bus_check_add(acpi_handle handle, u32 lvl_not_used,
21122173
return AE_CTRL_DEPTH;
21132174

21142175
acpi_scan_init_hotplug(device);
2176+
acpi_device_dep_initialize(device);
21152177

21162178
out:
21172179
if (!*return_value)
@@ -2232,6 +2294,29 @@ static void acpi_bus_attach(struct acpi_device *device)
22322294
device->handler->hotplug.notify_online(device);
22332295
}
22342296

2297+
void acpi_walk_dep_device_list(acpi_handle handle)
2298+
{
2299+
struct acpi_dep_data *dep, *tmp;
2300+
struct acpi_device *adev;
2301+
2302+
mutex_lock(&acpi_dep_list_lock);
2303+
list_for_each_entry_safe(dep, tmp, &acpi_dep_list, node) {
2304+
if (dep->master == handle) {
2305+
acpi_bus_get_device(dep->slave, &adev);
2306+
if (!adev)
2307+
continue;
2308+
2309+
adev->dep_unmet--;
2310+
if (!adev->dep_unmet)
2311+
acpi_bus_attach(adev);
2312+
list_del(&dep->node);
2313+
kfree(dep);
2314+
}
2315+
}
2316+
mutex_unlock(&acpi_dep_list_lock);
2317+
}
2318+
EXPORT_SYMBOL_GPL(acpi_walk_dep_device_list);
2319+
22352320
/**
22362321
* acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
22372322
* @handle: Root of the namespace scope to scan.

drivers/i2c/i2c-core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ static int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
403403
return -ENOMEM;
404404
}
405405

406+
acpi_walk_dep_device_list(handle);
406407
return 0;
407408
}
408409

include/acpi/acpi_bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ struct acpi_device {
359359
void *driver_data;
360360
struct device dev;
361361
unsigned int physical_node_count;
362+
unsigned int dep_unmet;
362363
struct list_head physical_node_list;
363364
struct mutex physical_node_lock;
364365
void (*remove)(struct acpi_device *);

include/linux/acpi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ static inline bool acpi_driver_match_device(struct device *dev,
431431

432432
int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *);
433433
int acpi_device_modalias(struct device *, char *, int);
434+
void acpi_walk_dep_device_list(acpi_handle handle);
434435

435436
struct platform_device *acpi_create_platform_device(struct acpi_device *);
436437
#define ACPI_PTR(_ptr) (_ptr)

0 commit comments

Comments
 (0)