diff options
Diffstat (limited to 'drivers/staging/iio/trigger.h')
-rw-r--r-- | drivers/staging/iio/trigger.h | 116 |
1 files changed, 25 insertions, 91 deletions
diff --git a/drivers/staging/iio/trigger.h b/drivers/staging/iio/trigger.h index e0b58ed749b..598fcb3599f 100644 --- a/drivers/staging/iio/trigger.h +++ b/drivers/staging/iio/trigger.h @@ -7,6 +7,7 @@ * the Free Software Foundation. */ #include <linux/irq.h> +#include <linux/module.h> #ifndef _IIO_TRIGGER_H_ #define _IIO_TRIGGER_H_ @@ -16,6 +17,27 @@ struct iio_subirq { }; /** + * struct iio_trigger_ops - operations structure for an iio_trigger. + * @owner: used to monitor usage count of the trigger. + * @set_trigger_state: switch on/off the trigger on demand + * @try_reenable: function to reenable the trigger when the + * use count is zero (may be NULL) + * @validate_device: function to validate the device when the + * current trigger gets changed. + * + * This is typically static const within a driver and shared by + * instances of a given device. + **/ +struct iio_trigger_ops { + struct module *owner; + int (*set_trigger_state)(struct iio_trigger *trig, bool state); + int (*try_reenable)(struct iio_trigger *trig); + int (*validate_device)(struct iio_trigger *trig, + struct iio_dev *indio_dev); +}; + + +/** * struct iio_trigger - industrial I/O trigger device * * @id: [INTERN] unique id number @@ -26,11 +48,6 @@ struct iio_subirq { * @alloc_list: [DRIVER] used for driver specific trigger list * @owner: [DRIVER] used to monitor usage count of the trigger. * @use_count: use count for the trigger - * @set_trigger_state: [DRIVER] switch on/off the trigger on demand - * @try_reenable: function to reenable the trigger when the - * use count is zero (may be NULL) - * @validate_device: function to validate the device when the - * current trigger gets changed. * @subirq_chip: [INTERN] associate 'virtual' irq chip. * @subirq_base: [INTERN] base number for irqs provided by trigger. * @subirqs: [INTERN] information about the 'child' irqs. @@ -38,6 +55,7 @@ struct iio_subirq { * @pool_lock: [INTERN] protection of the irq pool. **/ struct iio_trigger { + const struct iio_trigger_ops *ops; int id; const char *name; struct device dev; @@ -48,11 +66,6 @@ struct iio_trigger { struct module *owner; int use_count; - int (*set_trigger_state)(struct iio_trigger *trig, bool state); - int (*try_reenable)(struct iio_trigger *trig); - int (*validate_device)(struct iio_trigger *trig, - struct iio_dev *indio_dev); - struct irq_chip subirq_chip; int subirq_base; @@ -61,29 +74,6 @@ struct iio_trigger { struct mutex pool_lock; }; -/** - * struct iio_poll_func - poll function pair - * - * @private_data: data specific to device (passed into poll func) - * @h: the function that is actually run on trigger - * @thread: threaded interrupt part - * @type: the type of interrupt (basically if oneshot) - * @name: name used to identify the trigger consumer. - * @irq: the corresponding irq as allocated from the - * trigger pool - * @timestamp: some devices need a timestamp grabbed as soon - * as possible after the trigger - hence handler - * passes it via here. - **/ -struct iio_poll_func { - void *private_data; - irqreturn_t (*h)(int irq, void *p); - irqreturn_t (*thread)(int irq, void *p); - int type; - char *name; - int irq; - s64 timestamp; -}; static inline struct iio_trigger *to_iio_trigger(struct device *d) { @@ -92,14 +82,14 @@ static inline struct iio_trigger *to_iio_trigger(struct device *d) static inline void iio_put_trigger(struct iio_trigger *trig) { + module_put(trig->ops->owner); put_device(&trig->dev); - module_put(trig->owner); }; static inline void iio_get_trigger(struct iio_trigger *trig) { - __module_get(trig->owner); get_device(&trig->dev); + __module_get(trig->ops->owner); }; /** @@ -115,23 +105,6 @@ int iio_trigger_register(struct iio_trigger *trig_info); void iio_trigger_unregister(struct iio_trigger *trig_info); /** - * iio_trigger_attach_poll_func() - add a function pair to be run on trigger - * @trig: trigger to which the function pair are being added - * @pf: poll function pair - **/ -int iio_trigger_attach_poll_func(struct iio_trigger *trig, - struct iio_poll_func *pf); - -/** - * iio_trigger_dettach_poll_func() - remove function pair from those to be - * run on trigger - * @trig: trigger from which the function is being removed - * @pf: poll function pair - **/ -int iio_trigger_dettach_poll_func(struct iio_trigger *trig, - struct iio_poll_func *pf); - -/** * iio_trigger_poll() - called on a trigger occurring * @trig: trigger which occurred * @@ -139,48 +112,9 @@ int iio_trigger_dettach_poll_func(struct iio_trigger *trig, **/ void iio_trigger_poll(struct iio_trigger *trig, s64 time); void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time); -void iio_trigger_notify_done(struct iio_trigger *trig); irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private); -static inline int iio_trigger_get_irq(struct iio_trigger *trig) -{ - int ret; - mutex_lock(&trig->pool_lock); - ret = bitmap_find_free_region(trig->pool, - CONFIG_IIO_CONSUMERS_PER_TRIGGER, - ilog2(1)); - mutex_unlock(&trig->pool_lock); - if (ret >= 0) - ret += trig->subirq_base; - - return ret; -}; - -static inline void iio_trigger_put_irq(struct iio_trigger *trig, int irq) -{ - mutex_lock(&trig->pool_lock); - clear_bit(irq - trig->subirq_base, trig->pool); - mutex_unlock(&trig->pool_lock); -}; - -struct iio_poll_func -*iio_alloc_pollfunc(irqreturn_t (*h)(int irq, void *p), - irqreturn_t (*thread)(int irq, void *p), - int type, - void *private, - const char *fmt, - ...); -void iio_dealloc_pollfunc(struct iio_poll_func *pf); -irqreturn_t iio_pollfunc_store_time(int irq, void *p); - -/* - * Two functions for common case where all that happens is a pollfunc - * is attached and detached from a trigger - */ -int iio_triggered_ring_postenable(struct iio_dev *indio_dev); -int iio_triggered_ring_predisable(struct iio_dev *indio_dev); - struct iio_trigger *iio_allocate_trigger(const char *fmt, ...) __attribute__((format(printf, 1, 2))); void iio_free_trigger(struct iio_trigger *trig); |