diff mbox series

[v2,1/2] ata: ahci_brcm: Perform reset after obtaining resources

Message ID 20200106191906.18266-2-f.fainelli@gmail.com
State Not Applicable
Delegated to: David Miller
Headers show
Series ata: ahci_brcm: Follow-up changes for BCM7216 | expand

Commit Message

Florian Fainelli Jan. 6, 2020, 7:19 p.m. UTC
Resources such as clocks, PHYs, regulators are likely to get a probe
deferral return code, which could lead to the AHCI controller being
reset a few times until it gets successfully probed. Since this is
typically the most time consuming operation, move it after the resources
have been acquired.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/ata/ahci_brcm.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Philipp Zabel Jan. 7, 2020, 8:19 a.m. UTC | #1
Hi Florian,

On Mon, 2020-01-06 at 11:19 -0800, Florian Fainelli wrote:
> Resources such as clocks, PHYs, regulators are likely to get a probe
> deferral return code, which could lead to the AHCI controller being
> reset a few times until it gets successfully probed. Since this is
> typically the most time consuming operation, move it after the resources
> have been acquired.
> 
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
>  drivers/ata/ahci_brcm.c | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/ata/ahci_brcm.c b/drivers/ata/ahci_brcm.c
> index 13ceca687104..70e3e386d52e 100644
> --- a/drivers/ata/ahci_brcm.c
> +++ b/drivers/ata/ahci_brcm.c
> @@ -453,15 +453,9 @@ static int brcm_ahci_probe(struct platform_device *pdev)
>  	else
>  		reset_name = "ahci";
>  
> -	priv->rcdev = devm_reset_control_get(&pdev->dev, reset_name);
> -	if (!IS_ERR_OR_NULL(priv->rcdev))
> -		reset_control_deassert(priv->rcdev);
> -
>  	hpriv = ahci_platform_get_resources(pdev, 0);
> -	if (IS_ERR(hpriv)) {
> -		ret = PTR_ERR(hpriv);
> -		goto out_reset;
> -	}
> +	if (IS_ERR(hpriv))
> +		return PTR_ERR(hpriv);
>  
>  	hpriv->plat_data = priv;
>  	hpriv->flags = AHCI_HFLAG_WAKE_BEFORE_STOP | AHCI_HFLAG_NO_WRITE_TO_RO;
> @@ -478,6 +472,10 @@ static int brcm_ahci_probe(struct platform_device *pdev)
>  		break;
>  	}
>  
> +	priv->rcdev = devm_reset_control_get(&pdev->dev, reset_name);
> +	if (!IS_ERR_OR_NULL(priv->rcdev))
> +		reset_control_deassert(priv->rcdev);
> +

Please use devm_reset_control_get_optional_exclusive(), that returns
NULL if the requested reset is not specified in the device tree. Do
return the error code on IS_ERR(). You can then call
reset_control_deassert() unconditionally, it checks for and ignores
the NULL pointer.

regards
Philipp
diff mbox series

Patch

diff --git a/drivers/ata/ahci_brcm.c b/drivers/ata/ahci_brcm.c
index 13ceca687104..70e3e386d52e 100644
--- a/drivers/ata/ahci_brcm.c
+++ b/drivers/ata/ahci_brcm.c
@@ -453,15 +453,9 @@  static int brcm_ahci_probe(struct platform_device *pdev)
 	else
 		reset_name = "ahci";
 
-	priv->rcdev = devm_reset_control_get(&pdev->dev, reset_name);
-	if (!IS_ERR_OR_NULL(priv->rcdev))
-		reset_control_deassert(priv->rcdev);
-
 	hpriv = ahci_platform_get_resources(pdev, 0);
-	if (IS_ERR(hpriv)) {
-		ret = PTR_ERR(hpriv);
-		goto out_reset;
-	}
+	if (IS_ERR(hpriv))
+		return PTR_ERR(hpriv);
 
 	hpriv->plat_data = priv;
 	hpriv->flags = AHCI_HFLAG_WAKE_BEFORE_STOP | AHCI_HFLAG_NO_WRITE_TO_RO;
@@ -478,6 +472,10 @@  static int brcm_ahci_probe(struct platform_device *pdev)
 		break;
 	}
 
+	priv->rcdev = devm_reset_control_get(&pdev->dev, reset_name);
+	if (!IS_ERR_OR_NULL(priv->rcdev))
+		reset_control_deassert(priv->rcdev);
+
 	ret = ahci_platform_enable_clks(hpriv);
 	if (ret)
 		goto out_reset;