2009-08-19 00:06:26 +07: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 20:41:18 +07:00
|
|
|
#include <linux/irq.h>
|
2011-07-04 02:49:50 +07:00
|
|
|
#include <linux/module.h>
|
2013-07-16 21:28:00 +07:00
|
|
|
#include <linux/atomic.h>
|
2011-05-18 20:41:18 +07:00
|
|
|
|
2009-08-19 00:06:26 +07:00
|
|
|
#ifndef _IIO_TRIGGER_H_
|
|
|
|
#define _IIO_TRIGGER_H_
|
|
|
|
|
2013-02-09 17:49:00 +07:00
|
|
|
#ifdef CONFIG_IIO_TRIGGER
|
2011-05-18 20:41:18 +07:00
|
|
|
struct iio_subirq {
|
|
|
|
bool enabled;
|
|
|
|
};
|
|
|
|
|
2015-08-04 15:32:18 +07:00
|
|
|
struct iio_dev;
|
|
|
|
struct iio_trigger;
|
|
|
|
|
2011-08-12 23:08:38 +07:00
|
|
|
/**
|
|
|
|
* struct iio_trigger_ops - operations structure for an iio_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 {
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-08-19 00:06:26 +07:00
|
|
|
/**
|
|
|
|
* struct iio_trigger - industrial I/O trigger device
|
2012-08-26 19:43:00 +07:00
|
|
|
* @ops: [DRIVER] operations structure
|
2018-01-07 04:56:05 +07:00
|
|
|
* @owner: [INTERN] owner of this driver module
|
2009-08-19 00:06:26 +07:00
|
|
|
* @id: [INTERN] unique id number
|
|
|
|
* @name: [DRIVER] unique name
|
|
|
|
* @dev: [DRIVER] associated device (if relevant)
|
|
|
|
* @list: [INTERN] used in maintenance of global trigger list
|
|
|
|
* @alloc_list: [DRIVER] used for driver specific trigger list
|
2018-01-07 04:56:06 +07:00
|
|
|
* @use_count: [INTERN] use count for the trigger.
|
2011-05-18 20:42:22 +07: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.
|
2016-09-01 15:27:17 +07:00
|
|
|
* @attached_own_device:[INTERN] if we are using our own device as trigger,
|
|
|
|
* i.e. if we registered a poll function to the same
|
|
|
|
* device as the one providing the trigger.
|
2009-08-19 00:06:26 +07:00
|
|
|
**/
|
|
|
|
struct iio_trigger {
|
2011-08-12 23:08:38 +07:00
|
|
|
const struct iio_trigger_ops *ops;
|
2017-07-23 23:25:44 +07:00
|
|
|
struct module *owner;
|
2009-08-19 00:06:26 +07:00
|
|
|
int id;
|
|
|
|
const char *name;
|
|
|
|
struct device dev;
|
|
|
|
|
|
|
|
struct list_head list;
|
|
|
|
struct list_head alloc_list;
|
2013-07-16 21:28:00 +07:00
|
|
|
atomic_t use_count;
|
2009-08-19 00:06:26 +07:00
|
|
|
|
2011-05-18 20:41:18 +07: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;
|
2016-09-01 15:27:17 +07:00
|
|
|
bool attached_own_device;
|
2009-08-19 00:06:26 +07:00
|
|
|
};
|
|
|
|
|
2011-06-27 19:07:08 +07:00
|
|
|
|
2009-08-19 00:06:26 +07:00
|
|
|
static inline struct iio_trigger *to_iio_trigger(struct device *d)
|
|
|
|
{
|
|
|
|
return container_of(d, struct iio_trigger, dev);
|
2012-08-26 19:43:00 +07:00
|
|
|
}
|
2009-08-19 00:06:26 +07:00
|
|
|
|
2012-04-26 18:35:01 +07:00
|
|
|
static inline void iio_trigger_put(struct iio_trigger *trig)
|
2009-08-19 00:06:26 +07:00
|
|
|
{
|
2017-07-23 23:25:44 +07:00
|
|
|
module_put(trig->owner);
|
2011-08-24 23:28:34 +07:00
|
|
|
put_device(&trig->dev);
|
2012-08-26 19:43:00 +07:00
|
|
|
}
|
2009-08-19 00:06:26 +07:00
|
|
|
|
2014-08-23 03:48:00 +07:00
|
|
|
static inline struct iio_trigger *iio_trigger_get(struct iio_trigger *trig)
|
2009-08-19 00:06:26 +07:00
|
|
|
{
|
|
|
|
get_device(&trig->dev);
|
2017-07-23 23:25:44 +07:00
|
|
|
__module_get(trig->owner);
|
2014-08-23 03:48:00 +07:00
|
|
|
|
|
|
|
return trig;
|
2012-08-26 19:43:00 +07:00
|
|
|
}
|
2009-08-19 00:06:26 +07:00
|
|
|
|
2013-03-25 15:58:00 +07:00
|
|
|
/**
|
|
|
|
* iio_device_set_drvdata() - Set trigger driver data
|
|
|
|
* @trig: IIO trigger structure
|
|
|
|
* @data: Driver specific data
|
|
|
|
*
|
|
|
|
* Allows to attach an arbitrary pointer to an IIO trigger, which can later be
|
|
|
|
* retrieved by iio_trigger_get_drvdata().
|
|
|
|
*/
|
|
|
|
static inline void iio_trigger_set_drvdata(struct iio_trigger *trig, void *data)
|
|
|
|
{
|
2013-03-25 15:58:00 +07:00
|
|
|
dev_set_drvdata(&trig->dev, data);
|
2013-03-25 15:58:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iio_trigger_get_drvdata() - Get trigger driver data
|
|
|
|
* @trig: IIO trigger structure
|
|
|
|
*
|
|
|
|
* Returns the data previously set with iio_trigger_set_drvdata()
|
|
|
|
*/
|
|
|
|
static inline void *iio_trigger_get_drvdata(struct iio_trigger *trig)
|
|
|
|
{
|
2013-03-25 15:58:00 +07:00
|
|
|
return dev_get_drvdata(&trig->dev);
|
2013-03-25 15:58:00 +07:00
|
|
|
}
|
|
|
|
|
2009-08-19 00:06:26 +07:00
|
|
|
/**
|
|
|
|
* iio_trigger_register() - register a trigger with the IIO core
|
|
|
|
* @trig_info: trigger to be registered
|
|
|
|
**/
|
2017-07-23 23:25:44 +07:00
|
|
|
#define iio_trigger_register(trig_info) \
|
|
|
|
__iio_trigger_register((trig_info), THIS_MODULE)
|
|
|
|
int __iio_trigger_register(struct iio_trigger *trig_info,
|
|
|
|
struct module *this_mod);
|
|
|
|
|
|
|
|
#define devm_iio_trigger_register(dev, trig_info) \
|
|
|
|
__devm_iio_trigger_register((dev), (trig_info), THIS_MODULE)
|
|
|
|
int __devm_iio_trigger_register(struct device *dev,
|
|
|
|
struct iio_trigger *trig_info,
|
|
|
|
struct module *this_mod);
|
2016-09-03 01:47:54 +07:00
|
|
|
|
2009-08-19 00:06:26 +07:00
|
|
|
/**
|
|
|
|
* iio_trigger_unregister() - unregister a trigger from the core
|
2009-10-05 09:34:02 +07:00
|
|
|
* @trig_info: trigger to be unregistered
|
2009-08-19 00:06:26 +07:00
|
|
|
**/
|
|
|
|
void iio_trigger_unregister(struct iio_trigger *trig_info);
|
|
|
|
|
2016-09-03 01:47:54 +07:00
|
|
|
void devm_iio_trigger_unregister(struct device *dev,
|
|
|
|
struct iio_trigger *trig_info);
|
|
|
|
|
2016-09-03 13:36:15 +07:00
|
|
|
/**
|
|
|
|
* iio_trigger_set_immutable() - set an immutable trigger on destination
|
|
|
|
*
|
2017-07-31 05:14:42 +07:00
|
|
|
* @indio_dev: IIO device structure containing the device
|
|
|
|
* @trig: trigger to assign to device
|
2016-09-03 13:36:15 +07:00
|
|
|
*
|
|
|
|
**/
|
|
|
|
int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig);
|
|
|
|
|
2009-08-19 00:06:26 +07:00
|
|
|
/**
|
2009-10-05 09:34:02 +07:00
|
|
|
* iio_trigger_poll() - called on a trigger occurring
|
2012-08-26 19:43:00 +07:00
|
|
|
* @trig: trigger which occurred
|
2009-10-05 09:34:02 +07:00
|
|
|
*
|
2009-08-19 00:06:26 +07:00
|
|
|
* Typically called in relevant hardware interrupt handler.
|
|
|
|
**/
|
2014-12-06 13:46:00 +07:00
|
|
|
void iio_trigger_poll(struct iio_trigger *trig);
|
|
|
|
void iio_trigger_poll_chained(struct iio_trigger *trig);
|
2011-08-24 23:28:39 +07:00
|
|
|
|
2011-05-18 20:41:21 +07:00
|
|
|
irqreturn_t iio_trigger_generic_data_rdy_poll(int irq, void *private);
|
|
|
|
|
2012-04-26 18:35:01 +07:00
|
|
|
__printf(1, 2) struct iio_trigger *iio_trigger_alloc(const char *fmt, ...);
|
|
|
|
void iio_trigger_free(struct iio_trigger *trig);
|
2009-08-19 00:06:26 +07:00
|
|
|
|
2016-09-01 15:27:17 +07:00
|
|
|
/**
|
|
|
|
* iio_trigger_using_own() - tells us if we use our own HW trigger ourselves
|
|
|
|
* @indio_dev: device to check
|
|
|
|
*/
|
|
|
|
bool iio_trigger_using_own(struct iio_dev *indio_dev);
|
|
|
|
|
2016-09-23 22:19:41 +07:00
|
|
|
int iio_trigger_validate_own_device(struct iio_trigger *trig,
|
|
|
|
struct iio_dev *indio_dev);
|
2016-09-01 15:27:17 +07:00
|
|
|
|
2013-02-09 17:49:00 +07:00
|
|
|
#else
|
|
|
|
struct iio_trigger;
|
|
|
|
struct iio_trigger_ops;
|
|
|
|
#endif
|
2009-08-19 00:06:26 +07:00
|
|
|
#endif /* _IIO_TRIGGER_H_ */
|