mbox series

[v4,0/5] Add clock drivers for SM8350

Message ID 20210118044321.2571775-1-vkoul@kernel.org
Headers show
Series Add clock drivers for SM8350 | expand

Message

Vinod Koul Jan. 18, 2021, 4:43 a.m. UTC
This adds gcc clock controller drivers for the controller found
in SM8350 SoC

Changes in v4:
 - Add Ack from Rob on binding
 - modularize alpha_pll_trion_set_rate()

Changes in v3:
 - Drop rpmh clk patches applied
 - Add a new patch to replace regval with val as suggested by Stephen
 - Fix comments for new Lucid 5LPE PLL: sort new defines by BIT numbers, fix
   comments, use alpha_pll_check_rate_margin(), rework
   clk_lucid_5lpe_pll_postdiv_set_rate() logic
 - Add power domains and optional clocks in bindings
 - Fix comments for gcc sm8350 driver: clean includes used, use only
   .fw_name for clocks defined in DT, use floor ops for sdcc clocks, remove
   critical clocks and enable them in probe, add comments for clks using
   BRANCH_HALT_SKIP and BRANCH_HALT_DELAY

Changes in v2:
 - Add r-b from Bjorn
 - Add the gcc_qupv3_wrap_1_{m|s}_ahb_clk and gcc_qupv3_wrap1_s5_clk

Vinod Koul (3):
  clk: qcom: clk-alpha-pll: replace regval with val
  clk: qcom: clk-alpha-pll: modularize alpha_pll_trion_set_rate()
  dt-bindings: clock: Add SM8350 GCC clock bindings

Vivek Aknurwar (2):
  clk: qcom: clk-alpha-pll: Add support for Lucid 5LPE PLL
  clk: qcom: gcc: Add clock driver for SM8350

 .../bindings/clock/qcom,gcc-sm8350.yaml       |   96 +
 drivers/clk/qcom/Kconfig                      |    8 +
 drivers/clk/qcom/Makefile                     |    1 +
 drivers/clk/qcom/clk-alpha-pll.c              |  209 +-
 drivers/clk/qcom/clk-alpha-pll.h              |    4 +
 drivers/clk/qcom/gcc-sm8350.c                 | 3790 +++++++++++++++++
 include/dt-bindings/clock/qcom,gcc-sm8350.h   |  261 ++
 7 files changed, 4353 insertions(+), 16 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/clock/qcom,gcc-sm8350.yaml
 create mode 100644 drivers/clk/qcom/gcc-sm8350.c
 create mode 100644 include/dt-bindings/clock/qcom,gcc-sm8350.h

-- 
2.26.2

Comments

AngeloGioacchino Del Regno Jan. 19, 2021, 9:54 p.m. UTC | #1
Il 18/01/21 05:43, Vinod Koul ha scritto:
> From: Vivek Aknurwar <viveka@codeaurora.org>

> 

> Lucid 5LPE is a slightly different Lucid PLL with different offsets and

> porgramming sequence so add support for these

> 

> Signed-off-by: Vivek Aknurwar <viveka@codeaurora.org>

> Signed-off-by: Jeevan Shriram <jshriram@codeaurora.org>

> [vkoul: rebase and tidy up for upstream]

> Signed-off-by: Vinod Koul <vkoul@kernel.org>

> ---

>   drivers/clk/qcom/clk-alpha-pll.c | 173 +++++++++++++++++++++++++++++++

>   drivers/clk/qcom/clk-alpha-pll.h |   4 +

>   2 files changed, 177 insertions(+)

> 

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

> index a30ea7b09224..f9c48da21bd1 100644

> --- a/drivers/clk/qcom/clk-alpha-pll.c

> +++ b/drivers/clk/qcom/clk-alpha-pll.c

> @@ -156,6 +156,12 @@ EXPORT_SYMBOL_GPL(clk_alpha_pll_regs);

>   /* LUCID PLL specific settings and offsets */

>   #define LUCID_PCAL_DONE		BIT(27)

>   

> +/* LUCID 5LPE PLL specific settings and offsets */

> +#define LUCID_5LPE_PCAL_DONE		BIT(11)

> +#define LUCID_5LPE_ALPHA_PLL_ACK_LATCH	BIT(13)

> +#define LUCID_5LPE_PLL_LATCH_INPUT	BIT(14)

> +#define LUCID_5LPE_ENABLE_VOTE_RUN	BIT(21)

> +

>   #define pll_alpha_width(p)					\

>   		((PLL_ALPHA_VAL_U(p) - PLL_ALPHA_VAL(p) == 4) ?	\

>   				 ALPHA_REG_BITWIDTH : ALPHA_REG_16BIT_WIDTH)

> @@ -1604,3 +1610,170 @@ const struct clk_ops clk_alpha_pll_agera_ops = {

>   	.set_rate = clk_alpha_pll_agera_set_rate,

>   };

>   EXPORT_SYMBOL_GPL(clk_alpha_pll_agera_ops);

> +

> +static int alpha_pll_lucid_5lpe_enable(struct clk_hw *hw)

> +{

> +	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);

> +	u32 val;

> +	int ret;

> +

> +	ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val);

> +	if (ret)

> +		return ret;

> +

> +	/* If in FSM mode, just vote for it */

> +	if (val & LUCID_5LPE_ENABLE_VOTE_RUN) {

> +		ret = clk_enable_regmap(hw);

> +		if (ret)

> +			return ret;

> +		return wait_for_pll_enable_lock(pll);

> +	}

> +

> +	/* Check if PLL is already enabled, return if enabled */

> +	ret = trion_pll_is_enabled(pll, pll->clkr.regmap);

> +	if (ret < 0)

> +		return ret;

> +

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_RESET_N, PLL_RESET_N);

> +	if (ret)

> +		return ret;

> +

> +	regmap_write(pll->clkr.regmap, PLL_OPMODE(pll), PLL_RUN);

> +

> +	ret = wait_for_pll_enable_lock(pll);

> +	if (ret)

> +		return ret;

> +

> +	/* Enable the PLL outputs */

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), PLL_OUT_MASK, PLL_OUT_MASK);

> +	if (ret)

> +		return ret;

> +

> +	/* Enable the global PLL outputs */

> +	return regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_OUTCTRL, PLL_OUTCTRL);

> +}

> +

> +static void alpha_pll_lucid_5lpe_disable(struct clk_hw *hw)

> +{

> +	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);

> +	u32 val;

> +	int ret;

> +

> +	ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val);

> +	if (ret)

> +		return;

> +

> +	/* If in FSM mode, just unvote it */

> +	if (val & LUCID_5LPE_ENABLE_VOTE_RUN) {

> +		clk_disable_regmap(hw);

> +		return;

> +	}

> +

> +	/* Disable the global PLL output */

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_OUTCTRL, 0);

> +	if (ret)

> +		return;

> +

> +	/* Disable the PLL outputs */

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), PLL_OUT_MASK, 0);

> +	if (ret)

> +		return;

> +

> +	/* Place the PLL mode in STANDBY */

> +	regmap_write(pll->clkr.regmap, PLL_OPMODE(pll), PLL_STANDBY);

> +}

> +

> +/*

> + * The Lucid 5LPE PLL requires a power-on self-calibration which happens

> + * when the PLL comes out of reset. Calibrate in case it is not completed.

> + */

> +static int alpha_pll_lucid_5lpe_prepare(struct clk_hw *hw)

> +{

> +	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);

> +	struct clk_hw *p;

> +	u32 val;

> +	int ret;

> +

> +	/* Return early if calibration is not needed. */

> +	regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);

> +	if (val & LUCID_5LPE_PCAL_DONE)

> +		return 0;

> +

> +	p = clk_hw_get_parent(hw);

> +	if (!p)

> +		return -EINVAL;

> +

> +	ret = alpha_pll_lucid_5lpe_enable(hw);

> +	if (ret)

> +		return ret;

> +

> +	alpha_pll_lucid_5lpe_disable(hw);

> +

> +	return 0;

> +}

> +

> +static int alpha_pll_lucid_5lpe_set_rate(struct clk_hw *hw, unsigned long rate,

> +					 unsigned long prate)

> +{

> +	return __alpha_pll_trion_set_rate(hw, rate, prate,

> +					  LUCID_5LPE_PLL_LATCH_INPUT,

> +					  LUCID_5LPE_ALPHA_PLL_ACK_LATCH);

> +}

> +

> +static int clk_lucid_5lpe_pll_postdiv_set_rate(struct clk_hw *hw, unsigned long rate,

> +					       unsigned long parent_rate)

> +{

> +	struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw);

> +	int i, val = 0, div, ret;

> +	u32 mask;

> +

> +	/*

> +	 * If the PLL is in FSM mode, then treat set_rate callback as a

> +	 * no-operation.

> +	 */

> +	ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val);

> +	if (ret)

> +		return ret;

> +

> +	if (val & LUCID_5LPE_ENABLE_VOTE_RUN)

> +		return 0;

> +

> +	div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);

> +	for (i = 0; i < pll->num_post_div; i++) {

> +		if (pll->post_div_table[i].div == div) {

> +			val = pll->post_div_table[i].val;

> +			break;

> +		}

> +	}

> +

> +	mask = GENMASK(pll->width + pll->post_div_shift - 1, pll->post_div_shift);

> +	return regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll),

> +				  mask, val << pll->post_div_shift);

> +}

> +

> +const struct clk_ops clk_alpha_pll_lucid_5lpe_ops = {

> +	.prepare = alpha_pll_lucid_5lpe_prepare,

> +	.enable = alpha_pll_lucid_5lpe_enable,

> +	.disable = alpha_pll_lucid_5lpe_disable,

> +	.is_enabled = clk_trion_pll_is_enabled,

> +	.recalc_rate = clk_trion_pll_recalc_rate,

> +	.round_rate = clk_alpha_pll_round_rate,

> +	.set_rate = alpha_pll_lucid_5lpe_set_rate,

> +};

> +EXPORT_SYMBOL(clk_alpha_pll_lucid_5lpe_ops);

> +

> +const struct clk_ops clk_alpha_pll_fixed_lucid_5lpe_ops = {

> +	.enable = alpha_pll_lucid_5lpe_enable,

> +	.disable = alpha_pll_lucid_5lpe_disable,

> +	.is_enabled = clk_trion_pll_is_enabled,

> +	.recalc_rate = clk_trion_pll_recalc_rate,

> +	.round_rate = clk_alpha_pll_round_rate,

> +};

> +EXPORT_SYMBOL(clk_alpha_pll_fixed_lucid_5lpe_ops);

> +

> +const struct clk_ops clk_alpha_pll_postdiv_lucid_5lpe_ops = {

> +	.recalc_rate = clk_alpha_pll_postdiv_fabia_recalc_rate,

> +	.round_rate = clk_alpha_pll_postdiv_fabia_round_rate,

> +	.set_rate = clk_lucid_5lpe_pll_postdiv_set_rate,

> +};

> +EXPORT_SYMBOL(clk_alpha_pll_postdiv_lucid_5lpe_ops);

> diff --git a/drivers/clk/qcom/clk-alpha-pll.h b/drivers/clk/qcom/clk-alpha-pll.h

> index 0ea30d2f3da1..6943e933be0f 100644

> --- a/drivers/clk/qcom/clk-alpha-pll.h

> +++ b/drivers/clk/qcom/clk-alpha-pll.h

> @@ -144,6 +144,10 @@ extern const struct clk_ops clk_alpha_pll_lucid_ops;

>   extern const struct clk_ops clk_alpha_pll_postdiv_lucid_ops;

>   extern const struct clk_ops clk_alpha_pll_agera_ops;

>   

> +extern const struct clk_ops clk_alpha_pll_lucid_5lpe_ops;

> +extern const struct clk_ops clk_alpha_pll_fixed_lucid_5lpe_ops;

> +extern const struct clk_ops clk_alpha_pll_postdiv_lucid_5lpe_ops;

> +

>   void clk_alpha_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,

>   			     const struct alpha_pll_config *config);

>   void clk_fabia_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,

> 


Thanks for following my suggestion!

Reviewed-by: AngeloGioacchino Del Regno 

<angelogioacchino.delregno@somainline.org>
Bjorn Andersson Jan. 25, 2021, 5:18 p.m. UTC | #2
On Sun 17 Jan 22:43 CST 2021, Vinod Koul wrote:

> From: Vivek Aknurwar <viveka@codeaurora.org>

> 

> Lucid 5LPE is a slightly different Lucid PLL with different offsets and

> porgramming sequence so add support for these

> 

> Signed-off-by: Vivek Aknurwar <viveka@codeaurora.org>

> Signed-off-by: Jeevan Shriram <jshriram@codeaurora.org>

> [vkoul: rebase and tidy up for upstream]

> Signed-off-by: Vinod Koul <vkoul@kernel.org>

> ---

>  drivers/clk/qcom/clk-alpha-pll.c | 173 +++++++++++++++++++++++++++++++

>  drivers/clk/qcom/clk-alpha-pll.h |   4 +

>  2 files changed, 177 insertions(+)

> 

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

> index a30ea7b09224..f9c48da21bd1 100644

> --- a/drivers/clk/qcom/clk-alpha-pll.c

