From patchwork Wed Jun 26 13:55:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dirk Eibach X-Patchwork-Id: 254749 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 B7BF02C0091 for ; Wed, 26 Jun 2013 23:56:39 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ECE6E4A039; Wed, 26 Jun 2013 15:56:10 +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 GEt6glawL81E; Wed, 26 Jun 2013 15:56:10 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F04054A03A; Wed, 26 Jun 2013 15:55:46 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 843844A02A for ; Wed, 26 Jun 2013 15:55:42 +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 Dghze6iRsdUY for ; Wed, 26 Jun 2013 15:55:37 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 BL_NJABL=ERR(-1.5) (only DNSBL check requested) Received: from smtprelay03.ispgateway.de (smtprelay03.ispgateway.de [80.67.31.30]) by theia.denx.de (Postfix) with ESMTP id 1E52A4A02F for ; Wed, 26 Jun 2013 15:55:29 +0200 (CEST) Received: from [217.6.197.18] (helo=bob3.gd.local) by smtprelay03.ispgateway.de with esmtpa (Exim 4.68) (envelope-from ) id 1UrqBy-0008Sq-2H; Wed, 26 Jun 2013 15:55:26 +0200 From: dirk.eibach@gdsys.cc To: u-boot@lists.denx.de Date: Wed, 26 Jun 2013 15:55:14 +0200 Message-Id: <1372254917-8027-3-git-send-email-dirk.eibach@gdsys.cc> X-Mailer: git-send-email 1.8.3 In-Reply-To: <1372254917-8027-1-git-send-email-dirk.eibach@gdsys.cc> References: <1372254917-8027-1-git-send-email-dirk.eibach@gdsys.cc> X-Df-Sender: ZGlyay5laWJhY2hAZ2RzeXMuY2M= Cc: Reinhard Pfau , Tabi Timur , Jim Chargin , Andy Fleming , trini@ti.com, Heiko Schocher Subject: [U-Boot] [PATCH v7 2/5] 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 Acked-by: Heiko Schocher --- Changes in v7: None Changes in v6: None 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 file 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);