Skip to content

Commit e75729b

Browse files
dtorlinusw
authored andcommitted
pinctrl: st: stop abusing of_get_named_gpio()
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 <[email protected]> Tested-by: Patrice Chotard <[email protected]> Reviewed-by: Patrice Chotard <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent f4a31fa commit e75729b

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

drivers/pinctrl/pinctrl-st.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/io.h>
1313
#include <linux/of.h>
1414
#include <linux/of_irq.h>
15-
#include <linux/of_gpio.h> /* of_get_named_gpio() */
1615
#include <linux/of_address.h>
1716
#include <linux/gpio/driver.h>
1817
#include <linux/regmap.h>
@@ -1162,6 +1161,31 @@ static void st_parse_syscfgs(struct st_pinctrl *info, int bank,
11621161
return;
11631162
}
11641163

1164+
static int st_pctl_dt_calculate_pin(struct st_pinctrl *info,
1165+
phandle bank, unsigned int offset)
1166+
{
1167+
struct device_node *np;
1168+
struct gpio_chip *chip;
1169+
int retval = -EINVAL;
1170+
int i;
1171+
1172+
np = of_find_node_by_phandle(bank);
1173+
if (!np)
1174+
return -EINVAL;
1175+
1176+
for (i = 0; i < info->nbanks; i++) {
1177+
chip = &info->banks[i].gpio_chip;
1178+
if (chip->of_node == np) {
1179+
if (offset < chip->ngpio)
1180+
retval = chip->base + offset;
1181+
break;
1182+
}
1183+
}
1184+
1185+
of_node_put(np);
1186+
return retval;
1187+
}
1188+
11651189
/*
11661190
* Each pin is represented in of the below forms.
11671191
* <bank offset mux direction rt_type rt_delay rt_clk>
@@ -1175,6 +1199,8 @@ static int st_pctl_dt_parse_groups(struct device_node *np,
11751199
struct device *dev = info->dev;
11761200
struct st_pinconf *conf;
11771201
struct device_node *pins;
1202+
phandle bank;
1203+
unsigned int offset;
11781204
int i = 0, npins = 0, nr_props, ret = 0;
11791205

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

12161242
/* bank & offset */
1217-
be32_to_cpup(list++);
1218-
be32_to_cpup(list++);
1219-
conf->pin = of_get_named_gpio(pins, pp->name, 0);
1243+
bank = be32_to_cpup(list++);
1244+
offset = be32_to_cpup(list++);
1245+
conf->pin = st_pctl_dt_calculate_pin(info, bank, offset);
12201246
conf->name = pp->name;
12211247
grp->pins[i] = conf->pin;
12221248
/* mux */

0 commit comments

Comments
 (0)