diff mbox series

[RESEND,v2,4/7] clk: qcom: gdsc: enable optional power domain support

Message ID 20210709043136.533205-5-dmitry.baryshkov@linaro.org
State Superseded
Headers show
Series clk: qcom: use power-domain for sm8250's clock controllers | expand

Commit Message

Dmitry Baryshkov July 9, 2021, 4:31 a.m. UTC
On sm8250 dispcc and videocc registers are powered up by the MMCX power
domain. Currently we used a regulator to enable this domain on demand,
however this has some consequences, as genpd code is not reentrant.

Teach Qualcomm clock controller code about setting up power domains and
using them for gdsc control.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

---
 drivers/clk/qcom/common.c | 37 +++++++++++++++++++++++++++++++------
 drivers/clk/qcom/gdsc.c   |  5 +++++
 2 files changed, 36 insertions(+), 6 deletions(-)

-- 
2.30.2

Comments

Ulf Hansson July 9, 2021, 9:32 a.m. UTC | #1
On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>
> On sm8250 dispcc and videocc registers are powered up by the MMCX power
> domain. Currently we used a regulator to enable this domain on demand,
> however this has some consequences, as genpd code is not reentrant.
>
> Teach Qualcomm clock controller code about setting up power domains and
> using them for gdsc control.
>
> Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

[...]

> diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c
> index 51ed640e527b..9401d01533c8 100644
> --- a/drivers/clk/qcom/gdsc.c
> +++ b/drivers/clk/qcom/gdsc.c
> @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,
>                         continue;
>                 scs[i]->regmap = regmap;
>                 scs[i]->rcdev = rcdev;
> +               scs[i]->pd.dev.parent = desc->dev;
>                 ret = gdsc_init(scs[i]);
>                 if (ret)
>                         return ret;
> @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,
>                         continue;
>                 if (scs[i]->parent)
>                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);
> +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being
called for gdsc platform device from the platform bus', to try to
attach the device to its corresponding PM domain.

Looking a bit closer to genpd_dev_pm_attach(), I realize that we
shouldn't really try to attach a device to its PM domain, when its OF
node (dev->of_node) contains a "#power-domain-cells" specifier. This
is because it indicates that the device belongs to a genpd provider
itself. In this case, a "power-domains" specifier tells that it has a
parent domain.

I will post a patch that fixes this asap.

> +                       pm_genpd_add_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
>         }
>
>         return of_genpd_add_provider_onecell(dev->of_node, data);
> @@ -457,6 +460,8 @@ void gdsc_unregister(struct gdsc_desc *desc)
>                         continue;
>                 if (scs[i]->parent)
>                         pm_genpd_remove_subdomain(scs[i]->parent, &scs[i]->pd);
> +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

Ditto.

> +                       pm_genpd_remove_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
>         }
>         of_genpd_del_provider(dev->of_node);
>  }
> --
> 2.30.2
>

Kind regards
Uffe
Dmitry Baryshkov July 9, 2021, 11:46 a.m. UTC | #2
On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov
> <dmitry.baryshkov@linaro.org> wrote:
> >
> > On sm8250 dispcc and videocc registers are powered up by the MMCX power
> > domain. Currently we used a regulator to enable this domain on demand,
> > however this has some consequences, as genpd code is not reentrant.
> >
> > Teach Qualcomm clock controller code about setting up power domains and
> > using them for gdsc control.
> >
> > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
>
> [...]
>
> > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c
> > index 51ed640e527b..9401d01533c8 100644
> > --- a/drivers/clk/qcom/gdsc.c
> > +++ b/drivers/clk/qcom/gdsc.c
> > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,
> >                         continue;
> >                 scs[i]->regmap = regmap;
> >                 scs[i]->rcdev = rcdev;
> > +               scs[i]->pd.dev.parent = desc->dev;
> >                 ret = gdsc_init(scs[i]);
> >                 if (ret)
> >                         return ret;
> > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,
> >                         continue;
> >                 if (scs[i]->parent)
> >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);
> > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))
>
> So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being
> called for gdsc platform device from the platform bus', to try to
> attach the device to its corresponding PM domain.
>
> Looking a bit closer to genpd_dev_pm_attach(), I realize that we
> shouldn't really try to attach a device to its PM domain, when its OF
> node (dev->of_node) contains a "#power-domain-cells" specifier. This
> is because it indicates that the device belongs to a genpd provider
> itself. In this case, a "power-domains" specifier tells that it has a
> parent domain.
>
> I will post a patch that fixes this asap.

I think there is nothing to fix here. The dispcc/videocc drivers
provide clocks in addition to the gdsc power domain. And provided
clocks would definitely benefit from having the dispcc device being
attached to the power domain which governs clock registers (MMCX in
our case). Thus I think it is perfectly valid to have:

rpmhpd device:
 - provides MMCX domain.

dispcc device:
 - is attached to the MMCX domain,
 - provides MDSS_GDSC
 - provides clocks

>
> > +                       pm_genpd_add_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
> >         }
> >
> >         return of_genpd_add_provider_onecell(dev->of_node, data);
> > @@ -457,6 +460,8 @@ void gdsc_unregister(struct gdsc_desc *desc)
> >                         continue;
> >                 if (scs[i]->parent)
> >                         pm_genpd_remove_subdomain(scs[i]->parent, &scs[i]->pd);
> > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))
>
> Ditto.
>
> > +                       pm_genpd_remove_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
> >         }
> >         of_genpd_del_provider(dev->of_node);
> >  }
> > --
> > 2.30.2
> >
>
> Kind regards
> Uffe
Ulf Hansson July 9, 2021, 12:18 p.m. UTC | #3
On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>
> On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> >
> > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov
> > <dmitry.baryshkov@linaro.org> wrote:
> > >
> > > On sm8250 dispcc and videocc registers are powered up by the MMCX power
> > > domain. Currently we used a regulator to enable this domain on demand,
> > > however this has some consequences, as genpd code is not reentrant.
> > >
> > > Teach Qualcomm clock controller code about setting up power domains and
> > > using them for gdsc control.
> > >
> > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> >
> > [...]
> >
> > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c
> > > index 51ed640e527b..9401d01533c8 100644
> > > --- a/drivers/clk/qcom/gdsc.c
> > > +++ b/drivers/clk/qcom/gdsc.c
> > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,
> > >                         continue;
> > >                 scs[i]->regmap = regmap;
> > >                 scs[i]->rcdev = rcdev;
> > > +               scs[i]->pd.dev.parent = desc->dev;
> > >                 ret = gdsc_init(scs[i]);
> > >                 if (ret)
> > >                         return ret;
> > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,
> > >                         continue;
> > >                 if (scs[i]->parent)
> > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);
> > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))
> >
> > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being
> > called for gdsc platform device from the platform bus', to try to
> > attach the device to its corresponding PM domain.
> >
> > Looking a bit closer to genpd_dev_pm_attach(), I realize that we
> > shouldn't really try to attach a device to its PM domain, when its OF
> > node (dev->of_node) contains a "#power-domain-cells" specifier. This
> > is because it indicates that the device belongs to a genpd provider
> > itself. In this case, a "power-domains" specifier tells that it has a
> > parent domain.
> >
> > I will post a patch that fixes this asap.
>
> I think there is nothing to fix here. The dispcc/videocc drivers
> provide clocks in addition to the gdsc power domain. And provided
> clocks would definitely benefit from having the dispcc device being
> attached to the power domain which governs clock registers (MMCX in
> our case). Thus I think it is perfectly valid to have:
>
> rpmhpd device:
>  - provides MMCX domain.
>
> dispcc device:
>  - is attached to the MMCX domain,

