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

staging: comedi: me_daq: tidy up dac control register defines

Redefine the dac control register bits as macros that take the
channel number and return the correct bit values.

This register needs to be read after the new values are written
in order to actually update the dac. For aesthetics, use the same
define to read and write the registers.
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 abd2541f
...@@ -89,24 +89,12 @@ ...@@ -89,24 +89,12 @@
#define ME_AI_FIFO_CHANLIST_UNIPOLAR BIT(6) #define ME_AI_FIFO_CHANLIST_UNIPOLAR BIT(6)
#define ME_AI_FIFO_CHANLIST_GAIN(x) (((x) & 0x3) << 4) #define ME_AI_FIFO_CHANLIST_GAIN(x) (((x) & 0x3) << 4)
#define ME_AI_FIFO_CHANLIST_CHAN(x) (((x) & 0xf) << 0) #define ME_AI_FIFO_CHANLIST_CHAN(x) (((x) & 0xf) << 0)
#define ME_DAC_CONTROL 0x0012 /* - | W */ #define ME_DAC_CTRL_REG 0x12 /* R (updates) | W */
#define DAC_UNIPOLAR_D (0<<4) #define ME_DAC_CTRL_BIPOLAR(x) BIT(7 - ((x) & 0x3))
#define DAC_BIPOLAR_D (1<<4) #define ME_DAC_CTRL_GAIN(x) BIT(11 - ((x) & 0x3))
#define DAC_UNIPOLAR_C (0<<5) #define ME_DAC_CTRL_MASK(x) (ME_DAC_CTRL_BIPOLAR(x) | \
#define DAC_BIPOLAR_C (1<<5) ME_DAC_CTRL_GAIN(x))
#define DAC_UNIPOLAR_B (0<<6)
#define DAC_BIPOLAR_B (1<<6)
#define DAC_UNIPOLAR_A (0<<7)
#define DAC_BIPOLAR_A (1<<7)
#define DAC_GAIN_0_D (0<<8)
#define DAC_GAIN_1_D (1<<8)
#define DAC_GAIN_0_C (0<<9)
#define DAC_GAIN_1_C (1<<9)
#define DAC_GAIN_0_B (0<<10)
#define DAC_GAIN_1_B (1<<10)
#define DAC_GAIN_0_A (0<<11)
#define DAC_GAIN_1_A (1<<11)
#define ME_DAC_CONTROL_UPDATE 0x0012 /* R | - */
#define ME_DAC_DATA_A 0x0014 /* - | W */ #define ME_DAC_DATA_A 0x0014 /* - | W */
#define ME_DAC_DATA_B 0x0016 /* - | W */ #define ME_DAC_DATA_B 0x0016 /* - | W */
#define ME_DAC_DATA_C 0x0018 /* - | W */ #define ME_DAC_DATA_C 0x0018 /* - | W */
...@@ -318,7 +306,7 @@ static int me_ao_insn_write(struct comedi_device *dev, ...@@ -318,7 +306,7 @@ static int me_ao_insn_write(struct comedi_device *dev,
{ {
struct me_private_data *devpriv = dev->private; struct me_private_data *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec); unsigned int chan = CR_CHAN(insn->chanspec);
unsigned int rang = CR_RANGE(insn->chanspec); unsigned int range = CR_RANGE(insn->chanspec);
unsigned int val = s->readback[chan]; unsigned int val = s->readback[chan];
int i; int i;
...@@ -333,18 +321,17 @@ static int me_ao_insn_write(struct comedi_device *dev, ...@@ -333,18 +321,17 @@ static int me_ao_insn_write(struct comedi_device *dev,
/* Set dac-control register */ /* Set dac-control register */
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
/* clear bits for this channel */ /* clear bits for this channel */
devpriv->dac_ctrl &= ~(0x0880 >> chan); devpriv->dac_ctrl &= ~ME_DAC_CTRL_MASK(chan);
if (rang == 0) if (range == 0)
devpriv->dac_ctrl |= devpriv->dac_ctrl |= ME_DAC_CTRL_GAIN(chan) |
((DAC_BIPOLAR_A | DAC_GAIN_1_A) >> chan); ME_DAC_CTRL_BIPOLAR(chan);
else if (rang == 1) else if (range == 1)
devpriv->dac_ctrl |= devpriv->dac_ctrl |= ME_DAC_CTRL_BIPOLAR(chan);
((DAC_BIPOLAR_A | DAC_GAIN_0_A) >> chan);
} }
writew(devpriv->dac_ctrl, dev->mmio + ME_DAC_CONTROL); writew(devpriv->dac_ctrl, dev->mmio + ME_DAC_CTRL_REG);
/* Update dac-control register */ /* Update dac-control register */
readw(dev->mmio + ME_DAC_CONTROL_UPDATE); readw(dev->mmio + ME_DAC_CTRL_REG);
/* Set data register */ /* Set data register */
for (i = 0; i < insn->n; i++) { for (i = 0; i < insn->n; i++) {
...@@ -438,7 +425,7 @@ static int me_reset(struct comedi_device *dev) ...@@ -438,7 +425,7 @@ static int me_reset(struct comedi_device *dev)
writew(0x00, dev->mmio + ME_CTRL1_REG); writew(0x00, dev->mmio + ME_CTRL1_REG);
writew(0x00, dev->mmio + ME_CTRL2_REG); writew(0x00, dev->mmio + ME_CTRL2_REG);
writew(0x00, dev->mmio + ME_STATUS_REG); /* clear interrupts */ writew(0x00, dev->mmio + ME_STATUS_REG); /* clear interrupts */
writew(0x00, dev->mmio + ME_DAC_CONTROL); writew(0x00, dev->mmio + ME_DAC_CTRL_REG);
/* Save values in the board context */ /* Save values in the board context */
devpriv->dac_ctrl = 0; devpriv->dac_ctrl = 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