Re: [PATCH] gpiolib: make gpiochip_find_by_name to be common function

From: Linus Walleij
Date: Tue Sep 20 2022 - 08:17:00 EST


On Tue, Sep 20, 2022 at 3:09 AM Jianqun Xu <jay.xu@xxxxxxxxxxxxxx> wrote:

> Move find_chip_by_name from gpiolib to the gpio/driver.h, also rename to
> gpiochip_find_by_name, make it to be a common function.
>
> Signed-off-by: Jianqun Xu <jay.xu@xxxxxxxxxxxxxx>

It feels like you are reimplementing component_match_add() and
component_master_add_with_match().

This is infrastructure from <linux/component.h> that make a device
initialize (bind) and probe subdrivers from a master driver.

See for example in drivers/gpu/drm/vc4/vc4_drv.c:

static struct platform_driver *const component_drivers[] = {
&vc4_hvs_driver,
&vc4_hdmi_driver,
&vc4_vec_driver,
&vc4_dpi_driver,
&vc4_dsi_driver,
&vc4_txp_driver,
&vc4_crtc_driver,
&vc4_v3d_driver,
};

static int vc4_platform_drm_probe(struct platform_device *pdev)
{
struct component_match *match = NULL;
struct device *dev = &pdev->dev;

vc4_match_add_drivers(dev, &match,
component_drivers, ARRAY_SIZE(component_drivers));

return component_master_add_with_match(dev, &vc4_drm_ops, match);
}

This will let each driver bind individually, then the probe calls will be
orchestrated by the component_master_add_with_match(): the master
probes first then each subdriver (hvs, hdmi etc).

This makes it possible to control dependencies in componsite
(componentized) drivers, as you pin controller and GPIO controllers.

I used this for example in a charging driver with dependencies in
drivers/power/supply/ab8500_charger.c and in some DRM drivers.

Yours,
Linus Walleij