We don't need this, it's redundant and weird to me.

Also I am kind of worried that you will hit another new path in genpd,
causing locking issues etc, as it has not been designed to work like
this (a provider device and a child domain sharing the same "parent").

>  - provides MDSS_GDSC

It's perfectly fine that dispcc acts as a genpd provider. In this
case, the corresponding PM domain should be assigned as a child for
the parent MMCX domain. That should make this work, I think.

>  - provides clocks

That sounds reasonable as well.

>
> >
> > > +                       pm_genpd_add_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
> > >         }
> > >
> > >         return of_genpd_add_provider_onecell(dev->of_node, data);
> > > @@ -457,6 +460,8 @@ void gdsc_unregister(struct gdsc_desc *desc)
> > >                         continue;
> > >                 if (scs[i]->parent)
> > >                         pm_genpd_remove_subdomain(scs[i]->parent, &scs[i]->pd);
> > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))
> >
> > Ditto.
> >
> > > +                       pm_genpd_remove_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
> > >         }
> > >         of_genpd_del_provider(dev->of_node);
> > >  }
> > > --
> > > 2.30.2
> > >
> >

Kind regards
Uffe
Dmitry Baryshkov July 9, 2021, 12:59 p.m. UTC | #4
On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>

> On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov

> <dmitry.baryshkov@linaro.org> wrote:

> >

> > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > >

> > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov

> > > <dmitry.baryshkov@linaro.org> wrote:

> > > >

> > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power

> > > > domain. Currently we used a regulator to enable this domain on demand,

> > > > however this has some consequences, as genpd code is not reentrant.

> > > >

> > > > Teach Qualcomm clock controller code about setting up power domains and

> > > > using them for gdsc control.

> > > >

> > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> > >

> > > [...]

> > >

> > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c

> > > > index 51ed640e527b..9401d01533c8 100644

> > > > --- a/drivers/clk/qcom/gdsc.c

> > > > +++ b/drivers/clk/qcom/gdsc.c

> > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,

> > > >                         continue;

> > > >                 scs[i]->regmap = regmap;

> > > >                 scs[i]->rcdev = rcdev;

> > > > +               scs[i]->pd.dev.parent = desc->dev;

> > > >                 ret = gdsc_init(scs[i]);

> > > >                 if (ret)

> > > >                         return ret;

> > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,

> > > >                         continue;

> > > >                 if (scs[i]->parent)

> > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);

> > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

> > >

> > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being

> > > called for gdsc platform device from the platform bus', to try to

> > > attach the device to its corresponding PM domain.

> > >

> > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we

> > > shouldn't really try to attach a device to its PM domain, when its OF

> > > node (dev->of_node) contains a "#power-domain-cells" specifier. This

> > > is because it indicates that the device belongs to a genpd provider

> > > itself. In this case, a "power-domains" specifier tells that it has a

> > > parent domain.

> > >

> > > I will post a patch that fixes this asap.

> >

> > I think there is nothing to fix here. The dispcc/videocc drivers

> > provide clocks in addition to the gdsc power domain. And provided

> > clocks would definitely benefit from having the dispcc device being

> > attached to the power domain which governs clock registers (MMCX in

> > our case). Thus I think it is perfectly valid to have:

> >

> > rpmhpd device:

> >  - provides MMCX domain.

> >

> > dispcc device:

> >  - is attached to the MMCX domain,

>

> We don't need this, it's redundant and weird to me.

>

> Also I am kind of worried that you will hit another new path in genpd,

> causing locking issues etc, as it has not been designed to work like

> this (a provider device and a child domain sharing the same "parent").


So, which domain should the dispcc device belong to? It's registers
are powered by the MMCX domain. I can not attach it to the child
(GDSC) domain either: in the case of videocc there are 4 child
domains.
An alternative would be to request that all users of the provided
clocks power on one of the child domains. However this is also not
perfect. If some generic code (e.g. clock framework) calls into
provided clocks (e.g. because of assigned-clock-rates), this can
happen w/o proper power domain being powered up yet.

>

> >  - provides MDSS_GDSC

>

> It's perfectly fine that dispcc acts as a genpd provider. In this

> case, the corresponding PM domain should be assigned as a child for

> the parent MMCX domain. That should make this work, I think.

>

> >  - provides clocks

>

> That sounds reasonable as well.

>

> >

> > >

> > > > +                       pm_genpd_add_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);

> > > >         }

> > > >

> > > >         return of_genpd_add_provider_onecell(dev->of_node, data);

> > > > @@ -457,6 +460,8 @@ void gdsc_unregister(struct gdsc_desc *desc)

> > > >                         continue;

> > > >                 if (scs[i]->parent)

> > > >                         pm_genpd_remove_subdomain(scs[i]->parent, &scs[i]->pd);

> > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

> > >

> > > Ditto.

> > >

> > > > +                       pm_genpd_remove_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);

> > > >         }

> > > >         of_genpd_del_provider(dev->of_node);

> > > >  }

> > > > --

> > > > 2.30.2

> > > >

> > >

>

> Kind regards

> Uffe




-- 
With best wishes
Dmitry
Ulf Hansson July 9, 2021, 1:14 p.m. UTC | #5
On Fri, 9 Jul 2021 at 14:59, Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>

> On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> >

> > On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov

> > <dmitry.baryshkov@linaro.org> wrote:

> > >

> > > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > >

> > > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov

> > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > >

> > > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power

> > > > > domain. Currently we used a regulator to enable this domain on demand,

> > > > > however this has some consequences, as genpd code is not reentrant.

> > > > >

> > > > > Teach Qualcomm clock controller code about setting up power domains and

> > > > > using them for gdsc control.

> > > > >

> > > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> > > >

