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

staging: comedi: usbduxsigma: tidy up usbdux_pwm_pattern()

Rename the function so it has namespace associated with the driver.

Tidy up the function to make it more concise.
Signed-off-by: default avatarH Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 4ced8c64
...@@ -1326,42 +1326,30 @@ static int usbdux_pwm_start(struct comedi_device *dev, ...@@ -1326,42 +1326,30 @@ static int usbdux_pwm_start(struct comedi_device *dev,
return 0; return 0;
} }
/* generates the bit pattern for PWM with the optional sign bit */ static int usbduxsigma_pwm_pattern(struct comedi_device *dev,
static int usbdux_pwm_pattern(struct comedi_device *dev, struct comedi_subdevice *s,
struct comedi_subdevice *s, int channel, unsigned int chan,
unsigned int value, unsigned int sign) unsigned int value,
unsigned int sign)
{ {
struct usbduxsigma_private *this_usbduxsub = dev->private; struct usbduxsigma_private *devpriv = dev->private;
int i, szbuf; char pwm_mask = (1 << chan); /* DIO bit for the PWM data */
char *pBuf; char sgn_mask = (16 << chan); /* DIO bit for the sign */
char pwm_mask; char *buf = (char *)(devpriv->urbPwm->transfer_buffer);
char sgn_mask; int szbuf = devpriv->sizePwmBuf;
char c; int i;
/* this is the DIO bit which carries the PWM data */
pwm_mask = (1 << channel);
/* this is the DIO bit which carries the optional direction bit */
sgn_mask = (16 << channel);
/* this is the buffer which will be filled with the with bit */
/* pattern for one period */
szbuf = this_usbduxsub->sizePwmBuf;
pBuf = (char *)(this_usbduxsub->urbPwm->transfer_buffer);
for (i = 0; i < szbuf; i++) { for (i = 0; i < szbuf; i++) {
c = *pBuf; char c = *buf;
/* reset bits */
c = c & (~pwm_mask); c &= ~pwm_mask;
/* set the bit as long as the index is lower than the value */
if (i < value) if (i < value)
c = c | pwm_mask; c |= pwm_mask;
/* set the optional sign bit for a relay */ if (!sign)
if (!sign) { c &= ~sgn_mask;
/* positive value */ else
c = c & (~sgn_mask); c |= sgn_mask;
} else { *buf++ = c;
/* negative value */
c = c | sgn_mask;
}
*(pBuf++) = c;
} }
return 1; return 1;
} }
...@@ -1384,7 +1372,7 @@ static int usbduxsigma_pwm_write(struct comedi_device *dev, ...@@ -1384,7 +1372,7 @@ static int usbduxsigma_pwm_write(struct comedi_device *dev,
* The sign is set via a special INSN only, this gives us 8 bits * The sign is set via a special INSN only, this gives us 8 bits
* for normal operation, sign is 0 by default. * for normal operation, sign is 0 by default.
*/ */
return usbdux_pwm_pattern(dev, s, chan, data[0], 0); return usbduxsigma_pwm_pattern(dev, s, chan, data[0], 0);
} }
static int usbduxsigma_pwm_config(struct comedi_device *dev, static int usbduxsigma_pwm_config(struct comedi_device *dev,
...@@ -1393,6 +1381,7 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev, ...@@ -1393,6 +1381,7 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev,
unsigned int *data) unsigned int *data)
{ {
struct usbduxsigma_private *devpriv = dev->private; struct usbduxsigma_private *devpriv = dev->private;
unsigned int chan = CR_CHAN(insn->chanspec);
switch (data[0]) { switch (data[0]) {
case INSN_CONFIG_ARM: case INSN_CONFIG_ARM:
...@@ -1418,7 +1407,7 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev, ...@@ -1418,7 +1407,7 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev,
* data[1] = value * data[1] = value
* data[2] = sign (for a relay) * data[2] = sign (for a relay)
*/ */
return usbdux_pwm_pattern(dev, s, CR_CHAN(insn->chanspec), return usbduxsigma_pwm_pattern(dev, s, chan,
data[1], (data[2] != 0)); data[1], (data[2] != 0));
case INSN_CONFIG_PWM_GET_H_BRIDGE: case INSN_CONFIG_PWM_GET_H_BRIDGE:
/* values are not kept in this driver, nothing to return */ /* values are not kept in this driver, nothing to return */
......
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