[PATCH 2/4] ark3116: Tidy register read and write functions

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

 



This patch should not change functionality and is a cleanup only:

 * Use lower case for function names.
 * Remove unused parameters expected and seq.
 * Hardcode unchanging parameters request and requesttype.
 * Remove ARK3116_RCV_QUIET.
 * Return usb_control_msg's return code.

Signed-off-by: Mike McCormack <mikem@xxxxxxxxxx>
---
 drivers/usb/serial/ark3116.c |  158 ++++++++++++++++++------------------------
 1 files changed, 68 insertions(+), 90 deletions(-)

diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index 12d70e3..36f61d4 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -45,107 +45,87 @@ static int is_irda(struct usb_serial *serial)
 	return 0;
 }
 
-static inline void ARK3116_SND(struct usb_serial *serial, int seq,
-			       __u8 request, __u8 requesttype,
-			       __u16 value, __u16 index)
+static inline int ark3116_snd(struct usb_serial *serial,
+			      u16 value, u16 index)
 {
-	int result;
-	result = usb_control_msg(serial->dev,
+	return usb_control_msg(serial->dev,
 				 usb_sndctrlpipe(serial->dev, 0),
-				 request, requesttype, value, index,
+				 0xfe, 0x40, value, index,
 				 NULL, 0x00, 1000);
-	dbg("%03d > ok", seq);
 }
 
-static inline void ARK3116_RCV(struct usb_serial *serial, int seq,
-			       __u8 request, __u8 requesttype,
-			       __u16 value, __u16 index, __u8 expected,
-			       char *buf)
+static inline int ark3116_rcv(struct usb_serial *serial,
+			      u16 value, u16 index,
+			      unsigned char *buf)
 {
-	int result;
-	result = usb_control_msg(serial->dev,
+	return usb_control_msg(serial->dev,
 				 usb_rcvctrlpipe(serial->dev, 0),
-				 request, requesttype, value, index,
+				 0xfe, 0xc0, value, index,
 				 buf, 0x0000001, 1000);
-	if (result)
-		dbg("%03d < %d bytes [0x%02X]", seq, result,
-		    ((unsigned char *)buf)[0]);
-	else
-		dbg("%03d < 0 bytes", seq);
-}
-
-static inline void ARK3116_RCV_QUIET(struct usb_serial *serial,
-				     __u8 request, __u8 requesttype,
-				     __u16 value, __u16 index, char *buf)
-{
-	usb_control_msg(serial->dev,
-			usb_rcvctrlpipe(serial->dev, 0),
-			request, requesttype, value, index,
-			buf, 0x0000001, 1000);
 }
 
 static int ark3116_attach(struct usb_serial *serial)
 {
-	char buf[1];
+	unsigned char buf[1];
 
 	if (is_irda(serial))
 		dbg("IrDA mode");
 
 	/* 3 */
-	ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002);
-	ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001);
-	ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008);
-	ARK3116_SND(serial, 6, 0xFE, 0x40, is_irda(serial) ? 0x0001 : 0x0000,
+	ark3116_snd(serial, 0x0008, 0x0002);
+	ark3116_snd(serial, 0x0008, 0x0001);
+	ark3116_snd(serial, 0x0000, 0x0008);
+	ark3116_snd(serial, is_irda(serial) ? 0x0001 : 0x0000,
 		    0x000B);
 
 	if (is_irda(serial)) {
-		ARK3116_SND(serial, 1001, 0xFE, 0x40, 0x0000, 0x000C);
-		ARK3116_SND(serial, 1002, 0xFE, 0x40, 0x0041, 0x000D);
-		ARK3116_SND(serial, 1003, 0xFE, 0x40, 0x0001, 0x000A);
+		ark3116_snd(serial, 0x0000, 0x000C);
+		ark3116_snd(serial, 0x0041, 0x000D);
+		ark3116_snd(serial, 0x0001, 0x000A);
 	}
 
 	/* <-- seq7 */
-	ARK3116_RCV(serial,  7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
-	ARK3116_SND(serial,  8, 0xFE, 0x40, 0x0080, 0x0003);
-	ARK3116_SND(serial,  9, 0xFE, 0x40, 0x001A, 0x0000);
-	ARK3116_SND(serial, 10, 0xFE, 0x40, 0x0000, 0x0001);
-	ARK3116_SND(serial, 11, 0xFE, 0x40, 0x0000, 0x0003);
+	ark3116_rcv(serial, 0x0000, 0x0003, buf);
+	ark3116_snd(serial, 0x0080, 0x0003);
+	ark3116_snd(serial, 0x001A, 0x0000);
+	ark3116_snd(serial, 0x0000, 0x0001);
+	ark3116_snd(serial, 0x0000, 0x0003);
 
 	/* <-- seq12 */
-	ARK3116_RCV(serial, 12, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
-	ARK3116_SND(serial, 13, 0xFE, 0x40, 0x0000, 0x0004);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
+	ark3116_snd(serial, 0x0000, 0x0004);
 
 	/* 14 */
-	ARK3116_RCV(serial, 14, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
-	ARK3116_SND(serial, 15, 0xFE, 0x40, 0x0000, 0x0004);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
+	ark3116_snd(serial, 0x0000, 0x0004);
 
 	/* 16 */
-	ARK3116_RCV(serial, 16, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
 	/* --> seq17 */
-	ARK3116_SND(serial, 17, 0xFE, 0x40, 0x0001, 0x0004);
+	ark3116_snd(serial, 0x0001, 0x0004);
 
 	/* <-- seq18 */
-	ARK3116_RCV(serial, 18, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
 
 	/* --> seq19 */
-	ARK3116_SND(serial, 19, 0xFE, 0x40, 0x0003, 0x0004);
+	ark3116_snd(serial, 0x0003, 0x0004);
 
 	/* <-- seq20 */
 	/* seems like serial port status info (RTS, CTS, ...) */
 	/* returns modem control line status?! */
-	ARK3116_RCV(serial, 20, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
+	ark3116_rcv(serial, 0x0000, 0x0006, buf);
 
 	/* set 9600 baud & do some init?! */
-	ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
-	ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000);
-	ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001);
+	ark3116_snd(serial, 0x0083, 0x0003);
+	ark3116_snd(serial, 0x0038, 0x0000);
+	ark3116_snd(serial, 0x0001, 0x0001);
 	if (is_irda(serial))
-		ARK3116_SND(serial, 1004, 0xFE, 0x40, 0x0000, 0x0009);
-	ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
-	ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
-	ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
-	ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
-	ARK3116_SND(serial, 154, 0xFE, 0x40, 0x0003, 0x0003);
+		ark3116_snd(serial, 0x0000, 0x0009);
+	ark3116_snd(serial, 0x0003, 0x0003);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
+	ark3116_snd(serial, 0x0000, 0x0003);
+	ark3116_rcv(serial, 0x0000, 0x0003, buf);
+	ark3116_snd(serial, 0x0003, 0x0003);
 
 	return 0;
 }
@@ -169,7 +149,7 @@ static void ark3116_set_termios(struct tty_struct *tty,
 	unsigned int cflag = termios->c_cflag;
 	int baud;
 	int ark3116_baud;
-	char buf[1];
+	unsigned char buf[1];
 	char config;
 
 	config = 0;
@@ -267,7 +247,7 @@ static void ark3116_set_termios(struct tty_struct *tty,
 		ark3116_baud = 3000000 / baud;
 
 	/* ? */
-	ARK3116_RCV(serial, 0, 0xFE, 0xC0, 0x0000, 0x0003, 0x03, buf);
+	ark3116_rcv(serial, 0x0000, 0x0003, buf);
 
 	/* offset = buf[0]; */
 	/* offset = 0x03; */
@@ -275,33 +255,31 @@ static void ark3116_set_termios(struct tty_struct *tty,
 
 	/* set baudrate */
 	dbg("setting baudrate to %d (->reg=%d)", baud, ark3116_baud);
-	ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
-	ARK3116_SND(serial, 148, 0xFE, 0x40,
-			    (ark3116_baud & 0x00FF), 0x0000);
-	ARK3116_SND(serial, 149, 0xFE, 0x40,
-			    (ark3116_baud & 0xFF00) >> 8, 0x0001);
-	ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
+	ark3116_snd(serial, 0x0083, 0x0003);
+	ark3116_snd(serial, (ark3116_baud & 0x00FF), 0x0000);
+	ark3116_snd(serial, (ark3116_baud & 0xFF00) >> 8, 0x0001);
+	ark3116_snd(serial, 0x0003, 0x0003);
 
 	/* ? */
-	ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
-	ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
+	ark3116_snd(serial, 0x0000, 0x0003);
 
 	/* set data bit count, stop bit count & parity: */
 	dbg("updating bit count, stop bit or parity (cfg=0x%02X)", config);
-	ARK3116_RCV(serial, 153, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
-	ARK3116_SND(serial, 154, 0xFE, 0x40, config, 0x0003);
+	ark3116_rcv(serial, 0x0000, 0x0003, buf);
+	ark3116_snd(serial, config, 0x0003);
 
 	if (cflag & CRTSCTS)
 		dbg("CRTSCTS not supported by chipset?!");
 
-	/* TEST ARK3116_SND(154, 0xFE, 0x40, 0xFFFF, 0x0006); */
+	/* TEST ark3116_snd(154, 0xFFFF, 0x0006); */
 }
 
 static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
 {
 	struct ktermios tmp_termios;
 	struct usb_serial *serial = port->serial;
-	char buf[1];
+	unsigned char buf[1];
 	int result = 0;
 
 	dbg("%s - port %d", __func__, port->number);
@@ -311,29 +289,29 @@ static int ark3116_open(struct tty_struct *tty, struct usb_serial_port *port)
 		goto err_out;
 
 	/* open */
-	ARK3116_RCV(serial, 111, 0xFE, 0xC0, 0x0000, 0x0003, 0x02, buf);
+	ark3116_rcv(serial, 0x0000, 0x0003, buf);
 
-	ARK3116_SND(serial, 112, 0xFE, 0x40, 0x0082, 0x0003);
-	ARK3116_SND(serial, 113, 0xFE, 0x40, 0x001A, 0x0000);
-	ARK3116_SND(serial, 114, 0xFE, 0x40, 0x0000, 0x0001);
-	ARK3116_SND(serial, 115, 0xFE, 0x40, 0x0002, 0x0003);
+	ark3116_snd(serial, 0x0082, 0x0003);
+	ark3116_snd(serial, 0x001A, 0x0000);
+	ark3116_snd(serial, 0x0000, 0x0001);
+	ark3116_snd(serial, 0x0002, 0x0003);
 
-	ARK3116_RCV(serial, 116, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
-	ARK3116_SND(serial, 117, 0xFE, 0x40, 0x0002, 0x0004);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
+	ark3116_snd(serial, 0x0002, 0x0004);
 
-	ARK3116_RCV(serial, 118, 0xFE, 0xC0, 0x0000, 0x0004, 0x02, buf);
-	ARK3116_SND(serial, 119, 0xFE, 0x40, 0x0000, 0x0004);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
+	ark3116_snd(serial, 0x0000, 0x0004);
 
-	ARK3116_RCV(serial, 120, 0xFE, 0xC0, 0x0000, 0x0004, 0x00, buf);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
 
-	ARK3116_SND(serial, 121, 0xFE, 0x40, 0x0001, 0x0004);
+	ark3116_snd(serial, 0x0001, 0x0004);
 
-	ARK3116_RCV(serial, 122, 0xFE, 0xC0, 0x0000, 0x0004, 0x01, buf);
+	ark3116_rcv(serial, 0x0000, 0x0004, buf);
 
-	ARK3116_SND(serial, 123, 0xFE, 0x40, 0x0003, 0x0004);
+	ark3116_snd(serial, 0x0003, 0x0004);
 
 	/* returns different values (control lines?!) */
-	ARK3116_RCV(serial, 124, 0xFE, 0xC0, 0x0000, 0x0006, 0xFF, buf);
+	ark3116_rcv(serial, 0x0000, 0x0006, buf);
 
 	/* initialise termios */
 	if (tty)
@@ -381,7 +359,7 @@ static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
 {
 	struct usb_serial_port *port = tty->driver_data;
 	struct usb_serial *serial = port->serial;
-	char temp;
+	unsigned char temp;
 
 	/* seems like serial port status info (RTS, CTS, ...) is stored
 	 * in reg(?) 0x0006
@@ -390,7 +368,7 @@ static int ark3116_tiocmget(struct tty_struct *tty, struct file *file)
 	 */
 
 	/* read register */
-	ARK3116_RCV_QUIET(serial, 0xFE, 0xC0, 0x0000, 0x0006, &temp);
+	ark3116_rcv(serial, 0x0000, 0x0006, &temp);
 
 	/* i do not really know if bit4=CTS and bit6=DSR... just a
 	 * quick guess!
-- 
1.5.6.5


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux