From patchwork Tue Apr 30 12:54:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Eibach X-Patchwork-Id: 240609 X-Patchwork-Delegate: afleming@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id CD92A2C009F for ; Tue, 30 Apr 2013 22:56:47 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6B1674A28B; Tue, 30 Apr 2013 14:56:13 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id p7LRyJi-dHxm; Tue, 30 Apr 2013 14:56:13 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 266C14A28C; Tue, 30 Apr 2013 14:55:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0AFC34A280 for ; Tue, 30 Apr 2013 14:55:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zK5nwPhGk0Rd for ; Tue, 30 Apr 2013 14:55:27 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from smtprelay04.ispgateway.de (smtprelay04.ispgateway.de [80.67.29.8]) by theia.denx.de (Postfix) with ESMTP id 364834A26B for ; Tue, 30 Apr 2013 14:55:15 +0200 (CEST) Received: from [217.6.197.18] (helo=bob3.gd.local) by smtprelay04.ispgateway.de with esmtpa (Exim 4.68) (envelope-from ) id 1UXA5R-0006bL-MP; Tue, 30 Apr 2013 14:55:13 +0200 From: dirk.eibach@gdsys.cc To: u-boot@lists.denx.de Date: Tue, 30 Apr 2013 14:54:53 +0200 Message-Id: <1367326496-12734-5-git-send-email-dirk.eibach@gdsys.cc> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1367326496-12734-1-git-send-email-dirk.eibach@gdsys.cc> References: <1367326496-12734-1-git-send-email-dirk.eibach@gdsys.cc> X-Df-Sender: ZGlyay5laWJhY2hAZ2RzeXMuY2M= Cc: Reinhard Pfau , Tabi Timur , Jim Chargin , trini@ti.com, Heiko Schocher Subject: [U-Boot] [PATCH v5 4/7] i2c: fsl_i2c: i2c_read(): dont try to write address w/ alen=0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Reinhard Pfau if alen is 0: no longer start a write cycle before reading data. Signed-off-by: Dirk Eibach Signed-off-by: Reinhard Pfau --- Changes in v5: - fix i2c_probe Changes in v4: None Changes in v3: None Changes in v2: - whitespace fixes drivers/i2c/fsl_i2c.c | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/fsl_i2c.c b/drivers/i2c/fsl_i2c.c index 1c7265d..5d7e010 100644 --- a/drivers/i2c/fsl_i2c.c +++ b/drivers/i2c/fsl_i2c.c @@ -383,13 +383,16 @@ i2c_read(u8 dev, uint addr, int alen, u8 *data, int length) int i = -1; /* signal error */ u8 *a = (u8*)&addr; - if (i2c_wait4bus() >= 0 + if (i2c_wait4bus() < 0) + return -1; + + if ((!length || alen > 0) && i2c_write_addr(dev, I2C_WRITE_BIT, 0) != 0 && __i2c_write(&a[4 - alen], alen) == alen) i = 0; /* No error so far */ - if (length - && i2c_write_addr(dev, I2C_READ_BIT, 1) != 0) + if (length && + i2c_write_addr(dev, I2C_READ_BIT, alen ? 1 : 0) != 0) i = __i2c_read(data, length); writeb(I2C_CR_MEN, &i2c_dev[i2c_bus_num]->cr);