pinmux.c 22 KB

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