aboutsummaryrefslogtreecommitdiffstats
path: root/tools/iio/lsiio.c
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-03-24 17:53:52 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-03-24 17:53:52 -0400
commitdc5f2c5f6aa159ebf4b29b169aa1f71cf98d3d6a (patch)
treef9fd13fd4025e8844adbe27383cfcd1ad9c5106f /tools/iio/lsiio.c
parentc754ff966d54b3a6cb45cd57524186a16e7f5831 (diff)
parentc0644160a8b5e56b3c3896d77ac3d50d41fa9336 (diff)
Merge tag 'iio-for-4.1a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next
Jonathan writes: First set of new drivers, cleanups and functionality for IIO in the 4.1 cycle. New drivers * CM3323 color sensor. * MS5611 pressure and temperature sensor. New functionality * mup6050 - create mux clients for devices described via ACPI. The reasoning and approach taken in this patch are complex. Basically there is no otherway of finding out what is there than by some esoteric look ups in the ACPI data. * cm3232 - PM support * itg3200 - suspend/resume support * mcp320x - add more ADCs to the kconfig to reflect what the driver supports (this patch and the bindings got left behind when the support was added a while back). Docs / utils * ti-adc128s052 - DT bindings. * mcp3422 - DT bindings. * mcp320x - DT bindings * ABI docs for event threshold scale attributes, in_magn_offset, proximity scan_element and thresh falling/rising values for accelerometers. All elements long in use that have slipped by being explicitly documented. * Tidy up the tools previously in drivers/staging/iio/Documentation and move them out to /tools/iio. Yet another move that should have happened long ago. This time Roberta Dobrescu did the leg work. Thanks! Core Cleanups * Export userspace IIO headers. We should have done the appropriate header splitting a long time ago. Thanks to Daniel for sorting this out. * Refactor the registring of attributes for buffers to move all non-custom ones to a vector allowing easier additions to the current set in the future. Driver Cleanups * gpiod related cleanups. Make use of the additional parameter to specify initial direciton to avoid extra code. * bmc150 - Various refactorings to reduce code repitition and prepare for hardware buffer support. Some of these cleanups are good even without the new functionality. * kmx61 - direct use of index to an array avoiding a structure element which was always the index to an element in an array of that structure. * vf610 - avoid incorrect type for return from wait_for_completion_timeout. * gp2ap020a00f - use put_unaligned_le32 for slight code simplification. * ade7754 - improve error handling including suppressing some build warnings. * ade7759 - improve error handling including suppressing some build warnings. * hmc5843 - Long line and indentation fixes. Also some constifying of various constant data. * ade7854 - 80+ character line splitting. * ad2s1210 - fix wrong printf format string. * mxs-lradc - fix wrong printf format string. * ade7954-i2c - code alignment fixes and other trivial but worthwhile bits. * periodic rtc trigger - make the frequency type an unsigned int as it is always treated as such. * jsa1212 - constify struct regmap_config as it is constant. * ad7793 - typo in the MODULE_DESCRIPTION * mma9551 - check gpiod_to_irq errors. Note that this doesn't actually cause any trouble but is worth tidying up as obviously incorrect. * mlx90614 - refactor the register symbols to make it clear which reads are to RAM not PROM.
Diffstat (limited to 'tools/iio/lsiio.c')
-rw-r--r--tools/iio/lsiio.c158
1 files changed, 158 insertions, 0 deletions
diff --git a/tools/iio/lsiio.c b/tools/iio/lsiio.c
new file mode 100644
index 000000000000..c585440f864e
--- /dev/null
+++ b/tools/iio/lsiio.c
@@ -0,0 +1,158 @@
1/*
2 * Industrial I/O utilities - lsiio.c
3 *
4 * Copyright (c) 2010 Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10
11#include <string.h>
12#include <dirent.h>
13#include <stdio.h>
14#include <errno.h>
15#include <stdint.h>
16#include <stdlib.h>
17#include <unistd.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include <sys/dir.h>
21#include "iio_utils.h"
22
23
24static enum verbosity {
25 VERBLEVEL_DEFAULT, /* 0 gives lspci behaviour */
26 VERBLEVEL_SENSORS, /* 1 lists sensors */
27} verblevel = VERBLEVEL_DEFAULT;
28
29const char *type_device = "iio:device";
30const char *type_trigger = "trigger";
31
32
33static inline int check_prefix(const char *str, const char *prefix)
34{
35 return strlen(str) > strlen(prefix) &&
36 strncmp(str, prefix, strlen(prefix)) == 0;
37}
38
39static inline int check_postfix(const char *str, const char *postfix)
40{
41 return strlen(str) > strlen(postfix) &&
42 strcmp(str + strlen(str) - strlen(postfix), postfix) == 0;
43}
44
45static int dump_channels(const char *dev_dir_name)
46{
47 DIR *dp;
48 const struct dirent *ent;
49
50 dp = opendir(dev_dir_name);
51 if (dp == NULL)
52 return -errno;
53 while (ent = readdir(dp), ent != NULL)
54 if (check_prefix(ent->d_name, "in_") &&
55 check_postfix(ent->d_name, "_raw")) {
56 printf(" %-10s\n", ent->d_name);
57 }
58
59 return 0;
60}
61
62static int dump_one_device(const char *dev_dir_name)
63{
64 char name[IIO_MAX_NAME_LENGTH];
65 int dev_idx;
66 int retval;
67
68 retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_device),
69 "%i", &dev_idx);
70 if (retval != 1)
71 return -EINVAL;
72 read_sysfs_string("name", dev_dir_name, name);
73 printf("Device %03d: %s\n", dev_idx, name);
74
75 if (verblevel >= VERBLEVEL_SENSORS)
76 return dump_channels(dev_dir_name);
77 return 0;
78}
79
80static int dump_one_trigger(const char *dev_dir_name)
81{
82 char name[IIO_MAX_NAME_LENGTH];
83 int dev_idx;
84 int retval;
85
86 retval = sscanf(dev_dir_name + strlen(iio_dir) + strlen(type_trigger),
87 "%i", &dev_idx);
88 if (retval != 1)
89 return -EINVAL;
90 read_sysfs_string("name", dev_dir_name, name);
91 printf("Trigger %03d: %s\n", dev_idx, name);
92 return 0;
93}
94
95static void dump_devices(void)
96{
97 const struct dirent *ent;
98 DIR *dp;
99
100 dp = opendir(iio_dir);
101 if (dp == NULL) {
102 printf("No industrial I/O devices available\n");
103 return;
104 }
105
106 while (ent = readdir(dp), ent != NULL) {
107 if (check_prefix(ent->d_name, type_device)) {
108 char *dev_dir_name;
109
110 asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
111 dump_one_device(dev_dir_name);
112 free(dev_dir_name);
113 if (verblevel >= VERBLEVEL_SENSORS)
114 printf("\n");
115 }
116 }
117 rewinddir(dp);
118 while (ent = readdir(dp), ent != NULL) {
119 if (check_prefix(ent->d_name, type_trigger)) {
120 char *dev_dir_name;
121
122 asprintf(&dev_dir_name, "%s%s", iio_dir, ent->d_name);
123 dump_one_trigger(dev_dir_name);
124 free(dev_dir_name);
125 }
126 }
127 closedir(dp);
128}
129
130int main(int argc, char **argv)
131{
132 int c, err = 0;
133
134 while ((c = getopt(argc, argv, "d:D:v")) != EOF) {
135 switch (c) {
136 case 'v':
137 verblevel++;
138 break;
139
140 case '?':
141 default:
142 err++;
143 break;
144 }
145 }
146 if (err || argc > optind) {
147 fprintf(stderr, "Usage: lsiio [options]...\n"
148 "List industrial I/O devices\n"
149 " -v, --verbose\n"
150 " Increase verbosity (may be given multiple times)\n"
151 );
152 exit(1);
153 }
154
155 dump_devices();
156
157 return 0;
158}