> > > > [...]

> > > >

> > > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c

> > > > > index 51ed640e527b..9401d01533c8 100644

> > > > > --- a/drivers/clk/qcom/gdsc.c

> > > > > +++ b/drivers/clk/qcom/gdsc.c

> > > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > >                         continue;

> > > > >                 scs[i]->regmap = regmap;

> > > > >                 scs[i]->rcdev = rcdev;

> > > > > +               scs[i]->pd.dev.parent = desc->dev;

> > > > >                 ret = gdsc_init(scs[i]);

> > > > >                 if (ret)

> > > > >                         return ret;

> > > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > >                         continue;

> > > > >                 if (scs[i]->parent)

> > > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);

> > > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

> > > >

> > > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being

> > > > called for gdsc platform device from the platform bus', to try to

> > > > attach the device to its corresponding PM domain.

> > > >

> > > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we

> > > > shouldn't really try to attach a device to its PM domain, when its OF

> > > > node (dev->of_node) contains a "#power-domain-cells" specifier. This

> > > > is because it indicates that the device belongs to a genpd provider

> > > > itself. In this case, a "power-domains" specifier tells that it has a

> > > > parent domain.

> > > >

> > > > I will post a patch that fixes this asap.

> > >

> > > I think there is nothing to fix here. The dispcc/videocc drivers

> > > provide clocks in addition to the gdsc power domain. And provided

> > > clocks would definitely benefit from having the dispcc device being

> > > attached to the power domain which governs clock registers (MMCX in

> > > our case). Thus I think it is perfectly valid to have:

> > >

> > > rpmhpd device:

> > >  - provides MMCX domain.

> > >

> > > dispcc device:

> > >  - is attached to the MMCX domain,

> >

> > We don't need this, it's redundant and weird to me.

> >

> > Also I am kind of worried that you will hit another new path in genpd,

> > causing locking issues etc, as it has not been designed to work like

> > this (a provider device and a child domain sharing the same "parent").

>

> So, which domain should the dispcc device belong to? It's registers

> are powered by the MMCX domain. I can not attach it to the child

> (GDSC) domain either: in the case of videocc there are 4 child

> domains.


The dispcc device should *not* be attached to a PM domain.

Instead it should be registered as a genpd provider and the
corresponding PM domains it provides, should be assigned as child
domains to the MMCX domain.

This is exactly what the child/parent domain support in genpd is there
to help with.

> An alternative would be to request that all users of the provided

> clocks power on one of the child domains. However this is also not

> perfect. If some generic code (e.g. clock framework) calls into

> provided clocks (e.g. because of assigned-clock-rates), this can

> happen w/o proper power domain being powered up yet.


Issues with power on/off synchronization during genpd initializations
and genpd provider registration, certainly need to be fixed and I am
happy to help. However, my point is that I think it's a bad idea to
fix it through modelling the PM domain hierarchy in an incorrect way.

[...]

Kind regards
Uffe
Dmitry Baryshkov July 9, 2021, 1:22 p.m. UTC | #6
On Fri, 9 Jul 2021 at 16:14, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>

> On Fri, 9 Jul 2021 at 14:59, Dmitry Baryshkov

> <dmitry.baryshkov@linaro.org> wrote:

> >

> > On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > >

> > > On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov

> > > <dmitry.baryshkov@linaro.org> wrote:

> > > >

> > > > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > > >

> > > > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov

> > > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > > >

> > > > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power

> > > > > > domain. Currently we used a regulator to enable this domain on demand,

> > > > > > however this has some consequences, as genpd code is not reentrant.

> > > > > >

> > > > > > Teach Qualcomm clock controller code about setting up power domains and

> > > > > > using them for gdsc control.

> > > > > >

> > > > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> > > > >

> > > > > [...]

> > > > >

> > > > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c

> > > > > > index 51ed640e527b..9401d01533c8 100644

> > > > > > --- a/drivers/clk/qcom/gdsc.c

> > > > > > +++ b/drivers/clk/qcom/gdsc.c

> > > > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > >                         continue;

> > > > > >                 scs[i]->regmap = regmap;

> > > > > >                 scs[i]->rcdev = rcdev;

> > > > > > +               scs[i]->pd.dev.parent = desc->dev;

> > > > > >                 ret = gdsc_init(scs[i]);

> > > > > >                 if (ret)

> > > > > >                         return ret;

> > > > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > >                         continue;

> > > > > >                 if (scs[i]->parent)

> > > > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);

> > > > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

> > > > >

> > > > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being

> > > > > called for gdsc platform device from the platform bus', to try to

> > > > > attach the device to its corresponding PM domain.

> > > > >

> > > > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we

> > > > > shouldn't really try to attach a device to its PM domain, when its OF

> > > > > node (dev->of_node) contains a "#power-domain-cells" specifier. This

> > > > > is because it indicates that the device belongs to a genpd provider

> > > > > itself. In this case, a "power-domains" specifier tells that it has a

> > > > > parent domain.

> > > > >

> > > > > I will post a patch that fixes this asap.

> > > >

> > > > I think there is nothing to fix here. The dispcc/videocc drivers

> > > > provide clocks in addition to the gdsc power domain. And provided

> > > > clocks would definitely benefit from having the dispcc device being

> > > > attached to the power domain which governs clock registers (MMCX in

> > > > our case). Thus I think it is perfectly valid to have:

> > > >

> > > > rpmhpd device:

> > > >  - provides MMCX domain.

> > > >

> > > > dispcc device:

> > > >  - is attached to the MMCX domain,

> > >

> > > We don't need this, it's redundant and weird to me.

> > >

> > > Also I am kind of worried that you will hit another new path in genpd,

> > > causing locking issues etc, as it has not been designed to work like

> > > this (a provider device and a child domain sharing the same "parent").

> >

> > So, which domain should the dispcc device belong to? It's registers

> > are powered by the MMCX domain. I can not attach it to the child

> > (GDSC) domain either: in the case of videocc there are 4 child

> > domains.

>

> The dispcc device should *not* be attached to a PM domain.

>

> Instead it should be registered as a genpd provider and the

> corresponding PM domains it provides, should be assigned as child

> domains to the MMCX domain.

>

> This is exactly what the child/parent domain support in genpd is there

> to help with.


This is done in this patchset. If we stop attaching dispcc to the MMCX
genpd, I'll have to locate it in a different way, but the idea is
implemented here.

> > An alternative would be to request that all users of the provided

> > clocks power on one of the child domains. However this is also not

> > perfect. If some generic code (e.g. clock framework) calls into

> > provided clocks (e.g. because of assigned-clock-rates), this can

> > happen w/o proper power domain being powered up yet.

>

