Skip to content

Commit b314f7b

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 700a522 commit b314f7b

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
@@ -105,6 +105,8 @@
105105
#define AD7768_RD_FLAG_MSK(x) (BIT(6) | ((x) & 0x3F))
106106
#define AD7768_WR_FLAG_MSK(x) ((x) & 0x3F)
107107

108+
#define AD7768_CHAN_INFO_NONE 0
109+
108110
enum ad7768_conv_mode {
109111
AD7768_CONTINUOUS,
110112
AD7768_ONE_SHOT,
@@ -278,23 +280,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
278280
{ },
279281
};
280282

283+
#define AD7768_CHAN(_idx, _msk_avail) { \
284+
.type = IIO_VOLTAGE,\
285+
.info_mask_separate_available = _msk_avail,\
286+
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),\
287+
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
288+
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
289+
.ext_info = ad7768_ext_info,\
290+
.indexed = 1,\
291+
.channel = _idx,\
292+
.scan_index = 0,\
293+
.has_ext_scan_type = 1,\
294+
.ext_scan_type = ad7768_scan_type,\
295+
.num_ext_scan_type = ARRAY_SIZE(ad7768_scan_type),\
296+
}
297+
281298
static const struct iio_chan_spec ad7768_channels[] = {
282-
{
283-
.type = IIO_VOLTAGE,
284-
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
285-
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
286-
.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),
287-
.ext_info = ad7768_ext_info,
288-
.indexed = 1,
289-
.channel = 0,
290-
.scan_index = 0,
291-
.has_ext_scan_type = 1,
292-
.ext_scan_type = ad7768_scan_type,
293-
.num_ext_scan_type = ARRAY_SIZE(ad7768_scan_type),
294-
},
299+
AD7768_CHAN(0, AD7768_CHAN_INFO_NONE),
300+
};
301+
302+
struct ad7768_chip_info {
303+
const char *name;
304+
const struct iio_chan_spec *channel_spec;
305+
const unsigned long *available_masks;
306+
int num_channels;
295307
};
296308

297309
struct ad7768_state {
310+
const struct ad7768_chip_info *chip;
298311
struct spi_device *spi;
299312
struct regulator *vref;
300313
struct mutex lock;
@@ -1208,6 +1221,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
12081221
return 0;
12091222
}
12101223

1224+
static const unsigned long ad7768_channel_masks[] = {
1225+
BIT(0),
1226+
0,
1227+
};
1228+
1229+
static const struct ad7768_chip_info ad7768_chip_info = {
1230+
.name = "ad7768-1",
1231+
.channel_spec = ad7768_channels,
1232+
.num_channels = 1,
1233+
.available_masks = ad7768_channel_masks,
1234+
};
1235+
12111236
static int ad7768_probe(struct spi_device *spi)
12121237
{
12131238
struct ad7768_state *st;
@@ -1252,11 +1277,16 @@ static int ad7768_probe(struct spi_device *spi)
12521277
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
12531278
st->irq = spi->irq;
12541279

1280+
st->chip = spi_get_device_match_data(spi);
1281+
if (!st->chip)
1282+
return dev_err_probe(&spi->dev, -ENODEV,
1283+
"Could not find chip info data\n");
1284+
12551285
mutex_init(&st->lock);
12561286

1257-
indio_dev->channels = ad7768_channels;
1258-
indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
1259-
indio_dev->name = spi_get_device_id(spi)->name;
1287+
indio_dev->channels = st->chip->channel_spec;
1288+
indio_dev->num_channels = st->chip->num_channels;
1289+
indio_dev->name = st->chip->name;
12601290
indio_dev->info = &ad7768_info;
12611291
indio_dev->modes = INDIO_DIRECT_MODE;
12621292

@@ -1266,7 +1296,7 @@ static int ad7768_probe(struct spi_device *spi)
12661296
return ret;
12671297
}
12681298

1269-
ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels));
1299+
ret = ad7768_set_channel_label(indio_dev, st->chip->num_channels);
12701300
if (ret)
12711301
return ret;
12721302

@@ -1281,13 +1311,13 @@ static int ad7768_probe(struct spi_device *spi)
12811311
}
12821312

12831313
static const struct spi_device_id ad7768_id_table[] = {
1284-
{ "ad7768-1", 0 },
1314+
{ "ad7768-1", (kernel_ulong_t)&ad7768_chip_info },
12851315
{}
12861316
};
12871317
MODULE_DEVICE_TABLE(spi, ad7768_id_table);
12881318

12891319
static const struct of_device_id ad7768_of_match[] = {
1290-
{ .compatible = "adi,ad7768-1" },
1320+
{ .compatible = "adi,ad7768-1", .data = &ad7768_chip_info },
12911321
{ },
12921322
};
12931323
MODULE_DEVICE_TABLE(of, ad7768_of_match);

0 commit comments

Comments
 (0)