From ab58a6e35d5f2bbbdd54095df642bcc364e8e3a2 Mon Sep 17 00:00:00 2001 From: H Hartley Sweeten Date: Thu, 23 May 2013 12:58:43 -0700 Subject: [PATCH] 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: H Hartley Sweeten Cc: Ian Abbott Signed-off-by: Greg Kroah-Hartman --- drivers/staging/comedi/drivers/usbduxsigma.c | 61 ++++++++------------ 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/drivers/staging/comedi/drivers/usbduxsigma.c b/drivers/staging/comedi/drivers/usbduxsigma.c index 52f75a4b48e1..e0358daab2a0 100644 --- a/drivers/staging/comedi/drivers/usbduxsigma.c +++ b/drivers/staging/comedi/drivers/usbduxsigma.c @@ -1326,42 +1326,30 @@ static int usbdux_pwm_start(struct comedi_device *dev, return 0; } -/* generates the bit pattern for PWM with the optional sign bit */ -static int usbdux_pwm_pattern(struct comedi_device *dev, - struct comedi_subdevice *s, int channel, - unsigned int value, unsigned int sign) +static int usbduxsigma_pwm_pattern(struct comedi_device *dev, + struct comedi_subdevice *s, + unsigned int chan, + unsigned int value, + unsigned int sign) { - struct usbduxsigma_private *this_usbduxsub = dev->private; - int i, szbuf; - char *pBuf; - char pwm_mask; - char sgn_mask; - char c; - - /* 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); + struct usbduxsigma_private *devpriv = dev->private; + char pwm_mask = (1 << chan); /* DIO bit for the PWM data */ + char sgn_mask = (16 << chan); /* DIO bit for the sign */ + char *buf = (char *)(devpriv->urbPwm->transfer_buffer); + int szbuf = devpriv->sizePwmBuf; + int i; + for (i = 0; i < szbuf; i++) { - c = *pBuf; - /* reset bits */ - c = c & (~pwm_mask); - /* set the bit as long as the index is lower than the value */ + char c = *buf; + + c &= ~pwm_mask; if (i < value) - c = c | pwm_mask; - /* set the optional sign bit for a relay */ - if (!sign) { - /* positive value */ - c = c & (~sgn_mask); - } else { - /* negative value */ - c = c | sgn_mask; - } - *(pBuf++) = c; + c |= pwm_mask; + if (!sign) + c &= ~sgn_mask; + else + c |= sgn_mask; + *buf++ = c; } return 1; } @@ -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 * 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, @@ -1393,6 +1381,7 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev, unsigned int *data) { struct usbduxsigma_private *devpriv = dev->private; + unsigned int chan = CR_CHAN(insn->chanspec); switch (data[0]) { case INSN_CONFIG_ARM: @@ -1418,8 +1407,8 @@ static int usbduxsigma_pwm_config(struct comedi_device *dev, * data[1] = value * data[2] = sign (for a relay) */ - return usbdux_pwm_pattern(dev, s, CR_CHAN(insn->chanspec), - data[1], (data[2] != 0)); + return usbduxsigma_pwm_pattern(dev, s, chan, + data[1], (data[2] != 0)); case INSN_CONFIG_PWM_GET_H_BRIDGE: /* values are not kept in this driver, nothing to return */ return -EINVAL; -- 2.20.1