From nobody Sat Jun 20 17:33:50 2026 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 A4F4029B77E for ; Sun, 12 Apr 2026 16:32:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776011540; cv=none; b=R7yh90WSt3EuVk7F4GWaIQagnExJqpj7T21/YbMFki0KCgElo4ZGBFipsO8BMy45Pp+ju9rpRWBmOua2PVLYSPr89IYktXIdyiBPZXw+nxqFASkao2jUr5TYzbOZjSyIC81ixwdBL+9FZjKshdoVUtKLpAUy+U+tH+IOXtHb8L8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776011540; c=relaxed/simple; bh=qC/bld90r+ThMcnTaEI8CINzwhOGNircQN5AmvhHCP0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JL7Wp/WvP6Kd+r2cpSHExB55JzB2sIcPYo69G4ICyMjGSAlviQK64hl2ofG8SxH15s0VEjqCiMFn/8/bDE1QwtMPyHLlzvr1qCZiNrrFdAHyKuuL6ZbZMSxThHAi6DxBq6iYpLxIc6XAkuy15stt0tjWtJXtPKBFJSljB6spPUk= 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=R1lemTGY; arc=none smtp.client-ip=209.85.218.50 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="R1lemTGY" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-b9bff57cb62so588172566b.2 for ; Sun, 12 Apr 2026 09:32:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776011537; x=1776616337; 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; bh=QkilzuMUQETyKz1FjFPqWn2VyiH1H/H3jmR+rqzk7H0=; b=R1lemTGYVMEfAWjZifZg7CULmonpTMYojK+x8GF+k3EOuW0jeosAybx6vLMP+WGDqZ 2K8spSvtSocIkQuxRmCt0cIlbFY+9dFhF26DrxlM0BiTGZVDE/HK8+mVgi7haNtf1Tud BivJOh4obcobjf+GUaHdfttItb+xwQt8EZpRWsftJFKr0xyqR7OExYFGQKTZ4DelVWHp 0PB+/NEhJmiqOSeVW57D36p/jMCmtCHMAO4h6FxkRYoOkqqyYONelJnm8qIje7Nb7a2m osaRN/ofkfYt/2xgJDGRaQaRBmv/nF9n9pnyKYm85ibT2Vn2Zr2TfJLZa+2Py40kCbF+ WKIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776011537; x=1776616337; 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; bh=QkilzuMUQETyKz1FjFPqWn2VyiH1H/H3jmR+rqzk7H0=; b=q8kaU25eAvgcsl+ryCA3ph+iw1Y1Bs0YPaItgjUgDBjq95QltCg6I37g05ky6ob0Z/ Ebr5JBz9QV7Pcoz9yc31V0wBr2+jOjFTt0tD3ZpmaNjiO2v6kq4DQfEn2YrApvLHR+uj lVR6som3YGm8NyBDTK/pU/puxbfTSyj4nH/lb/XlriD3+5OUIT6MN0KWW5QTcILimHfR Tf4XcRouxBVy+XxbQrmHo7SWRGwaULUjpR/5LBOkyPTNPqCtwpa0sT+hubi8RagBeYqY bWZHEZRq1j6REOfp1lDBToI99ljg3gOOmwGyjLvuo62oWX/RvOkjFqv0drPsPRojjFyG U05A== X-Forwarded-Encrypted: i=1; AJvYcCVo2sYYE7Z/ERox3zEGQH2tTkb9VE6jkEd/47xZu2q28ESYuq9tuavUiLcpwGrkAek4u3OC5qz9kZo+f+s=@vger.kernel.org X-Gm-Message-State: AOJu0Yyffiuj+0mVz/wcUxZay47m/YPTpekG+MKvbUQZXVabNy/P0vl6 wiy9qP0EheWIMmuOMXUce7q+Vr8XasQ0MxC8qnLqVdmAaURW5EGWwXSU X-Gm-Gg: AeBDietEcUfwZF7iu0F8VpB2zQM84QpxzYUldLlhIb3f530umEoGFFfOjOnMbdbSVkZ Hp99Fap6q0CRudplqrui4VZa9s+HbfUHmhQ0wp6uXYav8T9+wlsX1The4dD2sTmzUgCItXMIy5A VBQIa8FIyXFCXs4z5r5zr3X3MKO3i7bUpLfDawgnyHCoWdMO4v2kGE34T4yV049zI7M6gkbj2dM ceZ0sjwJBDQ8JyRGoDw+u9Nyf4D49jB1YXKTMV0+/dXhjVHfkjbjf4yrvrRT7PuPaqSZ4RJurXx RtIOVMEPmYCLycwNiQOoc2hgqHk9WYjxco7w9hMa1An8M/5LT4NZ0+DHR7cvLzFa4ADAQViF1vx FWHQB5p7KoWq5mrbutGnpV9bd+bcaDr6Qh+Qp6SRPfColiv5SG9ylzVQkH/pcrleOl9veZbtCzn Gp5SkjB7XNQ2K0AGIwgO5JWg== X-Received: by 2002:a17:907:6ea7:b0:b8f:f08a:4b80 with SMTP id a640c23a62f3a-b9d724ee4f5mr589125966b.3.1776011536824; Sun, 12 Apr 2026 09:32:16 -0700 (PDT) Received: from khalil-hp.home ([62.250.67.33]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9d6e7f1a3bsm236468666b.62.2026.04.12.09.32.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 09:32:16 -0700 (PDT) From: Khalil X-Google-Original-From: Khalil To: broonie@kernel.org, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rf@opensource.cirrus.com, linux-spi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Khalil , Khalil Subject: [PATCH 1/3] spi: Preserve preset cs_gpiod in __spi_add_device() Date: Sun, 12 Apr 2026 18:31:49 +0200 Message-ID: <20260412163151.506282-2-khalil@rentman.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260412163151.506282-1-khalil@rentman.nl> References: <20260215135524.1171065-2-khalil@rentman.nl> <20260412163151.506282-1-khalil@rentman.nl> 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" __spi_add_device() unconditionally overwrites spi->cs_gpiod[] from ctlr->cs_gpiods[cs], even if the caller has already set a GPIO descriptor on the device. This prevents drivers like serial-multi-instantiate from pre-configuring a GPIO chip select acquired from ACPI before adding the device. Skip the overwrite when the device already has a cs_gpiod set for the given index, allowing callers to preset GPIO chip selects that aren't described in the controller's cs-gpios property. This is useful on platforms where the ACPI _DSD cs-gpios property on the SPI controller is incomplete, but the peripheral's ACPI node does contain the correct GpioIo resource for its chip select. Suggested-by: Richard Fitzgerald Signed-off-by: Khalil --- drivers/spi/spi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index a0b2bd3b8..64be99d13 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -734,7 +734,8 @@ static int __spi_add_device(struct spi_device *spi, str= uct spi_device *parent) =20 for (idx =3D 0; idx < spi->num_chipselect; idx++) { cs =3D spi_get_chipselect(spi, idx); - spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]); + if (!spi_get_csgpiod(spi, idx)) + spi_set_csgpiod(spi, idx, ctlr->cs_gpiods[cs]); } } =20 --=20 2.43.0 From nobody Sat Jun 20 17:33:50 2026 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 B6F692D77F5 for ; Sun, 12 Apr 2026 16:32:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776011541; cv=none; b=bJSIO58kPzYrdEHU2QI5lE7sZ7Jsk8Vt5NH52h8RGxf4ue/cje6R0JZehNi62Te3H5dS1J4lC2C8WSHfMVMuWDqen21fKzDBIF+YdnH4CreL8z5CIImEmQ9DZ0o7ieM9zKjrnT1FFL/21LrKxEhjeOe/naeMv9qI5Ekx93XIfb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776011541; c=relaxed/simple; bh=Tclstug7hRiXGCPxAlH+OYkGPX8vCtXfLKlt8b4ukG4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TC2tKWUgmLUo36VS8VAvVx7rxXyFuw/Y0dvpV5H0lqkL42i1rQ4bSiYF9/LRN/Ezbtp8dK7AHOqPMUI3FX6Wfd6IEeggmjmYo3V20qYXayqcSsQ10qkIg5RiujEbArmWcE3oILIX4efb3f+S7p2EjTEkwuC05acIfkoFJRHLg5c= 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=AyQgTHKn; arc=none smtp.client-ip=209.85.218.54 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="AyQgTHKn" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-b8f9568e074so589385066b.0 for ; Sun, 12 Apr 2026 09:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776011538; x=1776616338; 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; bh=WUQbeJrmnLAC83DjJTyOiwZ5gn/HwjrSl7M0Tq5ML7I=; b=AyQgTHKnk2luhEOVvW/e3DA/S/ikLSHmqmLsG/JUxOokJt+rwpnTY+oyWTEtqbNBN+ W+z0HJxK4FYQ9rNoQ/lvF2JeAIB6L7yipcokJwnYFEJ6fTT8lJjurBJ2nOw7J0rIi6fO WoyDb3aqpYjmuokjE+rPQgJa7Um5licNDaA6nqibXzfROA+IwTlD4x49Qk0KULog0+zn uUFS5CEyxNGmAKZZyiOoMc8BWnSiMazSlDRKsOEsFAf4FE5ffXaeVDyWSnjPd6ZFvhkc tRgsp6Uh4Iv9RyJ3FaQx4x476vBCMz8Zgm0nSBroBpZw2Mu94SvGn/7MvtwFpScqPEtS Ghzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776011538; x=1776616338; 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; bh=WUQbeJrmnLAC83DjJTyOiwZ5gn/HwjrSl7M0Tq5ML7I=; b=BEKwQk2zZna1pqlXt8L+7pm1QyvkSgC2bz1oMKJj+63/sjd3hNe6NFk08eySLo3WIR Jy/KePaMc2Tsp5XuFMbMRdnlzql1bhag0O+Ps1heojDRxHtN3marSjY7OEXQqLCdMq60 jJViIRudELqU0sIE1gKLDVpNNThnE+4P6fjlw3pKZR3tsSESbEez9C249BXVl0i4ucrY lScHI6OmkaiaR0RelxoDex6GvcLRmSpcQZVTZIbf+u3YOUNYnjxHmI8u2WTrd6Zd93rQ BU0Sdvuy6z33xSkhiMAcMJnqDWh1V+pW+qpQG94wB1xIZz74dxeLGQF8+tsScLIGCnMq 9NaQ== X-Forwarded-Encrypted: i=1; AJvYcCVCLU1+VAXXKk/IHCqr8hU1eIAOvNcjpQdkK3oclLuI5Xfx1yst7KyXgsMf7sv0FthN1owSskCQ9uhIO3M=@vger.kernel.org X-Gm-Message-State: AOJu0YxPu0ReZk5pue/J2cuZyraDOmPhHUSDwgk03vFQDsaZbJRKNZ5W kFLpVoyyOu9q7dAjw9x1lo7YuuiT0v9l4EQQdCmYWnaJyhT5umOPdwqs+7fD9USG X-Gm-Gg: AeBDievDq5C0OloP0oFYtlC21cnWzF2OvBK+lBE2+vG/y8OyUcS+c4GB1Ui1U0AWKb5 e7tEfO3B/u7PBTheapWVmHoLTYT7Yrvtkdz97kZotT5JOlrAaGfUSgirtW0lNhuCC1ZPK76AaR3 wEb4U3LWu4qyKe85+zq2nYfmh+/ToU3t52MjYi+zqoQ0d8lmiXVhxLPtU7VCyYYT8ZTOMMaPNaq D9b+UCN1uiBVwbmLtYKYiyQWqPJQ+WPbkxHNv/R9jk3QO/0otxsm9xatB/kdMvdwYCKqgrzQECk sKwAeicsnNxtY422vpc/XXt8kNkuRo75Emk2TlvNQBsSnYk4j5oUOI5DJyelvAZMjbj2Y9cud2p ziHT3gpWxYUXyYw5HHq3xPytEd+ra5zyoS6Os89RUuO49THhWrNo/yPp2SKvsKVBqwiLKRJOMuX tczFQwskfnJbrVwyzT+SDBJHV2Ii2hTgLG X-Received: by 2002:a17:907:74d:b0:b9c:bc70:e928 with SMTP id a640c23a62f3a-b9d726577e3mr577628966b.25.1776011537620; Sun, 12 Apr 2026 09:32:17 -0700 (PDT) Received: from khalil-hp.home ([62.250.67.33]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9d6e7f1a3bsm236468666b.62.2026.04.12.09.32.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 09:32:17 -0700 (PDT) From: Khalil X-Google-Original-From: Khalil To: broonie@kernel.org, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rf@opensource.cirrus.com, linux-spi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Khalil , Khalil Subject: [PATCH 2/3] platform/x86: serial-multi-instantiate: Fix SPI chip select on platforms with incomplete ACPI cs-gpios Date: Sun, 12 Apr 2026 18:31:50 +0200 Message-ID: <20260412163151.506282-3-khalil@rentman.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260412163151.506282-1-khalil@rentman.nl> References: <20260215135524.1171065-2-khalil@rentman.nl> <20260412163151.506282-1-khalil@rentman.nl> 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" Some HP laptops with Intel Lunar Lake and dual Cirrus Logic CS35L56 amplifiers over SPI have an incomplete cs-gpios property in the SPI controller's _DSD - it only declares the first chip select. The remaining chip select GPIOs are defined as GpioIo resources in the peripheral's ACPI node but are not referenced by the controller. This causes the SPI framework to reject devices whose chip select exceeds num_chipselect with -EINVAL, preventing the second amplifier from probing. Fix this on known affected platforms by: 1. Adding a DMI quirk table to identify affected systems 2. For devices with chip selects outside the controller's range, acquiring the GPIO from the peripheral's ACPI GpioIo resource 3. Extending num_chipselect and reallocating the controller's cs_gpiods array to install the GPIO descriptor 4. Setting SPI_CONTROLLER_GPIO_SS so the framework calls both the GPIO toggle and controller->set_cs (needed for clock gating on Intel LPSS controllers) Only chip selects beyond the controller's num_chipselect are fixed up. Chip selects within range with a NULL cs_gpiods entry are left alone, as NULL means "native chip select" which is intentional. Tested on HP EliteBook 8 G1i 16 inch (board 8D8A) with 2x CS35L56 Rev B0 amplifiers. Both amplifiers probe and produce audio. Signed-off-by: Khalil --- .../platform/x86/serial-multi-instantiate.c | 168 ++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/drivers/platform/x86/serial-multi-instantiate.c b/drivers/plat= form/x86/serial-multi-instantiate.c index 1a369334f..0d30bd0a7 100644 --- a/drivers/platform/x86/serial-multi-instantiate.c +++ b/drivers/platform/x86/serial-multi-instantiate.c @@ -8,6 +8,10 @@ =20 #include #include +#include +#include +#include +#include #include #include #include @@ -46,6 +50,53 @@ struct smi { int spi_num; struct i2c_client **i2c_devs; struct spi_device **spi_devs; + struct gpio_desc *cs_gpio; +}; + +/* + * Quirk data for platforms with broken ACPI SPI chip select descriptions. + * cs_gpio_idx: index of the GpioIo resource in the ACPI _CRS that provides + * the chip select GPIO for devices missing a proper cs-gpios + * entry on the SPI controller. + */ +struct smi_cs_gpio_quirk { + int cs_gpio_idx; +}; + +static const struct smi_cs_gpio_quirk hp_elitebook_8g1i_quirk =3D { + .cs_gpio_idx =3D 0, +}; + +/* + * DMI table of platforms with broken SPI chip select ACPI descriptions. + * + * These systems have multiple SPI peripherals (e.g., dual CS35L56 + * amplifiers) but the SPI controller's _DSD cs-gpios property is + * incomplete - it only declares the first chip select. The remaining + * chip select GPIOs are defined as GpioIo resources in the peripheral's + * ACPI node but are not referenced by the controller. + */ +static const struct dmi_system_id smi_cs_gpio_dmi_table[] =3D { + { + .ident =3D "HP EliteBook 8 G1i 16 inch", + .matches =3D { + DMI_MATCH(DMI_SYS_VENDOR, "HP"), + DMI_MATCH(DMI_BOARD_NAME, "8D8A"), + }, + .driver_data =3D (void *)&hp_elitebook_8g1i_quirk, + }, + { } +}; + +/* + * ACPI GPIO mapping for the chip select GpioIo resource. + * Maps "cs-gpios" to the GpioIo resource at index 0 of the ACPI _CRS. + */ +static const struct acpi_gpio_params smi_cs_gpio_params =3D { 0, 0, false = }; + +static const struct acpi_gpio_mapping smi_cs_gpio_mapping[] =3D { + { "cs-gpios", &smi_cs_gpio_params, 1 }, + { } }; =20 static int smi_get_irq(struct platform_device *pdev, struct acpi_device *a= dev, @@ -99,6 +150,101 @@ static void smi_devs_unregister(struct smi *smi) } } =20 +/* + * smi_spi_setup_cs_gpio - Fix up chip select for a device on a platform + * with broken ACPI cs-gpios description. + * + * On affected platforms, the SPI controller's cs-gpios property is incomp= lete, + * so the framework has no GPIO descriptor for some chip selects. This cau= ses + * __spi_add_device() to reject the device with -EINVAL (cs >=3D num_chips= elect). + * + * This function: + * 1. Extends num_chipselect if the device's CS is out of range + * 2. Reallocates cs_gpiods to match, preventing out-of-bounds access + * in __spi_add_device() + * 3. Installs the GPIO from the peripheral's ACPI node into the + * controller's cs_gpiods array so __spi_add_device() propagates + * it to the device + * 4. Sets SPI_CONTROLLER_GPIO_SS so the framework calls both the GPIO + * toggle and controller->set_cs (needed for clock gating on Intel + * LPSS controllers) + */ +static int smi_spi_setup_cs_gpio(struct device *dev, + struct spi_device *spi_dev, + struct smi *smi, + const struct smi_cs_gpio_quirk *quirk) +{ + struct spi_controller *ctlr =3D spi_dev->controller; + struct gpio_desc **new_gpiods; + u16 cs =3D spi_get_chipselect(spi_dev, 0); + + /* + * Only fix up chip selects that the controller doesn't know about. + * A NULL cs_gpiods[cs] within the controller's num_chipselect range + * means "native chip select" - that's intentional, not broken. + * The broken case is when cs >=3D num_chipselect, meaning the ACPI + * cs-gpios property on the controller was incomplete. + */ + if (cs < ctlr->num_chipselect) + return 0; + + /* Extend num_chipselect to cover this device */ + dev_info(dev, "Extending num_chipselect from %u to %u for CS%u\n", + ctlr->num_chipselect, cs + 1, cs); + ctlr->num_chipselect =3D cs + 1; + + /* Acquire the CS GPIO from the ACPI GpioIo resource if not yet done */ + if (!smi->cs_gpio) { + int ret; + + ret =3D devm_acpi_dev_add_driver_gpios(dev, smi_cs_gpio_mapping); + if (ret) { + dev_warn(dev, "Failed to add CS GPIO mapping: %d\n", ret); + return ret; + } + + smi->cs_gpio =3D devm_gpiod_get(dev, "cs", GPIOD_OUT_HIGH); + if (IS_ERR(smi->cs_gpio)) { + dev_warn(dev, "Failed to get CS GPIO: %ld\n", + PTR_ERR(smi->cs_gpio)); + smi->cs_gpio =3D NULL; + return -ENOENT; + } + dev_info(dev, "Acquired CS GPIO for CS%u from ACPI GpioIo[%d]\n", + cs, quirk->cs_gpio_idx); + } + + /* + * Reallocate the controller's cs_gpiods array to accommodate the + * new num_chipselect, and install the GPIO descriptor. This is + * necessary because __spi_add_device() unconditionally reads + * ctlr->cs_gpiods[cs] to set the device's cs_gpiod. + */ + new_gpiods =3D devm_kcalloc(&ctlr->dev, ctlr->num_chipselect, + sizeof(*new_gpiods), GFP_KERNEL); + if (!new_gpiods) + return -ENOMEM; + + if (ctlr->cs_gpiods) { + unsigned int i; + + for (i =3D 0; i < cs; i++) + new_gpiods[i] =3D ctlr->cs_gpiods[i]; + } + new_gpiods[cs] =3D smi->cs_gpio; + ctlr->cs_gpiods =3D new_gpiods; + + /* + * SPI_CONTROLLER_GPIO_SS ensures the framework calls both the + * GPIO CS toggle and controller->set_cs(). This is required on + * Intel LPSS controllers where set_cs handles clock gating. + */ + ctlr->flags |=3D SPI_CONTROLLER_GPIO_SS; + + dev_info(dev, "Installed GPIO CS on controller for CS%u\n", cs); + return 0; +} + /** * smi_spi_probe - Instantiate multiple SPI devices from inst array * @pdev: Platform device @@ -112,10 +258,19 @@ static int smi_spi_probe(struct platform_device *pdev= , struct smi *smi, { struct device *dev =3D &pdev->dev; struct acpi_device *adev =3D ACPI_COMPANION(dev); + const struct dmi_system_id *dmi_id; + const struct smi_cs_gpio_quirk *quirk =3D NULL; struct spi_controller *ctlr; struct spi_device *spi_dev; char name[50]; int i, ret, count; + u16 cs; + + dmi_id =3D dmi_first_match(smi_cs_gpio_dmi_table); + if (dmi_id) { + quirk =3D dmi_id->driver_data; + dev_info(dev, "Applying CS GPIO quirk for %s\n", dmi_id->ident); + } =20 ret =3D acpi_spi_count_resources(adev); if (ret < 0) @@ -139,6 +294,19 @@ static int smi_spi_probe(struct platform_device *pdev,= struct smi *smi, } =20 ctlr =3D spi_dev->controller; + cs =3D spi_get_chipselect(spi_dev, 0); + + /* + * On quirked platforms, fix up the chip select GPIO for + * devices that would otherwise fail due to incomplete + * ACPI cs-gpios on the SPI controller. + */ + if (quirk) { + ret =3D smi_spi_setup_cs_gpio(dev, spi_dev, smi, quirk); + if (ret) + dev_dbg(dev, "CS GPIO setup returned %d for CS%u\n", + ret, cs); + } =20 strscpy(spi_dev->modalias, inst_array[i].type); =20 --=20 2.43.0 From nobody Sat Jun 20 17:33:50 2026 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 2700C2EB87F for ; Sun, 12 Apr 2026 16:32:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776011543; cv=none; b=YESTdLiM6nD75wvmQaJsCi9cQjGTFvOMD/1AdIbPV5dL/02+fwleR82KxBogiO+rR3eqGmLr2/FsIE5SFcwUrnRjLV3e3/rf54WNzeee6fjRAXJEZlgGWNMnhknqAE3v6nk5BPCwK/HorQg8DGLKBCZTH+ai1SA1KLnkV7jcAjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776011543; c=relaxed/simple; bh=A9NrOmrGg9D5qQPIJd3OHlgLpJRhg3BN4oaCn3ZDTsQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jiMNU9swYn+LH/VACnQy912nWQmSeHLMZJ+wTtSPdfPvRsRpJc1ztViitNL8Alu1GHFr/yUXrWe8jomOFI1SQ3+fFfiTfPvdFyV+ceAWPT3V3ehMZgaM4Uq9zZw78+tF5AYCJ8FA5OF0oOBCuZ2UoPRfl903krYFIkmQnenGHzM= 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=HWdieLq3; arc=none smtp.client-ip=209.85.218.46 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="HWdieLq3" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-b9c3e2cf3c0so560477566b.1 for ; Sun, 12 Apr 2026 09:32:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776011539; x=1776616339; 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; bh=bb0Cl07VkZM2TjR90yXu/+DWSboJw3nu1/V+vc9DpAw=; b=HWdieLq3FjGDVhne0yX7HcGi5NK+CKOtbSKa/lG5AU/ee0fYf7sdRBA/hW1t22mQBw ryr9dv9+YbhN2q7qMZHVv1tgaebLfPgnppXpMOs9M1evZ12TG1F9OOOebzqNumAlvasL cosJzquotaCabhO3rAnv/NFNpFS+JhmPbOhFz+2ftFrXjf4cyfWpKDMj1h7rTi+W6iX8 enOrBH/pOighuPt9VKHU1Joce4nhFZH1du//oeTZRdjGtrwvJ4yDlLryGBxAUfPvd32g 5irjQiYETany6eforh9+XUNnutaA5/q3+SqzuVa8O+XidEm5RD1/+/ku3lVdL3wZzl6G VsQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776011539; x=1776616339; 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; bh=bb0Cl07VkZM2TjR90yXu/+DWSboJw3nu1/V+vc9DpAw=; b=BnNXKZTKc21A8moGCRCCiZ/EWCEmjQ1GlPZr7kdqWT1Z2BOAMms2PmjZ+uDPl3M5ec +AFaW6NmvNKjzgDhqCVwuvdOhgS4VvxaFR56SSH1qbjNdyurBW7+hs6wBe/s/q7PTjOd BwQjWd6P2dC9nsSDM0voinPwUJey3VIKgzc3st6KmLoG/gq+CXB8T+e4yXIx7SZFErZv hopVtOcbgqF+hSmhslJqweX4j2p3BS0b0P5dGZsHwCQXeqhoyXLE2Ei+vSijTeho2HIW 9yX5E768sTCOOERU0mX6BsrajBUWQF/Xcdfd2GL0jDAKU+AxvfQGIGL4aHqSMpC4W2C/ EsMg== X-Forwarded-Encrypted: i=1; AJvYcCXfmzumojcsNu8jcPwGiJKEPaIndUVH5rTI0YRdWxnlH9vQGjAklmjgw0FSfEW/GSJXgZncWrbuQoA6i2s=@vger.kernel.org X-Gm-Message-State: AOJu0YyFoeMwtdNtKSyxDOs+JOC0h2pkc17dHLoncuGUC7rSwf8Mu5lx Zh9O7y0O+8Qf2FhH/FBqcoBeCa9MCYGMh1M+6I54+kQH3+vUPHz6NGIH X-Gm-Gg: AeBDiesJraNH+Cflc9NhELrs3a+Wi5Iw3B/gN479iIPwyrOel0oAsxQEMV4H9DoZTsy 0NedYKMqegljD8Jk8zQcsWT8kI1UaccHmp79HcfJNsIDPLsuonaqqFnYLTOuj4uvY8L8yXSYWcq ZBuoX2EdZJqmyXT3Jy+YVRx+yLl0MV/Ie+q6VqEf80RBJ+ba64St0RiE2pjpQOiZgdgsSNNK6XR GZrTp9HXkpyWM9DDWxFisj6rsHNVa8ZkoYW3E9v0DUY7uIYsIgTSHIuFgDq3/A54fEQO7US++Qz kD6dattB7CSll7DCwTSM+5oxZKsXGNqDDBpKTgVSPftb23IIZKnaLZdvIKJhQ35KKAom2byUsdn vPs52F1IbKFMYu7+rFc80KNqgqTjEMdJOmqIB0IfSu6tZRzPM3xbOuF/8+3fDhSlKT7N7uC7Jk0 SfEXnCas6EoDWfK8fii8Hnv/iWZ8gYd1oa X-Received: by 2002:a17:907:a646:b0:b9b:e5d:71de with SMTP id a640c23a62f3a-b9d72833620mr561255566b.49.1776011539215; Sun, 12 Apr 2026 09:32:19 -0700 (PDT) Received: from khalil-hp.home ([62.250.67.33]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b9d6e7f1a3bsm236468666b.62.2026.04.12.09.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Apr 2026 09:32:18 -0700 (PDT) From: Khalil X-Google-Original-From: Khalil To: broonie@kernel.org, hdegoede@redhat.com, ilpo.jarvinen@linux.intel.com Cc: rf@opensource.cirrus.com, linux-spi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Khalil , Khalil Subject: [PATCH 3/3] spi: pxa2xx: Handle clock gating for GPIO chip select devices Date: Sun, 12 Apr 2026 18:31:51 +0200 Message-ID: <20260412163151.506282-4-khalil@rentman.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260412163151.506282-1-khalil@rentman.nl> References: <20260215135524.1171065-2-khalil@rentman.nl> <20260412163151.506282-1-khalil@rentman.nl> 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" On Intel LPSS SPI controllers (Cannon Lake and later) with dynamic clock gating (cs_clk_stays_gated=3Dtrue), the SPI clock is gated when no native chip select is asserted. When using a GPIO chip select (via SPI_CONTROLLER_GPIO_SS), the SPI framework toggles the GPIO and also calls the controller's set_cs callback. Handle this in the pxa2xx cs_assert/cs_deassert functions: when the device uses a GPIO chip select on an LPSS controller, assert native CS in the control register to enable the clock, and force the clock gate on. On deassert, restore both. This is needed on platforms where serial-multi-instantiate installs a GPIO chip select from the peripheral's ACPI GpioIo resource to work around an incomplete cs-gpios property on the SPI controller. Signed-off-by: Khalil --- drivers/spi/spi-pxa2xx.c | 45 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c index 6291d7c2e..fe5762063 100644 --- a/drivers/spi/spi-pxa2xx.c +++ b/drivers/spi/spi-pxa2xx.c @@ -419,20 +419,43 @@ static void cs_assert(struct spi_device *spi) { struct driver_data *drv_data =3D spi_controller_get_devdata(spi->controller); + const struct lpss_config *config; =20 if (drv_data->ssp_type =3D=3D CE4100_SSP) { pxa2xx_spi_write(drv_data, SSSR, spi_get_chipselect(spi, 0)); return; } =20 - if (is_lpss_ssp(drv_data)) - lpss_ssp_cs_control(spi, true); + if (is_lpss_ssp(drv_data)) { + config =3D lpss_get_config(drv_data); + + if (spi_is_csgpiod(spi)) { + /* + * GPIO handles the actual chip select to the device. + * On LPSS controllers with dynamic clock gating, the + * SPI clock won't run unless the native CS state says + * "asserted" in the CS control register. Assert native + * CS in the register to enable the clock, and force + * the clock gate on. + */ + lpss_ssp_cs_control(spi, true); + if (config->cs_clk_stays_gated) { + __lpss_ssp_update_priv(drv_data, + LPSS_PRIV_CLOCK_GATE, + LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK, + LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_ON); + } + } else { + lpss_ssp_cs_control(spi, true); + } + } } =20 static void cs_deassert(struct spi_device *spi) { struct driver_data *drv_data =3D spi_controller_get_devdata(spi->controller); + const struct lpss_config *config; unsigned long timeout; =20 if (drv_data->ssp_type =3D=3D CE4100_SSP) @@ -444,8 +467,22 @@ static void cs_deassert(struct spi_device *spi) !time_after(jiffies, timeout)) cpu_relax(); =20 - if (is_lpss_ssp(drv_data)) - lpss_ssp_cs_control(spi, false); + if (is_lpss_ssp(drv_data)) { + config =3D lpss_get_config(drv_data); + + if (spi_is_csgpiod(spi)) { + /* Deassert native CS and restore clock gating */ + lpss_ssp_cs_control(spi, false); + if (config->cs_clk_stays_gated) { + __lpss_ssp_update_priv(drv_data, + LPSS_PRIV_CLOCK_GATE, + LPSS_PRIV_CLOCK_GATE_CLK_CTL_MASK, + LPSS_PRIV_CLOCK_GATE_CLK_CTL_FORCE_OFF); + } + } else { + lpss_ssp_cs_control(spi, false); + } + } } =20 static void pxa2xx_spi_set_cs(struct spi_device *spi, bool level) --=20 2.43.0