aboutsummaryrefslogtreecommitdiffstats
path: root/tools/iio/generic_buffer.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-04-26 18:07:23 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2016-04-26 18:07:23 -0400
commit5a45e01d414636e144ab28b62089d0eb97f43ec2 (patch)
tree814ddaaceba0e759988c795a42728e91819af2c1 /tools/iio/generic_buffer.c
parent4145ba76b1f7f3296cc673c299084145e1267029 (diff)
parentfbced0e9465152d628ece5fd0d11de4e7a1f5ce5 (diff)
Merge tag 'iio-for-4.7b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-testing
Jonathan writes: 2nd set of new device support, features and cleanup for IIO in the 4.7 cycle. Bit of a bumper set for new drivers but plenty of other stuff here as well! New device support * ad5592R ADC/DAC - new driver supporting ad5592r and ad5593r combined ADC/DAC and gpio chips. * Aosong am2315 relative humidity - new driver with triggered buffer support in follow up patch. * bmi160 imu - new driver * bmp280 - bmp180 support - note there is support in the misc/bmp085 driver. Intent is to remove that driver long term. * invensense mpu6050 - cleanup leading to explicit support of mpu9150 with a good few cleanups along the way. * Hope RF hp03 pressure and temperature sensor. - new driver * maxim DS1803 potentiometer - new driver * maxim max44000 light and proximity sensor - new driver built in a series of steps to support pretty much everything. * ROHM BH1780 light sensor - new driver. There is an existing driver in misc that this is pretty much intended to replace. The discussion on whether to support the non standard interface of that driver is some way is continuing. * st-gyro - lsm9ds0-gyro. The accel/magn side of this will take a while longer as extensions to the st library are needed for cases where two types of sensor share a single i2c address. * ti-adc081c - support the adc101c and adc121c * Vishay VEML6070 UV sensor - new driver. New features * core - devm_ APIs for channel_get and channel_get_all. The first user of these is the generic ADC based thermal driver. As it is going through the thermal tree these will be picked up as a patch to that next cycle as that is how the author preferred to do it. - mounting matrix support. This new core support allows devices to provide to userspace (typically from the device tree) allowing compensation for how the sensor is mounted on the device. First examples are on UAVs but it has a more mundane use on typical phone where the chip may be on the front or the back of the circuit board and soldered at any angle. Includes support for this ABI in ak8975 (which has an older interface, now deprecated) and mpu6050. * tools - add a -a option to enable all available channels in generic_buffer sample. Makes it somewhat easier to use. * adis library and drivers - support manual self test flag clearing. This has technically been broken for a very long time - result is an offset on readings as the applied field is on all the time. * ak8975 - triggered buffer support * bmc150 - spi support (including splitting the driver into core and i2c parts) * bmp280 - oversampling support. * dht11 - improved logging - useful to debug timing issues on this quirky device. * st-sensors - read each channel invidivually as not all support the optimization of reading in bulk. This is technically a fix, but will need to be backported if desired. - support open drain and shared interrupts. * ti-adc081c - triggered buffer support. Cleanups * inkern - white space fix. * ad7606 - use the iio_device_claim_direct_mode call rather than open coding equiv. * ad799x - white space fix. * ad9523 - unsigned -> unsigned int * apds9660 - brace location tidying up. - silence an uninitialized variable warning. * ak8975 - else and brace on same line fix. * at91_adc - white space fixes. * bmc150 - use regmap stored copy of the device pointer rather than having an additional copy. * bmg160 - use regmap stored copy of the device pointer rather than having an additional copy. * hid-sensors - white space fixes. * mcp3422 - white space fix. * mma7455 - use regmap to retrieve the device struct rather than carrying another copy in the private data. * ms_sensors - white space fix. * mxs-lradc - move current bindings out of staging - some will be shortly deprecated but the reality is that we have device trees out there using them so they will need to be supported for some time. They accidentally got left behind when the driver graduated from staging. - white space cleanup. - set INPUT_PROP_DIRECT. - move ts config into a better function. - move the STMP reset out of the ADC init. * vf610_adc - case label indenting fix.
Diffstat (limited to 'tools/iio/generic_buffer.c')
-rw-r--r--tools/iio/generic_buffer.c102
1 files changed, 98 insertions, 4 deletions
diff --git a/tools/iio/generic_buffer.c b/tools/iio/generic_buffer.c
index c42b7f836b48..2429c78de940 100644
--- a/tools/iio/generic_buffer.c
+++ b/tools/iio/generic_buffer.c
@@ -35,6 +35,15 @@
35#include "iio_utils.h" 35#include "iio_utils.h"
36 36
37/** 37/**
38 * enum autochan - state for the automatic channel enabling mechanism
39 */
40enum autochan {
41 AUTOCHANNELS_DISABLED,
42 AUTOCHANNELS_ENABLED,
43 AUTOCHANNELS_ACTIVE,
44};
45
46/**
38 * size_from_channelarray() - calculate the storage size of a scan 47 * size_from_channelarray() - calculate the storage size of a scan
39 * @channels: the channel info array 48 * @channels: the channel info array
40 * @num_channels: number of channels 49 * @num_channels: number of channels
@@ -191,10 +200,51 @@ void process_scan(char *data,
191 printf("\n"); 200 printf("\n");
192} 201}
193 202
203static int enable_disable_all_channels(char *dev_dir_name, int enable)
204{
205 const struct dirent *ent;
206 char scanelemdir[256];
207 DIR *dp;
208 int ret;
209
210 snprintf(scanelemdir, sizeof(scanelemdir),
211 FORMAT_SCAN_ELEMENTS_DIR, dev_dir_name);
212 scanelemdir[sizeof(scanelemdir)-1] = '\0';
213
214 dp = opendir(scanelemdir);
215 if (!dp) {
216 fprintf(stderr, "Enabling/disabling channels: can't open %s\n",
217 scanelemdir);
218 return -EIO;
219 }
220
221 ret = -ENOENT;
222 while (ent = readdir(dp), ent) {
223 if (iioutils_check_suffix(ent->d_name, "_en")) {
224 printf("%sabling: %s\n",
225 enable ? "En" : "Dis",
226 ent->d_name);
227 ret = write_sysfs_int(ent->d_name, scanelemdir,
228 enable);
229 if (ret < 0)
230 fprintf(stderr, "Failed to enable/disable %s\n",
231 ent->d_name);
232 }
233 }
234
235 if (closedir(dp) == -1) {
236 perror("Enabling/disabling channels: "
237 "Failed to close directory");
238 return -errno;
239 }
240 return 0;
241}
242
194void print_usage(void) 243void print_usage(void)
195{ 244{
196 fprintf(stderr, "Usage: generic_buffer [options]...\n" 245 fprintf(stderr, "Usage: generic_buffer [options]...\n"
197 "Capture, convert and output data from IIO device buffer\n" 246 "Capture, convert and output data from IIO device buffer\n"
247 " -a Auto-activate all available channels\n"
198 " -c <n> Do n conversions\n" 248 " -c <n> Do n conversions\n"
199 " -e Disable wait for event (new data)\n" 249 " -e Disable wait for event (new data)\n"
200 " -g Use trigger-less mode\n" 250 " -g Use trigger-less mode\n"
@@ -225,12 +275,16 @@ int main(int argc, char **argv)
225 int scan_size; 275 int scan_size;
226 int noevents = 0; 276 int noevents = 0;
227 int notrigger = 0; 277 int notrigger = 0;
278 enum autochan autochannels = AUTOCHANNELS_DISABLED;
228 char *dummy; 279 char *dummy;
229 280
230 struct iio_channel_info *channels; 281 struct iio_channel_info *channels;
231 282
232 while ((c = getopt(argc, argv, "c:egl:n:t:w:")) != -1) { 283 while ((c = getopt(argc, argv, "ac:egl:n:t:w:")) != -1) {
233 switch (c) { 284 switch (c) {
285 case 'a':
286 autochannels = AUTOCHANNELS_ENABLED;
287 break;
234 case 'c': 288 case 'c':
235 errno = 0; 289 errno = 0;
236 num_loops = strtoul(optarg, &dummy, 10); 290 num_loops = strtoul(optarg, &dummy, 10);
@@ -340,12 +394,47 @@ int main(int argc, char **argv)
340 "diag %s\n", dev_dir_name); 394 "diag %s\n", dev_dir_name);
341 goto error_free_triggername; 395 goto error_free_triggername;
342 } 396 }
343 if (!num_channels) { 397 if (num_channels && autochannels == AUTOCHANNELS_ENABLED) {
398 fprintf(stderr, "Auto-channels selected but some channels "
399 "are already activated in sysfs\n");
400 fprintf(stderr, "Proceeding without activating any channels\n");
401 }
402
403 if (!num_channels && autochannels == AUTOCHANNELS_ENABLED) {
404 fprintf(stderr,
405 "No channels are enabled, enabling all channels\n");
406
407 ret = enable_disable_all_channels(dev_dir_name, 1);
408 if (ret) {
409 fprintf(stderr, "Failed to enable all channels\n");
410 goto error_free_triggername;
411 }
412
413 /* This flags that we need to disable the channels again */
414 autochannels = AUTOCHANNELS_ACTIVE;
415
416 ret = build_channel_array(dev_dir_name, &channels,
417 &num_channels);
418 if (ret) {
419 fprintf(stderr, "Problem reading scan element "
420 "information\n"
421 "diag %s\n", dev_dir_name);
422 goto error_disable_channels;
423 }
424 if (!num_channels) {
425 fprintf(stderr, "Still no channels after "
426 "auto-enabling, giving up\n");
427 goto error_disable_channels;
428 }
429 }
430
431 if (!num_channels && autochannels == AUTOCHANNELS_DISABLED) {
344 fprintf(stderr, 432 fprintf(stderr,
345 "No channels are enabled, we have nothing to scan.\n"); 433 "No channels are enabled, we have nothing to scan.\n");
346 fprintf(stderr, "Enable channels manually in " 434 fprintf(stderr, "Enable channels manually in "
347 FORMAT_SCAN_ELEMENTS_DIR 435 FORMAT_SCAN_ELEMENTS_DIR
348 "/*_en and try again.\n", dev_dir_name); 436 "/*_en or pass -a to autoenable channels and "
437 "try again.\n", dev_dir_name);
349 ret = -ENOENT; 438 ret = -ENOENT;
350 goto error_free_triggername; 439 goto error_free_triggername;
351 } 440 }
@@ -479,7 +568,12 @@ error_free_channels:
479error_free_triggername: 568error_free_triggername:
480 if (datardytrigger) 569 if (datardytrigger)
481 free(trigger_name); 570 free(trigger_name);
482 571error_disable_channels:
572 if (autochannels == AUTOCHANNELS_ACTIVE) {
573 ret = enable_disable_all_channels(dev_dir_name, 0);
574 if (ret)
575 fprintf(stderr, "Failed to disable all channels\n");
576 }
483error_free_dev_dir_name: 577error_free_dev_dir_name:
484 free(dev_dir_name); 578 free(dev_dir_name);
485 579