[07/11] tm6000: add i2c send recv functions

Message ID 1266255444-7422-7-git-send-email-stefan.ringel@arcor.de (mailing list archive)
State Superseded, archived
Headers

Commit Message

Stefan Ringel Feb. 15, 2010, 5:37 p.m. UTC
  From: Stefan Ringel <stefan.ringel@arcor.de>

Signed-off-by: Stefan Ringel <stefan.ringel@arcor.de>
  

Comments

Mauro Carvalho Chehab Feb. 18, 2010, 8:28 p.m. UTC | #1
stefan.ringel@arcor.de wrote:
> From: Stefan Ringel <stefan.ringel@arcor.de>
> 
> Signed-off-by: Stefan Ringel <stefan.ringel@arcor.de>

Why do you need to split it into two functions? It should be noticed that the naming
tm6000_i2c_recv_word is wrong, since the size can be bigger than 2.

Also, this patch broke compilation on -git:

  CC [M]  drivers/staging/tm6000/tm6000-i2c.o
drivers/staging/tm6000/tm6000-i2c.c: In function ‘tm6000_i2c_send_byte’:
drivers/staging/tm6000/tm6000-i2c.c:50: error: ‘REQ_16_SET_GET_I2C_WR1_RND’ undeclared (first use in this function)
drivers/staging/tm6000/tm6000-i2c.c:50: error: (Each undeclared identifier is reported only once
drivers/staging/tm6000/tm6000-i2c.c:50: error: for each function it appears in.)
drivers/staging/tm6000/tm6000-i2c.c: In function ‘tm6000_i2c_recv_byte’:
drivers/staging/tm6000/tm6000-i2c.c:55: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘:’ token
drivers/staging/tm6000/tm6000-i2c.c:55: error: expected expression before ‘:’ token
drivers/staging/tm6000/tm6000-i2c.c:60: error: ‘rc’ undeclared (first use in this function)
drivers/staging/tm6000/tm6000-i2c.c: In function ‘tm6000_i2c_recv_word’:
drivers/staging/tm6000/tm6000-i2c.c:68: error: ‘REQ_14_SET_GET_I2C_WR2_RND’ undeclared (first use in this function)
make[1]: ** [drivers/staging/tm6000/tm6000-i2c.o] Erro 1


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

Patch

diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c
index 6b17d0b..9d02674 100644
--- a/drivers/staging/tm6000/tm6000-i2c.c
+++ b/drivers/staging/tm6000/tm6000-i2c.c
@@ -42,6 +42,32 @@  MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
 			printk(KERN_DEBUG "%s at %s: " fmt, \
 			dev->name, __FUNCTION__ , ##args); } while (0)
 
+int tm6000_i2c_send_byte (struct tm6000_core *dev, unsigned char addr, __u8 reg, char *buf, int len)
+{
+	return tm6000_read_write_usb (dev, USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+		REQ_16_SET_GET_I2C_WR1_RND, addr | reg << 8, 0, buf, len);
+}
+
+int tm6000_i2c_recv_byte (struct tm6000_core *dev, unsigned char addr, __u8 reg, char *buf, int len)
+{
+	int rc:
+
+	rc = tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+		REQ_16_SET_GET_I2C_WR1_RND, addr | reg << 8, 0, buf, len);
+
+	return rc;
+}
+
+int tm6000_i2c_recv_word (struct tm6000_core *dev, unsigned char addr, __u16 reg, char *buf , int len)
+{
+	int rc;
+
+	rc = tm6000_read_write_usb (dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+		REQ_14_SET_GET_I2C_WR2_RND, addr, reg, buf, len);
+
+	return rc;
+}
+
 static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
 			   struct i2c_msg msgs[], int num)
 {
@@ -76,13 +102,14 @@  static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
 			i2c_dprintk(2, "; joined to read %s len=%d:",
 				    i == num - 2 ? "stop" : "nonstop",
 				    msgs[i + 1].len);
-			rc = tm6000_read_write_usb (dev,
-				USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-				msgs[i].len == 1 ? REQ_16_SET_GET_I2C_WR1_RDN
-						 : REQ_14_SET_GET_I2C_WR2_RDN,
-				addr | msgs[i].buf[0] << 8,
-				msgs[i].len == 1 ? 0 : msgs[i].buf[1],
-				msgs[i + 1].buf, msgs[i + 1].len);
+
+			if (msgs[i].len == 1) {
+				rc = tm6000_i2c_recv_byte (dev, addr, msgs[i].buf[0],
+					msgs[i + 1].buf, msgs[i + 1].len);
+			} else {
+				rc = tm6000_i2c_recv_word (dev, addr, msgs[i].buf[0] << 8 | msgs[i].buf[1],
+					msgs[i + 1].buf, msgs[i + 1].len);
+			}
 			i++;
 
 			if ((dev->dev_type == TM6010) && (addr == 0xc2)) {
@@ -97,10 +124,8 @@  static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap,
 			if (i2c_debug >= 2)
 				for (byte = 0; byte < msgs[i].len; byte++)
 					printk(" %02x", msgs[i].buf[byte]);
-			rc = tm6000_read_write_usb(dev,
-				USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
-				REQ_16_SET_GET_I2C_WR1_RDN,
-				addr | msgs[i].buf[0] << 8, 0,
+
+			rc = tm6000_i2c_send_byte(dev, addr, msgs[i].buf[0],
 				msgs[i].buf + 1, msgs[i].len - 1);
 
 			if ((dev->dev_type == TM6010) && (addr == 0xc2)) {