[PATCH 20/20] pinctrl/rockchip: find existed gpiochip by gpio label
Jianqun Xu
jay.xu at rock-chips.com
Tue Sep 20 03:31:08 PDT 2022
Currently the pinctrl device acts as parent for the GPIO devices for
Rockchip platform, the pinctrl driver creates the gpiochips and pass to
the GPIO driver.
This patch makes the member of pinctrl structure from gpiochip to
*gpiochip, switch to find existed gpiochips instead of creating them,
that requires the GPIO driver to create them and earlier than the
pinctrl driver.
Signed-off-by: Jianqun Xu <jay.xu at rock-chips.com>
---
drivers/pinctrl/pinctrl-rockchip.c | 24 +++++++++++++++++++++---
drivers/pinctrl/pinctrl-rockchip.h | 2 +-
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
index 97af52bb5481..05e688cd8536 100644
--- a/drivers/pinctrl/pinctrl-rockchip.c
+++ b/drivers/pinctrl/pinctrl-rockchip.c
@@ -2725,7 +2725,7 @@ static int rockchip_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
{
struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
- struct gpio_chip *gpio = &bank->gpio_chip;
+ struct gpio_chip *gpio = bank->gpio_chip;
enum pin_config_param param;
u32 arg;
int i;
@@ -2828,7 +2828,7 @@ static int rockchip_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
{
struct rockchip_pinctrl *info = pinctrl_dev_get_drvdata(pctldev);
struct rockchip_pin_bank *bank = pin_to_bank(info, pin);
- struct gpio_chip *gpio = &bank->gpio_chip;
+ struct gpio_chip *gpio = bank->gpio_chip;
enum pin_config_param param = pinconf_to_config_param(*config);
u16 arg;
int rc;
@@ -3293,7 +3293,7 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev)
struct rockchip_pin_ctrl *ctrl;
struct resource *res;
void __iomem *base;
- int ret;
+ int ret, i;
if (is_of_node(fwnode)) {
ret = of_platform_populate(np, NULL, NULL, dev);
@@ -3357,6 +3357,24 @@ static int rockchip_pinctrl_probe(struct platform_device *pdev)
if (ret)
return ret;
+ for (i = 0; i < ctrl->nr_banks; i++) {
+ struct gpio_chip *gc;
+ struct rockchip_pin_bank *bank = &ctrl->pin_banks[i];
+
+ gc = gpiochip_find_by_name((void *)ctrl->pin_banks[i].name);
+ if (!gc) {
+ dev_err(dev, "fail to find gpiochip\n");
+ return ret;
+ }
+
+ ret = gpiochip_add_pin_range(gc, dev_name(dev), 0, gc->base, gc->ngpio);
+ if (ret) {
+ dev_err(dev, "fail to add pin range\n");
+ return ret;
+ }
+ bank->gpio_chip = gc;
+ }
+
platform_set_drvdata(pdev, info);
dev_info(dev, "probed %pfw\n", fwnode);
diff --git a/drivers/pinctrl/pinctrl-rockchip.h b/drivers/pinctrl/pinctrl-rockchip.h
index 3531633c0397..8b44e02bce97 100644
--- a/drivers/pinctrl/pinctrl-rockchip.h
+++ b/drivers/pinctrl/pinctrl-rockchip.h
@@ -330,7 +330,7 @@ struct rockchip_pin_bank {
struct device_node *of_node;
struct rockchip_pinctrl *drvdata;
struct irq_domain *domain;
- struct gpio_chip gpio_chip;
+ struct gpio_chip *gpio_chip;
struct pinctrl_gpio_range grange;
raw_spinlock_t slock;
const struct rockchip_gpio_regs *gpio_regs;
--
2.25.1
More information about the Linux-rockchip
mailing list