blob: 2a50b8458a4322788dc1d3ac65c9b3241b53561b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Peter Griffin31f327e2015-07-30 18:55:23 +01002/*
3 * (C) Copyright 2015 Linaro
4 * Peter Griffin <peter.griffin@linaro.org>
Peter Griffin31f327e2015-07-30 18:55:23 +01005 */
6#include <common.h>
Simon Glassafb02152019-12-28 10:45:01 -07007#include <cpu_func.h>
Peter Griffin31f327e2015-07-30 18:55:23 +01008#include <dm.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07009#include <fdt_support.h>
Simon Glass97589732020-05-10 11:40:02 -060010#include <init.h>
Peter Griffin0382c642015-09-10 21:55:17 +010011#include <dm/platform_data/serial_pl01x.h>
Peter Griffin31f327e2015-07-30 18:55:23 +010012#include <errno.h>
13#include <malloc.h>
14#include <netdev.h>
15#include <asm/io.h>
16#include <usb.h>
17#include <power/hi6553_pmic.h>
18#include <asm-generic/gpio.h>
19#include <asm/arch/dwmmc.h>
20#include <asm/arch/gpio.h>
21#include <asm/arch/periph.h>
22#include <asm/arch/pinmux.h>
23#include <asm/arch/hi6220.h>
Alexander Graf580be6e2016-03-04 01:09:53 +010024#include <asm/armv8/mmu.h>
Peter Griffin31f327e2015-07-30 18:55:23 +010025
26/*TODO drop this table in favour of device tree */
27static const struct hikey_gpio_platdata hi6220_gpio[] = {
28 { 0, HI6220_GPIO_BASE(0)},
29 { 1, HI6220_GPIO_BASE(1)},
30 { 2, HI6220_GPIO_BASE(2)},
31 { 3, HI6220_GPIO_BASE(3)},
32 { 4, HI6220_GPIO_BASE(4)},
33 { 5, HI6220_GPIO_BASE(5)},
34 { 6, HI6220_GPIO_BASE(6)},
35 { 7, HI6220_GPIO_BASE(7)},
36 { 8, HI6220_GPIO_BASE(8)},
37 { 9, HI6220_GPIO_BASE(9)},
38 { 10, HI6220_GPIO_BASE(10)},
39 { 11, HI6220_GPIO_BASE(11)},
40 { 12, HI6220_GPIO_BASE(12)},
41 { 13, HI6220_GPIO_BASE(13)},
42 { 14, HI6220_GPIO_BASE(14)},
43 { 15, HI6220_GPIO_BASE(15)},
44 { 16, HI6220_GPIO_BASE(16)},
45 { 17, HI6220_GPIO_BASE(17)},
46 { 18, HI6220_GPIO_BASE(18)},
47 { 19, HI6220_GPIO_BASE(19)},
48
49};
50
51U_BOOT_DEVICES(hi6220_gpios) = {
52 { "gpio_hi6220", &hi6220_gpio[0] },
53 { "gpio_hi6220", &hi6220_gpio[1] },
54 { "gpio_hi6220", &hi6220_gpio[2] },
55 { "gpio_hi6220", &hi6220_gpio[3] },
56 { "gpio_hi6220", &hi6220_gpio[4] },
57 { "gpio_hi6220", &hi6220_gpio[5] },
58 { "gpio_hi6220", &hi6220_gpio[6] },
59 { "gpio_hi6220", &hi6220_gpio[7] },
60 { "gpio_hi6220", &hi6220_gpio[8] },
61 { "gpio_hi6220", &hi6220_gpio[9] },
62 { "gpio_hi6220", &hi6220_gpio[10] },
63 { "gpio_hi6220", &hi6220_gpio[11] },
64 { "gpio_hi6220", &hi6220_gpio[12] },
65 { "gpio_hi6220", &hi6220_gpio[13] },
66 { "gpio_hi6220", &hi6220_gpio[14] },
67 { "gpio_hi6220", &hi6220_gpio[15] },
68 { "gpio_hi6220", &hi6220_gpio[16] },
69 { "gpio_hi6220", &hi6220_gpio[17] },
70 { "gpio_hi6220", &hi6220_gpio[18] },
71 { "gpio_hi6220", &hi6220_gpio[19] },
72};
73
74DECLARE_GLOBAL_DATA_PTR;
75
Peter Griffinc97c37a2016-04-20 17:13:59 +010076#if !CONFIG_IS_ENABLED(OF_CONTROL)
77
Peter Griffin0382c642015-09-10 21:55:17 +010078static const struct pl01x_serial_platdata serial_platdata = {
79#if CONFIG_CONS_INDEX == 1
80 .base = HI6220_UART0_BASE,
81#elif CONFIG_CONS_INDEX == 4
82 .base = HI6220_UART3_BASE,
83#else
Vagrant Cascadiane1643ed2016-03-15 12:11:13 -070084#error "Unsupported console index value."
Peter Griffin0382c642015-09-10 21:55:17 +010085#endif
86 .type = TYPE_PL011,
87 .clock = 19200000
88};
89
90U_BOOT_DEVICE(hikey_seriala) = {
91 .name = "serial_pl01x",
92 .platdata = &serial_platdata,
93};
Peter Griffinc97c37a2016-04-20 17:13:59 +010094#endif
Peter Griffin0382c642015-09-10 21:55:17 +010095
Alexander Graf580be6e2016-03-04 01:09:53 +010096static struct mm_region hikey_mem_map[] = {
97 {
York Sunc7104e52016-06-24 16:46:22 -070098 .virt = 0x0UL,
99 .phys = 0x0UL,
Alexander Graf580be6e2016-03-04 01:09:53 +0100100 .size = 0x80000000UL,
101 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
102 PTE_BLOCK_INNER_SHARE
103 }, {
York Sunc7104e52016-06-24 16:46:22 -0700104 .virt = 0x80000000UL,
105 .phys = 0x80000000UL,
Alexander Graf580be6e2016-03-04 01:09:53 +0100106 .size = 0x80000000UL,
107 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
108 PTE_BLOCK_NON_SHARE |
109 PTE_BLOCK_PXN | PTE_BLOCK_UXN
110 }, {
111 /* List terminator */
112 0,
113 }
114};
115
116struct mm_region *mem_map = hikey_mem_map;
117
Peter Griffin0382c642015-09-10 21:55:17 +0100118#ifdef CONFIG_BOARD_EARLY_INIT_F
119int board_uart_init(void)
120{
121 switch (CONFIG_CONS_INDEX) {
122 case 1:
123 hi6220_pinmux_config(PERIPH_ID_UART0);
124 break;
125 case 4:
126 hi6220_pinmux_config(PERIPH_ID_UART3);
127 break;
128 default:
129 debug("%s: Unsupported UART selected\n", __func__);
130 return -1;
131 }
132
133 return 0;
134}
135
136int board_early_init_f(void)
137{
138 board_uart_init();
139 return 0;
140}
141#endif
142
Peter Griffin31f327e2015-07-30 18:55:23 +0100143struct peri_sc_periph_regs *peri_sc =
144 (struct peri_sc_periph_regs *)HI6220_PERI_BASE;
145
146struct alwayson_sc_regs *ao_sc =
147 (struct alwayson_sc_regs *)ALWAYSON_CTRL_BASE;
148
149/* status offset from enable reg */
150#define STAT_EN_OFF 0x2
151
152void hi6220_clk_enable(u32 bitfield, unsigned int *clk_base)
153{
154 uint32_t data;
155
156 data = readl(clk_base);
157 data |= bitfield;
158
159 writel(bitfield, clk_base);
160 do {
161 data = readl(clk_base + STAT_EN_OFF);
162 } while ((data & bitfield) == 0);
163}
164
165/* status offset from disable reg */
166#define STAT_DIS_OFF 0x1
167
168void hi6220_clk_disable(u32 bitfield, unsigned int *clk_base)
169{
170 uint32_t data;
171
172 data = readl(clk_base);
173 data |= bitfield;
174
175 writel(data, clk_base);
176 do {
177 data = readl(clk_base + STAT_DIS_OFF);
178 } while (data & bitfield);
179}
180
181#define EYE_PATTERN 0x70533483
182
183int board_usb_init(int index, enum usb_init_type init)
184{
185 unsigned int data;
186
187 /* enable USB clock */
188 hi6220_clk_enable(PERI_CLK0_USBOTG, &peri_sc->clk0_en);
189
190 /* take usb IPs out of reset */
191 writel(PERI_RST0_USBOTG_BUS | PERI_RST0_POR_PICOPHY |
192 PERI_RST0_USBOTG | PERI_RST0_USBOTG_32K,
193 &peri_sc->rst0_dis);
194 do {
195 data = readl(&peri_sc->rst0_stat);
196 data &= PERI_RST0_USBOTG_BUS | PERI_RST0_POR_PICOPHY |
197 PERI_RST0_USBOTG | PERI_RST0_USBOTG_32K;
198 } while (data);
199
200 /*CTRL 5*/
201 data = readl(&peri_sc->ctrl5);
202 data &= ~PERI_CTRL5_PICOPHY_BC_MODE;
203 data |= PERI_CTRL5_USBOTG_RES_SEL | PERI_CTRL5_PICOPHY_ACAENB;
204 data |= 0x300;
205 writel(data, &peri_sc->ctrl5);
206
207 /*CTRL 4*/
208
209 /* configure USB PHY */
210 data = readl(&peri_sc->ctrl4);
211
212 /* make PHY out of low power mode */
213 data &= ~PERI_CTRL4_PICO_SIDDQ;
214 data &= ~PERI_CTRL4_PICO_OGDISABLE;
215 data |= PERI_CTRL4_PICO_VBUSVLDEXTSEL | PERI_CTRL4_PICO_VBUSVLDEXT;
216 writel(data, &peri_sc->ctrl4);
217
218 writel(EYE_PATTERN, &peri_sc->ctrl8);
219
220 mdelay(5);
221 return 0;
222}
223
224static int config_sd_carddetect(void)
225{
226 int ret;
227
228 /* configure GPIO8 as nopull */
229 writel(0, 0xf8001830);
230
231 gpio_request(8, "SD CD");
232
233 gpio_direction_input(8);
234 ret = gpio_get_value(8);
235
236 if (!ret) {
237 printf("%s: SD card present\n", __func__);
238 return 1;
239 }
240
241 printf("%s: SD card not present\n", __func__);
242 return 0;
243}
244
245
246static void mmc1_init_pll(void)
247{
248 uint32_t data;
249
250 /* select SYSPLL as the source of MMC1 */
251 /* select SYSPLL as the source of MUX1 (SC_CLK_SEL0) */
252 writel(1 << 11 | 1 << 27, &peri_sc->clk0_sel);
253 do {
254 data = readl(&peri_sc->clk0_sel);
255 } while (!(data & (1 << 11)));
256
257 /* select MUX1 as the source of MUX2 (SC_CLK_SEL0) */
258 writel(1 << 30, &peri_sc->clk0_sel);
259 do {
260 data = readl(&peri_sc->clk0_sel);
261 } while (data & (1 << 14));
262
263 hi6220_clk_enable(PERI_CLK0_MMC1, &peri_sc->clk0_en);
264
265 hi6220_clk_enable(PERI_CLK12_MMC1_SRC, &peri_sc->clk12_en);
266
267 do {
268 /* 1.2GHz / 50 = 24MHz */
269 writel(0x31 | (1 << 7), &peri_sc->clkcfg8bit2);
270 data = readl(&peri_sc->clkcfg8bit2);
271 } while ((data & 0x31) != 0x31);
272}
273
274static void mmc1_reset_clk(void)
275{
276 unsigned int data;
277
278 /* disable mmc1 bus clock */
279 hi6220_clk_disable(PERI_CLK0_MMC1, &peri_sc->clk0_dis);
280
281 /* enable mmc1 bus clock */
282 hi6220_clk_enable(PERI_CLK0_MMC1, &peri_sc->clk0_en);
283
284 /* reset mmc1 clock domain */
285 writel(PERI_RST0_MMC1, &peri_sc->rst0_en);
286
287 /* bypass mmc1 clock phase */
288 data = readl(&peri_sc->ctrl2);
289 data |= 3 << 2;
290 writel(data, &peri_sc->ctrl2);
291
292 /* disable low power */
293 data = readl(&peri_sc->ctrl13);
294 data |= 1 << 4;
295 writel(data, &peri_sc->ctrl13);
296 do {
297 data = readl(&peri_sc->rst0_stat);
298 } while (!(data & PERI_RST0_MMC1));
299
Peter Griffin461f4422017-08-15 17:18:16 +0100300 /* unreset mmc1 clock domain */
Peter Griffin31f327e2015-07-30 18:55:23 +0100301 writel(PERI_RST0_MMC1, &peri_sc->rst0_dis);
302 do {
303 data = readl(&peri_sc->rst0_stat);
304 } while (data & PERI_RST0_MMC1);
305}
306
Peter Griffin461f4422017-08-15 17:18:16 +0100307static void mmc0_reset_clk(void)
308{
309 unsigned int data;
310
311 /* disable mmc0 bus clock */
312 hi6220_clk_disable(PERI_CLK0_MMC0, &peri_sc->clk0_dis);
313
314 /* enable mmc0 bus clock */
315 hi6220_clk_enable(PERI_CLK0_MMC0, &peri_sc->clk0_en);
316
317 /* reset mmc0 clock domain */
318 writel(PERI_RST0_MMC0, &peri_sc->rst0_en);
319
320 /* bypass mmc0 clock phase */
321 data = readl(&peri_sc->ctrl2);
322 data |= 3;
323 writel(data, &peri_sc->ctrl2);
324
325 /* disable low power */
326 data = readl(&peri_sc->ctrl13);
327 data |= 1 << 3;
328 writel(data, &peri_sc->ctrl13);
329 do {
330 data = readl(&peri_sc->rst0_stat);
331 } while (!(data & PERI_RST0_MMC0));
332
333 /* unreset mmc0 clock domain */
334 writel(PERI_RST0_MMC0, &peri_sc->rst0_dis);
335 do {
336 data = readl(&peri_sc->rst0_stat);
337 } while (data & PERI_RST0_MMC0);
338}
339
340
Peter Griffin31f327e2015-07-30 18:55:23 +0100341/* PMU SSI is the IP that maps the external PMU hi6553 registers as IO */
342static void hi6220_pmussi_init(void)
343{
344 uint32_t data;
345
346 /* Take PMUSSI out of reset */
347 writel(ALWAYSON_SC_PERIPH_RST4_DIS_PRESET_PMUSSI_N,
348 &ao_sc->rst4_dis);
349 do {
350 data = readl(&ao_sc->rst4_stat);
351 } while (data & ALWAYSON_SC_PERIPH_RST4_DIS_PRESET_PMUSSI_N);
352
353 /* set PMU SSI clock latency for read operation */
354 data = readl(&ao_sc->mcu_subsys_ctrl3);
355 data &= ~ALWAYSON_SC_MCU_SUBSYS_CTRL3_RCLK_MASK;
356 data |= ALWAYSON_SC_MCU_SUBSYS_CTRL3_RCLK_3;
357 writel(data, &ao_sc->mcu_subsys_ctrl3);
358
359 /* enable PMUSSI clock */
360 data = ALWAYSON_SC_PERIPH_CLK5_EN_PCLK_PMUSSI_CCPU |
361 ALWAYSON_SC_PERIPH_CLK5_EN_PCLK_PMUSSI_MCU;
362
363 hi6220_clk_enable(data, &ao_sc->clk5_en);
364
365 /* Output high to PMIC on PWR_HOLD_GPIO0_0 */
366 gpio_request(0, "PWR_HOLD_GPIO0_0");
367 gpio_direction_output(0, 1);
368}
369
370int misc_init_r(void)
371{
372 return 0;
373}
374
375int board_init(void)
376{
Peter Griffin31f327e2015-07-30 18:55:23 +0100377 return 0;
378}
379
Masahiro Yamada0a780172017-05-09 20:31:39 +0900380#ifdef CONFIG_MMC
Peter Griffin31f327e2015-07-30 18:55:23 +0100381
382static int init_dwmmc(void)
383{
xypron.glpk@gmx.dea43d6d42017-07-30 21:30:55 +0200384 int ret = 0;
Peter Griffin31f327e2015-07-30 18:55:23 +0100385
Masahiro Yamada7942e912017-01-10 13:32:04 +0900386#ifdef CONFIG_MMC_DW
Peter Griffin31f327e2015-07-30 18:55:23 +0100387
Peter Griffin461f4422017-08-15 17:18:16 +0100388 /* mmc0 pll is already configured by ATF */
389 mmc0_reset_clk();
Peter Griffin31f327e2015-07-30 18:55:23 +0100390 ret = hi6220_pinmux_config(PERIPH_ID_SDMMC0);
391 if (ret)
392 printf("%s: Error configuring pinmux for eMMC (%d)\n"
393 , __func__, ret);
394
395 ret |= hi6220_dwmci_add_port(0, HI6220_MMC0_BASE, 8);
396 if (ret)
397 printf("%s: Error adding eMMC port (%d)\n", __func__, ret);
398
399
400 /* take mmc1 (sd slot) out of reset, configure clocks and pinmuxing */
401 mmc1_init_pll();
402 mmc1_reset_clk();
403
404 ret |= hi6220_pinmux_config(PERIPH_ID_SDMMC1);
405 if (ret)
406 printf("%s: Error configuring pinmux for eMMC (%d)\n"
407 , __func__, ret);
408
409 config_sd_carddetect();
410
411 ret |= hi6220_dwmci_add_port(1, HI6220_MMC1_BASE, 4);
412 if (ret)
413 printf("%s: Error adding SD port (%d)\n", __func__, ret);
414
415#endif
416 return ret;
417}
418
419/* setup board specific PMIC */
420int power_init_board(void)
421{
422 /* init the hi6220 pmussi ip */
423 hi6220_pmussi_init();
424
425 power_hi6553_init((u8 *)HI6220_PMUSSI_BASE);
426
427 return 0;
428}
429
430int board_mmc_init(bd_t *bis)
431{
432 int ret;
433
434 /* add the eMMC and sd ports */
435 ret = init_dwmmc();
436
437 if (ret)
438 debug("init_dwmmc failed\n");
439
440 return ret;
441}
442#endif
443
444int dram_init(void)
445{
446 gd->ram_size = PHYS_SDRAM_1_SIZE;
447 return 0;
448}
449
Simon Glass2f949c32017-03-31 08:40:32 -0600450int dram_init_banksize(void)
Peter Griffin31f327e2015-07-30 18:55:23 +0100451{
Peter Griffin9967fd02016-04-20 17:14:02 +0100452 /*
453 * Reserve regions below from DT memory node (which gets generated
454 * by U-Boot from the dram banks in arch_fixup_fdt() before booting
455 * the kernel. This will then match the kernel hikey dts memory node.
456 *
457 * 0x05e0,0000 - 0x05ef,ffff: MCU firmware runtime using
458 * 0x05f0,1000 - 0x05f0,1fff: Reboot reason
459 * 0x06df,f000 - 0x06df,ffff: Mailbox message data
460 * 0x0740,f000 - 0x0740,ffff: MCU firmware section
461 * 0x21f0,0000 - 0x21ff,ffff: pstore/ramoops buffer
462 * 0x3e00,0000 - 0x3fff,ffff: OP-TEE
463 */
464
Peter Griffin31f327e2015-07-30 18:55:23 +0100465 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
Peter Griffin9967fd02016-04-20 17:14:02 +0100466 gd->bd->bi_dram[0].size = 0x05e00000;
467
468 gd->bd->bi_dram[1].start = 0x05f00000;
469 gd->bd->bi_dram[1].size = 0x00001000;
470
471 gd->bd->bi_dram[2].start = 0x05f02000;
472 gd->bd->bi_dram[2].size = 0x00efd000;
473
474 gd->bd->bi_dram[3].start = 0x06e00000;
475 gd->bd->bi_dram[3].size = 0x0060f000;
476
477 gd->bd->bi_dram[4].start = 0x07410000;
478 gd->bd->bi_dram[4].size = 0x1aaf0000;
479
480 gd->bd->bi_dram[5].start = 0x22000000;
481 gd->bd->bi_dram[5].size = 0x1c000000;
Simon Glass2f949c32017-03-31 08:40:32 -0600482
483 return 0;
Peter Griffin31f327e2015-07-30 18:55:23 +0100484}
485
Peter Griffin31f327e2015-07-30 18:55:23 +0100486void reset_cpu(ulong addr)
487{
Peter Griffin97fa7652016-04-20 17:14:00 +0100488 writel(0x48698284, &ao_sc->stat0);
489 wfi();
Peter Griffin31f327e2015-07-30 18:55:23 +0100490}