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

staging: comedi: c6xdigio: define the data register bits

To clarify the code, define the bits in the data register and remove the
magic numbers.
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 19d0a872
......@@ -47,6 +47,9 @@ This driver will not work with a 2.4 kernel.
* Register I/O map
*/
#define C6XDIGIO_DATA_REG 0x00
#define C6XDIGIO_DATA_CHAN(x) (((x) + 1) << 4)
#define C6XDIGIO_DATA_PWM (1 << 5)
#define C6XDIGIO_DATA_ENCODER (1 << 6)
#define C6XDIGIO_STATUS_REG 0x01
#define C6XDIGIO_CTRL_REG 0x02
......@@ -101,13 +104,8 @@ static void c6xdigio_pwm_init(struct comedi_device *dev)
static void c6xdigio_pwm_write(struct comedi_device *dev,
unsigned int chan, unsigned int val)
{
unsigned int cmd = C6XDIGIO_DATA_PWM | C6XDIGIO_DATA_CHAN(chan);
unsigned int bits;
unsigned ppcmd;
if (chan == 0)
ppcmd = 0x28;
else
ppcmd = 0x30;
if (val > 498)
val = 498;
......@@ -115,15 +113,15 @@ static void c6xdigio_pwm_write(struct comedi_device *dev,
val = 2;
bits = (val >> 0) & 0x03;
c6xdigio_write_data(dev, ppcmd + bits, 0x00);
c6xdigio_write_data(dev, cmd | bits | (0 << 2), 0x00);
bits = (val >> 2) & 0x03;
c6xdigio_write_data(dev, ppcmd + bits + 0x4, 0x80);
c6xdigio_write_data(dev, cmd | bits | (1 << 2), 0x80);
bits = (val >> 4) & 0x03;
c6xdigio_write_data(dev, ppcmd + bits, 0x00);
c6xdigio_write_data(dev, cmd | bits | (0 << 2), 0x00);
bits = (val >> 6) & 0x03;
c6xdigio_write_data(dev, ppcmd + bits + 0x4, 0x80);
c6xdigio_write_data(dev, cmd | bits | (1 << 2), 0x80);
bits = (val >> 8) & 0x03;
c6xdigio_write_data(dev, ppcmd + bits, 0x00);
c6xdigio_write_data(dev, cmd | bits | (0 << 2), 0x00);
c6xdigio_write_data(dev, 0x00, 0x80);
}
......@@ -131,39 +129,34 @@ static void c6xdigio_pwm_write(struct comedi_device *dev,
static int c6xdigio_encoder_read(struct comedi_device *dev,
unsigned int chan)
{
unsigned int cmd = C6XDIGIO_DATA_ENCODER | C6XDIGIO_DATA_CHAN(chan);
unsigned int val = 0;
unsigned int bits;
unsigned ppcmd;
if (chan == 0)
ppcmd = 0x48;
else
ppcmd = 0x50;
c6xdigio_write_data(dev, ppcmd, 0x00);
c6xdigio_write_data(dev, cmd, 0x00);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd + 0x04, 0x80);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (1 << 2), 0x80);
val |= (bits << 0);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd, 0x00);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (0 << 2), 0x00);
val |= (bits << 3);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd + 0x04, 0x80);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (1 << 2), 0x80);
val |= (bits << 6);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd, 0x00);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (0 << 2), 0x00);
val |= (bits << 9);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd + 0x04, 0x80);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (1 << 2), 0x80);
val |= (bits << 12);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd, 0x00);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (0 << 2), 0x00);
val |= (bits << 15);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd + 0x04, 0x80);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (1 << 2), 0x80);
val |= (bits << 18);
c6xdigio_get_encoder_bits(dev, &bits, ppcmd, 0x00);
c6xdigio_get_encoder_bits(dev, &bits, cmd | (0 << 2), 0x00);
val |= (bits << 21);
c6xdigio_write_data(dev, 0x00, 0x80);
......
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