Re: [PATCH v4 1/7] iio: dummy: Add virtual registers for dummy device

From: Jonathan Cameron
Date: Sat Nov 22 2014 - 06:07:05 EST


On 10/11/14 12:45, Daniel Baluta wrote:
> We need a way to store events generated by iio_dummy_evgen module,
> in order to correctly process IRQs in iio_simple_dummy_events.
>
> For the moment, we add two registers:
>
> * id_reg - ID register, stores the source of the event
> * id_data - DATA register, stores the type of the event
>
> e.g echo 4 > /sys/bus/iio/devices/iio_evgen/poke2
>
> id_reg 0x02, id_data 0x04
>
> This means, event of type 4 was generated by fake device 2.
>
> We currently use a hardcoded mapping of virtual events to IIO events.
>
> Signed-off-by: Irina Tirdea <irina.tirdea@xxxxxxxxx>
> Signed-off-by: Daniel Baluta <daniel.baluta@xxxxxxxxx>
Applied to the togreg branch of iio.git - initially push out as testing for
the autobuilders to pick a fight with it.
> ---
> drivers/staging/iio/iio_dummy_evgen.c | 17 +++++++++++++++++
> drivers/staging/iio/iio_dummy_evgen.h | 6 ++++++
> drivers/staging/iio/iio_simple_dummy.h | 2 ++
> drivers/staging/iio/iio_simple_dummy_events.c | 23 ++++++++++++++++++-----
> 4 files changed, 43 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/staging/iio/iio_dummy_evgen.c b/drivers/staging/iio/iio_dummy_evgen.c
> index 5a804f1..59ad5a3 100644
> --- a/drivers/staging/iio/iio_dummy_evgen.c
> +++ b/drivers/staging/iio/iio_dummy_evgen.c
> @@ -33,6 +33,7 @@
> * @base: base of irq range
> * @enabled: mask of which irqs are enabled
> * @inuse: mask of which irqs are connected
> + * @regs: irq regs we are faking
> * @lock: protect the evgen state
> */
> struct iio_dummy_eventgen {
> @@ -40,6 +41,7 @@ struct iio_dummy_eventgen {
> int base;
> bool enabled[IIO_EVENTGEN_NO];
> bool inuse[IIO_EVENTGEN_NO];
> + struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
> struct mutex lock;
> };
>
> @@ -136,6 +138,12 @@ int iio_dummy_evgen_release_irq(int irq)
> }
> EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq);
>
> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq)
> +{
> + return &iio_evgen->regs[irq - iio_evgen->base];
> +}
> +EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
> +
> static void iio_dummy_evgen_free(void)
> {
> irq_free_descs(iio_evgen->base, IIO_EVENTGEN_NO);
> @@ -153,6 +161,15 @@ static ssize_t iio_evgen_poke(struct device *dev,
> size_t len)
> {
> struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
> + unsigned long event;
> + int ret;
> +
> + ret = kstrtoul(buf, 10, &event);
> + if (ret)
> + return ret;
> +
> + iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
> + iio_evgen->regs[this_attr->address].reg_data = event;
>
> if (iio_evgen->enabled[this_attr->address])
> handle_nested_irq(iio_evgen->base + this_attr->address);
> diff --git a/drivers/staging/iio/iio_dummy_evgen.h b/drivers/staging/iio/iio_dummy_evgen.h
> index 3a18081..2ac293a 100644
> --- a/drivers/staging/iio/iio_dummy_evgen.h
> +++ b/drivers/staging/iio/iio_dummy_evgen.h
> @@ -1,6 +1,12 @@
> #ifndef _IIO_DUMMY_EVGEN_H_
> #define _IIO_DUMMY_EVGEN_H_
>
> +struct iio_dummy_regs {
> + u32 reg_id;
> + u32 reg_data;
> +};
> +
> +struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq);
> int iio_dummy_evgen_get_irq(void);
> int iio_dummy_evgen_release_irq(int irq);
>
> diff --git a/drivers/staging/iio/iio_simple_dummy.h b/drivers/staging/iio/iio_simple_dummy.h
> index 3027aed..ad89842 100644
> --- a/drivers/staging/iio/iio_simple_dummy.h
> +++ b/drivers/staging/iio/iio_simple_dummy.h
> @@ -13,6 +13,7 @@
> #include <linux/kernel.h>
>
> struct iio_dummy_accel_calibscale;
> +struct iio_dummy_regs;
>
> /**
> * struct iio_dummy_state - device instance specific state.
> @@ -35,6 +36,7 @@ struct iio_dummy_state {
> int accel_calibbias;
> const struct iio_dummy_accel_calibscale *accel_calibscale;
> struct mutex lock;
> + struct iio_dummy_regs *regs;
> #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
> int event_irq;
> int event_val;
> diff --git a/drivers/staging/iio/iio_simple_dummy_events.c b/drivers/staging/iio/iio_simple_dummy_events.c
> index 64b45b0..719dfa5 100644
> --- a/drivers/staging/iio/iio_simple_dummy_events.c
> +++ b/drivers/staging/iio/iio_simple_dummy_events.c
> @@ -148,12 +148,23 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
> static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
> {
> struct iio_dev *indio_dev = private;
> + struct iio_dummy_state *st = iio_priv(indio_dev);
> +
> + dev_dbg(&indio_dev->dev, "id %x event %x\n",
> + st->regs->reg_id, st->regs->reg_data);
> +
> + switch (st->regs->reg_data) {
> + case 0:
> + iio_push_event(indio_dev,
> + IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
> + IIO_EV_DIR_RISING,
> + IIO_EV_TYPE_THRESH, 0, 0, 0),
> + iio_get_time_ns());
> + break;
> + default:
> + break;
> + }
>
> - iio_push_event(indio_dev,
> - IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
> - IIO_EV_DIR_RISING,
> - IIO_EV_TYPE_THRESH, 0, 0, 0),
> - iio_get_time_ns());
> return IRQ_HANDLED;
> }
>
> @@ -179,6 +190,8 @@ int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
> ret = st->event_irq;
> goto error_ret;
> }
> + st->regs = iio_dummy_evgen_get_regs(st->event_irq);
> +
> ret = request_threaded_irq(st->event_irq,
> NULL,
> &iio_simple_dummy_event_handler,
>

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/