196609ef4SPaul Walmsley /* 296609ef4SPaul Walmsley * linux/arch/arm/mach-omap2/sdrc2xxx.c 396609ef4SPaul Walmsley * 496609ef4SPaul Walmsley * SDRAM timing related functions for OMAP2xxx 596609ef4SPaul Walmsley * 6f2ab9977SPaul Walmsley * Copyright (C) 2005, 2008 Texas Instruments Inc. 7f2ab9977SPaul Walmsley * Copyright (C) 2005, 2008 Nokia Corporation 896609ef4SPaul Walmsley * 996609ef4SPaul Walmsley * Tony Lindgren <tony@atomide.com> 10f2ab9977SPaul Walmsley * Paul Walmsley 11f2ab9977SPaul Walmsley * Richard Woodruff <r-woodruff2@ti.com> 1296609ef4SPaul Walmsley * 1396609ef4SPaul Walmsley * This program is free software; you can redistribute it and/or modify 1496609ef4SPaul Walmsley * it under the terms of the GNU General Public License version 2 as 1596609ef4SPaul Walmsley * published by the Free Software Foundation. 1696609ef4SPaul Walmsley */ 1796609ef4SPaul Walmsley 1896609ef4SPaul Walmsley #include <linux/module.h> 1996609ef4SPaul Walmsley #include <linux/kernel.h> 2096609ef4SPaul Walmsley #include <linux/device.h> 2196609ef4SPaul Walmsley #include <linux/list.h> 2296609ef4SPaul Walmsley #include <linux/errno.h> 2396609ef4SPaul Walmsley #include <linux/delay.h> 2496609ef4SPaul Walmsley #include <linux/clk.h> 2596609ef4SPaul Walmsley #include <linux/io.h> 2696609ef4SPaul Walmsley 27dbc04161STony Lindgren #include "soc.h" 28ee0839c2STony Lindgren #include "iomap.h" 29ee0839c2STony Lindgren #include "common.h" 30139563adSPaul Walmsley #include "prm2xxx.h" 31c0bf3132SRussell King #include "clock.h" 3296609ef4SPaul Walmsley #include "sdrc.h" 33bf027ca1STony Lindgren #include "sram.h" 3496609ef4SPaul Walmsley 3596609ef4SPaul Walmsley /* Memory timing, DLL mode flags */ 3696609ef4SPaul Walmsley #define M_DDR 1 3796609ef4SPaul Walmsley #define M_LOCK_CTRL (1 << 2) 3896609ef4SPaul Walmsley #define M_UNLOCK 0 3996609ef4SPaul Walmsley #define M_LOCK 1 4096609ef4SPaul Walmsley 4196609ef4SPaul Walmsley 4296609ef4SPaul Walmsley static struct memory_timings mem_timings; 4396609ef4SPaul Walmsley static u32 curr_perf_level = CORE_CLK_SRC_DPLL_X2; 4496609ef4SPaul Walmsley 45f2ab9977SPaul Walmsley static u32 omap2xxx_sdrc_get_slow_dll_ctrl(void) 4696609ef4SPaul Walmsley { 4796609ef4SPaul Walmsley return mem_timings.slow_dll_ctrl; 4896609ef4SPaul Walmsley } 4996609ef4SPaul Walmsley 50f2ab9977SPaul Walmsley static u32 omap2xxx_sdrc_get_fast_dll_ctrl(void) 5196609ef4SPaul Walmsley { 5296609ef4SPaul Walmsley return mem_timings.fast_dll_ctrl; 5396609ef4SPaul Walmsley } 5496609ef4SPaul Walmsley 55f2ab9977SPaul Walmsley static u32 omap2xxx_sdrc_get_type(void) 5696609ef4SPaul Walmsley { 5796609ef4SPaul Walmsley return mem_timings.m_type; 5896609ef4SPaul Walmsley } 5996609ef4SPaul Walmsley 6096609ef4SPaul Walmsley /* 6196609ef4SPaul Walmsley * Check the DLL lock state, and return tue if running in unlock mode. 6296609ef4SPaul Walmsley * This is needed to compensate for the shifted DLL value in unlock mode. 6396609ef4SPaul Walmsley */ 64f2ab9977SPaul Walmsley u32 omap2xxx_sdrc_dll_is_unlocked(void) 6596609ef4SPaul Walmsley { 6696609ef4SPaul Walmsley /* dlla and dllb are a set */ 6796609ef4SPaul Walmsley u32 dll_state = sdrc_read_reg(SDRC_DLLA_CTRL); 6896609ef4SPaul Walmsley 6996609ef4SPaul Walmsley if ((dll_state & (1 << 2)) == (1 << 2)) 7096609ef4SPaul Walmsley return 1; 7196609ef4SPaul Walmsley else 7296609ef4SPaul Walmsley return 0; 7396609ef4SPaul Walmsley } 7496609ef4SPaul Walmsley 7596609ef4SPaul Walmsley /* 7696609ef4SPaul Walmsley * 'level' is the value to store to CM_CLKSEL2_PLL.CORE_CLK_SRC. 7796609ef4SPaul Walmsley * Practical values are CORE_CLK_SRC_DPLL (for CORE_CLK = DPLL_CLK) or 7896609ef4SPaul Walmsley * CORE_CLK_SRC_DPLL_X2 (for CORE_CLK = * DPLL_CLK * 2) 79f2ab9977SPaul Walmsley * 80f2ab9977SPaul Walmsley * Used by the clock framework during CORE DPLL changes 8196609ef4SPaul Walmsley */ 82f2ab9977SPaul Walmsley u32 omap2xxx_sdrc_reprogram(u32 level, u32 force) 8396609ef4SPaul Walmsley { 8496609ef4SPaul Walmsley u32 dll_ctrl, m_type; 8596609ef4SPaul Walmsley u32 prev = curr_perf_level; 8696609ef4SPaul Walmsley unsigned long flags; 8796609ef4SPaul Walmsley 8896609ef4SPaul Walmsley if ((curr_perf_level == level) && !force) 8996609ef4SPaul Walmsley return prev; 9096609ef4SPaul Walmsley 9196609ef4SPaul Walmsley if (level == CORE_CLK_SRC_DPLL) 92f2ab9977SPaul Walmsley dll_ctrl = omap2xxx_sdrc_get_slow_dll_ctrl(); 9396609ef4SPaul Walmsley else if (level == CORE_CLK_SRC_DPLL_X2) 94f2ab9977SPaul Walmsley dll_ctrl = omap2xxx_sdrc_get_fast_dll_ctrl(); 9596609ef4SPaul Walmsley else 9696609ef4SPaul Walmsley return prev; 9796609ef4SPaul Walmsley 98f2ab9977SPaul Walmsley m_type = omap2xxx_sdrc_get_type(); 9996609ef4SPaul Walmsley 10096609ef4SPaul Walmsley local_irq_save(flags); 101c4d7e58fSPaul Walmsley /* 102c4d7e58fSPaul Walmsley * XXX These calls should be abstracted out through a 103c4d7e58fSPaul Walmsley * prm2xxx.c function 104c4d7e58fSPaul Walmsley */ 1058e3bd351STony Lindgren if (cpu_is_omap2420()) 106edfaf05cSVictor Kamensky writel_relaxed(0xffff, OMAP2420_PRCM_VOLTSETUP); 1078e3bd351STony Lindgren else 108edfaf05cSVictor Kamensky writel_relaxed(0xffff, OMAP2430_PRCM_VOLTSETUP); 10996609ef4SPaul Walmsley omap2_sram_reprogram_sdrc(level, dll_ctrl, m_type); 11096609ef4SPaul Walmsley curr_perf_level = level; 11196609ef4SPaul Walmsley local_irq_restore(flags); 11296609ef4SPaul Walmsley 11396609ef4SPaul Walmsley return prev; 11496609ef4SPaul Walmsley } 11596609ef4SPaul Walmsley 116f2ab9977SPaul Walmsley /* Used by the clock framework during CORE DPLL changes */ 117f2ab9977SPaul Walmsley void omap2xxx_sdrc_init_params(u32 force_lock_to_unlock_mode) 11896609ef4SPaul Walmsley { 11996609ef4SPaul Walmsley unsigned long dll_cnt; 12096609ef4SPaul Walmsley u32 fast_dll = 0; 12196609ef4SPaul Walmsley 12296609ef4SPaul Walmsley /* DDR = 1, SDR = 0 */ 12396609ef4SPaul Walmsley mem_timings.m_type = !((sdrc_read_reg(SDRC_MR_0) & 0x3) == 0x1); 12496609ef4SPaul Walmsley 12596609ef4SPaul Walmsley /* 2422 es2.05 and beyond has a single SIP DDR instead of 2 like others. 12696609ef4SPaul Walmsley * In the case of 2422, its ok to use CS1 instead of CS0. 12796609ef4SPaul Walmsley */ 12896609ef4SPaul Walmsley if (cpu_is_omap2422()) 12996609ef4SPaul Walmsley mem_timings.base_cs = 1; 13096609ef4SPaul Walmsley else 13196609ef4SPaul Walmsley mem_timings.base_cs = 0; 13296609ef4SPaul Walmsley 13396609ef4SPaul Walmsley if (mem_timings.m_type != M_DDR) 13496609ef4SPaul Walmsley return; 13596609ef4SPaul Walmsley 13696609ef4SPaul Walmsley /* With DDR we need to determine the low frequency DLL value */ 13796609ef4SPaul Walmsley if (((mem_timings.fast_dll_ctrl & (1 << 2)) == M_LOCK_CTRL)) 13896609ef4SPaul Walmsley mem_timings.dll_mode = M_UNLOCK; 13996609ef4SPaul Walmsley else 14096609ef4SPaul Walmsley mem_timings.dll_mode = M_LOCK; 14196609ef4SPaul Walmsley 14296609ef4SPaul Walmsley if (mem_timings.base_cs == 0) { 14396609ef4SPaul Walmsley fast_dll = sdrc_read_reg(SDRC_DLLA_CTRL); 14496609ef4SPaul Walmsley dll_cnt = sdrc_read_reg(SDRC_DLLA_STATUS) & 0xff00; 14596609ef4SPaul Walmsley } else { 14696609ef4SPaul Walmsley fast_dll = sdrc_read_reg(SDRC_DLLB_CTRL); 14796609ef4SPaul Walmsley dll_cnt = sdrc_read_reg(SDRC_DLLB_STATUS) & 0xff00; 14896609ef4SPaul Walmsley } 14996609ef4SPaul Walmsley if (force_lock_to_unlock_mode) { 15096609ef4SPaul Walmsley fast_dll &= ~0xff00; 15196609ef4SPaul Walmsley fast_dll |= dll_cnt; /* Current lock mode */ 15296609ef4SPaul Walmsley } 15396609ef4SPaul Walmsley /* set fast timings with DLL filter disabled */ 15496609ef4SPaul Walmsley mem_timings.fast_dll_ctrl = (fast_dll | (3 << 8)); 15596609ef4SPaul Walmsley 15696609ef4SPaul Walmsley /* No disruptions, DDR will be offline & C-ABI not followed */ 15796609ef4SPaul Walmsley omap2_sram_ddr_init(&mem_timings.slow_dll_ctrl, 15896609ef4SPaul Walmsley mem_timings.fast_dll_ctrl, 15996609ef4SPaul Walmsley mem_timings.base_cs, 16096609ef4SPaul Walmsley force_lock_to_unlock_mode); 16196609ef4SPaul Walmsley mem_timings.slow_dll_ctrl &= 0xff00; /* Keep lock value */ 16296609ef4SPaul Walmsley 16396609ef4SPaul Walmsley /* Turn status into unlock ctrl */ 16496609ef4SPaul Walmsley mem_timings.slow_dll_ctrl |= 16596609ef4SPaul Walmsley ((mem_timings.fast_dll_ctrl & 0xF) | (1 << 2)); 16696609ef4SPaul Walmsley 167*6a53bc75SRussell King /* 90 degree phase for anything below 133MHz + disable DLL filter */ 16896609ef4SPaul Walmsley mem_timings.slow_dll_ctrl |= ((1 << 1) | (3 << 8)); 16996609ef4SPaul Walmsley } 170