Message ID | 20220920010930.822856-1-jay.xu@rock-chips.com |
---|---|
State | New |
Headers | show |
Series | gpiolib: make gpiochip_find_by_name to be common function | expand |
On Tue, Sep 20, 2022 at 3:09 AM Jianqun Xu <jay.xu@rock-chips.com> 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@rock-chips.com> 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
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index cc9c0a12259e..60259e76d361 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -935,18 +935,6 @@ struct gpio_chip *gpiochip_find(void *data, } EXPORT_SYMBOL_GPL(gpiochip_find); -static int gpiochip_match_name(struct gpio_chip *gc, void *data) -{ - const char *name = data; - - return !strcmp(gc->label, name); -} - -static struct gpio_chip *find_chip_by_name(const char *name) -{ - return gpiochip_find((void *)name, gpiochip_match_name); -} - #ifdef CONFIG_GPIOLIB_IRQCHIP /* diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 6aeea1071b1b..4ed26a7d98ff 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -618,6 +618,18 @@ extern int devm_gpiochip_add_data_with_key(struct device *dev, struct gpio_chip extern struct gpio_chip *gpiochip_find(void *data, int (*match)(struct gpio_chip *gc, void *data)); +static int gpiochip_match_name(struct gpio_chip *gc, void *data) +{ + const char *name = data; + + return !strcmp(gc->label, name); +} + +static inline struct gpio_chip *gpiochip_find_by_name(const char *name) +{ + return gpiochip_find((void *)name, gpiochip_match_name); +} + bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset); int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset); void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset);
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@rock-chips.com> --- drivers/gpio/gpiolib.c | 12 ------------ include/linux/gpio/driver.h | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-)