177b55e8cSThomas Abraham /*
277b55e8cSThomas Abraham * Copyright (c) 2012 Samsung Electronics.
377b55e8cSThomas Abraham * Abhilash Kesavan <a.kesavan@samsung.com>
477b55e8cSThomas Abraham *
577b55e8cSThomas Abraham * SPDX-License-Identifier: GPL-2.0+
677b55e8cSThomas Abraham */
777b55e8cSThomas Abraham
877b55e8cSThomas Abraham #include <common.h>
977b55e8cSThomas Abraham #include <fdtdec.h>
1077b55e8cSThomas Abraham #include <asm/gpio.h>
1177b55e8cSThomas Abraham #include <asm/arch/pinmux.h>
1277b55e8cSThomas Abraham #include <asm/arch/sromc.h>
1377b55e8cSThomas Abraham
exynos5_uart_config(int peripheral)1477b55e8cSThomas Abraham static void exynos5_uart_config(int peripheral)
1577b55e8cSThomas Abraham {
1677b55e8cSThomas Abraham int i, start, count;
1777b55e8cSThomas Abraham
1877b55e8cSThomas Abraham switch (peripheral) {
1977b55e8cSThomas Abraham case PERIPH_ID_UART0:
2077b55e8cSThomas Abraham start = EXYNOS5_GPIO_A00;
2177b55e8cSThomas Abraham count = 4;
2277b55e8cSThomas Abraham break;
2377b55e8cSThomas Abraham case PERIPH_ID_UART1:
2477b55e8cSThomas Abraham start = EXYNOS5_GPIO_D00;
2577b55e8cSThomas Abraham count = 4;
2677b55e8cSThomas Abraham break;
2777b55e8cSThomas Abraham case PERIPH_ID_UART2:
2877b55e8cSThomas Abraham start = EXYNOS5_GPIO_A10;
2977b55e8cSThomas Abraham count = 4;
3077b55e8cSThomas Abraham break;
3177b55e8cSThomas Abraham case PERIPH_ID_UART3:
3277b55e8cSThomas Abraham start = EXYNOS5_GPIO_A14;
3377b55e8cSThomas Abraham count = 2;
3477b55e8cSThomas Abraham break;
3577b55e8cSThomas Abraham default:
3677b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
3777b55e8cSThomas Abraham return;
3877b55e8cSThomas Abraham }
3977b55e8cSThomas Abraham for (i = start; i < start + count; i++) {
4077b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
4177b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
4277b55e8cSThomas Abraham }
4377b55e8cSThomas Abraham }
4477b55e8cSThomas Abraham
exynos5420_uart_config(int peripheral)4577b55e8cSThomas Abraham static void exynos5420_uart_config(int peripheral)
4677b55e8cSThomas Abraham {
4777b55e8cSThomas Abraham int i, start, count;
4877b55e8cSThomas Abraham
4977b55e8cSThomas Abraham switch (peripheral) {
5077b55e8cSThomas Abraham case PERIPH_ID_UART0:
5177b55e8cSThomas Abraham start = EXYNOS5420_GPIO_A00;
5277b55e8cSThomas Abraham count = 4;
5377b55e8cSThomas Abraham break;
5477b55e8cSThomas Abraham case PERIPH_ID_UART1:
5577b55e8cSThomas Abraham start = EXYNOS5420_GPIO_A04;
5677b55e8cSThomas Abraham count = 4;
5777b55e8cSThomas Abraham break;
5877b55e8cSThomas Abraham case PERIPH_ID_UART2:
5977b55e8cSThomas Abraham start = EXYNOS5420_GPIO_A10;
6077b55e8cSThomas Abraham count = 4;
6177b55e8cSThomas Abraham break;
6277b55e8cSThomas Abraham case PERIPH_ID_UART3:
6377b55e8cSThomas Abraham start = EXYNOS5420_GPIO_A14;
6477b55e8cSThomas Abraham count = 2;
6577b55e8cSThomas Abraham break;
6677b55e8cSThomas Abraham default:
6777b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
6877b55e8cSThomas Abraham return;
6977b55e8cSThomas Abraham }
7077b55e8cSThomas Abraham
7177b55e8cSThomas Abraham for (i = start; i < start + count; i++) {
7277b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
7377b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
7477b55e8cSThomas Abraham }
7577b55e8cSThomas Abraham }
7677b55e8cSThomas Abraham
exynos5_mmc_config(int peripheral,int flags)7777b55e8cSThomas Abraham static int exynos5_mmc_config(int peripheral, int flags)
7877b55e8cSThomas Abraham {
7977b55e8cSThomas Abraham int i, start, start_ext, gpio_func = 0;
8077b55e8cSThomas Abraham
8177b55e8cSThomas Abraham switch (peripheral) {
8277b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
8377b55e8cSThomas Abraham start = EXYNOS5_GPIO_C00;
8477b55e8cSThomas Abraham start_ext = EXYNOS5_GPIO_C10;
8577b55e8cSThomas Abraham gpio_func = S5P_GPIO_FUNC(0x2);
8677b55e8cSThomas Abraham break;
8777b55e8cSThomas Abraham case PERIPH_ID_SDMMC1:
8877b55e8cSThomas Abraham start = EXYNOS5_GPIO_C20;
8977b55e8cSThomas Abraham start_ext = 0;
9077b55e8cSThomas Abraham break;
9177b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
9277b55e8cSThomas Abraham start = EXYNOS5_GPIO_C30;
9377b55e8cSThomas Abraham start_ext = EXYNOS5_GPIO_C43;
9477b55e8cSThomas Abraham gpio_func = S5P_GPIO_FUNC(0x3);
9577b55e8cSThomas Abraham break;
9677b55e8cSThomas Abraham case PERIPH_ID_SDMMC3:
9777b55e8cSThomas Abraham start = EXYNOS5_GPIO_C40;
9877b55e8cSThomas Abraham start_ext = 0;
9977b55e8cSThomas Abraham break;
10077b55e8cSThomas Abraham default:
10177b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
10277b55e8cSThomas Abraham return -1;
10377b55e8cSThomas Abraham }
10477b55e8cSThomas Abraham if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
10577b55e8cSThomas Abraham debug("SDMMC device %d does not support 8bit mode",
10677b55e8cSThomas Abraham peripheral);
10777b55e8cSThomas Abraham return -1;
10877b55e8cSThomas Abraham }
10977b55e8cSThomas Abraham if (flags & PINMUX_FLAG_8BIT_MODE) {
11077b55e8cSThomas Abraham for (i = start_ext; i <= (start_ext + 3); i++) {
11177b55e8cSThomas Abraham gpio_cfg_pin(i, gpio_func);
11277b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_UP);
11377b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
11477b55e8cSThomas Abraham }
11577b55e8cSThomas Abraham }
11677b55e8cSThomas Abraham for (i = start; i < (start + 2); i++) {
11777b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
11877b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
11977b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
12077b55e8cSThomas Abraham }
12177b55e8cSThomas Abraham for (i = (start + 3); i <= (start + 6); i++) {
12277b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
12377b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_UP);
12477b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
12577b55e8cSThomas Abraham }
12677b55e8cSThomas Abraham
12777b55e8cSThomas Abraham return 0;
12877b55e8cSThomas Abraham }
12977b55e8cSThomas Abraham
exynos5420_mmc_config(int peripheral,int flags)13077b55e8cSThomas Abraham static int exynos5420_mmc_config(int peripheral, int flags)
13177b55e8cSThomas Abraham {
13277b55e8cSThomas Abraham int i, start = 0, start_ext = 0;
13377b55e8cSThomas Abraham
13477b55e8cSThomas Abraham switch (peripheral) {
13577b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
13677b55e8cSThomas Abraham start = EXYNOS5420_GPIO_C00;
13777b55e8cSThomas Abraham start_ext = EXYNOS5420_GPIO_C30;
13877b55e8cSThomas Abraham break;
13977b55e8cSThomas Abraham case PERIPH_ID_SDMMC1:
14077b55e8cSThomas Abraham start = EXYNOS5420_GPIO_C10;
14177b55e8cSThomas Abraham start_ext = EXYNOS5420_GPIO_D14;
14277b55e8cSThomas Abraham break;
14377b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
14477b55e8cSThomas Abraham start = EXYNOS5420_GPIO_C20;
14577b55e8cSThomas Abraham start_ext = 0;
14677b55e8cSThomas Abraham break;
14777b55e8cSThomas Abraham default:
14877b55e8cSThomas Abraham start = 0;
14977b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
15077b55e8cSThomas Abraham return -1;
15177b55e8cSThomas Abraham }
15277b55e8cSThomas Abraham
15377b55e8cSThomas Abraham if ((flags & PINMUX_FLAG_8BIT_MODE) && !start_ext) {
15477b55e8cSThomas Abraham debug("SDMMC device %d does not support 8bit mode",
15577b55e8cSThomas Abraham peripheral);
15677b55e8cSThomas Abraham return -1;
15777b55e8cSThomas Abraham }
15877b55e8cSThomas Abraham
15977b55e8cSThomas Abraham if (flags & PINMUX_FLAG_8BIT_MODE) {
16077b55e8cSThomas Abraham for (i = start_ext; i <= (start_ext + 3); i++) {
16177b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
16277b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_UP);
16377b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
16477b55e8cSThomas Abraham }
16577b55e8cSThomas Abraham }
16677b55e8cSThomas Abraham
16777b55e8cSThomas Abraham for (i = start; i < (start + 3); i++) {
16877b55e8cSThomas Abraham /*
16977b55e8cSThomas Abraham * MMC0 is intended to be used for eMMC. The
17077b55e8cSThomas Abraham * card detect pin is used as a VDDEN signal to
17177b55e8cSThomas Abraham * power on the eMMC. The 5420 iROM makes
17277b55e8cSThomas Abraham * this same assumption.
17377b55e8cSThomas Abraham */
17477b55e8cSThomas Abraham if ((peripheral == PERIPH_ID_SDMMC0) && (i == (start + 2))) {
17577b55e8cSThomas Abraham #ifndef CONFIG_SPL_BUILD
17677b55e8cSThomas Abraham gpio_request(i, "sdmmc0_vdden");
17777b55e8cSThomas Abraham #endif
17877b55e8cSThomas Abraham gpio_set_value(i, 1);
17977b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_OUTPUT);
18077b55e8cSThomas Abraham } else {
18177b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
18277b55e8cSThomas Abraham }
18377b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
18477b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
18577b55e8cSThomas Abraham }
18677b55e8cSThomas Abraham
18777b55e8cSThomas Abraham for (i = (start + 3); i <= (start + 6); i++) {
18877b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
18977b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_UP);
19077b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
19177b55e8cSThomas Abraham }
19277b55e8cSThomas Abraham
19377b55e8cSThomas Abraham return 0;
19477b55e8cSThomas Abraham }
19577b55e8cSThomas Abraham
exynos5_sromc_config(int flags)19677b55e8cSThomas Abraham static void exynos5_sromc_config(int flags)
19777b55e8cSThomas Abraham {
19877b55e8cSThomas Abraham int i;
19977b55e8cSThomas Abraham
20077b55e8cSThomas Abraham /*
20177b55e8cSThomas Abraham * SROM:CS1 and EBI
20277b55e8cSThomas Abraham *
20377b55e8cSThomas Abraham * GPY0[0] SROM_CSn[0]
20477b55e8cSThomas Abraham * GPY0[1] SROM_CSn[1](2)
20577b55e8cSThomas Abraham * GPY0[2] SROM_CSn[2]
20677b55e8cSThomas Abraham * GPY0[3] SROM_CSn[3]
20777b55e8cSThomas Abraham * GPY0[4] EBI_OEn(2)
20877b55e8cSThomas Abraham * GPY0[5] EBI_EEn(2)
20977b55e8cSThomas Abraham *
21077b55e8cSThomas Abraham * GPY1[0] EBI_BEn[0](2)
21177b55e8cSThomas Abraham * GPY1[1] EBI_BEn[1](2)
21277b55e8cSThomas Abraham * GPY1[2] SROM_WAIT(2)
21377b55e8cSThomas Abraham * GPY1[3] EBI_DATA_RDn(2)
21477b55e8cSThomas Abraham */
21577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Y00 + (flags & PINMUX_FLAG_BANK),
21677b55e8cSThomas Abraham S5P_GPIO_FUNC(2));
21777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Y04, S5P_GPIO_FUNC(2));
21877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Y05, S5P_GPIO_FUNC(2));
21977b55e8cSThomas Abraham
22077b55e8cSThomas Abraham for (i = 0; i < 4; i++)
22177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Y10 + i, S5P_GPIO_FUNC(2));
22277b55e8cSThomas Abraham
22377b55e8cSThomas Abraham /*
22477b55e8cSThomas Abraham * EBI: 8 Addrss Lines
22577b55e8cSThomas Abraham *
22677b55e8cSThomas Abraham * GPY3[0] EBI_ADDR[0](2)
22777b55e8cSThomas Abraham * GPY3[1] EBI_ADDR[1](2)
22877b55e8cSThomas Abraham * GPY3[2] EBI_ADDR[2](2)
22977b55e8cSThomas Abraham * GPY3[3] EBI_ADDR[3](2)
23077b55e8cSThomas Abraham * GPY3[4] EBI_ADDR[4](2)
23177b55e8cSThomas Abraham * GPY3[5] EBI_ADDR[5](2)
23277b55e8cSThomas Abraham * GPY3[6] EBI_ADDR[6](2)
23377b55e8cSThomas Abraham * GPY3[7] EBI_ADDR[7](2)
23477b55e8cSThomas Abraham *
23577b55e8cSThomas Abraham * EBI: 16 Data Lines
23677b55e8cSThomas Abraham *
23777b55e8cSThomas Abraham * GPY5[0] EBI_DATA[0](2)
23877b55e8cSThomas Abraham * GPY5[1] EBI_DATA[1](2)
23977b55e8cSThomas Abraham * GPY5[2] EBI_DATA[2](2)
24077b55e8cSThomas Abraham * GPY5[3] EBI_DATA[3](2)
24177b55e8cSThomas Abraham * GPY5[4] EBI_DATA[4](2)
24277b55e8cSThomas Abraham * GPY5[5] EBI_DATA[5](2)
24377b55e8cSThomas Abraham * GPY5[6] EBI_DATA[6](2)
24477b55e8cSThomas Abraham * GPY5[7] EBI_DATA[7](2)
24577b55e8cSThomas Abraham *
24677b55e8cSThomas Abraham * GPY6[0] EBI_DATA[8](2)
24777b55e8cSThomas Abraham * GPY6[1] EBI_DATA[9](2)
24877b55e8cSThomas Abraham * GPY6[2] EBI_DATA[10](2)
24977b55e8cSThomas Abraham * GPY6[3] EBI_DATA[11](2)
25077b55e8cSThomas Abraham * GPY6[4] EBI_DATA[12](2)
25177b55e8cSThomas Abraham * GPY6[5] EBI_DATA[13](2)
25277b55e8cSThomas Abraham * GPY6[6] EBI_DATA[14](2)
25377b55e8cSThomas Abraham * GPY6[7] EBI_DATA[15](2)
25477b55e8cSThomas Abraham */
25577b55e8cSThomas Abraham for (i = 0; i < 8; i++) {
25677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_FUNC(2));
25777b55e8cSThomas Abraham gpio_set_pull(EXYNOS5_GPIO_Y30 + i, S5P_GPIO_PULL_UP);
25877b55e8cSThomas Abraham
25977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_FUNC(2));
26077b55e8cSThomas Abraham gpio_set_pull(EXYNOS5_GPIO_Y50 + i, S5P_GPIO_PULL_UP);
26177b55e8cSThomas Abraham
26277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_FUNC(2));
26377b55e8cSThomas Abraham gpio_set_pull(EXYNOS5_GPIO_Y60 + i, S5P_GPIO_PULL_UP);
26477b55e8cSThomas Abraham }
26577b55e8cSThomas Abraham }
26677b55e8cSThomas Abraham
exynos5_i2c_config(int peripheral,int flags)26777b55e8cSThomas Abraham static void exynos5_i2c_config(int peripheral, int flags)
26877b55e8cSThomas Abraham {
26977b55e8cSThomas Abraham int func01, func23;
27077b55e8cSThomas Abraham
27177b55e8cSThomas Abraham /* High-Speed I2C */
27277b55e8cSThomas Abraham if (flags & PINMUX_FLAG_HS_MODE) {
27377b55e8cSThomas Abraham func01 = 4;
27477b55e8cSThomas Abraham func23 = 4;
27577b55e8cSThomas Abraham } else {
27677b55e8cSThomas Abraham func01 = 2;
27777b55e8cSThomas Abraham func23 = 3;
27877b55e8cSThomas Abraham }
27977b55e8cSThomas Abraham
28077b55e8cSThomas Abraham switch (peripheral) {
28177b55e8cSThomas Abraham case PERIPH_ID_I2C0:
28277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B30, S5P_GPIO_FUNC(func01));
28377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B31, S5P_GPIO_FUNC(func01));
28477b55e8cSThomas Abraham break;
28577b55e8cSThomas Abraham case PERIPH_ID_I2C1:
28677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B32, S5P_GPIO_FUNC(func01));
28777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B33, S5P_GPIO_FUNC(func01));
28877b55e8cSThomas Abraham break;
28977b55e8cSThomas Abraham case PERIPH_ID_I2C2:
29077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A06, S5P_GPIO_FUNC(func23));
29177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A07, S5P_GPIO_FUNC(func23));
29277b55e8cSThomas Abraham break;
29377b55e8cSThomas Abraham case PERIPH_ID_I2C3:
29477b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A12, S5P_GPIO_FUNC(func23));
29577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A13, S5P_GPIO_FUNC(func23));
29677b55e8cSThomas Abraham break;
29777b55e8cSThomas Abraham case PERIPH_ID_I2C4:
29877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A20, S5P_GPIO_FUNC(0x3));
29977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A21, S5P_GPIO_FUNC(0x3));
30077b55e8cSThomas Abraham break;
30177b55e8cSThomas Abraham case PERIPH_ID_I2C5:
30277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A22, S5P_GPIO_FUNC(0x3));
30377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_A23, S5P_GPIO_FUNC(0x3));
30477b55e8cSThomas Abraham break;
30577b55e8cSThomas Abraham case PERIPH_ID_I2C6:
30677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B13, S5P_GPIO_FUNC(0x4));
30777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B14, S5P_GPIO_FUNC(0x4));
30877b55e8cSThomas Abraham break;
30977b55e8cSThomas Abraham case PERIPH_ID_I2C7:
31077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B22, S5P_GPIO_FUNC(0x3));
31177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B23, S5P_GPIO_FUNC(0x3));
31277b55e8cSThomas Abraham break;
31377b55e8cSThomas Abraham }
31477b55e8cSThomas Abraham }
31577b55e8cSThomas Abraham
exynos5420_i2c_config(int peripheral)31677b55e8cSThomas Abraham static void exynos5420_i2c_config(int peripheral)
31777b55e8cSThomas Abraham {
31877b55e8cSThomas Abraham switch (peripheral) {
31977b55e8cSThomas Abraham case PERIPH_ID_I2C0:
32077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B30, S5P_GPIO_FUNC(0x2));
32177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B31, S5P_GPIO_FUNC(0x2));
32277b55e8cSThomas Abraham break;
32377b55e8cSThomas Abraham case PERIPH_ID_I2C1:
32477b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B32, S5P_GPIO_FUNC(0x2));
32577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B33, S5P_GPIO_FUNC(0x2));
32677b55e8cSThomas Abraham break;
32777b55e8cSThomas Abraham case PERIPH_ID_I2C2:
32877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A06, S5P_GPIO_FUNC(0x3));
32977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A07, S5P_GPIO_FUNC(0x3));
33077b55e8cSThomas Abraham break;
33177b55e8cSThomas Abraham case PERIPH_ID_I2C3:
33277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A12, S5P_GPIO_FUNC(0x3));
33377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A13, S5P_GPIO_FUNC(0x3));
33477b55e8cSThomas Abraham break;
33577b55e8cSThomas Abraham case PERIPH_ID_I2C4:
33677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A20, S5P_GPIO_FUNC(0x3));
33777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A21, S5P_GPIO_FUNC(0x3));
33877b55e8cSThomas Abraham break;
33977b55e8cSThomas Abraham case PERIPH_ID_I2C5:
34077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A22, S5P_GPIO_FUNC(0x3));
34177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_A23, S5P_GPIO_FUNC(0x3));
34277b55e8cSThomas Abraham break;
34377b55e8cSThomas Abraham case PERIPH_ID_I2C6:
34477b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B13, S5P_GPIO_FUNC(0x4));
34577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B14, S5P_GPIO_FUNC(0x4));
34677b55e8cSThomas Abraham break;
34777b55e8cSThomas Abraham case PERIPH_ID_I2C7:
34877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B22, S5P_GPIO_FUNC(0x3));
34977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B23, S5P_GPIO_FUNC(0x3));
35077b55e8cSThomas Abraham break;
35177b55e8cSThomas Abraham case PERIPH_ID_I2C8:
35277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B34, S5P_GPIO_FUNC(0x2));
35377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B35, S5P_GPIO_FUNC(0x2));
35477b55e8cSThomas Abraham break;
35577b55e8cSThomas Abraham case PERIPH_ID_I2C9:
35677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B36, S5P_GPIO_FUNC(0x2));
35777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B37, S5P_GPIO_FUNC(0x2));
35877b55e8cSThomas Abraham break;
35977b55e8cSThomas Abraham case PERIPH_ID_I2C10:
36077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B40, S5P_GPIO_FUNC(0x2));
36177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_B41, S5P_GPIO_FUNC(0x2));
36277b55e8cSThomas Abraham break;
36377b55e8cSThomas Abraham }
36477b55e8cSThomas Abraham }
36577b55e8cSThomas Abraham
exynos5_i2s_config(int peripheral)36677b55e8cSThomas Abraham static void exynos5_i2s_config(int peripheral)
36777b55e8cSThomas Abraham {
36877b55e8cSThomas Abraham int i;
36977b55e8cSThomas Abraham
37077b55e8cSThomas Abraham switch (peripheral) {
37177b55e8cSThomas Abraham case PERIPH_ID_I2S0:
37277b55e8cSThomas Abraham for (i = 0; i < 5; i++)
37377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_Z0 + i, S5P_GPIO_FUNC(0x02));
37477b55e8cSThomas Abraham break;
37577b55e8cSThomas Abraham case PERIPH_ID_I2S1:
37677b55e8cSThomas Abraham for (i = 0; i < 5; i++)
37777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_B00 + i, S5P_GPIO_FUNC(0x02));
37877b55e8cSThomas Abraham break;
37977b55e8cSThomas Abraham }
38077b55e8cSThomas Abraham }
38177b55e8cSThomas Abraham
exynos5_spi_config(int peripheral)38277b55e8cSThomas Abraham void exynos5_spi_config(int peripheral)
38377b55e8cSThomas Abraham {
38477b55e8cSThomas Abraham int cfg = 0, pin = 0, i;
38577b55e8cSThomas Abraham
38677b55e8cSThomas Abraham switch (peripheral) {
38777b55e8cSThomas Abraham case PERIPH_ID_SPI0:
38877b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x2);
38977b55e8cSThomas Abraham pin = EXYNOS5_GPIO_A20;
39077b55e8cSThomas Abraham break;
39177b55e8cSThomas Abraham case PERIPH_ID_SPI1:
39277b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x2);
39377b55e8cSThomas Abraham pin = EXYNOS5_GPIO_A24;
39477b55e8cSThomas Abraham break;
39577b55e8cSThomas Abraham case PERIPH_ID_SPI2:
39677b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x5);
39777b55e8cSThomas Abraham pin = EXYNOS5_GPIO_B11;
39877b55e8cSThomas Abraham break;
39977b55e8cSThomas Abraham case PERIPH_ID_SPI3:
40077b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x2);
40177b55e8cSThomas Abraham pin = EXYNOS5_GPIO_F10;
40277b55e8cSThomas Abraham break;
40377b55e8cSThomas Abraham case PERIPH_ID_SPI4:
40477b55e8cSThomas Abraham for (i = 0; i < 2; i++) {
40577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_F02 + i, S5P_GPIO_FUNC(0x4));
40677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_E04 + i, S5P_GPIO_FUNC(0x4));
40777b55e8cSThomas Abraham }
40877b55e8cSThomas Abraham break;
40977b55e8cSThomas Abraham }
41077b55e8cSThomas Abraham if (peripheral != PERIPH_ID_SPI4) {
41177b55e8cSThomas Abraham for (i = pin; i < pin + 4; i++)
41277b55e8cSThomas Abraham gpio_cfg_pin(i, cfg);
41377b55e8cSThomas Abraham }
41477b55e8cSThomas Abraham }
41577b55e8cSThomas Abraham
exynos5420_spi_config(int peripheral)41677b55e8cSThomas Abraham void exynos5420_spi_config(int peripheral)
41777b55e8cSThomas Abraham {
41877b55e8cSThomas Abraham int cfg, pin, i;
41977b55e8cSThomas Abraham
42077b55e8cSThomas Abraham switch (peripheral) {
42177b55e8cSThomas Abraham case PERIPH_ID_SPI0:
42277b55e8cSThomas Abraham pin = EXYNOS5420_GPIO_A20;
42377b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x2);
42477b55e8cSThomas Abraham break;
42577b55e8cSThomas Abraham case PERIPH_ID_SPI1:
42677b55e8cSThomas Abraham pin = EXYNOS5420_GPIO_A24;
42777b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x2);
42877b55e8cSThomas Abraham break;
42977b55e8cSThomas Abraham case PERIPH_ID_SPI2:
43077b55e8cSThomas Abraham pin = EXYNOS5420_GPIO_B11;
43177b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x5);
43277b55e8cSThomas Abraham break;
43377b55e8cSThomas Abraham case PERIPH_ID_SPI3:
43477b55e8cSThomas Abraham pin = EXYNOS5420_GPIO_F10;
43577b55e8cSThomas Abraham cfg = S5P_GPIO_FUNC(0x2);
43677b55e8cSThomas Abraham break;
43777b55e8cSThomas Abraham case PERIPH_ID_SPI4:
43877b55e8cSThomas Abraham cfg = 0;
43977b55e8cSThomas Abraham pin = 0;
44077b55e8cSThomas Abraham break;
44177b55e8cSThomas Abraham default:
44277b55e8cSThomas Abraham cfg = 0;
44377b55e8cSThomas Abraham pin = 0;
44477b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
44577b55e8cSThomas Abraham return;
44677b55e8cSThomas Abraham }
44777b55e8cSThomas Abraham
44877b55e8cSThomas Abraham if (peripheral != PERIPH_ID_SPI4) {
44977b55e8cSThomas Abraham for (i = pin; i < pin + 4; i++)
45077b55e8cSThomas Abraham gpio_cfg_pin(i, cfg);
45177b55e8cSThomas Abraham } else {
45277b55e8cSThomas Abraham for (i = 0; i < 2; i++) {
45377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_F02 + i,
45477b55e8cSThomas Abraham S5P_GPIO_FUNC(0x4));
45577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5420_GPIO_E04 + i,
45677b55e8cSThomas Abraham S5P_GPIO_FUNC(0x4));
45777b55e8cSThomas Abraham }
45877b55e8cSThomas Abraham }
45977b55e8cSThomas Abraham }
46077b55e8cSThomas Abraham
exynos5_pinmux_config(int peripheral,int flags)46177b55e8cSThomas Abraham static int exynos5_pinmux_config(int peripheral, int flags)
46277b55e8cSThomas Abraham {
46377b55e8cSThomas Abraham switch (peripheral) {
46477b55e8cSThomas Abraham case PERIPH_ID_UART0:
46577b55e8cSThomas Abraham case PERIPH_ID_UART1:
46677b55e8cSThomas Abraham case PERIPH_ID_UART2:
46777b55e8cSThomas Abraham case PERIPH_ID_UART3:
46877b55e8cSThomas Abraham exynos5_uart_config(peripheral);
46977b55e8cSThomas Abraham break;
47077b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
47177b55e8cSThomas Abraham case PERIPH_ID_SDMMC1:
47277b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
47377b55e8cSThomas Abraham case PERIPH_ID_SDMMC3:
47477b55e8cSThomas Abraham return exynos5_mmc_config(peripheral, flags);
47577b55e8cSThomas Abraham case PERIPH_ID_SROMC:
47677b55e8cSThomas Abraham exynos5_sromc_config(flags);
47777b55e8cSThomas Abraham break;
47877b55e8cSThomas Abraham case PERIPH_ID_I2C0:
47977b55e8cSThomas Abraham case PERIPH_ID_I2C1:
48077b55e8cSThomas Abraham case PERIPH_ID_I2C2:
48177b55e8cSThomas Abraham case PERIPH_ID_I2C3:
48277b55e8cSThomas Abraham case PERIPH_ID_I2C4:
48377b55e8cSThomas Abraham case PERIPH_ID_I2C5:
48477b55e8cSThomas Abraham case PERIPH_ID_I2C6:
48577b55e8cSThomas Abraham case PERIPH_ID_I2C7:
48677b55e8cSThomas Abraham exynos5_i2c_config(peripheral, flags);
48777b55e8cSThomas Abraham break;
48877b55e8cSThomas Abraham case PERIPH_ID_I2S0:
48977b55e8cSThomas Abraham case PERIPH_ID_I2S1:
49077b55e8cSThomas Abraham exynos5_i2s_config(peripheral);
49177b55e8cSThomas Abraham break;
49277b55e8cSThomas Abraham case PERIPH_ID_SPI0:
49377b55e8cSThomas Abraham case PERIPH_ID_SPI1:
49477b55e8cSThomas Abraham case PERIPH_ID_SPI2:
49577b55e8cSThomas Abraham case PERIPH_ID_SPI3:
49677b55e8cSThomas Abraham case PERIPH_ID_SPI4:
49777b55e8cSThomas Abraham exynos5_spi_config(peripheral);
49877b55e8cSThomas Abraham break;
49977b55e8cSThomas Abraham case PERIPH_ID_DPHPD:
50077b55e8cSThomas Abraham /* Set Hotplug detect for DP */
50177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS5_GPIO_X07, S5P_GPIO_FUNC(0x3));
50277b55e8cSThomas Abraham
50377b55e8cSThomas Abraham /*
50477b55e8cSThomas Abraham * Hotplug detect should have an external pullup; disable the
50577b55e8cSThomas Abraham * internal pulldown so they don't fight.
50677b55e8cSThomas Abraham */
50777b55e8cSThomas Abraham gpio_set_pull(EXYNOS5_GPIO_X07, S5P_GPIO_PULL_NONE);
50877b55e8cSThomas Abraham break;
509*af5b5eaeSSimon Glass case PERIPH_ID_PWM0:
510*af5b5eaeSSimon Glass gpio_cfg_pin(EXYNOS5_GPIO_B20, S5P_GPIO_FUNC(2));
511*af5b5eaeSSimon Glass break;
51277b55e8cSThomas Abraham default:
51377b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
51477b55e8cSThomas Abraham return -1;
51577b55e8cSThomas Abraham }
51677b55e8cSThomas Abraham
51777b55e8cSThomas Abraham return 0;
51877b55e8cSThomas Abraham }
51977b55e8cSThomas Abraham
exynos5420_pinmux_config(int peripheral,int flags)52077b55e8cSThomas Abraham static int exynos5420_pinmux_config(int peripheral, int flags)
52177b55e8cSThomas Abraham {
52277b55e8cSThomas Abraham switch (peripheral) {
52377b55e8cSThomas Abraham case PERIPH_ID_UART0:
52477b55e8cSThomas Abraham case PERIPH_ID_UART1:
52577b55e8cSThomas Abraham case PERIPH_ID_UART2:
52677b55e8cSThomas Abraham case PERIPH_ID_UART3:
52777b55e8cSThomas Abraham exynos5420_uart_config(peripheral);
52877b55e8cSThomas Abraham break;
52977b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
53077b55e8cSThomas Abraham case PERIPH_ID_SDMMC1:
53177b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
53277b55e8cSThomas Abraham case PERIPH_ID_SDMMC3:
53377b55e8cSThomas Abraham return exynos5420_mmc_config(peripheral, flags);
53477b55e8cSThomas Abraham case PERIPH_ID_SPI0:
53577b55e8cSThomas Abraham case PERIPH_ID_SPI1:
53677b55e8cSThomas Abraham case PERIPH_ID_SPI2:
53777b55e8cSThomas Abraham case PERIPH_ID_SPI3:
53877b55e8cSThomas Abraham case PERIPH_ID_SPI4:
53977b55e8cSThomas Abraham exynos5420_spi_config(peripheral);
54077b55e8cSThomas Abraham break;
54177b55e8cSThomas Abraham case PERIPH_ID_I2C0:
54277b55e8cSThomas Abraham case PERIPH_ID_I2C1:
54377b55e8cSThomas Abraham case PERIPH_ID_I2C2:
54477b55e8cSThomas Abraham case PERIPH_ID_I2C3:
54577b55e8cSThomas Abraham case PERIPH_ID_I2C4:
54677b55e8cSThomas Abraham case PERIPH_ID_I2C5:
54777b55e8cSThomas Abraham case PERIPH_ID_I2C6:
54877b55e8cSThomas Abraham case PERIPH_ID_I2C7:
54977b55e8cSThomas Abraham case PERIPH_ID_I2C8:
55077b55e8cSThomas Abraham case PERIPH_ID_I2C9:
55177b55e8cSThomas Abraham case PERIPH_ID_I2C10:
55277b55e8cSThomas Abraham exynos5420_i2c_config(peripheral);
55377b55e8cSThomas Abraham break;
554*af5b5eaeSSimon Glass case PERIPH_ID_PWM0:
555*af5b5eaeSSimon Glass gpio_cfg_pin(EXYNOS5420_GPIO_B20, S5P_GPIO_FUNC(2));
556*af5b5eaeSSimon Glass break;
55777b55e8cSThomas Abraham default:
55877b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
55977b55e8cSThomas Abraham return -1;
56077b55e8cSThomas Abraham }
56177b55e8cSThomas Abraham
56277b55e8cSThomas Abraham return 0;
56377b55e8cSThomas Abraham }
56477b55e8cSThomas Abraham
exynos4_i2c_config(int peripheral,int flags)56577b55e8cSThomas Abraham static void exynos4_i2c_config(int peripheral, int flags)
56677b55e8cSThomas Abraham {
56777b55e8cSThomas Abraham switch (peripheral) {
56877b55e8cSThomas Abraham case PERIPH_ID_I2C0:
56977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_D10, S5P_GPIO_FUNC(0x2));
57077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_D11, S5P_GPIO_FUNC(0x2));
57177b55e8cSThomas Abraham break;
57277b55e8cSThomas Abraham case PERIPH_ID_I2C1:
57377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_D12, S5P_GPIO_FUNC(0x2));
57477b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_D13, S5P_GPIO_FUNC(0x2));
57577b55e8cSThomas Abraham break;
57677b55e8cSThomas Abraham case PERIPH_ID_I2C2:
57777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_A06, S5P_GPIO_FUNC(0x3));
57877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_A07, S5P_GPIO_FUNC(0x3));
57977b55e8cSThomas Abraham break;
58077b55e8cSThomas Abraham case PERIPH_ID_I2C3:
58177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_A12, S5P_GPIO_FUNC(0x3));
58277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_A13, S5P_GPIO_FUNC(0x3));
58377b55e8cSThomas Abraham break;
58477b55e8cSThomas Abraham case PERIPH_ID_I2C4:
58577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_B2, S5P_GPIO_FUNC(0x3));
58677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_B3, S5P_GPIO_FUNC(0x3));
58777b55e8cSThomas Abraham break;
58877b55e8cSThomas Abraham case PERIPH_ID_I2C5:
58977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_B6, S5P_GPIO_FUNC(0x3));
59077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_B7, S5P_GPIO_FUNC(0x3));
59177b55e8cSThomas Abraham break;
59277b55e8cSThomas Abraham case PERIPH_ID_I2C6:
59377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_C13, S5P_GPIO_FUNC(0x4));
59477b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_C14, S5P_GPIO_FUNC(0x4));
59577b55e8cSThomas Abraham break;
59677b55e8cSThomas Abraham case PERIPH_ID_I2C7:
59777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_D02, S5P_GPIO_FUNC(0x3));
59877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4_GPIO_D03, S5P_GPIO_FUNC(0x3));
59977b55e8cSThomas Abraham break;
60077b55e8cSThomas Abraham }
60177b55e8cSThomas Abraham }
60277b55e8cSThomas Abraham
exynos4_mmc_config(int peripheral,int flags)60377b55e8cSThomas Abraham static int exynos4_mmc_config(int peripheral, int flags)
60477b55e8cSThomas Abraham {
60577b55e8cSThomas Abraham int i, start = 0, start_ext = 0;
60677b55e8cSThomas Abraham unsigned int func, ext_func;
60777b55e8cSThomas Abraham
60877b55e8cSThomas Abraham switch (peripheral) {
60977b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
61077b55e8cSThomas Abraham start = EXYNOS4_GPIO_K00;
61177b55e8cSThomas Abraham start_ext = EXYNOS4_GPIO_K13;
61277b55e8cSThomas Abraham func = S5P_GPIO_FUNC(0x2);
61377b55e8cSThomas Abraham ext_func = S5P_GPIO_FUNC(0x3);
61477b55e8cSThomas Abraham break;
61577b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
61677b55e8cSThomas Abraham start = EXYNOS4_GPIO_K20;
61777b55e8cSThomas Abraham start_ext = EXYNOS4_GPIO_K33;
61877b55e8cSThomas Abraham func = S5P_GPIO_FUNC(0x2);
61977b55e8cSThomas Abraham ext_func = S5P_GPIO_FUNC(0x3);
62077b55e8cSThomas Abraham break;
62177b55e8cSThomas Abraham case PERIPH_ID_SDMMC4:
62277b55e8cSThomas Abraham start = EXYNOS4_GPIO_K00;
62377b55e8cSThomas Abraham start_ext = EXYNOS4_GPIO_K13;
62477b55e8cSThomas Abraham func = S5P_GPIO_FUNC(0x3);
62577b55e8cSThomas Abraham ext_func = S5P_GPIO_FUNC(0x4);
62677b55e8cSThomas Abraham break;
62777b55e8cSThomas Abraham default:
62877b55e8cSThomas Abraham return -1;
62977b55e8cSThomas Abraham }
63077b55e8cSThomas Abraham for (i = start; i < (start + 7); i++) {
63177b55e8cSThomas Abraham if (i == (start + 2))
63277b55e8cSThomas Abraham continue;
63377b55e8cSThomas Abraham gpio_cfg_pin(i, func);
63477b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
63577b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
63677b55e8cSThomas Abraham }
63777b55e8cSThomas Abraham /* SDMMC2 do not use 8bit mode at exynos4 */
63877b55e8cSThomas Abraham if (flags & PINMUX_FLAG_8BIT_MODE) {
63977b55e8cSThomas Abraham for (i = start_ext; i < (start_ext + 4); i++) {
64077b55e8cSThomas Abraham gpio_cfg_pin(i, ext_func);
64177b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
64277b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
64377b55e8cSThomas Abraham }
64477b55e8cSThomas Abraham }
64577b55e8cSThomas Abraham
64677b55e8cSThomas Abraham return 0;
64777b55e8cSThomas Abraham }
64877b55e8cSThomas Abraham
exynos4_uart_config(int peripheral)64977b55e8cSThomas Abraham static void exynos4_uart_config(int peripheral)
65077b55e8cSThomas Abraham {
65177b55e8cSThomas Abraham int i, start, count;
65277b55e8cSThomas Abraham
65377b55e8cSThomas Abraham switch (peripheral) {
65477b55e8cSThomas Abraham case PERIPH_ID_UART0:
65577b55e8cSThomas Abraham start = EXYNOS4_GPIO_A00;
65677b55e8cSThomas Abraham count = 4;
65777b55e8cSThomas Abraham break;
65877b55e8cSThomas Abraham case PERIPH_ID_UART1:
65977b55e8cSThomas Abraham start = EXYNOS4_GPIO_A04;
66077b55e8cSThomas Abraham count = 4;
66177b55e8cSThomas Abraham break;
66277b55e8cSThomas Abraham case PERIPH_ID_UART2:
66377b55e8cSThomas Abraham start = EXYNOS4_GPIO_A10;
66477b55e8cSThomas Abraham count = 4;
66577b55e8cSThomas Abraham break;
66677b55e8cSThomas Abraham case PERIPH_ID_UART3:
66777b55e8cSThomas Abraham start = EXYNOS4_GPIO_A14;
66877b55e8cSThomas Abraham count = 2;
66977b55e8cSThomas Abraham break;
67077b55e8cSThomas Abraham default:
67177b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
67277b55e8cSThomas Abraham return;
67377b55e8cSThomas Abraham }
67477b55e8cSThomas Abraham for (i = start; i < (start + count); i++) {
67577b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
67677b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
67777b55e8cSThomas Abraham }
67877b55e8cSThomas Abraham }
67977b55e8cSThomas Abraham
exynos4x12_i2c_config(int peripheral,int flags)68077b55e8cSThomas Abraham static void exynos4x12_i2c_config(int peripheral, int flags)
68177b55e8cSThomas Abraham {
68277b55e8cSThomas Abraham switch (peripheral) {
68377b55e8cSThomas Abraham case PERIPH_ID_I2C0:
68477b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_D10, S5P_GPIO_FUNC(0x2));
68577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_D11, S5P_GPIO_FUNC(0x2));
68677b55e8cSThomas Abraham break;
68777b55e8cSThomas Abraham case PERIPH_ID_I2C1:
68877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_D12, S5P_GPIO_FUNC(0x2));
68977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_D13, S5P_GPIO_FUNC(0x2));
69077b55e8cSThomas Abraham break;
69177b55e8cSThomas Abraham case PERIPH_ID_I2C2:
69277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_A06, S5P_GPIO_FUNC(0x3));
69377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_A07, S5P_GPIO_FUNC(0x3));
69477b55e8cSThomas Abraham break;
69577b55e8cSThomas Abraham case PERIPH_ID_I2C3:
69677b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_A12, S5P_GPIO_FUNC(0x3));
69777b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_A13, S5P_GPIO_FUNC(0x3));
69877b55e8cSThomas Abraham break;
69977b55e8cSThomas Abraham case PERIPH_ID_I2C4:
70077b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_B2, S5P_GPIO_FUNC(0x3));
70177b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_B3, S5P_GPIO_FUNC(0x3));
70277b55e8cSThomas Abraham break;
70377b55e8cSThomas Abraham case PERIPH_ID_I2C5:
70477b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_B6, S5P_GPIO_FUNC(0x3));
70577b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_B7, S5P_GPIO_FUNC(0x3));
70677b55e8cSThomas Abraham break;
70777b55e8cSThomas Abraham case PERIPH_ID_I2C6:
70877b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_C13, S5P_GPIO_FUNC(0x4));
70977b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_C14, S5P_GPIO_FUNC(0x4));
71077b55e8cSThomas Abraham break;
71177b55e8cSThomas Abraham case PERIPH_ID_I2C7:
71277b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_D02, S5P_GPIO_FUNC(0x3));
71377b55e8cSThomas Abraham gpio_cfg_pin(EXYNOS4X12_GPIO_D03, S5P_GPIO_FUNC(0x3));
71477b55e8cSThomas Abraham break;
71577b55e8cSThomas Abraham }
71677b55e8cSThomas Abraham }
71777b55e8cSThomas Abraham
exynos4x12_mmc_config(int peripheral,int flags)71877b55e8cSThomas Abraham static int exynos4x12_mmc_config(int peripheral, int flags)
71977b55e8cSThomas Abraham {
72077b55e8cSThomas Abraham int i, start = 0, start_ext = 0;
72177b55e8cSThomas Abraham unsigned int func, ext_func;
72277b55e8cSThomas Abraham
72377b55e8cSThomas Abraham switch (peripheral) {
72477b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
72577b55e8cSThomas Abraham start = EXYNOS4X12_GPIO_K00;
72677b55e8cSThomas Abraham start_ext = EXYNOS4X12_GPIO_K13;
72777b55e8cSThomas Abraham func = S5P_GPIO_FUNC(0x2);
72877b55e8cSThomas Abraham ext_func = S5P_GPIO_FUNC(0x3);
72977b55e8cSThomas Abraham break;
73077b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
73177b55e8cSThomas Abraham start = EXYNOS4X12_GPIO_K20;
73277b55e8cSThomas Abraham start_ext = EXYNOS4X12_GPIO_K33;
73377b55e8cSThomas Abraham func = S5P_GPIO_FUNC(0x2);
73477b55e8cSThomas Abraham ext_func = S5P_GPIO_FUNC(0x3);
73577b55e8cSThomas Abraham break;
73677b55e8cSThomas Abraham case PERIPH_ID_SDMMC4:
73777b55e8cSThomas Abraham start = EXYNOS4X12_GPIO_K00;
73877b55e8cSThomas Abraham start_ext = EXYNOS4X12_GPIO_K13;
73977b55e8cSThomas Abraham func = S5P_GPIO_FUNC(0x3);
74077b55e8cSThomas Abraham ext_func = S5P_GPIO_FUNC(0x4);
74177b55e8cSThomas Abraham break;
74277b55e8cSThomas Abraham default:
74377b55e8cSThomas Abraham return -1;
74477b55e8cSThomas Abraham }
74577b55e8cSThomas Abraham for (i = start; i < (start + 7); i++) {
7465d043431SPrzemyslaw Marczak gpio_set_pull(i, S5P_GPIO_PULL_NONE);
74777b55e8cSThomas Abraham if (i == (start + 2))
74877b55e8cSThomas Abraham continue;
74977b55e8cSThomas Abraham gpio_cfg_pin(i, func);
75077b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
75177b55e8cSThomas Abraham }
75277b55e8cSThomas Abraham if (flags & PINMUX_FLAG_8BIT_MODE) {
75377b55e8cSThomas Abraham for (i = start_ext; i < (start_ext + 4); i++) {
75477b55e8cSThomas Abraham gpio_cfg_pin(i, ext_func);
75577b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
75677b55e8cSThomas Abraham gpio_set_drv(i, S5P_GPIO_DRV_4X);
75777b55e8cSThomas Abraham }
75877b55e8cSThomas Abraham }
75977b55e8cSThomas Abraham
76077b55e8cSThomas Abraham return 0;
76177b55e8cSThomas Abraham }
76277b55e8cSThomas Abraham
exynos4x12_uart_config(int peripheral)76377b55e8cSThomas Abraham static void exynos4x12_uart_config(int peripheral)
76477b55e8cSThomas Abraham {
76577b55e8cSThomas Abraham int i, start, count;
76677b55e8cSThomas Abraham
76777b55e8cSThomas Abraham switch (peripheral) {
76877b55e8cSThomas Abraham case PERIPH_ID_UART0:
76977b55e8cSThomas Abraham start = EXYNOS4X12_GPIO_A00;
77077b55e8cSThomas Abraham count = 4;
77177b55e8cSThomas Abraham break;
77277b55e8cSThomas Abraham case PERIPH_ID_UART1:
77377b55e8cSThomas Abraham start = EXYNOS4X12_GPIO_A04;
77477b55e8cSThomas Abraham count = 4;
77577b55e8cSThomas Abraham break;
77677b55e8cSThomas Abraham case PERIPH_ID_UART2:
77777b55e8cSThomas Abraham start = EXYNOS4X12_GPIO_A10;
77877b55e8cSThomas Abraham count = 4;
77977b55e8cSThomas Abraham break;
78077b55e8cSThomas Abraham case PERIPH_ID_UART3:
78177b55e8cSThomas Abraham start = EXYNOS4X12_GPIO_A14;
78277b55e8cSThomas Abraham count = 2;
78377b55e8cSThomas Abraham break;
78477b55e8cSThomas Abraham default:
78577b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
78677b55e8cSThomas Abraham return;
78777b55e8cSThomas Abraham }
78877b55e8cSThomas Abraham for (i = start; i < (start + count); i++) {
78977b55e8cSThomas Abraham gpio_set_pull(i, S5P_GPIO_PULL_NONE);
79077b55e8cSThomas Abraham gpio_cfg_pin(i, S5P_GPIO_FUNC(0x2));
79177b55e8cSThomas Abraham }
79277b55e8cSThomas Abraham }
79377b55e8cSThomas Abraham
exynos4_pinmux_config(int peripheral,int flags)79477b55e8cSThomas Abraham static int exynos4_pinmux_config(int peripheral, int flags)
79577b55e8cSThomas Abraham {
79677b55e8cSThomas Abraham switch (peripheral) {
79777b55e8cSThomas Abraham case PERIPH_ID_UART0:
79877b55e8cSThomas Abraham case PERIPH_ID_UART1:
79977b55e8cSThomas Abraham case PERIPH_ID_UART2:
80077b55e8cSThomas Abraham case PERIPH_ID_UART3:
80177b55e8cSThomas Abraham exynos4_uart_config(peripheral);
80277b55e8cSThomas Abraham break;
80377b55e8cSThomas Abraham case PERIPH_ID_I2C0:
80477b55e8cSThomas Abraham case PERIPH_ID_I2C1:
80577b55e8cSThomas Abraham case PERIPH_ID_I2C2:
80677b55e8cSThomas Abraham case PERIPH_ID_I2C3:
80777b55e8cSThomas Abraham case PERIPH_ID_I2C4:
80877b55e8cSThomas Abraham case PERIPH_ID_I2C5:
80977b55e8cSThomas Abraham case PERIPH_ID_I2C6:
81077b55e8cSThomas Abraham case PERIPH_ID_I2C7:
81177b55e8cSThomas Abraham exynos4_i2c_config(peripheral, flags);
81277b55e8cSThomas Abraham break;
81377b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
81477b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
81577b55e8cSThomas Abraham case PERIPH_ID_SDMMC4:
81677b55e8cSThomas Abraham return exynos4_mmc_config(peripheral, flags);
81777b55e8cSThomas Abraham case PERIPH_ID_SDMMC1:
81877b55e8cSThomas Abraham case PERIPH_ID_SDMMC3:
81977b55e8cSThomas Abraham debug("SDMMC device %d not implemented\n", peripheral);
82077b55e8cSThomas Abraham return -1;
82177b55e8cSThomas Abraham default:
82277b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
82377b55e8cSThomas Abraham return -1;
82477b55e8cSThomas Abraham }
82577b55e8cSThomas Abraham
82677b55e8cSThomas Abraham return 0;
82777b55e8cSThomas Abraham }
82877b55e8cSThomas Abraham
exynos4x12_pinmux_config(int peripheral,int flags)82977b55e8cSThomas Abraham static int exynos4x12_pinmux_config(int peripheral, int flags)
83077b55e8cSThomas Abraham {
83177b55e8cSThomas Abraham switch (peripheral) {
83277b55e8cSThomas Abraham case PERIPH_ID_UART0:
83377b55e8cSThomas Abraham case PERIPH_ID_UART1:
83477b55e8cSThomas Abraham case PERIPH_ID_UART2:
83577b55e8cSThomas Abraham case PERIPH_ID_UART3:
83677b55e8cSThomas Abraham exynos4x12_uart_config(peripheral);
83777b55e8cSThomas Abraham break;
83877b55e8cSThomas Abraham case PERIPH_ID_I2C0:
83977b55e8cSThomas Abraham case PERIPH_ID_I2C1:
84077b55e8cSThomas Abraham case PERIPH_ID_I2C2:
84177b55e8cSThomas Abraham case PERIPH_ID_I2C3:
84277b55e8cSThomas Abraham case PERIPH_ID_I2C4:
84377b55e8cSThomas Abraham case PERIPH_ID_I2C5:
84477b55e8cSThomas Abraham case PERIPH_ID_I2C6:
84577b55e8cSThomas Abraham case PERIPH_ID_I2C7:
84677b55e8cSThomas Abraham exynos4x12_i2c_config(peripheral, flags);
84777b55e8cSThomas Abraham break;
84877b55e8cSThomas Abraham case PERIPH_ID_SDMMC0:
84977b55e8cSThomas Abraham case PERIPH_ID_SDMMC2:
85077b55e8cSThomas Abraham case PERIPH_ID_SDMMC4:
85177b55e8cSThomas Abraham return exynos4x12_mmc_config(peripheral, flags);
85277b55e8cSThomas Abraham case PERIPH_ID_SDMMC1:
85377b55e8cSThomas Abraham case PERIPH_ID_SDMMC3:
85477b55e8cSThomas Abraham debug("SDMMC device %d not implemented\n", peripheral);
85577b55e8cSThomas Abraham return -1;
85677b55e8cSThomas Abraham default:
85777b55e8cSThomas Abraham debug("%s: invalid peripheral %d", __func__, peripheral);
85877b55e8cSThomas Abraham return -1;
85977b55e8cSThomas Abraham }
86077b55e8cSThomas Abraham
86177b55e8cSThomas Abraham return 0;
86277b55e8cSThomas Abraham }
86377b55e8cSThomas Abraham
exynos_pinmux_config(int peripheral,int flags)86477b55e8cSThomas Abraham int exynos_pinmux_config(int peripheral, int flags)
86577b55e8cSThomas Abraham {
86677b55e8cSThomas Abraham if (cpu_is_exynos5()) {
867d64c8adeSPrzemyslaw Marczak if (proid_is_exynos5420() || proid_is_exynos5422())
86877b55e8cSThomas Abraham return exynos5420_pinmux_config(peripheral, flags);
86977b55e8cSThomas Abraham else if (proid_is_exynos5250())
87077b55e8cSThomas Abraham return exynos5_pinmux_config(peripheral, flags);
87177b55e8cSThomas Abraham } else if (cpu_is_exynos4()) {
87277b55e8cSThomas Abraham if (proid_is_exynos4412())
87377b55e8cSThomas Abraham return exynos4x12_pinmux_config(peripheral, flags);
87477b55e8cSThomas Abraham else
87577b55e8cSThomas Abraham return exynos4_pinmux_config(peripheral, flags);
87677b55e8cSThomas Abraham }
87777b55e8cSThomas Abraham
87877b55e8cSThomas Abraham debug("pinmux functionality not supported\n");
87977b55e8cSThomas Abraham
88077b55e8cSThomas Abraham return -1;
88177b55e8cSThomas Abraham }
88277b55e8cSThomas Abraham
8830f925822SMasahiro Yamada #if CONFIG_IS_ENABLED(OF_CONTROL)
exynos4_pinmux_decode_periph_id(const void * blob,int node)88477b55e8cSThomas Abraham static int exynos4_pinmux_decode_periph_id(const void *blob, int node)
88577b55e8cSThomas Abraham {
88677b55e8cSThomas Abraham int err;
88777b55e8cSThomas Abraham u32 cell[3];
88877b55e8cSThomas Abraham
88977b55e8cSThomas Abraham err = fdtdec_get_int_array(blob, node, "interrupts", cell,
89077b55e8cSThomas Abraham ARRAY_SIZE(cell));
89177b55e8cSThomas Abraham if (err) {
89277b55e8cSThomas Abraham debug(" invalid peripheral id\n");
89377b55e8cSThomas Abraham return PERIPH_ID_NONE;
89477b55e8cSThomas Abraham }
89577b55e8cSThomas Abraham
89677b55e8cSThomas Abraham return cell[1];
89777b55e8cSThomas Abraham }
89877b55e8cSThomas Abraham
exynos5_pinmux_decode_periph_id(const void * blob,int node)89977b55e8cSThomas Abraham static int exynos5_pinmux_decode_periph_id(const void *blob, int node)
90077b55e8cSThomas Abraham {
90177b55e8cSThomas Abraham int err;
90277b55e8cSThomas Abraham u32 cell[3];
90377b55e8cSThomas Abraham
90477b55e8cSThomas Abraham err = fdtdec_get_int_array(blob, node, "interrupts", cell,
90577b55e8cSThomas Abraham ARRAY_SIZE(cell));
90677b55e8cSThomas Abraham if (err)
90777b55e8cSThomas Abraham return PERIPH_ID_NONE;
90877b55e8cSThomas Abraham
90977b55e8cSThomas Abraham return cell[1];
91077b55e8cSThomas Abraham }
91177b55e8cSThomas Abraham
pinmux_decode_periph_id(const void * blob,int node)91277b55e8cSThomas Abraham int pinmux_decode_periph_id(const void *blob, int node)
91377b55e8cSThomas Abraham {
91477b55e8cSThomas Abraham if (cpu_is_exynos5())
91577b55e8cSThomas Abraham return exynos5_pinmux_decode_periph_id(blob, node);
91677b55e8cSThomas Abraham else if (cpu_is_exynos4())
91777b55e8cSThomas Abraham return exynos4_pinmux_decode_periph_id(blob, node);
91877b55e8cSThomas Abraham
91977b55e8cSThomas Abraham return PERIPH_ID_NONE;
92077b55e8cSThomas Abraham }
92177b55e8cSThomas Abraham #endif
922