Commit 43a4360e authored by Michael Hennerich's avatar Michael Hennerich Committed by Greg Kroah-Hartman

iio: trigger: Add filter callback

Allow devices to reject triggers and vice versa.

Changes since V1:
Added kernel-doc
Moved callback into iio_info
Changed function naming
Revised return value passing
Add forward declaration to avoid warnings
Signed-off-by: default avatarMichael Hennerich <michael.hennerich@analog.com>
Acked-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 03e1672a
...@@ -204,6 +204,8 @@ static inline s64 iio_get_time_ns(void) ...@@ -204,6 +204,8 @@ static inline s64 iio_get_time_ns(void)
#define IIO_VAL_INT_PLUS_MICRO 2 #define IIO_VAL_INT_PLUS_MICRO 2
#define IIO_VAL_INT_PLUS_NANO 3 #define IIO_VAL_INT_PLUS_NANO 3
struct iio_trigger; /* forward declaration */
/** /**
* struct iio_info - constant information about device * struct iio_info - constant information about device
* @driver_module: module structure used to ensure correct * @driver_module: module structure used to ensure correct
...@@ -224,6 +226,8 @@ static inline s64 iio_get_time_ns(void) ...@@ -224,6 +226,8 @@ static inline s64 iio_get_time_ns(void)
* is event dependant. event_code specifies which event. * is event dependant. event_code specifies which event.
* @write_event_value: write the value associate with the event. * @write_event_value: write the value associate with the event.
* Meaning is event dependent. * Meaning is event dependent.
* @validate_trigger: function to validate the trigger when the
* current trigger gets changed.
**/ **/
struct iio_info { struct iio_info {
struct module *driver_module; struct module *driver_module;
...@@ -256,6 +260,9 @@ struct iio_info { ...@@ -256,6 +260,9 @@ struct iio_info {
int (*write_event_value)(struct iio_dev *indio_dev, int (*write_event_value)(struct iio_dev *indio_dev,
int event_code, int event_code,
int val); int val);
int (*validate_trigger)(struct iio_dev *indio_dev,
struct iio_trigger *trig);
}; };
/** /**
......
...@@ -340,6 +340,9 @@ static ssize_t iio_trigger_write_current(struct device *dev, ...@@ -340,6 +340,9 @@ static ssize_t iio_trigger_write_current(struct device *dev,
{ {
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct iio_trigger *oldtrig = dev_info->trig; struct iio_trigger *oldtrig = dev_info->trig;
struct iio_trigger *trig;
int ret;
mutex_lock(&dev_info->mlock); mutex_lock(&dev_info->mlock);
if (dev_info->currentmode == INDIO_RING_TRIGGERED) { if (dev_info->currentmode == INDIO_RING_TRIGGERED) {
mutex_unlock(&dev_info->mlock); mutex_unlock(&dev_info->mlock);
...@@ -347,7 +350,22 @@ static ssize_t iio_trigger_write_current(struct device *dev, ...@@ -347,7 +350,22 @@ static ssize_t iio_trigger_write_current(struct device *dev,
} }
mutex_unlock(&dev_info->mlock); mutex_unlock(&dev_info->mlock);
dev_info->trig = iio_trigger_find_by_name(buf, len); trig = iio_trigger_find_by_name(buf, len);
if (trig && dev_info->info->validate_trigger) {
ret = dev_info->info->validate_trigger(dev_info, trig);
if (ret)
return ret;
}
if (trig && trig->validate_device) {
ret = trig->validate_device(trig, dev_info);
if (ret)
return ret;
}
dev_info->trig = trig;
if (oldtrig && dev_info->trig != oldtrig) if (oldtrig && dev_info->trig != oldtrig)
iio_put_trigger(oldtrig); iio_put_trigger(oldtrig);
if (dev_info->trig) if (dev_info->trig)
......
...@@ -29,6 +29,8 @@ struct iio_subirq { ...@@ -29,6 +29,8 @@ struct iio_subirq {
* @set_trigger_state: [DRIVER] switch on/off the trigger on demand * @set_trigger_state: [DRIVER] switch on/off the trigger on demand
* @try_reenable: function to reenable the trigger when the * @try_reenable: function to reenable the trigger when the
* use count is zero (may be NULL) * 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_chip: [INTERN] associate 'virtual' irq chip.
* @subirq_base: [INTERN] base number for irqs provided by trigger. * @subirq_base: [INTERN] base number for irqs provided by trigger.
* @subirqs: [INTERN] information about the 'child' irqs. * @subirqs: [INTERN] information about the 'child' irqs.
...@@ -48,6 +50,8 @@ struct iio_trigger { ...@@ -48,6 +50,8 @@ struct iio_trigger {
int (*set_trigger_state)(struct iio_trigger *trig, bool state); int (*set_trigger_state)(struct iio_trigger *trig, bool state);
int (*try_reenable)(struct iio_trigger *trig); int (*try_reenable)(struct iio_trigger *trig);
int (*validate_device)(struct iio_trigger *trig,
struct iio_dev *indio_dev);
struct irq_chip subirq_chip; struct irq_chip subirq_chip;
int subirq_base; int subirq_base;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment