hikey.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2015 Linaro
  4. * Peter Griffin <peter.griffin@linaro.org>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <dm/platform_data/serial_pl01x.h>
  9. #include <errno.h>
  10. #include <malloc.h>
  11. #include <netdev.h>
  12. #include <asm/io.h>
  13. #include <usb.h>
  14. #include <power/hi6553_pmic.h>
  15. #include <asm-generic/gpio.h>
  16. #include <asm/arch/dwmmc.h>
  17. #include <asm/arch/gpio.h>
  18. #include <asm/arch/periph.h>
  19. #include <asm/arch/pinmux.h>
  20. #include <asm/arch/hi6220.h>
  21. #include <asm/armv8/mmu.h>
  22. /*TODO drop this table in favour of device tree */
  23. static const struct hikey_gpio_platdata hi6220_gpio[] = {
  24. { 0, HI6220_GPIO_BASE(0)},
  25. { 1, HI6220_GPIO_BASE(1)},
  26. { 2, HI6220_GPIO_BASE(2)},
  27. { 3, HI6220_GPIO_BASE(3)},
  28. { 4, HI6220_GPIO_BASE(4)},
  29. { 5, HI6220_GPIO_BASE(5)},
  30. { 6, HI6220_GPIO_BASE(6)},
  31. { 7, HI6220_GPIO_BASE(7)},
  32. { 8, HI6220_GPIO_BASE(8)},
  33. { 9, HI6220_GPIO_BASE(9)},
  34. { 10, HI6220_GPIO_BASE(10)},
  35. { 11, HI6220_GPIO_BASE(11)},
  36. { 12, HI6220_GPIO_BASE(12)},
  37. { 13, HI6220_GPIO_BASE(13)},
  38. { 14, HI6220_GPIO_BASE(14)},
  39. { 15, HI6220_GPIO_BASE(15)},
  40. { 16, HI6220_GPIO_BASE(16)},
  41. { 17, HI6220_GPIO_BASE(17)},
  42. { 18, HI6220_GPIO_BASE(18)},
  43. { 19, HI6220_GPIO_BASE(19)},
  44. };
  45. U_BOOT_DEVICES(hi6220_gpios) = {
  46. { "gpio_hi6220", &hi6220_gpio[0] },
  47. { "gpio_hi6220", &hi6220_gpio[1] },
  48. { "gpio_hi6220", &hi6220_gpio[2] },
  49. { "gpio_hi6220", &hi6220_gpio[3] },
  50. { "gpio_hi6220", &hi6220_gpio[4] },
  51. { "gpio_hi6220", &hi6220_gpio[5] },
  52. { "gpio_hi6220", &hi6220_gpio[6] },
  53. { "gpio_hi6220", &hi6220_gpio[7] },
  54. { "gpio_hi6220", &hi6220_gpio[8] },
  55. { "gpio_hi6220", &hi6220_gpio[9] },
  56. { "gpio_hi6220", &hi6220_gpio[10] },
  57. { "gpio_hi6220", &hi6220_gpio[11] },
  58. { "gpio_hi6220", &hi6220_gpio[12] },
  59. { "gpio_hi6220", &hi6220_gpio[13] },
  60. { "gpio_hi6220", &hi6220_gpio[14] },
  61. { "gpio_hi6220", &hi6220_gpio[15] },
  62. { "gpio_hi6220", &hi6220_gpio[16] },
  63. { "gpio_hi6220", &hi6220_gpio[17] },
  64. { "gpio_hi6220", &hi6220_gpio[18] },
  65. { "gpio_hi6220", &hi6220_gpio[19] },
  66. };
  67. DECLARE_GLOBAL_DATA_PTR;
  68. #if !CONFIG_IS_ENABLED(OF_CONTROL)
  69. static const struct pl01x_serial_platdata serial_platdata = {
  70. #if CONFIG_CONS_INDEX == 1
  71. .base = HI6220_UART0_BASE,
  72. #elif CONFIG_CONS_INDEX == 4
  73. .base = HI6220_UART3_BASE,
  74. #else
  75. #error "Unsupported console index value."
  76. #endif
  77. .type = TYPE_PL011,
  78. .clock = 19200000
  79. };
  80. U_BOOT_DEVICE(hikey_seriala) = {
  81. .name = "serial_pl01x",
  82. .platdata = &serial_platdata,
  83. };
  84. #endif
  85. static struct mm_region hikey_mem_map[] = {
  86. {
  87. .virt = 0x0UL,
  88. .phys = 0x0UL,
  89. .size = 0x80000000UL,
  90. .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
  91. PTE_BLOCK_INNER_SHARE
  92. }, {
  93. .virt = 0x80000000UL,
  94. .phys = 0x80000000UL,
  95. .size = 0x80000000UL,
  96. .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
  97. PTE_BLOCK_NON_SHARE |
  98. PTE_BLOCK_PXN | PTE_BLOCK_UXN
  99. }, {
  100. /* List terminator */
  101. 0,
  102. }
  103. };
  104. struct mm_region *mem_map = hikey_mem_map;
  105. #ifdef CONFIG_BOARD_EARLY_INIT_F
  106. int board_uart_init(void)
  107. {
  108. switch (CONFIG_CONS_INDEX) {
  109. case 1:
  110. hi6220_pinmux_config(PERIPH_ID_UART0);
  111. break;
  112. case 4:
  113. hi6220_pinmux_config(PERIPH_ID_UART3);
  114. break;
  115. default:
  116. debug("%s: Unsupported UART selected\n", __func__);
  117. return -1;
  118. }
  119. return 0;
  120. }
  121. int board_early_init_f(void)
  122. {
  123. board_uart_init();
  124. return 0;
  125. }
  126. #endif
  127. struct peri_sc_periph_regs *peri_sc =
  128. (struct peri_sc_periph_regs *)HI6220_PERI_BASE;
  129. struct alwayson_sc_regs *ao_sc =
  130. (struct alwayson_sc_regs *)ALWAYSON_CTRL_BASE;
  131. /* status offset from enable reg */
  132. #define STAT_EN_OFF 0x2
  133. void hi6220_clk_enable(u32 bitfield, unsigned int *clk_base)
  134. {
  135. uint32_t data;
  136. data = readl(clk_base);
  137. data |= bitfield;
  138. writel(bitfield, clk_base);
  139. do {
  140. data = readl(clk_base + STAT_EN_OFF);
  141. } while ((data & bitfield) == 0);
  142. }
  143. /* status offset from disable reg */
  144. #define STAT_DIS_OFF 0x1
  145. void hi6220_clk_disable(u32 bitfield, unsigned int *clk_base)
  146. {
  147. uint32_t data;
  148. data = readl(clk_base);
  149. data |= bitfield;
  150. writel(data, clk_base);
  151. do {
  152. data = readl(clk_base + STAT_DIS_OFF);
  153. } while (data & bitfield);
  154. }
  155. #define EYE_PATTERN 0x70533483
  156. int board_usb_init(int index, enum usb_init_type init)
  157. {
  158. unsigned int data;
  159. /* enable USB clock */
  160. hi6220_clk_enable(PERI_CLK0_USBOTG, &peri_sc->clk0_en);
  161. /* take usb IPs out of reset */
  162. writel(PERI_RST0_USBOTG_BUS | PERI_RST0_POR_PICOPHY |
  163. PERI_RST0_USBOTG | PERI_RST0_USBOTG_32K,
  164. &peri_sc->rst0_dis);
  165. do {
  166. data = readl(&peri_sc->rst0_stat);
  167. data &= PERI_RST0_USBOTG_BUS | PERI_RST0_POR_PICOPHY |
  168. PERI_RST0_USBOTG | PERI_RST0_USBOTG_32K;
  169. } while (data);
  170. /*CTRL 5*/
  171. data = readl(&peri_sc->ctrl5);
  172. data &= ~PERI_CTRL5_PICOPHY_BC_MODE;
  173. data |= PERI_CTRL5_USBOTG_RES_SEL | PERI_CTRL5_PICOPHY_ACAENB;
  174. data |= 0x300;
  175. writel(data, &peri_sc->ctrl5);
  176. /*CTRL 4*/
  177. /* configure USB PHY */
  178. data = readl(&peri_sc->ctrl4);
  179. /* make PHY out of low power mode */
  180. data &= ~PERI_CTRL4_PICO_SIDDQ;
  181. data &= ~PERI_CTRL4_PICO_OGDISABLE;
  182. data |= PERI_CTRL4_PICO_VBUSVLDEXTSEL | PERI_CTRL4_PICO_VBUSVLDEXT;
  183. writel(data, &peri_sc->ctrl4);
  184. writel(EYE_PATTERN, &peri_sc->ctrl8);
  185. mdelay(5);
  186. return 0;
  187. }
  188. static int config_sd_carddetect(void)
  189. {
  190. int ret;
  191. /* configure GPIO8 as nopull */
  192. writel(0, 0xf8001830);
  193. gpio_request(8, "SD CD");
  194. gpio_direction_input(8);
  195. ret = gpio_get_value(8);
  196. if (!ret) {
  197. printf("%s: SD card present\n", __func__);
  198. return 1;
  199. }
  200. printf("%s: SD card not present\n", __func__);
  201. return 0;
  202. }
  203. static void mmc1_init_pll(void)
  204. {
  205. uint32_t data;
  206. /* select SYSPLL as the source of MMC1 */
  207. /* select SYSPLL as the source of MUX1 (SC_CLK_SEL0) */
  208. writel(1 << 11 | 1 << 27, &peri_sc->clk0_sel);
  209. do {
  210. data = readl(&peri_sc->clk0_sel);
  211. } while (!(data & (1 << 11)));
  212. /* select MUX1 as the source of MUX2 (SC_CLK_SEL0) */
  213. writel(1 << 30, &peri_sc->clk0_sel);
  214. do {
  215. data = readl(&peri_sc->clk0_sel);
  216. } while (data & (1 << 14));
  217. hi6220_clk_enable(PERI_CLK0_MMC1, &peri_sc->clk0_en);
  218. hi6220_clk_enable(PERI_CLK12_MMC1_SRC, &peri_sc->clk12_en);
  219. do {
  220. /* 1.2GHz / 50 = 24MHz */
  221. writel(0x31 | (1 << 7), &peri_sc->clkcfg8bit2);
  222. data = readl(&peri_sc->clkcfg8bit2);
  223. } while ((data & 0x31) != 0x31);
  224. }
  225. static void mmc1_reset_clk(void)
  226. {
  227. unsigned int data;
  228. /* disable mmc1 bus clock */
  229. hi6220_clk_disable(PERI_CLK0_MMC1, &peri_sc->clk0_dis);
  230. /* enable mmc1 bus clock */
  231. hi6220_clk_enable(PERI_CLK0_MMC1, &peri_sc->clk0_en);
  232. /* reset mmc1 clock domain */
  233. writel(PERI_RST0_MMC1, &peri_sc->rst0_en);
  234. /* bypass mmc1 clock phase */
  235. data = readl(&peri_sc->ctrl2);
  236. data |= 3 << 2;
  237. writel(data, &peri_sc->ctrl2);
  238. /* disable low power */
  239. data = readl(&peri_sc->ctrl13);
  240. data |= 1 << 4;
  241. writel(data, &peri_sc->ctrl13);
  242. do {
  243. data = readl(&peri_sc->rst0_stat);
  244. } while (!(data & PERI_RST0_MMC1));
  245. /* unreset mmc1 clock domain */
  246. writel(PERI_RST0_MMC1, &peri_sc->rst0_dis);
  247. do {
  248. data = readl(&peri_sc->rst0_stat);
  249. } while (data & PERI_RST0_MMC1);
  250. }
  251. static void mmc0_reset_clk(void)
  252. {
  253. unsigned int data;
  254. /* disable mmc0 bus clock */
  255. hi6220_clk_disable(PERI_CLK0_MMC0, &peri_sc->clk0_dis);
  256. /* enable mmc0 bus clock */
  257. hi6220_clk_enable(PERI_CLK0_MMC0, &peri_sc->clk0_en);
  258. /* reset mmc0 clock domain */
  259. writel(PERI_RST0_MMC0, &peri_sc->rst0_en);
  260. /* bypass mmc0 clock phase */
  261. data = readl(&peri_sc->ctrl2);
  262. data |= 3;
  263. writel(data, &peri_sc->ctrl2);
  264. /* disable low power */
  265. data = readl(&peri_sc->ctrl13);
  266. data |= 1 << 3;
  267. writel(data, &peri_sc->ctrl13);
  268. do {
  269. data = readl(&peri_sc->rst0_stat);
  270. } while (!(data & PERI_RST0_MMC0));
  271. /* unreset mmc0 clock domain */
  272. writel(PERI_RST0_MMC0, &peri_sc->rst0_dis);
  273. do {
  274. data = readl(&peri_sc->rst0_stat);
  275. } while (data & PERI_RST0_MMC0);
  276. }
  277. /* PMU SSI is the IP that maps the external PMU hi6553 registers as IO */
  278. static void hi6220_pmussi_init(void)
  279. {
  280. uint32_t data;
  281. /* Take PMUSSI out of reset */
  282. writel(ALWAYSON_SC_PERIPH_RST4_DIS_PRESET_PMUSSI_N,
  283. &ao_sc->rst4_dis);
  284. do {
  285. data = readl(&ao_sc->rst4_stat);
  286. } while (data & ALWAYSON_SC_PERIPH_RST4_DIS_PRESET_PMUSSI_N);
  287. /* set PMU SSI clock latency for read operation */
  288. data = readl(&ao_sc->mcu_subsys_ctrl3);
  289. data &= ~ALWAYSON_SC_MCU_SUBSYS_CTRL3_RCLK_MASK;
  290. data |= ALWAYSON_SC_MCU_SUBSYS_CTRL3_RCLK_3;
  291. writel(data, &ao_sc->mcu_subsys_ctrl3);
  292. /* enable PMUSSI clock */
  293. data = ALWAYSON_SC_PERIPH_CLK5_EN_PCLK_PMUSSI_CCPU |
  294. ALWAYSON_SC_PERIPH_CLK5_EN_PCLK_PMUSSI_MCU;
  295. hi6220_clk_enable(data, &ao_sc->clk5_en);
  296. /* Output high to PMIC on PWR_HOLD_GPIO0_0 */
  297. gpio_request(0, "PWR_HOLD_GPIO0_0");
  298. gpio_direction_output(0, 1);
  299. }
  300. int misc_init_r(void)
  301. {
  302. return 0;
  303. }
  304. int board_init(void)
  305. {
  306. return 0;
  307. }
  308. #ifdef CONFIG_MMC
  309. static int init_dwmmc(void)
  310. {
  311. int ret = 0;
  312. #ifdef CONFIG_MMC_DW
  313. /* mmc0 pll is already configured by ATF */
  314. mmc0_reset_clk();
  315. ret = hi6220_pinmux_config(PERIPH_ID_SDMMC0);
  316. if (ret)
  317. printf("%s: Error configuring pinmux for eMMC (%d)\n"
  318. , __func__, ret);
  319. ret |= hi6220_dwmci_add_port(0, HI6220_MMC0_BASE, 8);
  320. if (ret)
  321. printf("%s: Error adding eMMC port (%d)\n", __func__, ret);
  322. /* take mmc1 (sd slot) out of reset, configure clocks and pinmuxing */
  323. mmc1_init_pll();
  324. mmc1_reset_clk();
  325. ret |= hi6220_pinmux_config(PERIPH_ID_SDMMC1);
  326. if (ret)
  327. printf("%s: Error configuring pinmux for eMMC (%d)\n"
  328. , __func__, ret);
  329. config_sd_carddetect();
  330. ret |= hi6220_dwmci_add_port(1, HI6220_MMC1_BASE, 4);
  331. if (ret)
  332. printf("%s: Error adding SD port (%d)\n", __func__, ret);
  333. #endif
  334. return ret;
  335. }
  336. /* setup board specific PMIC */
  337. int power_init_board(void)
  338. {
  339. /* init the hi6220 pmussi ip */
  340. hi6220_pmussi_init();
  341. power_hi6553_init((u8 *)HI6220_PMUSSI_BASE);
  342. return 0;
  343. }
  344. int board_mmc_init(bd_t *bis)
  345. {
  346. int ret;
  347. /* add the eMMC and sd ports */
  348. ret = init_dwmmc();
  349. if (ret)
  350. debug("init_dwmmc failed\n");
  351. return ret;
  352. }
  353. #endif
  354. int dram_init(void)
  355. {
  356. gd->ram_size = PHYS_SDRAM_1_SIZE;
  357. return 0;
  358. }
  359. int dram_init_banksize(void)
  360. {
  361. /*
  362. * Reserve regions below from DT memory node (which gets generated
  363. * by U-Boot from the dram banks in arch_fixup_fdt() before booting
  364. * the kernel. This will then match the kernel hikey dts memory node.
  365. *
  366. * 0x05e0,0000 - 0x05ef,ffff: MCU firmware runtime using
  367. * 0x05f0,1000 - 0x05f0,1fff: Reboot reason
  368. * 0x06df,f000 - 0x06df,ffff: Mailbox message data
  369. * 0x0740,f000 - 0x0740,ffff: MCU firmware section
  370. * 0x21f0,0000 - 0x21ff,ffff: pstore/ramoops buffer
  371. * 0x3e00,0000 - 0x3fff,ffff: OP-TEE
  372. */
  373. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  374. gd->bd->bi_dram[0].size = 0x05e00000;
  375. gd->bd->bi_dram[1].start = 0x05f00000;
  376. gd->bd->bi_dram[1].size = 0x00001000;
  377. gd->bd->bi_dram[2].start = 0x05f02000;
  378. gd->bd->bi_dram[2].size = 0x00efd000;
  379. gd->bd->bi_dram[3].start = 0x06e00000;
  380. gd->bd->bi_dram[3].size = 0x0060f000;
  381. gd->bd->bi_dram[4].start = 0x07410000;
  382. gd->bd->bi_dram[4].size = 0x1aaf0000;
  383. gd->bd->bi_dram[5].start = 0x22000000;
  384. gd->bd->bi_dram[5].size = 0x1c000000;
  385. return 0;
  386. }
  387. void reset_cpu(ulong addr)
  388. {
  389. writel(0x48698284, &ao_sc->stat0);
  390. wfi();
  391. }