Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Biju Das and committed by
Jonathan Cameron
8c89edc1 20f87a9a

+12 -12
+12 -12
drivers/iio/chemical/sgp30.c
··· 114 114 }; 115 115 116 116 struct sgp_device { 117 + unsigned long product_id; 117 118 const struct iio_chan_spec *channels; 118 119 int num_channels; 119 120 }; ··· 183 182 184 183 static const struct sgp_device sgp_devices[] = { 185 184 [SGP30] = { 185 + .product_id = SGP30, 186 186 .channels = sgp30_channels, 187 187 .num_channels = ARRAY_SIZE(sgp30_channels), 188 188 }, 189 189 [SGPC3] = { 190 + .product_id = SGPC3, 190 191 .channels = sgpc3_channels, 191 192 .num_channels = ARRAY_SIZE(sgpc3_channels), 192 193 }, ··· 494 491 }; 495 492 496 493 static const struct of_device_id sgp_dt_ids[] = { 497 - { .compatible = "sensirion,sgp30", .data = (void *)SGP30 }, 498 - { .compatible = "sensirion,sgpc3", .data = (void *)SGPC3 }, 494 + { .compatible = "sensirion,sgp30", .data = &sgp_devices[SGP30] }, 495 + { .compatible = "sensirion,sgpc3", .data = &sgp_devices[SGPC3] }, 499 496 { } 500 497 }; 501 498 502 499 static int sgp_probe(struct i2c_client *client) 503 500 { 504 501 const struct i2c_device_id *id = i2c_client_get_device_id(client); 502 + const struct sgp_device *match_data; 505 503 struct device *dev = &client->dev; 506 504 struct iio_dev *indio_dev; 507 505 struct sgp_data *data; 508 - unsigned long product_id; 509 506 int ret; 510 507 511 508 indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); 512 509 if (!indio_dev) 513 510 return -ENOMEM; 514 511 515 - if (dev_fwnode(dev)) 516 - product_id = (unsigned long)device_get_match_data(dev); 517 - else 518 - product_id = id->driver_data; 512 + match_data = i2c_get_match_data(client); 519 513 520 514 data = iio_priv(indio_dev); 521 515 i2c_set_clientdata(client, indio_dev); ··· 528 528 529 529 data->feature_set = be16_to_cpu(data->buffer.raw_words[0].value); 530 530 531 - ret = sgp_check_compat(data, product_id); 531 + ret = sgp_check_compat(data, match_data->product_id); 532 532 if (ret) 533 533 return ret; 534 534 535 535 indio_dev->info = &sgp_info; 536 536 indio_dev->name = id->name; 537 537 indio_dev->modes = INDIO_DIRECT_MODE; 538 - indio_dev->channels = sgp_devices[product_id].channels; 539 - indio_dev->num_channels = sgp_devices[product_id].num_channels; 538 + indio_dev->channels = match_data->channels; 539 + indio_dev->num_channels = match_data->num_channels; 540 540 541 541 sgp_init(data); 542 542 ··· 562 562 } 563 563 564 564 static const struct i2c_device_id sgp_id[] = { 565 - { "sgp30", SGP30 }, 566 - { "sgpc3", SGPC3 }, 565 + { "sgp30", (kernel_ulong_t)&sgp_devices[SGP30] }, 566 + { "sgpc3", (kernel_ulong_t)&sgp_devices[SGPC3] }, 567 567 { } 568 568 }; 569 569