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

staging: comedi: usbdux: tidy up usbdux_pwm_pattern()

Rename the local variable used for the private data pointer to 'devpriv'.

Remove the sanity check of the private data. This function can only be
called if the private data was successfully allocated in the attach.

Tidy up the function to make it more concise.
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 9fe4df4d
...@@ -1396,45 +1396,30 @@ static int usbdux_pwm_start(struct comedi_device *dev, ...@@ -1396,45 +1396,30 @@ static int usbdux_pwm_start(struct comedi_device *dev,
return ret; return ret;
} }
/* generates the bit pattern for PWM with the optional sign bit */
static int usbdux_pwm_pattern(struct comedi_device *dev, static int usbdux_pwm_pattern(struct comedi_device *dev,
struct comedi_subdevice *s, int channel, struct comedi_subdevice *s,
unsigned int value, unsigned int sign) unsigned int chan,
unsigned int value,
unsigned int sign)
{ {
struct usbdux_private *this_usbduxsub = dev->private; struct usbdux_private *devpriv = dev->private;
int i, szbuf; char pwm_mask = (1 << chan); /* DIO bit for the PWM data */
char *p_buf; char sgn_mask = (16 << chan); /* DIO bit for the sign */
char pwm_mask; char *buf = (char *)(devpriv->pwm_urb->transfer_buffer);
char sgn_mask; int szbuf = devpriv->pwm_buf_sz;
char c; int i;
if (!this_usbduxsub)
return -EFAULT;
/* 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->pwm_buf_sz;
p_buf = (char *)(this_usbduxsub->pwm_urb->transfer_buffer);
for (i = 0; i < szbuf; i++) { for (i = 0; i < szbuf; i++) {
c = *p_buf; 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;
}
*(p_buf++) = c;
} }
return 1; return 1;
} }
......
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