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++) ;
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
|
|
|
|
int get_clocks(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_MCF5441x
|
|
|
|
setup_5441x_clocks();
|
|
|
|
#endif
|
|
|
|
|
2023-04-04 22:59:25 +00:00
|
|
|
if (IS_ENABLED(CONFIG_SYS_I2C_FSL))
|
|
|
|
gd->arch.i2c1_clk = gd->bus_clk;
|
2008-08-18 21:01:19 +00:00
|
|
|
|
2007-08-16 20:05:11 +00:00
|
|
|
return (0);
|
|
|
|
}
|