staging:iio:triggers introduce iio_trigger_ops to take const bits out of iio_trig_str...
authorJonathan Cameron <jic23@cam.ac.uk>
Fri, 12 Aug 2011 16:08:38 +0000 (17:08 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 23 Aug 2011 20:31:06 +0000 (13:31 -0700)
Right now this results in increased code, but I still think it is worth doing to avoid
replication across instances of drivers etc and move as much stuff as possible to constant.
Ops structure is optional for the occasional driver that uses none of it (currently
only the ad7793).

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
15 files changed:
drivers/staging/iio/accel/adis16201_trigger.c
drivers/staging/iio/accel/adis16203_trigger.c
drivers/staging/iio/accel/adis16204_trigger.c
drivers/staging/iio/accel/adis16209_trigger.c
drivers/staging/iio/accel/adis16240_trigger.c
drivers/staging/iio/accel/lis3l02dq_ring.c
drivers/staging/iio/gyro/adis16260_trigger.c
drivers/staging/iio/imu/adis16400_trigger.c
drivers/staging/iio/industrialio-trigger.c
drivers/staging/iio/meter/ade7758_trigger.c
drivers/staging/iio/trigger.h
drivers/staging/iio/trigger/iio-trig-bfin-timer.c
drivers/staging/iio/trigger/iio-trig-gpio.c
drivers/staging/iio/trigger/iio-trig-periodic-rtc.c
drivers/staging/iio/trigger/iio-trig-sysfs.c

index 3a95c083b45215f7c52eca7dbe97c3899f82a3c5..7c853a6f7003dfb9f84b238b5246194b5a2f0230 100644 (file)
@@ -23,6 +23,11 @@ static int adis16201_data_rdy_trigger_set_state(struct iio_trigger *trig,
        return adis16201_set_irq(indio_dev, state);
 }
 
+static const struct iio_trigger_ops adis16201_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &adis16201_data_rdy_trigger_set_state,
+};
+
 int adis16201_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -41,9 +46,8 @@ int adis16201_probe_trigger(struct iio_dev *indio_dev)
        if (ret)
                goto error_free_trig;
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &adis16201_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &adis16201_data_rdy_trigger_set_state;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index 3caf3e8bc9d95e036d417f055670e4d82e01a915..9ea1c1e1e1c508b76aa2a295e9b4aa2cee596468 100644 (file)
@@ -24,6 +24,11 @@ static int adis16203_data_rdy_trigger_set_state(struct iio_trigger *trig,
        return adis16203_set_irq(indio_dev, state);
 }
 
+static const struct iio_trigger_ops adis16203_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &adis16203_data_rdy_trigger_set_state,
+};
+
 int adis16203_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -44,9 +49,8 @@ int adis16203_probe_trigger(struct iio_dev *indio_dev)
                goto error_free_trig;
 
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &adis16203_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &adis16203_data_rdy_trigger_set_state;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index 01f73b9b8886db9ad1629af47f5105a243a60ed4..bd6d293a818e9ca0869be26c0a91e0cb76abd6c9 100644 (file)
@@ -24,6 +24,11 @@ static int adis16204_data_rdy_trigger_set_state(struct iio_trigger *trig,
        return adis16204_set_irq(indio_dev, state);
 }
 
+static const struct iio_trigger_ops adis16204_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &adis16204_data_rdy_trigger_set_state,
+};
+
 int adis16204_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -44,9 +49,8 @@ int adis16204_probe_trigger(struct iio_dev *indio_dev)
                goto error_free_trig;
 
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &adis16204_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &adis16204_data_rdy_trigger_set_state;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index 6df7b47ec7b43ea38de6d8718849da20a8826dfb..4c6df9e564fd5cc95f74b1e1264c83d24e464990 100644 (file)
@@ -33,6 +33,11 @@ static int adis16209_data_rdy_trigger_set_state(struct iio_trigger *trig,
        return adis16209_set_irq(indio_dev, state);
 }
 
