Commit f8990d08 authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman
Browse files

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: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Reviewed-by: default avatarIan Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e42151f9
Loading
Loading
Loading
Loading
+21 −34
Original line number Diff line number Diff line
@@ -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;

	devpriv->caldac[chan] = data[insn->n - 1] & s->maxdata;
	if (insn->n) {
		unsigned int val = data[insn->n - 1];
		unsigned int bitstring = ((chan & 0x7) << 8) | val;
		unsigned int bits;
		int bit;

		/* write the channel and last data value to the caldac */
	bitstring = ((chan & 0x7) << 8) | devpriv->caldac[chan];

		/* clock the bitstring to the caldac; MSB -> LSB */
		for (bit = 1 << 10; bit; bit >>= 1) {
		val = (bit & bitstring) ? ATAO_CFG2_SDATA : 0;
			bits = (bit & bitstring) ? ATAO_CFG2_SDATA : 0;

		outw(val, dev->iobase + ATAO_CFG2_REG);
		outw(val | ATAO_CFG2_SCLK, dev->iobase + ATAO_CFG2_REG);
			outw(bits, dev->iobase + ATAO_CFG2_REG);
			outw(bits | ATAO_CFG2_SCLK,
			     dev->iobase + ATAO_CFG2_REG);
		}

		/* 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;
		s->readback[chan] = val;
	}

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;