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

staging: comedi: icp_multi: 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.

For aesthetics, rename the (*insn_write) function and tidy it up a bit.
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 559975c1
...@@ -116,7 +116,6 @@ struct icp_multi_private { ...@@ -116,7 +116,6 @@ struct icp_multi_private {
unsigned char act_chanlist_len; /* len of scanlist */ unsigned char act_chanlist_len; /* len of scanlist */
unsigned char act_chanlist_pos; /* actual position in MUX list */ unsigned char act_chanlist_pos; /* actual position in MUX list */
unsigned int *ai_chanlist; /* actaul chanlist */ unsigned int *ai_chanlist; /* actaul chanlist */
unsigned short ao_data[4]; /* data output buffer */
unsigned int do_data; /* Remember digital output data */ unsigned int do_data; /* Remember digital output data */
}; };
...@@ -240,14 +239,15 @@ static int icp_multi_ao_eoc(struct comedi_device *dev, ...@@ -240,14 +239,15 @@ static int icp_multi_ao_eoc(struct comedi_device *dev,
return -EBUSY; return -EBUSY;
} }
static int icp_multi_insn_write_ao(struct comedi_device *dev, static int icp_multi_ao_insn_write(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, struct comedi_insn *insn,
unsigned int *data) unsigned int *data)
{ {
struct icp_multi_private *devpriv = dev->private; struct icp_multi_private *devpriv = dev->private;
int n, chan, range; unsigned int chan = CR_CHAN(insn->chanspec);
int ret; unsigned int range = CR_RANGE(insn->chanspec);
int i;
/* Disable D/A conversion ready interrupt */ /* Disable D/A conversion ready interrupt */
devpriv->IntEnable &= ~DAC_READY; devpriv->IntEnable &= ~DAC_READY;
...@@ -257,10 +257,6 @@ static int icp_multi_insn_write_ao(struct comedi_device *dev, ...@@ -257,10 +257,6 @@ static int icp_multi_insn_write_ao(struct comedi_device *dev,
devpriv->IntStatus |= DAC_READY; devpriv->IntStatus |= DAC_READY;
writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT); writew(devpriv->IntStatus, dev->mmio + ICP_MULTI_INT_STAT);
/* Get channel number and range */
chan = CR_CHAN(insn->chanspec);
range = CR_RANGE(insn->chanspec);
/* Set up range and channel data */ /* Set up range and channel data */
/* Bit 4 = 1 : Bipolar */ /* Bit 4 = 1 : Bipolar */
/* Bit 5 = 0 : 5V */ /* Bit 5 = 0 : 5V */
...@@ -272,7 +268,10 @@ static int icp_multi_insn_write_ao(struct comedi_device *dev, ...@@ -272,7 +268,10 @@ static int icp_multi_insn_write_ao(struct comedi_device *dev,
writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR); writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR);
for (n = 0; n < insn->n; n++) { for (i = 0; i < insn->n; i++) {
unsigned int val = data[i];
int ret;
/* Wait for analogue output data register to be /* Wait for analogue output data register to be
* ready for new data, or get fed up waiting */ * ready for new data, or get fed up waiting */
ret = comedi_timeout(dev, s, insn, icp_multi_ao_eoc, 0); ret = comedi_timeout(dev, s, insn, icp_multi_ao_eoc, 0);
...@@ -287,42 +286,20 @@ static int icp_multi_insn_write_ao(struct comedi_device *dev, ...@@ -287,42 +286,20 @@ static int icp_multi_insn_write_ao(struct comedi_device *dev,
writew(devpriv->IntStatus, writew(devpriv->IntStatus,
dev->mmio + ICP_MULTI_INT_STAT); dev->mmio + ICP_MULTI_INT_STAT);
/* Clear data received */
devpriv->ao_data[chan] = 0;
return ret; return ret;
} }
/* Write data to analogue output data register */ writew(val, dev->mmio + ICP_MULTI_AO);
writew(data[n], dev->mmio + ICP_MULTI_AO);
/* Set DAC_ST bit to write the data to selected channel */ /* Set DAC_ST bit to write the data to selected channel */
devpriv->DacCmdStatus |= DAC_ST; devpriv->DacCmdStatus |= DAC_ST;
writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR); writew(devpriv->DacCmdStatus, dev->mmio + ICP_MULTI_DAC_CSR);
devpriv->DacCmdStatus &= ~DAC_ST; devpriv->DacCmdStatus &= ~DAC_ST;
/* Save analogue output data */ s->readback[chan] = val;
devpriv->ao_data[chan] = data[n];
} }
return n; return insn->n;
}
static int icp_multi_insn_read_ao(struct comedi_device *dev,
struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{
struct icp_multi_private *devpriv = dev->private;
int n, chan;
/* Get channel number */
chan = CR_CHAN(insn->chanspec);
/* Read analogue outputs */
for (n = 0; n < insn->n; n++)
data[n] = devpriv->ao_data[chan];
return n;
} }
static int icp_multi_insn_bits_di(struct comedi_device *dev, static int icp_multi_insn_bits_di(struct comedi_device *dev,
...@@ -518,8 +495,12 @@ static int icp_multi_auto_attach(struct comedi_device *dev, ...@@ -518,8 +495,12 @@ static int icp_multi_auto_attach(struct comedi_device *dev,
s->maxdata = 0x0fff; s->maxdata = 0x0fff;
s->len_chanlist = 4; s->len_chanlist = 4;
s->range_table = &range_analog; s->range_table = &range_analog;
s->insn_write = icp_multi_insn_write_ao; s->insn_write = icp_multi_ao_insn_write;
s->insn_read = icp_multi_insn_read_ao; s->insn_read = comedi_readback_insn_read;
ret = comedi_alloc_subdev_readback(s);
if (ret)
return ret;
s = &dev->subdevices[2]; s = &dev->subdevices[2];
s->type = COMEDI_SUBD_DI; s->type = COMEDI_SUBD_DI;
......
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