2 * Copyright (C) 2011 by Vladimir Zapolskiy <vz@mleia.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #include <asm/arch/cpu.h>
23 #include <asm/arch/clk.h>
26 static struct clk_pm_regs *clk = (struct clk_pm_regs *)CLK_PM_BASE;
28 unsigned int get_sys_clk_rate(void)
30 if (readl(&clk->sysclk_ctrl) & CLK_SYSCLK_PLL397)
31 return RTC_CLK_FREQUENCY * 397;
33 return OSC_CLK_FREQUENCY;
36 unsigned int get_hclk_pll_rate(void)
38 unsigned long long fin, fref, fcco, fout;
39 u32 val, m_div, n_div, p_div;
42 * Valid frequency ranges:
43 * 1 * 10^6 <= Fin <= 20 * 10^6
44 * 1 * 10^6 <= Fref <= 27 * 10^6
45 * 156 * 10^6 <= Fcco <= 320 * 10^6
48 fref = fin = get_sys_clk_rate();
49 if (fin > 20000000ULL || fin < 1000000ULL)
52 val = readl(&clk->hclkpll_ctrl);
53 m_div = ((val & CLK_HCLK_PLL_FEEDBACK_DIV_MASK) >> 1) + 1;
54 n_div = ((val & CLK_HCLK_PLL_PREDIV_MASK) >> 9) + 1;
55 if (val & CLK_HCLK_PLL_DIRECT)
58 p_div = ((val & CLK_HCLK_PLL_POSTDIV_MASK) >> 11) + 1;
61 if (val & CLK_HCLK_PLL_BYPASS) {
67 if (fref > 27000000ULL || fref < 1000000ULL)
71 if (val & CLK_HCLK_PLL_FEEDBACK) {
77 if (fcco > 320000000ULL || fcco < 156000000ULL)
83 unsigned int get_hclk_clk_div(void)
87 val = readl(&clk->hclkdiv_ctrl) & CLK_HCLK_ARM_PLL_DIV_MASK;
92 unsigned int get_hclk_clk_rate(void)
94 return get_hclk_pll_rate() / get_hclk_clk_div();
97 unsigned int get_periph_clk_div(void)
101 val = readl(&clk->hclkdiv_ctrl) & CLK_HCLK_PERIPH_DIV_MASK;
103 return (val >> 2) + 1;
106 unsigned int get_periph_clk_rate(void)
108 if (!(readl(&clk->pwr_ctrl) & CLK_PWR_NORMAL_RUN))
109 return get_sys_clk_rate();
111 return get_hclk_pll_rate() / get_periph_clk_div();
114 int get_serial_clock(void)
116 return get_periph_clk_rate();