]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/imx-common/cpu.c
b8b890b4769749d5eceebe44c7a76a8fa0019707
[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  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 #include <bootm.h>
11 #include <common.h>
12 #include <netdev.h>
13 #include <asm/errno.h>
14 #include <asm/io.h>
15 #include <asm/arch/imx-regs.h>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/sys_proto.h>
18 #include <asm/arch/crm_regs.h>
19 #include <ipu_pixfmt.h>
20 #include <thermal.h>
21 #include <sata.h>
22
23 #ifdef CONFIG_FSL_ESDHC
24 #include <fsl_esdhc.h>
25 #endif
26
27 #if defined(CONFIG_DISPLAY_CPUINFO)
28 static u32 reset_cause = -1;
29
30 static char *get_reset_cause(void)
31 {
32         u32 cause;
33         struct src *src_regs = (struct src *)SRC_BASE_ADDR;
34
35         cause = readl(&src_regs->srsr);
36         writel(cause, &src_regs->srsr);
37         reset_cause = cause;
38
39         switch (cause) {
40         case 0x00001:
41         case 0x00011:
42                 return "POR";
43         case 0x00004:
44                 return "CSU";
45         case 0x00008:
46                 return "IPP USER";
47         case 0x00010:
48                 return "WDOG";
49         case 0x00020:
50                 return "JTAG HIGH-Z";
51         case 0x00040:
52                 return "JTAG SW";
53         case 0x10000:
54                 return "WARM BOOT";
55         default:
56                 return "unknown reset";
57         }
58 }
59
60 u32 get_imx_reset_cause(void)
61 {
62         return reset_cause;
63 }
64 #endif
65
66 #if defined(CONFIG_SOC_MX53) || defined(CONFIG_SOC_MX6)
67 #if defined(CONFIG_SOC_MX53)
68 #define MEMCTL_BASE     ESDCTL_BASE_ADDR
69 #else
70 #define MEMCTL_BASE     MMDC_P0_BASE_ADDR
71 #endif
72 static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
73 static const unsigned char bank_lookup[] = {3, 2};
74
75 /* these MMDC registers are common to the IMX53 and IMX6 */
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 };
85
86 #define ESD_MMDC_CTL_GET_ROW(mdctl)     ((ctl >> 24) & 7)
87 #define ESD_MMDC_CTL_GET_COLUMN(mdctl)  ((ctl >> 20) & 7)
88 #define ESD_MMDC_CTL_GET_WIDTH(mdctl)   ((ctl >> 16) & 3)
89 #define ESD_MMDC_CTL_GET_CS1(mdctl)     ((ctl >> 30) & 1)
90 #define ESD_MMDC_MISC_GET_BANK(mdmisc)  ((misc >> 5) & 1)
91
92 /*
93  * imx_ddr_size - return size in bytes of DRAM according MMDC config
94  * The MMDC MDCTL register holds the number of bits for row, col, and data
95  * width and the MMDC MDMISC register holds the number of banks. Combine
96  * all these bits to determine the meme size the MMDC has been configured for
97  */
98 unsigned imx_ddr_size(void)
99 {
100         struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
101         unsigned ctl = readl(&mem->ctl);
102         unsigned misc = readl(&mem->misc);
103         int bits = 11 + 0 + 0 + 1;      /* row + col + bank + width */
104
105         bits += ESD_MMDC_CTL_GET_ROW(ctl);
106         bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
107         bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
108         bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
109         bits += ESD_MMDC_CTL_GET_CS1(ctl);
110
111         /* The MX6 can do only 3840 MiB of DRAM */
112         if (bits == 32)
113                 return 0xf0000000;
114
115         return 1 << bits;
116 }
117 #endif
118
119 #if defined(CONFIG_DISPLAY_CPUINFO)
120
121 const char *get_imx_type(u32 imxtype)
122 {
123         switch (imxtype) {
124         case MXC_CPU_MX6Q:
125                 return "6Q";    /* Quad-core version of the mx6 */
126         case MXC_CPU_MX6D:
127                 return "6D";    /* Dual-core version of the mx6 */
128         case MXC_CPU_MX6DL:
129                 return "6DL";   /* Dual Lite version of the mx6 */
130         case MXC_CPU_MX6SOLO:
131                 return "6SOLO"; /* Solo version of the mx6 */
132         case MXC_CPU_MX6SL:
133                 return "6SL";   /* Solo-Lite version of the mx6 */
134         case MXC_CPU_MX6SX:
135                 return "6SX";   /* SoloX version of the mx6 */
136         case MXC_CPU_MX51:
137                 return "51";
138         case MXC_CPU_MX53:
139                 return "53";
140         default:
141                 return "??";
142         }
143 }
144
145 int print_cpuinfo(void)
146 {
147         u32 cpurev, max_freq;
148
149 #if defined(CONFIG_SOC_MX6) && defined(CONFIG_IMX6_THERMAL)
150         struct udevice *thermal_dev;
151         int cpu_tmp, ret;
152 #endif
153
154         cpurev = get_cpu_rev();
155
156 #if defined(CONFIG_MX6)
157         printf("CPU:   Freescale i.MX%s rev%d.%d",
158                get_imx_type((cpurev & 0xFF000) >> 12),
159                (cpurev & 0x000F0) >> 4,
160                (cpurev & 0x0000F) >> 0);
161         max_freq = get_cpu_speed_grade_hz();
162         if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
163                 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
164         } else {
165                 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
166                        mxc_get_clock(MXC_ARM_CLK) / 1000000);
167         }
168 #else
169         printf("CPU:   Freescale i.MX%s rev%d.%d at %d MHz\n",
170                 get_imx_type((cpurev & 0xFF000) >> 12),
171                 (cpurev & 0x000F0) >> 4,
172                 (cpurev & 0x0000F) >> 0,
173                 mxc_get_clock(MXC_ARM_CLK) / 1000000);
174 #endif
175
176 #if defined(CONFIG_SOC_MX6) && defined(CONFIG_IMX6_THERMAL)
177         ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
178         if (!ret) {
179                 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
180
181                 if (!ret)
182                         printf("CPU:   Temperature %d C\n", cpu_tmp);
183                 else
184                         printf("CPU:   Temperature: invalid sensor data\n");
185         } else {
186                 printf("CPU:   Temperature: Can't find sensor device\n");
187         }
188 #endif
189
190         printf("Reset cause: %s\n", get_reset_cause());
191         return 0;
192 }
193 #endif
194
195 int cpu_eth_init(bd_t *bis)
196 {
197         int rc = -ENODEV;
198
199 #if defined(CONFIG_FEC_MXC)
200         rc = fecmxc_initialize(bis);
201 #endif
202
203         return rc;
204 }
205
206 #ifdef CONFIG_FSL_ESDHC
207 /*
208  * Initializes on-chip MMC controllers.
209  * to override, implement board_mmc_init()
210  */
211 int cpu_mmc_init(bd_t *bis)
212 {
213         return fsl_esdhc_mmc_init(bis);
214 }
215 #endif
216
217 u32 get_ahb_clk(void)
218 {
219         struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
220         u32 reg, ahb_podf;
221
222         reg = __raw_readl(&imx_ccm->cbcdr);
223         reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
224         ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
225
226         return get_periph_clk() / (ahb_podf + 1);
227 }
228
229 void arch_preboot_os(void)
230 {
231 #if defined(CONFIG_CMD_SATA)
232         sata_stop();
233 #if defined(CONFIG_SOC_MX6)
234         disable_sata_clock();
235 #endif
236 #endif
237 #if defined(CONFIG_VIDEO_IPUV3)
238         /* disable video before launching O/S */
239         ipuv3_fb_shutdown();
240 #endif
241 }
242
243 void set_chipselect_size(int const cs_size)
244 {
245         unsigned int reg;
246         struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
247         reg = readl(&iomuxc_regs->gpr[1]);
248
249         switch (cs_size) {
250         case CS0_128:
251                 reg &= ~0x7;    /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
252                 reg |= 0x5;
253                 break;
254         case CS0_64M_CS1_64M:
255                 reg &= ~0x3F;   /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
256                 reg |= 0x1B;
257                 break;
258         case CS0_64M_CS1_32M_CS2_32M:
259                 reg &= ~0x1FF;  /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
260                 reg |= 0x4B;
261                 break;
262         case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
263                 reg &= ~0xFFF;  /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
264                 reg |= 0x249;
265                 break;
266         default:
267                 printf("Unknown chip select size: %d\n", cs_size);
268                 break;
269         }
270
271         writel(reg, &iomuxc_regs->gpr[1]);
272 }