staging: comedi: ni_at_ao: use subdevice readback for 'caldac'

Use the comedi_subdevice 'readback' member and the core provided (*insn_read)
to handle the readback of the write-only caldac subdevice. Remove the then unused
'caldac' member from the private data.

Tidy up atao_calib_insn_write().

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>
This commit is contained in:
H Hartley Sweeten 2014-11-20 15:07:30 -07:00 committed by Greg Kroah-Hartman
parent e42151f945
commit f8990d088c

View file

@ -244,47 +244,31 @@ static int atao_calib_insn_write(struct comedi_device *dev,
struct comedi_insn *insn,
unsigned int *data)
{
struct atao_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int bitstring;
unsigned int val;
int bit;
if (insn->n == 0)
return 0;
if (insn->n) {
unsigned int val = data[insn->n - 1];
unsigned int bitstring = ((chan & 0x7) << 8) | val;
unsigned int bits;
int bit;
devpriv->caldac[chan] = data[insn->n - 1] & s->maxdata;
/* write the channel and last data value to the caldac */
/* clock the bitstring to the caldac; MSB -> LSB */
for (bit = 1 << 10; bit; bit >>= 1) {
bits = (bit & bitstring) ? ATAO_CFG2_SDATA : 0;
/* write the channel and last data value to the caldac */
bitstring = ((chan & 0x7) << 8) | devpriv->caldac[chan];
outw(bits, dev->iobase + ATAO_CFG2_REG);
outw(bits | ATAO_CFG2_SCLK,
dev->iobase + ATAO_CFG2_REG);
}
/* clock the bitstring to the caldac; MSB -> LSB */
for (bit = 1 << 10; bit; bit >>= 1) {
val = (bit & bitstring) ? ATAO_CFG2_SDATA : 0;
/* strobe the caldac to load the value */
outw(ATAO_CFG2_CALLD(chan), dev->iobase + ATAO_CFG2_REG);
outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);
outw(val, dev->iobase + ATAO_CFG2_REG);
outw(val | ATAO_CFG2_SCLK, dev->iobase + ATAO_CFG2_REG);
s->readback[chan] = val;
}
/* strobe the caldac to load the value */
outw(ATAO_CFG2_CALLD(chan), dev->iobase + ATAO_CFG2_REG);
outw(ATAO_CFG2_CALLD_NOP, dev->iobase + ATAO_CFG2_REG);
return insn->n;
}
static int atao_calib_insn_read(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{
struct atao_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
int i;
for (i = 0; i < insn->n; i++)
data[i] = devpriv->caldac[chan];
return insn->n;
}
@ -365,9 +349,12 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it)
s->subdev_flags = SDF_WRITABLE | SDF_INTERNAL;
s->n_chan = (board->n_ao_chans * 2) + 1;
s->maxdata = 0xff;
s->insn_read = atao_calib_insn_read;
s->insn_write = atao_calib_insn_write;
ret = comedi_alloc_subdev_readback(s);
if (ret)
return ret;
/* EEPROM subdevice */
s = &dev->subdevices[3];
s->type = COMEDI_SUBD_UNUSED;