iio: Clean up acpi_match_device() use cases
v2 cover iio: Clean up acpi_match_device() use cases
There are current uses of acpi_match_device():
- as strange way of checking if the device was enumerated via ACPI
- as a way to get IIO device name as ACPI device instance name
- as above with accompanying driver data
Deduplicate its use by providing two new helper functions in IIO ACPI library and update the rest accordingly.
This also includes a rework of previously sent ltr501 patch.
In v2:
- collected tags (Hans, Jean-Baptiste)
- updated SoB chain in patch 4
Andy Shevchenko (13):
iio: magnetometer: bmc150: Drop dead code from the driver
iio: adc: pac1934: Replace strange way of checking type of enumeration
iio: imu: inv_mpu6050: Replace strange way of checking type of
enumeration
iio: acpi: Improve iio_read_acpi_mount_matrix()
iio: acpi: Add iio_get_acpi_device_name_and_data() helper function
iio: accel: mma9551: Replace custom implementation of
iio_get_acpi_device_name()
iio: accel: mma9553: Replace custom implementation of
iio_get_acpi_device_name()
iio: gyro: bmg160: Replace custom implementation of
iio_get_acpi_device_name()
iio: light: isl29018: Replace a variant of
iio_get_acpi_device_name_and_data()
iio: light: isl29018: drop ACPI_PTR() and CONFIG_ACPI guards
iio: light: ltr501: Drop most likely fake ACPI IDs
iio: light: ltr501: Add LTER0303 to the supported devices
iio: light: ltr501: Replace a variant of
iio_get_acpi_device_name_and_data()
drivers/iio/accel/mma9551.c | 19 ++------- drivers/iio/accel/mma9553.c | 19 ++------- drivers/iio/adc/pac1934.c | 2 +- drivers/iio/gyro/bmg160_core.c | 15 -------- drivers/iio/gyro/bmg160_i2c.c | 4 +- drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c | 5 +-- drivers/iio/industrialio-acpi.c | 45 ++++++++++++++++++++-- drivers/iio/light/isl29018.c | 38 ++++++------------ drivers/iio/light/ltr501.c | 29 +++++--------- drivers/iio/magnetometer/bmc150_magn.c | 15 -------- include/linux/iio/iio.h | 10 +++++ 11 files changed, 86 insertions(+), 115 deletions(-)
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 1/13 iio: magnetometer: bmc150: Drop dead code from the driver
Since there is no ACPI IDs for this driver to be served for, drop dead ACPI bits from it completely.
--- drivers/iio/magnetometer/bmc150_magn.c | 15 --------------- 1 file changed, 15 deletions(-)
drivers/iio/magnetometer/bmc150_magn.c +0 -15
@@ -14,7 +14,6 @@#include <linux/interrupt.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/acpi.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/iio/iio.h>
@@ -855,17 +854,6 @@ static const struct iio_buffer_setup_ops bmc150_magn_buffer_setup_ops = { .postdisable = bmc150_magn_buffer_postdisable, }; -static const char *bmc150_magn_match_acpi_device (struct device *dev) -{ -const struct acpi_device_id *id; - - id =acpi_match_device (dev->driver->acpi_match_table, dev); -if (!id) -return NULL ; - -return dev_name (dev); -} -int bmc150_magn_probe (struct device *dev,struct regmap *regmap,int irq,const char *name) {
@@ -894,9 +882,6 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap,if (ret)return ret; -if (!name &&ACPI_HANDLE (dev)) - name =bmc150_magn_match_acpi_device (dev); -mutex_init (&data->mutex); ret =bmc150_magn_init (data);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 2/13 iio: adc: pac1934: Replace strange way of checking type of enumeration
In reply to Andy ShevchenkoWhen device is enumerated via ACPI the respective device node is of ACPI device type. Use that to check for ACPI enumeration, rather than calling for full match which is O(n) vs. O(1) for the regular check.
--- drivers/iio/adc/pac1934.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/pac1934.c +1 -1
@@ -1507,7 +1507,7 @@ static int pac1934_probe(struct i2c_client *client) indio_dev->name = pac1934_chip_config[ret].name; } -if (acpi_match_device (dev->driver->acpi_match_table, dev)) +if (is_acpi_device_node (dev_fwnode (dev))) ret =pac1934_acpi_parse_channel_config (client, info);else /*
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Re: [PATCH v2 02/13] iio: adc: pac1934: Replace strange way of checking type of enumeration
Hi Andy,
Thank you for the patch. It looks OK for me.
Regards,
Marius
Quoted 31 lines · Andy Shevchenko
EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
When device is enumerated via ACPI the respective device node is of ACPI device type. Use that to check for ACPI enumeration, rather than calling for full match which is O(n) vs. O(1) for the regular check.
Reviewed-by Hans de Goede <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>---
drivers/iio/adc/pac1934.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/adc/pac1934.c +1
-1@@ -1507,7 +1507,7 @@ static int pac1934_probe(struct i2c_client *client) indio_dev->name = pac1934_chip_config[ret].name; } - if (acpi_match_device(dev->driver->acpi_match_table, dev)) + if (is_acpi_device_node(dev_fwnode(dev))) ret = pac1934_acpi_parse_channel_config(client, info);else
/*
--
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 3/13 iio: imu: inv_mpu6050: Replace strange way of checking type of enumeration
In reply to Andy ShevchenkoWhen device is enumerated via ACPI the respective device node is of ACPI device type. Use that to check for ACPI enumeration, rather than calling for full match which is O(n) vs. O(1) for the regular check.
--- drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c +1 -4
@@ -104,14 +104,11 @@ static int inv_mpu_process_acpi_config(struct i2c_client *client, unsigned short *secondary_addr) {struct acpi_device *adev =ACPI_COMPANION (&client->dev); -const struct acpi_device_id *id;u32 i2c_addr =0 ;LIST_HEAD (resources);int ret; - id =acpi_match_device (client->dev.driver->acpi_match_table, - &client->dev); -if (!id) +if (!is_acpi_device_node (dev_fwnode (&client->dev)))return -ENODEV ; ret = acpi_dev_get_resources(adev, &resources,
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 4/13 iio: acpi: Improve iio_read_acpi_mount_matrix()
In reply to Andy ShevchenkoFrom: Andy Shevchenko <[email protected]>
By using ACPI_HANDLE() the handler argument can be retrieved directly. Replace ACPI_COMPANION() + dereference with ACPI_HANDLE().
--- drivers/iio/industrialio-acpi.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/iio/industrialio-acpi.c +7 -3
@@ -28,17 +28,21 @@ bool iio_read_acpi_mount_matrix(struct device *dev, char *acpi_method) {struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; -struct acpi_device *adev =ACPI_COMPANION (dev);char *str;union acpi_object *obj, *elements; +acpi_handle handle;acpi_status status;int i, j, val[3 ];bool ret = false; -if (!adev || !acpi_has_method (adev->handle, acpi_method)) + handle =ACPI_HANDLE (dev); +if (!handle)return false; - status =acpi_evaluate_object (adev->handle, acpi_method,NULL , &buffer); +if (!acpi_has_method (handle, acpi_method)) +return false; + + status =acpi_evaluate_object (handle, acpi_method,NULL , &buffer);if (ACPI_FAILURE (status)) {dev_err (dev,"Failed to get ACPI mount matrix: %d\n" , status);return false;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 5/13 iio: acpi: Add iio_get_acpi_device_name_and_data() helper function
In reply to Andy ShevchenkoA few drivers duplicate the code to retrieve ACPI device instance name. Some of them want an associated driver data as well.
In order of deduplication introduce the common helper functions.
--- drivers/iio/industrialio-acpi.c | 35 ++++++++++++++++++++++++++++++++- include/linux/iio/iio.h | 10 ++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-)
drivers/iio/industrialio-acpi.c +34 -1
@@ -2,7 +2,8 @@/* IIO ACPI helper functions */ #include <linux/acpi.h> -#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/export.h> #include <linux/iio/iio.h> #include <linux/sprintf.h>
@@ -87,3 +88,35 @@ bool iio_read_acpi_mount_matrix(struct device *dev,return ret; }EXPORT_SYMBOL_GPL (iio_read_acpi_mount_matrix); + +/** +* iio_get_acpi_device_name_and_data() - Return ACPI device instance name and driver data +* @dev: Device structure +* @data: Optional pointer to return driver data +* +* When device was enumerated by ACPI ID matching, the user might +* want to set description for the physical chip. In such cases +* the ACPI device instance name might be used. This call may be +* performed to retrieve this information. +* +* Returns: ACPI device instance name or %NULL. +*/ +const char *iio_get_acpi_device_name_and_data (struct device *dev,const void **data) +{ +const struct acpi_device_id *id; +acpi_handle handle; + + handle =ACPI_HANDLE (dev); +if (!handle) +return NULL ; + + id =acpi_match_device (dev->driver->acpi_match_table, dev); +if (!id) +return NULL ; + +if (data) + *data = (const void *)id->driver_data; + +return dev_name (dev); +} +EXPORT_SYMBOL_GPL (iio_get_acpi_device_name_and_data);
include/linux/iio/iio.h +10 -0
@@ -831,6 +831,7 @@ int iio_device_resume_triggering(struct iio_dev *indio_dev);bool iio_read_acpi_mount_matrix (struct device *dev,struct iio_mount_matrix *orientation,char *acpi_method); +const char *iio_get_acpi_device_name_and_data (struct device *dev,const void **data);#else static inline bool iio_read_acpi_mount_matrix(struct device *dev, struct iio_mount_matrix *orientation,
@@ -838,7 +839,16 @@ static inline bool iio_read_acpi_mount_matrix(struct device *dev, {return false; } +static inline const char * +iio_get_acpi_device_name_and_data (struct device *dev,const void **data) +{ +return NULL ; +}#endif +static inline const char *iio_get_acpi_device_name (struct device *dev) +{ +return iio_get_acpi_device_name_and_data (dev,NULL ); +}/** * iio_get_current_scan_type - Get the current scan type for a channel
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 6/13 iio: accel: mma9551: Replace custom implementation of iio_get_acpi_device_name()
In reply to Andy ShevchenkoIIO core (ACPI part) provides a generic helper that may be used in the driver. Replace custom implementation of iio_get_acpi_device_name().
--- drivers/iio/accel/mma9551.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/iio/accel/mma9551.c +4 -15
@@ -4,11 +4,11 @@* Copyright (c) 2014, Intel Corporation. */ -#include <linux/module.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> #include <linux/slab.h> -#include <linux/acpi.h> #include <linux/delay.h> #include <linux/gpio/consumer.h> #include <linux/iio/iio.h>
@@ -435,17 +435,6 @@ static int mma9551_gpio_probe(struct iio_dev *indio_dev)return 0 ; } -static const char *mma9551_match_acpi_device (struct device *dev) -{ -const struct acpi_device_id *id; - - id =acpi_match_device (dev->driver->acpi_match_table, dev); -if (!id) -return NULL ; - -return dev_name (dev); -} -static int mma9551_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client);
@@ -464,8 +453,8 @@ static int mma9551_probe(struct i2c_client *client)if (id) name = id->name; -else if (ACPI_HANDLE (&client->dev)) - name =mma9551_match_acpi_device (&client->dev); +else + name =iio_get_acpi_device_name (&client->dev); ret =mma9551_init (data);if (ret <0 )
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 7/13 iio: accel: mma9553: Replace custom implementation of iio_get_acpi_device_name()
In reply to Andy ShevchenkoIIO core (ACPI part) provides a generic helper that may be used in the driver. Replace custom implementation of iio_get_acpi_device_name().
--- drivers/iio/accel/mma9553.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/iio/accel/mma9553.c +4 -15
@@ -4,11 +4,11 @@* Copyright (c) 2014, Intel Corporation. */ -#include <linux/module.h> #include <linux/i2c.h> #include <linux/interrupt.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> #include <linux/slab.h> -#include <linux/acpi.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h>
@@ -1062,17 +1062,6 @@ static irqreturn_t mma9553_event_handler(int irq, void *private)return IRQ_HANDLED ; } -static const char *mma9553_match_acpi_device (struct device *dev) -{ -const struct acpi_device_id *id; - - id =acpi_match_device (dev->driver->acpi_match_table, dev); -if (!id) -return NULL ; - -return dev_name (dev); -} -static int mma9553_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client);
@@ -1091,9 +1080,9 @@ static int mma9553_probe(struct i2c_client *client)if (id) name = id->name; -else if (ACPI_HANDLE (&client->dev)) - name =mma9553_match_acpi_device (&client->dev);else + name =iio_get_acpi_device_name (&client->dev); +if (!name)return -ENOSYS ;mutex_init (&data->mutex);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 8/13 iio: gyro: bmg160: Replace custom implementation of iio_get_acpi_device_name()
In reply to Andy ShevchenkoIIO core (ACPI part) provides a generic helper that may be used in the driver. Replace custom implementation of iio_get_acpi_device_name().
--- drivers/iio/gyro/bmg160_core.c | 15 --------------- drivers/iio/gyro/bmg160_i2c.c | 4 +++- 2 files changed, 3 insertions(+), 16 deletions(-)
drivers/iio/gyro/bmg160_core.c +0 -15
@@ -8,7 +8,6 @@#include <linux/interrupt.h> #include <linux/delay.h> #include <linux/slab.h> -#include <linux/acpi.h> #include <linux/pm.h> #include <linux/pm_runtime.h> #include <linux/iio/iio.h>
@@ -1055,17 +1054,6 @@ static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = { .postdisable = bmg160_buffer_postdisable, }; -static const char *bmg160_match_acpi_device (struct device *dev) -{ -const struct acpi_device_id *id; - - id =acpi_match_device (dev->driver->acpi_match_table, dev); -if (!id) -return NULL ; - -return dev_name (dev); -} -int bmg160_core_probe (struct device *dev,struct regmap *regmap,int irq,const char *name) {
@@ -1098,9 +1086,6 @@ int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,mutex_init (&data->mutex); -if (ACPI_HANDLE (dev)) - name =bmg160_match_acpi_device (dev); - indio_dev->channels = bmg160_channels; indio_dev->num_channels =ARRAY_SIZE (bmg160_channels); indio_dev->name = name;
drivers/iio/gyro/bmg160_i2c.c +3 -1
@@ -17,7 +17,7 @@ static int bmg160_i2c_probe(struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client);struct regmap *regmap; -const char *name =NULL ; +const char *name; regmap =devm_regmap_init_i2c (client, &bmg160_regmap_i2c_conf);if (IS_ERR (regmap)) {
@@ -28,6 +28,8 @@ static int bmg160_i2c_probe(struct i2c_client *client)if (id) name = id->name; +else + name =iio_get_acpi_device_name (&client->dev);return bmg160_core_probe (&client->dev, regmap, client->irq, name); }
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 9/13 iio: light: isl29018: Replace a variant of iio_get_acpi_device_name_and_data()
In reply to Andy ShevchenkoIIO core (ACPI part) provides a generic helper that may be used in the driver. Replace a variant of iio_get_acpi_device_name_and_data().
--- drivers/iio/light/isl29018.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-)
drivers/iio/light/isl29018.c +6 -19
@@ -687,20 +687,6 @@ static const struct isl29018_chip_info isl29018_chip_info_tbl[] = { }, }; -static const char *isl29018_match_acpi_device (struct device *dev,int *data) -{ -const struct acpi_device_id *id; - - id =acpi_match_device (dev->driver->acpi_match_table, dev); - -if (!id) -return NULL ; - - *data = (int )id->driver_data; - -return dev_name (dev); -} -static void isl29018_disable_regulator_action (void *_data) {struct isl29018_chip *chip = _data;
@@ -716,9 +702,10 @@ static int isl29018_probe(struct i2c_client *client)const struct i2c_device_id *id =i2c_client_get_device_id (client);struct isl29018_chip *chip;struct iio_dev *indio_dev; +const void *ddata; +const char *name; +int dev_id;int err; -const char *name =NULL ; -int dev_id =0 ; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*chip));if (!indio_dev)
@@ -731,11 +718,11 @@ static int isl29018_probe(struct i2c_client *client)if (id) { name = id->name; dev_id = id->driver_data; + }else { + name =iio_get_acpi_device_name_and_data (&client->dev, &ddata); + dev_id = (intptr_t )ddata; } -if (ACPI_HANDLE (&client->dev)) - name =isl29018_match_acpi_device (&client->dev, &dev_id); -mutex_init (&chip->lock); chip->type = dev_id;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 10/13 iio: light: isl29018: drop ACPI_PTR() and CONFIG_ACPI guards
In reply to Andy ShevchenkoThe complexity of config guards needed for ACPI_PTR() is not worthwhile for the small amount of saved data. This example was doing it correctly but I am proposing dropping this so as to reduce chance of cut and paste where it is done wrong. Also drop now unneeded linux/acpi.h include and added linux/mod_devicetable.h for struct acpi_device_id definition.
--- drivers/iio/light/isl29018.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/light/isl29018.c +6 -7
@@ -8,17 +8,18 @@* Copyright (c) 2010, NVIDIA Corporation. */ -#include <linux/module.h> #include <linux/i2c.h> #include <linux/err.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> #include <linux/mutex.h> #include <linux/delay.h> #include <linux/regmap.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> +#include <linux/iio/iio.h> #include <linux/iio/sysfs.h> -#include <linux/acpi.h> #define ISL29018_CONV_TIME_MS 100
@@ -819,15 +820,13 @@ static int isl29018_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(isl29018_pm_ops, isl29018_suspend, isl29018_resume); -#ifdef CONFIG_ACPI static const struct acpi_device_id isl29018_acpi_match[] = { {"ISL29018" , isl29018}, {"ISL29023" , isl29023}, {"ISL29035" , isl29035}, - {}, + {} };MODULE_DEVICE_TABLE (acpi, isl29018_acpi_match); -#endif static const struct i2c_device_id isl29018_id[] = { {"isl29018" , isl29018},
@@ -841,14 +840,14 @@ static const struct of_device_id isl29018_of_match[] = { { .compatible = "isil,isl29018", }, { .compatible = "isil,isl29023", }, { .compatible = "isil,isl29035", }, - { }, + {} }; MODULE_DEVICE_TABLE(of, isl29018_of_match); static struct i2c_driver isl29018_driver = { .driver = { .name = "isl29018", - .acpi_match_table = ACPI_PTR(isl29018_acpi_match), + .acpi_match_table = isl29018_acpi_match, .pm = pm_sleep_ptr(&isl29018_pm_ops), .of_match_table = isl29018_of_match, },
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 11/13 iio: light: ltr501: Drop most likely fake ACPI IDs
In reply to Andy ShevchenkoThe commits in question do not proove that ACPI IDs exist. Quite likely it was a cargo cult addition while doing that for DT-based enumeration. Drop most likely fake ACPI IDs.
The to be removed IDs has been checked against the following resources:
1) DuckDuckGo
2) Google
3) MS catalog: https://www.catalog.update.microsoft.com/Search.aspx
This gives no useful results in regard to DSDT, moreover, the official vendor ID in the registry for Lite-On is LCI.
--- drivers/iio/light/ltr501.c | 2 -- 1 file changed, 2 deletions(-)
drivers/iio/light/ltr501.c +0 -2
@@ -1610,8 +1610,6 @@ static int ltr501_resume(struct device *dev) static DEFINE_SIMPLE_DEV_PM_OPS(ltr501_pm_ops, ltr501_suspend, ltr501_resume);static const struct acpi_device_id ltr_acpi_match[] = { - {"LTER0501" , ltr501 }, - {"LTER0559" , ltr559 }, {"LTER0301" , ltr301 }, { }, };
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 12/13 iio: light: ltr501: Add LTER0303 to the supported devices
In reply to Andy ShevchenkoIt has been found that the (non-vendor issued) ACPI ID for Lite-On LTR303 is present in Microsoft catalog. Add it to the list of the supported devices.
--- drivers/iio/light/ltr501.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/iio/light/ltr501.c +2 -0
@@ -1611,6 +1611,8 @@ static DEFINE_SIMPLE_DEV_PM_OPS(ltr501_pm_ops, ltr501_suspend, ltr501_resume);static const struct acpi_device_id ltr_acpi_match[] = { {"LTER0301" , ltr301 }, +/* https://www.catalog.update.microsoft.com/Search.aspx?q=lter0303 */ + {"LTER0303" , ltr303 }, { }, };MODULE_DEVICE_TABLE (acpi, ltr_acpi_match);
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
PATCH v2 13/13 iio: light: ltr501: Replace a variant of iio_get_acpi_device_name_and_data()
In reply to Andy ShevchenkoIIO core (ACPI part) provides a generic helper that may be used in the driver. Replace a variant of iio_get_acpi_device_name_and_data().
--- drivers/iio/light/ltr501.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-)
drivers/iio/light/ltr501.c +8 -17
@@ -15,7 +15,6 @@#include <linux/err.h> #include <linux/delay.h> #include <linux/regmap.h> -#include <linux/acpi.h> #include <linux/regulator/consumer.h> #include <linux/iio/iio.h>
@@ -1422,17 +1421,6 @@ static int ltr501_powerdown(struct ltr501_data *data) data->ps_contr & ~LTR501_CONTR_ACTIVE); } -static const char *ltr501_match_acpi_device (struct device *dev,int *chip_idx) -{ -const struct acpi_device_id *id; - - id =acpi_match_device (dev->driver->acpi_match_table, dev); -if (!id) -return NULL ; - *chip_idx = id->driver_data; -return dev_name (dev); -} -static int ltr501_probe (struct i2c_client *client) {const struct i2c_device_id *id =i2c_client_get_device_id (client);
@@ -1440,8 +1428,10 @@ static int ltr501_probe(struct i2c_client *client)struct ltr501_data *data;struct iio_dev *indio_dev;struct regmap *regmap; -int ret, partid, chip_idx =0 ; -const char *name =NULL ; +int partid, chip_idx; +const void *ddata; +const char *name; +int ret; indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data));if (!indio_dev)
@@ -1523,11 +1513,12 @@ static int ltr501_probe(struct i2c_client *client)if (id) { name = id->name; chip_idx = id->driver_data; - }else if (ACPI_HANDLE (&client->dev)) { - name =ltr501_match_acpi_device (&client->dev, &chip_idx); }else { -return -ENODEV ; + name =iio_get_acpi_device_name_and_data (&client->dev, &ddata); + chip_idx = (intptr_t )ddata; } +if (!name) +return -ENODEV ; data->chip_info = <r501_chip_info_tbl[chip_idx];
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
Quoted 5 lines · Andy Shevchenko
There are current uses of
acpi_match_device():
- as strange way of checking if the device was enumerated via ACPI
- as a way to get IIO device name as ACPI device instance name
- as above with accompanying driver data
Quoted 8 lines
Deduplicate its use by providing two new helper functions in IIO ACPI library and update the rest accordingly.
This also includes a rework of previously sent ltr501 patch.
In v2:
- collected tags (Hans, Jean-Baptiste)
- updated SoB chain in patch 4
Heck, I forgot to address the main comment by Jonathan! Sorry for the noise, I will send a v3 later today.
Signature · 2 lines
With Best Regards, Andy Shevchenko