diff mbox series

[1/7] clk: imx: clk-pll14xx: Switch to clk_hw based API

Message ID 1572356175-24950-2-git-send-email-peng.fan@nxp.com (mailing list archive)
State New, archived
Headers show
Series clk: imx: switch to clk_hw based API | expand

Commit Message

Peng Fan Oct. 29, 2019, 1:40 p.m. UTC
From: Peng Fan <peng.fan@nxp.com>

Switch the imx_clk_pll14xx function to clk_hw based API, rename
accordingly and add a macro for clk based legacy. This allows us to
move closer to a clear split between consumer and provider clk APIs.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/clk/imx/clk-pll14xx.c | 22 +++++++++++++---------
 drivers/clk/imx/clk.h         |  8 ++++++--
 2 files changed, 19 insertions(+), 11 deletions(-)

Comments

Shawn Guo Dec. 2, 2019, 1:17 a.m. UTC | #1
On Tue, Oct 29, 2019 at 01:40:54PM +0000, Peng Fan wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> Switch the imx_clk_pll14xx function to clk_hw based API, rename
> accordingly and add a macro for clk based legacy. This allows us to
> move closer to a clear split between consumer and provider clk APIs.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/clk/imx/clk-pll14xx.c | 22 +++++++++++++---------
>  drivers/clk/imx/clk.h         |  8 ++++++--
>  2 files changed, 19 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c
> index 5c458199060a..fa76e04251c4 100644
> --- a/drivers/clk/imx/clk-pll14xx.c
> +++ b/drivers/clk/imx/clk-pll14xx.c
> @@ -369,13 +369,14 @@ static const struct clk_ops clk_pll1443x_ops = {
>  	.set_rate	= clk_pll1443x_set_rate,
>  };
>  
> -struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
> -			    void __iomem *base,
> -			    const struct imx_pll14xx_clk *pll_clk)
> +struct clk_hw *imx_clk_hw_pll14xx(const char *name, const char *parent_name,
> +				  void __iomem *base,
> +				  const struct imx_pll14xx_clk *pll_clk)
>  {
>  	struct clk_pll14xx *pll;
> -	struct clk *clk;
> +	struct clk_hw *hw;
>  	struct clk_init_data init;
> +	int ret;
>  	u32 val;
>  
>  	pll = kzalloc(sizeof(*pll), GFP_KERNEL);
> @@ -412,12 +413,15 @@ struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
>  	val &= ~BYPASS_MASK;
>  	writel_relaxed(val, pll->base + GNRL_CTL);
>  
> -	clk = clk_register(NULL, &pll->hw);
> -	if (IS_ERR(clk)) {
> -		pr_err("%s: failed to register pll %s %lu\n",
> -			__func__, name, PTR_ERR(clk));
> +	hw = &pll->hw;
> +
> +	ret = clk_hw_register(NULL, hw);
> +	if (ret) {
> +		pr_err("%s: failed to register pll %s %d\n",
> +			__func__, name, ret);
>  		kfree(pll);
> +		return ERR_PTR(ret);
>  	}
>  
> -	return clk;
> +	return hw;
>  }
> diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h
> index bc5bb6ac8636..5038622f1a72 100644
> --- a/drivers/clk/imx/clk.h
> +++ b/drivers/clk/imx/clk.h
> @@ -97,8 +97,12 @@ extern struct imx_pll14xx_clk imx_1443x_pll;
>  #define imx_clk_mux(name, reg, shift, width, parents, num_parents) \
>  	imx_clk_hw_mux(name, reg, shift, width, parents, num_parents)->clk
>  
> -struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
> -		 void __iomem *base, const struct imx_pll14xx_clk *pll_clk);
> +#define imx_clk_pll14xx(name, parent_name, base, pll_clk) \
> +	imx_clk_hw_pll14xx(name, parent_name, base, pll_clk)->clk
> +

I would suggest to use an inline function for this, which will be more
readable and complying to kernel coding style.

Shawn

> +struct clk_hw *imx_clk_hw_pll14xx(const char *name, const char *parent_name,
> +				  void __iomem *base,
> +				  const struct imx_pll14xx_clk *pll_clk);
>  
>  struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name,
>  		const char *parent, void __iomem *base);
> -- 
> 2.16.4
>
Peng Fan Dec. 2, 2019, 2:26 a.m. UTC | #2
Hi Shawn,

