Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/sage/ceph...
[deliverable/linux.git] / drivers / staging / iio / trigger.h
1 /* The industrial I/O core, trigger handling functions
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 #ifndef _IIO_TRIGGER_H_
10 #define _IIO_TRIGGER_H_
11
12 /**
13 * struct iio_trigger - industrial I/O trigger device
14 *
15 * @id: [INTERN] unique id number
16 * @name: [DRIVER] unique name
17 * @dev: [DRIVER] associated device (if relevant)
18 * @private_data: [DRIVER] device specific data
19 * @list: [INTERN] used in maintenance of global trigger list
20 * @alloc_list: [DRIVER] used for driver specific trigger list
21 * @pollfunc_list_lock: [INTERN] protection of the polling function list
22 * @pollfunc_list: [INTERN] list of functions to run on trigger.
23 * @control_attrs: [DRIVER] sysfs attributes relevant to trigger type
24 * @owner: [DRIVER] used to monitor usage count of the trigger.
25 * @use_count: use count for the trigger
26 * @set_trigger_state: [DRIVER] switch on/off the trigger on demand
27 * @try_reenable: function to reenable the trigger when the
28 * use count is zero (may be NULL)
29 **/
30 struct iio_trigger {
31 int id;
32 const char *name;
33 struct device dev;
34
35 void *private_data;
36 struct list_head list;
37 struct list_head alloc_list;
38 spinlock_t pollfunc_list_lock;
39 struct list_head pollfunc_list;
40 const struct attribute_group *control_attrs;
41 struct module *owner;
42 int use_count;
43
44 int (*set_trigger_state)(struct iio_trigger *trig, bool state);
45 int (*try_reenable)(struct iio_trigger *trig);
46 };
47
48 static inline struct iio_trigger *to_iio_trigger(struct device *d)
49 {
50 return container_of(d, struct iio_trigger, dev);
51 };
52
53 static inline void iio_put_trigger(struct iio_trigger *trig)
54 {
55 put_device(&trig->dev);
56 module_put(trig->owner);
57 };
58
59 static inline void iio_get_trigger(struct iio_trigger *trig)
60 {
61 __module_get(trig->owner);
62 get_device(&trig->dev);
63 };
64
65 /**
66 * iio_trigger_read_name() - sysfs access function to get the trigger name
67 * @dev: the system device
68 * @attr: device attributes for the device
69 * @buf: output buffer to store the trigger name
70 **/
71 ssize_t iio_trigger_read_name(struct device *dev,
72 struct device_attribute *attr,
73 char *buf);
74
75 #define IIO_TRIGGER_NAME_ATTR DEVICE_ATTR(name, S_IRUGO, \
76 iio_trigger_read_name, \
77 NULL);
78
79 /**
80 * iio_trigger_find_by_name() - search global trigger list
81 * @name: trigger name to search for
82 * @len: trigger name string length to compare
83 **/
84 struct iio_trigger *iio_trigger_find_by_name(const char *name, size_t len);
85
86 /**
87 * iio_trigger_register() - register a trigger with the IIO core
88 * @trig_info: trigger to be registered
89 **/
90 int iio_trigger_register(struct iio_trigger *trig_info);
91
92 /**
93 * iio_trigger_unregister() - unregister a trigger from the core
94 * @trig_info: trigger to be unregistered
95 **/
96 void iio_trigger_unregister(struct iio_trigger *trig_info);
97
98 /**
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
101 * @pf: poll function pair
102 **/
103 int iio_trigger_attach_poll_func(struct iio_trigger *trig,
104 struct iio_poll_func *pf);
105
106 /**
107 * iio_trigger_dettach_poll_func() - remove function pair from those to be
108 * run on trigger
109 * @trig: trigger from which the function is being removed
110 * @pf: poll function pair
111 **/
112 int iio_trigger_dettach_poll_func(struct iio_trigger *trig,
113 struct iio_poll_func *pf);
114
115 /**
116 * iio_trigger_poll() - called on a trigger occurring
117 * @trig: trigger which occurred
118 *
119 * Typically called in relevant hardware interrupt handler.
120 **/
121 void iio_trigger_poll(struct iio_trigger *trig, s64 time);
122 void iio_trigger_notify_done(struct iio_trigger *trig);
123
124 /**
125 * struct iio_poll_func - poll function pair
126 *
127 * @list: associate this with a triggers pollfunc_list
128 * @private_data: data specific to device (passed into poll func)
129 * @poll_func_immediate: function in here is run first. They should be
130 * extremely lightweight. Typically used for latch
131 * control on sensor supporting it.
132 * @poll_func_main: function in here is run after all immediates.
133 * Reading from sensor etc typically involves
134 * scheduling from here.
135 *
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
138 * simultaneous sampling devices where a simple latch command can be used to
139 * make the device store the values on all inputs.
140 **/
141 struct iio_poll_func {
142 struct list_head list;
143 void *private_data;
144 void (*poll_func_immediate)(struct iio_dev *indio_dev);
145 void (*poll_func_main)(struct iio_dev *private_data, s64 time);
146
147 };
148
149 int iio_alloc_pollfunc(struct iio_dev *indio_dev,
150 void (*immediate)(struct iio_dev *indio_dev),
151 void (*main)(struct iio_dev *private_data, s64 time));
152
153 /*
154 * Two functions for common case where all that happens is a pollfunc
155 * is attached and detached from a trigger
156 */
157 int iio_triggered_ring_postenable(struct iio_dev *indio_dev);
158 int iio_triggered_ring_predisable(struct iio_dev *indio_dev);
159
160 struct iio_trigger *iio_allocate_trigger(void);
161
162 void iio_free_trigger(struct iio_trigger *trig);
163
164 #endif /* _IIO_TRIGGER_H_ */
This page took 0.032843 seconds and 5 git commands to generate.