> Issues with power on/off synchronization during genpd initializations

> and genpd provider registration, certainly need to be fixed and I am

> happy to help. However, my point is that I think it's a bad idea to

> fix it through modelling the PM domain hierarchy in an incorrect way.


So, which device should I pass to clk_register to handle runtime PM
for the provided clocks? dispcc, should I not?
Then if the dispcc is not attached, we will have to manually handle
MMCX from dispcc's runtime pm callbacks. Correct?

Could you please be more specific, why is it so wrong to attach dispcc
to the MMCX genpd?


-- 
With best wishes
Dmitry
Bjorn Andersson July 9, 2021, 2:04 p.m. UTC | #7
On Fri 09 Jul 08:14 CDT 2021, Ulf Hansson wrote:

> On Fri, 9 Jul 2021 at 14:59, Dmitry Baryshkov
> <dmitry.baryshkov@linaro.org> wrote:
> >
> > On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > >
> > > On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov
> > > <dmitry.baryshkov@linaro.org> wrote:
> > > >
> > > > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > >
> > > > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov
> > > > > <dmitry.baryshkov@linaro.org> wrote:
> > > > > >
> > > > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power
> > > > > > domain. Currently we used a regulator to enable this domain on demand,
> > > > > > however this has some consequences, as genpd code is not reentrant.
> > > > > >
> > > > > > Teach Qualcomm clock controller code about setting up power domains and
> > > > > > using them for gdsc control.
> > > > > >
> > > > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> > > > >
> > > > > [...]
> > > > >
> > > > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c
> > > > > > index 51ed640e527b..9401d01533c8 100644
> > > > > > --- a/drivers/clk/qcom/gdsc.c
> > > > > > +++ b/drivers/clk/qcom/gdsc.c
> > > > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,
> > > > > >                         continue;
> > > > > >                 scs[i]->regmap = regmap;
> > > > > >                 scs[i]->rcdev = rcdev;
> > > > > > +               scs[i]->pd.dev.parent = desc->dev;
> > > > > >                 ret = gdsc_init(scs[i]);
> > > > > >                 if (ret)
> > > > > >                         return ret;
> > > > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,
> > > > > >                         continue;
> > > > > >                 if (scs[i]->parent)
> > > > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);
> > > > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))
> > > > >
> > > > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being
> > > > > called for gdsc platform device from the platform bus', to try to
> > > > > attach the device to its corresponding PM domain.
> > > > >
> > > > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we
> > > > > shouldn't really try to attach a device to its PM domain, when its OF
> > > > > node (dev->of_node) contains a "#power-domain-cells" specifier. This
> > > > > is because it indicates that the device belongs to a genpd provider
> > > > > itself. In this case, a "power-domains" specifier tells that it has a
> > > > > parent domain.
> > > > >
> > > > > I will post a patch that fixes this asap.
> > > >
> > > > I think there is nothing to fix here. The dispcc/videocc drivers
> > > > provide clocks in addition to the gdsc power domain. And provided
> > > > clocks would definitely benefit from having the dispcc device being
> > > > attached to the power domain which governs clock registers (MMCX in
> > > > our case). Thus I think it is perfectly valid to have:
> > > >
> > > > rpmhpd device:
> > > >  - provides MMCX domain.
> > > >
> > > > dispcc device:
> > > >  - is attached to the MMCX domain,
> > >
> > > We don't need this, it's redundant and weird to me.
> > >
> > > Also I am kind of worried that you will hit another new path in genpd,
> > > causing locking issues etc, as it has not been designed to work like
> > > this (a provider device and a child domain sharing the same "parent").
> >
> > So, which domain should the dispcc device belong to? It's registers
> > are powered by the MMCX domain. I can not attach it to the child
> > (GDSC) domain either: in the case of videocc there are 4 child
> > domains.
> 
> The dispcc device should *not* be attached to a PM domain.
> 

dispcc is powered by the MMCX power domain, so it needs to be on if you
want to touch the registers.

I presume that for genpd this might not be a problem as long as all the
exposed power domains are parented by the genpd provider's parent, as
the core would turn the parent on before and turn off after performing
those operations. But without attaching to the domain we don't have
power to get through probe/registration.

Further more, dispcc is also a clock driver and there's certainly
operations where the genpd framework won't save us.

> Instead it should be registered as a genpd provider and the
> corresponding PM domains it provides, should be assigned as child
> domains to the MMCX domain.
> 

Right, this relationship is today missing and is what Dmitry needs to
add - so that the parent domains stays powered even when we're not
keeping the parent domain enabled to poke the dispcc.

> This is exactly what the child/parent domain support in genpd is there
> to help with.
> 
> > An alternative would be to request that all users of the provided
> > clocks power on one of the child domains. However this is also not
> > perfect. If some generic code (e.g. clock framework) calls into
> > provided clocks (e.g. because of assigned-clock-rates), this can
> > happen w/o proper power domain being powered up yet.
> 
> Issues with power on/off synchronization during genpd initializations
> and genpd provider registration, certainly need to be fixed and I am
> happy to help. However, my point is that I think it's a bad idea to
> fix it through modelling the PM domain hierarchy in an incorrect way.
> 

This was my initial feeling to the patch as well and I think it might be
better to push the pm_runtime_get/put operations into gdsc.c - in
particular if you're saying that the general case is not for the genpd
provider itself to be powered by the specified parent domain.

At least we could start by doing it manually in gdsc.c and possibly move
it into the framework if we're confident that it's a good idea.

Regards,
Bjorn
Ulf Hansson July 9, 2021, 2:11 p.m. UTC | #8
On Fri, 9 Jul 2021 at 15:22, Dmitry Baryshkov
<dmitry.baryshkov@linaro.org> wrote:
>

> On Fri, 9 Jul 2021 at 16:14, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> >

> > On Fri, 9 Jul 2021 at 14:59, Dmitry Baryshkov

> > <dmitry.baryshkov@linaro.org> wrote:

> > >

> > > On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > >

> > > > On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov

> > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > >

> > > > > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > > > >

> > > > > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov

> > > > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > > > >

> > > > > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power

> > > > > > > domain. Currently we used a regulator to enable this domain on demand,

> > > > > > > however this has some consequences, as genpd code is not reentrant.

> > > > > > >

> > > > > > > Teach Qualcomm clock controller code about setting up power domains and

> > > > > > > using them for gdsc control.

> > > > > > >

> > > > > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> > > > > >

> > > > > > [...]

> > > > > >

> > > > > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c

> > > > > > > index 51ed640e527b..9401d01533c8 100644

> > > > > > > --- a/drivers/clk/qcom/gdsc.c

> > > > > > > +++ b/drivers/clk/qcom/gdsc.c

> > > > > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > > >                         continue;

> > > > > > >                 scs[i]->regmap = regmap;

> > > > > > >                 scs[i]->rcdev = rcdev;

> > > > > > > +               scs[i]->pd.dev.parent = desc->dev;

> > > > > > >                 ret = gdsc_init(scs[i]);

> > > > > > >                 if (ret)

> > > > > > >                         return ret;

> > > > > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > > >                         continue;

> > > > > > >                 if (scs[i]->parent)

> > > > > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);

> > > > > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

> > > > > >

> > > > > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being

> > > > > > called for gdsc platform device from the platform bus', to try to

> > > > > > attach the device to its corresponding PM domain.

> > > > > >

> > > > > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we

> > > > > > shouldn't really try to attach a device to its PM domain, when its OF

> > > > > > node (dev->of_node) contains a "#power-domain-cells" specifier. This

> > > > > > is because it indicates that the device belongs to a genpd provider

> > > > > > itself. In this case, a "power-domains" specifier tells that it has a

> > > > > > parent domain.

> > > > > >

> > > > > > I will post a patch that fixes this asap.

> > > > >

> > > > > I think there is nothing to fix here. The dispcc/videocc drivers

> > > > > provide clocks in addition to the gdsc power domain. And provided

> > > > > clocks would definitely benefit from having the dispcc device being

> > > > > attached to the power domain which governs clock registers (MMCX in

> > > > > our case). Thus I think it is perfectly valid to have:

> > > > >

> > > > > rpmhpd device:

> > > > >  - provides MMCX domain.

> > > > >

> > > > > dispcc device:

> > > > >  - is attached to the MMCX domain,

> > > >

> > > > We don't need this, it's redundant and weird to me.

> > > >

> > > > Also I am kind of worried that you will hit another new path in genpd,

> > > > causing locking issues etc, as it has not been designed to work like

> > > > this (a provider device and a child domain sharing the same "parent").

> > >

> > > So, which domain should the dispcc device belong to? It's registers

> > > are powered by the MMCX domain. I can not attach it to the child

> > > (GDSC) domain either: in the case of videocc there are 4 child

> > > domains.

> >

> > The dispcc device should *not* be attached to a PM domain.

> >

> > Instead it should be registered as a genpd provider and the

> > corresponding PM domains it provides, should be assigned as child

> > domains to the MMCX domain.

> >

> > This is exactly what the child/parent domain support in genpd is there

> > to help with.

>

> This is done in this patchset. If we stop attaching dispcc to the MMCX

> genpd, I'll have to locate it in a different way, but the idea is

> implemented here.


Right. Perhaps it's not such a bad idea after all as it gives you two things:

1) The handle to the MMCX PM domain, which makes sure it has been
registered too before dispcc gets probed.
2) The possibility to control power for the MMCX PM domain via runtime
PM for the dispcc device. This seems useful for your use case.

>

> > > An alternative would be to request that all users of the provided

> > > clocks power on one of the child domains. However this is also not

> > > perfect. If some generic code (e.g. clock framework) calls into

> > > provided clocks (e.g. because of assigned-clock-rates), this can

> > > happen w/o proper power domain being powered up yet.

> >

> > Issues with power on/off synchronization during genpd initializations

> > and genpd provider registration, certainly need to be fixed and I am

> > happy to help. However, my point is that I think it's a bad idea to

> > fix it through modelling the PM domain hierarchy in an incorrect way.

>

> So, which device should I pass to clk_register to handle runtime PM

> for the provided clocks? dispcc, should I not?


Right, anything but dispcc seems wrong.

> Then if the dispcc is not attached, we will have to manually handle

> MMCX from dispcc's runtime pm callbacks. Correct?


Yep - and we don't want that either.

>

> Could you please be more specific, why is it so wrong to attach dispcc

> to the MMCX genpd?


In the end it seems like I just needed to make my brain feel a little
more comfortable with the ideas that you put forward.

It should work fine, I think! My apologies for all the noise.

KInd regards
Uffe
Ulf Hansson July 9, 2021, 2:13 p.m. UTC | #9
On Fri, 9 Jul 2021 at 16:04, Bjorn Andersson <bjorn.andersson@linaro.org> wrote:
>

> On Fri 09 Jul 08:14 CDT 2021, Ulf Hansson wrote:

>

> > On Fri, 9 Jul 2021 at 14:59, Dmitry Baryshkov

> > <dmitry.baryshkov@linaro.org> wrote:

> > >

> > > On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > >

> > > > On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov

> > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > >

> > > > > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > > > >

> > > > > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov

> > > > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > > > >

> > > > > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power

> > > > > > > domain. Currently we used a regulator to enable this domain on demand,

> > > > > > > however this has some consequences, as genpd code is not reentrant.

> > > > > > >

> > > > > > > Teach Qualcomm clock controller code about setting up power domains and

> > > > > > > using them for gdsc control.

> > > > > > >

> > > > > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> > > > > >

> > > > > > [...]

> > > > > >

> > > > > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c

> > > > > > > index 51ed640e527b..9401d01533c8 100644

> > > > > > > --- a/drivers/clk/qcom/gdsc.c

> > > > > > > +++ b/drivers/clk/qcom/gdsc.c

> > > > > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > > >                         continue;

> > > > > > >                 scs[i]->regmap = regmap;

> > > > > > >                 scs[i]->rcdev = rcdev;

> > > > > > > +               scs[i]->pd.dev.parent = desc->dev;

> > > > > > >                 ret = gdsc_init(scs[i]);

> > > > > > >                 if (ret)

> > > > > > >                         return ret;

> > > > > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > > >                         continue;

> > > > > > >                 if (scs[i]->parent)

> > > > > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);

> > > > > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

> > > > > >

> > > > > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being

> > > > > > called for gdsc platform device from the platform bus', to try to

> > > > > > attach the device to its corresponding PM domain.

> > > > > >

> > > > > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we

> > > > > > shouldn't really try to attach a device to its PM domain, when its OF

> > > > > > node (dev->of_node) contains a "#power-domain-cells" specifier. This

> > > > > > is because it indicates that the device belongs to a genpd provider

> > > > > > itself. In this case, a "power-domains" specifier tells that it has a

> > > > > > parent domain.

> > > > > >

> > > > > > I will post a patch that fixes this asap.

> > > > >

> > > > > I think there is nothing to fix here. The dispcc/videocc drivers

> > > > > provide clocks in addition to the gdsc power domain. And provided

> > > > > clocks would definitely benefit from having the dispcc device being

> > > > > attached to the power domain which governs clock registers (MMCX in

> > > > > our case). Thus I think it is perfectly valid to have:

