staging:iio:trigger handle name attr in core, remove old alloc and register any contr...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / iio / trigger.h
blob7faa31a2421e8ae8aaa74e1981b0cf67c0a5949d
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 #include <linux/irq.h>
11 #ifndef _IIO_TRIGGER_H_
12 #define _IIO_TRIGGER_H_
14 struct iio_subirq {
15 bool enabled;
18 /**
19 * struct iio_trigger - industrial I/O trigger device
21 * @id: [INTERN] unique id number
22 * @name: [DRIVER] unique name
23 * @dev: [DRIVER] associated device (if relevant)
24 * @private_data: [DRIVER] device specific data
25 * @list: [INTERN] used in maintenance of global trigger list
26 * @alloc_list: [DRIVER] used for driver specific trigger list
27 * @owner: [DRIVER] used to monitor usage count of the trigger.
28 * @use_count: use count for the trigger
29 * @set_trigger_state: [DRIVER] switch on/off the trigger on demand
30 * @try_reenable: function to reenable the trigger when the
31 * use count is zero (may be NULL)
32 * @subirq_chip: [INTERN] associate 'virtual' irq chip.
33 * @subirq_base: [INTERN] base number for irqs provided by trigger.
34 * @subirqs: [INTERN] information about the 'child' irqs.
35 * @pool: [INTERN] bitmap of irqs currently in use.
36 * @pool_lock: [INTERN] protection of the irq pool.
37 **/
38 struct iio_trigger {
39 int id;
40 const char *name;
41 struct device dev;
43 void *private_data;
44 struct list_head list;
45 struct list_head alloc_list;
46 struct module *owner;
47 int use_count;
49 int (*set_trigger_state)(struct iio_trigger *trig, bool state);
50 int (*try_reenable)(struct iio_trigger *trig);
52 struct irq_chip subirq_chip;
53 int subirq_base;
55 struct iio_subirq subirqs[CONFIG_IIO_CONSUMERS_PER_TRIGGER];
56 unsigned long pool[BITS_TO_LONGS(CONFIG_IIO_CONSUMERS_PER_TRIGGER)];
57 struct mutex pool_lock;
60 static inline struct iio_trigger *to_iio_trigger(struct device *d)
62 return container_of(d, struct iio_trigger, dev);
65 static inline void iio_put_trigger(struct iio_trigger *trig)
67 put_device(&trig->dev);
68 module_put(trig->owner);
71 static inline void iio_get_trigger(struct iio_trigger *trig)
73 __module_get(trig->owner);
74 get_device(&trig->dev);
77 /**
78 * iio_trigger_register() - register a trigger with the IIO core
79 * @trig_info: trigger to be registered
80 **/
81 int iio_trigger_register(struct iio_trigger *trig_info);
83 /**
84 * iio_trigger_unregister() - unregister a trigger from the core
85 * @trig_info: trigger to be unregistered
86 **/
87 void iio_trigger_unregister(struct iio_trigger *trig_info);
89 /**
90 * iio_trigger_attach_poll_func() - add a function pair to be run on trigger
91 * @trig: trigger to which the function pair are being added
92 * @pf: poll function pair
93 **/
94 int iio_trigger_attach_poll_func(struct iio_trigger *trig,
95 struct iio_poll_func *pf);
97 /**
98 * iio_trigger_dettach_poll_func() - remove function pair from those to be
99 * run on trigger
100 * @trig: trigger from which the function is being removed
101 * @pf: poll function pair
103 int iio_trigger_dettach_poll_func(struct iio_trigger *trig,
104 struct iio_poll_func *pf);
107 * iio_trigger_poll() - called on a trigger occurring
108 * @trig: trigger which occurred
110 * Typically called in relevant hardware interrupt handler.
112 void iio_trigger_poll(struct iio_trigger *trig, s64 time);
113 void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time);
114 void iio_trigger_notify_done(struct iio_trigger *trig);
116 irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
118 static inline int iio_trigger_get_irq(struct iio_trigger *trig)
120 int ret;
121 mutex_lock(&trig->pool_lock);
122 ret = bitmap_find_free_region(trig->pool,
123 CONFIG_IIO_CONSUMERS_PER_TRIGGER,
124 ilog2(1));
125 mutex_unlock(&trig->pool_lock);
126 if (ret >= 0)
127 ret += trig->subirq_base;
129 return ret;
132 static inline void iio_trigger_put_irq(struct iio_trigger *trig, int irq)
134 mutex_lock(&trig->pool_lock);
135 clear_bit(irq - trig->subirq_base, trig->pool);
136 mutex_unlock(&trig->pool_lock);
140 * struct iio_poll_func - poll function pair
142 * @private_data: data specific to device (passed into poll func)
143 * @h: the function that is actually run on trigger
144 * @thread: threaded interrupt part
145 * @type: the type of interrupt (basically if oneshot)
146 * @name: name used to identify the trigger consumer.
147 * @irq: the corresponding irq as allocated from the
148 * trigger pool
149 * @timestamp: some devices need a timestamp grabbed as soon
150 * as possible after the trigger - hence handler
151 * passes it via here.
153 struct iio_poll_func {
154 void *private_data;
155 irqreturn_t (*h)(int irq, void *p);
156 irqreturn_t (*thread)(int irq, void *p);
157 int type;
158 char *name;
159 int irq;
160 s64 timestamp;
163 irqreturn_t iio_pollfunc_store_time(int irq, void *p);
166 * Two functions for common case where all that happens is a pollfunc
167 * is attached and detached from a trigger
169 int iio_triggered_ring_postenable(struct iio_dev *indio_dev);
170 int iio_triggered_ring_predisable(struct iio_dev *indio_dev);
172 struct iio_trigger *iio_allocate_trigger(const char *fmt, ...)
173 __attribute__((format(printf, 1, 2)));
174 void iio_free_trigger(struct iio_trigger *trig);
176 #endif /* _IIO_TRIGGER_H_ */