blob: fec2df9bd95013826d4e75e346835e3c97f6ce89 [file] [log] [blame]
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +00001/*
2 * Copyright (c) 2012 Samsung Electronics.
3 * Abhilash Kesavan <a.kesavan@samsung.com>
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +00006 */
7
8#include <common.h>
Rajeshwari Shinde28bae822012-12-26 20:03:11 +00009#include <fdtdec.h>
Simon Glass37f11622014-10-20 19:48:37 -060010#include <asm/gpio.h>
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000011#include <asm/arch/pinmux.h>
12#include <asm/arch/sromc.h>
13
14static void exynos5_uart_config(int peripheral)
15{
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000016 int i, start, count;
17
18 switch (peripheral) {
19 case PERIPH_ID_UART0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053020 start = EXYNOS5_GPIO_A00;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000021 count = 4;
22 break;
23 case PERIPH_ID_UART1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053024 start = EXYNOS5_GPIO_D00;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000025 count = 4;
26 break;
27 case PERIPH_ID_UART2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053028 start = EXYNOS5_GPIO_A10;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000029 count = 4;
30 break;
31 case PERIPH_ID_UART3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053032 start = EXYNOS5_GPIO_A14;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000033 count = 2;
34 break;
Marek Vasute382be92014-03-10 20:04:31 +010035 default:
36 debug("%s: invalid peripheral %d", __func__, peripheral);
37 return;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000038 }
39 for (i = start; i < start + count; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053040 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
41 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000042 }
43}
44
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053045static void exynos5420_uart_config(int peripheral)
46{
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053047 int i, start, count;
48
49 switch (peripheral) {
50 case PERIPH_ID_UART0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053051 start = EXYNOS5420_GPIO_A00;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053052 count = 4;
53 break;
54 case PERIPH_ID_UART1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053055 start = EXYNOS5420_GPIO_A04;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053056 count = 4;
57 break;
58 case PERIPH_ID_UART2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053059 start = EXYNOS5420_GPIO_A10;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053060 count = 4;
61 break;
62 case PERIPH_ID_UART3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053063 start = EXYNOS5420_GPIO_A14;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053064 count = 2;
65 break;
Marek Vasute382be92014-03-10 20:04:31 +010066 default:
67 debug("%s: invalid peripheral %d", __func__, peripheral);
68 return;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053069 }
70
71 for (i = start; i < start + count; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053072 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
73 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +053074 }
75}
76
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000077static int exynos5_mmc_config(int peripheral, int flags)
78{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053079 int i, start, start_ext, gpio_func = 0;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000080
81 switch (peripheral) {
82 case PERIPH_ID_SDMMC0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053083 start = EXYNOS5_GPIO_C00;
84 start_ext = EXYNOS5_GPIO_C10;
85 gpio_func = S5P_GPIO_FUNC(0x2);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000086 break;
87 case PERIPH_ID_SDMMC1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053088 start = EXYNOS5_GPIO_C20;
89 start_ext = 0;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000090 break;
91 case PERIPH_ID_SDMMC2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053092 start = EXYNOS5_GPIO_C30;
93 start_ext = EXYNOS5_GPIO_C43;
94 gpio_func = S5P_GPIO_FUNC(0x3);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000095 break;
96 case PERIPH_ID_SDMMC3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +053097 start = EXYNOS5_GPIO_C40;
98 start_ext = 0;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +000099 break;
Marek Vasute382be92014-03-10 20:04:31 +0100100 default:
101 debug("%s: invalid peripheral %d", __func__, peripheral);
102 return -1;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000103 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530104 if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000105 debug("SDMMC device %d does not support 8bit mode",
106 peripheral);
107 return -1;
108 }
109 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530110 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);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000114 }
115 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530116 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);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530120 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530121 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);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530125 }
126
127 return 0;
128}
129
130static int exynos5420_mmc_config(int peripheral, int flags)
131{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530132 int i, start = 0, start_ext = 0;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530133
134 switch (peripheral) {
135 case PERIPH_ID_SDMMC0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530136 start = EXYNOS5420_GPIO_C00;
137 start_ext = EXYNOS5420_GPIO_C30;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530138 break;
139 case PERIPH_ID_SDMMC1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530140 start = EXYNOS5420_GPIO_C10;
141 start_ext = EXYNOS5420_GPIO_D14;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530142 break;
143 case PERIPH_ID_SDMMC2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530144 start = EXYNOS5420_GPIO_C20;
145 start_ext = 0;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530146 break;
147 default:
148 start = 0;
149 debug("%s: invalid peripheral %d", __func__, peripheral);
150 return -1;
151 }
152
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530153 if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530154 debug("SDMMC device %d does not support 8bit mode",
155 peripheral);
156 return -1;
157 }
158
159 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530160 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);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530164 }
165 }
166
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530167 for (i = start; i < (start + 3); i++) {
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530168 /*
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 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530174 if ((peripheral == PERIPH_ID_SDMMC0) && (i == (start + 2))) {
Simon Glass4f83d3d2014-10-20 19:48:39 -0600175#ifndef CONFIG_SPL_BUILD
176 gpio_request(i, "sdmmc0_vdden");
177#endif
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530178 gpio_set_value(i, 1);
179 gpio_cfg_pin(i, S5P_GPIO_OUTPUT);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530180 } else {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530181 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530182 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530183 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
184 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000185 }
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530186
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530187 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);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000191 }
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000192
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000193 return 0;
194}
195
196static void exynos5_sromc_config(int flags)
197{
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000198 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 */
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530215 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));
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000219
220 for (i = 0; i < 4; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530221 gpio_cfg_pin(EXYNOS5_GPIO_Y10 + i, S5P_GPIO_FUNC(2));
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000222
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++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530256 gpio_cfg_pin(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_FUNC(2));
257 gpio_set_pull(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_PULL_UP);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000258
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530259 gpio_cfg_pin(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_FUNC(2));
260 gpio_set_pull(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_PULL_UP);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000261
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530262 gpio_cfg_pin(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_FUNC(2));
263 gpio_set_pull(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_PULL_UP);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000264 }
265}
266
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000267static void exynos5_i2c_config(int peripheral, int flags)
268{
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100269 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
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000280 switch (peripheral) {
281 case PERIPH_ID_I2C0:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100282 gpio_cfg_pin(EXYNOS5_GPIO_B30, S5P_GPIO_FUNC(func01));
283 gpio_cfg_pin(EXYNOS5_GPIO_B31, S5P_GPIO_FUNC(func01));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000284 break;
285 case PERIPH_ID_I2C1:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100286 gpio_cfg_pin(EXYNOS5_GPIO_B32, S5P_GPIO_FUNC(func01));
287 gpio_cfg_pin(EXYNOS5_GPIO_B33, S5P_GPIO_FUNC(func01));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000288 break;
289 case PERIPH_ID_I2C2:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100290 gpio_cfg_pin(EXYNOS5_GPIO_A06, S5P_GPIO_FUNC(func23));
291 gpio_cfg_pin(EXYNOS5_GPIO_A07, S5P_GPIO_FUNC(func23));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000292 break;
293 case PERIPH_ID_I2C3:
Przemyslaw Marczak056d6552015-01-27 13:36:34 +0100294 gpio_cfg_pin(EXYNOS5_GPIO_A12, S5P_GPIO_FUNC(func23));
295 gpio_cfg_pin(EXYNOS5_GPIO_A13, S5P_GPIO_FUNC(func23));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000296 break;
297 case PERIPH_ID_I2C4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530298 gpio_cfg_pin(EXYNOS5_GPIO_A20, S5P_GPIO_FUNC(0x3));
299 gpio_cfg_pin(EXYNOS5_GPIO_A21, S5P_GPIO_FUNC(0x3));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000300 break;
301 case PERIPH_ID_I2C5:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530302 gpio_cfg_pin(EXYNOS5_GPIO_A22, S5P_GPIO_FUNC(0x3));
303 gpio_cfg_pin(EXYNOS5_GPIO_A23, S5P_GPIO_FUNC(0x3));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000304 break;
305 case PERIPH_ID_I2C6:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530306 gpio_cfg_pin(EXYNOS5_GPIO_B13, S5P_GPIO_FUNC(0x4));
307 gpio_cfg_pin(EXYNOS5_GPIO_B14, S5P_GPIO_FUNC(0x4));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000308 break;
309 case PERIPH_ID_I2C7:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530310 gpio_cfg_pin(EXYNOS5_GPIO_B22, S5P_GPIO_FUNC(0x3));
311 gpio_cfg_pin(EXYNOS5_GPIO_B23, S5P_GPIO_FUNC(0x3));
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000312 break;
313 }
314}
315
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530316static void exynos5420_i2c_config(int peripheral)
317{
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530318 switch (peripheral) {
319 case PERIPH_ID_I2C0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530320 gpio_cfg_pin(EXYNOS5420_GPIO_B30, S5P_GPIO_FUNC(0x2));
321 gpio_cfg_pin(EXYNOS5420_GPIO_B31, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530322 break;
323 case PERIPH_ID_I2C1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530324 gpio_cfg_pin(EXYNOS5420_GPIO_B32, S5P_GPIO_FUNC(0x2));
325 gpio_cfg_pin(EXYNOS5420_GPIO_B33, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530326 break;
327 case PERIPH_ID_I2C2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530328 gpio_cfg_pin(EXYNOS5420_GPIO_A06, S5P_GPIO_FUNC(0x3));
329 gpio_cfg_pin(EXYNOS5420_GPIO_A07, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530330 break;
331 case PERIPH_ID_I2C3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530332 gpio_cfg_pin(EXYNOS5420_GPIO_A12, S5P_GPIO_FUNC(0x3));
333 gpio_cfg_pin(EXYNOS5420_GPIO_A13, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530334 break;
335 case PERIPH_ID_I2C4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530336 gpio_cfg_pin(EXYNOS5420_GPIO_A20, S5P_GPIO_FUNC(0x3));
337 gpio_cfg_pin(EXYNOS5420_GPIO_A21, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530338 break;
339 case PERIPH_ID_I2C5:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530340 gpio_cfg_pin(EXYNOS5420_GPIO_A22, S5P_GPIO_FUNC(0x3));
341 gpio_cfg_pin(EXYNOS5420_GPIO_A23, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530342 break;
343 case PERIPH_ID_I2C6:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530344 gpio_cfg_pin(EXYNOS5420_GPIO_B13, S5P_GPIO_FUNC(0x4));
345 gpio_cfg_pin(EXYNOS5420_GPIO_B14, S5P_GPIO_FUNC(0x4));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530346 break;
347 case PERIPH_ID_I2C7:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530348 gpio_cfg_pin(EXYNOS5420_GPIO_B22, S5P_GPIO_FUNC(0x3));
349 gpio_cfg_pin(EXYNOS5420_GPIO_B23, S5P_GPIO_FUNC(0x3));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530350 break;
351 case PERIPH_ID_I2C8:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530352 gpio_cfg_pin(EXYNOS5420_GPIO_B34, S5P_GPIO_FUNC(0x2));
353 gpio_cfg_pin(EXYNOS5420_GPIO_B35, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530354 break;
355 case PERIPH_ID_I2C9:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530356 gpio_cfg_pin(EXYNOS5420_GPIO_B36, S5P_GPIO_FUNC(0x2));
357 gpio_cfg_pin(EXYNOS5420_GPIO_B37, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530358 break;
359 case PERIPH_ID_I2C10:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530360 gpio_cfg_pin(EXYNOS5420_GPIO_B40, S5P_GPIO_FUNC(0x2));
361 gpio_cfg_pin(EXYNOS5420_GPIO_B41, S5P_GPIO_FUNC(0x2));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530362 break;
363 }
364}
365
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000366static void exynos5_i2s_config(int peripheral)
367{
368 int i;
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000369
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530370 switch (peripheral) {
371 case PERIPH_ID_I2S0:
372 for (i = 0; i < 5; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530373 gpio_cfg_pin(EXYNOS5_GPIO_Z0 + i, S5P_GPIO_FUNC(0x02));
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530374 break;
375 case PERIPH_ID_I2S1:
376 for (i = 0; i < 5; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530377 gpio_cfg_pin(EXYNOS5_GPIO_B00 + i, S5P_GPIO_FUNC(0x02));
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530378 break;
379 }
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000380}
381
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000382void exynos5_spi_config(int peripheral)
383{
384 int cfg = 0, pin = 0, i;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000385
386 switch (peripheral) {
387 case PERIPH_ID_SPI0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530388 cfg = S5P_GPIO_FUNC(0x2);
389 pin = EXYNOS5_GPIO_A20;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000390 break;
391 case PERIPH_ID_SPI1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530392 cfg = S5P_GPIO_FUNC(0x2);
393 pin = EXYNOS5_GPIO_A24;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000394 break;
395 case PERIPH_ID_SPI2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530396 cfg = S5P_GPIO_FUNC(0x5);
397 pin = EXYNOS5_GPIO_B11;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000398 break;
399 case PERIPH_ID_SPI3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530400 cfg = S5P_GPIO_FUNC(0x2);
401 pin = EXYNOS5_GPIO_F10;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000402 break;
403 case PERIPH_ID_SPI4:
404 for (i = 0; i < 2; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530405 gpio_cfg_pin(EXYNOS5_GPIO_F02 + i, S5P_GPIO_FUNC(0x4));
406 gpio_cfg_pin(EXYNOS5_GPIO_E04 + i, S5P_GPIO_FUNC(0x4));
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000407 }
408 break;
409 }
410 if (peripheral != PERIPH_ID_SPI4) {
411 for (i = pin; i < pin + 4; i++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530412 gpio_cfg_pin(i, cfg);
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000413 }
414}
415
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530416void exynos5420_spi_config(int peripheral)
417{
418 int cfg, pin, i;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530419
420 switch (peripheral) {
421 case PERIPH_ID_SPI0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530422 pin = EXYNOS5420_GPIO_A20;
423 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530424 break;
425 case PERIPH_ID_SPI1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530426 pin = EXYNOS5420_GPIO_A24;
427 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530428 break;
429 case PERIPH_ID_SPI2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530430 pin = EXYNOS5420_GPIO_B11;
431 cfg = S5P_GPIO_FUNC(0x5);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530432 break;
433 case PERIPH_ID_SPI3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530434 pin = EXYNOS5420_GPIO_F10;
435 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530436 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++)
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530450 gpio_cfg_pin(i, cfg);
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530451 } else {
452 for (i = 0; i < 2; i++) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530453 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));
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530457 }
458 }
459}
460
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000461static 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;
Rajeshwari Shinde6c313f92012-07-23 21:23:51 +0000478 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;
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530488 case PERIPH_ID_I2S0:
Rajeshwari Shinde7cf89a22012-10-25 19:49:27 +0000489 case PERIPH_ID_I2S1:
490 exynos5_i2s_config(peripheral);
491 break;
Rajeshwari Shinde8d909f32012-10-28 19:32:54 +0000492 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;
Simon Glass6f6af972015-07-02 18:16:13 -0600499 case PERIPH_ID_DPHPD:
500 /* Set Hotplug detect for DP */
501 gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
502
503 /*
504 * Hotplug detect should have an external pullup; disable the
505 * internal pulldown so they don't fight.
506 */
507 gpio_set_pull(EXYNOS5_GPIO_X07, S5P_GPIO_PULL_NONE);
508 break;
Simon Glass114f8362016-02-21 21:08:56 -0700509 case PERIPH_ID_PWM0:
510 gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_FUNC(2));
511 break;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000512 default:
513 debug("%s: invalid peripheral %d", __func__, peripheral);
514 return -1;
515 }
516
517 return 0;
518}
519
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530520static int exynos5420_pinmux_config(int peripheral, int flags)
521{
522 switch (peripheral) {
523 case PERIPH_ID_UART0:
524 case PERIPH_ID_UART1:
525 case PERIPH_ID_UART2:
526 case PERIPH_ID_UART3:
527 exynos5420_uart_config(peripheral);
528 break;
529 case PERIPH_ID_SDMMC0:
530 case PERIPH_ID_SDMMC1:
531 case PERIPH_ID_SDMMC2:
532 case PERIPH_ID_SDMMC3:
533 return exynos5420_mmc_config(peripheral, flags);
534 case PERIPH_ID_SPI0:
535 case PERIPH_ID_SPI1:
536 case PERIPH_ID_SPI2:
537 case PERIPH_ID_SPI3:
538 case PERIPH_ID_SPI4:
539 exynos5420_spi_config(peripheral);
540 break;
541 case PERIPH_ID_I2C0:
542 case PERIPH_ID_I2C1:
543 case PERIPH_ID_I2C2:
544 case PERIPH_ID_I2C3:
545 case PERIPH_ID_I2C4:
546 case PERIPH_ID_I2C5:
547 case PERIPH_ID_I2C6:
548 case PERIPH_ID_I2C7:
549 case PERIPH_ID_I2C8:
550 case PERIPH_ID_I2C9:
551 case PERIPH_ID_I2C10:
552 exynos5420_i2c_config(peripheral);
553 break;
Simon Glass114f8362016-02-21 21:08:56 -0700554 case PERIPH_ID_PWM0:
555 gpio_cfg_pin(EXYNOS5420_GPIO_B20, S5P_GPIO_FUNC(2));
556 break;
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530557 default:
558 debug("%s: invalid peripheral %d", __func__, peripheral);
559 return -1;
560 }
561
562 return 0;
563}
564
Piotr Wilczekedad2172012-11-20 02:19:04 +0000565static void exynos4_i2c_config(int peripheral, int flags)
Piotr Wilczek7318b292012-09-20 00:19:57 +0000566{
Piotr Wilczek7318b292012-09-20 00:19:57 +0000567 switch (peripheral) {
Piotr Wilczekedad2172012-11-20 02:19:04 +0000568 case PERIPH_ID_I2C0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530569 gpio_cfg_pin(EXYNOS4_GPIO_D10, S5P_GPIO_FUNC(0x2));
570 gpio_cfg_pin(EXYNOS4_GPIO_D11, S5P_GPIO_FUNC(0x2));
Piotr Wilczek7318b292012-09-20 00:19:57 +0000571 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000572 case PERIPH_ID_I2C1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530573 gpio_cfg_pin(EXYNOS4_GPIO_D12, S5P_GPIO_FUNC(0x2));
574 gpio_cfg_pin(EXYNOS4_GPIO_D13, S5P_GPIO_FUNC(0x2));
Piotr Wilczek7318b292012-09-20 00:19:57 +0000575 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000576 case PERIPH_ID_I2C2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530577 gpio_cfg_pin(EXYNOS4_GPIO_A06, S5P_GPIO_FUNC(0x3));
578 gpio_cfg_pin(EXYNOS4_GPIO_A07, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000579 break;
580 case PERIPH_ID_I2C3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530581 gpio_cfg_pin(EXYNOS4_GPIO_A12, S5P_GPIO_FUNC(0x3));
582 gpio_cfg_pin(EXYNOS4_GPIO_A13, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000583 break;
584 case PERIPH_ID_I2C4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530585 gpio_cfg_pin(EXYNOS4_GPIO_B2, S5P_GPIO_FUNC(0x3));
586 gpio_cfg_pin(EXYNOS4_GPIO_B3, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000587 break;
588 case PERIPH_ID_I2C5:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530589 gpio_cfg_pin(EXYNOS4_GPIO_B6, S5P_GPIO_FUNC(0x3));
590 gpio_cfg_pin(EXYNOS4_GPIO_B7, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000591 break;
592 case PERIPH_ID_I2C6:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530593 gpio_cfg_pin(EXYNOS4_GPIO_C13, S5P_GPIO_FUNC(0x4));
594 gpio_cfg_pin(EXYNOS4_GPIO_C14, S5P_GPIO_FUNC(0x4));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000595 break;
596 case PERIPH_ID_I2C7:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530597 gpio_cfg_pin(EXYNOS4_GPIO_D02, S5P_GPIO_FUNC(0x3));
598 gpio_cfg_pin(EXYNOS4_GPIO_D03, S5P_GPIO_FUNC(0x3));
Piotr Wilczekedad2172012-11-20 02:19:04 +0000599 break;
Piotr Wilczek7318b292012-09-20 00:19:57 +0000600 }
Piotr Wilczek7318b292012-09-20 00:19:57 +0000601}
602
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000603static int exynos4_mmc_config(int peripheral, int flags)
604{
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530605 int i, start = 0, start_ext = 0;
Beomho Seo06d1b162014-05-16 13:59:46 +0900606 unsigned int func, ext_func;
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000607
608 switch (peripheral) {
609 case PERIPH_ID_SDMMC0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530610 start = EXYNOS4_GPIO_K00;
611 start_ext = EXYNOS4_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900612 func = S5P_GPIO_FUNC(0x2);
613 ext_func = S5P_GPIO_FUNC(0x3);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000614 break;
615 case PERIPH_ID_SDMMC2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530616 start = EXYNOS4_GPIO_K20;
617 start_ext = EXYNOS4_GPIO_K33;
Beomho Seo06d1b162014-05-16 13:59:46 +0900618 func = S5P_GPIO_FUNC(0x2);
619 ext_func = S5P_GPIO_FUNC(0x3);
620 break;
621 case PERIPH_ID_SDMMC4:
622 start = EXYNOS4_GPIO_K00;
623 start_ext = EXYNOS4_GPIO_K13;
624 func = S5P_GPIO_FUNC(0x3);
625 ext_func = S5P_GPIO_FUNC(0x4);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000626 break;
627 default:
628 return -1;
629 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530630 for (i = start; i < (start + 7); i++) {
631 if (i == (start + 2))
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000632 continue;
Beomho Seo06d1b162014-05-16 13:59:46 +0900633 gpio_cfg_pin(i, func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530634 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
635 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000636 }
Beomho Seo06d1b162014-05-16 13:59:46 +0900637 /* SDMMC2 do not use 8bit mode at exynos4 */
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000638 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530639 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo06d1b162014-05-16 13:59:46 +0900640 gpio_cfg_pin(i, ext_func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530641 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
642 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000643 }
644 }
645
646 return 0;
647}
648
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530649static void exynos4_uart_config(int peripheral)
650{
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530651 int i, start, count;
652
653 switch (peripheral) {
654 case PERIPH_ID_UART0:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530655 start = EXYNOS4_GPIO_A00;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530656 count = 4;
657 break;
658 case PERIPH_ID_UART1:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530659 start = EXYNOS4_GPIO_A04;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530660 count = 4;
661 break;
662 case PERIPH_ID_UART2:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530663 start = EXYNOS4_GPIO_A10;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530664 count = 4;
665 break;
666 case PERIPH_ID_UART3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530667 start = EXYNOS4_GPIO_A14;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530668 count = 2;
669 break;
Marek Vasute382be92014-03-10 20:04:31 +0100670 default:
671 debug("%s: invalid peripheral %d", __func__, peripheral);
672 return;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530673 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530674 for (i = start; i < (start + count); i++) {
675 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
676 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
677 }
678}
679
680static void exynos4x12_i2c_config(int peripheral, int flags)
681{
682 switch (peripheral) {
683 case PERIPH_ID_I2C0:
684 gpio_cfg_pin(EXYNOS4X12_GPIO_D10, S5P_GPIO_FUNC(0x2));
685 gpio_cfg_pin(EXYNOS4X12_GPIO_D11, S5P_GPIO_FUNC(0x2));
686 break;
687 case PERIPH_ID_I2C1:
688 gpio_cfg_pin(EXYNOS4X12_GPIO_D12, S5P_GPIO_FUNC(0x2));
689 gpio_cfg_pin(EXYNOS4X12_GPIO_D13, S5P_GPIO_FUNC(0x2));
690 break;
691 case PERIPH_ID_I2C2:
692 gpio_cfg_pin(EXYNOS4X12_GPIO_A06, S5P_GPIO_FUNC(0x3));
693 gpio_cfg_pin(EXYNOS4X12_GPIO_A07, S5P_GPIO_FUNC(0x3));
694 break;
695 case PERIPH_ID_I2C3:
696 gpio_cfg_pin(EXYNOS4X12_GPIO_A12, S5P_GPIO_FUNC(0x3));
697 gpio_cfg_pin(EXYNOS4X12_GPIO_A13, S5P_GPIO_FUNC(0x3));
698 break;
699 case PERIPH_ID_I2C4:
700 gpio_cfg_pin(EXYNOS4X12_GPIO_B2, S5P_GPIO_FUNC(0x3));
701 gpio_cfg_pin(EXYNOS4X12_GPIO_B3, S5P_GPIO_FUNC(0x3));
702 break;
703 case PERIPH_ID_I2C5:
704 gpio_cfg_pin(EXYNOS4X12_GPIO_B6, S5P_GPIO_FUNC(0x3));
705 gpio_cfg_pin(EXYNOS4X12_GPIO_B7, S5P_GPIO_FUNC(0x3));
706 break;
707 case PERIPH_ID_I2C6:
708 gpio_cfg_pin(EXYNOS4X12_GPIO_C13, S5P_GPIO_FUNC(0x4));
709 gpio_cfg_pin(EXYNOS4X12_GPIO_C14, S5P_GPIO_FUNC(0x4));
710 break;
711 case PERIPH_ID_I2C7:
712 gpio_cfg_pin(EXYNOS4X12_GPIO_D02, S5P_GPIO_FUNC(0x3));
713 gpio_cfg_pin(EXYNOS4X12_GPIO_D03, S5P_GPIO_FUNC(0x3));
714 break;
715 }
716}
717
718static int exynos4x12_mmc_config(int peripheral, int flags)
719{
720 int i, start = 0, start_ext = 0;
Beomho Seo06d1b162014-05-16 13:59:46 +0900721 unsigned int func, ext_func;
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530722
723 switch (peripheral) {
724 case PERIPH_ID_SDMMC0:
725 start = EXYNOS4X12_GPIO_K00;
726 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900727 func = S5P_GPIO_FUNC(0x2);
728 ext_func = S5P_GPIO_FUNC(0x3);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530729 break;
730 case PERIPH_ID_SDMMC2:
731 start = EXYNOS4X12_GPIO_K20;
732 start_ext = EXYNOS4X12_GPIO_K33;
Beomho Seo06d1b162014-05-16 13:59:46 +0900733 func = S5P_GPIO_FUNC(0x2);
734 ext_func = S5P_GPIO_FUNC(0x3);
735 break;
736 case PERIPH_ID_SDMMC4:
Przemyslaw Marczak64c7da52014-09-01 13:50:43 +0200737 start = EXYNOS4X12_GPIO_K00;
738 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo06d1b162014-05-16 13:59:46 +0900739 func = S5P_GPIO_FUNC(0x3);
740 ext_func = S5P_GPIO_FUNC(0x4);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530741 break;
742 default:
743 return -1;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530744 }
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530745 for (i = start; i < (start + 7); i++) {
Przemyslaw Marczak91fd7472015-10-28 15:41:49 +0100746 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530747 if (i == (start + 2))
748 continue;
Beomho Seo06d1b162014-05-16 13:59:46 +0900749 gpio_cfg_pin(i, func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530750 gpio_set_drv(i, S5P_GPIO_DRV_4X);
751 }
752 if (flags & PINMUX_FLAG_8BIT_MODE) {
753 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo06d1b162014-05-16 13:59:46 +0900754 gpio_cfg_pin(i, ext_func);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530755 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
756 gpio_set_drv(i, S5P_GPIO_DRV_4X);
757 }
758 }
759
760 return 0;
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530761}
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530762
763static void exynos4x12_uart_config(int peripheral)
764{
765 int i, start, count;
766
767 switch (peripheral) {
768 case PERIPH_ID_UART0:
769 start = EXYNOS4X12_GPIO_A00;
770 count = 4;
771 break;
772 case PERIPH_ID_UART1:
773 start = EXYNOS4X12_GPIO_A04;
774 count = 4;
775 break;
776 case PERIPH_ID_UART2:
777 start = EXYNOS4X12_GPIO_A10;
778 count = 4;
779 break;
780 case PERIPH_ID_UART3:
781 start = EXYNOS4X12_GPIO_A14;
782 count = 2;
783 break;
784 default:
785 debug("%s: invalid peripheral %d", __func__, peripheral);
786 return;
787 }
788 for (i = start; i < (start + count); i++) {
789 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
790 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
791 }
792}
793
Piotr Wilczek7318b292012-09-20 00:19:57 +0000794static int exynos4_pinmux_config(int peripheral, int flags)
795{
796 switch (peripheral) {
Rajeshwari Shinde99ae9b82013-07-04 12:29:16 +0530797 case PERIPH_ID_UART0:
798 case PERIPH_ID_UART1:
799 case PERIPH_ID_UART2:
800 case PERIPH_ID_UART3:
801 exynos4_uart_config(peripheral);
802 break;
Piotr Wilczekedad2172012-11-20 02:19:04 +0000803 case PERIPH_ID_I2C0:
804 case PERIPH_ID_I2C1:
805 case PERIPH_ID_I2C2:
806 case PERIPH_ID_I2C3:
807 case PERIPH_ID_I2C4:
808 case PERIPH_ID_I2C5:
809 case PERIPH_ID_I2C6:
810 case PERIPH_ID_I2C7:
811 exynos4_i2c_config(peripheral, flags);
812 break;
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000813 case PERIPH_ID_SDMMC0:
814 case PERIPH_ID_SDMMC2:
Beomho Seo06d1b162014-05-16 13:59:46 +0900815 case PERIPH_ID_SDMMC4:
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000816 return exynos4_mmc_config(peripheral, flags);
817 case PERIPH_ID_SDMMC1:
818 case PERIPH_ID_SDMMC3:
Rajeshwari Shinde507f8922013-10-08 18:42:22 +0530819 debug("SDMMC device %d not implemented\n", peripheral);
Piotr Wilczeka90efe92013-01-02 21:31:00 +0000820 return -1;
Piotr Wilczek7318b292012-09-20 00:19:57 +0000821 default:
822 debug("%s: invalid peripheral %d", __func__, peripheral);
823 return -1;
824 }
825
826 return 0;
827}
828
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530829static int exynos4x12_pinmux_config(int peripheral, int flags)
830{
831 switch (peripheral) {
832 case PERIPH_ID_UART0:
833 case PERIPH_ID_UART1:
834 case PERIPH_ID_UART2:
835 case PERIPH_ID_UART3:
836 exynos4x12_uart_config(peripheral);
837 break;
838 case PERIPH_ID_I2C0:
839 case PERIPH_ID_I2C1:
840 case PERIPH_ID_I2C2:
841 case PERIPH_ID_I2C3:
842 case PERIPH_ID_I2C4:
843 case PERIPH_ID_I2C5:
844 case PERIPH_ID_I2C6:
845 case PERIPH_ID_I2C7:
846 exynos4x12_i2c_config(peripheral, flags);
847 break;
848 case PERIPH_ID_SDMMC0:
849 case PERIPH_ID_SDMMC2:
Beomho Seo06d1b162014-05-16 13:59:46 +0900850 case PERIPH_ID_SDMMC4:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530851 return exynos4x12_mmc_config(peripheral, flags);
852 case PERIPH_ID_SDMMC1:
853 case PERIPH_ID_SDMMC3:
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530854 debug("SDMMC device %d not implemented\n", peripheral);
855 return -1;
856 default:
857 debug("%s: invalid peripheral %d", __func__, peripheral);
858 return -1;
859 }
860
861 return 0;
862}
863
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000864int exynos_pinmux_config(int peripheral, int flags)
865{
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530866 if (cpu_is_exynos5()) {
Przemyslaw Marczakcefbfe42015-10-27 13:07:57 +0100867 if (proid_is_exynos5420() || proid_is_exynos5422())
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530868 return exynos5420_pinmux_config(peripheral, flags);
869 else if (proid_is_exynos5250())
870 return exynos5_pinmux_config(peripheral, flags);
Dani Krishna Mohan65c7ee62013-09-11 16:38:48 +0530871 } else if (cpu_is_exynos4()) {
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530872 if (proid_is_exynos4412())
873 return exynos4x12_pinmux_config(peripheral, flags);
874 else
875 return exynos4_pinmux_config(peripheral, flags);
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000876 }
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530877
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530878 debug("pinmux functionality not supported\n");
879
Rajeshwari Birjef0ce84f2013-12-26 09:44:23 +0530880 return -1;
Rajeshwari Shinde57da3e32012-06-06 19:54:29 +0000881}
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000882
Masahiro Yamada366b24f2015-08-12 07:31:55 +0900883#if CONFIG_IS_ENABLED(OF_CONTROL)
Piotr Wilczek246ec3a2014-03-07 14:59:38 +0100884static int exynos4_pinmux_decode_periph_id(const void *blob, int node)
885{
886 int err;
887 u32 cell[3];
888
889 err = fdtdec_get_int_array(blob, node, "interrupts", cell,
890 ARRAY_SIZE(cell));
891 if (err) {
892 debug(" invalid peripheral id\n");
893 return PERIPH_ID_NONE;
894 }
895
896 return cell[1];
897}
898
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000899static int exynos5_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 return PERIPH_ID_NONE;
908
Minkyu Kangdcc99172014-01-29 17:04:17 +0900909 return cell[1];
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000910}
911
912int pinmux_decode_periph_id(const void *blob, int node)
913{
914 if (cpu_is_exynos5())
915 return exynos5_pinmux_decode_periph_id(blob, node);
Piotr Wilczek246ec3a2014-03-07 14:59:38 +0100916 else if (cpu_is_exynos4())
917 return exynos4_pinmux_decode_periph_id(blob, node);
Akshay Saraswat1376cdd2014-05-13 10:30:14 +0530918
919 return PERIPH_ID_NONE;
Rajeshwari Shinde28bae822012-12-26 20:03:11 +0000920}
921#endif