From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 0EA1335FF53 for ; Fri, 13 Feb 2026 16:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771000750; cv=none; b=L9lpPZvWPZtIppPP7RMhngdrgf8bewwdnR7ti+hxKGlmh7ZaHzrVLsXJfIka0SoyjnnydV8HTtURuj9jdcAWQxpj/LgJ4ZZcAjf1d3MHlzfM4/7PwKfuCblHpIlWpNyc8V8Tci2PKBqsOQJjQbFlC2fUdHd4fjp/PfFH4z/h0pk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771000750; c=relaxed/simple; bh=GnGObxv/l86GyeIwa8n8wqwf7Ir95LEVqVdBanRdmpU=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References: Content-Type:MIME-Version; b=uGi3dGKcw0k3/AvciPw5UvFke5072VVUdqECGS4FYtL/v7cQ86T2U4oCJWnR+vUOKl7gqRwvDBy3uuvOyoxDdqTvpJC0n+0xUOVTUom4RnMMAUp120BfWz+BIpvCdp2BsTQOTxhHr6DmlssjXZYz6BDCWWImxVCIfcDrI0/TkPA= 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=HlvR1fYk; arc=none smtp.client-ip=209.85.128.45 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="HlvR1fYk" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-48374014a77so7299255e9.3 for ; Fri, 13 Feb 2026 08:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771000747; x=1771605547; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=yr07ejpNPZdSsJFPw9OG8vsIRIDGnBouhIbIyj4Wji0=; b=HlvR1fYk32jZoqreqJrFmdMbAKiYPruXD69RUDOqZwDh+KBoZ3AgzYSDac1x6OWbAW si8Y8qGI83Oew2cAI56xRwjhclVaflc+8dTdsibaXwytkwvMifHJX7ZTYeC4wc8k/gLo N89uYqccUAScRVHXr4ymLXpC6DuBIgX5mFWwwzbg8RT7aPg4kb02HVy7mlIY3yU3G15P teCWWcRkaOGB1IQJfMDQyXrBQ0Efo3GbNhYjrR7NBH7rhkS94/5xAf7XvzaYeBSB47x0 SqY61NgxUnB4tDkRSSCLABzUKip5W0QxPnXYROEKGLALOeYpKuxBY4L8M3StZaBmMbzd 7UDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771000747; x=1771605547; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yr07ejpNPZdSsJFPw9OG8vsIRIDGnBouhIbIyj4Wji0=; b=Wo69ayYhxb7kRwDyfIr1rhmUfoxju5k8Tr5rR+7cN4uhSL1gAu9AscK5l+QsYGH8BM BvZJGAQkcXoonP+1hsUOAuNhIlHLXAqrib6+n1t+v/j38Uyg6/d6iIejUn9hob0AayH6 QGIA7l2ymfh0bf0ckub3q6KYFbtb9mA/rIWkvtNOkhWePOBTulcPpx3wloKLkhMr9tMO sMcxZMYe4VhnmfOF0gcC24kVYA6emaH5jjsthQerqUYnlsisd67eyFtLnITtCOLmhlZ6 LwV7nvjDTQqhAUN8co9JKW2fw4BhudUkRRDjP43E3Fy9ijUId9Cf7nrD6g00xJnJDA9u io/Q== X-Forwarded-Encrypted: i=1; AJvYcCXJI5ZBrzo8pG5e4X4mOyz/OcqhDz/GcKSqI2YtPZtzOhVZULD4DYMkMODecOmkMpAkP65PeQgZ0rNPqAY=@vger.kernel.org X-Gm-Message-State: AOJu0YwCfmSm3xkRUJkFUpRUPldRlgVap2irNh8kTr4fyn2kwwux/GqK y8uvF6ZAynr397HA7rlPIkjJFraYrNRyOBFXO7TvUTQPkZKeIy6ZR0Pf X-Gm-Gg: AZuq6aL9AXh9Fgk8tn0aaZi9uZer/EhEu2w04vucYk7zcPc7QKYtgsx5RXf1cH/x7vB AWNVE3c+Gq9T/JBscu3XKtRo0OENMdIcT5BvmdlBO2WwmuC8s7pYbHBV4o4545n61x+yKuVlD5F aYRRMkN0+NBknt3Y0cT0j9I149yyR1b7o5WtvcuHZWVuevADDHYpMkJW19lyo9HnSKUS9Tn5jPl DkcLexT7PzinwGfFy1V8KtZkn+04kHZClztq9gVHIhh+QpBNxveMXqXEnesHWeci2hb8/VFJ3z3 6ZpzcYzpypldIjsMMgGmOV0K6x+pUxUUOufVFenf2TfMpiH+E6x1JsfPicfK0XHkdG9L8Gx/MGg TVI7ijVs1ep4ZyJvQ02+f2f33/Rw3ULqMMbKkETmEFTQucczCMkONGinRD2OzhXGJO9bVDy+Y7T p1vXpY5/i6pehUTb7YEXYhmK+/JI8qyp5A1p6L3WSj/Q== X-Received: by 2002:a05:600c:64c5:b0:47b:da85:b9ef with SMTP id 5b1f17b1804b1-48373a10316mr44988775e9.16.1771000747154; Fri, 13 Feb 2026 08:39:07 -0800 (PST) Received: from [192.168.1.187] ([148.63.225.166]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4834d835f6bsm247848425e9.14.2026.02.13.08.39.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Feb 2026 08:39:06 -0800 (PST) Message-ID: Subject: Re: [PATCH v3 1/5] spi: allow ancillary devices to share parent's chip selects From: Nuno =?ISO-8859-1?Q?S=E1?= To: Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , David Lechner , Nuno =?ISO-8859-1?Q?S=E1?= , Andy Shevchenko , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Olivier Moysan , Mark Brown , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Date: Fri, 13 Feb 2026 16:39:49 +0000 In-Reply-To: <20260213144742.16394-2-antoniu.miclaus@analog.com> References: <20260213144742.16394-1-antoniu.miclaus@analog.com> <20260213144742.16394-2-antoniu.miclaus@analog.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Fri, 2026-02-13 at 16:47 +0200, Antoniu Miclaus wrote: > When registering an ancillary SPI device, the current code flags a chip > select conflict with the parent device. This happens because the > ancillary device intentionally uses one of the parent's chip selects, > but __spi_add_device() checks against all existing devices including > the parent. >=20 > Allow this by passing the parent device pointer to __spi_add_device() > and skipping the conflict check when the existing device is the parent. >=20 > Signed-off-by: Antoniu Miclaus > Reviewed-by: David Lechner > --- Acked-by: Nuno S=C3=A1 > Changes in v3: > =C2=A0 - Drop redundant NULL check for info->parent in spi_dev_check() >=20 > =C2=A0drivers/spi/spi.c | 29 +++++++++++++++++++++++------ > =C2=A01 file changed, 23 insertions(+), 6 deletions(-) >=20 > diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c > index e25df9990f82..693bdcc5a12a 100644 > --- a/drivers/spi/spi.c > +++ b/drivers/spi/spi.c > @@ -641,12 +641,26 @@ static inline int spi_dev_check_cs(struct device *d= ev, > =C2=A0 return 0; > =C2=A0} > =C2=A0 > +struct spi_dev_check_info { > + struct spi_device *new_spi; > + struct spi_device *parent; /* set for ancillary devices */ > +}; > + > =C2=A0static int spi_dev_check(struct device *dev, void *data) > =C2=A0{ > =C2=A0 struct spi_device *spi =3D to_spi_device(dev); > - struct spi_device *new_spi =3D data; > + struct spi_dev_check_info *info =3D data; > + struct spi_device *new_spi =3D info->new_spi; > =C2=A0 int status, idx; > =C2=A0 > + /* > + * When registering an ancillary device, skip checking against the > + * parent device since the ancillary is intentionally using one of > + * the parent's chip selects. > + */ > + if (spi =3D=3D info->parent) > + return 0; > + > =C2=A0 if (spi->controller =3D=3D new_spi->controller) { > =C2=A0 for (idx =3D 0; idx < spi->num_chipselect; idx++) { > =C2=A0 status =3D spi_dev_check_cs(dev, spi, idx, new_spi, 0); > @@ -663,10 +677,11 @@ static void spi_cleanup(struct spi_device *spi) > =C2=A0 spi->controller->cleanup(spi); > =C2=A0} > =C2=A0 > -static int __spi_add_device(struct spi_device *spi) > +static int __spi_add_device(struct spi_device *spi, struct spi_device *p= arent) > =C2=A0{ > =C2=A0 struct spi_controller *ctlr =3D spi->controller; > =C2=A0 struct device *dev =3D ctlr->dev.parent; > + struct spi_dev_check_info check_info; > =C2=A0 int status, idx; > =C2=A0 u8 cs; > =C2=A0 > @@ -710,7 +725,9 @@ static int __spi_add_device(struct spi_device *spi) > =C2=A0 * chipselect **BEFORE** we call setup(), else we'll trash > =C2=A0 * its configuration. > =C2=A0 */ > - status =3D bus_for_each_dev(&spi_bus_type, NULL, spi, spi_dev_check); > + check_info.new_spi =3D spi; > + check_info.parent =3D parent; > + status =3D bus_for_each_dev(&spi_bus_type, NULL, &check_info, spi_dev_c= heck); > =C2=A0 if (status) > =C2=A0 return status; > =C2=A0 > @@ -772,7 +789,7 @@ int spi_add_device(struct spi_device *spi) > =C2=A0 spi_dev_set_name(spi); > =C2=A0 > =C2=A0 mutex_lock(&ctlr->add_lock); > - status =3D __spi_add_device(spi); > + status =3D __spi_add_device(spi, NULL); > =C2=A0 mutex_unlock(&ctlr->add_lock); > =C2=A0 return status; > =C2=A0} > @@ -2580,8 +2597,8 @@ struct spi_device *spi_new_ancillary_device(struct = spi_device *spi, > =C2=A0 > =C2=A0 WARN_ON(!mutex_is_locked(&ctlr->add_lock)); > =C2=A0 > - /* Register the new device */ > - rc =3D __spi_add_device(ancillary); > + /* Register the new device, passing the parent to skip CS conflict chec= k */ > + rc =3D __spi_add_device(ancillary, spi); > =C2=A0 if (rc) { > =C2=A0 dev_err(&spi->dev, "failed to register ancillary device\n"); > =C2=A0 goto err_out;