114
114
#define WIDEBAND_DEC_RATE_MIN 32
115
115
#define WIDEBAND_DEC_RATE_MAX 1024
116
116
117
+ #define AD7768_CHAN_INFO_NONE 0
118
+
117
119
enum {
118
120
DEC_RATE ,
119
121
};
@@ -267,23 +269,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
267
269
{ },
268
270
};
269
271
272
+ #define AD7768_CHAN (_idx , _msk_avail ) { \
273
+ .type = IIO_VOLTAGE,\
274
+ .info_mask_separate_available = _msk_avail,\
275
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW),\
276
+ .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),\
277
+ .info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SAMP_FREQ),\
278
+ .ext_info = ad7768_ext_info,\
279
+ .indexed = 1,\
280
+ .channel = _idx,\
281
+ .scan_index = _idx,\
282
+ .has_ext_scan_type = 1,\
283
+ .ext_scan_type = ad7768_scan_type,\
284
+ .num_ext_scan_type = ARRAY_SIZE(ad7768_scan_type),\
285
+ }
286
+
270
287
static const struct iio_chan_spec ad7768_channels [] = {
271
- {
272
- .type = IIO_VOLTAGE ,
273
- .info_mask_separate = BIT (IIO_CHAN_INFO_RAW ),
274
- .info_mask_shared_by_type = BIT (IIO_CHAN_INFO_SCALE ),
275
- .info_mask_shared_by_all = BIT (IIO_CHAN_INFO_SAMP_FREQ ),
276
- .ext_info = ad7768_ext_info ,
277
- .indexed = 1 ,
278
- .channel = 0 ,
279
- .scan_index = 0 ,
280
- .has_ext_scan_type = 1 ,
281
- .ext_scan_type = ad7768_scan_type ,
282
- .num_ext_scan_type = ARRAY_SIZE (ad7768_scan_type ),
283
- },
288
+ AD7768_CHAN (0 , AD7768_CHAN_INFO_NONE ),
289
+ };
290
+
291
+ struct ad7768_chip_info {
292
+ const char * name ;
293
+ const struct iio_chan_spec * channel_spec ;
294
+ const unsigned long * available_masks ;
295
+ int num_channels ;
284
296
};
285
297
286
298
struct ad7768_state {
299
+ const struct ad7768_chip_info * chip ;
287
300
struct spi_device * spi ;
288
301
struct regulator * vref ;
289
302
struct mutex lock ;
@@ -1249,6 +1262,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
1249
1262
return 0 ;
1250
1263
}
1251
1264
1265
+ static const unsigned long ad7768_channel_masks [] = {
1266
+ BIT (0 ),
1267
+ 0 ,
1268
+ };
1269
+
1270
+ static const struct ad7768_chip_info ad7768_chip_info = {
1271
+ .name = "ad7768-1" ,
1272
+ .channel_spec = ad7768_channels ,
1273
+ .num_channels = ARRAY_SIZE (ad7768_channels ),
1274
+ .available_masks = ad7768_channel_masks ,
1275
+ };
1276
+
1252
1277
static int ad7768_probe (struct spi_device * spi )
1253
1278
{
1254
1279
struct ad7768_state * st ;
@@ -1293,11 +1318,17 @@ static int ad7768_probe(struct spi_device *spi)
1293
1318
st -> spi_is_dma_mapped = spi_engine_ex_offload_supported (spi );
1294
1319
st -> irq = spi -> irq ;
1295
1320
1321
+ st -> chip = spi_get_device_match_data (spi );
1322
+ if (!st -> chip )
1323
+ return dev_err_probe (& spi -> dev , - ENODEV ,
1324
+ "Could not find chip info data\n" );
1325
+
1296
1326
mutex_init (& st -> lock );
1297
1327
1298
- indio_dev -> channels = ad7768_channels ;
1299
- indio_dev -> num_channels = ARRAY_SIZE (ad7768_channels );
1300
- indio_dev -> name = spi_get_device_id (spi )-> name ;
1328
+ indio_dev -> channels = st -> chip -> channel_spec ;
1329
+ indio_dev -> num_channels = st -> chip -> num_channels ;
1330
+ indio_dev -> available_scan_masks = st -> chip -> available_masks ;
1331
+ indio_dev -> name = st -> chip -> name ;
1301
1332
indio_dev -> info = & ad7768_info ;
1302
1333
indio_dev -> modes = INDIO_DIRECT_MODE ;
1303
1334
@@ -1307,7 +1338,7 @@ static int ad7768_probe(struct spi_device *spi)
1307
1338
return ret ;
1308
1339
}
1309
1340
1310
- ret = ad7768_set_channel_label (indio_dev , ARRAY_SIZE ( ad7768_channels ) );
1341
+ ret = ad7768_set_channel_label (indio_dev , st -> chip -> num_channels );
1311
1342
if (ret )
1312
1343
return ret ;
1313
1344
@@ -1322,13 +1353,13 @@ static int ad7768_probe(struct spi_device *spi)
1322
1353
}
1323
1354
1324
1355
static const struct spi_device_id ad7768_id_table [] = {
1325
- { "ad7768-1" , 0 },
1356
+ { "ad7768-1" , ( kernel_ulong_t ) & ad7768_chip_info },
1326
1357
{}
1327
1358
};
1328
1359
MODULE_DEVICE_TABLE (spi , ad7768_id_table );
1329
1360
1330
1361
static const struct of_device_id ad7768_of_match [] = {
1331
- { .compatible = "adi,ad7768-1" },
1362
+ { .compatible = "adi,ad7768-1" , . data = & ad7768_chip_info },
1332
1363
{ },
1333
1364
};
1334
1365
MODULE_DEVICE_TABLE (of , ad7768_of_match );
0 commit comments