mirror of
https://github.com/torvalds/linux.git
synced 2026-06-02 03:24:19 +02:00
scsi: ufs: qcom: Call ufs_qcom_cfg_timers() in clock scaling path
ufs_qcom_cfg_timers() is clock freq dependent like ufs_qcom_set_core_clk_ctrl(), hence move ufs_qcom_cfg_timers() call to clock scaling path. In addition, do not assume the devfreq OPP freq is always the 'core_clock' freq although 'core_clock' is the first clock phandle in device tree, use ufs_qcom_opp_freq_to_clk_freq() to find the core clk freq. Signed-off-by: Can Guo <quic_cang@quicinc.com> Co-developed-by: Ziqi Chen <quic_ziqichen@quicinc.com> Signed-off-by: Ziqi Chen <quic_ziqichen@quicinc.com> Link: https://lore.kernel.org/r/20250522021537.999107-4-quic_ziqichen@quicinc.com Reported-by: Luca Weiss <luca.weiss@fairphone.com> Closes: https://lore.kernel.org/linux-arm-msm/D9FZ9U3AEXW4.1I12FX3YQ3JPW@fairphone.com/ Tested-by: Luca Weiss <luca.weiss@fairphone.com> Reviewed-by: Bean Huo <beanhuo@micron.com> Tested-by: Loïc Minier <loic.minier@oss.qualcomm.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
This commit is contained in:
parent
8c5bcb3dae
commit
c77b37dafb
|
|
@ -599,13 +599,14 @@ static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,
|
|||
*
|
||||
* @hba: host controller instance
|
||||
* @is_pre_scale_up: flag to check if pre scale up condition.
|
||||
* @freq: target opp freq
|
||||
* Return: zero for success and non-zero in case of a failure.
|
||||
*/
|
||||
static int ufs_qcom_cfg_timers(struct ufs_hba *hba, bool is_pre_scale_up)
|
||||
static int ufs_qcom_cfg_timers(struct ufs_hba *hba, bool is_pre_scale_up, unsigned long freq)
|
||||
{
|
||||
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
|
||||
struct ufs_clk_info *clki;
|
||||
unsigned long core_clk_rate = 0;
|
||||
unsigned long clk_freq = 0;
|
||||
u32 core_clk_cycles_per_us;
|
||||
|
||||
/*
|
||||
|
|
@ -617,22 +618,34 @@ static int ufs_qcom_cfg_timers(struct ufs_hba *hba, bool is_pre_scale_up)
|
|||
if (host->hw_ver.major < 4 && !ufshcd_is_intr_aggr_allowed(hba))
|
||||
return 0;
|
||||
|
||||
if (hba->use_pm_opp && freq != ULONG_MAX) {
|
||||
clk_freq = ufs_qcom_opp_freq_to_clk_freq(hba, freq, "core_clk");
|
||||
if (clk_freq)
|
||||
goto cfg_timers;
|
||||
}
|
||||
|
||||
list_for_each_entry(clki, &hba->clk_list_head, list) {
|
||||
if (!strcmp(clki->name, "core_clk")) {
|
||||
if (freq == ULONG_MAX) {
|
||||
clk_freq = clki->max_freq;
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_pre_scale_up)
|
||||
core_clk_rate = clki->max_freq;
|
||||
clk_freq = clki->max_freq;
|
||||
else
|
||||
core_clk_rate = clk_get_rate(clki->clk);
|
||||
clk_freq = clk_get_rate(clki->clk);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
cfg_timers:
|
||||
/* If frequency is smaller than 1MHz, set to 1MHz */
|
||||
if (core_clk_rate < DEFAULT_CLK_RATE_HZ)
|
||||
core_clk_rate = DEFAULT_CLK_RATE_HZ;
|
||||
if (clk_freq < DEFAULT_CLK_RATE_HZ)
|
||||
clk_freq = DEFAULT_CLK_RATE_HZ;
|
||||
|
||||
core_clk_cycles_per_us = core_clk_rate / USEC_PER_SEC;
|
||||
core_clk_cycles_per_us = clk_freq / USEC_PER_SEC;
|
||||
if (ufshcd_readl(hba, REG_UFS_SYS1CLK_1US) != core_clk_cycles_per_us) {
|
||||
ufshcd_writel(hba, core_clk_cycles_per_us, REG_UFS_SYS1CLK_1US);
|
||||
/*
|
||||
|
|
@ -652,7 +665,7 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
|
|||
|
||||
switch (status) {
|
||||
case PRE_CHANGE:
|
||||
if (ufs_qcom_cfg_timers(hba, false)) {
|
||||
if (ufs_qcom_cfg_timers(hba, false, ULONG_MAX)) {
|
||||
dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n",
|
||||
__func__);
|
||||
return -EINVAL;
|
||||
|
|
@ -930,17 +943,6 @@ static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba,
|
|||
|
||||
break;
|
||||
case POST_CHANGE:
|
||||
if (ufs_qcom_cfg_timers(hba, false)) {
|
||||
dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n",
|
||||
__func__);
|
||||
/*
|
||||
* we return error code at the end of the routine,
|
||||
* but continue to configure UFS_PHY_TX_LANE_ENABLE
|
||||
* and bus voting as usual
|
||||
*/
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
/* cache the power mode parameters to use internally */
|
||||
memcpy(&host->dev_req_params,
|
||||
dev_req_params, sizeof(*dev_req_params));
|
||||
|
|
@ -1492,7 +1494,7 @@ static int ufs_qcom_clk_scale_up_pre_change(struct ufs_hba *hba, unsigned long f
|
|||
{
|
||||
int ret;
|
||||
|
||||
ret = ufs_qcom_cfg_timers(hba, true);
|
||||
ret = ufs_qcom_cfg_timers(hba, true, freq);
|
||||
if (ret) {
|
||||
dev_err(hba->dev, "%s ufs cfg timer failed\n", __func__);
|
||||
return ret;
|
||||
|
|
@ -1529,6 +1531,13 @@ static int ufs_qcom_clk_scale_down_pre_change(struct ufs_hba *hba)
|
|||
|
||||
static int ufs_qcom_clk_scale_down_post_change(struct ufs_hba *hba, unsigned long freq)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = ufs_qcom_cfg_timers(hba, false, freq);
|
||||
if (ret) {
|
||||
dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n", __func__);
|
||||
return ret;
|
||||
}
|
||||
/* set unipro core clock attributes and clear clock divider */
|
||||
return ufs_qcom_set_core_clk_ctrl(hba, false, freq);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user