diff mbox series

[v6,2/2] pinctrl: microchip sgpio: use reset driver

Message ID 20211018085754.1066056-3-horatiu.vultur@microchip.com (mailing list archive)
State New, archived
Headers show
Series pinctrl: pinctrl-microchip-sgpio: Extend to call reset driver | expand

Commit Message

Horatiu Vultur Oct. 18, 2021, 8:57 a.m. UTC
On lan966x platform when the switch gets reseted then also the sgpio
gets reseted. The fix for this is to extend also the sgpio driver to
call the reset driver which will be reseted only once by the first
driver that is probed.

Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
---
 drivers/pinctrl/pinctrl-microchip-sgpio.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Philipp Zabel Oct. 18, 2021, 10:37 a.m. UTC | #1
Hi Horatiu,

On Mon, 2021-10-18 at 10:57 +0200, Horatiu Vultur wrote:
> On lan966x platform when the switch gets reseted then also the sgpio
> gets reseted. The fix for this is to extend also the sgpio driver to
> call the reset driver which will be reseted only once by the first
> driver that is probed.
> 
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> ---
>  drivers/pinctrl/pinctrl-microchip-sgpio.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c
> index 072bccdea2a5..78765faa245a 100644
> --- a/drivers/pinctrl/pinctrl-microchip-sgpio.c
> +++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c
> @@ -17,6 +17,7 @@
>  #include <linux/pinctrl/pinmux.h>
>  #include <linux/platform_device.h>
>  #include <linux/property.h>
> +#include <linux/reset.h>
>  
>  #include "core.h"
>  #include "pinconf.h"
> @@ -803,6 +804,7 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
>  	int div_clock = 0, ret, port, i, nbanks;
>  	struct device *dev = &pdev->dev;
>  	struct fwnode_handle *fwnode;
> +	struct reset_control *reset;
>  	struct sgpio_priv *priv;
>  	struct clk *clk;
>  	u32 val;
> @@ -813,6 +815,11 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
>  
>  	priv->dev = dev;
>  
> +	reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");

This is the first GPIO driver that I am aware of that requests a named
reset control, so I'm still not sure if this should be called "switch"
instead of "gpio" or just "reset", just in case there is a future model
where the GPIO controller reset is not shared with the switch reset.

> +	if (IS_ERR(reset))
> +		return dev_err_probe(dev, PTR_ERR(reset), "Failed to get reset\n");
> +	reset_control_reset(reset);
> +
>  	clk = devm_clk_get(dev, NULL);
>  	if (IS_ERR(clk))
>  		return dev_err_probe(dev, PTR_ERR(clk), "Failed to get clock\n");

But whichever name you choose, the code is

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

regards
Philipp
Horatiu Vultur Oct. 18, 2021, 11:12 a.m. UTC | #2
The 10/18/2021 12:37, Philipp Zabel wrote:

Hi Philipp,
> 
> Hi Horatiu,
> 
> On Mon, 2021-10-18 at 10:57 +0200, Horatiu Vultur wrote:
> > On lan966x platform when the switch gets reseted then also the sgpio
> > gets reseted. The fix for this is to extend also the sgpio driver to
> > call the reset driver which will be reseted only once by the first
> > driver that is probed.
> >
> > Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> > ---
> >  drivers/pinctrl/pinctrl-microchip-sgpio.c | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c
> > index 072bccdea2a5..78765faa245a 100644
> > --- a/drivers/pinctrl/pinctrl-microchip-sgpio.c
> > +++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c
> > @@ -17,6 +17,7 @@
> >  #include <linux/pinctrl/pinmux.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/property.h>
> > +#include <linux/reset.h>
> >
> >  #include "core.h"
> >  #include "pinconf.h"
> > @@ -803,6 +804,7 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
> >       int div_clock = 0, ret, port, i, nbanks;
> >       struct device *dev = &pdev->dev;
> >       struct fwnode_handle *fwnode;
> > +     struct reset_control *reset;
> >       struct sgpio_priv *priv;
> >       struct clk *clk;
> >       u32 val;
> > @@ -813,6 +815,11 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
> >
> >       priv->dev = dev;
> >
> > +     reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");
> 
> This is the first GPIO driver that I am aware of that requests a named
> reset control, so I'm still not sure if this should be called "switch"
> instead of "gpio" or just "reset", just in case there is a future model
> where the GPIO controller reset is not shared with the switch reset.

I agree, it is not the best name. But the name "switch" was already used
in DT by sparx5[1], so I just went with this name.

> 
> > +     if (IS_ERR(reset))
> > +             return dev_err_probe(dev, PTR_ERR(reset), "Failed to get reset\n");
> > +     reset_control_reset(reset);
> > +
> >       clk = devm_clk_get(dev, NULL);
> >       if (IS_ERR(clk))
> >               return dev_err_probe(dev, PTR_ERR(clk), "Failed to get clock\n");
> 
> But whichever name you choose, the code is
> 
> Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
> 
> regards
> Philipp

