From: Jennifer Berringer <jberring@redhat.com>
To: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>,
Sebastian Reichel <sre@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
Jennifer Berringer <jberring@redhat.com>
Subject: [PATCH v4 2/2] power: reset: nvmem-reboot-mode: support smaller magic
Date: Fri, 28 Feb 2025 13:03:26 -0500 [thread overview]
Message-ID: <20250228180326.256058-3-jberring@redhat.com> (raw)
In-Reply-To: <20250228180326.256058-1-jberring@redhat.com>
Some devices, such as Qualcomm sa8775p, have an nvmem reboot mode cell
that is only 1 byte, which resulted in nvmem_reboot_mode_write() failing
when it attempts to write a 4-byte magic. Checking the nvmem cell size
and writing only the lower bits of the reboot mode magic is needed for
these devices.
Signed-off-by: Jennifer Berringer <jberring@redhat.com>
---
drivers/power/reset/nvmem-reboot-mode.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/power/reset/nvmem-reboot-mode.c b/drivers/power/reset/nvmem-reboot-mode.c
index 41530b70cfc4..112e6cf77d1b 100644
--- a/drivers/power/reset/nvmem-reboot-mode.c
+++ b/drivers/power/reset/nvmem-reboot-mode.c
@@ -20,11 +20,18 @@ static int nvmem_reboot_mode_write(struct reboot_mode_driver *reboot,
unsigned int magic)
{
int ret;
+ u8 *magic_ptr = (u8 *) &magic;
+ size_t cell_size;
struct nvmem_reboot_mode *nvmem_rbm;
nvmem_rbm = container_of(reboot, struct nvmem_reboot_mode, reboot);
+ cell_size = nvmem_cell_size(nvmem_rbm->cell);
- ret = nvmem_cell_write(nvmem_rbm->cell, &magic, sizeof(magic));
+ /* Use magic's low-order bytes when writing to a smaller cell. */
+ if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) && cell_size < sizeof(magic))
+ magic_ptr += sizeof(magic) - cell_size;
+
+ ret = nvmem_cell_write(nvmem_rbm->cell, magic_ptr, MIN(cell_size, sizeof(magic)));
if (ret < 0)
dev_err(reboot->dev, "update reboot mode bits failed\n");
--
2.47.1
prev parent reply other threads:[~2025-02-28 18:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-28 18:03 [PATCH v4 0/2] nvmem-reboot-mode: support small reboot mode magic Jennifer Berringer
2025-02-28 18:03 ` [PATCH v4 1/2] nvmem: core: add nvmem_cell_size() Jennifer Berringer
2025-03-07 17:42 ` Srinivas Kandagatla
2025-03-08 4:38 ` Jennifer Berringer
2025-02-28 18:03 ` Jennifer Berringer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250228180326.256058-3-jberring@redhat.com \
--to=jberring@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sre@kernel.org \
--cc=srinivas.kandagatla@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox