2008-04-11 08:51:27 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Michael Sevakis
|
|
|
|
*
|
|
|
|
* Clock control functions for IMX31 processor
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-04-11 08:51:27 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "system.h"
|
|
|
|
#include "cpu.h"
|
2009-03-22 02:13:27 +00:00
|
|
|
#include "ccm-imx31.h"
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
/* Return the current source pll for MCU */
|
|
|
|
enum IMX31_PLLS ccm_get_src_pll(void)
|
2009-02-08 22:32:41 +00:00
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
return (CCM_PMCR0 & 0xC0000000) == 0 ? PLL_SERIAL : PLL_MCU;
|
2009-02-08 22:32:41 +00:00
|
|
|
}
|
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
void ccm_module_clock_gating(enum IMX31_CG_LIST cg, enum IMX31_CG_MODES mode)
|
2008-04-11 08:51:27 +00:00
|
|
|
{
|
|
|
|
volatile unsigned long *reg;
|
|
|
|
unsigned long mask;
|
|
|
|
int shift;
|
|
|
|
|
|
|
|
if (cg >= CG_NUM_CLOCKS)
|
|
|
|
return;
|
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
reg = &CCM_CGR0 + cg / 16; /* Select CGR0, CGR1, CGR2 */
|
|
|
|
shift = 2*(cg % 16); /* Get field shift */
|
|
|
|
mask = CG_MASK << shift; /* Select field */
|
2008-04-11 08:51:27 +00:00
|
|
|
|
2010-06-30 02:02:46 +00:00
|
|
|
bitmod32(reg, mode << shift, mask);
|
2008-04-11 08:51:27 +00:00
|
|
|
}
|
2008-05-05 10:53:06 +00:00
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
/* Decode PLL output frequency from register value */
|
|
|
|
unsigned int ccm_calc_pll_rate(unsigned int infreq, unsigned long regval)
|
|
|
|
{
|
|
|
|
uint32_t mfn = regval & 0x3ff;
|
|
|
|
uint32_t pd = ((regval >> 26) & 0xf) + 1;
|
|
|
|
uint32_t mfd = ((regval >> 16) & 0x3ff) + 1;
|
|
|
|
uint32_t mfi = (regval >> 10) & 0xf;
|
|
|
|
|
|
|
|
mfi = mfi <= 5 ? 5 : mfi;
|
|
|
|
|
|
|
|
return 2ull*infreq*(mfi * mfd + mfn) / (mfd * pd);
|
|
|
|
}
|
|
|
|
|
2008-05-05 10:53:06 +00:00
|
|
|
/* Get the PLL reference clock frequency in HZ */
|
2010-04-23 15:32:50 +00:00
|
|
|
unsigned int ccm_get_pll_ref_clk_rate(void)
|
2008-05-05 10:53:06 +00:00
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
if ((CCM_CCMR & (3 << 1)) == (1 << 1))
|
2010-04-09 03:24:17 +00:00
|
|
|
return CONFIG_CKIL_FREQ * 1024;
|
2008-05-05 10:53:06 +00:00
|
|
|
else
|
2010-04-09 03:24:17 +00:00
|
|
|
return CONFIG_CKIH_FREQ;
|
2008-05-05 10:53:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return PLL frequency in HZ */
|
2010-04-23 15:32:50 +00:00
|
|
|
unsigned int ccm_get_pll_rate(enum IMX31_PLLS pll)
|
2008-05-05 10:53:06 +00:00
|
|
|
{
|
2010-04-23 15:32:50 +00:00
|
|
|
return ccm_calc_pll_rate(ccm_get_pll_ref_clk_rate(), (&CCM_MPCTL)[pll]);
|
|
|
|
}
|
2008-05-05 10:53:06 +00:00
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
unsigned int ccm_get_mcu_clk(void)
|
|
|
|
{
|
|
|
|
unsigned int pllnum = ccm_get_src_pll();
|
|
|
|
unsigned int fpll = ccm_get_pll_rate(pllnum);
|
|
|
|
unsigned int mcu_podf = (CCM_PDR0 & 0x7) + 1;
|
2008-05-05 10:53:06 +00:00
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
return fpll / mcu_podf;
|
2008-05-05 10:53:06 +00:00
|
|
|
}
|
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
unsigned int ccm_get_ipg_clk(void)
|
2008-05-05 10:53:06 +00:00
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
unsigned int pllnum = ccm_get_src_pll();
|
2010-04-23 15:32:50 +00:00
|
|
|
unsigned int fpll = ccm_get_pll_rate(pllnum);
|
2009-03-22 01:50:48 +00:00
|
|
|
uint32_t reg = CCM_PDR0;
|
2008-05-05 10:53:06 +00:00
|
|
|
unsigned int max_pdf = ((reg >> 3) & 0x7) + 1;
|
|
|
|
unsigned int ipg_pdf = ((reg >> 6) & 0x3) + 1;
|
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
return fpll / (max_pdf * ipg_pdf);
|
2008-05-05 10:53:06 +00:00
|
|
|
}
|
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
unsigned int ccm_get_ahb_clk(void)
|
2009-02-08 22:32:41 +00:00
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
unsigned int pllnum = ccm_get_src_pll();
|
2010-04-23 15:32:50 +00:00
|
|
|
unsigned int fpll = ccm_get_pll_rate(pllnum);
|
2009-03-22 01:50:48 +00:00
|
|
|
unsigned int max_pdf = ((CCM_PDR0 >> 3) & 0x7) + 1;
|
2009-02-08 22:32:41 +00:00
|
|
|
|
2010-04-23 15:32:50 +00:00
|
|
|
return fpll / max_pdf;
|
2009-02-08 22:32:41 +00:00
|
|
|
}
|
|
|
|
|
2009-03-22 01:50:48 +00:00
|
|
|
unsigned int ccm_get_ata_clk(void)
|
2008-05-05 10:53:06 +00:00
|
|
|
{
|
2009-03-22 01:50:48 +00:00
|
|
|
return ccm_get_ipg_clk();
|
2008-05-05 10:53:06 +00:00
|
|
|
}
|
2010-04-23 15:32:50 +00:00
|
|
|
|
|
|
|
/* Write new values to the current PLL and post-dividers */
|
|
|
|
void ccm_set_mcupll_and_pdr(unsigned long pllctl, unsigned long pdr)
|
|
|
|
{
|
|
|
|
unsigned int pll = ccm_get_src_pll();
|
|
|
|
volatile unsigned long *pllreg = &(&CCM_MPCTL)[pll];
|
|
|
|
unsigned long fref = ccm_get_pll_ref_clk_rate();
|
|
|
|
unsigned long curfreq = ccm_calc_pll_rate(fref, *pllreg);
|
|
|
|
unsigned long newfreq = ccm_calc_pll_rate(fref, pllctl);
|
|
|
|
|
|
|
|
if (newfreq > curfreq)
|
|
|
|
CCM_PDR0 = pdr;
|
|
|
|
|
|
|
|
*pllreg = pllctl;
|
|
|
|
|
|
|
|
if (newfreq <= curfreq)
|
|
|
|
CCM_PDR0 = pdr;
|
|
|
|
}
|