]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/arm926ejs/mx25/generic.c
applied patches from Freescale and Ka-Ro
[karo-tx-uboot.git] / cpu / arm926ejs / mx25 / generic.c
1 /*
2  * (C) Copyright 2007
3  * Sascha Hauer, Pengutronix
4  *
5  * (C) Copyright 2009-2010 Freescale Semiconductor
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25
26 #include <common.h>
27 #include <asm/errno.h>
28 #include <asm/arch/mx25-regs.h>
29
30 static u32 mx25_decode_pll(u32 reg)
31 {
32         u32 mfi = (reg >> 10) & 0xf;
33         u32 mfn = reg & 0x3ff;
34         u32 mfd = (reg >> 16) & 0x3ff;
35         u32 pd =  (reg >> 26) & 0xf;
36
37         u32 ref_clk = PLL_REF_CLK;
38
39         mfi = mfi <= 5 ? 5 : mfi;
40         mfd += 1;
41         pd += 1;
42
43         return ((2 * (ref_clk >> 10) * (mfi * mfd + mfn)) /
44                 (mfd * pd)) << 10;
45 }
46
47 static u32 mx25_get_mcu_main_clk(void)
48 {
49         u32 cctl = __REG(CCM_CCTL);
50         u32 ret_val = mx25_decode_pll(__REG(CCM_MPCTL));
51
52         if (cctl & CRM_CCTL_ARM_SRC) {
53                 ret_val *= 3;
54                 ret_val /= 4;
55         }
56
57         return ret_val;
58 }
59
60 static u32 mx25_get_ahb_clk(void)
61 {
62         u32 cctl = __REG(CCM_CCTL);
63         u32 ahb_div = ((cctl >> CRM_CCTL_AHB_OFFSET) & 3) + 1;
64
65         return mx25_get_mcu_main_clk()/ahb_div;
66 }
67
68 unsigned int mx25_get_ipg_clk(void)
69 {
70         return mx25_get_ahb_clk()/2;
71 }
72
73 unsigned int mx25_get_cspi_clk(void)
74 {
75         return mx25_get_ipg_clk();
76 }
77
78 void mx25_dump_clocks(void)
79 {
80         u32 cpufreq = mx25_get_mcu_main_clk();
81         printf("mx25 cpu clock: %dMHz\n", cpufreq / 1000000);
82         printf("ipg clock     : %dHz\n", mx25_get_ipg_clk());
83 }
84
85 unsigned int mxc_get_clock(enum mxc_clock clk)
86 {
87         switch (clk) {
88         case MXC_ARM_CLK:
89                 return mx25_get_mcu_main_clk();
90         case MXC_AHB_CLK:
91                 return mx25_get_ahb_clk();
92                 break;
93         case MXC_IPG_PERCLK:
94         case MXC_IPG_CLK:
95                 return mx25_get_ipg_clk();
96         case MXC_CSPI_CLK:
97                 return mx25_get_cspi_clk();
98         case MXC_UART_CLK:
99                 break;
100         case MXC_ESDHC_CLK:
101                 return mx25_get_ipg_clk();
102                 break;
103         }
104         return -1;
105 }
106
107 #if defined(CONFIG_DISPLAY_CPUINFO)
108 int print_cpuinfo(void)
109 {
110         printf("CPU:   Freescale i.MX25 at %d MHz\n",
111                 mx25_get_mcu_main_clk() / 1000000);
112         mx25_dump_clocks();
113         return 0;
114 }
115 #endif
116
117 #if defined(CONFIG_MXC_FEC)
118 extern int mxc_fec_initialize(bd_t *bis);
119 extern void mxc_fec_set_mac_from_env(char *mac_addr);
120 #endif
121
122 /*
123  * Initializes on-chip ethernet controllers.
124  * to override, implement board_eth_init()
125  */
126 int cpu_eth_init(bd_t *bis)
127 {
128         int rc = -ENODEV;
129
130 #if defined(CONFIG_MXC_FEC)
131         rc = mxc_fec_initialize(bis);
132 #endif
133
134         return rc;
135 }
136