diff options
author | Karol Wrona <k.wrona@samsung.com> | 2014-11-04 09:29:39 -0500 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-11-05 09:45:18 -0500 |
commit | b6d5be57024a8edcc91d0c2549d63c68d67a2257 (patch) | |
tree | c45a938861a639ab8dbfbfa2b1b88dd29a6a5637 | |
parent | 455f0049e0c02ee0a769d967b1eba2c52e932237 (diff) |
staging: iio: Add notrigger mode for generic_buffer
Some IIO devices do not use the triggers. This patch makes trigger setting
conditional so generic_buffer can be used when triggers are disabled.
Signed-off-by: Karol Wrona <k.wrona@samsung.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r-- | drivers/staging/iio/Documentation/generic_buffer.c | 77 |
1 files changed, 45 insertions, 32 deletions
diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c index 044ea196aa6f..2671bf9433cb 100644 --- a/drivers/staging/iio/Documentation/generic_buffer.c +++ b/drivers/staging/iio/Documentation/generic_buffer.c | |||
@@ -158,11 +158,12 @@ int main(int argc, char **argv) | |||
158 | char *buffer_access; | 158 | char *buffer_access; |
159 | int scan_size; | 159 | int scan_size; |
160 | int noevents = 0; | 160 | int noevents = 0; |
161 | int notrigger = 0; | ||
161 | char *dummy; | 162 | char *dummy; |
162 | 163 | ||
163 | struct iio_channel_info *channels; | 164 | struct iio_channel_info *channels; |
164 | 165 | ||
165 | while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) { | 166 | while ((c = getopt(argc, argv, "l:w:c:et:n:g")) != -1) { |
166 | switch (c) { | 167 | switch (c) { |
167 | case 'n': | 168 | case 'n': |
168 | device_name = optarg; | 169 | device_name = optarg; |
@@ -183,6 +184,9 @@ int main(int argc, char **argv) | |||
183 | case 'l': | 184 | case 'l': |
184 | buf_len = strtoul(optarg, &dummy, 10); | 185 | buf_len = strtoul(optarg, &dummy, 10); |
185 | break; | 186 | break; |
187 | case 'g': | ||
188 | notrigger = 1; | ||
189 | break; | ||
186 | case '?': | 190 | case '?': |
187 | return -1; | 191 | return -1; |
188 | } | 192 | } |
@@ -201,28 +205,32 @@ int main(int argc, char **argv) | |||
201 | printf("iio device number being used is %d\n", dev_num); | 205 | printf("iio device number being used is %d\n", dev_num); |
202 | 206 | ||
203 | asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); | 207 | asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); |
204 | if (trigger_name == NULL) { | 208 | |
205 | /* | 209 | if (!notrigger) { |
206 | * Build the trigger name. If it is device associated its | 210 | if (trigger_name == NULL) { |
207 | * name is <device_name>_dev[n] where n matches the device | 211 | /* |
208 | * number found above | 212 | * Build the trigger name. If it is device associated |
209 | */ | 213 | * its name is <device_name>_dev[n] where n matches |
210 | ret = asprintf(&trigger_name, | 214 | * the device number found above. |
211 | "%s-dev%d", device_name, dev_num); | 215 | */ |
212 | if (ret < 0) { | 216 | ret = asprintf(&trigger_name, |
213 | ret = -ENOMEM; | 217 | "%s-dev%d", device_name, dev_num); |
214 | goto error_ret; | 218 | if (ret < 0) { |
219 | ret = -ENOMEM; | ||
220 | goto error_ret; | ||
221 | } | ||
215 | } | 222 | } |
216 | } | ||
217 | 223 | ||
218 | /* Verify the trigger exists */ | 224 | /* Verify the trigger exists */ |
219 | trig_num = find_type_by_name(trigger_name, "trigger"); | 225 | trig_num = find_type_by_name(trigger_name, "trigger"); |
220 | if (trig_num < 0) { | 226 | if (trig_num < 0) { |
221 | printf("Failed to find the trigger %s\n", trigger_name); | 227 | printf("Failed to find the trigger %s\n", trigger_name); |
222 | ret = -ENODEV; | 228 | ret = -ENODEV; |
223 | goto error_free_triggername; | 229 | goto error_free_triggername; |
224 | } | 230 | } |
225 | printf("iio trigger number being used is %d\n", trig_num); | 231 | printf("iio trigger number being used is %d\n", trig_num); |
232 | } else | ||
233 | printf("trigger-less mode selected\n"); | ||
226 | 234 | ||
227 | /* | 235 | /* |
228 | * Parse the files in scan_elements to identify what channels are | 236 | * Parse the files in scan_elements to identify what channels are |
@@ -246,14 +254,18 @@ int main(int argc, char **argv) | |||
246 | ret = -ENOMEM; | 254 | ret = -ENOMEM; |
247 | goto error_free_triggername; | 255 | goto error_free_triggername; |
248 | } | 256 | } |
249 | printf("%s %s\n", dev_dir_name, trigger_name); | 257 | |
250 | /* Set the device trigger to be the data ready trigger found above */ | 258 | if (!notrigger) { |
251 | ret = write_sysfs_string_and_verify("trigger/current_trigger", | 259 | printf("%s %s\n", dev_dir_name, trigger_name); |
252 | dev_dir_name, | 260 | /* Set the device trigger to be the data ready trigger found |
253 | trigger_name); | 261 | * above */ |
254 | if (ret < 0) { | 262 | ret = write_sysfs_string_and_verify("trigger/current_trigger", |
255 | printf("Failed to write current_trigger file\n"); | 263 | dev_dir_name, |
256 | goto error_free_buf_dir_name; | 264 | trigger_name); |
265 | if (ret < 0) { | ||
266 | printf("Failed to write current_trigger file\n"); | ||
267 | goto error_free_buf_dir_name; | ||
268 | } | ||
257 | } | 269 | } |
258 | 270 | ||
259 | /* Setup ring buffer parameters */ | 271 | /* Setup ring buffer parameters */ |
@@ -323,9 +335,10 @@ int main(int argc, char **argv) | |||
323 | if (ret < 0) | 335 | if (ret < 0) |
324 | goto error_close_buffer_access; | 336 | goto error_close_buffer_access; |
325 | 337 | ||
326 | /* Disconnect the trigger - just write a dummy name. */ | 338 | if (!notrigger) |
327 | write_sysfs_string("trigger/current_trigger", | 339 | /* Disconnect the trigger - just write a dummy name. */ |
328 | dev_dir_name, "NULL"); | 340 | write_sysfs_string("trigger/current_trigger", |
341 | dev_dir_name, "NULL"); | ||
329 | 342 | ||
330 | error_close_buffer_access: | 343 | error_close_buffer_access: |
331 | close(fp); | 344 | close(fp); |