diff mbox series

[1/1] scsi: ufs: Remove scale down gear hard code

Message ID 1606442334-22641-1-git-send-email-cang@codeaurora.org (mailing list archive)
State Accepted
Headers show
Series [1/1] scsi: ufs: Remove scale down gear hard code | expand

Commit Message

Can Guo Nov. 27, 2020, 1:58 a.m. UTC
Instead of making the scale down gear a hard code, make it a member of
ufs_clk_scaling struct.

Signed-off-by: Can Guo <cang@codeaurora.org>
---
 drivers/scsi/ufs/ufshcd.c | 12 +++++++-----
 drivers/scsi/ufs/ufshcd.h |  2 ++
 2 files changed, 9 insertions(+), 5 deletions(-)

Comments

Stanley Chu Nov. 30, 2020, 2:23 a.m. UTC | #1
On Thu, 2020-11-26 at 17:58 -0800, Can Guo wrote:
> Instead of making the scale down gear a hard code, make it a member of
> ufs_clk_scaling struct.
> 
> Signed-off-by: Can Guo <cang@codeaurora.org>

Reviewed-by: Stanley Chu <stanley.chu@mediatek.com>
Bean Huo Nov. 30, 2020, 6:58 p.m. UTC | #2
On Thu, 2020-11-26 at 17:58 -0800, Can Guo wrote:
> Instead of making the scale down gear a hard code, make it a member
> of
> ufs_clk_scaling struct.
> 
> Signed-off-by: Can Guo <cang@codeaurora.org>

Reviewed-by: Bean Huo <beanhuo@micron.com>
Asutosh Das (asd) Nov. 30, 2020, 10:54 p.m. UTC | #3
On 11/26/2020 5:58 PM, Can Guo wrote:
> Instead of making the scale down gear a hard code, make it a member of
> ufs_clk_scaling struct.
> 
> Signed-off-by: Can Guo <cang@codeaurora.org>
> ---

Reviewed-by: Asutosh Das <asutoshd@codeaurora.org>

