]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/imx-common/cpu.c
Merge remote branch 'remotes/kc/karo-tx6q' into karo-tx48
[karo-tx-uboot.git] / arch / arm / imx-common / cpu.c
1 /*
2  * (C) Copyright 2007
3  * Sascha Hauer, Pengutronix
4  *
5  * (C) Copyright 2009 Freescale Semiconductor, Inc.
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/io.h>
29 #include <asm/arch/imx-regs.h>
30 #include <asm/arch/clock.h>
31 #include <asm/arch/sys_proto.h>
32 #include <asm/arch/crm_regs.h>
33
34 #ifdef CONFIG_FSL_ESDHC
35 #include <fsl_esdhc.h>
36 #endif
37
38 char *get_reset_cause(void)
39 {
40         u32 cause;
41         struct src *src_regs = (struct src *)SRC_BASE_ADDR;
42
43         cause = readl(&src_regs->srsr);
44         writel(cause, &src_regs->srsr);
45
46         switch (cause) {
47         case 0x00001:
48         case 0x00011:
49                 return "POR";
50         case 0x00004:
51                 return "CSU";
52         case 0x00008:
53                 return "IPP USER";
54         case 0x00010:
55                 return "WDOG";
56         case 0x00020:
57                 return "JTAG HIGH-Z";
58         case 0x00040:
59                 return "JTAG SW";
60         case 0x10000:
61                 return "WARM BOOT";
62         default:
63                 return "unknown reset";
64         }
65 }
66
67 #if defined(CONFIG_MX53) || defined(CONFIG_MX6)
68 #if defined(CONFIG_MX53)
69 #define MEMCTL_BASE     ESDCTL_BASE_ADDR;
70 #else
71 #define MEMCTL_BASE     MMDC_P0_BASE_ADDR;
72 #endif
73 static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
74 static const unsigned char bank_lookup[] = {3, 2};
75
76 struct esd_mmdc_regs {
77         uint32_t        ctl;
78         uint32_t        pdc;
79         uint32_t        otc;
80         uint32_t        cfg0;
81         uint32_t        cfg1;
82         uint32_t        cfg2;
83         uint32_t        misc;
84         uint32_t        scr;
85         uint32_t        ref;
86         uint32_t        rsvd1;
87         uint32_t        rsvd2;
88         uint32_t        rwd;
89         uint32_t        or;
90         uint32_t        mrr;
91         uint32_t        cfg3lp;
92         uint32_t        mr4;
93 };
94
95 #define ESD_MMDC_CTL_GET_ROW(mdctl)     ((ctl >> 24) & 7)
96 #define ESD_MMDC_CTL_GET_COLUMN(mdctl)  ((ctl >> 20) & 7)
97 #define ESD_MMDC_CTL_GET_WIDTH(mdctl)   ((ctl >> 16) & 3)
98 #define ESD_MMDC_CTL_GET_CS1(mdctl)     ((ctl >> 30) & 1)
99 #define ESD_MMDC_MISC_GET_BANK(mdmisc)  ((misc >> 5) & 1)
100
101 unsigned imx_ddr_size(void)
102 {
103         struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
104         unsigned ctl = readl(&mem->ctl);
105         unsigned misc = readl(&mem->misc);
106         int bits = 11 + 0 + 0 + 1;      /* row + col + bank + width */
107
108         bits += ESD_MMDC_CTL_GET_ROW(ctl);
109         bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
110         bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
111         bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
112         bits += ESD_MMDC_CTL_GET_CS1(ctl);
113         return 1 << bits;
114 }
115 #endif
116
117 #if defined(CONFIG_DISPLAY_CPUINFO)
118
119 const char *get_imx_type(u32 imxtype)
120 {
121         switch (imxtype) {
122         case MXC_CPU_MX6Q:
123                 return "6Q";    /* Quad-core version of the mx6 */
124         case MXC_CPU_MX6DL:
125                 return "6DL";   /* Dual Lite version of the mx6 */
126         case MXC_CPU_MX6SOLO:
127                 return "6SOLO"; /* Solo version of the mx6 */
128         case MXC_CPU_MX6SL:
129                 return "6SL";   /* Solo-Lite version of the mx6 */
130         case MXC_CPU_MX51:
131                 return "51";
132         case MXC_CPU_MX53:
133                 return "53";
134         default:
135                 return "??";
136         }
137 }
138
139 int print_cpuinfo(void)
140 {
141         u32 cpurev;
142
143         cpurev = get_cpu_rev();
144
145         printf("CPU:   Freescale i.MX%s rev%d.%d at %d MHz\n",
146                 get_imx_type((cpurev & 0xFF000) >> 12),
147                 (cpurev & 0x000F0) >> 4,
148                 (cpurev & 0x0000F) >> 0,
149                 mxc_get_clock(MXC_ARM_CLK) / 1000000);
150         printf("Reset cause: %s\n", get_reset_cause());
151         return 0;
152 }
153 #endif
154
155 int cpu_eth_init(bd_t *bis)
156 {
157         int rc = -ENODEV;
158
159 #if defined(CONFIG_FEC_MXC)
160         rc = fecmxc_initialize(bis);
161 #endif
162
163         return rc;
164 }
165
166 #ifdef CONFIG_FSL_ESDHC
167 /*
168  * Initializes on-chip MMC controllers.
169  * to override, implement board_mmc_init()
170  */
171 int cpu_mmc_init(bd_t *bis)
172 {
173         return fsl_esdhc_mmc_init(bis);
174 }
175 #endif
176
177 u32 get_ahb_clk(void)
178 {
179         struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
180         u32 reg, ahb_podf;
181
182         reg = __raw_readl(&imx_ccm->cbcdr);
183         reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
184         ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
185
186         return get_periph_clk() / (ahb_podf + 1);
187 }