Skip to content

Commit

Permalink
pinctrl: st: stop abusing of_get_named_gpio()
Browse files Browse the repository at this point in the history
Pin descriptions for this chip only look like standard GPIO device tree
descriptions, while in fact they contain additional data (in excess of
number of cells specified in description of gpio controllers). They also
refer to only pins/gpios belonging to the driver and not to arbitrary
gpio in the system.

Because we want to stop exporting OF-specific handlers from gpiolib-of,
let's parse the pin reference ourself instead of trying to call
of_get_named_gpio().

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Link: https://lore.kernel.org/r/YzSsgoVoJn4+mSpv@google.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
  • Loading branch information
Dmitry Torokhov authored and Linus Walleij committed Oct 4, 2022
1 parent f4a31fa commit e75729b
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions drivers/pinctrl/pinctrl-st.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <linux/io.h>
#include <linux/of.h>
#include <linux/of_irq.h>
#include <linux/of_gpio.h> /* of_get_named_gpio() */
#include <linux/of_address.h>
#include <linux/gpio/driver.h>
#include <linux/regmap.h>
Expand Down Expand Up @@ -1162,6 +1161,31 @@ static void st_parse_syscfgs(struct st_pinctrl *info, int bank,
return;
}

static int st_pctl_dt_calculate_pin(struct st_pinctrl *info,
phandle bank, unsigned int offset)
{
struct device_node *np;
struct gpio_chip *chip;
int retval = -EINVAL;
int i;

np = of_find_node_by_phandle(bank);
if (!np)
return -EINVAL;

for (i = 0; i < info->nbanks; i++) {
chip = &info->banks[i].gpio_chip;
if (chip->of_node == np) {
if (offset < chip->ngpio)
retval = chip->base + offset;
break;
}
}

of_node_put(np);
return retval;
}

/*
* Each pin is represented in of the below forms.
* <bank offset mux direction rt_type rt_delay rt_clk>
Expand All @@ -1175,6 +1199,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
struct device *dev = info->dev;
struct st_pinconf *conf;
struct device_node *pins;
phandle bank;
unsigned int offset;
int i = 0, npins = 0, nr_props, ret = 0;

pins = of_get_child_by_name(np, "st,pins");
Expand Down Expand Up @@ -1214,9 +1240,9 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
conf = &grp->pin_conf[i];

/* bank & offset */
be32_to_cpup(list++);
be32_to_cpup(list++);
conf->pin = of_get_named_gpio(pins, pp->name, 0);
bank = be32_to_cpup(list++);
offset = be32_to_cpup(list++);
conf->pin = st_pctl_dt_calculate_pin(info, bank, offset);
conf->name = pp->name;
grp->pins[i] = conf->pin;
/* mux */
Expand Down

0 comments on commit e75729b

Please sign in to comment.