diff mbox series

[v3,11/11] PCI: imx6: Replace calls to udelay() with usleep_range()

Message ID 20190401042547.14067-12-andrew.smirnov@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series i.MX6, DesignWare PCI improvements | expand

Commit Message

Andrey Smirnov April 1, 2019, 4:25 a.m. UTC
In both cases udelay() is called in non-atomic context, so there's
really no need to use it there. Change the code to use usleep_range()
instead.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/pci/controller/dwc/pci-imx6.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Lucas Stach April 12, 2019, 4:26 p.m. UTC | #1
Am Sonntag, den 31.03.2019, 21:25 -0700 schrieb Andrey Smirnov:
> In both cases udelay() is called in non-atomic context, so there's
> really no need to use it there. Change the code to use usleep_range()
> instead.
> 
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  drivers/pci/controller/dwc/pci-imx6.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> index c9431a8a7ca1..3f13022991ec 100644
> --- a/drivers/pci/controller/dwc/pci-imx6.c
> +++ b/drivers/pci/controller/dwc/pci-imx6.c
> @@ -167,7 +167,7 @@ static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, bool exp_val)
>  		if (val == exp_val)
>  			return 0;
>  
> -		udelay(1);
> +		usleep_range(10, 100);

I'm not sure we want to change this. This is dragging out the timeout
considerably while the really short delay, together with the low number
of max loop iterations suggests that the condition is usually met very
quickly.

Maybe this would even want a change in the other direction by replacing
the udelay with a cpu_relax to speed up the condition detection and
stall the CPU in device memory loads, instead of having it spin in a
tight inner loop.

>  	} while (wait_counter < max_iterations);
>  
>  	return -ETIMEDOUT;
> @@ -449,7 +449,7 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
>  		 * reset time is too short, cannot meet the requirement.
>  		 * add one ~10us delay here.
>  		 */
> -		udelay(10);
> +		usleep_range(10, 100);

This one looks good.

Regards,
Lucas

>  		regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
>  				   IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
>  		break;
Andrey Smirnov April 14, 2019, 6:48 p.m. UTC | #2
On Fri, Apr 12, 2019 at 9:26 AM Lucas Stach <l.stach@pengutronix.de> wrote:
>
> Am Sonntag, den 31.03.2019, 21:25 -0700 schrieb Andrey Smirnov:
> > In both cases udelay() is called in non-atomic context, so there's
> > really no need to use it there. Change the code to use usleep_range()
> > instead.
> >
> > > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> > ---
> >  drivers/pci/controller/dwc/pci-imx6.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
> > index c9431a8a7ca1..3f13022991ec 100644
> > --- a/drivers/pci/controller/dwc/pci-imx6.c
> > +++ b/drivers/pci/controller/dwc/pci-imx6.c
> > @@ -167,7 +167,7 @@ static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, bool exp_val)
> >               if (val == exp_val)
> >                       return 0;
> >
> > -             udelay(1);
> > +             usleep_range(10, 100);
>
> I'm not sure we want to change this. This is dragging out the timeout
> considerably while the really short delay, together with the low number
> of max loop iterations suggests that the condition is usually met very
> quickly.
>
> Maybe this would even want a change in the other direction by replacing
> the udelay with a cpu_relax to speed up the condition detection and
> stall the CPU in device memory loads, instead of having it spin in a
> tight inner loop.
>

OK, will do.

Thanks,
Andrey Smirnov
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index c9431a8a7ca1..3f13022991ec 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -167,7 +167,7 @@  static int pcie_phy_poll_ack(struct imx6_pcie *imx6_pcie, bool exp_val)
 		if (val == exp_val)
 			return 0;
 
-		udelay(1);
+		usleep_range(10, 100);
 	} while (wait_counter < max_iterations);
 
 	return -ETIMEDOUT;
@@ -449,7 +449,7 @@  static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie)
 		 * reset time is too short, cannot meet the requirement.
 		 * add one ~10us delay here.
 		 */
-		udelay(10);
+		usleep_range(10, 100);
 		regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR1,
 				   IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16);
 		break;