aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/industrialio-trigger.c
diff options
context:
space:
mode:
authorMatt Ranostay <mranostay@gmail.com>2016-09-03 02:36:15 -0400
committerJonathan Cameron <jic23@kernel.org>2016-09-03 10:31:55 -0400
commitc8cdf70890d89c07c9e890b103106d58999f0ce4 (patch)
treec96f5fa74ac061a3151b1099119a584c55a18a85 /drivers/iio/industrialio-trigger.c
parenta5c8b11a361065db028721c62aa880bfe0736aa6 (diff)
iio: trigger: allow immutable triggers to be assigned
There are times when an assigned trigger to a device shouldn't ever change after intialization. Examples of this being used is when an provider device has a trigger that is assigned to an ADC, which uses it populate data into a callback buffer. Signed-off-by: Matt Ranostay <matt@ranostay.consulting> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/industrialio-trigger.c')
-rw-r--r--drivers/iio/industrialio-trigger.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/drivers/iio/industrialio-trigger.c b/drivers/iio/industrialio-trigger.c
index 7ad82fdd3e5b..3dde81e57e97 100644
--- a/drivers/iio/industrialio-trigger.c
+++ b/drivers/iio/industrialio-trigger.c
@@ -119,6 +119,22 @@ void iio_trigger_unregister(struct iio_trigger *trig_info)
119} 119}
120EXPORT_SYMBOL(iio_trigger_unregister); 120EXPORT_SYMBOL(iio_trigger_unregister);
121 121
122int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig)
123{
124 if (!indio_dev || !trig)
125 return -EINVAL;
126
127 mutex_lock(&indio_dev->mlock);
128 WARN_ON(indio_dev->trig_readonly);
129
130 indio_dev->trig = iio_trigger_get(trig);
131 indio_dev->trig_readonly = true;
132 mutex_unlock(&indio_dev->mlock);
133
134 return 0;
135}
136EXPORT_SYMBOL(iio_trigger_set_immutable);
137
122/* Search for trigger by name, assuming iio_trigger_list_lock held */ 138/* Search for trigger by name, assuming iio_trigger_list_lock held */
123static struct iio_trigger *__iio_trigger_find_by_name(const char *name) 139static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
124{ 140{
@@ -384,6 +400,10 @@ static ssize_t iio_trigger_write_current(struct device *dev,
384 mutex_unlock(&indio_dev->mlock); 400 mutex_unlock(&indio_dev->mlock);
385 return -EBUSY; 401 return -EBUSY;
386 } 402 }
403 if (indio_dev->trig_readonly) {
404 mutex_unlock(&indio_dev->mlock);
405 return -EPERM;
406 }
387 mutex_unlock(&indio_dev->mlock); 407 mutex_unlock(&indio_dev->mlock);
388 408
389 trig = iio_trigger_find_by_name(buf, len); 409 trig = iio_trigger_find_by_name(buf, len);