From patchwork Sun Feb 21 20:10:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Ringel X-Patchwork-Id: 81060 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 o1LKBnSi007454 for ; Sun, 21 Feb 2010 20:11:49 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751929Ab0BUULs (ORCPT ); Sun, 21 Feb 2010 15:11:48 -0500 Received: from mail-in-17.arcor-online.net ([151.189.21.57]:53858 "EHLO mail-in-17.arcor-online.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751547Ab0BUULr (ORCPT ); Sun, 21 Feb 2010 15:11:47 -0500 Received: from mail-in-05-z2.arcor-online.net (mail-in-05-z2.arcor-online.net [151.189.8.17]) by mx.arcor.de (Postfix) with ESMTP id EDED03B2440; Sun, 21 Feb 2010 21:11:45 +0100 (CET) Received: from mail-in-16.arcor-online.net (mail-in-16.arcor-online.net [151.189.21.56]) by mail-in-05-z2.arcor-online.net (Postfix) with ESMTP id D1FA52DB225; Sun, 21 Feb 2010 21:11:45 +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-16.arcor-online.net (Postfix) with ESMTPA id 40905256D7B; Sun, 21 Feb 2010 21:11:45 +0100 (CET) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-16.arcor-online.net 40905256D7B DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arcor.de; s=mail-in; t=1266783105; bh=1idPXUNwlPkVA80c4zlv6CdjNLFAfIX8urvAfoYowJI=; h=From:To:Cc:Subject:Date:Message-Id; b=WjWl0VtTA0VYa9gRxX58on94DIrJkYadcp308+A9jZ819/qrELzjfY1Ed2hVMtq+7 Nf7a6HK54L4vEy+wHTVh0eY1h7ZY8hF4us/CYiiTvI59soJ4wyZv6nIs5bkIaCZ47y eVb7XJJGprzfbqfjACDGO9kaFMQDnKTa389Ayyc4= From: stefan.ringel@arcor.de To: linux-media@vger.kernel.org Cc: mchehab@redhat.com, dheitmueller@kernellabs.com, Stefan Ringel Subject: [PATCH 1/3] tm6000: add send and recv function Date: Sun, 21 Feb 2010 21:10:34 +0100 Message-Id: <1266783036-6549-1-git-send-email-stefan.ringel@arcor.de> X-Mailer: git-send-email 1.6.6.1 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]); Sun, 21 Feb 2010 20:11:50 +0000 (UTC) diff --git a/drivers/staging/tm6000/tm6000-i2c.c b/drivers/staging/tm6000/tm6000-i2c.c index 656cd19..b563129 100644 --- a/drivers/staging/tm6000/tm6000-i2c.c +++ b/drivers/staging/tm6000/tm6000-i2c.c @@ -44,6 +44,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_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); +} + +/* read from a 8bit register */ +int tm6000_i2c_recv_regs(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_VENDOR_TYPE | USB_RECIP_DEVICE, + REQ_16_SET_GET_I2C_WR1_RDN, addr | reg << 8, 0, buf, len); + + return rc; +} + +/* read from a 16bit register + * for example xc2028, xc3028 or xc3028L + */ +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_VENDOR_TYPE | USB_RECIP_DEVICE, + REQ_14_SET_GET_I2C_WR2_RDN, addr, reg, buf, len); +} + static int tm6000_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) { @@ -78,13 +104,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], + if (msgs{i].len == 1) { + rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0], msgs[i + 1].buf, msgs[i + 1].len); + } else { + rc = tm6000_i2c_recv_regs(dev, addr, msgs[i].buf[0] << 8 | msgs[i].buf[1], + msgs[i + 1].buf, msgs[i + 1].len); + } + i++; if (addr == dev->tuner_addr) { @@ -99,10 +126,7 @@ 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_regs(dev, addr, msgs[i].buf[0], msgs[i].buf + 1, msgs[i].len - 1); if (addr == dev->tuner_addr) { @@ -134,9 +158,7 @@ static int tm6000_i2c_eeprom(struct tm6000_core *dev, bytes[16] = '\0'; for (i = 0; i < len; ) { *p = i; - rc = tm6000_read_write_usb (dev, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - REQ_16_SET_GET_I2C_WR1_RDN, 0xa0 | i<<8, 0, p, 1); + rc = tm6000_i2c_revc_regs(dev, 0xa0, i, p, 1); if (rc < 1) { if (p == eedata) goto noeeprom;