[PATCH 1/3] of: platform: call struct device::detect in of_device_create_on_demand

Sascha Hauer sha at pengutronix.de
Thu Jan 19 23:36:52 PST 2023


On Mon, Jan 16, 2023 at 02:36:37PM +0100, Ahmad Fatoum wrote:
> Most devices featuring a detect callback use it to probe an underlying
> bus. However, of_device_create_on_demand so far created devices on the
> platform bus, ignoring that it might be e.g. an I2C device that's
> supposed to be crated by the parent controller.
> 
> Fix this by calling the parent's detect callback if available. Busses
> that probe via device tree, but register their devices on a different
> bus will need to register a detect callback to benefit from this.
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
> ---
>  drivers/of/platform.c | 7 +++++++
>  1 file changed, 7 insertions(+)

Applied, thanks

Sascha

> 
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index ff7096b6eedd..edb082b106ff 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -414,11 +414,18 @@ static struct device *of_device_create_on_demand(struct device_node *np)
>  {
>  	struct device_node *parent;
>  	struct device *parent_dev, *dev;
> +	int ret;
>  
>  	parent = of_get_parent(np);
>  	if (!parent)
>  		return NULL;
>  
> +	if (!np->dev && parent->dev) {
> +		ret = device_detect(parent->dev);
> +		if (ret && ret != -ENOSYS)
> +			return ERR_PTR(ret);
> +	}
> +
>  	if (!np->dev)
>  		pr_debug("Creating device for %s\n", np->full_name);
>  
> -- 
> 2.30.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list