diff mbox series

gpio: gpio-dwapb: add optional reset

Message ID 20171011163444.2989-1-atull@kernel.org
State New
Headers show
Series gpio: gpio-dwapb: add optional reset | expand

Commit Message

Alan Tull Oct. 11, 2017, 4:34 p.m. UTC
Some platforms require reset to be released to allow register
access.

Signed-off-by: Alan Tull <atull@kernel.org>
---
v2: Request shared controller
    return all errors from reset controller request
    drop conditions on asserting/deasserting reset
---
 drivers/gpio/gpio-dwapb.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Alan Tull Oct. 11, 2017, 5:47 p.m. UTC | #1
On Wed, Oct 11, 2017 at 11:34 AM, Alan Tull <atull@kernel.org> wrote:

Sorry, I forgot to specify PATCH v2 in the subject.

Alan

> Some platforms require reset to be released to allow register
> access.
>
> Signed-off-by: Alan Tull <atull@kernel.org>
> ---
> v2: Request shared controller
>     return all errors from reset controller request
>     drop conditions on asserting/deasserting reset
> ---
>  drivers/gpio/gpio-dwapb.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
> index f051c45..0df8cdf 100644
> --- a/drivers/gpio/gpio-dwapb.c
> +++ b/drivers/gpio/gpio-dwapb.c
> @@ -25,6 +25,7 @@
>  #include <linux/of_irq.h>
>  #include <linux/platform_device.h>
>  #include <linux/property.h>
> +#include <linux/reset.h>
>  #include <linux/spinlock.h>
>  #include <linux/platform_data/gpio-dwapb.h>
>  #include <linux/slab.h>
> @@ -97,6 +98,7 @@ struct dwapb_gpio {
>         unsigned int            nr_ports;
>         struct irq_domain       *domain;
>         unsigned int            flags;
> +       struct reset_control    *rst;
>  };
>
>  static inline u32 gpio_reg_v2_convert(unsigned int offset)
> @@ -608,6 +610,12 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
>         gpio->dev = &pdev->dev;
>         gpio->nr_ports = pdata->nports;
>
> +       gpio->rst = devm_reset_control_get_optional_shared(dev, NULL);
> +       if (IS_ERR(gpio->rst))
> +               return PTR_ERR(gpio->rst);
> +
> +       reset_control_deassert(gpio->rst);
> +
>         gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports,
>                                    sizeof(*gpio->ports), GFP_KERNEL);
>         if (!gpio->ports)
> @@ -659,6 +667,7 @@ static int dwapb_gpio_remove(struct platform_device *pdev)
>
>         dwapb_gpio_unregister(gpio);
>         dwapb_irq_teardown(gpio);
> +       reset_control_assert(gpio->rst);
>
>         return 0;
>  }
> --
> 2.7.4
>
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Philipp Zabel Oct. 12, 2017, 8:18 a.m. UTC | #2
On Wed, 2017-10-11 at 11:34 -0500, Alan Tull wrote:
> Some platforms require reset to be released to allow register
> access.
> 
> Signed-off-by: Alan Tull <atull@kernel.org>
> ---
> v2: Request shared controller
>     return all errors from reset controller request
>     drop conditions on asserting/deasserting reset

Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>

Could you also update the device tree binding docs [1] to mention the
optional resets phandle?

[1] Documentation/devicetree/bindings/gpio/snps-dwapb-gpio.txt

regards
Philipp

