From nobody Thu Oct 1 23:00:34 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC1DC486B85; Thu, 1 Oct 2026 20:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886932; cv=none; b=s/wnqaVLG+bp9t98KY+c4DgM9ZhhSZwkD/GypsVFy0YjfeTjUnOUs0sNs8Rh3ZH8FI0AGFisssPLOp3QLkaY95cz1UGZPKpeJ7fQcE8RP325nVbAs6ZYOiz3MLP3HOz9ScYziV2WTjPduUbrQ1w+X21gb/1Iq+qx4IIxUDslufs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886932; c=relaxed/simple; bh=hB41yiTeB7yUdgLmPck4QL6QQEw/Im8eycw8rMjdcpE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VfME2jHcIvp1194lr/XU70SAnqGxznhuRBG869mnXd77d393I7tobPL5byvVIzjlAaI7LJ8SgYafeH2nIiMGrBaa/dFbGMdsz9wWc2Ql5EV4xC54+6DDwpPqI7PcgO6WOdxAedXZ02FS2CtPcgR4H9QwmeCEjExoZX5QiSdYaBk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=Mn/r1KrY; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="Mn/r1KrY" Received: by chaosmail.tech (Postfix) id 11A6F1C8DB2; Thu, 01 Oct 2026 20:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1790886422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j+zwGGV7ihofYpqOYK7iJnQ5635HlS3lYL7TQsZckEE=; b=Mn/r1KrYyIcdpuPGXO+80+SB7lNpz70rHhIFeJuW7fAVUL1p835Vym0NQT8cU4QdRQ3/pT EiGLINwMST7UPSD5N0TVK9dJb04L47dO2J+TVREU0eZxBJ+bJ6+xZ+WTy8leSMTBAluO5m bok5r3ZdGFbXY8b+8PChGqbS8YEUp/c= From: Sasha Finkelstein Date: Thu, 01 Oct 2026 22:26:56 +0200 Subject: [PATCH v10 1/6] dt-bindings: spmi: apple,spmi: Add t603x and t8122 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: <20261001-t603x-spmi-v10-1-ff815c66c73f@chaosmail.tech> References: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> In-Reply-To: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> To: Sven Peter , Janne Grunau , Neal Gompa , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sasha Finkelstein , Conor Dooley X-Developer-Signature: v=1; a=ed25519-sha256; t=1790886421; l=1694; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=hB41yiTeB7yUdgLmPck4QL6QQEw/Im8eycw8rMjdcpE=; b=tYhSRgI62c8w8T20AZaKQqeBjXJreQT+gRgFVKrGaSB/3+I5ouCmKpMi6hulQIqQPHBMl2rHn rrdlPm64MPwAi6OfKNyAkHP6IUqoDWbMAx81Afvu8z178sVlPebNPPP X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= Add t603x and t8122 compatibles, interrupt support, and support for SPMI controllers that are not always-on. Reviewed-by: Janne Grunau Acked-by: Conor Dooley Signed-off-by: Sasha Finkelstein --- Documentation/devicetree/bindings/spmi/apple,spmi.yaml | 29 ++++++++++++++= +++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Docum= entation/devicetree/bindings/spmi/apple,spmi.yaml index 3e5b14bc8c31..4e73083ecec3 100644 --- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml +++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml @@ -20,8 +20,11 @@ properties: - items: - enum: - apple,t6020-spmi + - apple,t6030-spmi + - apple,t6031-spmi - apple,t8012-spmi - apple,t8015-spmi + - apple,t8122-spmi - const: apple,t8103-spmi - items: - enum: @@ -34,10 +37,36 @@ properties: reg: maxItems: 1 =20 + 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 =20 +if: + properties: + compatible: + contains: + enum: + - apple,t8122-spmi + - apple,t6030-spmi + - apple,t6031-spmi +then: + required: + - interrupt-controller + - "#interrupt-cells" + - interrupts + unevaluatedProperties: false =20 examples: --=20 2.55.0 From nobody Thu Oct 1 23:00:34 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC339488D97; Thu, 1 Oct 2026 20:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886933; cv=none; b=Tzjx1p5PkdVw/1bNylkjbzz6Wz1sBdxsAr1u6xn8cEngHuY6QQtuf36NpX92fKJ1FSYOjtYKDXwLdN2WqwWopNGmUg8GT1LZ4NINHhmqJaJGFdBhUcCw7pt7sxr8IeZUMIEGQJQ+CQsK3VXkjrkoC2auZoecGWHLALiJAmj/ZVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886933; c=relaxed/simple; bh=6OqlLgbwT3A+zqyYXf5DfSfc4ts3mlhzwvgwzdupCBI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mf2S80xkIPwsWihGkpuy2HOvwU0SSF6XWGYVsGiia7f6CKiz/aBHBnuqcNKLyc2P4xefzyUlqM42vIMIKLhc64F7FE0LFTko/CaYxEfM1AJbg1wxfEMh6kYxPCQlgTxZAAgQDTo0xTlgLxqqYJLPYdHPgOHG/TFOoZ6G9btRmZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=d+MWTNfI; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="d+MWTNfI" Received: by chaosmail.tech (Postfix) id CEF2A1C8DE2; Thu, 01 Oct 2026 20:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1790886423; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RoxLjw+FaEv6UBa2auRBgAVGOoEFVhZL0a0SozhjcLw=; b=d+MWTNfIKo8GefYq0Bvxb62IzB+/BeUxL+vCZ/C24u12eMVRTaejPzAgZZLNmmHSdXyIWC fhLQsrm0pRpyYZE1XpFnl88lJFatKA9dykYhxEknxYR2tUD0JZok1sHE7/sPxktvmRoZgT nd87dWWMaOi6Gj/zFP5yNtd69rP1F0Q= From: Sasha Finkelstein Date: Thu, 01 Oct 2026 22:26:57 +0200 Subject: [PATCH v10 2/6] spmi: apple: Validate FIFO state 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: <20261001-t603x-spmi-v10-2-ff815c66c73f@chaosmail.tech> References: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> In-Reply-To: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> To: Sven Peter , Janne Grunau , Neal Gompa , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sasha Finkelstein , Alba Mendez X-Developer-Signature: v=1; a=ed25519-sha256; t=1790886421; l=3000; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=D9GL2Z01e0tzF0XHDaJ4oJIv+24UCKbgdDmyLz2zBJU=; b=RvIjH00Ek0X/H7h2YVz1+9eGgsoApPVw35WjZybP+yOXvTpvmCZ5XgOGpCnTXYuFnRQ5JBGQ7 zWQoM+TdvqzBd5wdf61ZI7nm406xhi8JDDDj23CCEFScbAQKIhmV0Yw X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= From: Alba Mendez Check for data before reading the body of a reply, and check for end of data afterwards. Signed-off-by: Alba Mendez Reviewed-by: Janne Grunau Signed-off-by: Sasha Finkelstein --- drivers/spmi/spmi-apple-controller.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple= -controller.c index 376cf682c43e..15721cb41d5c 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -21,7 +21,9 @@ #define SPMI_STATUS_REG 0 #define SPMI_CMD_REG 0x4 #define SPMI_RSP_REG 0x8 +#define SPMI_ACT_REG 0xa4 =20 +#define SPMI_ACT_FIFO_FLUSH BIT(0) #define SPMI_RX_FIFO_EMPTY BIT(24) =20 #define REG_POLL_INTERVAL_US 10000 @@ -29,6 +31,7 @@ =20 struct apple_spmi { void __iomem *regs; + bool prev_fail; }; =20 #define poll_reg(spmi, reg, val, cond) \ @@ -49,6 +52,7 @@ static int apple_spmi_wait_rx_not_empty(struct spmi_contr= oller *ctrl) =20 ret =3D poll_reg(spmi, SPMI_STATUS_REG, status, !(status & SPMI_RX_FIFO_E= MPTY)); if (ret) { + spmi->prev_fail =3D true; dev_err(&ctrl->dev, "failed to wait for RX FIFO not empty\n"); return ret; @@ -67,6 +71,11 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u= 8 opc, u8 sid, u8 i; int ret; =20 + if (spmi->prev_fail) { + writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG); + spmi->prev_fail =3D false; + } + writel(spmi_cmd, spmi->regs + SPMI_CMD_REG); =20 ret =3D apple_spmi_wait_rx_not_empty(ctrl); @@ -78,6 +87,12 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u= 8 opc, u8 sid, =20 /* Read SPMI data reply */ while (len_read < len) { + if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) { + spmi->prev_fail =3D true; + dev_err_ratelimited(&ctrl->dev, + "FIFO lacks reply data, controller stuck?\n"); + return -EIO; + } rsp =3D readl(spmi->regs + SPMI_RSP_REG); i =3D 0; while ((len_read < len) && (i < 4)) { @@ -86,6 +101,11 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, = u8 opc, u8 sid, } } =20 + if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY)) { + dev_warn(&ctrl->dev, "FIFO has extra data\n"); + spmi->prev_fail =3D true; + } + return 0; } =20 @@ -97,6 +117,11 @@ static int spmi_write_cmd(struct spmi_controller *ctrl,= u8 opc, u8 sid, size_t i =3D 0, j; int ret; =20 + if (spmi->prev_fail) { + writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG); + spmi->prev_fail =3D false; + } + writel(spmi_cmd, spmi->regs + SPMI_CMD_REG); =20 while (i < len) { @@ -115,6 +140,11 @@ static int spmi_write_cmd(struct spmi_controller *ctrl= , u8 opc, u8 sid, /* Discard */ readl(spmi->regs + SPMI_RSP_REG); =20 + if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY)) { + dev_warn(&ctrl->dev, "FIFO has extra data\n"); + spmi->prev_fail =3D true; + } + return 0; } =20 --=20 2.55.0 From nobody Thu Oct 1 23:00:34 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC4C2489FDE; Thu, 1 Oct 2026 20:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886932; cv=none; b=adxF4d7Ua+9viUxuwNSqw9qrdhe6h982Bxj+gisOoay09eQpopYYQz7XEaWILvpTA60oMUXT5aYLuI9THYeozneMI7ZKH6IfidVLIZQ0Exb/FsPqGd1FwXWaeB6IZczcrn+2BVX0QeklXyrCtLbKtyroBLpxY/TT65rej1DNotg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886932; c=relaxed/simple; bh=h6ymgcV3EFdULvBN7pXvXFtJZciM6qsk6AqGU/0i1j0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fQ3UY04W7DiLUwpAdU2i5pN6FVlLvBWoiNrBSWDLnN4Zt/rMWWRW6wAPihXC/XITQvTPZpIy43Op2Rt/NW3BQkEdyTXX5PnVk8kitGiMW/j/HSQztqk7b3LA3Yx1b7EfN7RH1zk+WaN/sXxUjAzut4kRypDIGPijGSItB437ZXw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=w4MRNPDu; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="w4MRNPDu" Received: by chaosmail.tech (Postfix) id 93E101C90D6; Thu, 01 Oct 2026 20:27:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1790886424; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VlhlhN6Ao8cxtOBbRD5JaNyRrKmX5FvsiLtDWtyTEJY=; b=w4MRNPDu9/UCxAvQ+qLku9ud5x5xkJd17U8SBaBoo88xjqh9wwntXuR4cue0d11HdYgE2/ 2EfLaFDVcu3aLS9m5dOuq2/9UsLJtGby1HTkFWXGAk1X3QohEnsJTKYUCYrHMqcZWQH8a/ r1fsUc5gQjJcSWU6T2jCkr/nOifo5wA= From: Sasha Finkelstein Date: Thu, 01 Oct 2026 22:26:58 +0200 Subject: [PATCH v10 3/6] spmi: apple: check transaction status 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: <20261001-t603x-spmi-v10-3-ff815c66c73f@chaosmail.tech> References: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> In-Reply-To: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> To: Sven Peter , Janne Grunau , Neal Gompa , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sasha Finkelstein , Alba Mendez X-Developer-Signature: v=1; a=ed25519-sha256; t=1790886421; l=2846; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=EambuisSIw3s+EavjiZydICr5EUeyWSuYrWkUmgadRo=; b=td1fRxeD6RF5ssspxjD3QcF315LxL0J+L8ZtYu2M5CGZF1XJJBm90wv26VxF2Q4NVF+kVhce4 TnwuA7qGF5gBdquwxmawr6KcvabL98HZKGq0j2dIwyQ7H2LkWyE4fRY X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= From: Alba Mendez Check for parity errors and missing command ACKs. Signed-off-by: Alba Mendez Reviewed-by: Janne Grunau Signed-off-by: Sasha Finkelstein --- drivers/spmi/spmi-apple-controller.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple= -controller.c index 15721cb41d5c..b1c127cf5f44 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. */ =20 +#include +#include #include #include #include @@ -23,6 +25,12 @@ #define SPMI_RSP_REG 0x8 #define SPMI_ACT_REG 0xa4 =20 +/* SPMI_RSP_REG reply word */ +#define SPMI_REPLY_FRAME_PARITY_STATUS GENMASK(31, 16) +#define SPMI_REPLY_ACK BIT(15) +#define SPMI_REPLY_SLAVE_ID GENMASK(14, 8) +#define SPMI_REPLY_CMD GENMASK(7, 0) + #define SPMI_ACT_FIFO_FLUSH BIT(0) #define SPMI_RX_FIFO_EMPTY BIT(24) =20 @@ -66,7 +74,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8= opc, u8 sid, { struct apple_spmi *spmi =3D spmi_controller_get_drvdata(ctrl); u32 spmi_cmd =3D apple_spmi_pack_cmd(opc, sid, saddr, len); - u32 rsp; + u32 reply, rsp; size_t len_read =3D 0; u8 i; int ret; @@ -82,8 +90,7 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u8= opc, u8 sid, if (ret) return ret; =20 - /* Discard SPMI reply status */ - readl(spmi->regs + SPMI_RSP_REG); + reply =3D readl(spmi->regs + SPMI_RSP_REG); =20 /* Read SPMI data reply */ while (len_read < len) { @@ -106,6 +113,10 @@ static int spmi_read_cmd(struct spmi_controller *ctrl,= u8 opc, u8 sid, spmi->prev_fail =3D true; } =20 + if (~FIELD_GET(SPMI_REPLY_FRAME_PARITY_STATUS, reply) & ((1 << len) - 1))= { + dev_err(&ctrl->dev, "some frames failed parity check\n"); + return -EIO; + } return 0; } =20 @@ -114,6 +125,7 @@ static int spmi_write_cmd(struct spmi_controller *ctrl,= u8 opc, u8 sid, { struct apple_spmi *spmi =3D spmi_controller_get_drvdata(ctrl); u32 spmi_cmd =3D apple_spmi_pack_cmd(opc, sid, saddr, len); + u32 reply; size_t i =3D 0, j; int ret; =20 @@ -137,14 +149,17 @@ static int spmi_write_cmd(struct spmi_controller *ctr= l, u8 opc, u8 sid, if (ret) return ret; =20 - /* Discard */ - readl(spmi->regs + SPMI_RSP_REG); + reply =3D readl(spmi->regs + SPMI_RSP_REG); =20 if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY)) { dev_warn(&ctrl->dev, "FIFO has extra data\n"); spmi->prev_fail =3D true; } =20 + if (!FIELD_GET(SPMI_REPLY_ACK, reply)) { + dev_err(&ctrl->dev, "command not acknowledged\n"); + return -EIO; + } return 0; } =20 --=20 2.55.0 From nobody Thu Oct 1 23:00:34 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B86B9492E48; Thu, 1 Oct 2026 20:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886931; cv=none; b=tbjYBDRVrAXeYZb3t4roXPp29bNu+FYLX3cZ+jEpaUEze/oQz3vSESIDfG6DOVl2f99ltsqbZ9kHIrYItoNYdx0wEJkKJLkZpLeCSs4Qtcp1WOURd2PJHeyQvN3GF21pBG3alLO6zn0cedb4O9Nsg7EpGH/g3sg6tdTUv8ti6Nc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886931; c=relaxed/simple; bh=2bwsVS73ftdNFM2Okf+JM1I40RefIS4dKh7P1t9yANY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b7r8Vn5/Qx11EwHiwL+udPvxc1G5luBOliO9XXNWtWp/3gl1vzyIcTjjcBYE7itH/l5xH4PwTFAnkIL+rwQMBcl8sHbnf6/hriy3x2J/WG2TcNuxhhO6+t0LUW3v74ZZ47UhvOmSAeUfyGVRysK9lipinrLNT6h65rI64GZNdsA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=T6be6Osz; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="T6be6Osz" Received: by chaosmail.tech (Postfix) id 687771C930F; Thu, 01 Oct 2026 20:27:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1790886425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i1ZT8E0+Pm5VDx4LcOMCqD5baN3Oe5eOsk0bsRrW/zs=; b=T6be6OszmA3zpI7hKfZ2nYEtAE6inUj0H6HQf0qZZ7ujuTIFhGVAI9FRqHw8r481AvTUAT /7XjP59LKcek8v2SFj8IbT/Mj3uXy6ER/l5Vhj3e0VWqYhh+B7+TXuwTkAtzK/jQSl+ZuH HjEMCPgOjsXB9EU33tTOFMeEA7e7xJM= From: Sasha Finkelstein Date: Thu, 01 Oct 2026 22:26:59 +0200 Subject: [PATCH v10 4/6] spmi: apple: Implement remaining commands 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: <20261001-t603x-spmi-v10-4-ff815c66c73f@chaosmail.tech> References: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> In-Reply-To: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> To: Sven Peter , Janne Grunau , Neal Gompa , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sasha Finkelstein , Alba Mendez X-Developer-Signature: v=1; a=ed25519-sha256; t=1790886421; l=6582; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=RH6K223nJdTsq2zsNyub+vrfUTvair8i/u/7LCuGT1E=; b=1VcLM7DisTeW0r+S2OpaUauCdieZV3IkGCSdIbUOPRklkD1zwU9J82gq3O2wSlPW9LprGZpVT mzwh7VYvnbtDbFmxyvdTysFq2XUBszOQUkgfsjarzb6jR1I+gJfwn7B X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= From: Alba Mendez Add support for zero write and power management commands. Signed-off-by: Alba Mendez Signed-off-by: Sasha Finkelstein --- drivers/spmi/spmi-apple-controller.c | 116 +++++++++++++++++++++++++++++++= ++++++++++++++++++++++++++++++++++++++-------------------------------------= ---------- 1 file changed, 69 insertions(+), 47 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple= -controller.c index b1c127cf5f44..9843dc871d6c 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -46,9 +46,9 @@ struct apple_spmi { readl_poll_timeout((spmi)->regs + (reg), (val), (cond), \ REG_POLL_INTERVAL_US, REG_POLL_TIMEOUT_US) =20 -static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 saddr, size_t le= n) +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); } =20 /* Wait for Rx FIFO to have something */ @@ -69,14 +69,13 @@ static int apple_spmi_wait_rx_not_empty(struct spmi_con= troller *ctrl) return 0; } =20 -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_wr, size_t len_wr, u8 *buf_rd, size_t len_rd) { struct apple_spmi *spmi =3D spmi_controller_get_drvdata(ctrl); - u32 spmi_cmd =3D apple_spmi_pack_cmd(opc, sid, saddr, len); + u32 spmi_cmd =3D apple_spmi_pack_cmd(opc, sid, param); u32 reply, rsp; - size_t len_read =3D 0; - u8 i; + size_t i =3D 0, j; int ret; =20 if (spmi->prev_fail) { @@ -86,6 +85,14 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u= 8 opc, u8 sid, =20 writel(spmi_cmd, spmi->regs + SPMI_CMD_REG); =20 + while (i < len_wr) { + j =3D min_t(size_t, sizeof(spmi_cmd), len_wr - i); + spmi_cmd =3D 0; + memcpy(&spmi_cmd, buf_wr + i, j); + writel(spmi_cmd, spmi->regs + SPMI_CMD_REG); + i +=3D j; + } + ret =3D apple_spmi_wait_rx_not_empty(ctrl); if (ret) return ret; @@ -93,7 +100,8 @@ static int spmi_read_cmd(struct spmi_controller *ctrl, u= 8 opc, u8 sid, reply =3D readl(spmi->regs + SPMI_RSP_REG); =20 /* Read SPMI data reply */ - while (len_read < len) { + i =3D 0; + while (i < len_rd) { if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) { spmi->prev_fail =3D true; dev_err_ratelimited(&ctrl->dev, @@ -101,11 +109,9 @@ static int spmi_read_cmd(struct spmi_controller *ctrl,= u8 opc, u8 sid, return -EIO; } rsp =3D readl(spmi->regs + SPMI_RSP_REG); - i =3D 0; - while ((len_read < len) && (i < 4)) { - buf[len_read++] =3D ((0xff << (8 * i)) & rsp) >> (8 * i); - i +=3D 1; - } + j =3D min_t(size_t, sizeof(spmi_cmd), len_rd - i); + memcpy(buf_rd + i, &rsp, j); + i +=3D j; } =20 if (!(readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY)) { @@ -113,54 +119,69 @@ static int spmi_read_cmd(struct spmi_controller *ctrl= , u8 opc, u8 sid, spmi->prev_fail =3D true; } =20 - if (~FIELD_GET(SPMI_REPLY_FRAME_PARITY_STATUS, reply) & ((1 << len) - 1))= { + if (!len_rd && !FIELD_GET(SPMI_REPLY_ACK, reply)) { + dev_err(&ctrl->dev, "command not acknowledged\n"); + return -EIO; + } + if (~FIELD_GET(SPMI_REPLY_FRAME_PARITY_STATUS, reply) & ((1 << len_rd) - = 1)) { dev_err(&ctrl->dev, "some frames failed parity check\n"); return -EIO; } return 0; } =20 -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 =3D spmi_controller_get_drvdata(ctrl); - u32 spmi_cmd =3D apple_spmi_pack_cmd(opc, sid, saddr, len); - u32 reply; - size_t i =3D 0, j; - int ret; - - if (spmi->prev_fail) { - writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG); - spmi->prev_fail =3D false; - } - - writel(spmi_cmd, spmi->regs + SPMI_CMD_REG); + return spmi_raw_cmd(ctrl, opc, sid, param, NULL, 0, buf, len); +} =20 - while (i < len) { - j =3D 0; - spmi_cmd =3D 0; - while ((j < 4) & (i < len)) - spmi_cmd |=3D 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); +} =20 - 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; +} =20 - ret =3D apple_spmi_wait_rx_not_empty(ctrl); - if (ret) - return ret; - - reply =3D 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"); - spmi->prev_fail =3D true; +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, NUL= L, 0); + case SPMI_CMD_ZERO_WRITE: + return spmi_raw_cmd_ack(ctrl, opc | buf[0], sid, buf[0] << 8 | saddr, NU= LL, 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 -EINVAL; +} =20 - if (!FIELD_GET(SPMI_REPLY_ACK, reply)) { - dev_err(&ctrl->dev, "command not acknowledged\n"); - return -EIO; +static int spmi_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid) +{ + switch (opc) { + case SPMI_CMD_RESET: + case SPMI_CMD_SLEEP: + case SPMI_CMD_SHUTDOWN: + case SPMI_CMD_WAKEUP: + return spmi_raw_cmd_ack(ctrl, opc, sid, 0, NULL, 0); } - return 0; + return -EINVAL; } =20 static int apple_spmi_probe(struct platform_device *pdev) @@ -183,6 +204,7 @@ static int apple_spmi_probe(struct platform_device *pde= v) =20 ctrl->read_cmd =3D spmi_read_cmd; ctrl->write_cmd =3D spmi_write_cmd; + ctrl->cmd =3D spmi_cmd; =20 ret =3D devm_spmi_controller_add(&pdev->dev, ctrl); if (ret) --=20 2.55.0 From nobody Thu Oct 1 23:00:34 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20FD354705C; Thu, 1 Oct 2026 20:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886435; cv=none; b=jztmQD8Sl4Q7tI95Ya8GcPyhU+V+xiGeynAqzfX8fBK2fCJVTgOWS63PIuwwwEX/gbDv3smoXrSHgNJftHNh7V3MFZjNkygZduG+7MePRgVb6FbGDAukgSQ98dLVKam3CWBt99TzT5dSE2pAulC0l15rLO6L3EKO+Hpidcjedcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886435; c=relaxed/simple; bh=FY6nUFUsg5ykRDaCyNCZU21elpZrnVLRtGzYwII8m2U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YW/UORRBRqg4+6+L6nHTjeLN5Li0j4sjWTQxhIvagFA/eNfHhg0QW7IX79B/un+A6A1AOkjP/rYt5y3XRot9aw0k3KErHFivg/KkNBLlrBdrPmLH329jUWG3DCxOHE9Et3q5d6YhJLg8xnqsy3cnuoB+DTt4sgnTez3bVh2JTo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=bxgHFkrs; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="bxgHFkrs" Received: by chaosmail.tech (Postfix) id 30E551C93A5; Thu, 01 Oct 2026 20:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1790886425; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wVHbMMgwTRdvhl3Xmvr04M/6W1HqFA3Q/iNZoN90xm8=; b=bxgHFkrsXJtqQYohE23KtPAJfGpqy1sbKRWSmlOpuYev8Jf8T/g4IqQt/UyPPnwmB83XaQ /OOrpSJo1mJ6JvolQf4XTk2ehNweQfc/YMIkuJLLYpmTvXpUf9HaxavvAYaFGylwjThwtp lH4X89ELXHOmPB+jGtvgZGgGdmdeMWs= From: Sasha Finkelstein Date: Thu, 01 Oct 2026 22:27:00 +0200 Subject: [PATCH v10 5/6] spmi: apple: lock around FIFOs 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: <20261001-t603x-spmi-v10-5-ff815c66c73f@chaosmail.tech> References: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> In-Reply-To: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> To: Sven Peter , Janne Grunau , Neal Gompa , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sasha Finkelstein , Alba Mendez X-Developer-Signature: v=1; a=ed25519-sha256; t=1790886421; l=1392; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=/okjDmX4WP5ORuj7W0YBcJBa1hZOvGWaK9RmHtLYrOM=; b=oRiJgN4EvPZw7X6K1kim0dyp9pQyFMBIYVj/DtasNG2c5J2+DIRsY1SuZNdnSMGuHovUtkfRy NfDPhoyLoKqCN9LGXnFj8k2alpeP+/Cjtup96DjmPZgdkwGVONWa6s+ X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= From: Alba Mendez The driver was missing locking around register interactions. Signed-off-by: Alba Mendez Reviewed-by: Janne Grunau Signed-off-by: Sasha Finkelstein --- drivers/spmi/spmi-apple-controller.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple= -controller.c index 9843dc871d6c..fabccd25aa0d 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include =20 @@ -39,6 +40,7 @@ =20 struct apple_spmi { void __iomem *regs; + struct mutex fifo_lock; bool prev_fail; }; =20 @@ -78,6 +80,8 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u8 = opc, u8 sid, u16 param, size_t i =3D 0, j; int ret; =20 + guard(mutex)(&spmi->fifo_lock); + if (spmi->prev_fail) { writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG); spmi->prev_fail =3D false; @@ -195,6 +199,7 @@ static int apple_spmi_probe(struct platform_device *pde= v) return -ENOMEM; =20 spmi =3D spmi_controller_get_drvdata(ctrl); + mutex_init(&spmi->fifo_lock); =20 spmi->regs =3D devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(spmi->regs)) --=20 2.55.0 From nobody Thu Oct 1 23:00:34 2026 Received: from chaosmail.tech (chaosmail.tech [77.81.229.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FA67490BF7; Thu, 1 Oct 2026 20:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=77.81.229.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886434; cv=none; b=ezGD8FppnKxClkw2K/01ceXYKgQoSjLNDZFwC99wOxMNbBEE3AZJlMb6FTKplT/DyOsu8/PYn+3Fi+LGG+tm1rxSnIDKj6Dktv3w8PgRM34JoL2MNxBHZrrpOBnTRXVh2a4TI2MV3EsPsNgs6c7ivsaNVVDJCPyLp6XBYYcRcOs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790886434; c=relaxed/simple; bh=sj5QSx0jVTLcLKXl0dw0yMOgaejSa65zBLL6FKu0G28=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LViIxzPEm4JlHp7sCeSMdYp17KLSJmmVZnrKiPGRqWLQxzFE+J2x7Ax9O7rn6TZvxB3+BQqQigo6VCK0XxadjTRB2hTVmLB7bh/psS4JQl6q3o6SWMoxubQvxtqg7i8n3/NS81Dr1HmHPMUHZDAPtbXqVXnVxL1/WHVsM2XEATs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech; spf=pass smtp.mailfrom=chaosmail.tech; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b=OJ3xe5hs; arc=none smtp.client-ip=77.81.229.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chaosmail.tech Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chaosmail.tech header.i=@chaosmail.tech header.b="OJ3xe5hs" Received: by chaosmail.tech (Postfix) id EC6681C9748; Thu, 01 Oct 2026 20:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chaosmail.tech; s=mail; t=1790886426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fnn+sn/viviSJMIrXgo/zR8sy63zVOzZqPp+tjXwopE=; b=OJ3xe5hs3ZBIZQixwoGpMYee1WG2/wpP9bzbEsgHx6r2hIttcVYYEindqfRJa+P0KU7rJr PKLUO9ui7xd2hXIrPZ2/BuWHoKeNrVs0woshEX9Q37MWNTuDUJbWuQ0s+xykrgUtDSSbww faj4gUWmUOfHPJ8eZPXmSbUaBDwLYSY= From: Sasha Finkelstein Date: Thu, 01 Oct 2026 22:27:01 +0200 Subject: [PATCH v10 6/6] spmi: apple: Add interrupt functionality 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: <20261001-t603x-spmi-v10-6-ff815c66c73f@chaosmail.tech> References: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> In-Reply-To: <20261001-t603x-spmi-v10-0-ff815c66c73f@chaosmail.tech> To: Sven Peter , Janne Grunau , Neal Gompa , Stephen Boyd , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sasha Finkelstein , Alba Mendez X-Developer-Signature: v=1; a=ed25519-sha256; t=1790886421; l=11043; i=k@chaosmail.tech; s=20241124; h=from:subject:message-id; bh=6TU+MwrLfTiyBv4VeYrsCfpmcIubiyjlPuis5CkV52c=; b=q13iEQLHOwQNs40AG5hJTmu/n7HsNDBrfczfO4x+bMkBrXG3kxNPB84obVxgKEfXZCwQT4oRz c8g8vTr65cTDsBglFcuXCXBT3kVU05ses2RQJcrtRxM5w93v9PRltnO X-Developer-Key: i=k@chaosmail.tech; a=ed25519; pk=aSkp1PdZ+eF4jpMO6oLvz/YfT5XkBUneWwyhQrOgmsU= From: Alba Mendez Add support for interrupts sent by slave devices and use IRQ for RX FIFO if possible, as that 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 Reviewed-by: Janne Grunau Signed-off-by: Sasha Finkelstein --- drivers/spmi/Kconfig | 3 +- drivers/spmi/spmi-apple-controller.c | 257 +++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++- 2 files changed, 258 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 =20 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 fabccd25aa0d..2390174452ab 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -13,11 +13,17 @@ =20 #include #include +#include +#include #include #include +#include +#include +#include #include #include #include +#include #include =20 /* SPMI Controller Registers */ @@ -26,6 +32,13 @@ #define SPMI_RSP_REG 0x8 #define SPMI_ACT_REG 0xa4 =20 +#define SPMI_IRQ_MASK_BASE 0x20 +#define SPMI_IRQ_ACK_BASE 0x60 +#define SPMI_NUM_PERIPHERAL_IRQS 256 +#define SPMI_NUM_IRQS (SPMI_NUM_PERIPHERAL_IRQS + 32) + +#define SPMI_IRQ_NOTIFY 256 + /* SPMI_RSP_REG reply word */ #define SPMI_REPLY_FRAME_PARITY_STATUS GENMASK(31, 16) #define SPMI_REPLY_ACK BIT(15) @@ -41,6 +54,12 @@ struct apple_spmi { void __iomem *regs; struct mutex fifo_lock; + struct completion fifo_rx; + struct irq_domain *irqd; + raw_spinlock_t irq_mask_lock; + DECLARE_BITMAP(irq_mask_cache, SPMI_NUM_PERIPHERAL_IRQS); + int irq; + bool notify_irq; bool prev_fail; }; =20 @@ -48,6 +67,56 @@ struct apple_spmi { readl_poll_timeout((spmi)->regs + (reg), (val), (cond), \ REG_POLL_INTERVAL_US, REG_POLL_TIMEOUT_US) =20 +static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq) +{ + u32 __iomem *reg =3D 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 =3D 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 =3D spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + + writel(readl(reg) | BIT(irq % 32), reg); +} + +static void apple_spmi_irq_ack(struct irq_data *d) +{ + struct apple_spmi *spmi =3D 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 =3D 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); + clear_bit(d->hwirq, spmi->irq_mask_cache); + raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags); +} + +static void apple_spmi_irq_unmask(struct irq_data *d) +{ + struct apple_spmi *spmi =3D irq_data_get_irq_chip_data(d); + unsigned long flags; + + raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); + set_bit(d->hwirq, spmi->irq_mask_cache); + apple_spmi_irq_unmask_raw(spmi, d->hwirq); + raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags); +} + static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 param) { return opc | sid << 8 | (u32)param << 16 | (1 << 15); @@ -60,7 +129,19 @@ static int apple_spmi_wait_rx_not_empty(struct spmi_con= troller *ctrl) int ret; u32 status; =20 - ret =3D poll_reg(spmi, SPMI_STATUS_REG, status, !(status & SPMI_RX_FIFO_E= MPTY)); + if (spmi->notify_irq) { + ret =3D wait_for_completion_timeout(&spmi->fifo_rx, + usecs_to_jiffies(REG_POLL_TIMEOUT_US)); + if (!ret) + ret =3D -ETIMEDOUT; + else if (readl(spmi->regs + SPMI_STATUS_REG) & SPMI_RX_FIFO_EMPTY) + ret =3D -EIO; + else + ret =3D 0; + } else { + ret =3D poll_reg(spmi, SPMI_STATUS_REG, status, !(status & SPMI_RX_FIFO_= EMPTY)); + } + if (ret) { spmi->prev_fail =3D true; dev_err(&ctrl->dev, @@ -84,8 +165,10 @@ static int spmi_raw_cmd(struct spmi_controller *ctrl, u= 8 opc, u8 sid, u16 param, =20 if (spmi->prev_fail) { writel(SPMI_ACT_FIFO_FLUSH, spmi->regs + SPMI_ACT_REG); + apple_spmi_irq_ack_raw(spmi, SPMI_IRQ_NOTIFY); spmi->prev_fail =3D false; } + reinit_completion(&spmi->fifo_rx); =20 writel(spmi_cmd, spmi->regs + SPMI_CMD_REG); =20 @@ -188,6 +271,167 @@ static int spmi_cmd(struct spmi_controller *ctrl, u8 = opc, u8 sid) return -EINVAL; } =20 +static int apple_spmi_irq_set_type(struct irq_data *d, unsigned int type) +{ + /* all interrupts have MSI semantics */ + return type =3D=3D IRQ_TYPE_EDGE_RISING ? 0 : -EINVAL; +} + +static struct irq_chip apple_spmi_irq_chip =3D { + .name =3D "apple_spmi", + .irq_mask =3D apple_spmi_irq_mask, + .irq_unmask =3D apple_spmi_irq_unmask, + .irq_ack =3D apple_spmi_irq_ack, + .irq_set_type =3D apple_spmi_irq_set_type, + .flags =3D 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 =3D fwspec->param; + + if (fwspec->param_count !=3D 2) + return -EINVAL; + + if (args[0] >=3D SPMI_NUM_PERIPHERAL_IRQS) + return -EINVAL; + *hwirq =3D args[0]; + *type =3D args[1] & IRQ_TYPE_SENSE_MASK; + return 0; +} + +static int apple_spmi_irq_domain_alloc(struct irq_domain *irqd, unsigned i= nt virq, + unsigned int nr_irqs, void *arg) +{ + unsigned int type =3D IRQ_TYPE_NONE; + struct irq_fwspec *fwspec =3D arg; + irq_hw_number_t hwirq; + int i, ret; + + ret =3D apple_spmi_irq_domain_translate(irqd, fwspec, &hwirq, &type); + if (ret) + return ret; + + if (hwirq + nr_irqs > SPMI_NUM_PERIPHERAL_IRQS) + return -EINVAL; + + for (i =3D 0; i < nr_irqs; i++) { + ret =3D 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 i= nt virq, + unsigned int nr_irqs) +{ + int i; + + for (i =3D 0; i < nr_irqs; i++) { + struct irq_data *d =3D 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 =3D { + .translate =3D apple_spmi_irq_domain_translate, + .alloc =3D apple_spmi_irq_domain_alloc, + .free =3D apple_spmi_irq_domain_free, +}; + +static void apple_spmi_irq_handler(struct irq_desc *desc) +{ + struct apple_spmi *spmi =3D irq_desc_get_handler_data(desc); + struct irq_chip *chip =3D irq_desc_get_chip(desc); + bool handled =3D false; + unsigned long val, offset, bit; + + chained_irq_enter(chip, desc); + val =3D readl(spmi->regs + SPMI_IRQ_ACK_BASE + (SPMI_IRQ_NOTIFY / 32) * 4= ); + if (val & BIT(SPMI_IRQ_NOTIFY % 32)) { + apple_spmi_irq_ack_raw(spmi, SPMI_IRQ_NOTIFY); + complete(&spmi->fifo_rx); + handled =3D true; + } + + for (offset =3D 0; offset < SPMI_NUM_PERIPHERAL_IRQS / 8; offset +=3D siz= eof(val)) { + val =3D 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 &=3D spmi->irq_mask_cache[offset / sizeof(val)]; + for_each_set_bit(bit, &val, 64) { + generic_handle_domain_irq(spmi->irqd, offset * 8 + bit); + handled =3D true; + } + } + if (!handled) + handle_bad_irq(desc); + chained_irq_exit(chip, desc); +} + +static void apple_spmi_teardown_irq(void *data) +{ + struct apple_spmi *spmi =3D data; + + for (size_t offset =3D 0; offset < SPMI_NUM_IRQS / 8; offset +=3D 4) + writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); + + synchronize_irq(spmi->irq); + irq_set_chained_handler_and_data(spmi->irq, NULL, NULL); +} + +static int apple_spmi_init_irq(struct platform_device *pdev, + struct apple_spmi *spmi, int irq) +{ + int ret; + struct irq_domain_info info =3D { + .fwnode =3D pdev->dev.fwnode, + .hwirq_max =3D ~0U, + .ops =3D &apple_spmi_irq_domain_ops, + .host_data =3D spmi, + }; + + raw_spin_lock_init(&spmi->irq_mask_lock); + + for (size_t offset =3D 0; offset < SPMI_NUM_IRQS / 8; offset +=3D 4) { + writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); + writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset); + } + + spmi->irqd =3D devm_irq_domain_instantiate(&pdev->dev, &info); + if (IS_ERR(spmi->irqd)) + return PTR_ERR(spmi->irqd); + + ret =3D devm_add_action(&pdev->dev, apple_spmi_teardown_irq, spmi); + if (ret) + return ret; + + irq_set_chained_handler_and_data(spmi->irq, apple_spmi_irq_handler, spmi); + apple_spmi_irq_unmask_raw(spmi, SPMI_IRQ_NOTIFY); + spmi->notify_irq =3D true; + + return 0; +} + static int apple_spmi_probe(struct platform_device *pdev) { struct apple_spmi *spmi; @@ -200,6 +444,8 @@ static int apple_spmi_probe(struct platform_device *pde= v) =20 spmi =3D spmi_controller_get_drvdata(ctrl); mutex_init(&spmi->fifo_lock); + init_completion(&spmi->fifo_rx); + platform_set_drvdata(pdev, spmi); =20 spmi->regs =3D devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(spmi->regs)) @@ -211,6 +457,15 @@ static int apple_spmi_probe(struct platform_device *pd= ev) ctrl->write_cmd =3D spmi_write_cmd; ctrl->cmd =3D spmi_cmd; =20 + spmi->irq =3D platform_get_irq_optional(pdev, 0); + if (spmi->irq < 0 && spmi->irq !=3D -ENXIO) + return spmi->irq; + if (spmi->irq >=3D 0) { + ret =3D apple_spmi_init_irq(pdev, spmi, spmi->irq); + if (ret) + return ret; + } + ret =3D devm_spmi_controller_add(&pdev->dev, ctrl); if (ret) return dev_err_probe(&pdev->dev, ret, --=20 2.55.0