diff mbox series

[v5,1/2] phy: core: Use runtime pm during configure too

Message ID 2de2ee26bbf443491dfff1c802f2fa9efaf58d52.1617968250.git.agx@sigxcpu.org (mailing list archive)
State New, archived
Headers show
Series phy: fsl-imx8-mipi-dphy: Hook into runtime pm | expand

Commit Message

Guido Günther April 9, 2021, 11:40 a.m. UTC
The phy's configure phase usually needs register access so taking the
device out of pm_runtime suspend looks useful.

There's currently two in tree drivers using runtime pm and .configure
(qualcomm/phy-qcom-qmp.c, rockchip/phy-rockchip-inno-dsidphy.c) but both
don't use the phy layers 'transparent' runtime phy_pm_runtime handling
but manage it manually so this will for now only affect the
phy-fsl-imx8-mipi-dphy driver.

Signed-off-by: Guido Günther <agx@sigxcpu.org>
---
 drivers/phy/phy-core.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Ying Liu April 12, 2021, 8:40 a.m. UTC | #1
Hi Guido,

On Fri, 2021-04-09 at 13:40 +0200, Guido Günther wrote:
> The phy's configure phase usually needs register access so taking the
> device out of pm_runtime suspend looks useful.
> 
> There's currently two in tree drivers using runtime pm and .configure
> (qualcomm/phy-qcom-qmp.c, rockchip/phy-rockchip-inno-dsidphy.c) but both
> don't use the phy layers 'transparent' runtime phy_pm_runtime handling
> but manage it manually so this will for now only affect the
> phy-fsl-imx8-mipi-dphy driver.

IIUC, the qualcomm one's runtime PM is managed by the phy core when
users enable it using power/control in sysfs(see comment just before
pm_runtime_forbid() in that driver).
I'm assuming it's affected and it would be good to test it.

I'm not pretty sure if the rockchip one is affected or not, because I'm
assuming the power/control nodes of phy->dev and phy->parent.dev in
sysfs are both 'auto' after the driver probes.

> 
> Signed-off-by: Guido Günther <agx@sigxcpu.org>
> ---
>  drivers/phy/phy-core.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index ccb575b13777..256a964d52d3 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -470,10 +470,16 @@ int phy_configure(struct phy *phy, union phy_configure_opts *opts)
>  	if (!phy->ops->configure)
>  		return -EOPNOTSUPP;
>  
> +	ret = phy_pm_runtime_get_sync(phy);
> +	if (ret < 0 && ret != -ENOTSUPP)
> +		return ret;
> +	ret = 0; /* Override possible ret == -ENOTSUPP */

This override is not needed, because 'ret' will be the return value of
phy->ops->configure() right below.

Regards,
Liu Ying

> +
>  	mutex_lock(&phy->mutex);
>  	ret = phy->ops->configure(phy, opts);
>  	mutex_unlock(&phy->mutex);
>  
> +	phy_pm_runtime_put(phy);
>  	return ret;
>  }
>  EXPORT_SYMBOL_GPL(phy_configure);
Guido Günther April 12, 2021, 9:41 a.m. UTC | #2
Hi,
On Mon, Apr 12, 2021 at 04:40:56PM +0800, Liu Ying wrote:
> Hi Guido,
> 
> On Fri, 2021-04-09 at 13:40 +0200, Guido Günther wrote:
> > The phy's configure phase usually needs register access so taking the
> > device out of pm_runtime suspend looks useful.
> > 
> > There's currently two in tree drivers using runtime pm and .configure
> > (qualcomm/phy-qcom-qmp.c, rockchip/phy-rockchip-inno-dsidphy.c) but both
> > don't use the phy layers 'transparent' runtime phy_pm_runtime handling
> > but manage it manually so this will for now only affect the
> > phy-fsl-imx8-mipi-dphy driver.
> 
> IIUC, the qualcomm one's runtime PM is managed by the phy core when
> users enable it using power/control in sysfs(see comment just before
> pm_runtime_forbid() in that driver).
> I'm assuming it's affected and it would be good to test it.

Ah, right. I'll reword the commit message but i don't have any means to
test it.

> I'm not pretty sure if the rockchip one is affected or not, because I'm
> assuming the power/control nodes of phy->dev and phy->parent.dev in
> sysfs are both 'auto' after the driver probes.

Testing if adding runtime pm for .configure to phy_core breaks anything
here would be great too.

I've added Dmitry and Heiko to cc: since they were active in those
drivers lately and i sure don't want to break these.

> > 
> > Signed-off-by: Guido Günther <agx@sigxcpu.org>
> > ---
> >  drivers/phy/phy-core.c | 6 ++++++
> >  1 file changed, 6 insertions(+)
> > 
> > diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> > index ccb575b13777..256a964d52d3 100644
> > --- a/drivers/phy/phy-core.c
> > +++ b/drivers/phy/phy-core.c
> > @@ -470,10 +470,16 @@ int phy_configure(struct phy *phy, union phy_configure_opts *opts)
> >  	if (!phy->ops->configure)
> >  		return -EOPNOTSUPP;
> >  
> > +	ret = phy_pm_runtime_get_sync(phy);
> > +	if (ret < 0 && ret != -ENOTSUPP)
> > +		return ret;
> > +	ret = 0; /* Override possible ret == -ENOTSUPP */
> 
> This override is not needed, because 'ret' will be the return value of
> phy->ops->configure() right below.

I thought being explicit is better here but i'll drop that for the next
rev.

Thanks!
 -- Guido

> 
> Regards,
> Liu Ying
> 
> > +
> >  	mutex_lock(&phy->mutex);
> >  	ret = phy->ops->configure(phy, opts);
> >  	mutex_unlock(&phy->mutex);
> >  
> > +	phy_pm_runtime_put(phy);
> >  	return ret;
> >  }
> >  EXPORT_SYMBOL_GPL(phy_configure);
>
diff mbox series

Patch

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index ccb575b13777..256a964d52d3 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -470,10 +470,16 @@  int phy_configure(struct phy *phy, union phy_configure_opts *opts)
 	if (!phy->ops->configure)
 		return -EOPNOTSUPP;
 
+	ret = phy_pm_runtime_get_sync(phy);
+	if (ret < 0 && ret != -ENOTSUPP)
+		return ret;
+	ret = 0; /* Override possible ret == -ENOTSUPP */
+
 	mutex_lock(&phy->mutex);
 	ret = phy->ops->configure(phy, opts);
 	mutex_unlock(&phy->mutex);
 
+	phy_pm_runtime_put(phy);
 	return ret;
 }
 EXPORT_SYMBOL_GPL(phy_configure);