> > > > >

> > > > > rpmhpd device:

> > > > >  - provides MMCX domain.

> > > > >

> > > > > dispcc device:

> > > > >  - is attached to the MMCX domain,

> > > >

> > > > We don't need this, it's redundant and weird to me.

> > > >

> > > > Also I am kind of worried that you will hit another new path in genpd,

> > > > causing locking issues etc, as it has not been designed to work like

> > > > this (a provider device and a child domain sharing the same "parent").

> > >

> > > So, which domain should the dispcc device belong to? It's registers

> > > are powered by the MMCX domain. I can not attach it to the child

> > > (GDSC) domain either: in the case of videocc there are 4 child

> > > domains.

> >

> > The dispcc device should *not* be attached to a PM domain.

> >

>

> dispcc is powered by the MMCX power domain, so it needs to be on if you

> want to touch the registers.

>

> I presume that for genpd this might not be a problem as long as all the

> exposed power domains are parented by the genpd provider's parent, as

> the core would turn the parent on before and turn off after performing

> those operations. But without attaching to the domain we don't have

> power to get through probe/registration.

>

> Further more, dispcc is also a clock driver and there's certainly

> operations where the genpd framework won't save us.

>

> > Instead it should be registered as a genpd provider and the

> > corresponding PM domains it provides, should be assigned as child

> > domains to the MMCX domain.

> >

>

> Right, this relationship is today missing and is what Dmitry needs to

> add - so that the parent domains stays powered even when we're not

> keeping the parent domain enabled to poke the dispcc.

>

> > This is exactly what the child/parent domain support in genpd is there

> > to help with.

> >

> > > An alternative would be to request that all users of the provided

> > > clocks power on one of the child domains. However this is also not

> > > perfect. If some generic code (e.g. clock framework) calls into

> > > provided clocks (e.g. because of assigned-clock-rates), this can

> > > happen w/o proper power domain being powered up yet.

> >

> > Issues with power on/off synchronization during genpd initializations

> > and genpd provider registration, certainly need to be fixed and I am

> > happy to help. However, my point is that I think it's a bad idea to

> > fix it through modelling the PM domain hierarchy in an incorrect way.

> >

>

> This was my initial feeling to the patch as well and I think it might be

> better to push the pm_runtime_get/put operations into gdsc.c - in

> particular if you're saying that the general case is not for the genpd

> provider itself to be powered by the specified parent domain.

>

> At least we could start by doing it manually in gdsc.c and possibly move

> it into the framework if we're confident that it's a good idea.


Yes, better to start making this Qcom specific, then we can take it from there.

Kind regards
Uffe
Dmitry Baryshkov July 9, 2021, 2:14 p.m. UTC | #10
On Fri, 9 Jul 2021 at 17:11, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>
> On Fri, 9 Jul 2021 at 15:22, Dmitry Baryshkov
> <dmitry.baryshkov@linaro.org> wrote:
> >
> > On Fri, 9 Jul 2021 at 16:14, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > >
> > > On Fri, 9 Jul 2021 at 14:59, Dmitry Baryshkov
> > > <dmitry.baryshkov@linaro.org> wrote:
> > > >
> > > > On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > >
> > > > > On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov
> > > > > <dmitry.baryshkov@linaro.org> wrote:
> > > > > >
> > > > > > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:
> > > > > > >
> > > > > > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov
> > > > > > > <dmitry.baryshkov@linaro.org> wrote:
> > > > > > > >
> > > > > > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power
> > > > > > > > domain. Currently we used a regulator to enable this domain on demand,
> > > > > > > > however this has some consequences, as genpd code is not reentrant.
> > > > > > > >
> > > > > > > > Teach Qualcomm clock controller code about setting up power domains and
> > > > > > > > using them for gdsc control.
> > > > > > > >
> > > > > > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> > > > > > >
> > > > > > > [...]
> > > > > > >
> > > > > > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c
> > > > > > > > index 51ed640e527b..9401d01533c8 100644
> > > > > > > > --- a/drivers/clk/qcom/gdsc.c
> > > > > > > > +++ b/drivers/clk/qcom/gdsc.c
> > > > > > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,
> > > > > > > >                         continue;
> > > > > > > >                 scs[i]->regmap = regmap;
> > > > > > > >                 scs[i]->rcdev = rcdev;
> > > > > > > > +               scs[i]->pd.dev.parent = desc->dev;
> > > > > > > >                 ret = gdsc_init(scs[i]);
> > > > > > > >                 if (ret)
> > > > > > > >                         return ret;
> > > > > > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,
> > > > > > > >                         continue;
> > > > > > > >                 if (scs[i]->parent)
> > > > > > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);
> > > > > > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))
> > > > > > >
> > > > > > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being
> > > > > > > called for gdsc platform device from the platform bus', to try to
> > > > > > > attach the device to its corresponding PM domain.
> > > > > > >
> > > > > > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we
> > > > > > > shouldn't really try to attach a device to its PM domain, when its OF
> > > > > > > node (dev->of_node) contains a "#power-domain-cells" specifier. This
> > > > > > > is because it indicates that the device belongs to a genpd provider
> > > > > > > itself. In this case, a "power-domains" specifier tells that it has a
> > > > > > > parent domain.
> > > > > > >
> > > > > > > I will post a patch that fixes this asap.
> > > > > >
> > > > > > I think there is nothing to fix here. The dispcc/videocc drivers
> > > > > > provide clocks in addition to the gdsc power domain. And provided
> > > > > > clocks would definitely benefit from having the dispcc device being
> > > > > > attached to the power domain which governs clock registers (MMCX in
> > > > > > our case). Thus I think it is perfectly valid to have:
> > > > > >
> > > > > > rpmhpd device:
> > > > > >  - provides MMCX domain.
> > > > > >
> > > > > > dispcc device:
> > > > > >  - is attached to the MMCX domain,
> > > > >
> > > > > We don't need this, it's redundant and weird to me.
> > > > >
> > > > > Also I am kind of worried that you will hit another new path in genpd,
> > > > > causing locking issues etc, as it has not been designed to work like
> > > > > this (a provider device and a child domain sharing the same "parent").
> > > >
> > > > So, which domain should the dispcc device belong to? It's registers
> > > > are powered by the MMCX domain. I can not attach it to the child
> > > > (GDSC) domain either: in the case of videocc there are 4 child
> > > > domains.
> > >
> > > The dispcc device should *not* be attached to a PM domain.
> > >
> > > Instead it should be registered as a genpd provider and the
> > > corresponding PM domains it provides, should be assigned as child
> > > domains to the MMCX domain.
> > >
> > > This is exactly what the child/parent domain support in genpd is there
> > > to help with.
> >
> > This is done in this patchset. If we stop attaching dispcc to the MMCX
> > genpd, I'll have to locate it in a different way, but the idea is
> > implemented here.
>
> Right. Perhaps it's not such a bad idea after all as it gives you two things:
>
> 1) The handle to the MMCX PM domain, which makes sure it has been
> registered too before dispcc gets probed.
> 2) The possibility to control power for the MMCX PM domain via runtime
> PM for the dispcc device. This seems useful for your use case.
>
> >
> > > > An alternative would be to request that all users of the provided
> > > > clocks power on one of the child domains. However this is also not
> > > > perfect. If some generic code (e.g. clock framework) calls into
> > > > provided clocks (e.g. because of assigned-clock-rates), this can
> > > > happen w/o proper power domain being powered up yet.
> > >
> > > Issues with power on/off synchronization during genpd initializations
> > > and genpd provider registration, certainly need to be fixed and I am
> > > happy to help. However, my point is that I think it's a bad idea to
> > > fix it through modelling the PM domain hierarchy in an incorrect way.
> >
> > So, which device should I pass to clk_register to handle runtime PM
> > for the provided clocks? dispcc, should I not?
>
> Right, anything but dispcc seems wrong.
>
> > Then if the dispcc is not attached, we will have to manually handle
> > MMCX from dispcc's runtime pm callbacks. Correct?
>
> Yep - and we don't want that either.
>
> >
> > Could you please be more specific, why is it so wrong to attach dispcc
> > to the MMCX genpd?
>
> In the end it seems like I just needed to make my brain feel a little
> more comfortable with the ideas that you put forward.
>
> It should work fine, I think! My apologies for all the noise.

