1*8a954eb6SPeter Griffin /* 2*8a954eb6SPeter Griffin * Copyright (C) 2015 Linaro. 3*8a954eb6SPeter Griffin * Peter Griffin <peter.griffin@linaro.org> 4*8a954eb6SPeter Griffin * 5*8a954eb6SPeter Griffin * SPDX-License-Identifier: GPL-2.0+ 6*8a954eb6SPeter Griffin */ 7*8a954eb6SPeter Griffin 8*8a954eb6SPeter Griffin #include <common.h> 9*8a954eb6SPeter Griffin #include <fdtdec.h> 10*8a954eb6SPeter Griffin #include <asm/gpio.h> 11*8a954eb6SPeter Griffin #include <asm/io.h> 12*8a954eb6SPeter Griffin #include <asm/arch/pinmux.h> 13*8a954eb6SPeter Griffin 14*8a954eb6SPeter Griffin struct hi6220_pinmux0_regs *pmx0 = 15*8a954eb6SPeter Griffin (struct hi6220_pinmux0_regs *)HI6220_PINMUX0_BASE; 16*8a954eb6SPeter Griffin 17*8a954eb6SPeter Griffin struct hi6220_pinmux1_regs *pmx1 = 18*8a954eb6SPeter Griffin (struct hi6220_pinmux1_regs *)HI6220_PINMUX1_BASE; 19*8a954eb6SPeter Griffin 20*8a954eb6SPeter Griffin static void hi6220_uart_config(int peripheral) 21*8a954eb6SPeter Griffin { 22*8a954eb6SPeter Griffin switch (peripheral) { 23*8a954eb6SPeter Griffin case PERIPH_ID_UART0: 24*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[48]); /* UART0_RXD */ 25*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[49]); /* UART0_TXD */ 26*8a954eb6SPeter Griffin 27*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[49]); /* UART0_RXD */ 28*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[50]); /* UART0_TXD */ 29*8a954eb6SPeter Griffin break; 30*8a954eb6SPeter Griffin 31*8a954eb6SPeter Griffin case PERIPH_ID_UART1: 32*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[50]); /* UART1_CTS_N */ 33*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[51]); /* UART1_RTS_N */ 34*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[52]); /* UART1_RXD */ 35*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[53]); /* UART1_TXD */ 36*8a954eb6SPeter Griffin 37*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[51]); /*UART1_CTS_N*/ 38*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[53]); /* UART1_RXD */ 39*8a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[52]); /* UART1_RTS_N */ 40*8a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[54]); /* UART1_TXD */ 41*8a954eb6SPeter Griffin break; 42*8a954eb6SPeter Griffin 43*8a954eb6SPeter Griffin case PERIPH_ID_UART2: 44*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[54]); /* UART2_CTS_N */ 45*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[55]); /* UART2_RTS_N */ 46*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[56]); /* UART2_RXD */ 47*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[57]); /* UART2_TXD */ 48*8a954eb6SPeter Griffin 49*8a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[55]); /* UART2_CTS_N */ 50*8a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[56]); /* UART2_RTS_N */ 51*8a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[57]); /* UART2_RXD */ 52*8a954eb6SPeter Griffin writel(DRIVE1_02MA, &pmx1->iocfg[58]); /* UART2_TXD */ 53*8a954eb6SPeter Griffin break; 54*8a954eb6SPeter Griffin 55*8a954eb6SPeter Griffin case PERIPH_ID_UART3: 56*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[96]); /* UART3_CTS_N */ 57*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[97]); /* UART3_RTS_N */ 58*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[98]); /* UART3_RXD */ 59*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[99]); /* UART3_TXD */ 60*8a954eb6SPeter Griffin 61*8a954eb6SPeter Griffin /* UART3_TXD */ 62*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[100]); 63*8a954eb6SPeter Griffin /* UART3_RTS_N */ 64*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[101]); 65*8a954eb6SPeter Griffin /* UART3_RXD */ 66*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[102]); 67*8a954eb6SPeter Griffin /* UART3_TXD */ 68*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[103]); 69*8a954eb6SPeter Griffin break; 70*8a954eb6SPeter Griffin 71*8a954eb6SPeter Griffin case PERIPH_ID_UART4: 72*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[116]); /* UART4_CTS_N */ 73*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[117]); /* UART4_RTS_N */ 74*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[118]); /* UART4_RXD */ 75*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[119]); /* UART4_TXD */ 76*8a954eb6SPeter Griffin 77*8a954eb6SPeter Griffin /* UART4_CTS_N */ 78*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[120]); 79*8a954eb6SPeter Griffin /* UART4_RTS_N */ 80*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[121]); 81*8a954eb6SPeter Griffin /* UART4_RXD */ 82*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[122]); 83*8a954eb6SPeter Griffin /* UART4_TXD */ 84*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[123]); 85*8a954eb6SPeter Griffin break; 86*8a954eb6SPeter Griffin case PERIPH_ID_UART5: 87*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[114]); /* UART5_RXD */ 88*8a954eb6SPeter Griffin writel(MUX_M1, &pmx0->iomg[115]); /* UART5_TXD */ 89*8a954eb6SPeter Griffin 90*8a954eb6SPeter Griffin /* UART5_RXD */ 91*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[118]); 92*8a954eb6SPeter Griffin /* UART5_TXD */ 93*8a954eb6SPeter Griffin writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[119]); 94*8a954eb6SPeter Griffin 95*8a954eb6SPeter Griffin break; 96*8a954eb6SPeter Griffin 97*8a954eb6SPeter Griffin default: 98*8a954eb6SPeter Griffin debug("%s: invalid peripheral %d", __func__, peripheral); 99*8a954eb6SPeter Griffin return; 100*8a954eb6SPeter Griffin } 101*8a954eb6SPeter Griffin } 102*8a954eb6SPeter Griffin 103*8a954eb6SPeter Griffin static int hi6220_mmc_config(int peripheral) 104*8a954eb6SPeter Griffin { 105*8a954eb6SPeter Griffin u32 tmp; 106*8a954eb6SPeter Griffin 107*8a954eb6SPeter Griffin switch (peripheral) { 108*8a954eb6SPeter Griffin case PERIPH_ID_SDMMC0: 109*8a954eb6SPeter Griffin 110*8a954eb6SPeter Griffin /* eMMC pinmux config */ 111*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[64]); /* EMMC_CLK */ 112*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[65]); /* EMMC_CMD */ 113*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[66]); /* EMMC_DATA0 */ 114*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[67]); /* EMMC_DATA1 */ 115*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[68]); /* EMMC_DATA2 */ 116*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[69]); /* EMMC_DATA3 */ 117*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[70]); /* EMMC_DATA4 */ 118*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[71]); /* EMMC_DATA5 */ 119*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[72]); /* EMMC_DATA6 */ 120*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[73]); /* EMMC_DATA7 */ 121*8a954eb6SPeter Griffin 122*8a954eb6SPeter Griffin /*eMMC configure up/down/drive */ 123*8a954eb6SPeter Griffin writel(DRIVE1_08MA, &pmx1->iocfg[65]); /* EMMC_CLK */ 124*8a954eb6SPeter Griffin 125*8a954eb6SPeter Griffin tmp = DRIVE1_04MA | PULL_UP; 126*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[65]); /* EMMC_CMD */ 127*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[66]); /* EMMC_DATA0 */ 128*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[67]); /* EMMC_DATA1 */ 129*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[68]); /* EMMC_DATA2 */ 130*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[69]); /* EMMC_DATA3 */ 131*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[70]); /* EMMC_DATA4 */ 132*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[71]); /* EMMC_DATA5 */ 133*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[72]); /* EMMC_DATA6 */ 134*8a954eb6SPeter Griffin writel(tmp, &pmx1->iocfg[73]); /* EMMC_DATA7 */ 135*8a954eb6SPeter Griffin 136*8a954eb6SPeter Griffin writel(DRIVE1_04MA, &pmx1->iocfg[73]); /* EMMC_RST_N */ 137*8a954eb6SPeter Griffin break; 138*8a954eb6SPeter Griffin 139*8a954eb6SPeter Griffin case PERIPH_ID_SDMMC1: 140*8a954eb6SPeter Griffin 141*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[3]); /* SD_CLK */ 142*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[4]); /* SD_CMD */ 143*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[5]); /* SD_DATA0 */ 144*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[6]); /* SD_DATA1 */ 145*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[7]); /* SD_DATA2 */ 146*8a954eb6SPeter Griffin writel(MUX_M0, &pmx0->iomg[8]); /* SD_DATA3 */ 147*8a954eb6SPeter Griffin 148*8a954eb6SPeter Griffin writel(DRIVE1_10MA | BIT(2), &pmx1->iocfg[3]); /*SD_CLK*/ 149*8a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[4]); /*SD_CMD*/ 150*8a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[5]); /*SD_DATA0*/ 151*8a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[6]); /*SD_DATA1*/ 152*8a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[7]); /*SD_DATA2*/ 153*8a954eb6SPeter Griffin writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[8]); /*SD_DATA3*/ 154*8a954eb6SPeter Griffin break; 155*8a954eb6SPeter Griffin 156*8a954eb6SPeter Griffin default: 157*8a954eb6SPeter Griffin debug("%s: invalid peripheral %d", __func__, peripheral); 158*8a954eb6SPeter Griffin return -1; 159*8a954eb6SPeter Griffin } 160*8a954eb6SPeter Griffin 161*8a954eb6SPeter Griffin return 0; 162*8a954eb6SPeter Griffin } 163*8a954eb6SPeter Griffin 164*8a954eb6SPeter Griffin int hi6220_pinmux_config(int peripheral) 165*8a954eb6SPeter Griffin { 166*8a954eb6SPeter Griffin switch (peripheral) { 167*8a954eb6SPeter Griffin case PERIPH_ID_UART0: 168*8a954eb6SPeter Griffin case PERIPH_ID_UART1: 169*8a954eb6SPeter Griffin case PERIPH_ID_UART2: 170*8a954eb6SPeter Griffin case PERIPH_ID_UART3: 171*8a954eb6SPeter Griffin hi6220_uart_config(peripheral); 172*8a954eb6SPeter Griffin break; 173*8a954eb6SPeter Griffin case PERIPH_ID_SDMMC0: 174*8a954eb6SPeter Griffin case PERIPH_ID_SDMMC1: 175*8a954eb6SPeter Griffin return hi6220_mmc_config(peripheral); 176*8a954eb6SPeter Griffin default: 177*8a954eb6SPeter Griffin debug("%s: invalid peripheral %d", __func__, peripheral); 178*8a954eb6SPeter Griffin return -1; 179*8a954eb6SPeter Griffin } 180*8a954eb6SPeter Griffin 181*8a954eb6SPeter Griffin return 0; 182*8a954eb6SPeter Griffin } 183*8a954eb6SPeter Griffin 184*8a954eb6SPeter Griffin 185