Skip to content

Commit fd915c6

Browse files
Nitin Rawatmartinkpetersen
authored andcommitted
scsi: ufs: qcom: Configure SYS1CLK_1US_REG for UFS V4 and above
SYS1CLK_1US represents the required number of system 1-clock cycles for one microsecond. UFS Host Controller V4.0 and above mandates to write SYS1CLK_1US_REG register and also these timer configuration needs to be called from clk scaling pre ops as per HPG. Refactor ufs_qcom_cfg_timers and add the below code support to align with HPG. a)Configure SYS1CLK_1US_REG for UFS V4 and above. b)Introduce a new argument is_pre_scale_up for ufs_qcom_cfg_timers to configure SYS1CLK_1US for max freq during prescale and link startup condition. c)Move ufs_qcom_cfg_timers from clk scaling post change ops to clk scaling pre change ops. Co-developed-by: Naveen Kumar Goud Arepalli <[email protected]> Signed-off-by: Naveen Kumar Goud Arepalli <[email protected]> Signed-off-by: Nitin Rawat <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Can Guo <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 3091181 commit fd915c6

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

drivers/ufs/host/ufs-qcom.c

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,20 @@ static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba,
527527
return err;
528528
}
529529

530-
/*
530+
/**
531+
* ufs_qcom_cfg_timers - Configure ufs qcom cfg timers
532+
*
533+
* @hba: host controller instance
534+
* @gear: Current operating gear
535+
* @hs: current power mode
536+
* @rate: current operating rate (A or B)
537+
* @update_link_startup_timer: indicate if link_start ongoing
538+
* @is_pre_scale_up: flag to check if pre scale up condition.
531539
* Return: zero for success and non-zero in case of a failure.
532540
*/
533541
static int ufs_qcom_cfg_timers(struct ufs_hba *hba, u32 gear,
534-
u32 hs, u32 rate, bool update_link_startup_timer)
542+
u32 hs, u32 rate, bool update_link_startup_timer,
543+
bool is_pre_scale_up)
535544
{
536545
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
537546
struct ufs_clk_info *clki;
@@ -562,11 +571,14 @@ static int ufs_qcom_cfg_timers(struct ufs_hba *hba, u32 gear,
562571
/*
563572
* The Qunipro controller does not use following registers:
564573
* SYS1CLK_1US_REG, TX_SYMBOL_CLK_1US_REG, CLK_NS_REG &
565-
* UFS_REG_PA_LINK_STARTUP_TIMER
566-
* But UTP controller uses SYS1CLK_1US_REG register for Interrupt
574+
* UFS_REG_PA_LINK_STARTUP_TIMER.
575+
* However UTP controller uses SYS1CLK_1US_REG register for Interrupt
567576
* Aggregation logic.
568-
*/
569-
if (ufs_qcom_cap_qunipro(host) && !ufshcd_is_intr_aggr_allowed(hba))
577+
* It is mandatory to write SYS1CLK_1US_REG register on UFS host
578+
* controller V4.0.0 onwards.
579+
*/
580+
if (host->hw_ver.major < 4 && ufs_qcom_cap_qunipro(host) &&
581+
!ufshcd_is_intr_aggr_allowed(hba))
570582
return 0;
571583

572584
if (gear == 0) {
@@ -575,8 +587,14 @@ static int ufs_qcom_cfg_timers(struct ufs_hba *hba, u32 gear,
575587
}
576588

577589
list_for_each_entry(clki, &hba->clk_list_head, list) {
578-
if (!strcmp(clki->name, "core_clk"))
579-
core_clk_rate = clk_get_rate(clki->clk);
590+
if (!strcmp(clki->name, "core_clk")) {
591+
if (is_pre_scale_up)
592+
core_clk_rate = clki->max_freq;
593+
else
594+
core_clk_rate = clk_get_rate(clki->clk);
595+
break;
596+
}
597+
580598
}
581599

582600
/* If frequency is smaller than 1MHz, set to 1MHz */
@@ -678,7 +696,7 @@ static int ufs_qcom_link_startup_notify(struct ufs_hba *hba,
678696
switch (status) {
679697
case PRE_CHANGE:
680698
if (ufs_qcom_cfg_timers(hba, UFS_PWM_G1, SLOWAUTO_MODE,
681-
0, true)) {
699+
0, true, false)) {
682700
dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n",
683701
__func__);
684702
return -EINVAL;
@@ -922,7 +940,7 @@ static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba,
922940
case POST_CHANGE:
923941
if (ufs_qcom_cfg_timers(hba, dev_req_params->gear_rx,
924942
dev_req_params->pwr_rx,
925-
dev_req_params->hs_rate, false)) {
943+
dev_req_params->hs_rate, false, false)) {
926944
dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n",
927945
__func__);
928946
/*
@@ -1418,10 +1436,22 @@ static int ufs_qcom_set_core_clk_ctrl(struct ufs_hba *hba, bool is_scale_up)
14181436
static int ufs_qcom_clk_scale_up_pre_change(struct ufs_hba *hba)
14191437
{
14201438
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
1439+
struct ufs_pa_layer_attr *attr = &host->dev_req_params;
1440+
int ret;
14211441

14221442
if (!ufs_qcom_cap_qunipro(host))
14231443
return 0;
14241444

1445+
if (attr) {
1446+
ret = ufs_qcom_cfg_timers(hba, attr->gear_rx,
1447+
attr->pwr_rx, attr->hs_rate,
1448+
false, true);
1449+
if (ret) {
1450+
dev_err(hba->dev, "%s ufs cfg timer failed\n",
1451+
__func__);
1452+
return ret;
1453+
}
1454+
}
14251455
/* set unipro core clock attributes and clear clock divider */
14261456
return ufs_qcom_set_core_clk_ctrl(hba, true);
14271457
}
@@ -1471,7 +1501,6 @@ static int ufs_qcom_clk_scale_notify(struct ufs_hba *hba,
14711501
bool scale_up, enum ufs_notify_change_status status)
14721502
{
14731503
struct ufs_qcom_host *host = ufshcd_get_variant(hba);
1474-
struct ufs_pa_layer_attr *dev_req_params = &host->dev_req_params;
14751504
int err = 0;
14761505

14771506
/* check the host controller state before sending hibern8 cmd */
@@ -1501,11 +1530,6 @@ static int ufs_qcom_clk_scale_notify(struct ufs_hba *hba,
15011530
return err;
15021531
}
15031532

1504-
ufs_qcom_cfg_timers(hba,
1505-
dev_req_params->gear_rx,
1506-
dev_req_params->pwr_rx,
1507-
dev_req_params->hs_rate,
1508-
false);
15091533
ufs_qcom_icc_update_bw(host);
15101534
ufshcd_uic_hibern8_exit(hba);
15111535
}

0 commit comments

Comments
 (0)