1 /* The industrial I/O core, trigger handling functions
3 * Copyright (c) 2008 Jonathan Cameron
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.
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"
17 * struct iio_trigger - industrial I/O trigger device
19 * @id: [INTERN] unique id number
20 * @name: [DRIVER] unique name
21 * @dev: [DRIVER] associated device (if relevant)
22 * @sysfs_dev: [INTERN] sysfs relevant device
23 * @private_data: [DRIVER] device specific data
24 * @list: [INTERN] used in maintenance of global trigger list
25 * @alloc_list: [DRIVER] used for driver specific trigger list
26 * @poll_func_list_lock:[INTERN] protection of the polling function list
27 * @pollfunc_list: [INTERN] list of functions to run on trigger.
28 * @control_attrs: [DRIVER] sysfs attributes relevant to trigger type
29 * @set_trigger_state: [DRIVER] switch on/off the trigger on demand
30 * @timestamp: [INTERN] timestamp usesd by some trigs (e.g. datardy)
31 * @owner: [DRIVER] used to monitor usage count of the trigger.
39 struct list_head list
;
40 struct list_head alloc_list
;
41 spinlock_t pollfunc_list_lock
;
42 struct list_head pollfunc_list
;
43 const struct attribute_group
*control_attrs
;
48 int (*set_trigger_state
)(struct iio_trigger
*trig
, bool state
);
49 int (*try_reenable
)(struct iio_trigger
*trig
);
52 static inline struct iio_trigger
*to_iio_trigger(struct device
*d
)
54 return container_of(d
, struct iio_trigger
, dev
);
57 static inline void iio_put_trigger(struct iio_trigger
*trig
)
59 put_device(&trig
->dev
);
60 module_put(trig
->owner
);
63 static inline void iio_get_trigger(struct iio_trigger
*trig
)
65 __module_get(trig
->owner
);
66 get_device(&trig
->dev
);
70 * iio_trigger_read_name() - sysfs access function to get the trigger name
72 ssize_t
iio_trigger_read_name(struct device
*dev
,
73 struct device_attribute
*attr
,
76 #define IIO_TRIGGER_NAME_ATTR DEVICE_ATTR(name, S_IRUGO, \
77 iio_trigger_read_name, \
81 * iio_trigger_find_by_name() - search global trigger list
83 struct iio_trigger
*iio_trigger_find_by_name(const char *name
, size_t len
);
86 * iio_trigger_register() - register a trigger with the IIO core
87 * @trig_info: trigger to be registered
89 int iio_trigger_register(struct iio_trigger
*trig_info
);
92 * iio_trigger_unregister() - unregister a trigger from the core
94 void iio_trigger_unregister(struct iio_trigger
*trig_info
);
97 * iio_trigger_attach_poll_func() - add a function pair to be run on trigger
98 * @trig: trigger to which the function pair are being added
99 * @pf: poll function pair
101 int iio_trigger_attach_poll_func(struct iio_trigger
*trig
,
102 struct iio_poll_func
*pf
);
105 * iio_trigger_dettach_poll_func() - remove function pair from those to be
107 * @trig: trigger from which the function is being removed.
108 * @pf: poll function pair
110 int iio_trigger_dettach_poll_func(struct iio_trigger
*trig
,
111 struct iio_poll_func
*pf
);
114 * iio_trigger_poll() - called on a trigger occuring
115 * Typically called in relevant hardware interrupt handler.
117 void iio_trigger_poll(struct iio_trigger
*);
118 void iio_trigger_notify_done(struct iio_trigger
*);
121 * struct iio_poll_func - poll function pair
123 * @list: associate this with a triggers pollfunc_list
124 * @private_data: data specific to device (passed into poll func)
125 * @poll_func_immediate: function in here is run first. They should be
126 * extremely lightweight. Typically used for latch
127 * control on sensor supporting it.
128 * @poll_func_main: function in here is run after all immediates.
129 * Reading from sensor etc typically involves
133 * The two stage approach used here only important when multiple sensors are
134 * being triggered by a single trigger. This really comes into it's own with
135 * simultaneous sampling devices where a simple latch command can be used to
136 * make the device store the values on all inputs.
138 struct iio_poll_func
{
139 struct list_head list
;
141 void (*poll_func_immediate
)(struct iio_dev
*indio_dev
);
142 void (*poll_func_main
)(struct iio_dev
*private_data
);
146 struct iio_trigger
*iio_allocate_trigger(void);
148 void iio_free_trigger(struct iio_trigger
*trig
);
151 #endif /* _IIO_TRIGGER_H_ */