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

staging: comedi: pcl711: tidy up pcl711_ao_insn()

For aesthetics, rename this function to help with greps.

Introduce a helper function to write the values to the analog
output channel registers. Modify the defines for the D/A registers
to avoid the ? : tests based on the chan number.

Only the final value written needs to be saved for read back.
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 8509e6d8
...@@ -70,13 +70,11 @@ supported. ...@@ -70,13 +70,11 @@ supported.
#define PCL711_CTR2 0x02 #define PCL711_CTR2 0x02
#define PCL711_CTRCTL 0x03 #define PCL711_CTRCTL 0x03
#define PCL711_AD_LO 0x04 #define PCL711_AD_LO 0x04
#define PCL711_DA0_LO 0x04
#define PCL711_AD_HI 0x05 #define PCL711_AD_HI 0x05
#define PCL711_DA0_HI 0x05 #define PCL711_AO_LSB_REG(x) (0x04 + ((x) * 2))
#define PCL711_AO_MSB_REG(x) (0x05 + ((x) * 2))
#define PCL711_DI_LO 0x06 #define PCL711_DI_LO 0x06
#define PCL711_DA1_LO 0x06
#define PCL711_DI_HI 0x07 #define PCL711_DI_HI 0x07
#define PCL711_DA1_HI 0x07
#define PCL711_CLRINTR 0x08 #define PCL711_CLRINTR 0x08
#define PCL711_GAIN 0x09 #define PCL711_GAIN 0x09
#define PCL711_MUX 0x0a #define PCL711_MUX 0x0a
...@@ -405,26 +403,30 @@ static int pcl711_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s) ...@@ -405,26 +403,30 @@ static int pcl711_ai_cmd(struct comedi_device *dev, struct comedi_subdevice *s)
return 0; return 0;
} }
/* static void pcl711_ao_write(struct comedi_device *dev,
analog output unsigned int chan, unsigned int val)
*/
static int pcl711_ao_insn(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_insn *insn, unsigned int *data)
{ {
struct pcl711_private *devpriv = dev->private; outb(val & 0xff, dev->iobase + PCL711_AO_LSB_REG(chan));
int n; outb((val >> 8) & 0xff, dev->iobase + PCL711_AO_MSB_REG(chan));
int chan = CR_CHAN(insn->chanspec); }
for (n = 0; n < insn->n; n++) { static int pcl711_ao_insn_write(struct comedi_device *dev,
outb((data[n] & 0xff), struct comedi_subdevice *s,
dev->iobase + (chan ? PCL711_DA1_LO : PCL711_DA0_LO)); struct comedi_insn *insn,
outb((data[n] >> 8), unsigned int *data)
dev->iobase + (chan ? PCL711_DA1_HI : PCL711_DA0_HI)); {
struct pcl711_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int val = devpriv->ao_readback[chan];
int i;
devpriv->ao_readback[chan] = data[n]; for (i = 0; i < insn->n; i++) {
val = data[i];
pcl711_ao_write(dev, chan, val);
} }
devpriv->ao_readback[chan] = val;
return n; return insn->n;
} }
static int pcl711_ao_insn_read(struct comedi_device *dev, static int pcl711_ao_insn_read(struct comedi_device *dev,
...@@ -530,7 +532,7 @@ static int pcl711_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -530,7 +532,7 @@ static int pcl711_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->range_table = &range_bipolar5; s->range_table = &range_bipolar5;
s->insn_write = pcl711_ao_insn; s->insn_write = pcl711_ao_insn_write;
s->insn_read = pcl711_ao_insn_read; s->insn_read = pcl711_ao_insn_read;
/* Digital Input subdevice */ /* Digital Input subdevice */
...@@ -552,12 +554,8 @@ static int pcl711_attach(struct comedi_device *dev, struct comedi_devconfig *it) ...@@ -552,12 +554,8 @@ static int pcl711_attach(struct comedi_device *dev, struct comedi_devconfig *it)
s->insn_bits = pcl711_do_insn_bits; s->insn_bits = pcl711_do_insn_bits;
/* clear DAC */ /* clear DAC */
outb(0, dev->iobase + PCL711_DA0_LO); pcl711_ao_write(dev, 0, 0x0);
outb(0, dev->iobase + PCL711_DA0_HI); pcl711_ao_write(dev, 1, 0x0);
outb(0, dev->iobase + PCL711_DA1_LO);
outb(0, dev->iobase + PCL711_DA1_HI);
printk(KERN_INFO "\n");
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