2021-04-09 11:42:31

by Guido Günther

[permalink] [raw]
Subject: [PATCH v5 0/2] phy: fsl-imx8-mipi-dphy: Hook into runtime pm

This allows us to shut down the mipi power domain on the imx8. The alternative
would be to drop the dphy from the mipi power domain in the SOCs device tree
and only have the DSI host controller visible there but since the PD is mostly
about the PHY that would defeat it's purpose.

This allows to shut off the power domain when blanking the LCD panel:

pm_genpd_summary before:

domain status slaves
/device runtime status
----------------------------------------------------------------------
mipi on
/devices/platform/soc@0/soc@0:bus@30800000/30a00300.dphy unsupported
/devices/platform/soc@0/soc@0:bus@30800000/30a00000.mipi_dsi suspended

after:

mipi off-0
/devices/platform/soc@0/soc@0:bus@30800000/30a00300.dphy suspended
/devices/platform/soc@0/soc@0:bus@30800000/30a00000.mipi_dsi suspended

Changes from v1:
- Tweak commit message slightly

Changes from v2:
- As per review comment by Lucas Stach
https://lore.kernel.org/linux-arm-kernel/[email protected]/
Check for pm_runtime_get_sync failure

Changes from v3:
- As per review comment by Liu Ying
https://lore.kernel.org/linux-arm-kernel/[email protected]/
https://lore.kernel.org/linux-arm-kernel/[email protected]/
- Use phy layers runtime pm
- simplify mixel_dphy_remove

Chanes from v4:
- As per review comment by Liu Ying
https://lore.kernel.org/linux-arm-kernel/[email protected]/
- Disable after probe errors
- core: increment device usage count on .configure as well

Guido Günther (2):
phy: core: Use runtime pm during configure too
phy: fsl-imx8-mipi-dphy: Hook into runtime pm

drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c | 13 +++++++++++++
drivers/phy/phy-core.c | 6 ++++++
2 files changed, 19 insertions(+)

--
2.30.1


2021-04-09 11:42:52

by Guido Günther

[permalink] [raw]
Subject: [PATCH v5 2/2] phy: fsl-imx8-mipi-dphy: Hook into runtime pm

This allows us to shut down the mipi power domain on the imx8. The
alternative would be to drop the dphy from the mipi power domain in the
SOCs device tree and only have the DSI host controller visible there but
since the PD is mostly about the PHY that would defeat it's purpose.

This allows to shut off the power domain when blanking the LCD panel:

pm_genpd_summary before:

domain status slaves
/device runtime status
----------------------------------------------------------------------
mipi on
/devices/platform/soc@0/soc@0:bus@30800000/30a00300.dphy unsupported
/devices/platform/soc@0/soc@0:bus@30800000/30a00000.mipi_dsi suspended

after:

mipi off-0
/devices/platform/soc@0/soc@0:bus@30800000/30a00300.dphy suspended
/devices/platform/soc@0/soc@0:bus@30800000/30a00000.mipi_dsi suspended

Signed-off-by: Guido Günther <[email protected]>
---
drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c
index a95572b397ca..f89a0c458499 100644
--- a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c
+++ b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c
@@ -14,6 +14,7 @@
#include <linux/of_platform.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
#include <linux/regmap.h>

/* DPHY registers */
@@ -469,20 +470,32 @@ static int mixel_dphy_probe(struct platform_device *pdev)

dev_set_drvdata(dev, priv);

+ pm_runtime_enable(dev);
+
phy = devm_phy_create(dev, np, &mixel_dphy_phy_ops);
if (IS_ERR(phy)) {
+ pm_runtime_disable(&pdev->dev);
dev_err(dev, "Failed to create phy %ld\n", PTR_ERR(phy));
return PTR_ERR(phy);
}
phy_set_drvdata(phy, priv);

phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
+ if (IS_ERR(phy_provider))
+ pm_runtime_disable(&pdev->dev);

return PTR_ERR_OR_ZERO(phy_provider);
}

