Skip to content

Commit 6ff8415

Browse files
committed
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>
1 parent 7626c25 commit 6ff8415

File tree

1 file changed

+49
-19
lines changed

1 file changed

+49
-19
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@
113113
#define WIDEBAND_DEC_RATE_MIN 32
114114
#define WIDEBAND_DEC_RATE_MAX 1024
115115

116+
#define AD7768_CHAN_INFO_NONE 0
117+
116118
enum {
117119
DEC_RATE,
118120
};
@@ -272,23 +274,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
272274
{ },
273275
};
274276

277+
#define AD7768_CHAN(_idx, _msk_avail) { \
278+
.type = IIO_VOLTAGE,\
279+
.info_mask_separate_available = _msk_avail,\
280+
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),\
281+
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
282+
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
283+
.ext_info = ad7768_ext_info,\
284+
.indexed = 1,\
285+
.channel = _idx,\
286+
.scan_index = 0,\
287+
.has_ext_scan_type = 1,\
288+
.ext_scan_type = ad7768_scan_type,\
289+
.num_ext_scan_type = ARRAY_SIZE(ad7768_scan_type),\
290+
}
291+
275292
static const struct iio_chan_spec ad7768_channels[] = {
276-
{
277-
.type = IIO_VOLTAGE,
278-
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
279-
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
280-
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
281-
.ext_info = ad7768_ext_info,
282-
.indexed = 1,
283-
.channel = 0,
284-
.scan_index = 0,
285-
.has_ext_scan_type = 1,
286-
.ext_scan_type = ad7768_scan_type,
287-
.num_ext_scan_type = ARRAY_SIZE(ad7768_scan_type),
288-
},
293+
AD7768_CHAN(0, AD7768_CHAN_INFO_NONE),
294+
};
295+
296+
struct ad7768_chip_info {
297+
const char *name;
298+
const struct iio_chan_spec *channel_spec;
299+
const unsigned long *available_masks;
300+
int num_channels;
289301
};
290302

291303
struct ad7768_state {
304+
const struct ad7768_chip_info *chip;
292305
struct spi_device *spi;
293306
struct regulator *vref;
294307
struct mutex lock;
@@ -1279,6 +1292,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
12791292
return 0;
12801293
}
12811294

1295+
static const unsigned long ad7768_channel_masks[] = {
1296+
BIT(0),
1297+
0,
1298+
};
1299+
1300+
static const struct ad7768_chip_info ad7768_chip_info = {
1301+
.name = "ad7768-1",
1302+
.channel_spec = ad7768_channels,
1303+
.num_channels = 1,
1304+
.available_masks = ad7768_channel_masks,
1305+
};
1306+
12821307
static int ad7768_probe(struct spi_device *spi)
12831308
{
12841309
struct ad7768_state *st;
@@ -1323,11 +1348,16 @@ static int ad7768_probe(struct spi_device *spi)
13231348
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
13241349
st->irq = spi->irq;
13251350

1351+
st->chip = spi_get_device_match_data(spi);
1352+
if (!st->chip)
1353+
return dev_err_probe(&spi->dev, -ENODEV,
1354+
"Could not find chip info data\n");
1355+
13261356
mutex_init(&st->lock);
13271357

1328-
indio_dev->channels = ad7768_channels;
1329-
indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
1330-
indio_dev->name = spi_get_device_id(spi)->name;
1358+
indio_dev->channels = st->chip->channel_spec;
1359+
indio_dev->num_channels = st->chip->num_channels;
1360+
indio_dev->name = st->chip->name;
13311361
indio_dev->info = &ad7768_info;
13321362
indio_dev->modes = INDIO_DIRECT_MODE;
13331363

@@ -1337,7 +1367,7 @@ static int ad7768_probe(struct spi_device *spi)
13371367
return ret;
13381368
}
13391369

1340-
ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels));
1370+
ret = ad7768_set_channel_label(indio_dev, st->chip->num_channels);
13411371
if (ret)
13421372
return ret;
13431373

@@ -1352,13 +1382,13 @@ static int ad7768_probe(struct spi_device *spi)
13521382
}
13531383

13541384
static const struct spi_device_id ad7768_id_table[] = {
1355-
{ "ad7768-1", 0 },
1385+
{ "ad7768-1", (kernel_ulong_t)&ad7768_chip_info },
13561386
{}
13571387
};
13581388
MODULE_DEVICE_TABLE(spi, ad7768_id_table);
13591389

13601390
static const struct of_device_id ad7768_of_match[] = {
1361-
{ .compatible = "adi,ad7768-1" },
1391+
{ .compatible = "adi,ad7768-1", .data = &ad7768_chip_info },
13621392
{ },
13631393
};
13641394
MODULE_DEVICE_TABLE(of, ad7768_of_match);

0 commit comments

Comments
 (0)