No problem, it is always better to have a discussion (and a
conclusion) rather than not to have it.

Thank you for your comments!
Dmitry Baryshkov July 9, 2021, 2:15 p.m. UTC | #11
On Fri, 9 Jul 2021 at 17:13, Ulf Hansson <ulf.hansson@linaro.org> wrote:
>

> On Fri, 9 Jul 2021 at 16:04, Bjorn Andersson <bjorn.andersson@linaro.org> wrote:

> >

> > On Fri 09 Jul 08:14 CDT 2021, Ulf Hansson wrote:

> >

> > > On Fri, 9 Jul 2021 at 14:59, Dmitry Baryshkov

> > > <dmitry.baryshkov@linaro.org> wrote:

> > > >

> > > > On Fri, 9 Jul 2021 at 15:18, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > > >

> > > > > On Fri, 9 Jul 2021 at 13:46, Dmitry Baryshkov

> > > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > > >

> > > > > > On Fri, 9 Jul 2021 at 12:33, Ulf Hansson <ulf.hansson@linaro.org> wrote:

> > > > > > >

> > > > > > > On Fri, 9 Jul 2021 at 06:32, Dmitry Baryshkov

> > > > > > > <dmitry.baryshkov@linaro.org> wrote:

> > > > > > > >

> > > > > > > > On sm8250 dispcc and videocc registers are powered up by the MMCX power

> > > > > > > > domain. Currently we used a regulator to enable this domain on demand,

> > > > > > > > however this has some consequences, as genpd code is not reentrant.

> > > > > > > >

> > > > > > > > Teach Qualcomm clock controller code about setting up power domains and

> > > > > > > > using them for gdsc control.

> > > > > > > >

> > > > > > > > Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>

> > > > > > >

> > > > > > > [...]

> > > > > > >

> > > > > > > > diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c

> > > > > > > > index 51ed640e527b..9401d01533c8 100644

> > > > > > > > --- a/drivers/clk/qcom/gdsc.c

> > > > > > > > +++ b/drivers/clk/qcom/gdsc.c

> > > > > > > > @@ -427,6 +427,7 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > > > >                         continue;

> > > > > > > >                 scs[i]->regmap = regmap;

> > > > > > > >                 scs[i]->rcdev = rcdev;

> > > > > > > > +               scs[i]->pd.dev.parent = desc->dev;

> > > > > > > >                 ret = gdsc_init(scs[i]);

> > > > > > > >                 if (ret)

> > > > > > > >                         return ret;

> > > > > > > > @@ -439,6 +440,8 @@ int gdsc_register(struct gdsc_desc *desc,

> > > > > > > >                         continue;

> > > > > > > >                 if (scs[i]->parent)

> > > > > > > >                         pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);

> > > > > > > > +               else if (!IS_ERR_OR_NULL(dev->pm_domain))

> > > > > > >

