Skip to content

Commit 5c26081

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 0a1f277 commit 5c26081

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 = _idx,\
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;
@@ -1297,6 +1310,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
12971310
return 0;
12981311
}
12991312

1313+
static const unsigned long ad7768_channel_masks[] = {
1314+
BIT(0),
1315+
0,
1316+
};
1317+
1318+
static const struct ad7768_chip_info ad7768_chip_info = {
1319+
.name = "ad7768-1",
1320+
.channel_spec = ad7768_channels,
1321+
.num_channels = ARRAY_SIZE(ad7768_channels),
1322+
.available_masks = ad7768_channel_masks,
1323+
};
1324+
13001325
static int ad7768_probe(struct spi_device *spi)
13011326
{
13021327
struct ad7768_state *st;
@@ -1341,11 +1366,16 @@ static int ad7768_probe(struct spi_device *spi)
13411366
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
13421367
st->irq = spi->irq;
13431368

1369+
st->chip = spi_get_device_match_data(spi);
1370+
if (!st->chip)
1371+
return dev_err_probe(&spi->dev, -ENODEV,
1372+
"Could not find chip info data\n");
1373+
13441374
mutex_init(&st->lock);
13451375

1346-
indio_dev->channels = ad7768_channels;
1347-
indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
1348-
indio_dev->name = spi_get_device_id(spi)->name;
1376+
indio_dev->channels = st->chip->channel_spec;
1377+
indio_dev->num_channels = st->chip->num_channels;
1378+
indio_dev->name = st->chip->name;
13491379
indio_dev->info = &ad7768_info;
13501380
indio_dev->modes = INDIO_DIRECT_MODE;
13511381

@@ -1355,7 +1385,7 @@ static int ad7768_probe(struct spi_device *spi)
13551385
return ret;
13561386
}
13571387

1358-
ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels));
1388+
ret = ad7768_set_channel_label(indio_dev, st->chip->num_channels);
13591389
if (ret)
13601390
return ret;
13611391

@@ -1370,13 +1400,13 @@ static int ad7768_probe(struct spi_device *spi)
13701400
}
13711401

13721402
static const struct spi_device_id ad7768_id_table[] = {
1373-
{ "ad7768-1", 0 },
1403+
{ "ad7768-1", (kernel_ulong_t)&ad7768_chip_info },
13741404
{}
13751405
};
13761406
MODULE_DEVICE_TABLE(spi, ad7768_id_table);
13771407

13781408
static const struct of_device_id ad7768_of_match[] = {
1379-
{ .compatible = "adi,ad7768-1" },
1409+
{ .compatible = "adi,ad7768-1", .data = &ad7768_chip_info },
13801410
{ },
13811411
};
13821412
MODULE_DEVICE_TABLE(of, ad7768_of_match);

0 commit comments

Comments
 (0)