From patchwork Thu Dec 6 03:55:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 152982 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp10074212ljp; Wed, 5 Dec 2018 19:56:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/UtXY1U7AdnQbRMqta6d7Gcj1831Wj6UyMotZvn/+3LPTzw0EETVAcJUmvhQ+HGlG+f7wAN X-Received: by 2002:a63:5207:: with SMTP id g7mr23070753pgb.253.1544068614084; Wed, 05 Dec 2018 19:56:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544068614; cv=none; d=google.com; s=arc-20160816; b=L6PsLqMVp/iZOVhw3j3eF8WYnOqNVA2bkhUv7ZakMegAXercd0l4zKEcsoSE9skyVj iLkwhdqQIdENIS2ho5cfTZbmRwEaDTFHRxJhl61qLGoD1GVdfN64wVIDEtguyKXjRdrh G7EK5gTsEPVSLoZdy/osN00u5Oy/gT2ZD5h4pVGPFSo3KMPKXCkztCuz1IybQbwS90Qw 9RL/UBYSZ8rvvufxUMfM96e46khlS/w+kPPX43NkWzOz1Ocv+SeOisDTL7ZsihHAX66r oFNvC5cR3i/m2vLzmFmH90Ngy2FKn8b5xJaZZSdToyQtPAGq/vTXOD6kXRzH7NCFR18k rjDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=2y2cw2qzebvkA+Mtv/XDf/lXFAsgLnN70QsGjRHK68c=; b=CIqNNjZFprcybXlZ15vc9vgQrCyUqMY7lzKbJBFhM0q5m9mrUwr+yKvr0nfmV0EBSR fyQ6zBUONjg7GljOQAxt9ieOk+xVcd0xmatydvCmcYPDssqt6PAv5IVbIAD4y16ySyYE fdOuZmbAe5u6005clgUXchlAKmo7DUIEAq3v43983Rf9ZBLymLCobHMQS8mSwytDJbP+ Efa/jsH2ymvvmQVhNP7eCSDqSKQ7PNFLmMpSxMoJwJa2etLssA7sNoXnMX5CyCNIVyfr Ov2gjycj1WwAMDjxdZmTbHBX7Oak0G3T+ejfLVNoz4vCQMmP2B7jI0FRZfXfmQWLAYqh ZSxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=kPHi2dOE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66si21497796pfb.231.2018.12.05.19.56.53; Wed, 05 Dec 2018 19:56:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=kPHi2dOE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729103AbeLFD4w (ORCPT + 31 others); Wed, 5 Dec 2018 22:56:52 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:59213 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729058AbeLFD4u (ORCPT ); Wed, 5 Dec 2018 22:56:50 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id wB63trS6007398; Thu, 6 Dec 2018 12:55:54 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com wB63trS6007398 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1544068555; bh=2y2cw2qzebvkA+Mtv/XDf/lXFAsgLnN70QsGjRHK68c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kPHi2dOEi3qWH6h8XKwY274U9vnp6zKg7l3nNiKvf+kib3GV6+hakUNhgUnJJv/NF QHc/hlsIotcEtGB5VC2dt/W9jOMZqqbgx8hd5vZ3ylxiudEBtz8JnBgUwak7qri5rt Zpt+7C4FpNFZjl8l8IW8KZNAfoQ1ZMIV8KPl+Aiiilu2M+0j9fYu5OskyJ4UINipp7 kdkbPwV862Vny5wy2cJZ1alQv9PL7LDEz2AIMbYuPxYGX7ZvElrn9bsnDorMCu/2CW oWeUxwZPvHto49Ojo8gn5cZ4aIXQT+MsT1D4wDwCF9w4GI/LiHEO9CTKWOrP9c6CJ/ 1zoDG2ayu67Zw== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-i2c@vger.kernel.org Cc: Masahiro Yamada , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] i2c: uniphier-f: fix timeout error after reading 8 bytes Date: Thu, 6 Dec 2018 12:55:25 +0900 Message-Id: <1544068528-27657-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> References: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I was totally screwed up in commit eaba68785c2d ("i2c: uniphier-f: fix race condition when IRQ is cleared"). Since that commit, if the number of read bytes is multiple of the FIFO size (8, 16, 24... bytes), the STOP condition could be issued twice, depending on the timing. If this happens, the controller will go wrong, resulting in the timeout error. It was more than 3 years ago when I wrote this driver, so my memory about this hardware was vague. Please let me correct the description in the commit log of eaba68785c2d. Clearing the IRQ status on exiting the IRQ handler is absolutely fine. This controller makes a pause while any IRQ status is asserted. If the IRQ status is cleared first, the hardware may start the next transaction before the IRQ handler finishes what it supposed to do. This partially reverts the bad commit with clear comments so that I will never repeat this mistake. I also investigated what is happening at the last moment of the read mode. The UNIPHIER_FI2C_INT_RF interrupt is asserted a bit earlier (by half a period of the clock cycle) than UNIPHIER_FI2C_INT_RB. I consulted a hardware engineer, and I got the following information: UNIPHIER_FI2C_INT_RF asserted at the falling edge of SCL at the 8th bit. UNIPHIER_FI2C_INT_RB asserted at the rising edge of SCL at the 9th (ACK) bit. In order to avoid calling uniphier_fi2c_stop() twice, check the latter interrupt. I also commented this because it is obscure hardware internal. Fixes: eaba68785c2d ("i2c: uniphier-f: fix race condition when IRQ is cleared") Signed-off-by: Masahiro Yamada --- drivers/i2c/busses/i2c-uniphier-f.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index dd38474..fad2b00 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -173,8 +173,6 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) "interrupt: enabled_irqs=%04x, irq_status=%04x\n", priv->enabled_irqs, irq_status); - uniphier_fi2c_clear_irqs(priv, irq_status); - if (irq_status & UNIPHIER_FI2C_INT_STOP) goto complete; @@ -214,7 +212,13 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) if (irq_status & (UNIPHIER_FI2C_INT_RF | UNIPHIER_FI2C_INT_RB)) { uniphier_fi2c_drain_rxfifo(priv); - if (!priv->len) + /* + * If the number of bytes to read is multiple of the FIFO size + * (msg->len == 8, 16, 24, ...), the INT_RF bit is set a little + * earlier than INT_RB. We wait for INT_RB to confirm the + * completion of the current message. + */ + if (!priv->len && (irq_status & UNIPHIER_FI2C_INT_RB)) goto data_done; if (unlikely(priv->flags & UNIPHIER_FI2C_MANUAL_NACK)) { @@ -253,6 +257,13 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) } handled: + /* + * This controller makes a pause while any bit of the IRQ status is + * asserted. Clear the asserted bit to kick the controller just before + * exiting the handler. + */ + uniphier_fi2c_clear_irqs(priv, irq_status); + spin_unlock(&priv->lock); return IRQ_HANDLED; From patchwork Thu Dec 6 03:55:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 152983 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp10074247ljp; Wed, 5 Dec 2018 19:56:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/U48lpubRi1NV7QhPtWjf3hNJ6MV5tm4Xs3YcvF6lI8FUH2wolFoHX0vg7lSCbS6Z1e1Woj X-Received: by 2002:a63:1f1c:: with SMTP id f28mr22848793pgf.193.1544068617197; Wed, 05 Dec 2018 19:56:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544068617; cv=none; d=google.com; s=arc-20160816; b=K8g6wriu3kO34hr1KOCoemjrnz38+A4FZvNLicJM/PKCO3FWkcwIYo7SxDqCy4eJ1T 9WJYGoAKuyM+Ou6slnCrd7CY6ifKNOqaY1CVj8vu4boKeLslxQsT78pk0ph12tq240rz yz3fGoSM8M6/vJOB9bjAXmrezuG75kgdPMkqxkBnnRqpRcCrMdpLvIHg2Su9J26/rx0J PNv2DB8HX2L0Rr+sDWzZ9pa+WlugycI4XbCj+S6WwTURj48kBszuF+jg8GX9puOlyEwE Mb1IPbJCqYLAkGpdd3Ap+s06x4pPeZTV/Ay6kVvln8xQoYadBW+S4o2d/qPEvbY5/Cz2 ushg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=i2ojI7R92ngd4Xq06C6mSR5SZWE8QuYiZ8bI+8Q1qyI=; b=TSFc9Lr9CPglbDYYF1W8HbhrJCo6+dUqjb53c3sY6Amlm5eQpM1N0lgqgV3vp2xOEM u4MlIT262nWMuvgHwe5HwqftW2TwHQJfNzvvSqjP71Zedxg4zT/znHAA9jUh8YFPSXch s/9whoWWuefkfYEnc+HTDj3EJ/ks0KXm8nDTYkExLLFDnzKUVE9UkXoS20jWlcXo5UBO ci2ykbgwrJXzAVEESI7qRxNcfVgIqwFmGdS/Kpv3BVarWkdmBfs0fNjPiWv+Cxzy9w4A paf18MXfneBYten5Vxo88Q6kkCGzvojEPec/Z90Kqe2Zwm5/EKHVPpxBfh1QlaMSLZ3b it2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=lw3qleMF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q66si21497796pfb.231.2018.12.05.19.56.56; Wed, 05 Dec 2018 19:56:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=lw3qleMF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729080AbeLFD4v (ORCPT + 31 others); Wed, 5 Dec 2018 22:56:51 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:59210 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729057AbeLFD4s (ORCPT ); Wed, 5 Dec 2018 22:56:48 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id wB63trS7007398; Thu, 6 Dec 2018 12:55:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com wB63trS7007398 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1544068555; bh=i2ojI7R92ngd4Xq06C6mSR5SZWE8QuYiZ8bI+8Q1qyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lw3qleMFLx7MX5hI2QHV+N1op9V3rzX2NxKj4ltz9br1n2EUdhJgOO8Yy6UW3yGC6 40hSFYWCpcX+5XzSj4zpC9S1lSqy2tpPL+yx+5+YfpARAVQn/DmH8bAKL99Fekh1g/ eRsyOBwGoeREpuLOF1KfwqmezRX7VYC9lPVrLobqkEdJbkvaIED8WKo0yw4WkD9MST HcggJZHWRxMtXgutDem94exOe41dzM3hmorTTUeQx8Of5tOMB1G70fSBB/KitdNQAj HEtQ8boE90NnN9IBzcXYSCW+Cbgxn90D06lZqVC6tDaBs8l69PTBmE1YMcbPH76eRX kaQh/KGg0/wqg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-i2c@vger.kernel.org Cc: Masahiro Yamada , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] i2c: uniphier-f: fill TX-FIFO only in IRQ handler for repeated START Date: Thu, 6 Dec 2018 12:55:26 +0900 Message-Id: <1544068528-27657-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> References: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - For a repeated START condition, this controller starts data transfer immediately after the slave address is written to the TX-FIFO. - Once the TX-FIFO empty interrupt is asserted, the controller makes a pause even if additional data are written to the TX-FIFO. Given those circumstances, the data after a repeated START may not be transferred if the interrupt is asserted while the TX-FIFO is being filled up. A more reliable way is to append TX data only in the interrupt handler. Signed-off-by: Masahiro Yamada --- drivers/i2c/busses/i2c-uniphier-f.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index fad2b00..d8a5db14 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -269,7 +269,8 @@ static irqreturn_t uniphier_fi2c_interrupt(int irq, void *dev_id) return IRQ_HANDLED; } -static void uniphier_fi2c_tx_init(struct uniphier_fi2c_priv *priv, u16 addr) +static void uniphier_fi2c_tx_init(struct uniphier_fi2c_priv *priv, u16 addr, + bool repeat) { priv->enabled_irqs |= UNIPHIER_FI2C_INT_TE; uniphier_fi2c_set_irqs(priv); @@ -279,8 +280,12 @@ static void uniphier_fi2c_tx_init(struct uniphier_fi2c_priv *priv, u16 addr) /* set slave address */ writel(UNIPHIER_FI2C_DTTX_CMD | addr << 1, priv->membase + UNIPHIER_FI2C_DTTX); - /* first chunk of data */ - uniphier_fi2c_fill_txfifo(priv, true); + /* + * First chunk of data. For a repeated START condition, do not write + * data to the TX fifo here to avoid the timing issue. + */ + if (!repeat) + uniphier_fi2c_fill_txfifo(priv, true); } static void uniphier_fi2c_rx_init(struct uniphier_fi2c_priv *priv, u16 addr) @@ -361,7 +366,7 @@ static int uniphier_fi2c_master_xfer_one(struct i2c_adapter *adap, if (is_read) uniphier_fi2c_rx_init(priv, msg->addr); else - uniphier_fi2c_tx_init(priv, msg->addr); + uniphier_fi2c_tx_init(priv, msg->addr, repeat); dev_dbg(&adap->dev, "start condition\n"); /* From patchwork Thu Dec 6 03:55:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 152979 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp10074089ljp; Wed, 5 Dec 2018 19:56:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/UWjM2sczQ6+hXk6OsOB1ZFPhPbdK0IHP3Sdmi9jrvcHepF1ziopAJGg8RV78Ipe3+xVjF/ X-Received: by 2002:a63:b649:: with SMTP id v9mr22877549pgt.436.1544068599811; Wed, 05 Dec 2018 19:56:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544068599; cv=none; d=google.com; s=arc-20160816; b=ivKyuI0bX3MEpJXlJ3LVufpMs4DcupAPQlmTss3GTodj2Kgb+vYHCSahFz1rm1kgkJ sVFS9nU2WRF72f0oZN56UfpvRH1TVCtFeLGhTg/cC7hZQVYsfnsfqMiB9icmpOiej9e6 kEt56w8Fq378feQQqeMLgBjivzb00pP6Z/0h2qJHAJQyEv/l6nRRQ0ngsfWThMrMTEEZ alAZsUy3kJQYh8MTfE2m3T1CDYCEzmWZyosSJWeJF6bDmxDyRVyWBnpmISj/9G/9A9Mu C7QwB1s7VslW8mpovZSStaXzxo+/CF1rokld/kM7OcUkXMe1GAVDqZ6aDFQUtVoNjf2V cb4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=i2DTwxcgMHeHYcJ2f2azxuoZs+0qhk4Q7YQ7oWQJxew=; b=D+Rb2wWOlJEID5mX2F5VCsHicfn4YwqubAoGd9FTPlFN3om0nCdeUsL9ek3mH1N3VT Ex7m6urcY+cHInADGk5BDw/okUOj4OG7MZQsFwNclXfJ2J3QcQa3YTyPcL/8JYPiiEvz 9lzVQCnZXn0kM4jjNDwDaxLxSAGD1XOv8DxzOmYUE7cwYMIEbuUaRa9u5m+NZ8gyxXAy ngPBh7VjfuV821e1+WDp4WNdPaCo0xZ2eK/wWmHOV9NfFZb4bBP+VQR0rCeHonzCWakV twikJzuNDMy8o+Dt4gb6RTG9F40qe72w4zuBoLMXIPXOK79LTU/o14jyIFKfZ03CNrR+ uC4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="N5WC2H/1"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a17si21426051pfn.213.2018.12.05.19.56.39; Wed, 05 Dec 2018 19:56:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="N5WC2H/1"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729003AbeLFD4g (ORCPT + 31 others); Wed, 5 Dec 2018 22:56:36 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:58840 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727940AbeLFD4g (ORCPT ); Wed, 5 Dec 2018 22:56:36 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id wB63trS8007398; Thu, 6 Dec 2018 12:55:55 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com wB63trS8007398 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1544068556; bh=i2DTwxcgMHeHYcJ2f2azxuoZs+0qhk4Q7YQ7oWQJxew=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N5WC2H/19yIcfPFEM11mY3qrS+Dnr9VtgGLKAPEEzKvosZOQB6FhhFkTUJ+ME17cq qVTZX3NojjlORMZn4SUYlKzCLSyiT+jOJSjEEbeq2m6jv9ipvDARy7mgPgfaBUvp0e RzYLffsbwNhdGywqJFTlJC3BKLEsFHI5/Zj37Oslp7noqh+S8yMRWAVJQSq50+Zfyi uXP0DA3VZTRrxrJLxJ9MclnSUZIUqUT6wWt5SkTF3SzsQC8af322i9bmWcUqbhn73Y BcewCncPKUhKKsp8htfrvPQ9dit9hmtx9vwyyGqNCJ0qJKUfUKVbOBmNU/0iWdE2IS mWgghyI6yiowg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-i2c@vger.kernel.org Cc: Masahiro Yamada , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] i2c: uniphier: fix violation of tLOW requirement for Fast-mode Date: Thu, 6 Dec 2018 12:55:27 +0900 Message-Id: <1544068528-27657-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> References: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the clock duty is set as tLOW/tHIGH = 1/1. For Fast-mode, tLOW is set to 1.25 us while the I2C spec requires tLOW >= 1.3 us. tLOW/tHIGH = 5/4 would meet both Standard-mode and Fast-mode: Standard-mode: tLOW = 5.56 us, tHIGH = 4.44 us Fast-mode: tLOW = 1.39 us, tHIGH = 1.11 us Signed-off-by: Masahiro Yamada --- drivers/i2c/busses/i2c-uniphier.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-uniphier.c b/drivers/i2c/busses/i2c-uniphier.c index 454f914..c488e55 100644 --- a/drivers/i2c/busses/i2c-uniphier.c +++ b/drivers/i2c/busses/i2c-uniphier.c @@ -320,7 +320,13 @@ static void uniphier_i2c_hw_init(struct uniphier_i2c_priv *priv) uniphier_i2c_reset(priv, true); - writel((cyc / 2 << 16) | cyc, priv->membase + UNIPHIER_I2C_CLK); + /* + * Bit30-16: clock cycles of tLOW. + * Standard-mode: tLOW = 4.7 us, tHIGH = 4.0 us + * Fast-mode: tLOW = 1.3 us, tHIGH = 0.6 us + * "tLow/tHIGH = 5/4" meets both. + */ + writel((cyc * 5 / 9 << 16) | cyc, priv->membase + UNIPHIER_I2C_CLK); uniphier_i2c_reset(priv, false); } From patchwork Thu Dec 6 03:55:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 152981 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp10074170ljp; Wed, 5 Dec 2018 19:56:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xg5H9o+6IwrOqB5Rf5aXL58uMnkZ18T+IldkaNtgkNFs2YAREpuX87eC93apRv71/amKHd X-Received: by 2002:a65:434d:: with SMTP id k13mr22879902pgq.269.1544068610034; Wed, 05 Dec 2018 19:56:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544068610; cv=none; d=google.com; s=arc-20160816; b=Nq/GLgTnuyYF21/rvN20QYrR0iIZq598ZBz6u4Owo1fDMXFcAzfzCQrrdWWaLzFRBb yBFQfl0CXaPzxXP4s3MLjem59f7b9Plu8SIqm/5vUt9OiK/frx1ZZ28qLydNzyVZ6X9R WkFMY+M4B8DHPRjufUZEuHqUYRwG8DrbFQLA6mPGqYEdwylg30OumZZsU3nlRLb5A9fn bi1wQyd8KiTWnJ7oojxbuRF1TsVjzlFH9QjFV68N8XPS6aIO36vbqKLQZ0eIPef/tNrU Zob11/s8UdMTs4rc2m+qmz1v8Otuk2IWojahrL/PMFy14Gz46sXpniRZEooNuSPy3htk iMdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=vq9iTJECSWUXoTz65/XclZ3Mf1gaCLqGMYaa34hNQzo=; b=wIDavSeruyXHS0ZFR00dL7I+bt9OpATiwvkMX1Cjy2MvO+J6WBi9BTcFo8k2SaTxNL fq0X8xCgliPEAkhE8/mX0t91jPNL2/KlzYsfTqZ0ZD6I5gDEXz/6K7XTItTgrZFYhmfn knrIFM4UDHEWXFhMrkT3yB0eWVAa/ZuCI4CDCldd7X9zNA9CueKPM15yVGfbYS8InBiF n+HN4C8XkSa8rqKUbo4ZPEjNeIQ2ZskFPvCPdB0/PmooXj4E64x0S1lXpD4cCjwpc49b N3jTwkhh/aS6kUzDDNp87zD6ml4kaWJ+ib2uxINkvQow6un2snADhq07TGEvjjbC+yaT 6o2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=k1ewxlKK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g7si21396429plt.212.2018.12.05.19.56.49; Wed, 05 Dec 2018 19:56:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=k1ewxlKK; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729056AbeLFD4r (ORCPT + 31 others); Wed, 5 Dec 2018 22:56:47 -0500 Received: from conuserg-09.nifty.com ([210.131.2.76]:59102 "EHLO conuserg-09.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727940AbeLFD4p (ORCPT ); Wed, 5 Dec 2018 22:56:45 -0500 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id wB63trS9007398; Thu, 6 Dec 2018 12:55:56 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com wB63trS9007398 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1544068556; bh=vq9iTJECSWUXoTz65/XclZ3Mf1gaCLqGMYaa34hNQzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k1ewxlKKR/XsG0V3d2Akt8g4TCv+aHm8a3OUtlC8uoyfqlPwXE86mMbvpBNYHAlGk BFw+pLk33zxTefChgiYmvRz76SlVxWnBLj35a8HUEWMpcUJvqzCTkbzMoN2pUZkxVO Aqgk9SixT51vdYPldt7PYFF3ed0DzNmduOj+Q644GKI6qusqPACK6k1PxU+L4pmCMi qJHrijhwNA+bowo36nqA7rR6QrV4MySgNH/FvcX0nvGW4lGgfRtR/KRfMYth4XZPhf VIM1lNbkIJWyYvU3QofXTnynRpj/7Xjn0nbU2rsVxvBhaxfCe/4mWpILRNuQCp570B x4fQeA+ztAolA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-i2c@vger.kernel.org Cc: Masahiro Yamada , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] i2c: uniphier-f: fix violation of tLOW requirement for Fast-mode Date: Thu, 6 Dec 2018 12:55:28 +0900 Message-Id: <1544068528-27657-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> References: <1544068528-27657-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the clock duty is set as tLOW/tHIGH = 1/1. For Fast-mode, tLOW is set to 1.25 us while the I2C spec requires tLOW >= 1.3 us. tLOW/tHIGH = 5/4 would meet both Standard-mode and Fast-mode: Standard-mode: tLOW = 5.56 us, tHIGH = 4.44 us Fast-mode: tLOW = 1.39 us, tHIGH = 1.11 us Signed-off-by: Masahiro Yamada --- drivers/i2c/busses/i2c-uniphier-f.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/i2c/busses/i2c-uniphier-f.c b/drivers/i2c/busses/i2c-uniphier-f.c index d8a5db14..03da4a5 100644 --- a/drivers/i2c/busses/i2c-uniphier-f.c +++ b/drivers/i2c/busses/i2c-uniphier-f.c @@ -518,9 +518,26 @@ static void uniphier_fi2c_hw_init(struct uniphier_fi2c_priv *priv) uniphier_fi2c_reset(priv); + /* + * Standard-mode: tLOW + tHIGH = 10 us + * Fast-mode: tLOW + tHIGH = 2.5 us + */ writel(cyc, priv->membase + UNIPHIER_FI2C_CYC); - writel(cyc / 2, priv->membase + UNIPHIER_FI2C_LCTL); + /* + * Standard-mode: tLOW = 4.7 us, tHIGH = 4.0 us, tBUF = 4.7 us + * Fast-mode: tLOW = 1.3 us, tHIGH = 0.6 us, tBUF = 1.3 us + * "tLow/tHIGH = 5/4" meets both. + */ + writel(cyc * 5 / 9, priv->membase + UNIPHIER_FI2C_LCTL); + /* + * Standard-mode: tHD;STA = 4.0 us, tSU;STA = 4.7 us, tSU;STO = 4.0 us + * Fast-mode: tHD;STA = 0.6 us, tSU;STA = 0.6 us, tSU;STO = 0.6 us + */ writel(cyc / 2, priv->membase + UNIPHIER_FI2C_SSUT); + /* + * Standard-mode: tSU;DAT = 250 ns + * Fast-mode: tSU;DAT = 100 ns + */ writel(cyc / 16, priv->membase + UNIPHIER_FI2C_DSUT); uniphier_fi2c_prepare_operation(priv);