Skip to content

Commit

Permalink
gpiolib: allow line names from device props to override driver names
Browse files Browse the repository at this point in the history
Some GPIO providers set names for GPIO lines that match the names of
the pins on the SoC, or variations on that theme. These names are
generic more often that not, such as pioC12 in the at91 case. These
generic names block the possibility to set more useful GPIO line
names with device properties (i.e. gpio-line-names).

Allow overriding a generic name given by the GPIO driver if there is
a name given to the GPIO line using device properties, but leave the
generic name alone if no better name is available.

However, there is a risk. If user space is depending on the above
mentioned fixed GPIO names, AND there are device properties that
previously did not reach the surface, the name change might cause
regressions. But hopefully this stays below the radar...

Reviewed-by: Andy Shevchenko <[email protected]>
Tested-by: Alexander Dahl <[email protected]>
Signed-off-by: Peter Rosin <[email protected]>
Signed-off-by: Bartosz Golaszewski <[email protected]>
Signed-off-by: Valentin Caron <[email protected]>
Change-Id: I26f7f2e1dcc49a7496da0d36ee526a4594189890
Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/271951
Reviewed-by: CITOOLS <[email protected]>
Reviewed-by: CIBUILD <[email protected]>
Reviewed-by: Amelie DELAUNAY <[email protected]>
Reviewed-by: Antonio Maria BORNEO <[email protected]>
Reviewed-by: Eric FOURMONT <[email protected]>
Domain-Review: Amelie DELAUNAY <[email protected]>
  • Loading branch information
peda-r authored and fourmone committed Oct 26, 2022
1 parent 8a71c8c commit 661e4b1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,16 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)
if (count > chip->ngpio)
count = chip->ngpio;

for (i = 0; i < count; i++)
gdev->descs[i].name = names[chip->offset + i];
for (i = 0; i < count; i++) {
/*
* Allow overriding "fixed" names provided by the GPIO
* provider. The "fixed" names are more often than not
* generic and less informative than the names given in
* device properties.
*/
if (names[chip->offset + i] && names[chip->offset + i][0])
gdev->descs[i].name = names[chip->offset + i];
}

kfree(names);

Expand Down Expand Up @@ -708,10 +716,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
INIT_LIST_HEAD(&gdev->pin_ranges);
#endif

if (gc->names)
if (gc->names) {
ret = gpiochip_set_desc_names(gc);
else
ret = devprop_gpiochip_set_names(gc);
if (ret)
goto err_remove_from_list;
}
ret = devprop_gpiochip_set_names(gc);
if (ret)
goto err_remove_from_list;

Expand Down

0 comments on commit 661e4b1

Please sign in to comment.