]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/exynos/pinmux.c
Merge branch 'karo-tx-uboot' into kc-merge
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / exynos / pinmux.c
1 /*
2  * Copyright (c) 2012 Samsung Electronics.
3  * Abhilash Kesavan <a.kesavan@samsung.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <fdtdec.h>
10 #include <asm/gpio.h>
11 #include <asm/arch/pinmux.h>
12 #include <asm/arch/sromc.h>
13
14 static void exynos5_uart_config(int peripheral)
15 {
16         int i, start, count;
17
18         switch (peripheral) {
19         case PERIPH_ID_UART0:
20                 start = EXYNOS5_GPIO_A00;
21                 count = 4;
22                 break;
23         case PERIPH_ID_UART1:
24                 start = EXYNOS5_GPIO_D00;
25                 count = 4;
26                 break;
27         case PERIPH_ID_UART2:
28                 start = EXYNOS5_GPIO_A10;
29                 count = 4;
30                 break;
31         case PERIPH_ID_UART3:
32                 start = EXYNOS5_GPIO_A14;
33                 count = 2;
34                 break;
35         default:
36                 debug("%s: invalid peripheral %d", __func__, peripheral);
37                 return;
38         }
39         for (i = start; i < start + count; i++) {
40                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
41                 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
42         }
43 }
44
45 static void exynos5420_uart_config(int peripheral)
46 {
47         int i, start, count;
48
49         switch (peripheral) {
50         case PERIPH_ID_UART0:
51                 start = EXYNOS5420_GPIO_A00;
52                 count = 4;
53                 break;
54         case PERIPH_ID_UART1:
55                 start = EXYNOS5420_GPIO_A04;
56                 count = 4;
57                 break;
58         case PERIPH_ID_UART2:
59                 start = EXYNOS5420_GPIO_A10;
60                 count = 4;
61                 break;
62         case PERIPH_ID_UART3:
63                 start = EXYNOS5420_GPIO_A14;
64                 count = 2;
65                 break;
66         default:
67                 debug("%s: invalid peripheral %d", __func__, peripheral);
68                 return;
69         }
70
71         for (i = start; i < start + count; i++) {
72                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
73                 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
74         }
75 }
76
77 static int exynos5_mmc_config(int peripheral, int flags)
78 {
79         int i, start, start_ext, gpio_func = 0;
80
81         switch (peripheral) {
82         case PERIPH_ID_SDMMC0:
83                 start = EXYNOS5_GPIO_C00;
84                 start_ext = EXYNOS5_GPIO_C10;
85                 gpio_func = S5P_GPIO_FUNC(0x2);
86                 break;
87         case PERIPH_ID_SDMMC1:
88                 start = EXYNOS5_GPIO_C20;
89                 start_ext = 0;
90                 break;
91         case PERIPH_ID_SDMMC2:
92                 start = EXYNOS5_GPIO_C30;
93                 start_ext = EXYNOS5_GPIO_C43;
94                 gpio_func = S5P_GPIO_FUNC(0x3);
95                 break;
96         case PERIPH_ID_SDMMC3:
97                 start = EXYNOS5_GPIO_C40;
98                 start_ext = 0;
99                 break;
100         default:
101                 debug("%s: invalid peripheral %d", __func__, peripheral);
102                 return -1;
103         }
104         if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
105                 debug("SDMMC device %d does not support 8bit mode",
106                                 peripheral);
107                 return -1;
108         }
109         if (flags & PINMUX_FLAG_8BIT_MODE) {
110                 for (i = start_ext; i <= (start_ext + 3); i++) {
111                         gpio_cfg_pin(i, gpio_func);
112                         gpio_set_pull(i, S5P_GPIO_PULL_UP);
113                         gpio_set_drv(i, S5P_GPIO_DRV_4X);
114                 }
115         }
116         for (i = start; i < (start + 2); i++) {
117                 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
118                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
119                 gpio_set_drv(i, S5P_GPIO_DRV_4X);
120         }
121         for (i = (start + 3); i <= (start + 6); i++) {
122                 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
123                 gpio_set_pull(i, S5P_GPIO_PULL_UP);
124                 gpio_set_drv(i, S5P_GPIO_DRV_4X);
125         }
126
127         return 0;
128 }
129
130 static int exynos5420_mmc_config(int peripheral, int flags)
131 {
132         int i, start = 0, start_ext = 0;
133
134         switch (peripheral) {
135         case PERIPH_ID_SDMMC0:
136                 start = EXYNOS5420_GPIO_C00;
137                 start_ext = EXYNOS5420_GPIO_C30;
138                 break;
139         case PERIPH_ID_SDMMC1:
140                 start = EXYNOS5420_GPIO_C10;
141                 start_ext = EXYNOS5420_GPIO_D14;
142                 break;
143         case PERIPH_ID_SDMMC2:
144                 start = EXYNOS5420_GPIO_C20;
145                 start_ext = 0;
146                 break;
147         default:
148                 start = 0;
149                 debug("%s: invalid peripheral %d", __func__, peripheral);
150                 return -1;
151         }
152
153         if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
154                 debug("SDMMC device %d does not support 8bit mode",
155                       peripheral);
156                 return -1;
157         }
158
159         if (flags & PINMUX_FLAG_8BIT_MODE) {
160                 for (i = start_ext; i <= (start_ext + 3); i++) {
161                         gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
162                         gpio_set_pull(i, S5P_GPIO_PULL_UP);
163                         gpio_set_drv(i, S5P_GPIO_DRV_4X);
164                 }
165         }
166
167         for (i = start; i < (start + 3); i++) {
168                 /*
169                  * MMC0 is intended to be used for eMMC. The
170                  * card detect pin is used as a VDDEN signal to
171                  * power on the eMMC. The 5420 iROM makes
172                  * this same assumption.
173                  */
174                 if ((peripheral == PERIPH_ID_SDMMC0) && (i == (start + 2))) {
175 #ifndef CONFIG_SPL_BUILD
176                         gpio_request(i, "sdmmc0_vdden");
177 #endif
178                         gpio_set_value(i, 1);
179                         gpio_cfg_pin(i, S5P_GPIO_OUTPUT);
180                 } else {
181                         gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
182                 }
183                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
184                 gpio_set_drv(i, S5P_GPIO_DRV_4X);
185         }
186
187         for (i = (start + 3); i <= (start + 6); i++) {
188                 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
189                 gpio_set_pull(i, S5P_GPIO_PULL_UP);
190                 gpio_set_drv(i, S5P_GPIO_DRV_4X);
191         }
192
193         return 0;
194 }
195
196 static void exynos5_sromc_config(int flags)
197 {
198         int i;
199
200         /*
201          * SROM:CS1 and EBI
202          *
203          * GPY0[0]      SROM_CSn[0]
204          * GPY0[1]      SROM_CSn[1](2)
205          * GPY0[2]      SROM_CSn[2]
206          * GPY0[3]      SROM_CSn[3]
207          * GPY0[4]      EBI_OEn(2)
208          * GPY0[5]      EBI_EEn(2)
209          *
210          * GPY1[0]      EBI_BEn[0](2)
211          * GPY1[1]      EBI_BEn[1](2)
212          * GPY1[2]      SROM_WAIT(2)
213          * GPY1[3]      EBI_DATA_RDn(2)
214          */
215         gpio_cfg_pin(EXYNOS5_GPIO_Y00 + (flags & PINMUX_FLAG_BANK),
216                      S5P_GPIO_FUNC(2));
217         gpio_cfg_pin(EXYNOS5_GPIO_Y04, S5P_GPIO_FUNC(2));
218         gpio_cfg_pin(EXYNOS5_GPIO_Y05, S5P_GPIO_FUNC(2));
219
220         for (i = 0; i < 4; i++)
221                 gpio_cfg_pin(EXYNOS5_GPIO_Y10 + i, S5P_GPIO_FUNC(2));
222
223         /*
224          * EBI: 8 Addrss Lines
225          *
226          * GPY3[0]      EBI_ADDR[0](2)
227          * GPY3[1]      EBI_ADDR[1](2)
228          * GPY3[2]      EBI_ADDR[2](2)
229          * GPY3[3]      EBI_ADDR[3](2)
230          * GPY3[4]      EBI_ADDR[4](2)
231          * GPY3[5]      EBI_ADDR[5](2)
232          * GPY3[6]      EBI_ADDR[6](2)
233          * GPY3[7]      EBI_ADDR[7](2)
234          *
235          * EBI: 16 Data Lines
236          *
237          * GPY5[0]      EBI_DATA[0](2)
238          * GPY5[1]      EBI_DATA[1](2)
239          * GPY5[2]      EBI_DATA[2](2)
240          * GPY5[3]      EBI_DATA[3](2)
241          * GPY5[4]      EBI_DATA[4](2)
242          * GPY5[5]      EBI_DATA[5](2)
243          * GPY5[6]      EBI_DATA[6](2)
244          * GPY5[7]      EBI_DATA[7](2)
245          *
246          * GPY6[0]      EBI_DATA[8](2)
247          * GPY6[1]      EBI_DATA[9](2)
248          * GPY6[2]      EBI_DATA[10](2)
249          * GPY6[3]      EBI_DATA[11](2)
250          * GPY6[4]      EBI_DATA[12](2)
251          * GPY6[5]      EBI_DATA[13](2)
252          * GPY6[6]      EBI_DATA[14](2)
253          * GPY6[7]      EBI_DATA[15](2)
254          */
255         for (i = 0; i < 8; i++) {
256                 gpio_cfg_pin(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_FUNC(2));
257                 gpio_set_pull(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_PULL_UP);
258
259                 gpio_cfg_pin(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_FUNC(2));
260                 gpio_set_pull(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_PULL_UP);
261
262                 gpio_cfg_pin(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_FUNC(2));
263                 gpio_set_pull(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_PULL_UP);
264         }
265 }
266
267 static void exynos5_i2c_config(int peripheral, int flags)
268 {
269         int func01, func23;
270
271          /* High-Speed I2C */
272         if (flags & PINMUX_FLAG_HS_MODE) {
273                 func01 = 4;
274                 func23 = 4;
275         } else {
276                 func01 = 2;
277                 func23 = 3;
278         }
279
280         switch (peripheral) {
281         case PERIPH_ID_I2C0:
282                 gpio_cfg_pin(EXYNOS5_GPIO_B30, S5P_GPIO_FUNC(func01));
283                 gpio_cfg_pin(EXYNOS5_GPIO_B31, S5P_GPIO_FUNC(func01));
284                 break;
285         case PERIPH_ID_I2C1:
286                 gpio_cfg_pin(EXYNOS5_GPIO_B32, S5P_GPIO_FUNC(func01));
287                 gpio_cfg_pin(EXYNOS5_GPIO_B33, S5P_GPIO_FUNC(func01));
288                 break;
289         case PERIPH_ID_I2C2:
290                 gpio_cfg_pin(EXYNOS5_GPIO_A06, S5P_GPIO_FUNC(func23));
291                 gpio_cfg_pin(EXYNOS5_GPIO_A07, S5P_GPIO_FUNC(func23));
292                 break;
293         case PERIPH_ID_I2C3:
294                 gpio_cfg_pin(EXYNOS5_GPIO_A12, S5P_GPIO_FUNC(func23));
295                 gpio_cfg_pin(EXYNOS5_GPIO_A13, S5P_GPIO_FUNC(func23));
296                 break;
297         case PERIPH_ID_I2C4:
298                 gpio_cfg_pin(EXYNOS5_GPIO_A20, S5P_GPIO_FUNC(0x3));
299                 gpio_cfg_pin(EXYNOS5_GPIO_A21, S5P_GPIO_FUNC(0x3));
300                 break;
301         case PERIPH_ID_I2C5:
302                 gpio_cfg_pin(EXYNOS5_GPIO_A22, S5P_GPIO_FUNC(0x3));
303                 gpio_cfg_pin(EXYNOS5_GPIO_A23, S5P_GPIO_FUNC(0x3));
304                 break;
305         case PERIPH_ID_I2C6:
306                 gpio_cfg_pin(EXYNOS5_GPIO_B13, S5P_GPIO_FUNC(0x4));
307                 gpio_cfg_pin(EXYNOS5_GPIO_B14, S5P_GPIO_FUNC(0x4));
308                 break;
309         case PERIPH_ID_I2C7:
310                 gpio_cfg_pin(EXYNOS5_GPIO_B22, S5P_GPIO_FUNC(0x3));
311                 gpio_cfg_pin(EXYNOS5_GPIO_B23, S5P_GPIO_FUNC(0x3));
312                 break;
313         }
314 }
315
316 static void exynos5420_i2c_config(int peripheral)
317 {
318         switch (peripheral) {
319         case PERIPH_ID_I2C0:
320                 gpio_cfg_pin(EXYNOS5420_GPIO_B30, S5P_GPIO_FUNC(0x2));
321                 gpio_cfg_pin(EXYNOS5420_GPIO_B31, S5P_GPIO_FUNC(0x2));
322                 break;
323         case PERIPH_ID_I2C1:
324                 gpio_cfg_pin(EXYNOS5420_GPIO_B32, S5P_GPIO_FUNC(0x2));
325                 gpio_cfg_pin(EXYNOS5420_GPIO_B33, S5P_GPIO_FUNC(0x2));
326                 break;
327         case PERIPH_ID_I2C2:
328                 gpio_cfg_pin(EXYNOS5420_GPIO_A06, S5P_GPIO_FUNC(0x3));
329                 gpio_cfg_pin(EXYNOS5420_GPIO_A07, S5P_GPIO_FUNC(0x3));
330                 break;
331         case PERIPH_ID_I2C3:
332                 gpio_cfg_pin(EXYNOS5420_GPIO_A12, S5P_GPIO_FUNC(0x3));
333                 gpio_cfg_pin(EXYNOS5420_GPIO_A13, S5P_GPIO_FUNC(0x3));
334                 break;
335         case PERIPH_ID_I2C4:
336                 gpio_cfg_pin(EXYNOS5420_GPIO_A20, S5P_GPIO_FUNC(0x3));
337                 gpio_cfg_pin(EXYNOS5420_GPIO_A21, S5P_GPIO_FUNC(0x3));
338                 break;
339         case PERIPH_ID_I2C5:
340                 gpio_cfg_pin(EXYNOS5420_GPIO_A22, S5P_GPIO_FUNC(0x3));
341                 gpio_cfg_pin(EXYNOS5420_GPIO_A23, S5P_GPIO_FUNC(0x3));
342                 break;
343         case PERIPH_ID_I2C6:
344                 gpio_cfg_pin(EXYNOS5420_GPIO_B13, S5P_GPIO_FUNC(0x4));
345                 gpio_cfg_pin(EXYNOS5420_GPIO_B14, S5P_GPIO_FUNC(0x4));
346                 break;
347         case PERIPH_ID_I2C7:
348                 gpio_cfg_pin(EXYNOS5420_GPIO_B22, S5P_GPIO_FUNC(0x3));
349                 gpio_cfg_pin(EXYNOS5420_GPIO_B23, S5P_GPIO_FUNC(0x3));
350                 break;
351         case PERIPH_ID_I2C8:
352                 gpio_cfg_pin(EXYNOS5420_GPIO_B34, S5P_GPIO_FUNC(0x2));
353                 gpio_cfg_pin(EXYNOS5420_GPIO_B35, S5P_GPIO_FUNC(0x2));
354                 break;
355         case PERIPH_ID_I2C9:
356                 gpio_cfg_pin(EXYNOS5420_GPIO_B36, S5P_GPIO_FUNC(0x2));
357                 gpio_cfg_pin(EXYNOS5420_GPIO_B37, S5P_GPIO_FUNC(0x2));
358                 break;
359         case PERIPH_ID_I2C10:
360                 gpio_cfg_pin(EXYNOS5420_GPIO_B40, S5P_GPIO_FUNC(0x2));
361                 gpio_cfg_pin(EXYNOS5420_GPIO_B41, S5P_GPIO_FUNC(0x2));
362                 break;
363         }
364 }
365
366 static void exynos5_i2s_config(int peripheral)
367 {
368         int i;
369
370         switch (peripheral) {
371         case PERIPH_ID_I2S0:
372                 for (i = 0; i < 5; i++)
373                         gpio_cfg_pin(EXYNOS5_GPIO_Z0 + i, S5P_GPIO_FUNC(0x02));
374                 break;
375         case PERIPH_ID_I2S1:
376                 for (i = 0; i < 5; i++)
377                         gpio_cfg_pin(EXYNOS5_GPIO_B00 + i, S5P_GPIO_FUNC(0x02));
378                 break;
379         }
380 }
381
382 void exynos5_spi_config(int peripheral)
383 {
384         int cfg = 0, pin = 0, i;
385
386         switch (peripheral) {
387         case PERIPH_ID_SPI0:
388                 cfg = S5P_GPIO_FUNC(0x2);
389                 pin = EXYNOS5_GPIO_A20;
390                 break;
391         case PERIPH_ID_SPI1:
392                 cfg = S5P_GPIO_FUNC(0x2);
393                 pin = EXYNOS5_GPIO_A24;
394                 break;
395         case PERIPH_ID_SPI2:
396                 cfg = S5P_GPIO_FUNC(0x5);
397                 pin = EXYNOS5_GPIO_B11;
398                 break;
399         case PERIPH_ID_SPI3:
400                 cfg = S5P_GPIO_FUNC(0x2);
401                 pin = EXYNOS5_GPIO_F10;
402                 break;
403         case PERIPH_ID_SPI4:
404                 for (i = 0; i < 2; i++) {
405                         gpio_cfg_pin(EXYNOS5_GPIO_F02 + i, S5P_GPIO_FUNC(0x4));
406                         gpio_cfg_pin(EXYNOS5_GPIO_E04 + i, S5P_GPIO_FUNC(0x4));
407                 }
408                 break;
409         }
410         if (peripheral != PERIPH_ID_SPI4) {
411                 for (i = pin; i < pin + 4; i++)
412                         gpio_cfg_pin(i, cfg);
413         }
414 }
415
416 void exynos5420_spi_config(int peripheral)
417 {
418         int cfg, pin, i;
419
420         switch (peripheral) {
421         case PERIPH_ID_SPI0:
422                 pin = EXYNOS5420_GPIO_A20;
423                 cfg = S5P_GPIO_FUNC(0x2);
424                 break;
425         case PERIPH_ID_SPI1:
426                 pin = EXYNOS5420_GPIO_A24;
427                 cfg = S5P_GPIO_FUNC(0x2);
428                 break;
429         case PERIPH_ID_SPI2:
430                 pin = EXYNOS5420_GPIO_B11;
431                 cfg = S5P_GPIO_FUNC(0x5);
432                 break;
433         case PERIPH_ID_SPI3:
434                 pin = EXYNOS5420_GPIO_F10;
435                 cfg = S5P_GPIO_FUNC(0x2);
436                 break;
437         case PERIPH_ID_SPI4:
438                 cfg = 0;
439                 pin = 0;
440                 break;
441         default:
442                 cfg = 0;
443                 pin = 0;
444                 debug("%s: invalid peripheral %d", __func__, peripheral);
445                 return;
446         }
447
448         if (peripheral != PERIPH_ID_SPI4) {
449                 for (i = pin; i < pin + 4; i++)
450                         gpio_cfg_pin(i, cfg);
451         } else {
452                 for (i = 0; i < 2; i++) {
453                         gpio_cfg_pin(EXYNOS5420_GPIO_F02 + i,
454                                      S5P_GPIO_FUNC(0x4));
455                         gpio_cfg_pin(EXYNOS5420_GPIO_E04 + i,
456                                      S5P_GPIO_FUNC(0x4));
457                 }
458         }
459 }
460
461 static int exynos5_pinmux_config(int peripheral, int flags)
462 {
463         switch (peripheral) {
464         case PERIPH_ID_UART0:
465         case PERIPH_ID_UART1:
466         case PERIPH_ID_UART2:
467         case PERIPH_ID_UART3:
468                 exynos5_uart_config(peripheral);
469                 break;
470         case PERIPH_ID_SDMMC0:
471         case PERIPH_ID_SDMMC1:
472         case PERIPH_ID_SDMMC2:
473         case PERIPH_ID_SDMMC3:
474                 return exynos5_mmc_config(peripheral, flags);
475         case PERIPH_ID_SROMC:
476                 exynos5_sromc_config(flags);
477                 break;
478         case PERIPH_ID_I2C0:
479         case PERIPH_ID_I2C1:
480         case PERIPH_ID_I2C2:
481         case PERIPH_ID_I2C3:
482         case PERIPH_ID_I2C4:
483         case PERIPH_ID_I2C5:
484         case PERIPH_ID_I2C6:
485         case PERIPH_ID_I2C7:
486                 exynos5_i2c_config(peripheral, flags);
487                 break;
488         case PERIPH_ID_I2S0:
489         case PERIPH_ID_I2S1:
490                 exynos5_i2s_config(peripheral);
491                 break;
492         case PERIPH_ID_SPI0:
493         case PERIPH_ID_SPI1:
494         case PERIPH_ID_SPI2:
495         case PERIPH_ID_SPI3:
496         case PERIPH_ID_SPI4:
497                 exynos5_spi_config(peripheral);
498                 break;
499         default:
500                 debug("%s: invalid peripheral %d", __func__, peripheral);
501                 return -1;
502         }
503
504         return 0;
505 }
506
507 static int exynos5420_pinmux_config(int peripheral, int flags)
508 {
509         switch (peripheral) {
510         case PERIPH_ID_UART0:
511         case PERIPH_ID_UART1:
512         case PERIPH_ID_UART2:
513         case PERIPH_ID_UART3:
514                 exynos5420_uart_config(peripheral);
515                 break;
516         case PERIPH_ID_SDMMC0:
517         case PERIPH_ID_SDMMC1:
518         case PERIPH_ID_SDMMC2:
519         case PERIPH_ID_SDMMC3:
520                 return exynos5420_mmc_config(peripheral, flags);
521         case PERIPH_ID_SPI0:
522         case PERIPH_ID_SPI1:
523         case PERIPH_ID_SPI2:
524         case PERIPH_ID_SPI3:
525         case PERIPH_ID_SPI4:
526                 exynos5420_spi_config(peripheral);
527                 break;
528         case PERIPH_ID_I2C0:
529         case PERIPH_ID_I2C1:
530         case PERIPH_ID_I2C2:
531         case PERIPH_ID_I2C3:
532         case PERIPH_ID_I2C4:
533         case PERIPH_ID_I2C5:
534         case PERIPH_ID_I2C6:
535         case PERIPH_ID_I2C7:
536         case PERIPH_ID_I2C8:
537         case PERIPH_ID_I2C9:
538         case PERIPH_ID_I2C10:
539                 exynos5420_i2c_config(peripheral);
540                 break;
541         default:
542                 debug("%s: invalid peripheral %d", __func__, peripheral);
543                 return -1;
544         }
545
546         return 0;
547 }
548
549 static void exynos4_i2c_config(int peripheral, int flags)
550 {
551         switch (peripheral) {
552         case PERIPH_ID_I2C0:
553                 gpio_cfg_pin(EXYNOS4_GPIO_D10, S5P_GPIO_FUNC(0x2));
554                 gpio_cfg_pin(EXYNOS4_GPIO_D11, S5P_GPIO_FUNC(0x2));
555                 break;
556         case PERIPH_ID_I2C1:
557                 gpio_cfg_pin(EXYNOS4_GPIO_D12, S5P_GPIO_FUNC(0x2));
558                 gpio_cfg_pin(EXYNOS4_GPIO_D13, S5P_GPIO_FUNC(0x2));
559                 break;
560         case PERIPH_ID_I2C2:
561                 gpio_cfg_pin(EXYNOS4_GPIO_A06, S5P_GPIO_FUNC(0x3));
562                 gpio_cfg_pin(EXYNOS4_GPIO_A07, S5P_GPIO_FUNC(0x3));
563                 break;
564         case PERIPH_ID_I2C3:
565                 gpio_cfg_pin(EXYNOS4_GPIO_A12, S5P_GPIO_FUNC(0x3));
566                 gpio_cfg_pin(EXYNOS4_GPIO_A13, S5P_GPIO_FUNC(0x3));
567                 break;
568         case PERIPH_ID_I2C4:
569                 gpio_cfg_pin(EXYNOS4_GPIO_B2, S5P_GPIO_FUNC(0x3));
570                 gpio_cfg_pin(EXYNOS4_GPIO_B3, S5P_GPIO_FUNC(0x3));
571                 break;
572         case PERIPH_ID_I2C5:
573                 gpio_cfg_pin(EXYNOS4_GPIO_B6, S5P_GPIO_FUNC(0x3));
574                 gpio_cfg_pin(EXYNOS4_GPIO_B7, S5P_GPIO_FUNC(0x3));
575                 break;
576         case PERIPH_ID_I2C6:
577                 gpio_cfg_pin(EXYNOS4_GPIO_C13, S5P_GPIO_FUNC(0x4));
578                 gpio_cfg_pin(EXYNOS4_GPIO_C14, S5P_GPIO_FUNC(0x4));
579                 break;
580         case PERIPH_ID_I2C7:
581                 gpio_cfg_pin(EXYNOS4_GPIO_D02, S5P_GPIO_FUNC(0x3));
582                 gpio_cfg_pin(EXYNOS4_GPIO_D03, S5P_GPIO_FUNC(0x3));
583                 break;
584         }
585 }
586
587 static int exynos4_mmc_config(int peripheral, int flags)
588 {
589         int i, start = 0, start_ext = 0;
590         unsigned int func, ext_func;
591
592         switch (peripheral) {
593         case PERIPH_ID_SDMMC0:
594                 start = EXYNOS4_GPIO_K00;
595                 start_ext = EXYNOS4_GPIO_K13;
596                 func = S5P_GPIO_FUNC(0x2);
597                 ext_func = S5P_GPIO_FUNC(0x3);
598                 break;
599         case PERIPH_ID_SDMMC2:
600                 start = EXYNOS4_GPIO_K20;
601                 start_ext = EXYNOS4_GPIO_K33;
602                 func = S5P_GPIO_FUNC(0x2);
603                 ext_func = S5P_GPIO_FUNC(0x3);
604                 break;
605         case PERIPH_ID_SDMMC4:
606                 start = EXYNOS4_GPIO_K00;
607                 start_ext = EXYNOS4_GPIO_K13;
608                 func = S5P_GPIO_FUNC(0x3);
609                 ext_func = S5P_GPIO_FUNC(0x4);
610                 break;
611         default:
612                 return -1;
613         }
614         for (i = start; i < (start + 7); i++) {
615                 if (i == (start + 2))
616                         continue;
617                 gpio_cfg_pin(i,  func);
618                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
619                 gpio_set_drv(i, S5P_GPIO_DRV_4X);
620         }
621         /* SDMMC2 do not use 8bit mode at exynos4 */
622         if (flags & PINMUX_FLAG_8BIT_MODE) {
623                 for (i = start_ext; i < (start_ext + 4); i++) {
624                         gpio_cfg_pin(i,  ext_func);
625                         gpio_set_pull(i, S5P_GPIO_PULL_NONE);
626                         gpio_set_drv(i, S5P_GPIO_DRV_4X);
627                 }
628         }
629
630         return 0;
631 }
632
633 static void exynos4_uart_config(int peripheral)
634 {
635         int i, start, count;
636
637         switch (peripheral) {
638         case PERIPH_ID_UART0:
639                 start = EXYNOS4_GPIO_A00;
640                 count = 4;
641                 break;
642         case PERIPH_ID_UART1:
643                 start = EXYNOS4_GPIO_A04;
644                 count = 4;
645                 break;
646         case PERIPH_ID_UART2:
647                 start = EXYNOS4_GPIO_A10;
648                 count = 4;
649                 break;
650         case PERIPH_ID_UART3:
651                 start = EXYNOS4_GPIO_A14;
652                 count = 2;
653                 break;
654         default:
655                 debug("%s: invalid peripheral %d", __func__, peripheral);
656                 return;
657         }
658         for (i = start; i < (start + count); i++) {
659                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
660                 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
661         }
662 }
663
664 static void exynos4x12_i2c_config(int peripheral, int flags)
665 {
666         switch (peripheral) {
667         case PERIPH_ID_I2C0:
668                 gpio_cfg_pin(EXYNOS4X12_GPIO_D10, S5P_GPIO_FUNC(0x2));
669                 gpio_cfg_pin(EXYNOS4X12_GPIO_D11, S5P_GPIO_FUNC(0x2));
670                 break;
671         case PERIPH_ID_I2C1:
672                 gpio_cfg_pin(EXYNOS4X12_GPIO_D12, S5P_GPIO_FUNC(0x2));
673                 gpio_cfg_pin(EXYNOS4X12_GPIO_D13, S5P_GPIO_FUNC(0x2));
674                 break;
675         case PERIPH_ID_I2C2:
676                 gpio_cfg_pin(EXYNOS4X12_GPIO_A06, S5P_GPIO_FUNC(0x3));
677                 gpio_cfg_pin(EXYNOS4X12_GPIO_A07, S5P_GPIO_FUNC(0x3));
678                 break;
679         case PERIPH_ID_I2C3:
680                 gpio_cfg_pin(EXYNOS4X12_GPIO_A12, S5P_GPIO_FUNC(0x3));
681                 gpio_cfg_pin(EXYNOS4X12_GPIO_A13, S5P_GPIO_FUNC(0x3));
682                 break;
683         case PERIPH_ID_I2C4:
684                 gpio_cfg_pin(EXYNOS4X12_GPIO_B2, S5P_GPIO_FUNC(0x3));
685                 gpio_cfg_pin(EXYNOS4X12_GPIO_B3, S5P_GPIO_FUNC(0x3));
686                 break;
687         case PERIPH_ID_I2C5:
688                 gpio_cfg_pin(EXYNOS4X12_GPIO_B6, S5P_GPIO_FUNC(0x3));
689                 gpio_cfg_pin(EXYNOS4X12_GPIO_B7, S5P_GPIO_FUNC(0x3));
690                 break;
691         case PERIPH_ID_I2C6:
692                 gpio_cfg_pin(EXYNOS4X12_GPIO_C13, S5P_GPIO_FUNC(0x4));
693                 gpio_cfg_pin(EXYNOS4X12_GPIO_C14, S5P_GPIO_FUNC(0x4));
694                 break;
695         case PERIPH_ID_I2C7:
696                 gpio_cfg_pin(EXYNOS4X12_GPIO_D02, S5P_GPIO_FUNC(0x3));
697                 gpio_cfg_pin(EXYNOS4X12_GPIO_D03, S5P_GPIO_FUNC(0x3));
698                 break;
699         }
700 }
701
702 static int exynos4x12_mmc_config(int peripheral, int flags)
703 {
704         int i, start = 0, start_ext = 0;
705         unsigned int func, ext_func;
706
707         switch (peripheral) {
708         case PERIPH_ID_SDMMC0:
709                 start = EXYNOS4X12_GPIO_K00;
710                 start_ext = EXYNOS4X12_GPIO_K13;
711                 func = S5P_GPIO_FUNC(0x2);
712                 ext_func = S5P_GPIO_FUNC(0x3);
713                 break;
714         case PERIPH_ID_SDMMC2:
715                 start = EXYNOS4X12_GPIO_K20;
716                 start_ext = EXYNOS4X12_GPIO_K33;
717                 func = S5P_GPIO_FUNC(0x2);
718                 ext_func = S5P_GPIO_FUNC(0x3);
719                 break;
720         case PERIPH_ID_SDMMC4:
721                 start = EXYNOS4X12_GPIO_K00;
722                 start_ext = EXYNOS4X12_GPIO_K13;
723                 func = S5P_GPIO_FUNC(0x3);
724                 ext_func = S5P_GPIO_FUNC(0x4);
725                 break;
726         default:
727                 return -1;
728         }
729         for (i = start; i < (start + 7); i++) {
730                 if (i == (start + 2))
731                         continue;
732                 gpio_cfg_pin(i,  func);
733                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
734                 gpio_set_drv(i, S5P_GPIO_DRV_4X);
735         }
736         if (flags & PINMUX_FLAG_8BIT_MODE) {
737                 for (i = start_ext; i < (start_ext + 4); i++) {
738                         gpio_cfg_pin(i,  ext_func);
739                         gpio_set_pull(i, S5P_GPIO_PULL_NONE);
740                         gpio_set_drv(i, S5P_GPIO_DRV_4X);
741                 }
742         }
743
744         return 0;
745 }
746
747 static void exynos4x12_uart_config(int peripheral)
748 {
749         int i, start, count;
750
751         switch (peripheral) {
752         case PERIPH_ID_UART0:
753                 start = EXYNOS4X12_GPIO_A00;
754                 count = 4;
755                 break;
756         case PERIPH_ID_UART1:
757                 start = EXYNOS4X12_GPIO_A04;
758                 count = 4;
759                 break;
760         case PERIPH_ID_UART2:
761                 start = EXYNOS4X12_GPIO_A10;
762                 count = 4;
763                 break;
764         case PERIPH_ID_UART3:
765                 start = EXYNOS4X12_GPIO_A14;
766                 count = 2;
767                 break;
768         default:
769                 debug("%s: invalid peripheral %d", __func__, peripheral);
770                 return;
771         }
772         for (i = start; i < (start + count); i++) {
773                 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
774                 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
775         }
776 }
777
778 static int exynos4_pinmux_config(int peripheral, int flags)
779 {
780         switch (peripheral) {
781         case PERIPH_ID_UART0:
782         case PERIPH_ID_UART1:
783         case PERIPH_ID_UART2:
784         case PERIPH_ID_UART3:
785                 exynos4_uart_config(peripheral);
786                 break;
787         case PERIPH_ID_I2C0:
788         case PERIPH_ID_I2C1:
789         case PERIPH_ID_I2C2:
790         case PERIPH_ID_I2C3:
791         case PERIPH_ID_I2C4:
792         case PERIPH_ID_I2C5:
793         case PERIPH_ID_I2C6:
794         case PERIPH_ID_I2C7:
795                 exynos4_i2c_config(peripheral, flags);
796                 break;
797         case PERIPH_ID_SDMMC0:
798         case PERIPH_ID_SDMMC2:
799         case PERIPH_ID_SDMMC4:
800                 return exynos4_mmc_config(peripheral, flags);
801         case PERIPH_ID_SDMMC1:
802         case PERIPH_ID_SDMMC3:
803                 debug("SDMMC device %d not implemented\n", peripheral);
804                 return -1;
805         default:
806                 debug("%s: invalid peripheral %d", __func__, peripheral);
807                 return -1;
808         }
809
810         return 0;
811 }
812
813 static int exynos4x12_pinmux_config(int peripheral, int flags)
814 {
815         switch (peripheral) {
816         case PERIPH_ID_UART0:
817         case PERIPH_ID_UART1:
818         case PERIPH_ID_UART2:
819         case PERIPH_ID_UART3:
820                 exynos4x12_uart_config(peripheral);
821                 break;
822         case PERIPH_ID_I2C0:
823         case PERIPH_ID_I2C1:
824         case PERIPH_ID_I2C2:
825         case PERIPH_ID_I2C3:
826         case PERIPH_ID_I2C4:
827         case PERIPH_ID_I2C5:
828         case PERIPH_ID_I2C6:
829         case PERIPH_ID_I2C7:
830                 exynos4x12_i2c_config(peripheral, flags);
831                 break;
832         case PERIPH_ID_SDMMC0:
833         case PERIPH_ID_SDMMC2:
834         case PERIPH_ID_SDMMC4:
835                 return exynos4x12_mmc_config(peripheral, flags);
836         case PERIPH_ID_SDMMC1:
837         case PERIPH_ID_SDMMC3:
838                 debug("SDMMC device %d not implemented\n", peripheral);
839                 return -1;
840         default:
841                 debug("%s: invalid peripheral %d", __func__, peripheral);
842                 return -1;
843         }
844
845         return 0;
846 }
847
848 int exynos_pinmux_config(int peripheral, int flags)
849 {
850         if (cpu_is_exynos5()) {
851                 if (proid_is_exynos5420() || proid_is_exynos5800())
852                         return exynos5420_pinmux_config(peripheral, flags);
853                 else if (proid_is_exynos5250())
854                         return exynos5_pinmux_config(peripheral, flags);
855         } else if (cpu_is_exynos4()) {
856                 if (proid_is_exynos4412())
857                         return exynos4x12_pinmux_config(peripheral, flags);
858                 else
859                         return exynos4_pinmux_config(peripheral, flags);
860         }
861
862         debug("pinmux functionality not supported\n");
863
864         return -1;
865 }
866
867 #ifdef CONFIG_OF_CONTROL
868 static int exynos4_pinmux_decode_periph_id(const void *blob, int node)
869 {
870         int err;
871         u32 cell[3];
872
873         err = fdtdec_get_int_array(blob, node, "interrupts", cell,
874                                         ARRAY_SIZE(cell));
875         if (err) {
876                 debug(" invalid peripheral id\n");
877                 return PERIPH_ID_NONE;
878         }
879
880         return cell[1];
881 }
882
883 static int exynos5_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                 return PERIPH_ID_NONE;
892
893         return cell[1];
894 }
895
896 int pinmux_decode_periph_id(const void *blob, int node)
897 {
898         if (cpu_is_exynos5())
899                 return  exynos5_pinmux_decode_periph_id(blob, node);
900         else if (cpu_is_exynos4())
901                 return  exynos4_pinmux_decode_periph_id(blob, node);
902
903         return PERIPH_ID_NONE;
904 }
905 #endif