From: H Hartley Sweeten Date: Mon, 25 Aug 2014 23:04:12 +0000 (-0700) Subject: staging: comedi: ni_at_ao: use comedi_subdevice 'readback' X-Git-Tag: v3.18-rc1~130^2~1040 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=72e35fd3c5b7fa08b1e39838889718df5fc04f84;p=karo-tx-linux.git staging: comedi: ni_at_ao: 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 --- diff --git a/drivers/staging/comedi/drivers/ni_at_ao.c b/drivers/staging/comedi/drivers/ni_at_ao.c index c93b47bcca51..7a60713226ae 100644 --- a/drivers/staging/comedi/drivers/ni_at_ao.c +++ b/drivers/staging/comedi/drivers/ni_at_ao.c @@ -118,9 +118,6 @@ struct atao_private { unsigned short cfg1; unsigned short cfg3; - /* Used for AO readback */ - unsigned int ao_readback[10]; - /* Used for caldac readback */ unsigned char caldac[21]; }; @@ -141,9 +138,8 @@ static int atao_ao_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 val; + unsigned int val = s->readback[chan]; int i; if (chan == 0) @@ -151,12 +147,12 @@ static int atao_ao_insn_write(struct comedi_device *dev, for (i = 0; i < insn->n; i++) { val = data[i]; - devpriv->ao_readback[chan] = val; - /* munge offset binary (unsigned) to two's complement */ - val = comedi_offset_munge(s, val); - outw(val, dev->iobase + ATAO_AO_REG(chan)); + /* the hardware expects two's complement values */ + outw(comedi_offset_munge(s, val), + dev->iobase + ATAO_AO_REG(chan)); } + s->readback[chan] = val; if (chan == 0) atao_select_reg_group(dev, 0); @@ -164,21 +160,6 @@ static int atao_ao_insn_write(struct comedi_device *dev, return insn->n; } -static int atao_ao_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->ao_readback[chan]; - - return insn->n; -} - static int atao_dio_insn_bits(struct comedi_device *dev, struct comedi_subdevice *s, struct comedi_insn *insn, @@ -363,7 +344,11 @@ static int atao_attach(struct comedi_device *dev, struct comedi_devconfig *it) s->maxdata = 0x0fff; s->range_table = it->options[3] ? &range_unipolar10 : &range_bipolar10; s->insn_write = atao_ao_insn_write; - s->insn_read = atao_ao_insn_read; + s->insn_read = comedi_readback_insn_read; + + ret = comedi_alloc_subdev_readback(s); + if (ret) + return ret; /* Digital I/O subdevice */ s = &dev->subdevices[1];