]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
iio: trigger: allow immutable triggers to be assigned
authorMatt Ranostay <mranostay@gmail.com>
Sat, 3 Sep 2016 06:36:15 +0000 (23:36 -0700)
committerJonathan Cameron <jic23@kernel.org>
Sat, 3 Sep 2016 14:31:55 +0000 (15:31 +0100)
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>
drivers/iio/industrialio-trigger.c
include/linux/iio/iio.h
include/linux/iio/trigger.h

index 7ad82fdd3e5bfb0e39565f93fb2491962f97e01b..3dde81e57e97d9e7f1e8962ba9f9882150b250fd 100644 (file)
@@ -119,6 +119,22 @@ void iio_trigger_unregister(struct iio_trigger *trig_info)
 }
 EXPORT_SYMBOL(iio_trigger_unregister);
 
+int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig)
+{
+       if (!indio_dev || !trig)
+               return -EINVAL;
+
+       mutex_lock(&indio_dev->mlock);
+       WARN_ON(indio_dev->trig_readonly);
+
+       indio_dev->trig = iio_trigger_get(trig);
+       indio_dev->trig_readonly = true;
+       mutex_unlock(&indio_dev->mlock);
+
+       return 0;
+}
+EXPORT_SYMBOL(iio_trigger_set_immutable);
+
 /* Search for trigger by name, assuming iio_trigger_list_lock held */
 static struct iio_trigger *__iio_trigger_find_by_name(const char *name)
 {
@@ -384,6 +400,10 @@ static ssize_t iio_trigger_write_current(struct device *dev,
                mutex_unlock(&indio_dev->mlock);
                return -EBUSY;
        }
+       if (indio_dev->trig_readonly) {
+               mutex_unlock(&indio_dev->mlock);
+               return -EPERM;
+       }
        mutex_unlock(&indio_dev->mlock);
 
        trig = iio_trigger_find_by_name(buf, len);
index 854e2dad1e0df71af7f0d29f443e07ed77b3f24f..786952cd509fa78085f0bced5b9d61c79e891f4a 100644 (file)
@@ -483,6 +483,7 @@ struct iio_buffer_setup_ops {
  * @scan_timestamp:    [INTERN] set if any buffers have requested timestamp
  * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  * @trig:              [INTERN] current device trigger (buffer modes)
+ * @trig_readonly      [INTERN] mark the current trigger immutable
  * @pollfunc:          [DRIVER] function run on trigger being received
  * @pollfunc_event:    [DRIVER] function run on events trigger being received
  * @channels:          [DRIVER] channel specification structure table
@@ -523,6 +524,7 @@ struct iio_dev {
        bool                            scan_timestamp;
        unsigned                        scan_index_timestamp;
        struct iio_trigger              *trig;
+       bool                            trig_readonly;
        struct iio_poll_func            *pollfunc;
        struct iio_poll_func            *pollfunc_event;
 
index 1c9e028e0d4a8223ace9236194c376b96a27d9d8..a122bdd4076cad73cbf6e19283b41401fde92c70 100644 (file)
@@ -131,6 +131,15 @@ int iio_trigger_register(struct iio_trigger *trig_info);
  **/
 void iio_trigger_unregister(struct iio_trigger *trig_info);
 
+/**
+ * iio_trigger_set_immutable() - set an immutable trigger on destination
+ *
+ * @indio_dev - IIO device structure containing the device
+ * @trig - trigger to assign to device
+ *
+ **/
+int iio_trigger_set_immutable(struct iio_dev *indio_dev, struct iio_trigger *trig);
+
 /**
  * iio_trigger_poll() - called on a trigger occurring
  * @trig:      trigger which occurred