Skip to content

Commit 6d97010

Browse files
andy-shevJiri Kosina
authored andcommitted
HID: i2c-hid: acpi: Get ACPI companion only once and reuse it
Currently the ACPI companion and handle are retrieved and checked a few times in different functions. Instead get ACPI companion only once and reuse it everywhere. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 69aea9d commit 6d97010

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

drivers/hid/i2c-hid/i2c-hid-acpi.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
struct i2c_hid_acpi {
3232
struct i2chid_ops ops;
33-
struct i2c_client *client;
33+
struct acpi_device *adev;
3434
};
3535

3636
static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
@@ -42,29 +42,22 @@ static const struct acpi_device_id i2c_hid_acpi_blacklist[] = {
4242
{ },
4343
};
4444

45-
static int i2c_hid_acpi_get_descriptor(struct i2c_client *client)
45+
static int i2c_hid_acpi_get_descriptor(struct acpi_device *adev)
4646
{
4747
static guid_t i2c_hid_guid =
4848
GUID_INIT(0x3CDFF6F7, 0x4267, 0x4555,
4949
0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE);
50+
acpi_handle handle = acpi_device_handle(adev);
5051
union acpi_object *obj;
51-
struct acpi_device *adev;
52-
acpi_handle handle;
5352
u16 hid_descriptor_address;
5453

55-
handle = ACPI_HANDLE(&client->dev);
56-
if (!handle || acpi_bus_get_device(handle, &adev)) {
57-
dev_err(&client->dev, "Error could not get ACPI device\n");
58-
return -ENODEV;
59-
}
60-
6154
if (acpi_match_device_ids(adev, i2c_hid_acpi_blacklist) == 0)
6255
return -ENODEV;
6356

6457
obj = acpi_evaluate_dsm_typed(handle, &i2c_hid_guid, 1, 1, NULL,
6558
ACPI_TYPE_INTEGER);
6659
if (!obj) {
67-
dev_err(&client->dev, "Error _DSM call to get HID descriptor address failed\n");
60+
acpi_handle_err(handle, "Error _DSM call to get HID descriptor address failed\n");
6861
return -ENODEV;
6962
}
7063

@@ -76,10 +69,9 @@ static int i2c_hid_acpi_get_descriptor(struct i2c_client *client)
7669

7770
static void i2c_hid_acpi_shutdown_tail(struct i2chid_ops *ops)
7871
{
79-
struct i2c_hid_acpi *ihid_acpi =
80-
container_of(ops, struct i2c_hid_acpi, ops);
81-
struct device *dev = &ihid_acpi->client->dev;
82-
acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D3_COLD);
72+
struct i2c_hid_acpi *ihid_acpi = container_of(ops, struct i2c_hid_acpi, ops);
73+
74+
acpi_device_set_power(ihid_acpi->adev, ACPI_STATE_D3_COLD);
8375
}
8476

8577
static int i2c_hid_acpi_probe(struct i2c_client *client,
@@ -91,21 +83,25 @@ static int i2c_hid_acpi_probe(struct i2c_client *client,
9183
u16 hid_descriptor_address;
9284
int ret;
9385

86+
adev = ACPI_COMPANION(dev);
87+
if (!adev) {
88+
dev_err(&client->dev, "Error could not get ACPI device\n");
89+
return -ENODEV;
90+
}
91+
9492
ihid_acpi = devm_kzalloc(&client->dev, sizeof(*ihid_acpi), GFP_KERNEL);
9593
if (!ihid_acpi)
9694
return -ENOMEM;
9795

98-
ihid_acpi->client = client;
96+
ihid_acpi->adev = adev;
9997
ihid_acpi->ops.shutdown_tail = i2c_hid_acpi_shutdown_tail;
10098

101-
ret = i2c_hid_acpi_get_descriptor(client);
99+
ret = i2c_hid_acpi_get_descriptor(adev);
102100
if (ret < 0)
103101
return ret;
104102
hid_descriptor_address = ret;
105103

106-
adev = ACPI_COMPANION(dev);
107-
if (adev)
108-
acpi_device_fix_up_power(adev);
104+
acpi_device_fix_up_power(adev);
109105

110106
if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
111107
device_set_wakeup_capable(dev, true);

0 commit comments

Comments
 (0)