From: H Hartley Sweeten Date: Mon, 25 Aug 2014 23:04:19 +0000 (-0700) Subject: staging: comedi: dt9812: use comedi_subdevice 'readback' X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=acc5fe2ce36f41f74603d57b635df28a61c94c34;p=linux-beck.git staging: comedi: dt9812: 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/dt9812.c b/drivers/staging/comedi/drivers/dt9812.c index bd2ca2b371e6..77bb89fee327 100644 --- a/drivers/staging/comedi/drivers/dt9812.c +++ b/drivers/staging/comedi/drivers/dt9812.c @@ -240,7 +240,6 @@ struct dt9812_private { size_t size; } cmd_wr, cmd_rd; u16 device; - u16 ao_shadow[2]; }; static int dt9812_read_info(struct comedi_device *dev, @@ -546,7 +545,6 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value) break; } ret = dt9812_rmw_multiple_registers(dev, 3, rmw); - devpriv->ao_shadow[channel] = value; up(&devpriv->sem); @@ -609,15 +607,13 @@ static int dt9812_ao_insn_read(struct comedi_device *dev, unsigned int *data) { struct dt9812_private *devpriv = dev->private; - unsigned int chan = CR_CHAN(insn->chanspec); - int i; + int ret; down(&devpriv->sem); - for (i = 0; i < insn->n; i++) - data[i] = devpriv->ao_shadow[chan]; + ret = comedi_readback_insn_read(dev, s, insn, data); up(&devpriv->sem); - return insn->n; + return ret; } static int dt9812_ao_insn_write(struct comedi_device *dev, @@ -626,13 +622,17 @@ static int dt9812_ao_insn_write(struct comedi_device *dev, unsigned int *data) { unsigned int chan = CR_CHAN(insn->chanspec); - int ret; int i; for (i = 0; i < insn->n; i++) { - ret = dt9812_analog_out(dev, chan, data[i]); + unsigned int val = data[i]; + int ret; + + ret = dt9812_analog_out(dev, chan, val); if (ret) return ret; + + s->readback[chan] = val; } return insn->n; @@ -769,6 +769,7 @@ static int dt9812_auto_attach(struct comedi_device *dev, struct comedi_subdevice *s; bool is_unipolar; int ret; + int i; devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); if (!devpriv) @@ -828,8 +829,12 @@ static int dt9812_auto_attach(struct comedi_device *dev, s->insn_write = dt9812_ao_insn_write; s->insn_read = dt9812_ao_insn_read; - devpriv->ao_shadow[0] = is_unipolar ? 0x0000 : 0x0800; - devpriv->ao_shadow[1] = is_unipolar ? 0x0000 : 0x0800; + ret = comedi_alloc_subdev_readback(s); + if (ret) + return ret; + + for (i = 0; i < s->n_chan; i++) + s->readback[i] = is_unipolar ? 0x0000 : 0x0800; return 0; }