Hi Jianqun, Am Montag, 31. August 2020, 10:50:21 CEST schrieb Jianqun Xu: > Register both gpio driver and device as part of driver model, so that > the '-gpio'/'-gpios' dependency in dts can be correctly handled by > of_devlink/of_fwlink. > > Signed-off-by: Jianqun Xu <jay.xu@xxxxxxxxxxxxxx> [...] > -static int rockchip_gpiolib_unregister(struct platform_device *pdev, > - struct rockchip_pinctrl *info) > -{ > - struct rockchip_pin_ctrl *ctrl = info->ctrl; > - struct rockchip_pin_bank *bank = ctrl->pin_banks; > - int i; > + pctldev = info->pctl_dev; > + if (!pctldev) > + return -ENODEV; > > - for (i = 0; i < ctrl->nr_banks; ++i, ++bank) { > - if (!bank->valid) > - continue; > - gpiochip_remove(&bank->gpio_chip); > + ret = gpiochip_add_pin_range(gc, dev_name(pctldev->dev), 0, gc->base, gc->ngpio); > + if (ret) { > + dev_err(&pdev->dev, "Failed to add pin range\n"); > + gpiochip_remove(&bank->gpio_chip); > + return ret; > + } > } > > return 0; > @@ -3752,6 +3734,46 @@ static int __maybe_unused rockchip_pinctrl_resume(struct device *dev) > static SIMPLE_DEV_PM_OPS(rockchip_pinctrl_dev_pm_ops, rockchip_pinctrl_suspend, > rockchip_pinctrl_resume); > > +static int rockchip_gpio_probe(struct platform_device *pdev) > +{ > + struct device_node *np = pdev->dev.of_node; > + struct device *parent = pdev->dev.parent; > + struct rockchip_pinctrl *info = dev_get_drvdata(parent); > + struct rockchip_pin_ctrl *ctrl = info ? (info->ctrl) : NULL; > + struct rockchip_pin_bank *bank; > + int ret, i; > + > + if (!info || !ctrl) > + return -EINVAL; > + > + if (!of_find_property(np, "gpio-controller", NULL)) > + return -ENODEV; > + > + bank = ctrl->pin_banks; > + for (i = 0; i < ctrl->nr_banks; ++i, ++bank) { > + if (!strcmp(bank->name, np->name)) { > + bank->of_node = np; > + > + if (!rockchip_get_bank_data(bank, info)) > + bank->valid = true; > + > + break; > + } > + } > + > + bank->of_node = pdev->dev.of_node; > + > + ret = rockchip_gpiolib_register(pdev, bank); > + if (ret) > + return ret; > + > + ret = rockchip_interrupts_register(pdev, bank); > + if (ret) > + return ret; > + > + return 0; > +} > + > static int rockchip_pinctrl_probe(struct platform_device *pdev) > { > struct rockchip_pinctrl *info; > @@ -3823,18 +3845,20 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev) > return PTR_ERR(info->regmap_pmu); > } > > - ret = rockchip_gpiolib_register(pdev, info); > - if (ret) > - return ret; > - > ret = rockchip_pinctrl_register(pdev, info); > if (ret) { > - rockchip_gpiolib_unregister(pdev, info); > + dev_err(&pdev->dev, "failed to register pinctrl device\n"); > return ret; > } > > platform_set_drvdata(pdev, info); > > + ret = of_platform_populate(np, rockchip_bank_match, NULL, dev); > + if (ret) { > + dev_err(&pdev->dev, "failed to register gpio device\n"); > + return ret; > + } > + > return 0; > } > > @@ -4254,6 +4278,14 @@ static const struct of_device_id rockchip_pinctrl_dt_match[] = { > {}, > }; > > +static struct platform_driver rockchip_gpio_driver = { > + .probe = rockchip_gpio_probe, > + .driver = { > + .name = "rockchip-gpio", > + .of_match_table = rockchip_bank_match, > + }, > +}; > + > static struct platform_driver rockchip_pinctrl_driver = { > .probe = rockchip_pinctrl_probe, > .driver = { > @@ -4265,7 +4297,9 @@ static struct platform_driver rockchip_pinctrl_driver = { > > static int __init rockchip_pinctrl_drv_register(void) > { > - return platform_driver_register(&rockchip_pinctrl_driver); > + platform_driver_register(&rockchip_pinctrl_driver); > + > + return platform_driver_register(&rockchip_gpio_driver); > } > postcore_initcall(rockchip_pinctrl_drv_register); This also seems to miss the whole unloading of module paths? I'd expect a gpiochip_remove etc in some _remove function and of course a platform_driver_unregister. Heiko