+static const struct iio_trigger_ops adis16209_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &adis16209_data_rdy_trigger_set_state,
+};
+
 int adis16209_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -52,9 +57,8 @@ int adis16209_probe_trigger(struct iio_dev *indio_dev)
        if (ret)
                goto error_free_trig;
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &adis16209_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &adis16209_data_rdy_trigger_set_state;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index 17135fc33c9928a7c99904adff6b5ef69473da31..0c75338964397ce90583348f0703a7841cb9b65d 100644 (file)
@@ -33,6 +33,11 @@ static int adis16240_data_rdy_trigger_set_state(struct iio_trigger *trig,
        return adis16240_set_irq(indio_dev, state);
 }
 
+static const struct iio_trigger_ops adis16240_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &adis16240_data_rdy_trigger_set_state,
+};
+
 int adis16240_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -53,9 +58,8 @@ int adis16240_probe_trigger(struct iio_dev *indio_dev)
                goto error_free_trig;
 
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &adis16240_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &adis16240_data_rdy_trigger_set_state;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index 8d5c8ac7db5197f8b0334ccc11a8be128605376c..5795f82c1f17d8a0b3398c06de2005206dda355b 100644 (file)
@@ -306,6 +306,12 @@ static int lis3l02dq_trig_try_reen(struct iio_trigger *trig)
        return 0;
 }
 
+static const struct iio_trigger_ops lis3l02dq_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &lis3l02dq_data_rdy_trigger_set_state,
+       .try_reenable = &lis3l02dq_trig_try_reen,
+};
+
 int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -318,10 +324,8 @@ int lis3l02dq_probe_trigger(struct iio_dev *indio_dev)
        }
 
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &lis3l02dq_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &lis3l02dq_data_rdy_trigger_set_state;
-       st->trig->try_reenable = &lis3l02dq_trig_try_reen;
        ret = iio_trigger_register(st->trig);
        if (ret)
                goto error_free_trig;
index 01094d0e714a8a9a28694588581e32e9a59f9f0c..f2409615706630693db345398f6bc7e09a4b7307 100644 (file)
@@ -24,6 +24,11 @@ static int adis16260_data_rdy_trigger_set_state(struct iio_trigger *trig,
        return adis16260_set_irq(indio_dev, state);
 }
 
+static const struct iio_trigger_ops adis16260_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &adis16260_data_rdy_trigger_set_state,
+};
+
 int adis16260_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -46,9 +51,8 @@ int adis16260_probe_trigger(struct iio_dev *indio_dev)
                goto error_free_trig;
 
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &adis16260_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &adis16260_data_rdy_trigger_set_state;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index ce981731a34016393dd99d2d9b345971790c53c5..3860d92f1ae742514da52d6846566dd5d6afc7a8 100644 (file)
@@ -18,6 +18,11 @@ static int adis16400_data_rdy_trigger_set_state(struct iio_trigger *trig,
        return adis16400_set_irq(indio_dev, state);
 }
 