[1] https://elixir.bootlin.com/linux/v5.15-rc5/source/arch/arm64/boot/dts/microchip/sparx5.dtsi#L307
Philipp Zabel Oct. 18, 2021, 11:14 a.m. UTC | #3
On Mon, 2021-10-18 at 13:12 +0200, Horatiu Vultur wrote:
> The 10/18/2021 12:37, Philipp Zabel wrote:
> 
> Hi Philipp,
> > Hi Horatiu,
> > 
> > On Mon, 2021-10-18 at 10:57 +0200, Horatiu Vultur wrote:
> > > On lan966x platform when the switch gets reseted then also the sgpio
> > > gets reseted. The fix for this is to extend also the sgpio driver to
> > > call the reset driver which will be reseted only once by the first
> > > driver that is probed.
> > > 
> > > Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>
> > > ---
> > >  drivers/pinctrl/pinctrl-microchip-sgpio.c | 7 +++++++
> > >  1 file changed, 7 insertions(+)
> > > 
> > > diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c
> > > index 072bccdea2a5..78765faa245a 100644
> > > --- a/drivers/pinctrl/pinctrl-microchip-sgpio.c
> > > +++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c
> > > @@ -17,6 +17,7 @@
> > >  #include <linux/pinctrl/pinmux.h>
> > >  #include <linux/platform_device.h>
> > >  #include <linux/property.h>
> > > +#include <linux/reset.h>
> > > 
> > >  #include "core.h"
> > >  #include "pinconf.h"
> > > @@ -803,6 +804,7 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
> > >       int div_clock = 0, ret, port, i, nbanks;
> > >       struct device *dev = &pdev->dev;
> > >       struct fwnode_handle *fwnode;
> > > +     struct reset_control *reset;
> > >       struct sgpio_priv *priv;
> > >       struct clk *clk;
> > >       u32 val;
> > > @@ -813,6 +815,11 @@ static int microchip_sgpio_probe(struct platform_device *pdev)
> > > 
> > >       priv->dev = dev;
> > > 
> > > +     reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");
> > 
> > This is the first GPIO driver that I am aware of that requests a named
> > reset control, so I'm still not sure if this should be called "switch"
> > instead of "gpio" or just "reset", just in case there is a future model
> > where the GPIO controller reset is not shared with the switch reset.
> 
> I agree, it is not the best name. But the name "switch" was already used
> in DT by sparx5[1], so I just went with this name.

Oh, ok, in that case the decision already has been made.

regards
Philipp
Steen Hegelund Oct. 19, 2021, 7:05 a.m. UTC | #4
On Mon, 2021-10-18 at 10:57 +0200, Horatiu Vultur wrote:
> On lan966x platform when the switch gets reseted then also the sgpio
> gets reseted. The fix for this is to extend also the sgpio driver to
> call the reset driver which will be reseted only once by the first
> driver that is probed.
> 
> Signed-off-by: Horatiu Vultur <horatiu.vultur@microchip.com>

Reviewed-by: Steen Hegelund <steen.hegelund@microchip.com>
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-microchip-sgpio.c b/drivers/pinctrl/pinctrl-microchip-sgpio.c
index 072bccdea2a5..78765faa245a 100644
--- a/drivers/pinctrl/pinctrl-microchip-sgpio.c
+++ b/drivers/pinctrl/pinctrl-microchip-sgpio.c
@@ -17,6 +17,7 @@ 
 #include <linux/pinctrl/pinmux.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
+#include <linux/reset.h>
 
 #include "core.h"
 #include "pinconf.h"
@@ -803,6 +804,7 @@  static int microchip_sgpio_probe(struct platform_device *pdev)
 	int div_clock = 0, ret, port, i, nbanks;
 	struct device *dev = &pdev->dev;
 	struct fwnode_handle *fwnode;
+	struct reset_control *reset;
 	struct sgpio_priv *priv;
 	struct clk *clk;
 	u32 val;
@@ -813,6 +815,11 @@  static int microchip_sgpio_probe(struct platform_device *pdev)
 
 	priv->dev = dev;
 
+	reset = devm_reset_control_get_optional_shared(&pdev->dev, "switch");
+	if (IS_ERR(reset))
+		return dev_err_probe(dev, PTR_ERR(reset), "Failed to get reset\n");
+	reset_control_reset(reset);
+
 	clk = devm_clk_get(dev, NULL);
 	if (IS_ERR(clk))
 		return dev_err_probe(dev, PTR_ERR(clk), "Failed to get clock\n");