Commit 04b708124aa72d43d74b2ea559813649593e1d4a

Authored by Jonathan Cameron
Committed by Greg Kroah-Hartman
1 parent 299475e0d9

staging: iio: lis3l02dqbuffersimple.c bring example up to date.

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Manuel Stahl <manuel.stahl@iis.fraunhofer.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 2 changed files with 3 additions and 3 deletions Inline Diff

drivers/staging/iio/Documentation/lis3l02dqbuffersimple.c
1 /* Industrialio ring buffer with a lis3l02dq accelerometer 1 /* Industrialio ring buffer with a lis3l02dq accelerometer
2 * 2 *
3 * Copyright (c) 2008 Jonathan Cameron 3 * Copyright (c) 2008 Jonathan Cameron
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation. 7 * the Free Software Foundation.
8 * 8 *
9 * This program is primarily intended as an example application. 9 * This program is primarily intended as an example application.
10 */ 10 */
11 11
12 #include <dirent.h> 12 #include <dirent.h>
13 #include <fcntl.h> 13 #include <fcntl.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <errno.h> 15 #include <errno.h>
16 #include <sys/stat.h> 16 #include <sys/stat.h>
17 #include <sys/dir.h> 17 #include <sys/dir.h>
18 #include <linux/types.h> 18 #include <linux/types.h>
19 #include "iio_utils.h" 19 #include "iio_utils.h"
20 20
21 const char *device_name = "lis3l02dq"; 21 const char *device_name = "lis3l02dq";
22 const char *trigger_name_base = "lis3l02dq-dev"; 22 const char *trigger_name_base = "lis3l02dq-dev";
23 const int num_vals = 3; 23 const int num_vals = 3;
24 const int scan_ts = 1; 24 const int scan_ts = 1;
25 const int buf_len = 128; 25 const int buf_len = 128;
26 const int num_loops = 10; 26 const int num_loops = 10;
27 27
28 /* 28 /*
29 * Could get this from ring bps, but only after starting the ring 29 * Could get this from ring bps, but only after starting the ring
30 * which is a bit late for it to be useful. 30 * which is a bit late for it to be useful.
31 * 31 *
32 * Todo: replace with much more generic version based on scan_elements 32 * Todo: replace with much more generic version based on scan_elements
33 * directory. 33 * directory.
34 */ 34 */
35 int size_from_scanmode(int num_vals, int timestamp) 35 int size_from_scanmode(int num_vals, int timestamp)
36 { 36 {
37 if (num_vals && timestamp) 37 if (num_vals && timestamp)
38 return 16; 38 return 16;
39 else if (timestamp) 39 else if (timestamp)
40 return 8; 40 return 8;
41 else 41 else
42 return num_vals*2; 42 return num_vals*2;
43 } 43 }
44 44
45 int main(int argc, char **argv) 45 int main(int argc, char **argv)
46 { 46 {
47 int ret; 47 int ret;
48 int i, j, k, toread; 48 int i, j, k, toread;
49 FILE *fp_ev; 49 FILE *fp_ev;
50 int fp; 50 int fp;
51 51
52 char *trigger_name, *dev_dir_name, *buf_dir_name; 52 char *trigger_name, *dev_dir_name, *buf_dir_name;
53 char *data; 53 char *data;
54 size_t read_size; 54 size_t read_size;
55 struct iio_event_data dat; 55 struct iio_event_data dat;
56 int dev_num, trig_num; 56 int dev_num, trig_num;
57 57
58 char *buffer_access, *buffer_event; 58 char *buffer_access, *buffer_event;
59 const char *iio_dir = "/sys/bus/iio/devices/"; 59 const char *iio_dir = "/sys/bus/iio/devices/";
60 int scan_size; 60 int scan_size;
61 float gain = 1; 61 float gain = 1;
62 62
63 63
64 /* Find out which iio device is the accelerometer. */ 64 /* Find out which iio device is the accelerometer. */
65 dev_num = find_type_by_name(device_name, "device"); 65 dev_num = find_type_by_name(device_name, "device");
66 if (dev_num < 0) { 66 if (dev_num < 0) {
67 printf("Failed to find the %s\n", device_name); 67 printf("Failed to find the %s\n", device_name);
68 ret = -ENODEV; 68 ret = -ENODEV;
69 goto error_ret; 69 goto error_ret;
70 } 70 }
71 printf("iio device number being used is %d\n", dev_num); 71 printf("iio device number being used is %d\n", dev_num);
72 asprintf(&dev_dir_name, "%sdevice%d", iio_dir, dev_num); 72 asprintf(&dev_dir_name, "%sdevice%d", iio_dir, dev_num);
73 73
74 /* 74 /*
75 * Build the trigger name. 75 * Build the trigger name.
76 * In this case we want the lis3l02dq's data ready trigger 76 * In this case we want the lis3l02dq's data ready trigger
77 * for this lis3l02dq. The naming is lis3l02dq_dev[n], where 77 * for this lis3l02dq. The naming is lis3l02dq_dev[n], where
78 * n matches the device number found above. 78 * n matches the device number found above.
79 */ 79 */
80 ret = asprintf(&trigger_name, "%s%d", trigger_name_base, dev_num); 80 ret = asprintf(&trigger_name, "%s%d", trigger_name_base, dev_num);
81 if (ret < 0) { 81 if (ret < 0) {
82 ret = -ENOMEM; 82 ret = -ENOMEM;
83 goto error_free_dev_dir_name; 83 goto error_free_dev_dir_name;
84 } 84 }
85 85
86 /* 86 /*
87 * Find the trigger by name. 87 * Find the trigger by name.
88 * This is techically unecessary here as we only need to 88 * This is techically unecessary here as we only need to
89 * refer to the trigger by name and that name is already 89 * refer to the trigger by name and that name is already
90 * known. 90 * known.
91 */ 91 */
92 trig_num = find_type_by_name(trigger_name, "trigger"); 92 trig_num = find_type_by_name(trigger_name, "trigger");
93 if (trig_num < 0) { 93 if (trig_num < 0) {
94 printf("Failed to find the %s\n", trigger_name); 94 printf("Failed to find the %s\n", trigger_name);
95 ret = -ENODEV; 95 ret = -ENODEV;
96 goto error_free_triggername; 96 goto error_free_triggername;
97 } 97 }
98 printf("iio trigger number being used is %d\n", trig_num); 98 printf("iio trigger number being used is %d\n", trig_num);
99 99
100 /* 100 /*
101 * Read in the scale value - in a more generic case, first 101 * Read in the scale value - in a more generic case, first
102 * check for accel_scale, then the indivual channel scales 102 * check for accel_scale, then the indivual channel scales
103 */ 103 */
104 ret = read_sysfs_float("accel_scale", dev_dir_name, &gain); 104 ret = read_sysfs_float("accel_scale", dev_dir_name, &gain);
105 if (ret) 105 if (ret)
106 goto error_free_triggername;; 106 goto error_free_triggername;;
107 107
108 /* 108 /*
109 * Construct the directory name for the associated buffer. 109 * Construct the directory name for the associated buffer.
110 * As we know that the lis3l02dq has only one buffer this may 110 * As we know that the lis3l02dq has only one buffer this may
111 * be built rather than found. 111 * be built rather than found.
112 */ 112 */
113 ret = asprintf(&buf_dir_name, "%sdevice%d:buffer0", iio_dir, dev_num); 113 ret = asprintf(&buf_dir_name, "%sdevice%d:buffer0", iio_dir, dev_num);
114 if (ret < 0) { 114 if (ret < 0) {
115 ret = -ENOMEM; 115 ret = -ENOMEM;
116 goto error_free_triggername; 116 goto error_free_triggername;
117 } 117 }
118 /* Set the device trigger to be the data rdy trigger found above */ 118 /* Set the device trigger to be the data rdy trigger found above */
119 ret = write_sysfs_string_and_verify("trigger/current_trigger", 119 ret = write_sysfs_string_and_verify("trigger/current_trigger",
120 dev_dir_name, 120 dev_dir_name,
121 trigger_name); 121 trigger_name);
122 if (ret < 0) { 122 if (ret < 0) {
123 printf("Failed to write current_trigger file\n"); 123 printf("Failed to write current_trigger file\n");
124 goto error_free_buf_dir_name; 124 goto error_free_buf_dir_name;
125 } 125 }
126 126
127 /* Setup ring buffer parameters */ 127 /* Setup ring buffer parameters */
128 ret = write_sysfs_int("length", buf_dir_name, buf_len); 128 ret = write_sysfs_int("length", buf_dir_name, buf_len);
129 if (ret < 0) 129 if (ret < 0)
130 goto error_free_buf_dir_name; 130 goto error_free_buf_dir_name;
131 131
132 /* Enable the buffer */ 132 /* Enable the buffer */
133 ret = write_sysfs_int("ring_enable", buf_dir_name, 1); 133 ret = write_sysfs_int("enable", buf_dir_name, 1);
134 if (ret < 0) 134 if (ret < 0)
135 goto error_free_buf_dir_name; 135 goto error_free_buf_dir_name;
136 136
137 data = malloc(size_from_scanmode(num_vals, scan_ts)*buf_len); 137 data = malloc(size_from_scanmode(num_vals, scan_ts)*buf_len);
138 if (!data) { 138 if (!data) {
139 ret = -ENOMEM; 139 ret = -ENOMEM;
140 goto error_free_buf_dir_name; 140 goto error_free_buf_dir_name;
141 } 141 }
142 142
143 ret = asprintf(&buffer_access, 143 ret = asprintf(&buffer_access,
144 "/dev/device%d:buffer0:access0", 144 "/dev/device%d:buffer0:access0",
145 dev_num); 145 dev_num);
146 if (ret < 0) { 146 if (ret < 0) {
147 ret = -ENOMEM; 147 ret = -ENOMEM;
148 goto error_free_data; 148 goto error_free_data;
149 } 149 }
150 150
151 ret = asprintf(&buffer_event, "/dev/device%d:buffer0:event0", dev_num); 151 ret = asprintf(&buffer_event, "/dev/device%d:buffer0:event0", dev_num);
152 if (ret < 0) { 152 if (ret < 0) {
153 ret = -ENOMEM; 153 ret = -ENOMEM;
154 goto error_free_data; 154 goto error_free_data;
155 } 155 }
156 /* Attempt to open non blocking the access dev */ 156 /* Attempt to open non blocking the access dev */
157 fp = open(buffer_access, O_RDONLY | O_NONBLOCK); 157 fp = open(buffer_access, O_RDONLY | O_NONBLOCK);
158 if (fp == -1) { /*If it isn't there make the node */ 158 if (fp == -1) { /*If it isn't there make the node */
159 printf("Failed to open %s\n", buffer_access); 159 printf("Failed to open %s\n", buffer_access);
160 ret = -errno; 160 ret = -errno;
161 goto error_free_buffer_event; 161 goto error_free_buffer_event;
162 } 162 }
163 /* Attempt to open the event access dev (blocking this time) */ 163 /* Attempt to open the event access dev (blocking this time) */
164 fp_ev = fopen(buffer_event, "rb"); 164 fp_ev = fopen(buffer_event, "rb");
165 if (fp_ev == NULL) { 165 if (fp_ev == NULL) {
166 printf("Failed to open %s\n", buffer_event); 166 printf("Failed to open %s\n", buffer_event);
167 ret = -errno; 167 ret = -errno;
168 goto error_close_buffer_access; 168 goto error_close_buffer_access;
169 } 169 }
170 170
171 /* Wait for events 10 times */ 171 /* Wait for events 10 times */
172 for (j = 0; j < num_loops; j++) { 172 for (j = 0; j < num_loops; j++) {
173 read_size = fread(&dat, 1, sizeof(struct iio_event_data), 173 read_size = fread(&dat, 1, sizeof(struct iio_event_data),
174 fp_ev); 174 fp_ev);
175 switch (dat.id) { 175 switch (dat.id) {
176 case IIO_EVENT_CODE_RING_100_FULL: 176 case IIO_EVENT_CODE_RING_100_FULL:
177 toread = buf_len; 177 toread = buf_len;
178 break; 178 break;
179 case IIO_EVENT_CODE_RING_75_FULL: 179 case IIO_EVENT_CODE_RING_75_FULL:
180 toread = buf_len*3/4; 180 toread = buf_len*3/4;
181 break; 181 break;
182 case IIO_EVENT_CODE_RING_50_FULL: 182 case IIO_EVENT_CODE_RING_50_FULL:
183 toread = buf_len/2; 183 toread = buf_len/2;
184 break; 184 break;
185 default: 185 default:
186 printf("Unexpecteded event code\n"); 186 printf("Unexpecteded event code\n");
187 continue; 187 continue;
188 } 188 }
189 read_size = read(fp, 189 read_size = read(fp,
190 data, 190 data,
191 toread*size_from_scanmode(num_vals, scan_ts)); 191 toread*size_from_scanmode(num_vals, scan_ts));
192 if (read_size == -EAGAIN) { 192 if (read_size == -EAGAIN) {
193 printf("nothing available\n"); 193 printf("nothing available\n");
194 continue; 194 continue;
195 } 195 }
196 scan_size = size_from_scanmode(num_vals, scan_ts); 196 scan_size = size_from_scanmode(num_vals, scan_ts);
197 for (i = 0; i < read_size/scan_size; i++) { 197 for (i = 0; i < read_size/scan_size; i++) {
198 for (k = 0; k < num_vals; k++) { 198 for (k = 0; k < num_vals; k++) {
199 __s16 val = *(__s16 *)(&data[i*scan_size 199 __s16 val = *(__s16 *)(&data[i*scan_size
200 + (k)*2]); 200 + (k)*2]);
201 printf("%05f ", (float)val*gain); 201 printf("%05f ", (float)val*gain);
202 } 202 }
203 printf(" %lld\n", 203 printf(" %lld\n",
204 *(__s64 *)(&data[(i + 1) 204 *(__s64 *)(&data[(i + 1)
205 *size_from_scanmode(num_vals, 205 *size_from_scanmode(num_vals,
206 scan_ts) 206 scan_ts)
207 - sizeof(__s64)])); 207 - sizeof(__s64)]));
208 } 208 }
209 } 209 }
210 210
211 /* Stop the ring buffer */ 211 /* Stop the ring buffer */
212 ret = write_sysfs_int("ring_enable", buf_dir_name, 0); 212 ret = write_sysfs_int("enable", buf_dir_name, 0);
213 if (ret < 0) 213 if (ret < 0)
214 goto error_close_buffer_event; 214 goto error_close_buffer_event;
215 215
216 /* Disconnect from the trigger - just write a dummy name.*/ 216 /* Disconnect from the trigger - just write a dummy name.*/
217 write_sysfs_string("trigger/current_trigger", 217 write_sysfs_string("trigger/current_trigger",
218 dev_dir_name, "NULL"); 218 dev_dir_name, "NULL");
219 219
220 error_close_buffer_event: 220 error_close_buffer_event:
221 fclose(fp_ev); 221 fclose(fp_ev);
222 error_close_buffer_access: 222 error_close_buffer_access:
223 close(fp); 223 close(fp);
224 error_free_data: 224 error_free_data:
225 free(data); 225 free(data);
226 error_free_buffer_access: 226 error_free_buffer_access:
227 free(buffer_access); 227 free(buffer_access);
228 error_free_buffer_event: 228 error_free_buffer_event:
229 free(buffer_event); 229 free(buffer_event);
230 error_free_buf_dir_name: 230 error_free_buf_dir_name:
231 free(buf_dir_name); 231 free(buf_dir_name);
232 error_free_triggername: 232 error_free_triggername:
233 free(trigger_name); 233 free(trigger_name);
234 error_free_dev_dir_name: 234 error_free_dev_dir_name:
235 free(dev_dir_name); 235 free(dev_dir_name);
236 error_ret: 236 error_ret:
237 return ret; 237 return ret;
238 } 238 }
239 239
drivers/staging/iio/trigger.h
1 /* The industrial I/O core, trigger handling functions 1 /* The industrial I/O core, trigger handling functions
2 * 2 *
3 * Copyright (c) 2008 Jonathan Cameron 3 * Copyright (c) 2008 Jonathan Cameron
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation. 7 * the Free Software Foundation.
8 */ 8 */
9 #ifndef _IIO_TRIGGER_H_ 9 #ifndef _IIO_TRIGGER_H_
10 #define _IIO_TRIGGER_H_ 10 #define _IIO_TRIGGER_H_
11 11
12 /** 12 /**
13 * struct iio_trigger - industrial I/O trigger device 13 * struct iio_trigger - industrial I/O trigger device
14 * 14 *
15 * @id: [INTERN] unique id number 15 * @id: [INTERN] unique id number
16 * @name: [DRIVER] unique name 16 * @name: [DRIVER] unique name
17 * @dev: [DRIVER] associated device (if relevant) 17 * @dev: [DRIVER] associated device (if relevant)
18 * @private_data: [DRIVER] device specific data 18 * @private_data: [DRIVER] device specific data
19 * @list: [INTERN] used in maintenance of global trigger list 19 * @list: [INTERN] used in maintenance of global trigger list
20 * @alloc_list: [DRIVER] used for driver specific trigger list 20 * @alloc_list: [DRIVER] used for driver specific trigger list
21 * @pollfunc_list_lock: [INTERN] protection of the polling function list 21 * @pollfunc_list_lock: [INTERN] protection of the polling function list
22 * @pollfunc_list: [INTERN] list of functions to run on trigger. 22 * @pollfunc_list: [INTERN] list of functions to run on trigger.
23 * @control_attrs: [DRIVER] sysfs attributes relevant to trigger type 23 * @control_attrs: [DRIVER] sysfs attributes relevant to trigger type
24 * @owner: [DRIVER] used to monitor usage count of the trigger. 24 * @owner: [DRIVER] used to monitor usage count of the trigger.
25 * @use_count: use count for the trigger 25 * @use_count: use count for the trigger
26 * @set_trigger_state: [DRIVER] switch on/off the trigger on demand 26 * @set_trigger_state: [DRIVER] switch on/off the trigger on demand
27 * @try_reenable: function to reenable the trigger when the 27 * @try_reenable: function to reenable the trigger when the
28 * use count is zero (may be NULL) 28 * use count is zero (may be NULL)
29 **/ 29 **/
30 struct iio_trigger { 30 struct iio_trigger {
31 int id; 31 int id;
32 const char *name; 32 const char *name;
33 struct device dev; 33 struct device dev;
34 34
35 void *private_data; 35 void *private_data;
36 struct list_head list; 36 struct list_head list;
37 struct list_head alloc_list; 37 struct list_head alloc_list;
38 spinlock_t pollfunc_list_lock; 38 spinlock_t pollfunc_list_lock;
39 struct list_head pollfunc_list; 39 struct list_head pollfunc_list;
40 const struct attribute_group *control_attrs; 40 const struct attribute_group *control_attrs;
41 struct module *owner; 41 struct module *owner;
42 int use_count; 42 int use_count;
43 43
44 int (*set_trigger_state)(struct iio_trigger *trig, bool state); 44 int (*set_trigger_state)(struct iio_trigger *trig, bool state);
45 int (*try_reenable)(struct iio_trigger *trig); 45 int (*try_reenable)(struct iio_trigger *trig);
46 }; 46 };
47 47
48 static inline struct iio_trigger *to_iio_trigger(struct device *d) 48 static inline struct iio_trigger *to_iio_trigger(struct device *d)
49 { 49 {
50 return container_of(d, struct iio_trigger, dev); 50 return container_of(d, struct iio_trigger, dev);
51 }; 51 };
52 52
53 static inline void iio_put_trigger(struct iio_trigger *trig) 53 static inline void iio_put_trigger(struct iio_trigger *trig)
54 { 54 {
55 put_device(&trig->dev); 55 put_device(&trig->dev);
56 module_put(trig->owner); 56 module_put(trig->owner);
57 }; 57 };
58 58
59 static inline void iio_get_trigger(struct iio_trigger *trig) 59 static inline void iio_get_trigger(struct iio_trigger *trig)
60 { 60 {
61 __module_get(trig->owner); 61 __module_get(trig->owner);
62 get_device(&trig->dev); 62 get_device(&trig->dev);
63 }; 63 };
64 64
65 /** 65 /**
66 * iio_trigger_read_name() - sysfs access function to get the trigger name 66 * iio_trigger_read_name() - sysfs access function to get the trigger name
67 * @dev: the system device 67 * @dev: the system device
68 * @attr: device attributes for the device 68 * @attr: device attributes for the device
69 * @buf: output buffer to store the trigger name 69 * @buf: output buffer to store the trigger name
70 **/ 70 **/
71 ssize_t iio_trigger_read_name(struct device *dev, 71 ssize_t iio_trigger_read_name(struct device *dev,
72 struct device_attribute *attr, 72 struct device_attribute *attr,
73 char *buf); 73 char *buf);
74 74
75 #define IIO_TRIGGER_NAME_ATTR DEVICE_ATTR(name, S_IRUGO, \ 75 #define IIO_TRIGGER_NAME_ATTR DEVICE_ATTR(name, S_IRUGO, \
76 iio_trigger_read_name, \ 76 iio_trigger_read_name, \
77 NULL); 77 NULL);
78 78
79 /** 79 /**
80 * iio_trigger_find_by_name() - search global trigger list 80 * iio_trigger_find_by_name() - search global trigger list
81 * @name: trigger name to search for 81 * @name: trigger name to search for
82 * @len: trigger name string length to compare 82 * @len: trigger name string length to compare
83 **/ 83 **/
84 struct iio_trigger *iio_trigger_find_by_name(const char *name, size_t len); 84 struct iio_trigger *iio_trigger_find_by_name(const char *name, size_t len);
85 85
86 /** 86 /**
87 * iio_trigger_register() - register a trigger with the IIO core 87 * iio_trigger_register() - register a trigger with the IIO core
88 * @trig_info: trigger to be registered 88 * @trig_info: trigger to be registered
89 **/ 89 **/
90 int iio_trigger_register(struct iio_trigger *trig_info); 90 int iio_trigger_register(struct iio_trigger *trig_info);
91 91
92 /** 92 /**
93 * iio_trigger_unregister() - unregister a trigger from the core 93 * iio_trigger_unregister() - unregister a trigger from the core
94 * @trig_info: trigger to be unregistered 94 * @trig_info: trigger to be unregistered
95 **/ 95 **/
96 void iio_trigger_unregister(struct iio_trigger *trig_info); 96 void iio_trigger_unregister(struct iio_trigger *trig_info);
97 97
98 /** 98 /**
99 * iio_trigger_attach_poll_func() - add a function pair to be run on trigger 99 * iio_trigger_attach_poll_func() - add a function pair to be run on trigger
100 * @trig: trigger to which the function pair are being added 100 * @trig: trigger to which the function pair are being added
101 * @pf: poll function pair 101 * @pf: poll function pair
102 **/ 102 **/
103 int iio_trigger_attach_poll_func(struct iio_trigger *trig, 103 int iio_trigger_attach_poll_func(struct iio_trigger *trig,
104 struct iio_poll_func *pf); 104 struct iio_poll_func *pf);
105 105
106 /** 106 /**
107 * iio_trigger_dettach_poll_func() - remove function pair from those to be 107 * iio_trigger_dettach_poll_func() - remove function pair from those to be
108 * run on trigger 108 * run on trigger
109 * @trig: trigger from which the function is being removed 109 * @trig: trigger from which the function is being removed
110 * @pf: poll function pair 110 * @pf: poll function pair
111 **/ 111 **/
112 int iio_trigger_dettach_poll_func(struct iio_trigger *trig, 112 int iio_trigger_dettach_poll_func(struct iio_trigger *trig,
113 struct iio_poll_func *pf); 113 struct iio_poll_func *pf);
114 114
115 /** 115 /**
116 * iio_trigger_poll() - called on a trigger occurring 116 * iio_trigger_poll() - called on a trigger occurring
117 * @trig: trigger which occurred 117 * @trig: trigger which occurred
118 * 118 *
119 * Typically called in relevant hardware interrupt handler. 119 * Typically called in relevant hardware interrupt handler.
120 **/ 120 **/
121 void iio_trigger_poll(struct iio_trigger *trig, s64 time); 121 void iio_trigger_poll(struct iio_trigger *trig, s64 time);
122 void iio_trigger_notify_done(struct iio_trigger *trig); 122 void iio_trigger_notify_done(struct iio_trigger *trig);
123 123
124 /** 124 /**
125 * struct iio_poll_func - poll function pair 125 * struct iio_poll_func - poll function pair
126 * 126 *
127 * @list: associate this with a triggers pollfunc_list 127 * @list: associate this with a triggers pollfunc_list
128 * @private_data: data specific to device (passed into poll func) 128 * @private_data: data specific to device (passed into poll func)
129 * @poll_func_immediate: function in here is run first. They should be 129 * @poll_func_immediate: function in here is run first. They should be
130 * extremely lightweight. Typically used for latch 130 * extremely lightweight. Typically used for latch
131 * control on sensor supporting it. 131 * control on sensor supporting it.
132 * @poll_func_main: function in here is run after all immediates. 132 * @poll_func_main: function in here is run after all immediates.
133 * Reading from sensor etc typically involves 133 * Reading from sensor etc typically involves
134 * scheduling from here. 134 * scheduling from here.
135 * 135 *
136 * The two stage approach used here is only important when multiple sensors are 136 * The two stage approach used here is only important when multiple sensors are
137 * being triggered by a single trigger. This really comes into its own with 137 * being triggered by a single trigger. This really comes into its own with
138 * simultaneous sampling devices where a simple latch command can be used to 138 * simultaneous sampling devices where a simple latch command can be used to
139 * make the device store the values on all inputs. 139 * make the device store the values on all inputs.
140 **/ 140 **/
141 struct iio_poll_func { 141 struct iio_poll_func {
142 struct list_head list; 142 struct list_head list;
143 void *private_data; 143 void *private_data;
144 void (*poll_func_immediate)(struct iio_dev *indio_dev); 144 void (*poll_func_immediate)(struct iio_dev *indio_dev);
145 void (*poll_func_main)(struct iio_dev *private_data, s64 time); 145 void (*poll_func_main)(struct iio_dev *private_data, s64 time);
146 146
147 }; 147 };
148 148
149 int iio_alloc_pollfunc(struct iio_dev *indio_dev, 149 int iio_alloc_pollfunc(struct iio_dev *indio_dev,
150 void (*immediate)(struct iio_dev *indio_dev), 150 void (*immediate)(struct iio_dev *indio_dev),
151 void (*main)(struct iio_dev *private_data, s64 time)); 151 void (*main)(struct iio_dev *private_data, s64 time));
152 152
153 /* 153 /*
154 * Two functions for common case where all that happens is a pollfunc 154 * Two functions for common case where all that happens is a pollfunc
155 * is attached and detached form a trigger 155 * is attached and detached from a trigger
156 */ 156 */
157 int iio_triggered_ring_postenable(struct iio_dev *indio_dev); 157 int iio_triggered_ring_postenable(struct iio_dev *indio_dev);
158 int iio_triggered_ring_predisable(struct iio_dev *indio_dev); 158 int iio_triggered_ring_predisable(struct iio_dev *indio_dev);
159 159
160 struct iio_trigger *iio_allocate_trigger(void); 160 struct iio_trigger *iio_allocate_trigger(void);
161 161
162 void iio_free_trigger(struct iio_trigger *trig); 162 void iio_free_trigger(struct iio_trigger *trig);
163 163
164 #endif /* _IIO_TRIGGER_H_ */ 164 #endif /* _IIO_TRIGGER_H_ */
165 165