Skip to content

Commit

Permalink
staging: comedi: adv_pci1710: use comedi_subdevice 'readback'
Browse files Browse the repository at this point in the history
Use the new comedi_subdevice 'readback' member and the core provided
(*insn_read) for the readback of the analog output subdevice channels.

The board is "reset" prior to the subdevice init. Part of this reset
sets all the analog output channels to 0V. Move the initialization of
the 'readback' values after the 'readback' member has been allocated.

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 Jan 25, 2015
1 parent 87abf66 commit e4623ce
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions drivers/staging/comedi/drivers/adv_pci1710.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ struct pci1710_private {
unsigned int act_chanlist[32]; /* list of scanned channel */
unsigned char saved_seglen; /* len of the non-repeating chanlist */
unsigned char da_ranges; /* copy of D/A outpit range register */
unsigned short ao_data[4]; /* data output buffer */
unsigned int cnt0_write_wait; /* after a write, wait for update of the
* internal state */
};
Expand Down Expand Up @@ -491,36 +490,19 @@ static int pci171x_insn_write_ao(struct comedi_device *dev,
outw(devpriv->da_ranges, dev->iobase + PCI171x_DAREF);
ofs = PCI171x_DA1;
}
val = devpriv->ao_data[chan];
val = s->readback[chan];

for (n = 0; n < insn->n; n++) {
val = data[n];
outw(val, dev->iobase + ofs);
}

devpriv->ao_data[chan] = val;
s->readback[chan] = val;

return n;

}

/*
==============================================================================
*/
static int pci171x_insn_read_ao(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct pci1710_private *devpriv = dev->private;
int n, chan;

chan = CR_CHAN(insn->chanspec);
for (n = 0; n < insn->n; n++)
data[n] = devpriv->ao_data[chan];

return n;
}

/*
==============================================================================
*/
Expand Down Expand Up @@ -672,15 +654,15 @@ static int pci1720_insn_write_ao(struct comedi_device *dev,
outb(rangereg, dev->iobase + PCI1720_RANGE);
devpriv->da_ranges = rangereg;
}
val = devpriv->ao_data[chan];
val = s->readback[chan];

for (n = 0; n < insn->n; n++) {
val = data[n];
outw(val, dev->iobase + PCI1720_DA0 + (chan << 1));
outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */
}

devpriv->ao_data[chan] = val;
s->readback[chan] = val;

return n;
}
Expand Down Expand Up @@ -1012,9 +994,7 @@ static int pci171x_reset(struct comedi_device *dev)
/* set DACs to 0..5V */
outb(devpriv->da_ranges, dev->iobase + PCI171x_DAREF);
outw(0, dev->iobase + PCI171x_DA1); /* set DA outputs to 0V */
devpriv->ao_data[0] = 0x0000;
outw(0, dev->iobase + PCI171x_DA2);
devpriv->ao_data[1] = 0x0000;
}
outw(0, dev->iobase + PCI171x_DO); /* digital outputs to 0 */
outb(0, dev->iobase + PCI171x_CLRFIFO); /* clear FIFO */
Expand All @@ -1039,10 +1019,7 @@ static int pci1720_reset(struct comedi_device *dev)
outw(0x0800, dev->iobase + PCI1720_DA2);
outw(0x0800, dev->iobase + PCI1720_DA3);
outb(0, dev->iobase + PCI1720_SYNCOUT); /* update outputs */
devpriv->ao_data[0] = 0x0800;
devpriv->ao_data[1] = 0x0800;
devpriv->ao_data[2] = 0x0800;
devpriv->ao_data[3] = 0x0800;

return 0;
}

Expand Down Expand Up @@ -1148,7 +1125,19 @@ static int pci1710_auto_attach(struct comedi_device *dev,
s->insn_write = pci171x_insn_write_ao;
break;
}
s->insn_read = pci171x_insn_read_ao;

ret = comedi_alloc_subdev_readback(s);
if (ret)
return ret;

/* initialize the readback values to match the board reset */
if (this_board->cardtype == TYPE_PCI1720) {
int i;

for (i = 0; i < s->n_chan; i++)
s->readback[i] = 0x0800;
}

subdev++;
}

Expand Down

0 comments on commit e4623ce

Please sign in to comment.