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 = 0,\
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 ;
@@ -1279,6 +1292,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
1279
1292
return 0 ;
1280
1293
}
1281
1294
1295
+ static const unsigned long ad7768_channel_masks [] = {
1296
+ BIT (0 ),
1297
+ 0 ,
1298
+ };
1299
+
1300
+ static const struct ad7768_chip_info ad7768_chip_info = {
1301
+ .name = "ad7768-1" ,
1302
+ .channel_spec = ad7768_channels ,
1303
+ .num_channels = 1 ,
1304
+ .available_masks = ad7768_channel_masks ,
1305
+ };
1306
+
1282
1307
static int ad7768_probe (struct spi_device * spi )
1283
1308
{
1284
1309
struct ad7768_state * st ;
@@ -1323,11 +1348,16 @@ static int ad7768_probe(struct spi_device *spi)
1323
1348
st -> spi_is_dma_mapped = spi_engine_ex_offload_supported (spi );
1324
1349
st -> irq = spi -> irq ;
1325
1350
1351
+ st -> chip = spi_get_device_match_data (spi );
1352
+ if (!st -> chip )
1353
+ return dev_err_probe (& spi -> dev , - ENODEV ,
1354
+ "Could not find chip info data\n" );
1355
+
1326
1356
mutex_init (& st -> lock );
1327
1357
1328
- indio_dev -> channels = ad7768_channels ;
1329
- indio_dev -> num_channels = ARRAY_SIZE ( ad7768_channels ) ;
1330
- indio_dev -> name = spi_get_device_id ( spi ) -> name ;
1358
+ indio_dev -> channels = st -> chip -> channel_spec ;
1359
+ indio_dev -> num_channels = st -> chip -> num_channels ;
1360
+ indio_dev -> name = st -> chip -> name ;
1331
1361
indio_dev -> info = & ad7768_info ;
1332
1362
indio_dev -> modes = INDIO_DIRECT_MODE ;
1333
1363
@@ -1337,7 +1367,7 @@ static int ad7768_probe(struct spi_device *spi)
1337
1367
return ret ;
1338
1368
}
1339
1369
1340
- ret = ad7768_set_channel_label (indio_dev , ARRAY_SIZE ( ad7768_channels ) );
1370
+ ret = ad7768_set_channel_label (indio_dev , st -> chip -> num_channels );
1341
1371
if (ret )
1342
1372
return ret ;
1343
1373
@@ -1352,13 +1382,13 @@ static int ad7768_probe(struct spi_device *spi)
1352
1382
}
1353
1383
1354
1384
static const struct spi_device_id ad7768_id_table [] = {
1355
- { "ad7768-1" , 0 },
1385
+ { "ad7768-1" , ( kernel_ulong_t ) & ad7768_chip_info },
1356
1386
{}
1357
1387
};
1358
1388
MODULE_DEVICE_TABLE (spi , ad7768_id_table );
1359
1389
1360
1390
static const struct of_device_id ad7768_of_match [] = {
1361
- { .compatible = "adi,ad7768-1" },
1391
+ { .compatible = "adi,ad7768-1" , . data = & ad7768_chip_info },
1362
1392
{ },
1363
1393
};
1364
1394
MODULE_DEVICE_TABLE (of , ad7768_of_match );
0 commit comments