All of lore.kernel.org
 help / color / mirror / Atom feed
From: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
To: Sumit Garg <sumit.garg@kernel.org>
Cc: u-boot@lists.denx.de, u-boot-qcom@groups.io,
	Lukasz Majewski <lukma@denx.de>, Tom Rini <trini@konsulko.com>,
	Casey Connolly <casey.connolly@linaro.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	David Wronek <david.wronek@mainlining.org>,
	Luca Weiss <luca.weiss@fairphone.com>,
	Jorge Ramirez-Ortiz <jorge.ramirez@oss.qualcomm.com>,
	Swathi Tamilselvan <swathi.tamilselvan@oss.qualcomm.com>,
	Aswin Murugan <aswin.murugan@oss.qualcomm.com>,
	Bhupesh Sharma <bhupesh.linux@gmail.com>,
	Neha Malcom Francis <n-francis@ti.com>,
	Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Julien Stephan <jstephan@baylibre.com>
Subject: Re: [PATCH 5/5] drivers: ufs: qcom: Initialize and enable clocks before hardware access
Date: Mon, 27 Apr 2026 22:24:23 +0530	[thread overview]
Message-ID: <f80c70eb-feac-4f1d-ad56-5ba757c81b00@oss.qualcomm.com> (raw)
In-Reply-To: <acI0Flg4gUKmP2FQ@sumit-xelite>


On 3/24/2026 12:19 PM, Sumit Garg wrote:
> On Thu, Mar 19, 2026 at 03:07:42PM +0530, Balaji Selvanathan wrote:
>> Move UFS clock initialization and enabling before hardware setup
>> to ensure clocks are running when accessing UFS registers.
>>
>> Previously, U-Boot depended on earlier bootloader stages to
>> initialize UFS clocks. When these bootloaders failed to do so,
>> UFS registers became inaccessible, causing initialization to fail.
>> This change makes U-Boot initialize and enable UFS clocks early
>> in the init sequence, removing the dependency on previous
>> bootloaders.
>>
>> Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
>> ---
>>   drivers/ufs/ufs-qcom.c | 45 +++++++++++++++++++++++++++++++++++++--------
>>   1 file changed, 37 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/ufs/ufs-qcom.c b/drivers/ufs/ufs-qcom.c
>> index dc40ee62daf..c63e550c881 100644
>> --- a/drivers/ufs/ufs-qcom.c
>> +++ b/drivers/ufs/ufs-qcom.c
>> @@ -30,6 +30,7 @@
>>   #define UFS_CPU_MAX_BANDWIDTH	819200
>>   
>>   static void ufs_qcom_dev_ref_clk_ctrl(struct ufs_hba *hba, bool enable);
>> +static u32 ufs_qcom_get_core_clk_unipro_max_freq(struct ufs_hba *hba);
>>   
>>   static int ufs_qcom_enable_clks(struct ufs_qcom_priv *priv)
>>   {
>> @@ -49,12 +50,34 @@ static int ufs_qcom_enable_clks(struct ufs_qcom_priv *priv)
>>   
>>   static int ufs_qcom_init_clks(struct ufs_qcom_priv *priv)
>>   {
>> -	int err;
>>   	struct udevice *dev = priv->hba->dev;
>> +	struct clk clk;
>> +	int err;
>> +	long rate;
>> +	u32 max_freq;
>> +
>> +	/* Get maximum frequency for core_clk_unipro from device tree */
>> +	max_freq = ufs_qcom_get_core_clk_unipro_max_freq(priv->hba);
>> +
>> +	/* Get and configure core_clk_unipro */
>> +	err = clk_get_by_name(dev, "core_clk_unipro", &clk);
>> +	if (err) {
>> +		dev_err(dev, "Failed to get core_clk_unipro: %d\n", err);
>> +		return err;
>> +	}
>> +
>> +	rate = clk_set_rate(&clk, max_freq);
>> +
>> +	if (rate < 0) {
>> +		dev_err(dev, "Failed to set core_clk_unipro rate to %u Hz: %ld\n",
>> +			max_freq, rate);
>> +	}
>>   
>>   	err = clk_get_bulk(dev, &priv->clks);
>> -	if (err)
>> +	if (err) {
>> +		dev_err(dev, "clk_get_bulk failed: %d\n", err);
>>   		return err;
>> +	}
>>   
>>   	return 0;
>>   }
>> @@ -561,6 +584,18 @@ static int ufs_qcom_init(struct ufs_hba *hba)
>>   
>>   	priv->hba = hba;
>>   
>> +	err = ufs_qcom_init_clks(priv);
> I would just drop this wrapper and directly invoke clk_get_bulk() here.

Hi Sumit,

Implemented this in v2: 
https://lore.kernel.org/u-boot/20260427-ufs_clk-v2-6-36e10a7c0ef6@oss.qualcomm.com/

>
>> +	if (err) {
>> +		dev_err(hba->dev, "failed to initialize clocks, err:%d\n", err);
>> +		return err;
>> +	}
>> +
>> +	err = ufs_qcom_enable_clks(priv);
> There is already a comment related to this API:
>
> /*
>   * The PHY PLL output is the source of tx/rx lane symbol
>   * clocks, hence, enable the lane clocks only after PHY
>   * is initialized.
>   */
>
> Shouldn't PHY be initialized before clocks being enabled?

We can enable CBCRs of the tx/rx clks before we initiatize the PHYs. 
Once the PHY is turned on, these clks are enabled automatically.

The same process is followed in XBL/UEFI codes.

>
>> +	if (err) {
>> +		dev_err(hba->dev, "failed to enable clocks, err:%d\n", err);
>> +		return err;
>> +	}
>> +
>>   	/* setup clocks */
>>   	ufs_qcom_setup_clocks(hba, true, PRE_CHANGE);
>>   
>> @@ -579,12 +614,6 @@ static int ufs_qcom_init(struct ufs_hba *hba)
>>   		 priv->hw_ver.minor,
>>   		 priv->hw_ver.step);
>>   
>> -	err = ufs_qcom_init_clks(priv);
>> -	if (err) {
>> -		dev_err(hba->dev, "failed to initialize clocks, err:%d\n", err);
>> -		return err;
>> -	}
>> -
>>   	ufs_qcom_advertise_quirks(hba);
>>   	ufs_qcom_setup_clocks(hba, true, POST_CHANGE);
> While at it, I see this POST_CHANGE setup invoked twice. Can you check
> as to why that is needed?

