From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 6A9552D8379 for ; Mon, 9 Feb 2026 17:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770659251; cv=none; b=lV6844gJwjcbLN8hbTBe6gsO09CJooOoazAs7RD7umf6YBgXT0P2ixgvm/IUzONAfe0gZ7M7RWiyg5SK5Q2MQCdgmEC0YPGUVe6bH4jrxUo308e30YADzfV0/fXMI/Z/BpaZuhT3p158TWlCqYZ/X2yiBxMuO64C5Wlq00ALz74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770659251; c=relaxed/simple; bh=08CBwNSSgBiOal2WtMi393bKTsGkbdSqACFq9WdNEL8=; h=Message-ID:Subject:From:To:Date:In-Reply-To:References: Content-Type:MIME-Version; b=m0I13bSIZ/ba6j+/iQ/KFeB+zIhuSzXl7Fhg3UrYUCsC9id8JWD5bzAo3h4iD9TlBKAw3EZg9z7V+ca3bgLeYpfi7QmBC8kYSm9fFTB6pRY6BPZklqgcKdE/R1gOX7vrFoMIOaSc7HEHGCp6QkkyAeYva32/cHYvDF0RHQOPynY= 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=VCodYy1Y; arc=none smtp.client-ip=209.85.128.52 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="VCodYy1Y" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-48329eb96a7so13874505e9.3 for ; Mon, 09 Feb 2026 09:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770659250; x=1771264050; 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=NFqSPbMQY4EjZSJSplWP+ILGSKihZ3lOjOFtMZsQEWI=; b=VCodYy1YWvSgoZ2RI6BnGJ7e9OcTeuDHG2FTCOA8RsDZR8eY9NPLLhF9IBjox7/Cxk ohQSjK4M9WkyljW0ZgAVdn06/88mq0HBns58cnOuFxUGQsr06xamYN0JD8ONYL9MOHqg g948dAQUxf2orpoJuIgWSXo/mmIIH+pHCz6IPQuvjlF/loySnLvW0NDhFEQET36lnE9p /SMQta1dwdIh2zNk3aMgMmlIm4LZ14pdL9/hSoSK32mYILwgYgA9Xpk7pNUp2qcwfuVM LweT19iPhYDWqI7/qtx3vIVQtfn3LdejUbIiyco84YIp98qWczddKb0wS95pPXYKwhz8 ThDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770659250; x=1771264050; 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=NFqSPbMQY4EjZSJSplWP+ILGSKihZ3lOjOFtMZsQEWI=; b=aOSRN44VTPPUXxbWGzQNqAahGKcyKCHU6lVVMaSdp7/WwApzOOvt+kwcSQUwtiWNET M+EtxOtXGkVWBhovgcGeJR/H681rPqKaVBzMEjya6BBCTqj4X3rPvuPsCkVkxtgCRKez lqTaLFl18n1OFB6YwSsd7wlqqbS3QetGG9PYXtjtrYBdyeTbPzf4TGPMJ/NqLv58n66P 7y6hcvImnmZKf4PDs5UQ1aFmJ3mnSjvWgT9cLgg5VHULmUZ/0VOR5Qbt0nYb+K7qlqqu GXa/YQnslI/N75GGJRK5n/sGQSM2S7slOErs3RZxYp0VfI4M7faAHmNeZw2RzU/5Kyw8 c6pQ== X-Forwarded-Encrypted: i=1; AJvYcCXynWQDg/p02pHioK9G9mlG4BTHOqBDEyirLY0lUPv3b0irI0R7R+rhrRObtG0GOlSZi9ONBR22y8MGwLE=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/A/j89NLZPbJzJhos4hEhA0/GtmtLCbY/f686vmVatSAuNXAw 3C+cxg9GqLKfy37IJX+IYW8oHfvRNltPhR5xecLr44x6VMp9nVaXc0Y6 X-Gm-Gg: AZuq6aKs66o/Mv6BR05/fnX41SlYnLwCPUKzdRkXPkCvMkkqVD+dKR0QpxXkAlj46ac sW7K5Nc5mP0Z/I3kFCmcMktHgv/Aca5e81UsGSI5p91O4y+Uqstg/8tTjnaaiUCfvXXlsUu2JpE fNgtvMgZxWKJmAvtSNjeZ29R870gFefREDkM1X0c+7iBB4ETrgaA4FIGHmKrCD2lEgVtUqdrxP3 1u9qY2RbV+/9cboEcrRVDchvq1l41ljRdmaw2Zh8vvCclho4LXOgcE+mv+oCSk6KhsQNsrNy4qv gOyWfYd+1t0qWK4JULILw8rxLeGGNhPDQBzRZx/7MF8LkM1J3EkdGC5oVcvfGpD2WsJnvCEpCPB S6MWt+eU1InucONEO1fBR7DCIMtioVjE/ghibq/8e3UGb0Ze6ivzlDhqk8w0DbPqQxtcxzWf3of iUCflONy10JkDSddF8oCk= X-Received: by 2002:a05:600c:3b99:b0:480:5951:fc1e with SMTP id 5b1f17b1804b1-48320933765mr165570205e9.11.1770659249660; Mon, 09 Feb 2026 09:47:29 -0800 (PST) Received: from [192.168.1.187] ([148.63.225.166]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48320978108sm141792595e9.7.2026.02.09.09.47.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Feb 2026 09:47:29 -0800 (PST) Message-ID: Subject: Re: [PATCH v2 2/4] iio: backend: add devm_iio_backend_get_by_index() From: Nuno =?ISO-8859-1?Q?S=E1?= To: David Lechner , Antoniu Miclaus , Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , 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: Mon, 09 Feb 2026 17:48:12 +0000 In-Reply-To: References: <550323d752213f177b7673bdd42e667f1d2228cb.1770393792.git.antoniu.miclaus@analog.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2026-02-09 at 16:47 +0000, Nuno S=C3=A1 wrote: > On Mon, 2026-02-09 at 09:28 -0600, David Lechner wrote: > > On 2/8/26 3:24 AM, Nuno S=C3=A1 wrote: > > > On Fri, 2026-02-06 at 18:07 +0200, Antoniu Miclaus wrote: > > > > Add a new function to get an IIO backend by its index in the > > > > io-backends device tree property. This is useful for multi-channel > > > > devices that have multiple backends, where looking up by index is > > > > more straightforward than using named backends. > > > >=20 > > > > The new function directly uses the index to find the backend refere= nce > > > > in the io-backends property, avoiding the need for io-backend-names= . > > > >=20 > > > > Signed-off-by: Antoniu Miclaus > > > > --- > > > > =C2=A0drivers/iio/industrialio-backend.c | 51 +++++++++++++++++++++= +++++++++ > > > > =C2=A0include/linux/iio/backend.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 |=C2=A0 2 ++ > > > > =C2=A02 files changed, 53 insertions(+) > > > >=20 > > > > diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/indus= trialio- > > > > backend.c > > > > index 447b694d6d5f..3b692d48481e 100644 > > > > --- a/drivers/iio/industrialio-backend.c > > > > +++ b/drivers/iio/industrialio-backend.c > > > > @@ -1008,6 +1008,57 @@ struct iio_backend *devm_iio_backend_get(str= uct device *dev, > > > > const char *name) > > > > =C2=A0} > > > > =C2=A0EXPORT_SYMBOL_NS_GPL(devm_iio_backend_get, "IIO_BACKEND"); > > > > =C2=A0 > > > > +static struct iio_backend * > > > > +__devm_iio_backend_fwnode_get_by_index(struct device *dev, > > > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct fwnode_handle *fwn= ode, > > > > + =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 unsigned int index) > > > > +{ > > > > + struct fwnode_handle *fwnode_back; > > > > + struct iio_backend *back; > > > > + int ret; > > > > + > > > > + fwnode_back =3D fwnode_find_reference(fwnode, "", index); > > > > + if (IS_ERR(fwnode_back)) > > > > + return dev_err_cast_probe(dev, fwnode_back, > > > > + =C2=A0 "Cannot get Firmware reference\n"); > > > > + > > > > + guard(mutex)(&iio_back_lock); > > > > + list_for_each_entry(back, &iio_back_list, entry) { > > > > + if (!device_match_fwnode(back->dev, fwnode_back)) > > > > + continue; > > > > + > > > > + fwnode_handle_put(fwnode_back); > > > > + ret =3D __devm_iio_backend_get(dev, back); > > > > + if (ret) > > > > + return ERR_PTR(ret); > > > > + > > > > + back->idx =3D index; > > > > + > > > > + return back; > > > > + } > > > > + > > > > + fwnode_handle_put(fwnode_back); > > > > + return ERR_PTR(-EPROBE_DEFER); > > > > +} > > >=20 > > > I believe we don't necessarily need this. Why can't we use io-backend= -names? I get > > > that in here we just want something matching the number of channels w= e have so giving > > > names is probably does not add much added value. But still, I would p= refer t have > > > more simplicity in the API and it should be fairly easy for the front= end to use the > > > names argument. > > >=20 > > > _ Nuno S=C3=A1 > > >=20 > >=20 > > IMHO, using names in this case would just be annoying because we would = have to > > sprintf the string to add the index to the string. And also have to spe= nd time > > coming up with more complex DT bindings. Using the index seems much sim= pler. > >=20 > > If you really feel strongly about it though, maybe we could make a > > devm_iio_backend_fwnode_get_fmt() function instead that handles the > > sprintf() part so that we only have to write that once? > >=20 >=20 > uHu? Maybe I'm completely missing your point but what I had in mind was j= ust something like:=C2=A0 >=20 >=20 > // from the frontend: >=20 > static const char * const names[] =3D { "adc1", "adc2" } >=20 > for (c =3D 0; c < ARRAY_SIZE(names); c++) { > back =3D devm_iio_backend_get(dev, names[c]); > } >=20 > So yes, I agree we would have a bit more complex bindings and more comple= xity in the > frontend. But on the bright side, no need to change backend code at all. = And the > -names property is already used like the above fairly often If I'm not mi= staken. >=20 > But again, I can agree that for this usecase getting things by index make= s sense. Given > that we just want n backends for n channels, the name does not add much. >=20 Given Krzysztof's feedback, let's not do the above. So, Antoniu, disregard = my comments about using io-backend-name. - Nuno S=C3=A1