From patchwork Sat Jan 7 21:18:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 641116 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 98F8BC46467 for ; Sat, 7 Jan 2023 21:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232711AbjAGVl4 (ORCPT ); Sat, 7 Jan 2023 16:41:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbjAGVli (ORCPT ); Sat, 7 Jan 2023 16:41:38 -0500 X-Greylist: delayed 1330 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 07 Jan 2023 13:41:36 PST Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AD4A271AC for ; Sat, 7 Jan 2023 13:41:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=4vTAnyLsOGqs/zcYUpRiQcsisyMPbBxtJuMbNJ1l1Gg=; b=kr48M6q4P05s9/J0p6vqHo9xPs VsHum1EbDdNm1I7EVkALnaod+q2EYdewlAXhh9fI8ACPmkbffeFMe1N0NoDbvnwcgeyh9Do5j2lbj vrA3j41gIKpIkKK63tgqHaL2SxwPxtxuMzdORCYqago4TkyS+znVzTXTrQJx44+XSyJUETo00VDGL NQ1rdp4FSRmP59ZZa/W4SVh1uEAAVzM0ZyYQ7ipkBUuDmYgqV5m/LbtRyvyWFPS/zQ4VGf3HfXLyV HJk8H7chNHMdy9E4MnYBZDFWAL08/i9YkXVLsQmxfbNjPHQerP2mVkm/LZ2cjqBK/KGQc8AvusLYB /L7pcWYQ==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pEGb7-000ITW-06; Sat, 07 Jan 2023 22:19:25 +0100 Received: from [2604:5500:c0e5:eb00:da5e:d3ff:feff:933b] (helo=lars-desktop.lan) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEGb6-000KM5-Gi; Sat, 07 Jan 2023 22:19:24 +0100 From: Lars-Peter Clausen To: Wolfram Sang Cc: Michal Simek , Shubhrajyoti Datta , linux-i2c@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 1/5] i2c: cadence: Remove unused CDNS_I2C_DATA_INTR_DEPTH define Date: Sat, 7 Jan 2023 13:18:10 -0800 Message-Id: <20230107211814.1179438-2-lars@metafoo.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230107211814.1179438-1-lars@metafoo.de> References: <20230107211814.1179438-1-lars@metafoo.de> MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26774/Sat Jan 7 09:54:43 2023) Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The CDNS_I2C_DATA_INTR_DEPTH is not used in the Cadence I2C driver. Remove it. Signed-off-by: Lars-Peter Clausen Reviewed-by: Michal Simek --- drivers/i2c/busses/i2c-cadence.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index f58943cb1341..71ea658f4bd3 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -115,8 +115,6 @@ #define CNDS_I2C_PM_TIMEOUT 1000 /* ms */ #define CDNS_I2C_FIFO_DEPTH 16 -/* FIFO depth at which the DATA interrupt occurs */ -#define CDNS_I2C_DATA_INTR_DEPTH (CDNS_I2C_FIFO_DEPTH - 2) #define CDNS_I2C_MAX_TRANSFER_SIZE 255 /* Transfer size in multiples of data interrupt depth */ #define CDNS_I2C_TRANSFER_SIZE (CDNS_I2C_MAX_TRANSFER_SIZE - 3) From patchwork Sat Jan 7 21:18:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 640216 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 AEBC8C54EBC for ; Sat, 7 Jan 2023 21:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbjAGVl4 (ORCPT ); Sat, 7 Jan 2023 16:41:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbjAGVll (ORCPT ); Sat, 7 Jan 2023 16:41:41 -0500 Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6397A271AC for ; Sat, 7 Jan 2023 13:41:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=swwFChQDdP70hQq9FeJyayvyCrQSNXQZ/YSXmNS+G2k=; b=mkB/ss+/Lz6JXrkMnuADofbVOH wIdKssY0Aol0ATYWPaRyXkLt9zVkmAews8QtHRc/DPP4XsBtd6YI2/33bnJDXPUyQBW56NBr9Rg8b JyHINz2ov8CGoMOq0yCSpQLj1ZW37FG/fW59+Ny7CVdueseN24Fy1i28SwbHZKFQ8fdiMr17KZ1xQ RjyfphjwKkQmO7adeXGAUm3E214K2+vFkoU4A3qiN92AubyinRzM8lUJdPGF9GJl0cEJdm5zz/9mJ qdEPZJrmCms57D9sefwCHaWalnl/fBCDLDMvUcixHPuYu65lhYXJzK1xW/QMfVIdt5cDAwxzBKbkV 5RCzd20Q==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pEGb8-000ITi-Ef; Sat, 07 Jan 2023 22:19:26 +0100 Received: from [2604:5500:c0e5:eb00:da5e:d3ff:feff:933b] (helo=lars-desktop.lan) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEGb7-000KM5-VJ; Sat, 07 Jan 2023 22:19:26 +0100 From: Lars-Peter Clausen To: Wolfram Sang Cc: Michal Simek , Shubhrajyoti Datta , linux-i2c@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 2/5] i2c: cadence: Remove `irq` field from driver state struct Date: Sat, 7 Jan 2023 13:18:11 -0800 Message-Id: <20230107211814.1179438-3-lars@metafoo.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230107211814.1179438-1-lars@metafoo.de> References: <20230107211814.1179438-1-lars@metafoo.de> MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26774/Sat Jan 7 09:54:43 2023) Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The irq field of the driver state struct is only used in the probe function. There is no need to keep it around. Remove it from the state struct and use a on-stack variable instead. Signed-off-by: Lars-Peter Clausen Reviewed-by: Michal Simek --- drivers/i2c/busses/i2c-cadence.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index 71ea658f4bd3..e2a4cb694cfb 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -173,7 +173,6 @@ enum cdns_i2c_slave_state { * @send_count: Number of bytes still expected to send * @recv_count: Number of bytes still expected to receive * @curr_recv_count: Number of bytes to be received in current transfer - * @irq: IRQ number * @input_clk: Input clock to I2C controller * @i2c_clk: Maximum I2C clock speed * @bus_hold_flag: Flag used in repeated start for clearing HOLD bit @@ -198,7 +197,6 @@ struct cdns_i2c { unsigned int send_count; unsigned int recv_count; unsigned int curr_recv_count; - int irq; unsigned long input_clk; unsigned int i2c_clk; unsigned int bus_hold_flag; @@ -1244,7 +1242,7 @@ static int cdns_i2c_probe(struct platform_device *pdev) { struct resource *r_mem; struct cdns_i2c *id; - int ret; + int ret, irq; const struct of_device_id *match; id = devm_kzalloc(&pdev->dev, sizeof(*id), GFP_KERNEL); @@ -1275,10 +1273,9 @@ static int cdns_i2c_probe(struct platform_device *pdev) if (IS_ERR(id->membase)) return PTR_ERR(id->membase); - ret = platform_get_irq(pdev, 0); - if (ret < 0) - return ret; - id->irq = ret; + irq = platform_get_irq(pdev, 0); + if (irq < 0) + return irq; id->adap.owner = THIS_MODULE; id->adap.dev.of_node = pdev->dev.of_node; @@ -1329,10 +1326,10 @@ static int cdns_i2c_probe(struct platform_device *pdev) goto err_clk_dis; } - ret = devm_request_irq(&pdev->dev, id->irq, cdns_i2c_isr, 0, + ret = devm_request_irq(&pdev->dev, irq, cdns_i2c_isr, 0, DRIVER_NAME, id); if (ret) { - dev_err(&pdev->dev, "cannot get irq %d\n", id->irq); + dev_err(&pdev->dev, "cannot get irq %d\n", irq); goto err_clk_dis; } cdns_i2c_init(id); @@ -1342,7 +1339,7 @@ static int cdns_i2c_probe(struct platform_device *pdev) goto err_clk_dis; dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n", - id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); + id->i2c_clk / 1000, (unsigned long)r_mem->start, irq); return 0; From patchwork Sat Jan 7 21:18:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 640214 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 308BBC46467 for ; Sat, 7 Jan 2023 21:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232641AbjAGVl7 (ORCPT ); Sat, 7 Jan 2023 16:41:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232675AbjAGVlv (ORCPT ); Sat, 7 Jan 2023 16:41:51 -0500 Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD5B30568 for ; Sat, 7 Jan 2023 13:41:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=WijF59gYFE7TyJcWQqc6Jvdfwgsz0L6hxpCmWfBEWw4=; b=gfWBTbNFq/frE6FJ/otkNBgR6h ZxivAsS8b7OMU3Q6Eo46b7AsUasgSxmkDElfCXmFTC2jz/Uysg+LN08dZ+NNGqzvDdiIgrWgDh4fJ USPMNEZrzfhbhMhjf/+FbGNv8JAnkCf09jrzWQoeIRyEAEkJnp4u0J8Zw8yi4W/IYKq3jBdmH2Oz5 b395q18UkU5YoAQGQ69zsw/qr8KU648fcMhaYisaV4KhLH6zBDfnobZokVvcKHIi44ud+CyHTulk4 b6fl4or/b5xxZRnpHbUc+Qhn5FNvvgP2CrC+8XQxS2w/8QUdJ9fxhkXIu4yq4mXpAknNVfAa46QFP o3T+M5ew==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pEGb9-000ITr-Uw; Sat, 07 Jan 2023 22:19:27 +0100 Received: from [2604:5500:c0e5:eb00:da5e:d3ff:feff:933b] (helo=lars-desktop.lan) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEGb9-000KM5-De; Sat, 07 Jan 2023 22:19:27 +0100 From: Lars-Peter Clausen To: Wolfram Sang Cc: Michal Simek , Shubhrajyoti Datta , linux-i2c@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 3/5] i2c: cadence: Remove redundant expression in if clause Date: Sat, 7 Jan 2023 13:18:12 -0800 Message-Id: <20230107211814.1179438-4-lars@metafoo.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230107211814.1179438-1-lars@metafoo.de> References: <20230107211814.1179438-1-lars@metafoo.de> MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26774/Sat Jan 7 09:54:43 2023) Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In the mrecv() function the Cadence I2C driver has the following expression in an if clause. ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) && (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) Earlier in the same function when I2C_M_RECV_LEN is set the recv_count is initialized to a value that is larger than CDNS_I2C_FIFO_DEPTH. This means if the first expression is false the second expression is also false. Checking the first expression is thus redundant and can be removed. This slightly simplifies the logic. Signed-off-by: Lars-Peter Clausen Reviewed-by: Michal Simek --- drivers/i2c/busses/i2c-cadence.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index e2a4cb694cfb..b5d22e7282c2 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -612,9 +612,7 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id) } /* Determine hold_clear based on number of bytes to receive and hold flag */ - if (!id->bus_hold_flag && - ((id->p_msg->flags & I2C_M_RECV_LEN) != I2C_M_RECV_LEN) && - (id->recv_count <= CDNS_I2C_FIFO_DEPTH)) { + if (!id->bus_hold_flag && id->recv_count <= CDNS_I2C_FIFO_DEPTH) { if (cdns_i2c_readreg(CDNS_I2C_CR_OFFSET) & CDNS_I2C_CR_HOLD) { hold_clear = true; if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) From patchwork Sat Jan 7 21:18:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 641115 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 7B15DC6379F for ; Sat, 7 Jan 2023 21:41:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231718AbjAGVl6 (ORCPT ); Sat, 7 Jan 2023 16:41:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232641AbjAGVls (ORCPT ); Sat, 7 Jan 2023 16:41:48 -0500 Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F4B2271B8 for ; Sat, 7 Jan 2023 13:41:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=dAUrCyqmCpW9NfB9wRpmj6DpYny5Ku47B1rkN6iCgwA=; b=XMqakxSGzTXFgL+s2Wg0l0Xk91 tV88NxJ25RfRW3S1yQpBc6RriGj7DjW2smCWco00IMceEyz5uojje52oL1Xr7ifjY18eMxLt1OcMa 208fA5aTTlj1FO7Ko7YVJTzXTGcVCKECKOZ2HE1F/xMLiDy8le0s1RRd3DxgN9y67P30KG+29L06N kQRs3rCuoxKyYUeCPGUzBahxIeKnUdUHQCZ4v2yv+fHbmFVPPxZA757MaaBKiBeEzBVJu5a6Fh0KL QrcYd1UyyoUqnSg32V6NK7XOlpnZ7ZTdMKEw+zLe/XFP720G0n8Tf2l6/JUZCjBqerpysRFcy5P/6 h97AlceA==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pEGbB-000IU2-Cc; Sat, 07 Jan 2023 22:19:29 +0100 Received: from [2604:5500:c0e5:eb00:da5e:d3ff:feff:933b] (helo=lars-desktop.lan) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEGbA-000KM5-SJ; Sat, 07 Jan 2023 22:19:29 +0100 From: Lars-Peter Clausen To: Wolfram Sang Cc: Michal Simek , Shubhrajyoti Datta , linux-i2c@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 4/5] i2c: cadence: Remove always false ternary operator Date: Sat, 7 Jan 2023 13:18:13 -0800 Message-Id: <20230107211814.1179438-5-lars@metafoo.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230107211814.1179438-1-lars@metafoo.de> References: <20230107211814.1179438-1-lars@metafoo.de> MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26774/Sat Jan 7 09:54:43 2023) Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org When selecting the clock dividers the Cadence I2C driver skips settings where the resulting I2C bus frequency is larger than the requested frequency. If the resulting frequency is lower it will compute the error to actual frequency. When calculating the difference it also handles the case where the resulting frequency is larger. Since the resulting frequency is always smaller or equal the computation of the error can be simplified by only considering this case. Signed-off-by: Lars-Peter Clausen Acked-by: Michal Simek --- drivers/i2c/busses/i2c-cadence.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index b5d22e7282c2..bec50bfe7aad 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -1030,8 +1030,7 @@ static int cdns_i2c_calc_divs(unsigned long *f, unsigned long input_clk, if (actual_fscl > fscl) continue; - current_error = ((actual_fscl > fscl) ? (actual_fscl - fscl) : - (fscl - actual_fscl)); + current_error = fscl - actual_fscl; if (last_error > current_error) { calc_div_a = div_a; From patchwork Sat Jan 7 21:18:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lars-Peter Clausen X-Patchwork-Id: 641114 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 ED3CEC677F1 for ; Sat, 7 Jan 2023 21:41:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230224AbjAGVl5 (ORCPT ); Sat, 7 Jan 2023 16:41:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231718AbjAGVlq (ORCPT ); Sat, 7 Jan 2023 16:41:46 -0500 Received: from www381.your-server.de (www381.your-server.de [78.46.137.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 381A8271AC for ; Sat, 7 Jan 2023 13:41:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=metafoo.de; s=default2002; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID; bh=jQJjwqVizlDsfAUb7jHtOgoEjaitvBRqyxSpBiUuHCg=; b=X6HKbEn/+hr/2GTyXLIy/Si3pN qu+xhKrK0nxuF33brSeFEO7ZoQyHaYM7JyOj8Eq8TmAeRx7vqhrIQs3/xjGghSauP6wsFO1v0XHCr iMPk51c/+l6EV4GAEeBm4/5LPVE7JxyylpBopaIJEousInmA2ZK3YX+PL9mRxkF3qZktLN3y62jh1 Wsx/5lI4VYHi4rKw+MNRHUexmgtLUUb8ETkU5/26mXf9jhXfEKYem7tCA1FRoV+BFtrOXGYPuDT0P GWwEPpvc/WqDor6MFyn+WBdREMoDLLQw9Tw9E7yKCAV8n84qXiZm5h3H+Z0ePGWLMBaMOWDSvAu5a Zj79il6A==; Received: from sslproxy01.your-server.de ([78.46.139.224]) by www381.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pEGbC-000IV5-Qi; Sat, 07 Jan 2023 22:19:30 +0100 Received: from [2604:5500:c0e5:eb00:da5e:d3ff:feff:933b] (helo=lars-desktop.lan) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pEGbC-000KM5-Ah; Sat, 07 Jan 2023 22:19:30 +0100 From: Lars-Peter Clausen To: Wolfram Sang Cc: Michal Simek , Shubhrajyoti Datta , linux-i2c@vger.kernel.org, Lars-Peter Clausen Subject: [PATCH 5/5] i2c: cadence: Remove unnecessary register reads Date: Sat, 7 Jan 2023 13:18:14 -0800 Message-Id: <20230107211814.1179438-6-lars@metafoo.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230107211814.1179438-1-lars@metafoo.de> References: <20230107211814.1179438-1-lars@metafoo.de> MIME-Version: 1.0 X-Authenticated-Sender: lars@metafoo.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26774/Sat Jan 7 09:54:43 2023) Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In the `cdns_i2c_mrecv()` function the CTRL register of the Cadence I2C controller is written and read back multiple times. The register value does not change on its own. So it is possible to remember the just written value instead of reading it back from the hardware. Signed-off-by: Lars-Peter Clausen --- drivers/i2c/busses/i2c-cadence.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index bec50bfe7aad..93c6d0822468 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -613,7 +613,7 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id) /* Determine hold_clear based on number of bytes to receive and hold flag */ if (!id->bus_hold_flag && id->recv_count <= CDNS_I2C_FIFO_DEPTH) { - if (cdns_i2c_readreg(CDNS_I2C_CR_OFFSET) & CDNS_I2C_CR_HOLD) { + if (ctrl_reg & CDNS_I2C_CR_HOLD) { hold_clear = true; if (id->quirks & CDNS_I2C_BROKEN_HOLD_BIT) irq_save = true; @@ -624,7 +624,7 @@ static void cdns_i2c_mrecv(struct cdns_i2c *id) addr &= CDNS_I2C_ADDR_MASK; if (hold_clear) { - ctrl_reg = cdns_i2c_readreg(CDNS_I2C_CR_OFFSET) & ~CDNS_I2C_CR_HOLD; + ctrl_reg &= ~CDNS_I2C_CR_HOLD; /* * In case of Xilinx Zynq SOC, clear the HOLD bit before transfer size * register reaches '0'. This is an IP bug which causes transfer size