Skip to content

Commit 53c0bee

Browse files
bigguinessgregkh
authored andcommitted
staging: comedi: aio_iiro_16: return input state in async command sample
Modify the sample data returned by the async command to include the current state of the digital inputs. Otherwise the command needs to be canceled in order for the user to do an (*insn_bits) operation to check the digital inputs. Signed-off-by: H Hartley Sweeten <[email protected]> Reviewed-by: Ian Abbott <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent be8e890 commit 53c0bee

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

drivers/staging/comedi/drivers/aio_iiro_16.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@
2727
*
2828
* The board supports interrupts on change of state of the digital inputs.
2929
* The sample data returned by the async command indicates which inputs
30-
* changed state:
30+
* changed state and the current state of the inputs:
3131
*
32-
* Bit 7 - IRQ Enable (1) / Disable (0)
33-
* Bit 1 - Input 8-15 Changed State (1 = Changed, 0 = No Change)
34-
* Bit 0 - Input 0-7 Changed State (1 = Changed, 0 = No Change)
32+
* Bit 23 - IRQ Enable (1) / Disable (0)
33+
* Bit 17 - Input 8-15 Changed State (1 = Changed, 0 = No Change)
34+
* Bit 16 - Input 0-7 Changed State (1 = Changed, 0 = No Change)
35+
* Bit 15 - Digital input 15
36+
* ...
37+
* Bit 0 - Digital input 0
3538
*/
3639

3740
#include <linux/module.h>
@@ -51,17 +54,31 @@
5154
#define AIO_IIRO_16_STATUS_INPUT_8_15 BIT(1)
5255
#define AIO_IIRO_16_STATUS_INPUT_0_7 BIT(0)
5356

57+
static unsigned int aio_iiro_16_read_inputs(struct comedi_device *dev)
58+
{
59+
unsigned int val;
60+
61+
val = inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
62+
val |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
63+
64+
return val;
65+
}
66+
5467
static irqreturn_t aio_iiro_16_cos(int irq, void *d)
5568
{
5669
struct comedi_device *dev = d;
5770
struct comedi_subdevice *s = dev->read_subdev;
5871
unsigned int status;
72+
unsigned int val;
5973

6074
status = inb(dev->iobase + AIO_IIRO_16_STATUS);
6175
if (!(status & AIO_IIRO_16_STATUS_IRQE))
6276
return IRQ_NONE;
6377

64-
comedi_buf_write_samples(s, &status, 1);
78+
val = aio_iiro_16_read_inputs(dev);
79+
val |= (status << 16);
80+
81+
comedi_buf_write_samples(s, &val, 1);
6582
comedi_handle_events(dev, s);
6683

6784
return IRQ_HANDLED;
@@ -150,9 +167,7 @@ static int aio_iiro_16_di_insn_bits(struct comedi_device *dev,
150167
struct comedi_insn *insn,
151168
unsigned int *data)
152169
{
153-
data[1] = 0;
154-
data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
155-
data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
170+
data[1] = aio_iiro_16_read_inputs(dev);
156171

157172
return insn->n;
158173
}
@@ -207,7 +222,7 @@ static int aio_iiro_16_attach(struct comedi_device *dev,
207222
s->insn_bits = aio_iiro_16_di_insn_bits;
208223
if (dev->irq) {
209224
dev->read_subdev = s;
210-
s->subdev_flags |= SDF_CMD_READ;
225+
s->subdev_flags |= SDF_CMD_READ | SDF_LSAMPL;
211226
s->len_chanlist = 1;
212227
s->do_cmdtest = aio_iiro_16_cos_cmdtest;
213228
s->do_cmd = aio_iiro_16_cos_cmd;

0 commit comments

Comments
 (0)