From nobody Sat Sep 26 11:47:53 2026 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 5A92F4A2052 for ; Tue, 1 Sep 2026 19:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788290797; cv=none; b=hhUOIYY5y7UZ0xkDQ78zvR7j52qtm3KFpemhhY42WzdjiELY/UHl966rDnoETQinWwtz1Rz5uedKm7AO7EsKepyv4LNRR0bvn98C/wNzqsfDkhedoqi2PHWxFaNFZIe5BWwBizEGaINrqeq2zrkFFH6jV8/BPPEubDFCUZzh4Wg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788290797; c=relaxed/simple; bh=Phr/lyT83N6DYL7BdtQd1/VdiLOr4iWUkwC8JFgGLyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NHMTr6lAOba3flG3dGYXjHl9p5wRurQxi2u1RnbGVTof2JQ3ZErdYirrfePJ7Jr5+AkJVHMqtDO7aCTvFLg5DzrxjS6iOCS2Dyfi3nafNUMZfWTi/u9psUsmC3cFjqFsXpKQuZ4vEd9aYmq6jUVYzbPCWepXZiAdHIDlm3xiJjg= 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=nb0qJvel; arc=none smtp.client-ip=209.85.208.48 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="nb0qJvel" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-6a61910369bso288627a12.0 for ; Tue, 01 Sep 2026 12:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788290793; x=1788895593; 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=+jZowfmyKxOguFaJuZq/Bm4rZ+Os6TFRN1DcxWsiy2Q=; b=nb0qJvelweh72Eh8xFecIIJGexpOlBTjJnA+Vd56Q5a+sPXa+vgsPG+IWtqei3h9S8 mI2vZAcPE7GDz07cpSYuIK0BkuNduXvajSkpiEvZRJpepGwsDkM5PwQyzGjwrtjKFSSA 8h+Hz6JX1sZOlk3hHQO4oFgKu/I7+E+IuCzWhEDGHA5ILfhmtNEBGH0jQIClV/IoYj1p Ocy6MwJFaIRrm4CRpFt7eVZyGhNGvAomWh0jiatmVP9vlBjoJLyj4cBtfb0gW8CjtB2a CgorVoJsVasH/F/3oCZjmRkbIEAHr1iBICVhTGW3ibHXs6PoUiLytY1SE5srW+rKvtic HWFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788290793; x=1788895593; 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=+jZowfmyKxOguFaJuZq/Bm4rZ+Os6TFRN1DcxWsiy2Q=; b=JsOtEvH2vkkquFzRMByENj1KnylyMSUGfal/VJJ9aWvpK69twmjeRK9Ng8CHBjyl+N ozwihV+KAef+u/ahEkI0oF/slozRxrhFKBfe77/ZMXYPz1Wb+I0JRr2KsnHaSjrU2nZk pIgRah0wq3n/wPc1P7kkWvGlx+ZtEE9dHSotV49BBlqWVLVbf0bEsjzIFRMfkAX1atIG onx47rAXtJOrRlsd2ghpnd0v4r2C2g7Fvxll8PO1tDT/OQxoTUEFpl9q9VLO6A+XzUCL rX34mdHG0NH1IWsZWP/kq+HakcfEQxuQpuwTBtc6wehzeNTsIr2JgPePxhHrDfy3VsvQ E1zA== X-Forwarded-Encrypted: i=1; AKwUvBxBAMJbV0+jiGZlRhP+F84u/Zy9oTKttVxHHNuKR/s4tVRrashFTrZzxJOOZY3Zyk4loXeolGI0UJwqlHo=@vger.kernel.org X-Gm-Message-State: AFuF++nCa5M66Y0ZpvJ19SP1WfmqIlC0+DrBYbGCLLezW6QuU1bdVSEI lmvvD5nOAQjicJkW8SGC0Ydl/ou3euOd3+pgi7Zscxedf3AmXwWKMHWs X-Gm-Gg: AYBFou3xHpl2ciQ3E3NIbEeU2VWl7SyWZuiaMHGIawFwh0o9yqiBiRylIQQlfJWjOtC sLev5YTLalZEoCgZYmc3v/mRJNaxWhU7ZZHidmD/QQj+TM74SHIuzsapwbCv27LG63+vyWwsV9p j59rTQfGrEZoDAqeAjLa3R2GELxzk0WOZXy/cZ4q0/5XOI32GyhpczcU8q5mrOEuIO6rV74PM3u lUzoZ8ByfUDuoG75opB2BGhOxUQXiFVK9RrT206FOEJuP6UeDBezF91owxcLEiM/E+VS94QzeSA 9ngA9dioRqQU+XYpWkSZKRYSBDkqzkQF7ifyz5h3u4W760WlKke1kGdajaYoLcVlU5drQuJfT11 ZyyXVIQOZ93X97TldS1XQUenXuK+TzRCVBipZTb6PeQHH+0nxa0OwEqjCDdo8bg++cIzBk+Wjtg XW8VWvLzmLrSvS8SmBkOG7vp/EfXI4jqK78FNzTWSruILd1UfV8DwaA0D6f0e4Ww== X-Received: by 2002:a05:6402:5305:b0:6a6:757d:6311 with SMTP id 4fb4d7f45d1cf-6a68257c1eemr63061a12.9.1788290793582; Tue, 01 Sep 2026 12:26:33 -0700 (PDT) Received: from khalil-hp.home ([62.250.116.161]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a67f94242csm146373a12.21.2026.09.01.12.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 12:26:33 -0700 (PDT) From: Khalil X-Google-Original-From: Khalil To: Mark Brown , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Richard Fitzgerald , patches@opensource.cirrus.com, Daniel Mack , Haojian Zhuang , Robert Jarzmik , linux-spi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Khalil , Khalil Subject: [PATCH v3 1/3] spi: Preserve preset cs_gpiod in __spi_add_device() Date: Tue, 1 Sep 2026 21:26:23 +0200 Message-ID: <20260901192625.1497791-2-khalil@rentman.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260901192625.1497791-1-khalil@rentman.nl> References: <20260901192625.1497791-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 07c572e1df..fbfb9a1aa2 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -924,7 +924,8 @@ static int __spi_add_device(struct spi_device *spi, str= uct spi_device *parent) if (ctlr->cs_gpiods) { 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 Sep 26 11:47:53 2026 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (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 63DBF4A2065 for ; Tue, 1 Sep 2026 19:26:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788290799; cv=none; b=SESuxbwfpUkx+/riwz+eoQhsSQinDWeBBJ1pyDcv6iFr/tljpGTFvWLy0y7wVOhn47QUSA6FqBB097lqM/a0s1c7YyK/kN83Pj4hTGecZd0jgsF1BREbZxuK7B7khhQuu4TjRSSN3cM9OhzYYLXRIHWpCJTtYOJGJ4CFctcxXFY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788290799; c=relaxed/simple; bh=fh/K8Z39v0fYp7arKDkR6BVh5e0+aBA52IxPFmCCt1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JO7e8DjnJKMoz5TVW8fakHZQyr5EqYLRy/oxOHNsYDhIR1RM/LvER8YH1jfqekdiMDzk3faEWR7YlTgqGufKgo9P3O71ywp4xgN+Yi/ZW7kw2iLpy6svnh5D5oBwwhoUOtKv9Lh1DRZnTvuTU00vPOROh7Tt7/K+xaFwtFO6N0c= 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=jn0QxvRC; arc=none smtp.client-ip=209.85.208.43 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="jn0QxvRC" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-6a60f0dbeccso353772a12.0 for ; Tue, 01 Sep 2026 12:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788290795; x=1788895595; 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=Au4Zowwhgt90eKNQsRrHmDjhWALjzLV/Ep727GpNnYw=; b=jn0QxvRCJ4I5CE/HiwVwdQ9Pe0FCR8EOM93uvd63ho9LzBnv/UnK8O7Z7sTxwQeW/m iugEUs+Yllg7iD02sb1NVpps9SyVmnkRJpOWA2YIp8kz8+pvqCmT3nK8OU4piWvav/WV ZHALcI1r3tGtpeZuVktiXAOJYf/APZJQVADRxyI7aG0szjE7XVyrJ6AfbS5NPw464ZKC q2ItsKLp5Bqwa93w63JAKr50R5tSHyuP0+/BNb4lY1ZRb65BzH1XS0eTdnmE67RexFQh NCf5HKoTONly0A8WIIv07ZJZ1yR3a+p6PxMJDEwVWlywWOPQrwEhMysgx7sDRRWHuudR caig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788290795; x=1788895595; 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=Au4Zowwhgt90eKNQsRrHmDjhWALjzLV/Ep727GpNnYw=; b=Q2L9ILW4QnKdhshMvRcQseXl/Eoomr0950YzL4sCWoEag5NZNWaSM0n9clg0xAoUbW wA8yZ16FBdAfAR2pIlqRYuIP5gmw8LbBWYTOQBMtlFlSMqvaUjgAfRtuYedopw/vKnsC yxgCnTv3fXCH+WAK+b1w+nrv0dM+UmeezHRlX2fnH7kiz8eorMTkDHMhNxKM5tsPXgbN nFvLP/yRlqfYBWSU6vuWKrRAvTrDwqSv64U0szMxfl4WSeRnbWiLIUASYHWxrB5qmT0Q iTUt3iaqjYCMzM/Qt9qtegkEV8BAw9mQIfLIwhOXrKKIi7inFLGza7mAEBAuBnG9xYmY krRQ== X-Forwarded-Encrypted: i=1; AKwUvBw8KFK1meAf0HkqzBKZElJk8nIKahwzs0nasns7NpZwh1vcnGdjUok7+qfhdwEf8YMqDcOO4BIkodSHr5Q=@vger.kernel.org X-Gm-Message-State: AFuF++nO4pXAvzL3AGAeu+8C2pPL9I0JMbNakQ531ynRBbgNEH4FatlS d2u77mOnhupjqpQ7vdudK5V5bJpGoK5d0Ph21zEe5Sk7jAdjv4FgQ7iW X-Gm-Gg: AYBFou2WL5ulMG292ZGa+TS5dT4tIiSqxB77zKB6mMl/CdxiettJx7MYg3ASGWFO8u3 me6UM9xpr6NIJzmgWsSeeicoh+DKxwQFweWwfxVtj0G+d4CSU4iyCLEYyQ43ZR07SYqJwtzn6zI 61k89P12Snuyedl/zXfbNd37EYmdfeaMfi6ftOeIKN2A8l5ernIlX+Zwd1C+u9tE7B6j1xK24Rk CTpJYLTCOvtJmLfmse98mriNxr9Fs4uuoQcoMnrOmVRw3vyDZEqSBbsQe/xMbxlF8oYWP7iiz4c NTE0MRe+EpIzzpQQGsA4TlSWK0RFNIux+RA4LYmN+tesNaqP+SDfkOsIEoM3fWuN0KjgToCnPrf MHzNNTh/1r1ObncEJka2Vrz/STCoedTMhg52PlvCL6hmnr3cYIcGM0vfRqsbqgGExg1kA8YSZux 2ftGwGAIRMvuRIGQehJ4fqKvrg5xoQ65fe01+V2D5fNftTgXaRUdVyYbQeenA9PqDGfx4Vvv3u X-Received: by 2002:a05:6402:210c:b0:6a5:f528:ff48 with SMTP id 4fb4d7f45d1cf-6a6825668eemr51905a12.5.1788290794393; Tue, 01 Sep 2026 12:26:34 -0700 (PDT) Received: from khalil-hp.home ([62.250.116.161]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a67f94242csm146373a12.21.2026.09.01.12.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 12:26:34 -0700 (PDT) From: Khalil X-Google-Original-From: Khalil To: Mark Brown , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Richard Fitzgerald , patches@opensource.cirrus.com, Daniel Mack , Haojian Zhuang , Robert Jarzmik , linux-spi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Khalil , Khalil Subject: [PATCH v3 2/3] platform/x86: serial-multi-instantiate: Fix SPI chip select on platforms with incomplete ACPI cs-gpios Date: Tue, 1 Sep 2026 21:26:24 +0200 Message-ID: <20260901192625.1497791-3-khalil@rentman.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260901192625.1497791-1-khalil@rentman.nl> References: <20260901192625.1497791-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 Tested-by: Juan Jimenez Carrero --- .../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 1a369334f9..0d30bd0a7b 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 Sep 26 11:47:53 2026 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.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 1B6554A205A for ; Tue, 1 Sep 2026 19:26:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788290799; cv=none; b=fDjKPpx+WoE1T4Okr7HcVjNoYJh4Nl6eYZ5bOVbF9yQVg0rlr6a8vcFdiQ9jtR0lR+SpUQqfZ+b11gHR3UTWmxXioVOg5aoXdf58dC2p+VUtyzWnISC+5ZJ+Dw5DitOB4iv2+jYsUt367kCJRjkwOfD+hlhEVnHvhtQtlnBByrM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788290799; c=relaxed/simple; bh=snDeyJ9tPxWhXrW2kNPrxD8sW8wylLhnjY3gj3zW9/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OU/dEehusv3UdgF9Y/GLYgfD7vM0NHHBgMuQbcGhSH4FJV6ER0feu/VdmT6AnpKAcaYvaDdOXhxVd5V35pWGtZkl0eNTwz2ysHz/GdPo1+OFtp/dRxqAuV0JgQn4un4YnTB4VR+IeIekHQ8vW3H7ytRC5CpFFJH4rhwMW7T6L8Y= 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=pOBhf3LD; arc=none smtp.client-ip=209.85.208.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="pOBhf3LD" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-6a601ba6870so415917a12.0 for ; Tue, 01 Sep 2026 12:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788290795; x=1788895595; 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=WyEFu62ujimxaQJil6RmK3n8Y5dLLUWHpcfLAU5G5Cc=; b=pOBhf3LDGUK++AHuCjYgvGgI6scbtVqa08hYw8S/tnmHzUckDKnv8/YC0S+eMhbVep 5gHxwjbBBEKL5je+hlQkOrIDj/RwTwJ7ZyLaZc6xzNm+hWdG7yzy5CcJUFHRZxErM4VQ OGyFG6KYKhO388+Ty5m/ALcmX3mBUHi+X1Emh3fsbepXauZs6DM5w1PUdAzOtABY3pil Yu0yaaFl7+wIMU1OboqEjdRuzIV5hTcygnqb8JC1cDN2J3nyb6rgxnZYwBY9h6nDJu4/ qxle8JvlFG3Xiw980a3Nz9er12adolC1TOHZ1T0PvBLu6oc4OqEEnwG51jTU8ExvO9/i ChFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788290795; x=1788895595; 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=WyEFu62ujimxaQJil6RmK3n8Y5dLLUWHpcfLAU5G5Cc=; b=eMfbHwabPxCHGHr6TrvfF7mtFjjXcTLznDFUTMyZkjJEn48EKyb6VvHkL3hjbd3eqx 2xgUViKrhmCPkt3f/+0nsmgTiLvH7Y0YWL4AIWB2r3YJQHi+oxtGQgrS+agjZoOKIg1I Or296dQr1EZrE1Yh+4Ciicp3HguNPNnkGDFCfaj3YM0tMPdtNj+P1SlH8ho4q19oueks WPDlTZUyHpcTyFP/9WyTk35SZ8F54yBivZqx9+o6Y1vlWtqtpWKQ6Bxc+tWJiey06gey U6RvGk95GAbXtZaFEUhmsg3wTrb5Pn0XWISGoLMILKPJl9qzdTNfsIr4fsYTbCw2LCDr TGzQ== X-Forwarded-Encrypted: i=1; AKwUvByW8OzrpaUbtKaRYN1UT807ERcaxkNnyYq13cm5G3vLDaA6f6tBH6zlXpShookMl5UKVV6JWzNx3f8IexQ=@vger.kernel.org X-Gm-Message-State: AFuF++mSlj5V2nOy6zZrWzo0R3S/8T6P/GscJDyQPdqnCvHbK6wY41jB etq6hyxyUjdTsNeaMtxYQvQnsGiNSwYoQ3JDbQ5WasdWtlAt9EL34D2R X-Gm-Gg: AYBFou2ZshfR8XJroXx1HrgQ7xJGRYpv7y2jt6cmwsKlkd1TE+GFx7zVVVrB164PK58 zZdII/ma+uX5ckJ0R8857Ef5UIpWiKjBzRg+c1TlAITvsWUhdbOcmL1v1+/sGR8qVGZzZXOA3KT VfITP9wNFdggMnMVBQ+YGpjOI6O1QSXNjsZQCQLVMvU798bq8nz/NeDeFIboyDwQfthOzhi7O8K cO7a35sBrNKDRjBPZgM5DS4BDbAJruxW/IeddM4SXtUEW9G8r7xJfieFsmFniogkLrkh+hVquOs Y7pXzDxtqbFPWfJ99DW6fNdye60/FfoIQK72hp1fI95L85vll02c0SeOx82I77Xeggk9deyOfsQ 4hDn0sFGWvT/7YGFOXn27gmxPag9kwSkLAWME0GvyTZj0dy3gY7lElRrDLD+qJQMQEiMKlFzpTC w+HDCThQg2jd7W7m+YpzDc1EdiuAOfs4cPG8qhsV+nw1KOLC6c7W7XMRh/YFh7FHZ5nwhaT8Ay X-Received: by 2002:a05:6402:21d4:b0:6a0:dda3:83db with SMTP id 4fb4d7f45d1cf-6a6818d24f1mr115922a12.0.1788290795093; Tue, 01 Sep 2026 12:26:35 -0700 (PDT) Received: from khalil-hp.home ([62.250.116.161]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a67f94242csm146373a12.21.2026.09.01.12.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Sep 2026 12:26:34 -0700 (PDT) From: Khalil X-Google-Original-From: Khalil To: Mark Brown , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Cc: Richard Fitzgerald , patches@opensource.cirrus.com, Daniel Mack , Haojian Zhuang , Robert Jarzmik , linux-spi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Khalil , Khalil Subject: [PATCH v3 3/3] spi: pxa2xx: Handle clock gating for GPIO chip select devices Date: Tue, 1 Sep 2026 21:26:25 +0200 Message-ID: <20260901192625.1497791-4-khalil@rentman.nl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260901192625.1497791-1-khalil@rentman.nl> References: <20260901192625.1497791-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 Tested-by: Juan Jimenez Carrero --- 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 6291d7c2e0..fe57620630 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