pinmux.c 22 KB

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