diff mbox series

[v14,03/11] soc: mediatek: Add basic_clk_name to scp_power_data

Message ID 1588752963-19934-4-git-send-email-weiyi.lu@mediatek.com (mailing list archive)
State New, archived
Headers show
Series Mediatek MT8183 scpsys support | expand

Commit Message

Weiyi Lu May 6, 2020, 8:15 a.m. UTC
Try to stop extending the clk_id or clk_names if there are
more and more new BASIC clocks. To get its own clocks by the
basic_clk_name of each power domain.
And then use basic_clk_name strings for all compatibles, instead of
mixing clk_id and clk_name.

Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
---
 drivers/soc/mediatek/mtk-scpsys.c | 134 ++++++++++++--------------------------
 1 file changed, 41 insertions(+), 93 deletions(-)

Comments

Enric Balletbo i Serra May 6, 2020, 9:01 p.m. UTC | #1
Hi Weiyi,

Thank you for your patch.

On 6/5/20 10:15, Weiyi Lu wrote:
> Try to stop extending the clk_id or clk_names if there are
> more and more new BASIC clocks. To get its own clocks by the
> basic_clk_name of each power domain.
> And then use basic_clk_name strings for all compatibles, instead of
> mixing clk_id and clk_name.
> 
> Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com>
> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
> ---
>  drivers/soc/mediatek/mtk-scpsys.c | 134 ++++++++++++--------------------------
>  1 file changed, 41 insertions(+), 93 deletions(-)
> 
> diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
> index f669d37..c9c3cf7 100644
> --- a/drivers/soc/mediatek/mtk-scpsys.c
> +++ b/drivers/soc/mediatek/mtk-scpsys.c
> @@ -78,34 +78,6 @@
>  #define PWR_STATUS_HIF1			BIT(26)	/* MT7622 */
>  #define PWR_STATUS_WB			BIT(27)	/* MT7622 */
>  
> -enum clk_id {
> -	CLK_NONE,
> -	CLK_MM,
> -	CLK_MFG,
> -	CLK_VENC,
> -	CLK_VENC_LT,
> -	CLK_ETHIF,
> -	CLK_VDEC,
> -	CLK_HIFSEL,
> -	CLK_JPGDEC,
> -	CLK_AUDIO,
> -	CLK_MAX,
> -};
> -
> -static const char * const clk_names[] = {
> -	NULL,
> -	"mm",
> -	"mfg",
> -	"venc",
> -	"venc_lt",
> -	"ethif",
> -	"vdec",
> -	"hif_sel",
> -	"jpgdec",
> -	"audio",
> -	NULL,
> -};
> -
>  #define MAX_CLKS	3
>  
>  /**
> @@ -116,7 +88,7 @@ enum clk_id {
>   * @sram_pdn_bits: The mask for sram power control bits.
>   * @sram_pdn_ack_bits: The mask for sram power control acked bits.
>   * @bus_prot_mask: The mask for single step bus protection.
> - * @clk_id: The basic clocks required by this power domain.
> + * @basic_clk_name: The basic clocks required by this power domain.
>   * @caps: The flag for active wake-up action.
>   */
>  struct scp_domain_data {
> @@ -126,7 +98,7 @@ struct scp_domain_data {
>  	u32 sram_pdn_bits;
>  	u32 sram_pdn_ack_bits;
>  	u32 bus_prot_mask;
> -	enum clk_id clk_id[MAX_CLKS];
> +	const char *basic_clk_name[MAX_CLKS];

I only reviewed v13, so sorry if this was already discussed. I am wondering if
would be better take advantage of the devm_clk_bulk_get() function instead of
kind of reimplementing the same, something like this

	const struct clk_bulk_data *basic_clocks;

>  	u8 caps;
>  };
>  
> @@ -411,12 +383,19 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
>  	return ret;
>  }
>  
> -static void init_clks(struct platform_device *pdev, struct clk **clk)
> +static int init_basic_clks(struct platform_device *pdev, struct clk **clk,
> +			const char * const *name)
>  {
>  	int i;
>  
> -	for (i = CLK_NONE + 1; i < CLK_MAX; i++)
> -		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
> +	for (i = 0; i < MAX_CLKS && name[i]; i++) {
> +		clk[i] = devm_clk_get(&pdev->dev, name[i]);
> +
> +		if (IS_ERR(clk[i]))
> +			return PTR_ERR(clk[i]);
> +	}

You will be able to remove this function, see below ...

> +
> +	return 0;
>  }
>  
>  static struct scp *init_scp(struct platform_device *pdev,
> @@ -426,9 +405,8 @@ static struct scp *init_scp(struct platform_device *pdev,
>  {
>  	struct genpd_onecell_data *pd_data;
>  	struct resource *res;
> -	int i, j;
> +	int i, ret;
>  	struct scp *scp;
> -	struct clk *clk[CLK_MAX];
>  
>  	scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL);
>  	if (!scp)
> @@ -481,8 +459,6 @@ static struct scp *init_scp(struct platform_device *pdev,
>  
>  	pd_data->num_domains = num;
>  
> -	init_clks(pdev, clk);
> -
>  	for (i = 0; i < num; i++) {
>  		struct scp_domain *scpd = &scp->domains[i];
>  		struct generic_pm_domain *genpd = &scpd->genpd;
> @@ -493,17 +469,9 @@ static struct scp *init_scp(struct platform_device *pdev,
>  
>  		scpd->data = data;
>  
> -		for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) {
> -			struct clk *c = clk[data->clk_id[j]];
> -
> -			if (IS_ERR(c)) {
> -				dev_err(&pdev->dev, "%s: clk unavailable\n",
> -					data->name);
> -				return ERR_CAST(c);
> -			}
> -
> -			scpd->clk[j] = c;
> -		}
> +		ret = init_basic_clks(pdev, scpd->clk, data->basic_clk_name);
> +		if (ret)
> +			return ERR_PTR(ret);

Just call:

	ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(basic_clocks),
				data->basic_clocks);
	if (ret)
		return ERR_PTR(ret);

>  
>  		genpd->name = data->name;
>  		genpd->power_off = scpsys_power_off;
> @@ -560,7 +528,6 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>  		.ctl_offs = SPM_CONN_PWR_CON,
>  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M |
>  				 MT2701_TOP_AXI_PROT_EN_CONN_S,
> -		.clk_id = {CLK_NONE},
>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
>  	},
>  	[MT2701_POWER_DOMAIN_DISP] = {
> @@ -568,7 +535,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>  		.sta_mask = PWR_STATUS_DISP,
>  		.ctl_offs = SPM_DIS_PWR_CON,
>  		.sram_pdn_bits = GENMASK(11, 8),
> -		.clk_id = {CLK_MM},
> +		.basic_clk_name = {"mm"},

		.basic_clocks[] = {
			{ .id = "mm" },
		};

>  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_MM_M0,
>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
>  	},
> @@ -578,7 +545,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>  		.ctl_offs = SPM_MFG_PWR_CON,
>  		.sram_pdn_bits = GENMASK(11, 8),
>  		.sram_pdn_ack_bits = GENMASK(12, 12),
> -		.clk_id = {CLK_MFG},
> +		.basic_clk_name = {"mfg"},

		.basic_clocks[] = {
			{ .id = "mfg" },
		};

>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
>  	},
>  	[MT2701_POWER_DOMAIN_VDEC] = {
> @@ -587,7 +554,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>  		.ctl_offs = SPM_VDE_PWR_CON,
>  		.sram_pdn_bits = GENMASK(11, 8),
>  		.sram_pdn_ack_bits = GENMASK(12, 12),
> -		.clk_id = {CLK_MM},
> +		.basic_clk_name = {"mm"},

...

[snip]
Weiyi Lu May 11, 2020, 6:02 a.m. UTC | #2
On Wed, 2020-05-06 at 23:01 +0200, Enric Balletbo i Serra wrote:
> Hi Weiyi,
> 
> Thank you for your patch.
> 
> On 6/5/20 10:15, Weiyi Lu wrote:
> > Try to stop extending the clk_id or clk_names if there are
> > more and more new BASIC clocks. To get its own clocks by the
> > basic_clk_name of each power domain.
> > And then use basic_clk_name strings for all compatibles, instead of
> > mixing clk_id and clk_name.
> > 
> > Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com>
> > Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
> > ---
> >  drivers/soc/mediatek/mtk-scpsys.c | 134 ++++++++++++--------------------------
> >  1 file changed, 41 insertions(+), 93 deletions(-)
> > 
> > diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
> > index f669d37..c9c3cf7 100644
> > --- a/drivers/soc/mediatek/mtk-scpsys.c
> > +++ b/drivers/soc/mediatek/mtk-scpsys.c
> > @@ -78,34 +78,6 @@
> >  #define PWR_STATUS_HIF1			BIT(26)	/* MT7622 */
> >  #define PWR_STATUS_WB			BIT(27)	/* MT7622 */
> >  
> > -enum clk_id {
> > -	CLK_NONE,
> > -	CLK_MM,
> > -	CLK_MFG,
> > -	CLK_VENC,
> > -	CLK_VENC_LT,
> > -	CLK_ETHIF,
> > -	CLK_VDEC,
> > -	CLK_HIFSEL,
> > -	CLK_JPGDEC,
> > -	CLK_AUDIO,
> > -	CLK_MAX,
> > -};
> > -
> > -static const char * const clk_names[] = {
> > -	NULL,
> > -	"mm",
> > -	"mfg",
> > -	"venc",
> > -	"venc_lt",
> > -	"ethif",
> > -	"vdec",
> > -	"hif_sel",
> > -	"jpgdec",
> > -	"audio",
> > -	NULL,
> > -};
> > -
> >  #define MAX_CLKS	3
> >  
> >  /**
> > @@ -116,7 +88,7 @@ enum clk_id {
> >   * @sram_pdn_bits: The mask for sram power control bits.
> >   * @sram_pdn_ack_bits: The mask for sram power control acked bits.
> >   * @bus_prot_mask: The mask for single step bus protection.
> > - * @clk_id: The basic clocks required by this power domain.
> > + * @basic_clk_name: The basic clocks required by this power domain.
> >   * @caps: The flag for active wake-up action.
> >   */
> >  struct scp_domain_data {
> > @@ -126,7 +98,7 @@ struct scp_domain_data {
> >  	u32 sram_pdn_bits;
> >  	u32 sram_pdn_ack_bits;
> >  	u32 bus_prot_mask;
> > -	enum clk_id clk_id[MAX_CLKS];
> > +	const char *basic_clk_name[MAX_CLKS];
> 
> I only reviewed v13, so sorry if this was already discussed. I am wondering if
> would be better take advantage of the devm_clk_bulk_get() function instead of
> kind of reimplementing the same, something like this
> 
> 	const struct clk_bulk_data *basic_clocks;
> 

I thought it should be const struct clk_bulk_data
basic_clocks[MAX_CLKS]; instead of const struct clk_bulk_data
*basic_clocks; in struct scp_domain_data data type

> >  	u8 caps;
> >  };
> >  
> > @@ -411,12 +383,19 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
> >  	return ret;
> >  }
> >  
> > -static void init_clks(struct platform_device *pdev, struct clk **clk)
> > +static int init_basic_clks(struct platform_device *pdev, struct clk **clk,
> > +			const char * const *name)
> >  {
> >  	int i;
> >  
> > -	for (i = CLK_NONE + 1; i < CLK_MAX; i++)
> > -		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
> > +	for (i = 0; i < MAX_CLKS && name[i]; i++) {
> > +		clk[i] = devm_clk_get(&pdev->dev, name[i]);
> > +
> > +		if (IS_ERR(clk[i]))
> > +			return PTR_ERR(clk[i]);
> > +	}
> 
> You will be able to remove this function, see below ...
> 
> > +
> > +	return 0;
> >  }
> >  
> >  static struct scp *init_scp(struct platform_device *pdev,
> > @@ -426,9 +405,8 @@ static struct scp *init_scp(struct platform_device *pdev,
> >  {
> >  	struct genpd_onecell_data *pd_data;
> >  	struct resource *res;
> > -	int i, j;
> > +	int i, ret;
> >  	struct scp *scp;
> > -	struct clk *clk[CLK_MAX];
> >  
> >  	scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL);
> >  	if (!scp)
> > @@ -481,8 +459,6 @@ static struct scp *init_scp(struct platform_device *pdev,
> >  
> >  	pd_data->num_domains = num;
> >  
> > -	init_clks(pdev, clk);
> > -
> >  	for (i = 0; i < num; i++) {
> >  		struct scp_domain *scpd = &scp->domains[i];
> >  		struct generic_pm_domain *genpd = &scpd->genpd;
> > @@ -493,17 +469,9 @@ static struct scp *init_scp(struct platform_device *pdev,
> >  
> >  		scpd->data = data;
> >  
> > -		for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) {
> > -			struct clk *c = clk[data->clk_id[j]];
> > -
> > -			if (IS_ERR(c)) {
> > -				dev_err(&pdev->dev, "%s: clk unavailable\n",
> > -					data->name);
> > -				return ERR_CAST(c);
> > -			}
> > -
> > -			scpd->clk[j] = c;
> > -		}
> > +		ret = init_basic_clks(pdev, scpd->clk, data->basic_clk_name);
> > +		if (ret)
> > +			return ERR_PTR(ret);
> 
> Just call:
> 
> 	ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(basic_clocks),
> 				data->basic_clocks);
> 	if (ret)
> 		return ERR_PTR(ret);
> 
> >  
> >  		genpd->name = data->name;
> >  		genpd->power_off = scpsys_power_off;
> > @@ -560,7 +528,6 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >  		.ctl_offs = SPM_CONN_PWR_CON,
> >  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M |
> >  				 MT2701_TOP_AXI_PROT_EN_CONN_S,
> > -		.clk_id = {CLK_NONE},
> >  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> >  	},
> >  	[MT2701_POWER_DOMAIN_DISP] = {
> > @@ -568,7 +535,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >  		.sta_mask = PWR_STATUS_DISP,
> >  		.ctl_offs = SPM_DIS_PWR_CON,
> >  		.sram_pdn_bits = GENMASK(11, 8),
> > -		.clk_id = {CLK_MM},
> > +		.basic_clk_name = {"mm"},
> 
> 		.basic_clocks[] = {
> 			{ .id = "mm" },
> 		};
> 

Those basic clocks without given a name (name: null) would get incorrect
clock via clk_bulk_get(...) due to 

/**
 * of_parse_clkspec() - Parse a DT clock specifier for a given device
node
 * @np: device node to parse clock specifier from
 * @index: index of phandle to parse clock out of. If index < 0, @name
is used
 * @name: clock name to find and parse. If name is NULL, the index is
used

And the index is 0 here in this callstack

I guess something need to be improved before we use the clk_bulk_ APIs.


> >  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_MM_M0,
> >  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> >  	},
> > @@ -578,7 +545,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >  		.ctl_offs = SPM_MFG_PWR_CON,
> >  		.sram_pdn_bits = GENMASK(11, 8),
> >  		.sram_pdn_ack_bits = GENMASK(12, 12),
> > -		.clk_id = {CLK_MFG},
> > +		.basic_clk_name = {"mfg"},
> 
> 		.basic_clocks[] = {
> 			{ .id = "mfg" },
> 		};
> 
> >  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> >  	},
> >  	[MT2701_POWER_DOMAIN_VDEC] = {
> > @@ -587,7 +554,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >  		.ctl_offs = SPM_VDE_PWR_CON,
> >  		.sram_pdn_bits = GENMASK(11, 8),
> >  		.sram_pdn_ack_bits = GENMASK(12, 12),
> > -		.clk_id = {CLK_MM},
> > +		.basic_clk_name = {"mm"},
> 
> ...
> 
> [snip]
Weiyi Lu May 15, 2020, 3:35 a.m. UTC | #3
On Mon, 2020-05-11 at 14:02 +0800, Weiyi Lu wrote:
> On Wed, 2020-05-06 at 23:01 +0200, Enric Balletbo i Serra wrote:
> > Hi Weiyi,
> > 
> > Thank you for your patch.
> > 
> > On 6/5/20 10:15, Weiyi Lu wrote:
> > > Try to stop extending the clk_id or clk_names if there are
> > > more and more new BASIC clocks. To get its own clocks by the
> > > basic_clk_name of each power domain.
> > > And then use basic_clk_name strings for all compatibles, instead of
> > > mixing clk_id and clk_name.
> > > 
> > > Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com>
> > > Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
> > > ---
> > >  drivers/soc/mediatek/mtk-scpsys.c | 134 ++++++++++++--------------------------
> > >  1 file changed, 41 insertions(+), 93 deletions(-)
> > > 
> > > diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
> > > index f669d37..c9c3cf7 100644
> > > --- a/drivers/soc/mediatek/mtk-scpsys.c
> > > +++ b/drivers/soc/mediatek/mtk-scpsys.c
> > > @@ -78,34 +78,6 @@
> > >  #define PWR_STATUS_HIF1			BIT(26)	/* MT7622 */
> > >  #define PWR_STATUS_WB			BIT(27)	/* MT7622 */
> > >  
> > > -enum clk_id {
> > > -	CLK_NONE,
> > > -	CLK_MM,
> > > -	CLK_MFG,
> > > -	CLK_VENC,
> > > -	CLK_VENC_LT,
> > > -	CLK_ETHIF,
> > > -	CLK_VDEC,
> > > -	CLK_HIFSEL,
> > > -	CLK_JPGDEC,
> > > -	CLK_AUDIO,
> > > -	CLK_MAX,
> > > -};
> > > -
> > > -static const char * const clk_names[] = {
> > > -	NULL,
> > > -	"mm",
> > > -	"mfg",
> > > -	"venc",
> > > -	"venc_lt",
> > > -	"ethif",
> > > -	"vdec",
> > > -	"hif_sel",
> > > -	"jpgdec",
> > > -	"audio",
> > > -	NULL,
> > > -};
> > > -
> > >  #define MAX_CLKS	3
> > >  
> > >  /**
> > > @@ -116,7 +88,7 @@ enum clk_id {
> > >   * @sram_pdn_bits: The mask for sram power control bits.
> > >   * @sram_pdn_ack_bits: The mask for sram power control acked bits.
> > >   * @bus_prot_mask: The mask for single step bus protection.
> > > - * @clk_id: The basic clocks required by this power domain.
> > > + * @basic_clk_name: The basic clocks required by this power domain.
> > >   * @caps: The flag for active wake-up action.
> > >   */
> > >  struct scp_domain_data {
> > > @@ -126,7 +98,7 @@ struct scp_domain_data {
> > >  	u32 sram_pdn_bits;
> > >  	u32 sram_pdn_ack_bits;
> > >  	u32 bus_prot_mask;
> > > -	enum clk_id clk_id[MAX_CLKS];
> > > +	const char *basic_clk_name[MAX_CLKS];
> > 
> > I only reviewed v13, so sorry if this was already discussed. I am wondering if
> > would be better take advantage of the devm_clk_bulk_get() function instead of
> > kind of reimplementing the same, something like this
> > 
> > 	const struct clk_bulk_data *basic_clocks;
> > 
> 
> I thought it should be const struct clk_bulk_data
> basic_clocks[MAX_CLKS]; instead of const struct clk_bulk_data
> *basic_clocks; in struct scp_domain_data data type
> 
> > >  	u8 caps;
> > >  };
> > >  
> > > @@ -411,12 +383,19 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
> > >  	return ret;
> > >  }
> > >  
> > > -static void init_clks(struct platform_device *pdev, struct clk **clk)
> > > +static int init_basic_clks(struct platform_device *pdev, struct clk **clk,
> > > +			const char * const *name)
> > >  {
> > >  	int i;
> > >  
> > > -	for (i = CLK_NONE + 1; i < CLK_MAX; i++)
> > > -		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
> > > +	for (i = 0; i < MAX_CLKS && name[i]; i++) {
> > > +		clk[i] = devm_clk_get(&pdev->dev, name[i]);
> > > +
> > > +		if (IS_ERR(clk[i]))
> > > +			return PTR_ERR(clk[i]);
> > > +	}
> > 
> > You will be able to remove this function, see below ...
> > 
> > > +
> > > +	return 0;
> > >  }
> > >  
> > >  static struct scp *init_scp(struct platform_device *pdev,
> > > @@ -426,9 +405,8 @@ static struct scp *init_scp(struct platform_device *pdev,
> > >  {
> > >  	struct genpd_onecell_data *pd_data;
> > >  	struct resource *res;
> > > -	int i, j;
> > > +	int i, ret;
> > >  	struct scp *scp;
> > > -	struct clk *clk[CLK_MAX];
> > >  
> > >  	scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL);
> > >  	if (!scp)
> > > @@ -481,8 +459,6 @@ static struct scp *init_scp(struct platform_device *pdev,
> > >  
> > >  	pd_data->num_domains = num;
> > >  
> > > -	init_clks(pdev, clk);
> > > -
> > >  	for (i = 0; i < num; i++) {
> > >  		struct scp_domain *scpd = &scp->domains[i];
> > >  		struct generic_pm_domain *genpd = &scpd->genpd;
> > > @@ -493,17 +469,9 @@ static struct scp *init_scp(struct platform_device *pdev,
> > >  
> > >  		scpd->data = data;
> > >  
> > > -		for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) {
> > > -			struct clk *c = clk[data->clk_id[j]];
> > > -
> > > -			if (IS_ERR(c)) {
> > > -				dev_err(&pdev->dev, "%s: clk unavailable\n",
> > > -					data->name);
> > > -				return ERR_CAST(c);
> > > -			}
> > > -
> > > -			scpd->clk[j] = c;
> > > -		}
> > > +		ret = init_basic_clks(pdev, scpd->clk, data->basic_clk_name);
> > > +		if (ret)
> > > +			return ERR_PTR(ret);
> > 
> > Just call:
> > 
> > 	ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(basic_clocks),
> > 				data->basic_clocks);
> > 	if (ret)
> > 		return ERR_PTR(ret);
> > 
> > >  
> > >  		genpd->name = data->name;
> > >  		genpd->power_off = scpsys_power_off;
> > > @@ -560,7 +528,6 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> > >  		.ctl_offs = SPM_CONN_PWR_CON,
> > >  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M |
> > >  				 MT2701_TOP_AXI_PROT_EN_CONN_S,
> > > -		.clk_id = {CLK_NONE},
> > >  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> > >  	},
> > >  	[MT2701_POWER_DOMAIN_DISP] = {
> > > @@ -568,7 +535,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> > >  		.sta_mask = PWR_STATUS_DISP,
> > >  		.ctl_offs = SPM_DIS_PWR_CON,
> > >  		.sram_pdn_bits = GENMASK(11, 8),
> > > -		.clk_id = {CLK_MM},
> > > +		.basic_clk_name = {"mm"},
> > 
> > 		.basic_clocks[] = {
> > 			{ .id = "mm" },
> > 		};
> > 
> 
> Those basic clocks without given a name (name: null) would get incorrect
> clock via clk_bulk_get(...) due to 
> 
> /**
>  * of_parse_clkspec() - Parse a DT clock specifier for a given device
> node
>  * @np: device node to parse clock specifier from
>  * @index: index of phandle to parse clock out of. If index < 0, @name
> is used
>  * @name: clock name to find and parse. If name is NULL, the index is
> used
> 
> And the index is 0 here in this callstack
> 
> I guess something need to be improved before we use the clk_bulk_ APIs.
> 

Hi Enric,

According to the result above, is it necessary to change the APIs or
maybe I should send the next version v15 first to fix other problems you
mentioned? Many thanks.

> 
> > >  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_MM_M0,
> > >  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> > >  	},
> > > @@ -578,7 +545,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> > >  		.ctl_offs = SPM_MFG_PWR_CON,
> > >  		.sram_pdn_bits = GENMASK(11, 8),
> > >  		.sram_pdn_ack_bits = GENMASK(12, 12),
> > > -		.clk_id = {CLK_MFG},
> > > +		.basic_clk_name = {"mfg"},
> > 
> > 		.basic_clocks[] = {
> > 			{ .id = "mfg" },
> > 		};
> > 
> > >  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> > >  	},
> > >  	[MT2701_POWER_DOMAIN_VDEC] = {
> > > @@ -587,7 +554,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> > >  		.ctl_offs = SPM_VDE_PWR_CON,
> > >  		.sram_pdn_bits = GENMASK(11, 8),
> > >  		.sram_pdn_ack_bits = GENMASK(12, 12),
> > > -		.clk_id = {CLK_MM},
> > > +		.basic_clk_name = {"mm"},
> > 
> > ...
> > 
> > [snip]
> 
>
Enric Balletbo i Serra May 18, 2020, 5:52 p.m. UTC | #4
Hi Weiyi,

On 15/5/20 5:35, Weiyi Lu wrote:
> On Mon, 2020-05-11 at 14:02 +0800, Weiyi Lu wrote:
>> On Wed, 2020-05-06 at 23:01 +0200, Enric Balletbo i Serra wrote:
>>> Hi Weiyi,
>>>
>>> Thank you for your patch.
>>>
>>> On 6/5/20 10:15, Weiyi Lu wrote:
>>>> Try to stop extending the clk_id or clk_names if there are
>>>> more and more new BASIC clocks. To get its own clocks by the
>>>> basic_clk_name of each power domain.
>>>> And then use basic_clk_name strings for all compatibles, instead of
>>>> mixing clk_id and clk_name.
>>>>
>>>> Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com>
>>>> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
>>>> ---
>>>>  drivers/soc/mediatek/mtk-scpsys.c | 134 ++++++++++++--------------------------
>>>>  1 file changed, 41 insertions(+), 93 deletions(-)
>>>>
>>>> diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
>>>> index f669d37..c9c3cf7 100644
>>>> --- a/drivers/soc/mediatek/mtk-scpsys.c
>>>> +++ b/drivers/soc/mediatek/mtk-scpsys.c
>>>> @@ -78,34 +78,6 @@
>>>>  #define PWR_STATUS_HIF1			BIT(26)	/* MT7622 */
>>>>  #define PWR_STATUS_WB			BIT(27)	/* MT7622 */
>>>>  
>>>> -enum clk_id {
>>>> -	CLK_NONE,
>>>> -	CLK_MM,
>>>> -	CLK_MFG,
>>>> -	CLK_VENC,
>>>> -	CLK_VENC_LT,
>>>> -	CLK_ETHIF,
>>>> -	CLK_VDEC,
>>>> -	CLK_HIFSEL,
>>>> -	CLK_JPGDEC,
>>>> -	CLK_AUDIO,
>>>> -	CLK_MAX,
>>>> -};
>>>> -
>>>> -static const char * const clk_names[] = {
>>>> -	NULL,
>>>> -	"mm",
>>>> -	"mfg",
>>>> -	"venc",
>>>> -	"venc_lt",
>>>> -	"ethif",
>>>> -	"vdec",
>>>> -	"hif_sel",
>>>> -	"jpgdec",
>>>> -	"audio",
>>>> -	NULL,
>>>> -};
>>>> -
>>>>  #define MAX_CLKS	3
>>>>  
>>>>  /**
>>>> @@ -116,7 +88,7 @@ enum clk_id {
>>>>   * @sram_pdn_bits: The mask for sram power control bits.
>>>>   * @sram_pdn_ack_bits: The mask for sram power control acked bits.
>>>>   * @bus_prot_mask: The mask for single step bus protection.
>>>> - * @clk_id: The basic clocks required by this power domain.
>>>> + * @basic_clk_name: The basic clocks required by this power domain.
>>>>   * @caps: The flag for active wake-up action.
>>>>   */
>>>>  struct scp_domain_data {
>>>> @@ -126,7 +98,7 @@ struct scp_domain_data {
>>>>  	u32 sram_pdn_bits;
>>>>  	u32 sram_pdn_ack_bits;
>>>>  	u32 bus_prot_mask;
>>>> -	enum clk_id clk_id[MAX_CLKS];
>>>> +	const char *basic_clk_name[MAX_CLKS];
>>>
>>> I only reviewed v13, so sorry if this was already discussed. I am wondering if
>>> would be better take advantage of the devm_clk_bulk_get() function instead of
>>> kind of reimplementing the same, something like this
>>>
>>> 	const struct clk_bulk_data *basic_clocks;
>>>
>>
>> I thought it should be const struct clk_bulk_data
>> basic_clocks[MAX_CLKS]; instead of const struct clk_bulk_data
>> *basic_clocks; in struct scp_domain_data data type
>>
>>>>  	u8 caps;
>>>>  };
>>>>  
>>>> @@ -411,12 +383,19 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
>>>>  	return ret;
>>>>  }
>>>>  
>>>> -static void init_clks(struct platform_device *pdev, struct clk **clk)
>>>> +static int init_basic_clks(struct platform_device *pdev, struct clk **clk,
>>>> +			const char * const *name)
>>>>  {
>>>>  	int i;
>>>>  
>>>> -	for (i = CLK_NONE + 1; i < CLK_MAX; i++)
>>>> -		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
>>>> +	for (i = 0; i < MAX_CLKS && name[i]; i++) {
>>>> +		clk[i] = devm_clk_get(&pdev->dev, name[i]);
>>>> +
>>>> +		if (IS_ERR(clk[i]))
>>>> +			return PTR_ERR(clk[i]);
>>>> +	}
>>>
>>> You will be able to remove this function, see below ...
>>>
>>>> +
>>>> +	return 0;
>>>>  }
>>>>  
>>>>  static struct scp *init_scp(struct platform_device *pdev,
>>>> @@ -426,9 +405,8 @@ static struct scp *init_scp(struct platform_device *pdev,
>>>>  {
>>>>  	struct genpd_onecell_data *pd_data;
>>>>  	struct resource *res;
>>>> -	int i, j;
>>>> +	int i, ret;
>>>>  	struct scp *scp;
>>>> -	struct clk *clk[CLK_MAX];
>>>>  
>>>>  	scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL);
>>>>  	if (!scp)
>>>> @@ -481,8 +459,6 @@ static struct scp *init_scp(struct platform_device *pdev,
>>>>  
>>>>  	pd_data->num_domains = num;
>>>>  
>>>> -	init_clks(pdev, clk);
>>>> -
>>>>  	for (i = 0; i < num; i++) {
>>>>  		struct scp_domain *scpd = &scp->domains[i];
>>>>  		struct generic_pm_domain *genpd = &scpd->genpd;
>>>> @@ -493,17 +469,9 @@ static struct scp *init_scp(struct platform_device *pdev,
>>>>  
>>>>  		scpd->data = data;
>>>>  
>>>> -		for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) {
>>>> -			struct clk *c = clk[data->clk_id[j]];
>>>> -
>>>> -			if (IS_ERR(c)) {
>>>> -				dev_err(&pdev->dev, "%s: clk unavailable\n",
>>>> -					data->name);
>>>> -				return ERR_CAST(c);
>>>> -			}
>>>> -
>>>> -			scpd->clk[j] = c;
>>>> -		}
>>>> +		ret = init_basic_clks(pdev, scpd->clk, data->basic_clk_name);
>>>> +		if (ret)
>>>> +			return ERR_PTR(ret);
>>>
>>> Just call:
>>>
>>> 	ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(basic_clocks),
>>> 				data->basic_clocks);
>>> 	if (ret)
>>> 		return ERR_PTR(ret);
>>>
>>>>  
>>>>  		genpd->name = data->name;
>>>>  		genpd->power_off = scpsys_power_off;
>>>> @@ -560,7 +528,6 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>>>>  		.ctl_offs = SPM_CONN_PWR_CON,
>>>>  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M |
>>>>  				 MT2701_TOP_AXI_PROT_EN_CONN_S,
>>>> -		.clk_id = {CLK_NONE},
>>>>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
>>>>  	},
>>>>  	[MT2701_POWER_DOMAIN_DISP] = {
>>>> @@ -568,7 +535,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>>>>  		.sta_mask = PWR_STATUS_DISP,
>>>>  		.ctl_offs = SPM_DIS_PWR_CON,
>>>>  		.sram_pdn_bits = GENMASK(11, 8),
>>>> -		.clk_id = {CLK_MM},
>>>> +		.basic_clk_name = {"mm"},
>>>
>>> 		.basic_clocks[] = {
>>> 			{ .id = "mm" },
>>> 		};
>>>
>>
>> Those basic clocks without given a name (name: null) would get incorrect
>> clock via clk_bulk_get(...) due to 
>>
>> /**
>>  * of_parse_clkspec() - Parse a DT clock specifier for a given device
>> node
>>  * @np: device node to parse clock specifier from
>>  * @index: index of phandle to parse clock out of. If index < 0, @name
>> is used
>>  * @name: clock name to find and parse. If name is NULL, the index is
>> used
>>
>> And the index is 0 here in this callstack
>>
>> I guess something need to be improved before we use the clk_bulk_ APIs.
>>
> 
> Hi Enric,
> 
> According to the result above, is it necessary to change the APIs or
> maybe I should send the next version v15 first to fix other problems you
> mentioned? Many thanks.
> 

It is fine to send a next version without changing the APIs, it depends on the
extra work if you are fine with the change. To be honest I didn't see the
problem above but I think can be fixed.

Cheers,
 Enric


>>
>>>>  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_MM_M0,
>>>>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
>>>>  	},
>>>> @@ -578,7 +545,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>>>>  		.ctl_offs = SPM_MFG_PWR_CON,
>>>>  		.sram_pdn_bits = GENMASK(11, 8),
>>>>  		.sram_pdn_ack_bits = GENMASK(12, 12),
>>>> -		.clk_id = {CLK_MFG},
>>>> +		.basic_clk_name = {"mfg"},
>>>
>>> 		.basic_clocks[] = {
>>> 			{ .id = "mfg" },
>>> 		};
>>>
>>>>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
>>>>  	},
>>>>  	[MT2701_POWER_DOMAIN_VDEC] = {
>>>> @@ -587,7 +554,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
>>>>  		.ctl_offs = SPM_VDE_PWR_CON,
>>>>  		.sram_pdn_bits = GENMASK(11, 8),
>>>>  		.sram_pdn_ack_bits = GENMASK(12, 12),
>>>> -		.clk_id = {CLK_MM},
>>>> +		.basic_clk_name = {"mm"},
>>>
>>> ...
>>>
>>> [snip]
>>
>>
>
Weiyi Lu May 21, 2020, 3:28 a.m. UTC | #5
On Mon, 2020-05-18 at 19:52 +0200, Enric Balletbo i Serra wrote:
> Hi Weiyi,
> 
> On 15/5/20 5:35, Weiyi Lu wrote:
> > On Mon, 2020-05-11 at 14:02 +0800, Weiyi Lu wrote:
> >> On Wed, 2020-05-06 at 23:01 +0200, Enric Balletbo i Serra wrote:
> >>> Hi Weiyi,
> >>>
> >>> Thank you for your patch.
> >>>
> >>> On 6/5/20 10:15, Weiyi Lu wrote:
> >>>> Try to stop extending the clk_id or clk_names if there are
> >>>> more and more new BASIC clocks. To get its own clocks by the
> >>>> basic_clk_name of each power domain.
> >>>> And then use basic_clk_name strings for all compatibles, instead of
> >>>> mixing clk_id and clk_name.
> >>>>
> >>>> Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com>
> >>>> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
> >>>> ---
> >>>>  drivers/soc/mediatek/mtk-scpsys.c | 134 ++++++++++++--------------------------
> >>>>  1 file changed, 41 insertions(+), 93 deletions(-)
> >>>>
> >>>> diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
> >>>> index f669d37..c9c3cf7 100644
> >>>> --- a/drivers/soc/mediatek/mtk-scpsys.c
> >>>> +++ b/drivers/soc/mediatek/mtk-scpsys.c
> >>>> @@ -78,34 +78,6 @@
> >>>>  #define PWR_STATUS_HIF1			BIT(26)	/* MT7622 */
> >>>>  #define PWR_STATUS_WB			BIT(27)	/* MT7622 */
> >>>>  
> >>>> -enum clk_id {
> >>>> -	CLK_NONE,
> >>>> -	CLK_MM,
> >>>> -	CLK_MFG,
> >>>> -	CLK_VENC,
> >>>> -	CLK_VENC_LT,
> >>>> -	CLK_ETHIF,
> >>>> -	CLK_VDEC,
> >>>> -	CLK_HIFSEL,
> >>>> -	CLK_JPGDEC,
> >>>> -	CLK_AUDIO,
> >>>> -	CLK_MAX,
> >>>> -};
> >>>> -
> >>>> -static const char * const clk_names[] = {
> >>>> -	NULL,
> >>>> -	"mm",
> >>>> -	"mfg",
> >>>> -	"venc",
> >>>> -	"venc_lt",
> >>>> -	"ethif",
> >>>> -	"vdec",
> >>>> -	"hif_sel",
> >>>> -	"jpgdec",
> >>>> -	"audio",
> >>>> -	NULL,
> >>>> -};
> >>>> -
> >>>>  #define MAX_CLKS	3
> >>>>  
> >>>>  /**
> >>>> @@ -116,7 +88,7 @@ enum clk_id {
> >>>>   * @sram_pdn_bits: The mask for sram power control bits.
> >>>>   * @sram_pdn_ack_bits: The mask for sram power control acked bits.
> >>>>   * @bus_prot_mask: The mask for single step bus protection.
> >>>> - * @clk_id: The basic clocks required by this power domain.
> >>>> + * @basic_clk_name: The basic clocks required by this power domain.
> >>>>   * @caps: The flag for active wake-up action.
> >>>>   */
> >>>>  struct scp_domain_data {
> >>>> @@ -126,7 +98,7 @@ struct scp_domain_data {
> >>>>  	u32 sram_pdn_bits;
> >>>>  	u32 sram_pdn_ack_bits;
> >>>>  	u32 bus_prot_mask;
> >>>> -	enum clk_id clk_id[MAX_CLKS];
> >>>> +	const char *basic_clk_name[MAX_CLKS];
> >>>
> >>> I only reviewed v13, so sorry if this was already discussed. I am wondering if
> >>> would be better take advantage of the devm_clk_bulk_get() function instead of
> >>> kind of reimplementing the same, something like this
> >>>
> >>> 	const struct clk_bulk_data *basic_clocks;
> >>>
> >>
> >> I thought it should be const struct clk_bulk_data
> >> basic_clocks[MAX_CLKS]; instead of const struct clk_bulk_data
> >> *basic_clocks; in struct scp_domain_data data type
> >>
> >>>>  	u8 caps;
> >>>>  };
> >>>>  
> >>>> @@ -411,12 +383,19 @@ static int scpsys_power_off(struct generic_pm_domain *genpd)
> >>>>  	return ret;
> >>>>  }
> >>>>  
> >>>> -static void init_clks(struct platform_device *pdev, struct clk **clk)
> >>>> +static int init_basic_clks(struct platform_device *pdev, struct clk **clk,
> >>>> +			const char * const *name)
> >>>>  {
> >>>>  	int i;
> >>>>  
> >>>> -	for (i = CLK_NONE + 1; i < CLK_MAX; i++)
> >>>> -		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
> >>>> +	for (i = 0; i < MAX_CLKS && name[i]; i++) {
> >>>> +		clk[i] = devm_clk_get(&pdev->dev, name[i]);
> >>>> +
> >>>> +		if (IS_ERR(clk[i]))
> >>>> +			return PTR_ERR(clk[i]);
> >>>> +	}
> >>>
> >>> You will be able to remove this function, see below ...
> >>>
> >>>> +
> >>>> +	return 0;
> >>>>  }
> >>>>  
> >>>>  static struct scp *init_scp(struct platform_device *pdev,
> >>>> @@ -426,9 +405,8 @@ static struct scp *init_scp(struct platform_device *pdev,
> >>>>  {
> >>>>  	struct genpd_onecell_data *pd_data;
> >>>>  	struct resource *res;
> >>>> -	int i, j;
> >>>> +	int i, ret;
> >>>>  	struct scp *scp;
> >>>> -	struct clk *clk[CLK_MAX];
> >>>>  
> >>>>  	scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL);
> >>>>  	if (!scp)
> >>>> @@ -481,8 +459,6 @@ static struct scp *init_scp(struct platform_device *pdev,
> >>>>  
> >>>>  	pd_data->num_domains = num;
> >>>>  
> >>>> -	init_clks(pdev, clk);
> >>>> -
> >>>>  	for (i = 0; i < num; i++) {
> >>>>  		struct scp_domain *scpd = &scp->domains[i];
> >>>>  		struct generic_pm_domain *genpd = &scpd->genpd;
> >>>> @@ -493,17 +469,9 @@ static struct scp *init_scp(struct platform_device *pdev,
> >>>>  
> >>>>  		scpd->data = data;
> >>>>  
> >>>> -		for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) {
> >>>> -			struct clk *c = clk[data->clk_id[j]];
> >>>> -
> >>>> -			if (IS_ERR(c)) {
> >>>> -				dev_err(&pdev->dev, "%s: clk unavailable\n",
> >>>> -					data->name);
> >>>> -				return ERR_CAST(c);
> >>>> -			}
> >>>> -
> >>>> -			scpd->clk[j] = c;
> >>>> -		}
> >>>> +		ret = init_basic_clks(pdev, scpd->clk, data->basic_clk_name);
> >>>> +		if (ret)
> >>>> +			return ERR_PTR(ret);
> >>>
> >>> Just call:
> >>>
> >>> 	ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(basic_clocks),
> >>> 				data->basic_clocks);
> >>> 	if (ret)
> >>> 		return ERR_PTR(ret);
> >>>
> >>>>  
> >>>>  		genpd->name = data->name;
> >>>>  		genpd->power_off = scpsys_power_off;
> >>>> @@ -560,7 +528,6 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >>>>  		.ctl_offs = SPM_CONN_PWR_CON,
> >>>>  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M |
> >>>>  				 MT2701_TOP_AXI_PROT_EN_CONN_S,
> >>>> -		.clk_id = {CLK_NONE},
> >>>>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> >>>>  	},
> >>>>  	[MT2701_POWER_DOMAIN_DISP] = {
> >>>> @@ -568,7 +535,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >>>>  		.sta_mask = PWR_STATUS_DISP,
> >>>>  		.ctl_offs = SPM_DIS_PWR_CON,
> >>>>  		.sram_pdn_bits = GENMASK(11, 8),
> >>>> -		.clk_id = {CLK_MM},
> >>>> +		.basic_clk_name = {"mm"},
> >>>
> >>> 		.basic_clocks[] = {
> >>> 			{ .id = "mm" },
> >>> 		};
> >>>
> >>
> >> Those basic clocks without given a name (name: null) would get incorrect
> >> clock via clk_bulk_get(...) due to 
> >>
> >> /**
> >>  * of_parse_clkspec() - Parse a DT clock specifier for a given device
> >> node
> >>  * @np: device node to parse clock specifier from
> >>  * @index: index of phandle to parse clock out of. If index < 0, @name
> >> is used
> >>  * @name: clock name to find and parse. If name is NULL, the index is
> >> used
> >>
> >> And the index is 0 here in this callstack
> >>
> >> I guess something need to be improved before we use the clk_bulk_ APIs.
> >>
> > 
> > Hi Enric,
> > 
> > According to the result above, is it necessary to change the APIs or
> > maybe I should send the next version v15 first to fix other problems you
> > mentioned? Many thanks.
> > 
> 
> It is fine to send a next version without changing the APIs, it depends on the
> extra work if you are fine with the change. To be honest I didn't see the
> problem above but I think can be fixed.
> 
> Cheers,
>  Enric
> 

Hi Enric,

Got it, I'll send a next version without changing the APIs.
And please let me explain it again.
If anything wrong, feel free to correct me.

First, the clock mapping in the dts
e.g. 
clocks = <&topckgen CLK_TOP_MUX_AUD_INTBUS>, <= index 0
	 <&infracfg CLK_INFRA_AUDIO>,
	 <&infracfg CLK_INFRA_AUDIO_26M_BCLK>,
	 <&topckgen CLK_TOP_MUX_MFG>,
	 <&topckgen CLK_TOP_MUX_MM>;

clock-names = "audio",
	      "audio1",
	      "audio2",
	      "mfg",
	      "mm";


And then, in struct scp_domain_data data structure we might need to use
const struct clk_bulk_data basic_clocks[MAX_CLKS]; rather than const
struct clk_bulk_data *basic_clocks;

So what

.basic_clocks = {
	{ .id = "mm" },
};

is certainly like below

.basic_clocks = {
	{ .id = "mm" },
	{ .id = null },
	{ .id = null },
};

And using devm_clk_bulk_get(...); to get the clock resource will result
in

basic_clocks = {
	{ .id = "mm", . clk = <&topckgen CLK_TOP_MUX_MM>},
	{ .id = null, . clk = <&topckgen CLK_TOP_MUX_AUD_INTBUS>},
	{ .id = null, . clk = <&topckgen CLK_TOP_MUX_AUD_INTBUS>},
};

I thought it's incorrect for my usage inside the mtk-scpsys.c
and currently how devm_clk_bulk_get(...) will get the clock resource is
by API of_parse_clksepc()

/**
 * of_parse_clkspec() - Parse a DT clock specifier for a given device
 node
  * @np: device node to parse clock specifier from
  * @index: index of phandle to parse clock out of. If index < 0, @name
 is used
  * @name: clock name to find and parse. If name is NULL, the index is
 used

And for clocks without given a name first(id=null), will use the index 0
to get the clock. In this example, the index 0 will map to <&topckgen
CLK_TOP_MUX_AUD_INTBUS>

If we ignore the problem and use clk_bulk_prepare()/_enable() to control
the clock, so far, clk_bulk_enable will traverse all the iterator and
enable the unexpected clocks without check if the clock id(name) is
valid or not.

Right now, I'm not sure why of_parse_clkspec() assume to use the index 0
if the name is NULL. I might need some time to dig it out. If you have
some information about this part, please share it to me. Many thanks.


> 
> >>
> >>>>  		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_MM_M0,
> >>>>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> >>>>  	},
> >>>> @@ -578,7 +545,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >>>>  		.ctl_offs = SPM_MFG_PWR_CON,
> >>>>  		.sram_pdn_bits = GENMASK(11, 8),
> >>>>  		.sram_pdn_ack_bits = GENMASK(12, 12),
> >>>> -		.clk_id = {CLK_MFG},
> >>>> +		.basic_clk_name = {"mfg"},
> >>>
> >>> 		.basic_clocks[] = {
> >>> 			{ .id = "mfg" },
> >>> 		};
> >>>
> >>>>  		.caps = MTK_SCPD_ACTIVE_WAKEUP,
> >>>>  	},
> >>>>  	[MT2701_POWER_DOMAIN_VDEC] = {
> >>>> @@ -587,7 +554,7 @@ static void mtk_register_power_domains(struct platform_device *pdev,
> >>>>  		.ctl_offs = SPM_VDE_PWR_CON,
> >>>>  		.sram_pdn_bits = GENMASK(11, 8),
> >>>>  		.sram_pdn_ack_bits = GENMASK(12, 12),
> >>>> -		.clk_id = {CLK_MM},
> >>>> +		.basic_clk_name = {"mm"},
> >>>
> >>> ...
> >>>
> >>> [snip]
> >>
> >>
> > 
> 
> _______________________________________________
> Linux-mediatek mailing list
> Linux-mediatek@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-mediatek
diff mbox series

Patch

diff --git a/drivers/soc/mediatek/mtk-scpsys.c b/drivers/soc/mediatek/mtk-scpsys.c
index f669d37..c9c3cf7 100644
--- a/drivers/soc/mediatek/mtk-scpsys.c
+++ b/drivers/soc/mediatek/mtk-scpsys.c
@@ -78,34 +78,6 @@ 
 #define PWR_STATUS_HIF1			BIT(26)	/* MT7622 */
 #define PWR_STATUS_WB			BIT(27)	/* MT7622 */
 
-enum clk_id {
-	CLK_NONE,
-	CLK_MM,
-	CLK_MFG,
-	CLK_VENC,
-	CLK_VENC_LT,
-	CLK_ETHIF,
-	CLK_VDEC,
-	CLK_HIFSEL,
-	CLK_JPGDEC,
-	CLK_AUDIO,
-	CLK_MAX,
-};
-
-static const char * const clk_names[] = {
-	NULL,
-	"mm",
-	"mfg",
-	"venc",
-	"venc_lt",
-	"ethif",
-	"vdec",
-	"hif_sel",
-	"jpgdec",
-	"audio",
-	NULL,
-};
-
 #define MAX_CLKS	3
 
 /**
@@ -116,7 +88,7 @@  enum clk_id {
  * @sram_pdn_bits: The mask for sram power control bits.
  * @sram_pdn_ack_bits: The mask for sram power control acked bits.
  * @bus_prot_mask: The mask for single step bus protection.
- * @clk_id: The basic clocks required by this power domain.
+ * @basic_clk_name: The basic clocks required by this power domain.
  * @caps: The flag for active wake-up action.
  */
 struct scp_domain_data {
@@ -126,7 +98,7 @@  struct scp_domain_data {
 	u32 sram_pdn_bits;
 	u32 sram_pdn_ack_bits;
 	u32 bus_prot_mask;
-	enum clk_id clk_id[MAX_CLKS];
+	const char *basic_clk_name[MAX_CLKS];
 	u8 caps;
 };
 
@@ -411,12 +383,19 @@  static int scpsys_power_off(struct generic_pm_domain *genpd)
 	return ret;
 }
 
-static void init_clks(struct platform_device *pdev, struct clk **clk)
+static int init_basic_clks(struct platform_device *pdev, struct clk **clk,
+			const char * const *name)
 {
 	int i;
 
-	for (i = CLK_NONE + 1; i < CLK_MAX; i++)
-		clk[i] = devm_clk_get(&pdev->dev, clk_names[i]);
+	for (i = 0; i < MAX_CLKS && name[i]; i++) {
+		clk[i] = devm_clk_get(&pdev->dev, name[i]);
+
+		if (IS_ERR(clk[i]))
+			return PTR_ERR(clk[i]);
+	}
+
+	return 0;
 }
 
 static struct scp *init_scp(struct platform_device *pdev,
@@ -426,9 +405,8 @@  static struct scp *init_scp(struct platform_device *pdev,
 {
 	struct genpd_onecell_data *pd_data;
 	struct resource *res;
-	int i, j;
+	int i, ret;
 	struct scp *scp;
-	struct clk *clk[CLK_MAX];
 
 	scp = devm_kzalloc(&pdev->dev, sizeof(*scp), GFP_KERNEL);
 	if (!scp)
@@ -481,8 +459,6 @@  static struct scp *init_scp(struct platform_device *pdev,
 
 	pd_data->num_domains = num;
 
-	init_clks(pdev, clk);
-
 	for (i = 0; i < num; i++) {
 		struct scp_domain *scpd = &scp->domains[i];
 		struct generic_pm_domain *genpd = &scpd->genpd;
@@ -493,17 +469,9 @@  static struct scp *init_scp(struct platform_device *pdev,
 
 		scpd->data = data;
 
-		for (j = 0; j < MAX_CLKS && data->clk_id[j]; j++) {
-			struct clk *c = clk[data->clk_id[j]];
-
-			if (IS_ERR(c)) {
-				dev_err(&pdev->dev, "%s: clk unavailable\n",
-					data->name);
-				return ERR_CAST(c);
-			}
-
-			scpd->clk[j] = c;
-		}
+		ret = init_basic_clks(pdev, scpd->clk, data->basic_clk_name);
+		if (ret)
+			return ERR_PTR(ret);
 
 		genpd->name = data->name;
 		genpd->power_off = scpsys_power_off;
@@ -560,7 +528,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_CONN_PWR_CON,
 		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M |
 				 MT2701_TOP_AXI_PROT_EN_CONN_S,
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2701_POWER_DOMAIN_DISP] = {
@@ -568,7 +535,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.sta_mask = PWR_STATUS_DISP,
 		.ctl_offs = SPM_DIS_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_MM_M0,
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
@@ -578,7 +545,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_MFG_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_MFG},
+		.basic_clk_name = {"mfg"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2701_POWER_DOMAIN_VDEC] = {
@@ -587,7 +554,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_VDE_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2701_POWER_DOMAIN_ISP] = {
@@ -596,7 +563,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_ISP_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(13, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2701_POWER_DOMAIN_BDP] = {
@@ -604,7 +571,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.sta_mask = PWR_STATUS_BDP,
 		.ctl_offs = SPM_BDP_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2701_POWER_DOMAIN_ETH] = {
@@ -613,7 +579,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_ETH_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_ETHIF},
+		.basic_clk_name = {"ethif"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2701_POWER_DOMAIN_HIF] = {
@@ -622,14 +588,13 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_HIF_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_ETHIF},
+		.basic_clk_name = {"ethif"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2701_POWER_DOMAIN_IFR_MSC] = {
 		.name = "ifr_msc",
 		.sta_mask = PWR_STATUS_IFR_MSC,
 		.ctl_offs = SPM_IFR_MSC_PWR_CON,
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 };
@@ -644,7 +609,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_DIS_PWR_CON,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_VDEC] = {
@@ -653,7 +618,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_VDE_PWR_CON,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_MM, CLK_VDEC},
+		.basic_clk_name = {"mm", "vdec"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_VENC] = {
@@ -662,7 +627,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_VEN_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_MM, CLK_VENC, CLK_JPGDEC},
+		.basic_clk_name = {"mm", "venc", "jpgdec"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_ISP] = {
@@ -671,7 +636,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_ISP_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(13, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_AUDIO] = {
@@ -680,7 +645,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_AUDIO_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_AUDIO},
+		.basic_clk_name = {"audio"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_USB] = {
@@ -689,7 +654,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_USB_PWR_CON,
 		.sram_pdn_bits = GENMASK(10, 8),
 		.sram_pdn_ack_bits = GENMASK(14, 12),
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_USB2] = {
@@ -698,7 +662,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_USB2_PWR_CON,
 		.sram_pdn_bits = GENMASK(10, 8),
 		.sram_pdn_ack_bits = GENMASK(14, 12),
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_MFG] = {
@@ -707,7 +670,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_MFG_PWR_CON,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(16, 16),
-		.clk_id = {CLK_MFG},
+		.basic_clk_name = {"mfg"},
 		.bus_prot_mask = BIT(14) | BIT(21) | BIT(23),
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
@@ -717,7 +680,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x02c0,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(16, 16),
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_MFG_SC2] = {
@@ -726,7 +688,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x02c4,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(16, 16),
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT2712_POWER_DOMAIN_MFG_SC3] = {
@@ -735,7 +696,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x01f8,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(16, 16),
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 };
@@ -760,7 +720,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x300,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_VDEC},
+		.basic_clk_name = {"vdec"},
 	},
 	[MT6797_POWER_DOMAIN_VENC] = {
 		.name = "venc",
@@ -768,7 +728,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x304,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_NONE},
 	},
 	[MT6797_POWER_DOMAIN_ISP] = {
 		.name = "isp",
@@ -776,7 +735,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x308,
 		.sram_pdn_bits = GENMASK(9, 8),
 		.sram_pdn_ack_bits = GENMASK(13, 12),
-		.clk_id = {CLK_NONE},
 	},
 	[MT6797_POWER_DOMAIN_MM] = {
 		.name = "mm",
@@ -784,7 +742,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x30C,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 		.bus_prot_mask = (BIT(1) | BIT(2)),
 	},
 	[MT6797_POWER_DOMAIN_AUDIO] = {
@@ -793,7 +751,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x314,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_NONE},
 	},
 	[MT6797_POWER_DOMAIN_MFG_ASYNC] = {
 		.name = "mfg_async",
@@ -801,7 +758,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x334,
 		.sram_pdn_bits = 0,
 		.sram_pdn_ack_bits = 0,
-		.clk_id = {CLK_MFG},
+		.basic_clk_name = {"mfg"},
 	},
 	[MT6797_POWER_DOMAIN_MJC] = {
 		.name = "mjc",
@@ -809,7 +766,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = 0x310,
 		.sram_pdn_bits = GENMASK(8, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_NONE},
 	},
 };
 
@@ -834,7 +790,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_ETHSYS_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_NONE},
 		.bus_prot_mask = MT7622_TOP_AXI_PROT_EN_ETHSYS,
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
@@ -844,7 +799,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_HIF0_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_HIFSEL},
+		.basic_clk_name = {"hif_sel"},
 		.bus_prot_mask = MT7622_TOP_AXI_PROT_EN_HIF0,
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
@@ -854,7 +809,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_HIF1_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_HIFSEL},
+		.basic_clk_name = {"hif_sel"},
 		.bus_prot_mask = MT7622_TOP_AXI_PROT_EN_HIF1,
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
@@ -864,7 +819,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_WB_PWR_CON,
 		.sram_pdn_bits = 0,
 		.sram_pdn_ack_bits = 0,
-		.clk_id = {CLK_NONE},
 		.bus_prot_mask = MT7622_TOP_AXI_PROT_EN_WB,
 		.caps = MTK_SCPD_ACTIVE_WAKEUP | MTK_SCPD_FWAIT_SRAM,
 	},
@@ -881,7 +835,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_CONN_PWR_CON,
 		.bus_prot_mask = MT2701_TOP_AXI_PROT_EN_CONN_M |
 				 MT2701_TOP_AXI_PROT_EN_CONN_S,
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT7623A_POWER_DOMAIN_ETH] = {
@@ -890,7 +843,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_ETH_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_ETHIF},
+		.basic_clk_name = {"ethif"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT7623A_POWER_DOMAIN_HIF] = {
@@ -899,14 +852,13 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_HIF_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_ETHIF},
+		.basic_clk_name = {"ethif"},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT7623A_POWER_DOMAIN_IFR_MSC] = {
 		.name = "ifr_msc",
 		.sta_mask = PWR_STATUS_IFR_MSC,
 		.ctl_offs = SPM_IFR_MSC_PWR_CON,
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 };
@@ -922,7 +874,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_VDE_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 	},
 	[MT8173_POWER_DOMAIN_VENC] = {
 		.name = "venc",
@@ -930,7 +882,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_VEN_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_MM, CLK_VENC},
+		.basic_clk_name = {"mm", "venc"},
 	},
 	[MT8173_POWER_DOMAIN_ISP] = {
 		.name = "isp",
@@ -938,7 +890,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_ISP_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(13, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 	},
 	[MT8173_POWER_DOMAIN_MM] = {
 		.name = "mm",
@@ -946,7 +898,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_DIS_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(12, 12),
-		.clk_id = {CLK_MM},
+		.basic_clk_name = {"mm"},
 		.bus_prot_mask = MT8173_TOP_AXI_PROT_EN_MM_M0 |
 			MT8173_TOP_AXI_PROT_EN_MM_M1,
 	},
@@ -956,7 +908,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_VEN2_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_MM, CLK_VENC_LT},
+		.basic_clk_name = {"mm", "venc_lt"},
 	},
 	[MT8173_POWER_DOMAIN_AUDIO] = {
 		.name = "audio",
@@ -964,7 +916,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_AUDIO_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_NONE},
 	},
 	[MT8173_POWER_DOMAIN_USB] = {
 		.name = "usb",
@@ -972,7 +923,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_USB_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(15, 12),
-		.clk_id = {CLK_NONE},
 		.caps = MTK_SCPD_ACTIVE_WAKEUP,
 	},
 	[MT8173_POWER_DOMAIN_MFG_ASYNC] = {
@@ -981,7 +931,7 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_MFG_ASYNC_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = 0,
-		.clk_id = {CLK_MFG},
+		.basic_clk_name = {"mfg"},
 	},
 	[MT8173_POWER_DOMAIN_MFG_2D] = {
 		.name = "mfg_2d",
@@ -989,7 +939,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_MFG_2D_PWR_CON,
 		.sram_pdn_bits = GENMASK(11, 8),
 		.sram_pdn_ack_bits = GENMASK(13, 12),
-		.clk_id = {CLK_NONE},
 	},
 	[MT8173_POWER_DOMAIN_MFG] = {
 		.name = "mfg",
@@ -997,7 +946,6 @@  static void mtk_register_power_domains(struct platform_device *pdev,
 		.ctl_offs = SPM_MFG_PWR_CON,
 		.sram_pdn_bits = GENMASK(13, 8),
 		.sram_pdn_ack_bits = GENMASK(21, 16),
-		.clk_id = {CLK_NONE},
 		.bus_prot_mask = MT8173_TOP_AXI_PROT_EN_MFG_S |
 			MT8173_TOP_AXI_PROT_EN_MFG_M0 |
 			MT8173_TOP_AXI_PROT_EN_MFG_M1 |