pinmux.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * Copyright (c) 2012 Samsung Electronics.
  3. * Abhilash Kesavan <a.kesavan@samsung.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/arch/gpio.h>
  25. #include <asm/arch/pinmux.h>
  26. #include <asm/arch/sromc.h>
  27. static void exynos5_uart_config(int peripheral)
  28. {
  29. struct exynos5_gpio_part1 *gpio1 =
  30. (struct exynos5_gpio_part1 *) samsung_get_base_gpio_part1();
  31. struct s5p_gpio_bank *bank;
  32. int i, start, count;
  33. switch (peripheral) {
  34. case PERIPH_ID_UART0:
  35. bank = &gpio1->a0;
  36. start = 0;
  37. count = 4;
  38. break;
  39. case PERIPH_ID_UART1:
  40. bank = &gpio1->a0;
  41. start = 4;
  42. count = 4;
  43. break;
  44. case PERIPH_ID_UART2:
  45. bank = &gpio1->a1;
  46. start = 0;
  47. count = 4;
  48. break;
  49. case PERIPH_ID_UART3:
  50. bank = &gpio1->a1;
  51. start = 4;
  52. count = 2;
  53. break;
  54. }
  55. for (i = start; i < start + count; i++) {
  56. s5p_gpio_set_pull(bank, i, GPIO_PULL_NONE);
  57. s5p_gpio_cfg_pin(bank, i, GPIO_FUNC(0x2));
  58. }
  59. }
  60. static int exynos5_mmc_config(int peripheral, int flags)
  61. {
  62. struct exynos5_gpio_part1 *gpio1 =
  63. (struct exynos5_gpio_part1 *) samsung_get_base_gpio_part1();
  64. struct s5p_gpio_bank *bank, *bank_ext;
  65. int i;
  66. switch (peripheral) {
  67. case PERIPH_ID_SDMMC0:
  68. bank = &gpio1->c0;
  69. bank_ext = &gpio1->c1;
  70. break;
  71. case PERIPH_ID_SDMMC1:
  72. bank = &gpio1->c1;
  73. bank_ext = NULL;
  74. break;
  75. case PERIPH_ID_SDMMC2:
  76. bank = &gpio1->c2;
  77. bank_ext = &gpio1->c3;
  78. break;
  79. case PERIPH_ID_SDMMC3:
  80. bank = &gpio1->c3;
  81. bank_ext = NULL;
  82. break;
  83. }
  84. if ((flags & PINMUX_FLAG_8BIT_MODE) && !bank_ext) {
  85. debug("SDMMC device %d does not support 8bit mode",
  86. peripheral);
  87. return -1;
  88. }
  89. if (flags & PINMUX_FLAG_8BIT_MODE) {
  90. for (i = 3; i <= 6; i++) {
  91. s5p_gpio_cfg_pin(bank_ext, i, GPIO_FUNC(0x3));
  92. s5p_gpio_set_pull(bank_ext, i, GPIO_PULL_UP);
  93. s5p_gpio_set_drv(bank_ext, i, GPIO_DRV_4X);
  94. }
  95. }
  96. for (i = 0; i < 2; i++) {
  97. s5p_gpio_cfg_pin(bank, i, GPIO_FUNC(0x2));
  98. s5p_gpio_set_pull(bank, i, GPIO_PULL_NONE);
  99. s5p_gpio_set_drv(bank, i, GPIO_DRV_4X);
  100. }
  101. for (i = 3; i <= 6; i++) {
  102. s5p_gpio_cfg_pin(bank, i, GPIO_FUNC(0x2));
  103. s5p_gpio_set_pull(bank, i, GPIO_PULL_UP);
  104. s5p_gpio_set_drv(bank, i, GPIO_DRV_4X);
  105. }
  106. return 0;
  107. }
  108. static void exynos5_sromc_config(int flags)
  109. {
  110. struct exynos5_gpio_part1 *gpio1 =
  111. (struct exynos5_gpio_part1 *) samsung_get_base_gpio_part1();
  112. int i;
  113. /*
  114. * SROM:CS1 and EBI
  115. *
  116. * GPY0[0] SROM_CSn[0]
  117. * GPY0[1] SROM_CSn[1](2)
  118. * GPY0[2] SROM_CSn[2]
  119. * GPY0[3] SROM_CSn[3]
  120. * GPY0[4] EBI_OEn(2)
  121. * GPY0[5] EBI_EEn(2)
  122. *
  123. * GPY1[0] EBI_BEn[0](2)
  124. * GPY1[1] EBI_BEn[1](2)
  125. * GPY1[2] SROM_WAIT(2)
  126. * GPY1[3] EBI_DATA_RDn(2)
  127. */
  128. s5p_gpio_cfg_pin(&gpio1->y0, (flags & PINMUX_FLAG_BANK),
  129. GPIO_FUNC(2));
  130. s5p_gpio_cfg_pin(&gpio1->y0, 4, GPIO_FUNC(2));
  131. s5p_gpio_cfg_pin(&gpio1->y0, 5, GPIO_FUNC(2));
  132. for (i = 0; i < 4; i++)
  133. s5p_gpio_cfg_pin(&gpio1->y1, i, GPIO_FUNC(2));
  134. /*
  135. * EBI: 8 Addrss Lines
  136. *
  137. * GPY3[0] EBI_ADDR[0](2)
  138. * GPY3[1] EBI_ADDR[1](2)
  139. * GPY3[2] EBI_ADDR[2](2)
  140. * GPY3[3] EBI_ADDR[3](2)
  141. * GPY3[4] EBI_ADDR[4](2)
  142. * GPY3[5] EBI_ADDR[5](2)
  143. * GPY3[6] EBI_ADDR[6](2)
  144. * GPY3[7] EBI_ADDR[7](2)
  145. *
  146. * EBI: 16 Data Lines
  147. *
  148. * GPY5[0] EBI_DATA[0](2)
  149. * GPY5[1] EBI_DATA[1](2)
  150. * GPY5[2] EBI_DATA[2](2)
  151. * GPY5[3] EBI_DATA[3](2)
  152. * GPY5[4] EBI_DATA[4](2)
  153. * GPY5[5] EBI_DATA[5](2)
  154. * GPY5[6] EBI_DATA[6](2)
  155. * GPY5[7] EBI_DATA[7](2)
  156. *
  157. * GPY6[0] EBI_DATA[8](2)
  158. * GPY6[1] EBI_DATA[9](2)
  159. * GPY6[2] EBI_DATA[10](2)
  160. * GPY6[3] EBI_DATA[11](2)
  161. * GPY6[4] EBI_DATA[12](2)
  162. * GPY6[5] EBI_DATA[13](2)
  163. * GPY6[6] EBI_DATA[14](2)
  164. * GPY6[7] EBI_DATA[15](2)
  165. */
  166. for (i = 0; i < 8; i++) {
  167. s5p_gpio_cfg_pin(&gpio1->y3, i, GPIO_FUNC(2));
  168. s5p_gpio_set_pull(&gpio1->y3, i, GPIO_PULL_UP);
  169. s5p_gpio_cfg_pin(&gpio1->y5, i, GPIO_FUNC(2));
  170. s5p_gpio_set_pull(&gpio1->y5, i, GPIO_PULL_UP);
  171. s5p_gpio_cfg_pin(&gpio1->y6, i, GPIO_FUNC(2));
  172. s5p_gpio_set_pull(&gpio1->y6, i, GPIO_PULL_UP);
  173. }
  174. }
  175. static int exynos5_pinmux_config(int peripheral, int flags)
  176. {
  177. switch (peripheral) {
  178. case PERIPH_ID_UART0:
  179. case PERIPH_ID_UART1:
  180. case PERIPH_ID_UART2:
  181. case PERIPH_ID_UART3:
  182. exynos5_uart_config(peripheral);
  183. break;
  184. case PERIPH_ID_SDMMC0:
  185. case PERIPH_ID_SDMMC1:
  186. case PERIPH_ID_SDMMC2:
  187. case PERIPH_ID_SDMMC3:
  188. return exynos5_mmc_config(peripheral, flags);
  189. case PERIPH_ID_SROMC:
  190. exynos5_sromc_config(flags);
  191. break;
  192. default:
  193. debug("%s: invalid peripheral %d", __func__, peripheral);
  194. return -1;
  195. }
  196. return 0;
  197. }
  198. int exynos_pinmux_config(int peripheral, int flags)
  199. {
  200. if (cpu_is_exynos5())
  201. return exynos5_pinmux_config(peripheral, flags);
  202. else {
  203. debug("pinmux functionality not supported\n");
  204. return -1;
  205. }
  206. }