Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: ad9467: check for backend capabilities

Add capability checks for operation with backends that do not necessarily
support full set of features, but are otherwise compatible with the device.
This ensures a fully functional device, but with limited capabilities.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Tomas Melin and committed by
Jonathan Cameron
2e471104 89443dc7

+49 -31
+49 -31
drivers/iio/adc/ad9467.c
··· 925 925 return ret; 926 926 927 927 guard(mutex)(&st->lock); 928 - return ad9467_calibrate(st); 928 + 929 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) 930 + return ad9467_calibrate(st); 931 + 932 + return 0; 929 933 } 930 934 931 935 static int ad9467_write_raw(struct iio_dev *indio_dev, ··· 1135 1131 len = scnprintf(buf, sizeof(buf), "Running \"%s\" Test:\n\t", 1136 1132 ad9467_test_modes[chan->mode]); 1137 1133 1138 - ret = iio_backend_debugfs_print_chan_status(st->back, chan->idx, 1139 - buf + len, 1140 - sizeof(buf) - len); 1141 - if (ret < 0) 1142 - return ret; 1143 - len += ret; 1134 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) { 1135 + ret = iio_backend_debugfs_print_chan_status(st->back, 1136 + chan->idx, 1137 + buf + len, 1138 + sizeof(buf) - len); 1139 + if (ret < 0) 1140 + return ret; 1141 + len += ret; 1142 + } 1144 1143 } else if (chan->mode == AN877_ADC_TESTMODE_OFF) { 1145 1144 len = scnprintf(buf, sizeof(buf), "No test Running...\n"); 1146 1145 } else { ··· 1182 1175 if (mode == AN877_ADC_TESTMODE_OFF) { 1183 1176 unsigned int out_mode; 1184 1177 1185 - if (chan->mode == AN877_ADC_TESTMODE_PN9_SEQ || 1186 - chan->mode == AN877_ADC_TESTMODE_PN23_SEQ) { 1187 - ret = ad9467_backend_testmode_off(st, chan->idx); 1188 - if (ret) 1189 - return ret; 1178 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) { 1179 + if (chan->mode == AN877_ADC_TESTMODE_PN9_SEQ || 1180 + chan->mode == AN877_ADC_TESTMODE_PN23_SEQ) { 1181 + ret = ad9467_backend_testmode_off(st, chan->idx); 1182 + if (ret) 1183 + return ret; 1184 + } 1190 1185 } 1191 1186 1192 1187 ret = ad9467_testmode_set(st, chan->idx, mode); ··· 1214 1205 return ret; 1215 1206 1216 1207 /* some patterns have a backend matching monitoring block */ 1217 - if (mode == AN877_ADC_TESTMODE_PN9_SEQ) { 1218 - ret = ad9467_backend_testmode_on(st, chan->idx, 1208 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) { 1209 + if (mode == AN877_ADC_TESTMODE_PN9_SEQ) { 1210 + ret = ad9467_backend_testmode_on(st, chan->idx, 1219 1211 IIO_BACKEND_ADI_PRBS_9A); 1220 - if (ret) 1221 - return ret; 1222 - } else if (mode == AN877_ADC_TESTMODE_PN23_SEQ) { 1223 - ret = ad9467_backend_testmode_on(st, chan->idx, 1212 + if (ret) 1213 + return ret; 1214 + } else if (mode == AN877_ADC_TESTMODE_PN23_SEQ) { 1215 + ret = ad9467_backend_testmode_on(st, chan->idx, 1224 1216 IIO_BACKEND_ADI_PRBS_23A); 1225 - if (ret) 1226 - return ret; 1217 + if (ret) 1218 + return ret; 1219 + } 1227 1220 } 1228 1221 } 1229 1222 ··· 1291 1280 if (!st->chan_test) 1292 1281 return; 1293 1282 1294 - debugfs_create_file("calibration_table_dump", 0400, d, st, 1295 - &ad9467_calib_table_fops); 1283 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) 1284 + debugfs_create_file("calibration_table_dump", 0400, d, st, 1285 + &ad9467_calib_table_fops); 1296 1286 1297 1287 for (chan = 0; chan < st->info->num_channels; chan++) { 1298 1288 snprintf(attr_name, sizeof(attr_name), "in_voltage%u_test_mode", ··· 1368 1356 if (ret) 1369 1357 return ret; 1370 1358 1371 - ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); 1372 - if (ret) 1373 - return ret; 1359 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_BUFFER)) { 1360 + ret = devm_iio_backend_request_buffer(dev, st->back, indio_dev); 1361 + if (ret) 1362 + return ret; 1363 + } 1374 1364 1375 - ret = devm_iio_backend_enable(dev, st->back); 1376 - if (ret) 1377 - return ret; 1365 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_ENABLE)) { 1366 + ret = devm_iio_backend_enable(dev, st->back); 1367 + if (ret) 1368 + return ret; 1369 + } 1378 1370 1379 - ret = ad9467_calibrate(st); 1380 - if (ret) 1381 - return ret; 1371 + if (iio_backend_has_caps(st->back, IIO_BACKEND_CAP_CALIBRATION)) { 1372 + ret = ad9467_calibrate(st); 1373 + if (ret) 1374 + return ret; 1375 + } 1382 1376 1383 1377 ret = devm_iio_device_register(dev, indio_dev); 1384 1378 if (ret)