* [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support.
@ 2026-07-28 9:28 Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
` (6 more replies)
0 siblings, 7 replies; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein, Alba Mendez
The SPMI bus has grown additional responsibilities in the M3
generation, making the current driver insufficient. Add M3 comatibles,
support for slave-sent interrupts, FIFO interrupts, power management
commands, parity validation, and fix locking.
To simplify the merge strategy, the device tree entries will be sent
in a future patch series.
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
Changes in v2:
- Change locking to non-interruptible
- Reorder irq ack
- Clarify dt binding
- Some data type cleanups
- Link to v1: https://patch.msgid.link/20260725-t603x-spmi-v1-0-e1a29fcd2d38@chaosmail.tech
---
Alba Mendez (6):
spmi: apple: Validate FIFO state
spmi: apple: check transaction status
spmi: apple: Implement remaining commands
spmi: apple: lock around FIFOs
spmi: apple: use IRQ for RX FIFO if possible
spmi: apple: interrupt controller functionality
Sasha Finkelstein (1):
dt-bindings: spmi: apple,spmi: Add t603x
Documentation/devicetree/bindings/spmi/apple,spmi.yaml | 14 +++++
drivers/spmi/Kconfig | 3 +-
drivers/spmi/spmi-apple-controller.c | 362 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------
3 files changed, 349 insertions(+), 30 deletions(-)
---
base-commit: 0ce37745d4bfbc493f718169c3974898ffec8ee7
change-id: 20260725-t603x-spmi-74630bf1b0a0
Best regards,
--
Sasha Finkelstein <k@chaosmail.tech>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
@ 2026-07-28 9:28 ` Sasha Finkelstein
2026-07-28 9:33 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 2/7] spmi: apple: Validate FIFO state Sasha Finkelstein
` (5 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein
Add t603x compatibles, interrupt support, and support for SPMI
controllers that are not always-on.
Keeping the "interrupt-controller" property as optional, as taking the
j514c as an example, we only need this functionality on 3 out of 10
SPMI controllers present on this SoC.
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
Documentation/devicetree/bindings/spmi/apple,spmi.yaml | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml
index 3e5b14bc8c31..9fc511bb0cb8 100644
--- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml
+++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml
@@ -20,6 +20,8 @@ properties:
- items:
- enum:
- apple,t6020-spmi
+ - apple,t6030-spmi
+ - apple,t6031-spmi
- apple,t8012-spmi
- apple,t8015-spmi
- const: apple,t8103-spmi
@@ -34,6 +36,18 @@ properties:
reg:
maxItems: 1
+ interrupts:
+ maxItems: 1
+ description: Optional, operates in polled mode if not present
+
+ interrupt-controller: true
+
+ "#interrupt-cells":
+ const: 2
+
+ power-domains:
+ maxItems: 1
+
required:
- compatible
- reg
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 2/7] spmi: apple: Validate FIFO state
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
@ 2026-07-28 9:28 ` Sasha Finkelstein
2026-07-28 9:41 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 3/7] spmi: apple: check transaction status Sasha Finkelstein
` (4 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein, Alba Mendez
From: Alba Mendez <me@alba.sh>
Check for data before reading the body of a reply, and check for
end of data afterwards.
Signed-off-by: Alba Mendez <me@alba.sh>
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
drivers/spmi/spmi-apple-controller.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
index 376cf682c43e..b4f442d0b4ad 100644
--- a/drivers/spmi/spmi-apple-controller.c
+++ b/drivers/spmi/spmi-apple-controller.c
@@ -78,6 +78,10 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
/* Read SPMI data reply */
while (len_read < len) {
+ if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
+ dev_err(&ctrl->dev, "FIFO lacks reply data, controller stuck?\n");
+ return -EIO;
+ }
rsp = readl(spmi->regs + SPMI_RSP_REG);
i = 0;
while ((len_read < len) && (i < 4)) {
@@ -86,6 +90,9 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
}
}
+ if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
+ dev_warn(&ctrl->dev, "FIFO has extra data\n");
+
return 0;
}
@@ -115,6 +122,9 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
/* Discard */
readl(spmi->regs + SPMI_RSP_REG);
+ if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
+ dev_warn(&ctrl->dev, "FIFO has extra data\n");
+
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 3/7] spmi: apple: check transaction status
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 2/7] spmi: apple: Validate FIFO state Sasha Finkelstein
@ 2026-07-28 9:28 ` Sasha Finkelstein
2026-07-28 9:41 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 4/7] spmi: apple: Implement remaining commands Sasha Finkelstein
` (3 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein, Alba Mendez
From: Alba Mendez <me@alba.sh>
Check for parity errors and missing command ACKs
Signed-off-by: Alba Mendez <me@alba.sh>
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
drivers/spmi/spmi-apple-controller.c | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
index b4f442d0b4ad..4678a9e5270a 100644
--- a/drivers/spmi/spmi-apple-controller.c
+++ b/drivers/spmi/spmi-apple-controller.c
@@ -22,6 +22,12 @@
#define SPMI_CMD_REG 0x4
#define SPMI_RSP_REG 0x8
+/* SPMI_RSP_REG reply word */
+#define SPMI_REPLY_FRAME_PARITY_OFFSET 16
+#define SPMI_REPLY_ACK BIT(15)
+#define SPMI_REPLY_SLAVE_ID GENMASK(14, 8)
+#define SPMI_REPLY_CMD GENMASK(7, 0)
+
#define SPMI_RX_FIFO_EMPTY BIT(24)
#define REG_POLL_INTERVAL_US 10000
@@ -62,7 +68,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
{
struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
- u32 rsp;
+ u32 reply, rsp;
size_t len_read = 0;
u8 i;
int ret;
@@ -73,8 +79,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
if (ret)
return ret;
- /* Discard SPMI reply status */
- readl(spmi->regs + SPMI_RSP_REG);
+ reply = readl(spmi->regs + SPMI_RSP_REG);
/* Read SPMI data reply */
while (len_read < len) {
@@ -93,6 +98,10 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
dev_warn(&ctrl->dev, "FIFO has extra data\n");
+ if ((~reply >> SPMI_REPLY_FRAME_PARITY_OFFSET) & ((1 << len) - 1)) {
+ dev_err(&ctrl->dev, "some frames failed parity check\n");
+ return -EIO;
+ }
return 0;
}
@@ -101,6 +110,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
{
struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
+ u32 reply;
size_t i = 0, j;
int ret;
@@ -119,12 +129,15 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
if (ret)
return ret;
- /* Discard */
- readl(spmi->regs + SPMI_RSP_REG);
+ reply = readl(spmi->regs + SPMI_RSP_REG);
if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
dev_warn(&ctrl->dev, "FIFO has extra data\n");
+ if (!(reply & SPMI_REPLY_ACK)) {
+ dev_err(&ctrl->dev, "command not acknowledged\n");
+ return -EIO;
+ }
return 0;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 4/7] spmi: apple: Implement remaining commands
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
` (2 preceding siblings ...)
2026-07-28 9:28 ` [PATCH v2 3/7] spmi: apple: check transaction status Sasha Finkelstein
@ 2026-07-28 9:28 ` Sasha Finkelstein
2026-07-28 9:46 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 5/7] spmi: apple: lock around FIFOs Sasha Finkelstein
` (2 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein, Alba Mendez
From: Alba Mendez <me@alba.sh>
Add support for zero write and power management commands
Signed-off-by: Alba Mendez <me@alba.sh>
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
drivers/spmi/spmi-apple-controller.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 68 insertions(+), 38 deletions(-)
diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
index 4678a9e5270a..aed18b7df15c 100644
--- a/drivers/spmi/spmi-apple-controller.c
+++ b/drivers/spmi/spmi-apple-controller.c
@@ -41,9 +41,9 @@ struct apple_spmi {
readl_poll_timeout((spmi)->regs + (reg), (val), (cond), \
REG_POLL_INTERVAL_US, REG_POLL_TIMEOUT_US)
-static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 saddr, size_t len)
+static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 param)
{
- return opc | sid << 8 | saddr << 16 | (len - 1) | (1 << 15);
+ return opc | sid << 8 | (u32)param << 16 | (1 << 15);
}
/* Wait for Rx FIFO to have something */
@@ -63,18 +63,27 @@ static int apple_spmi_wait_rx_not_empty(struct spmi_controller *ctrl)
return 0;
}
-static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
- u16 saddr, u8 *buf, size_t len)
+static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
+ u16 param, const u8 *buf, size_t len, u8 *ibuf, size_t ilen)
{
struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
- u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
+ u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, param);
u32 reply, rsp;
size_t len_read = 0;
- u8 i;
+ size_t i = 0, j;
int ret;
writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
+ while (i < len) {
+ j = 0;
+ spmi_cmd = 0;
+ while ((j < 4) & (i < len))
+ spmi_cmd |= buf[i++] << (j++ * 8);
+
+ writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
+ }
+
ret = apple_spmi_wait_rx_not_empty(ctrl);
if (ret)
return ret;
@@ -82,15 +91,15 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
reply = readl(spmi->regs + SPMI_RSP_REG);
/* Read SPMI data reply */
- while (len_read < len) {
+ while (len_read < ilen) {
if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
dev_err(&ctrl->dev, "FIFO lacks reply data, controller stuck?\n");
return -EIO;
}
rsp = readl(spmi->regs + SPMI_RSP_REG);
i = 0;
- while ((len_read < len) && (i < 4)) {
- buf[len_read++] = ((0xff << (8 * i)) & rsp) >> (8 * i);
+ while ((len_read < ilen) && (i < 4)) {
+ ibuf[len_read++] = ((0xffU << (8 * i)) & rsp) >> (8 * i);
i += 1;
}
}
@@ -98,47 +107,67 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
dev_warn(&ctrl->dev, "FIFO has extra data\n");
- if ((~reply >> SPMI_REPLY_FRAME_PARITY_OFFSET) & ((1 << len) - 1)) {
+ if (!ilen && !(reply & SPMI_REPLY_ACK)) {
+ dev_err(&ctrl->dev, "command not acknowledged\n");
+ return -EIO;
+ }
+ if ((~reply >> SPMI_REPLY_FRAME_PARITY_OFFSET) & ((1 << ilen) - 1)) {
dev_err(&ctrl->dev, "some frames failed parity check\n");
return -EIO;
}
return 0;
}
-static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
- u16 saddr, const u8 *buf, size_t len)
+/* Send a raw command with 1..16 input data frames */
+static int spmi_raw_cmd_input(struct spmi_controller *ctrl, u8 opc, u8 sid,
+ u16 param, u8 *buf, size_t len)
{
- struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
- u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
- u32 reply;
- size_t i = 0, j;
- int ret;
-
- writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
+ return spmi_raw_cmd(ctrl, opc, sid, param, NULL, 0, buf, len);
+}
- while (i < len) {
- j = 0;
- spmi_cmd = 0;
- while ((j < 4) & (i < len))
- spmi_cmd |= buf[i++] << (j++ * 8);
+/* Send a raw command with (optional) body and an input ACK */
+static int spmi_raw_cmd_ack(struct spmi_controller *ctrl, u8 opc, u8 sid,
+ u16 param, const u8 *buf, size_t len)
+{
+ return spmi_raw_cmd(ctrl, opc, sid, param, buf, len, NULL, 0);
+}
- writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
+static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
+ u16 saddr, u8 *buf, size_t len)
+{
+ switch (opc) {
+ case SPMI_CMD_EXT_READ:
+ case SPMI_CMD_EXT_READL:
+ return spmi_raw_cmd_input(ctrl, opc | (len - 1), sid, saddr, buf, len);
+ case SPMI_CMD_READ:
+ return spmi_raw_cmd_input(ctrl, opc | saddr, sid, saddr, buf, len);
}
+ return -EINVAL;
+}
- ret = apple_spmi_wait_rx_not_empty(ctrl);
- if (ret)
- return ret;
-
- reply = readl(spmi->regs + SPMI_RSP_REG);
-
- if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
- dev_warn(&ctrl->dev, "FIFO has extra data\n");
-
- if (!(reply & SPMI_REPLY_ACK)) {
- dev_err(&ctrl->dev, "command not acknowledged\n");
- return -EIO;
+static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
+ u16 saddr, const u8 *buf, size_t len)
+{
+ switch (opc) {
+ case SPMI_CMD_WRITE:
+ return spmi_raw_cmd_ack(ctrl, opc | saddr, sid, buf[0] << 8 | saddr, NULL, 0);
+ case SPMI_CMD_ZERO_WRITE:
+ return spmi_raw_cmd_ack(ctrl, opc | buf[0], sid, buf[0] << 8 | saddr, NULL, 0);
+ case SPMI_CMD_EXT_WRITE:
+ case SPMI_CMD_EXT_WRITEL:
+ return spmi_raw_cmd_ack(ctrl, opc | (len - 1), sid, saddr, buf, len);
}
- return 0;
+ return -EINVAL;
+}
+
+static int spmi_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid)
+{
+ if (
+ opc == SPMI_CMD_RESET || opc == SPMI_CMD_SLEEP ||
+ opc == SPMI_CMD_SHUTDOWN || opc == SPMI_CMD_WAKEUP
+ )
+ return spmi_raw_cmd_ack(ctrl, opc, sid, 0, NULL, 0);
+ return -EINVAL;
}
static int apple_spmi_probe(struct platform_device *pdev)
@@ -161,6 +190,7 @@ static int apple_spmi_probe(struct platform_device *pdev)
ctrl->read_cmd = spmi_read_cmd;
ctrl->write_cmd = spmi_write_cmd;
+ ctrl->cmd = spmi_cmd;
ret = devm_spmi_controller_add(&pdev->dev, ctrl);
if (ret)
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 5/7] spmi: apple: lock around FIFOs
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
` (3 preceding siblings ...)
2026-07-28 9:28 ` [PATCH v2 4/7] spmi: apple: Implement remaining commands Sasha Finkelstein
@ 2026-07-28 9:28 ` Sasha Finkelstein
2026-07-28 9:37 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 7/7] spmi: apple: interrupt controller functionality Sasha Finkelstein
6 siblings, 1 reply; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein, Alba Mendez
From: Alba Mendez <me@alba.sh>
The driver was missing locking around register interactions
Signed-off-by: Alba Mendez <me@alba.sh>
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
drivers/spmi/spmi-apple-controller.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
index aed18b7df15c..2cd4ed1803d4 100644
--- a/drivers/spmi/spmi-apple-controller.c
+++ b/drivers/spmi/spmi-apple-controller.c
@@ -14,6 +14,7 @@
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/platform_device.h>
#include <linux/spmi.h>
@@ -35,6 +36,7 @@
struct apple_spmi {
void __iomem *regs;
+ struct mutex fifo_lock;
};
#define poll_reg(spmi, reg, val, cond) \
@@ -73,6 +75,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
size_t i = 0, j;
int ret;
+ mutex_lock(&spmi->fifo_lock);
+
writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
while (i < len) {
@@ -86,7 +90,7 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
ret = apple_spmi_wait_rx_not_empty(ctrl);
if (ret)
- return ret;
+ goto out;
reply = readl(spmi->regs + SPMI_RSP_REG);
@@ -94,7 +98,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
while (len_read < ilen) {
if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
dev_err(&ctrl->dev, "FIFO lacks reply data, controller stuck?\n");
- return -EIO;
+ ret = -EIO;
+ goto out;
}
rsp = readl(spmi->regs + SPMI_RSP_REG);
i = 0;
@@ -107,6 +112,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
dev_warn(&ctrl->dev, "FIFO has extra data\n");
+ mutex_unlock(&spmi->fifo_lock);
+
if (!ilen && !(reply & SPMI_REPLY_ACK)) {
dev_err(&ctrl->dev, "command not acknowledged\n");
return -EIO;
@@ -116,6 +123,10 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
return -EIO;
}
return 0;
+
+out:
+ mutex_unlock(&spmi->fifo_lock);
+ return ret;
}
/* Send a raw command with 1..16 input data frames */
@@ -181,6 +192,7 @@ static int apple_spmi_probe(struct platform_device *pdev)
return -ENOMEM;
spmi = spmi_controller_get_drvdata(ctrl);
+ mutex_init(&spmi->fifo_lock);
spmi->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(spmi->regs))
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
` (4 preceding siblings ...)
2026-07-28 9:28 ` [PATCH v2 5/7] spmi: apple: lock around FIFOs Sasha Finkelstein
@ 2026-07-28 9:28 ` Sasha Finkelstein
2026-07-28 9:42 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 7/7] spmi: apple: interrupt controller functionality Sasha Finkelstein
6 siblings, 1 reply; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein, Alba Mendez
From: Alba Mendez <me@alba.sh>
The IRQ fires as soon as the reply is available, which is usually takes
a few us instead of the 10ms sleep interval for polling
Signed-off-by: Alba Mendez <me@alba.sh>
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
drivers/spmi/spmi-apple-controller.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 93 insertions(+), 1 deletion(-)
diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
index 2cd4ed1803d4..109c5d2c735d 100644
--- a/drivers/spmi/spmi-apple-controller.c
+++ b/drivers/spmi/spmi-apple-controller.c
@@ -11,6 +11,8 @@
* spmi-pmic-arb.c Copyright (c) 2021, The Linux Foundation.
*/
+#include <linux/completion.h>
+#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/module.h>
@@ -23,6 +25,12 @@
#define SPMI_CMD_REG 0x4
#define SPMI_RSP_REG 0x8
+#define SPMI_IRQ_MASK_BASE 0x20
+#define SPMI_IRQ_ACK_BASE 0x60
+#define SPMI_IRQ_USER_SIZE 0x20
+
+#define SPMI_IRQ_FIFO_RX 0
+
/* SPMI_RSP_REG reply word */
#define SPMI_REPLY_FRAME_PARITY_OFFSET 16
#define SPMI_REPLY_ACK BIT(15)
@@ -37,6 +45,8 @@
struct apple_spmi {
void __iomem *regs;
struct mutex fifo_lock;
+ bool fifo_rx_irq;
+ struct completion fifo_rx;
};
#define poll_reg(spmi, reg, val, cond) \
@@ -55,7 +65,19 @@ static int apple_spmi_wait_rx_not_empty(struct spmi_controller *ctrl)
int ret;
u32 status;
- ret = poll_reg(spmi, SPMI_STATUS_REG, status, !(status & SPMI_RX_FIFO_EMPTY));
+ if (spmi->fifo_rx_irq) {
+ ret = wait_for_completion_timeout(&spmi->fifo_rx,
+ usecs_to_jiffies(REG_POLL_TIMEOUT_US));
+ if (!ret)
+ ret = -ETIMEDOUT;
+ else if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY)
+ ret = -EIO;
+ else
+ ret = 0;
+ } else {
+ ret = poll_reg(spmi, SPMI_STATUS_REG, status, !(status & SPMI_RX_FIFO_EMPTY));
+ }
+
if (ret) {
dev_err(&ctrl->dev,
"failed to wait for RX FIFO not empty\n");
@@ -77,6 +99,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
mutex_lock(&spmi->fifo_lock);
+ reinit_completion(&spmi->fifo_rx);
+
writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
while (i < len) {
@@ -181,10 +205,68 @@ static int spmi_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid)
return -EINVAL;
}
+static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq)
+{
+ u32 __iomem *reg = spmi->regs + SPMI_IRQ_ACK_BASE + (irq / 32) * 4;
+
+ writel(BIT(irq % 32), reg);
+}
+
+static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq)
+{
+ u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4;
+
+ writel(readl(reg) & ~BIT(irq % 32), reg);
+}
+
+static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq)
+{
+ u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4;
+
+ writel(readl(reg) | BIT(irq % 32), reg);
+}
+
+static irqreturn_t apple_spmi_irq_handler(int irq, void *dev_id)
+{
+ struct apple_spmi *spmi = dev_id;
+ bool handled = false;
+ u32 val;
+
+ val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + SPMI_IRQ_USER_SIZE);
+ if (val & BIT(SPMI_IRQ_FIFO_RX)) {
+ apple_spmi_irq_ack_raw(spmi, SPMI_IRQ_USER_SIZE * 8 + SPMI_IRQ_FIFO_RX);
+ complete(&spmi->fifo_rx);
+ handled = true;
+ }
+
+ return handled ? IRQ_HANDLED : IRQ_NONE;
+}
+
+static int apple_spmi_init_irq(struct platform_device *pdev,
+ struct apple_spmi *spmi, int irq)
+{
+ int ret;
+
+ for (size_t offset = 0; offset < SPMI_IRQ_USER_SIZE + 4; offset += 4) {
+ writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset);
+ writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset);
+ }
+
+ spmi->fifo_rx_irq = true;
+ apple_spmi_irq_unmask_raw(spmi, SPMI_IRQ_USER_SIZE * 8 + SPMI_IRQ_FIFO_RX);
+
+ ret = devm_request_any_context_irq(&pdev->dev, irq, apple_spmi_irq_handler, 0, NULL, spmi);
+ if (ret < 0)
+ return dev_err_probe(&pdev->dev, ret, "failed to request IRQ\n");
+
+ return 0;
+}
+
static int apple_spmi_probe(struct platform_device *pdev)
{
struct apple_spmi *spmi;
struct spmi_controller *ctrl;
+ int irq;
int ret;
ctrl = devm_spmi_controller_alloc(&pdev->dev, sizeof(*spmi));
@@ -193,6 +275,7 @@ static int apple_spmi_probe(struct platform_device *pdev)
spmi = spmi_controller_get_drvdata(ctrl);
mutex_init(&spmi->fifo_lock);
+ init_completion(&spmi->fifo_rx);
spmi->regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(spmi->regs))
@@ -204,6 +287,15 @@ static int apple_spmi_probe(struct platform_device *pdev)
ctrl->write_cmd = spmi_write_cmd;
ctrl->cmd = spmi_cmd;
+ irq = platform_get_irq_optional(pdev, 0);
+ if (irq < 0 && irq != -ENXIO)
+ return irq;
+ if (irq >= 0) {
+ ret = apple_spmi_init_irq(pdev, spmi, irq);
+ if (ret)
+ return ret;
+ }
+
ret = devm_spmi_controller_add(&pdev->dev, ctrl);
if (ret)
return dev_err_probe(&pdev->dev, ret,
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH v2 7/7] spmi: apple: interrupt controller functionality
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
` (5 preceding siblings ...)
2026-07-28 9:28 ` [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible Sasha Finkelstein
@ 2026-07-28 9:28 ` Sasha Finkelstein
2026-07-28 9:40 ` sashiko-bot
6 siblings, 1 reply; 15+ messages in thread
From: Sasha Finkelstein @ 2026-07-28 9:28 UTC (permalink / raw)
To: Sven Peter, Janne Grunau, Neal Gompa, Stephen Boyd, Rob Herring,
Krzysztof Kozlowski, Conor Dooley
Cc: asahi, linux-arm-kernel, linux-kernel, devicetree,
Sasha Finkelstein, Alba Mendez
From: Alba Mendez <me@alba.sh>
Add support for interrupts sent by slave devices.
Signed-off-by: Alba Mendez <me@alba.sh>
Signed-off-by: Sasha Finkelstein <k@chaosmail.tech>
---
drivers/spmi/Kconfig | 3 ++-
drivers/spmi/spmi-apple-controller.c | 149 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 150 insertions(+), 2 deletions(-)
diff --git a/drivers/spmi/Kconfig b/drivers/spmi/Kconfig
index a80cf4047b86..7243863a09b4 100644
--- a/drivers/spmi/Kconfig
+++ b/drivers/spmi/Kconfig
@@ -13,7 +13,8 @@ if SPMI
config SPMI_APPLE
tristate "Apple SoC SPMI Controller platform driver"
- depends on ARCH_APPLE || COMPILE_TEST
+ select IRQ_DOMAIN_HIERARCHY
+ depends on ARCH_APPLE || (COMPILE_TEST && 64BIT)
help
If you say yes to this option, support will be included for the
SPMI controller present on many Apple SoCs, including the
diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
index 109c5d2c735d..8f6a0d560da8 100644
--- a/drivers/spmi/spmi-apple-controller.c
+++ b/drivers/spmi/spmi-apple-controller.c
@@ -15,9 +15,12 @@
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/iopoll.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/platform_device.h>
+#include <linux/spinlock.h>
#include <linux/spmi.h>
/* SPMI Controller Registers */
@@ -47,6 +50,9 @@ struct apple_spmi {
struct mutex fifo_lock;
bool fifo_rx_irq;
struct completion fifo_rx;
+ struct irq_domain *irqd;
+ raw_spinlock_t irq_mask_lock;
+ u64 irq_mask_cache[SPMI_IRQ_USER_SIZE / sizeof(u64)];
};
#define poll_reg(spmi, reg, val, cond) \
@@ -226,11 +232,123 @@ static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq)
writel(readl(reg) | BIT(irq % 32), reg);
}
+static void apple_spmi_irq_ack(struct irq_data *d)
+{
+ struct apple_spmi *spmi = irq_data_get_irq_chip_data(d);
+
+ apple_spmi_irq_ack_raw(spmi, d->hwirq);
+}
+
+static void apple_spmi_irq_mask(struct irq_data *d)
+{
+ struct apple_spmi *spmi = irq_data_get_irq_chip_data(d);
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags);
+ apple_spmi_irq_mask_raw(spmi, d->hwirq);
+ spmi->irq_mask_cache[d->hwirq / 64] &= ~BIT_ULL(d->hwirq % 64);
+ raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags);
+}
+
+static void apple_spmi_irq_unmask(struct irq_data *d)
+{
+ struct apple_spmi *spmi = irq_data_get_irq_chip_data(d);
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags);
+ apple_spmi_irq_unmask_raw(spmi, d->hwirq);
+ spmi->irq_mask_cache[d->hwirq / 64] |= BIT_ULL(d->hwirq % 64);
+ raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags);
+}
+
+static int apple_spmi_irq_set_type(struct irq_data *d, unsigned int type)
+{
+ /* all interrupts have MSI semantics */
+ return type == IRQ_TYPE_EDGE_RISING ? 0 : -EINVAL;
+}
+
+static struct irq_chip apple_spmi_irq_chip = {
+ .name = "apple_spmi",
+ .irq_mask = apple_spmi_irq_mask,
+ .irq_unmask = apple_spmi_irq_unmask,
+ .irq_ack = apple_spmi_irq_ack,
+ .irq_set_type = apple_spmi_irq_set_type,
+ .flags = IRQCHIP_ONESHOT_SAFE,
+};
+
+static int apple_spmi_irq_domain_map(struct irq_domain *irqd,
+ unsigned int irq, irq_hw_number_t hw)
+{
+ irq_domain_set_info(irqd, irq, hw, &apple_spmi_irq_chip, irqd->host_data,
+ handle_edge_irq, NULL, NULL);
+ return 0;
+}
+
+static int apple_spmi_irq_domain_translate(struct irq_domain *irqd,
+ struct irq_fwspec *fwspec,
+ unsigned long *hwirq,
+ unsigned int *type)
+{
+ u32 *args = fwspec->param;
+
+ if (fwspec->param_count != 2)
+ return -EINVAL;
+
+ if (args[0] >= SPMI_IRQ_USER_SIZE * 8)
+ return -EINVAL;
+ *hwirq = args[0];
+ *type = args[1] & IRQ_TYPE_SENSE_MASK;
+ return 0;
+}
+
+static int apple_spmi_irq_domain_alloc(struct irq_domain *irqd, unsigned int virq,
+ unsigned int nr_irqs, void *arg)
+{
+ unsigned int type = IRQ_TYPE_NONE;
+ struct irq_fwspec *fwspec = arg;
+ irq_hw_number_t hwirq;
+ int i, ret;
+
+ ret = apple_spmi_irq_domain_translate(irqd, fwspec, &hwirq, &type);
+ if (ret)
+ return ret;
+
+ if (hwirq + nr_irqs > SPMI_IRQ_USER_SIZE * 8)
+ return -EINVAL;
+
+ for (i = 0; i < nr_irqs; i++) {
+ ret = apple_spmi_irq_domain_map(irqd, virq + i, hwirq + i);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
+static void apple_spmi_irq_domain_free(struct irq_domain *irqd, unsigned int virq,
+ unsigned int nr_irqs)
+{
+ int i;
+
+ for (i = 0; i < nr_irqs; i++) {
+ struct irq_data *d = irq_domain_get_irq_data(irqd, virq + i);
+
+ irq_set_handler(virq + i, NULL);
+ irq_domain_reset_irq_data(d);
+ }
+}
+
+static const struct irq_domain_ops apple_spmi_irq_domain_ops = {
+ .translate = apple_spmi_irq_domain_translate,
+ .alloc = apple_spmi_irq_domain_alloc,
+ .free = apple_spmi_irq_domain_free,
+};
+
static irqreturn_t apple_spmi_irq_handler(int irq, void *dev_id)
{
struct apple_spmi *spmi = dev_id;
bool handled = false;
- u32 val;
+ u64 val, offset, bit;
val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + SPMI_IRQ_USER_SIZE);
if (val & BIT(SPMI_IRQ_FIFO_RX)) {
@@ -239,6 +357,23 @@ static irqreturn_t apple_spmi_irq_handler(int irq, void *dev_id)
handled = true;
}
+ for (offset = 0; offset < SPMI_IRQ_USER_SIZE; offset += sizeof(val)) {
+ val = readq(spmi->regs + SPMI_IRQ_ACK_BASE + offset);
+ /**
+ * because of other masters in the bus, we're going to get a multitude of
+ * interrupts we're not interested in. irq_resolve_mapping isn't very
+ * optimized for the nonexistent path, so instead we mask with (a locally
+ * cached version of) the IRQ mask
+ */
+ val &= spmi->irq_mask_cache[offset / sizeof(val)];
+ while (val) {
+ bit = __builtin_ctzll(val);
+ generic_handle_domain_irq(spmi->irqd, offset * 8 + bit);
+ handled = true;
+ val &= ~BIT(bit);
+ }
+ }
+
return handled ? IRQ_HANDLED : IRQ_NONE;
}
@@ -246,12 +381,24 @@ static int apple_spmi_init_irq(struct platform_device *pdev,
struct apple_spmi *spmi, int irq)
{
int ret;
+ struct irq_domain_info info = {
+ .fwnode = pdev->dev.fwnode,
+ .hwirq_max = ~0U,
+ .ops = &apple_spmi_irq_domain_ops,
+ .host_data = spmi,
+ };
+
+ raw_spin_lock_init(&spmi->irq_mask_lock);
for (size_t offset = 0; offset < SPMI_IRQ_USER_SIZE + 4; offset += 4) {
writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset);
writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset);
}
+ spmi->irqd = devm_irq_domain_instantiate(&pdev->dev, &info);
+ if (IS_ERR(spmi->irqd))
+ return PTR_ERR(spmi->irqd);
+
spmi->fifo_rx_irq = true;
apple_spmi_irq_unmask_raw(spmi, SPMI_IRQ_USER_SIZE * 8 + SPMI_IRQ_FIFO_RX);
--
2.55.0
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x
2026-07-28 9:28 ` [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
@ 2026-07-28 9:33 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-07-28 9:33 UTC (permalink / raw)
To: Sasha Finkelstein; +Cc: robh, conor+dt, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The binding introduces interrupt controller capabilities but fails to add `interrupt-controller` and `#interrupt-cells` to the `required` list, violating the dt-bindings subsystem guide.
--
--- Patch [1]: [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x ---
commit 3993abab519c4cf9121f6e121ee3a9b9ac214c43
Author: Sasha Finkelstein <k@chaosmail.tech>
dt-bindings: spmi: apple,spmi: Add t603x
This commit adds t603x compatibles, interrupt support, and support for
SPMI controllers that are not always-on.
> Keeping the "interrupt-controller" property as optional, as taking the
> j514c as an example, we only need this functionality on 3 out of 10
> SPMI controllers present on this SoC.
[Severity: Medium]
Device tree bindings are meant to describe hardware capabilities rather
than operating system usage.
If the hardware itself has interrupt controller capabilities, they should be
defined as required.
If only specific hardware instances possess this capability, they can be
enforced using an if/then conditional block instead of making the properties
globally optional.
Does keeping these properties optional here conflate operating system
usage with hardware capabilities?
> diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml
> --- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml
> +++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml
[ ... ]
> @@ -34,6 +36,18 @@ properties:
> reg:
> maxItems: 1
>
> + interrupts:
> + maxItems: 1
> + description: Optional, operates in polled mode if not present
> +
> + interrupt-controller: true
> +
> + "#interrupt-cells":
> + const: 2
> +
> + power-domains:
> + maxItems: 1
> +
> required:
> - compatible
> - reg
[Severity: Medium]
The device tree binding guidelines specify that when a hardware variant adds
provider capabilities, the corresponding standard properties (in this case,
interrupt-controller and #interrupt-cells) must appear in the required list
with appropriate constraints.
Leaving them optional allows incomplete device tree nodes missing these
properties to silently pass schema validation, which can lead to runtime
driver failures.
Should interrupt-controller and #interrupt-cells be added to this required
list?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=1
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 5/7] spmi: apple: lock around FIFOs
2026-07-28 9:28 ` [PATCH v2 5/7] spmi: apple: lock around FIFOs Sasha Finkelstein
@ 2026-07-28 9:37 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-07-28 9:37 UTC (permalink / raw)
To: Sasha Finkelstein; +Cc: robh, devicetree, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver does not drain or flush the RX FIFO during initialization or after error conditions, leading to cascading transaction failures and state desynchronization.
--
--- Patch [5]: [PATCH v2 5/7] spmi: apple: lock around FIFOs ---
commit 0e8d4d322dfd8a19a861bdcc1b9aefd06ad5b239
Author: Alba Mendez <me@alba.sh>
spmi: apple: lock around FIFOs
The driver adds a mutex to provide locking around register interactions.
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
[ ... ]
> @@ -86,7 +90,7 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>
> ret = apple_spmi_wait_rx_not_empty(ctrl);
> if (ret)
> - return ret;
> + goto out;
[Severity: High]
This is a pre-existing issue, but if a transaction times out here and the
hardware eventually replies, does the unread data remain in the hardware
RX FIFO? If the FIFO isn't explicitly drained on errors, the next
transaction could incorrectly consume the stale data as its own response,
leading to persistent state desynchronization.
>
> reply = readl(spmi->regs + SPMI_RSP_REG);
>
[ ... ]
> @@ -107,6 +112,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
> dev_warn(&ctrl->dev, "FIFO has extra data\n");
>
> + mutex_unlock(&spmi->fifo_lock);
> +
[Severity: High]
This is also a pre-existing issue, but when extra data is detected here,
should the driver drain the remaining words from the FIFO? Leaving the
unexpected data inside the FIFO instead of reading it out could corrupt
the state synchronization of the next command on the bus.
[ ... ]
> @@ -181,6 +192,7 @@ static int apple_spmi_probe(struct platform_device *pdev)
> return -ENOMEM;
>
> spmi = spmi_controller_get_drvdata(ctrl);
> + mutex_init(&spmi->fifo_lock);
>
> spmi->regs = devm_platform_ioremap_resource(pdev, 0);
> if (IS_ERR(spmi->regs))
[Severity: High]
This is a pre-existing issue, but does apple_spmi_probe() need to flush
or drain the RX FIFO during initialization? There could be stale data
left over from bootloader or firmware interactions before the controller
is fully registered and mapped.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=5
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 7/7] spmi: apple: interrupt controller functionality
2026-07-28 9:28 ` [PATCH v2 7/7] spmi: apple: interrupt controller functionality Sasha Finkelstein
@ 2026-07-28 9:40 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-07-28 9:40 UTC (permalink / raw)
To: Sasha Finkelstein; +Cc: conor+dt, devicetree, robh
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The software IRQ mask cache is updated after the hardware interrupt is unmasked, creating a race window where an interrupt can fire and be dropped.
- [Low] Lockless concurrent access to `irq_mask_cache` lacks `READ_ONCE()` and `WRITE_ONCE()` annotations, leading to a formal C data race.
--
--- Patch [7]: [PATCH v2 7/7] spmi: apple: interrupt controller functionality ---
commit 2c670245829f06c9db4ee3ae30ca2eacf7d1e022
Author: Alba Mendez <me@alba.sh>
spmi: apple: interrupt controller functionality
Add support for interrupts sent by slave devices.
> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> index 109c5d2c735d4..8f6a0d560da82 100644
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
[ ... ]
> +static void apple_spmi_irq_unmask(struct irq_data *d)
> +{
> + struct apple_spmi *spmi = irq_data_get_irq_chip_data(d);
> + unsigned long flags;
> +
> + raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags);
> + apple_spmi_irq_unmask_raw(spmi, d->hwirq);
[Severity: High]
Is there a race window here where a pending interrupt could be lost?
Since the hardware interrupt is unmasked via apple_spmi_irq_unmask_raw()
before the software irq_mask_cache is updated, an interrupt could fire
immediately. If the parent interrupt controller routes it to a CPU and
apple_spmi_irq_handler() executes, it will read the outdated cache mask
(observing a 0 for this IRQ).
The handler would then clear the interrupt from its pending mask and
return without acknowledging the hardware, potentially causing the
interrupt to be permanently lost (if edge-triggered) or resulting in an
interrupt storm (if level-triggered).
Should the irq_mask_cache be updated before the hardware is unmasked?
> + spmi->irq_mask_cache[d->hwirq / 64] |= BIT_ULL(d->hwirq % 64);
[Severity: Low]
Since irq_mask_cache is read locklessly in apple_spmi_irq_handler(),
should this update use WRITE_ONCE() to prevent potential compiler store
tearing?
> + raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags);
> +}
[ ... ]
> +static irqreturn_t apple_spmi_irq_handler(int irq, void *dev_id)
> {
> struct apple_spmi *spmi = dev_id;
> bool handled = false;
> - u32 val;
> + u64 val, offset, bit;
>
> val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + SPMI_IRQ_USER_SIZE);
> if (val & BIT(SPMI_IRQ_FIFO_RX)) {
> @@ -239,6 +357,23 @@ static irqreturn_t apple_spmi_irq_handler(int irq, void *dev_id)
> handled = true;
> }
>
> + for (offset = 0; offset < SPMI_IRQ_USER_SIZE; offset += sizeof(val)) {
> + val = readq(spmi->regs + SPMI_IRQ_ACK_BASE + offset);
> + /**
> + * because of other masters in the bus, we're going to get a multitude of
> + * interrupts we're not interested in. irq_resolve_mapping isn't very
> + * optimized for the nonexistent path, so instead we mask with (a locally
> + * cached version of) the IRQ mask
> + */
> + val &= spmi->irq_mask_cache[offset / sizeof(val)];
[Severity: Low]
Since this lockless read happens concurrently with the locked updates in
apple_spmi_irq_mask() and apple_spmi_irq_unmask(), should this use
READ_ONCE() to ensure the compiler doesn't cache the value in a register
or tear the load?
> + while (val) {
> + bit = __builtin_ctzll(val);
> + generic_handle_domain_irq(spmi->irqd, offset * 8 + bit);
> + handled = true;
> + val &= ~BIT(bit);
> + }
> + }
> +
> return handled ? IRQ_HANDLED : IRQ_NONE;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=7
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 2/7] spmi: apple: Validate FIFO state
2026-07-28 9:28 ` [PATCH v2 2/7] spmi: apple: Validate FIFO state Sasha Finkelstein
@ 2026-07-28 9:41 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-07-28 9:41 UTC (permalink / raw)
To: Sasha Finkelstein; +Cc: robh, devicetree, conor+dt
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver detects and warns about extra data in the RX FIFO but fails to drain it, permanently desynchronizing subsequent SPMI transactions.
- [High] The driver silently discards the SPMI reply status word, ignoring command NACKs and parity errors.
- [High] The SPMI read and write commands lack mutual exclusion, leading to concurrent hardware accesses clobbering each other.
- [High] The driver polls hardware registers using a sleeping timeout macro (`readl_poll_timeout`), triggering kernel BUGs in atomic contexts.
--
--- Patch [2]: [PATCH v2 2/7] spmi: apple: Validate FIFO state ---
commit 6fe31783af0978f8c2699194bf6efebf6615ed3b
Author: Alba Mendez <me@alba.sh>
spmi: apple: Validate FIFO state
Check for data before reading the body of a reply, and check for
end of data afterwards.
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
> @@ -78,6 +78,10 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
[Severity: High]
This is a pre-existing issue, but does spmi_read_cmd() lack mutual exclusion?
Concurrent calls to the SPMI controller could interleave writes to the command
register and reads from the FIFO.
Could this unpredictably corrupt commands and steal words from each other's
streams during concurrent access by different subsystems?
[Severity: High]
This isn't a bug introduced by this patch, but the wait function called
before this read loop appears to sleep in atomic contexts.
Every SPMI read/write operation calls apple_spmi_wait_rx_not_empty(), which
uses poll_reg() wrapped around readl_poll_timeout().
Since readl_poll_timeout() delegates to usleep_range(), wouldn't this trigger
a kernel BUG when SPMI client drivers issue commands from atomic contexts?
>
> /* Read SPMI data reply */
> while (len_read < len) {
[Severity: High]
This is a pre-existing issue, but earlier in this function the status word is
discarded before the read loop:
drivers/spmi/spmi-apple-controller.c:spmi_read_cmd() {
/* Discard SPMI reply status */
readl(spmi->regs + SPMI_RSP_REG);
...
}
Does this silently ignore command NACKs and parity errors on the wire?
> + if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
> + dev_err(&ctrl->dev, "FIFO lacks reply data, controller stuck?\n");
> + return -EIO;
> + }
> rsp = readl(spmi->regs + SPMI_RSP_REG);
> i = 0;
[ ... ]
> @@ -86,6 +90,9 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> }
> }
>
> + if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
> + dev_warn(&ctrl->dev, "FIFO has extra data\n");
[Severity: High]
This isn't a bug introduced by this patch, but if the FIFO is left with extra
data here, will the next SPMI transaction's wait function return immediately?
If the driver pops the stale leftover data instead of waiting for its own reply,
it seems like this would permanently shift the data stream and break all
subsequent communication with the PMIC.
Should the extra data be drained here to prevent this?
> +
> return 0;
> }
>
> @@ -115,6 +122,9 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
[Severity: High]
This is a pre-existing issue, but similar to spmi_read_cmd(), does
spmi_write_cmd() also lack mutual exclusion for stateful bus transactions?
> /* Discard */
> readl(spmi->regs + SPMI_RSP_REG);
[Severity: High]
This isn't a bug introduced by this patch, but discarding the status word
here appears to hide write failures and parity errors.
> + if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
> + dev_warn(&ctrl->dev, "FIFO has extra data\n");
[Severity: High]
This is a pre-existing issue, but just like in spmi_read_cmd(), failing to
drain the extra data detected here could permanently desynchronize subsequent
SPMI transactions.
> +
> return 0;
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=2
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 3/7] spmi: apple: check transaction status
2026-07-28 9:28 ` [PATCH v2 3/7] spmi: apple: check transaction status Sasha Finkelstein
@ 2026-07-28 9:41 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-07-28 9:41 UTC (permalink / raw)
To: Sasha Finkelstein; +Cc: robh, conor+dt, devicetree
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing synchronization (lock) around SPMI register accesses leads to hardware register corruption.
- [High] The driver does not flush the RX FIFO before initiating a new command, making it highly vulnerable to stream desynchronization.
--
--- Patch [3]: [PATCH v2 3/7] spmi: apple: check transaction status ---
commit 9becb223fa5ce2e2f70eb92ec4088e2171b28c87
Author: Alba Mendez <me@alba.sh>
spmi: apple: check transaction status
This commit adds checks for parity errors and missing command ACKs in the
Apple SPMI controller driver. It reads the reply status from the SPMI
response register and returns an error if the transaction fails.
> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> index b4f442d0b4ad7..4678a9e5270aa 100644
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
[ ... ]
> @@ -62,7 +68,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> {
> struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
> u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
[Severity: High]
This isn't a bug introduced by this patch, but since we are modifying
spmi_read_cmd(), is there a missing lock around the SPMI register accesses?
When the SPMI command is written to the hardware register via
writel(spmi_cmd, spmi->regs + SPMI_CMD_REG), concurrent SPMI transactions
from different client drivers (like regulators or RTCs) could interleave
their command writes and FIFO reads. Since the SPMI core does not serialize
these callbacks, shouldn't the controller driver implement its own locking
to prevent overwriting SPMI_CMD_REG before a transaction completes?
[Severity: High]
This is also a pre-existing issue, but does the driver need to flush the
RX FIFO before initiating a new command?
When a new command is issued via writel(spmi_cmd, spmi->regs + SPMI_CMD_REG),
if a previous transaction timed out or a slave responded with excess data,
leftover bytes might remain in the RX FIFO. Won't a subsequent transaction
inadvertently read this stale data instead of its own response, potentially
returning corrupted values to client drivers?
> - u32 rsp;
> + u32 reply, rsp;
> size_t len_read = 0;
> u8 i;
> int ret;
[ ... ]
> @@ -101,6 +110,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> {
> struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
> u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
[Severity: High]
This is a pre-existing issue, but similar to spmi_read_cmd(), are we
missing a lock around the hardware register accesses in spmi_write_cmd()?
Write operations also access the shared hardware controller without
synchronization when writing to SPMI_CMD_REG, exposing it to concurrent
overwrites.
[Severity: High]
This is a pre-existing issue, but does spmi_write_cmd() also need to
ensure the RX FIFO is drained of stale data before writing a new command?
Write commands similarly fail to flush the RX FIFO prior to execution,
making them vulnerable to stream desynchronization if earlier commands
timed out.
> + u32 reply;
> size_t i = 0, j;
> int ret;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=3
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible
2026-07-28 9:28 ` [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible Sasha Finkelstein
@ 2026-07-28 9:42 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-07-28 9:42 UTC (permalink / raw)
To: Sasha Finkelstein; +Cc: devicetree, conor+dt, robh
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Data race between `reinit_completion()` and `complete()` due to unhandled hardware timeouts, causing completion state corruption.
- [Low] The static function `apple_spmi_irq_mask_raw` is defined but never used, leading to `-Wunused-function` warnings.
--
--- Patch [6]: [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible ---
commit fa2cb405f77a7400cdbd89375c67fa8b1bc2c296
Author: Alba Mendez <me@alba.sh>
spmi: apple: use IRQ for RX FIFO if possible
This commit modifies the Apple SPMI driver to use an IRQ for the RX FIFO
when available, instead of relying on a 10ms sleep interval for polling.
This reduces the latency to process replies to a few microseconds.
> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> index 2cd4ed1803d40..109c5d2c735d4 100644
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
[ ... ]
> @@ -77,6 +99,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
>
> mutex_lock(&spmi->fifo_lock);
>
> + reinit_completion(&spmi->fifo_rx);
> +
[Severity: High]
Does this completion handle late interrupts correctly if a previous command
timed out?
If wait_for_completion_timeout() times out in apple_spmi_wait_rx_not_empty(),
an interrupt could still arrive later. If a delayed interrupt fires while a
subsequent transaction is calling reinit_completion(), could the late
apple_spmi_irq_handler() call complete() and cause the new transaction to
finish prematurely with incorrect data?
> writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
>
> while (i < len) {
[ ... ]
> @@ -181,10 +205,68 @@ static int spmi_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid)
> return -EINVAL;
> }
>
> +static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq)
> +{
> + u32 __iomem *reg = spmi->regs + SPMI_IRQ_ACK_BASE + (irq / 32) * 4;
> +
> + writel(BIT(irq % 32), reg);
> +}
> +
> +static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq)
> +{
> + u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4;
> +
> + writel(readl(reg) & ~BIT(irq % 32), reg);
> +}
[Severity: Low]
Is this function used anywhere in this patch? It looks like it is defined as
a static function but never called, which might trigger a compiler warning
when building with CONFIG_WERROR.
> +
> +static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq)
> +{
> + u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4;
> +
> + writel(readl(reg) | BIT(irq % 32), reg);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=6
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH v2 4/7] spmi: apple: Implement remaining commands
2026-07-28 9:28 ` [PATCH v2 4/7] spmi: apple: Implement remaining commands Sasha Finkelstein
@ 2026-07-28 9:46 ` sashiko-bot
0 siblings, 0 replies; 15+ messages in thread
From: sashiko-bot @ 2026-07-28 9:46 UTC (permalink / raw)
To: Sasha Finkelstein; +Cc: conor+dt, robh, devicetree
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
New issues:
- [High] Missing bounds validation allows unmasked data in SPMI_CMD_ZERO_WRITE to corrupt the command opcode.
- [Medium] Missing NACK check on read commands triggers a false 'controller stuck' error and incorrect error handling.
Pre-existing issues:
- [High] Missing locking around shared hardware FIFO registers causes race conditions and bus state corruption.
- [High] Unhandled residual data in the RX FIFO leads to permanent transaction desynchronization.
--
--- Patch [4]: [PATCH v2 4/7] spmi: apple: Implement remaining commands ---
commit aad16a3367909482f17e1e9e1da0123341931c90
Author: Alba Mendez <me@alba.sh>
spmi: apple: Implement remaining commands
This commit adds support for zero write and power management commands to the
Apple SPMI driver. It restructures the internal command functions to handle
raw inputs and acknowledgements.
> diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c
> --- a/drivers/spmi/spmi-apple-controller.c
> +++ b/drivers/spmi/spmi-apple-controller.c
[ ... ]
> -static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> - u16 saddr, u8 *buf, size_t len)
> +static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> + u16 param, const u8 *buf, size_t len, u8 *ibuf, size_t ilen)
> {
> struct apple_spmi *spmi = spmi_controller_get_drvdata(ctrl);
> - u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, saddr, len);
> + u32 spmi_cmd = apple_spmi_pack_cmd(opc, sid, param);
> u32 reply, rsp;
> size_t len_read = 0;
> - u8 i;
> + size_t i = 0, j;
> int ret;
>
> writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
[Severity: High]
This is a pre-existing issue, but does spmi_raw_cmd() need locking to serialize
access to the shared hardware FIFO registers? Since the SPMI framework does
not serialize transactions, if two threads perform concurrent commands, could
their reads and writes to SPMI_CMD_REG and SPMI_RSP_REG interleave, resulting
in hardware FIFO corruption or reading another transaction's response?
> +
> + while (i < len) {
> + j = 0;
> + spmi_cmd = 0;
> + while ((j < 4) & (i < len))
> + spmi_cmd |= buf[i++] << (j++ * 8);
> +
> + writel(spmi_cmd, spmi->regs + SPMI_CMD_REG);
> + }
> +
> ret = apple_spmi_wait_rx_not_empty(ctrl);
> if (ret)
> return ret;
> @@ -82,15 +91,15 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> reply = readl(spmi->regs + SPMI_RSP_REG);
>
> /* Read SPMI data reply */
> - while (len_read < len) {
> + while (len_read < ilen) {
> if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) {
> dev_err(&ctrl->dev, "FIFO lacks reply data, controller stuck?\n");
> return -EIO;
> }
[Severity: Medium]
Will this error path incorrectly trigger for unacknowledged read commands?
Because the NACK check below is restricted to commands with no input payload
(!ilen), if a read command is NACKed (e.g., when probing an empty bus address),
it bypasses the NACK check and enters this loop. Could this result in hitting
the empty FIFO check and raising a misleading "controller stuck?" error instead
of gracefully handling the normal NACK condition?
> rsp = readl(spmi->regs + SPMI_RSP_REG);
> i = 0;
> - while ((len_read < len) && (i < 4)) {
> - buf[len_read++] = ((0xff << (8 * i)) & rsp) >> (8 * i);
> + while ((len_read < ilen) && (i < 4)) {
> + ibuf[len_read++] = ((0xffU << (8 * i)) & rsp) >> (8 * i);
> i += 1;
> }
> }
> @@ -98,47 +107,67 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY))
> dev_warn(&ctrl->dev, "FIFO has extra data\n");
[Severity: High]
This is a pre-existing issue, but does the RX FIFO need to be drained when
residual data is detected? If the PMIC pushes more frames than expected or the
transaction returns early, leaving this extra data could cause subsequent
transactions to read the stale residual words, permanently desynchronizing the
bus.
> - if ((~reply >> SPMI_REPLY_FRAME_PARITY_OFFSET) & ((1 << len) - 1)) {
> + if (!ilen && !(reply & SPMI_REPLY_ACK)) {
> + dev_err(&ctrl->dev, "command not acknowledged\n");
> + return -EIO;
> + }
[ ... ]
> +static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
> + u16 saddr, const u8 *buf, size_t len)
> +{
> + switch (opc) {
> + case SPMI_CMD_WRITE:
> + return spmi_raw_cmd_ack(ctrl, opc | saddr, sid, buf[0] << 8 | saddr, NULL, 0);
> + case SPMI_CMD_ZERO_WRITE:
> + return spmi_raw_cmd_ack(ctrl, opc | buf[0], sid, buf[0] << 8 | saddr, NULL, 0);
[Severity: High]
Does this code allow unmasked user data to corrupt the command opcode? If a
caller provides a data payload for SPMI_CMD_ZERO_WRITE where bits 4-7 are set,
bitwise ORing it directly with the opcode (opc | buf[0]) without masking
(e.g., buf[0] & 0x0F) could overwrite the upper opcode bits, potentially
executing unintended commands on the PMIC.
> + case SPMI_CMD_EXT_WRITE:
> + case SPMI_CMD_EXT_WRITEL:
> + return spmi_raw_cmd_ack(ctrl, opc | (len - 1), sid, saddr, buf, len);
> }
> - return 0;
> + return -EINVAL;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260728-t603x-spmi-v2-0-f43e5f10e583@chaosmail.tech?part=4
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2026-07-28 9:46 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-28 9:28 [PATCH v2 0/7] spmi: apple: Additional commands and interrupt support Sasha Finkelstein
2026-07-28 9:28 ` [PATCH v2 1/7] dt-bindings: spmi: apple,spmi: Add t603x Sasha Finkelstein
2026-07-28 9:33 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 2/7] spmi: apple: Validate FIFO state Sasha Finkelstein
2026-07-28 9:41 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 3/7] spmi: apple: check transaction status Sasha Finkelstein
2026-07-28 9:41 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 4/7] spmi: apple: Implement remaining commands Sasha Finkelstein
2026-07-28 9:46 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 5/7] spmi: apple: lock around FIFOs Sasha Finkelstein
2026-07-28 9:37 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 6/7] spmi: apple: use IRQ for RX FIFO if possible Sasha Finkelstein
2026-07-28 9:42 ` sashiko-bot
2026-07-28 9:28 ` [PATCH v2 7/7] spmi: apple: interrupt controller functionality Sasha Finkelstein
2026-07-28 9:40 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox