* [PATCH] iio: chemical: atlas-sensor: Convert enum->pointer for data in the match tables
@ 2023-08-12 17:13 Biju Das
2023-08-15 14:49 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: Biju Das @ 2023-08-12 17:13 UTC (permalink / raw)
To: Jonathan Cameron
Cc: Biju Das, Lars-Peter Clausen, Uwe Kleine-König,
Andy Shevchenko, Peter Rosin, Krzysztof Hałasa, linux-iio,
Geert Uytterhoeven, linux-renesas-soc
Convert enum->pointer for data in the match tables, so that
device_get_match_data() can do match against OF/ACPI/I2C tables, once i2c
bus type match support added to it.
Replace enum->struct *atlas_device for data in the match table. Simplify
the probe() by replacing device_get_match_data() and ID lookup for
retrieving data by i2c_get_match_data().
While at it, add const qualifier to struct atlas_device and drop unused
id variable from probe().
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
drivers/iio/chemical/atlas-sensor.c | 32 +++++++++++++----------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/drivers/iio/chemical/atlas-sensor.c b/drivers/iio/chemical/atlas-sensor.c
index fb15bb216019..88a22d12a294 100644
--- a/drivers/iio/chemical/atlas-sensor.c
+++ b/drivers/iio/chemical/atlas-sensor.c
@@ -87,7 +87,7 @@ enum {
struct atlas_data {
struct i2c_client *client;
struct iio_trigger *trig;
- struct atlas_device *chip;
+ const struct atlas_device *chip;
struct regmap *regmap;
struct irq_work work;
unsigned int interrupt_enabled;
@@ -353,7 +353,7 @@ struct atlas_device {
int delay;
};
-static struct atlas_device atlas_devices[] = {
+static const struct atlas_device atlas_devices[] = {
[ATLAS_PH_SM] = {
.channels = atlas_ph_channels,
.num_channels = 3,
@@ -589,30 +589,29 @@ static const struct iio_info atlas_info = {
};
static const struct i2c_device_id atlas_id[] = {
- { "atlas-ph-sm", ATLAS_PH_SM },
- { "atlas-ec-sm", ATLAS_EC_SM },
- { "atlas-orp-sm", ATLAS_ORP_SM },
- { "atlas-do-sm", ATLAS_DO_SM },
- { "atlas-rtd-sm", ATLAS_RTD_SM },
+ { "atlas-ph-sm", (kernel_ulong_t)&atlas_devices[ATLAS_PH_SM] },
+ { "atlas-ec-sm", (kernel_ulong_t)&atlas_devices[ATLAS_EC_SM] },
+ { "atlas-orp-sm", (kernel_ulong_t)&atlas_devices[ATLAS_ORP_SM] },
+ { "atlas-do-sm", (kernel_ulong_t)&atlas_devices[ATLAS_DO_SM] },
+ { "atlas-rtd-sm", (kernel_ulong_t)&atlas_devices[ATLAS_RTD_SM] },
{}
};
MODULE_DEVICE_TABLE(i2c, atlas_id);
static const struct of_device_id atlas_dt_ids[] = {
- { .compatible = "atlas,ph-sm", .data = (void *)ATLAS_PH_SM, },
- { .compatible = "atlas,ec-sm", .data = (void *)ATLAS_EC_SM, },
- { .compatible = "atlas,orp-sm", .data = (void *)ATLAS_ORP_SM, },
- { .compatible = "atlas,do-sm", .data = (void *)ATLAS_DO_SM, },
- { .compatible = "atlas,rtd-sm", .data = (void *)ATLAS_RTD_SM, },
+ { .compatible = "atlas,ph-sm", .data = &atlas_devices[ATLAS_PH_SM], },
+ { .compatible = "atlas,ec-sm", .data = &atlas_devices[ATLAS_EC_SM], },
+ { .compatible = "atlas,orp-sm", .data = &atlas_devices[ATLAS_ORP_SM], },
+ { .compatible = "atlas,do-sm", .data = &atlas_devices[ATLAS_DO_SM], },
+ { .compatible = "atlas,rtd-sm", .data = &atlas_devices[ATLAS_RTD_SM], },
{ }
};
MODULE_DEVICE_TABLE(of, atlas_dt_ids);
static int atlas_probe(struct i2c_client *client)
{
- const struct i2c_device_id *id = i2c_client_get_device_id(client);
struct atlas_data *data;
- struct atlas_device *chip;
+ const struct atlas_device *chip;
struct iio_trigger *trig;
struct iio_dev *indio_dev;
int ret;
@@ -621,10 +620,7 @@ static int atlas_probe(struct i2c_client *client)
if (!indio_dev)
return -ENOMEM;
- if (!dev_fwnode(&client->dev))
- chip = &atlas_devices[id->driver_data];
- else
- chip = &atlas_devices[(unsigned long)device_get_match_data(&client->dev)];
+ chip = i2c_get_match_data(client);
indio_dev->info = &atlas_info;
indio_dev->name = ATLAS_DRV_NAME;
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] iio: chemical: atlas-sensor: Convert enum->pointer for data in the match tables
2023-08-12 17:13 [PATCH] iio: chemical: atlas-sensor: Convert enum->pointer for data in the match tables Biju Das
@ 2023-08-15 14:49 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2023-08-15 14:49 UTC (permalink / raw)
To: Biju Das
Cc: Jonathan Cameron, Lars-Peter Clausen, Uwe Kleine-König,
Peter Rosin, Krzysztof Hałasa, linux-iio, Geert Uytterhoeven,
linux-renesas-soc
On Sat, Aug 12, 2023 at 06:13:30PM +0100, Biju Das wrote:
> Convert enum->pointer for data in the match tables, so that
> device_get_match_data() can do match against OF/ACPI/I2C tables, once i2c
> bus type match support added to it.
>
> Replace enum->struct *atlas_device for data in the match table. Simplify
> the probe() by replacing device_get_match_data() and ID lookup for
> retrieving data by i2c_get_match_data().
>
> While at it, add const qualifier to struct atlas_device and drop unused
> id variable from probe().
Same comments for id variable removal.
With that addressed and below remark,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
...
> static const struct of_device_id atlas_dt_ids[] = {
> - { .compatible = "atlas,ph-sm", .data = (void *)ATLAS_PH_SM, },
> - { .compatible = "atlas,ec-sm", .data = (void *)ATLAS_EC_SM, },
> - { .compatible = "atlas,orp-sm", .data = (void *)ATLAS_ORP_SM, },
> - { .compatible = "atlas,do-sm", .data = (void *)ATLAS_DO_SM, },
> - { .compatible = "atlas,rtd-sm", .data = (void *)ATLAS_RTD_SM, },
> + { .compatible = "atlas,ph-sm", .data = &atlas_devices[ATLAS_PH_SM], },
> + { .compatible = "atlas,ec-sm", .data = &atlas_devices[ATLAS_EC_SM], },
> + { .compatible = "atlas,orp-sm", .data = &atlas_devices[ATLAS_ORP_SM], },
> + { .compatible = "atlas,do-sm", .data = &atlas_devices[ATLAS_DO_SM], },
> + { .compatible = "atlas,rtd-sm", .data = &atlas_devices[ATLAS_RTD_SM], },
Now drop inner trailing commas.
> { }
> };
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-15 14:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-12 17:13 [PATCH] iio: chemical: atlas-sensor: Convert enum->pointer for data in the match tables Biju Das
2023-08-15 14:49 ` Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox