Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f76aa6c authored by Subhash Jadavani's avatar Subhash Jadavani Committed by Can Guo
Browse files

scsi: ufs: add pre & post status change to clk_scale_notify ops



Some UFS host controller implementation may require vendor specific
configurations before and after changing the UFS controller
clock frequencies. This change adds the support for this.

Change-Id: Id4171ef8786fa6883d9af914dc2a675cb62c6a72
Signed-off-by: default avatarSubhash Jadavani <subhashj@codeaurora.org>
[venkatg@codeaurora.org: resolved trivial merge conflicts]
Signed-off-by: default avatarVenkat Gopalakrishnan <venkatg@codeaurora.org>
[cang@codeaurora.org: Resolved trivial merge conflicts]
Signed-off-by: default avatarCan Guo <cang@codeaurora.org>
parent 2275a311
Loading
Loading
Loading
Loading
+49 −9
Original line number Diff line number Diff line
@@ -1031,7 +1031,15 @@ static int ufshcd_send_request_sense_all_lus(struct ufs_hba *hba)
	return 0;
}

static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
/**
 * ufshcd_set_clk_freq - set UFS controller clock frequencies
 * @hba: per adapter instance
 * @scale_up: If True, set max possible frequency othewise set low frequency
 *
 * Returns 0 if successful
 * Returns < 0 for any other errors
 */
static int ufshcd_set_clk_freq(struct ufs_hba *hba, bool scale_up)
{
	int ret = 0;
	struct ufs_clk_info *clki;
@@ -1100,6 +1108,39 @@ static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
	return ret;
}

/**
 * ufshcd_scale_clks - scale up or scale down UFS controller clocks
 * @hba: per adapter instance
 * @scale_up: True if scaling up and false if scaling down
 *
 * Returns 0 if successful
 * Returns < 0 for any other errors
 */
static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
{
	int ret = 0;

	if (hba->vops && hba->vops->clk_scale_notify) {
		ret = hba->vops->clk_scale_notify(hba, scale_up, PRE_CHANGE);
		if (ret)
			return ret;
	}

	ret = ufshcd_set_clk_freq(hba, scale_up);
	if (ret)
		return ret;

	if (hba->vops && hba->vops->clk_scale_notify) {
		ret = hba->vops->clk_scale_notify(hba, scale_up, POST_CHANGE);
		if (ret) {
			ufshcd_set_clk_freq(hba, !scale_up);
			return ret;
		}
	}

	return ret;
}

/**
 * ufshcd_is_devfreq_scaling_required - check if scaling is required or not
 * @hba: per adapter instance
@@ -1292,11 +1333,8 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up)
	}

	ret = ufshcd_scale_clks(hba, scale_up);
	if (ret) {
		if (!scale_up)
			ufshcd_scale_gear(hba, true);
		goto out;
	}
	if (ret)
		goto scale_up_gear;

	/* scale up the gear after scaling up clocks */
	if (scale_up) {
@@ -1306,9 +1344,11 @@ static int ufshcd_devfreq_scale(struct ufs_hba *hba, bool scale_up)
			goto out;
		}
	}
	goto out;

	ret = ufshcd_vops_clk_scale_notify(hba, scale_up, POST_CHANGE);

scale_up_gear:
	if (!scale_up)
		ufshcd_scale_gear(hba, true);
out:
	ufshcd_clock_scaling_unprepare(hba);
	ufshcd_release_all(hba);
@@ -6463,7 +6503,7 @@ static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)
	spin_unlock_irqrestore(hba->host->host_lock, flags);

	/* scale up clocks to max frequency before full reinitialization */
	ufshcd_scale_clks(hba, true);
	ufshcd_set_clk_freq(hba, true);

	err = ufshcd_hba_enable(hba);
	if (err)