Add an API to support IIO generic channels binding: http://devicetree.org/schemas/iio/adc/adc.yaml# This new API is needed, as generic channel DT node isn't populated as a device. Add devm_iio_backend_subnode_get() to allow an IIO device backend consumer to configure backend phandles in its child nodes. Signed-off-by: Olivier Moysan <olivier.moysan@xxxxxxxxxxx> --- drivers/iio/industrialio-backend.c | 48 ++++++++++++++++++++++-------- include/linux/iio/backend.h | 2 ++ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c index d3db048c086b..e9d29131634d 100644 --- a/drivers/iio/industrialio-backend.c +++ b/drivers/iio/industrialio-backend.c @@ -575,17 +575,8 @@ static int __devm_iio_backend_get(struct device *dev, struct iio_backend *back) return 0; } -/** - * devm_iio_backend_get - Device managed backend device get - * @dev: Consumer device for the backend - * @name: Backend name - * - * Get's the backend associated with @dev. - * - * RETURNS: - * A backend pointer, negative error pointer otherwise. - */ -struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) +static struct iio_backend *__devm_iio_backend_node_get(struct device *dev, const char *name, + struct fwnode_handle *node) { struct fwnode_handle *fwnode; struct iio_backend *back; @@ -602,7 +593,7 @@ struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) index = 0; } - fwnode = fwnode_find_reference(dev_fwnode(dev), "io-backends", index); + fwnode = fwnode_find_reference(node, "io-backends", index); if (IS_ERR(fwnode)) { dev_err_probe(dev, PTR_ERR(fwnode), "Cannot get Firmware reference\n"); @@ -625,8 +616,41 @@ struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) fwnode_handle_put(fwnode); return ERR_PTR(-EPROBE_DEFER); } + +/** + * devm_iio_backend_get - Device managed backend device get + * @dev: Consumer device for the backend + * @name: Backend name + * + * Get's the backend associated with @dev. + * + * RETURNS: + * A backend pointer, negative error pointer otherwise. + */ +struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name) +{ + return __devm_iio_backend_node_get(dev, name, dev_fwnode(dev)); +} EXPORT_SYMBOL_NS_GPL(devm_iio_backend_get, IIO_BACKEND); +/** + * devm_iio_backend_subnode_get - Device managed backend device get + * @dev: Consumer device for the backend + * @name: Backend name + * @node: Firmware node of the backend consumer + * + * Get's the backend associated with @dev. + * + * RETURNS: + * A backend pointer, negative error pointer otherwise. + */ +struct iio_backend *devm_iio_backend_subnode_get(struct device *dev, const char *name, + struct fwnode_handle *node) +{ + return __devm_iio_backend_node_get(dev, name, node); +} +EXPORT_SYMBOL_NS_GPL(devm_iio_backend_subnode_get, IIO_BACKEND); + /** * __devm_iio_backend_get_from_fwnode_lookup - Device managed fwnode backend device get * @dev: Consumer device for the backend diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h index 81277e5b6160..1050ab68e4e4 100644 --- a/include/linux/iio/backend.h +++ b/include/linux/iio/backend.h @@ -152,6 +152,8 @@ int iio_backend_extend_chan_spec(struct iio_dev *indio_dev, struct iio_chan_spec *chan); 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_subnode_get(struct device *dev, const char *name, + struct fwnode_handle *node); struct iio_backend * __devm_iio_backend_get_from_fwnode_lookup(struct device *dev, struct fwnode_handle *fwnode); -- 2.25.1