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