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: adc: ad7768-1: introduce chip info for future multidevice support

Add Chip info struct in SPI device to store channel information for
each supported part.

Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Jonathan Santos and committed by
Jonathan Cameron
fa087f5b 2f55ae3a

+41 -23
+41 -23
drivers/iio/adc/ad7768-1.c
··· 213 213 }, 214 214 }; 215 215 216 + struct ad7768_chip_info { 217 + const char *name; 218 + const struct iio_chan_spec *channel_spec; 219 + int num_channels; 220 + }; 221 + 216 222 struct ad7768_state { 217 223 struct spi_device *spi; 218 224 struct regmap *regmap; ··· 240 234 struct gpio_desc *gpio_reset; 241 235 const char *labels[AD7768_MAX_CHANNELS]; 242 236 struct gpio_chip gpiochip; 237 + const struct ad7768_chip_info *chip; 243 238 bool en_spi_sync; 244 239 /* 245 240 * DMA (thus cache coherency maintenance) may require the ··· 755 748 { } 756 749 }; 757 750 751 + #define AD7768_CHAN(_idx, _msk_avail) \ 752 + { \ 753 + .type = IIO_VOLTAGE, \ 754 + .info_mask_separate_available = _msk_avail, \ 755 + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ 756 + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | \ 757 + BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | \ 758 + BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 759 + .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), \ 760 + .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 761 + .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), \ 762 + .ext_info = ad7768_ext_info, \ 763 + .indexed = 1, \ 764 + .channel = _idx, \ 765 + .scan_index = _idx, \ 766 + .has_ext_scan_type = 1, \ 767 + .ext_scan_type = ad7768_scan_type, \ 768 + .num_ext_scan_type = ARRAY_SIZE(ad7768_scan_type), \ 769 + } 770 + 758 771 static const struct iio_chan_spec ad7768_channels[] = { 759 - { 760 - .type = IIO_VOLTAGE, 761 - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), 762 - .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE) | 763 - BIT(IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY) | 764 - BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 765 - .info_mask_shared_by_type_available = BIT(IIO_CHAN_INFO_OVERSAMPLING_RATIO), 766 - .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ), 767 - .info_mask_shared_by_all_available = BIT(IIO_CHAN_INFO_SAMP_FREQ), 768 - .ext_info = ad7768_ext_info, 769 - .indexed = 1, 770 - .channel = 0, 771 - .scan_index = 0, 772 - .has_ext_scan_type = 1, 773 - .ext_scan_type = ad7768_scan_type, 774 - .num_ext_scan_type = ARRAY_SIZE(ad7768_scan_type), 775 - }, 772 + AD7768_CHAN(0, 0), 776 773 }; 777 774 778 775 static int ad7768_read_raw(struct iio_dev *indio_dev, ··· 1332 1321 return 0; 1333 1322 } 1334 1323 1324 + static const struct ad7768_chip_info ad7768_chip_info = { 1325 + .name = "ad7768-1", 1326 + .channel_spec = ad7768_channels, 1327 + .num_channels = ARRAY_SIZE(ad7768_channels), 1328 + }; 1329 + 1335 1330 static int ad7768_probe(struct spi_device *spi) 1336 1331 { 1337 1332 struct ad7768_state *st; ··· 1364 1347 return ret; 1365 1348 } 1366 1349 1350 + st->chip = spi_get_device_match_data(spi); 1367 1351 st->spi = spi; 1368 1352 1369 1353 st->regmap = devm_regmap_init_spi(spi, &ad7768_regmap_config); ··· 1389 1371 1390 1372 st->mclk_freq = clk_get_rate(st->mclk); 1391 1373 1392 - indio_dev->channels = ad7768_channels; 1393 - indio_dev->num_channels = ARRAY_SIZE(ad7768_channels); 1394 - indio_dev->name = spi_get_device_id(spi)->name; 1374 + indio_dev->channels = st->chip->channel_spec; 1375 + indio_dev->num_channels = st->chip->num_channels; 1376 + indio_dev->name = st->chip->name; 1395 1377 indio_dev->info = &ad7768_info; 1396 1378 indio_dev->modes = INDIO_DIRECT_MODE; 1397 1379 ··· 1408 1390 1409 1391 init_completion(&st->completion); 1410 1392 1411 - ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels)); 1393 + ret = ad7768_set_channel_label(indio_dev, st->chip->num_channels); 1412 1394 if (ret) 1413 1395 return ret; 1414 1396 ··· 1427 1409 } 1428 1410 1429 1411 static const struct spi_device_id ad7768_id_table[] = { 1430 - { "ad7768-1", 0 }, 1412 + { "ad7768-1", (kernel_ulong_t)&ad7768_chip_info }, 1431 1413 { } 1432 1414 }; 1433 1415 MODULE_DEVICE_TABLE(spi, ad7768_id_table); 1434 1416 1435 1417 static const struct of_device_id ad7768_of_match[] = { 1436 - { .compatible = "adi,ad7768-1" }, 1418 + { .compatible = "adi,ad7768-1", .data = &ad7768_chip_info }, 1437 1419 { } 1438 1420 }; 1439 1421 MODULE_DEVICE_TABLE(of, ad7768_of_match);