From: Taniya Das <quic_tdas@quicinc.com>
To: Bjorn Andersson <andersson@kernel.org>
Cc: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Ajit Pandey <quic_ajipan@quicinc.com>,
Imran Shaik <quic_imrashai@quicinc.com>,
"Jagadeesh Kona" <quic_jkona@quicinc.com>,
<linux-arm-msm@vger.kernel.org>, <linux-clk@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v6 01/10] clk: qcom: clk-alpha-pll: Add support for dynamic update for slewing PLLs
Date: Mon, 17 Mar 2025 12:10:13 +0530 [thread overview]
Message-ID: <fce2fe9e-5c1b-4fa9-b6ca-0a4ab5133e5a@quicinc.com> (raw)
In-Reply-To: <r6xikx2idlzwc4xl7doap3v5ug3a6qtg65jwqjuekiv7tvbwzn@5nk4c7nl2zws>
On 3/14/2025 5:09 AM, Bjorn Andersson wrote:
> On Thu, Mar 13, 2025 at 12:29:38PM +0530, Taniya Das wrote:
>> The alpha PLLs which slew to a new frequency at runtime would require
>> the PLL to calibrate at the mid point of the VCO. Add the new PLL ops
>> which can support the slewing of the PLL to a new frequency.
>>
>> Reviewed-by: Imran Shaik <quic_imrashai@quicinc.com>
>> Signed-off-by: Taniya Das <quic_tdas@quicinc.com>
>> ---
>> drivers/clk/qcom/clk-alpha-pll.c | 170 +++++++++++++++++++++++++++++++++++++++
>> drivers/clk/qcom/clk-alpha-pll.h | 1 +
>> 2 files changed, 171 insertions(+)
>>
>> diff --git a/drivers/clk/qcom/clk-alpha-pll.c b/drivers/clk/qcom/clk-alpha-pll.c
>> index cec0afea8e446010f0d4140d4ef63121706dde47..7d784db8b7441e886d94ded1d3e3258dda46674c 100644
>> --- a/drivers/clk/qcom/clk-alpha-pll.c
>> +++ b/drivers/clk/qcom/clk-alpha-pll.c
>> @@ -2960,3 +2960,173 @@ const struct clk_ops clk_alpha_pll_regera_ops = {
>> .set_rate = clk_zonda_pll_set_rate,
>> };
>> EXPORT_SYMBOL_GPL(clk_alpha_pll_regera_ops);
>> +
>> +static int clk_alpha_pll_slew_update(struct clk_alpha_pll *pll)
>> +{
>> + int ret;
>> + u32 val;
>> +
>> + regmap_update_bits(pll->clkr.regmap, PLL_MODE(pll), PLL_UPDATE, PLL_UPDATE);
>> + regmap_read(pll->clkr.regmap, PLL_MODE(pll), &val);
>> +
>> + ret = wait_for_pll_update(pll);
>> + if (ret)
>> + return ret;
>> + /*
>> + * Hardware programming mandates a wait of at least 570ns before polling the LOCK
>> + * detect bit. Have a delay of 1us just to be safe.
>> + */
>> + mb();
>> + udelay(1);
>> +
>> + return wait_for_pll_enable_lock(pll);
>> +}
>> +
>> +static int clk_alpha_pll_slew_set_rate(struct clk_hw *hw, unsigned long rate,
>> + unsigned long parent_rate)
>> +{
>> + struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
>> + unsigned long freq_hz;
>> + const struct pll_vco *curr_vco, *vco;
>> + u32 l, alpha_width = pll_alpha_width(pll);
>> + u64 a;
>> +
>> + freq_hz = alpha_pll_round_rate(rate, parent_rate, &l, &a, alpha_width);
>
> Double space here.
Sure, needs a fix.
>
>> + if (freq_hz != rate) {
>> + pr_err("alpha_pll: Call clk_set_rate with rounded rates!\n");
>> + return -EINVAL;
>> + }
>> +
>> + curr_vco = alpha_pll_find_vco(pll, clk_hw_get_rate(hw));
>> + if (!curr_vco) {
>> + pr_err("alpha pll: not in a valid vco range\n");
>> + return -EINVAL;
>> + }
>> +
>> + vco = alpha_pll_find_vco(pll, freq_hz);
>> + if (!vco) {
>> + pr_err("alpha pll: not in a valid vco range\n");
>> + return -EINVAL;
>> + }
>> +
>> + /*
>> + * Dynamic pll update will not support switching frequencies across
>> + * vco ranges. In those cases fall back to normal alpha set rate.
>> + */
>> + if (curr_vco->val != vco->val)
>> + return clk_alpha_pll_set_rate(hw, rate, parent_rate);
>> +
>> + a = a << (ALPHA_REG_BITWIDTH - ALPHA_BITWIDTH);
>
> Above this function is written to deal with both alpha bitwidths, but
> here it's assumed to only be one of the cases.
>
> It would be nice to get this cleaned up somehow, because we now have
> this shift 6 times in slightly different forms.
>
I will check if I can clean up.
>> +
>> + regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l);
>> + regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), a);
>> + regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL_U(pll), a >> 32);
>
> In a number of places in the driver alpha_width is compared to 32 bits
> to see if this should be written or not. Perhaps that's not applicable
> here, but again, if so then why is it dynamic above?
>
>
> Also, how about upper_32_bits() and lower_32_bits() to make it clear
> what's going on here?
>
Sure.
>> +
>> + /* Ensure that the write above goes through before proceeding. */
>
> That's not what mb() does.
>
> Regards,
> Bjorn
>
>> + mb();
>> +
>> + if (clk_hw_is_enabled(hw))
>> + return clk_alpha_pll_slew_update(pll);
>> +
>> + return 0;
>> +}
>> +
>> +/*
>> + * Slewing plls should be bought up at frequency which is in the middle of the
>> + * desired VCO range. So after bringing up the pll at calibration freq, set it
>> + * back to desired frequency(that was set by previous clk_set_rate).
>> + */
>> +static int clk_alpha_pll_calibrate(struct clk_hw *hw)
>> +{
>> + unsigned long calibration_freq, freq_hz;
>> + struct clk_alpha_pll *pll = to_clk_alpha_pll(hw);
>> + struct clk_hw *parent;
>> + const struct pll_vco *vco;
>> + u32 l, alpha_width = pll_alpha_width(pll);
>> + int rc;
>> + u64 a;
>> +
>> + parent = clk_hw_get_parent(hw);
>> + if (!parent) {
>> + pr_err("alpha pll: no valid parent found\n");
>> + return -EINVAL;
>> + }
>> +
>> + vco = alpha_pll_find_vco(pll, clk_hw_get_rate(hw));
>> + if (!vco) {
>> + pr_err("alpha pll: not in a valid vco range\n");
>> + return -EINVAL;
>> + }
>> +
>> + /*
>> + * As during slewing plls vco_sel won't be allowed to change, vco table
>> + * should have only one entry table, i.e. index = 0, find the
>> + * calibration frequency.
>> + */
>> + calibration_freq = (pll->vco_table[0].min_freq + pll->vco_table[0].max_freq) / 2;
>> +
>> + freq_hz = alpha_pll_round_rate(calibration_freq, clk_hw_get_rate(parent),
>> + &l, &a, alpha_width);
>> + if (freq_hz != calibration_freq) {
>> + pr_err("alpha_pll: call clk_set_rate with rounded rates!\n");
>> + return -EINVAL;
>> + }
>> +
>> + /* Setup PLL for calibration frequency */
>> + a <<= (ALPHA_REG_BITWIDTH - ALPHA_BITWIDTH);
>> +
>> + regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l);
>> + regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), a);
>> + regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL_U(pll), a >> 32);
>> +
>> + regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), PLL_VCO_MASK << PLL_VCO_SHIFT,
>> + vco->val << PLL_VCO_SHIFT);
>> +
>> + /* Bringup the pll at calibration frequency */
>> + rc = clk_alpha_pll_enable(hw);
>> + if (rc) {
>> + pr_err("alpha pll calibration failed\n");
>> + return rc;
>> + }
>> +
>> + /*
>> + * PLL is already running at calibration frequency.
>> + * So slew pll to the previously set frequency.
>> + */
>> + freq_hz = alpha_pll_round_rate(clk_hw_get_rate(hw),
>> + clk_hw_get_rate(parent), &l, &a, alpha_width);
>> +
>> + pr_debug("pll %s: setting back to required rate %lu, freq_hz %ld\n",
>> + clk_hw_get_name(hw), clk_hw_get_rate(hw), freq_hz);
>> +
>> + /* Setup the PLL for the new frequency */
>> + a <<= (ALPHA_REG_BITWIDTH - ALPHA_BITWIDTH);
>> +
>> + regmap_write(pll->clkr.regmap, PLL_L_VAL(pll), l);
>> + regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL(pll), a);
>> + regmap_write(pll->clkr.regmap, PLL_ALPHA_VAL_U(pll), a >> 32);
>> +
>> + regmap_update_bits(pll->clkr.regmap, PLL_USER_CTL(pll), PLL_ALPHA_EN, PLL_ALPHA_EN);
>> +
>> + return clk_alpha_pll_slew_update(pll);
>> +}
>> +
>> +static int clk_alpha_pll_slew_enable(struct clk_hw *hw)
>> +{
>> + int rc;
>> +
>> + rc = clk_alpha_pll_calibrate(hw);
>> + if (rc)
>> + return rc;
>> +
>> + return clk_alpha_pll_enable(hw);
>> +}
>> +
>> +const struct clk_ops clk_alpha_pll_slew_ops = {
>> + .enable = clk_alpha_pll_slew_enable,
>> + .disable = clk_alpha_pll_disable,
>> + .recalc_rate = clk_alpha_pll_recalc_rate,
>> + .round_rate = clk_alpha_pll_round_rate,
>> + .set_rate = clk_alpha_pll_slew_set_rate,
>> +};
>> +EXPORT_SYMBOL(clk_alpha_pll_slew_ops);
>> diff --git a/drivers/clk/qcom/clk-alpha-pll.h b/drivers/clk/qcom/clk-alpha-pll.h
>> index 79aca8525262211ae5295245427d4540abf1e09a..1d19001605eb10fd8ae8041c56d951e928cbbe9f 100644
>> --- a/drivers/clk/qcom/clk-alpha-pll.h
>> +++ b/drivers/clk/qcom/clk-alpha-pll.h
>> @@ -204,6 +204,7 @@ extern const struct clk_ops clk_alpha_pll_rivian_evo_ops;
>> #define clk_alpha_pll_postdiv_rivian_evo_ops clk_alpha_pll_postdiv_fabia_ops
>>
>> extern const struct clk_ops clk_alpha_pll_regera_ops;
>> +extern const struct clk_ops clk_alpha_pll_slew_ops;
>>
>> void clk_alpha_pll_configure(struct clk_alpha_pll *pll, struct regmap *regmap,
>> const struct alpha_pll_config *config);
>>
>> --
>> 2.48.1
>>
next prev parent reply other threads:[~2025-03-17 6:42 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 6:59 [PATCH v6 00/10] Add support for videocc, camcc, dispcc and gpucc on Qualcomm QCS615 platform Taniya Das
2025-03-13 6:59 ` [PATCH v6 01/10] clk: qcom: clk-alpha-pll: Add support for dynamic update for slewing PLLs Taniya Das
2025-03-13 23:39 ` Bjorn Andersson
2025-03-17 6:40 ` Taniya Das [this message]
2025-03-13 6:59 ` [PATCH v6 02/10] dt-bindings: clock: Add Qualcomm QCS615 Camera clock controller Taniya Das
2025-03-13 6:59 ` [PATCH v6 03/10] clk: qcom: camcc-qcs615: Add QCS615 camera clock controller driver Taniya Das
2025-03-13 6:59 ` [PATCH v6 04/10] dt-bindings: clock: Add Qualcomm QCS615 Display clock controller Taniya Das
2025-03-13 7:53 ` Krzysztof Kozlowski
2025-03-13 8:25 ` Krzysztof Kozlowski
2025-03-13 8:45 ` Taniya Das
2025-03-13 6:59 ` [PATCH v6 05/10] clk: qcom: dispcc-qcs615: Add QCS615 display clock controller driver Taniya Das
2025-03-13 6:59 ` [PATCH v6 06/10] dt-bindings: clock: Add Qualcomm QCS615 Graphics clock controller Taniya Das
2025-03-13 8:24 ` Krzysztof Kozlowski
2025-03-13 8:48 ` Taniya Das
2025-03-13 23:17 ` Bjorn Andersson
2025-03-17 6:34 ` Taniya Das
2025-03-13 6:59 ` [PATCH v6 07/10] clk: qcom: gpucc-qcs615: Add QCS615 graphics clock controller driver Taniya Das
2025-03-13 6:59 ` [PATCH v6 08/10] dt-bindings: clock: Add Qualcomm QCS615 Video clock controller Taniya Das
2025-03-13 6:59 ` [PATCH v6 09/10] clk: qcom: videocc-qcs615: Add QCS615 video clock controller driver Taniya Das
2025-03-13 6:59 ` [PATCH v6 10/10] arm64: defconfig: Enable QCS615 clock controllers Taniya Das
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fce2fe9e-5c1b-4fa9-b6ca-0a4ab5133e5a@quicinc.com \
--to=quic_tdas@quicinc.com \
--cc=andersson@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=quic_ajipan@quicinc.com \
--cc=quic_imrashai@quicinc.com \
--cc=quic_jkona@quicinc.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox