]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/armv7/mx7/soc.c
ns16550: zap the rockchip serial compatible string
[u-boot] / arch / arm / cpu / armv7 / mx7 / soc.c
1 /*
2  * Copyright (C) 2015 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <asm/io.h>
9 #include <asm/arch/imx-regs.h>
10 #include <asm/arch/clock.h>
11 #include <asm/arch/sys_proto.h>
12 #include <asm/imx-common/boot_mode.h>
13 #include <asm/imx-common/dma.h>
14 #include <asm/imx-common/hab.h>
15 #include <asm/arch/crm_regs.h>
16 #include <dm.h>
17 #include <imx_thermal.h>
18
19 #if defined(CONFIG_IMX_THERMAL)
20 static const struct imx_thermal_plat imx7_thermal_plat = {
21         .regs = (void *)ANATOP_BASE_ADDR,
22         .fuse_bank = 3,
23         .fuse_word = 3,
24 };
25
26 U_BOOT_DEVICE(imx7_thermal) = {
27         .name = "imx_thermal",
28         .platdata = &imx7_thermal_plat,
29 };
30 #endif
31
32 #if defined(CONFIG_SECURE_BOOT)
33 struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
34         .bank = 1,
35         .word = 3,
36 };
37 #endif
38
39 /*
40  * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
41  * defines a 2-bit SPEED_GRADING
42  */
43 #define OCOTP_TESTER3_SPEED_SHIFT       8
44 #define OCOTP_TESTER3_SPEED_800MHZ      0
45 #define OCOTP_TESTER3_SPEED_850MHZ      1
46 #define OCOTP_TESTER3_SPEED_1GHZ        2
47
48 u32 get_cpu_speed_grade_hz(void)
49 {
50         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
51         struct fuse_bank *bank = &ocotp->bank[1];
52         struct fuse_bank1_regs *fuse =
53                 (struct fuse_bank1_regs *)bank->fuse_regs;
54         uint32_t val;
55
56         val = readl(&fuse->tester3);
57         val >>= OCOTP_TESTER3_SPEED_SHIFT;
58         val &= 0x3;
59
60         switch(val) {
61         case OCOTP_TESTER3_SPEED_800MHZ:
62                 return 792000000;
63         case OCOTP_TESTER3_SPEED_850MHZ:
64                 return 852000000;
65         case OCOTP_TESTER3_SPEED_1GHZ:
66                 return 996000000;
67         }
68         return 0;
69 }
70
71 /*
72  * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
73  * defines a 2-bit SPEED_GRADING
74  */
75 #define OCOTP_TESTER3_TEMP_SHIFT        6
76
77 u32 get_cpu_temp_grade(int *minc, int *maxc)
78 {
79         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
80         struct fuse_bank *bank = &ocotp->bank[1];
81         struct fuse_bank1_regs *fuse =
82                 (struct fuse_bank1_regs *)bank->fuse_regs;
83         uint32_t val;
84
85         val = readl(&fuse->tester3);
86         val >>= OCOTP_TESTER3_TEMP_SHIFT;
87         val &= 0x3;
88
89         if (minc && maxc) {
90                 if (val == TEMP_AUTOMOTIVE) {
91                         *minc = -40;
92                         *maxc = 125;
93                 } else if (val == TEMP_INDUSTRIAL) {
94                         *minc = -40;
95                         *maxc = 105;
96                 } else if (val == TEMP_EXTCOMMERCIAL) {
97                         *minc = -20;
98                         *maxc = 105;
99                 } else {
100                         *minc = 0;
101                         *maxc = 95;
102                 }
103         }
104         return val;
105 }
106
107 u32 get_cpu_rev(void)
108 {
109         struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
110                                                  ANATOP_BASE_ADDR;
111         u32 reg = readl(&ccm_anatop->digprog);
112         u32 type = (reg >> 16) & 0xff;
113
114         reg &= 0xff;
115         return (type << 12) | reg;
116 }
117
118 #ifdef CONFIG_REVISION_TAG
119 u32 __weak get_board_rev(void)
120 {
121         return get_cpu_rev();
122 }
123 #endif
124
125 /* enable all periherial can be accessed in nosec mode */
126 static void init_csu(void)
127 {
128         int i = 0;
129         for (i = 0; i < CSU_NUM_REGS; i++)
130                 writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
131 }
132
133 int arch_cpu_init(void)
134 {
135         init_aips();
136
137         init_csu();
138         /* Disable PDE bit of WMCR register */
139         imx_set_wdog_powerdown(false);
140
141 #ifdef CONFIG_APBH_DMA
142         /* Start APBH DMA */
143         mxs_dma_init();
144 #endif
145
146         return 0;
147 }
148
149 #ifdef CONFIG_SERIAL_TAG
150 void get_board_serial(struct tag_serialnr *serialnr)
151 {
152         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
153         struct fuse_bank *bank = &ocotp->bank[0];
154         struct fuse_bank0_regs *fuse =
155                 (struct fuse_bank0_regs *)bank->fuse_regs;
156
157         serialnr->low = fuse->tester0;
158         serialnr->high = fuse->tester1;
159 }
160 #endif
161
162 #if defined(CONFIG_FEC_MXC)
163 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
164 {
165         struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
166         struct fuse_bank *bank = &ocotp->bank[9];
167         struct fuse_bank9_regs *fuse =
168                 (struct fuse_bank9_regs *)bank->fuse_regs;
169
170         if (0 == dev_id) {
171                 u32 value = readl(&fuse->mac_addr1);
172                 mac[0] = (value >> 8);
173                 mac[1] = value;
174
175                 value = readl(&fuse->mac_addr0);
176                 mac[2] = value >> 24;
177                 mac[3] = value >> 16;
178                 mac[4] = value >> 8;
179                 mac[5] = value;
180         } else {
181                 u32 value = readl(&fuse->mac_addr2);
182                 mac[0] = value >> 24;
183                 mac[1] = value >> 16;
184                 mac[2] = value >> 8;
185                 mac[3] = value;
186
187                 value = readl(&fuse->mac_addr1);
188                 mac[4] = value >> 24;
189                 mac[5] = value >> 16;
190         }
191 }
192 #endif
193
194 void set_wdog_reset(struct wdog_regs *wdog)
195 {
196         u32 reg = readw(&wdog->wcr);
197         /*
198          * Output WDOG_B signal to reset external pmic or POR_B decided by
199          * the board desgin. Without external reset, the peripherals/DDR/
200          * PMIC are not reset, that may cause system working abnormal.
201          */
202         reg = readw(&wdog->wcr);
203         reg |= 1 << 3;
204         /*
205          * WDZST bit is write-once only bit. Align this bit in kernel,
206          * otherwise kernel code will have no chance to set this bit.
207          */
208         reg |= 1 << 0;
209         writew(reg, &wdog->wcr);
210 }
211
212 /*
213  * cfg_val will be used for
214  * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
215  * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
216  * to SBMR1, which will determine the boot device.
217  */
218 const struct boot_mode soc_boot_modes[] = {
219         {"ecspi1:0",    MAKE_CFGVAL(0x00, 0x60, 0x00, 0x00)},
220         {"ecspi1:1",    MAKE_CFGVAL(0x40, 0x62, 0x00, 0x00)},
221         {"ecspi1:2",    MAKE_CFGVAL(0x80, 0x64, 0x00, 0x00)},
222         {"ecspi1:3",    MAKE_CFGVAL(0xc0, 0x66, 0x00, 0x00)},
223
224         {"weim",        MAKE_CFGVAL(0x00, 0x50, 0x00, 0x00)},
225         {"qspi1",       MAKE_CFGVAL(0x10, 0x40, 0x00, 0x00)},
226         /* 4 bit bus width */
227         {"usdhc1",      MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
228         {"usdhc2",      MAKE_CFGVAL(0x10, 0x14, 0x00, 0x00)},
229         {"usdhc3",      MAKE_CFGVAL(0x10, 0x18, 0x00, 0x00)},
230         {"mmc1",        MAKE_CFGVAL(0x10, 0x20, 0x00, 0x00)},
231         {"mmc2",        MAKE_CFGVAL(0x10, 0x24, 0x00, 0x00)},
232         {"mmc3",        MAKE_CFGVAL(0x10, 0x28, 0x00, 0x00)},
233         {NULL,          0},
234 };
235
236 enum boot_device get_boot_device(void)
237 {
238         struct bootrom_sw_info **p =
239                 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
240
241         enum boot_device boot_dev = SD1_BOOT;
242         u8 boot_type = (*p)->boot_dev_type;
243         u8 boot_instance = (*p)->boot_dev_instance;
244
245         switch (boot_type) {
246         case BOOT_TYPE_SD:
247                 boot_dev = boot_instance + SD1_BOOT;
248                 break;
249         case BOOT_TYPE_MMC:
250                 boot_dev = boot_instance + MMC1_BOOT;
251                 break;
252         case BOOT_TYPE_NAND:
253                 boot_dev = NAND_BOOT;
254                 break;
255         case BOOT_TYPE_QSPI:
256                 boot_dev = QSPI_BOOT;
257                 break;
258         case BOOT_TYPE_WEIM:
259                 boot_dev = WEIM_NOR_BOOT;
260                 break;
261         case BOOT_TYPE_SPINOR:
262                 boot_dev = SPI_NOR_BOOT;
263                 break;
264         default:
265                 break;
266         }
267
268         return boot_dev;
269 }
270
271 void s_init(void)
272 {
273 #if !defined CONFIG_SPL_BUILD
274         /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
275         asm volatile(
276                         "mrc p15, 0, r0, c1, c0, 1\n"
277                         "orr r0, r0, #1 << 6\n"
278                         "mcr p15, 0, r0, c1, c0, 1\n");
279 #endif
280         /* clock configuration. */
281         clock_init();
282
283         return;
284 }