From patchwork Fri Sep 14 05:08:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuyuki Kobayashi X-Patchwork-Id: 183799 X-Patchwork-Delegate: hs@denx.de 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 6312B2C0088 for ; Fri, 14 Sep 2012 15:11:39 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 12AFD28144; Fri, 14 Sep 2012 07:11:38 +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 zRCdj05z7WuK; Fri, 14 Sep 2012 07:11:37 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EFD1928146; Fri, 14 Sep 2012 07:11:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 74BFF28146 for ; Fri, 14 Sep 2012 07:11:30 +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 y98h1ac7BV8m for ; Fri, 14 Sep 2012 07:11:26 +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 vrgw9.firstserver.ne.jp (vrgw9.firstserver.ne.jp [164.46.1.107]) by theia.denx.de (Postfix) with ESMTPS id D4E3828144 for ; Fri, 14 Sep 2012 07:11:24 +0200 (CEST) Received: from fvrsp25.firstserver.ne.jp (fvrsp25.firstserver.ne.jp [203.183.16.3]) by vrgw9.firstserver.ne.jp (8.13.8/8.13.8/FirstServer) with ESMTP id q8E5B0ZJ003776; Fri, 14 Sep 2012 14:11:00 +0900 (envelope-from koba@kmckk.co.jp) Received: from 203.137.25.97 (203.137.25.97) by fvrsp25.firstserver.ne.jp (F-Secure/virusgw_smtp/407/fvrsp25.firstserver.ne.jp); Fri, 14 Sep 2012 14:11:00 +0900 (JST) X-Virus-Status: clean(F-Secure/virusgw_smtp/407/fvrsp25.firstserver.ne.jp) Received: from localhost (58-188-103-12f2.kns1.eonet.ne.jp [58.188.103.12]) (authenticated (0 bits)) by mail.kmckk.co.jp (8.14.3/8.11.3) with ESMTP id q8E5B03V022068; Fri, 14 Sep 2012 14:11:00 +0900 From: Tetsuyuki Kobayashi To: nobuhiro.iwamatsu.yj@renesas.com Date: Fri, 14 Sep 2012 14:08:00 +0900 Message-Id: <1347599285-11830-6-git-send-email-koba@kmckk.co.jp> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1347599285-11830-1-git-send-email-koba@kmckk.co.jp> References: <1347439573-19443-1-git-send-email-koba@kmckk.co.jp> <1347599285-11830-1-git-send-email-koba@kmckk.co.jp> Cc: hs@denx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 05/10] i2c: sh_i2c: enable i2c_probe 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 Before this patch i2c_probe() always returned 0 and "i2c probe" command did not work properly. Modify i2c_set_addr() to check TACK when waiting DTE and make i2c_probe() call this function. Acked-by: Nobuhiro Iwamatsu Signed-off-by: Tetsuyuki Kobayashi --- Changes for v2: - new Changes for v3: - call i2c_finish before returning i2c_probe. drivers/i2c/sh_i2c.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/i2c/sh_i2c.c b/drivers/i2c/sh_i2c.c index d524619..1f5104c 100644 --- a/drivers/i2c/sh_i2c.c +++ b/drivers/i2c/sh_i2c.c @@ -85,6 +85,20 @@ static void irq_dte(struct sh_i2c *base) } } +static int irq_dte_with_tack(struct sh_i2c *base) +{ + int i; + + for (i = 0 ; i < IRQ_WAIT ; i++) { + if (SH_IC_DTE & readb(&base->icsr)) + break; + if (SH_IC_TACK & readb(&base->icsr)) + return -1; + udelay(10); + } + return 0; +} + static void irq_busy(struct sh_i2c *base) { int i; @@ -96,9 +110,9 @@ static void irq_busy(struct sh_i2c *base) } } -static void i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop) +static int i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop) { - u8 icic = 0; + u8 icic = SH_IC_TACK; writeb(readb(&base->iccr) & ~SH_I2C_ICCR_ICE, &base->iccr); writeb(readb(&base->iccr) | SH_I2C_ICCR_ICE, &base->iccr); @@ -116,14 +130,18 @@ static void i2c_set_addr(struct sh_i2c *base, u8 id, u8 reg, int stop) writeb((SH_I2C_ICCR_ICE|SH_I2C_ICCR_RTS|SH_I2C_ICCR_BUSY), &base->iccr); irq_dte(base); + writeb(readb(&base->icsr) & ~SH_IC_TACK, &base->icsr); writeb(id << 1, &base->icdr); - irq_dte(base); + if (irq_dte_with_tack(base) != 0) + return -1; writeb(reg, &base->icdr); if (stop) writeb((SH_I2C_ICCR_ICE|SH_I2C_ICCR_RTS), &base->iccr); - irq_dte(base); + if (irq_dte_with_tack(base) != 0) + return -1; + return 0; } static void i2c_finish(struct sh_i2c *base) @@ -321,5 +339,9 @@ int i2c_write(u8 chip, u32 addr, int alen, u8 *buffer, int len) */ int i2c_probe(u8 chip) { - return 0; + int ret; + + ret = i2c_set_addr(base, chip, 0, 1); + i2c_finish(base); + return ret; }