Implemented this in v2: 
https://lore.kernel.org/u-boot/20260427-ufs_clk-v2-7-36e10a7c0ef6@oss.qualcomm.com/

Thanks,

Balaji

>
> -Sumit

  reply	other threads:[~2026-04-27 16:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19  9:37 [PATCH 0/5] Add UFS clock support for Qualcomm SoCs Balaji Selvanathan
2026-03-19  9:37 ` [PATCH 1/5] clk: qcom: clk-stub: Add compatibles for QCS615/SA8775P/SC7280 Balaji Selvanathan
2026-03-19 10:30   ` Julien Stephan
2026-03-19  9:37 ` [PATCH 2/5] clk: qcom: sa8775p: Add UFS clock support Balaji Selvanathan
2026-03-24  6:12   ` Sumit Garg
2026-03-19  9:37 ` [PATCH 3/5] clk: qcom: qcs615: " Balaji Selvanathan
2026-03-24  6:25   ` Sumit Garg
2026-03-19  9:37 ` [PATCH 4/5] clk: qcom: sc7280: " Balaji Selvanathan
2026-03-24  6:26   ` Sumit Garg
2026-03-19  9:37 ` [PATCH 5/5] drivers: ufs: qcom: Initialize and enable clocks before hardware access Balaji Selvanathan
2026-03-19 10:20   ` Julien Stephan
2026-03-24  6:49   ` Sumit Garg
2026-04-27 16:54     ` Balaji Selvanathan [this message]
2026-04-13 12:09   ` Casey Connolly

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=f80c70eb-feac-4f1d-ad56-5ba757c81b00@oss.qualcomm.com \
    --to=balaji.selvanathan@oss.qualcomm.com \
    --cc=aswin.murugan@oss.qualcomm.com \
    --cc=bhupesh.linux@gmail.com \
    --cc=casey.connolly@linaro.org \
    --cc=david.wronek@mainlining.org \
    --cc=jorge.ramirez@oss.qualcomm.com \
    --cc=jstephan@baylibre.com \
    --cc=luca.weiss@fairphone.com \
    --cc=lukma@denx.de \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=n-francis@ti.com \
    --cc=neil.armstrong@linaro.org \
    --cc=sumit.garg@kernel.org \
    --cc=swathi.tamilselvan@oss.qualcomm.com \
    --cc=trini@konsulko.com \
    --cc=u-boot-qcom@groups.io \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.