From patchwork Fri Apr 23 00:48:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitri Belimov X-Patchwork-Id: 94562 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 o3N0jQTM012710 for ; Fri, 23 Apr 2010 00:46:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754440Ab0DWApl (ORCPT ); Thu, 22 Apr 2010 20:45:41 -0400 Received: from mail-bw0-f225.google.com ([209.85.218.225]:57982 "EHLO mail-bw0-f225.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754493Ab0DWApk (ORCPT ); Thu, 22 Apr 2010 20:45:40 -0400 Received: by bwz25 with SMTP id 25so10399315bwz.28 for ; Thu, 22 Apr 2010 17:45:38 -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:subject :message-id:x-mailer:mime-version:content-type; bh=cv9a7h0WM+ibEPlFpP9ueoeby+szuUt1mpNeIj/c3VM=; b=Fqa3qQT2nCN6gnqkPefJIlnTdKaSrEpZ5fwpysKXroKy4rkkPNxntxCA2EFI6Rr1fI K22SdbKfX8vftdHphk7dkxaec1e9CSaOq9RyPKE/dQQZIU7j5PHXCqrvngdSVXEUWWA5 XLRqBNIpxN3FkHJJ150nDthEjRxU/oKg41yg8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:x-mailer:mime-version:content-type; b=fo3UU/ucPhp5HfoQg30e7f0QYobtoOFW1XxNMVHCepibQe3sPo20HOUl3unwtbAEAS FGyAvXUFmZjqsCFHFovzvU1T3H6/mJMOs+MkV9nu3LabgunSM1vvkGwhjQq5ZOotBUqb eSn9ipxbgz0AiT90f+glaoYguw7f69tXLOSZ0= Received: by 10.87.45.15 with SMTP id x15mr6123465fgj.42.1271983538362; Thu, 22 Apr 2010 17:45:38 -0700 (PDT) Received: from glory.loctelecom.ru (ns2.openhardware.ru [84.19.183.172]) by mx.google.com with ESMTPS id 21sm971444fks.53.2010.04.22.17.45.36 (version=SSLv3 cipher=RC4-MD5); Thu, 22 Apr 2010 17:45:37 -0700 (PDT) Date: Fri, 23 Apr 2010 10:48:04 +1000 From: Dmitri Belimov To: linux-media@vger.kernel.org, Mauro Carvalho Chehab Subject: [PATCH] tm6000 fix i2c Message-ID: <20100423104804.784fb730@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]); Fri, 23 Apr 2010 00:46:09 +0000 (UTC) diff -r 7c0b887911cf linux/drivers/staging/tm6000/tm6000-i2c.c --- a/linux/drivers/staging/tm6000/tm6000-i2c.c Mon Apr 05 22:56:43 2010 -0400 +++ b/linux/drivers/staging/tm6000/tm6000-i2c.c Fri Apr 23 04:23:03 2010 +1000 @@ -24,6 +24,7 @@ #include #include #include +#include #include "compat.h" #include "tm6000.h" @@ -45,11 +46,39 @@ printk(KERN_DEBUG "%s at %s: " fmt, \ dev->name, __FUNCTION__ , ##args); } while (0) +static void tm6000_i2c_reset(struct tm6000_core *dev) +{ + tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, TM6000_GPIO_CLK, 0); + msleep(15); + tm6000_set_reg(dev, REQ_03_SET_GET_MCU_PIN, TM6000_GPIO_CLK, 1); + msleep(15); +} + 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; + + if (!buf || len < 1 || len > 64) + 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 */ @@ -59,22 +88,30 @@ int rc; u8 b[2]; - if ((dev->caps.has_zl10353) && (dev->demod_addr << 1 == addr) && (reg % 2 == 0)) { + if (!buf || len < 1 || len > 64) + 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 */ reg -= 1; len += 1; - rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, b, len); + rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN, + addr | reg << 8, 0, b, len); *buf = b[1]; } else { - rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len); + rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_16_SET_GET_I2C_WR1_RDN, + addr | reg << 8, 0, buf, len); } + /* release mutex */ return rc; } @@ -85,8 +122,106 @@ 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 */ + 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); + + if (rc < 0) { + /* release mutex */ + return rc; + } + + /* release mutex */ + return rc; +} + +static int tm6000_i2c_read_sequence(struct tm6000_core *dev, unsigned char addr, + __u16 reg, char *buf, int len) +{ + int rc; + + if (!buf || len < 1 || len > 64) + return -1; + + /* capture mutex */ + rc = tm6000_read_write_usb(dev, USB_DIR_IN | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_35_AFTEK_TUNER_READ, + reg, 0, buf, len); + /* release mutex */ + return rc; +} + +static int tm6000_i2c_write_sequence(struct tm6000_core *dev, + unsigned char addr, __u16 reg, char *buf, + int len) +{ + int rc; + unsigned int tsleep; + + if (!buf || len < 1 || len > 64) + 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+1, len-1); + + if (rc < 0) { + /* release mutex */ + return rc; + } + + /* Calculate delay time, 13800us for 64 bytes */ + tsleep = ((len * 200) + 1000) / 1000; + msleep(tsleep); + + /* release mutex */ + return rc; +} + +static int tm6000_i2c_write_uni(struct tm6000_core *dev, unsigned char addr, + __u16 reg, char *buf, int len) +{ + int rc; + unsigned int tsleep; + + if (!buf || len < 1 || len > 64) + return -1; + + /* capture mutex */ + rc = tm6000_read_write_usb(dev, USB_DIR_OUT | USB_TYPE_VENDOR | + USB_RECIP_DEVICE, REQ_30_I2C_WRITE, + addr | reg << 8, 0, buf+1, len-1); + + if (rc < 0) { + /* release mutex */ + return rc; + } + + /* Calculate delay time, 14800us for 64 bytes */ + tsleep = ((len * 200) + 1000 + 1000) / 1000; + msleep(tsleep); + + /* release mutex */ + return rc; } static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, Signed-off-by: Beholder Intl. Ltd. Dmitry Belimov