+static int mixel_dphy_remove(struct platform_device *pdev)
+{
+ pm_runtime_disable(&pdev->dev);
+ return 0;
+}
+
static struct platform_driver mixel_dphy_driver = {
.probe = mixel_dphy_probe,
+ .remove = mixel_dphy_remove,
.driver = {
.name = "mixel-mipi-dphy",
.of_match_table = mixel_dphy_of_match,
--
2.30.1

2021-04-09 11:42:55

by Guido Günther

[permalink] [raw]
Subject: [PATCH v5 1/2] phy: core: Use runtime pm during configure too

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 <[email protected]>
---
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 */
+
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);
--
2.30.1

2021-04-12 08:43:18

by Liu Ying

[permalink] [raw]
Subject: Re: [PATCH v5 1/2] phy: core: Use runtime pm during configure too

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 <[email protected]>
> ---
> 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);

2021-04-12 09:47:48

by Liu Ying

[permalink] [raw]
Subject: Re: [PATCH v5 2/2] phy: fsl-imx8-mipi-dphy: Hook into runtime pm

Hi Guido,

On Fri, 2021-04-09 at 13:40 +0200, Guido Günther wrote:
> This allows us to shut down the mipi power domain on the imx8. The
> alternative would be to drop the dphy from the mipi power domain in the
> SOCs device tree and only have the DSI host controller visible there but
> since the PD is mostly about the PHY that would defeat it's purpose.
>
> This allows to shut off the power domain when blanking the LCD panel:
>
> pm_genpd_summary before:
>
> domain status slaves
> /device runtime status
> ----------------------------------------------------------------------
> mipi on
> /devices/platform/soc@0/soc@0:bus@30800000/30a00300.dphy unsupported
> /devices/platform/soc@0/soc@0:bus@30800000/30a00000.mipi_dsi suspended
>
> after:
>
> mipi off-0
> /devices/platform/soc@0/soc@0:bus@30800000/30a00300.dphy suspended
> /devices/platform/soc@0/soc@0:bus@30800000/30a00000.mipi_dsi suspended
>
> Signed-off-by: Guido Günther <[email protected]>
> ---
> drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c
> index a95572b397ca..f89a0c458499 100644
> --- a/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c
> +++ b/drivers/phy/freescale/phy-fsl-imx8-mipi-dphy.c
> @@ -14,6 +14,7 @@
> #include <linux/of_platform.h>
> #include <linux/phy/phy.h>
> #include <linux/platform_device.h>
> +#include <linux/pm_runtime.h>
> #include <linux/regmap.h>
>
> /* DPHY registers */
> @@ -469,20 +470,32 @@ static int mixel_dphy_probe(struct platform_device *pdev)
>
> dev_set_drvdata(dev, priv);
>
> + pm_runtime_enable(dev);
> +
> phy = devm_phy_create(dev, np, &mixel_dphy_phy_ops);
> if (IS_ERR(phy)) {
> + pm_runtime_disable(&pdev->dev);

It's fine to just use 'dev'.

> dev_err(dev, "Failed to create phy %ld\n", PTR_ERR(phy));
> return PTR_ERR(phy);
> }
> phy_set_drvdata(phy, priv);
>
> phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> + if (IS_ERR(phy_provider))
> + pm_runtime_disable(&pdev->dev);

Ditto.

With the above two addressed:

Reviewed-by: Liu Ying <[email protected]>

>
> return PTR_ERR_OR_ZERO(phy_provider);
> }
>
> +static int mixel_dphy_remove(struct platform_device *pdev)
> +{
> + pm_runtime_disable(&pdev->dev);
> + return 0;
> +}
> +
> static struct platform_driver mixel_dphy_driver = {
> .probe = mixel_dphy_probe,
> + .remove = mixel_dphy_remove,
> .driver = {
> .name = "mixel-mipi-dphy",
> .of_match_table = mixel_dphy_of_match,

2021-04-12 23:04:14

by Guido Günther

[permalink] [raw]
Subject: Re: [PATCH v5 1/2] phy: core: Use runtime pm during configure too

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 <[email protected]>
> > ---
> > 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);
>