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>
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;
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 */
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;
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 */
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;
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 */
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;
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 */
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;
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 */
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;
}
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;
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;
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 */
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;
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 */
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);
}
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;
}
= (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;
}
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;
}
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);
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 */
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
*
* @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.
* @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;
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;
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);
};
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;
}
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)
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;
}
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) {
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;
}
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]);
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;
}
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);