2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-01-14 23:46:19 +00:00
|
|
|
/*
|
|
|
|
*
|
2012-03-26 21:49:03 +00:00
|
|
|
* Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
|
2008-01-14 23:46:19 +00:00
|
|
|
* TsiChung Liew (Tsi-Chung.Liew@freescale.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:44:58 +00:00
|
|
|
#include <clock_legacy.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2008-01-14 23:46:19 +00:00
|
|
|
#include <asm/processor.h>
|
|
|
|
|
|
|
|
#include <asm/immap.h>
|
2012-03-26 21:49:03 +00:00
|
|
|
#include <asm/io.h>
|
2008-01-14 23:46:19 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Low Power Divider specifications
|
|
|
|
*/
|
|
|
|
#define CLOCK_LPD_MIN (1 << 0) /* Divider (decoded) */
|
|
|
|
#define CLOCK_LPD_MAX (1 << 15) /* Divider (decoded) */
|
|
|
|
|
|
|
|
#define CLOCK_PLL_FVCO_MAX 540000000
|
|
|
|
#define CLOCK_PLL_FVCO_MIN 300000000
|
|
|
|
|
|
|
|
#define CLOCK_PLL_FSYS_MAX 266666666
|
|
|
|
#define CLOCK_PLL_FSYS_MIN 100000000
|
|
|
|
#define MHZ 1000000
|
|
|
|
|
|
|
|
void clock_enter_limp(int lpdiv)
|
|
|
|
{
|
2012-03-26 21:49:03 +00:00
|
|
|
ccm_t *ccm = (ccm_t *)MMAP_CCM;
|
2008-01-14 23:46:19 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* Check bounds of divider */
|
|
|
|
if (lpdiv < CLOCK_LPD_MIN)
|
|
|
|
lpdiv = CLOCK_LPD_MIN;
|
|
|
|
if (lpdiv > CLOCK_LPD_MAX)
|
|
|
|
lpdiv = CLOCK_LPD_MAX;
|
|
|
|
|
|
|
|
/* Round divider down to nearest power of two */
|
|
|
|
for (i = 0, j = lpdiv; j != 1; j >>= 1, i++) ;
|
|
|
|
|
|
|
|
/* Apply the divider to the system clock */
|
2012-03-26 21:49:03 +00:00
|
|
|
clrsetbits_be16(&ccm->cdr, 0x0f00, CCM_CDR_LPDIV(i));
|
2008-01-14 23:46:19 +00:00
|
|
|
|
|
|
|
/* Enable Limp Mode */
|
2012-03-26 21:49:03 +00:00
|
|
|
setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
|
2008-01-14 23:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* brief Exit Limp mode
|
|
|
|
* warning The PLL should be set and locked prior to exiting Limp mode
|
|
|
|
*/
|
|
|
|
void clock_exit_limp(void)
|
|
|
|
{
|
2012-03-26 21:49:03 +00:00
|
|
|
ccm_t *ccm = (ccm_t *)MMAP_CCM;
|
|
|
|
pll_t *pll = (pll_t *)MMAP_PLL;
|
2008-01-14 23:46:19 +00:00
|
|
|
|
|
|
|
/* Exit Limp mode */
|
2012-03-26 21:49:03 +00:00
|
|
|
clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
|
2008-01-14 23:46:19 +00:00
|
|
|
|
|
|
|
/* Wait for the PLL to lock */
|
2012-03-26 21:49:03 +00:00
|
|
|
while (!(in_be32(&pll->psr) & PLL_PSR_LOCK))
|
|
|
|
;
|
2008-01-14 23:46:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_clocks() fills in gd->cpu_clock and gd->bus_clk
|
|
|
|
*/
|
|
|
|
int get_clocks(void)
|
|
|
|
{
|
|
|
|
|
2012-03-26 21:49:03 +00:00
|
|
|
ccm_t *ccm = (ccm_t *)MMAP_CCM;
|
|
|
|
pll_t *pll = (pll_t *)MMAP_PLL;
|
2008-01-14 23:46:19 +00:00
|
|
|
int vco, temp, pcrvalue, pfdr;
|
|
|
|
u8 bootmode;
|
|
|
|
|
2012-03-26 21:49:03 +00:00
|
|
|
pcrvalue = in_be32(&pll->pcr) & 0xFF0F0FFF;
|
2008-01-14 23:46:19 +00:00
|
|
|
pfdr = pcrvalue >> 24;
|
|
|
|
|
2008-10-21 15:37:02 +00:00
|
|
|
if (pfdr == 0x1E)
|
|
|
|
bootmode = 0; /* Normal Mode */
|
|
|
|
|
|
|
|
#ifdef CONFIG_CF_SBF
|
|
|
|
bootmode = 3; /* Serial Mode */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (bootmode == 0) {
|
|
|
|
/* Normal mode */
|
2012-03-26 21:49:03 +00:00
|
|
|
vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
|
2008-10-21 15:37:02 +00:00
|
|
|
if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
|
|
|
|
/* Default value */
|
2012-03-26 21:49:03 +00:00
|
|
|
pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF);
|
2008-10-21 15:37:02 +00:00
|
|
|
pcrvalue |= 0x1E << 24;
|
2012-03-26 21:49:03 +00:00
|
|
|
out_be32(&pll->pcr, pcrvalue);
|
2008-10-21 15:37:02 +00:00
|
|
|
vco =
|
2012-03-26 21:49:03 +00:00
|
|
|
((in_be32(&pll->pcr) & 0xFF000000) >> 24) *
|
2008-10-21 15:37:02 +00:00
|
|
|
CONFIG_SYS_INPUT_CLKSRC;
|
|
|
|
}
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.vco_clk = vco; /* Vco clock */
|
2008-10-21 15:37:02 +00:00
|
|
|
} else if (bootmode == 3) {
|
2008-01-14 23:46:19 +00:00
|
|
|
/* serial mode */
|
2012-03-26 21:49:03 +00:00
|
|
|
vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.vco_clk = vco; /* Vco clock */
|
2008-01-14 23:46:19 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 21:49:03 +00:00
|
|
|
if ((in_be16(&ccm->ccr) & CCM_MISCCR_LIMP) == CCM_MISCCR_LIMP) {
|
2008-01-14 23:46:19 +00:00
|
|
|
/* Limp mode */
|
|
|
|
} else {
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */
|
2008-01-14 23:46:19 +00:00
|
|
|
|
2012-03-26 21:49:03 +00:00
|
|
|
temp = (in_be32(&pll->pcr) & PLL_PCR_OUTDIV1_MASK) + 1;
|
2008-01-14 23:46:19 +00:00
|
|
|
gd->cpu_clk = vco / temp; /* cpu clock */
|
|
|
|
|
2012-03-26 21:49:03 +00:00
|
|
|
temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.flb_clk = vco / temp; /* flexbus clock */
|
|
|
|
gd->bus_clk = gd->arch.flb_clk;
|
2008-01-14 23:46:19 +00:00
|
|
|
}
|
|
|
|
|
2012-10-24 11:48:22 +00:00
|
|
|
#ifdef CONFIG_SYS_I2C_FSL
|
2012-12-13 20:48:49 +00:00
|
|
|
gd->arch.i2c1_clk = gd->bus_clk;
|
2008-08-18 21:01:19 +00:00
|
|
|
#endif
|
|
|
|
|
2008-01-14 23:46:19 +00:00
|
|
|
return (0);
|
|
|
|
}
|