> +++ b/drivers/clk/qcom/clk-alpha-pll.c

> @@ -156,6 +156,12 @@ EXPORT_SYMBOL_GPL(clk_alpha_pll_regs);

>  /* LUCID PLL specific settings and offsets */

>  #define LUCID_PCAL_DONE		BIT(27)

>  

> +/* LUCID 5LPE PLL specific settings and offsets */

> +#define LUCID_5LPE_PCAL_DONE		BIT(11)

> +#define LUCID_5LPE_ALPHA_PLL_ACK_LATCH	BIT(13)

> +#define LUCID_5LPE_PLL_LATCH_INPUT	BIT(14)

> +#define LUCID_5LPE_ENABLE_VOTE_RUN	BIT(21)

> +

>  #define pll_alpha_width(p)					\

>  		((PLL_ALPHA_VAL_U(p) - PLL_ALPHA_VAL(p) == 4) ?	\

>  				 ALPHA_REG_BITWIDTH : ALPHA_REG_16BIT_WIDTH)

> @@ -1604,3 +1610,170 @@ const struct clk_ops clk_alpha_pll_agera_ops = {

>  	.set_rate = clk_alpha_pll_agera_set_rate,

>  };

>  EXPORT_SYMBOL_GPL(clk_alpha_pll_agera_ops);

> +

> +static int alpha_pll_lucid_5lpe_enable(struct clk_hw *hw)

> +{

> +	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);

> +	u32 val;

> +	int ret;

> +

> +	ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val);

> +	if (ret)

> +		return ret;

> +

> +	/* If in FSM mode, just vote for it */

> +	if (val & LUCID_5LPE_ENABLE_VOTE_RUN) {

> +		ret = clk_enable_regmap(hw);

> +		if (ret)

> +			return ret;

> +		return wait_for_pll_enable_lock(pll);

> +	}

> +

> +	/* Check if PLL is already enabled, return if enabled */

> +	ret = trion_pll_is_enabled(pll, pll->clkr.regmap);

> +	if (ret < 0)

> +		return ret;

> +

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_RESET_N, PLL_RESET_N);

> +	if (ret)

> +		return ret;

> +

> +	regmap_write(pll->clkr.regmap, PLL_OPMODE(pll), PLL_RUN);

> +

> +	ret = wait_for_pll_enable_lock(pll);

> +	if (ret)

> +		return ret;

> +

> +	/* Enable the PLL outputs */

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), PLL_OUT_MASK, PLL_OUT_MASK);

> +	if (ret)

> +		return ret;

> +

> +	/* Enable the global PLL outputs */

> +	return regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_OUTCTRL, PLL_OUTCTRL);

> +}

> +

> +static void alpha_pll_lucid_5lpe_disable(struct clk_hw *hw)

> +{

> +	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);

> +	u32 val;

> +	int ret;

> +

> +	ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val);

> +	if (ret)

> +		return;

> +

> +	/* If in FSM mode, just unvote it */

> +	if (val & LUCID_5LPE_ENABLE_VOTE_RUN) {

> +		clk_disable_regmap(hw);

> +		return;

> +	}

> +

> +	/* Disable the global PLL output */

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_OUTCTRL, 0);

> +	if (ret)

> +		return;

> +

> +	/* Disable the PLL outputs */

> +	ret = regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), PLL_OUT_MASK, 0);

> +	if (ret)

> +		return;

> +

> +	/* Place the PLL mode in STANDBY */

> +	regmap_write(pll->clkr.regmap, PLL_OPMODE(pll), PLL_STANDBY);

> +}

> +

> +/*

> + * The Lucid 5LPE PLL requires a power-on self-calibration which happens

> + * when the PLL comes out of reset. Calibrate in case it is not completed.

> + */

> +static int alpha_pll_lucid_5lpe_prepare(struct clk_hw *hw)

> +{

> +	struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);

> +	struct clk_hw *p;

> +	u32 val;

> +	int ret;

> +

> +	/* Return early if calibration is not needed. */

> +	regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);


I doubt this will ever fail, but static analysis tools would complain
about val possibly being uninitialized after this.

And the return value is checked in the other functions.

Regards,
Bjorn

> +	if (val & LUCID_5LPE_PCAL_DONE)

> +		return 0;

> +

> +	p = clk_hw_get_parent(hw);

> +	if (!p)

> +		return -EINVAL;

> +

> +	ret = alpha_pll_lucid_5lpe_enable(hw);

> +	if (ret)

> +		return ret;

> +