> > > > > > > So dev_pm_domain_attach() (which calls genpd_dev_pm_attach() is being

> > > > > > > called for gdsc platform device from the platform bus', to try to

> > > > > > > attach the device to its corresponding PM domain.

> > > > > > >

> > > > > > > Looking a bit closer to genpd_dev_pm_attach(), I realize that we

> > > > > > > shouldn't really try to attach a device to its PM domain, when its OF

> > > > > > > node (dev->of_node) contains a "#power-domain-cells" specifier. This

> > > > > > > is because it indicates that the device belongs to a genpd provider

> > > > > > > itself. In this case, a "power-domains" specifier tells that it has a

> > > > > > > parent domain.

> > > > > > >

> > > > > > > I will post a patch that fixes this asap.

> > > > > >

> > > > > > I think there is nothing to fix here. The dispcc/videocc drivers

> > > > > > provide clocks in addition to the gdsc power domain. And provided

> > > > > > clocks would definitely benefit from having the dispcc device being

> > > > > > attached to the power domain which governs clock registers (MMCX in

> > > > > > our case). Thus I think it is perfectly valid to have:

> > > > > >

> > > > > > rpmhpd device:

> > > > > >  - provides MMCX domain.

> > > > > >

> > > > > > dispcc device:

> > > > > >  - is attached to the MMCX domain,

> > > > >

> > > > > We don't need this, it's redundant and weird to me.

> > > > >

> > > > > Also I am kind of worried that you will hit another new path in genpd,

> > > > > causing locking issues etc, as it has not been designed to work like

> > > > > this (a provider device and a child domain sharing the same "parent").

> > > >

> > > > So, which domain should the dispcc device belong to? It's registers

> > > > are powered by the MMCX domain. I can not attach it to the child

> > > > (GDSC) domain either: in the case of videocc there are 4 child

> > > > domains.

> > >

> > > The dispcc device should *not* be attached to a PM domain.

> > >

> >

> > dispcc is powered by the MMCX power domain, so it needs to be on if you

> > want to touch the registers.

> >

> > I presume that for genpd this might not be a problem as long as all the

> > exposed power domains are parented by the genpd provider's parent, as

> > the core would turn the parent on before and turn off after performing

> > those operations. But without attaching to the domain we don't have

> > power to get through probe/registration.

> >

> > Further more, dispcc is also a clock driver and there's certainly

> > operations where the genpd framework won't save us.

> >

> > > Instead it should be registered as a genpd provider and the

> > > corresponding PM domains it provides, should be assigned as child

> > > domains to the MMCX domain.

> > >

> >

> > Right, this relationship is today missing and is what Dmitry needs to

> > add - so that the parent domains stays powered even when we're not

> > keeping the parent domain enabled to poke the dispcc.

> >

> > > This is exactly what the child/parent domain support in genpd is there

> > > to help with.

> > >

> > > > An alternative would be to request that all users of the provided

> > > > clocks power on one of the child domains. However this is also not

> > > > perfect. If some generic code (e.g. clock framework) calls into

> > > > provided clocks (e.g. because of assigned-clock-rates), this can

> > > > happen w/o proper power domain being powered up yet.

> > >

> > > Issues with power on/off synchronization during genpd initializations

> > > and genpd provider registration, certainly need to be fixed and I am

> > > happy to help. However, my point is that I think it's a bad idea to

> > > fix it through modelling the PM domain hierarchy in an incorrect way.

> > >

> >

> > This was my initial feeling to the patch as well and I think it might be

> > better to push the pm_runtime_get/put operations into gdsc.c - in

> > particular if you're saying that the general case is not for the genpd

> > provider itself to be powered by the specified parent domain.

> >

> > At least we could start by doing it manually in gdsc.c and possibly move

> > it into the framework if we're confident that it's a good idea.

>

> Yes, better to start making this Qcom specific, then we can take it from there.


I will re-add pm_runtime calls to gdsc.c and send a v3.

-- 
With best wishes
Dmitry
diff mbox series

Patch

diff --git a/drivers/clk/qcom/common.c b/drivers/clk/qcom/common.c
index 60d2a78d1395..43d8f8feeb3c 100644
--- a/drivers/clk/qcom/common.c
+++ b/drivers/clk/qcom/common.c
@@ -10,6 +10,7 @@ 
 #include <linux/clk-provider.h>
 #include <linux/reset-controller.h>
 #include <linux/of.h>
+#include <linux/pm_runtime.h>
 
 #include "common.h"
 #include "clk-rcg.h"
@@ -224,6 +225,11 @@  static struct clk_hw *qcom_cc_clk_hw_get(struct of_phandle_args *clkspec,
 	return cc->rclks[idx] ? &cc->rclks[idx]->hw : NULL;
 }
 
+static void qcom_cc_pm_runtime_disable(void *data)
+{
+	pm_runtime_disable(data);
+}
+
 int qcom_cc_really_probe(struct platform_device *pdev,
 			 const struct qcom_cc_desc *desc, struct regmap *regmap)
 {
@@ -241,6 +247,18 @@  int qcom_cc_really_probe(struct platform_device *pdev,
 	if (!cc)
 		return -ENOMEM;
 
+	pm_runtime_enable(dev);
+	ret = pm_runtime_get_sync(dev);
+	if (ret < 0) {
+		pm_runtime_put(dev);
+		pm_runtime_disable(dev);
+		return ret;
+	}
+
+	ret = devm_add_action_or_reset(dev, qcom_cc_pm_runtime_disable, dev);
+	if (ret)
+		goto err;
+
 	reset = &cc->reset;
 	reset->rcdev.of_node = dev->of_node;
 	reset->rcdev.ops = &qcom_reset_ops;
@@ -251,7 +269,7 @@  int qcom_cc_really_probe(struct platform_device *pdev,
 
 	ret = devm_reset_controller_register(dev, &reset->rcdev);
 	if (ret)
-		return ret;
+		goto err;
 
 	if (desc->gdscs && desc->num_gdscs) {
 		scd = devm_kzalloc(dev, sizeof(*scd), GFP_KERNEL);
@@ -262,11 +280,11 @@  int qcom_cc_really_probe(struct platform_device *pdev,
 		scd->num = desc->num_gdscs;
 		ret = gdsc_register(scd, &reset->rcdev, regmap);
 		if (ret)
-			return ret;
+			goto err;
 		ret = devm_add_action_or_reset(dev, qcom_cc_gdsc_unregister,
 					       scd);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	cc->rclks = rclks;
@@ -277,7 +295,7 @@  int qcom_cc_really_probe(struct platform_device *pdev,
 	for (i = 0; i < num_clk_hws; i++) {
 		ret = devm_clk_hw_register(dev, clk_hws[i]);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	for (i = 0; i < num_clks; i++) {
@@ -286,14 +304,21 @@  int qcom_cc_really_probe(struct platform_device *pdev,
 
 		ret = devm_clk_register_regmap(dev, rclks[i]);
 		if (ret)
-			return ret;
+			goto err;
 	}
 
 	ret = devm_of_clk_add_hw_provider(dev, qcom_cc_clk_hw_get, cc);
 	if (ret)
-		return ret;
+		goto err;
+
+	pm_runtime_put(dev);
 
 	return 0;
+
+err:
+	pm_runtime_put(dev);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(qcom_cc_really_probe);
 
diff --git a/drivers/clk/qcom/gdsc.c b/drivers/clk/qcom/gdsc.c
index 51ed640e527b..9401d01533c8 100644
--- a/drivers/clk/qcom/gdsc.c
+++ b/drivers/clk/qcom/gdsc.c
@@ -427,6 +427,7 @@  int gdsc_register(struct gdsc_desc *desc,
 			continue;
 		scs[i]->regmap = regmap;
 		scs[i]->rcdev = rcdev;
+		scs[i]->pd.dev.parent = desc->dev;
 		ret = gdsc_init(scs[i]);
 		if (ret)
 			return ret;
@@ -439,6 +440,8 @@  int gdsc_register(struct gdsc_desc *desc,
 			continue;
 		if (scs[i]->parent)
 			pm_genpd_add_subdomain(scs[i]->parent, &scs[i]->pd);
+		else if (!IS_ERR_OR_NULL(dev->pm_domain))
+			pm_genpd_add_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
 	}
 
 	return of_genpd_add_provider_onecell(dev->of_node, data);
@@ -457,6 +460,8 @@  void gdsc_unregister(struct gdsc_desc *desc)
 			continue;
 		if (scs[i]->parent)
 			pm_genpd_remove_subdomain(scs[i]->parent, &scs[i]->pd);
+		else if (!IS_ERR_OR_NULL(dev->pm_domain))
+			pm_genpd_remove_subdomain(pd_to_genpd(dev->pm_domain), &scs[i]->pd);
 	}
 	of_genpd_del_provider(dev->of_node);
 }