From patchwork Mon Feb 15 17:37:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Ringel X-Patchwork-Id: 79439 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o1FHcQ2u013099 for ; Mon, 15 Feb 2010 17:38:26 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755892Ab0BORiW (ORCPT ); Mon, 15 Feb 2010 12:38:22 -0500 Received: from mail-in-16.arcor-online.net ([151.189.21.56]:35686 "EHLO mail-in-16.arcor-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755867Ab0BORiT (ORCPT ); Mon, 15 Feb 2010 12:38:19 -0500 Received: from mail-in-03-z2.arcor-online.net (mail-in-03-z2.arcor-online.net [151.189.8.15]) by mx.arcor.de (Postfix) with ESMTP id 184C0256FAB; Mon, 15 Feb 2010 18:38:18 +0100 (CET) Received: from mail-in-14.arcor-online.net (mail-in-14.arcor-online.net [151.189.21.54]) by mail-in-03-z2.arcor-online.net (Postfix) with ESMTP id F2CB22D367D; Mon, 15 Feb 2010 18:38:17 +0100 (CET) Received: from localhost.localdomain (dslb-188-103-172-103.pools.arcor-ip.net [188.103.172.103]) (Authenticated sender: stefan.ringel@arcor.de) by mail-in-14.arcor-online.net (Postfix) with ESMTPA id 8E7A428B0AE; Mon, 15 Feb 2010 18:38:17 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-14.arcor-online.net 8E7A428B0AE DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1266255497; bh=PtGNWsMySkOto+mCIvra8mPJlghqXSLg4Mk8a/bUEDQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=bcyaPW992qI2uRzGp7MpwPYjfAJN458v8HU/gyhnvagzHamZP7+4h25+QjElJylVO A/8jYjKNZQ1f8bQ+KinQz6VrQpjsmoap4RY4DboKx6vC2YXNfv0jM4Z/GY34jN1j0l TS5NLyfYPEqUmsnrlAOK8q69kcdwbljzQfYhP2F0= From: stefan.ringel@arcor.de To: linux-media@vger.kernel.org Cc: mchehab@redhat.com, dheitmueller@kernellabs.com, Stefan Ringel Subject: [PATCH 07/11] tm6000: add i2c send recv functions Date: Mon, 15 Feb 2010 18:37:20 +0100 Message-Id: <1266255444-7422-7-git-send-email-stefan.ringel@arcor.de> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1266255444-7422-6-git-send-email-stefan.ringel@arcor.de> References: <1266255444-7422-1-git-send-email-stefan.ringel@arcor.de> <1266255444-7422-2-git-send-email-stefan.ringel@arcor.de> <1266255444-7422-3-git-send-email-stefan.ringel@arcor.de> <1266255444-7422-4-git-send-email-stefan.ringel@arcor.de> <1266255444-7422-5-git-send-email-stefan.ringel@arcor.de> <1266255444-7422-6-git-send-email-stefan.ringel@arcor.de> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Mon, 15 Feb 2010 17:38:26 +0000 (UTC) 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)) {