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

Commit 6a56af62 authored by Bao D. Nguyen's avatar Bao D. Nguyen
Browse files

mmc: core: Use freq table with devfreq



Register the min/max frequencies with devfreq and use
these to determine if we're trying to step up or down.

Change-Id: Id1f49ad4b0e64967e4a72fb2c86df0a6550e1bec
Signed-off-by: default avatarBao D. Nguyen <nguyenb@codeaurora.org>
parent 0a48238d
Loading
Loading
Loading
Loading
+21 −3
Original line number Diff line number Diff line
@@ -543,6 +543,7 @@ static int mmc_devfreq_create_freq_table(struct mmc_host *host)
int mmc_init_clk_scaling(struct mmc_host *host)
{
	int err;
	struct devfreq *devfreq;

	if (!host || !host->card) {
		pr_err("%s: unexpected host/card parameters\n",
@@ -593,22 +594,34 @@ int mmc_init_clk_scaling(struct mmc_host *host)
		return err;
	}

	dev_pm_opp_add(mmc_classdev(host),
		host->clk_scaling.devfreq_profile.freq_table[0], 0);
	dev_pm_opp_add(mmc_classdev(host),
		host->clk_scaling.devfreq_profile.freq_table[1], 0);

	pr_debug("%s: adding devfreq with: upthreshold=%u downthreshold=%u polling=%u\n",
		mmc_hostname(host),
		host->clk_scaling.ondemand_gov_data.upthreshold,
		host->clk_scaling.ondemand_gov_data.downdifferential,
		host->clk_scaling.devfreq_profile.polling_ms);
	host->clk_scaling.devfreq = devfreq_add_device(

	devfreq = devfreq_add_device(
		mmc_classdev(host),
		&host->clk_scaling.devfreq_profile,
		"simple_ondemand",
		&host->clk_scaling.ondemand_gov_data);
	if (!host->clk_scaling.devfreq) {

	if (IS_ERR(devfreq)) {
		pr_err("%s: unable to register with devfreq\n",
			mmc_hostname(host));
		return -EPERM;
		dev_pm_opp_remove(mmc_classdev(host),
			host->clk_scaling.devfreq_profile.freq_table[0]);
		dev_pm_opp_remove(mmc_classdev(host),
			host->clk_scaling.devfreq_profile.freq_table[1]);
		return PTR_ERR(devfreq);
	}

	host->clk_scaling.devfreq = devfreq;
	pr_debug("%s: clk scaling is enabled for device %s (%pK) with devfreq %pK (clock = %uHz)\n",
		mmc_hostname(host),
		dev_name(mmc_classdev(host)),
@@ -765,6 +778,11 @@ int mmc_exit_clk_scaling(struct mmc_host *host)
		return err;
	}

	dev_pm_opp_remove(mmc_classdev(host),
		host->clk_scaling.devfreq_profile.freq_table[0]);
	dev_pm_opp_remove(mmc_classdev(host),
		host->clk_scaling.devfreq_profile.freq_table[1]);

	kfree(host->clk_scaling.devfreq_profile.freq_table);

	host->clk_scaling.devfreq = NULL;