Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 1 | /* Industrialio buffer test code. |
| 2 | * |
| 3 | * Copyright (c) 2008 Jonathan Cameron |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published by |
| 7 | * the Free Software Foundation. |
| 8 | * |
| 9 | * This program is primarily intended as an example application. |
| 10 | * Reads the current buffer setup from sysfs and starts a short capture |
| 11 | * from the specified device, pretty printing the result after appropriate |
| 12 | * conversion. |
| 13 | * |
| 14 | * Command line parameters |
| 15 | * generic_buffer -n <device_name> -t <trigger_name> |
| 16 | * If trigger name is not specified the program assumes you want a dataready |
| 17 | * trigger associated with the device and goes looking for it. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #include <unistd.h> |
Roberta Dobrescu | bdcb31d | 2015-02-26 10:49:24 +0200 | [diff] [blame] | 22 | #include <stdlib.h> |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 23 | #include <dirent.h> |
| 24 | #include <fcntl.h> |
| 25 | #include <stdio.h> |
| 26 | #include <errno.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <sys/dir.h> |
| 29 | #include <linux/types.h> |
Jonathan Cameron | 30268a3 | 2011-02-11 13:09:12 +0000 | [diff] [blame] | 30 | #include <string.h> |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 31 | #include <poll.h> |
Jonathan Cameron | 117cf8b | 2011-12-04 19:10:59 +0000 | [diff] [blame] | 32 | #include <endian.h> |
Peter Meerwald | bb23378 | 2012-06-25 23:12:17 +0200 | [diff] [blame] | 33 | #include <getopt.h> |
Peter Meerwald | 1bcdfbc | 2012-06-25 23:12:16 +0200 | [diff] [blame] | 34 | #include <inttypes.h> |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 35 | #include "iio_utils.h" |
| 36 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 37 | /** |
| 38 | * size_from_channelarray() - calculate the storage size of a scan |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 39 | * @channels: the channel info array |
| 40 | * @num_channels: number of channels |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 41 | * |
| 42 | * Has the side effect of filling the channels[i].location values used |
| 43 | * in processing the buffer output. |
| 44 | **/ |
| 45 | int size_from_channelarray(struct iio_channel_info *channels, int num_channels) |
| 46 | { |
| 47 | int bytes = 0; |
| 48 | int i = 0; |
Melike Yurtoglu | ff39a25 | 2014-10-03 23:34:50 +0300 | [diff] [blame] | 49 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 50 | while (i < num_channels) { |
| 51 | if (bytes % channels[i].bytes == 0) |
| 52 | channels[i].location = bytes; |
| 53 | else |
| 54 | channels[i].location = bytes - bytes%channels[i].bytes |
| 55 | + channels[i].bytes; |
| 56 | bytes = channels[i].location + channels[i].bytes; |
| 57 | i++; |
| 58 | } |
| 59 | return bytes; |
| 60 | } |
| 61 | |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 62 | void print2byte(int input, struct iio_channel_info *info) |
| 63 | { |
Jonathan Cameron | 117cf8b | 2011-12-04 19:10:59 +0000 | [diff] [blame] | 64 | /* First swap if incorrect endian */ |
Jonathan Cameron | 117cf8b | 2011-12-04 19:10:59 +0000 | [diff] [blame] | 65 | if (info->be) |
Jonathan Cameron | 09f78be | 2012-04-10 21:11:04 +0100 | [diff] [blame] | 66 | input = be16toh((uint16_t)input); |
Jonathan Cameron | 117cf8b | 2011-12-04 19:10:59 +0000 | [diff] [blame] | 67 | else |
Jonathan Cameron | 09f78be | 2012-04-10 21:11:04 +0100 | [diff] [blame] | 68 | input = le16toh((uint16_t)input); |
Jonathan Cameron | 117cf8b | 2011-12-04 19:10:59 +0000 | [diff] [blame] | 69 | |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 70 | /* |
| 71 | * Shift before conversion to avoid sign extension |
| 72 | * of left aligned data |
| 73 | */ |
Aya Mahfouz | 1525ecf | 2015-02-26 11:45:26 +0200 | [diff] [blame] | 74 | input >>= info->shift; |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 75 | if (info->is_signed) { |
| 76 | int16_t val = input; |
Melike Yurtoglu | ff39a25 | 2014-10-03 23:34:50 +0300 | [diff] [blame] | 77 | |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 78 | val &= (1 << info->bits_used) - 1; |
| 79 | val = (int16_t)(val << (16 - info->bits_used)) >> |
| 80 | (16 - info->bits_used); |
Peter Meerwald | 1d633fd | 2012-06-25 23:12:11 +0200 | [diff] [blame] | 81 | printf("%05f ", ((float)val + info->offset)*info->scale); |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 82 | } else { |
| 83 | uint16_t val = input; |
Melike Yurtoglu | ff39a25 | 2014-10-03 23:34:50 +0300 | [diff] [blame] | 84 | |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 85 | val &= (1 << info->bits_used) - 1; |
| 86 | printf("%05f ", ((float)val + info->offset)*info->scale); |
| 87 | } |
| 88 | } |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 89 | /** |
| 90 | * process_scan() - print out the values in SI units |
| 91 | * @data: pointer to the start of the scan |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 92 | * @channels: information about the channels. Note |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 93 | * size_from_channelarray must have been called first to fill the |
| 94 | * location offsets. |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 95 | * @num_channels: number of channels |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 96 | **/ |
| 97 | void process_scan(char *data, |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 98 | struct iio_channel_info *channels, |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 99 | int num_channels) |
| 100 | { |
| 101 | int k; |
Melike Yurtoglu | ff39a25 | 2014-10-03 23:34:50 +0300 | [diff] [blame] | 102 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 103 | for (k = 0; k < num_channels; k++) |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 104 | switch (channels[k].bytes) { |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 105 | /* only a few cases implemented so far */ |
| 106 | case 2: |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 107 | print2byte(*(uint16_t *)(data + channels[k].location), |
| 108 | &channels[k]); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 109 | break; |
Marek Vasut | 6cffc1f | 2012-08-12 16:21:00 +0100 | [diff] [blame] | 110 | case 4: |
| 111 | if (!channels[k].is_signed) { |
| 112 | uint32_t val = *(uint32_t *) |
| 113 | (data + channels[k].location); |
| 114 | printf("%05f ", ((float)val + |
| 115 | channels[k].offset)* |
| 116 | channels[k].scale); |
| 117 | |
| 118 | } |
| 119 | break; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 120 | case 8: |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 121 | if (channels[k].is_signed) { |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 122 | int64_t val = *(int64_t *) |
| 123 | (data + |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 124 | channels[k].location); |
| 125 | if ((val >> channels[k].bits_used) & 1) |
| 126 | val = (val & channels[k].mask) | |
| 127 | ~channels[k].mask; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 128 | /* special case for timestamp */ |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 129 | if (channels[k].scale == 1.0f && |
| 130 | channels[k].offset == 0.0f) |
Peter Meerwald | 1bcdfbc | 2012-06-25 23:12:16 +0200 | [diff] [blame] | 131 | printf("%" PRId64 " ", val); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 132 | else |
| 133 | printf("%05f ", ((float)val + |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 134 | channels[k].offset)* |
| 135 | channels[k].scale); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 136 | } |
| 137 | break; |
| 138 | default: |
| 139 | break; |
| 140 | } |
| 141 | printf("\n"); |
| 142 | } |
| 143 | |
| 144 | int main(int argc, char **argv) |
| 145 | { |
Jonathan Cameron | 96df979 | 2011-02-11 13:09:13 +0000 | [diff] [blame] | 146 | unsigned long num_loops = 2; |
| 147 | unsigned long timedelay = 1000000; |
| 148 | unsigned long buf_len = 128; |
| 149 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 150 | int ret, c, i, j, toread; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 151 | int fp; |
| 152 | |
| 153 | int num_channels; |
| 154 | char *trigger_name = NULL, *device_name = NULL; |
| 155 | char *dev_dir_name, *buf_dir_name; |
| 156 | |
| 157 | int datardytrigger = 1; |
| 158 | char *data; |
Jonathan Cameron | c77b381 | 2011-04-15 18:56:00 +0100 | [diff] [blame] | 159 | ssize_t read_size; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 160 | int dev_num, trig_num; |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 161 | char *buffer_access; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 162 | int scan_size; |
Jonathan Cameron | 30268a3 | 2011-02-11 13:09:12 +0000 | [diff] [blame] | 163 | int noevents = 0; |
Karol Wrona | b6d5be57 | 2014-11-04 15:29:39 +0100 | [diff] [blame] | 164 | int notrigger = 0; |
Jonathan Cameron | 96df979 | 2011-02-11 13:09:13 +0000 | [diff] [blame] | 165 | char *dummy; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 166 | |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 167 | struct iio_channel_info *channels; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 168 | |
Karol Wrona | b6d5be57 | 2014-11-04 15:29:39 +0100 | [diff] [blame] | 169 | while ((c = getopt(argc, argv, "l:w:c:et:n:g")) != -1) { |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 170 | switch (c) { |
| 171 | case 'n': |
| 172 | device_name = optarg; |
| 173 | break; |
| 174 | case 't': |
| 175 | trigger_name = optarg; |
| 176 | datardytrigger = 0; |
| 177 | break; |
Jonathan Cameron | 30268a3 | 2011-02-11 13:09:12 +0000 | [diff] [blame] | 178 | case 'e': |
| 179 | noevents = 1; |
| 180 | break; |
Jonathan Cameron | 96df979 | 2011-02-11 13:09:13 +0000 | [diff] [blame] | 181 | case 'c': |
| 182 | num_loops = strtoul(optarg, &dummy, 10); |
| 183 | break; |
| 184 | case 'w': |
| 185 | timedelay = strtoul(optarg, &dummy, 10); |
| 186 | break; |
| 187 | case 'l': |
| 188 | buf_len = strtoul(optarg, &dummy, 10); |
| 189 | break; |
Karol Wrona | b6d5be57 | 2014-11-04 15:29:39 +0100 | [diff] [blame] | 190 | case 'g': |
| 191 | notrigger = 1; |
| 192 | break; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 193 | case '?': |
| 194 | return -1; |
| 195 | } |
| 196 | } |
| 197 | |
Michael Hennerich | 065896e | 2011-02-24 16:34:50 +0100 | [diff] [blame] | 198 | if (device_name == NULL) |
| 199 | return -1; |
| 200 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 201 | /* Find the device requested */ |
Jonathan Cameron | 1aa0427 | 2011-08-30 12:32:47 +0100 | [diff] [blame] | 202 | dev_num = find_type_by_name(device_name, "iio:device"); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 203 | if (dev_num < 0) { |
| 204 | printf("Failed to find the %s\n", device_name); |
| 205 | ret = -ENODEV; |
| 206 | goto error_ret; |
| 207 | } |
| 208 | printf("iio device number being used is %d\n", dev_num); |
| 209 | |
Jonathan Cameron | 1aa0427 | 2011-08-30 12:32:47 +0100 | [diff] [blame] | 210 | asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 211 | |
Karol Wrona | b6d5be57 | 2014-11-04 15:29:39 +0100 | [diff] [blame] | 212 | if (!notrigger) { |
| 213 | if (trigger_name == NULL) { |
| 214 | /* |
| 215 | * Build the trigger name. If it is device associated |
| 216 | * its name is <device_name>_dev[n] where n matches |
| 217 | * the device number found above. |
| 218 | */ |
| 219 | ret = asprintf(&trigger_name, |
| 220 | "%s-dev%d", device_name, dev_num); |
| 221 | if (ret < 0) { |
| 222 | ret = -ENOMEM; |
| 223 | goto error_ret; |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | /* Verify the trigger exists */ |
| 228 | trig_num = find_type_by_name(trigger_name, "trigger"); |
| 229 | if (trig_num < 0) { |
| 230 | printf("Failed to find the trigger %s\n", trigger_name); |
| 231 | ret = -ENODEV; |
| 232 | goto error_free_triggername; |
| 233 | } |
| 234 | printf("iio trigger number being used is %d\n", trig_num); |
| 235 | } else |
| 236 | printf("trigger-less mode selected\n"); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 237 | |
| 238 | /* |
| 239 | * Parse the files in scan_elements to identify what channels are |
| 240 | * present |
| 241 | */ |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 242 | ret = build_channel_array(dev_dir_name, &channels, &num_channels); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 243 | if (ret) { |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 244 | printf("Problem reading scan element information\n"); |
Jonathan Cameron | 1aa0427 | 2011-08-30 12:32:47 +0100 | [diff] [blame] | 245 | printf("diag %s\n", dev_dir_name); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 246 | goto error_free_triggername; |
| 247 | } |
| 248 | |
| 249 | /* |
| 250 | * Construct the directory name for the associated buffer. |
| 251 | * As we know that the lis3l02dq has only one buffer this may |
| 252 | * be built rather than found. |
| 253 | */ |
Jonathan Cameron | 1aa0427 | 2011-08-30 12:32:47 +0100 | [diff] [blame] | 254 | ret = asprintf(&buf_dir_name, |
| 255 | "%siio:device%d/buffer", iio_dir, dev_num); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 256 | if (ret < 0) { |
| 257 | ret = -ENOMEM; |
| 258 | goto error_free_triggername; |
| 259 | } |
Karol Wrona | b6d5be57 | 2014-11-04 15:29:39 +0100 | [diff] [blame] | 260 | |
| 261 | if (!notrigger) { |
| 262 | printf("%s %s\n", dev_dir_name, trigger_name); |
| 263 | /* Set the device trigger to be the data ready trigger found |
| 264 | * above */ |
| 265 | ret = write_sysfs_string_and_verify("trigger/current_trigger", |
| 266 | dev_dir_name, |
| 267 | trigger_name); |
| 268 | if (ret < 0) { |
| 269 | printf("Failed to write current_trigger file\n"); |
| 270 | goto error_free_buf_dir_name; |
| 271 | } |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* Setup ring buffer parameters */ |
| 275 | ret = write_sysfs_int("length", buf_dir_name, buf_len); |
| 276 | if (ret < 0) |
| 277 | goto error_free_buf_dir_name; |
| 278 | |
| 279 | /* Enable the buffer */ |
| 280 | ret = write_sysfs_int("enable", buf_dir_name, 1); |
| 281 | if (ret < 0) |
| 282 | goto error_free_buf_dir_name; |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 283 | scan_size = size_from_channelarray(channels, num_channels); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 284 | data = malloc(scan_size*buf_len); |
| 285 | if (!data) { |
| 286 | ret = -ENOMEM; |
| 287 | goto error_free_buf_dir_name; |
| 288 | } |
| 289 | |
Jonathan Cameron | 1aa0427 | 2011-08-30 12:32:47 +0100 | [diff] [blame] | 290 | ret = asprintf(&buffer_access, "/dev/iio:device%d", dev_num); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 291 | if (ret < 0) { |
| 292 | ret = -ENOMEM; |
| 293 | goto error_free_data; |
| 294 | } |
| 295 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 296 | /* Attempt to open non blocking the access dev */ |
| 297 | fp = open(buffer_access, O_RDONLY | O_NONBLOCK); |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 298 | if (fp == -1) { /* If it isn't there make the node */ |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 299 | printf("Failed to open %s\n", buffer_access); |
| 300 | ret = -errno; |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 301 | goto error_free_buffer_access; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* Wait for events 10 times */ |
| 305 | for (j = 0; j < num_loops; j++) { |
Jonathan Cameron | 30268a3 | 2011-02-11 13:09:12 +0000 | [diff] [blame] | 306 | if (!noevents) { |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 307 | struct pollfd pfd = { |
| 308 | .fd = fp, |
| 309 | .events = POLLIN, |
| 310 | }; |
| 311 | |
| 312 | poll(&pfd, 1, -1); |
| 313 | toread = buf_len; |
| 314 | |
Jonathan Cameron | 30268a3 | 2011-02-11 13:09:12 +0000 | [diff] [blame] | 315 | } else { |
Jonathan Cameron | 96df979 | 2011-02-11 13:09:13 +0000 | [diff] [blame] | 316 | usleep(timedelay); |
Jonathan Cameron | 30268a3 | 2011-02-11 13:09:12 +0000 | [diff] [blame] | 317 | toread = 64; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 318 | } |
Jonathan Cameron | 30268a3 | 2011-02-11 13:09:12 +0000 | [diff] [blame] | 319 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 320 | read_size = read(fp, |
| 321 | data, |
| 322 | toread*scan_size); |
Peter Meerwald | 97b603a | 2014-12-06 06:00:00 +0000 | [diff] [blame] | 323 | if (read_size < 0) { |
| 324 | if (errno == -EAGAIN) { |
| 325 | printf("nothing available\n"); |
| 326 | continue; |
| 327 | } else |
| 328 | break; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 329 | } |
| 330 | for (i = 0; i < read_size/scan_size; i++) |
| 331 | process_scan(data + scan_size*i, |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 332 | channels, |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 333 | num_channels); |
| 334 | } |
| 335 | |
Peter Meerwald | d8da0ee | 2012-06-25 23:12:14 +0200 | [diff] [blame] | 336 | /* Stop the buffer */ |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 337 | ret = write_sysfs_int("enable", buf_dir_name, 0); |
| 338 | if (ret < 0) |
Jonathan Cameron | 52615d4 | 2011-05-18 14:41:19 +0100 | [diff] [blame] | 339 | goto error_close_buffer_access; |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 340 | |
Karol Wrona | b6d5be57 | 2014-11-04 15:29:39 +0100 | [diff] [blame] | 341 | if (!notrigger) |
| 342 | /* Disconnect the trigger - just write a dummy name. */ |
| 343 | write_sysfs_string("trigger/current_trigger", |
| 344 | dev_dir_name, "NULL"); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 345 | |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 346 | error_close_buffer_access: |
| 347 | close(fp); |
| 348 | error_free_data: |
| 349 | free(data); |
| 350 | error_free_buffer_access: |
| 351 | free(buffer_access); |
Jonathan Cameron | e58537c | 2010-10-08 12:14:14 +0100 | [diff] [blame] | 352 | error_free_buf_dir_name: |
| 353 | free(buf_dir_name); |
| 354 | error_free_triggername: |
| 355 | if (datardytrigger) |
| 356 | free(trigger_name); |
| 357 | error_ret: |
| 358 | return ret; |
| 359 | } |