There are some unfortunate cases where the DT representation
of the device and the Linux internal representation differs.
Such drivers for devices are forced to implement a custom function
to avoid the core code 'devprop_gpiochip_set_names' to be executed
since in any other case every gpiochip inside will got repeated
names through its internal gpiochip banks. To avoid this antipattern
this changes are introduced trying to adapt core 'devprop_gpiochip_set_names'
to get a correct behaviour for every single situation.
This series introduces a new 'offset' field in the gpiochip structure
that can be used for those unfortunate drivers that must define multiple
gpiochips per device.
Drivers affected by this situation are also updated. These are
'gpio-mt7621' and 'gpio-brcmstb'.
Motivation for this series available at [0].
Thanks in advance for your feedback.
Best regards,
Sergio Paracuellos
Changes in v4:
- Add comma in warning message for clarity.
- Collect Gregory Fong Reviewed-by for PATCH 1/3.
Changes in v3:
- Reflow a string literal to be on one line in PATCH 1/3.
- reflow commit messages PATCH 2/3 and PATCH 3/3 to occupy a little bit
more available space per line.
Changes in v2:
- Address Gregory Fong comments in v1 of the series [1].
- Collect Andy Shevchenko Reviewed-by for the series.
- Collect Gregory Fong Acked-by for PATCH 3/3.
[0]: https://lkml.org/lkml/2021/6/26/198
[1]: https://lkml.org/lkml/2021/7/8/47
Sergio Paracuellos (3):
gpiolib: convert 'devprop_gpiochip_set_names' to support multiple
gpiochip banks per device
gpio: mt7621: support gpio-line-names property
gpio: brcmstb: remove custom 'brcmstb_gpio_set_names'
drivers/gpio/gpio-brcmstb.c | 45 +------------------------------------
drivers/gpio/gpio-mt7621.c | 1 +
drivers/gpio/gpiolib.c | 32 +++++++++++++++++++++-----
include/linux/gpio/driver.h | 4 ++++
4 files changed, 33 insertions(+), 49 deletions(-)
--
2.25.1
The default gpiolib-of implementation does not work with the multiple
gpiochip banks per device structure used for example by the gpio-mt7621
and gpio-brcmstb drivers. To fix these kind of situations driver code
is forced to fill the names to avoid the gpiolib code to set names
repeated along the banks. Instead of continue with that antipattern
fix the gpiolib core function to get expected behaviour for every
single situation adding a field 'offset' in the gpiochip structure.
Doing in this way, we can assume this offset will be zero for normal
driver code where only one gpiochip bank per device is used but
can be set explicitly in those drivers that really need more than
one gpiochip.
Reviewed-by: Andy Shevchenko <redacted>
Reviewed-by: Gregory Fong <redacted>
Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
drivers/gpio/gpiolib.c | 32 +++++++++++++++++++++++++++-----
include/linux/gpio/driver.h | 4 ++++
2 files changed, 31 insertions(+), 5 deletions(-)
@@ -382,10 +382,18 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)if(count<0)return0;-if(count>gdev->ngpio){-dev_warn(&gdev->dev,"gpio-line-names is length %d but should be at most length %d",-count,gdev->ngpio);-count=gdev->ngpio;+/*+*Whenoffsetissetinthedriversideweassumethedriverinternally+*isusingmorethanonegpiochipperthesamedevice.Wehavetostop+*settingfriendlynamesifthespecifiedoneswith'gpio-line-names'+*arelessthantheoffsetinthedeviceitself.Thismeansallthe+*linesarenotpresentforeverysinglepinwithinalltheinternal+*gpiochips.+*/+if(count<=chip->offset){+dev_warn(&gdev->dev,"gpio-line-names too short (length %d), cannot map names for the gpiochip at offset %u\n",+count,chip->offset);+return0;}names=kcalloc(count,sizeof(*names),GFP_KERNEL);
@@ -400,8 +408,22 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)returnret;}+/*+*Whenmorethatonegpiochipperdeviceisused,'count'can+*containatmostnumbergpiochipsxchip->ngpio.Wehaveto+*correctlydistributealldefinedlinestakingintoaccount+*chip->offsetasstartingpointfromwherewewillassign+*thenamestopinsfromthe'names'array.Sinceproperty+*'gpio-line-names'cannotcontainsgaps,wehavetobesure+*weonlyassignthosepinsthatreallyexistssincechip->ngpio+*canbedifferentofthechip->offset.+*/+count=(count>chip->offset)?count-chip->offset:count;+if(count>chip->ngpio)+count=chip->ngpio;+for(i=0;i<count;i++)-gdev->descs[i].name=names[i];+gdev->descs[i].name=names[chip->offset+i];kfree(names);
This driver uses multiple gpiochip banks per device. To support
'gpio-line-names' along the banks 'offset' for each bank must be
set explicitly.
Reviewed-by: Andy Shevchenko <redacted>
Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
drivers/gpio/gpio-mt7621.c | 1 +
1 file changed, 1 insertion(+)
Gpiolib core code has been updated to support setting friendly names
through properly 'gpio-line-names'. Instead of redefine behaviour here
to skip the core to be executed, just properly assign the desired offset
per bank to get in the core the expected behaviour.
Reviewed-by: Andy Shevchenko <redacted>
Acked-by: Gregory Fong <redacted>
Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
drivers/gpio/gpio-brcmstb.c | 45 +------------------------------------
1 file changed, 1 insertion(+), 44 deletions(-)
@@ -603,49 +603,6 @@ static const struct dev_pm_ops brcmstb_gpio_pm_ops = {.resume_noirq=brcmstb_gpio_resume,};-staticvoidbrcmstb_gpio_set_names(structdevice*dev,-structbrcmstb_gpio_bank*bank)-{-structdevice_node*np=dev->of_node;-constchar**names;-intnstrings,base;-unsignedinti;--base=bank->id*MAX_GPIO_PER_BANK;--nstrings=of_property_count_strings(np,"gpio-line-names");-if(nstrings<=base)-/* Line names not present */-return;--names=devm_kcalloc(dev,MAX_GPIO_PER_BANK,sizeof(*names),-GFP_KERNEL);-if(!names)-return;--/*-*Makesuretonotindexbeyondtheendofthenumberofdescriptors-*oftheGPIOdevice.-*/-for(i=0;i<bank->width;i++){-constchar*name;-intret;--ret=of_property_read_string_index(np,"gpio-line-names",-base+i,&name);-if(ret){-if(ret!=-ENODATA)-dev_err(dev,"unable to name line %d: %d\n",-base+i,ret);-break;-}-if(*name)-names[i]=name;-}--bank->gc.names=names;-}-staticintbrcmstb_gpio_probe(structplatform_device*pdev){structdevice*dev=&pdev->dev;
@@ -759,6 +716,7 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)gc->of_xlate=brcmstb_gpio_of_xlate;/* not all ngpio lines are valid, will use bank width later */gc->ngpio=MAX_GPIO_PER_BANK;+gc->offset=bank->id*MAX_GPIO_PER_BANK;if(priv->parent_irq>0)gc->to_irq=brcmstb_gpio_to_irq;
@@ -769,7 +727,6 @@ static int brcmstb_gpio_probe(struct platform_device *pdev)need_wakeup_event|=!!__brcmstb_gpio_get_active_irqs(bank);gc->write_reg(reg_base+GIO_MASK(bank->id),0);-brcmstb_gpio_set_names(dev,bank);err=gpiochip_add_data(gc,bank);if(err){dev_err(dev,"Could not add gpiochip for bank %d\n",
On Wed, Jul 28, 2021 at 6:12 AM Sergio Paracuellos
[off-list ref] wrote:
There are some unfortunate cases where the DT representation
of the device and the Linux internal representation differs.
Such drivers for devices are forced to implement a custom function
to avoid the core code 'devprop_gpiochip_set_names' to be executed
since in any other case every gpiochip inside will got repeated
names through its internal gpiochip banks. To avoid this antipattern
this changes are introduced trying to adapt core 'devprop_gpiochip_set_names'
to get a correct behaviour for every single situation.
This series introduces a new 'offset' field in the gpiochip structure
that can be used for those unfortunate drivers that must define multiple
gpiochips per device.
Drivers affected by this situation are also updated. These are
'gpio-mt7621' and 'gpio-brcmstb'.
Motivation for this series available at [0].
Thanks in advance for your feedback.
Best regards,
Sergio Paracuellos
Changes in v4:
- Add comma in warning message for clarity.
- Collect Gregory Fong Reviewed-by for PATCH 1/3.
Changes in v3:
- Reflow a string literal to be on one line in PATCH 1/3.
- reflow commit messages PATCH 2/3 and PATCH 3/3 to occupy a little bit
more available space per line.
Changes in v2:
- Address Gregory Fong comments in v1 of the series [1].
- Collect Andy Shevchenko Reviewed-by for the series.
- Collect Gregory Fong Acked-by for PATCH 3/3.
[0]: https://lkml.org/lkml/2021/6/26/198
[1]: https://lkml.org/lkml/2021/7/8/47
Sergio Paracuellos (3):
gpiolib: convert 'devprop_gpiochip_set_names' to support multiple
gpiochip banks per device
gpio: mt7621: support gpio-line-names property
gpio: brcmstb: remove custom 'brcmstb_gpio_set_names'
drivers/gpio/gpio-brcmstb.c | 45 +------------------------------------
drivers/gpio/gpio-mt7621.c | 1 +
drivers/gpio/gpiolib.c | 32 +++++++++++++++++++++-----
include/linux/gpio/driver.h | 4 ++++
4 files changed, 33 insertions(+), 49 deletions(-)
--
2.25.1
On Thu, Jul 29, 2021 at 7:43 PM Bartosz Golaszewski
[off-list ref] wrote:
On Wed, Jul 28, 2021 at 6:12 AM Sergio Paracuellos
[off-list ref] wrote:
quoted
There are some unfortunate cases where the DT representation
of the device and the Linux internal representation differs.
Such drivers for devices are forced to implement a custom function
to avoid the core code 'devprop_gpiochip_set_names' to be executed
since in any other case every gpiochip inside will got repeated
names through its internal gpiochip banks. To avoid this antipattern
this changes are introduced trying to adapt core 'devprop_gpiochip_set_names'
to get a correct behaviour for every single situation.
This series introduces a new 'offset' field in the gpiochip structure
that can be used for those unfortunate drivers that must define multiple
gpiochips per device.
Drivers affected by this situation are also updated. These are
'gpio-mt7621' and 'gpio-brcmstb'.
Motivation for this series available at [0].
Thanks in advance for your feedback.
Best regards,
Sergio Paracuellos
Changes in v4:
- Add comma in warning message for clarity.
- Collect Gregory Fong Reviewed-by for PATCH 1/3.
Changes in v3:
- Reflow a string literal to be on one line in PATCH 1/3.
- reflow commit messages PATCH 2/3 and PATCH 3/3 to occupy a little bit
more available space per line.
Changes in v2:
- Address Gregory Fong comments in v1 of the series [1].
- Collect Andy Shevchenko Reviewed-by for the series.
- Collect Gregory Fong Acked-by for PATCH 3/3.
[0]: https://lkml.org/lkml/2021/6/26/198
[1]: https://lkml.org/lkml/2021/7/8/47
Sergio Paracuellos (3):
gpiolib: convert 'devprop_gpiochip_set_names' to support multiple
gpiochip banks per device
gpio: mt7621: support gpio-line-names property
gpio: brcmstb: remove custom 'brcmstb_gpio_set_names'
drivers/gpio/gpio-brcmstb.c | 45 +------------------------------------
drivers/gpio/gpio-mt7621.c | 1 +
drivers/gpio/gpiolib.c | 32 +++++++++++++++++++++-----
include/linux/gpio/driver.h | 4 ++++
4 files changed, 33 insertions(+), 49 deletions(-)
--
2.25.1
On Thu, Jul 29, 2021 at 7:43 PM Bartosz Golaszewski
[off-list ref] wrote:
On Wed, Jul 28, 2021 at 6:12 AM Sergio Paracuellos
[off-list ref] wrote:
Patches queued for next. Thanks!
Thanks to all for fixing this hairy situation with composite
GPIO controllers. I think there are some more controllers
that need this actually.
Yours,
Linus Walleij
Hi Linus,
On Wed, Aug 11, 2021 at 11:03 AM Linus Walleij [off-list ref] wrote:
On Thu, Jul 29, 2021 at 7:43 PM Bartosz Golaszewski
[off-list ref] wrote:
quoted
On Wed, Jul 28, 2021 at 6:12 AM Sergio Paracuellos
[off-list ref] wrote:
quoted
Patches queued for next. Thanks!
Thanks to all for fixing this hairy situation with composite
GPIO controllers. I think there are some more controllers
that need this actually.
I was searching for clear patterns that were using a similar approach
to this new stuff inside the gpio folder and I was not able to
properly be sure which other drivers can get the same change that I
did for mt7621 and broadcom applied... If you point me out to which
drivers can also use this, I am ok in sending patches for all of them
when I come back from a little rest time on August 23th.
Thanks,
Sergio Paracuellos
On Wed, Aug 11, 2021 at 12:27 PM Sergio Paracuellos
[off-list ref] wrote:
I was searching for clear patterns that were using a similar approach
to this new stuff inside the gpio folder and I was not able to
properly be sure which other drivers can get the same change that I
did for mt7621 and broadcom applied... If you point me out to which
drivers can also use this, I am ok in sending patches for all of them
when I come back from a little rest time on August 23th.
I don't know exactly how to identify these but this is one:
pinctrl-microchip-sgpio.c
Yours,
Linus Walleij