iio: chemical: sgp30: Convert enum->pointer for data in the match tables

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.

Add product_id variable to struct sgp_device and remove the local variable
product_id in probe() and replace enum->struct *sgp_device for data in the
match table. Simplify theprobe() by replacing device_get_match_data() and
ID lookup for retrieving data by i2c_get_match_data().

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20230812165730.216180-1-biju.das.jz@bp.renesas.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
Biju Das 2023-08-12 17:57:30 +01:00 committed by Jonathan Cameron
parent 20f87a9a26
commit 8c89edc1ac

View File

@ -114,6 +114,7 @@ struct sgp_data {
}; };
struct sgp_device { struct sgp_device {
unsigned long product_id;
const struct iio_chan_spec *channels; const struct iio_chan_spec *channels;
int num_channels; int num_channels;
}; };
@ -182,10 +183,12 @@ static const struct iio_chan_spec sgpc3_channels[] = {
static const struct sgp_device sgp_devices[] = { static const struct sgp_device sgp_devices[] = {
[SGP30] = { [SGP30] = {
.product_id = SGP30,
.channels = sgp30_channels, .channels = sgp30_channels,
.num_channels = ARRAY_SIZE(sgp30_channels), .num_channels = ARRAY_SIZE(sgp30_channels),
}, },
[SGPC3] = { [SGPC3] = {
.product_id = SGPC3,
.channels = sgpc3_channels, .channels = sgpc3_channels,
.num_channels = ARRAY_SIZE(sgpc3_channels), .num_channels = ARRAY_SIZE(sgpc3_channels),
}, },
@ -491,28 +494,25 @@ static const struct iio_info sgp_info = {
}; };
static const struct of_device_id sgp_dt_ids[] = { static const struct of_device_id sgp_dt_ids[] = {
{ .compatible = "sensirion,sgp30", .data = (void *)SGP30 }, { .compatible = "sensirion,sgp30", .data = &sgp_devices[SGP30] },
{ .compatible = "sensirion,sgpc3", .data = (void *)SGPC3 }, { .compatible = "sensirion,sgpc3", .data = &sgp_devices[SGPC3] },
{ } { }
}; };
static int sgp_probe(struct i2c_client *client) static int sgp_probe(struct i2c_client *client)
{ {
const struct i2c_device_id *id = i2c_client_get_device_id(client); const struct i2c_device_id *id = i2c_client_get_device_id(client);
const struct sgp_device *match_data;
struct device *dev = &client->dev; struct device *dev = &client->dev;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct sgp_data *data; struct sgp_data *data;
unsigned long product_id;
int ret; int ret;
indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (!indio_dev) if (!indio_dev)
return -ENOMEM; return -ENOMEM;
if (dev_fwnode(dev)) match_data = i2c_get_match_data(client);
product_id = (unsigned long)device_get_match_data(dev);
else
product_id = id->driver_data;
data = iio_priv(indio_dev); data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev); i2c_set_clientdata(client, indio_dev);
@ -528,15 +528,15 @@ static int sgp_probe(struct i2c_client *client)
data->feature_set = be16_to_cpu(data->buffer.raw_words[0].value); data->feature_set = be16_to_cpu(data->buffer.raw_words[0].value);
ret = sgp_check_compat(data, product_id); ret = sgp_check_compat(data, match_data->product_id);
if (ret) if (ret)
return ret; return ret;
indio_dev->info = &sgp_info; indio_dev->info = &sgp_info;
indio_dev->name = id->name; indio_dev->name = id->name;
indio_dev->modes = INDIO_DIRECT_MODE; indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = sgp_devices[product_id].channels; indio_dev->channels = match_data->channels;
indio_dev->num_channels = sgp_devices[product_id].num_channels; indio_dev->num_channels = match_data->num_channels;
sgp_init(data); sgp_init(data);
@ -562,8 +562,8 @@ static void sgp_remove(struct i2c_client *client)
} }
static const struct i2c_device_id sgp_id[] = { static const struct i2c_device_id sgp_id[] = {
{ "sgp30", SGP30 }, { "sgp30", (kernel_ulong_t)&sgp_devices[SGP30] },
{ "sgpc3", SGPC3 }, { "sgpc3", (kernel_ulong_t)&sgp_devices[SGPC3] },
{ } { }
}; };