From 4d36d4df68d3db9aca1e0785f464b5092f39952b Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Thu, 10 Sep 2020 18:32:28 +0100 Subject: iio:chemical:ams-iaq-core: Drop of_match_ptr protection This prevents use of this driver with ACPI via PRP0001 and is an example of an anti pattern I'm trying to remove from IIO. Hence drop from this driver. Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Acked-by: Matt Ranostay Link: https://lore.kernel.org/r/20200910173242.621168-25-jic23@kernel.org --- drivers/iio/chemical/ams-iaq-core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/iio/chemical') diff --git a/drivers/iio/chemical/ams-iaq-core.c b/drivers/iio/chemical/ams-iaq-core.c index 8c1b64fd424a..97be3669c554 100644 --- a/drivers/iio/chemical/ams-iaq-core.c +++ b/drivers/iio/chemical/ams-iaq-core.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -177,7 +178,7 @@ MODULE_DEVICE_TABLE(of, ams_iaqcore_dt_ids); static struct i2c_driver ams_iaqcore_driver = { .driver = { .name = "ams-iaq-core", - .of_match_table = of_match_ptr(ams_iaqcore_dt_ids), + .of_match_table = ams_iaqcore_dt_ids, }, .probe = ams_iaqcore_probe, .id_table = ams_iaqcore_id, -- cgit From a867e8986759bf25251c8cad3798cba0e4c25a6e Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Thu, 10 Sep 2020 18:32:29 +0100 Subject: iio:chemical:atlas-sensor: Drop of_match_ptr and use generic fw accessors of_match_ptr() prevents use of this driver with ACPI via PRP0001 and is an example of an anti pattern I'm trying to remove from IIO. Hence drop from this driver and use generic fw accessors to check if there is a fw_node and get the id. It might be neater to use pointers rather than indexes for the device_data but that is another issue and should be handled separately. Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Acked-by: Matt Ranostay Link: https://lore.kernel.org/r/20200910173242.621168-26-jic23@kernel.org --- drivers/iio/chemical/atlas-sensor.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'drivers/iio/chemical') diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c index 43069636fcd5..cdab9d04dedd 100644 --- a/drivers/iio/chemical/atlas-sensor.c +++ b/drivers/iio/chemical/atlas-sensor.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -620,7 +620,6 @@ static int atlas_probe(struct i2c_client *client, { struct atlas_data *data; struct atlas_device *chip; - const struct of_device_id *of_id; struct iio_trigger *trig; struct iio_dev *indio_dev; int ret; @@ -629,11 +628,10 @@ static int atlas_probe(struct i2c_client *client, if (!indio_dev) return -ENOMEM; - of_id = of_match_device(atlas_dt_ids, &client->dev); - if (!of_id) + if (!dev_fwnode(&client->dev)) chip = &atlas_devices[id->driver_data]; else - chip = &atlas_devices[(unsigned long)of_id->data]; + chip = &atlas_devices[(unsigned long)device_get_match_data(&client->dev)]; indio_dev->info = &atlas_info; indio_dev->name = ATLAS_DRV_NAME; @@ -775,7 +773,7 @@ static const struct dev_pm_ops atlas_pm_ops = { static struct i2c_driver atlas_driver = { .driver = { .name = ATLAS_DRV_NAME, - .of_match_table = of_match_ptr(atlas_dt_ids), + .of_match_table = atlas_dt_ids, .pm = &atlas_pm_ops, }, .probe = atlas_probe, -- cgit From cb26d236861ca6a3354f1623ae5b9c049fd2f972 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Thu, 10 Sep 2020 18:32:30 +0100 Subject: iio:chemical:sgp30: Use local variable dev to simplify code This cleans up the code at bit, but is primarily here as a precusor to the next patch. I've only done this for the two functions which use the dev pointer repeatedly. Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Cc: Andreas Brauchli Link: https://lore.kernel.org/r/20200910173242.621168-27-jic23@kernel.org --- drivers/iio/chemical/sgp30.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'drivers/iio/chemical') diff --git a/drivers/iio/chemical/sgp30.c b/drivers/iio/chemical/sgp30.c index 2c4086c48136..410565aa20b6 100644 --- a/drivers/iio/chemical/sgp30.c +++ b/drivers/iio/chemical/sgp30.c @@ -409,6 +409,7 @@ static int sgp_read_raw(struct iio_dev *indio_dev, static int sgp_check_compat(struct sgp_data *data, unsigned int product_id) { + struct device *dev = &data->client->dev; const struct sgp_version *supported_versions; u16 ix, num_fs; u16 product, generation, major, minor; @@ -416,21 +417,20 @@ static int sgp_check_compat(struct sgp_data *data, /* driver does not match product */ generation = SGP_VERS_GEN(data); if (generation != 0) { - dev_err(&data->client->dev, + dev_err(dev, "incompatible product generation %d != 0", generation); return -ENODEV; } product = SGP_VERS_PRODUCT(data); if (product != product_id) { - dev_err(&data->client->dev, - "sensor reports a different product: 0x%04hx\n", + dev_err(dev, "sensor reports a different product: 0x%04hx\n", product); return -ENODEV; } if (SGP_VERS_RESERVED(data)) - dev_warn(&data->client->dev, "reserved bit is set\n"); + dev_warn(dev, "reserved bit is set\n"); /* engineering samples are not supported: no interface guarantees */ if (SGP_VERS_ENG_BIT(data)) @@ -456,8 +456,7 @@ static int sgp_check_compat(struct sgp_data *data, minor >= supported_versions[ix].minor) return 0; } - dev_err(&data->client->dev, "unsupported sgp version: %d.%d\n", - major, minor); + dev_err(dev, "unsupported sgp version: %d.%d\n", major, minor); return -ENODEV; } @@ -499,17 +498,18 @@ static const struct of_device_id sgp_dt_ids[] = { static int sgp_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct iio_dev *indio_dev; struct sgp_data *data; const struct of_device_id *of_id; unsigned long product_id; int ret; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; - of_id = of_match_device(sgp_dt_ids, &client->dev); + of_id = of_match_device(sgp_dt_ids, dev); if (of_id) product_id = (unsigned long)of_id->data; else @@ -541,9 +541,9 @@ static int sgp_probe(struct i2c_client *client, sgp_init(data); - ret = devm_iio_device_register(&client->dev, indio_dev); + ret = devm_iio_device_register(dev, indio_dev); if (ret) { - dev_err(&client->dev, "failed to register iio device\n"); + dev_err(dev, "failed to register iio device\n"); return ret; } -- cgit From 6ac282edd653d28b4d64744c7ad05e9a4e1aeaf4 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Thu, 10 Sep 2020 18:32:31 +0100 Subject: iio:chemical:sgp30: Drop of_match_ptr and use generic fw accessors This change allow the driver to be used with ACPI PRP0001 and removes an antipattern that I want to avoid being copied into new IIO drivers. The handling of match_data uses a different approach as device_get_match_data doesn't distinguish between no match, and a match but with NULL data. Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Cc: Andreas Brauchli Link: https://lore.kernel.org/r/20200910173242.621168-28-jic23@kernel.org --- drivers/iio/chemical/sgp30.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'drivers/iio/chemical') diff --git a/drivers/iio/chemical/sgp30.c b/drivers/iio/chemical/sgp30.c index 410565aa20b6..c2d93b9796ce 100644 --- a/drivers/iio/chemical/sgp30.c +++ b/drivers/iio/chemical/sgp30.c @@ -20,9 +20,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -501,7 +501,6 @@ static int sgp_probe(struct i2c_client *client, struct device *dev = &client->dev; struct iio_dev *indio_dev; struct sgp_data *data; - const struct of_device_id *of_id; unsigned long product_id; int ret; @@ -509,9 +508,8 @@ static int sgp_probe(struct i2c_client *client, if (!indio_dev) return -ENOMEM; - of_id = of_match_device(sgp_dt_ids, dev); - if (of_id) - product_id = (unsigned long)of_id->data; + if (dev_fwnode(dev)) + product_id = (unsigned long)device_get_match_data(dev); else product_id = id->driver_data; @@ -576,7 +574,7 @@ MODULE_DEVICE_TABLE(of, sgp_dt_ids); static struct i2c_driver sgp_driver = { .driver = { .name = "sgp30", - .of_match_table = of_match_ptr(sgp_dt_ids), + .of_match_table = sgp_dt_ids, }, .probe = sgp_probe, .remove = sgp_remove, -- cgit From e12b3a6150f1ce271e2a5282d3cfd116a144d796 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Thu, 10 Sep 2020 18:32:32 +0100 Subject: iio:chemical:vz89x: Introduce local struct device pointer. Avoids lots of repetition of &client->dev and will make the next patch tidier. Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Acked-by: Matt Ranostay Link: https://lore.kernel.org/r/20200910173242.621168-29-jic23@kernel.org --- drivers/iio/chemical/vz89x.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'drivers/iio/chemical') diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c index 5586eb8e12cd..3cd469578590 100644 --- a/drivers/iio/chemical/vz89x.c +++ b/drivers/iio/chemical/vz89x.c @@ -352,12 +352,13 @@ MODULE_DEVICE_TABLE(of, vz89x_dt_ids); static int vz89x_probe(struct i2c_client *client, const struct i2c_device_id *id) { + struct device *dev = &client->dev; struct iio_dev *indio_dev; struct vz89x_data *data; const struct of_device_id *of_id; int chip_id; - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); if (!indio_dev) return -ENOMEM; data = iio_priv(indio_dev); @@ -370,7 +371,7 @@ static int vz89x_probe(struct i2c_client *client, else return -EOPNOTSUPP; - of_id = of_match_device(vz89x_dt_ids, &client->dev); + of_id = of_match_device(vz89x_dt_ids, dev); if (!of_id) chip_id = id->driver_data; else @@ -383,13 +384,13 @@ static int vz89x_probe(struct i2c_client *client, mutex_init(&data->lock); indio_dev->info = &vz89x_info; - indio_dev->name = dev_name(&client->dev); + indio_dev->name = dev_name(dev); indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->channels = data->chip->channels; indio_dev->num_channels = data->chip->num_channels; - return devm_iio_device_register(&client->dev, indio_dev); + return devm_iio_device_register(dev, indio_dev); } static const struct i2c_device_id vz89x_id[] = { -- cgit From b3fce99a57377673eaf7c89ae9a42f4fd60966e2 Mon Sep 17 00:00:00 2001 From: Jonathan Cameron Date: Thu, 10 Sep 2020 18:32:33 +0100 Subject: iio:chemical:vz89x: Drop of_match_ptr protection and use generic fw accessors This change allow the driver to be used with ACPI PRP0001 and removes an antipattern that I want to avoid being copied into new IIO drivers. The handling of match_data uses a different approach as device_get_match_data() doesn't distinguish between no match, and a match but with NULL data. Signed-off-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Acked-by: Matt Ranostay Link: https://lore.kernel.org/r/20200910173242.621168-30-jic23@kernel.org --- drivers/iio/chemical/vz89x.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'drivers/iio/chemical') diff --git a/drivers/iio/chemical/vz89x.c b/drivers/iio/chemical/vz89x.c index 3cd469578590..23b22a5f5c1c 100644 --- a/drivers/iio/chemical/vz89x.c +++ b/drivers/iio/chemical/vz89x.c @@ -10,8 +10,7 @@ #include #include #include -#include -#include +#include #include #include @@ -355,7 +354,6 @@ static int vz89x_probe(struct i2c_client *client, struct device *dev = &client->dev; struct iio_dev *indio_dev; struct vz89x_data *data; - const struct of_device_id *of_id; int chip_id; indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); @@ -371,11 +369,10 @@ static int vz89x_probe(struct i2c_client *client, else return -EOPNOTSUPP; - of_id = of_match_device(vz89x_dt_ids, dev); - if (!of_id) + if (!dev_fwnode(dev)) chip_id = id->driver_data; else - chip_id = (unsigned long)of_id->data; + chip_id = (unsigned long)device_get_match_data(dev); i2c_set_clientdata(client, indio_dev); data->client = client; @@ -403,7 +400,7 @@ MODULE_DEVICE_TABLE(i2c, vz89x_id); static struct i2c_driver vz89x_driver = { .driver = { .name = "vz89x", - .of_match_table = of_match_ptr(vz89x_dt_ids), + .of_match_table = vz89x_dt_ids, }, .probe = vz89x_probe, .id_table = vz89x_id, -- cgit From ed33833ea822212a961e920b7b3c33dd299837cd Mon Sep 17 00:00:00 2001 From: Lee Jones Date: Thu, 16 Jul 2020 14:59:03 +0100 Subject: iio: chemical: sgp30: Add description for sgp_read_cmd()'s 'duration_us' Fixes the following W=1 kernel build warning(s): drivers/iio/chemical/sgp30.c:236: warning: Function parameter or member 'duration_us' not described in 'sgp_read_cmd' Signed-off-by: Lee Jones Cc: Andreas Brauchli Cc: Pascal Sachs Link: https://lore.kernel.org/r/20200716135928.1456727-6-lee.jones@linaro.org Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/sgp30.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/iio/chemical') diff --git a/drivers/iio/chemical/sgp30.c b/drivers/iio/chemical/sgp30.c index c2d93b9796ce..1029c457be15 100644 --- a/drivers/iio/chemical/sgp30.c +++ b/drivers/iio/chemical/sgp30.c @@ -227,6 +227,7 @@ static int sgp_verify_buffer(const struct sgp_data *data, * @cmd: SGP Command to issue * @buf: Raw data buffer to use * @word_count: Num words to read, excluding CRC bytes + * @duration_us: Time taken to sensor to take a reading and data to be ready. * * Return: 0 on success, negative error otherwise. */ -- cgit