From patchwork Tue Mar 25 09:46:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 14028264 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99D32C35FFC for ; Tue, 25 Mar 2025 09:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=22F3uA1pFjUSsqH5uZTrmsJjR2r2mTgeguTTuS3Ky1o=; b=XQjdKU6giOkRrNspyit7hwqzwo aa5aXnWjfCPTShqlX2VF0E2p3gGG++hjfXCfYMbSyIcb6B53IKqXiJr5OFi76VABDxpKoK4Qtc9H/ 91Il9pgXazf+gHQcQRcw7QMgZRQzfgnRuj9Iuybh3Xg1zREK7GnhMI0JqB6CGlkaEHZORZpRxAgSL JncBFMuMyyEwRTizrvcPzM1mfB3uHANkonrN25eV1OW4xqoW2BA11fbW6VF53uk9L/423WjGENHG3 5bcbrMssb358bwXDArDG6VAzNpB2ZRK2yl4oO1yOgtCJicAdFfHGjLfG3GI+3U9J0IpqroxFOY3KN fmDW1egw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tx0ul-00000005M8N-2WQn; Tue, 25 Mar 2025 09:49:43 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tx0rL-00000005LcH-3iO1 for linux-arm-kernel@lists.infradead.org; Tue, 25 Mar 2025 09:46:13 +0000 Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-ac2bb7ca40bso184853866b.3 for ; Tue, 25 Mar 2025 02:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742895970; x=1743500770; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=22F3uA1pFjUSsqH5uZTrmsJjR2r2mTgeguTTuS3Ky1o=; b=Ve6NsjP3b2CGZkrrMp7/xwAqt6z8iK8CDkpYODDqxFEmC9EdA/NDbEnnL9EmE53inX Yf0knW3pnAlE30fBY41yj8EaaRWZ5/H9SGkeiZEVk3KDyc9WpJqxzmFsg8vXAnvbncZ/ iPicCJzvIkdjkxV0QhnivMRX806j2a+zFiiAaLGs+ZcJ6T0f3fr/vOBjZCmFu7yHetfa MHnTWN2Z1swWMT2j1VTLT5APgSGRLvqoXQAs9kToe44AaDgpOkN95Okeklzr+/PRgsU6 qfg/cEFFxi5w7jL8GOXaEMKMP+5bBrijzSjPhBG5pX1VAMahMpIWBeog1ZHy4Ltj1cjb zZSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742895970; x=1743500770; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=22F3uA1pFjUSsqH5uZTrmsJjR2r2mTgeguTTuS3Ky1o=; b=H0LrxcnezJWY+jQTOm6qgxhzf6ndcQKvNjOZHIHidjIXqIRaci0wiu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b4b:b0:ac1:e14a:19d6 with SMTP id a640c23a62f3a-ac3f1e494e8mr1615547566b.0.1742895970048; Tue, 25 Mar 2025 02:46:10 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3ef8e509dsm832834566b.68.2025.03.25.02.46.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 02:46:09 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Tue, 25 Mar 2025 09:46:07 +0000 Subject: [PATCH v3 1/2] firmware: exynos-acpm: use ktime APIs for timeout detection MIME-Version: 1.0 Message-Id: <20250325-acpm-atomic-v3-1-c66aae7df925@linaro.org> References: <20250325-acpm-atomic-v3-0-c66aae7df925@linaro.org> In-Reply-To: <20250325-acpm-atomic-v3-0-c66aae7df925@linaro.org> To: Tudor Ambarus , Krzysztof Kozlowski , Alim Akhtar Cc: Peter Griffin , Will McVicker , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250325_024611_923705_0108383B X-CRM114-Status: GOOD ( 14.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org acpm_dequeue_by_polling() uses a loop counter and assumes that each iteration of the loop takes 20us. It may take longer, though, because usleep_range() may sleep a different amount. Switch to using ktime_get() / ktime_before() to detect the timeout condition more reliably. This change also makes the code easier to follow and it allows us to adjust the sleep if necessary, without having to adjust the loop counter exit condition. Reviewed-by: Tudor Ambarus Signed-off-by: André Draszik --- v3: * slightly reword commit message due to updated patch 2/2 v2: * add missing ktime.h * ktime_before() instead of !ktime_after() (Tudor) --- drivers/firmware/samsung/exynos-acpm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c index a85b2dbdd9f0d7b1f327f54a0a283e4f32587a98..542eaff03f9e39422a8c5345ca75e05c1710a9ee 100644 --- a/drivers/firmware/samsung/exynos-acpm.c +++ b/drivers/firmware/samsung/exynos-acpm.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -32,8 +33,7 @@ #define ACPM_PROTOCOL_SEQNUM GENMASK(21, 16) -/* The unit of counter is 20 us. 5000 * 20 = 100 ms */ -#define ACPM_POLL_TIMEOUT 5000 +#define ACPM_POLL_TIMEOUT_US (100 * USEC_PER_MSEC) #define ACPM_TX_TIMEOUT_US 500000 #define ACPM_GS101_INITDATA_BASE 0xa000 @@ -284,12 +284,13 @@ static int acpm_dequeue_by_polling(struct acpm_chan *achan, const struct acpm_xfer *xfer) { struct device *dev = achan->acpm->dev; - unsigned int cnt_20us = 0; + ktime_t timeout; u32 seqnum; int ret; seqnum = FIELD_GET(ACPM_PROTOCOL_SEQNUM, xfer->txd[0]); + timeout = ktime_add_us(ktime_get(), ACPM_POLL_TIMEOUT_US); do { ret = acpm_get_rx(achan, xfer); if (ret) @@ -300,11 +301,10 @@ static int acpm_dequeue_by_polling(struct acpm_chan *achan, /* Determined experimentally. */ usleep_range(20, 30); - cnt_20us++; - } while (cnt_20us < ACPM_POLL_TIMEOUT); + } while (ktime_before(ktime_get(), timeout)); - dev_err(dev, "Timeout! ch:%u s:%u bitmap:%lx, cnt_20us = %d.\n", - achan->id, seqnum, achan->bitmap_seqnum[0], cnt_20us); + dev_err(dev, "Timeout! ch:%u s:%u bitmap:%lx.\n", + achan->id, seqnum, achan->bitmap_seqnum[0]); return -ETIME; } From patchwork Tue Mar 25 09:46:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andr=C3=A9_Draszik?= X-Patchwork-Id: 14028265 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D4ECC35FFC for ; Tue, 25 Mar 2025 09:51:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=u6Fu6WaKV6UwFUaV1JRbU4BYRYqi9fvopRa8oATbj0Q=; b=pmGkKZIRoRaQ3iSVnlzLbs3vAq pFHk7GFOBse/M3hVhgKWLfRTb9nSK5E4UgRu/2mFpmKtSy6WuIW8gnqg47mgum3kDaNDB/kjoCRL2 am+Al1WhU84BC+Xjc+bLdVuvg/v5qNAqMbX61jhV8nqBpy4BDCSh1kv0wbP1Nu/gCXILH3saxycH9 LxwMrrK+V1kzaeTdcvSJPOpvx203BpWK030UFJ6Y0FLf9Xdc1Y8ql/UKmbs4at+tv/85MxlqTcPCm piDEz/efx8EtQ4vR48TVlMIESYtG6elkCvSidLSdJC6ded7PTGRXOd4ZTBhOSre7orkgYsfKgdr1E OgBUKBKw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tx0wS-00000005MNF-1ADD; Tue, 25 Mar 2025 09:51:28 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tx0rM-00000005LcK-1e0e for linux-arm-kernel@lists.infradead.org; Tue, 25 Mar 2025 09:46:13 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-ac3b12e8518so283047466b.0 for ; Tue, 25 Mar 2025 02:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742895971; x=1743500771; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=u6Fu6WaKV6UwFUaV1JRbU4BYRYqi9fvopRa8oATbj0Q=; b=EFxdlqBiKPZgCHjhxEKkJjEJq2qo3sK37b4Nzt2MzP6XYg0j9VBGuuKST+8RMwDW4t jQjsZQpQQ5KDdkIS5F+uBKOT6vaBh2iHXb57feugW/sSlZNXRIctpbWzD6M49Z75CIcI 8tnGYE2YKEGtivImkhyt8NHzLp6Jr+7/NcIAIaa1L4e2U8HZ3Et0CTvbq0alrmFr5Cru FV0AO0FXSOaFMO6TvuAEp7RtdqHQwt8PZW9zSqgqCuV/4lQS95/wh/OW4/OdHK7IMAYd yPWmHsVw7jz3DxH2ZE4SRfKgyNWcKaYBRH2v/8vgeHVzuhnDhFdbZWvac+/0SIcltyzg XtAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742895971; x=1743500771; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u6Fu6WaKV6UwFUaV1JRbU4BYRYqi9fvopRa8oATbj0Q=; b=w9o+CY/fN8tB4HEHG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KEbwQxhd5ygBBxnoQ== X-Received: by 2002:a17:906:4795:b0:ac3:b372:6d10 with SMTP id a640c23a62f3a-ac3f2081eaamr1405346066b.4.1742895970561; Tue, 25 Mar 2025 02:46:10 -0700 (PDT) Received: from puffmais.c.googlers.com (8.239.204.35.bc.googleusercontent.com. [35.204.239.8]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3ef8e509dsm832834566b.68.2025.03.25.02.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Mar 2025 02:46:10 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Tue, 25 Mar 2025 09:46:08 +0000 Subject: [PATCH v3 2/2] firmware: exynos-acpm: allow use during system shutdown MIME-Version: 1.0 Message-Id: <20250325-acpm-atomic-v3-2-c66aae7df925@linaro.org> References: <20250325-acpm-atomic-v3-0-c66aae7df925@linaro.org> In-Reply-To: <20250325-acpm-atomic-v3-0-c66aae7df925@linaro.org> To: Tudor Ambarus , Krzysztof Kozlowski , Alim Akhtar Cc: Peter Griffin , Will McVicker , kernel-team@android.com, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, =?utf-8?q?Andr=C3=A9_Draszik?= X-Mailer: b4 0.14.2 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250325_024612_427659_B8FB94BE X-CRM114-Status: GOOD ( 15.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org We need to access the PMIC during late system shutdown and at that time we are not allowed to sleep anymore. To make this case work, and since we can't detect this case in a non-racy way, switch to using udelay() unconditionally, instead of usleep_range(). Signed-off-by: André Draszik --- v3: * use udelay() unconditionally (Krzysztof) * drop previous Rb tag udelay(20) causes a checkpatch --strict warning (it suggests to use usleep_range() instead for usec >= 10), but that's exactly what we can not do. Reducing the udelay to be smaller than 10 will generally cause the loop to be iterated more than once, which I wanted to avoid. I could reflow the code to hide the actual value from checkpatch, e.g. with the help of a local variable if that is preferred to ignoring the checkpatch warning. --- drivers/firmware/samsung/exynos-acpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/samsung/exynos-acpm.c index 542eaff03f9e39422a8c5345ca75e05c1710a9ee..379da420b9eb3fcbca5461bec7e2de6bf0774659 100644 --- a/drivers/firmware/samsung/exynos-acpm.c +++ b/drivers/firmware/samsung/exynos-acpm.c @@ -300,7 +300,7 @@ static int acpm_dequeue_by_polling(struct acpm_chan *achan, return 0; /* Determined experimentally. */ - usleep_range(20, 30); + udelay(20); } while (ktime_before(ktime_get(), timeout)); dev_err(dev, "Timeout! ch:%u s:%u bitmap:%lx.\n",