+static const struct iio_trigger_ops adis16400_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &adis16400_data_rdy_trigger_set_state,
+};
+
 int adis16400_probe_trigger(struct iio_dev *indio_dev)
 {
        int ret;
@@ -39,9 +44,8 @@ int adis16400_probe_trigger(struct iio_dev *indio_dev)
        if (ret)
                goto error_free_trig;
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &adis16400_data_rdy_trigger_set_state;
+       st->trig->ops = &adis16400_trigger_ops;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index 90ca2df23eab37aa7c60fd428c22633d642ac61d..513a7a04099c9e86d94fd27b7707bc8c4d7426bd 100644 (file)
@@ -206,8 +206,8 @@ EXPORT_SYMBOL(iio_trigger_poll_chained);
 void iio_trigger_notify_done(struct iio_trigger *trig)
 {
        trig->use_count--;
-       if (trig->use_count == 0 && trig->try_reenable)
-               if (trig->try_reenable(trig)) {
+       if (trig->use_count == 0 && trig->ops && trig->ops->try_reenable)
+               if (trig->ops->try_reenable(trig)) {
                        /* Missed and interrupt so launch new poll now */
                        iio_trigger_poll(trig, 0);
                }
@@ -234,8 +234,8 @@ int iio_trigger_attach_poll_func(struct iio_trigger *trig,
        ret = request_threaded_irq(pf->irq, pf->h, pf->thread,
                                   pf->type, pf->name,
                                   pf);
-       if (trig->set_trigger_state && notinuse)
-               ret = trig->set_trigger_state(trig, true);
+       if (trig->ops && trig->ops->set_trigger_state && notinuse)
+               ret = trig->ops->set_trigger_state(trig, true);
 
        return ret;
 }
@@ -249,8 +249,8 @@ int iio_trigger_dettach_poll_func(struct iio_trigger *trig,
                = (bitmap_weight(trig->pool,
                                 CONFIG_IIO_CONSUMERS_PER_TRIGGER)
                   == 1);
-       if (trig->set_trigger_state && no_other_users) {
-               ret = trig->set_trigger_state(trig, false);
+       if (trig->ops && trig->ops->set_trigger_state && no_other_users) {
+               ret = trig->ops->set_trigger_state(trig, false);
                if (ret)
                        goto error_ret;
        }
@@ -358,8 +358,8 @@ static ssize_t iio_trigger_write_current(struct device *dev,
                        return ret;
        }
 
-       if (trig && trig->validate_device) {
-               ret = trig->validate_device(trig, dev_info);
+       if (trig && trig->ops && trig->ops->validate_device) {
+               ret = trig->ops->validate_device(trig, dev_info);
                if (ret)
                        return ret;
        }
index a5c3248151ed6e2fafd2eaf91c53d0b6fa3d7ddb..4c451c26efbd70ed9cfa1bc37b625dcbc48c57fa 100644 (file)
@@ -57,6 +57,12 @@ static int ade7758_trig_try_reen(struct iio_trigger *trig)
        return 0;
 }
 
+static const struct iio_trigger_ops ade7758_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &ade7758_data_rdy_trigger_set_state,
+       .try_reenable = &ade7758_trig_try_reen,
+};
+
 int ade7758_probe_trigger(struct iio_dev *indio_dev)
 {
        struct ade7758_state *st = iio_priv(indio_dev);
@@ -79,10 +85,8 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev)
                goto error_free_trig;
 
        st->trig->dev.parent = &st->us->dev;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &ade7758_trigger_ops;
        st->trig->private_data = indio_dev;
-       st->trig->set_trigger_state = &ade7758_data_rdy_trigger_set_state;
-       st->trig->try_reenable = &ade7758_trig_try_reen;
        ret = iio_trigger_register(st->trig);
 
        /* select default trigger */
index e0b58ed749b89a2585a56705b17be61054e50bda..325e086e9e6867d9640e1c44745e5994e4562958 100644 (file)
@@ -15,6 +15,27 @@ struct iio_subirq {
        bool enabled;
 };
 
+/**
+ * struct iio_trigger_ops - operations structure for an iio_trigger.
+ * @owner:             used to monitor usage count of the 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 {
+       struct module                   *owner;
+       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);
+};
+
+
 /**
  * struct iio_trigger - industrial I/O trigger device
  *
@@ -26,11 +47,6 @@ struct iio_subirq {
  * @alloc_list:                [DRIVER] used for driver specific trigger list
  * @owner:             [DRIVER] used to monitor usage count of the trigger.
  * @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)
- * @validate_device:   function to validate the device when the
- *                     current trigger gets changed.
  * @subirq_chip:       [INTERN] associate 'virtual' irq chip.
  * @subirq_base:       [INTERN] base number for irqs provided by trigger.
  * @subirqs:           [INTERN] information about the 'child' irqs.
@@ -38,6 +54,7 @@ struct iio_subirq {
  * @pool_lock:         [INTERN] protection of the irq pool.
  **/
 struct iio_trigger {
+       const struct iio_trigger_ops    *ops;
        int                             id;
        const char                      *name;
        struct device                   dev;
@@ -48,11 +65,6 @@ struct iio_trigger {
        struct module                   *owner;
        int use_count;
 
-       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);
-
        struct irq_chip                 subirq_chip;
        int                             subirq_base;
 
@@ -93,12 +105,12 @@ static inline struct iio_trigger *to_iio_trigger(struct device *d)
 static inline void iio_put_trigger(struct iio_trigger *trig)
 {
        put_device(&trig->dev);
-       module_put(trig->owner);
+       module_put(trig->ops->owner);
 };
 
 static inline void iio_get_trigger(struct iio_trigger *trig)
 {
-       __module_get(trig->owner);
+       __module_get(trig->ops->owner);
        get_device(&trig->dev);
 };
 
index 4f1729565582f3853efade06cdf024ad5eed06da..243f38f80de13681b2f0464b8690f37eba7a8c8a 100644 (file)
@@ -143,6 +143,10 @@ static int iio_bfin_tmr_get_number(int irq)
        return -ENODEV;
 }
 
+static const struct iio_trigger_ops iio_bfin_tmr_trigger_ops = {
+       owner = THIS_MODULE,
+};
+
 static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
 {
        struct bfin_tmr_state *st;
@@ -175,7 +179,7 @@ static int __devinit iio_bfin_tmr_trigger_probe(struct platform_device *pdev)
        }
 
        st->trig->private_data = st;
-       st->trig->owner = THIS_MODULE;
+       st->trig->ops = &iio_bfin_tmr_trigger_ops;
        st->trig->dev.groups = iio_bfin_tmr_trigger_attr_groups;
        ret = iio_trigger_register(st->trig);
        if (ret)
index f1fb795e6410beac64894c15858a082124f4f52b..f2a6559816223bbbeed16e4354084efa2360389e 100644 (file)
@@ -47,6 +47,10 @@ static irqreturn_t iio_gpio_trigger_poll(int irq, void *private)
        return IRQ_HANDLED;
 }
 
+static const struct iio_trigger_ops iio_gpio_trigger_ops = {
+       .owner = THIS_MODULE,
+};
+
 static int iio_gpio_trigger_probe(struct platform_device *pdev)
 {
        struct iio_gpio_trigger_info *trig_info;
@@ -81,7 +85,7 @@ static int iio_gpio_trigger_probe(struct platform_device *pdev)
                        }
                        trig->private_data = trig_info;
                        trig_info->irq = irq;
-                       trig->owner = THIS_MODULE;
+                       trig->ops = &iio_gpio_trigger_ops;
                        ret = request_irq(irq, iio_gpio_trigger_poll,
                                          irqflags, trig->name, trig);
                        if (ret) {
index 01cf7e20b515bf45922e306d263070aedc695444..d35d085da949f00f0934ad44fd227898d4cdb016 100644 (file)
@@ -96,6 +96,11 @@ static void iio_prtc_trigger_poll(void *private_data)
        iio_trigger_poll(private_data, 0);
 }
 
+static const struct iio_trigger_ops iio_prtc_trigger_ops = {
+       .owner = THIS_MODULE,
+       .set_trigger_state = &iio_trig_periodic_rtc_set_state,
+};
+
 static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
 {
        char **pdata = dev->dev.platform_data;
@@ -121,7 +126,7 @@ static int iio_trig_periodic_rtc_probe(struct platform_device *dev)
                }
                trig->private_data = trig_info;
                trig->owner = THIS_MODULE;
-               trig->set_trigger_state = &iio_trig_periodic_rtc_set_state;
+               trig->ops = &iio_prtc_trigger_ops;
                /* RTC access */
                trig_info->rtc
                        = rtc_class_open(pdata[i]);
index 47248cd1fa0d6e91df443cf14c90acf31f710de2..346b30c2f7f737ff39f2b71229a4296cc426db9a 100644 (file)
@@ -107,6 +107,10 @@ static const struct attribute_group *iio_sysfs_trigger_attr_groups[] = {
        NULL
 };
 
+static const struct iio_trigger_ops iio_sysfs_trigger_ops = {
+       .owner = THIS_MODULE,
+};
+
 static int iio_sysfs_trigger_probe(int id)
 {
        struct iio_sysfs_trig *t;
@@ -135,7 +139,7 @@ static int iio_sysfs_trigger_probe(int id)
        }
 
        t->trig->dev.groups = iio_sysfs_trigger_attr_groups;
-       t->trig->owner = THIS_MODULE;
+       t->trig->ops = &iio_sysfs_trigger_ops;
        t->trig->dev.parent = &iio_sysfs_trig_dev;
 
        ret = iio_trigger_register(t->trig);