> Subject: Re: [PATCH 1/7] clk: imx: clk-pll14xx: Switch to clk_hw based API
> 
> On Tue, Oct 29, 2019 at 01:40:54PM +0000, Peng Fan wrote:
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > Switch the imx_clk_pll14xx function to clk_hw based API, rename
> > accordingly and add a macro for clk based legacy. This allows us to
> > move closer to a clear split between consumer and provider clk APIs.
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  drivers/clk/imx/clk-pll14xx.c | 22 +++++++++++++---------
> >  drivers/clk/imx/clk.h         |  8 ++++++--
> >  2 files changed, 19 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/clk/imx/clk-pll14xx.c
> > b/drivers/clk/imx/clk-pll14xx.c index 5c458199060a..fa76e04251c4
> > 100644
> > --- a/drivers/clk/imx/clk-pll14xx.c
> > +++ b/drivers/clk/imx/clk-pll14xx.c
> > @@ -369,13 +369,14 @@ static const struct clk_ops clk_pll1443x_ops = {
> >  	.set_rate	= clk_pll1443x_set_rate,
> >  };
> >
> > -struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
> > -			    void __iomem *base,
> > -			    const struct imx_pll14xx_clk *pll_clk)
> > +struct clk_hw *imx_clk_hw_pll14xx(const char *name, const char
> *parent_name,
> > +				  void __iomem *base,
> > +				  const struct imx_pll14xx_clk *pll_clk)
> >  {
> >  	struct clk_pll14xx *pll;
> > -	struct clk *clk;
> > +	struct clk_hw *hw;
> >  	struct clk_init_data init;
> > +	int ret;
> >  	u32 val;
> >
> >  	pll = kzalloc(sizeof(*pll), GFP_KERNEL); @@ -412,12 +413,15 @@
> > struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
> >  	val &= ~BYPASS_MASK;
> >  	writel_relaxed(val, pll->base + GNRL_CTL);
> >
> > -	clk = clk_register(NULL, &pll->hw);
> > -	if (IS_ERR(clk)) {
> > -		pr_err("%s: failed to register pll %s %lu\n",
> > -			__func__, name, PTR_ERR(clk));
> > +	hw = &pll->hw;
> > +
> > +	ret = clk_hw_register(NULL, hw);
> > +	if (ret) {
> > +		pr_err("%s: failed to register pll %s %d\n",
> > +			__func__, name, ret);
> >  		kfree(pll);
> > +		return ERR_PTR(ret);
> >  	}
> >
> > -	return clk;
> > +	return hw;
> >  }
> > diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index
> > bc5bb6ac8636..5038622f1a72 100644
> > --- a/drivers/clk/imx/clk.h
> > +++ b/drivers/clk/imx/clk.h
> > @@ -97,8 +97,12 @@ extern struct imx_pll14xx_clk imx_1443x_pll;
> > #define imx_clk_mux(name, reg, shift, width, parents, num_parents) \
> >  	imx_clk_hw_mux(name, reg, shift, width, parents, num_parents)->clk
> >
> > -struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
> > -		 void __iomem *base, const struct imx_pll14xx_clk *pll_clk);
> > +#define imx_clk_pll14xx(name, parent_name, base, pll_clk) \
> > +	imx_clk_hw_pll14xx(name, parent_name, base, pll_clk)->clk
> > +
> 
> I would suggest to use an inline function for this, which will be more readable
> and complying to kernel coding style.

ok, I'll send out v2.

Thanks,
Peng.

> 
> Shawn
> 
> > +struct clk_hw *imx_clk_hw_pll14xx(const char *name, const char
> *parent_name,
> > +				  void __iomem *base,
> > +				  const struct imx_pll14xx_clk *pll_clk);
> >
> >  struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name,
> >  		const char *parent, void __iomem *base);
> > --
> > 2.16.4
> >
Leonard Crestez Dec. 2, 2019, 5:07 a.m. UTC | #3
On 2019-12-02 4:26 AM, Peng Fan wrote:
>> Subject: Re: [PATCH 1/7] clk: imx: clk-pll14xx: Switch to clk_hw based API
>> On Tue, Oct 29, 2019 at 01:40:54PM +0000, Peng Fan wrote:
>>> From: Peng Fan <peng.fan@nxp.com>
>>>
>>> Switch the imx_clk_pll14xx function to clk_hw based API, rename
>>> accordingly and add a macro for clk based legacy. This allows us to
>>> move closer to a clear split between consumer and provider clk APIs.
>>>
>>> diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index
>>> bc5bb6ac8636..5038622f1a72 100644
>>> --- a/drivers/clk/imx/clk.h
>>> +++ b/drivers/clk/imx/clk.h
>>> @@ -97,8 +97,12 @@ extern struct imx_pll14xx_clk imx_1443x_pll;
>>> #define imx_clk_mux(name, reg, shift, width, parents, num_parents) \
>>>   	imx_clk_hw_mux(name, reg, shift, width, parents, num_parents)->clk
>>>
>>> -struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
>>> -		 void __iomem *base, const struct imx_pll14xx_clk *pll_clk);
>>> +#define imx_clk_pll14xx(name, parent_name, base, pll_clk) \
>>> +	imx_clk_hw_pll14xx(name, parent_name, base, pll_clk)->clk
>>> +
>>
>> I would suggest to use an inline function for this, which will be more readable
>> and complying to kernel coding style.
> 
> ok, I'll send out v2.

Blindly dereferencing ->clk will crash instead of propagating errors so 
you might want to use the to_clk helper from here:

https://patchwork.kernel.org/patch/11257811/

