From patchwork Thu Aug 17 09:45:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huangzheng Lai X-Patchwork-Id: 714478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EA52C2FC0E for ; Thu, 17 Aug 2023 09:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349458AbjHQJq4 (ORCPT ); Thu, 17 Aug 2023 05:46:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349827AbjHQJqn (ORCPT ); Thu, 17 Aug 2023 05:46:43 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07EE82D61; Thu, 17 Aug 2023 02:46:40 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 37H9kFjS085239; Thu, 17 Aug 2023 17:46:15 +0800 (+08) (envelope-from Huangzheng.Lai@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx04.spreadtrum.com [10.0.1.214]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RRKpD0fTTz2Q0M6k; Thu, 17 Aug 2023 17:44:04 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx04.spreadtrum.com (10.0.1.214) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 17 Aug 2023 17:46:14 +0800 From: Huangzheng Lai To: Andi Shyti CC: Orson Zhai , Baolin Wang , Chunyan Zhang , , , huangzheng lai , Huangzheng Lai , Xiongpeng Wu Subject: [PATCH 1/8] i2c: sprd: Add configurations that support 1Mhz and 3.4Mhz frequencies Date: Thu, 17 Aug 2023 17:45:13 +0800 Message-ID: <20230817094520.21286-2-Huangzheng.Lai@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> References: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx04.spreadtrum.com (10.0.1.214) X-MAIL: SHSQR01.spreadtrum.com 37H9kFjS085239 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch adds I2C controller driver support for 1Mhz and 3.4Mhz frequency configurations. Signed-off-by: Huangzheng Lai Acked-by: Andi Shyti --- drivers/i2c/busses/i2c-sprd.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c index ffc54fbf814d..acc2a4d4eeae 100644 --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -347,6 +347,10 @@ static void sprd_i2c_set_clk(struct sprd_i2c *i2c_dev, u32 freq) writel((6 * apb_clk) / 10000000, i2c_dev->base + ADDR_STA0_DVD); else if (freq == I2C_MAX_STANDARD_MODE_FREQ) writel((4 * apb_clk) / 1000000, i2c_dev->base + ADDR_STA0_DVD); + else if (freq == I2C_MAX_FAST_MODE_PLUS_FREQ) + writel((8 * apb_clk) / 10000000, i2c_dev->base + ADDR_STA0_DVD); + else if (freq == I2C_MAX_HIGH_SPEED_MODE_FREQ) + writel((8 * apb_clk) / 10000000, i2c_dev->base + ADDR_STA0_DVD); } static void sprd_i2c_enable(struct sprd_i2c *i2c_dev) @@ -519,9 +523,11 @@ static int sprd_i2c_probe(struct platform_device *pdev) if (!of_property_read_u32(dev->of_node, "clock-frequency", &prop)) i2c_dev->bus_freq = prop; - /* We only support 100k and 400k now, otherwise will return error. */ + /* We only support 100k\400k\1m\3.4m now, otherwise will return error. */ if (i2c_dev->bus_freq != I2C_MAX_STANDARD_MODE_FREQ && - i2c_dev->bus_freq != I2C_MAX_FAST_MODE_FREQ) + i2c_dev->bus_freq != I2C_MAX_FAST_MODE_FREQ && + i2c_dev->bus_freq != I2C_MAX_FAST_MODE_PLUS_FREQ && + i2c_dev->bus_freq != I2C_MAX_HIGH_SPEED_MODE_FREQ) return -EINVAL; ret = sprd_i2c_clk_init(i2c_dev); From patchwork Thu Aug 17 09:45:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huangzheng Lai X-Patchwork-Id: 714480 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0ED40C27C7A for ; Thu, 17 Aug 2023 09:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349837AbjHQJqz (ORCPT ); Thu, 17 Aug 2023 05:46:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349828AbjHQJqn (ORCPT ); Thu, 17 Aug 2023 05:46:43 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35D222D67; Thu, 17 Aug 2023 02:46:41 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 37H9kGL5085282; Thu, 17 Aug 2023 17:46:16 +0800 (+08) (envelope-from Huangzheng.Lai@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx04.spreadtrum.com [10.0.1.214]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RRKpF0W4yz2P3khb; Thu, 17 Aug 2023 17:44:05 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx04.spreadtrum.com (10.0.1.214) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 17 Aug 2023 17:46:15 +0800 From: Huangzheng Lai To: Andi Shyti CC: Orson Zhai , Baolin Wang , Chunyan Zhang , , , huangzheng lai , Huangzheng Lai , Xiongpeng Wu Subject: [PATCH 2/8] i2c: sprd: Add I2C driver to use 'reset framework' function Date: Thu, 17 Aug 2023 17:45:14 +0800 Message-ID: <20230817094520.21286-3-Huangzheng.Lai@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> References: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx04.spreadtrum.com (10.0.1.214) X-MAIL: SHSQR01.spreadtrum.com 37H9kGL5085282 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This patch adds the 'reset framework' function for I2C drivers, which resets the I2C controller when a timeout exception occurs. Signed-off-by: Huangzheng Lai --- drivers/i2c/busses/i2c-sprd.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c index acc2a4d4eeae..066b3a9c30c8 100644 --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -17,6 +17,7 @@ #include #include #include +#include #define I2C_CTL 0x00 #define I2C_ADDR_CFG 0x04 @@ -85,6 +86,7 @@ struct sprd_i2c { u32 src_clk; u32 bus_freq; struct completion complete; + struct reset_control *rst; u8 *buf; u32 count; int irq; @@ -247,6 +249,7 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap, { struct sprd_i2c *i2c_dev = i2c_adap->algo_data; unsigned long time_left; + int ret; i2c_dev->msg = msg; i2c_dev->buf = msg->buf; @@ -278,9 +281,16 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap, time_left = wait_for_completion_timeout(&i2c_dev->complete, msecs_to_jiffies(I2C_XFER_TIMEOUT)); - if (!time_left) + if (!time_left) { + dev_err(i2c_dev->dev, "transfer timeout, I2C_STATUS = 0x%x\n", + readl(i2c_dev->base + I2C_STATUS)); + if (i2c_dev->rst != NULL) { + ret = reset_control_reset(i2c_dev->rst); + if (ret < 0) + dev_err(i2c_dev->dev, "i2c soft reset failed, ret = %d\n", ret); + } return -ETIMEDOUT; - + } return i2c_dev->err; } @@ -535,6 +545,11 @@ static int sprd_i2c_probe(struct platform_device *pdev) return ret; platform_set_drvdata(pdev, i2c_dev); + i2c_dev->rst = devm_reset_control_get(i2c_dev->dev, "i2c_rst"); + if (IS_ERR(i2c_dev->rst)) { + dev_err(i2c_dev->dev, "can't get i2c reset node\n"); + i2c_dev->rst = NULL; + } ret = clk_prepare_enable(i2c_dev->clk); if (ret) From patchwork Thu Aug 17 09:45:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huangzheng Lai X-Patchwork-Id: 714479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AFF48C41513 for ; Thu, 17 Aug 2023 09:47:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349782AbjHQJq6 (ORCPT ); Thu, 17 Aug 2023 05:46:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349835AbjHQJqx (ORCPT ); Thu, 17 Aug 2023 05:46:53 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90CEA2D61; Thu, 17 Aug 2023 02:46:51 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 37H9kJn8085390; Thu, 17 Aug 2023 17:46:19 +0800 (+08) (envelope-from Huangzheng.Lai@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx04.spreadtrum.com [10.0.1.214]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RRKpH1kdPz2P3khb; Thu, 17 Aug 2023 17:44:07 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx04.spreadtrum.com (10.0.1.214) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 17 Aug 2023 17:46:17 +0800 From: Huangzheng Lai To: Andi Shyti CC: Orson Zhai , Baolin Wang , Chunyan Zhang , , , huangzheng lai , Huangzheng Lai , Xiongpeng Wu Subject: [PATCH 4/8] i2c: sprd: Add IIC controller driver to support dynamic switching of 400K/1M/3.4M frequency Date: Thu, 17 Aug 2023 17:45:16 +0800 Message-ID: <20230817094520.21286-5-Huangzheng.Lai@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> References: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx04.spreadtrum.com (10.0.1.214) X-MAIL: SHSQR01.spreadtrum.com 37H9kJn8085390 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org When IIC-slaves supporting different frequencies use the same IIC controller, the IIC controller usually only operates at lower frequencies. In order to improve the performance of IIC-slaves transmission supporting faster frequencies, we dynamically configure the IIC operating frequency based on the value of the input parameter msg ->flag. Signed-off-by: Huangzheng Lai --- drivers/i2c/busses/i2c-sprd.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c index 549b60dd3273..02c11a9ff2da 100644 --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -75,7 +75,14 @@ #define SPRD_I2C_PM_TIMEOUT 1000 /* timeout (ms) for transfer message */ #define I2C_XFER_TIMEOUT 1000 - +/* dynamic modify clk_freq flag */ +#define I2C_3M4_FLAG 0x0100 +#define I2C_1M_FLAG 0x0080 +#define I2C_400K_FLAG 0x0040 + +#define I2C_FREQ_400K 400000 +#define I2C_FREQ_1M 1000000 +#define I2C_FREQ_3_4M 3400000 /* SPRD i2c data structure */ struct sprd_i2c { struct i2c_adapter adap; @@ -94,6 +101,8 @@ struct sprd_i2c { int err; }; +static void sprd_i2c_set_clk(struct sprd_i2c *i2c_dev, u32 freq); + static void sprd_i2c_set_count(struct sprd_i2c *i2c_dev, u32 count) { writel(count, i2c_dev->base + I2C_COUNT); @@ -269,6 +278,12 @@ static int sprd_i2c_handle_msg(struct i2c_adapter *i2c_adap, sprd_i2c_send_stop(i2c_dev, !!is_last_msg); } + if (msg->flags & I2C_400K_FLAG) + sprd_i2c_set_clk(i2c_dev, I2C_FREQ_400K); + else if (msg->flags & I2C_1M_FLAG) + sprd_i2c_set_clk(i2c_dev, I2C_FREQ_1M); + else if (msg->flags & I2C_3M4_FLAG) + sprd_i2c_set_clk(i2c_dev, I2C_FREQ_3_4M); /* * We should enable rx fifo full interrupt to get data when receiving * full data. From patchwork Thu Aug 17 09:45:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Huangzheng Lai X-Patchwork-Id: 714477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3173C27C7A for ; Thu, 17 Aug 2023 09:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349936AbjHQJr1 (ORCPT ); Thu, 17 Aug 2023 05:47:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349660AbjHQJq4 (ORCPT ); Thu, 17 Aug 2023 05:46:56 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FBC52D57; Thu, 17 Aug 2023 02:46:55 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 37H9kMAr085658; Thu, 17 Aug 2023 17:46:22 +0800 (+08) (envelope-from Huangzheng.Lai@unisoc.com) Received: from SHDLP.spreadtrum.com (shmbx04.spreadtrum.com [10.0.1.214]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4RRKpL2gQvz2PyrhG; Thu, 17 Aug 2023 17:44:10 +0800 (CST) Received: from xm9614pcu.spreadtrum.com (10.13.2.29) by shmbx04.spreadtrum.com (10.0.1.214) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Thu, 17 Aug 2023 17:46:20 +0800 From: Huangzheng Lai To: Andi Shyti CC: Orson Zhai , Baolin Wang , Chunyan Zhang , , , huangzheng lai , Huangzheng Lai , Xiongpeng Wu Subject: [PATCH 7/8] i2c: sprd: Set I2C_RX_ACK when clear irq Date: Thu, 17 Aug 2023 17:45:19 +0800 Message-ID: <20230817094520.21286-8-Huangzheng.Lai@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> References: <20230817094520.21286-1-Huangzheng.Lai@unisoc.com> MIME-Version: 1.0 X-Originating-IP: [10.13.2.29] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To shmbx04.spreadtrum.com (10.0.1.214) X-MAIL: SHSQR01.spreadtrum.com 37H9kMAr085658 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org We found that when clearing the I2C_TX_ACK bit, the I2C_MODE bit will also be cleared to 0. When the IIC master reads data, this situation will cause the FIFO of the IIC to be empty after clearing the interrupt. To address this issue, when clearing interrupts, set I2C_RX_ACK bit to 1, as writing 1 to this bit will not take effect. Signed-off-by: Huangzheng Lai --- drivers/i2c/busses/i2c-sprd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-sprd.c b/drivers/i2c/busses/i2c-sprd.c index d867389c7f17..6f65f28ea69d 100644 --- a/drivers/i2c/busses/i2c-sprd.c +++ b/drivers/i2c/busses/i2c-sprd.c @@ -138,7 +138,7 @@ static void sprd_i2c_clear_irq(struct sprd_i2c *i2c_dev) { u32 tmp = readl(i2c_dev->base + I2C_STATUS); - writel(tmp & ~I2C_INT, i2c_dev->base + I2C_STATUS); + writel((tmp & ~I2C_INT) | I2C_RX_ACK, i2c_dev->base + I2C_STATUS); } static void sprd_i2c_reset_fifo(struct sprd_i2c *i2c_dev)