pinctrl: samsung: Calculate GPIO base for pinctrl_add_gpio_range
diff mbox

Message ID 1487872490-27643-1-git-send-email-ckeepax@opensource.wolfsonmicro.com
State Not Applicable
Headers show

Commit Message

Charles Keepax Feb. 23, 2017, 5:54 p.m. UTC
As the pinctrl is now added before the GPIOs are registered we need to
manually calculate what the GPIO base will be, otherwise the base for
each gpio_range will be set to zero. Fortunately the driver
already assigns a GPIO base, in samsung_gpiolib_register, and uses the
same calculation it does for the pin_base. Meaning the two will always
be the same and allowing us to reuse the pinbase and avoid the issue.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
---

Ok I might have spoken to soon there looks like there is a simple
way to fix this up, at least in this case. It would be much more
of an issue if the driver allocated its GPIO base dynamically.

Thanks,
Charles

 drivers/pinctrl/samsung/pinctrl-samsung.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tomasz Figa Feb. 27, 2017, 2:13 a.m. UTC | #1
Hi Charles,

2017-02-24 2:54 GMT+09:00 Charles Keepax <ckeepax@opensource.wolfsonmicro.com>:
> As the pinctrl is now added before the GPIOs are registered we need to
> manually calculate what the GPIO base will be, otherwise the base for
> each gpio_range will be set to zero. Fortunately the driver
> already assigns a GPIO base, in samsung_gpiolib_register, and uses the
> same calculation it does for the pin_base. Meaning the two will always
> be the same and allowing us to reuse the pinbase and avoid the issue.

Please see my comment inline.

>
> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
> ---
>
> Ok I might have spoken to soon there looks like there is a simple
> way to fix this up, at least in this case. It would be much more
> of an issue if the driver allocated its GPIO base dynamically.
>
> Thanks,
> Charles
>
>  drivers/pinctrl/samsung/pinctrl-samsung.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> index ddc8d6b..864d8b4d 100644
> --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> @@ -882,7 +882,7 @@ static int samsung_pinctrl_register(struct platform_device *pdev,
>                 pin_bank->grange.id = bank;
>                 pin_bank->grange.pin_base = drvdata->pin_base
>                                                 + pin_bank->pin_base;
> -               pin_bank->grange.base = pin_bank->gpio_chip.base;
> +               pin_bank->grange.base = pin_bank->grange.pin_base;

If we are not reading the base from the GPIO bank anymore, maybe it
could make sense to actually make samsung_gpiolib_register() use
bank->grange.base as gc->base? This way we would avoid explicitly
numbering two times.

Best regards,
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Charles Keepax Feb. 28, 2017, 9:01 a.m. UTC | #2
On Mon, Feb 27, 2017 at 11:13:59AM +0900, Tomasz Figa wrote:
> > diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
> > index ddc8d6b..864d8b4d 100644
> > --- a/drivers/pinctrl/samsung/pinctrl-samsung.c
> > +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
> > @@ -882,7 +882,7 @@ static int samsung_pinctrl_register(struct platform_device *pdev,
> >                 pin_bank->grange.id = bank;
> >                 pin_bank->grange.pin_base = drvdata->pin_base
> >                                                 + pin_bank->pin_base;
> > -               pin_bank->grange.base = pin_bank->gpio_chip.base;
> > +               pin_bank->grange.base = pin_bank->grange.pin_base;
> 
> If we are not reading the base from the GPIO bank anymore, maybe it
> could make sense to actually make samsung_gpiolib_register() use
> bank->grange.base as gc->base? This way we would avoid explicitly
> numbering two times.
> 

Yeah no problem I can respin with that included.

Thanks,
Charles
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c
index ddc8d6b..864d8b4d 100644
--- a/drivers/pinctrl/samsung/pinctrl-samsung.c
+++ b/drivers/pinctrl/samsung/pinctrl-samsung.c
@@ -882,7 +882,7 @@  static int samsung_pinctrl_register(struct platform_device *pdev,
 		pin_bank->grange.id = bank;
 		pin_bank->grange.pin_base = drvdata->pin_base
 						+ pin_bank->pin_base;
-		pin_bank->grange.base = pin_bank->gpio_chip.base;
+		pin_bank->grange.base = pin_bank->grange.pin_base;
 		pin_bank->grange.npins = pin_bank->gpio_chip.ngpio;
 		pin_bank->grange.gc = &pin_bank->gpio_chip;
 		pinctrl_add_gpio_range(drvdata->pctl_dev, &pin_bank->grange);