From patchwork Wed Nov 8 16:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13450318 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 18B62C4167D for ; Wed, 8 Nov 2023 16:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229816AbjKHQoJ (ORCPT ); Wed, 8 Nov 2023 11:44:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230501AbjKHQoI (ORCPT ); Wed, 8 Nov 2023 11:44:08 -0500 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E1BB1FE8 for ; Wed, 8 Nov 2023 08:44:06 -0800 (PST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231108164404euoutp01aa1b271fc067a12e25d9c8f5e81a20d1~Vs4szgKrs1558815588euoutp01u for ; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231108164404euoutp01aa1b271fc067a12e25d9c8f5e81a20d1~Vs4szgKrs1558815588euoutp01u DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1699461844; bh=+fxGh0F2jh5WLjDPhQfaN5Ox2KF8VceXdmWAUqrEtYA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=urKWOBNrmNI1A2mqlb9XnjRKasfR8IL8VzkA7pS1+WqudOynRrVnPGUvdPqpuuIxc I0opGqJMu7RX0G4lkfbYVMgxrc2oj982KovlBOlYnkD1FYGnvHz40H5gTp/5x8GQrr ppPqxT4wzee1cJJaRzGkG3cE1yKLyTXQukdclFbM= Received: from eusmges1new.samsung.com (unknown [203.254.199.242]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20231108164404eucas1p10c37b7f63fcda0e722054080041dd191~Vs4sV61-P0870608706eucas1p1u; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges1new.samsung.com (EUCPMTA) with SMTP id 95.D2.42423.4DABB456; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231108164404eucas1p2fab093d286ef3c118f63bdc375964776~Vs4sBgv0G0157401574eucas1p2s; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231108164403eusmtrp2c372e8b21f0aea4efba9a59f62810d04~Vs4sA3DFp2869728697eusmtrp2E; Wed, 8 Nov 2023 16:44:03 +0000 (GMT) X-AuditID: cbfec7f2-a3bff7000002a5b7-1e-654bbad4429f Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 79.12.25043.3DABB456; Wed, 8 Nov 2023 16:44:03 +0000 (GMT) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231108164403eusmtip28a7163c316b152ef92196a14a2a86518~Vs4rdcjUL1025410254eusmtip2E; Wed, 8 Nov 2023 16:44:03 +0000 (GMT) From: Marek Szyprowski To: linux-samsung-soc@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Marek Szyprowski , Krzysztof Kozlowski , Alim Akhtar , Andi Shyti , Wolfram Sang , Chanho Park Subject: [PATCH v4 1/3] i2c: s3c24xx: fix read transfers in polling mode Date: Wed, 8 Nov 2023 17:43:52 +0100 Message-Id: <20231108164354.712406-2-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108164354.712406-1-m.szyprowski@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42LZduzned0ru7xTDS7PF7R4MG8bm8X9rx2M Fpf3a1vsfb2V3aLj7xdGixnn9zFZrD1yl93i7v65jA4cHptWdbJ53Lm2h82jb8sqRo/Pm+QC WKK4bFJSczLLUov07RK4Mh4d/M9UcIarYtnPLqYGxvMcXYycHBICJhL3D2xk72Lk4hASWMEo sWvOYTaQhJDAF0aJPeskIezPjBJH3wfCNEy61M8K0bCcUeLT8euMEA5Qw5wvk9lBqtgEDCW6 3naBTRIRcJCYt/Y7WJxZ4B+jxPcveiC2sICHxMcp88DiLAKqErd+gkzl5OAVsJNY39TGDLFN XmL/wbNgNqeAvUT3hNnsEDWCEidnPmGBmCkv0bx1NjPIERICOzgkvkxdBVTEAeS4SDQvK4eY Iyzx6vgWdghbRuL/zvlMEPXtjBILft+HciYwSjQ8v8UIUWUtcefcLzaQQcwCmhLrd+lDzHSU +PmNC8Lkk7jxVhDiBD6JSdumM0OEeSU62oQgZqhJzDq+Dm7rwQuXoL7ykLj6cDvjBEbFWUie mYXkmVkIaxcwMq9iFE8tLc5NTy02zEst1ytOzC0uzUvXS87P3cQITDKn/x3/tINx7quPeocY mTgYDzFKcDArifD+tfdIFeJNSaysSi3Kjy8qzUktPsQozcGiJM6rmiKfKiSQnliSmp2aWpBa BJNl4uCUamCa8kHIJd6p33eV6Y0rW+dEMV6xLLWS7Cjbn7D+orLgyzUN80pY1L/zdeo45VqH rnHXyFhfaaQQN1fN8eDJXee0HaZENe/sdfmkaHL07on0g1/qH6935rR44vdljffVUzdq9hbx NvKccjk0rTDIVmbFmUyXpDT5B7Nf+1gYXpo5VUz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g8N0da z51h76OjKvT9qFBJtNHEd1dmnT56/Pryb8Wqyp/6gviecgsYsHQbzFxbv+64yNt59pZe/Qy7 XS/UHE/0kPW+FLFxTv76+XURSx/cZ7wQOk3Wpe3x+qLHKa9XPVViKc5INNRiLipOBACvzYGf EgMAAA== X-CMS-MailID: 20231108164404eucas1p2fab093d286ef3c118f63bdc375964776 X-Msg-Generator: CA X-RootMTR: 20231108164404eucas1p2fab093d286ef3c118f63bdc375964776 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231108164404eucas1p2fab093d286ef3c118f63bdc375964776 References: <20231108164354.712406-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org To properly handle read transfers in polling mode, no waiting for the ACK state is needed as it will never come. Just wait a bit to ensure start state is on the bus and continue processing next bytes. Fixes: 117053f77a5a ("i2c: s3c2410: Add polling mode support") Signed-off-by: Marek Szyprowski Reviewed-by: Chanho Park Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-s3c2410.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index c56886af724e..bf9a5670ef33 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -216,8 +216,17 @@ static bool is_ack(struct s3c24xx_i2c *i2c) int tries; for (tries = 50; tries; --tries) { - if (readl(i2c->regs + S3C2410_IICCON) - & S3C2410_IICCON_IRQPEND) { + unsigned long tmp = readl(i2c->regs + S3C2410_IICCON); + + if (!(tmp & S3C2410_IICCON_ACKEN)) { + /* + * Wait a bit for the bus to stabilize, + * delay estimated experimentally. + */ + usleep_range(100, 200); + return true; + } + if (tmp & S3C2410_IICCON_IRQPEND) { if (!(readl(i2c->regs + S3C2410_IICSTAT) & S3C2410_IICSTAT_LASTBIT)) return true; From patchwork Wed Nov 8 16:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13450317 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 BE187C0018C for ; Wed, 8 Nov 2023 16:44:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232099AbjKHQoK (ORCPT ); Wed, 8 Nov 2023 11:44:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231976AbjKHQoJ (ORCPT ); Wed, 8 Nov 2023 11:44:09 -0500 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B4021FCE for ; Wed, 8 Nov 2023 08:44:06 -0800 (PST) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231108164405euoutp015c88092574a639ababdddc3c2d679d28~Vs4tVeb0w1559015590euoutp01q for ; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231108164405euoutp015c88092574a639ababdddc3c2d679d28~Vs4tVeb0w1559015590euoutp01q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1699461845; bh=/Poy4ZiSU6m7dMMQv9E5e9L8uydGQeX714UmDAIeZxY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gJjtKDOUgg029EK+v1fTvVSCK3tVesV5hZZsz3X8szu24he/UqnbdYOHDPLXC4WIa oUYtHM+NNKUqwSKcbXuvWHFiGoDYmQTde5yZ4VCq4NpBQbhxwmoLfKMzMhOD53w3Hh cpeCA0OPiUBZEt4CIRwN0SoeqOCpxzUYdafzxOTE= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231108164405eucas1p251f53df0a2356c394c4b60ceab2dd278~Vs4tAU2UF1401514015eucas1p2S; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id AA.54.11320.4DABB456; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231108164404eucas1p2b4d3bbbd618707456d3d667fabccc4f9~Vs4sogklC1401114011eucas1p2M; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231108164404eusmtrp221c9ce923becbcc519ef35e9337ca30f~Vs4snijxN2869728697eusmtrp2G; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) X-AuditID: cbfec7f4-993ff70000022c38-7c-654bbad4957d Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 9A.12.25043.4DABB456; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231108164403eusmtip2b93279776c1de1a4da9671ccbfef3092~Vs4r-k7-50975909759eusmtip2C; Wed, 8 Nov 2023 16:44:03 +0000 (GMT) From: Marek Szyprowski To: linux-samsung-soc@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Marek Szyprowski , Krzysztof Kozlowski , Alim Akhtar , Andi Shyti , Wolfram Sang , Chanho Park Subject: [PATCH v4 2/3] i2c: s3c24xx: fix transferring more than one message in polling mode Date: Wed, 8 Nov 2023 17:43:53 +0100 Message-Id: <20231108164354.712406-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108164354.712406-1-m.szyprowski@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA02Se0hTYRjG+XaO29lg6zgdvnQbSUoabWpBpyw1LThhSHSvP6yRBxV1yi5Z kaETy1TMNKwmXkLDMfGSOS/DXIpoOqdlJeElJeyqluZKLKycZ13++73v+zzf877wEZg432U1 EavUMCqlIt6TK8Abuxb7tzw3hzN+mWaKmihp5FLjXzMR9cyymXo4ZeJRmUt2RN0eaONQ1Z1j PGrMUoxCCLreeI1Ljw61cuncBiOi5+vXH8RPCXZFMfGx5xiVPOiMIMYyZ0NJre7nS6ZfcFLR KzIL8Qkgt0GaftwlCwkIMWlAUPtmFLGFHUFOYaVzMo/AnGHh/rFcL23lsYNKBJP2Ks5fi25w ekXFJf0hayZrhd3JECipXuA5GCN/IliwyxzsRkbCjZpF3ME46QV36ytXNEIyCGqalnA2TQqW dhvmYD4ZDNl5RU6NK/TcmcTZN6WQbirCHEsA2UyA8ceQ07wXah/cc7IbfOxu4LG8Fn61lHJY w1UEZT/GnUUegtR3w4hVBcJo//flE4jlCB+oNcvZ9h6Y07UhRxtIEbyccWWXEEF+4y2MbQsh 84qYVXuDvrvmb2z7k0GMZRp6rAt4Htqg/+8c/X/n6P/lliHMiDwYrTohmlEHKJlkmVqRoNYq o2VnExPq0fK3sf7stjejyo9zsg7EIVAHAgLzdBcuBdOMWBiluHCRUSWeVmnjGXUHWkPgnh5C rygpIyajFRomjmGSGNWfKYfgr07lHH96sDzc5bFf0KUGWxhs+XRCakrc0ycJ0++uCzNsz7Am iWy+kUr5t66IlO0VRO5wWnTjBYtWwK3xfjsuci8xdMqmKgJ0B0yuB9o2Wfcu3tqqehoTO91X tc16cj5CI+51zUm5u/+BRxWnrrBFN1WasXOmOtmFejkpT58lj/nkFPSOJBU2FbTy9y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H1sH+zDfK0HSs2HPkgkPjl1MxMo0fHTbfV9PnIMoQ8/BnyxZJ/z2FX FbHIKMEEL/2jd9I9S0vaJoW97z8hne7qFhnlsyBazdnuu9PXUJtIJZbijERDLeai4kQAbLHB axEDAAA= X-CMS-MailID: 20231108164404eucas1p2b4d3bbbd618707456d3d667fabccc4f9 X-Msg-Generator: CA X-RootMTR: 20231108164404eucas1p2b4d3bbbd618707456d3d667fabccc4f9 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231108164404eucas1p2b4d3bbbd618707456d3d667fabccc4f9 References: <20231108164354.712406-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org To properly handle ACK on the bus when transferring more than one message in polling mode, move the polling handling loop from s3c24xx_i2c_message_start() to s3c24xx_i2c_doxfer(). This way i2c_s3c_irq_nextbyte() is always executed till the end, properly acknowledging the IRQ bits and no recursive calls to i2c_s3c_irq_nextbyte() are made. While touching this, also fix finishing transfers in polling mode by using common code path and always waiting for the bus to become idle and disabled. Fixes: 117053f77a5a ("i2c: s3c2410: Add polling mode support") Signed-off-by: Marek Szyprowski Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-s3c2410.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index bf9a5670ef33..c0fe96a4f2c4 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -279,16 +279,6 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c, stat |= S3C2410_IICSTAT_START; writel(stat, i2c->regs + S3C2410_IICSTAT); - - if (i2c->quirks & QUIRK_POLL) { - while ((i2c->msg_num != 0) && is_ack(i2c)) { - i2c_s3c_irq_nextbyte(i2c, stat); - stat = readl(i2c->regs + S3C2410_IICSTAT); - - if (stat & S3C2410_IICSTAT_ARBITR) - dev_err(i2c->dev, "deal with arbitration loss\n"); - } - } } static inline void s3c24xx_i2c_stop(struct s3c24xx_i2c *i2c, int ret) @@ -694,7 +684,7 @@ static void s3c24xx_i2c_wait_idle(struct s3c24xx_i2c *i2c) static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int num) { - unsigned long timeout; + unsigned long timeout = 0; int ret; ret = s3c24xx_i2c_set_master(i2c); @@ -714,16 +704,19 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, s3c24xx_i2c_message_start(i2c, msgs); if (i2c->quirks & QUIRK_POLL) { - ret = i2c->msg_idx; + while ((i2c->msg_num != 0) && is_ack(i2c)) { + unsigned long stat = readl(i2c->regs + S3C2410_IICSTAT); - if (ret != num) - dev_dbg(i2c->dev, "incomplete xfer (%d)\n", ret); + i2c_s3c_irq_nextbyte(i2c, stat); - goto out; + stat = readl(i2c->regs + S3C2410_IICSTAT); + if (stat & S3C2410_IICSTAT_ARBITR) + dev_err(i2c->dev, "deal with arbitration loss\n"); + } + } else { + timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); } - timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); - ret = i2c->msg_idx; /* From patchwork Wed Nov 8 16:43:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13450319 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 3EEE7C04E85 for ; Wed, 8 Nov 2023 16:44:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231924AbjKHQoK (ORCPT ); Wed, 8 Nov 2023 11:44:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjKHQoJ (ORCPT ); Wed, 8 Nov 2023 11:44:09 -0500 Received: from mailout1.w1.samsung.com (mailout1.w1.samsung.com [210.118.77.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36D211FD4 for ; Wed, 8 Nov 2023 08:44:07 -0800 (PST) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout1.w1.samsung.com (KnoxPortal) with ESMTP id 20231108164405euoutp0131b53f4950a747b2418bffc68611a578~Vs4t1xN1-1558915589euoutp01o for ; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20231108164405euoutp0131b53f4950a747b2418bffc68611a578~Vs4t1xN1-1558915589euoutp01o DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1699461846; bh=NbOLdkZRq1ksTSN0R9GmLW+f9tkPmZRg76wbrp7/+aU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nOdMqBO6eLM6jhgmZ1enMJMlWEJbZSZxtSULgdvb2A6AG9Uzy9wsAqFG4FNluylJW 0DLH0hxKuIgkYLcYWvT/6BJBD1LjwhM+5eFNoi7/wMmICpoicYY12/agyQCHG8A6Rb e3+xzIzWN2qc/LEpUXeqlK60dwNmF9LqYFmYk0bM= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20231108164405eucas1p147ff4a743fc8f883c07171faaaacc20d~Vs4tkalw62061420614eucas1p1J; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 62.82.52736.5DABB456; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231108164405eucas1p13c761b67a4c5e3631ee245b00b997e4e~Vs4tLSHka2061420614eucas1p1I; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231108164405eusmtrp2efb98e103de690da400ef0e05c5caf0a~Vs4tKudFI2869928699eusmtrp2K; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) X-AuditID: cbfec7f5-bb7ff7000000ce00-d3-654bbad558a9 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 2B.12.25043.5DABB456; Wed, 8 Nov 2023 16:44:05 +0000 (GMT) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231108164404eusmtip2dbc75dc5e98ecbef4c24bca757c98243~Vs4sil3Dt0430704307eusmtip21; Wed, 8 Nov 2023 16:44:04 +0000 (GMT) From: Marek Szyprowski To: linux-samsung-soc@vger.kernel.org, linux-i2c@vger.kernel.org Cc: Marek Szyprowski , Krzysztof Kozlowski , Alim Akhtar , Andi Shyti , Wolfram Sang , Chanho Park Subject: [PATCH v4 3/3] i2c: s3c24xx: add support for atomic transfers Date: Wed, 8 Nov 2023 17:43:54 +0100 Message-Id: <20231108164354.712406-4-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231108164354.712406-1-m.szyprowski@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnleLIzCtJLcpLzFFi42LZduznOd2ru7xTDX5fVbZ4MG8bm8X9rx2M Fpf3a1vsfb2V3aLj7xdGixnn9zFZrD1yl93i7v65jA4cHptWdbJ53Lm2h82jb8sqRo/Pm+QC WKK4bFJSczLLUov07RK4MiZdWcVccEmpYusSkwbG67JdjJwcEgImEg0vGhm7GLk4hARWMEps +L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mTkF5fYKkUbWhjpGVpa6BmZWOoZGpvHWhmZKunb2aSk5mSWpRbp2yXoZUy6 soq54JJSxdYlJg2M12W7GDk5JARMJGZd2M3UxcjFISSwlFHi5abjbBAJGYmT0xpYIWxhiT/X utggij4xSmz/84kJJMEmYCjR9bYLrEFEwEni9qJZrCBFzAJNTBIdJxaxgySEBdwkJr5ZCDaJ RUBVou9DD1gDr4CdxKG+GSwQG+Ql9h88ywxicwrYS3RPmA3WKwRU8/3CYah6QYmTM5+A1TMD 1Tdvnc08gVFgFpLULCSpBYxMqxhFUkuLc9Nzi430ihNzi0vz0vWS83M3MQJjYtuxn1t2MK58 9VHvECMTB+MhRgkOZiUR3r/2HqlCvCmJlVWpRfnxRaU5qcWHGE2B7p7ILCWanA+MyrySeEMz A1NDEzNLA1NLM2MlcV7Pgo5EIYH0xJLU7NTUgtQimD4mDk6pBqboxu+WJ8JvKdVMnXVkfXPB jE+/v2p6u/yYuPi4/PoEk3836r3WrTY6PXXJ2YdWt3l3xGnVhzocU5uuryu01n2uhuiuDSfl A7bF/UtgfVS9dE/8n7yWebuM+aTi9feoBJ3U/65ssyRi1dYX77+fV5228oquwmLbGtMIwXhx 8boXLKlhQabHdeRZgqvD5d54H/NQMN14Ys3F+W+nzHJ8f+ne6jvxTWnHraI+XWxQN3NeOOlo itOxDanaYockDxzitz3EF820TCAlr8vG5sL0PSxsu9Ptt16ffOJGkxKT3Pn/0krlOz80zWHV /c/Sc3jXXxY2/kOZvxa+e5+18ZrayXy16WqmK/KPdxk/7WOrL5FUYinOSDTUYi4qTgQASMlQ bBIDAAA= X-CMS-MailID: 20231108164405eucas1p13c761b67a4c5e3631ee245b00b997e4e X-Msg-Generator: CA X-RootMTR: 20231108164405eucas1p13c761b67a4c5e3631ee245b00b997e4e X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231108164405eucas1p13c761b67a4c5e3631ee245b00b997e4e References: <20231108164354.712406-1-m.szyprowski@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org Add support for atomic transfers using polling mode with interrupts intentionally disabled to get rid of the following warning introduced by commit 63b96983a5dd ("i2c: core: introduce callbacks for atomic transfers") during system reboot and power-off: ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1518 at drivers/i2c/i2c-core.h:40 i2c_transfer+0xe8/0xf4 No atomic I2C transfer handler for 'i2c-0' Modules linked in: CPU: 0 PID: 1518 Comm: reboot Not tainted 6.6.0-next-20231031 #7453 Hardware name: Samsung Exynos (Flattened Device Tree) unwind_backtrace from show_stack+0x10/0x14 show_stack from dump_stack_lvl+0x40/0x4c dump_stack_lvl from __warn+0x7c/0x124 __warn from warn_slowpath_fmt+0x110/0x178 warn_slowpath_fmt from i2c_transfer+0xe8/0xf4 i2c_transfer from regmap_i2c_read+0x58/0x88 regmap_i2c_read from _regmap_raw_read+0xfc/0x260 _regmap_raw_read from _regmap_bus_read+0x44/0x70 _regmap_bus_read from _regmap_read+0x60/0x14c _regmap_read from regmap_read+0x3c/0x60 regmap_read from regulator_get_voltage_sel_regmap+0x2c/0x74 regulator_get_voltage_sel_regmap from regulator_get_voltage_rdev+0x64/0x15c regulator_get_voltage_rdev from _regulator_do_set_voltage+0x2c/0x5a8 _regulator_do_set_voltage from regulator_set_voltage_rdev+0x90/0x248 regulator_set_voltage_rdev from regulator_do_balance_voltage+0x350/0x4d0 regulator_do_balance_voltage from regulator_set_voltage_unlocked+0xd4/0x118 regulator_set_voltage_unlocked from regulator_set_voltage+0x40/0x74 regulator_set_voltage from _opp_config_regulator_single+0x44/0x110 _opp_config_regulator_single from _set_opp+0x118/0x500 _set_opp from dev_pm_opp_set_rate+0x108/0x20c dev_pm_opp_set_rate from __cpufreq_driver_target+0x568/0x6cc __cpufreq_driver_target from cpufreq_generic_suspend+0x28/0x50 cpufreq_generic_suspend from cpufreq_suspend+0xbc/0x124 cpufreq_suspend from device_shutdown+0x18/0x230 device_shutdown from kernel_restart+0x38/0x90 kernel_restart from __do_sys_reboot+0x12c/0x1f8 __do_sys_reboot from ret_fast_syscall+0x0/0x54 Exception stack(0xf0fedfa8 to 0xf0fedff0) ... ---[ end trace 0000000000000000 ]--- Signed-off-by: Marek Szyprowski Reviewed-by: Chanho Park Reviewed-by: Andi Shyti --- drivers/i2c/busses/i2c-s3c2410.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index c0fe96a4f2c4..275f7c42165c 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -76,6 +76,7 @@ #define QUIRK_HDMIPHY (1 << 1) #define QUIRK_NO_GPIO (1 << 2) #define QUIRK_POLL (1 << 3) +#define QUIRK_ATOMIC (1 << 4) /* Max time to wait for bus to become idle after a xfer (in us) */ #define S3C2410_IDLE_TIMEOUT 5000 @@ -174,7 +175,7 @@ static inline void s3c24xx_i2c_master_complete(struct s3c24xx_i2c *i2c, int ret) if (ret) i2c->msg_idx = ret; - if (!(i2c->quirks & QUIRK_POLL)) + if (!(i2c->quirks & (QUIRK_POLL | QUIRK_ATOMIC))) wake_up(&i2c->wait); } @@ -703,7 +704,7 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, s3c24xx_i2c_enable_irq(i2c); s3c24xx_i2c_message_start(i2c, msgs); - if (i2c->quirks & QUIRK_POLL) { + if (i2c->quirks & (QUIRK_POLL | QUIRK_ATOMIC)) { while ((i2c->msg_num != 0) && is_ack(i2c)) { unsigned long stat = readl(i2c->regs + S3C2410_IICSTAT); @@ -775,6 +776,21 @@ static int s3c24xx_i2c_xfer(struct i2c_adapter *adap, return -EREMOTEIO; } +static int s3c24xx_i2c_xfer_atomic(struct i2c_adapter *adap, + struct i2c_msg *msgs, int num) +{ + struct s3c24xx_i2c *i2c = (struct s3c24xx_i2c *)adap->algo_data; + int ret; + + disable_irq(i2c->irq); + i2c->quirks |= QUIRK_ATOMIC; + ret = s3c24xx_i2c_xfer(adap, msgs, num); + i2c->quirks &= ~QUIRK_ATOMIC; + enable_irq(i2c->irq); + + return ret; +} + /* declare our i2c functionality */ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap) { @@ -785,6 +801,7 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap) /* i2c bus registration info */ static const struct i2c_algorithm s3c24xx_i2c_algorithm = { .master_xfer = s3c24xx_i2c_xfer, + .master_xfer_atomic = s3c24xx_i2c_xfer_atomic, .functionality = s3c24xx_i2c_func, };