--
Regards,
Leonard
Peng Fan Dec. 2, 2019, 5:11 a.m. UTC | #4
> Subject: Re: [PATCH 1/7] clk: imx: clk-pll14xx: Switch to clk_hw based API
> 
> On 2019-12-02 4:26 AM, Peng Fan wrote:
> >> Subject: Re: [PATCH 1/7] clk: imx: clk-pll14xx: Switch to clk_hw
> >> based API On Tue, Oct 29, 2019 at 01:40:54PM +0000, Peng Fan wrote:
> >>> From: Peng Fan <peng.fan@nxp.com>
> >>>
> >>> Switch the imx_clk_pll14xx function to clk_hw based API, rename
> >>> accordingly and add a macro for clk based legacy. This allows us to
> >>> move closer to a clear split between consumer and provider clk APIs.
> >>>
> >>> diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h index
> >>> bc5bb6ac8636..5038622f1a72 100644
> >>> --- a/drivers/clk/imx/clk.h
> >>> +++ b/drivers/clk/imx/clk.h
> >>> @@ -97,8 +97,12 @@ extern struct imx_pll14xx_clk imx_1443x_pll;
> >>> #define imx_clk_mux(name, reg, shift, width, parents, num_parents) \
> >>>   	imx_clk_hw_mux(name, reg, shift, width, parents,
> >>> num_parents)->clk
> >>>
> >>> -struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
> >>> -		 void __iomem *base, const struct imx_pll14xx_clk *pll_clk);
> >>> +#define imx_clk_pll14xx(name, parent_name, base, pll_clk) \
> >>> +	imx_clk_hw_pll14xx(name, parent_name, base, pll_clk)->clk
> >>> +
> >>
> >> I would suggest to use an inline function for this, which will be
> >> more readable and complying to kernel coding style.
> >
> > ok, I'll send out v2.
> 
> Blindly dereferencing ->clk will crash instead of propagating errors so you
> might want to use the to_clk helper from here:
> 
> https://patchwork.kernel.org/patch/11257811/

I not see Abel's patch applied, should I include Abel's patchset in my v2?
Or I posted out my v2 with only my changes based on Abel's patchset?

Thanks,
Peng.

> 
> --
> Regards,
> Leonard
diff mbox series

Patch

diff --git a/drivers/clk/imx/clk-pll14xx.c b/drivers/clk/imx/clk-pll14xx.c
index 5c458199060a..fa76e04251c4 100644
--- a/drivers/clk/imx/clk-pll14xx.c
+++ b/drivers/clk/imx/clk-pll14xx.c
@@ -369,13 +369,14 @@  static const struct clk_ops clk_pll1443x_ops = {
 	.set_rate	= clk_pll1443x_set_rate,
 };
 
-struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
-			    void __iomem *base,
-			    const struct imx_pll14xx_clk *pll_clk)
+struct clk_hw *imx_clk_hw_pll14xx(const char *name, const char *parent_name,
+				  void __iomem *base,
+				  const struct imx_pll14xx_clk *pll_clk)
 {
 	struct clk_pll14xx *pll;
-	struct clk *clk;
+	struct clk_hw *hw;
 	struct clk_init_data init;
+	int ret;
 	u32 val;
 
 	pll = kzalloc(sizeof(*pll), GFP_KERNEL);
@@ -412,12 +413,15 @@  struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
 	val &= ~BYPASS_MASK;
 	writel_relaxed(val, pll->base + GNRL_CTL);
 
-	clk = clk_register(NULL, &pll->hw);
-	if (IS_ERR(clk)) {
-		pr_err("%s: failed to register pll %s %lu\n",
-			__func__, name, PTR_ERR(clk));
+	hw = &pll->hw;
+
+	ret = clk_hw_register(NULL, hw);
+	if (ret) {
+		pr_err("%s: failed to register pll %s %d\n",
+			__func__, name, ret);
 		kfree(pll);
+		return ERR_PTR(ret);
 	}
 
-	return clk;
+	return hw;
 }
diff --git a/drivers/clk/imx/clk.h b/drivers/clk/imx/clk.h
index bc5bb6ac8636..5038622f1a72 100644
--- a/drivers/clk/imx/clk.h
+++ b/drivers/clk/imx/clk.h
@@ -97,8 +97,12 @@  extern struct imx_pll14xx_clk imx_1443x_pll;
 #define imx_clk_mux(name, reg, shift, width, parents, num_parents) \
 	imx_clk_hw_mux(name, reg, shift, width, parents, num_parents)->clk
 
-struct clk *imx_clk_pll14xx(const char *name, const char *parent_name,
-		 void __iomem *base, const struct imx_pll14xx_clk *pll_clk);
+#define imx_clk_pll14xx(name, parent_name, base, pll_clk) \
+	imx_clk_hw_pll14xx(name, parent_name, base, pll_clk)->clk
+
+struct clk_hw *imx_clk_hw_pll14xx(const char *name, const char *parent_name,
+				  void __iomem *base,
+				  const struct imx_pll14xx_clk *pll_clk);
 
 struct clk *imx_clk_pllv1(enum imx_pllv1_type type, const char *name,
 		const char *parent, void __iomem *base);