gpio.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * (C) Copyright 2010 Samsung Electronics
  3. * Minkyu Kang <mk7.kang@samsung.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  18. * MA 02111-1307 USA
  19. */
  20. #ifndef __ASM_ARCH_GPIO_H
  21. #define __ASM_ARCH_GPIO_H
  22. #ifndef __ASSEMBLY__
  23. struct s5p_gpio_bank {
  24. unsigned int con;
  25. unsigned int dat;
  26. unsigned int pull;
  27. unsigned int drv;
  28. unsigned int pdn_con;
  29. unsigned int pdn_pull;
  30. unsigned char res1[8];
  31. };
  32. struct exynos4_gpio_part1 {
  33. struct s5p_gpio_bank a0;
  34. struct s5p_gpio_bank a1;
  35. struct s5p_gpio_bank b;
  36. struct s5p_gpio_bank c0;
  37. struct s5p_gpio_bank c1;
  38. struct s5p_gpio_bank d0;
  39. struct s5p_gpio_bank d1;
  40. struct s5p_gpio_bank e0;
  41. struct s5p_gpio_bank e1;
  42. struct s5p_gpio_bank e2;
  43. struct s5p_gpio_bank e3;
  44. struct s5p_gpio_bank e4;
  45. struct s5p_gpio_bank f0;
  46. struct s5p_gpio_bank f1;
  47. struct s5p_gpio_bank f2;
  48. struct s5p_gpio_bank f3;
  49. };
  50. struct exynos4_gpio_part2 {
  51. struct s5p_gpio_bank j0;
  52. struct s5p_gpio_bank j1;
  53. struct s5p_gpio_bank k0;
  54. struct s5p_gpio_bank k1;
  55. struct s5p_gpio_bank k2;
  56. struct s5p_gpio_bank k3;
  57. struct s5p_gpio_bank l0;
  58. struct s5p_gpio_bank l1;
  59. struct s5p_gpio_bank l2;
  60. struct s5p_gpio_bank y0;
  61. struct s5p_gpio_bank y1;
  62. struct s5p_gpio_bank y2;
  63. struct s5p_gpio_bank y3;
  64. struct s5p_gpio_bank y4;
  65. struct s5p_gpio_bank y5;
  66. struct s5p_gpio_bank y6;
  67. struct s5p_gpio_bank res1[80];
  68. struct s5p_gpio_bank x0;
  69. struct s5p_gpio_bank x1;
  70. struct s5p_gpio_bank x2;
  71. struct s5p_gpio_bank x3;
  72. };
  73. struct exynos4_gpio_part3 {
  74. struct s5p_gpio_bank z;
  75. };
  76. struct exynos4x12_gpio_part1 {
  77. struct s5p_gpio_bank a0;
  78. struct s5p_gpio_bank a1;
  79. struct s5p_gpio_bank b;
  80. struct s5p_gpio_bank c0;
  81. struct s5p_gpio_bank c1;
  82. struct s5p_gpio_bank d0;
  83. struct s5p_gpio_bank d1;
  84. struct s5p_gpio_bank res1[0x5];
  85. struct s5p_gpio_bank f0;
  86. struct s5p_gpio_bank f1;
  87. struct s5p_gpio_bank f2;
  88. struct s5p_gpio_bank f3;
  89. struct s5p_gpio_bank res2[0x2];
  90. struct s5p_gpio_bank j0;
  91. struct s5p_gpio_bank j1;
  92. };
  93. struct exynos4x12_gpio_part2 {
  94. struct s5p_gpio_bank res1[0x2];
  95. struct s5p_gpio_bank k0;
  96. struct s5p_gpio_bank k1;
  97. struct s5p_gpio_bank k2;
  98. struct s5p_gpio_bank k3;
  99. struct s5p_gpio_bank l0;
  100. struct s5p_gpio_bank l1;
  101. struct s5p_gpio_bank l2;
  102. struct s5p_gpio_bank y0;
  103. struct s5p_gpio_bank y1;
  104. struct s5p_gpio_bank y2;
  105. struct s5p_gpio_bank y3;
  106. struct s5p_gpio_bank y4;
  107. struct s5p_gpio_bank y5;
  108. struct s5p_gpio_bank y6;
  109. struct s5p_gpio_bank res2[0x3];
  110. struct s5p_gpio_bank m0;
  111. struct s5p_gpio_bank m1;
  112. struct s5p_gpio_bank m2;
  113. struct s5p_gpio_bank m3;
  114. struct s5p_gpio_bank m4;
  115. struct s5p_gpio_bank res3[0x48];
  116. struct s5p_gpio_bank x0;
  117. struct s5p_gpio_bank x1;
  118. struct s5p_gpio_bank x2;
  119. struct s5p_gpio_bank x3;
  120. };
  121. struct exynos4x12_gpio_part3 {
  122. struct s5p_gpio_bank z;
  123. };
  124. struct exynos4x12_gpio_part4 {
  125. struct s5p_gpio_bank v0;
  126. struct s5p_gpio_bank v1;
  127. struct s5p_gpio_bank res1[0x1];
  128. struct s5p_gpio_bank v2;
  129. struct s5p_gpio_bank v3;
  130. struct s5p_gpio_bank res2[0x1];
  131. struct s5p_gpio_bank v4;
  132. };
  133. struct exynos5_gpio_part1 {
  134. struct s5p_gpio_bank a0;
  135. struct s5p_gpio_bank a1;
  136. struct s5p_gpio_bank a2;
  137. struct s5p_gpio_bank b0;
  138. struct s5p_gpio_bank b1;
  139. struct s5p_gpio_bank b2;
  140. struct s5p_gpio_bank b3;
  141. struct s5p_gpio_bank c0;
  142. struct s5p_gpio_bank c1;
  143. struct s5p_gpio_bank c2;
  144. struct s5p_gpio_bank c3;
  145. struct s5p_gpio_bank d0;
  146. struct s5p_gpio_bank d1;
  147. struct s5p_gpio_bank y0;
  148. struct s5p_gpio_bank y1;
  149. struct s5p_gpio_bank y2;
  150. struct s5p_gpio_bank y3;
  151. struct s5p_gpio_bank y4;
  152. struct s5p_gpio_bank y5;
  153. struct s5p_gpio_bank y6;
  154. struct s5p_gpio_bank res1[0x3];
  155. struct s5p_gpio_bank c4;
  156. struct s5p_gpio_bank res2[0x48];
  157. struct s5p_gpio_bank x0;
  158. struct s5p_gpio_bank x1;
  159. struct s5p_gpio_bank x2;
  160. struct s5p_gpio_bank x3;
  161. };
  162. struct exynos5_gpio_part2 {
  163. struct s5p_gpio_bank e0;
  164. struct s5p_gpio_bank e1;
  165. struct s5p_gpio_bank f0;
  166. struct s5p_gpio_bank f1;
  167. struct s5p_gpio_bank g0;
  168. struct s5p_gpio_bank g1;
  169. struct s5p_gpio_bank g2;
  170. struct s5p_gpio_bank h0;
  171. struct s5p_gpio_bank h1;
  172. };
  173. struct exynos5_gpio_part3 {
  174. struct s5p_gpio_bank v0;
  175. struct s5p_gpio_bank v1;
  176. struct s5p_gpio_bank res1[0x1];
  177. struct s5p_gpio_bank v2;
  178. struct s5p_gpio_bank v3;
  179. struct s5p_gpio_bank res2[0x1];
  180. struct s5p_gpio_bank v4;
  181. };
  182. struct exynos5_gpio_part4 {
  183. struct s5p_gpio_bank z;
  184. };
  185. /* functions */
  186. void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg);
  187. void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en);
  188. void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio);
  189. void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en);
  190. unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio);
  191. void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode);
  192. void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode);
  193. void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
  194. /* GPIO pins per bank */
  195. #define GPIO_PER_BANK 8
  196. #define exynos4_gpio_part1_get_nr(bank, pin) \
  197. ((((((unsigned int) &(((struct exynos4_gpio_part1 *) \
  198. EXYNOS4_GPIO_PART1_BASE)->bank)) \
  199. - EXYNOS4_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
  200. * GPIO_PER_BANK) + pin)
  201. #define EXYNOS4_GPIO_PART1_MAX ((sizeof(struct exynos4_gpio_part1) \
  202. / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
  203. #define exynos4_gpio_part2_get_nr(bank, pin) \
  204. (((((((unsigned int) &(((struct exynos4_gpio_part2 *) \
  205. EXYNOS4_GPIO_PART2_BASE)->bank)) \
  206. - EXYNOS4_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
  207. * GPIO_PER_BANK) + pin) + EXYNOS4_GPIO_PART1_MAX)
  208. #define exynos4x12_gpio_part1_get_nr(bank, pin) \
  209. ((((((unsigned int) &(((struct exynos4x12_gpio_part1 *) \
  210. EXYNOS4X12_GPIO_PART1_BASE)->bank)) \
  211. - EXYNOS4X12_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
  212. * GPIO_PER_BANK) + pin)
  213. #define EXYNOS4X12_GPIO_PART1_MAX ((sizeof(struct exynos4x12_gpio_part1) \
  214. / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
  215. #define exynos4x12_gpio_part2_get_nr(bank, pin) \
  216. (((((((unsigned int) &(((struct exynos4x12_gpio_part2 *) \
  217. EXYNOS4X12_GPIO_PART2_BASE)->bank)) \
  218. - EXYNOS4X12_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
  219. * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART1_MAX)
  220. #define EXYNOS4X12_GPIO_PART2_MAX ((sizeof(struct exynos4x12_gpio_part2) \
  221. / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
  222. #define exynos4x12_gpio_part3_get_nr(bank, pin) \
  223. (((((((unsigned int) &(((struct exynos4x12_gpio_part3 *) \
  224. EXYNOS4X12_GPIO_PART3_BASE)->bank)) \
  225. - EXYNOS4X12_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \
  226. * GPIO_PER_BANK) + pin) + EXYNOS4X12_GPIO_PART2_MAX)
  227. #define exynos5_gpio_part1_get_nr(bank, pin) \
  228. ((((((unsigned int) &(((struct exynos5_gpio_part1 *) \
  229. EXYNOS5_GPIO_PART1_BASE)->bank)) \
  230. - EXYNOS5_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
  231. * GPIO_PER_BANK) + pin)
  232. #define EXYNOS5_GPIO_PART1_MAX ((sizeof(struct exynos5_gpio_part1) \
  233. / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
  234. #define exynos5_gpio_part2_get_nr(bank, pin) \
  235. (((((((unsigned int) &(((struct exynos5_gpio_part2 *) \
  236. EXYNOS5_GPIO_PART2_BASE)->bank)) \
  237. - EXYNOS5_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
  238. * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART1_MAX)
  239. #define EXYNOS5_GPIO_PART2_MAX ((sizeof(struct exynos5_gpio_part2) \
  240. / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
  241. #define exynos5_gpio_part3_get_nr(bank, pin) \
  242. (((((((unsigned int) &(((struct exynos5_gpio_part3 *) \
  243. EXYNOS5_GPIO_PART3_BASE)->bank)) \
  244. - EXYNOS5_GPIO_PART3_BASE) / sizeof(struct s5p_gpio_bank)) \
  245. * GPIO_PER_BANK) + pin) + EXYNOS5_GPIO_PART2_MAX)
  246. static inline unsigned int s5p_gpio_base(int nr)
  247. {
  248. if (cpu_is_exynos5()) {
  249. if (nr < EXYNOS5_GPIO_PART1_MAX)
  250. return EXYNOS5_GPIO_PART1_BASE;
  251. else if (nr < EXYNOS5_GPIO_PART2_MAX)
  252. return EXYNOS5_GPIO_PART2_BASE;
  253. else
  254. return EXYNOS5_GPIO_PART3_BASE;
  255. } else if (cpu_is_exynos4()) {
  256. if (nr < EXYNOS4_GPIO_PART1_MAX)
  257. return EXYNOS4_GPIO_PART1_BASE;
  258. else
  259. return EXYNOS4_GPIO_PART2_BASE;
  260. }
  261. return 0;
  262. }
  263. static inline unsigned int s5p_gpio_part_max(int nr)
  264. {
  265. if (cpu_is_exynos5()) {
  266. if (nr < EXYNOS5_GPIO_PART1_MAX)
  267. return 0;
  268. else if (nr < EXYNOS5_GPIO_PART2_MAX)
  269. return EXYNOS5_GPIO_PART1_MAX;
  270. else
  271. return EXYNOS5_GPIO_PART2_MAX;
  272. } else if (cpu_is_exynos4()) {
  273. if (nr < EXYNOS4_GPIO_PART1_MAX)
  274. return 0;
  275. else
  276. return EXYNOS4_GPIO_PART1_MAX;
  277. }
  278. return 0;
  279. }
  280. #endif
  281. /* Pin configurations */
  282. #define GPIO_INPUT 0x0
  283. #define GPIO_OUTPUT 0x1
  284. #define GPIO_IRQ 0xf
  285. #define GPIO_FUNC(x) (x)
  286. /* Pull mode */
  287. #define GPIO_PULL_NONE 0x0
  288. #define GPIO_PULL_DOWN 0x1
  289. #define GPIO_PULL_UP 0x3
  290. /* Drive Strength level */
  291. #define GPIO_DRV_1X 0x0
  292. #define GPIO_DRV_3X 0x1
  293. #define GPIO_DRV_2X 0x2
  294. #define GPIO_DRV_4X 0x3
  295. #define GPIO_DRV_FAST 0x0
  296. #define GPIO_DRV_SLOW 0x1
  297. #endif