[03/14] ASoC: sun4i-i2s: Add apb reset
diff mbox

Message ID 2c5abe6578c8e4e841cb59357d88ce397551a593.1475571575.git.mylene.josserand@free-electrons.com
State New
Headers show

Commit Message

Mylene JOSSERAND Oct. 4, 2016, 9:46 a.m. UTC
Add APB deassert function for sun4i-i2s driver.

Signed-off-by: Mylène Josserand <mylene.josserand@free-electrons.com>
---
 sound/soc/sunxi/sun4i-i2s.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

Thomas Petazzoni Oct. 4, 2016, 12:15 p.m. UTC | #1
Hello,

On Tue,  4 Oct 2016 11:46:16 +0200, Mylène Josserand wrote:

>  #include <sound/dmaengine_pcm.h>
>  #include <sound/pcm_params.h>
> @@ -589,6 +590,7 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
>  {
>  	struct sun4i_i2s *i2s;
>  	struct resource *res;
> +	struct reset_control *reset_apb;
>  	void __iomem *regs;
>  	int irq, ret;
>  
> @@ -626,7 +628,19 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
>  		dev_err(&pdev->dev, "Can't get our mod clock\n");
>  		return PTR_ERR(i2s->mod_clk);
>  	}
> -	
> +
> +	reset_apb = devm_reset_control_get(&pdev->dev, "apb_reset");

I believe this is a change in the Device Tree binding, since you're
adding support for a new resource. Perhaps the Device Tree binding
documentation should be updated accordingly?

> +	if (IS_ERR(reset_apb)) {
> +		dev_err(&pdev->dev, "Can't get apb reset\n");
> +		return PTR_ERR(i2s->mod_clk);

This should be:

		return PTR_ERR(reset_apb);

> +	}
> +
> +	ret = reset_control_deassert(reset_apb);
> +	if (ret < 0) {
> +		dev_err(&pdev->dev, "Can't deassert apb reset (%d)\n", ret);
> +		return ret;
> +	}

Do you need to re-assert the reset line in the ->remove() hook?

Best regards,

Thomas
Code Kipper Oct. 4, 2016, 12:22 p.m. UTC | #2
On 4 October 2016 at 11:46, Mylène Josserand
<mylene.josserand@free-electrons.com> wrote:
> Add APB deassert function for sun4i-i2s driver.
>
> Signed-off-by: Mylène Josserand <mylene.josserand@free-electrons.com>
> ---
>  sound/soc/sunxi/sun4i-i2s.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
> index 687a8f8..f3f7026 100644
> --- a/sound/soc/sunxi/sun4i-i2s.c
> +++ b/sound/soc/sunxi/sun4i-i2s.c
> @@ -17,6 +17,7 @@
>  #include <linux/platform_device.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/regmap.h>
> +#include <linux/reset.h>
>
>  #include <sound/dmaengine_pcm.h>
>  #include <sound/pcm_params.h>
> @@ -589,6 +590,7 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
>  {
>         struct sun4i_i2s *i2s;
>         struct resource *res;
> +       struct reset_control *reset_apb;
>         void __iomem *regs;
>         int irq, ret;
>
> @@ -626,7 +628,19 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
>                 dev_err(&pdev->dev, "Can't get our mod clock\n");
>                 return PTR_ERR(i2s->mod_clk);
>         }
> -
> +
> +       reset_apb = devm_reset_control_get(&pdev->dev, "apb_reset");
> +       if (IS_ERR(reset_apb)) {
> +               dev_err(&pdev->dev, "Can't get apb reset\n");
> +               return PTR_ERR(i2s->mod_clk);
> +       }
> +
> +       ret = reset_control_deassert(reset_apb);
> +       if (ret < 0) {
> +               dev_err(&pdev->dev, "Can't deassert apb reset (%d)\n", ret);
> +               return ret;
> +       }
> +
Is this functionality only required for A31 and onwards?,
CK
>         i2s->playback_dma_data.addr = res->start + SUN4I_I2S_FIFO_TX_REG;
>         i2s->playback_dma_data.maxburst = 4;
>
> --
> 2.9.3
>
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Maxime Ripard Oct. 4, 2016, 3:42 p.m. UTC | #3
Hi,

On Tue, Oct 04, 2016 at 02:15:16PM +0200, Thomas Petazzoni wrote:
> Hello,
> 
> On Tue,  4 Oct 2016 11:46:16 +0200, Mylène Josserand wrote:
> 
> >  #include <sound/dmaengine_pcm.h>
> >  #include <sound/pcm_params.h>
> > @@ -589,6 +590,7 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
> >  {
> >  	struct sun4i_i2s *i2s;
> >  	struct resource *res;
> > +	struct reset_control *reset_apb;
> >  	void __iomem *regs;
> >  	int irq, ret;
> >  
> > @@ -626,7 +628,19 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
> >  		dev_err(&pdev->dev, "Can't get our mod clock\n");
> >  		return PTR_ERR(i2s->mod_clk);
> >  	}
> > -	
> > +
> > +	reset_apb = devm_reset_control_get(&pdev->dev, "apb_reset");
> 
> I believe this is a change in the Device Tree binding, since you're
> adding support for a new resource. Perhaps the Device Tree binding
> documentation should be updated accordingly?

