blob: f6743ca0f6ed4ab0c249656aa870fa6162fbce08 [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
7#include <common.h>
Rajeshwari Shinde28bae822012-12-26 20:03:11 +00008#include <fdtdec.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
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000381void exynos5_spi_config(int peripheral)
382{
383 int cfg = 0, pin = 0, i;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000384
385 switch (peripheral) {
386 case PERIPH_ID_SPI0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530387 cfg = S5P_GPIO_FUNC(0x2);
388 pin = EXYNOS5_GPIO_A20;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000389 break;
390 case PERIPH_ID_SPI1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530391 cfg = S5P_GPIO_FUNC(0x2);
392 pin = EXYNOS5_GPIO_A24;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000393 break;
394 case PERIPH_ID_SPI2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530395 cfg = S5P_GPIO_FUNC(0x5);
396 pin = EXYNOS5_GPIO_B11;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000397 break;
398 case PERIPH_ID_SPI3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530399 cfg = S5P_GPIO_FUNC(0x2);
400 pin = EXYNOS5_GPIO_F10;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000401 break;
402 case PERIPH_ID_SPI4:
403 for (i = 0; i < 2; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530404 gpio_cfg_pin(EXYNOS5_GPIO_F02 + i, S5P_GPIO_FUNC(0x4));
405 gpio_cfg_pin(EXYNOS5_GPIO_E04 + i, S5P_GPIO_FUNC(0x4));
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000406 }
407 break;
408 }
409 if (peripheral != PERIPH_ID_SPI4) {
410 for (i = pin; i < pin + 4; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530411 gpio_cfg_pin(i, cfg);
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000412 }
413}
414
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530415void exynos5420_spi_config(int peripheral)
416{
417 int cfg, pin, i;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530418
419 switch (peripheral) {
420 case PERIPH_ID_SPI0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530421 pin = EXYNOS5420_GPIO_A20;
422 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530423 break;
424 case PERIPH_ID_SPI1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530425 pin = EXYNOS5420_GPIO_A24;
426 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530427 break;
428 case PERIPH_ID_SPI2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530429 pin = EXYNOS5420_GPIO_B11;
430 cfg = S5P_GPIO_FUNC(0x5);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530431 break;
432 case PERIPH_ID_SPI3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530433 pin = EXYNOS5420_GPIO_F10;
434 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530435 break;
436 case PERIPH_ID_SPI4:
437 cfg = 0;
438 pin = 0;
439 break;
440 default:
441 cfg = 0;
442 pin = 0;
443 debug("%s: invalid peripheral %d", __func__, peripheral);
444 return;
445 }
446
447 if (peripheral != PERIPH_ID_SPI4) {
448 for (i = pin; i < pin + 4; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530449 gpio_cfg_pin(i, cfg);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530450 } else {
451 for (i = 0; i < 2; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530452 gpio_cfg_pin(EXYNOS5420_GPIO_F02 + i,
453 S5P_GPIO_FUNC(0x4));
454 gpio_cfg_pin(EXYNOS5420_GPIO_E04 + i,
455 S5P_GPIO_FUNC(0x4));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530456 }
457 }
458}
459
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000460static int exynos5_pinmux_config(int peripheral, int flags)
461{
462 switch (peripheral) {
463 case PERIPH_ID_UART0:
464 case PERIPH_ID_UART1:
465 case PERIPH_ID_UART2:
466 case PERIPH_ID_UART3:
467 exynos5_uart_config(peripheral);
468 break;
469 case PERIPH_ID_SDMMC0:
470 case PERIPH_ID_SDMMC1:
471 case PERIPH_ID_SDMMC2:
472 case PERIPH_ID_SDMMC3:
473 return exynos5_mmc_config(peripheral, flags);
474 case PERIPH_ID_SROMC:
475 exynos5_sromc_config(flags);
476 break;
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000477 case PERIPH_ID_I2C0:
478 case PERIPH_ID_I2C1:
479 case PERIPH_ID_I2C2:
480 case PERIPH_ID_I2C3:
481 case PERIPH_ID_I2C4:
482 case PERIPH_ID_I2C5:
483 case PERIPH_ID_I2C6:
484 case PERIPH_ID_I2C7:
485 exynos5_i2c_config(peripheral, flags);
486 break;
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530487 case PERIPH_ID_I2S0:
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000488 case PERIPH_ID_I2S1:
489 exynos5_i2s_config(peripheral);
490 break;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000491 case PERIPH_ID_SPI0:
492 case PERIPH_ID_SPI1:
493 case PERIPH_ID_SPI2:
494 case PERIPH_ID_SPI3:
495 case PERIPH_ID_SPI4:
496 exynos5_spi_config(peripheral);
497 break;
Simon Glass6f6af972015-07-02 18:16:13 -0600498 case PERIPH_ID_DPHPD:
499 /* Set Hotplug detect for DP */
500 gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
501
502 /*
503 * Hotplug detect should have an external pullup; disable the
504 * internal pulldown so they don't fight.
505 */
506 gpio_set_pull(EXYNOS5_GPIO_X07, S5P_GPIO_PULL_NONE);
507 break;
Simon Glass114f8362016-02-21 21:08:56 -0700508 case PERIPH_ID_PWM0:
509 gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_FUNC(2));
510 break;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000511 default:
512 debug("%s: invalid peripheral %d", __func__, peripheral);
513 return -1;
514 }
515
516 return 0;
517}
518
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530519static int exynos5420_pinmux_config(int peripheral, int flags)
520{
521 switch (peripheral) {
522 case PERIPH_ID_UART0:
523 case PERIPH_ID_UART1:
524 case PERIPH_ID_UART2:
525 case PERIPH_ID_UART3:
526 exynos5420_uart_config(peripheral);
527 break;
528 case PERIPH_ID_SDMMC0:
529 case PERIPH_ID_SDMMC1:
530 case PERIPH_ID_SDMMC2:
531 case PERIPH_ID_SDMMC3:
532 return exynos5420_mmc_config(peripheral, flags);
533 case PERIPH_ID_SPI0:
534 case PERIPH_ID_SPI1:
535 case PERIPH_ID_SPI2:
536 case PERIPH_ID_SPI3:
537 case PERIPH_ID_SPI4:
538 exynos5420_spi_config(peripheral);
539 break;
540 case PERIPH_ID_I2C0:
541 case PERIPH_ID_I2C1:
542 case PERIPH_ID_I2C2:
543 case PERIPH_ID_I2C3:
544 case PERIPH_ID_I2C4:
545 case PERIPH_ID_I2C5:
546 case PERIPH_ID_I2C6:
547 case PERIPH_ID_I2C7:
548 case PERIPH_ID_I2C8:
549 case PERIPH_ID_I2C9:
550 case PERIPH_ID_I2C10:
551 exynos5420_i2c_config(peripheral);
552 break;
Simon Glass114f8362016-02-21 21:08:56 -0700553 case PERIPH_ID_PWM0:
554 gpio_cfg_pin(EXYNOS5420_GPIO_B20, S5P_GPIO_FUNC(2));
555 break;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530556 default:
557 debug("%s: invalid peripheral %d", __func__, peripheral);
558 return -1;
559 }
560
561 return 0;
562}
563
Piotr Wilczekedad2172012-11-20 02:19:04 +0000564static void exynos4_i2c_config(int peripheral, int flags)
Piotr Wilczek7318b292012-09-20 00:19:57 +0000565{
Piotr Wilczek7318b292012-09-20 00:19:57 +0000566 switch (peripheral) {
Piotr Wilczekedad2172012-11-20 02:19:04 +0000567 case PERIPH_ID_I2C0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530568 gpio_cfg_pin(EXYNOS4_GPIO_D10, S5P_GPIO_FUNC(0x2));
569 gpio_cfg_pin(EXYNOS4_GPIO_D11, S5P_GPIO_FUNC(0x2));
Piotr Wilczek7318b292012-09-20 00:19:57 +0000570 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000571 case PERIPH_ID_I2C1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530572 gpio_cfg_pin(EXYNOS4_GPIO_D12, S5P_GPIO_FUNC(0x2));
573 gpio_cfg_pin(EXYNOS4_GPIO_D13, S5P_GPIO_FUNC(0x2));
Piotr Wilczek7318b292012-09-20 00:19:57 +0000574 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000575 case PERIPH_ID_I2C2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530576 gpio_cfg_pin(EXYNOS4_GPIO_A06, S5P_GPIO_FUNC(0x3));
577 gpio_cfg_pin(EXYNOS4_GPIO_A07, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000578 break;
579 case PERIPH_ID_I2C3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530580 gpio_cfg_pin(EXYNOS4_GPIO_A12, S5P_GPIO_FUNC(0x3));
581 gpio_cfg_pin(EXYNOS4_GPIO_A13, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000582 break;
583 case PERIPH_ID_I2C4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530584 gpio_cfg_pin(EXYNOS4_GPIO_B2, S5P_GPIO_FUNC(0x3));
585 gpio_cfg_pin(EXYNOS4_GPIO_B3, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000586 break;
587 case PERIPH_ID_I2C5:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530588 gpio_cfg_pin(EXYNOS4_GPIO_B6, S5P_GPIO_FUNC(0x3));
589 gpio_cfg_pin(EXYNOS4_GPIO_B7, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000590 break;
591 case PERIPH_ID_I2C6:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530592 gpio_cfg_pin(EXYNOS4_GPIO_C13, S5P_GPIO_FUNC(0x4));
593 gpio_cfg_pin(EXYNOS4_GPIO_C14, S5P_GPIO_FUNC(0x4));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000594 break;
595 case PERIPH_ID_I2C7:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530596 gpio_cfg_pin(EXYNOS4_GPIO_D02, S5P_GPIO_FUNC(0x3));
597 gpio_cfg_pin(EXYNOS4_GPIO_D03, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000598 break;
Piotr Wilczek7318b292012-09-20 00:19:57 +0000599 }
Piotr Wilczek7318b292012-09-20 00:19:57 +0000600}
601
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000602static int exynos4_mmc_config(int peripheral, int flags)
603{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530604 int i, start = 0, start_ext = 0;
Beomho Seo06d1b162014-05-16 13:59:46 +0900605 unsigned int func, ext_func;
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000606
607 switch (peripheral) {
608 case PERIPH_ID_SDMMC0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530609 start = EXYNOS4_GPIO_K00;
610 start_ext = EXYNOS4_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900611 func = S5P_GPIO_FUNC(0x2);
612 ext_func = S5P_GPIO_FUNC(0x3);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000613 break;
614 case PERIPH_ID_SDMMC2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530615 start = EXYNOS4_GPIO_K20;
616 start_ext = EXYNOS4_GPIO_K33;
Beomho Seo06d1b162014-05-16 13:59:46 +0900617 func = S5P_GPIO_FUNC(0x2);
618 ext_func = S5P_GPIO_FUNC(0x3);
619 break;
620 case PERIPH_ID_SDMMC4:
621 start = EXYNOS4_GPIO_K00;
622 start_ext = EXYNOS4_GPIO_K13;
623 func = S5P_GPIO_FUNC(0x3);
624 ext_func = S5P_GPIO_FUNC(0x4);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000625 break;
626 default:
627 return -1;
628 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530629 for (i = start; i < (start + 7); i++) {
630 if (i == (start + 2))
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000631 continue;
Beomho Seo06d1b162014-05-16 13:59:46 +0900632 gpio_cfg_pin(i, func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530633 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
634 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000635 }
Beomho Seo06d1b162014-05-16 13:59:46 +0900636 /* SDMMC2 do not use 8bit mode at exynos4 */
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000637 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530638 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo06d1b162014-05-16 13:59:46 +0900639 gpio_cfg_pin(i, ext_func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530640 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
641 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000642 }
643 }
644
645 return 0;
646}
647
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530648static void exynos4_uart_config(int peripheral)
649{
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530650 int i, start, count;
651
652 switch (peripheral) {
653 case PERIPH_ID_UART0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530654 start = EXYNOS4_GPIO_A00;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530655 count = 4;
656 break;
657 case PERIPH_ID_UART1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530658 start = EXYNOS4_GPIO_A04;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530659 count = 4;
660 break;
661 case PERIPH_ID_UART2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530662 start = EXYNOS4_GPIO_A10;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530663 count = 4;
664 break;
665 case PERIPH_ID_UART3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530666 start = EXYNOS4_GPIO_A14;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530667 count = 2;
668 break;
Marek Vasute382be92014-03-10 20:04:31 +0100669 default:
670 debug("%s: invalid peripheral %d", __func__, peripheral);
671 return;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530672 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530673 for (i = start; i < (start + count); i++) {
674 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
675 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
676 }
677}
678
679static void exynos4x12_i2c_config(int peripheral, int flags)
680{
681 switch (peripheral) {
682 case PERIPH_ID_I2C0:
683 gpio_cfg_pin(EXYNOS4X12_GPIO_D10, S5P_GPIO_FUNC(0x2));
684 gpio_cfg_pin(EXYNOS4X12_GPIO_D11, S5P_GPIO_FUNC(0x2));
685 break;
686 case PERIPH_ID_I2C1:
687 gpio_cfg_pin(EXYNOS4X12_GPIO_D12, S5P_GPIO_FUNC(0x2));
688 gpio_cfg_pin(EXYNOS4X12_GPIO_D13, S5P_GPIO_FUNC(0x2));
689 break;
690 case PERIPH_ID_I2C2:
691 gpio_cfg_pin(EXYNOS4X12_GPIO_A06, S5P_GPIO_FUNC(0x3));
692 gpio_cfg_pin(EXYNOS4X12_GPIO_A07, S5P_GPIO_FUNC(0x3));
693 break;
694 case PERIPH_ID_I2C3:
695 gpio_cfg_pin(EXYNOS4X12_GPIO_A12, S5P_GPIO_FUNC(0x3));
696 gpio_cfg_pin(EXYNOS4X12_GPIO_A13, S5P_GPIO_FUNC(0x3));
697 break;
698 case PERIPH_ID_I2C4:
699 gpio_cfg_pin(EXYNOS4X12_GPIO_B2, S5P_GPIO_FUNC(0x3));
700 gpio_cfg_pin(EXYNOS4X12_GPIO_B3, S5P_GPIO_FUNC(0x3));
701 break;
702 case PERIPH_ID_I2C5:
703 gpio_cfg_pin(EXYNOS4X12_GPIO_B6, S5P_GPIO_FUNC(0x3));
704 gpio_cfg_pin(EXYNOS4X12_GPIO_B7, S5P_GPIO_FUNC(0x3));
705 break;
706 case PERIPH_ID_I2C6:
707 gpio_cfg_pin(EXYNOS4X12_GPIO_C13, S5P_GPIO_FUNC(0x4));
708 gpio_cfg_pin(EXYNOS4X12_GPIO_C14, S5P_GPIO_FUNC(0x4));
709 break;
710 case PERIPH_ID_I2C7:
711 gpio_cfg_pin(EXYNOS4X12_GPIO_D02, S5P_GPIO_FUNC(0x3));
712 gpio_cfg_pin(EXYNOS4X12_GPIO_D03, S5P_GPIO_FUNC(0x3));
713 break;
714 }
715}
716
717static int exynos4x12_mmc_config(int peripheral, int flags)
718{
719 int i, start = 0, start_ext = 0;
Beomho Seo06d1b162014-05-16 13:59:46 +0900720 unsigned int func, ext_func;
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530721
722 switch (peripheral) {
723 case PERIPH_ID_SDMMC0:
724 start = EXYNOS4X12_GPIO_K00;
725 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900726 func = S5P_GPIO_FUNC(0x2);
727 ext_func = S5P_GPIO_FUNC(0x3);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530728 break;
729 case PERIPH_ID_SDMMC2:
730 start = EXYNOS4X12_GPIO_K20;
731 start_ext = EXYNOS4X12_GPIO_K33;
Beomho Seo06d1b162014-05-16 13:59:46 +0900732 func = S5P_GPIO_FUNC(0x2);
733 ext_func = S5P_GPIO_FUNC(0x3);
734 break;
735 case PERIPH_ID_SDMMC4:
Przemyslaw Marczak64c7da52014-09-01 13:50:43 +0200736 start = EXYNOS4X12_GPIO_K00;
737 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900738 func = S5P_GPIO_FUNC(0x3);
739 ext_func = S5P_GPIO_FUNC(0x4);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530740 break;
741 default:
742 return -1;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530743 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530744 for (i = start; i < (start + 7); i++) {
Przemyslaw Marczak91fd7472015-10-28 15:41:49 +0100745 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530746 if (i == (start + 2))
747 continue;
Beomho Seo06d1b162014-05-16 13:59:46 +0900748 gpio_cfg_pin(i, func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530749 gpio_set_drv(i, S5P_GPIO_DRV_4X);
750 }
751 if (flags & PINMUX_FLAG_8BIT_MODE) {
752 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo06d1b162014-05-16 13:59:46 +0900753 gpio_cfg_pin(i, ext_func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530754 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
755 gpio_set_drv(i, S5P_GPIO_DRV_4X);
756 }
757 }
758
759 return 0;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530760}
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530761
762static void exynos4x12_uart_config(int peripheral)
763{
764 int i, start, count;
765
766 switch (peripheral) {
767 case PERIPH_ID_UART0:
768 start = EXYNOS4X12_GPIO_A00;
769 count = 4;
770 break;
771 case PERIPH_ID_UART1:
772 start = EXYNOS4X12_GPIO_A04;
773 count = 4;
774 break;
775 case PERIPH_ID_UART2:
776 start = EXYNOS4X12_GPIO_A10;
777 count = 4;
778 break;
779 case PERIPH_ID_UART3:
780 start = EXYNOS4X12_GPIO_A14;
781 count = 2;
782 break;
783 default:
784 debug("%s: invalid peripheral %d", __func__, peripheral);
785 return;
786 }
787 for (i = start; i < (start + count); i++) {
788 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
789 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
790 }
791}
792
Piotr Wilczek7318b292012-09-20 00:19:57 +0000793static int exynos4_pinmux_config(int peripheral, int flags)
794{
795 switch (peripheral) {
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530796 case PERIPH_ID_UART0:
797 case PERIPH_ID_UART1:
798 case PERIPH_ID_UART2:
799 case PERIPH_ID_UART3:
800 exynos4_uart_config(peripheral);
801 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000802 case PERIPH_ID_I2C0:
803 case PERIPH_ID_I2C1:
804 case PERIPH_ID_I2C2:
805 case PERIPH_ID_I2C3:
806 case PERIPH_ID_I2C4:
807 case PERIPH_ID_I2C5:
808 case PERIPH_ID_I2C6:
809 case PERIPH_ID_I2C7:
810 exynos4_i2c_config(peripheral, flags);
811 break;
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000812 case PERIPH_ID_SDMMC0:
813 case PERIPH_ID_SDMMC2:
Beomho Seo06d1b162014-05-16 13:59:46 +0900814 case PERIPH_ID_SDMMC4:
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000815 return exynos4_mmc_config(peripheral, flags);
816 case PERIPH_ID_SDMMC1:
817 case PERIPH_ID_SDMMC3:
Rajeshwari Shinde507f8922013-10-08 18:42:22 +0530818 debug("SDMMC device %d not implemented\n", peripheral);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000819 return -1;
Piotr Wilczek7318b292012-09-20 00:19:57 +0000820 default:
821 debug("%s: invalid peripheral %d", __func__, peripheral);
822 return -1;
823 }
824
825 return 0;
826}
827
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530828static int exynos4x12_pinmux_config(int peripheral, int flags)
829{
830 switch (peripheral) {
831 case PERIPH_ID_UART0:
832 case PERIPH_ID_UART1:
833 case PERIPH_ID_UART2:
834 case PERIPH_ID_UART3:
835 exynos4x12_uart_config(peripheral);
836 break;
837 case PERIPH_ID_I2C0:
838 case PERIPH_ID_I2C1:
839 case PERIPH_ID_I2C2:
840 case PERIPH_ID_I2C3:
841 case PERIPH_ID_I2C4:
842 case PERIPH_ID_I2C5:
843 case PERIPH_ID_I2C6:
844 case PERIPH_ID_I2C7:
845 exynos4x12_i2c_config(peripheral, flags);
846 break;
847 case PERIPH_ID_SDMMC0:
848 case PERIPH_ID_SDMMC2:
Beomho Seo06d1b162014-05-16 13:59:46 +0900849 case PERIPH_ID_SDMMC4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530850 return exynos4x12_mmc_config(peripheral, flags);
851 case PERIPH_ID_SDMMC1:
852 case PERIPH_ID_SDMMC3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530853 debug("SDMMC device %d not implemented\n", peripheral);
854 return -1;
855 default:
856 debug("%s: invalid peripheral %d", __func__, peripheral);
857 return -1;
858 }
859
860 return 0;
861}
862
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000863int exynos_pinmux_config(int peripheral, int flags)
864{
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530865 if (cpu_is_exynos5()) {
Przemyslaw Marczakcefbfe42015-10-27 13:07:57 +0100866 if (proid_is_exynos5420() || proid_is_exynos5422())
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530867 return exynos5420_pinmux_config(peripheral, flags);
868 else if (proid_is_exynos5250())
869 return exynos5_pinmux_config(peripheral, flags);
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530870 } else if (cpu_is_exynos4()) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530871 if (proid_is_exynos4412())
872 return exynos4x12_pinmux_config(peripheral, flags);
873 else
874 return exynos4_pinmux_config(peripheral, flags);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000875 }
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530876
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530877 debug("pinmux functionality not supported\n");
878
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530879 return -1;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000880}
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000881
Masahiro Yamada366b24f2015-08-12 07:31:55 +0900882#if CONFIG_IS_ENABLED(OF_CONTROL)
Piotr Wilczek246ec3a2014-03-07 14:59:38 +0100883static int exynos4_pinmux_decode_periph_id(const void *blob, int node)
884{
885 int err;
886 u32 cell[3];
887
888 err = fdtdec_get_int_array(blob, node, "interrupts", cell,
889 ARRAY_SIZE(cell));
890 if (err) {
891 debug(" invalid peripheral id\n");
892 return PERIPH_ID_NONE;
893 }
894
895 return cell[1];
896}
897
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000898static int exynos5_pinmux_decode_periph_id(const void *blob, int node)
899{
900 int err;
901 u32 cell[3];
902
903 err = fdtdec_get_int_array(blob, node, "interrupts", cell,
904 ARRAY_SIZE(cell));
905 if (err)
906 return PERIPH_ID_NONE;
907
Minkyu Kangdcc99172014-01-29 17:04:17 +0900908 return cell[1];
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000909}
910
911int pinmux_decode_periph_id(const void *blob, int node)
912{
913 if (cpu_is_exynos5())
914 return exynos5_pinmux_decode_periph_id(blob, node);
Piotr Wilczek246ec3a2014-03-07 14:59:38 +0100915 else if (cpu_is_exynos4())
916 return exynos4_pinmux_decode_periph_id(blob, node);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530917
918 return PERIPH_ID_NONE;
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000919}
920#endif