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

staging: comedi: pcl726: tidy up pcl726_ao_insn()

For aesthetics, rename the function to help with greps.

The offset binary value from the core should be saved for read back.
Move the saving of the value in the private data so it occurs before
the value is possibly munged for bipolar outputs.

Use the comedi_offset_munge() helper to munge the offset binary value
to two's complement for bipolar outputs.

According to the November 2011 users manual, the write order must be
MSB them LSB. Update the comment.

Modify the register map defines to handle the channel offset calculation.
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 b4f58e1f
...@@ -71,8 +71,8 @@ Interrupts are not supported. ...@@ -71,8 +71,8 @@ Interrupts are not supported.
#define PCL727_SIZE 32 #define PCL727_SIZE 32
#define PCL728_SIZE 8 #define PCL728_SIZE 8
#define PCL726_DAC0_HI 0 #define PCL726_AO_MSB_REG(x) (0x00 + ((x) * 2))
#define PCL726_DAC0_LO 1 #define PCL726_AO_LSB_REG(x) (0x01 + ((x) * 2))
#define PCL726_DO_HI 12 #define PCL726_DO_HI 12
#define PCL726_DO_LO 13 #define PCL726_DO_LO 13
...@@ -187,31 +187,31 @@ struct pcl726_private { ...@@ -187,31 +187,31 @@ struct pcl726_private {
unsigned int ao_readback[12]; unsigned int ao_readback[12];
}; };
static int pcl726_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s, static int pcl726_ao_insn_write(struct comedi_device *dev,
struct comedi_insn *insn, unsigned int *data) struct comedi_subdevice *s,
struct comedi_insn *insn,
unsigned int *data)
{ {
struct pcl726_private *devpriv = dev->private; struct pcl726_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec); unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int range = CR_RANGE(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec);
int hi, lo; unsigned int val;
int n; int i;
for (n = 0; n < insn->n; n++) { for (i = 0; i < insn->n; i++) {
lo = data[n] & 0xff; val = data[i];
hi = (data[n] >> 8) & 0xf; devpriv->ao_readback[chan] = val;
/* bipolar data to the DAC is two's complement */
if (comedi_chan_range_is_bipolar(s, chan, range)) if (comedi_chan_range_is_bipolar(s, chan, range))
hi ^= 0x8; val = comedi_offset_munge(s, val);
/*
* the programming info did not say which order /* order is important, MSB then LSB */
* to write bytes. switch the order of the next outb((val >> 8) & 0xff, dev->iobase + PCL726_AO_MSB_REG(chan));
* two lines if you get glitches. outb(val & 0xff, dev->iobase + PCL726_AO_LSB_REG(chan));
*/
outb(hi, dev->iobase + PCL726_DAC0_HI + 2 * chan);
outb(lo, dev->iobase + PCL726_DAC0_LO + 2 * chan);
devpriv->ao_readback[chan] = data[n];
} }
return n; return insn->n;
} }
static int pcl726_ao_insn_read(struct comedi_device *dev, static int pcl726_ao_insn_read(struct comedi_device *dev,
...@@ -322,7 +322,7 @@ static int pcl726_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -322,7 +322,7 @@ static int pcl726_attach(struct comedi_device *dev, struct comedi_devconfig *it)
s->n_chan = board->n_aochan; s->n_chan = board->n_aochan;
s->maxdata = 0xfff; s->maxdata = 0xfff;
s->len_chanlist = 1; s->len_chanlist = 1;
s->insn_write = pcl726_ao_insn; s->insn_write = pcl726_ao_insn_write;
s->insn_read = pcl726_ao_insn_read; s->insn_read = pcl726_ao_insn_read;
s->range_table_list = devpriv->rangelist; s->range_table_list = devpriv->rangelist;
for (i = 0; i < board->n_aochan; i++) { for (i = 0; i < board->n_aochan; i++) {
......
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