From nobody Thu Dec 18 14:46:27 2025 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CC75261369 for ; Mon, 24 Mar 2025 15:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742830458; cv=none; b=mTutkfuIyGZ4WJ1DjpU8fZ5lOdSDFpvFo8PxifHn8YIQtsLITp0SRVlBAEoLjUqrN4p2RJXaEKWrNnySdLX7pDBRtgftl4fMWordB23gMooan4NRG/a+py2t7QIwv5clsofx5wNZutmbyyFh8LcYU6kRyhhO+1husCozSkokJlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742830458; c=relaxed/simple; bh=p+IEHY6sIvNuhaTNsK9FWIQI5zgZXUPtd8JCLrJBLgE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HowOr2VvrLUzz3sjML2zHxbdn+b8309cubCBaL4v3EkBxQQ7IIgtTZbu32+NJtBYGv1lr/3Y3WwTGDKzeY9m8EJm3XfJfOV/RMNbVnEyKQX5+cPzBaFe2smR+dc3Up+7LGsBLonssHBqfMf/vkhltdnR4dONUJmcLUP6Pclxm5w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=JPDDtA3X; arc=none smtp.client-ip=209.85.218.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="JPDDtA3X" Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-ac41514a734so267377166b.2 for ; Mon, 24 Mar 2025 08:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742830453; x=1743435253; darn=vger.kernel.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=xKFz6eLJyqKb87mD6Fpb+y2pLdxHOWnaVFUS6QOxr3U=; b=JPDDtA3X8G312iY7/8My6dM/WbxOZMIAZ5BWxjFabqZfBAX9sDnHDH2YVjhgRMYadr 09OD6CbDAcsXi+E/rjxPo72QMerMB+aNeHDnaiZyJjC8kkmmVp5jvGFdwsnU3UJL1m0O 7WFyG5mbxI2boYo0Sehoxgwyj9QrS2HDTq907+EsotJYeVnF8ZVNxXQb0wLjG9B0tD9a JY/gKyVTtVm/NwhIPmgVTEEjsNjmE9GNP9zjxgN8pGULG/oWXhe7M9pFJtZU0jtGillR nPCvCVSAfBX8bdQXu8x9njD6xno1n5icoKwu9mK9mO68nUZ0wguGhoWqtkS9TTPMG5Oo 1RBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742830453; x=1743435253; 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=xKFz6eLJyqKb87mD6Fpb+y2pLdxHOWnaVFUS6QOxr3U=; b=lCXquu+y65SqTOWSAZ70K8gbN/lL4ENUoGfatA93x7mFmAkDDyYdxLNIz0gUcoc04H meSqMh5BNUchE6ZsBc9uam6OgbjzXK8EtQxRJ7AMQs7DITzMt1DcfXFKZNn1mV+E9r6x /MsaecS10pM2B/8Enk1nW5yKWvRaq30lEhcgjw6fnRwplUJdFT5x7EF8kZ/fwT4RxUFd e7taC6vxFyBtW0WDPifYwi1G9xhsxoueFm7cLpb0N8+E3ZMC5jkKr9lfSAdhXiOXW86a +SqsoZd5Qi/X4C74orHSnUPodJ3xGkM2iOeVlPeABPrNOXJkNserEtB9ULoB7t4CjV+G 7k4g== X-Forwarded-Encrypted: i=1; AJvYcCXxv5dqnTpCjkGGNWA6Z/TBTYm9m0wKbPMAb0grDLDXd4qhGN7KpfjCRptgxHGZRHYlaaisP/KpgtpEU8M=@vger.kernel.org X-Gm-Message-State: AOJu0YzUqSfzpiaX7A5fOMAeTHZLfkp4MJOMLOZBu2Vrw6CaKM96T9d9 gxohmQsWhMpEnj+kprkJ51gWfoDhh+rI7plypXHuuIlrcYdFWopJ1+i4kcCaO54= X-Gm-Gg: ASbGncsXD5grf2eusfz8rYI3wd2pH0mCHIj/t8g6p4hS57UlZtgSkQNfvABZ4btm9f7 sB/WQVCbTako6Y7KkTZtks8WWQ5UbDcepptswpM4CeZXOuYTPVBV9cLmDEIFi3vpzwJea+vCglT nmExfRG83NSUVTugJj6yew5CgU1+7u3wSFiiL//fkpi5NnsXetHc8REh5U7R3oTRLqr1OWCzeQW p6Whbzn5n7Nqd9FHlaXdDJR9C7rNSjR+6Bn+mBOtjCWaH00GQ7xVq8RiC4c0v0rt52nBRrdZ1Dg WJRMZhURUsAPswhIoIRdu2WYHC0/6bZcRhpLrDAc3nn3bvPASOfN1cqCrLDSAHr09wCFV9f1OQ3 HA1XrxSpRYkP9JYchwxYYSKmAO4Zk X-Google-Smtp-Source: AGHT+IErQhBX/WXUMuS2xd0b7MNJeantSHZ2LsehWbVB+frQPoLUYxwOawSJkU4fE0OO3vdYCY7DoQ== X-Received: by 2002:a17:907:3e03:b0:ab7:d87f:665b with SMTP id a640c23a62f3a-ac3f25593b7mr1313444066b.48.1742830453430; Mon, 24 Mar 2025 08:34:13 -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-ac3ef86e44dsm690219466b.31.2025.03.24.08.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Mar 2025 08:34:13 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Mon, 24 Mar 2025 15:34:09 +0000 Subject: [PATCH v2 1/2] firmware: exynos-acpm: use ktime APIs for timeout detection Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250324-acpm-atomic-v2-1-7d87746e1765@linaro.org> References: <20250324-acpm-atomic-v2-0-7d87746e1765@linaro.org> In-Reply-To: <20250324-acpm-atomic-v2-0-7d87746e1765@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 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 without having to adjust the loop counter exit condition. This will come in useful in a follow-up patch that changes the delays. Reviewed-by: Tudor Ambarus Signed-off-by: Andr=C3=A9 Draszik --- 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/sams= ung/exynos-acpm.c index a85b2dbdd9f0d7b1f327f54a0a283e4f32587a98..542eaff03f9e39422a8c5345ca7= 5e05c1710a9ee 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 @@ =20 #define ACPM_PROTOCOL_SEQNUM GENMASK(21, 16) =20 -/* The unit of counter is 20 us. 5000 * 20 =3D 100 ms */ -#define ACPM_POLL_TIMEOUT 5000 +#define ACPM_POLL_TIMEOUT_US (100 * USEC_PER_MSEC) #define ACPM_TX_TIMEOUT_US 500000 =20 #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 =3D achan->acpm->dev; - unsigned int cnt_20us =3D 0; + ktime_t timeout; u32 seqnum; int ret; =20 seqnum =3D FIELD_GET(ACPM_PROTOCOL_SEQNUM, xfer->txd[0]); =20 + timeout =3D ktime_add_us(ktime_get(), ACPM_POLL_TIMEOUT_US); do { ret =3D acpm_get_rx(achan, xfer); if (ret) @@ -300,11 +301,10 @@ static int acpm_dequeue_by_polling(struct acpm_chan *= achan, =20 /* Determined experimentally. */ usleep_range(20, 30); - cnt_20us++; - } while (cnt_20us < ACPM_POLL_TIMEOUT); + } while (ktime_before(ktime_get(), timeout)); =20 - dev_err(dev, "Timeout! ch:%u s:%u bitmap:%lx, cnt_20us =3D %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]); =20 return -ETIME; } --=20 2.49.0.395.g12beb8f557-goog From nobody Thu Dec 18 14:46:27 2025 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CE99826136F for ; Mon, 24 Mar 2025 15:34:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742830457; cv=none; b=KnSI68WAuXuDuhufgAFt00XwcMwp6fX4tYVg0fUsBwemviOGY7hcbV23fcEqt5GvrzF63jSqbgHpXdd6jd/StSzO7a38MWopMnjD3OGOCSntRXJJgPuQJiPAGh7RvGkjQS4ItqxiP1yYKPNihZ3ZLHzMcrucKki90imri0GkIg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742830457; c=relaxed/simple; bh=BbaRiEVNhHM1RZ2ZnJzY8WLo+QoHvZrXazGZXzvdN9M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tU0Aza/RZjqVAJQGc9LnCrWnxaxYxKzuR0XvWDb2qkdIHEc5dDNmu6RAJA7lgw1NPD/7YPg+ZpLsL6W3p/N+0oidlYe1vNC5mmg3uk4LDcXegGbZdiR1MObadLl8V9hM6pC2VybPUK/3rOER/HirpsZ8k9ZcKzo2I6HdpOuvHCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=fqV/Y7gl; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="fqV/Y7gl" Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-ac3eb3fdd2eso706792466b.0 for ; Mon, 24 Mar 2025 08:34:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1742830454; x=1743435254; darn=vger.kernel.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=xRWYwpfb+Qm0/LZ29AYhcqtDsg2o5q/MxVz554Yo+yk=; b=fqV/Y7gl3A+nzJWgWVFe+IEhaRydBSbnkZJDpGei4Pey4zmcC6pUD02drg8L7T22ex Y0mMrBGgvwpbPz/Wmcrz00DrIuzyNBIUN6IEcorfwV2wqi+pd0k2pq14BxnEtS/8FKow PcZonkZPmIYwtwnrousKhUnZuseHLfPjvUXsqZHsEoNjYbhli087vTcZHRIoFJ578G2T PtRZSuinelSo8F+nQ+iS9hXI5K/vcnUf0zhXMF3k1uM4odr0at2iwOoEvAPZwGZvVLHp RACi+X9twz72VX2vud3sP+OeEmEtH9p82HCoJSzhnKzpN24ogQS9ymcWjvqqVR+B9KKQ xMTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742830454; x=1743435254; 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=xRWYwpfb+Qm0/LZ29AYhcqtDsg2o5q/MxVz554Yo+yk=; b=QYme1sC1He4kZcKVutRWlCQ9ctHUSqgH5Q99ZCNt6wj4l46zwSy1He8wYTmbUHSbdy JT4klEdbGIMHR3HSCXYTLBVoadYgPpxVGzYZHPfUL698DgjNdFRetAXWFNEVSpMAMjD4 W3nyGB3sesukSYTtlfUYgBnstxrFMa0Hl/RbWlwvEoNqyxUVCTqnCKXcZ566idAtcOM7 qDU8l2l9w3PCmdk4KSquUtmTiX/bYyTwuEep0sDmjR8HeVNxrJfTf5xKmWYu4Jft7LNX 5iB0nJCtWBxCq1zJlTdy8SWvzqaj3UkX+wSeuBCAuLrKwnXexG3elJufG1yMNCUU7apF 8ppg== X-Forwarded-Encrypted: i=1; AJvYcCV6j/4VWpS0MwA6tTsmKKX6szc4O0dKzFkOkQJ5jEfCcorQySczzvM7n56rxgdtzm5/cmED8IHH2wp/IaA=@vger.kernel.org X-Gm-Message-State: AOJu0YzmvKCoVZ0fvR86tv6jGxKiVsrawg8nEoiqc0nOH4eStz0lgBdx R1hT9L1lL45rjkecuMieITD94M85qy0zJqsLSiN7Fn4SFbxrj8GXmx17+3zbs54= X-Gm-Gg: ASbGncu/UrfnehRwPbYHDC0aANZpEiQb1xHwwNdWt4zkcnuVgHsCqQj4Pjp38ondF3T QtwdB5mzbp5o3xqNA4JdnsxLAidNQEXhWuxE+KFgTz00hXfUuXj8ud7of3fjYvyTF4TqfKdD3hd L0BaREFZQPJBqIpXX7xqEj8ZuPEUqfbhcMaMjLN6UEi2n6Z5GCRApnczJg0eh+pBHtamYXDAH2a sbL6DkHY6VdYv2DOAUJ4wSw7eXb5EnE2pa+fhjWusNeu00qRo6ptV/SrTkMy+OvAOHVixtDyR5A voUViK7foWS2OOHYwd5aidUB0sABWE4jIDy35Q8r5aLAGLMnO1vfoZQTEoHLLFhwFrngktIY427 dbZKRSQjSgEjU/DxG7m48M5E92XEp X-Google-Smtp-Source: AGHT+IFWUzpGuHqazl0dpTOmipY8A50S66wW8ZDj1rQKEydjpZVDbROVxeCvHwm+5oYARuqtOVEg6A== X-Received: by 2002:a17:907:3f9b:b0:ac2:63a9:df0b with SMTP id a640c23a62f3a-ac3f251f206mr1143189666b.35.1742830453945; Mon, 24 Mar 2025 08:34:13 -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-ac3ef86e44dsm690219466b.31.2025.03.24.08.34.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Mar 2025 08:34:13 -0700 (PDT) From: =?utf-8?q?Andr=C3=A9_Draszik?= Date: Mon, 24 Mar 2025 15:34:10 +0000 Subject: [PATCH v2 2/2] firmware: exynos-acpm: allow use during system shutdown Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250324-acpm-atomic-v2-2-7d87746e1765@linaro.org> References: <20250324-acpm-atomic-v2-0-7d87746e1765@linaro.org> In-Reply-To: <20250324-acpm-atomic-v2-0-7d87746e1765@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 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, detect this condition and use busy waiting via udelay() instead of usleep_range() in that situation. The code isn't switched over to udelay() unconditionally so as to not waste resources during normal operation. acpm_may_sleep() was heavily inspired by the I2C subsystem's i2c_in_atomic_xfer_mode(). Reviewed-by: Tudor Ambarus Signed-off-by: Andr=C3=A9 Draszik --- udelay(10) causes a checkpatch warning (it suggests to use usleep_range() instead for usec >=3D 10), but that's exactly what we can not do. Reducing the udelay to be smaller 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 | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/samsung/exynos-acpm.c b/drivers/firmware/sams= ung/exynos-acpm.c index 542eaff03f9e39422a8c5345ca75e05c1710a9ee..4f65f7ef39b5fdbf5bb10f6ee9f= fb78c5e34d8b2 100644 --- a/drivers/firmware/samsung/exynos-acpm.c +++ b/drivers/firmware/samsung/exynos-acpm.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -25,6 +27,7 @@ #include #include #include +#include #include #include =20 @@ -273,6 +276,17 @@ static int acpm_get_rx(struct acpm_chan *achan, const = struct acpm_xfer *xfer) return 0; } =20 +/* + * When ACPM transfers happen very late, e.g. to access a PMIC when poweri= ng + * down, we can not sleep. We do want to sleep in the normal case, though,= to + * avoid wasting CPU cycles! + */ +static bool acpm_may_sleep(void) +{ + return system_state <=3D SYSTEM_RUNNING || + (IS_ENABLED(CONFIG_PREEMPT_COUNT) ? preemptible() : !irqs_disabled()); +} + /** * acpm_dequeue_by_polling() - RX dequeue by polling. * @achan: ACPM channel info. @@ -300,7 +314,10 @@ static int acpm_dequeue_by_polling(struct acpm_chan *a= chan, return 0; =20 /* Determined experimentally. */ - usleep_range(20, 30); + if (!acpm_may_sleep()) + udelay(10); + else + usleep_range(20, 30); } while (ktime_before(ktime_get(), timeout)); =20 dev_err(dev, "Timeout! ch:%u s:%u bitmap:%lx.\n", --=20 2.49.0.395.g12beb8f557-goog