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