From a416133abb117fc9cc50ff53762d72296140be39 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 25 Aug 2014 16:04:00 -0700 Subject: [PATCH] staging: comedi: multiq3: use comedi_subdevice 'readback' Use the new comedi_subdevice 'readback' member and the core provided (*insn_read) for the readback of the analog output subdevice channels. Remove the unused private data and its allocation. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/multiq3.c | 46 ++++++++---------------- 1 file changed, 14 insertions(+), 32 deletions(-) diff --git a/drivers/staging/comedi/drivers/multiq3.c b/drivers/staging/comedi/drivers/multiq3.c index e841a5a3ec4f..f710c8e81320 100644 --- a/drivers/staging/comedi/drivers/multiq3.c +++ b/drivers/staging/comedi/drivers/multiq3.c @@ -75,10 +75,6 @@ Devices: [Quanser Consulting] MultiQ-3 (multiq3) #define MULTIQ3_TIMEOUT 30 -struct multiq3_private { - unsigned int ao_readback[2]; -}; - static int multiq3_ai_status(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -126,38 +122,25 @@ static int multiq3_ai_insn_read(struct comedi_device *dev, return n; } -static int multiq3_ao_insn_read(struct comedi_device *dev, - struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) -{ - struct multiq3_private *devpriv = dev->private; - int i; - int chan = CR_CHAN(insn->chanspec); - - for (i = 0; i < insn->n; i++) - data[i] = devpriv->ao_readback[chan]; - - return i; -} - static int multiq3_ao_insn_write(struct comedi_device *dev, struct comedi_subdevice *s, - struct comedi_insn *insn, unsigned int *data) + struct comedi_insn *insn, + unsigned int *data) { - struct multiq3_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); + unsigned int val = s->readback[chan]; int i; - int chan = CR_CHAN(insn->chanspec); for (i = 0; i < insn->n; i++) { + val = data[i]; outw(MULTIQ3_CONTROL_MUST | MULTIQ3_DA_LOAD | chan, dev->iobase + MULTIQ3_CONTROL); - outw(data[i], dev->iobase + MULTIQ3_DAC_DATA); + outw(val, dev->iobase + MULTIQ3_DAC_DATA); outw(MULTIQ3_CONTROL_MUST, dev->iobase + MULTIQ3_CONTROL); - - devpriv->ao_readback[chan] = data[i]; } + s->readback[chan] = val; - return i; + return insn->n; } static int multiq3_di_insn_bits(struct comedi_device *dev, @@ -227,7 +210,6 @@ static void encoder_reset(struct comedi_device *dev) static int multiq3_attach(struct comedi_device *dev, struct comedi_devconfig *it) { - struct multiq3_private *devpriv; struct comedi_subdevice *s; int ret; @@ -239,10 +221,6 @@ static int multiq3_attach(struct comedi_device *dev, if (ret) return ret; - devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); - if (!devpriv) - return -ENOMEM; - s = &dev->subdevices[0]; /* ai subdevice */ s->type = COMEDI_SUBD_AI; @@ -257,10 +235,14 @@ static int multiq3_attach(struct comedi_device *dev, s->type = COMEDI_SUBD_AO; s->subdev_flags = SDF_WRITABLE; s->n_chan = 8; - s->insn_read = multiq3_ao_insn_read; - s->insn_write = multiq3_ao_insn_write; s->maxdata = 0xfff; s->range_table = &range_bipolar5; + s->insn_write = multiq3_ao_insn_write; + s->insn_read = comedi_readback_insn_read; + + ret = comedi_alloc_subdev_readback(s); + if (ret) + return ret; s = &dev->subdevices[2]; /* di subdevice */ -- 2.34.1