~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: e14057c0a47c372675967a7414513e9be1d63446 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2015 Linaro.
 * Peter Griffin <peter.griffin@linaro.org>
 */

#include <common.h>
#include <fdtdec.h>
#include <log.h>
#include <asm/gpio.h>
#include <asm/io.h>
#include <asm/arch/pinmux.h>
#include <linux/bitops.h>

struct hi6220_pinmux0_regs *pmx0 =
	(struct hi6220_pinmux0_regs *)HI6220_PINMUX0_BASE;

struct hi6220_pinmux1_regs *pmx1 =
	(struct hi6220_pinmux1_regs *)HI6220_PINMUX1_BASE;

static void hi6220_uart_config(int peripheral)
{
	switch (peripheral) {
	case PERIPH_ID_UART0:
		writel(MUX_M0, &pmx0->iomg[48]); /* UART0_RXD */
		writel(MUX_M0, &pmx0->iomg[49]); /* UART0_TXD */

		writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[49]); /* UART0_RXD */
		writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[50]); /* UART0_TXD */
		break;

	case PERIPH_ID_UART1:
		writel(MUX_M0, &pmx0->iomg[50]); /* UART1_CTS_N */
		writel(MUX_M0, &pmx0->iomg[51]); /* UART1_RTS_N */
		writel(MUX_M0, &pmx0->iomg[52]); /* UART1_RXD */
		writel(MUX_M0, &pmx0->iomg[53]); /* UART1_TXD */

		writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[51]); /*UART1_CTS_N*/
		writel(DRIVE1_02MA | PULL_UP, &pmx1->iocfg[53]); /* UART1_RXD */
		writel(DRIVE1_02MA, &pmx1->iocfg[52]); /* UART1_RTS_N */
		writel(DRIVE1_02MA, &pmx1->iocfg[54]); /* UART1_TXD */
		break;

	case PERIPH_ID_UART2:
		writel(MUX_M0, &pmx0->iomg[54]); /* UART2_CTS_N */
		writel(MUX_M0, &pmx0->iomg[55]); /* UART2_RTS_N */
		writel(MUX_M0, &pmx0->iomg[56]); /* UART2_RXD */
		writel(MUX_M0, &pmx0->iomg[57]); /* UART2_TXD */

		writel(DRIVE1_02MA, &pmx1->iocfg[55]); /* UART2_CTS_N */
		writel(DRIVE1_02MA, &pmx1->iocfg[56]); /* UART2_RTS_N */
		writel(DRIVE1_02MA, &pmx1->iocfg[57]); /* UART2_RXD */
		writel(DRIVE1_02MA, &pmx1->iocfg[58]); /* UART2_TXD */
		break;

	case PERIPH_ID_UART3:
		writel(MUX_M1, &pmx0->iomg[96]); /* UART3_CTS_N */
		writel(MUX_M1, &pmx0->iomg[97]); /* UART3_RTS_N */
		writel(MUX_M1, &pmx0->iomg[98]); /* UART3_RXD */
		writel(MUX_M1, &pmx0->iomg[99]); /* UART3_TXD */

		/* UART3_TXD */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[100]);
		/* UART3_RTS_N */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[101]);
		/* UART3_RXD */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[102]);
		/* UART3_TXD */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[103]);
		break;

	case PERIPH_ID_UART4:
		writel(MUX_M1, &pmx0->iomg[116]); /* UART4_CTS_N */
		writel(MUX_M1, &pmx0->iomg[117]); /* UART4_RTS_N */
		writel(MUX_M1, &pmx0->iomg[118]); /* UART4_RXD */
		writel(MUX_M1, &pmx0->iomg[119]); /* UART4_TXD */

		/* UART4_CTS_N */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[120]);
		/* UART4_RTS_N */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[121]);
		/* UART4_RXD */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[122]);
		/* UART4_TXD */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[123]);
		break;
	case PERIPH_ID_UART5:
		writel(MUX_M1, &pmx0->iomg[114]); /* UART5_RXD */
		writel(MUX_M1, &pmx0->iomg[115]); /* UART5_TXD */

		/* UART5_RXD */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[118]);
		/* UART5_TXD */
		writel(DRIVE1_02MA | PULL_DOWN, &pmx1->iocfg[119]);

		break;

	default:
		debug("%s: invalid peripheral %d", __func__, peripheral);
		return;
	}
}

