From mboxrd@z Thu Jan 1 00:00:00 1970 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: 8bit 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=108331 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 @@ #include #include +#include #include "spi-pxa2xx.h" +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 transfers. ([0] = disabled, 1 = 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); } +static const struct dmi_system_id pxa2xx_spi_pci_dmi_table[] = { + { + .ident = "Apple MacBook8,1", + .matches = { + 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_controller *c) { struct ssp_device *ssp = &c->ssp; @@ -166,7 +199,7 @@ static int lpss_spi_setup(struct pci_dev *dev, struct pxa2xx_spi_controller *c) c->dma_filter = lpss_dma_filter; c->dma_burst_size = 1; - c->enable_dma = 1; + c->enable_dma = pxa2xx_spi_pci_can_dma(dev, true); return 0; } @@ -238,7 +271,7 @@ static int mrfld_spi_setup(struct pci_dev *dev, struct pxa2xx_spi_controller *c) c->dma_filter = lpss_dma_filter; c->dma_burst_size = 8; - c->enable_dma = 1; + c->enable_dma = pxa2xx_spi_pci_can_dma(dev, true); return 0; } @@ -300,10 +333,12 @@ static int pxa2xx_spi_pci_probe(struct pci_dev *dev, if (ret) return ret; - 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); + } 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_device *ssp, } } + if (!platform_info->enable_dma) + pm_runtime_forbid(dev); + /* Enable SOC clock */ status = 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 = dev_get_drvdata(dev); + synchronize_irq(drv_data->ssp->irq); clk_disable_unprepare(drv_data->ssp->clk); return 0; } -- 2.39.5