From 293f3a7f5c0bbc2bcf0c09db337a11897cf40d5b Mon Sep 17 00:00:00 2001 From: Kapil Porwal Date: Mon, 24 Nov 2025 22:02:16 +0530 Subject: [PATCH] soc/qc/spmi: Add API to read byte array Introduce a new API, spmi_read_bytes(), to allow reading a sequence of registers from a Qualcomm PMIC using the SPMI bus. While the existing spmi_read8() is suitable for single-byte access, reading large log areas (like the PON history log) requires iterating over a contiguous block of addresses. This new function encapsulates the required loop, calling spmi_read8() sequentially for each address in the range. This abstraction improves code cleanliness and makes high-level PMIC log parsing much simpler. Key changes: - Define spmi_read_bytes() prototype in qcom_spmi.h. - Implement spmi_read_bytes() in spmi.c to perform sequential reads using spmi_read8(). BUG=b:439819922 TEST=Verify off-mode charging behavior on Google/Quenbi. Change-Id: I6017336a882a8fa8d771b0127e78dd4f0fdbdd0e Signed-off-by: Kapil Porwal Reviewed-on: https://review.coreboot.org/c/coreboot/+/90191 Tested-by: build bot (Jenkins) Reviewed-by: Subrata Banik --- src/soc/qualcomm/common/include/soc/qcom_spmi.h | 1 + src/soc/qualcomm/common/spmi.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/soc/qualcomm/common/include/soc/qcom_spmi.h b/src/soc/qualcomm/common/include/soc/qcom_spmi.h index 2c0d9416ab..65d2e17bba 100644 --- a/src/soc/qualcomm/common/include/soc/qcom_spmi.h +++ b/src/soc/qualcomm/common/include/soc/qcom_spmi.h @@ -11,5 +11,6 @@ int spmi_read8(uint32_t addr); int spmi_write8(uint32_t addr, uint8_t data); +int spmi_read_bytes(uint32_t addr, uint8_t *data, uint32_t num_bytes); #endif // __SOC_QCOM_SPMI_H__ diff --git a/src/soc/qualcomm/common/spmi.c b/src/soc/qualcomm/common/spmi.c index 51a37058b0..2409cbbf23 100644 --- a/src/soc/qualcomm/common/spmi.c +++ b/src/soc/qualcomm/common/spmi.c @@ -125,3 +125,19 @@ int spmi_write8(uint32_t addr, uint8_t data) return ret; } + +int spmi_read_bytes(uint32_t addr, uint8_t *data, uint32_t num_bytes) +{ + int spmi_result; + if (!data) + return -1; + + for (uint32_t i = 0; i < num_bytes; i++) { + spmi_result = spmi_read8(addr + i); + if (spmi_result < 0) + return -1; + *data = spmi_result & 0xff; + data++; + } + return 0; +}