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
};
@@ -272,23 +274,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
272
274
{ },
273
275
};
274
276
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
+
275
292
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 ;
289
301
};
290
302
291
303
struct ad7768_state {
304
+ const struct ad7768_chip_info * chip ;
292
305
struct spi_device * spi ;
293
306
struct regulator * vref ;
294
307
struct mutex lock ;
@@ -1297,6 +1310,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
1297
1310
return 0 ;
1298
1311
}
1299
1312
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
+
1300
1325
static int ad7768_probe (struct spi_device * spi )
1301
1326
{
1302
1327
struct ad7768_state * st ;
@@ -1341,11 +1366,16 @@ static int ad7768_probe(struct spi_device *spi)
1341
1366
st -> spi_is_dma_mapped = spi_engine_ex_offload_supported (spi );
1342
1367
st -> irq = spi -> irq ;
1343
1368
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
+
1344
1374
mutex_init (& st -> lock );
1345
1375
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 ;
1349
1379
indio_dev -> info = & ad7768_info ;
1350
1380
indio_dev -> modes = INDIO_DIRECT_MODE ;
1351
1381
@@ -1355,7 +1385,7 @@ static int ad7768_probe(struct spi_device *spi)
1355
1385
return ret ;
1356
1386
}
1357
1387
1358
- ret = ad7768_set_channel_label (indio_dev , ARRAY_SIZE ( ad7768_channels ) );
1388
+ ret = ad7768_set_channel_label (indio_dev , st -> chip -> num_channels );
1359
1389
if (ret )
1360
1390
return ret ;
1361
1391
@@ -1370,13 +1400,13 @@ static int ad7768_probe(struct spi_device *spi)
1370
1400
}
1371
1401
1372
1402
static const struct spi_device_id ad7768_id_table [] = {
1373
- { "ad7768-1" , 0 },
1403
+ { "ad7768-1" , ( kernel_ulong_t ) & ad7768_chip_info },
1374
1404
{}
1375
1405
};
1376
1406
MODULE_DEVICE_TABLE (spi , ad7768_id_table );
1377
1407
1378
1408
static const struct of_device_id ad7768_of_match [] = {
1379
- { .compatible = "adi,ad7768-1" },
1409
+ { .compatible = "adi,ad7768-1" , . data = & ad7768_chip_info },
1380
1410
{ },
1381
1411
};
1382
1412
MODULE_DEVICE_TABLE (of , ad7768_of_match );
0 commit comments