Skip to content

Commit

Permalink
staging: comedi: drivers: use comedi_dio_update_state() for simple cases
Browse files Browse the repository at this point in the history
Use comedi_dio_update_state() to handle the boilerplate code to update
the subdevice s->state for simple cases where the hardware is updated
when any channel is modified.

Also, fix a bug in the amplc_pc263 and amplc_pci263 drivers where the
current state is not returned in data[1].

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
H Hartley Sweeten authored and Greg Kroah-Hartman committed Sep 17, 2013
1 parent 77e9487 commit 97f4289
Show file tree
Hide file tree
Showing 40 changed files with 135 additions and 308 deletions.
7 changes: 1 addition & 6 deletions drivers/staging/comedi/drivers/addi-data/hwdrv_apci1564.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,13 @@ static int apci1564_do_insn_bits(struct comedi_device *dev,
unsigned int *data)
{
struct addi_private *devpriv = dev->private;
unsigned int mask = data[0];
unsigned int bits = data[1];

s->state = inl(devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
APCI1564_DIGITAL_OP_RW);
if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outl(s->state, devpriv->i_IobaseAmcc + APCI1564_DIGITAL_OP +
APCI1564_DIGITAL_OP_RW);
}

data[1] = s->state;

Expand Down
7 changes: 1 addition & 6 deletions drivers/staging/comedi/drivers/addi-data/hwdrv_apci3200.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,16 +623,11 @@ static int apci3200_do_insn_bits(struct comedi_device *dev,
unsigned int *data)
{
struct addi_private *devpriv = dev->private;
unsigned int mask = data[0];
unsigned int bits = data[1];

s->state = inl(devpriv->i_IobaseAddon) & 0xf;
if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outl(s->state, devpriv->i_IobaseAddon);
}

data[1] = s->state;

Expand Down
8 changes: 1 addition & 7 deletions drivers/staging/comedi/drivers/addi_apci_1516.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,10 @@ static int apci1516_do_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask = data[0];
unsigned int bits = data[1];

s->state = inw(dev->iobase + APCI1516_DO_REG);
if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outw(s->state, dev->iobase + APCI1516_DO_REG);
}

data[1] = s->state;

Expand Down
8 changes: 1 addition & 7 deletions drivers/staging/comedi/drivers/addi_apci_2032.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,10 @@ static int apci2032_do_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask = data[0];
unsigned int bits = data[1];

s->state = inl(dev->iobase + APCI2032_DO_REG);
if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outl(s->state, dev->iobase + APCI2032_DO_REG);
}

data[1] = s->state;

Expand Down
8 changes: 1 addition & 7 deletions drivers/staging/comedi/drivers/addi_apci_2200.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,10 @@ static int apci2200_do_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask = data[0];
unsigned int bits = data[1];

s->state = inw(dev->iobase + APCI2200_DO_REG);
if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outw(s->state, dev->iobase + APCI2200_DO_REG);
}

data[1] = s->state;

Expand Down
8 changes: 1 addition & 7 deletions drivers/staging/comedi/drivers/addi_apci_3501.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,10 @@ static int apci3501_do_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask = data[0];
unsigned int bits = data[1];

s->state = inl(dev->iobase + APCI3501_DO_REG);
if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outl(s->state, dev->iobase + APCI3501_DO_REG);
}

data[1] = s->state;

Expand Down
8 changes: 1 addition & 7 deletions drivers/staging/comedi/drivers/addi_apci_3xxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,16 +664,10 @@ static int apci3xxx_do_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask = data[0];
unsigned int bits = data[1];

s->state = inl(dev->iobase + 48) & 0xf;
if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outl(s->state, dev->iobase + 48);
}

data[1] = s->state;

Expand Down
9 changes: 1 addition & 8 deletions drivers/staging/comedi/drivers/adl_pci6208.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,8 @@ static int pci6208_do_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask = data[0];
unsigned int bits = data[1];

if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outw(s->state, dev->iobase + PCI6208_DIO);
}

data[1] = s->state;

Expand Down
13 changes: 1 addition & 12 deletions drivers/staging/comedi/drivers/adl_pci7x3x.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,10 @@ static int adl_pci7x3x_do_insn_bits(struct comedi_device *dev,
unsigned int *data)
{
unsigned long reg = (unsigned long)s->private;
unsigned int mask = data[0];
unsigned int bits = data[1];

if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outl(s->state, dev->iobase + reg);
}

/*
* NOTE: The output register is not readable.
* This returned state will not be correct until all the
* outputs have been updated.
*/
data[1] = s->state;

