blob: 07d19fd17ba455e09a83ecc20ce108e8166ae485 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +00002/*
3 * Copyright (c) 2012 Samsung Electronics.
4 * Abhilash Kesavan <a.kesavan@samsung.com>
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +00005 */
6
Rajeshwari Shinde28bae822012-12-26 20:03:11 +00007#include <fdtdec.h>
Simon Glass0f2af882020-05-10 11:40:05 -06008#include <log.h>
Simon Glass37f11622014-10-20 19:48:37 -06009#include <asm/gpio.h>
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000010#include <asm/arch/pinmux.h>
11#include <asm/arch/sromc.h>
12
13static void exynos5_uart_config(int peripheral)
14{
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000015 int i, start, count;
16
17 switch (peripheral) {
18 case PERIPH_ID_UART0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053019 start = EXYNOS5_GPIO_A00;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000020 count = 4;
21 break;
22 case PERIPH_ID_UART1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053023 start = EXYNOS5_GPIO_D00;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000024 count = 4;
25 break;
26 case PERIPH_ID_UART2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053027 start = EXYNOS5_GPIO_A10;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000028 count = 4;
29 break;
30 case PERIPH_ID_UART3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053031 start = EXYNOS5_GPIO_A14;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000032 count = 2;
33 break;
Marek Vasute382be92014-03-10 20:04:31 +010034 default:
35 debug("%s: invalid peripheral %d", __func__, peripheral);
36 return;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000037 }
38 for (i = start; i < start + count; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053039 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
40 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000041 }
42}
43
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053044static void exynos5420_uart_config(int peripheral)
45{
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053046 int i, start, count;
47
48 switch (peripheral) {
49 case PERIPH_ID_UART0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053050 start = EXYNOS5420_GPIO_A00;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053051 count = 4;
52 break;
53 case PERIPH_ID_UART1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053054 start = EXYNOS5420_GPIO_A04;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053055 count = 4;
56 break;
57 case PERIPH_ID_UART2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053058 start = EXYNOS5420_GPIO_A10;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053059 count = 4;
60 break;
61 case PERIPH_ID_UART3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053062 start = EXYNOS5420_GPIO_A14;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053063 count = 2;
64 break;
Marek Vasute382be92014-03-10 20:04:31 +010065 default:
66 debug("%s: invalid peripheral %d", __func__, peripheral);
67 return;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053068 }
69
70 for (i = start; i < start + count; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053071 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
72 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053073 }
74}
75
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000076static int exynos5_mmc_config(int peripheral, int flags)
77{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053078 int i, start, start_ext, gpio_func = 0;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000079
80 switch (peripheral) {
81 case PERIPH_ID_SDMMC0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053082 start = EXYNOS5_GPIO_C00;
83 start_ext = EXYNOS5_GPIO_C10;
84 gpio_func = S5P_GPIO_FUNC(0x2);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000085 break;
86 case PERIPH_ID_SDMMC1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053087 start = EXYNOS5_GPIO_C20;
88 start_ext = 0;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000089 break;
90 case PERIPH_ID_SDMMC2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053091 start = EXYNOS5_GPIO_C30;
92 start_ext = EXYNOS5_GPIO_C43;
93 gpio_func = S5P_GPIO_FUNC(0x3);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000094 break;
95 case PERIPH_ID_SDMMC3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053096 start = EXYNOS5_GPIO_C40;
97 start_ext = 0;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000098 break;
Marek Vasute382be92014-03-10 20:04:31 +010099 default:
100 debug("%s: invalid peripheral %d", __func__, peripheral);
101 return -1;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000102 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530103 if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000104 debug("SDMMC device %d does not support 8bit mode",
105 peripheral);
106 return -1;
107 }
108 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530109 for (i = start_ext; i <= (start_ext + 3); i++) {
110 gpio_cfg_pin(i, gpio_func);
111 gpio_set_pull(i, S5P_GPIO_PULL_UP);
112 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000113 }
114 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530115 for (i = start; i < (start + 2); i++) {
116 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
117 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
118 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530119 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530120 for (i = (start + 3); i <= (start + 6); i++) {
121 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
122 gpio_set_pull(i, S5P_GPIO_PULL_UP);
123 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530124 }
125
126 return 0;
127}
128
129static int exynos5420_mmc_config(int peripheral, int flags)
130{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530131 int i, start = 0, start_ext = 0;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530132
133 switch (peripheral) {
134 case PERIPH_ID_SDMMC0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530135 start = EXYNOS5420_GPIO_C00;
136 start_ext = EXYNOS5420_GPIO_C30;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530137 break;
138 case PERIPH_ID_SDMMC1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530139 start = EXYNOS5420_GPIO_C10;
140 start_ext = EXYNOS5420_GPIO_D14;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530141 break;
142 case PERIPH_ID_SDMMC2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530143 start = EXYNOS5420_GPIO_C20;
144 start_ext = 0;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530145 break;
146 default:
147 start = 0;
148 debug("%s: invalid peripheral %d", __func__, peripheral);
149 return -1;
150 }
151
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530152 if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530153 debug("SDMMC device %d does not support 8bit mode",
154 peripheral);
155 return -1;
156 }
157
158 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530159 for (i = start_ext; i <= (start_ext + 3); i++) {
160 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
161 gpio_set_pull(i, S5P_GPIO_PULL_UP);
162 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530163 }
164 }
165
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530166 for (i = start; i < (start + 3); i++) {
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530167 /*
168 * MMC0 is intended to be used for eMMC. The
169 * card detect pin is used as a VDDEN signal to
170 * power on the eMMC. The 5420 iROM makes
171 * this same assumption.
172 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530173 if ((peripheral == PERIPH_ID_SDMMC0) && (i == (start + 2))) {
Simon Glass4f83d3d2014-10-20 19:48:39 -0600174#ifndef CONFIG_SPL_BUILD
175 gpio_request(i, "sdmmc0_vdden");
176#endif
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530177 gpio_set_value(i, 1);
178 gpio_cfg_pin(i, S5P_GPIO_OUTPUT);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530179 } else {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530180 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530181 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530182 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
183 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000184 }
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530185
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530186 for (i = (start + 3); i <= (start + 6); i++) {
187 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
188 gpio_set_pull(i, S5P_GPIO_PULL_UP);
189 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000190 }
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000191
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000192 return 0;
193}
194
195static void exynos5_sromc_config(int flags)
196{
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000197 int i;
198
199 /*
200 * SROM:CS1 and EBI
201 *
202 * GPY0[0] SROM_CSn[0]
203 * GPY0[1] SROM_CSn[1](2)
204 * GPY0[2] SROM_CSn[2]
205 * GPY0[3] SROM_CSn[3]
206 * GPY0[4] EBI_OEn(2)
207 * GPY0[5] EBI_EEn(2)
208 *
209 * GPY1[0] EBI_BEn[0](2)
210 * GPY1[1] EBI_BEn[1](2)
211 * GPY1[2] SROM_WAIT(2)
212 * GPY1[3] EBI_DATA_RDn(2)
213 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530214 gpio_cfg_pin(EXYNOS5_GPIO_Y00 + (flags & PINMUX_FLAG_BANK),
215 S5P_GPIO_FUNC(2));
216 gpio_cfg_pin(EXYNOS5_GPIO_Y04, S5P_GPIO_FUNC(2));
217 gpio_cfg_pin(EXYNOS5_GPIO_Y05, S5P_GPIO_FUNC(2));
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000218
219 for (i = 0; i < 4; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530220 gpio_cfg_pin(EXYNOS5_GPIO_Y10 + i, S5P_GPIO_FUNC(2));
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000221
222 /*
223 * EBI: 8 Addrss Lines
224 *
225 * GPY3[0] EBI_ADDR[0](2)
226 * GPY3[1] EBI_ADDR[1](2)
227 * GPY3[2] EBI_ADDR[2](2)
228 * GPY3[3] EBI_ADDR[3](2)
229 * GPY3[4] EBI_ADDR[4](2)
230 * GPY3[5] EBI_ADDR[5](2)
231 * GPY3[6] EBI_ADDR[6](2)
232 * GPY3[7] EBI_ADDR[7](2)
233 *
234 * EBI: 16 Data Lines
235 *
236 * GPY5[0] EBI_DATA[0](2)
237 * GPY5[1] EBI_DATA[1](2)
238 * GPY5[2] EBI_DATA[2](2)
239 * GPY5[3] EBI_DATA[3](2)
240 * GPY5[4] EBI_DATA[4](2)
241 * GPY5[5] EBI_DATA[5](2)
242 * GPY5[6] EBI_DATA[6](2)
243 * GPY5[7] EBI_DATA[7](2)
244 *
245 * GPY6[0] EBI_DATA[8](2)
246 * GPY6[1] EBI_DATA[9](2)
247 * GPY6[2] EBI_DATA[10](2)
248 * GPY6[3] EBI_DATA[11](2)
249 * GPY6[4] EBI_DATA[12](2)
250 * GPY6[5] EBI_DATA[13](2)
251 * GPY6[6] EBI_DATA[14](2)
252 * GPY6[7] EBI_DATA[15](2)
253 */
254 for (i = 0; i < 8; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530255 gpio_cfg_pin(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_FUNC(2));
256 gpio_set_pull(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_PULL_UP);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000257
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530258 gpio_cfg_pin(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_FUNC(2));
259 gpio_set_pull(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_PULL_UP);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000260
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530261 gpio_cfg_pin(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_FUNC(2));
262 gpio_set_pull(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_PULL_UP);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000263 }
264}
265
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000266static void exynos5_i2c_config(int peripheral, int flags)
267{
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100268 int func01, func23;
269
270 /* High-Speed I2C */
271 if (flags & PINMUX_FLAG_HS_MODE) {
272 func01 = 4;
273 func23 = 4;
274 } else {
275 func01 = 2;
276 func23 = 3;
277 }
278
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000279 switch (peripheral) {
280 case PERIPH_ID_I2C0:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100281 gpio_cfg_pin(EXYNOS5_GPIO_B30, S5P_GPIO_FUNC(func01));
282 gpio_cfg_pin(EXYNOS5_GPIO_B31, S5P_GPIO_FUNC(func01));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000283 break;
284 case PERIPH_ID_I2C1:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100285 gpio_cfg_pin(EXYNOS5_GPIO_B32, S5P_GPIO_FUNC(func01));
286 gpio_cfg_pin(EXYNOS5_GPIO_B33, S5P_GPIO_FUNC(func01));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000287 break;
288 case PERIPH_ID_I2C2:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100289 gpio_cfg_pin(EXYNOS5_GPIO_A06, S5P_GPIO_FUNC(func23));
290 gpio_cfg_pin(EXYNOS5_GPIO_A07, S5P_GPIO_FUNC(func23));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000291 break;
292 case PERIPH_ID_I2C3:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100293 gpio_cfg_pin(EXYNOS5_GPIO_A12, S5P_GPIO_FUNC(func23));
294 gpio_cfg_pin(EXYNOS5_GPIO_A13, S5P_GPIO_FUNC(func23));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000295 break;
296 case PERIPH_ID_I2C4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530297 gpio_cfg_pin(EXYNOS5_GPIO_A20, S5P_GPIO_FUNC(0x3));
298 gpio_cfg_pin(EXYNOS5_GPIO_A21, S5P_GPIO_FUNC(0x3));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000299 break;
300 case PERIPH_ID_I2C5:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530301 gpio_cfg_pin(EXYNOS5_GPIO_A22, S5P_GPIO_FUNC(0x3));
302 gpio_cfg_pin(EXYNOS5_GPIO_A23, S5P_GPIO_FUNC(0x3));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000303 break;
304 case PERIPH_ID_I2C6:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530305 gpio_cfg_pin(EXYNOS5_GPIO_B13, S5P_GPIO_FUNC(0x4));
306 gpio_cfg_pin(EXYNOS5_GPIO_B14, S5P_GPIO_FUNC(0x4));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000307 break;
308 case PERIPH_ID_I2C7:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530309 gpio_cfg_pin(EXYNOS5_GPIO_B22, S5P_GPIO_FUNC(0x3));
310 gpio_cfg_pin(EXYNOS5_GPIO_B23, S5P_GPIO_FUNC(0x3));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000311 break;
312 }
313}
314
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530315static void exynos5420_i2c_config(int peripheral)
316{
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530317 switch (peripheral) {
318 case PERIPH_ID_I2C0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530319 gpio_cfg_pin(EXYNOS5420_GPIO_B30, S5P_GPIO_FUNC(0x2));
320 gpio_cfg_pin(EXYNOS5420_GPIO_B31, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530321 break;
322 case PERIPH_ID_I2C1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530323 gpio_cfg_pin(EXYNOS5420_GPIO_B32, S5P_GPIO_FUNC(0x2));
324 gpio_cfg_pin(EXYNOS5420_GPIO_B33, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530325 break;
326 case PERIPH_ID_I2C2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530327 gpio_cfg_pin(EXYNOS5420_GPIO_A06, S5P_GPIO_FUNC(0x3));
328 gpio_cfg_pin(EXYNOS5420_GPIO_A07, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530329 break;
330 case PERIPH_ID_I2C3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530331 gpio_cfg_pin(EXYNOS5420_GPIO_A12, S5P_GPIO_FUNC(0x3));
332 gpio_cfg_pin(EXYNOS5420_GPIO_A13, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530333 break;
334 case PERIPH_ID_I2C4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530335 gpio_cfg_pin(EXYNOS5420_GPIO_A20, S5P_GPIO_FUNC(0x3));
336 gpio_cfg_pin(EXYNOS5420_GPIO_A21, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530337 break;
338 case PERIPH_ID_I2C5:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530339 gpio_cfg_pin(EXYNOS5420_GPIO_A22, S5P_GPIO_FUNC(0x3));
340 gpio_cfg_pin(EXYNOS5420_GPIO_A23, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530341 break;
342 case PERIPH_ID_I2C6:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530343 gpio_cfg_pin(EXYNOS5420_GPIO_B13, S5P_GPIO_FUNC(0x4));
344 gpio_cfg_pin(EXYNOS5420_GPIO_B14, S5P_GPIO_FUNC(0x4));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530345 break;
346 case PERIPH_ID_I2C7:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530347 gpio_cfg_pin(EXYNOS5420_GPIO_B22, S5P_GPIO_FUNC(0x3));
348 gpio_cfg_pin(EXYNOS5420_GPIO_B23, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530349 break;
350 case PERIPH_ID_I2C8:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530351 gpio_cfg_pin(EXYNOS5420_GPIO_B34, S5P_GPIO_FUNC(0x2));
352 gpio_cfg_pin(EXYNOS5420_GPIO_B35, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530353 break;
354 case PERIPH_ID_I2C9:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530355 gpio_cfg_pin(EXYNOS5420_GPIO_B36, S5P_GPIO_FUNC(0x2));
356 gpio_cfg_pin(EXYNOS5420_GPIO_B37, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530357 break;
358 case PERIPH_ID_I2C10:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530359 gpio_cfg_pin(EXYNOS5420_GPIO_B40, S5P_GPIO_FUNC(0x2));
360 gpio_cfg_pin(EXYNOS5420_GPIO_B41, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530361 break;
362 }
363}
364
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000365static void exynos5_i2s_config(int peripheral)
366{
367 int i;
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000368
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530369 switch (peripheral) {
370 case PERIPH_ID_I2S0:
371 for (i = 0; i < 5; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530372 gpio_cfg_pin(EXYNOS5_GPIO_Z0 + i, S5P_GPIO_FUNC(0x02));
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530373 break;
374 case PERIPH_ID_I2S1:
375 for (i = 0; i < 5; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530376 gpio_cfg_pin(EXYNOS5_GPIO_B00 + i, S5P_GPIO_FUNC(0x02));
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530377 break;
378 }
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000379}
380
Simon Glass12d70f42018-12-10 10:37:41 -0700381static void exynos5420_i2s_config(int peripheral)
382{
383 int i;
384
385 switch (peripheral) {
386 case PERIPH_ID_I2S0:
387 for (i = 0; i < 5; i++)
388 gpio_cfg_pin(EXYNOS5420_GPIO_Z0 + i,
389 S5P_GPIO_FUNC(0x02));
390 break;
391 }
392}
393
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000394void exynos5_spi_config(int peripheral)
395{
396 int cfg = 0, pin = 0, i;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000397
398 switch (peripheral) {
399 case PERIPH_ID_SPI0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530400 cfg = S5P_GPIO_FUNC(0x2);
401 pin = EXYNOS5_GPIO_A20;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000402 break;
403 case PERIPH_ID_SPI1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530404 cfg = S5P_GPIO_FUNC(0x2);
405 pin = EXYNOS5_GPIO_A24;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000406 break;
407 case PERIPH_ID_SPI2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530408 cfg = S5P_GPIO_FUNC(0x5);
409 pin = EXYNOS5_GPIO_B11;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000410 break;
411 case PERIPH_ID_SPI3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530412 cfg = S5P_GPIO_FUNC(0x2);
413 pin = EXYNOS5_GPIO_F10;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000414 break;
415 case PERIPH_ID_SPI4:
416 for (i = 0; i < 2; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530417 gpio_cfg_pin(EXYNOS5_GPIO_F02 + i, S5P_GPIO_FUNC(0x4));
418 gpio_cfg_pin(EXYNOS5_GPIO_E04 + i, S5P_GPIO_FUNC(0x4));
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000419 }
420 break;
421 }
422 if (peripheral != PERIPH_ID_SPI4) {
423 for (i = pin; i < pin + 4; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530424 gpio_cfg_pin(i, cfg);
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000425 }
426}
427
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530428void exynos5420_spi_config(int peripheral)
429{
430 int cfg, pin, i;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530431
432 switch (peripheral) {
433 case PERIPH_ID_SPI0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530434 pin = EXYNOS5420_GPIO_A20;
435 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530436 break;
437 case PERIPH_ID_SPI1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530438 pin = EXYNOS5420_GPIO_A24;
439 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530440 break;
441 case PERIPH_ID_SPI2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530442 pin = EXYNOS5420_GPIO_B11;
443 cfg = S5P_GPIO_FUNC(0x5);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530444 break;
445 case PERIPH_ID_SPI3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530446 pin = EXYNOS5420_GPIO_F10;
447 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530448 break;
449 case PERIPH_ID_SPI4:
450 cfg = 0;
451 pin = 0;
452 break;
453 default:
454 cfg = 0;
455 pin = 0;
456 debug("%s: invalid peripheral %d", __func__, peripheral);
457 return;
458 }
459
460 if (peripheral != PERIPH_ID_SPI4) {
461 for (i = pin; i < pin + 4; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530462 gpio_cfg_pin(i, cfg);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530463 } else {
464 for (i = 0; i < 2; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530465 gpio_cfg_pin(EXYNOS5420_GPIO_F02 + i,
466 S5P_GPIO_FUNC(0x4));
467 gpio_cfg_pin(EXYNOS5420_GPIO_E04 + i,
468 S5P_GPIO_FUNC(0x4));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530469 }
470 }
471}
472
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000473static int exynos5_pinmux_config(int peripheral, int flags)
474{
475 switch (peripheral) {
476 case PERIPH_ID_UART0:
477 case PERIPH_ID_UART1:
478 case PERIPH_ID_UART2:
479 case PERIPH_ID_UART3:
480 exynos5_uart_config(peripheral);
481 break;
482 case PERIPH_ID_SDMMC0:
483 case PERIPH_ID_SDMMC1:
484 case PERIPH_ID_SDMMC2:
485 case PERIPH_ID_SDMMC3:
486 return exynos5_mmc_config(peripheral, flags);
487 case PERIPH_ID_SROMC:
488 exynos5_sromc_config(flags);
489 break;
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000490 case PERIPH_ID_I2C0:
491 case PERIPH_ID_I2C1:
492 case PERIPH_ID_I2C2:
493 case PERIPH_ID_I2C3:
494 case PERIPH_ID_I2C4:
495 case PERIPH_ID_I2C5:
496 case PERIPH_ID_I2C6:
497 case PERIPH_ID_I2C7:
498 exynos5_i2c_config(peripheral, flags);
499 break;
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530500 case PERIPH_ID_I2S0:
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000501 case PERIPH_ID_I2S1:
502 exynos5_i2s_config(peripheral);
503 break;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000504 case PERIPH_ID_SPI0:
505 case PERIPH_ID_SPI1:
506 case PERIPH_ID_SPI2:
507 case PERIPH_ID_SPI3:
508 case PERIPH_ID_SPI4:
509 exynos5_spi_config(peripheral);
510 break;
Simon Glass6f6af972015-07-02 18:16:13 -0600511 case PERIPH_ID_DPHPD:
512 /* Set Hotplug detect for DP */
513 gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
514
515 /*
516 * Hotplug detect should have an external pullup; disable the
517 * internal pulldown so they don't fight.
518 */
519 gpio_set_pull(EXYNOS5_GPIO_X07, S5P_GPIO_PULL_NONE);
520 break;
Simon Glass114f8362016-02-21 21:08:56 -0700521 case PERIPH_ID_PWM0:
522 gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_FUNC(2));
523 break;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000524 default:
525 debug("%s: invalid peripheral %d", __func__, peripheral);
526 return -1;
527 }
528
529 return 0;
530}
531
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530532static int exynos5420_pinmux_config(int peripheral, int flags)
533{
534 switch (peripheral) {
535 case PERIPH_ID_UART0:
536 case PERIPH_ID_UART1:
537 case PERIPH_ID_UART2:
538 case PERIPH_ID_UART3:
539 exynos5420_uart_config(peripheral);
540 break;
541 case PERIPH_ID_SDMMC0:
542 case PERIPH_ID_SDMMC1:
543 case PERIPH_ID_SDMMC2:
544 case PERIPH_ID_SDMMC3:
545 return exynos5420_mmc_config(peripheral, flags);
546 case PERIPH_ID_SPI0:
547 case PERIPH_ID_SPI1:
548 case PERIPH_ID_SPI2:
549 case PERIPH_ID_SPI3:
550 case PERIPH_ID_SPI4:
551 exynos5420_spi_config(peripheral);
552 break;
553 case PERIPH_ID_I2C0:
554 case PERIPH_ID_I2C1:
555 case PERIPH_ID_I2C2:
556 case PERIPH_ID_I2C3:
557 case PERIPH_ID_I2C4:
558 case PERIPH_ID_I2C5:
559 case PERIPH_ID_I2C6:
560 case PERIPH_ID_I2C7:
561 case PERIPH_ID_I2C8:
562 case PERIPH_ID_I2C9:
563 case PERIPH_ID_I2C10:
564 exynos5420_i2c_config(peripheral);
565 break;
Simon Glass12d70f42018-12-10 10:37:41 -0700566 case PERIPH_ID_I2S0:
567 exynos5420_i2s_config(peripheral);
568 break;
Simon Glass114f8362016-02-21 21:08:56 -0700569 case PERIPH_ID_PWM0:
570 gpio_cfg_pin(EXYNOS5420_GPIO_B20, S5P_GPIO_FUNC(2));
571 break;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530572 default:
573 debug("%s: invalid peripheral %d", __func__, peripheral);
574 return -1;
575 }
576
577 return 0;
578}
579
Piotr Wilczekedad2172012-11-20 02:19:04 +0000580static void exynos4_i2c_config(int peripheral, int flags)
Piotr Wilczek7318b292012-09-20 00:19:57 +0000581{
Piotr Wilczek7318b292012-09-20 00:19:57 +0000582 switch (peripheral) {
Piotr Wilczekedad2172012-11-20 02:19:04 +0000583 case PERIPH_ID_I2C0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530584 gpio_cfg_pin(EXYNOS4_GPIO_D10, S5P_GPIO_FUNC(0x2));
585 gpio_cfg_pin(EXYNOS4_GPIO_D11, S5P_GPIO_FUNC(0x2));
Piotr Wilczek7318b292012-09-20 00:19:57 +0000586 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000587 case PERIPH_ID_I2C1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530588 gpio_cfg_pin(EXYNOS4_GPIO_D12, S5P_GPIO_FUNC(0x2));
589 gpio_cfg_pin(EXYNOS4_GPIO_D13, S5P_GPIO_FUNC(0x2));
Piotr Wilczek7318b292012-09-20 00:19:57 +0000590 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000591 case PERIPH_ID_I2C2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530592 gpio_cfg_pin(EXYNOS4_GPIO_A06, S5P_GPIO_FUNC(0x3));
593 gpio_cfg_pin(EXYNOS4_GPIO_A07, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000594 break;
595 case PERIPH_ID_I2C3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530596 gpio_cfg_pin(EXYNOS4_GPIO_A12, S5P_GPIO_FUNC(0x3));
597 gpio_cfg_pin(EXYNOS4_GPIO_A13, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000598 break;
599 case PERIPH_ID_I2C4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530600 gpio_cfg_pin(EXYNOS4_GPIO_B2, S5P_GPIO_FUNC(0x3));
601 gpio_cfg_pin(EXYNOS4_GPIO_B3, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000602 break;
603 case PERIPH_ID_I2C5:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530604 gpio_cfg_pin(EXYNOS4_GPIO_B6, S5P_GPIO_FUNC(0x3));
605 gpio_cfg_pin(EXYNOS4_GPIO_B7, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000606 break;
607 case PERIPH_ID_I2C6:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530608 gpio_cfg_pin(EXYNOS4_GPIO_C13, S5P_GPIO_FUNC(0x4));
609 gpio_cfg_pin(EXYNOS4_GPIO_C14, S5P_GPIO_FUNC(0x4));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000610 break;
611 case PERIPH_ID_I2C7:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530612 gpio_cfg_pin(EXYNOS4_GPIO_D02, S5P_GPIO_FUNC(0x3));
613 gpio_cfg_pin(EXYNOS4_GPIO_D03, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000614 break;
Piotr Wilczek7318b292012-09-20 00:19:57 +0000615 }
Piotr Wilczek7318b292012-09-20 00:19:57 +0000616}
617
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000618static int exynos4_mmc_config(int peripheral, int flags)
619{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530620 int i, start = 0, start_ext = 0;
Beomho Seo06d1b162014-05-16 13:59:46 +0900621 unsigned int func, ext_func;
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000622
623 switch (peripheral) {
624 case PERIPH_ID_SDMMC0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530625 start = EXYNOS4_GPIO_K00;
626 start_ext = EXYNOS4_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900627 func = S5P_GPIO_FUNC(0x2);
628 ext_func = S5P_GPIO_FUNC(0x3);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000629 break;
630 case PERIPH_ID_SDMMC2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530631 start = EXYNOS4_GPIO_K20;
632 start_ext = EXYNOS4_GPIO_K33;
Beomho Seo06d1b162014-05-16 13:59:46 +0900633 func = S5P_GPIO_FUNC(0x2);
634 ext_func = S5P_GPIO_FUNC(0x3);
635 break;
636 case PERIPH_ID_SDMMC4:
637 start = EXYNOS4_GPIO_K00;
638 start_ext = EXYNOS4_GPIO_K13;
639 func = S5P_GPIO_FUNC(0x3);
640 ext_func = S5P_GPIO_FUNC(0x4);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000641 break;
642 default:
643 return -1;
644 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530645 for (i = start; i < (start + 7); i++) {
646 if (i == (start + 2))
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000647 continue;
Beomho Seo06d1b162014-05-16 13:59:46 +0900648 gpio_cfg_pin(i, func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530649 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
650 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000651 }
Beomho Seo06d1b162014-05-16 13:59:46 +0900652 /* SDMMC2 do not use 8bit mode at exynos4 */
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000653 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530654 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo06d1b162014-05-16 13:59:46 +0900655 gpio_cfg_pin(i, ext_func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530656 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
657 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000658 }
659 }
660
661 return 0;
662}
663
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530664static void exynos4_uart_config(int peripheral)
665{
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530666 int i, start, count;
667
668 switch (peripheral) {
669 case PERIPH_ID_UART0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530670 start = EXYNOS4_GPIO_A00;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530671 count = 4;
672 break;
673 case PERIPH_ID_UART1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530674 start = EXYNOS4_GPIO_A04;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530675 count = 4;
676 break;
677 case PERIPH_ID_UART2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530678 start = EXYNOS4_GPIO_A10;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530679 count = 4;
680 break;
681 case PERIPH_ID_UART3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530682 start = EXYNOS4_GPIO_A14;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530683 count = 2;
684 break;
Marek Vasute382be92014-03-10 20:04:31 +0100685 default:
686 debug("%s: invalid peripheral %d", __func__, peripheral);
687 return;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530688 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530689 for (i = start; i < (start + count); i++) {
690 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
691 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
692 }
693}
694
695static void exynos4x12_i2c_config(int peripheral, int flags)
696{
697 switch (peripheral) {
698 case PERIPH_ID_I2C0:
699 gpio_cfg_pin(EXYNOS4X12_GPIO_D10, S5P_GPIO_FUNC(0x2));
700 gpio_cfg_pin(EXYNOS4X12_GPIO_D11, S5P_GPIO_FUNC(0x2));
701 break;
702 case PERIPH_ID_I2C1:
703 gpio_cfg_pin(EXYNOS4X12_GPIO_D12, S5P_GPIO_FUNC(0x2));
704 gpio_cfg_pin(EXYNOS4X12_GPIO_D13, S5P_GPIO_FUNC(0x2));
705 break;
706 case PERIPH_ID_I2C2:
707 gpio_cfg_pin(EXYNOS4X12_GPIO_A06, S5P_GPIO_FUNC(0x3));
708 gpio_cfg_pin(EXYNOS4X12_GPIO_A07, S5P_GPIO_FUNC(0x3));
709 break;
710 case PERIPH_ID_I2C3:
711 gpio_cfg_pin(EXYNOS4X12_GPIO_A12, S5P_GPIO_FUNC(0x3));
712 gpio_cfg_pin(EXYNOS4X12_GPIO_A13, S5P_GPIO_FUNC(0x3));
713 break;
714 case PERIPH_ID_I2C4:
715 gpio_cfg_pin(EXYNOS4X12_GPIO_B2, S5P_GPIO_FUNC(0x3));
716 gpio_cfg_pin(EXYNOS4X12_GPIO_B3, S5P_GPIO_FUNC(0x3));
717 break;
718 case PERIPH_ID_I2C5:
719 gpio_cfg_pin(EXYNOS4X12_GPIO_B6, S5P_GPIO_FUNC(0x3));
720 gpio_cfg_pin(EXYNOS4X12_GPIO_B7, S5P_GPIO_FUNC(0x3));
721 break;
722 case PERIPH_ID_I2C6:
723 gpio_cfg_pin(EXYNOS4X12_GPIO_C13, S5P_GPIO_FUNC(0x4));
724 gpio_cfg_pin(EXYNOS4X12_GPIO_C14, S5P_GPIO_FUNC(0x4));
725 break;
726 case PERIPH_ID_I2C7:
727 gpio_cfg_pin(EXYNOS4X12_GPIO_D02, S5P_GPIO_FUNC(0x3));
728 gpio_cfg_pin(EXYNOS4X12_GPIO_D03, S5P_GPIO_FUNC(0x3));
729 break;
730 }
731}
732
733static int exynos4x12_mmc_config(int peripheral, int flags)
734{
735 int i, start = 0, start_ext = 0;
Beomho Seo06d1b162014-05-16 13:59:46 +0900736 unsigned int func, ext_func;
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530737
738 switch (peripheral) {
739 case PERIPH_ID_SDMMC0:
740 start = EXYNOS4X12_GPIO_K00;
741 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900742 func = S5P_GPIO_FUNC(0x2);
743 ext_func = S5P_GPIO_FUNC(0x3);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530744 break;
745 case PERIPH_ID_SDMMC2:
746 start = EXYNOS4X12_GPIO_K20;
747 start_ext = EXYNOS4X12_GPIO_K33;
Beomho Seo06d1b162014-05-16 13:59:46 +0900748 func = S5P_GPIO_FUNC(0x2);
749 ext_func = S5P_GPIO_FUNC(0x3);
750 break;
751 case PERIPH_ID_SDMMC4:
Przemyslaw Marczak64c7da52014-09-01 13:50:43 +0200752 start = EXYNOS4X12_GPIO_K00;
753 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900754 func = S5P_GPIO_FUNC(0x3);
755 ext_func = S5P_GPIO_FUNC(0x4);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530756 break;
757 default:
758 return -1;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530759 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530760 for (i = start; i < (start + 7); i++) {
Przemyslaw Marczak91fd7472015-10-28 15:41:49 +0100761 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530762 if (i == (start + 2))
763 continue;
Beomho Seo06d1b162014-05-16 13:59:46 +0900764 gpio_cfg_pin(i, func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530765 gpio_set_drv(i, S5P_GPIO_DRV_4X);
766 }
767 if (flags & PINMUX_FLAG_8BIT_MODE) {
768 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo06d1b162014-05-16 13:59:46 +0900769 gpio_cfg_pin(i, ext_func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530770 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
771 gpio_set_drv(i, S5P_GPIO_DRV_4X);
772 }
773 }
774
775 return 0;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530776}
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530777
778static void exynos4x12_uart_config(int peripheral)
779{
780 int i, start, count;
781
782 switch (peripheral) {
783 case PERIPH_ID_UART0:
784 start = EXYNOS4X12_GPIO_A00;
785 count = 4;
786 break;
787 case PERIPH_ID_UART1:
788 start = EXYNOS4X12_GPIO_A04;
789 count = 4;
790 break;
791 case PERIPH_ID_UART2:
792 start = EXYNOS4X12_GPIO_A10;
793 count = 4;
794 break;
795 case PERIPH_ID_UART3:
796 start = EXYNOS4X12_GPIO_A14;
797 count = 2;
798 break;
799 default:
800 debug("%s: invalid peripheral %d", __func__, peripheral);
801 return;
802 }
803 for (i = start; i < (start + count); i++) {
804 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
805 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
806 }
807}
808
Piotr Wilczek7318b292012-09-20 00:19:57 +0000809static int exynos4_pinmux_config(int peripheral, int flags)
810{
811 switch (peripheral) {
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530812 case PERIPH_ID_UART0:
813 case PERIPH_ID_UART1:
814 case PERIPH_ID_UART2:
815 case PERIPH_ID_UART3:
816 exynos4_uart_config(peripheral);
817 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000818 case PERIPH_ID_I2C0:
819 case PERIPH_ID_I2C1:
820 case PERIPH_ID_I2C2:
821 case PERIPH_ID_I2C3:
822 case PERIPH_ID_I2C4:
823 case PERIPH_ID_I2C5:
824 case PERIPH_ID_I2C6:
825 case PERIPH_ID_I2C7:
826 exynos4_i2c_config(peripheral, flags);
827 break;
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000828 case PERIPH_ID_SDMMC0:
829 case PERIPH_ID_SDMMC2:
Beomho Seo06d1b162014-05-16 13:59:46 +0900830 case PERIPH_ID_SDMMC4:
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000831 return exynos4_mmc_config(peripheral, flags);
832 case PERIPH_ID_SDMMC1:
833 case PERIPH_ID_SDMMC3:
Rajeshwari Shinde507f8922013-10-08 18:42:22 +0530834 debug("SDMMC device %d not implemented\n", peripheral);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000835 return -1;
Piotr Wilczek7318b292012-09-20 00:19:57 +0000836 default:
837 debug("%s: invalid peripheral %d", __func__, peripheral);
838 return -1;
839 }
840
841 return 0;
842}
843
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530844static int exynos4x12_pinmux_config(int peripheral, int flags)
845{
846 switch (peripheral) {
847 case PERIPH_ID_UART0:
848 case PERIPH_ID_UART1:
849 case PERIPH_ID_UART2:
850 case PERIPH_ID_UART3:
851 exynos4x12_uart_config(peripheral);
852 break;
853 case PERIPH_ID_I2C0:
854 case PERIPH_ID_I2C1:
855 case PERIPH_ID_I2C2:
856 case PERIPH_ID_I2C3:
857 case PERIPH_ID_I2C4:
858 case PERIPH_ID_I2C5:
859 case PERIPH_ID_I2C6:
860 case PERIPH_ID_I2C7:
861 exynos4x12_i2c_config(peripheral, flags);
862 break;
863 case PERIPH_ID_SDMMC0:
864 case PERIPH_ID_SDMMC2:
Beomho Seo06d1b162014-05-16 13:59:46 +0900865 case PERIPH_ID_SDMMC4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530866 return exynos4x12_mmc_config(peripheral, flags);
867 case PERIPH_ID_SDMMC1:
868 case PERIPH_ID_SDMMC3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530869 debug("SDMMC device %d not implemented\n", peripheral);
870 return -1;
871 default:
872 debug("%s: invalid peripheral %d", __func__, peripheral);
873 return -1;
874 }
875
876 return 0;
877}
878
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000879int exynos_pinmux_config(int peripheral, int flags)
880{
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530881 if (cpu_is_exynos5()) {
Simon Glass8d451b42018-12-10 10:37:40 -0700882 if (proid_is_exynos542x())
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530883 return exynos5420_pinmux_config(peripheral, flags);
884 else if (proid_is_exynos5250())
885 return exynos5_pinmux_config(peripheral, flags);
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530886 } else if (cpu_is_exynos4()) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530887 if (proid_is_exynos4412())
888 return exynos4x12_pinmux_config(peripheral, flags);
889 else
890 return exynos4_pinmux_config(peripheral, flags);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000891 }
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530892
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530893 debug("pinmux functionality not supported\n");
894
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530895 return -1;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000896}
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000897
Masahiro Yamada366b24f2015-08-12 07:31:55 +0900898#if CONFIG_IS_ENABLED(OF_CONTROL)
Piotr Wilczek246ec3a2014-03-07 14:59:38 +0100899static int exynos4_pinmux_decode_periph_id(const void *blob, int node)
900{
901 int err;
902 u32 cell[3];
903
904 err = fdtdec_get_int_array(blob, node, "interrupts", cell,
905 ARRAY_SIZE(cell));
906 if (err) {
907 debug(" invalid peripheral id\n");
908 return PERIPH_ID_NONE;
909 }
910
911 return cell[1];
912}
913
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000914static int exynos5_pinmux_decode_periph_id(const void *blob, int node)
915{
916 int err;
917 u32 cell[3];
918
919 err = fdtdec_get_int_array(blob, node, "interrupts", cell,
920 ARRAY_SIZE(cell));
921 if (err)
922 return PERIPH_ID_NONE;
923
Minkyu Kangdcc99172014-01-29 17:04:17 +0900924 return cell[1];
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000925}
926
927int pinmux_decode_periph_id(const void *blob, int node)
928{
929 if (cpu_is_exynos5())
930 return exynos5_pinmux_decode_periph_id(blob, node);
Piotr Wilczek246ec3a2014-03-07 14:59:38 +0100931 else if (cpu_is_exynos4())
932 return exynos4_pinmux_decode_periph_id(blob, node);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530933
934 return PERIPH_ID_NONE;
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000935}
936#endif