Indeed.

You have two solutions to do that:
  - Either mark it as optional and use reset_control_get_optional
    (because here, you broke the other SoCs that have that controller
    but no reset line)
  - Or introduce a new compatible, and make the reset property
    mandatory for that new compatible.

I prefer the latter, since you get a stricter error check, and you
cannot end up in a situation where your driver probes but is
useless. But you'll find both in our drivers.

> > +	}
> > +
> > +	ret = reset_control_deassert(reset_apb);
> > +	if (ret < 0) {
> > +		dev_err(&pdev->dev, "Can't deassert apb reset (%d)\n", ret);
> > +		return ret;
> > +	}
> 
> Do you need to re-assert the reset line in the ->remove() hook?

Even better, you can add it to the runtime_pm hooks! :)

Maxime
Mylene JOSSERAND Oct. 5, 2016, 9:43 a.m. UTC | #4
Hello,


On 04/10/2016 17:42, Maxime Ripard wrote:
> Hi,
>
> On Tue, Oct 04, 2016 at 02:15:16PM +0200, Thomas Petazzoni wrote:
>> Hello,
>>
>> On Tue,  4 Oct 2016 11:46:16 +0200, Mylène Josserand wrote:
>>
>>>  #include <sound/dmaengine_pcm.h>
>>>  #include <sound/pcm_params.h>
>>> @@ -589,6 +590,7 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
>>>  {
>>>  	struct sun4i_i2s *i2s;
>>>  	struct resource *res;
>>> +	struct reset_control *reset_apb;
>>>  	void __iomem *regs;
>>>  	int irq, ret;
>>>
>>> @@ -626,7 +628,19 @@ static int sun4i_i2s_probe(struct platform_device *pdev)
>>>  		dev_err(&pdev->dev, "Can't get our mod clock\n");
>>>  		return PTR_ERR(i2s->mod_clk);
>>>  	}
>>> -	
>>> +
>>> +	reset_apb = devm_reset_control_get(&pdev->dev, "apb_reset");
>>
>> I believe this is a change in the Device Tree binding, since you're
>> adding support for a new resource. Perhaps the Device Tree binding
>> documentation should be updated accordingly?
>
> Indeed.
>
> You have two solutions to do that:
>   - Either mark it as optional and use reset_control_get_optional
>     (because here, you broke the other SoCs that have that controller
>     but no reset line)
>   - Or introduce a new compatible, and make the reset property
>     mandatory for that new compatible.
>
> I prefer the latter, since you get a stricter error check, and you
> cannot end up in a situation where your driver probes but is
> useless. But you'll find both in our drivers.
>


Okay, thank you for the hints!


>>> +	}
>>> +
>>> +	ret = reset_control_deassert(reset_apb);
>>> +	if (ret < 0) {
>>> +		dev_err(&pdev->dev, "Can't deassert apb reset (%d)\n", ret);
>>> +		return ret;
>>> +	}
>>
>> Do you need to re-assert the reset line in the ->remove() hook?
>
> Even better, you can add it to the runtime_pm hooks! :)


I will have a look to runtime_pm and update it for a V2.

Patch
diff mbox

diff --git a/sound/soc/sunxi/sun4i-i2s.c b/sound/soc/sunxi/sun4i-i2s.c
index 687a8f8..f3f7026 100644
--- a/sound/soc/sunxi/sun4i-i2s.c
+++ b/sound/soc/sunxi/sun4i-i2s.c
@@ -17,6 +17,7 @@ 
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/regmap.h>
+#include <linux/reset.h>
 
 #include <sound/dmaengine_pcm.h>
 #include <sound/pcm_params.h>
@@ -589,6 +590,7 @@  static int sun4i_i2s_probe(struct platform_device *pdev)
 {
 	struct sun4i_i2s *i2s;
 	struct resource *res;
+	struct reset_control *reset_apb;
 	void __iomem *regs;
 	int irq, ret;
 
@@ -626,7 +628,19 @@  static int sun4i_i2s_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "Can't get our mod clock\n");
 		return PTR_ERR(i2s->mod_clk);
 	}
-	
+
+	reset_apb = devm_reset_control_get(&pdev->dev, "apb_reset");
+	if (IS_ERR(reset_apb)) {
+		dev_err(&pdev->dev, "Can't get apb reset\n");
+		return PTR_ERR(i2s->mod_clk);
+	}
+
+	ret = reset_control_deassert(reset_apb);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Can't deassert apb reset (%d)\n", ret);
+		return ret;
+	}
+
 	i2s->playback_dma_data.addr = res->start + SUN4I_I2S_FIFO_TX_REG;
 	i2s->playback_dma_data.maxburst = 4;