]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/imx-common/cpu.c
ARM: i.MX: provide access to reset cause through get_imx_reset_cause()
[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 static u32 reset_cause = -1;
28
29 static char *get_reset_cause(void)
30 {
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);
36         reset_cause = cause;
37
38         switch (cause) {
39         case 0x00001:
40         case 0x00011:
41                 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
59 u32 get_imx_reset_cause(void)
60 {
61         return reset_cause;
62 }
63
64 #if defined(CONFIG_SOC_MX53) || defined(CONFIG_SOC_MX6)
65 #if defined(CONFIG_SOC_MX53)
66 #define MEMCTL_BASE     ESDCTL_BASE_ADDR
67 #else
68 #define MEMCTL_BASE     MMDC_P0_BASE_ADDR
69 #endif
70 static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
71 static const unsigned char bank_lookup[] = {3, 2};
72
73 /* these MMDC registers are common to the IMX53 and IMX6 */
74 struct 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;
82 };
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
90 /*
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  */
96 unsigned 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);
108
109         /* The MX6 can do only 3840 MiB of DRAM */
110         if (bits == 32)
111                 return 0xf0000000;
112
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_MX6D:
125                 return "6D";    /* Dual-core version of the mx6 */
126         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:
131                 return "6SL";   /* Solo-Lite version of the mx6 */
132         case MXC_CPU_MX6SX:
133                 return "6SX";   /* SoloX version of the mx6 */
134         case MXC_CPU_MX51:
135                 return "51";
136         case MXC_CPU_MX53:
137                 return "53";
138         default:
139                 return "??";
140         }
141 }
142
143 int print_cpuinfo(void)
144 {
145         u32 cpurev;
146
147 #if defined(CONFIG_SOC_MX6) && defined(CONFIG_IMX6_THERMAL)
148         struct udevice *thermal_dev;
149         int cpu_tmp, ret;
150 #endif
151
152         cpurev = get_cpu_rev();
153
154         printf("CPU:   Freescale i.MX%s rev%d.%d at %d MHz\n",
155                 get_imx_type((cpurev & 0xFF000) >> 12),
156                 (cpurev & 0x000F0) >> 4,
157                 (cpurev & 0x0000F) >> 0,
158                 mxc_get_clock(MXC_ARM_CLK) / 1000000);
159
160 #if defined(CONFIG_SOC_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
174         printf("Reset cause: %s\n", get_reset_cause());
175         return 0;
176 }
177 #endif
178
179 int 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
190 #ifdef CONFIG_FSL_ESDHC
191 /*
192  * Initializes on-chip MMC controllers.
193  * to override, implement board_mmc_init()
194  */
195 int cpu_mmc_init(bd_t *bis)
196 {
197         return fsl_esdhc_mmc_init(bis);
198 }
199 #endif
200
201 u32 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 }
212
213 void arch_preboot_os(void)
214 {
215 #if defined(CONFIG_CMD_SATA)
216         sata_stop();
217 #if defined(CONFIG_SOC_MX6)
218         disable_sata_clock();
219 #endif
220 #endif
221 #if defined(CONFIG_VIDEO_IPUV3)
222         /* disable video before launching O/S */
223         ipuv3_fb_shutdown();
224 #endif
225 }
226
227 void 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 }