1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+ 28a954eb6SPeter Griffin /* 38a954eb6SPeter Griffin * Copyright (C) 2015 Linaro. 48a954eb6SPeter Griffin * Peter Griffin <peter.griffin@linaro.org> 58a954eb6SPeter Griffin */ 68a954eb6SPeter Griffin 78a954eb6SPeter Griffin #include <common.h> 88a954eb6SPeter Griffin #include <fdtdec.h> 98a954eb6SPeter Griffin #include <asm/gpio.h> 108a954eb6SPeter Griffin #include <asm/io.h> 118a954eb6SPeter Griffin #include <asm/arch/pinmux.h> 128a954eb6SPeter Griffin 138a954eb6SPeter Griffin struct hi6220_pinmux0_regs *pmx0 = 148a954eb6SPeter Griffin (struct hi6220_pinmux0_regs *)HI6220_PINMUX0_BASE; 158a954eb6SPeter Griffin 168a954eb6SPeter Griffin struct hi6220_pinmux1_regs *pmx1 = 178a954eb6SPeter Griffin (struct hi6220_pinmux1_regs *)HI6220_PINMUX1_BASE; 188a954eb6SPeter Griffin 198a954eb6SPeter Griffin static void hi6220_uart_config(int peripheral) 208a954eb6SPeter Griffin { 218a954eb6SPeter Griffin switch (peripheral) { 228a954eb6SPeter Griffin case PERIPH_ID_UART0: 238a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[48]); /* UART0_RXD */ 248a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[49]); /* UART0_TXD */ 258a954eb6SPeter Griffin 268a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[49]); /* UART0_RXD */ 278a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[50]); /* UART0_TXD */ 288a954eb6SPeter Griffin break; 298a954eb6SPeter Griffin 308a954eb6SPeter Griffin case PERIPH_ID_UART1: 318a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[50]); /* UART1_CTS_N */ 328a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[51]); /* UART1_RTS_N */ 338a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[52]); /* UART1_RXD */ 348a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[53]); /* UART1_TXD */ 358a954eb6SPeter Griffin 368a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[51]); /*UART1_CTS_N*/ 378a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[53]); /* UART1_RXD */ 388a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[52]); /* UART1_RTS_N */ 398a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[54]); /* UART1_TXD */ 408a954eb6SPeter Griffin break; 418a954eb6SPeter Griffin 428a954eb6SPeter Griffin case PERIPH_ID_UART2: 438a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[54]); /* UART2_CTS_N */ 448a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[55]); /* UART2_RTS_N */ 458a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[56]); /* UART2_RXD */ 468a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[57]); /* UART2_TXD */ 478a954eb6SPeter Griffin 488a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[55]); /* UART2_CTS_N */ 498a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[56]); /* UART2_RTS_N */ 508a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[57]); /* UART2_RXD */ 518a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[58]); /* UART2_TXD */ 528a954eb6SPeter Griffin break; 538a954eb6SPeter Griffin 548a954eb6SPeter Griffin case PERIPH_ID_UART3: 558a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[96]); /* UART3_CTS_N */ 568a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[97]); /* UART3_RTS_N */ 578a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[98]); /* UART3_RXD */ 588a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[99]); /* UART3_TXD */ 598a954eb6SPeter Griffin 608a954eb6SPeter Griffin /* UART3_TXD */ 618a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[100]); 628a954eb6SPeter Griffin /* UART3_RTS_N */ 638a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[101]); 648a954eb6SPeter Griffin /* UART3_RXD */ 658a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[102]); 668a954eb6SPeter Griffin /* UART3_TXD */ 678a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[103]); 688a954eb6SPeter Griffin break; 698a954eb6SPeter Griffin 708a954eb6SPeter Griffin case PERIPH_ID_UART4: 718a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[116]); /* UART4_CTS_N */ 728a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[117]); /* UART4_RTS_N */ 738a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[118]); /* UART4_RXD */ 748a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[119]); /* UART4_TXD */ 758a954eb6SPeter Griffin 768a954eb6SPeter Griffin /* UART4_CTS_N */ 778a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[120]); 788a954eb6SPeter Griffin /* UART4_RTS_N */ 798a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[121]); 808a954eb6SPeter Griffin /* UART4_RXD */ 818a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[122]); 828a954eb6SPeter Griffin /* UART4_TXD */ 838a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[123]); 848a954eb6SPeter Griffin break; 858a954eb6SPeter Griffin case PERIPH_ID_UART5: 868a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[114]); /* UART5_RXD */ 878a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[115]); /* UART5_TXD */ 888a954eb6SPeter Griffin 898a954eb6SPeter Griffin /* UART5_RXD */ 908a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[118]); 918a954eb6SPeter Griffin /* UART5_TXD */ 928a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[119]); 938a954eb6SPeter Griffin 948a954eb6SPeter Griffin break; 958a954eb6SPeter Griffin 968a954eb6SPeter Griffin default: 978a954eb6SPeter Griffin debug("%s: invalid peripheral %d", __func__, peripheral); 988a954eb6SPeter Griffin return; 998a954eb6SPeter Griffin } 1008a954eb6SPeter Griffin } 1018a954eb6SPeter Griffin 1028a954eb6SPeter Griffin static int hi6220_mmc_config(int peripheral) 1038a954eb6SPeter Griffin { 1048a954eb6SPeter Griffin u32 tmp; 1058a954eb6SPeter Griffin 1068a954eb6SPeter Griffin switch (peripheral) { 1078a954eb6SPeter Griffin case PERIPH_ID_SDMMC0: 1088a954eb6SPeter Griffin 1098a954eb6SPeter Griffin /* eMMC pinmux config */ 1108a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[64]); /* EMMC_CLK */ 1118a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[65]); /* EMMC_CMD */ 1128a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[66]); /* EMMC_DATA0 */ 1138a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[67]); /* EMMC_DATA1 */ 1148a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[68]); /* EMMC_DATA2 */ 1158a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[69]); /* EMMC_DATA3 */ 1168a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[70]); /* EMMC_DATA4 */ 1178a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[71]); /* EMMC_DATA5 */ 1188a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[72]); /* EMMC_DATA6 */ 1198a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[73]); /* EMMC_DATA7 */ 1208a954eb6SPeter Griffin 1218a954eb6SPeter Griffin /*eMMC configure up/down/drive */ 1228a954eb6SPeter Griffin writel(DRIVE1_08MA, &pmx1->iocfg[65]); /* EMMC_CLK */ 1238a954eb6SPeter Griffin 1248a954eb6SPeter Griffin tmp = DRIVE1_04MA | PULL_UP; 1258a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[65]); /* EMMC_CMD */ 1268a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[66]); /* EMMC_DATA0 */ 1278a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[67]); /* EMMC_DATA1 */ 1288a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[68]); /* EMMC_DATA2 */ 1298a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[69]); /* EMMC_DATA3 */ 1308a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[70]); /* EMMC_DATA4 */ 1318a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[71]); /* EMMC_DATA5 */ 1328a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[72]); /* EMMC_DATA6 */ 1338a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[73]); /* EMMC_DATA7 */ 1348a954eb6SPeter Griffin 1358a954eb6SPeter Griffin writel(DRIVE1_04MA, &pmx1->iocfg[73]); /* EMMC_RST_N */ 1368a954eb6SPeter Griffin break; 1378a954eb6SPeter Griffin 1388a954eb6SPeter Griffin case PERIPH_ID_SDMMC1: 1398a954eb6SPeter Griffin 1408a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[3]); /* SD_CLK */ 1418a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[4]); /* SD_CMD */ 1428a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[5]); /* SD_DATA0 */ 1438a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[6]); /* SD_DATA1 */ 1448a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[7]); /* SD_DATA2 */ 1458a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[8]); /* SD_DATA3 */ 1468a954eb6SPeter Griffin 1478a954eb6SPeter Griffin writel(DRIVE1_10MA | BIT(2), &pmx1->iocfg[3]); /*SD_CLK*/ 1488a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[4]); /*SD_CMD*/ 1498a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[5]); /*SD_DATA0*/ 1508a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[6]); /*SD_DATA1*/ 1518a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[7]); /*SD_DATA2*/ 1528a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[8]); /*SD_DATA3*/ 1538a954eb6SPeter Griffin break; 1548a954eb6SPeter Griffin 1558a954eb6SPeter Griffin default: 1568a954eb6SPeter Griffin debug("%s: invalid peripheral %d", __func__, peripheral); 1578a954eb6SPeter Griffin return -1; 1588a954eb6SPeter Griffin } 1598a954eb6SPeter Griffin 1608a954eb6SPeter Griffin return 0; 1618a954eb6SPeter Griffin } 1628a954eb6SPeter Griffin 1638a954eb6SPeter Griffin int hi6220_pinmux_config(int peripheral) 1648a954eb6SPeter Griffin { 1658a954eb6SPeter Griffin switch (peripheral) { 1668a954eb6SPeter Griffin case PERIPH_ID_UART0: 1678a954eb6SPeter Griffin case PERIPH_ID_UART1: 1688a954eb6SPeter Griffin case PERIPH_ID_UART2: 1698a954eb6SPeter Griffin case PERIPH_ID_UART3: 1708a954eb6SPeter Griffin hi6220_uart_config(peripheral); 1718a954eb6SPeter Griffin break; 1728a954eb6SPeter Griffin case PERIPH_ID_SDMMC0: 1738a954eb6SPeter Griffin case PERIPH_ID_SDMMC1: 1748a954eb6SPeter Griffin return hi6220_mmc_config(peripheral); 1758a954eb6SPeter Griffin default: 1768a954eb6SPeter Griffin debug("%s: invalid peripheral %d", __func__, peripheral); 1778a954eb6SPeter Griffin return -1; 1788a954eb6SPeter Griffin } 1798a954eb6SPeter Griffin 1808a954eb6SPeter Griffin return 0; 1818a954eb6SPeter Griffin } 1828a954eb6SPeter Griffin 1838a954eb6SPeter Griffin 184