> +	alpha_pll_lucid_5lpe_disable(hw);

> +

> +	return 0;

> +}

> +

> +static int alpha_pll_lucid_5lpe_set_rate(struct clk_hw *hw, unsigned long rate,

> +					 unsigned long prate)

> +{

> +	return __alpha_pll_trion_set_rate(hw, rate, prate,

> +					  LUCID_5LPE_PLL_LATCH_INPUT,

> +					  LUCID_5LPE_ALPHA_PLL_ACK_LATCH);

> +}

> +

> +static int clk_lucid_5lpe_pll_postdiv_set_rate(struct clk_hw *hw, unsigned long rate,

> +					       unsigned long parent_rate)

> +{

> +	struct clk_alpha_pll_postdiv *pll = to_clk_alpha_pll_postdiv(hw);

> +	int i, val = 0, div, ret;

> +	u32 mask;

> +

> +	/*

> +	 * If the PLL is in FSM mode, then treat set_rate callback as a

> +	 * no-operation.

> +	 */

> +	ret = regmap_read(pll->clkr.regmap, PLL_USER_CTL(pll), &val);

> +	if (ret)

> +		return ret;

> +

> +	if (val & LUCID_5LPE_ENABLE_VOTE_RUN)

> +		return 0;

> +

> +	div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);

> +	for (i = 0; i < pll->num_post_div; i++) {

> +		if (pll->post_div_table[i].div == div) {

> +			val = pll->post_div_table[i].val;

> +			break;

> +		}

> +	}

> +

> +	mask = GENMASK(pll->width + pll->post_div_shift - 1, pll->post_div_shift);

> +	return regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll),

> +				  mask, val << pll->post_div_shift);

> +}

> +

> +const struct clk_ops clk_alpha_pll_lucid_5lpe_ops = {

> +	.prepare = alpha_pll_lucid_5lpe_prepare,

> +	.enable = alpha_pll_lucid_5lpe_enable,

> +	.disable = alpha_pll_lucid_5lpe_disable,

> +	.is_enabled = clk_trion_pll_is_enabled,

> +	.recalc_rate = clk_trion_pll_recalc_rate,

> +	.round_rate = clk_alpha_pll_round_rate,

> +	.set_rate = alpha_pll_lucid_5lpe_set_rate,

> +};

> +EXPORT_SYMBOL(clk_alpha_pll_lucid_5lpe_ops);

> +

> +const struct clk_ops clk_alpha_pll_fixed_lucid_5lpe_ops = {

> +	.enable = alpha_pll_lucid_5lpe_enable,

> +	.disable = alpha_pll_lucid_5lpe_disable,

> +	.is_enabled = clk_trion_pll_is_enabled,

> +	.recalc_rate = clk_trion_pll_recalc_rate,

> +	.round_rate = clk_alpha_pll_round_rate,

> +};

> +EXPORT_SYMBOL(clk_alpha_pll_fixed_lucid_5lpe_ops);

> +

> +const struct clk_ops clk_alpha_pll_postdiv_lucid_5lpe_ops = {

> +	.recalc_rate = clk_alpha_pll_postdiv_fabia_recalc_rate,

> +	.round_rate = clk_alpha_pll_postdiv_fabia_round_rate,

> +	.set_rate = clk_lucid_5lpe_pll_postdiv_set_rate,

> +};

> +EXPORT_SYMBOL(clk_alpha_pll_postdiv_lucid_5lpe_ops);

> diff --git a/drivers/clk/qcom/clk-alpha-pll.h b/drivers/clk/qcom/clk-alpha-pll.h

> index 0ea30d2f3da1..6943e933be0f 100644

> --- a/drivers/clk/qcom/clk-alpha-pll.h

> +++ b/drivers/clk/qcom/clk-alpha-pll.h

> @@ -144,6 +144,10 @@ extern const struct clk_ops clk_alpha_pll_lucid_ops;

>  extern const struct clk_ops clk_alpha_pll_postdiv_lucid_ops;

>  extern const struct clk_ops clk_alpha_pll_agera_ops;

>  

> +extern const struct clk_ops clk_alpha_pll_lucid_5lpe_ops;

> +extern const struct clk_ops clk_alpha_pll_fixed_lucid_5lpe_ops;

> +extern const struct clk_ops clk_alpha_pll_postdiv_lucid_5lpe_ops;

> +

>  void clk_alpha_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,

>  			     const struct alpha_pll_config *config);

>  void clk_fabia_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,

> -- 

> 2.26.2

>