>   drivers/scsi/ufs/ufshcd.c | 12 +++++++-----
>   drivers/scsi/ufs/ufshcd.h |  2 ++
>   2 files changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
> index 44254c9..1789df3 100644
> --- a/drivers/scsi/ufs/ufshcd.c
> +++ b/drivers/scsi/ufs/ufshcd.c
> @@ -1100,7 +1100,6 @@ static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba,
>    */
>   static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up)
>   {
> -	#define UFS_MIN_GEAR_TO_SCALE_DOWN	UFS_HS_G1
>   	int ret = 0;
>   	struct ufs_pa_layer_attr new_pwr_info;
>   
> @@ -1111,16 +1110,16 @@ static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up)
>   		memcpy(&new_pwr_info, &hba->pwr_info,
>   		       sizeof(struct ufs_pa_layer_attr));
>   
> -		if (hba->pwr_info.gear_tx > UFS_MIN_GEAR_TO_SCALE_DOWN
> -		    || hba->pwr_info.gear_rx > UFS_MIN_GEAR_TO_SCALE_DOWN) {
> +		if (hba->pwr_info.gear_tx > hba->clk_scaling.min_gear ||
> +		    hba->pwr_info.gear_rx > hba->clk_scaling.min_gear) {
>   			/* save the current power mode */
>   			memcpy(&hba->clk_scaling.saved_pwr_info.info,
>   				&hba->pwr_info,
>   				sizeof(struct ufs_pa_layer_attr));
>   
>   			/* scale down gear */
> -			new_pwr_info.gear_tx = UFS_MIN_GEAR_TO_SCALE_DOWN;
> -			new_pwr_info.gear_rx = UFS_MIN_GEAR_TO_SCALE_DOWN;
> +			new_pwr_info.gear_tx = hba->clk_scaling.min_gear;
> +			new_pwr_info.gear_rx = hba->clk_scaling.min_gear;
>   		}
>   	}
>   
> @@ -1824,6 +1823,9 @@ static void ufshcd_init_clk_scaling(struct ufs_hba *hba)
>   	if (!ufshcd_is_clkscaling_supported(hba))
>   		return;
>   
> +	if (!hba->clk_scaling.min_gear)
> +		hba->clk_scaling.min_gear = UFS_HS_G1;
> +
>   	INIT_WORK(&hba->clk_scaling.suspend_work,
>   		  ufshcd_clk_scaling_suspend_work);
>   	INIT_WORK(&hba->clk_scaling.resume_work,
> diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
> index 6f0f2d4..bdab23e 100644
> --- a/drivers/scsi/ufs/ufshcd.h
> +++ b/drivers/scsi/ufs/ufshcd.h
> @@ -385,6 +385,7 @@ struct ufs_saved_pwr_info {
>    * @workq: workqueue to schedule devfreq suspend/resume work
>    * @suspend_work: worker to suspend devfreq
>    * @resume_work: worker to resume devfreq
> + * @min_gear: lowest HS gear to scale down to
>    * @is_allowed: tracks if scaling is currently allowed or not
>    * @is_busy_started: tracks if busy period has started or not
>    * @is_suspended: tracks if devfreq is suspended or not
> @@ -399,6 +400,7 @@ struct ufs_clk_scaling {
>   	struct workqueue_struct *workq;
>   	struct work_struct suspend_work;
>   	struct work_struct resume_work;
> +	u32 min_gear;
>   	bool is_allowed;
>   	bool is_busy_started;
>   	bool is_suspended;
>
Martin K. Petersen Dec. 1, 2020, 5:17 a.m. UTC | #4
Can,

> Instead of making the scale down gear a hard code, make it a member of
> ufs_clk_scaling struct.

Applied to 5.11/scsi-staging, thanks!
Martin K. Petersen Dec. 8, 2020, 4:51 a.m. UTC | #5
On Thu, 26 Nov 2020 17:58:48 -0800, Can Guo wrote:

> Instead of making the scale down gear a hard code, make it a member of
> ufs_clk_scaling struct.

Applied to 5.11/scsi-queue, thanks!

[1/1] scsi: ufs: Remove scale down gear hard code
      https://git.kernel.org/mkp/scsi/c/29b87e92a216
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 44254c9..1789df3 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -1100,7 +1100,6 @@  static int ufshcd_wait_for_doorbell_clr(struct ufs_hba *hba,
  */
 static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up)
 {
-	#define UFS_MIN_GEAR_TO_SCALE_DOWN	UFS_HS_G1
 	int ret = 0;
 	struct ufs_pa_layer_attr new_pwr_info;
 
@@ -1111,16 +1110,16 @@  static int ufshcd_scale_gear(struct ufs_hba *hba, bool scale_up)
 		memcpy(&new_pwr_info, &hba->pwr_info,
 		       sizeof(struct ufs_pa_layer_attr));
 
-		if (hba->pwr_info.gear_tx > UFS_MIN_GEAR_TO_SCALE_DOWN
-		    || hba->pwr_info.gear_rx > UFS_MIN_GEAR_TO_SCALE_DOWN) {
+		if (hba->pwr_info.gear_tx > hba->clk_scaling.min_gear ||
+		    hba->pwr_info.gear_rx > hba->clk_scaling.min_gear) {
 			/* save the current power mode */
 			memcpy(&hba->clk_scaling.saved_pwr_info.info,
 				&hba->pwr_info,
 				sizeof(struct ufs_pa_layer_attr));
 
 			/* scale down gear */
-			new_pwr_info.gear_tx = UFS_MIN_GEAR_TO_SCALE_DOWN;
-			new_pwr_info.gear_rx = UFS_MIN_GEAR_TO_SCALE_DOWN;
+			new_pwr_info.gear_tx = hba->clk_scaling.min_gear;
+			new_pwr_info.gear_rx = hba->clk_scaling.min_gear;
 		}
 	}
 
@@ -1824,6 +1823,9 @@  static void ufshcd_init_clk_scaling(struct ufs_hba *hba)
 	if (!ufshcd_is_clkscaling_supported(hba))
 		return;
 
+	if (!hba->clk_scaling.min_gear)
+		hba->clk_scaling.min_gear = UFS_HS_G1;
+
 	INIT_WORK(&hba->clk_scaling.suspend_work,
 		  ufshcd_clk_scaling_suspend_work);
 	INIT_WORK(&hba->clk_scaling.resume_work,
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index 6f0f2d4..bdab23e 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -385,6 +385,7 @@  struct ufs_saved_pwr_info {
  * @workq: workqueue to schedule devfreq suspend/resume work
  * @suspend_work: worker to suspend devfreq
  * @resume_work: worker to resume devfreq
+ * @min_gear: lowest HS gear to scale down to
  * @is_allowed: tracks if scaling is currently allowed or not
  * @is_busy_started: tracks if busy period has started or not
  * @is_suspended: tracks if devfreq is suspended or not
@@ -399,6 +400,7 @@  struct ufs_clk_scaling {
 	struct workqueue_struct *workq;
 	struct work_struct suspend_work;
 	struct work_struct resume_work;
+	u32 min_gear;
 	bool is_allowed;
 	bool is_busy_started;
 	bool is_suspended;