return insn->n;
Expand Down
9 changes: 1 addition & 8 deletions drivers/staging/comedi/drivers/adl_pci9111.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,15 +813,8 @@ static int pci9111_do_insn_bits(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
unsigned int mask = data[0];
unsigned int bits = data[1];

if (mask) {
s->state &= ~mask;
s->state |= (bits & mask);

if (comedi_dio_update_state(s, data))
outw(s->state, dev->iobase + PCI9111_DIO_REG);
}

data[1] = s->state;

Expand Down
9 changes: 4 additions & 5 deletions drivers/staging/comedi/drivers/adl_pci9118.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,12 @@ static int pci9118_insn_bits_di(struct comedi_device *dev,

static int pci9118_insn_bits_do(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
if (comedi_dio_update_state(s, data))
outl(s->state & 0x0f, dev->iobase + PCI9118_DO);
}

data[1] = s->state;

return insn->n;
Expand Down
12 changes: 4 additions & 8 deletions drivers/staging/comedi/drivers/adv_pci1710.c
Original file line number Diff line number Diff line change
Expand Up @@ -544,18 +544,14 @@ static int pci171x_insn_bits_di(struct comedi_device *dev,
return insn->n;
}

/*
==============================================================================
*/
static int pci171x_insn_bits_do(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
if (comedi_dio_update_state(s, data))
outw(s->state, dev->iobase + PCI171x_DO);
}

data[1] = s->state;

return insn->n;
Expand Down
13 changes: 5 additions & 8 deletions drivers/staging/comedi/drivers/adv_pci1723.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,16 @@ static int pci1723_dio_insn_config(struct comedi_device *dev,
return insn->n;
}

/*
digital i/o bits read/write
*/
static int pci1723_dio_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
if (comedi_dio_update_state(s, data))
outw(s->state, dev->iobase + PCI1723_WRITE_DIGITAL_OUTPUT_CMD);
}

data[1] = inw(dev->iobase + PCI1723_READ_DIGITAL_INPUT_DATA);

return insn->n;
}

Expand Down
33 changes: 12 additions & 21 deletions drivers/staging/comedi/drivers/adv_pci_dio.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,45 +448,39 @@ static int pci_dio_insn_bits_di_w(struct comedi_device *dev,
return insn->n;
}

/*
==============================================================================
*/
static int pci_dio_insn_bits_do_b(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
const struct diosubd_data *d = (const struct diosubd_data *)s->private;
int i;

if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
if (comedi_dio_update_state(s, data)) {
for (i = 0; i < d->regs; i++)
outb((s->state >> (8 * i)) & 0xff,
dev->iobase + d->addr + i);
}

data[1] = s->state;

return insn->n;
}

/*
==============================================================================
*/
static int pci_dio_insn_bits_do_w(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
const struct diosubd_data *d = (const struct diosubd_data *)s->private;
int i;

if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
if (comedi_dio_update_state(s, data)) {
for (i = 0; i < d->regs; i++)
outw((s->state >> (16 * i)) & 0xffff,
dev->iobase + d->addr + 2 * i);
}

data[1] = s->state;

return insn->n;
Expand Down Expand Up @@ -641,12 +635,10 @@ static int pci1760_insn_bits_di(struct comedi_device *dev,
return insn->n;
}

/*
==============================================================================
*/
static int pci1760_insn_bits_do(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
int ret;
unsigned char omb[4] = {
Expand All @@ -657,14 +649,13 @@ static int pci1760_insn_bits_do(struct comedi_device *dev,
};
unsigned char imb[4];

if (data[0]) {
s->state &= ~data[0];
s->state |= (data[0] & data[1]);
if (comedi_dio_update_state(s, data)) {
omb[0] = s->state;
ret = pci1760_mbxrequest(dev, omb, imb);
if (!ret)
return ret;
}

data[1] = s->state;

return insn->n;
Expand Down
4 changes: 1 addition & 3 deletions drivers/staging/comedi/drivers/aio_iiro_16.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ static int aio_iiro_16_dio_insn_bits_write(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
if (data[0]) {
s->state &= ~data[0];
s->state |= data[0] & data[1];
if (comedi_dio_update_state(s, data)) {
outb(s->state & 0xff, dev->iobase + AIO_IIRO_16_RELAY_0_7);
outb((s->state >> 8) & 0xff,
dev->iobase + AIO_IIRO_16_RELAY_8_15);
Expand Down
17 changes: 8 additions & 9 deletions drivers/staging/comedi/drivers/amplc_pc263.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,16 @@ static const struct pc263_board pc263_boards[] = {

static int pc263_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
/* The insn data is a mask in data[0] and the new data
* in data[1], each channel cooresponding to a bit. */
if (data[0]) {
s->state &= ~data[0];
s->state |= data[0] & data[1];
/* Write out the new digital output lines */
outb(s->state & 0xFF, dev->iobase);
outb(s->state >> 8, dev->iobase + 1);
if (comedi_dio_update_state(s, data)) {
outb(s->state & 0xff, dev->iobase);
outb((s->state >> 8) & 0xff, dev->iobase + 1);
}

data[1] = s->state;

return insn->n;
}

Expand Down
17 changes: 8 additions & 9 deletions drivers/staging/comedi/drivers/amplc_pci263.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ The state of the outputs can be read.

static int pci263_do_insn_bits(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
struct comedi_insn *insn,
unsigned int *data)
{
/* The insn data is a mask in data[0] and the new data
* in data[1], each channel cooresponding to a bit. */
if (data[0]) {
s->state &= ~data[0];
s->state |= data[0] & data[1];
/* Write out the new digital output lines */
outb(s->state & 0xFF, dev->iobase);
outb(s->state >> 8, dev->iobase + 1);
if (comedi_dio_update_state(s, data)) {
outb(s->state & 0xff, dev->iobase);
outb((s->state >> 8) & 0xff, dev->iobase + 1);
}

data[1] = s->state;

return insn->n;
}

Expand Down
Loading

0 comments on commit 97f4289

Please sign in to comment.