]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/imx-common/cpu.c
arm/imx-common: Fix warning 'get_reset_cause' defined but not used
[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;
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         printf("CPU:   Freescale i.MX%s rev%d.%d at %d MHz\n",
157                 get_imx_type((cpurev & 0xFF000) >> 12),
158                 (cpurev & 0x000F0) >> 4,
159                 (cpurev & 0x0000F) >> 0,
160                 mxc_get_clock(MXC_ARM_CLK) / 1000000);
161
162 #if defined(CONFIG_SOC_MX6) && defined(CONFIG_IMX6_THERMAL)
163         ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
164         if (!ret) {
165                 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
166
167                 if (!ret)
168                         printf("CPU:   Temperature %d C\n", cpu_tmp);
169                 else
170                         printf("CPU:   Temperature: invalid sensor data\n");
171         } else {
172                 printf("CPU:   Temperature: Can't find sensor device\n");
173         }
174 #endif
175
176         printf("Reset cause: %s\n", get_reset_cause());
177         return 0;
178 }
179 #endif
180
181 int cpu_eth_init(bd_t *bis)
182 {
183         int rc = -ENODEV;
184
185 #if defined(CONFIG_FEC_MXC)
186         rc = fecmxc_initialize(bis);
187 #endif
188
189         return rc;
190 }
191
192 #ifdef CONFIG_FSL_ESDHC
193 /*
194  * Initializes on-chip MMC controllers.
195  * to override, implement board_mmc_init()
196  */
197 int cpu_mmc_init(bd_t *bis)
198 {
199         return fsl_esdhc_mmc_init(bis);
200 }
201 #endif
202
203 u32 get_ahb_clk(void)
204 {
205         struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
206         u32 reg, ahb_podf;
207
208         reg = __raw_readl(&imx_ccm->cbcdr);
209         reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
210         ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
211
212         return get_periph_clk() / (ahb_podf + 1);
213 }
214
215 void arch_preboot_os(void)
216 {
217 #if defined(CONFIG_CMD_SATA)
218         sata_stop();
219 #if defined(CONFIG_SOC_MX6)
220         disable_sata_clock();
221 #endif
222 #endif
223 #if defined(CONFIG_VIDEO_IPUV3)
224         /* disable video before launching O/S */
225         ipuv3_fb_shutdown();
226 #endif
227 }
228
229 void set_chipselect_size(int const cs_size)
230 {
231         unsigned int reg;
232         struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
233         reg = readl(&iomuxc_regs->gpr[1]);
234
235         switch (cs_size) {
236         case CS0_128:
237                 reg &= ~0x7;    /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
238                 reg |= 0x5;
239                 break;
240         case CS0_64M_CS1_64M:
241                 reg &= ~0x3F;   /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
242                 reg |= 0x1B;
243                 break;
244         case CS0_64M_CS1_32M_CS2_32M:
245                 reg &= ~0x1FF;  /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
246                 reg |= 0x4B;
247                 break;
248         case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
249                 reg &= ~0xFFF;  /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
250                 reg |= 0x249;
251                 break;
252         default:
253                 printf("Unknown chip select size: %d\n", cs_size);
254                 break;
255         }
256
257         writel(reg, &iomuxc_regs->gpr[1]);
258 }