2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2007-08-16 20:05:11 +00:00
|
|
|
/*
|
|
|
|
*
|
2012-03-26 21:49:08 +00:00
|
|
|
* Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
|
2007-08-16 20:05:11 +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>
|
2007-08-16 20:05:11 +00:00
|
|
|
#include <asm/processor.h>
|
|
|
|
|
|
|
|
#include <asm/immap.h>
|
2012-03-26 21:49:08 +00:00
|
|
|
#include <asm/io.h>
|
2007-08-16 20:05:11 +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:08 +00:00
|
|
|
ccm_t *ccm = (ccm_t *)MMAP_CCM;
|
2007-08-16 20:05:11 +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++) ;
|
|
|
|
|
2012-10-18 19:25:51 +00:00
|
|
|
#ifdef CONFIG_MCF5445x
|
2007-08-16 20:05:11 +00:00
|
|
|
/* Apply the divider to the system clock */
|
2012-03-26 21:49:08 +00:00
|
|
|
clrsetbits_be16(&ccm->cdr, 0x0f00, CCM_CDR_LPDIV(i));
|
2012-10-18 19:25:51 +00:00
|
|
|
#endif
|
2007-08-16 20:05:11 +00:00
|
|
|
|
|
|
|
/* Enable Limp Mode */
|
2012-03-26 21:49:08 +00:00
|
|
|
setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
|
2007-08-16 20:05:11 +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:08 +00:00
|
|
|
ccm_t *ccm = (ccm_t *)MMAP_CCM;
|
|
|
|
pll_t *pll = (pll_t *)MMAP_PLL;
|
2007-08-16 20:05:11 +00:00
|
|
|
|
|
|
|
/* Exit Limp mode */
|
2012-03-26 21:49:08 +00:00
|
|
|
clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
|
2007-08-16 20:05:11 +00:00
|
|
|
|
|
|
|
/* Wait for the PLL to lock */
|
2012-03-26 21:49:08 +00:00
|
|
|
while (!(in_be32(&pll->psr) & PLL_PSR_LOCK))
|
|
|
|
;
|
2007-08-16 20:05:11 +00:00
|
|
|
}
|
|
|
|
|
2012-10-18 19:25:51 +00:00
|
|
|
#ifdef CONFIG_MCF5441x
|
|
|
|
void setup_5441x_clocks(void)
|
2007-08-16 20:05:11 +00:00
|
|
|
{
|
2012-10-18 19:25:51 +00:00
|
|
|
ccm_t *ccm = (ccm_t *)MMAP_CCM;
|
|
|
|
pll_t *pll = (pll_t *)MMAP_PLL;
|
|
|
|
int temp, vco = 0, bootmod_ccr, pdr;
|
|
|
|
|
|
|
|
bootmod_ccr = (in_be16(&ccm->ccr) & CCM_CCR_BOOTMOD) >> 14;
|
|
|
|
|
|
|
|
switch (bootmod_ccr) {
|
|
|
|
case 0:
|
|
|
|
out_be32(&pll->pcr, 0x00000013);
|
|
|
|
out_be32(&pll->pdr, 0x00e70c61);
|
|
|
|
clock_exit_limp();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
}
|
2008-07-24 01:38:53 +00:00
|
|
|
|
2012-10-18 19:25:51 +00:00
|
|
|
/*Change frequency for Modelo SER1 USB host*/
|
|
|
|
#ifdef CONFIG_LOW_MCFCLK
|
|
|
|
temp = in_be32(&pll->pcr);
|
|
|
|
temp &= ~0x3f;
|
|
|
|
temp |= 5;
|
|
|
|
out_be32(&pll->pcr, temp);
|
|
|
|
|
|
|
|
temp = in_be32(&pll->pdr);
|
|
|
|
temp &= ~0x001f0000;
|
|
|
|
temp |= 0x00040000;
|
|
|
|
out_be32(&pll->pdr, temp);
|
|
|
|
__asm__("tpf");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
setbits_be16(&ccm->misccr2, 0x02);
|
|
|
|
|
|
|
|
vco = ((in_be32(&pll->pcr) & PLL_CR_FBKDIV_BITS) + 1) *
|
|
|
|
CONFIG_SYS_INPUT_CLKSRC;
|
2013-06-26 02:21:31 +00:00
|
|
|
gd->arch.vco_clk = vco;
|
2012-10-18 19:25:51 +00:00
|
|
|
|
2013-06-26 02:21:31 +00:00
|
|
|
gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */
|
2012-10-18 19:25:51 +00:00
|
|
|
|
|
|
|
pdr = in_be32(&pll->pdr);
|
|
|
|
temp = (pdr & PLL_DR_OUTDIV1_BITS) + 1;
|
|
|
|
gd->cpu_clk = vco / temp; /* cpu clock */
|
2013-06-26 02:21:31 +00:00
|
|
|
gd->arch.flb_clk = vco / temp; /* FlexBus clock */
|
|
|
|
gd->arch.flb_clk >>= 1;
|
2014-06-30 09:59:06 +00:00
|
|
|
if (in_be16(&ccm->misccr2) & 2) /* fsys/4 */
|
2013-06-26 02:21:31 +00:00
|
|
|
gd->arch.flb_clk >>= 1;
|
2012-10-18 19:25:51 +00:00
|
|
|
|
|
|
|
temp = ((pdr & PLL_DR_OUTDIV2_BITS) >> 5) + 1;
|
|
|
|
gd->bus_clk = vco / temp; /* bus clock */
|
|
|
|
|
2018-01-25 21:42:52 +00:00
|
|
|
temp = ((pdr & PLL_DR_OUTDIV3_BITS) >> 10) + 1;
|
|
|
|
gd->arch.sdhc_clk = vco / temp;
|
2012-10-18 19:25:51 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_MCF5445x
|
|
|
|
void setup_5445x_clocks(void)
|
|
|
|
{
|
2012-03-26 21:49:08 +00:00
|
|
|
ccm_t *ccm = (ccm_t *)MMAP_CCM;
|
|
|
|
pll_t *pll = (pll_t *)MMAP_PLL;
|
2007-08-16 20:05:11 +00:00
|
|
|
int pllmult_nopci[] = { 20, 10, 24, 18, 12, 6, 16, 8 };
|
|
|
|
int pllmult_pci[] = { 12, 6, 16, 8 };
|
2012-10-03 13:28:45 +00:00
|
|
|
int vco = 0, temp, fbtemp, pcrvalue;
|
2007-08-16 20:05:11 +00:00
|
|
|
int *pPllmult = NULL;
|
|
|
|
u16 fbpll_mask;
|
2012-10-03 13:28:45 +00:00
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
int bPci;
|
|
|
|
#endif
|
2008-07-24 01:38:53 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_M54455EVB
|
2012-03-26 21:49:08 +00:00
|
|
|
u8 *cpld = (u8 *)(CONFIG_SYS_CS2_BASE + 3);
|
2008-07-24 01:38:53 +00:00
|
|
|
#endif
|
|
|
|
u8 bootmode;
|
2007-08-16 20:05:11 +00:00
|
|
|
|
|
|
|
/* To determine PCI is present or not */
|
2012-03-26 21:49:08 +00:00
|
|
|
if (((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x00e0) ||
|
|
|
|
((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x0060)) {
|
2007-08-16 20:05:11 +00:00
|
|
|
pPllmult = &pllmult_pci[0];
|
2008-07-24 01:38:53 +00:00
|
|
|
fbpll_mask = 3; /* 11b */
|
2012-10-03 13:28:45 +00:00
|
|
|
#ifdef CONFIG_PCI
|
2007-08-16 20:05:11 +00:00
|
|
|
bPci = 1;
|
2012-10-03 13:28:45 +00:00
|
|
|
#endif
|
2007-08-16 20:05:11 +00:00
|
|
|
} else {
|
|
|
|
pPllmult = &pllmult_nopci[0];
|
2008-07-24 01:38:53 +00:00
|
|
|
fbpll_mask = 7; /* 111b */
|
2007-08-16 20:05:11 +00:00
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
gd->pci_clk = 0;
|
|
|
|
bPci = 0;
|
2012-10-03 13:28:45 +00:00
|
|
|
#endif
|
2007-08-16 20:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_M54455EVB
|
2012-03-26 21:49:08 +00:00
|
|
|
bootmode = (in_8(cpld) & 0x03);
|
2007-08-16 20:05:11 +00:00
|
|
|
|
2008-07-24 01:38:53 +00:00
|
|
|
if (bootmode != 3) {
|
|
|
|
/* Temporary read from CCR- fixed fb issue, must be the same clock
|
|
|
|
as pci or input clock, causing cpld/fpga read inconsistancy */
|
|
|
|
fbtemp = pPllmult[ccm->ccr & fbpll_mask];
|
2007-08-16 20:05:11 +00:00
|
|
|
|
2008-07-24 01:38:53 +00:00
|
|
|
/* Break down into small pieces, code still in flex bus */
|
2012-03-26 21:49:08 +00:00
|
|
|
pcrvalue = in_be32(&pll->pcr) & 0xFFFFF0FF;
|
2008-07-24 01:38:53 +00:00
|
|
|
temp = fbtemp - 1;
|
|
|
|
pcrvalue |= PLL_PCR_OUTDIV3(temp);
|
|
|
|
|
2012-03-26 21:49:08 +00:00
|
|
|
out_be32(&pll->pcr, pcrvalue);
|
2008-07-24 01:38:53 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_M54451EVB
|
|
|
|
/* No external logic to read the bootmode, hard coded from built */
|
|
|
|
#ifdef CONFIG_CF_SBF
|
|
|
|
bootmode = 3;
|
|
|
|
#else
|
|
|
|
bootmode = 2;
|
|
|
|
|
|
|
|
/* default value is 16 mul, set to 20 mul */
|
2012-03-26 21:49:08 +00:00
|
|
|
pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF) | 0x14000000;
|
|
|
|
out_be32(&pll->pcr, pcrvalue);
|
|
|
|
while ((in_be32(&pll->psr) & PLL_PSR_LOCK) != PLL_PSR_LOCK)
|
|
|
|
;
|
2008-07-24 01:38:53 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2007-08-16 20:05:11 +00:00
|
|
|
|
2008-07-24 01:38:53 +00:00
|
|
|
if (bootmode == 0) {
|
2007-08-16 20:05:11 +00:00
|
|
|
/* RCON mode */
|
2008-10-16 13:01:15 +00:00
|
|
|
vco = pPllmult[ccm->rcon & fbpll_mask] * CONFIG_SYS_INPUT_CLKSRC;
|
2007-08-16 20:05:11 +00:00
|
|
|
|
|
|
|
if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
|
|
|
|
/* invaild range, re-set in PCR */
|
2012-03-26 21:49:08 +00:00
|
|
|
int temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
|
2007-08-16 20:05:11 +00:00
|
|
|
int i, j, bus;
|
|
|
|
|
2012-03-26 21:49:08 +00:00
|
|
|
j = (in_be32(&pll->pcr) & 0xFF000000) >> 24;
|
2007-08-16 20:05:11 +00:00
|
|
|
for (i = j; i < 0xFF; i++) {
|
2008-10-16 13:01:15 +00:00
|
|
|
vco = i * CONFIG_SYS_INPUT_CLKSRC;
|
2007-08-16 20:05:11 +00:00
|
|
|
if (vco >= CLOCK_PLL_FVCO_MIN) {
|
|
|
|
bus = vco / temp;
|
|
|
|
if (bus <= CLOCK_PLL_FSYS_MIN - MHZ)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-26 21:49:08 +00:00
|
|
|
pcrvalue = in_be32(&pll->pcr) & 0x00FF00FF;
|
2007-08-16 20:05:11 +00:00
|
|
|
fbtemp = ((i - 1) << 8) | ((i - 1) << 12);
|
|
|
|
pcrvalue |= ((i << 24) | fbtemp);
|
|
|
|
|
2012-03-26 21:49:08 +00:00
|
|
|
out_be32(&pll->pcr, pcrvalue);
|
2007-08-16 20:05:11 +00:00
|
|
|
}
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.vco_clk = vco; /* Vco clock */
|
2008-07-24 01:38:53 +00:00
|
|
|
} else if (bootmode == 2) {
|
2007-08-16 20:05:11 +00:00
|
|
|
/* Normal mode */
|
2012-03-26 21:49:08 +00:00
|
|
|
vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
|
2008-07-24 01:38:53 +00:00
|
|
|
if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
|
|
|
|
/* Default value */
|
2012-03-26 21:49:08 +00:00
|
|
|
pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF);
|
|
|
|
pcrvalue |= pPllmult[in_be16(&ccm->ccr) & fbpll_mask] << 24;
|
|
|
|
out_be32(&pll->pcr, pcrvalue);
|
|
|
|
vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
|
2008-07-24 01:38:53 +00:00
|
|
|
}
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.vco_clk = vco; /* Vco clock */
|
2008-07-24 01:38:53 +00:00
|
|
|
} else if (bootmode == 3) {
|
2007-08-16 20:05:11 +00:00
|
|
|
/* serial mode */
|
2012-03-26 21:49:08 +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 */
|
2007-08-16 20:05:11 +00:00
|
|
|
}
|
|
|
|
|
2012-03-26 21:49:08 +00:00
|
|
|
if ((in_be16(&ccm->ccr) & CCM_MISCCR_LIMP) == CCM_MISCCR_LIMP) {
|
2007-08-16 20:05:11 +00:00
|
|
|
/* Limp mode */
|
|
|
|
} else {
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */
|
2007-08-16 20:05:11 +00:00
|
|
|
|
2012-03-26 21:49:08 +00:00
|
|
|
temp = (in_be32(&pll->pcr) & PLL_PCR_OUTDIV1_MASK) + 1;
|
2007-08-16 20:05:11 +00:00
|
|
|
gd->cpu_clk = vco / temp; /* cpu clock */
|
|
|
|
|
2012-03-26 21:49:08 +00:00
|
|
|
temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
|
2007-08-16 20:05:11 +00:00
|
|
|
gd->bus_clk = vco / temp; /* bus clock */
|
|
|
|
|
2012-03-26 21:49:08 +00:00
|
|
|
temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV3_MASK) >> 8) + 1;
|
2012-12-13 20:49:07 +00:00
|
|
|
gd->arch.flb_clk = vco / temp; /* FlexBus clock */
|
2007-08-16 20:05:11 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
if (bPci) {
|
2012-03-26 21:49:08 +00:00
|
|
|
temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV4_MASK) >> 12) + 1;
|
2007-08-16 20:05:11 +00:00
|
|
|
gd->pci_clk = vco / temp; /* PCI clock */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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;
|
2012-10-18 19:25:51 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
|
|
|
|
int get_clocks(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_MCF5441x
|
|
|
|
setup_5441x_clocks();
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_MCF5445x
|
|
|
|
setup_5445x_clocks();
|
|
|
|
#endif
|
|
|
|
|
2012-10-24 11:48:22 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_I2C
|
2012-12-13 20:48:49 +00:00
|
|
|
gd->arch.i2c1_clk = gd->bus_clk;
|
2008-08-18 21:01:19 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-16 20:05:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|