Skip to content

Commit 356ae94

Browse files
Daniel Balutajic23
authored andcommitted
iio: dummy: Add virtual registers for dummy device
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 <[email protected]> Signed-off-by: Daniel Baluta <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d7d787d commit 356ae94

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

drivers/staging/iio/iio_dummy_evgen.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
* @base: base of irq range
3434
* @enabled: mask of which irqs are enabled
3535
* @inuse: mask of which irqs are connected
36+
* @regs: irq regs we are faking
3637
* @lock: protect the evgen state
3738
*/
3839
struct iio_dummy_eventgen {
3940
struct irq_chip chip;
4041
int base;
4142
bool enabled[IIO_EVENTGEN_NO];
4243
bool inuse[IIO_EVENTGEN_NO];
44+
struct iio_dummy_regs regs[IIO_EVENTGEN_NO];
4345
struct mutex lock;
4446
};
4547

@@ -136,6 +138,12 @@ int iio_dummy_evgen_release_irq(int irq)
136138
}
137139
EXPORT_SYMBOL_GPL(iio_dummy_evgen_release_irq);
138140

141+
struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq)
142+
{
143+
return &iio_evgen->regs[irq - iio_evgen->base];
144+
}
145+
EXPORT_SYMBOL_GPL(iio_dummy_evgen_get_regs);
146+
139147
static void iio_dummy_evgen_free(void)
140148
{
141149
irq_free_descs(iio_evgen->base, IIO_EVENTGEN_NO);
@@ -153,6 +161,15 @@ static ssize_t iio_evgen_poke(struct device *dev,
153161
size_t len)
154162
{
155163
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
164+
unsigned long event;
165+
int ret;
166+
167+
ret = kstrtoul(buf, 10, &event);
168+
if (ret)
169+
return ret;
170+
171+
iio_evgen->regs[this_attr->address].reg_id = this_attr->address;
172+
iio_evgen->regs[this_attr->address].reg_data = event;
156173

157174
if (iio_evgen->enabled[this_attr->address])
158175
handle_nested_irq(iio_evgen->base + this_attr->address);

drivers/staging/iio/iio_dummy_evgen.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#ifndef _IIO_DUMMY_EVGEN_H_
22
#define _IIO_DUMMY_EVGEN_H_
33

4+
struct iio_dummy_regs {
5+
u32 reg_id;
6+
u32 reg_data;
7+
};
8+
9+
struct iio_dummy_regs *iio_dummy_evgen_get_regs(int irq);
410
int iio_dummy_evgen_get_irq(void);
511
int iio_dummy_evgen_release_irq(int irq);
612

drivers/staging/iio/iio_simple_dummy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/kernel.h>
1414

1515
struct iio_dummy_accel_calibscale;
16+
struct iio_dummy_regs;
1617

1718
/**
1819
* struct iio_dummy_state - device instance specific state.
@@ -35,6 +36,7 @@ struct iio_dummy_state {
3536
int accel_calibbias;
3637
const struct iio_dummy_accel_calibscale *accel_calibscale;
3738
struct mutex lock;
39+
struct iio_dummy_regs *regs;
3840
#ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS
3941
int event_irq;
4042
int event_val;

drivers/staging/iio/iio_simple_dummy_events.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,23 @@ int iio_simple_dummy_write_event_value(struct iio_dev *indio_dev,
148148
static irqreturn_t iio_simple_dummy_event_handler(int irq, void *private)
149149
{
150150
struct iio_dev *indio_dev = private;
151+
struct iio_dummy_state *st = iio_priv(indio_dev);
152+
153+
dev_dbg(&indio_dev->dev, "id %x event %x\n",
154+
st->regs->reg_id, st->regs->reg_data);
155+
156+
switch (st->regs->reg_data) {
157+
case 0:
158+
iio_push_event(indio_dev,
159+
IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
160+
IIO_EV_DIR_RISING,
161+
IIO_EV_TYPE_THRESH, 0, 0, 0),
162+
iio_get_time_ns());
163+
break;
164+
default:
165+
break;
166+
}
151167

152-
iio_push_event(indio_dev,
153-
IIO_EVENT_CODE(IIO_VOLTAGE, 0, 0,
154-
IIO_EV_DIR_RISING,
155-
IIO_EV_TYPE_THRESH, 0, 0, 0),
156-
iio_get_time_ns());
157168
return IRQ_HANDLED;
158169
}
159170

@@ -179,6 +190,8 @@ int iio_simple_dummy_events_register(struct iio_dev *indio_dev)
179190
ret = st->event_irq;
180191
goto error_ret;
181192
}
193+
st->regs = iio_dummy_evgen_get_regs(st->event_irq);
194+
182195
ret = request_threaded_irq(st->event_irq,
183196
NULL,
184197
&iio_simple_dummy_event_handler,

0 commit comments

Comments
 (0)