Skip to content

Commit 593b88a

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 300cd94 commit 593b88a

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
@@ -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
};
@@ -266,23 +268,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
266268
{ },
267269
};
268270

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

285297
struct ad7768_state {
298+
const struct ad7768_chip_info *chip;
286299
struct spi_device *spi;
287300
struct regulator *vref;
288301
struct mutex lock;
@@ -1287,6 +1300,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
12871300
return 0;
12881301
}
12891302

1303+
static const unsigned long ad7768_channel_masks[] = {
1304+
BIT(0),
1305+
0,
1306+
};
1307+
1308+
static const struct ad7768_chip_info ad7768_chip_info = {
1309+
.name = "ad7768-1",
1310+
.channel_spec = ad7768_channels,
1311+
.num_channels = ARRAY_SIZE(ad7768_channels),
1312+
.available_masks = ad7768_channel_masks,
1313+
};
1314+
12901315
static int ad7768_probe(struct spi_device *spi)
12911316
{
12921317
struct ad7768_state *st;
@@ -1331,11 +1356,17 @@ static int ad7768_probe(struct spi_device *spi)
13311356
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
13321357
st->irq = spi->irq;
13331358

1359+
st->chip = spi_get_device_match_data(spi);
1360+
if (!st->chip)
1361+
return dev_err_probe(&spi->dev, -ENODEV,
1362+
"Could not find chip info data\n");
1363+
13341364
mutex_init(&st->lock);
13351365

1336-
indio_dev->channels = ad7768_channels;
1337-
indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
1338-
indio_dev->name = spi_get_device_id(spi)->name;
1366+
indio_dev->channels = st->chip->channel_spec;
1367+
indio_dev->num_channels = st->chip->num_channels;
1368+
indio_dev->available_scan_masks = st->chip->available_masks;
1369+
indio_dev->name = st->chip->name;
13391370
indio_dev->info = &ad7768_info;
13401371
indio_dev->modes = INDIO_DIRECT_MODE;
13411372

@@ -1345,7 +1376,7 @@ static int ad7768_probe(struct spi_device *spi)
13451376
return ret;
13461377
}
13471378

1348-
ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels));
1379+
ret = ad7768_set_channel_label(indio_dev, st->chip->num_channels);
13491380
if (ret)
13501381
return ret;
13511382

@@ -1360,13 +1391,13 @@ static int ad7768_probe(struct spi_device *spi)
13601391
}
13611392

13621393
static const struct spi_device_id ad7768_id_table[] = {
1363-
{ "ad7768-1", 0 },
1394+
{ "ad7768-1", (kernel_ulong_t)&ad7768_chip_info },
13641395
{}
13651396
};
13661397
MODULE_DEVICE_TABLE(spi, ad7768_id_table);
13671398

13681399
static const struct of_device_id ad7768_of_match[] = {
1369-
{ .compatible = "adi,ad7768-1" },
1400+
{ .compatible = "adi,ad7768-1", .data = &ad7768_chip_info },
13701401
{ },
13711402
};
13721403
MODULE_DEVICE_TABLE(of, ad7768_of_match);

0 commit comments

Comments
 (0)