blob: 067d08f131ad084fc5375945e848b24477a3453c [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>
Eric Nelsone1eb75b2012-09-23 07:30:55 +000019#include <ipu_pixfmt.h>
Ye.Li7a264162014-11-20 21:14:14 +080020#include <thermal.h>
Nikita Kiryanov44b98412014-11-21 12:47:26 +020021#include <sata.h>
Jason Liu18936ee2011-11-25 00:18:01 +000022
23#ifdef CONFIG_FSL_ESDHC
24#include <fsl_esdhc.h>
25#endif
26
Eric Nelson11c2e502015-02-15 14:37:21 -070027static u32 reset_cause = -1;
28
29static char *get_reset_cause(void)
Jason Liu18936ee2011-11-25 00:18:01 +000030{
31 u32 cause;
32 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
33
34 cause = readl(&src_regs->srsr);
35 writel(cause, &src_regs->srsr);
Eric Nelson11c2e502015-02-15 14:37:21 -070036 reset_cause = cause;
Jason Liu18936ee2011-11-25 00:18:01 +000037
38 switch (cause) {
39 case 0x00001:
Fabio Estevamcece2622012-03-13 07:26:48 +000040 case 0x00011:
Jason Liu18936ee2011-11-25 00:18:01 +000041 return "POR";
42 case 0x00004:
43 return "CSU";
44 case 0x00008:
45 return "IPP USER";
46 case 0x00010:
47 return "WDOG";
48 case 0x00020:
49 return "JTAG HIGH-Z";
50 case 0x00040:
51 return "JTAG SW";
52 case 0x10000:
53 return "WARM BOOT";
54 default:
55 return "unknown reset";
56 }
57}
58
Eric Nelson11c2e502015-02-15 14:37:21 -070059u32 get_imx_reset_cause(void)
60{
61 return reset_cause;
62}
63
Troy Kiskyeb0344d2012-10-23 10:57:48 +000064#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
65#if defined(CONFIG_MX53)
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070066#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000067#else
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070068#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000069#endif
70static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
71static const unsigned char bank_lookup[] = {3, 2};
72
Tim Harveyb07161c2014-06-02 16:13:21 -070073/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000074struct esd_mmdc_regs {
75 uint32_t ctl;
76 uint32_t pdc;
77 uint32_t otc;
78 uint32_t cfg0;
79 uint32_t cfg1;
80 uint32_t cfg2;
81 uint32_t misc;
Troy Kiskyeb0344d2012-10-23 10:57:48 +000082};
83
84#define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
85#define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
86#define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
87#define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
88#define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
89
Tim Harveyb07161c2014-06-02 16:13:21 -070090/*
91 * imx_ddr_size - return size in bytes of DRAM according MMDC config
92 * The MMDC MDCTL register holds the number of bits for row, col, and data
93 * width and the MMDC MDMISC register holds the number of banks. Combine
94 * all these bits to determine the meme size the MMDC has been configured for
95 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000096unsigned imx_ddr_size(void)
97{
98 struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
99 unsigned ctl = readl(&mem->ctl);
100 unsigned misc = readl(&mem->misc);
101 int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
102
103 bits += ESD_MMDC_CTL_GET_ROW(ctl);
104 bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
105 bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
106 bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
107 bits += ESD_MMDC_CTL_GET_CS1(ctl);
Marek Vasutfcfdfdd2014-08-04 01:47:09 +0200108
109 /* The MX6 can do only 3840 MiB of DRAM */
110 if (bits == 32)
111 return 0xf0000000;
112
Troy Kiskyeb0344d2012-10-23 10:57:48 +0000113 return 1 << bits;
114}
115#endif
116
Jason Liu18936ee2011-11-25 00:18:01 +0000117#if defined(CONFIG_DISPLAY_CPUINFO)
Fabio Estevama7683862012-03-20 04:21:45 +0000118
Troy Kisky20332a02012-10-23 10:57:46 +0000119const char *get_imx_type(u32 imxtype)
Fabio Estevama7683862012-03-20 04:21:45 +0000120{
121 switch (imxtype) {
Troy Kisky20332a02012-10-23 10:57:46 +0000122 case MXC_CPU_MX6Q:
Fabio Estevama7683862012-03-20 04:21:45 +0000123 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevam94db6652014-01-26 15:06:41 -0200124 case MXC_CPU_MX6D:
125 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000126 case MXC_CPU_MX6DL:
127 return "6DL"; /* Dual Lite version of the mx6 */
128 case MXC_CPU_MX6SOLO:
129 return "6SOLO"; /* Solo version of the mx6 */
130 case MXC_CPU_MX6SL:
Fabio Estevama7683862012-03-20 04:21:45 +0000131 return "6SL"; /* Solo-Lite version of the mx6 */
Fabio Estevam05d54b82014-06-24 17:40:58 -0300132 case MXC_CPU_MX6SX:
133 return "6SX"; /* SoloX version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000134 case MXC_CPU_MX51:
Fabio Estevama7683862012-03-20 04:21:45 +0000135 return "51";
Troy Kisky20332a02012-10-23 10:57:46 +0000136 case MXC_CPU_MX53:
Fabio Estevama7683862012-03-20 04:21:45 +0000137 return "53";
138 default:
Otavio Salvadore972d722012-06-30 05:07:32 +0000139 return "??";
Fabio Estevama7683862012-03-20 04:21:45 +0000140 }
141}
142
Jason Liu18936ee2011-11-25 00:18:01 +0000143int print_cpuinfo(void)
144{
145 u32 cpurev;
146
Ye.Li7a264162014-11-20 21:14:14 +0800147#if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
148 struct udevice *thermal_dev;
149 int cpu_tmp, ret;
150#endif
151
Jason Liu18936ee2011-11-25 00:18:01 +0000152 cpurev = get_cpu_rev();
Fabio Estevama7683862012-03-20 04:21:45 +0000153
154 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
155 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu18936ee2011-11-25 00:18:01 +0000156 (cpurev & 0x000F0) >> 4,
157 (cpurev & 0x0000F) >> 0,
158 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Ye.Li7a264162014-11-20 21:14:14 +0800159
160#if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
161 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
162 if (!ret) {
163 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
164
165 if (!ret)
166 printf("CPU: Temperature %d C\n", cpu_tmp);
167 else
168 printf("CPU: Temperature: invalid sensor data\n");
169 } else {
170 printf("CPU: Temperature: Can't find sensor device\n");
171 }
172#endif
173
Jason Liu18936ee2011-11-25 00:18:01 +0000174 printf("Reset cause: %s\n", get_reset_cause());
175 return 0;
176}
177#endif
178
179int cpu_eth_init(bd_t *bis)
180{
181 int rc = -ENODEV;
182
183#if defined(CONFIG_FEC_MXC)
184 rc = fecmxc_initialize(bis);
185#endif
186
187 return rc;
188}
189
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000190#ifdef CONFIG_FSL_ESDHC
Jason Liu18936ee2011-11-25 00:18:01 +0000191/*
192 * Initializes on-chip MMC controllers.
193 * to override, implement board_mmc_init()
194 */
195int cpu_mmc_init(bd_t *bis)
196{
Jason Liu18936ee2011-11-25 00:18:01 +0000197 return fsl_esdhc_mmc_init(bis);
Jason Liu18936ee2011-11-25 00:18:01 +0000198}
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000199#endif
Jason Liu18936ee2011-11-25 00:18:01 +0000200
Fabio Estevam6a376042012-04-29 08:11:13 +0000201u32 get_ahb_clk(void)
202{
203 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
204 u32 reg, ahb_podf;
205
206 reg = __raw_readl(&imx_ccm->cbcdr);
207 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
208 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
209
210 return get_periph_clk() / (ahb_podf + 1);
211}
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000212
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000213void arch_preboot_os(void)
214{
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200215#if defined(CONFIG_CMD_SATA)
216 sata_stop();
Soeren Mochdd1c8f12014-11-27 10:11:41 +0100217#if defined(CONFIG_MX6)
218 disable_sata_clock();
219#endif
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200220#endif
221#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000222 /* disable video before launching O/S */
223 ipuv3_fb_shutdown();
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000224#endif
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200225}
Fabio Estevam32c81ea2014-11-14 11:27:21 -0200226
227void set_chipselect_size(int const cs_size)
228{
229 unsigned int reg;
230 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
231 reg = readl(&iomuxc_regs->gpr[1]);
232
233 switch (cs_size) {
234 case CS0_128:
235 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
236 reg |= 0x5;
237 break;
238 case CS0_64M_CS1_64M:
239 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
240 reg |= 0x1B;
241 break;
242 case CS0_64M_CS1_32M_CS2_32M:
243 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
244 reg |= 0x4B;
245 break;
246 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
247 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
248 reg |= 0x249;
249 break;
250 default:
251 printf("Unknown chip select size: %d\n", cs_size);
252 break;
253 }
254
255 writel(reg, &iomuxc_regs->gpr[1]);
256}