From b1d6bffb92fe78d11e18f8853a80d4cc372afc2d Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Mon, 25 Aug 2014 16:04:21 -0700 Subject: [PATCH] staging: comedi: addi_apci_3501: 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. Signed-off-by: H Hartley Sweeten Reviewed-by: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- .../staging/comedi/drivers/addi_apci_3501.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/staging/comedi/drivers/addi_apci_3501.c b/drivers/staging/comedi/drivers/addi_apci_3501.c index d9594f48d00f..56781c155343 100644 --- a/drivers/staging/comedi/drivers/addi_apci_3501.c +++ b/drivers/staging/comedi/drivers/addi_apci_3501.c @@ -104,9 +104,9 @@ static int apci3501_ao_insn_write(struct comedi_device *dev, { unsigned int chan = CR_CHAN(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec); - unsigned int val = 0; - int i; + unsigned int cfg = APCI3501_AO_DATA_CHAN(chan); int ret; + int i; /* * All analog output channels have the same output range. @@ -117,14 +117,14 @@ static int apci3501_ao_insn_write(struct comedi_device *dev, if (range) { outl(0, dev->iobase + APCI3501_AO_CTRL_STATUS_REG); } else { - val |= APCI3501_AO_DATA_BIPOLAR; + cfg |= APCI3501_AO_DATA_BIPOLAR; outl(APCI3501_AO_CTRL_BIPOLAR, dev->iobase + APCI3501_AO_CTRL_STATUS_REG); } - val |= APCI3501_AO_DATA_CHAN(chan); - for (i = 0; i < insn->n; i++) { + unsigned int val = data[i]; + if (range == 1) { if (data[i] > 0x1fff) { dev_err(dev->class_dev, @@ -137,8 +137,10 @@ static int apci3501_ao_insn_write(struct comedi_device *dev, if (ret) return ret; - outl(val | APCI3501_AO_DATA_VAL(data[i]), + outl(cfg | APCI3501_AO_DATA_VAL(val), dev->iobase + APCI3501_AO_DATA_REG); + + s->readback[chan] = val; } return insn->n; @@ -360,6 +362,11 @@ static int apci3501_auto_attach(struct comedi_device *dev, s->maxdata = 0x3fff; s->range_table = &apci3501_ao_range; s->insn_write = apci3501_ao_insn_write; + s->insn_read = comedi_readback_insn_read; + + ret = comedi_alloc_subdev_readback(s); + if (ret) + return ret; } else { s->type = COMEDI_SUBD_UNUSED; } -- 2.39.5