Skip to content

Commit

Permalink
staging: comedi: aio_iiro_16: return input state in async command sample
Browse files Browse the repository at this point in the history
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 <hsweeten@visionengravers.com>
Reviewed-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
bigguiness authored and gregkh committed Jan 25, 2015
1 parent be8e890 commit 53c0bee
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions drivers/staging/comedi/drivers/aio_iiro_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
*
* The board supports interrupts on change of state of the digital inputs.
* The sample data returned by the async command indicates which inputs
* changed state:
* changed state and the current state of the inputs:
*
* Bit 7 - IRQ Enable (1) / Disable (0)
* Bit 1 - Input 8-15 Changed State (1 = Changed, 0 = No Change)
* Bit 0 - Input 0-7 Changed State (1 = Changed, 0 = No Change)
* Bit 23 - IRQ Enable (1) / Disable (0)
* Bit 17 - Input 8-15 Changed State (1 = Changed, 0 = No Change)
* Bit 16 - Input 0-7 Changed State (1 = Changed, 0 = No Change)
* Bit 15 - Digital input 15
* ...
* Bit 0 - Digital input 0
*/

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

static unsigned int aio_iiro_16_read_inputs(struct comedi_device *dev)
{
unsigned int val;

val = inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
val |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;

return val;
}

static irqreturn_t aio_iiro_16_cos(int irq, void *d)
{
struct comedi_device *dev = d;
struct comedi_subdevice *s = dev->read_subdev;
unsigned int status;
unsigned int val;

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

comedi_buf_write_samples(s, &status, 1);
val = aio_iiro_16_read_inputs(dev);
val |= (status << 16);

comedi_buf_write_samples(s, &val, 1);
comedi_handle_events(dev, s);

return IRQ_HANDLED;
Expand Down Expand Up @@ -150,9 +167,7 @@ static int aio_iiro_16_di_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
data[1] = 0;
data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_0_7);
data[1] |= inb(dev->iobase + AIO_IIRO_16_INPUT_8_15) << 8;
data[1] = aio_iiro_16_read_inputs(dev);

return insn->n;
}
Expand Down Expand Up @@ -207,7 +222,7 @@ static int aio_iiro_16_attach(struct comedi_device *dev,
s->insn_bits = aio_iiro_16_di_insn_bits;
if (dev->irq) {
dev->read_subdev = s;
s->subdev_flags |= SDF_CMD_READ;
s->subdev_flags |= SDF_CMD_READ | SDF_LSAMPL;
s->len_chanlist = 1;
s->do_cmdtest = aio_iiro_16_cos_cmdtest;
s->do_cmd = aio_iiro_16_cos_cmd;
Expand Down

0 comments on commit 53c0bee

Please sign in to comment.