static int hi6220_mmc_config(int peripheral)
{
	u32 tmp;

	switch (peripheral) {
	case PERIPH_ID_SDMMC0:

		/* eMMC pinmux config */
		writel(MUX_M0, &pmx0->iomg[64]); /* EMMC_CLK */
		writel(MUX_M0, &pmx0->iomg[65]); /* EMMC_CMD */
		writel(MUX_M0, &pmx0->iomg[66]); /* EMMC_DATA0 */
		writel(MUX_M0, &pmx0->iomg[67]); /* EMMC_DATA1 */
		writel(MUX_M0, &pmx0->iomg[68]); /* EMMC_DATA2 */
		writel(MUX_M0, &pmx0->iomg[69]); /* EMMC_DATA3 */
		writel(MUX_M0, &pmx0->iomg[70]); /* EMMC_DATA4 */
		writel(MUX_M0, &pmx0->iomg[71]); /* EMMC_DATA5 */
		writel(MUX_M0, &pmx0->iomg[72]); /* EMMC_DATA6 */
		writel(MUX_M0, &pmx0->iomg[73]); /* EMMC_DATA7 */

		/*eMMC configure up/down/drive */
		writel(DRIVE1_08MA, &pmx1->iocfg[65]); /* EMMC_CLK */

		tmp = DRIVE1_04MA | PULL_UP;
		writel(tmp, &pmx1->iocfg[65]); /* EMMC_CMD */
		writel(tmp, &pmx1->iocfg[66]); /* EMMC_DATA0 */
		writel(tmp, &pmx1->iocfg[67]); /* EMMC_DATA1 */
		writel(tmp, &pmx1->iocfg[68]); /* EMMC_DATA2 */
		writel(tmp, &pmx1->iocfg[69]); /* EMMC_DATA3 */
		writel(tmp, &pmx1->iocfg[70]); /* EMMC_DATA4 */
		writel(tmp, &pmx1->iocfg[71]); /* EMMC_DATA5 */
		writel(tmp, &pmx1->iocfg[72]); /* EMMC_DATA6 */
		writel(tmp, &pmx1->iocfg[73]); /* EMMC_DATA7 */

		writel(DRIVE1_04MA, &pmx1->iocfg[73]); /* EMMC_RST_N */
		break;

	case PERIPH_ID_SDMMC1:

		writel(MUX_M0, &pmx0->iomg[3]); /* SD_CLK */
		writel(MUX_M0, &pmx0->iomg[4]); /* SD_CMD */
		writel(MUX_M0, &pmx0->iomg[5]); /* SD_DATA0 */
		writel(MUX_M0, &pmx0->iomg[6]); /* SD_DATA1 */
		writel(MUX_M0, &pmx0->iomg[7]); /* SD_DATA2 */
		writel(MUX_M0, &pmx0->iomg[8]); /* SD_DATA3 */

		writel(DRIVE1_10MA | BIT(2), &pmx1->iocfg[3]); /*SD_CLK*/
		writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[4]); /*SD_CMD*/
		writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[5]); /*SD_DATA0*/
		writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[6]); /*SD_DATA1*/
		writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[7]); /*SD_DATA2*/
		writel(DRIVE1_08MA | BIT(2), &pmx1->iocfg[8]); /*SD_DATA3*/
		break;

	default:
		debug("%s: invalid peripheral %d", __func__, peripheral);
		return -1;
	}

	return 0;
}

int hi6220_pinmux_config(int peripheral)
{
	switch (peripheral) {
	case PERIPH_ID_UART0:
	case PERIPH_ID_UART1:
	case PERIPH_ID_UART2:
	case PERIPH_ID_UART3:
		hi6220_uart_config(peripheral);
		break;
	case PERIPH_ID_SDMMC0:
	case PERIPH_ID_SDMMC1:
		return hi6220_mmc_config(peripheral);
	default:
		debug("%s: invalid peripheral %d", __func__, peripheral);
		return -1;
	}

	return 0;
}