From patchwork Tue Oct 31 14:42:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13441606 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 B135BC4708E for ; Tue, 31 Oct 2023 14:43:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344315AbjJaOnJ (ORCPT ); Tue, 31 Oct 2023 10:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344241AbjJaOnH (ORCPT ); Tue, 31 Oct 2023 10:43:07 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC57BDB for ; Tue, 31 Oct 2023 07:43:03 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231031144300euoutp0222003a90049d0293880cf076c7a17d72~TOEtY6dAZ2518725187euoutp02g for ; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231031144300euoutp0222003a90049d0293880cf076c7a17d72~TOEtY6dAZ2518725187euoutp02g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698763380; bh=904cUKyVQZK/KgbJ73bN/05Obq8ZP8p+O3KY1ovxV50=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nIhANSsluH24JFeUhDgPZNtHvwlifw9+LHE8lYhQQ1ADz/OleDQX6YChobWNlyi+x gBh/FFHiNgrOp6AkzK72oWuVTCiLDNxssgcEcnLyN5syznQb9vnukBBQQIpTa5+sb8 uI/lLZ2l22FEMEKALm1R+hijFnKHFvnCcXXG/jRw= Received: from eusmges2new.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20231031144300eucas1p11ba954c862cdf0fa87a2ab7d3c50f32c~TOEtHVpJU3036530365eucas1p1W; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges2new.samsung.com (EUCPMTA) with SMTP id 79.F5.11320.47211456; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from eusmtrp2.samsung.com (unknown [182.198.249.139]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231031144300eucas1p2c7d05a247469cec1bf3aec978bbd58d1~TOEswInTS1408414084eucas1p2J; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp2.samsung.com (KnoxPortal) with ESMTP id 20231031144300eusmtrp2f4ad919247e63a78b0cb8ab35e93763c~TOEsviMkY2445524455eusmtrp2p; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) X-AuditID: cbfec7f4-993ff70000022c38-6c-65411274787e Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 85.7A.10549.37211456; Tue, 31 Oct 2023 14:42:59 +0000 (GMT) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231031144259eusmtip23b087c17714f9b0cca3c38a0518ca0ac~TOEsMRynK1957719577eusmtip2O; Tue, 31 Oct 2023 14:42:59 +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 v3 1/3] i2c: s3c24xx: fix read transfers in polling mode Date: Tue, 31 Oct 2023 15:42:50 +0100 Message-Id: <20231031144252.2112593-2-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031144252.2112593-1-m.szyprowski@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42LZduznOd0SIcdUg1ufRS0ezNvGZnH/awej xeX92hZ7X29lt+j4+4XRYsb5fUwWa4/cZbe4u38uowOHx6ZVnWwed67tYfPo27KK0ePzJrkA ligum5TUnMyy1CJ9uwSujC3PKwrWc1ZsaDZuYLzJ3sXIySEhYCLxadYDti5GLg4hgRWMEp8P X2aEcL4wSlz7/pYVwvnMKHHw2n82mJYHmx9CJZYzSvxq2MwC13L/yCMWkCo2AUOJrrddYB0i Ag4S89Z+B1vILPCPUeL7Fz0QW1jAQ+Lz9n6mLkYODhYBVYlLU2VAwrwC9hJrXz9hhFgmL7H/ 4FlmkBJOoDErz1RBlAhKnJz5hAViorxE89bZzCAnSAjs4JCYvegiM0Svi0Rj3zsoW1ji1fEt UD/LSPzfOZ8JoqGdUWLB7/tQzgRGiYbnt6A2W0vcOfeLDWQzs4CmxPpd+hBhR4kpPX8YQcIS AnwSN94KQhzBJzFp23RmiDCvREebEES1msSs4+vg1h68cAmqxENi8ZzQCYyKs5B8MwvJN7MQ 1i5gZF7FKJ5aWpybnlpslJdarlecmFtcmpeul5yfu4kRmGJO/zv+ZQfj8lcf9Q4xMnEwHmKU 4GBWEuE9bOqQKsSbklhZlVqUH19UmpNafIhRmoNFSZxXNUU+VUggPbEkNTs1tSC1CCbLxMEp 1cC0VvhcdMlk8/ifCg8UW9cnJem7B3m7qKyb+r43lWdvvvvutdlKt/nD932Sm3VPQPpaLMvZ tSz7d38/7m76+0PkH4VX16Z7/lnLuaPhyE9bd/XKh96aZYdynmznsmty1PedUfPra9FaowZp ZuNr33QvzDcXWXHiQUrezm+7NX0O6tRsnfZaT63+meam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rIrFs j0t7yp7GRv03cDMwuyf5LcFKf0/a/clpCXXflm5LkW/ctUZQx6axPv9u/Mwmg2PGNk0Vyocy HS6davpkabrimND6zSccHmjmnvCb3Lh7hkpowhL234yTH6su4qhQYinOSDTUYi4qTgQAFPia NA8DAAA= X-CMS-MailID: 20231031144300eucas1p2c7d05a247469cec1bf3aec978bbd58d1 X-Msg-Generator: CA X-RootMTR: 20231031144300eucas1p2c7d05a247469cec1bf3aec978bbd58d1 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231031144300eucas1p2c7d05a247469cec1bf3aec978bbd58d1 References: <20231031144252.2112593-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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c index c56886af724e..bcc6afe2ccb5 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -216,8 +216,13 @@ 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)) { + usleep_range(100, 200); + return true; + } + if (tmp & S3C2410_IICCON_IRQPEND) { if (!(readl(i2c->regs + S3C2410_IICSTAT) & S3C2410_IICSTAT_LASTBIT)) return true; From patchwork Tue Oct 31 14:42:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 13441607 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 29D97C0018A for ; Tue, 31 Oct 2023 14:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344241AbjJaOnJ (ORCPT ); Tue, 31 Oct 2023 10:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344312AbjJaOnH (ORCPT ); Tue, 31 Oct 2023 10:43:07 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD135E4 for ; Tue, 31 Oct 2023 07:43:03 -0700 (PDT) Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231031144301euoutp027d8b0f11ed69e8578b1781325c59d5d5~TOEtxMa-o2518725187euoutp02i for ; Tue, 31 Oct 2023 14:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231031144301euoutp027d8b0f11ed69e8578b1781325c59d5d5~TOEtxMa-o2518725187euoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698763381; bh=GcU2ll/TxroeEN8DWXDBWInJsuAQQu6nVNdzAemEqiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Scl+WuxMWSF2zl5lGPxmnCEkOlsEcEEN7EDJ1fFIFJReIfzkicXSsSBa1/aX6o1ni WjUoVKSSfJXhNLAMS+eDFS9pHt7r+RzAjxSfNwcpd9FQPE8MnHGL28sAh0G/bCwOz9 PgKlh3IYLEi0HKc9J7xK8DjYXik4ROrGsBm8X3t4= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231031144300eucas1p284a1d63ba169c8543deb016711e1ac5a~TOEtesviG1408414084eucas1p2K; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id BF.87.52736.47211456; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20231031144300eucas1p1106849fbdedf6eb929647b96c24a7891~TOEtJnpOd3034530345eucas1p1Y; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231031144300eusmtrp11fcf2e3c8b4a2c4c6fca05ba9da47ff7~TOEtI_VBe0253802538eusmtrp1K; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) X-AuditID: cbfec7f5-ba1ff7000000ce00-ca-65411274ce0b Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 53.1A.25043.47211456; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231031144259eusmtip22c885635341d0594803add4a65745945~TOEsq6Lbo1967919679eusmtip2G; Tue, 31 Oct 2023 14:42:59 +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 v3 2/3] i2c: s3c24xx: fix transferring more than one message in polling mode Date: Tue, 31 Oct 2023 15:42:51 +0100 Message-Id: <20231031144252.2112593-3-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031144252.2112593-1-m.szyprowski@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42LZduzned0SIcdUg9d79CwezNvGZnH/awej xeX92hZ7X29lt+j4+4XRYsb5fUwWa4/cZbe4u38uowOHx6ZVnWwed67tYfPo27KK0ePzJrkA ligum5TUnMyy1CJ9uwSujK6ZL5kLukUqzr44wdzAuEmgi5GDQ0LAROLX8YouRi4OIYEVjBIf J79nhHC+MEp8332ACcL5zCjRdv8aexcjJ1jH6ZtXoKqWM0psXXOPHa5ly7bJbCBVbAKGEl1v u8BsEQEHiXlrv4N1Mwv8A5r7RQ9kt7BAnMTTc9YgYRYBVYn7t54xgdi8AvYSt2deYIRYJi+x /+BZZpByTqAxK89UQZQISpyc+YQFYqK8RPPW2cwgJ0gI7OGQmH5nIRNEr4vEqyf9UHOEJV4d 3wL1gIzE6ck9LBAN7YwSC37fZ4JwJjBKNDy/BdVhLXHn3C82kM3MApoS63fpQ8LLUeL3dUkI k0/ixltBiBv4JCZtm84MEeaV6GgTgpihJjHr+Dq4rQcvXGKGsD0kDs78yTSBUXEWkm9mIflm FsLaBYzMqxjFU0uLc9NTi43zUsv1ihNzi0vz0vWS83M3MQKTzOl/x7/uYFzx6qPeIUYmDsZD jBIczEoivIdNHVKFeFMSK6tSi/Lji0pzUosPMUpzsCiJ86qmyKcKCaQnlqRmp6YWpBbBZJk4 OKUamMwce6TWa9hsE3exOPVm4pYrL0r9p83LFWuo2/ey9tySu5nnzQ5aTF9mFZb3pCxr36zn HcGBq3Z3pXSZp9o+NTxcM/n5p4+zf7A/PvgroSOwmu3PF9mH7YZ70sM6n5YeeCj2s5F/UuCp cmOmhG82XoKKKqJeamYLzGZKrBC+qfOq+BLfeT4JY7Y83oJrzzxz7jeatdZHHZiev+2n/6Kn b+az/pD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pxL/eM2cXTRR3CD1hc3md9v/QaucrjAWqUfXBs+e+ XLD+ckCdvMyL09mdXokFF4+seGSm2CPxQ0VD1KaKVf+E7aO+dd9XBfgosRRnJBpqMRcVJwIA ByUlXBEDAAA= X-CMS-MailID: 20231031144300eucas1p1106849fbdedf6eb929647b96c24a7891 X-Msg-Generator: CA X-RootMTR: 20231031144300eucas1p1106849fbdedf6eb929647b96c24a7891 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231031144300eucas1p1106849fbdedf6eb929647b96c24a7891 References: <20231031144252.2112593-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 bcc6afe2ccb5..28114b6aadfa 100644 --- a/drivers/i2c/busses/i2c-s3c2410.c +++ b/drivers/i2c/busses/i2c-s3c2410.c @@ -275,16 +275,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) @@ -690,7 +680,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); @@ -710,16 +700,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 Tue Oct 31 14:42: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: 13441608 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 9F47BC001B2 for ; Tue, 31 Oct 2023 14:43:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344312AbjJaOnK (ORCPT ); Tue, 31 Oct 2023 10:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344319AbjJaOnI (ORCPT ); Tue, 31 Oct 2023 10:43:08 -0400 Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81F52DA for ; Tue, 31 Oct 2023 07:43:06 -0700 (PDT) Received: from eucas1p2.samsung.com (unknown [182.198.249.207]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20231031144301euoutp02d43396ac9501c1672cde822deeb31067~TOEuZn4k82615926159euoutp02N for ; Tue, 31 Oct 2023 14:43:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20231031144301euoutp02d43396ac9501c1672cde822deeb31067~TOEuZn4k82615926159euoutp02N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1698763381; bh=8ON5wqrvWN+W4pHTqNvTNUJDhMTrzS3lgDsmX//DvXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EgELcqH/z4w1DiFJXtrHJqvNNtoOwSQJfm4qWlbRdBvTm4JCp6jlaQphiRwg9JERq 8e8AI/ZOQLFyyibIr+cyKfA4s1PxDezR0IEWdWstXaFTPCE1BLPJTHDO1BjkPFAgZE H11OKGHVMAcYxr0JkXUb/ehA23lfwYHPeta2JbMo= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20231031144301eucas1p27a251b0cd8f345944185efa19d0a471f~TOEt8j1Op1404914049eucas1p2j; Tue, 31 Oct 2023 14:43:01 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 40.97.52736.57211456; Tue, 31 Oct 2023 14:43:01 +0000 (GMT) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p2.samsung.com (KnoxPortal) with ESMTPA id 20231031144300eucas1p2edfb098f7dba134cdfa637abbf632987~TOEtoHii41407714077eucas1p2G; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20231031144300eusmtrp139d98cb873b7cc00247ed2378d82851c~TOEtneF4P0253802538eusmtrp1N; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) X-AuditID: cbfec7f5-bb7ff7000000ce00-cb-65411275de4e Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 54.1A.25043.47211456; Tue, 31 Oct 2023 14:43:00 +0000 (GMT) Received: from AMDC4653.digital.local (unknown [106.120.51.32]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20231031144300eusmtip29456c88c794236613b3e8193051051cd~TOEtIhvbt1643916439eusmtip2s; Tue, 31 Oct 2023 14:43:00 +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 v3 3/3] i2c: s3c24xx: add support for atomic transfers Date: Tue, 31 Oct 2023 15:42:52 +0100 Message-Id: <20231031144252.2112593-4-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231031144252.2112593-1-m.szyprowski@samsung.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAKsWRmVeSWpSXmKPExsWy7djP87qlQo6pBo8WC1g8mLeNzeL+1w5G i8v7tS32vt7KbtHx9wujxYzz+5gs1h65y25xd/9cRgcOj02rOtk87lzbw+bRt2UVo8fnTXIB LFFcNimpOZllqUX6dglcGb9PvGcrWKhU0b3yIksD42rZLkZODgkBE4mG9j1sXYxcHEICKxgl +ju3MkI4XxglNi8+AJX5zCjR/O4nE0zL0hsdTBCJ5Yw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l6Gb9P vGcrWKhU0b3yIksD42rZLkZODgkBE4mlNzqYuhi5OIQEljJKrLmxnBEiISNxcloDK4QtLPHn WhcbRNEnRol/+08wgSTYBAwlut6CJDg5RAScJG4vmsUKUsQs0MQk0XFiEXsXIweHsICbxMzX NiA1LAKqEt/afjCD2LwC9hKbri1hh1ggL7H/4FlmkHJOAQeJlWeqQMJCQCW3TrQzQZQLSpyc +YQFxGYGKm/eOpt5AqPALCSpWUhSCxiZVjGKpJYW56bnFhvpFSfmFpfmpesl5+duYgRGxLZj P7fsYFz56qPeIUYmDsZDjBIczEoivIdNHVKFeFMSK6tSi/Lji0pzUosPMZoCnT2RWUo0OR8Y k3kl8YZmBqaGJmaWBqaWZsZK4ryeBR2JQgLpiSWp2ampBalFMH1MHJxSDUyGgfMn+QnnLI2M WfgldJZho/iBC0mph/eGVmWlr/FN/Bh0OKtLWmD56ZKjB+WzFkae+hmyvlRszz5zxnNMvQox X2yufHBcfsxS/M2RiSnat8Qf3jc5XGM4+aVkOYvZli+M3fMU6hn3aMbHqYVviPhzhXnX01Va bsFVLAXuvv/eLPbbu2zWGtOcwP2HeLovnH3msK7n3IeMsm3vv+oUaD/JZPpdrLov66lxYOgf 7uf8qi9jI0SneyxK0pm1Y9EssU1ir+8Gbcz5u+qh7Zutgsd2cD1YfHl594p5XRLveFsMpVNS 62b/2da5KjnWy2eStc2Pn33B5scEXra6tByzVvrqE3vB7yKXx0qFAEaXZzZKLMUZiYZazEXF iQDf7GfDEQMAAA== X-CMS-MailID: 20231031144300eucas1p2edfb098f7dba134cdfa637abbf632987 X-Msg-Generator: CA X-RootMTR: 20231031144300eucas1p2edfb098f7dba134cdfa637abbf632987 X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20231031144300eucas1p2edfb098f7dba134cdfa637abbf632987 References: <20231031144252.2112593-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 28114b6aadfa..cf55238fca71 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); } @@ -699,7 +700,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); @@ -771,6 +772,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) { @@ -781,6 +797,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, };