113
113
#define WIDEBAND_DEC_RATE_MIN 32
114
114
#define WIDEBAND_DEC_RATE_MAX 1024
115
115
116
+ #define AD7768_CHAN_INFO_NONE 0
117
+
116
118
enum {
117
119
DEC_RATE ,
118
120
};
@@ -266,23 +268,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
266
268
{ },
267
269
};
268
270
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
+
269
286
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 ;
283
295
};
284
296
285
297
struct ad7768_state {
298
+ const struct ad7768_chip_info * chip ;
286
299
struct spi_device * spi ;
287
300
struct regulator * vref ;
288
301
struct mutex lock ;
@@ -1287,6 +1300,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
1287
1300
return 0 ;
1288
1301
}
1289
1302
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
+
1290
1315
static int ad7768_probe (struct spi_device * spi )
1291
1316
{
1292
1317
struct ad7768_state * st ;
@@ -1331,11 +1356,17 @@ static int ad7768_probe(struct spi_device *spi)
1331
1356
st -> spi_is_dma_mapped = spi_engine_ex_offload_supported (spi );
1332
1357
st -> irq = spi -> irq ;
1333
1358
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
+
1334
1364
mutex_init (& st -> lock );
1335
1365
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 ;
1339
1370
indio_dev -> info = & ad7768_info ;
1340
1371
indio_dev -> modes = INDIO_DIRECT_MODE ;
1341
1372
@@ -1345,7 +1376,7 @@ static int ad7768_probe(struct spi_device *spi)
1345
1376
return ret ;
1346
1377
}
1347
1378
1348
- ret = ad7768_set_channel_label (indio_dev , ARRAY_SIZE ( ad7768_channels ) );
1379
+ ret = ad7768_set_channel_label (indio_dev , st -> chip -> num_channels );
1349
1380
if (ret )
1350
1381
return ret ;
1351
1382
@@ -1360,13 +1391,13 @@ static int ad7768_probe(struct spi_device *spi)
1360
1391
}
1361
1392
1362
1393
static const struct spi_device_id ad7768_id_table [] = {
1363
- { "ad7768-1" , 0 },
1394
+ { "ad7768-1" , ( kernel_ulong_t ) & ad7768_chip_info },
1364
1395
{}
1365
1396
};
1366
1397
MODULE_DEVICE_TABLE (spi , ad7768_id_table );
1367
1398
1368
1399
static const struct of_device_id ad7768_of_match [] = {
1369
- { .compatible = "adi,ad7768-1" },
1400
+ { .compatible = "adi,ad7768-1" , . data = & ad7768_chip_info },
1370
1401
{ },
1371
1402
};
1372
1403
MODULE_DEVICE_TABLE (of , ad7768_of_match );
0 commit comments