blob: 37472eadfcd5a832271f5927b7503da37401887e [file] [log] [blame]
Jason Liu83aa8fe2011-11-25 00:18:01 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Jason Liu83aa8fe2011-11-25 00:18:01 +00008 */
9
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020010#include <bootm.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000011#include <common.h>
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020012#include <netdev.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000013#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>
Fabio Estevam6479f512012-04-29 08:11:13 +000018#include <asm/arch/crm_regs.h>
Eric Nelson54b3f3b2012-09-23 07:30:55 +000019#include <ipu_pixfmt.h>
Ye.Lif19692c2014-11-20 21:14:14 +080020#include <thermal.h>
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +020021#include <sata.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000022
23#ifdef CONFIG_FSL_ESDHC
24#include <fsl_esdhc.h>
25#endif
26
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053027#if defined(CONFIG_DISPLAY_CPUINFO)
Eric Nelson25e02302015-02-15 14:37:21 -070028static u32 reset_cause = -1;
29
30static char *get_reset_cause(void)
Jason Liu83aa8fe2011-11-25 00:18:01 +000031{
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);
Eric Nelson25e02302015-02-15 14:37:21 -070037 reset_cause = cause;
Jason Liu83aa8fe2011-11-25 00:18:01 +000038
39 switch (cause) {
40 case 0x00001:
Fabio Estevam9af122b2012-03-13 07:26:48 +000041 case 0x00011:
Jason Liu83aa8fe2011-11-25 00:18:01 +000042 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
Eric Nelson25e02302015-02-15 14:37:21 -070060u32 get_imx_reset_cause(void)
61{
62 return reset_cause;
63}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053064#endif
Eric Nelson25e02302015-02-15 14:37:21 -070065
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000066#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
67#if defined(CONFIG_MX53)
Eric Nelsonc7d46122013-11-08 16:50:53 -070068#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000069#else
Eric Nelsonc7d46122013-11-08 16:50:53 -070070#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000071#endif
72static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
73static const unsigned char bank_lookup[] = {3, 2};
74
Tim Harvey066fbad2014-06-02 16:13:21 -070075/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000076struct 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;
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000084};
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
Tim Harvey066fbad2014-06-02 16:13:21 -070092/*
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 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000098unsigned 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);
Marek Vasut005a4d12014-08-04 01:47:09 +0200110
111 /* The MX6 can do only 3840 MiB of DRAM */
112 if (bits == 32)
113 return 0xf0000000;
114
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000115 return 1 << bits;
116}
117#endif
118
Jason Liu83aa8fe2011-11-25 00:18:01 +0000119#if defined(CONFIG_DISPLAY_CPUINFO)
Fabio Estevam46e97332012-03-20 04:21:45 +0000120
Troy Kisky58394932012-10-23 10:57:46 +0000121const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +0000122{
123 switch (imxtype) {
Troy Kisky58394932012-10-23 10:57:46 +0000124 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000125 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200126 case MXC_CPU_MX6D:
127 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000128 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:
Fabio Estevam46e97332012-03-20 04:21:45 +0000133 return "6SL"; /* Solo-Lite version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300134 case MXC_CPU_MX6SX:
135 return "6SX"; /* SoloX version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000136 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000137 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000138 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000139 return "53";
140 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000141 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000142 }
143}
144
Jason Liu83aa8fe2011-11-25 00:18:01 +0000145int print_cpuinfo(void)
146{
Tim Harveyd792ede2015-05-18 07:02:25 -0700147 u32 cpurev, max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000148
Ye.Lif19692c2014-11-20 21:14:14 +0800149#if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
150 struct udevice *thermal_dev;
151 int cpu_tmp, ret;
152#endif
153
Jason Liu83aa8fe2011-11-25 00:18:01 +0000154 cpurev = get_cpu_rev();
Fabio Estevam46e97332012-03-20 04:21:45 +0000155
Tim Harveyd792ede2015-05-18 07:02:25 -0700156#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
Fabio Estevam46e97332012-03-20 04:21:45 +0000169 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
170 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000171 (cpurev & 0x000F0) >> 4,
172 (cpurev & 0x0000F) >> 0,
173 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700174#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800175
176#if defined(CONFIG_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
Jason Liu83aa8fe2011-11-25 00:18:01 +0000190 printf("Reset cause: %s\n", get_reset_cause());
191 return 0;
192}
193#endif
194
195int 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
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000206#ifdef CONFIG_FSL_ESDHC
Jason Liu83aa8fe2011-11-25 00:18:01 +0000207/*
208 * Initializes on-chip MMC controllers.
209 * to override, implement board_mmc_init()
210 */
211int cpu_mmc_init(bd_t *bis)
212{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000213 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000214}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000215#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000216
Fabio Estevam6479f512012-04-29 08:11:13 +0000217u32 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}
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000228
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000229void arch_preboot_os(void)
230{
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200231#if defined(CONFIG_CMD_SATA)
232 sata_stop();
Soeren Mocha517d022014-11-27 10:11:41 +0100233#if defined(CONFIG_MX6)
234 disable_sata_clock();
235#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200236#endif
237#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000238 /* disable video before launching O/S */
239 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000240#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200241}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200242
243void 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}