Path: blob/master/arch/arm/mach-omap2/clkt2xxx_dpllcore.c
10817 views
/*1* DPLL + CORE_CLK composite clock functions2*3* Copyright (C) 2005-2008 Texas Instruments, Inc.4* Copyright (C) 2004-2010 Nokia Corporation5*6* Contacts:7* Richard Woodruff <[email protected]>8* Paul Walmsley9*10* Based on earlier work by Tuukka Tikkanen, Tony Lindgren,11* Gordon McNutt and RidgeRun, Inc.12*13* This program is free software; you can redistribute it and/or modify14* it under the terms of the GNU General Public License version 2 as15* published by the Free Software Foundation.16*17* XXX The DPLL and CORE clocks should be split into two separate clock18* types.19*/20#undef DEBUG2122#include <linux/kernel.h>23#include <linux/errno.h>24#include <linux/clk.h>25#include <linux/io.h>2627#include <plat/clock.h>28#include <plat/sram.h>29#include <plat/sdrc.h>3031#include "clock.h"32#include "clock2xxx.h"33#include "opp2xxx.h"34#include "cm2xxx_3xxx.h"35#include "cm-regbits-24xx.h"3637/* #define DOWN_VARIABLE_DPLL 1 */ /* Experimental */3839/**40* omap2xxx_clk_get_core_rate - return the CORE_CLK rate41* @clk: pointer to the combined dpll_ck + core_ck (currently "dpll_ck")42*43* Returns the CORE_CLK rate. CORE_CLK can have one of three rate44* sources on OMAP2xxx: the DPLL CLKOUT rate, DPLL CLKOUTX2, or 32KHz45* (the latter is unusual). This currently should be called with46* struct clk *dpll_ck, which is a composite clock of dpll_ck and47* core_ck.48*/49unsigned long omap2xxx_clk_get_core_rate(struct clk *clk)50{51long long core_clk;52u32 v;5354core_clk = omap2_get_dpll_rate(clk);5556v = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);57v &= OMAP24XX_CORE_CLK_SRC_MASK;5859if (v == CORE_CLK_SRC_32K)60core_clk = 32768;61else62core_clk *= v;6364return core_clk;65}6667/*68* Uses the current prcm set to tell if a rate is valid.69* You can go slower, but not faster within a given rate set.70*/71static long omap2_dpllcore_round_rate(unsigned long target_rate)72{73u32 high, low, core_clk_src;7475core_clk_src = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);76core_clk_src &= OMAP24XX_CORE_CLK_SRC_MASK;7778if (core_clk_src == CORE_CLK_SRC_DPLL) { /* DPLL clockout */79high = curr_prcm_set->dpll_speed * 2;80low = curr_prcm_set->dpll_speed;81} else { /* DPLL clockout x 2 */82high = curr_prcm_set->dpll_speed;83low = curr_prcm_set->dpll_speed / 2;84}8586#ifdef DOWN_VARIABLE_DPLL87if (target_rate > high)88return high;89else90return target_rate;91#else92if (target_rate > low)93return high;94else95return low;96#endif9798}99100unsigned long omap2_dpllcore_recalc(struct clk *clk)101{102return omap2xxx_clk_get_core_rate(clk);103}104105int omap2_reprogram_dpllcore(struct clk *clk, unsigned long rate)106{107u32 cur_rate, low, mult, div, valid_rate, done_rate;108u32 bypass = 0;109struct prcm_config tmpset;110const struct dpll_data *dd;111112cur_rate = omap2xxx_clk_get_core_rate(dclk);113mult = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);114mult &= OMAP24XX_CORE_CLK_SRC_MASK;115116if ((rate == (cur_rate / 2)) && (mult == 2)) {117omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL, 1);118} else if ((rate == (cur_rate * 2)) && (mult == 1)) {119omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);120} else if (rate != cur_rate) {121valid_rate = omap2_dpllcore_round_rate(rate);122if (valid_rate != rate)123return -EINVAL;124125if (mult == 1)126low = curr_prcm_set->dpll_speed;127else128low = curr_prcm_set->dpll_speed / 2;129130dd = clk->dpll_data;131if (!dd)132return -EINVAL;133134tmpset.cm_clksel1_pll = __raw_readl(dd->mult_div1_reg);135tmpset.cm_clksel1_pll &= ~(dd->mult_mask |136dd->div1_mask);137div = ((curr_prcm_set->xtal_speed / 1000000) - 1);138tmpset.cm_clksel2_pll = omap2_cm_read_mod_reg(PLL_MOD, CM_CLKSEL2);139tmpset.cm_clksel2_pll &= ~OMAP24XX_CORE_CLK_SRC_MASK;140if (rate > low) {141tmpset.cm_clksel2_pll |= CORE_CLK_SRC_DPLL_X2;142mult = ((rate / 2) / 1000000);143done_rate = CORE_CLK_SRC_DPLL_X2;144} else {145tmpset.cm_clksel2_pll |= CORE_CLK_SRC_DPLL;146mult = (rate / 1000000);147done_rate = CORE_CLK_SRC_DPLL;148}149tmpset.cm_clksel1_pll |= (div << __ffs(dd->mult_mask));150tmpset.cm_clksel1_pll |= (mult << __ffs(dd->div1_mask));151152/* Worst case */153tmpset.base_sdrc_rfr = SDRC_RFR_CTRL_BYPASS;154155if (rate == curr_prcm_set->xtal_speed) /* If asking for 1-1 */156bypass = 1;157158/* For omap2xxx_sdrc_init_params() */159omap2xxx_sdrc_reprogram(CORE_CLK_SRC_DPLL_X2, 1);160161/* Force dll lock mode */162omap2_set_prcm(tmpset.cm_clksel1_pll, tmpset.base_sdrc_rfr,163bypass);164165/* Errata: ret dll entry state */166omap2xxx_sdrc_init_params(omap2xxx_sdrc_dll_is_unlocked());167omap2xxx_sdrc_reprogram(done_rate, 0);168}169170return 0;171}172173174175