2009-08-18 19:06:26 +02:00
|
|
|
/* The industrial I/O core, trigger handling functions
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Jonathan Cameron
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*/
|
2011-05-18 15:41:18 +02:00
|
|
|
#include <linux/irq.h>
|
|
|
|
|
2009-08-18 19:06:26 +02:00
|
|
|
#ifndef _IIO_TRIGGER_H_
|
|
|
|
#define _IIO_TRIGGER_H_
|
|
|
|
|
2011-05-18 15:41:18 +02:00
|
|
|
struct iio_subirq {
|
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
2009-08-18 19:06:26 +02:00
|
|
|
/**
|
|
|
|
* struct iio_trigger - industrial I/O trigger device
|
|
|
|
*
|
|
|
|
* @id: [INTERN] unique id number
|
|
|
|
* @name: [DRIVER] unique name
|
|
|
|
* @dev: [DRIVER] associated device (if relevant)
|
|
|
|
* @private_data: [DRIVER] device specific data
|
|
|
|
* @list: [INTERN] used in maintenance of global trigger list
|
|
|
|
* @alloc_list: [DRIVER] used for driver specific trigger list
|
|
|
|
* @owner: [DRIVER] used to monitor usage count of the trigger.
|
2009-10-05 04:34:02 +02:00
|
|
|
* @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)
|
2011-06-27 14:07:09 +02:00
|
|
|
* @validate_device: function to validate the device when the
|
|
|
|
* current trigger gets changed.
|
2011-05-18 15:42:22 +02:00
|
|
|
* @subirq_chip: [INTERN] associate 'virtual' irq chip.
|
|
|
|
* @subirq_base: [INTERN] base number for irqs provided by trigger.
|
|
|
|
* @subirqs: [INTERN] information about the 'child' irqs.
|
|
|
|
* @pool: [INTERN] bitmap of irqs currently in use.
|
|
|
|
* @pool_lock: [INTERN] protection of the irq pool.
|
2009-08-18 19:06:26 +02:00
|
|
|
**/
|
|
|
|
struct iio_trigger {
|
|
|
|
int id;
|
|
|
|
const char *name;
|
|
|
|
struct device dev;
|
|
|
|
|
|
|
|
void *private_data;
|
|
|
|
struct list_head list;
|
|
|
|
struct list_head alloc_list;
|
|
|
|
struct module *owner;
|
|
|
|
int use_count;
|
|
|
|
|
|
|
|
int (*set_trigger_state)(struct iio_trigger *trig, bool state);
|
|
|
|
int (*try_reenable)(struct iio_trigger *trig);
|
2011-06-27 14:07:09 +02:00
|
|
|
int (*validate_device)(struct iio_trigger *trig,
|
|
|
|
struct iio_dev *indio_dev);
|
2011-05-18 15:41:18 +02:00
|
|
|
|
|
|
|
struct irq_chip subirq_chip;
|
|
|
|
int subirq_base;
|
|
|
|
|
|
|
|
struct iio_subirq subirqs[CONFIG_IIO_CONSUMERS_PER_TRIGGER];
|
|
|
|
unsigned long pool[BITS_TO_LONGS(CONFIG_IIO_CONSUMERS_PER_TRIGGER)];
|
|
|
|
struct mutex pool_lock;
|
2009-08-18 19:06:26 +02:00
|
|
|
};
|
|
|
|
|
2011-06-27 14:07:08 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
2009-08-18 19:06:26 +02:00
|
|
|
static inline struct iio_trigger *to_iio_trigger(struct device *d)
|
|
|
|
{
|
|
|
|
return container_of(d, struct iio_trigger, dev);
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void iio_put_trigger(struct iio_trigger *trig)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iio_trigger_register() - register a trigger with the IIO core
|
|
|
|
* @trig_info: trigger to be registered
|
|
|
|
**/
|
|
|
|
int iio_trigger_register(struct iio_trigger *trig_info);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iio_trigger_unregister() - unregister a trigger from the core
|
2009-10-05 04:34:02 +02:00
|
|
|
* @trig_info: trigger to be unregistered
|
2009-08-18 19:06:26 +02:00
|
|
|
**/
|
|
|
|
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
|
2009-10-05 04:34:02 +02:00
|
|
|
* @pf: poll function pair
|
2009-08-18 19:06:26 +02:00
|
|
|
**/
|
|
|
|
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
|
2009-10-05 04:34:02 +02:00
|
|
|
* run on trigger
|
|
|
|
* @trig: trigger from which the function is being removed
|
2009-08-18 19:06:26 +02:00
|
|
|
* @pf: poll function pair
|
|
|
|
**/
|
|
|
|
int iio_trigger_dettach_poll_func(struct iio_trigger *trig,
|
|
|
|
struct iio_poll_func *pf);
|
|
|
|
|
|
|
|
/**
|
2009-10-05 04:34:02 +02:00
|
|
|
* iio_trigger_poll() - called on a trigger occurring
|
|
|
|
* @trig: trigger which occurred
|
|
|
|
*
|
2009-08-18 19:06:26 +02:00
|
|
|
* Typically called in relevant hardware interrupt handler.
|
|
|
|
**/
|
2010-07-11 17:39:11 +02:00
|
|
|
void iio_trigger_poll(struct iio_trigger *trig, s64 time);
|
2011-05-18 15:42:11 +02:00
|
|
|
void iio_trigger_poll_chained(struct iio_trigger *trig, s64 time);
|
2009-10-05 04:34:02 +02:00
|
|
|
void iio_trigger_notify_done(struct iio_trigger *trig);
|
2009-08-18 19:06:26 +02:00
|
|
|
|
2011-05-18 15:41:21 +02:00
|
|
|
irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
|
|
|
|
|
2011-05-18 15:41:18 +02:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2011-05-18 15:42:32 +02:00
|
|
|
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);
|
2011-05-18 15:41:18 +02:00
|
|
|
irqreturn_t iio_pollfunc_store_time(int irq, void *p);
|
|
|
|
|
2010-07-11 17:39:10 +02:00
|
|
|
/*
|
|
|
|
* Two functions for common case where all that happens is a pollfunc
|
2010-09-04 18:54:50 +02:00
|
|
|
* is attached and detached from a trigger
|
2010-07-11 17:39:10 +02:00
|
|
|
*/
|
|
|
|
int iio_triggered_ring_postenable(struct iio_dev *indio_dev);
|
|
|
|
int iio_triggered_ring_predisable(struct iio_dev *indio_dev);
|
|
|
|
|
2011-05-18 15:42:22 +02:00
|
|
|
struct iio_trigger *iio_allocate_trigger(const char *fmt, ...)
|
|
|
|
__attribute__((format(printf, 1, 2)));
|
2009-08-18 19:06:26 +02:00
|
|
|
void iio_free_trigger(struct iio_trigger *trig);
|
|
|
|
|
|
|
|
#endif /* _IIO_TRIGGER_H_ */
|