#include "iio_dummy_evgen.h"
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
+#include <linux/irq_work.h>
/* Fiddly bit of faking and irq without hardware */
#define IIO_EVENTGEN_NO 10
+
+/**
+ * struct iio_dummy_handle_irq - helper struct to simulate interrupt generation
+ * @work: irq_work used to run handlers from hardirq context
+ * @irq: fake irq line number to trigger an interrupt
+ */
+struct iio_dummy_handle_irq {
+ struct irq_work work;
+ int irq;
+};
+
/**
* struct iio_dummy_evgen - evgen state
* @chip: irq chip we are faking
* @inuse: mask of which irqs are connected
* @regs: irq regs we are faking
* @lock: protect the evgen state
+ * @handler: helper for a 'hardware-like' interrupt simulation
*/
struct iio_dummy_eventgen {
struct irq_chip chip;
bool inuse[IIO_EVENTGEN_NO];
struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
struct mutex lock;
+ struct iio_dummy_handle_irq handler;
};
/* We can only ever have one instance of this 'device' */
evgen->enabled[d->irq - evgen->base] = true;
}
+static void iio_dummy_work_handler(struct irq_work *work)
+{
+ struct iio_dummy_handle_irq *irq_handler;
+
+ irq_handler = container_of(work, struct iio_dummy_handle_irq, work);
+ handle_simple_irq(irq_handler->irq, irq_to_desc(irq_handler->irq));
+}
+
static int iio_dummy_evgen_create(void)
{
int ret, i;
IRQ_NOREQUEST | IRQ_NOAUTOEN,
IRQ_NOPROBE);
}
+ init_irq_work(&iio_evgen->handler.work, iio_dummy_work_handler);
mutex_init(&iio_evgen->lock);
return 0;
}
iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
iio_evgen->regs[this_attr->address].reg_data = event;
+ iio_evgen->handler.irq = iio_evgen->base + this_attr->address;
if (iio_evgen->enabled[this_attr->address])
- handle_nested_irq(iio_evgen->base + this_attr->address);
+ irq_work_queue(&iio_evgen->handler.work);
return len;
}
return 0;
}
+static irqreturn_t iio_simple_dummy_get_timestamp(int irq, void *private)
+{
+ struct iio_dev *indio_dev = private;
+ struct iio_dummy_state *st = iio_priv(indio_dev);
+
+ st->event_timestamp = iio_get_time_ns();
+ return IRQ_HANDLED;
+}
+
/**
* iio_simple_dummy_event_handler() - identify and pass on event
* @irq: irq of event line
IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
IIO_EV_DIR_RISING,
IIO_EV_TYPE_THRESH, 0, 0, 0),
- iio_get_time_ns());
+ st->event_timestamp);
break;
case 1:
if (st->activity_running > st->event_val)
IIO_EV_DIR_RISING,
IIO_EV_TYPE_THRESH,
0, 0, 0),
- iio_get_time_ns());
+ st->event_timestamp);
break;
case 2:
if (st->activity_walking < st->event_val)
IIO_EV_DIR_FALLING,
IIO_EV_TYPE_THRESH,
0, 0, 0),
- iio_get_time_ns());
+ st->event_timestamp);
break;
case 3:
iio_push_event(indio_dev,
IIO_EVENT_CODE(IIO_STEPS, 0, IIO_NO_MOD,
IIO_EV_DIR_NONE,
IIO_EV_TYPE_CHANGE, 0, 0, 0),
- iio_get_time_ns());
+ st->event_timestamp);
break;
default:
break;
st->regs = iio_dummy_evgen_get_regs(st->event_irq);
ret = request_threaded_irq(st->event_irq,
- NULL,
+ &iio_simple_dummy_get_timestamp,
&iio_simple_dummy_event_handler,
IRQF_ONESHOT,
"iio_simple_event",