hikey.c 9.9 KB

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