105
105
#define AD7768_RD_FLAG_MSK (x ) (BIT(6) | ((x) & 0x3F))
106
106
#define AD7768_WR_FLAG_MSK (x ) ((x) & 0x3F)
107
107
108
+ #define AD7768_CHAN_INFO_NONE 0
109
+
108
110
enum ad7768_conv_mode {
109
111
AD7768_CONTINUOUS ,
110
112
AD7768_ONE_SHOT ,
@@ -278,23 +280,34 @@ static struct iio_chan_spec_ext_info ad7768_ext_info[] = {
278
280
{ },
279
281
};
280
282
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
+
281
298
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 ;
295
307
};
296
308
297
309
struct ad7768_state {
310
+ const struct ad7768_chip_info * chip ;
298
311
struct spi_device * spi ;
299
312
struct regulator * vref ;
300
313
struct mutex lock ;
@@ -1208,6 +1221,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
1208
1221
return 0 ;
1209
1222
}
1210
1223
1224
+ static const unsigned long ad7768_channel_masks [] = {
1225
+ BIT (0 ),
1226
+ 0 ,
1227
+ };
1228
+
1229
+ static const struct ad7768_chip_info ad7768_chip_info = {
1230
+ .name = "ad7768-1" ,
1231
+ .channel_spec = ad7768_channels ,
1232
+ .num_channels = 1 ,
1233
+ .available_masks = ad7768_channel_masks ,
1234
+ };
1235
+
1211
1236
static int ad7768_probe (struct spi_device * spi )
1212
1237
{
1213
1238
struct ad7768_state * st ;
@@ -1252,11 +1277,16 @@ static int ad7768_probe(struct spi_device *spi)
1252
1277
st -> spi_is_dma_mapped = spi_engine_ex_offload_supported (spi );
1253
1278
st -> irq = spi -> irq ;
1254
1279
1280
+ st -> chip = spi_get_device_match_data (spi );
1281
+ if (!st -> chip )
1282
+ return dev_err_probe (& spi -> dev , - ENODEV ,
1283
+ "Could not find chip info data\n" );
1284
+
1255
1285
mutex_init (& st -> lock );
1256
1286
1257
- indio_dev -> channels = ad7768_channels ;
1258
- indio_dev -> num_channels = ARRAY_SIZE ( ad7768_channels ) ;
1259
- indio_dev -> name = spi_get_device_id ( spi ) -> name ;
1287
+ indio_dev -> channels = st -> chip -> channel_spec ;
1288
+ indio_dev -> num_channels = st -> chip -> num_channels ;
1289
+ indio_dev -> name = st -> chip -> name ;
1260
1290
indio_dev -> info = & ad7768_info ;
1261
1291
indio_dev -> modes = INDIO_DIRECT_MODE ;
1262
1292
@@ -1266,7 +1296,7 @@ static int ad7768_probe(struct spi_device *spi)
1266
1296
return ret ;
1267
1297
}
1268
1298
1269
- ret = ad7768_set_channel_label (indio_dev , ARRAY_SIZE ( ad7768_channels ) );
1299
+ ret = ad7768_set_channel_label (indio_dev , st -> chip -> num_channels );
1270
1300
if (ret )
1271
1301
return ret ;
1272
1302
@@ -1281,13 +1311,13 @@ static int ad7768_probe(struct spi_device *spi)
1281
1311
}
1282
1312
1283
1313
static const struct spi_device_id ad7768_id_table [] = {
1284
- { "ad7768-1" , 0 },
1314
+ { "ad7768-1" , ( kernel_ulong_t ) & ad7768_chip_info },
1285
1315
{}
1286
1316
};
1287
1317
MODULE_DEVICE_TABLE (spi , ad7768_id_table );
1288
1318
1289
1319
static const struct of_device_id ad7768_of_match [] = {
1290
- { .compatible = "adi,ad7768-1" },
1320
+ { .compatible = "adi,ad7768-1" , . data = & ad7768_chip_info },
1291
1321
{ },
1292
1322
};
1293
1323
MODULE_DEVICE_TABLE (of , ad7768_of_match );
0 commit comments