Commit acc5fe2c authored by H Hartley Sweeten's avatar H Hartley Sweeten Committed by Greg Kroah-Hartman

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: 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 3dd0b514
...@@ -240,7 +240,6 @@ struct dt9812_private { ...@@ -240,7 +240,6 @@ struct dt9812_private {
size_t size; size_t size;
} cmd_wr, cmd_rd; } cmd_wr, cmd_rd;
u16 device; u16 device;
u16 ao_shadow[2];
}; };
static int dt9812_read_info(struct comedi_device *dev, 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) ...@@ -546,7 +545,6 @@ static int dt9812_analog_out(struct comedi_device *dev, int channel, u16 value)
break; break;
} }
ret = dt9812_rmw_multiple_registers(dev, 3, rmw); ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
devpriv->ao_shadow[channel] = value;
up(&devpriv->sem); up(&devpriv->sem);
...@@ -609,15 +607,13 @@ static int dt9812_ao_insn_read(struct comedi_device *dev, ...@@ -609,15 +607,13 @@ static int dt9812_ao_insn_read(struct comedi_device *dev,
unsigned int *data) unsigned int *data)
{ {
struct dt9812_private *devpriv = dev->private; struct dt9812_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec); int ret;
int i;
down(&devpriv->sem); down(&devpriv->sem);
for (i = 0; i < insn->n; i++) ret = comedi_readback_insn_read(dev, s, insn, data);
data[i] = devpriv->ao_shadow[chan];
up(&devpriv->sem); up(&devpriv->sem);
return insn->n; return ret;
} }
static int dt9812_ao_insn_write(struct comedi_device *dev, static int dt9812_ao_insn_write(struct comedi_device *dev,
...@@ -626,13 +622,17 @@ 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 *data)
{ {
unsigned int chan = CR_CHAN(insn->chanspec); unsigned int chan = CR_CHAN(insn->chanspec);
int ret;
int i; int i;
for (i = 0; i < insn->n; 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) if (ret)
return ret; return ret;
s->readback[chan] = val;
} }
return insn->n; return insn->n;
...@@ -769,6 +769,7 @@ static int dt9812_auto_attach(struct comedi_device *dev, ...@@ -769,6 +769,7 @@ static int dt9812_auto_attach(struct comedi_device *dev,
struct comedi_subdevice *s; struct comedi_subdevice *s;
bool is_unipolar; bool is_unipolar;
int ret; int ret;
int i;
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv)); devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv) if (!devpriv)
...@@ -828,8 +829,12 @@ static int dt9812_auto_attach(struct comedi_device *dev, ...@@ -828,8 +829,12 @@ static int dt9812_auto_attach(struct comedi_device *dev,
s->insn_write = dt9812_ao_insn_write; s->insn_write = dt9812_ao_insn_write;
s->insn_read = dt9812_ao_insn_read; s->insn_read = dt9812_ao_insn_read;
devpriv->ao_shadow[0] = is_unipolar ? 0x0000 : 0x0800; ret = comedi_alloc_subdev_readback(s);
devpriv->ao_shadow[1] = is_unipolar ? 0x0000 : 0x0800; if (ret)
return ret;
for (i = 0; i < s->n_chan; i++)
s->readback[i] = is_unipolar ? 0x0000 : 0x0800;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment