staging: iio: Use kasprintf to allocate and fill trig->name
[linux-2.6/x86.git] / drivers / staging / iio / trigger.h
blob89610b54e114de67fa37f285c53fbf57a8780497
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.
8 */
9 #ifndef _IIO_TRIGGER_H_
10 #define _IIO_TRIGGER_H_
12 /**
13 * struct iio_trigger - industrial I/O trigger device
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 **/
31 struct iio_trigger {
32 int id;
33 const char *name;
34 struct device dev;
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;
46 int (*set_trigger_state)(struct iio_trigger *trig, bool state);
47 int (*try_reenable)(struct iio_trigger *trig);
50 static inline struct iio_trigger *to_iio_trigger(struct device *d)
52 return container_of(d, struct iio_trigger, dev);
55 static inline void iio_put_trigger(struct iio_trigger *trig)
57 put_device(&trig->dev);
58 module_put(trig->owner);
61 static inline void iio_get_trigger(struct iio_trigger *trig)
63 __module_get(trig->owner);
64 get_device(&trig->dev);
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 **/
73 ssize_t iio_trigger_read_name(struct device *dev,
74 struct device_attribute *attr,
75 char *buf);
77 #define IIO_TRIGGER_NAME_ATTR DEVICE_ATTR(name, S_IRUGO, \
78 iio_trigger_read_name, \
79 NULL);
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 **/
86 struct iio_trigger *iio_trigger_find_by_name(const char *name, size_t len);
88 /**
89 * iio_trigger_register() - register a trigger with the IIO core
90 * @trig_info: trigger to be registered
91 **/
92 int iio_trigger_register(struct iio_trigger *trig_info);
94 /**
95 * iio_trigger_unregister() - unregister a trigger from the core
96 * @trig_info: trigger to be unregistered
97 **/
98 void iio_trigger_unregister(struct iio_trigger *trig_info);
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
105 int iio_trigger_attach_poll_func(struct iio_trigger *trig,
106 struct iio_poll_func *pf);
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
114 int iio_trigger_dettach_poll_func(struct iio_trigger *trig,
115 struct iio_poll_func *pf);
118 * iio_trigger_poll() - called on a trigger occurring
119 * @trig: trigger which occurred
121 * Typically called in relevant hardware interrupt handler.
123 void iio_trigger_poll(struct iio_trigger *trig);
124 void iio_trigger_notify_done(struct iio_trigger *trig);
127 * struct iio_poll_func - poll function pair
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.
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.
143 struct 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);
151 struct iio_trigger *iio_allocate_trigger(void);
153 void iio_free_trigger(struct iio_trigger *trig);
156 #endif /* _IIO_TRIGGER_H_ */