2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2006-04-03 00:46:20 +08:00
|
|
|
/*
|
2009-01-29 03:27:34 +08:00
|
|
|
* linux/arch/arm/mach-omap2/sdrc2xxx.c
|
2006-04-03 00:46:20 +08:00
|
|
|
*
|
2009-01-29 03:27:34 +08:00
|
|
|
* SDRAM timing related functions for OMAP2xxx
|
2006-04-03 00:46:20 +08:00
|
|
|
*
|
2009-01-29 03:27:37 +08:00
|
|
|
* Copyright (C) 2005, 2008 Texas Instruments Inc.
|
|
|
|
* Copyright (C) 2005, 2008 Nokia Corporation
|
2006-04-03 00:46:20 +08:00
|
|
|
*
|
|
|
|
* Tony Lindgren <tony@atomide.com>
|
2009-01-29 03:27:37 +08:00
|
|
|
* Paul Walmsley
|
|
|
|
* Richard Woodruff <r-woodruff2@ti.com>
|
2006-04-03 00:46:20 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/clk.h>
|
2008-09-06 19:10:45 +08:00
|
|
|
#include <linux/io.h>
|
2006-04-03 00:46:20 +08:00
|
|
|
|
2012-09-01 01:59:07 +08:00
|
|
|
#include "soc.h"
|
2012-02-25 02:34:35 +08:00
|
|
|
#include "iomap.h"
|
|
|
|
#include "common.h"
|
2012-10-21 15:01:10 +08:00
|
|
|
#include "prm2xxx.h"
|
[ARM] omap: add support for bypassing DPLLs
This roughly corresponds with OMAP commits: 7d06c48, 3241b19,
88b5d9b, 18a5500, 9c909ac, 5c6497b, 8b1f0bd, 2ac1da8.
For both OMAP2 and OMAP3, we note the reference and bypass clocks in
the DPLL data structure. Whenever we modify the DPLL rate, we first
ensure that both the reference and bypass clocks are enabled. Then,
we decide whether to use the reference and DPLL, or the bypass clock
if the desired rate is identical to the bypass rate, and program the
DPLL appropriately. Finally, we update the clock's parent, and then
disable the unused clocks.
This keeps the parents correctly balanced, and more importantly ensures
that the bypass clock is running whenever we reprogram the DPLL. This
is especially important because the procedure for reprogramming the DPLL
involves switching to the bypass clock.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
2009-02-19 21:29:22 +08:00
|
|
|
#include "clock.h"
|
2008-03-18 16:04:51 +08:00
|
|
|
#include "sdrc.h"
|
2012-10-30 04:54:06 +08:00
|
|
|
#include "sram.h"
|
2006-04-03 00:46:20 +08:00
|
|
|
|
2009-01-29 03:27:31 +08:00
|
|
|
/* Memory timing, DLL mode flags */
|
|
|
|
#define M_DDR 1
|
|
|
|
#define M_LOCK_CTRL (1 << 2)
|
|
|
|
#define M_UNLOCK 0
|
|
|
|
#define M_LOCK 1
|
|
|
|
|
|
|
|
|
2006-04-03 00:46:20 +08:00
|
|
|
static struct memory_timings mem_timings;
|
2008-03-18 16:04:51 +08:00
|
|
|
static u32 curr_perf_level = CORE_CLK_SRC_DPLL_X2;
|
2006-04-03 00:46:20 +08:00
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
static u32 omap2xxx_sdrc_get_slow_dll_ctrl(void)
|
2006-04-03 00:46:20 +08:00
|
|
|
{
|
|
|
|
return mem_timings.slow_dll_ctrl;
|
|
|
|
}
|
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
static u32 omap2xxx_sdrc_get_fast_dll_ctrl(void)
|
2006-04-03 00:46:20 +08:00
|
|
|
{
|
|
|
|
return mem_timings.fast_dll_ctrl;
|
|
|
|
}
|
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
static u32 omap2xxx_sdrc_get_type(void)
|
2006-04-03 00:46:20 +08:00
|
|
|
{
|
|
|
|
return mem_timings.m_type;
|
|
|
|
}
|
|
|
|
|
2008-03-18 16:35:15 +08:00
|
|
|
/*
|
|
|
|
* Check the DLL lock state, and return tue if running in unlock mode.
|
|
|
|
* This is needed to compensate for the shifted DLL value in unlock mode.
|
|
|
|
*/
|
2009-01-29 03:27:37 +08:00
|
|
|
u32 omap2xxx_sdrc_dll_is_unlocked(void)
|
2008-03-18 16:35:15 +08:00
|
|
|
{
|
|
|
|
/* dlla and dllb are a set */
|
|
|
|
u32 dll_state = sdrc_read_reg(SDRC_DLLA_CTRL);
|
|
|
|
|
|
|
|
if ((dll_state & (1 << 2)) == (1 << 2))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 'level' is the value to store to CM_CLKSEL2_PLL.CORE_CLK_SRC.
|
|
|
|
* Practical values are CORE_CLK_SRC_DPLL (for CORE_CLK = DPLL_CLK) or
|
|
|
|
* CORE_CLK_SRC_DPLL_X2 (for CORE_CLK = * DPLL_CLK * 2)
|
2009-01-29 03:27:37 +08:00
|
|
|
*
|
|
|
|
* Used by the clock framework during CORE DPLL changes
|
2008-03-18 16:35:15 +08:00
|
|
|
*/
|
2009-01-29 03:27:37 +08:00
|
|
|
u32 omap2xxx_sdrc_reprogram(u32 level, u32 force)
|
2008-03-18 16:35:15 +08:00
|
|
|
{
|
|
|
|
u32 dll_ctrl, m_type;
|
|
|
|
u32 prev = curr_perf_level;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if ((curr_perf_level == level) && !force)
|
|
|
|
return prev;
|
|
|
|
|
2009-01-29 03:27:34 +08:00
|
|
|
if (level == CORE_CLK_SRC_DPLL)
|
2009-01-29 03:27:37 +08:00
|
|
|
dll_ctrl = omap2xxx_sdrc_get_slow_dll_ctrl();
|
2009-01-29 03:27:34 +08:00
|
|
|
else if (level == CORE_CLK_SRC_DPLL_X2)
|
2009-01-29 03:27:37 +08:00
|
|
|
dll_ctrl = omap2xxx_sdrc_get_fast_dll_ctrl();
|
2009-01-29 03:27:34 +08:00
|
|
|
else
|
2008-03-18 16:35:15 +08:00
|
|
|
return prev;
|
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
m_type = omap2xxx_sdrc_get_type();
|
2008-03-18 16:35:15 +08:00
|
|
|
|
|
|
|
local_irq_save(flags);
|
2010-12-22 12:05:14 +08:00
|
|
|
/*
|
|
|
|
* XXX These calls should be abstracted out through a
|
|
|
|
* prm2xxx.c function
|
|
|
|
*/
|
2009-05-26 02:26:42 +08:00
|
|
|
if (cpu_is_omap2420())
|
2014-04-16 01:37:46 +08:00
|
|
|
writel_relaxed(0xffff, OMAP2420_PRCM_VOLTSETUP);
|
2009-05-26 02:26:42 +08:00
|
|
|
else
|
2014-04-16 01:37:46 +08:00
|
|
|
writel_relaxed(0xffff, OMAP2430_PRCM_VOLTSETUP);
|
2008-03-18 16:35:15 +08:00
|
|
|
omap2_sram_reprogram_sdrc(level, dll_ctrl, m_type);
|
|
|
|
curr_perf_level = level;
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
2009-01-29 03:27:37 +08:00
|
|
|
/* Used by the clock framework during CORE DPLL changes */
|
|
|
|
void omap2xxx_sdrc_init_params(u32 force_lock_to_unlock_mode)
|
2006-04-03 00:46:20 +08:00
|
|
|
{
|
|
|
|
unsigned long dll_cnt;
|
|
|
|
u32 fast_dll = 0;
|
|
|
|
|
2009-01-29 03:27:34 +08:00
|
|
|
/* DDR = 1, SDR = 0 */
|
|
|
|
mem_timings.m_type = !((sdrc_read_reg(SDRC_MR_0) & 0x3) == 0x1);
|
2006-04-03 00:46:20 +08:00
|
|
|
|
|
|
|
/* 2422 es2.05 and beyond has a single SIP DDR instead of 2 like others.
|
|
|
|
* In the case of 2422, its ok to use CS1 instead of CS0.
|
|
|
|
*/
|
|
|
|
if (cpu_is_omap2422())
|
|
|
|
mem_timings.base_cs = 1;
|
|
|
|
else
|
|
|
|
mem_timings.base_cs = 0;
|
|
|
|
|
|
|
|
if (mem_timings.m_type != M_DDR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* With DDR we need to determine the low frequency DLL value */
|
|
|
|
if (((mem_timings.fast_dll_ctrl & (1 << 2)) == M_LOCK_CTRL))
|
|
|
|
mem_timings.dll_mode = M_UNLOCK;
|
|
|
|
else
|
|
|
|
mem_timings.dll_mode = M_LOCK;
|
|
|
|
|
|
|
|
if (mem_timings.base_cs == 0) {
|
2008-03-18 16:04:51 +08:00
|
|
|
fast_dll = sdrc_read_reg(SDRC_DLLA_CTRL);
|
|
|
|
dll_cnt = sdrc_read_reg(SDRC_DLLA_STATUS) & 0xff00;
|
2006-04-03 00:46:20 +08:00
|
|
|
} else {
|
2008-03-18 16:04:51 +08:00
|
|
|
fast_dll = sdrc_read_reg(SDRC_DLLB_CTRL);
|
|
|
|
dll_cnt = sdrc_read_reg(SDRC_DLLB_STATUS) & 0xff00;
|
2006-04-03 00:46:20 +08:00
|
|
|
}
|
|
|
|
if (force_lock_to_unlock_mode) {
|
|
|
|
fast_dll &= ~0xff00;
|
|
|
|
fast_dll |= dll_cnt; /* Current lock mode */
|
|
|
|
}
|
|
|
|
/* set fast timings with DLL filter disabled */
|
|
|
|
mem_timings.fast_dll_ctrl = (fast_dll | (3 << 8));
|
|
|
|
|
|
|
|
/* No disruptions, DDR will be offline & C-ABI not followed */
|
|
|
|
omap2_sram_ddr_init(&mem_timings.slow_dll_ctrl,
|
|
|
|
mem_timings.fast_dll_ctrl,
|
|
|
|
mem_timings.base_cs,
|
|
|
|
force_lock_to_unlock_mode);
|
|
|
|
mem_timings.slow_dll_ctrl &= 0xff00; /* Keep lock value */
|
|
|
|
|
|
|
|
/* Turn status into unlock ctrl */
|
|
|
|
mem_timings.slow_dll_ctrl |=
|
|
|
|
((mem_timings.fast_dll_ctrl & 0xF) | (1 << 2));
|
|
|
|
|
2015-05-14 23:18:46 +08:00
|
|
|
/* 90 degree phase for anything below 133MHz + disable DLL filter */
|
2006-04-03 00:46:20 +08:00
|
|
|
mem_timings.slow_dll_ctrl |= ((1 << 1) | (3 << 8));
|
|
|
|
}
|