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: dac: ds4424: use device match data for chip info

Refactor the driver to use device match data instead of checking ID enums
in a switch statement.

Define a `ds4424_chip_info` structure to hold variant-specific attributes
(currently just the channel count) and attach it directly to the I2C and
OF device ID tables.

This simplifies the probe function and makes it easier to add support for
new variants like DS4402/DS4404.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Oleksij Rempel and committed by
Jonathan Cameron
37840446 d2d5a6cb

+24 -23
+24 -23
drivers/iio/dac/ds4424.c
··· 33 33 .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 34 34 } 35 35 36 - enum ds4424_device_ids { 37 - ID_DS4422, 38 - ID_DS4424, 36 + struct ds4424_chip_info { 37 + const char *name; 38 + u8 num_channels; 39 + }; 40 + 41 + static const struct ds4424_chip_info ds4422_info = { 42 + .name = "ds4422", 43 + .num_channels = DS4422_MAX_DAC_CHANNELS, 44 + }; 45 + 46 + static const struct ds4424_chip_info ds4424_info = { 47 + .name = "ds4424", 48 + .num_channels = DS4424_MAX_DAC_CHANNELS, 39 49 }; 40 50 41 51 struct ds4424_data { ··· 213 203 214 204 static int ds4424_probe(struct i2c_client *client) 215 205 { 216 - const struct i2c_device_id *id = i2c_client_get_device_id(client); 206 + const struct ds4424_chip_info *chip_info; 217 207 struct ds4424_data *data; 218 208 struct iio_dev *indio_dev; 219 209 int ret; 210 + 211 + chip_info = i2c_get_match_data(client); 212 + if (!chip_info) 213 + return -ENODEV; 220 214 221 215 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 222 216 if (!indio_dev) ··· 229 215 data = iio_priv(indio_dev); 230 216 i2c_set_clientdata(client, indio_dev); 231 217 data->client = client; 232 - indio_dev->name = id->name; 218 + indio_dev->name = chip_info->name; 233 219 234 220 data->vcc_reg = devm_regulator_get(&client->dev, "vcc"); 235 221 if (IS_ERR(data->vcc_reg)) ··· 249 235 if (ret < 0) 250 236 goto fail; 251 237 252 - switch (id->driver_data) { 253 - case ID_DS4422: 254 - indio_dev->num_channels = DS4422_MAX_DAC_CHANNELS; 255 - break; 256 - case ID_DS4424: 257 - indio_dev->num_channels = DS4424_MAX_DAC_CHANNELS; 258 - break; 259 - default: 260 - dev_err(&client->dev, 261 - "ds4424: Invalid chip id.\n"); 262 - ret = -ENXIO; 263 - goto fail; 264 - } 265 - 238 + indio_dev->num_channels = chip_info->num_channels; 266 239 indio_dev->channels = ds4424_channels; 267 240 indio_dev->modes = INDIO_DIRECT_MODE; 268 241 indio_dev->info = &ds4424_iio_info; ··· 278 277 } 279 278 280 279 static const struct i2c_device_id ds4424_id[] = { 281 - { "ds4422", ID_DS4422 }, 282 - { "ds4424", ID_DS4424 }, 280 + { "ds4422", (kernel_ulong_t)&ds4422_info }, 281 + { "ds4424", (kernel_ulong_t)&ds4424_info }, 283 282 { } 284 283 }; 285 284 286 285 MODULE_DEVICE_TABLE(i2c, ds4424_id); 287 286 288 287 static const struct of_device_id ds4424_of_match[] = { 289 - { .compatible = "maxim,ds4422" }, 290 - { .compatible = "maxim,ds4424" }, 288 + { .compatible = "maxim,ds4422", .data = &ds4422_info }, 289 + { .compatible = "maxim,ds4424", .data = &ds4424_info }, 291 290 { } 292 291 }; 293 292