From patchwork Wed Apr 28 01:32:43 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitri Belimov X-Patchwork-Id: 95563 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 o3S1U0wE008845 for ; Wed, 28 Apr 2010 01:30:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755295Ab0D1B35 (ORCPT ); Tue, 27 Apr 2010 21:29:57 -0400 Received: from ey-out-2122.google.com ([74.125.78.27]:3685 "EHLO ey-out-2122.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755251Ab0D1B34 (ORCPT ); Tue, 27 Apr 2010 21:29:56 -0400 Received: by ey-out-2122.google.com with SMTP id d26so1248911eyd.19 for ; Tue, 27 Apr 2010 18:29:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:in-reply-to:references:x-mailer:mime-version :content-type; bh=aZhD/a8BgufvX61wj+hg0gRWWw2CJuZdTLBZW/DCeA8=; b=mUQ5hAg3RbLigeOABEGmy2VLq+0Iz3NbuKyEOHiWGaGp2n5v8yrk5cdq2A5Z3B3uBB LapN7H5HTmtylLc6AB5Izdahc9nALFIeZZhO3W0a1fIdmo+AFxJduV24DqNUFBC00SzG 2xxSILzkvZHOp9cnabtXnC1ATdtJOwJGx1DNk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type; b=KVhpR/WM0gvC7CJvmPZqjJ2BH5KjXKzGldf3mPm1aDkLw+OwAKQ7yZf7MjLNw4CEZP ETklJC1G6h5/HoFLeuGsPKPO143ZB7DzEsmWwqS/vHJEEzkmNNLwah8cKgD3FpVCHna+ af1k0Y17emgt1F6AODKKvnxTzzfT50+Acx7GI= Received: by 10.213.79.76 with SMTP id o12mr2530774ebk.19.1272418194276; Tue, 27 Apr 2010 18:29:54 -0700 (PDT) Received: from glory.loctelecom.ru (ns2.openhardware.ru [84.19.183.172]) by mx.google.com with ESMTPS id 14sm3061092ewy.14.2010.04.27.18.29.50 (version=SSLv3 cipher=RC4-MD5); Tue, 27 Apr 2010 18:29:53 -0700 (PDT) Date: Wed, 28 Apr 2010 11:32:43 +1000 From: Dmitri Belimov To: Bee Hock Goh Cc: Stefan Ringel , linux-media@vger.kernel.org, Mauro Carvalho Chehab Subject: Re: [PATCH] tm6000 fix i2c Message-ID: <20100428113243.26bc7030@glory.loctelecom.ru> In-Reply-To: References: <20100423104804.784fb730@glory.loctelecom.ru> <4BD1B985.8060703@arcor.de> <20100426102514.2c13761e@glory.loctelecom.ru> <20100427151545.217a5c90@glory.loctelecom.ru> X-Mailer: Claws Mail 3.5.0 (GTK+ 2.16.1; i486-pc-linux-gnu) Mime-Version: 1.0 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]); Wed, 28 Apr 2010 01:30:01 +0000 (UTC) diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c index 2ab632b..e9b568d 100644 --- a/drivers/staging/tm6000/tm6000-i2c.c +++ b/drivers/staging/tm6000/tm6000-i2c.c @@ -47,8 +47,38 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); static int tm6000_i2c_send_regs(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_RDN, addr | reg << 8, 0, buf, len); + int rc; + unsigned int tsleep; + unsigned int i2c_packet_limit = 16; + + if (dev->dev_type == TM6010) + i2c_packet_limit = 64; + + if (!buf) + return -1; + + if (len < 1 || len > i2c_packet_limit){ + printk("Incorrect lenght of i2c packet = %d, limit set to %d\n", + len, i2c_packet_limit); + return -1; + } + + /* capture mutex */ + rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN, + addr | reg << 8, 0, buf, len); + + if (rc < 0) { + /* release mutex */ + return rc; + } + + /* Calculate delay time, 14000us for 64 bytes */ + tsleep = ((len * 200) + 200 + 1000) / 1000; + msleep(tsleep); + + /* release mutex */ + return rc; } /* Generic read - doesn't work fine with 16bit registers */ @@ -57,7 +87,21 @@ static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr, { int rc; u8 b[2]; + unsigned int i2c_packet_limit = 16; + + if (dev->dev_type == TM6010) + i2c_packet_limit = 64; + + if (!buf) + return -1; + if (len < 1 || len > i2c_packet_limit){ + printk("Incorrect lenght of i2c packet = %d, limit set to %d\n", + len, i2c_packet_limit); + return -1; + } + + /* capture mutex */ if ((dev->caps.has_zl10353) && (dev->demod_addr << 1 == addr) && (reg % 2 == 0)) { /* * Workaround an I2C bug when reading from zl10353 @@ -74,6 +118,7 @@ static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr, REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len); } + /* release mutex */ return rc; } @@ -84,8 +129,37 @@ static int tm6000_i2c_recv_regs(struct tm6000_core *dev, unsigned char addr, static int tm6000_i2c_recv_regs16(struct tm6000_core *dev, unsigned char addr, __u16 reg, char *buf, int len) { - return tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - REQ_14_SET_GET_I2C_WR2_RDN, addr, reg, buf, len); + int rc; + unsigned char ureg; + + if (!buf || len != 2) + return -1; + + /* capture mutex */ + if (dev->dev_type == TM6010){ + ureg = reg & 0xFF; + rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN, + addr | (reg & 0xFF00), 0, &ureg, 1); + + if (rc < 0) { + /* release mutex */ + return rc; + } + + msleep(1400 / 1000); + rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_35_AFTEK_TUNER_READ, + reg, 0, buf, len); + } + else { + rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_14_SET_GET_I2C_WR2_RDN, + addr, reg, buf, len); + } + + /* release mutex */ + return rc; } static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, Signed-off-by: Beholder Intl. Ltd. Dmitry Belimov