blob: 29165266630cd9ca627d078acfe54ed5ca4f255f [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 */
Simon Glassafb02152019-12-28 10:45:01 -07006#include <cpu_func.h>
Peter Griffin31f327e2015-07-30 18:55:23 +01007#include <dm.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07008#include <fdt_support.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Peter Griffin0382c642015-09-10 21:55:17 +010012#include <dm/platform_data/serial_pl01x.h>
Peter Griffin31f327e2015-07-30 18:55:23 +010013#include <errno.h>
14#include <malloc.h>
15#include <netdev.h>
16#include <asm/io.h>
17#include <usb.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Peter Griffin31f327e2015-07-30 18:55:23 +010019#include <power/hi6553_pmic.h>
20#include <asm-generic/gpio.h>
21#include <asm/arch/dwmmc.h>
22#include <asm/arch/gpio.h>
23#include <asm/arch/periph.h>
24#include <asm/arch/pinmux.h>
25#include <asm/arch/hi6220.h>
Alexander Graf580be6e2016-03-04 01:09:53 +010026#include <asm/armv8/mmu.h>
Peter Griffin31f327e2015-07-30 18:55:23 +010027
28/*TODO drop this table in favour of device tree */
Simon Glassb75b15b2020-12-03 16:55:23 -070029static const struct hikey_gpio_plat hi6220_gpio[] = {
Peter Griffin31f327e2015-07-30 18:55:23 +010030 { 0, HI6220_GPIO_BASE(0)},
31 { 1, HI6220_GPIO_BASE(1)},
32 { 2, HI6220_GPIO_BASE(2)},
33 { 3, HI6220_GPIO_BASE(3)},
34 { 4, HI6220_GPIO_BASE(4)},
35 { 5, HI6220_GPIO_BASE(5)},
36 { 6, HI6220_GPIO_BASE(6)},
37 { 7, HI6220_GPIO_BASE(7)},
38 { 8, HI6220_GPIO_BASE(8)},
39 { 9, HI6220_GPIO_BASE(9)},
40 { 10, HI6220_GPIO_BASE(10)},
41 { 11, HI6220_GPIO_BASE(11)},
42 { 12, HI6220_GPIO_BASE(12)},
43 { 13, HI6220_GPIO_BASE(13)},
44 { 14, HI6220_GPIO_BASE(14)},
45 { 15, HI6220_GPIO_BASE(15)},
46 { 16, HI6220_GPIO_BASE(16)},
47 { 17, HI6220_GPIO_BASE(17)},
48 { 18, HI6220_GPIO_BASE(18)},
49 { 19, HI6220_GPIO_BASE(19)},
50
51};
52
Simon Glass1d8364a2020-12-28 20:34:54 -070053U_BOOT_DRVINFOS(hi6220_gpios) = {
Peter Griffin31f327e2015-07-30 18:55:23 +010054 { "gpio_hi6220", &hi6220_gpio[0] },
55 { "gpio_hi6220", &hi6220_gpio[1] },
56 { "gpio_hi6220", &hi6220_gpio[2] },
57 { "gpio_hi6220", &hi6220_gpio[3] },
58 { "gpio_hi6220", &hi6220_gpio[4] },
59 { "gpio_hi6220", &hi6220_gpio[5] },
60 { "gpio_hi6220", &hi6220_gpio[6] },
61 { "gpio_hi6220", &hi6220_gpio[7] },
62 { "gpio_hi6220", &hi6220_gpio[8] },
63 { "gpio_hi6220", &hi6220_gpio[9] },
64 { "gpio_hi6220", &hi6220_gpio[10] },
65 { "gpio_hi6220", &hi6220_gpio[11] },
66 { "gpio_hi6220", &hi6220_gpio[12] },
67 { "gpio_hi6220", &hi6220_gpio[13] },
68 { "gpio_hi6220", &hi6220_gpio[14] },
69 { "gpio_hi6220", &hi6220_gpio[15] },
70 { "gpio_hi6220", &hi6220_gpio[16] },
71 { "gpio_hi6220", &hi6220_gpio[17] },
72 { "gpio_hi6220", &hi6220_gpio[18] },
73 { "gpio_hi6220", &hi6220_gpio[19] },
74};
75
76DECLARE_GLOBAL_DATA_PTR;
77
Peter Griffinc97c37a2016-04-20 17:13:59 +010078#if !CONFIG_IS_ENABLED(OF_CONTROL)
79
Simon Glassb75b15b2020-12-03 16:55:23 -070080static const struct pl01x_serial_plat serial_plat = {
Peter Griffin0382c642015-09-10 21:55:17 +010081#if CONFIG_CONS_INDEX == 1
82 .base = HI6220_UART0_BASE,
83#elif CONFIG_CONS_INDEX == 4
84 .base = HI6220_UART3_BASE,
85#else
Vagrant Cascadiane1643ed2016-03-15 12:11:13 -070086#error "Unsupported console index value."
Peter Griffin0382c642015-09-10 21:55:17 +010087#endif
88 .type = TYPE_PL011,
89 .clock = 19200000
90};
91
Simon Glass1d8364a2020-12-28 20:34:54 -070092U_BOOT_DRVINFO(hikey_seriala) = {
Peter Griffin0382c642015-09-10 21:55:17 +010093 .name = "serial_pl01x",
Simon Glassb75b15b2020-12-03 16:55:23 -070094 .plat = &serial_plat,
Peter Griffin0382c642015-09-10 21:55:17 +010095};
Peter Griffinc97c37a2016-04-20 17:13:59 +010096#endif
Peter Griffin0382c642015-09-10 21:55:17 +010097
Alexander Graf580be6e2016-03-04 01:09:53 +010098static struct mm_region hikey_mem_map[] = {
99 {
York Sunc7104e52016-06-24 16:46:22 -0700100 .virt = 0x0UL,
101 .phys = 0x0UL,
Alexander Graf580be6e2016-03-04 01:09:53 +0100102 .size = 0x80000000UL,
103 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
104 PTE_BLOCK_INNER_SHARE
105 }, {
York Sunc7104e52016-06-24 16:46:22 -0700106 .virt = 0x80000000UL,
107 .phys = 0x80000000UL,
Alexander Graf580be6e2016-03-04 01:09:53 +0100108 .size = 0x80000000UL,
109 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
110 PTE_BLOCK_NON_SHARE |
111 PTE_BLOCK_PXN | PTE_BLOCK_UXN
112 }, {
113 /* List terminator */
114 0,
115 }
116};
117
118struct mm_region *mem_map = hikey_mem_map;
119
Peter Griffin0382c642015-09-10 21:55:17 +0100120#ifdef CONFIG_BOARD_EARLY_INIT_F
121int board_uart_init(void)
122{
123 switch (CONFIG_CONS_INDEX) {
124 case 1:
125 hi6220_pinmux_config(PERIPH_ID_UART0);
126 break;
127 case 4:
128 hi6220_pinmux_config(PERIPH_ID_UART3);
129 break;
130 default:
131 debug("%s: Unsupported UART selected\n", __func__);
132 return -1;
133 }
134
135 return 0;
136}
137
138int board_early_init_f(void)
139{
140 board_uart_init();
141 return 0;
142}
143#endif
144
Peter Griffin31f327e2015-07-30 18:55:23 +0100145struct peri_sc_periph_regs *peri_sc =
146 (struct peri_sc_periph_regs *)HI6220_PERI_BASE;
147
148struct alwayson_sc_regs *ao_sc =
149 (struct alwayson_sc_regs *)ALWAYSON_CTRL_BASE;
150
151/* status offset from enable reg */
152#define STAT_EN_OFF 0x2
153
154void hi6220_clk_enable(u32 bitfield, unsigned int *clk_base)
155{
156 uint32_t data;
157
158 data = readl(clk_base);
159 data |= bitfield;
160
161 writel(bitfield, clk_base);
162 do {
163 data = readl(clk_base + STAT_EN_OFF);
164 } while ((data & bitfield) == 0);
165}
166
167/* status offset from disable reg */
168#define STAT_DIS_OFF 0x1
169
170void hi6220_clk_disable(u32 bitfield, unsigned int *clk_base)
171{
172 uint32_t data;
173
174 data = readl(clk_base);
175 data |= bitfield;
176
177 writel(data, clk_base);
178 do {
179 data = readl(clk_base + STAT_DIS_OFF);
180 } while (data & bitfield);
181}
182
183#define EYE_PATTERN 0x70533483
184
185int board_usb_init(int index, enum usb_init_type init)
186{
187 unsigned int data;
188
189 /* enable USB clock */
190 hi6220_clk_enable(PERI_CLK0_USBOTG, &peri_sc->clk0_en);
191
192 /* take usb IPs out of reset */
193 writel(PERI_RST0_USBOTG_BUS | PERI_RST0_POR_PICOPHY |
194 PERI_RST0_USBOTG | PERI_RST0_USBOTG_32K,
195 &peri_sc->rst0_dis);
196 do {
197 data = readl(&peri_sc->rst0_stat);
198 data &= PERI_RST0_USBOTG_BUS | PERI_RST0_POR_PICOPHY |
199 PERI_RST0_USBOTG | PERI_RST0_USBOTG_32K;
200 } while (data);
201
202 /*CTRL 5*/
203 data = readl(&peri_sc->ctrl5);
204 data &= ~PERI_CTRL5_PICOPHY_BC_MODE;
205 data |= PERI_CTRL5_USBOTG_RES_SEL | PERI_CTRL5_PICOPHY_ACAENB;
206 data |= 0x300;
207 writel(data, &peri_sc->ctrl5);
208
209 /*CTRL 4*/
210
211 /* configure USB PHY */
212 data = readl(&peri_sc->ctrl4);
213
214 /* make PHY out of low power mode */
215 data &= ~PERI_CTRL4_PICO_SIDDQ;
216 data &= ~PERI_CTRL4_PICO_OGDISABLE;
217 data |= PERI_CTRL4_PICO_VBUSVLDEXTSEL | PERI_CTRL4_PICO_VBUSVLDEXT;
218 writel(data, &peri_sc->ctrl4);
219
220 writel(EYE_PATTERN, &peri_sc->ctrl8);
221
222 mdelay(5);
223 return 0;
224}
225
226static int config_sd_carddetect(void)
227{
228 int ret;
229
230 /* configure GPIO8 as nopull */
231 writel(0, 0xf8001830);
232
233 gpio_request(8, "SD CD");
234
235 gpio_direction_input(8);
236 ret = gpio_get_value(8);
237
238 if (!ret) {
239 printf("%s: SD card present\n", __func__);
240 return 1;
241 }
242
243 printf("%s: SD card not present\n", __func__);
244 return 0;
245}
246
Peter Griffin31f327e2015-07-30 18:55:23 +0100247static void mmc1_init_pll(void)
248{
249 uint32_t data;
250
251 /* select SYSPLL as the source of MMC1 */
252 /* select SYSPLL as the source of MUX1 (SC_CLK_SEL0) */
253 writel(1 << 11 | 1 << 27, &peri_sc->clk0_sel);
254 do {
255 data = readl(&peri_sc->clk0_sel);
256 } while (!(data & (1 << 11)));
257
258 /* select MUX1 as the source of MUX2 (SC_CLK_SEL0) */
259 writel(1 << 30, &peri_sc->clk0_sel);
260 do {
261 data = readl(&peri_sc->clk0_sel);
262 } while (data & (1 << 14));
263
264 hi6220_clk_enable(PERI_CLK0_MMC1, &peri_sc->clk0_en);
265
266 hi6220_clk_enable(PERI_CLK12_MMC1_SRC, &peri_sc->clk12_en);
267
268 do {
269 /* 1.2GHz / 50 = 24MHz */
270 writel(0x31 | (1 << 7), &peri_sc->clkcfg8bit2);
271 data = readl(&peri_sc->clkcfg8bit2);
272 } while ((data & 0x31) != 0x31);
273}
274
275static void mmc1_reset_clk(void)
276{
277 unsigned int data;
278
279 /* disable mmc1 bus clock */
280 hi6220_clk_disable(PERI_CLK0_MMC1, &peri_sc->clk0_dis);
281
282 /* enable mmc1 bus clock */
283 hi6220_clk_enable(PERI_CLK0_MMC1, &peri_sc->clk0_en);
284
285 /* reset mmc1 clock domain */
286 writel(PERI_RST0_MMC1, &peri_sc->rst0_en);
287
288 /* bypass mmc1 clock phase */
289 data = readl(&peri_sc->ctrl2);
290 data |= 3 << 2;
291 writel(data, &peri_sc->ctrl2);
292
293 /* disable low power */
294 data = readl(&peri_sc->ctrl13);
295 data |= 1 << 4;
296 writel(data, &peri_sc->ctrl13);
297 do {
298 data = readl(&peri_sc->rst0_stat);
299 } while (!(data & PERI_RST0_MMC1));
300
Peter Griffin461f4422017-08-15 17:18:16 +0100301 /* unreset mmc1 clock domain */
Peter Griffin31f327e2015-07-30 18:55:23 +0100302 writel(PERI_RST0_MMC1, &peri_sc->rst0_dis);
303 do {
304 data = readl(&peri_sc->rst0_stat);
305 } while (data & PERI_RST0_MMC1);
306}
307
Peter Griffin461f4422017-08-15 17:18:16 +0100308static void mmc0_reset_clk(void)
309{
310 unsigned int data;
311
312 /* disable mmc0 bus clock */
313 hi6220_clk_disable(PERI_CLK0_MMC0, &peri_sc->clk0_dis);
314
315 /* enable mmc0 bus clock */
316 hi6220_clk_enable(PERI_CLK0_MMC0, &peri_sc->clk0_en);
317
318 /* reset mmc0 clock domain */
319 writel(PERI_RST0_MMC0, &peri_sc->rst0_en);
320
321 /* bypass mmc0 clock phase */
322 data = readl(&peri_sc->ctrl2);
323 data |= 3;
324 writel(data, &peri_sc->ctrl2);
325
326 /* disable low power */
327 data = readl(&peri_sc->ctrl13);
328 data |= 1 << 3;
329 writel(data, &peri_sc->ctrl13);
330 do {
331 data = readl(&peri_sc->rst0_stat);
332 } while (!(data & PERI_RST0_MMC0));
333
334 /* unreset mmc0 clock domain */
335 writel(PERI_RST0_MMC0, &peri_sc->rst0_dis);
336 do {
337 data = readl(&peri_sc->rst0_stat);
338 } while (data & PERI_RST0_MMC0);
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
Peter Griffin31f327e2015-07-30 18:55:23 +0100399 /* take mmc1 (sd slot) out of reset, configure clocks and pinmuxing */
400 mmc1_init_pll();
401 mmc1_reset_clk();
402
403 ret |= hi6220_pinmux_config(PERIPH_ID_SDMMC1);
404 if (ret)
405 printf("%s: Error configuring pinmux for eMMC (%d)\n"
406 , __func__, ret);
407
408 config_sd_carddetect();
409
410 ret |= hi6220_dwmci_add_port(1, HI6220_MMC1_BASE, 4);
411 if (ret)
412 printf("%s: Error adding SD port (%d)\n", __func__, ret);
413
414#endif
415 return ret;
416}
417
418/* setup board specific PMIC */
419int power_init_board(void)
420{
421 /* init the hi6220 pmussi ip */
422 hi6220_pmussi_init();
423
424 power_hi6553_init((u8 *)HI6220_PMUSSI_BASE);
425
426 return 0;
427}
428
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900429int board_mmc_init(struct bd_info *bis)
Peter Griffin31f327e2015-07-30 18:55:23 +0100430{
431 int ret;
432
433 /* add the eMMC and sd ports */
434 ret = init_dwmmc();
435
436 if (ret)
437 debug("init_dwmmc failed\n");
438
439 return ret;
440}
441#endif
442
443int dram_init(void)
444{
445 gd->ram_size = PHYS_SDRAM_1_SIZE;
446 return 0;
447}
448
Simon Glass2f949c32017-03-31 08:40:32 -0600449int dram_init_banksize(void)
Peter Griffin31f327e2015-07-30 18:55:23 +0100450{
Peter Griffin9967fd02016-04-20 17:14:02 +0100451 /*
452 * Reserve regions below from DT memory node (which gets generated
453 * by U-Boot from the dram banks in arch_fixup_fdt() before booting
454 * the kernel. This will then match the kernel hikey dts memory node.
455 *
456 * 0x05e0,0000 - 0x05ef,ffff: MCU firmware runtime using
457 * 0x05f0,1000 - 0x05f0,1fff: Reboot reason
458 * 0x06df,f000 - 0x06df,ffff: Mailbox message data
459 * 0x0740,f000 - 0x0740,ffff: MCU firmware section
460 * 0x21f0,0000 - 0x21ff,ffff: pstore/ramoops buffer
461 * 0x3e00,0000 - 0x3fff,ffff: OP-TEE
462 */
463
Peter Griffin31f327e2015-07-30 18:55:23 +0100464 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
Peter Griffin9967fd02016-04-20 17:14:02 +0100465 gd->bd->bi_dram[0].size = 0x05e00000;
466
467 gd->bd->bi_dram[1].start = 0x05f00000;
468 gd->bd->bi_dram[1].size = 0x00001000;
469
470 gd->bd->bi_dram[2].start = 0x05f02000;
471 gd->bd->bi_dram[2].size = 0x00efd000;
472
473 gd->bd->bi_dram[3].start = 0x06e00000;
474 gd->bd->bi_dram[3].size = 0x0060f000;
475
476 gd->bd->bi_dram[4].start = 0x07410000;
477 gd->bd->bi_dram[4].size = 0x1aaf0000;
478
479 gd->bd->bi_dram[5].start = 0x22000000;
480 gd->bd->bi_dram[5].size = 0x1c000000;
Simon Glass2f949c32017-03-31 08:40:32 -0600481
482 return 0;
Peter Griffin31f327e2015-07-30 18:55:23 +0100483}
484
Harald Seiler6f14d5f2020-12-15 16:47:52 +0100485void reset_cpu(void)
Peter Griffin31f327e2015-07-30 18:55:23 +0100486{
Peter Griffin97fa7652016-04-20 17:14:00 +0100487 writel(0x48698284, &ao_sc->stat0);
488 wfi();
Peter Griffin31f327e2015-07-30 18:55:23 +0100489}