Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 2 | /* |
| 3 | * |
Alison Wang | 8d8dac9 | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 5 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 9 | #include <clock_legacy.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 11 | #include <asm/processor.h> |
| 12 | |
| 13 | #include <asm/immap.h> |
Alison Wang | 8d8dac9 | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 14 | #include <asm/io.h> |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | /* |
| 19 | * Low Power Divider specifications |
| 20 | */ |
| 21 | #define CLOCK_LPD_MIN (1 << 0) /* Divider (decoded) */ |
| 22 | #define CLOCK_LPD_MAX (1 << 15) /* Divider (decoded) */ |
| 23 | |
| 24 | #define CLOCK_PLL_FVCO_MAX 540000000 |
| 25 | #define CLOCK_PLL_FVCO_MIN 300000000 |
| 26 | |
| 27 | #define CLOCK_PLL_FSYS_MAX 266666666 |
| 28 | #define CLOCK_PLL_FSYS_MIN 100000000 |
| 29 | #define MHZ 1000000 |
| 30 | |
| 31 | void clock_enter_limp(int lpdiv) |
| 32 | { |
Alison Wang | 8d8dac9 | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 33 | ccm_t *ccm = (ccm_t *)MMAP_CCM; |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 34 | int i, j; |
| 35 | |
| 36 | /* Check bounds of divider */ |
| 37 | if (lpdiv < CLOCK_LPD_MIN) |
| 38 | lpdiv = CLOCK_LPD_MIN; |
| 39 | if (lpdiv > CLOCK_LPD_MAX) |
| 40 | lpdiv = CLOCK_LPD_MAX; |
| 41 | |
| 42 | /* Round divider down to nearest power of two */ |
| 43 | for (i = 0, j = lpdiv; j != 1; j >>= 1, i++) ; |
| 44 | |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 45 | /* Enable Limp Mode */ |
Alison Wang | 8d8dac9 | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 46 | setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP); |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
| 50 | * brief Exit Limp mode |
| 51 | * warning The PLL should be set and locked prior to exiting Limp mode |
| 52 | */ |
| 53 | void clock_exit_limp(void) |
| 54 | { |
Alison Wang | 8d8dac9 | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 55 | ccm_t *ccm = (ccm_t *)MMAP_CCM; |
| 56 | pll_t *pll = (pll_t *)MMAP_PLL; |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 57 | |
| 58 | /* Exit Limp mode */ |
Alison Wang | 8d8dac9 | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 59 | clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP); |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 60 | |
| 61 | /* Wait for the PLL to lock */ |
Alison Wang | 8d8dac9 | 2012-03-26 21:49:08 +0000 | [diff] [blame] | 62 | while (!(in_be32(&pll->psr) & PLL_PSR_LOCK)) |
| 63 | ; |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 64 | } |
| 65 | |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 66 | #ifdef CONFIG_MCF5441x |
| 67 | void setup_5441x_clocks(void) |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 68 | { |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 69 | ccm_t *ccm = (ccm_t *)MMAP_CCM; |
| 70 | pll_t *pll = (pll_t *)MMAP_PLL; |
| 71 | int temp, vco = 0, bootmod_ccr, pdr; |
| 72 | |
| 73 | bootmod_ccr = (in_be16(&ccm->ccr) & CCM_CCR_BOOTMOD) >> 14; |
| 74 | |
| 75 | switch (bootmod_ccr) { |
| 76 | case 0: |
| 77 | out_be32(&pll->pcr, 0x00000013); |
| 78 | out_be32(&pll->pdr, 0x00e70c61); |
| 79 | clock_exit_limp(); |
| 80 | break; |
| 81 | case 2: |
| 82 | break; |
| 83 | case 3: |
| 84 | break; |
| 85 | } |
| 86 | |
| 87 | /*Change frequency for Modelo SER1 USB host*/ |
| 88 | #ifdef CONFIG_LOW_MCFCLK |
| 89 | temp = in_be32(&pll->pcr); |
| 90 | temp &= ~0x3f; |
| 91 | temp |= 5; |
| 92 | out_be32(&pll->pcr, temp); |
| 93 | |
| 94 | temp = in_be32(&pll->pdr); |
| 95 | temp &= ~0x001f0000; |
| 96 | temp |= 0x00040000; |
| 97 | out_be32(&pll->pdr, temp); |
| 98 | __asm__("tpf"); |
| 99 | #endif |
| 100 | |
| 101 | setbits_be16(&ccm->misccr2, 0x02); |
| 102 | |
| 103 | vco = ((in_be32(&pll->pcr) & PLL_CR_FBKDIV_BITS) + 1) * |
| 104 | CONFIG_SYS_INPUT_CLKSRC; |
Jason Jin | 2ecfc78 | 2013-06-26 10:21:31 +0800 | [diff] [blame] | 105 | gd->arch.vco_clk = vco; |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 106 | |
Jason Jin | 2ecfc78 | 2013-06-26 10:21:31 +0800 | [diff] [blame] | 107 | gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */ |
TsiChung Liew | 23cf8fd | 2008-07-23 20:38:53 -0500 | [diff] [blame] | 108 | |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 109 | pdr = in_be32(&pll->pdr); |
| 110 | temp = (pdr & PLL_DR_OUTDIV1_BITS) + 1; |
| 111 | gd->cpu_clk = vco / temp; /* cpu clock */ |
Jason Jin | 2ecfc78 | 2013-06-26 10:21:31 +0800 | [diff] [blame] | 112 | gd->arch.flb_clk = vco / temp; /* FlexBus clock */ |
| 113 | gd->arch.flb_clk >>= 1; |
Vasili Galka | 24f413b | 2014-06-30 12:59:06 +0300 | [diff] [blame] | 114 | if (in_be16(&ccm->misccr2) & 2) /* fsys/4 */ |
Jason Jin | 2ecfc78 | 2013-06-26 10:21:31 +0800 | [diff] [blame] | 115 | gd->arch.flb_clk >>= 1; |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 116 | |
| 117 | temp = ((pdr & PLL_DR_OUTDIV2_BITS) >> 5) + 1; |
| 118 | gd->bus_clk = vco / temp; /* bus clock */ |
| 119 | |
Angelo Dureghello | 95a6998 | 2018-01-25 22:42:52 +0100 | [diff] [blame] | 120 | temp = ((pdr & PLL_DR_OUTDIV3_BITS) >> 10) + 1; |
| 121 | gd->arch.sdhc_clk = vco / temp; |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 122 | } |
| 123 | #endif |
| 124 | |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 125 | /* get_clocks() fills in gd->cpu_clock and gd->bus_clk */ |
| 126 | int get_clocks(void) |
| 127 | { |
| 128 | #ifdef CONFIG_MCF5441x |
| 129 | setup_5441x_clocks(); |
| 130 | #endif |
Alison Wang | fdc2fb1 | 2012-10-18 19:25:51 +0000 | [diff] [blame] | 131 | |
Angelo Dureghello | 706bd72 | 2023-04-05 00:59:25 +0200 | [diff] [blame] | 132 | if (IS_ENABLED(CONFIG_SYS_I2C_FSL)) |
| 133 | gd->arch.i2c1_clk = gd->bus_clk; |
TsiChung Liew | 0c1e325 | 2008-08-19 03:01:19 +0600 | [diff] [blame] | 134 | |
TsiChungLiew | fc3ca3b6 | 2007-08-16 15:05:11 -0500 | [diff] [blame] | 135 | return (0); |
| 136 | } |