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

staging: comedi: dmm32at: cleanup dmm32at_ao_winsn()

For aesthetics, rename the function and tidy it up a bit. Also rename the
registers used by this function and add a macro to set the 'chan' bits in
the MSB data register.
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 15aba0d2
...@@ -47,9 +47,10 @@ Configuration Options: ...@@ -47,9 +47,10 @@ Configuration Options:
#define DMM32AT_AILOW 0x02 #define DMM32AT_AILOW 0x02
#define DMM32AT_AIHIGH 0x03 #define DMM32AT_AIHIGH 0x03
#define DMM32AT_DACLSB 0x04
#define DMM32AT_DACSTAT 0x04 #define DMM32AT_DACSTAT 0x04
#define DMM32AT_DACMSB 0x05 #define DMM32AT_DACLSB_REG 0x04
#define DMM32AT_DACMSB_REG 0x05
#define DMM32AT_DACMSB_CHAN(x) ((x) << 6)
#define DMM32AT_FIFOCNTRL 0x07 #define DMM32AT_FIFOCNTRL 0x07
#define DMM32AT_FIFOSTAT 0x07 #define DMM32AT_FIFOSTAT 0x07
...@@ -540,42 +541,37 @@ static int dmm32at_ao_eoc(struct comedi_device *dev, ...@@ -540,42 +541,37 @@ static int dmm32at_ao_eoc(struct comedi_device *dev,
return -EBUSY; return -EBUSY;
} }
static int dmm32at_ao_winsn(struct comedi_device *dev, static int dmm32at_ao_insn_write(struct comedi_device *dev,
struct comedi_subdevice *s, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data) struct comedi_insn *insn,
unsigned int *data)
{ {
struct dmm32at_private *devpriv = dev->private; struct dmm32at_private *devpriv = dev->private;
int i; unsigned int chan = CR_CHAN(insn->chanspec);
int chan = CR_CHAN(insn->chanspec); unsigned int val;
unsigned char hi, lo, status;
int ret; int ret;
int i;
/* Writing a list of values to an AO channel is probably not
* very useful, but that's how the interface is defined. */
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
val = data[i];
devpriv->ao_readback[chan] = data[i]; /* write LSB then MSB + chan to load DAC */
outb(val & 0xff, dev->iobase + DMM32AT_DACLSB_REG);
/* get the low byte */ outb((val >> 8) | DMM32AT_DACMSB_CHAN(chan),
lo = data[i] & 0x00ff; dev->iobase + DMM32AT_DACMSB_REG);
/* high byte also contains channel number */
hi = (data[i] >> 8) + chan * (1 << 6);
/* write the low and high values to the board */
outb(lo, dev->iobase + DMM32AT_DACLSB);
outb(hi, dev->iobase + DMM32AT_DACMSB);
/* wait for circuit to settle */ /* wait for circuit to settle */
ret = comedi_timeout(dev, s, insn, dmm32at_ao_eoc, 0); ret = comedi_timeout(dev, s, insn, dmm32at_ao_eoc, 0);
if (ret) if (ret)
return ret; return ret;
/* dummy read to update trigger the output */ /* dummy read to update DAC */
status = inb(dev->iobase + DMM32AT_DACMSB); inb(dev->iobase + DMM32AT_DACMSB_REG);
devpriv->ao_readback[chan] = val;
} }
/* return the number of samples read/written */ return insn->n;
return i;
} }
static int dmm32at_ao_rinsn(struct comedi_device *dev, static int dmm32at_ao_rinsn(struct comedi_device *dev,
...@@ -764,7 +760,7 @@ static int dmm32at_attach(struct comedi_device *dev, ...@@ -764,7 +760,7 @@ static int dmm32at_attach(struct comedi_device *dev,
s->n_chan = 4; s->n_chan = 4;
s->maxdata = 0x0fff; s->maxdata = 0x0fff;
s->range_table = &dmm32at_aoranges; s->range_table = &dmm32at_aoranges;
s->insn_write = dmm32at_ao_winsn; s->insn_write = dmm32at_ao_insn_write;
s->insn_read = dmm32at_ao_rinsn; s->insn_read = dmm32at_ao_rinsn;
s = &dev->subdevices[2]; s = &dev->subdevices[2];
......
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