> ---
>  drivers/gpio/gpio-dwapb.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
> index f051c45..0df8cdf 100644
> --- a/drivers/gpio/gpio-dwapb.c
> +++ b/drivers/gpio/gpio-dwapb.c
> @@ -25,6 +25,7 @@
>  #include <linux/of_irq.h>
>  #include <linux/platform_device.h>
>  #include <linux/property.h>
> +#include <linux/reset.h>
>  #include <linux/spinlock.h>
>  #include <linux/platform_data/gpio-dwapb.h>
>  #include <linux/slab.h>
> @@ -97,6 +98,7 @@ struct dwapb_gpio {
>  	unsigned int		nr_ports;
>  	struct irq_domain	*domain;
>  	unsigned int		flags;
> +	struct reset_control	*rst;
>  };
>  
>  static inline u32 gpio_reg_v2_convert(unsigned int offset)
> @@ -608,6 +610,12 @@ static int dwapb_gpio_probe(struct platform_device *pdev)
>  	gpio->dev = &pdev->dev;
>  	gpio->nr_ports = pdata->nports;
>  
> +	gpio->rst = devm_reset_control_get_optional_shared(dev, NULL);
> +	if (IS_ERR(gpio->rst))
> +		return PTR_ERR(gpio->rst);
> +
> +	reset_control_deassert(gpio->rst);
> +
>  	gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports,
>  				   sizeof(*gpio->ports), GFP_KERNEL);
>  	if (!gpio->ports)
> @@ -659,6 +667,7 @@ static int dwapb_gpio_remove(struct platform_device *pdev)
>  
>  	dwapb_gpio_unregister(gpio);
>  	dwapb_irq_teardown(gpio);
> +	reset_control_assert(gpio->rst);
>  
>  	return 0;
>  }
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Oct. 12, 2017, 8:26 a.m. UTC | #3
On Wed, Oct 11, 2017 at 6:34 PM, Alan Tull <atull@kernel.org> wrote:

> Some platforms require reset to be released to allow register
> access.
>
> Signed-off-by: Alan Tull <atull@kernel.org>
> ---
> v2: Request shared controller
>     return all errors from reset controller request
>     drop conditions on asserting/deasserting reset

This v2 version applied with Philipp's review tag, I also added
a blurb to the DT binding as Philipp asked so no need to fix that
separately.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alan Tull Oct. 12, 2017, 2:34 p.m. UTC | #4
On Thu, Oct 12, 2017 at 3:26 AM, Linus Walleij <linus.walleij@linaro.org> wrote:

Hi Linus, Phillipp,

> This v2 version applied with Philipp's review tag, I also added
> a blurb to the DT binding as Philipp asked so no need to fix that
> separately.
>
> Yours,
> Linus Walleij

Thanks!

Alan Tull
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c
index f051c45..0df8cdf 100644
--- a/drivers/gpio/gpio-dwapb.c
+++ b/drivers/gpio/gpio-dwapb.c
@@ -25,6 +25,7 @@ 
 #include <linux/of_irq.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
+#include <linux/reset.h>
 #include <linux/spinlock.h>
 #include <linux/platform_data/gpio-dwapb.h>
 #include <linux/slab.h>
@@ -97,6 +98,7 @@  struct dwapb_gpio {
 	unsigned int		nr_ports;
 	struct irq_domain	*domain;
 	unsigned int		flags;
+	struct reset_control	*rst;
 };
 
 static inline u32 gpio_reg_v2_convert(unsigned int offset)
@@ -608,6 +610,12 @@  static int dwapb_gpio_probe(struct platform_device *pdev)
 	gpio->dev = &pdev->dev;
 	gpio->nr_ports = pdata->nports;
 
+	gpio->rst = devm_reset_control_get_optional_shared(dev, NULL);
+	if (IS_ERR(gpio->rst))
+		return PTR_ERR(gpio->rst);
+
+	reset_control_deassert(gpio->rst);
+
 	gpio->ports = devm_kcalloc(&pdev->dev, gpio->nr_ports,
 				   sizeof(*gpio->ports), GFP_KERNEL);
 	if (!gpio->ports)
@@ -659,6 +667,7 @@  static int dwapb_gpio_remove(struct platform_device *pdev)
 
 	dwapb_gpio_unregister(gpio);
 	dwapb_irq_teardown(gpio);
+	reset_control_assert(gpio->rst);
 
 	return 0;
 }