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 ;
@@ -1183,6 +1196,18 @@ static int ad7768_set_channel_label(struct iio_dev *indio_dev,
1183
1196
return 0 ;
1184
1197
}
1185
1198
1199
+ static const unsigned long ad7768_channel_masks [] = {
1200
+ BIT (0 ),
1201
+ 0 ,
1202
+ };
1203
+
1204
+ static const struct ad7768_chip_info ad7768_chip_info = {
1205
+ .name = "ad7768-1" ,
1206
+ .channel_spec = ad7768_channels ,
1207
+ .num_channels = 1 ,
1208
+ .available_masks = ad7768_channel_masks ,
1209
+ };
1210
+
1186
1211
static int ad7768_probe (struct spi_device * spi )
1187
1212
{
1188
1213
struct ad7768_state * st ;
@@ -1227,11 +1252,16 @@ static int ad7768_probe(struct spi_device *spi)
1227
1252
st -> spi_is_dma_mapped = spi_engine_ex_offload_supported (spi );
1228
1253
st -> irq = spi -> irq ;
1229
1254
1255
+ st -> chip = spi_get_device_match_data (spi );
1256
+ if (!st -> chip )
1257
+ return dev_err_probe (& spi -> dev , - ENODEV ,
1258
+ "Could not find chip info data\n" );
1259
+
1230
1260
mutex_init (& st -> lock );
1231
1261
1232
- indio_dev -> channels = ad7768_channels ;
1233
- indio_dev -> num_channels = ARRAY_SIZE ( ad7768_channels ) ;
1234
- indio_dev -> name = spi_get_device_id ( spi ) -> name ;
1262
+ indio_dev -> channels = st -> chip -> channel_spec ;
1263
+ indio_dev -> num_channels = st -> chip -> num_channels ;
1264
+ indio_dev -> name = st -> chip -> name ;
1235
1265
indio_dev -> info = & ad7768_info ;
1236
1266
indio_dev -> modes = INDIO_DIRECT_MODE ;
1237
1267
@@ -1241,7 +1271,7 @@ static int ad7768_probe(struct spi_device *spi)
1241
1271
return ret ;
1242
1272
}
1243
1273
1244
- ret = ad7768_set_channel_label (indio_dev , ARRAY_SIZE ( ad7768_channels ) );
1274
+ ret = ad7768_set_channel_label (indio_dev , st -> chip -> num_channels );
1245
1275
if (ret )
1246
1276
return ret ;
1247
1277
@@ -1256,13 +1286,13 @@ static int ad7768_probe(struct spi_device *spi)
1256
1286
}
1257
1287
1258
1288
static const struct spi_device_id ad7768_id_table [] = {
1259
- { "ad7768-1" , 0 },
1289
+ { "ad7768-1" , ( kernel_ulong_t ) & ad7768_chip_info },
1260
1290
{}
1261
1291
};
1262
1292
MODULE_DEVICE_TABLE (spi , ad7768_id_table );
1263
1293
1264
1294
static const struct of_device_id ad7768_of_match [] = {
1265
- { .compatible = "adi,ad7768-1" },
1295
+ { .compatible = "adi,ad7768-1" , . data = & ad7768_chip_info },
1266
1296
{ },
1267
1297
};
1268
1298
MODULE_DEVICE_TABLE (of , ad7768_of_match );
0 commit comments