size_t size;
} cmd_wr, cmd_rd;
u16 device;
- u16 ao_shadow[2];
};
static int dt9812_read_info(struct comedi_device *dev,
break;
}
ret = dt9812_rmw_multiple_registers(dev, 3, rmw);
- devpriv->ao_shadow[channel] = value;
up(&devpriv->sem);
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,
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;
struct comedi_subdevice *s;
bool is_unipolar;
int ret;
+ int i;
devpriv = comedi_alloc_devpriv(dev, sizeof(*devpriv));
if (!devpriv)
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;
}