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

staging: comedi: adv_pci1724: use subdevice readback for 'offset_value'



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

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 388674e0
Loading
Loading
Loading
Loading
+6 −25
Original line number Diff line number Diff line
@@ -127,7 +127,6 @@ static const struct comedi_lrange ao_ranges_1724 = {

/* this structure is for data unique to this hardware driver. */
struct adv_pci1724_private {
	int offset_value[NUM_AO_CHANNELS];
	int gain_value[NUM_AO_CHANNELS];
};

@@ -189,7 +188,6 @@ static int offset_write_insn(struct comedi_device *dev,
			     struct comedi_subdevice *s,
			     struct comedi_insn *insn, unsigned int *data)
{
	struct adv_pci1724_private *devpriv = dev->private;
	int channel = CR_CHAN(insn->chanspec);
	int retval;
	int i;
@@ -201,27 +199,8 @@ static int offset_write_insn(struct comedi_device *dev,
		retval = set_dac(dev, DAC_OFFSET_MODE, channel, data[i]);
		if (retval < 0)
			return retval;
		devpriv->offset_value[channel] = data[i];
	}

	return insn->n;
}

static int offset_read_insn(struct comedi_device *dev,
			    struct comedi_subdevice *s,
			    struct comedi_insn *insn, unsigned int *data)
{
	struct adv_pci1724_private *devpriv = dev->private;
	unsigned int channel = CR_CHAN(insn->chanspec);
	int i;

	if (devpriv->offset_value[channel] < 0) {
		dev_err(dev->class_dev,
			"Cannot read back channels which have not yet been written to\n");
		return -EIO;
		s->readback[channel] = data[i];
	}
	for (i = 0; i < insn->n; i++)
		data[i] = devpriv->offset_value[channel];

	return insn->n;
}
@@ -296,9 +275,12 @@ static int setup_subdevices(struct comedi_device *dev)
	s->type = COMEDI_SUBD_CALIB;
	s->subdev_flags = SDF_READABLE | SDF_WRITABLE | SDF_INTERNAL;
	s->n_chan = NUM_AO_CHANNELS;
	s->insn_read = offset_read_insn;
	s->insn_write = offset_write_insn;
	s->maxdata = 0x3fff;
	s->insn_write = offset_write_insn;

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

	/* gain calibration */
	s = &dev->subdevices[2];
@@ -328,7 +310,6 @@ static int adv_pci1724_auto_attach(struct comedi_device *dev,
	/* init software copies of output values to indicate we don't know
	 * what the output value is since it has never been written. */
	for (i = 0; i < NUM_AO_CHANNELS; ++i) {
		devpriv->offset_value[i] = -1;
		devpriv->gain_value[i] = -1;
	}