blob: 5c78eb983496acd8cdf217825c6fcd6783d48a81 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -05002/*
3 *
Alison Wang8d8dac92012-03-26 21:49:08 +00004 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -05005 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -05006 */
7
8#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -07009#include <clock_legacy.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050011#include <asm/processor.h>
12
13#include <asm/immap.h>
Alison Wang8d8dac92012-03-26 21:49:08 +000014#include <asm/io.h>
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050015
16DECLARE_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
31void clock_enter_limp(int lpdiv)
32{
Alison Wang8d8dac92012-03-26 21:49:08 +000033 ccm_t *ccm = (ccm_t *)MMAP_CCM;
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050034 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
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050045 /* Enable Limp Mode */
Alison Wang8d8dac92012-03-26 21:49:08 +000046 setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050047}
48
49/*
50 * brief Exit Limp mode
51 * warning The PLL should be set and locked prior to exiting Limp mode
52 */
53void clock_exit_limp(void)
54{
Alison Wang8d8dac92012-03-26 21:49:08 +000055 ccm_t *ccm = (ccm_t *)MMAP_CCM;
56 pll_t *pll = (pll_t *)MMAP_PLL;
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050057
58 /* Exit Limp mode */
Alison Wang8d8dac92012-03-26 21:49:08 +000059 clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050060
61 /* Wait for the PLL to lock */
Alison Wang8d8dac92012-03-26 21:49:08 +000062 while (!(in_be32(&pll->psr) & PLL_PSR_LOCK))
63 ;
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050064}
65
Alison Wangfdc2fb12012-10-18 19:25:51 +000066#ifdef CONFIG_MCF5441x
67void setup_5441x_clocks(void)
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -050068{
Alison Wangfdc2fb12012-10-18 19:25:51 +000069 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 Jin2ecfc782013-06-26 10:21:31 +0800105 gd->arch.vco_clk = vco;
Alison Wangfdc2fb12012-10-18 19:25:51 +0000106
Jason Jin2ecfc782013-06-26 10:21:31 +0800107 gd->arch.inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */
TsiChung Liew23cf8fd2008-07-23 20:38:53 -0500108
Alison Wangfdc2fb12012-10-18 19:25:51 +0000109 pdr = in_be32(&pll->pdr);
110 temp = (pdr & PLL_DR_OUTDIV1_BITS) + 1;
111 gd->cpu_clk = vco / temp; /* cpu clock */
Jason Jin2ecfc782013-06-26 10:21:31 +0800112 gd->arch.flb_clk = vco / temp; /* FlexBus clock */
113 gd->arch.flb_clk >>= 1;
Vasili Galka24f413b2014-06-30 12:59:06 +0300114 if (in_be16(&ccm->misccr2) & 2) /* fsys/4 */
Jason Jin2ecfc782013-06-26 10:21:31 +0800115 gd->arch.flb_clk >>= 1;
Alison Wangfdc2fb12012-10-18 19:25:51 +0000116
117 temp = ((pdr & PLL_DR_OUTDIV2_BITS) >> 5) + 1;
118 gd->bus_clk = vco / temp; /* bus clock */
119
Angelo Dureghello95a69982018-01-25 22:42:52 +0100120 temp = ((pdr & PLL_DR_OUTDIV3_BITS) >> 10) + 1;
121 gd->arch.sdhc_clk = vco / temp;
Alison Wangfdc2fb12012-10-18 19:25:51 +0000122}
123#endif
124
Alison Wangfdc2fb12012-10-18 19:25:51 +0000125/* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
126int get_clocks(void)
127{
128#ifdef CONFIG_MCF5441x
129 setup_5441x_clocks();
130#endif
Alison Wangfdc2fb12012-10-18 19:25:51 +0000131
Angelo Dureghello706bd722023-04-05 00:59:25 +0200132 if (IS_ENABLED(CONFIG_SYS_I2C_FSL))
133 gd->arch.i2c1_clk = gd->bus_clk;
TsiChung Liew0c1e3252008-08-19 03:01:19 +0600134
TsiChungLiewfc3ca3b62007-08-16 15:05:11 -0500135 return (0);
136}