blob: ad3fbf2da7a86d1089bfddb67994c36d7f05fdc7 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Rajeshwari Shindec5e37102012-06-06 19:54:29 +00002/*
3 * Copyright (c) 2012 Samsung Electronics.
4 * Abhilash Kesavan <a.kesavan@samsung.com>
Rajeshwari Shindec5e37102012-06-06 19:54:29 +00005 */
6
7#include <common.h>
Rajeshwari Shinded0559112012-12-26 20:03:11 +00008#include <fdtdec.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06009#include <log.h>
Simon Glass903fd792014-10-20 19:48:37 -060010#include <asm/gpio.h>
Rajeshwari Shindec5e37102012-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 Shindec5e37102012-06-06 19:54:29 +000016 int i, start, count;
17
18 switch (peripheral) {
19 case PERIPH_ID_UART0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053020 start = EXYNOS5_GPIO_A00;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000021 count = 4;
22 break;
23 case PERIPH_ID_UART1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053024 start = EXYNOS5_GPIO_D00;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000025 count = 4;
26 break;
27 case PERIPH_ID_UART2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053028 start = EXYNOS5_GPIO_A10;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000029 count = 4;
30 break;
31 case PERIPH_ID_UART3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053032 start = EXYNOS5_GPIO_A14;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000033 count = 2;
34 break;
Marek Vasut47c9c762014-03-10 20:04:31 +010035 default:
36 debug("%s: invalid peripheral %d", __func__, peripheral);
37 return;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000038 }
39 for (i = start; i < start + count; i++) {
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053040 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
41 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000042 }
43}
44
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053045static void exynos5420_uart_config(int peripheral)
46{
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053047 int i, start, count;
48
49 switch (peripheral) {
50 case PERIPH_ID_UART0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053051 start = EXYNOS5420_GPIO_A00;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053052 count = 4;
53 break;
54 case PERIPH_ID_UART1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053055 start = EXYNOS5420_GPIO_A04;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053056 count = 4;
57 break;
58 case PERIPH_ID_UART2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053059 start = EXYNOS5420_GPIO_A10;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053060 count = 4;
61 break;
62 case PERIPH_ID_UART3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053063 start = EXYNOS5420_GPIO_A14;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053064 count = 2;
65 break;
Marek Vasut47c9c762014-03-10 20:04:31 +010066 default:
67 debug("%s: invalid peripheral %d", __func__, peripheral);
68 return;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053069 }
70
71 for (i = start; i < start + count; i++) {
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053072 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
73 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +053074 }
75}
76
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000077static int exynos5_mmc_config(int peripheral, int flags)
78{
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053079 int i, start, start_ext, gpio_func = 0;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000080
81 switch (peripheral) {
82 case PERIPH_ID_SDMMC0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053083 start = EXYNOS5_GPIO_C00;
84 start_ext = EXYNOS5_GPIO_C10;
85 gpio_func = S5P_GPIO_FUNC(0x2);
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000086 break;
87 case PERIPH_ID_SDMMC1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053088 start = EXYNOS5_GPIO_C20;
89 start_ext = 0;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000090 break;
91 case PERIPH_ID_SDMMC2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053092 start = EXYNOS5_GPIO_C30;
93 start_ext = EXYNOS5_GPIO_C43;
94 gpio_func = S5P_GPIO_FUNC(0x3);
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000095 break;
96 case PERIPH_ID_SDMMC3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +053097 start = EXYNOS5_GPIO_C40;
98 start_ext = 0;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +000099 break;
Marek Vasut47c9c762014-03-10 20:04:31 +0100100 default:
101 debug("%s: invalid peripheral %d", __func__, peripheral);
102 return -1;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000103 }
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530104 if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
Rajeshwari Shindec5e37102012-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 Saraswatf6ae1ca2014-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 Shindec5e37102012-06-06 19:54:29 +0000114 }
115 }
Akshay Saraswatf6ae1ca2014-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 Shindec5e37102012-06-06 19:54:29 +0000120 }
Akshay Saraswatf6ae1ca2014-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 Shindec5e37102012-06-06 19:54:29 +0000125 }
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000126
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000127 return 0;
128}
129
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530130static int exynos5420_mmc_config(int peripheral, int flags)
131{
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530132 int i, start = 0, start_ext = 0;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530133
134 switch (peripheral) {
135 case PERIPH_ID_SDMMC0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530136 start = EXYNOS5420_GPIO_C00;
137 start_ext = EXYNOS5420_GPIO_C30;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530138 break;
139 case PERIPH_ID_SDMMC1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530140 start = EXYNOS5420_GPIO_C10;
141 start_ext = EXYNOS5420_GPIO_D14;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530142 break;
143 case PERIPH_ID_SDMMC2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530144 start = EXYNOS5420_GPIO_C20;
145 start_ext = 0;
Rajeshwari Birje5af4a4f2013-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 Saraswatf6ae1ca2014-05-13 10:30:14 +0530153 if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
Rajeshwari Birje5af4a4f2013-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 Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530164 }
165 }
166
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530167 for (i = start; i < (start + 3); i++) {
Rajeshwari Birje5af4a4f2013-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 Saraswatf6ae1ca2014-05-13 10:30:14 +0530174 if ((peripheral == PERIPH_ID_SDMMC0) && (i == (start + 2))) {
Simon Glass7f196102014-10-20 19:48:39 -0600175#ifndef CONFIG_SPL_BUILD
176 gpio_request(i, "sdmmc0_vdden");
177#endif
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530178 gpio_set_value(i, 1);
179 gpio_cfg_pin(i, S5P_GPIO_OUTPUT);
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530180 } else {
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530181 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530182 }
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530183 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
184 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530185 }
186
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530191 }
192
193 return 0;
194}
195
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000196static void exynos5_sromc_config(int flags)
197{
Rajeshwari Shindec5e37102012-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 Saraswatf6ae1ca2014-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 Shindec5e37102012-06-06 19:54:29 +0000219
220 for (i = 0; i < 4; i++)
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530221 gpio_cfg_pin(EXYNOS5_GPIO_Y10 + i, S5P_GPIO_FUNC(2));
Rajeshwari Shindec5e37102012-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 Saraswatf6ae1ca2014-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 Shindec5e37102012-06-06 19:54:29 +0000258
Akshay Saraswatf6ae1ca2014-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 Shindec5e37102012-06-06 19:54:29 +0000261
Akshay Saraswatf6ae1ca2014-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 Shindec5e37102012-06-06 19:54:29 +0000264 }
265}
266
Rajeshwari Shindec65c05f2012-07-23 21:23:51 +0000267static void exynos5_i2c_config(int peripheral, int flags)
268{
Przemyslaw Marczakfda0e272015-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 Shindec65c05f2012-07-23 21:23:51 +0000280 switch (peripheral) {
281 case PERIPH_ID_I2C0:
Przemyslaw Marczakfda0e272015-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 Shindec65c05f2012-07-23 21:23:51 +0000284 break;
285 case PERIPH_ID_I2C1:
Przemyslaw Marczakfda0e272015-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 Shindec65c05f2012-07-23 21:23:51 +0000288 break;
289 case PERIPH_ID_I2C2:
Przemyslaw Marczakfda0e272015-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 Shindec65c05f2012-07-23 21:23:51 +0000292 break;
293 case PERIPH_ID_I2C3:
Przemyslaw Marczakfda0e272015-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 Shindec65c05f2012-07-23 21:23:51 +0000296 break;
297 case PERIPH_ID_I2C4:
Akshay Saraswatf6ae1ca2014-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 Shindec65c05f2012-07-23 21:23:51 +0000300 break;
301 case PERIPH_ID_I2C5:
Akshay Saraswatf6ae1ca2014-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 Shindec65c05f2012-07-23 21:23:51 +0000304 break;
305 case PERIPH_ID_I2C6:
Akshay Saraswatf6ae1ca2014-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 Shindec65c05f2012-07-23 21:23:51 +0000308 break;
309 case PERIPH_ID_I2C7:
Akshay Saraswatf6ae1ca2014-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 Shindec65c05f2012-07-23 21:23:51 +0000312 break;
313 }
314}
315
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530316static void exynos5420_i2c_config(int peripheral)
317{
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530318 switch (peripheral) {
319 case PERIPH_ID_I2C0:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530322 break;
323 case PERIPH_ID_I2C1:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530326 break;
327 case PERIPH_ID_I2C2:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530330 break;
331 case PERIPH_ID_I2C3:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530334 break;
335 case PERIPH_ID_I2C4:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530338 break;
339 case PERIPH_ID_I2C5:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530342 break;
343 case PERIPH_ID_I2C6:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530346 break;
347 case PERIPH_ID_I2C7:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530350 break;
351 case PERIPH_ID_I2C8:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530354 break;
355 case PERIPH_ID_I2C9:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530358 break;
359 case PERIPH_ID_I2C10:
Akshay Saraswatf6ae1ca2014-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 Birje5af4a4f2013-12-26 09:44:23 +0530362 break;
363 }
364}
365
Rajeshwari Shinde6b0884d2012-10-25 19:49:27 +0000366static void exynos5_i2s_config(int peripheral)
367{
368 int i;
Rajeshwari Shinde6b0884d2012-10-25 19:49:27 +0000369
Dani Krishna Mohan3dd22a32013-09-11 16:38:48 +0530370 switch (peripheral) {
371 case PERIPH_ID_I2S0:
372 for (i = 0; i < 5; i++)
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530373 gpio_cfg_pin(EXYNOS5_GPIO_Z0 + i, S5P_GPIO_FUNC(0x02));
Dani Krishna Mohan3dd22a32013-09-11 16:38:48 +0530374 break;
375 case PERIPH_ID_I2S1:
376 for (i = 0; i < 5; i++)
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530377 gpio_cfg_pin(EXYNOS5_GPIO_B00 + i, S5P_GPIO_FUNC(0x02));
Dani Krishna Mohan3dd22a32013-09-11 16:38:48 +0530378 break;
379 }
Rajeshwari Shinde6b0884d2012-10-25 19:49:27 +0000380}
381
Simon Glass482e5852018-12-10 10:37:41 -0700382static void exynos5420_i2s_config(int peripheral)
383{
384 int i;
385
386 switch (peripheral) {
387 case PERIPH_ID_I2S0:
388 for (i = 0; i < 5; i++)
389 gpio_cfg_pin(EXYNOS5420_GPIO_Z0 + i,
390 S5P_GPIO_FUNC(0x02));
391 break;
392 }
393}
394
395
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000396void exynos5_spi_config(int peripheral)
397{
398 int cfg = 0, pin = 0, i;
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000399
400 switch (peripheral) {
401 case PERIPH_ID_SPI0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530402 cfg = S5P_GPIO_FUNC(0x2);
403 pin = EXYNOS5_GPIO_A20;
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000404 break;
405 case PERIPH_ID_SPI1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530406 cfg = S5P_GPIO_FUNC(0x2);
407 pin = EXYNOS5_GPIO_A24;
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000408 break;
409 case PERIPH_ID_SPI2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530410 cfg = S5P_GPIO_FUNC(0x5);
411 pin = EXYNOS5_GPIO_B11;
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000412 break;
413 case PERIPH_ID_SPI3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530414 cfg = S5P_GPIO_FUNC(0x2);
415 pin = EXYNOS5_GPIO_F10;
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000416 break;
417 case PERIPH_ID_SPI4:
418 for (i = 0; i < 2; i++) {
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530419 gpio_cfg_pin(EXYNOS5_GPIO_F02 + i, S5P_GPIO_FUNC(0x4));
420 gpio_cfg_pin(EXYNOS5_GPIO_E04 + i, S5P_GPIO_FUNC(0x4));
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000421 }
422 break;
423 }
424 if (peripheral != PERIPH_ID_SPI4) {
425 for (i = pin; i < pin + 4; i++)
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530426 gpio_cfg_pin(i, cfg);
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000427 }
428}
429
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530430void exynos5420_spi_config(int peripheral)
431{
432 int cfg, pin, i;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530433
434 switch (peripheral) {
435 case PERIPH_ID_SPI0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530436 pin = EXYNOS5420_GPIO_A20;
437 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530438 break;
439 case PERIPH_ID_SPI1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530440 pin = EXYNOS5420_GPIO_A24;
441 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530442 break;
443 case PERIPH_ID_SPI2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530444 pin = EXYNOS5420_GPIO_B11;
445 cfg = S5P_GPIO_FUNC(0x5);
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530446 break;
447 case PERIPH_ID_SPI3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530448 pin = EXYNOS5420_GPIO_F10;
449 cfg = S5P_GPIO_FUNC(0x2);
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530450 break;
451 case PERIPH_ID_SPI4:
452 cfg = 0;
453 pin = 0;
454 break;
455 default:
456 cfg = 0;
457 pin = 0;
458 debug("%s: invalid peripheral %d", __func__, peripheral);
459 return;
460 }
461
462 if (peripheral != PERIPH_ID_SPI4) {
463 for (i = pin; i < pin + 4; i++)
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530464 gpio_cfg_pin(i, cfg);
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530465 } else {
466 for (i = 0; i < 2; i++) {
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530467 gpio_cfg_pin(EXYNOS5420_GPIO_F02 + i,
468 S5P_GPIO_FUNC(0x4));
469 gpio_cfg_pin(EXYNOS5420_GPIO_E04 + i,
470 S5P_GPIO_FUNC(0x4));
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530471 }
472 }
473}
474
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000475static int exynos5_pinmux_config(int peripheral, int flags)
476{
477 switch (peripheral) {
478 case PERIPH_ID_UART0:
479 case PERIPH_ID_UART1:
480 case PERIPH_ID_UART2:
481 case PERIPH_ID_UART3:
482 exynos5_uart_config(peripheral);
483 break;
484 case PERIPH_ID_SDMMC0:
485 case PERIPH_ID_SDMMC1:
486 case PERIPH_ID_SDMMC2:
487 case PERIPH_ID_SDMMC3:
488 return exynos5_mmc_config(peripheral, flags);
489 case PERIPH_ID_SROMC:
490 exynos5_sromc_config(flags);
491 break;
Rajeshwari Shindec65c05f2012-07-23 21:23:51 +0000492 case PERIPH_ID_I2C0:
493 case PERIPH_ID_I2C1:
494 case PERIPH_ID_I2C2:
495 case PERIPH_ID_I2C3:
496 case PERIPH_ID_I2C4:
497 case PERIPH_ID_I2C5:
498 case PERIPH_ID_I2C6:
499 case PERIPH_ID_I2C7:
500 exynos5_i2c_config(peripheral, flags);
501 break;
Dani Krishna Mohan3dd22a32013-09-11 16:38:48 +0530502 case PERIPH_ID_I2S0:
Rajeshwari Shinde6b0884d2012-10-25 19:49:27 +0000503 case PERIPH_ID_I2S1:
504 exynos5_i2s_config(peripheral);
505 break;
Rajeshwari Shindefbb57432012-10-28 19:32:54 +0000506 case PERIPH_ID_SPI0:
507 case PERIPH_ID_SPI1:
508 case PERIPH_ID_SPI2:
509 case PERIPH_ID_SPI3:
510 case PERIPH_ID_SPI4:
511 exynos5_spi_config(peripheral);
512 break;
Simon Glassa5074542015-07-02 18:16:13 -0600513 case PERIPH_ID_DPHPD:
514 /* Set Hotplug detect for DP */
515 gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
516
517 /*
518 * Hotplug detect should have an external pullup; disable the
519 * internal pulldown so they don't fight.
520 */
521 gpio_set_pull(EXYNOS5_GPIO_X07, S5P_GPIO_PULL_NONE);
522 break;
Simon Glassaf5b5ea2016-02-21 21:08:56 -0700523 case PERIPH_ID_PWM0:
524 gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_FUNC(2));
525 break;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000526 default:
527 debug("%s: invalid peripheral %d", __func__, peripheral);
528 return -1;
529 }
530
531 return 0;
532}
533
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530534static int exynos5420_pinmux_config(int peripheral, int flags)
535{
536 switch (peripheral) {
537 case PERIPH_ID_UART0:
538 case PERIPH_ID_UART1:
539 case PERIPH_ID_UART2:
540 case PERIPH_ID_UART3:
541 exynos5420_uart_config(peripheral);
542 break;
543 case PERIPH_ID_SDMMC0:
544 case PERIPH_ID_SDMMC1:
545 case PERIPH_ID_SDMMC2:
546 case PERIPH_ID_SDMMC3:
547 return exynos5420_mmc_config(peripheral, flags);
548 case PERIPH_ID_SPI0:
549 case PERIPH_ID_SPI1:
550 case PERIPH_ID_SPI2:
551 case PERIPH_ID_SPI3:
552 case PERIPH_ID_SPI4:
553 exynos5420_spi_config(peripheral);
554 break;
555 case PERIPH_ID_I2C0:
556 case PERIPH_ID_I2C1:
557 case PERIPH_ID_I2C2:
558 case PERIPH_ID_I2C3:
559 case PERIPH_ID_I2C4:
560 case PERIPH_ID_I2C5:
561 case PERIPH_ID_I2C6:
562 case PERIPH_ID_I2C7:
563 case PERIPH_ID_I2C8:
564 case PERIPH_ID_I2C9:
565 case PERIPH_ID_I2C10:
566 exynos5420_i2c_config(peripheral);
567 break;
Simon Glass482e5852018-12-10 10:37:41 -0700568 case PERIPH_ID_I2S0:
569 exynos5420_i2s_config(peripheral);
570 break;
Simon Glassaf5b5ea2016-02-21 21:08:56 -0700571 case PERIPH_ID_PWM0:
572 gpio_cfg_pin(EXYNOS5420_GPIO_B20, S5P_GPIO_FUNC(2));
573 break;
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530574 default:
575 debug("%s: invalid peripheral %d", __func__, peripheral);
576 return -1;
577 }
578
579 return 0;
580}
581
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000582static void exynos4_i2c_config(int peripheral, int flags)
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000583{
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000584 switch (peripheral) {
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000585 case PERIPH_ID_I2C0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530586 gpio_cfg_pin(EXYNOS4_GPIO_D10, S5P_GPIO_FUNC(0x2));
587 gpio_cfg_pin(EXYNOS4_GPIO_D11, S5P_GPIO_FUNC(0x2));
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000588 break;
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000589 case PERIPH_ID_I2C1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530590 gpio_cfg_pin(EXYNOS4_GPIO_D12, S5P_GPIO_FUNC(0x2));
591 gpio_cfg_pin(EXYNOS4_GPIO_D13, S5P_GPIO_FUNC(0x2));
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000592 break;
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000593 case PERIPH_ID_I2C2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530594 gpio_cfg_pin(EXYNOS4_GPIO_A06, S5P_GPIO_FUNC(0x3));
595 gpio_cfg_pin(EXYNOS4_GPIO_A07, S5P_GPIO_FUNC(0x3));
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000596 break;
597 case PERIPH_ID_I2C3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530598 gpio_cfg_pin(EXYNOS4_GPIO_A12, S5P_GPIO_FUNC(0x3));
599 gpio_cfg_pin(EXYNOS4_GPIO_A13, S5P_GPIO_FUNC(0x3));
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000600 break;
601 case PERIPH_ID_I2C4:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530602 gpio_cfg_pin(EXYNOS4_GPIO_B2, S5P_GPIO_FUNC(0x3));
603 gpio_cfg_pin(EXYNOS4_GPIO_B3, S5P_GPIO_FUNC(0x3));
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000604 break;
605 case PERIPH_ID_I2C5:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530606 gpio_cfg_pin(EXYNOS4_GPIO_B6, S5P_GPIO_FUNC(0x3));
607 gpio_cfg_pin(EXYNOS4_GPIO_B7, S5P_GPIO_FUNC(0x3));
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000608 break;
609 case PERIPH_ID_I2C6:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530610 gpio_cfg_pin(EXYNOS4_GPIO_C13, S5P_GPIO_FUNC(0x4));
611 gpio_cfg_pin(EXYNOS4_GPIO_C14, S5P_GPIO_FUNC(0x4));
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000612 break;
613 case PERIPH_ID_I2C7:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530614 gpio_cfg_pin(EXYNOS4_GPIO_D02, S5P_GPIO_FUNC(0x3));
615 gpio_cfg_pin(EXYNOS4_GPIO_D03, S5P_GPIO_FUNC(0x3));
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000616 break;
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000617 }
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000618}
619
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000620static int exynos4_mmc_config(int peripheral, int flags)
621{
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530622 int i, start = 0, start_ext = 0;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900623 unsigned int func, ext_func;
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000624
625 switch (peripheral) {
626 case PERIPH_ID_SDMMC0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530627 start = EXYNOS4_GPIO_K00;
628 start_ext = EXYNOS4_GPIO_K13;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900629 func = S5P_GPIO_FUNC(0x2);
630 ext_func = S5P_GPIO_FUNC(0x3);
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000631 break;
632 case PERIPH_ID_SDMMC2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530633 start = EXYNOS4_GPIO_K20;
634 start_ext = EXYNOS4_GPIO_K33;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900635 func = S5P_GPIO_FUNC(0x2);
636 ext_func = S5P_GPIO_FUNC(0x3);
637 break;
638 case PERIPH_ID_SDMMC4:
639 start = EXYNOS4_GPIO_K00;
640 start_ext = EXYNOS4_GPIO_K13;
641 func = S5P_GPIO_FUNC(0x3);
642 ext_func = S5P_GPIO_FUNC(0x4);
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000643 break;
644 default:
645 return -1;
646 }
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530647 for (i = start; i < (start + 7); i++) {
648 if (i == (start + 2))
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000649 continue;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900650 gpio_cfg_pin(i, func);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530651 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
652 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000653 }
Beomho Seo77ee62d2014-05-16 13:59:46 +0900654 /* SDMMC2 do not use 8bit mode at exynos4 */
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000655 if (flags & PINMUX_FLAG_8BIT_MODE) {
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530656 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo77ee62d2014-05-16 13:59:46 +0900657 gpio_cfg_pin(i, ext_func);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530658 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
659 gpio_set_drv(i, S5P_GPIO_DRV_4X);
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000660 }
661 }
662
663 return 0;
664}
665
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530666static void exynos4_uart_config(int peripheral)
667{
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530668 int i, start, count;
669
670 switch (peripheral) {
671 case PERIPH_ID_UART0:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530672 start = EXYNOS4_GPIO_A00;
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530673 count = 4;
674 break;
675 case PERIPH_ID_UART1:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530676 start = EXYNOS4_GPIO_A04;
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530677 count = 4;
678 break;
679 case PERIPH_ID_UART2:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530680 start = EXYNOS4_GPIO_A10;
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530681 count = 4;
682 break;
683 case PERIPH_ID_UART3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530684 start = EXYNOS4_GPIO_A14;
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530685 count = 2;
686 break;
Marek Vasut47c9c762014-03-10 20:04:31 +0100687 default:
688 debug("%s: invalid peripheral %d", __func__, peripheral);
689 return;
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530690 }
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530691 for (i = start; i < (start + count); i++) {
692 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
693 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530694 }
695}
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530696
697static void exynos4x12_i2c_config(int peripheral, int flags)
698{
699 switch (peripheral) {
700 case PERIPH_ID_I2C0:
701 gpio_cfg_pin(EXYNOS4X12_GPIO_D10, S5P_GPIO_FUNC(0x2));
702 gpio_cfg_pin(EXYNOS4X12_GPIO_D11, S5P_GPIO_FUNC(0x2));
703 break;
704 case PERIPH_ID_I2C1:
705 gpio_cfg_pin(EXYNOS4X12_GPIO_D12, S5P_GPIO_FUNC(0x2));
706 gpio_cfg_pin(EXYNOS4X12_GPIO_D13, S5P_GPIO_FUNC(0x2));
707 break;
708 case PERIPH_ID_I2C2:
709 gpio_cfg_pin(EXYNOS4X12_GPIO_A06, S5P_GPIO_FUNC(0x3));
710 gpio_cfg_pin(EXYNOS4X12_GPIO_A07, S5P_GPIO_FUNC(0x3));
711 break;
712 case PERIPH_ID_I2C3:
713 gpio_cfg_pin(EXYNOS4X12_GPIO_A12, S5P_GPIO_FUNC(0x3));
714 gpio_cfg_pin(EXYNOS4X12_GPIO_A13, S5P_GPIO_FUNC(0x3));
715 break;
716 case PERIPH_ID_I2C4:
717 gpio_cfg_pin(EXYNOS4X12_GPIO_B2, S5P_GPIO_FUNC(0x3));
718 gpio_cfg_pin(EXYNOS4X12_GPIO_B3, S5P_GPIO_FUNC(0x3));
719 break;
720 case PERIPH_ID_I2C5:
721 gpio_cfg_pin(EXYNOS4X12_GPIO_B6, S5P_GPIO_FUNC(0x3));
722 gpio_cfg_pin(EXYNOS4X12_GPIO_B7, S5P_GPIO_FUNC(0x3));
723 break;
724 case PERIPH_ID_I2C6:
725 gpio_cfg_pin(EXYNOS4X12_GPIO_C13, S5P_GPIO_FUNC(0x4));
726 gpio_cfg_pin(EXYNOS4X12_GPIO_C14, S5P_GPIO_FUNC(0x4));
727 break;
728 case PERIPH_ID_I2C7:
729 gpio_cfg_pin(EXYNOS4X12_GPIO_D02, S5P_GPIO_FUNC(0x3));
730 gpio_cfg_pin(EXYNOS4X12_GPIO_D03, S5P_GPIO_FUNC(0x3));
731 break;
732 }
733}
734
735static int exynos4x12_mmc_config(int peripheral, int flags)
736{
737 int i, start = 0, start_ext = 0;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900738 unsigned int func, ext_func;
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530739
740 switch (peripheral) {
741 case PERIPH_ID_SDMMC0:
742 start = EXYNOS4X12_GPIO_K00;
743 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900744 func = S5P_GPIO_FUNC(0x2);
745 ext_func = S5P_GPIO_FUNC(0x3);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530746 break;
747 case PERIPH_ID_SDMMC2:
748 start = EXYNOS4X12_GPIO_K20;
749 start_ext = EXYNOS4X12_GPIO_K33;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900750 func = S5P_GPIO_FUNC(0x2);
751 ext_func = S5P_GPIO_FUNC(0x3);
752 break;
753 case PERIPH_ID_SDMMC4:
Przemyslaw Marczak19f1b622014-09-01 13:50:43 +0200754 start = EXYNOS4X12_GPIO_K00;
755 start_ext = EXYNOS4X12_GPIO_K13;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900756 func = S5P_GPIO_FUNC(0x3);
757 ext_func = S5P_GPIO_FUNC(0x4);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530758 break;
759 default:
760 return -1;
761 }
762 for (i = start; i < (start + 7); i++) {
Przemyslaw Marczak5d043432015-10-28 15:41:49 +0100763 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530764 if (i == (start + 2))
765 continue;
Beomho Seo77ee62d2014-05-16 13:59:46 +0900766 gpio_cfg_pin(i, func);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530767 gpio_set_drv(i, S5P_GPIO_DRV_4X);
768 }
769 if (flags & PINMUX_FLAG_8BIT_MODE) {
770 for (i = start_ext; i < (start_ext + 4); i++) {
Beomho Seo77ee62d2014-05-16 13:59:46 +0900771 gpio_cfg_pin(i, ext_func);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530772 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
773 gpio_set_drv(i, S5P_GPIO_DRV_4X);
774 }
775 }
776
777 return 0;
778}
779
780static void exynos4x12_uart_config(int peripheral)
781{
782 int i, start, count;
783
784 switch (peripheral) {
785 case PERIPH_ID_UART0:
786 start = EXYNOS4X12_GPIO_A00;
787 count = 4;
788 break;
789 case PERIPH_ID_UART1:
790 start = EXYNOS4X12_GPIO_A04;
791 count = 4;
792 break;
793 case PERIPH_ID_UART2:
794 start = EXYNOS4X12_GPIO_A10;
795 count = 4;
796 break;
797 case PERIPH_ID_UART3:
798 start = EXYNOS4X12_GPIO_A14;
799 count = 2;
800 break;
801 default:
802 debug("%s: invalid peripheral %d", __func__, peripheral);
803 return;
804 }
805 for (i = start; i < (start + count); i++) {
806 gpio_set_pull(i, S5P_GPIO_PULL_NONE);
807 gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
808 }
809}
810
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000811static int exynos4_pinmux_config(int peripheral, int flags)
812{
813 switch (peripheral) {
Rajeshwari Shinde198a40b2013-07-04 12:29:16 +0530814 case PERIPH_ID_UART0:
815 case PERIPH_ID_UART1:
816 case PERIPH_ID_UART2:
817 case PERIPH_ID_UART3:
818 exynos4_uart_config(peripheral);
819 break;
Piotr Wilczek89bd58a2012-11-20 02:19:04 +0000820 case PERIPH_ID_I2C0:
821 case PERIPH_ID_I2C1:
822 case PERIPH_ID_I2C2:
823 case PERIPH_ID_I2C3:
824 case PERIPH_ID_I2C4:
825 case PERIPH_ID_I2C5:
826 case PERIPH_ID_I2C6:
827 case PERIPH_ID_I2C7:
828 exynos4_i2c_config(peripheral, flags);
829 break;
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000830 case PERIPH_ID_SDMMC0:
831 case PERIPH_ID_SDMMC2:
Beomho Seo77ee62d2014-05-16 13:59:46 +0900832 case PERIPH_ID_SDMMC4:
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000833 return exynos4_mmc_config(peripheral, flags);
834 case PERIPH_ID_SDMMC1:
835 case PERIPH_ID_SDMMC3:
Rajeshwari Shinde347e45d2013-10-08 18:42:22 +0530836 debug("SDMMC device %d not implemented\n", peripheral);
Piotr Wilczek7a84e1f2013-01-02 21:31:00 +0000837 return -1;
Piotr Wilczeka3eab2a2012-09-20 00:19:57 +0000838 default:
839 debug("%s: invalid peripheral %d", __func__, peripheral);
840 return -1;
841 }
842
843 return 0;
844}
845
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530846static int exynos4x12_pinmux_config(int peripheral, int flags)
847{
848 switch (peripheral) {
849 case PERIPH_ID_UART0:
850 case PERIPH_ID_UART1:
851 case PERIPH_ID_UART2:
852 case PERIPH_ID_UART3:
853 exynos4x12_uart_config(peripheral);
854 break;
855 case PERIPH_ID_I2C0:
856 case PERIPH_ID_I2C1:
857 case PERIPH_ID_I2C2:
858 case PERIPH_ID_I2C3:
859 case PERIPH_ID_I2C4:
860 case PERIPH_ID_I2C5:
861 case PERIPH_ID_I2C6:
862 case PERIPH_ID_I2C7:
863 exynos4x12_i2c_config(peripheral, flags);
864 break;
865 case PERIPH_ID_SDMMC0:
866 case PERIPH_ID_SDMMC2:
Beomho Seo77ee62d2014-05-16 13:59:46 +0900867 case PERIPH_ID_SDMMC4:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530868 return exynos4x12_mmc_config(peripheral, flags);
869 case PERIPH_ID_SDMMC1:
870 case PERIPH_ID_SDMMC3:
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530871 debug("SDMMC device %d not implemented\n", peripheral);
872 return -1;
873 default:
874 debug("%s: invalid peripheral %d", __func__, peripheral);
875 return -1;
876 }
877
878 return 0;
879}
880
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000881int exynos_pinmux_config(int peripheral, int flags)
882{
Dani Krishna Mohan3dd22a32013-09-11 16:38:48 +0530883 if (cpu_is_exynos5()) {
Simon Glasscf9007c2018-12-10 10:37:40 -0700884 if (proid_is_exynos542x())
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530885 return exynos5420_pinmux_config(peripheral, flags);
886 else if (proid_is_exynos5250())
887 return exynos5_pinmux_config(peripheral, flags);
Dani Krishna Mohan3dd22a32013-09-11 16:38:48 +0530888 } else if (cpu_is_exynos4()) {
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530889 if (proid_is_exynos4412())
890 return exynos4x12_pinmux_config(peripheral, flags);
891 else
892 return exynos4_pinmux_config(peripheral, flags);
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000893 }
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530894
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530895 debug("pinmux functionality not supported\n");
896
Rajeshwari Birje5af4a4f2013-12-26 09:44:23 +0530897 return -1;
Rajeshwari Shindec5e37102012-06-06 19:54:29 +0000898}
Rajeshwari Shinded0559112012-12-26 20:03:11 +0000899
Masahiro Yamada0f925822015-08-12 07:31:55 +0900900#if CONFIG_IS_ENABLED(OF_CONTROL)
Piotr Wilczekb8dfcdb2014-03-07 14:59:38 +0100901static int exynos4_pinmux_decode_periph_id(const void *blob, int node)
902{
903 int err;
904 u32 cell[3];
905
906 err = fdtdec_get_int_array(blob, node, "interrupts", cell,
907 ARRAY_SIZE(cell));
908 if (err) {
909 debug(" invalid peripheral id\n");
910 return PERIPH_ID_NONE;
911 }
912
913 return cell[1];
914}
915
Rajeshwari Shinded0559112012-12-26 20:03:11 +0000916static int exynos5_pinmux_decode_periph_id(const void *blob, int node)
917{
918 int err;
919 u32 cell[3];
920
921 err = fdtdec_get_int_array(blob, node, "interrupts", cell,
922 ARRAY_SIZE(cell));
923 if (err)
924 return PERIPH_ID_NONE;
925
Minkyu Kang0ab9a032014-01-29 17:04:17 +0900926 return cell[1];
Rajeshwari Shinded0559112012-12-26 20:03:11 +0000927}
928
929int pinmux_decode_periph_id(const void *blob, int node)
930{
931 if (cpu_is_exynos5())
932 return exynos5_pinmux_decode_periph_id(blob, node);
Piotr Wilczekb8dfcdb2014-03-07 14:59:38 +0100933 else if (cpu_is_exynos4())
934 return exynos4_pinmux_decode_periph_id(blob, node);
Akshay Saraswatf6ae1ca2014-05-13 10:30:14 +0530935
936 return PERIPH_ID_NONE;
Rajeshwari Shinded0559112012-12-26 20:03:11 +0000937}
938#endif