Skip to content

Commit a972276

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 dc084de commit a972276

File tree

1 file changed

+50
-19
lines changed

1 file changed

+50
-19
lines changed

drivers/iio/adc/ad7768-1.c

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

117+
#define AD7768_CHAN_INFO_NONE 0
118+
117119
enum {
118120
DEC_RATE,
119121
};
@@ -267,23 +269,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
267269
{ },
268270
};
269271

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

286298
struct ad7768_state {
299+
const struct ad7768_chip_info *chip;
287300
struct spi_device *spi;
288301
struct regulator *vref;
289302
struct mutex lock;
@@ -1249,6 +1262,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
12491262
return 0;
12501263
}
12511264

1265+
static const unsigned long ad7768_channel_masks[] = {
1266+
BIT(0),
1267+
0,
1268+
};
1269+
1270+
static const struct ad7768_chip_info ad7768_chip_info = {
1271+
.name = "ad7768-1",
1272+
.channel_spec = ad7768_channels,
1273+
.num_channels = ARRAY_SIZE(ad7768_channels),
1274+
.available_masks = ad7768_channel_masks,
1275+
};
1276+
12521277
static int ad7768_probe(struct spi_device *spi)
12531278
{
12541279
struct ad7768_state *st;
@@ -1293,11 +1318,17 @@ static int ad7768_probe(struct spi_device *spi)
12931318
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
12941319
st->irq = spi->irq;
12951320

1321+
st->chip = spi_get_device_match_data(spi);
1322+
if (!st->chip)
1323+
return dev_err_probe(&spi->dev, -ENODEV,
1324+
"Could not find chip info data\n");
1325+
12961326
mutex_init(&st->lock);
12971327

1298-
indio_dev->channels = ad7768_channels;
1299-
indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
1300-
indio_dev->name = spi_get_device_id(spi)->name;
1328+
indio_dev->channels = st->chip->channel_spec;
1329+
indio_dev->num_channels = st->chip->num_channels;
1330+
indio_dev->available_scan_masks = st->chip->available_masks;
1331+
indio_dev->name = st->chip->name;
13011332
indio_dev->info = &ad7768_info;
13021333
indio_dev->modes = INDIO_DIRECT_MODE;
13031334

@@ -1307,7 +1338,7 @@ static int ad7768_probe(struct spi_device *spi)
13071338
return ret;
13081339
}
13091340

1310-
ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels));
1341+
ret = ad7768_set_channel_label(indio_dev, st->chip->num_channels);
13111342
if (ret)
13121343
return ret;
13131344

@@ -1322,13 +1353,13 @@ static int ad7768_probe(struct spi_device *spi)
13221353
}
13231354

13241355
static const struct spi_device_id ad7768_id_table[] = {
1325-
{ "ad7768-1", 0 },
1356+
{ "ad7768-1", (kernel_ulong_t)&ad7768_chip_info },
13261357
{}
13271358
};
13281359
MODULE_DEVICE_TABLE(spi, ad7768_id_table);
13291360

13301361
static const struct of_device_id ad7768_of_match[] = {
1331-
{ .compatible = "adi,ad7768-1" },
1362+
{ .compatible = "adi,ad7768-1", .data = &ad7768_chip_info },
13321363
{ },
13331364
};
13341365
MODULE_DEVICE_TABLE(of, ad7768_of_match);

0 commit comments

Comments
 (0)