From nobody Sat Jul 25 04:53:31 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA39942A16A for ; Fri, 17 Jul 2026 14:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784298990; cv=none; b=p2BdTblJPntHqhSIBRhHrllsKMy/Y/ccvqwvIGurHaFlxppS0nFE4MT0qI7tz6SfJDRhd1F/vphldlw/tOiOi5yDvgtG/DDZLoPUwGvMlkWSLR9TKlCm5ZyPKjjrvgOxsfmmq0YmIDuf5WWHhh+PzdUjT7oCO9U91ye6xtcqSDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784298990; c=relaxed/simple; bh=cWqs/xM2NprZgZsHcWAq5boJInsoGn33q+s2JuodFJ8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Mr7VbVMqWrfjh0CK0gaZmwlEkOmS6jsIW8D9FPq4d8nmbZ3EZuqoK4ZsPS7ZW7wUm1GH4iXmITTGQlRIC7Sg/CLEiF+V754Yr/OpjNe87ySIfhRL/JjWxaC6Ez11jUEceL3S117x+BRGdOMhNlesnYspImHdZkJjQmh3fBqievw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mdP3vroJ; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mdP3vroJ" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ce98cb8165so18737705ad.1 for ; Fri, 17 Jul 2026 07:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784298987; x=1784903787; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=9/Iq76p+Cd5De2qDXnt7YXrGOFcOFv7tn5csU1+2pLk=; b=mdP3vroJu4ENOLXdaCZIAEJkgtpgUjIS/679P7unjM/KZNe/bGCgxVamBz5DBdTbZq nSaNuu/xYTBbOZ3Uwc508neSGUkphNN3+jZQ70kdXPquOxgPZrxScp4xqqIa/1VmdNQI IZXc/x8U6Ud8n1InGbaG3qIylYhCyHrcD3QzEOXT2Zy4Ksw1S4OEyNNy01Ef7U2clkz4 RlAzbsgp4Mx7NAoe/k44AC3jw2skAwOTU9xv5IkUYkLCVlsUbgF6zDqIY839liit3MOF 7VAK/pAH716KWK+3e1B5Clt0cMGUYxy1xRMVvMtzNvb6tHOcKw1Y8ENXiR9yo1lRSMT4 LpVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784298987; x=1784903787; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=9/Iq76p+Cd5De2qDXnt7YXrGOFcOFv7tn5csU1+2pLk=; b=n94Z+/HZz784utv7ZGlAXPh5dOClxKuk328HCjjx2jqHXGqgecUoZHZliMBOgGoSg6 w8I/wz1y9AJwC3FMQcgh7TTYU+mUnYveWrXpzJH+odoxHuqA7WniCrTg/XTR7hyVS73w NLMLo9hIMNFW6AKJJ4WQYRj937loTTx+oop4iETVYCSEmfRpwG2CUFQTnecoc/GzDvnq bYStmeXZ5WdV+PbJoL2hnzH0B8zAk4Z08dNh9yMwTNmT/g1POb6tlRkgbIMYXsBZb4cJ Kx6tSDHhOVe1p3pmzQOoy9mfPUeYu53JdIA9jGVr8vL9GyYkLUHa5vdetrGLWH+hMq1M nChg== X-Forwarded-Encrypted: i=1; AHgh+RqgM1kUB83kUh1yiFYa+tShF4BfbF6zHI2F40QBkjd1+0BGcUfMKnGHbd/XqK+l58c29z0WKKKEOuXnglk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxhf9P5IM5ntnb1ZSonSYQ3aD0zLGZGLcNlD0ADZbpw1olMZ5as 41jdKnSTvl5RDE5JWGW/TwGLGlqN4eqnBUqumCCh5Wn2MM/h8JYg26zd1onGS60= X-Gm-Gg: AfdE7clj8hE74v4SsKSn7WzUDwkTY9UgQxvsMMGLTdLL7CupUx0aXwlnCK5uKxrgrdi 7+wyr2KPB/qSgEqL+WQdOIWjavqS018YOmpKspp3ou+y1ECujmeeeoI0jDG+CDBU+5hHe2qWHMO 1MN4NNXkv8JYNTajpgjOLN1paxEXOUlFK5rQoqS1VIedaSM3eB75acJ2M7brRVXAZSShtIOjrIb G9FBpI1ZT2Kd9XxCMOAJ3SFsT/pApEijxC6++KffgIMbgEtRLsTFSukjQEZzxu/nJWo0O2aQhKF Xx++wxrvgRVCclkR6TEbjqb86FIQjy/WxerG6rFFyUouS1mCRNbo+V0EKnRIjbiHZAHk3ePm8/F cy/53h0iJPiZg2sScFmgrjsotYnSD4gn7kw/hPbYJxb6aDrRJdtQUPcSbw1M2RXRNnlFXpeRtk6 Jz4E8Uwm7ZtXPKarj42U7RVSsOuvYabOZrY2NDHjvLn5LBzr9PZM3kb2froOvJXPzPPdgF/WRxE Ea/Hf4wa5gmdg== X-Received: by 2002:a17:903:1b27:b0:2ca:16:c169 with SMTP id d9443c01a7336-2cf1f2ee1ccmr78657245ad.12.1784298987071; Fri, 17 Jul 2026 07:36:27 -0700 (PDT) Received: from penguin.tail0a1999.ts.net (61-228-46-68.dynamic-ip.hinet.net. [61.228.46.68]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf346d9bd5sm12145695ad.45.2026.07.17.07.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 07:36:26 -0700 (PDT) From: "Shih-Yuan Lee (FourDollars)" To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Shih-Yuan Lee Subject: [PATCH v2 1/2] spi: pxa2xx: disable DMA and fix runtime PM for Apple MacBook8,1 Date: Fri, 17 Jul 2026 22:36:15 +0800 Message-Id: <20260717143616.4765-2-fourdollars@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260717143616.4765-1-fourdollars@gmail.com> References: <20260712162420.7453-1-fourdollars%40debian.org> <20260717143616.4765-1-fourdollars@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shih-Yuan Lee On MacBook8,1 (early 2015 12" MacBook), the LPSS SPI controller at 00:15.4 has two related problems: 1. The DMA handshake and interrupt routing frequently fail or time out, causing the keyboard and trackpad (driven by the applespi driver via SPI) to become unresponsive. Force PIO mode to avoid this. 2. When DMA is disabled, runtime PM autosuspend clock-gates the LPSS block between transfers. Accessing its MMIO registers while clock-gated triggers a PCIe Completion Timeout which causes a watchdog reset. Move the force-PIO DMI quirk to spi-pxa2xx-pci.c (the LPSS host controller driver) to avoid layering violations in the client driver. To prevent the PCIe Completion Timeout crash when operating in PIO mode: - Only enable runtime autosuspend in pxa2xx_spi_pci_probe() if enable_dma is true. - If DMA is disabled (either statically via the DMI quirk / module parameter or dynamically due to channel exhaustion), call pm_runtime_forbid() in pxa2xx_spi_probe() to permanently disable runtime PM autosuspend. This prevents userspace tools (like PowerTOP) or udev rules from overriding the setting. - Call synchronize_irq() in pxa2xx_spi_runtime_suspend() to wait for any active handlers on the shared interrupt line to finish before disabling the clock, avoiding unclocked MMIO register reads in ssp_int(). Avoid duplicate can-DMA pci_info() logging by checking the pre-computed enable_dma status in probe and passing a verbose flag to can_dma(). Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D108331 Signed-off-by: Shih-Yuan Lee --- drivers/spi/spi-pxa2xx-pci.c | 47 +++++++++++++++++++++++++++++++----- drivers/spi/spi-pxa2xx.c | 4 +++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-pxa2xx-pci.c b/drivers/spi/spi-pxa2xx-pci.c index cae77ac18520..c107b3b53d33 100644 --- a/drivers/spi/spi-pxa2xx-pci.c +++ b/drivers/spi/spi-pxa2xx-pci.c @@ -18,9 +18,14 @@ =20 #include #include +#include =20 #include "spi-pxa2xx.h" =20 +static bool spi_pxa2xx_force_pio; +module_param_named(force_pio, spi_pxa2xx_force_pio, bool, 0444); +MODULE_PARM_DESC(force_pio, "Force PIO mode (disables DMA) for SPI transfe= rs. ([0] =3D disabled, 1 =3D enabled)"); + #define PCI_DEVICE_ID_INTEL_QUARK_X1000 0x0935 #define PCI_DEVICE_ID_INTEL_BYT 0x0f0e #define PCI_DEVICE_ID_INTEL_MRFLD 0x1194 @@ -93,6 +98,34 @@ static void lpss_dma_put_device(void *dma_dev) pci_dev_put(dma_dev); } =20 +static const struct dmi_system_id pxa2xx_spi_pci_dmi_table[] =3D { + { + .ident =3D "Apple MacBook8,1", + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."), + DMI_MATCH(DMI_PRODUCT_NAME, "MacBook8,1"), + }, + }, + { } +}; + +static bool pxa2xx_spi_pci_can_dma(struct pci_dev *dev, bool verbose) +{ + if (spi_pxa2xx_force_pio) { + if (verbose) + pci_info(dev, "Forcing PIO mode (disabling DMA)\n"); + return false; + } + + if (dmi_check_system(pxa2xx_spi_pci_dmi_table)) { + if (verbose) + pci_info(dev, "MacBook8,1 detected: disabling DMA to force PIO mode\n"); + return false; + } + + return true; +} + static int lpss_spi_setup(struct pci_dev *dev, struct pxa2xx_spi_controlle= r *c) { struct ssp_device *ssp =3D &c->ssp; @@ -166,7 +199,7 @@ static int lpss_spi_setup(struct pci_dev *dev, struct p= xa2xx_spi_controller *c) =20 c->dma_filter =3D lpss_dma_filter; c->dma_burst_size =3D 1; - c->enable_dma =3D 1; + c->enable_dma =3D pxa2xx_spi_pci_can_dma(dev, true); return 0; } =20 @@ -238,7 +271,7 @@ static int mrfld_spi_setup(struct pci_dev *dev, struct = pxa2xx_spi_controller *c) =20 c->dma_filter =3D lpss_dma_filter; c->dma_burst_size =3D 8; - c->enable_dma =3D 1; + c->enable_dma =3D pxa2xx_spi_pci_can_dma(dev, true); return 0; } =20 @@ -300,10 +333,12 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, if (ret) return ret; =20 - pm_runtime_set_autosuspend_delay(&dev->dev, 50); - pm_runtime_use_autosuspend(&dev->dev); - pm_runtime_put_autosuspend(&dev->dev); - pm_runtime_allow(&dev->dev); + if (pdata->enable_dma) { + pm_runtime_set_autosuspend_delay(&dev->dev, 50); + pm_runtime_use_autosuspend(&dev->dev); + pm_runtime_put_autosuspend(&dev->dev); + pm_runtime_allow(&dev->dev); + } =20 return 0; } diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index 6291d7c2e06f..f9dde4b28c32 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -1351,6 +1351,9 @@ int pxa2xx_spi_probe(struct device *dev, struct ssp_d= evice *ssp, } } =20 + if (!platform_info->enable_dma) + pm_runtime_forbid(dev); + /* Enable SOC clock */ status =3D clk_prepare_enable(ssp->clk); if (status) @@ -1518,6 +1521,7 @@ static int pxa2xx_spi_runtime_suspend(struct device *= dev) { struct driver_data *drv_data =3D dev_get_drvdata(dev); =20 + synchronize_irq(drv_data->ssp->irq); clk_disable_unprepare(drv_data->ssp->clk); return 0; } --=20 2.39.5 From nobody Sat Jul 25 04:53:31 2026 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE05B42A177 for ; Fri, 17 Jul 2026 14:36:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784298991; cv=none; b=NZcJrFR4OnAEaMihUezEMlUGn/hiy7mA4Vju7rWS71ybl6iJ6MrlZHQGkgo7tANE9ATBWkKiKI3sRd3/QUdVYxYGBivjAmUMvm40DlH2BOny1Yrc3AoL5aZXpXr2YqnQvuK3DOQRVCz7bLpS7z/8SAUgYOXB6wTMW4hFFGkgJLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784298991; c=relaxed/simple; bh=ukKOayovYPz+N1uxirJ7SNW+NLgElUDsr8xtH0cDn80=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A8DEREKNmPjg2wIsqBs5ivMvX79pyOOZ+/Z10kpn+iIsrlstj5bCYlIbw1HfOMYyMQEqYxXeE+DoP6WDJIG2E5XAyifOtkSK6zehPLnUAIwKu7RydH5yp2VmcH6RXUGdm3Oc4U3iSB0ExHMdMD41oqOx28D4mHe4Ciw8dQ1BVU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=f5zRdjzQ; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f5zRdjzQ" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2cc61541f8cso17337875ad.0 for ; Fri, 17 Jul 2026 07:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784298989; x=1784903789; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zsezRzUgH4CnJUtyPPiS7O3QQiFIeq4/udW8yu2mReo=; b=f5zRdjzQ9+NF9jTVuLOGUBLYuTEAURMCj58uEvgHtFFNPTiXyOJiXN7e68nDy5jPPk J2iUo2F7b/gJ/fPLmHyFheekwtv3wF88qurlxE9LqImZgu8vo4BIDz+7rhA4zYjyzGjJ V3DRYwCu3PPNuB+BNQ8JLyjStt8LcrZJ2/jyd2U0E0RWhal+dhh9mf7Um10QtSLEXOmU P/AXlAcYMoLq3rzmvrJ/yQ4ZLoXwuO+6Iu4C5yylbsVyt4f7BT55/mpYn2Nfn+QA71l2 +UzK6ZFxbT5mq7dva//iH9W30rzZOyJaSsZk3mBNc4VriKgkMQn/AE2oyE3o3iZA8MWs 3pXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784298989; x=1784903789; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=zsezRzUgH4CnJUtyPPiS7O3QQiFIeq4/udW8yu2mReo=; b=r0lwn3fGWBhvh1CFCa3s+mDqA8yFFczfYjGUgmvXIJ/dgxY285+U4cjd9Sb7SL5Z+k Bje6vMseLZRqH2TxB4Ngye078758MPBEzY2S40g5WEUU9JUuuSBaaY7hGssywj53aTB3 ccAJ2CjqazY5vhvJWXcNOR46AuXJpQdJN3s5x7USrKgkYqYKz5ezg9bNQDErMLJEzH2M KXKLoO2KgaGHzzbQ6hoMLcmp+ZzfFEiHSfpXJ/wHUoPwHhADJsLa7xYEF+ftWwFHC0OF /7GmL6FAfADo7DKpfgM6NO4QkU+8qoowft66pBqL4XK/bKWwfB1Gq7ZduoMlFiRHDHAw lDDg== X-Forwarded-Encrypted: i=1; AHgh+RoSKlINvpYCgz9NAaLt0H16rgrySTSZB2YxLckfCp/Q8cgaBzTJD60PmnLjPluPaursoJ2u+ScQ+nfT9us=@vger.kernel.org X-Gm-Message-State: AOJu0YyDXTeZUoEvt9ngF3jkWPQdUKEqQb4R25z+wBdJr422eFBGkwqV PtViEZkPOqjn9Atcu4YBOu+RjIk3u4euwVNEP0BZyBcJ/XIXkWUEa8XsE4G131I= X-Gm-Gg: AfdE7clphEVxpTIJGijZCT/0AP7PaqqFNXs93KZTw5VDFT43qMn5h4d9gNNJWtjb4DO EjUD1B6oP7oD0ypDH9o1JH7ln5gTj0/xAS0b1SepWaZEZmzCsQGbpyMSUbMvR4hDrNDg3DRxdSe dtH8k8rk0NcnUKGofMcAxkVd3FYRF0F9W8NKiDtr+UkLuOjydxdSeAwxR40FuCcjpQAYm4dRm4Z aIKW7ldAwdrefubQ0tqLBXFxCRtZdSB0eC4FqCniRycpKRjpWQAgNM1XYT56kzef1xemeg133jg EPAxdkTe8k1pCOC+wTrBAR1kvpHQoOSRUbQCNSeflDrcQah+MyzZ/zfUe54983qugSaDrZm0UnK oz0PksNUzRjV07p4gEL5hueKIZySUyLuSI/k5mS2y4uo4irgcmpZKUp+Azugt6BCTf3KLvv1cue mVbMJTio9gnY6X0zYi3pX1GmGj1Nmbc1j/wrnQGMcPfAmbb/MmpDhdExUcOIT9Tsx/dje1X+kgu F3zGaljTD9ylQ== X-Received: by 2002:a17:902:fc43:b0:2cf:41ba:96c2 with SMTP id d9443c01a7336-2cf41bab3cdmr1005375ad.12.1784298988850; Fri, 17 Jul 2026 07:36:28 -0700 (PDT) Received: from penguin.tail0a1999.ts.net (61-228-46-68.dynamic-ip.hinet.net. [61.228.46.68]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf346d9bd5sm12145695ad.45.2026.07.17.07.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jul 2026 07:36:28 -0700 (PDT) From: "Shih-Yuan Lee (FourDollars)" To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Shih-Yuan Lee Subject: [PATCH v2 2/2] spi: pxa2xx: restore LPSS private register state on S3 resume Date: Fri, 17 Jul 2026 22:36:16 +0800 Message-Id: <20260717143616.4765-3-fourdollars@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260717143616.4765-1-fourdollars@gmail.com> References: <20260712162420.7453-1-fourdollars%40debian.org> <20260717143616.4765-1-fourdollars@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Shih-Yuan Lee Intel LPSS SPI controllers lose all private register state across S3 suspend because the LPSS power domain is fully removed. On resume the driver only re-enables the SSP clock, leaving the LPSS private registers in their power-on-reset state, which causes two problems: 1. LPSS_PRIV_RESETS (offset 0x04 within the LPSS private space) stays zero, keeping the functional block in reset. Any MMIO access while the block is held in reset causes a PCIe Completion Timeout and a watchdog-triggered system reset. LPSS_PRIV_RESETS_FUNC and LPSS_PRIV_RESETS_IDMA must be de-asserted before any other register access on resume. 2. The LPSS software chip-select control register must not be blindly restored from its suspend-time snapshot: if CS was asserted at the moment of suspend, restoring that state corrupts the first post-resume SPI transaction. Instead, call lpss_ssp_setup() which unconditionally writes SW_MODE | CS_HIGH (idle/deasserted), matching the state established at probe time. To resolve these issues safely: - Wrap S3 suspend/resume with pm_runtime_resume_and_get() and pm_runtime_put_autosuspend() respectively. This ensures that if the device was runtime-suspended, it is temporarily resumed to active state prior to suspend. This guarantees that the clock and power domain are active during MMIO register access, and that the private registers are consistently saved and restored across S3 sleep cycles. - Save only the first 6 LPSS private registers (offsets 0x00 to 0x14) via drv_data->lpss_base during suspend. Offsets beyond 0x14 (except CS control at 0x18, which is re-initialised by lpss_ssp_setup()) are reserved/unimplemented on LPT platforms (such as MacBook8,1), and writing to them triggers a PCIe Completion Timeout causing a system freeze. - Store the saved context in drv_data->lpss_priv_ctx[6] (inside struct driver_data) which is private to the core driver. This avoids changing the layout of struct pxa2xx_spi_controller, preventing ABI symbol version mismatches with uncompiled platform drivers (e.g., spi-pxa2xx-platform.ko). On resume, de-assert resets first, restore all other saved registers, then call lpss_ssp_setup() to re-initialise CS. Signed-off-by: Shih-Yuan Lee --- drivers/spi/spi-pxa2xx.c | 88 +++++++++++++++++++++++++++++++++++----- drivers/spi/spi-pxa2xx.h | 1 + 2 files changed, 78 insertions(+), 11 deletions(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index f9dde4b28c32..6e554911c076 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -72,7 +72,12 @@ struct chip_data { #define LPSS_CAPS_CS_EN_SHIFT 9 #define LPSS_CAPS_CS_EN_MASK (0xf << LPSS_CAPS_CS_EN_SHIFT) =20 -#define LPSS_PRIV_CLOCK_GATE 0x38 +/* Offsets from drv_data->lpss_base */ +#define LPSS_PRIV_RESETS 0x04 +#define LPSS_PRIV_RESETS_IDMA BIT(2) +#define LPSS_PRIV_RESETS_FUNC 0x3 + +#define LPSS_PRIV_CLOCK_GATE 0x38 #define LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK 0x3 #define LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON 0x3 #define LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_OFF 0x0 @@ -1488,16 +1493,38 @@ static int pxa2xx_spi_suspend(struct device *dev) struct ssp_device *ssp =3D drv_data->ssp; int status; =20 + status =3D pm_runtime_resume_and_get(dev); + if (status < 0) + return status; + status =3D spi_controller_suspend(drv_data->controller); if (status) - return status; + goto out_put; =20 pxa_ssp_disable(ssp); =20 - if (!pm_runtime_suspended(dev)) - clk_disable_unprepare(ssp->clk); + if (is_lpss_ssp(drv_data)) { + unsigned int i; =20 - return 0; + /* + * Save the first 6 LPSS private registers (offsets 0x00 to 0x14) + * while the clock is still enabled. They are lost when the LPSS + * power domain is removed across S3 and must be restored on resume. + * Use drv_data->lpss_base so the correct per-platform offset + * is applied regardless of LPSS IP revision. + * Registers beyond 0x14 (except CS control at 0x18) are reserved + * or unimplemented on LPT, and accessing them triggers a PCIe + * Completion Timeout causing a system halt. + */ + for (i =3D 0; i < 6; i++) + drv_data->lpss_priv_ctx[i] =3D readl(drv_data->lpss_base + i * 4); + } + + clk_disable_unprepare(ssp->clk); + +out_put: + pm_runtime_put_noidle(dev); + return status; } =20 static int pxa2xx_spi_resume(struct device *dev) @@ -1507,14 +1534,53 @@ static int pxa2xx_spi_resume(struct device *dev) int status; =20 /* Enable the SSP clock */ - if (!pm_runtime_suspended(dev)) { - status =3D clk_prepare_enable(ssp->clk); - if (status) - return status; - } + status =3D clk_prepare_enable(ssp->clk); + if (status) + return status; + + if (is_lpss_ssp(drv_data)) { + unsigned int i; =20 + /* + * The LPSS power domain is removed across S3, taking + * all private registers with it. De-assert the + * functional block and IDMA resets first; any MMIO + * access while the block is held in reset causes a + * PCIe Completion Timeout and a watchdog-triggered + * system reset. + */ + writel(LPSS_PRIV_RESETS_FUNC | LPSS_PRIV_RESETS_IDMA, + drv_data->lpss_base + LPSS_PRIV_RESETS); + + /* Restore the other 5 saved private registers */ + for (i =3D 0; i < 6; i++) { + if (i =3D=3D LPSS_PRIV_RESETS / 4) + continue; + writel(drv_data->lpss_priv_ctx[i], + drv_data->lpss_base + i * 4); + } + + /* + * Re-initialise the SW chip-select control register so + * CS starts deasserted (SW_MODE | CS_HIGH), regardless + * of the state it was in at suspend time. A stale + * asserted CS on the first post-resume transaction + * corrupts the write-status response from the device. + */ + lpss_ssp_setup(drv_data); + } /* Start the queue running */ - return spi_controller_resume(drv_data->controller); + status =3D spi_controller_resume(drv_data->controller); + if (status) { + clk_disable_unprepare(ssp->clk); + return status; + } + + /* Let runtime PM autosuspend again if needed */ + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return 0; } =20 static int pxa2xx_spi_runtime_suspend(struct device *dev) diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h index 447be0369384..fce776e2404c 100644 --- a/drivers/spi/spi-pxa2xx.h +++ b/drivers/spi/spi-pxa2xx.h @@ -71,6 +71,7 @@ struct driver_data { irqreturn_t (*transfer_handler)(struct driver_data *drv_data); =20 void __iomem *lpss_base; + u32 lpss_priv_ctx[6]; =20 /* Optional slave FIFO ready signal */ struct gpio_desc *gpiod_ready; --=20 2.39.5