summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/tegra3_clocks.c
diff options
context:
space:
mode:
authorAlex Frid <afrid@nvidia.com>2012-06-23 18:22:13 -0700
committerSimone Willett <swillett@nvidia.com>2012-07-13 14:55:15 -0700
commit3df9f33800760738a32d5661424d68d03091be70 (patch)
tree227d2ea1feddc20a0d046d06957b6a499ab45d42 /arch/arm/mach-tegra/tegra3_clocks.c
parent635faa1a9818843b5693087dffc9a2ea07ec00f6 (diff)
ARM: tegra: clock: Dynamically re-lock memory pll
So far Tegra3 EMC DFS allowed only scaling rates that can be divided down from two fixed rate plls: memory PLLM, and peripheral PLLP. PLLM is always running at maximum SDRAM rate set at boot time, while PLLP rate 408MHz is fixed across all Tegra3 platforms. This commit implements dynamic re-locking of PLLM at run time. Now memory pll can lock either at boot rate or additional auxiliary rate that is selected as follows: auxiliary PLLM rate must be present in EMC DFS table, it must exactly match one of the rate steps for Tegra3 graphics bus with PLLC clock source (cbus), and must not be a proper factor of boot PLLM rate or PLLP fixed rate. When switching PLLM between boot and auxiliary rate, PLLC is used as backup memory pll, and during this time cbus is locked at auxiliary rate. In addition system bus is forced to temporarily use PLLP as a clock source (this is necessary as sbus main clock source is PLLM secondary divider PLLM_OUT1). Limitations: - only one auxiliary rate is supported, and it should be below PLLM boot rate, but above half of boot rate - dynamic re-lock is allowed only on LPDDR2 platforms - no clock other than EMC and system bus could use PLLM as a source; so for dynamic re-lock to work CONFIG_TEGRA_PLLM_RESTRICTED must be selected, and VI clock (not covered by PLLM restricted configuration) must be moved to PLLP. Bug 1005576 Change-Id: I6177107c89c3cbe975a1d940927efa1ed0ea61ec Signed-off-by: Alex Frid <afrid@nvidia.com> Reviewed-on: http://git-master/r/111438 Reviewed-by: Rohan Somvanshi <rsomvanshi@nvidia.com> Tested-by: Rohan Somvanshi <rsomvanshi@nvidia.com> (cherry picked from commit dc4d468a6acabfb268e7a7f44b45bb7354e9a99a) Reviewed-on: http://git-master/r/114760 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: Jihoon Bang <jbang@nvidia.com> Reviewed-by: Yu-Huan Hsu <yhsu@nvidia.com>
Diffstat (limited to 'arch/arm/mach-tegra/tegra3_clocks.c')
-rw-r--r--arch/arm/mach-tegra/tegra3_clocks.c96
1 files changed, 94 insertions, 2 deletions
diff --git a/arch/arm/mach-tegra/tegra3_clocks.c b/arch/arm/mach-tegra/tegra3_clocks.c
index ca8cd5c449b9..1161f1ca64f9 100644
--- a/arch/arm/mach-tegra/tegra3_clocks.c
+++ b/arch/arm/mach-tegra/tegra3_clocks.c
@@ -314,6 +314,8 @@
static void tegra3_pllp_init_dependencies(unsigned long pllp_rate);
static int tegra3_clk_shared_bus_update(struct clk *bus);
+static int tegra3_emc_relock_set_rate(struct clk *emc, unsigned long old_rate,
+ unsigned long new_rate, unsigned long new_pll_rate);
static unsigned long cpu_stay_on_backup_max;
static struct clk *emc_bridge;
@@ -2636,8 +2638,15 @@ static int tegra3_emc_clk_set_rate(struct clk *c, unsigned long rate)
* to achieve requested rate. */
p = tegra_emc_predict_parent(rate, &div_value);
div_value += 2; /* emc has fractional DIV_U71 divider */
+
+ /* No matching rate in emc dfs table */
+ if (IS_ERR(p))
+ return PTR_ERR(p);
+
+ /* Table rate found, but need to relock source pll */
if (!p)
- return -EINVAL;
+ return tegra3_emc_relock_set_rate(c, clk_get_rate_locked(c),
+ rate, rate * (div_value / 2));
if (p == c->parent) {
if (div_value == c->div)
@@ -4076,7 +4085,7 @@ static struct clk_mux_sel mux_pllm_pllc_pllp_plla[] = {
static struct clk_mux_sel mux_pllm_pllc_pllp_clkm[] = {
{ .input = &tegra_pll_m, .value = 0},
- /* { .input = &tegra_pll_c, .value = 1}, not used on tegra3 */
+ { .input = &tegra_pll_c, .value = 1},
{ .input = &tegra_pll_p, .value = 2},
{ .input = &tegra_clk_m, .value = 3},
{ 0, 0},
@@ -4200,6 +4209,9 @@ static struct clk tegra_clk_emc = {
.u.periph = {
.clk_num = 57,
},
+ .shared_bus_backup = {
+ .input = &tegra_pll_c,
+ },
.rate_change_nh = &emc_rate_change_nh,
};
@@ -4526,6 +4538,86 @@ struct clk *tegra_ptr_clks[] = {
&tegra_clk_cbus,
};
+static int tegra3_emc_relock_set_rate(struct clk *emc, unsigned long old_rate,
+ unsigned long new_rate, unsigned long new_pll_rate)
+{
+ int ret;
+
+ struct clk *sbus = &tegra_clk_sbus_cmplx;
+ struct clk *cbus = &tegra_clk_cbus;
+ struct clk *pll_m = &tegra_pll_m;
+ unsigned long backup_rate = emc->shared_bus_backup.bus_rate;
+ unsigned long flags;
+
+ bool on_pllm = emc->parent == pll_m;
+
+ /*
+ * Relock procedure pre-conditions:
+ * - LPDDR2 only
+ * - EMC clock is enabled, and EMC backup rate is found in DFS table
+ * - All 3 shared buses: emc, sbus, cbus can sleep
+ */
+ if ((tegra_emc_get_dram_type() != DRAM_TYPE_LPDDR2) || !emc->refcnt ||
+ !backup_rate || (cbus->parent != emc->shared_bus_backup.input) ||
+ !clk_cansleep(emc) || !clk_cansleep(cbus) || !clk_cansleep(sbus))
+ return -ENOSYS;
+
+ /* Move sbus from PLLM by setting it at low rate threshold level */
+ clk_lock_save(sbus, &flags);
+ if (clk_get_rate_locked(sbus) > sbus->u.system.threshold) {
+ ret = clk_set_rate_locked(sbus, sbus->u.system.threshold);
+ if (ret)
+ goto _sbus_out;
+ }
+
+ /* If PLLM is current EMC parent set cbus to backup rate, and move EMC
+ to backup PLLC */
+ if (on_pllm) {
+ clk_lock_save(cbus, &flags);
+ clk_enable(cbus->parent);
+ ret = clk_set_rate_locked(cbus, backup_rate);
+ if (ret) {
+ clk_disable(cbus->parent);
+ goto _cbus_out;
+ }
+
+ ret = tegra_emc_backup(backup_rate);
+ if (ret) {
+ clk_disable(cbus->parent);
+ goto _cbus_out;
+ }
+ clk_disable(emc->parent);
+ clk_reparent(emc, cbus->parent);
+ }
+
+ /*
+ * Re-lock PLLM and switch EMC to it; relocking error indicates that
+ * PLLM has some other than EMC or sbus client. In this case PLLM has
+ * not been changed, and we still can safely switch back. Recursive
+ * tegra3_emc_clk_set_rate() call below will be resolved, since PLLM
+ * is now matching target rate.
+ */
+ ret = clk_set_rate(pll_m, new_pll_rate);
+ if (ret) {
+ if (on_pllm)
+ tegra3_emc_clk_set_rate(emc, old_rate);
+ } else
+ ret = tegra3_emc_clk_set_rate(emc, new_rate);
+
+
+_cbus_out:
+ if (on_pllm) {
+ tegra3_clk_shared_bus_update(cbus);
+ clk_unlock_restore(cbus, &flags);
+ }
+
+_sbus_out:
+ tegra3_clk_shared_bus_update(sbus);
+ clk_unlock_restore(sbus, &flags);
+
+ return ret;
+}
+
/*
* Backup rate targets for each CPU mode is selected below Fmax(Vmin), and
* high enough to avoid voltage droop when CPU clock is switched between