From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70F7253D9C9; Thu, 15 Oct 2026 16:49:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792082995; cv=none; b=tq+0A29pIMaUAFAG7t5fv2JC18EydBxFQi4WW01ShS2bnFM88cKKOhdXiMVO2Xp6Ii8dQGRnt48gF2q+0q2iEXxkkttZfEoXgJU8igL3+4nA8lhfpjNylbTOdCJ0Ins7v4S1P6G+uBaQl2xtfE6BluH8KPq6NjPzRt98InH52BU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792082995; c=relaxed/simple; bh=qBeZXHM7R+eFGoiA8eSiWzdg88ngr2gc5eMV+f4Prrc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FgHW/g9d1QqEapIPCE+I9AeFGjhmCawVpDD46VTBGilw8idKM6jwcrqk/5wrR1nwMYUO4VDenNcAKtn3sP91CA62e6bnBCc6Bk+FuXX4RV+ZfcrwyJXuUucRmCBlRtXJm02VEKFHAWPu90eGGw9rT8vGxoEhIagYvgR34WVNVSc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ts3e0Cv9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ts3e0Cv9" Received: by smtp.kernel.org (Postfix) with ESMTPS id DE98FC2BCFC; Thu, 15 Oct 2026 16:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1792082995; bh=qBeZXHM7R+eFGoiA8eSiWzdg88ngr2gc5eMV+f4Prrc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ts3e0Cv9bjj9FVn0A/BXYpMQh6WXkUJn/HwdNAW+dbNENdSaY2Qcywr3NqmZ5EZRh n6eO3AU9JlnUtV23NlH1Qj2bihgeBqkjBYAvmeDVEa+zh0cWo4kUA53EIknGFulogJ xVuFZX+xo9FS6CSfSSqJYbIRPnB8u9YP24CdOKd1goDpN2EsdjAC/dyGfU1E6+bOAt SrmzK7j8/RECQaQLPzOim5Uh6GtjpT4AqFUl1kE2VWvGWSGgoehsj9sg6QRdeEdblC 7hDM2/DuhYHuSDbj1AgxtmCfWQiNoxiL4TxLAFKaDnA6LuCUerf5ZzUr1IQfILAZZj 0/qR+YN/XFhZA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF7A3CCA464; Thu, 15 Oct 2026 16:49:54 +0000 (UTC) From: Rodrigo Alencar via B4 Relay Date: Thu, 15 Oct 2026 13:49:42 -0300 Subject: [PATCH 02/10] iio: backend: add devm_iio_backend_get_optional() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261015-ad9910-backend-support-v1-2-3c21648c8e26@analog.com> References: <20261015-ad9910-backend-support-v1-0-3c21648c8e26@analog.com> In-Reply-To: <20261015-ad9910-backend-support-v1-0-3c21648c8e26@analog.com> To: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, linux@analog.com, devicetree@vger.kernel.org, linux-pwm@vger.kernel.org, linux-doc@vger.kernel.org, Jonathan Cameron Cc: Olivier Moysan , Jonathan Cameron , David Lechner , Andy Shevchenko , Michael Hennerich , Rob Herring , Krzysztof Kozlowski , Conor Dooley , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Jonathan Corbet , Shuah Khan , Randy Dunlap , Rodrigo Alencar X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1792082993; l=4254; i=rodrigo.alencar@analog.com; s=default; h=from:subject:message-id; bh=jMGRlIFAVCCUz4CCoYv97h4Bqb1DwkRQZ4omjdnHBPA=; b=rep/gWP6o7g0TuJDFbq5uZXAbtNeavCTcABecjt66g/dm2woALLaNAba8Ug2NM/XoRo2H/5tz jT5VQnTMh+rBpuJryTB+8YUz+Mea9VapIxuo8G5I8dpvie+TTZlLlk7 X-Developer-Key: i=rodrigo.alencar@analog.com; a=ed25519; pk=ULeHbgU/OYh/PG/4anHDfLgldFItQHAhOktYRVLMFRo= X-Endpoint-Received: by B4 Relay for rodrigo.alencar@analog.com/default with auth_id=561 X-Original-From: Rodrigo Alencar Reply-To: rodrigo.alencar@analog.com From: Rodrigo Alencar Frontend devices might not need a backend driver to rely on. An IIO device that supports backends can behave differently when they are not available and that should be acceptable. Such parts may provide basic functionality solely using the control interface (SPI for instance), being able to have extended features when a backend is present. Add devm_iio_backend_get_optional(), which returns NULL when the backend is not described in firmware, i.e., when the io-backends property is not present or, for a named lookup, when the name is not listed in the io-backend-names property. Other errors, such as probe deferral, are still returned. To make that possible, a named lookup that does not match any entry of io-backend-names now fails with -ENOENT, the same error returned when the io-backends reference is missing. Also, the missing reference is no longer logged as an error, leaving that to the caller. Signed-off-by: Rodrigo Alencar --- drivers/iio/industrialio-backend.c | 34 +++++++++++++++++++++++++++++++++- include/linux/iio/backend.h | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index fbf5c39d7655..7af41ba50a65 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -1006,9 +1006,14 @@ static struct iio_backend *__devm_iio_backend_fwnode_get_by_index(struct device struct fwnode_handle *fwnode_back __free(fwnode_handle) = fwnode_find_reference(fwnode, "io-backends", index); - if (IS_ERR(fwnode_back)) + if (IS_ERR(fwnode_back)) { + /* not described in firmware, let the caller decide what to do */ + if (PTR_ERR(fwnode_back) == -ENOENT) + return ERR_CAST(fwnode_back); + return dev_err_cast_probe(dev, fwnode_back, "Cannot get Firmware reference\n"); + } guard(mutex)(&iio_back_lock); list_for_each_entry(back, &iio_back_list, entry) { @@ -1035,6 +1040,8 @@ static struct iio_backend *__devm_iio_backend_fwnode_get(struct device *dev, con if (name) { ret = device_property_match_string(dev, "io-backend-names", name); + if (ret == -EINVAL || ret == -ENODATA) + return ERR_PTR(-ENOENT); if (ret < 0) return ERR_PTR(ret); index = ret; @@ -1061,6 +1068,31 @@ struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) } EXPORT_SYMBOL_NS_GPL(devm_iio_backend_get, "IIO_BACKEND"); +/** + * devm_iio_backend_get_optional - Optional device managed backend device get + * @dev: Consumer device for the backend + * @name: Backend name + * + * Gets the backend associated with @dev. A backend not described in firmware, + * i.e., the io-backends property is not present or @name is not listed in + * the io-backend-names property, is not treated as an error. + * + * RETURNS: + * A backend pointer, NULL if the backend is not described in firmware, + * negative error pointer otherwise. + */ +struct iio_backend *devm_iio_backend_get_optional(struct device *dev, + const char *name) +{ + struct iio_backend *back = devm_iio_backend_get(dev, name); + + if (IS_ERR(back) && PTR_ERR(back) == -ENOENT) + return NULL; + + return back; +} +EXPORT_SYMBOL_NS_GPL(devm_iio_backend_get_optional, "IIO_BACKEND"); + /** * devm_iio_backend_get_by_index - Device managed backend device get by index * @dev: Consumer device for the backend diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h index 9c16b695a602..93d5f2073cc3 100644 --- a/include/linux/iio/backend.h +++ b/include/linux/iio/backend.h @@ -267,6 +267,8 @@ int iio_backend_extend_chan_spec(struct iio_backend *back, bool iio_backend_has_caps(struct iio_backend *back, u32 caps); void *iio_backend_get_priv(const struct iio_backend *conv); struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name); +struct iio_backend *devm_iio_backend_get_optional(struct device *dev, + const char *name); struct iio_backend *devm_iio_backend_get_by_index(struct device *dev, unsigned int index); struct iio_backend *devm_iio_backend_fwnode_get(struct device *dev, const char *name, -- 2.43.0