blob: 096d22ea45c725e2a3409480829d852ad4df591d [file] [log] [blame]
Jason Liu18936ee2011-11-25 00:18:01 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Jason Liu18936ee2011-11-25 00:18:01 +00008 */
9
Jeroen Hofstee5624c6b2014-10-08 22:57:52 +020010#include <bootm.h>
Jason Liu18936ee2011-11-25 00:18:01 +000011#include <common.h>
Jeroen Hofstee5624c6b2014-10-08 22:57:52 +020012#include <netdev.h>
Jason Liu18936ee2011-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 Estevam6a376042012-04-29 08:11:13 +000018#include <asm/arch/crm_regs.h>
Tim Harvey70caa8e2015-05-18 06:56:46 -070019#include <imx_thermal.h>
Eric Nelsone1eb75b2012-09-23 07:30:55 +000020#include <ipu_pixfmt.h>
Ye.Li7a264162014-11-20 21:14:14 +080021#include <thermal.h>
Nikita Kiryanov44b98412014-11-21 12:47:26 +020022#include <sata.h>
Jason Liu18936ee2011-11-25 00:18:01 +000023
24#ifdef CONFIG_FSL_ESDHC
25#include <fsl_esdhc.h>
26#endif
27
Prabhakar Kushwaha28420e72015-05-18 17:13:52 +053028#if defined(CONFIG_DISPLAY_CPUINFO)
Eric Nelson11c2e502015-02-15 14:37:21 -070029static u32 reset_cause = -1;
30
31static char *get_reset_cause(void)
Jason Liu18936ee2011-11-25 00:18:01 +000032{
33 u32 cause;
34 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
35
36 cause = readl(&src_regs->srsr);
37 writel(cause, &src_regs->srsr);
Eric Nelson11c2e502015-02-15 14:37:21 -070038 reset_cause = cause;
Jason Liu18936ee2011-11-25 00:18:01 +000039
40 switch (cause) {
41 case 0x00001:
Fabio Estevamcece2622012-03-13 07:26:48 +000042 case 0x00011:
Jason Liu18936ee2011-11-25 00:18:01 +000043 return "POR";
44 case 0x00004:
45 return "CSU";
46 case 0x00008:
47 return "IPP USER";
48 case 0x00010:
49 return "WDOG";
50 case 0x00020:
51 return "JTAG HIGH-Z";
52 case 0x00040:
53 return "JTAG SW";
54 case 0x10000:
55 return "WARM BOOT";
56 default:
57 return "unknown reset";
58 }
59}
60
Eric Nelson11c2e502015-02-15 14:37:21 -070061u32 get_imx_reset_cause(void)
62{
63 return reset_cause;
64}
Prabhakar Kushwaha28420e72015-05-18 17:13:52 +053065#endif
Eric Nelson11c2e502015-02-15 14:37:21 -070066
Troy Kiskyeb0344d2012-10-23 10:57:48 +000067#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
68#if defined(CONFIG_MX53)
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070069#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000070#else
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070071#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000072#endif
73static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
74static const unsigned char bank_lookup[] = {3, 2};
75
Tim Harveyb07161c2014-06-02 16:13:21 -070076/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000077struct esd_mmdc_regs {
78 uint32_t ctl;
79 uint32_t pdc;
80 uint32_t otc;
81 uint32_t cfg0;
82 uint32_t cfg1;
83 uint32_t cfg2;
84 uint32_t misc;
Troy Kiskyeb0344d2012-10-23 10:57:48 +000085};
86
87#define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
88#define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
89#define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
90#define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
91#define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
92
Tim Harveyb07161c2014-06-02 16:13:21 -070093/*
94 * imx_ddr_size - return size in bytes of DRAM according MMDC config
95 * The MMDC MDCTL register holds the number of bits for row, col, and data
96 * width and the MMDC MDMISC register holds the number of banks. Combine
97 * all these bits to determine the meme size the MMDC has been configured for
98 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000099unsigned imx_ddr_size(void)
100{
101 struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
102 unsigned ctl = readl(&mem->ctl);
103 unsigned misc = readl(&mem->misc);
104 int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
105
106 bits += ESD_MMDC_CTL_GET_ROW(ctl);
107 bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
108 bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
109 bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
110 bits += ESD_MMDC_CTL_GET_CS1(ctl);
Marek Vasutfcfdfdd2014-08-04 01:47:09 +0200111
112 /* The MX6 can do only 3840 MiB of DRAM */
113 if (bits == 32)
114 return 0xf0000000;
115
Troy Kiskyeb0344d2012-10-23 10:57:48 +0000116 return 1 << bits;
117}
118#endif
119
Jason Liu18936ee2011-11-25 00:18:01 +0000120#if defined(CONFIG_DISPLAY_CPUINFO)
Fabio Estevama7683862012-03-20 04:21:45 +0000121
Troy Kisky20332a02012-10-23 10:57:46 +0000122const char *get_imx_type(u32 imxtype)
Fabio Estevama7683862012-03-20 04:21:45 +0000123{
124 switch (imxtype) {
Peng Fand0acd992015-07-11 11:38:42 +0800125 case MXC_CPU_MX6QP:
126 return "6QP"; /* Quad-Plus version of the mx6 */
127 case MXC_CPU_MX6DP:
128 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000129 case MXC_CPU_MX6Q:
Fabio Estevama7683862012-03-20 04:21:45 +0000130 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevam94db6652014-01-26 15:06:41 -0200131 case MXC_CPU_MX6D:
132 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000133 case MXC_CPU_MX6DL:
134 return "6DL"; /* Dual Lite version of the mx6 */
135 case MXC_CPU_MX6SOLO:
136 return "6SOLO"; /* Solo version of the mx6 */
137 case MXC_CPU_MX6SL:
Fabio Estevama7683862012-03-20 04:21:45 +0000138 return "6SL"; /* Solo-Lite version of the mx6 */
Fabio Estevam05d54b82014-06-24 17:40:58 -0300139 case MXC_CPU_MX6SX:
140 return "6SX"; /* SoloX version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000141 case MXC_CPU_MX51:
Fabio Estevama7683862012-03-20 04:21:45 +0000142 return "51";
Troy Kisky20332a02012-10-23 10:57:46 +0000143 case MXC_CPU_MX53:
Fabio Estevama7683862012-03-20 04:21:45 +0000144 return "53";
145 default:
Otavio Salvadore972d722012-06-30 05:07:32 +0000146 return "??";
Fabio Estevama7683862012-03-20 04:21:45 +0000147 }
148}
149
Jason Liu18936ee2011-11-25 00:18:01 +0000150int print_cpuinfo(void)
151{
Stefano Babic943a3f22015-05-26 19:53:41 +0200152 u32 cpurev;
153 __maybe_unused u32 max_freq;
Jason Liu18936ee2011-11-25 00:18:01 +0000154
Ye.Li7a264162014-11-20 21:14:14 +0800155#if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
156 struct udevice *thermal_dev;
Tim Harvey70caa8e2015-05-18 06:56:46 -0700157 int cpu_tmp, minc, maxc, ret;
Ye.Li7a264162014-11-20 21:14:14 +0800158#endif
159
Jason Liu18936ee2011-11-25 00:18:01 +0000160 cpurev = get_cpu_rev();
Fabio Estevama7683862012-03-20 04:21:45 +0000161
Tim Harveyb83ddac2015-05-18 07:02:25 -0700162#if defined(CONFIG_MX6)
163 printf("CPU: Freescale i.MX%s rev%d.%d",
164 get_imx_type((cpurev & 0xFF000) >> 12),
165 (cpurev & 0x000F0) >> 4,
166 (cpurev & 0x0000F) >> 0);
167 max_freq = get_cpu_speed_grade_hz();
168 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
169 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
170 } else {
171 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
172 mxc_get_clock(MXC_ARM_CLK) / 1000000);
173 }
174#else
Fabio Estevama7683862012-03-20 04:21:45 +0000175 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
176 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu18936ee2011-11-25 00:18:01 +0000177 (cpurev & 0x000F0) >> 4,
178 (cpurev & 0x0000F) >> 0,
179 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyb83ddac2015-05-18 07:02:25 -0700180#endif
Ye.Li7a264162014-11-20 21:14:14 +0800181
182#if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
Tim Harvey70caa8e2015-05-18 06:56:46 -0700183 puts("CPU: ");
184 switch (get_cpu_temp_grade(&minc, &maxc)) {
185 case TEMP_AUTOMOTIVE:
186 puts("Automotive temperature grade ");
187 break;
188 case TEMP_INDUSTRIAL:
189 puts("Industrial temperature grade ");
190 break;
191 case TEMP_EXTCOMMERCIAL:
192 puts("Extended Commercial temperature grade ");
193 break;
194 default:
195 puts("Commercial temperature grade ");
196 break;
197 }
198 printf("(%dC to %dC)", minc, maxc);
Ye.Li7a264162014-11-20 21:14:14 +0800199 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
200 if (!ret) {
201 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
202
203 if (!ret)
Tim Harvey70caa8e2015-05-18 06:56:46 -0700204 printf(" at %dC\n", cpu_tmp);
Ye.Li7a264162014-11-20 21:14:14 +0800205 else
Tim Harvey70caa8e2015-05-18 06:56:46 -0700206 puts(" - invalid sensor data\n");
Ye.Li7a264162014-11-20 21:14:14 +0800207 } else {
Tim Harvey70caa8e2015-05-18 06:56:46 -0700208 puts(" - invalid sensor device\n");
Ye.Li7a264162014-11-20 21:14:14 +0800209 }
210#endif
211
Jason Liu18936ee2011-11-25 00:18:01 +0000212 printf("Reset cause: %s\n", get_reset_cause());
213 return 0;
214}
215#endif
216
217int cpu_eth_init(bd_t *bis)
218{
219 int rc = -ENODEV;
220
221#if defined(CONFIG_FEC_MXC)
222 rc = fecmxc_initialize(bis);
223#endif
224
225 return rc;
226}
227
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000228#ifdef CONFIG_FSL_ESDHC
Jason Liu18936ee2011-11-25 00:18:01 +0000229/*
230 * Initializes on-chip MMC controllers.
231 * to override, implement board_mmc_init()
232 */
233int cpu_mmc_init(bd_t *bis)
234{
Jason Liu18936ee2011-11-25 00:18:01 +0000235 return fsl_esdhc_mmc_init(bis);
Jason Liu18936ee2011-11-25 00:18:01 +0000236}
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000237#endif
Jason Liu18936ee2011-11-25 00:18:01 +0000238
Fabio Estevam6a376042012-04-29 08:11:13 +0000239u32 get_ahb_clk(void)
240{
241 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
242 u32 reg, ahb_podf;
243
244 reg = __raw_readl(&imx_ccm->cbcdr);
245 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
246 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
247
248 return get_periph_clk() / (ahb_podf + 1);
249}
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000250
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000251void arch_preboot_os(void)
252{
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200253#if defined(CONFIG_CMD_SATA)
254 sata_stop();
Soeren Mochdd1c8f12014-11-27 10:11:41 +0100255#if defined(CONFIG_MX6)
256 disable_sata_clock();
257#endif
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200258#endif
259#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000260 /* disable video before launching O/S */
261 ipuv3_fb_shutdown();
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000262#endif
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200263}
Fabio Estevam32c81ea2014-11-14 11:27:21 -0200264
265void set_chipselect_size(int const cs_size)
266{
267 unsigned int reg;
268 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
269 reg = readl(&iomuxc_regs->gpr[1]);
270
271 switch (cs_size) {
272 case CS0_128:
273 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
274 reg |= 0x5;
275 break;
276 case CS0_64M_CS1_64M:
277 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
278 reg |= 0x1B;
279 break;
280 case CS0_64M_CS1_32M_CS2_32M:
281 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
282 reg |= 0x4B;
283 break;
284 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
285 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
286 reg |= 0x249;
287 break;
288 default:
289 printf("Unknown chip select size: %d\n", cs_size);
290 break;
291 }
292
293 writel(reg, &iomuxc_regs->gpr[1]);
294}