[PATCH 13/21] staging: comedi: c6xdigio: tidy up c6xdigio_pwm_write()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 10-bit pwm value (2-498) is written by banging 2-bits in the data register.

Refactor this function to remove the need for the union pcmcmdtype and struct
pwmbitstype.

Signed-off-by: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/staging/comedi/drivers/c6xdigio.c | 41 +++++++++++++------------------
 1 file changed, 17 insertions(+), 24 deletions(-)

diff --git a/drivers/staging/comedi/drivers/c6xdigio.c b/drivers/staging/comedi/drivers/c6xdigio.c
index 7c2c19f..a9066d6 100644
--- a/drivers/staging/comedi/drivers/c6xdigio.c
+++ b/drivers/staging/comedi/drivers/c6xdigio.c
@@ -50,18 +50,6 @@ http://robot0.ge.uiuc.edu/~spong/mecha/
 #define C6XDIGIO_STATUS_REG	0x01
 #define C6XDIGIO_CTRL_REG	0x02
 
-struct pwmbitstype {
-	unsigned sb0:2;
-	unsigned sb1:2;
-	unsigned sb2:2;
-	unsigned sb3:2;
-	unsigned sb4:2;
-};
-union pwmcmdtype {
-	unsigned cmd;		/*  assuming here that int is 32bit */
-	struct pwmbitstype bits;
-};
-
 #define C6XDIGIO_TIME_OUT 20
 
 static int c6xdigio_chk_status(struct comedi_device *dev, unsigned long context)
@@ -113,25 +101,30 @@ 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 bits;
 	unsigned ppcmd;
-	union pwmcmdtype pwm;
-
-	pwm.cmd = val;
-	if (pwm.cmd > 498)
-		pwm.cmd = 498;
-	if (pwm.cmd < 2)
-		pwm.cmd = 2;
 
 	if (chan == 0)
 		ppcmd = 0x28;
 	else
 		ppcmd = 0x30;
 
-	c6xdigio_write_data(dev, ppcmd + pwm.bits.sb0, 0x00);
-	c6xdigio_write_data(dev, ppcmd + pwm.bits.sb1 + 0x4, 0x80);
-	c6xdigio_write_data(dev, ppcmd + pwm.bits.sb2, 0x00);
-	c6xdigio_write_data(dev, ppcmd + pwm.bits.sb3 + 0x4, 0x80);
-	c6xdigio_write_data(dev, ppcmd + pwm.bits.sb4, 0x00);
+	if (val > 498)
+		val = 498;
+	if (val < 2)
+		val = 2;
+
+	bits = (val >> 0) & 0x03;
+	c6xdigio_write_data(dev, ppcmd + bits, 0x00);
+	bits = (val >> 2) & 0x03;
+	c6xdigio_write_data(dev, ppcmd + bits + 0x4, 0x80);
+	bits = (val >> 4) & 0x03;
+	c6xdigio_write_data(dev, ppcmd + bits, 0x00);
+	bits = (val >> 6) & 0x03;
+	c6xdigio_write_data(dev, ppcmd + bits + 0x4, 0x80);
+	bits = (val >> 8) & 0x03;
+	c6xdigio_write_data(dev, ppcmd + bits, 0x00);
+
 	c6xdigio_write_data(dev, 0x00, 0x80);
 }
 
-- 
1.8.5.2

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux