Skip to content

Commit dd1c8ab

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 19d05a3 commit dd1c8ab

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;
@@ -1183,6 +1196,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
11831196
return 0;
11841197
}
11851198

1199+
static const unsigned long ad7768_channel_masks[] = {
1200+
BIT(0),
1201+
0,
1202+
};
1203+
1204+
static const struct ad7768_chip_info ad7768_chip_info = {
1205+
.name = "ad7768-1",
1206+
.channel_spec = ad7768_channels,
1207+
.num_channels = 1,
1208+
.available_masks = ad7768_channel_masks,
1209+
};
1210+
11861211
static int ad7768_probe(struct spi_device *spi)
11871212
{
11881213
struct ad7768_state *st;
@@ -1227,11 +1252,16 @@ static int ad7768_probe(struct spi_device *spi)
12271252
st->spi_is_dma_mapped = spi_engine_ex_offload_supported(spi);
12281253
st->irq = spi->irq;
12291254

1255+
st->chip = spi_get_device_match_data(spi);
1256+
if (!st->chip)
1257+
return dev_err_probe(&spi->dev, -ENODEV,
1258+
"Could not find chip info data\n");
1259+
12301260
mutex_init(&st->lock);
12311261

1232-
indio_dev->channels = ad7768_channels;
1233-
indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
1234-
indio_dev->name = spi_get_device_id(spi)->name;
1262+
indio_dev->channels = st->chip->channel_spec;
1263+
indio_dev->num_channels = st->chip->num_channels;
1264+
indio_dev->name = st->chip->name;
12351265
indio_dev->info = &ad7768_info;
12361266
indio_dev->modes = INDIO_DIRECT_MODE;
12371267

@@ -1241,7 +1271,7 @@ static int ad7768_probe(struct spi_device *spi)
12411271
return ret;
12421272
}
12431273

1244-
ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels));
1274+
ret = ad7768_set_channel_label(indio_dev, st->chip->num_channels);
12451275
if (ret)
12461276
return ret;
12471277

@@ -1256,13 +1286,13 @@ static int ad7768_probe(struct spi_device *spi)
12561286
}
12571287

12581288
static const struct spi_device_id ad7768_id_table[] = {
1259-
{ "ad7768-1", 0 },
1289+
{ "ad7768-1", (kernel_ulong_t)&ad7768_chip_info },
12601290
{}
12611291
};
12621292
MODULE_DEVICE_TABLE(spi, ad7768_id_table);
12631293

12641294
static const struct of_device_id ad7768_of_match[] = {
1265-
{ .compatible = "adi,ad7768-1" },
1295+
{ .compatible = "adi,ad7768-1", .data = &ad7768_chip_info },
12661296
{ },
12671297
};
12681298
MODULE_DEVICE_TABLE(of, ad7768_of_match);

0 commit comments

Comments
 (0)