From patchwork Mon Mar 25 11:46:44 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akshay Saraswat X-Patchwork-Id: 230638 X-Patchwork-Delegate: promsoft@gmail.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 D8D742C00AD for ; Mon, 25 Mar 2013 22:28:09 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D3C6F4A03C; Mon, 25 Mar 2013 12:28:05 +0100 (CET) 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 wrscewdEK2s9; Mon, 25 Mar 2013 12:28:05 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C64134A041; Mon, 25 Mar 2013 12:28:02 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6B5784A041 for ; Mon, 25 Mar 2013 12:28:00 +0100 (CET) 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 Gw66rXoXT8MU for ; Mon, 25 Mar 2013 12:27:59 +0100 (CET) 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 mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by theia.denx.de (Postfix) with ESMTP id 71E734A03C for ; Mon, 25 Mar 2013 12:27:56 +0100 (CET) Received: from epcpsbgr4.samsung.com (u144.gpu120.samsung.co.kr [203.254.230.144]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MK700GXMRT3DF50@mailout4.samsung.com> for u-boot@lists.denx.de; Mon, 25 Mar 2013 20:27:28 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.124]) by epcpsbgr4.samsung.com (EPCPMTA) with SMTP id C0.C5.02019.0A430515; Mon, 25 Mar 2013 20:27:28 +0900 (KST) X-AuditID: cbfee690-b7f656d0000007e3-5d-515034a0abed Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id ED.20.17838.0A430515; Mon, 25 Mar 2013 20:27:28 +0900 (KST) Received: from chrome-ubuntu.sisodomain.com ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MK700LZRRSL2W40@mmp1.samsung.com>; Mon, 25 Mar 2013 20:27:28 +0900 (KST) From: Akshay Saraswat To: u-boot@lists.denx.de Date: Mon, 25 Mar 2013 07:46:44 -0400 Message-id: <1364212004-15964-1-git-send-email-akshay.s@samsung.com> X-Mailer: git-send-email 1.8.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrALMWRmVeSWpSXmKPExsWyRsSkRneBSUCgwe8PMhZTH5xjtPi2ZRuj xdu9newOzB6zGy6yeOycdZfd4+ydHYwBzFFcNimpOZllqUX6dglcGS0ntrMVTJComHJ2I1sD 42qhLkZODgkBE4l/DU3MELaYxIV769m6GLk4hASWMkr0Xl3JClP0+8kORhBbSGARo8TqhzIQ Rb1MEhtOTQErYhPQkdi+5Ds7iC0iICHxq/8qUAMHB7OAhsTjd+ogYWGBAInlF5aDzWERUJXo mb+cDcTmFXCR6G/+xgixS07iw55H7CDzJQSus0l0fpzNBNEgIPFt8iEWkJkSArISmw5AHS0p cXDFDZYJjIILGBlWMYqmFiQXFCelF5noFSfmFpfmpesl5+duYgSG3ul/zybsYLx3w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2HUv4cJZbijERDLeai4kQAk8Jr krACAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Subject: [U-Boot] [PATCH] Exynos5: i2c: Fix read NACK handling and remove some redundancy 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: Gabe Black The exynos s3c24x0 i2c driver wouldn't do the right thing when a NACK was received on a read because it didn't attempt a read before waiting for the read to finish. Putting a call to ReadWriteByte in the NACK path fixed a problem where getting a NACK reading from a device would jam up the bus and prevent future accesses like probing from working. Because other than the ReadWriteByte call the NACK and normal paths were almost the same thing, and to avoid future instances of the NACK path not working because it's not exercised normally, this change also consolidates those two paths. Signed-off-by: Gabe Black Signed-off-by: Akshay Saraswat --- drivers/i2c/s3c24x0_i2c.c | 53 ++++++++++++++++------------------------------- 1 file changed, 18 insertions(+), 35 deletions(-) diff --git a/drivers/i2c/s3c24x0_i2c.c b/drivers/i2c/s3c24x0_i2c.c index d2b4eb0..91298a7 100644 --- a/drivers/i2c/s3c24x0_i2c.c +++ b/drivers/i2c/s3c24x0_i2c.c @@ -366,21 +366,25 @@ static int i2c_transfer(struct s3c24x0_i2c *i2c, break; case I2C_READ: - if (result == I2C_OK) { - writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat); - writel(chip, &i2c->iicds); - /* send START */ - writel(readl(&i2c->iicstat) | I2C_START_STOP, - &i2c->iicstat); - ReadWriteByte(i2c); - result = WaitForXfer(i2c); + { + int was_ok = (result == I2C_OK); + + writel(chip, &i2c->iicds); + /* resend START */ + writel(I2C_MODE_MR | I2C_TXRX_ENA | + I2C_START_STOP, &i2c->iicstat); + ReadWriteByte(i2c); + result = WaitForXfer(i2c); + + if (was_ok || IsACK(i2c)) { i = 0; while ((i < data_len) && (result == I2C_OK)) { /* disable ACK for final READ */ - if (i == data_len - 1) - writel(readl(&i2c->iiccon) - & ~I2CCON_ACKGEN, - &i2c->iiccon); + if (i == data_len - 1) { + writel(readl(&i2c->iiccon) & + ~I2CCON_ACKGEN, + &i2c->iiccon); + } ReadWriteByte(i2c); result = WaitForXfer(i2c); data[i] = readl(&i2c->iicds); @@ -388,35 +392,14 @@ static int i2c_transfer(struct s3c24x0_i2c *i2c, } } else { - writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat); - writel(chip, &i2c->iicds); - /* send START */ - writel(readl(&i2c->iicstat) | I2C_START_STOP, - &i2c->iicstat); - result = WaitForXfer(i2c); - - if (IsACK(i2c)) { - i = 0; - while ((i < data_len) && (result == I2C_OK)) { - /* disable ACK for final READ */ - if (i == data_len - 1) - writel(readl(&i2c->iiccon) & - ~I2CCON_ACKGEN, - &i2c->iiccon); - ReadWriteByte(i2c); - result = WaitForXfer(i2c); - data[i] = readl(&i2c->iicds); - i++; - } - } else { - result = I2C_NACK; - } + result = I2C_NACK; } /* send STOP */ writel(I2C_MODE_MR | I2C_TXRX_ENA, &i2c->iicstat); ReadWriteByte(i2c); break; + } default: debug("i2c_transfer: bad call\n");