gpio.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * (C) Copyright 2010 Samsung Electronics
  3. * Minkyu Kang <mk7.kang@samsung.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __ASM_ARCH_GPIO_H
  8. #define __ASM_ARCH_GPIO_H
  9. #ifndef __ASSEMBLY__
  10. struct s5p_gpio_bank {
  11. unsigned int con;
  12. unsigned int dat;
  13. unsigned int pull;
  14. unsigned int drv;
  15. unsigned int pdn_con;
  16. unsigned int pdn_pull;
  17. unsigned char res1[8];
  18. };
  19. struct exynos4_gpio_part1 {
  20. struct s5p_gpio_bank a0;
  21. struct s5p_gpio_bank a1;
  22. struct s5p_gpio_bank b;
  23. struct s5p_gpio_bank c0;
  24. struct s5p_gpio_bank c1;
  25. struct s5p_gpio_bank d0;
  26. struct s5p_gpio_bank d1;
  27. struct s5p_gpio_bank e0;
  28. struct s5p_gpio_bank e1;
  29. struct s5p_gpio_bank e2;
  30. struct s5p_gpio_bank e3;
  31. struct s5p_gpio_bank e4;
  32. struct s5p_gpio_bank f0;
  33. struct s5p_gpio_bank f1;
  34. struct s5p_gpio_bank f2;
  35. struct s5p_gpio_bank f3;
  36. };
  37. struct exynos4_gpio_part2 {
  38. struct s5p_gpio_bank j0;
  39. struct s5p_gpio_bank j1;
  40. struct s5p_gpio_bank k0;
  41. struct s5p_gpio_bank k1;
  42. struct s5p_gpio_bank k2;
  43. struct s5p_gpio_bank k3;
  44. struct s5p_gpio_bank l0;
  45. struct s5p_gpio_bank l1;
  46. struct s5p_gpio_bank l2;
  47. struct s5p_gpio_bank y0;
  48. struct s5p_gpio_bank y1;
  49. struct s5p_gpio_bank y2;
  50. struct s5p_gpio_bank y3;
  51. struct s5p_gpio_bank y4;
  52. struct s5p_gpio_bank y5;
  53. struct s5p_gpio_bank y6;
  54. struct s5p_gpio_bank res1[80];
  55. struct s5p_gpio_bank x0;
  56. struct s5p_gpio_bank x1;
  57. struct s5p_gpio_bank x2;
  58. struct s5p_gpio_bank x3;
  59. };
  60. struct exynos4_gpio_part3 {
  61. struct s5p_gpio_bank z;
  62. };
  63. struct exynos4x12_gpio_part1 {
  64. struct s5p_gpio_bank a0;
  65. struct s5p_gpio_bank a1;
  66. struct s5p_gpio_bank b;
  67. struct s5p_gpio_bank c0;
  68. struct s5p_gpio_bank c1;
  69. struct s5p_gpio_bank d0;
  70. struct s5p_gpio_bank d1;
  71. struct s5p_gpio_bank res1[0x5];
  72. struct s5p_gpio_bank f0;
  73. struct s5p_gpio_bank f1;
  74. struct s5p_gpio_bank f2;
  75. struct s5p_gpio_bank f3;
  76. struct s5p_gpio_bank res2[0x2];
  77. struct s5p_gpio_bank j0;
  78. struct s5p_gpio_bank j1;
  79. };
  80. struct exynos4x12_gpio_part2 {
  81. struct s5p_gpio_bank res1[0x2];
  82. struct s5p_gpio_bank k0;
  83. struct s5p_gpio_bank k1;
  84. struct s5p_gpio_bank k2;
  85. struct s5p_gpio_bank k3;
  86. struct s5p_gpio_bank l0;
  87. struct s5p_gpio_bank l1;
  88. struct s5p_gpio_bank l2;
  89. struct s5p_gpio_bank y0;
  90. struct s5p_gpio_bank y1;
  91. struct s5p_gpio_bank y2;
  92. struct s5p_gpio_bank y3;
  93. struct s5p_gpio_bank y4;
  94. struct s5p_gpio_bank y5;
  95. struct s5p_gpio_bank y6;
  96. struct s5p_gpio_bank res2[0x3];
  97. struct s5p_gpio_bank m0;
  98. struct s5p_gpio_bank m1;
  99. struct s5p_gpio_bank m2;
  100. struct s5p_gpio_bank m3;
  101. struct s5p_gpio_bank m4;
  102. struct s5p_gpio_bank res3[0x48];
  103. struct s5p_gpio_bank x0;
  104. struct s5p_gpio_bank x1;
  105. struct s5p_gpio_bank x2;
  106. struct s5p_gpio_bank x3;
  107. };
  108. struct exynos4x12_gpio_part3 {
  109. struct s5p_gpio_bank z;
  110. };
  111. struct exynos4x12_gpio_part4 {
  112. struct s5p_gpio_bank v0;
  113. struct s5p_gpio_bank v1;
  114. struct s5p_gpio_bank res1[0x1];
  115. struct s5p_gpio_bank v2;
  116. struct s5p_gpio_bank v3;
  117. struct s5p_gpio_bank res2[0x1];
  118. struct s5p_gpio_bank v4;
  119. };
  120. struct exynos5420_gpio_part1 {
  121. struct s5p_gpio_bank a0;
  122. struct s5p_gpio_bank a1;
  123. struct s5p_gpio_bank a2;
  124. struct s5p_gpio_bank b0;
  125. struct s5p_gpio_bank b1;
  126. struct s5p_gpio_bank b2;
  127. struct s5p_gpio_bank b3;
  128. struct s5p_gpio_bank b4;
  129. struct s5p_gpio_bank h0;
  130. };
  131. struct exynos5420_gpio_part2 {
  132. struct s5p_gpio_bank y7; /* 0x1340_0000 */
  133. struct s5p_gpio_bank res[0x5f]; /* */
  134. struct s5p_gpio_bank x0; /* 0x1340_0C00 */
  135. struct s5p_gpio_bank x1; /* 0x1340_0C20 */
  136. struct s5p_gpio_bank x2; /* 0x1340_0C40 */
  137. struct s5p_gpio_bank x3; /* 0x1340_0C60 */
  138. };
  139. struct exynos5420_gpio_part3 {
  140. struct s5p_gpio_bank c0;
  141. struct s5p_gpio_bank c1;
  142. struct s5p_gpio_bank c2;
  143. struct s5p_gpio_bank c3;
  144. struct s5p_gpio_bank c4;
  145. struct s5p_gpio_bank d1;
  146. struct s5p_gpio_bank y0;
  147. struct s5p_gpio_bank y1;
  148. struct s5p_gpio_bank y2;
  149. struct s5p_gpio_bank y3;
  150. struct s5p_gpio_bank y4;
  151. struct s5p_gpio_bank y5;
  152. struct s5p_gpio_bank y6;
  153. };
  154. struct exynos5420_gpio_part4 {
  155. struct s5p_gpio_bank e0; /* 0x1400_0000 */
  156. struct s5p_gpio_bank e1; /* 0x1400_0020 */
  157. struct s5p_gpio_bank f0; /* 0x1400_0040 */
  158. struct s5p_gpio_bank f1; /* 0x1400_0060 */
  159. struct s5p_gpio_bank g0; /* 0x1400_0080 */
  160. struct s5p_gpio_bank g1; /* 0x1400_00A0 */
  161. struct s5p_gpio_bank g2; /* 0x1400_00C0 */
  162. struct s5p_gpio_bank j4; /* 0x1400_00E0 */
  163. };
  164. struct exynos5420_gpio_part5 {
  165. struct s5p_gpio_bank z0; /* 0x0386_0000 */
  166. };
  167. struct exynos5_gpio_part1 {
  168. struct s5p_gpio_bank a0;
  169. struct s5p_gpio_bank a1;
  170. struct s5p_gpio_bank a2;
  171. struct s5p_gpio_bank b0;
  172. struct s5p_gpio_bank b1;
  173. struct s5p_gpio_bank b2;
  174. struct s5p_gpio_bank b3;
  175. struct s5p_gpio_bank c0;
  176. struct s5p_gpio_bank c1;
  177. struct s5p_gpio_bank c2;
  178. struct s5p_gpio_bank c3;
  179. struct s5p_gpio_bank d0;
  180. struct s5p_gpio_bank d1;
  181. struct s5p_gpio_bank y0;
  182. struct s5p_gpio_bank y1;
  183. struct s5p_gpio_bank y2;
  184. struct s5p_gpio_bank y3;
  185. struct s5p_gpio_bank y4;
  186. struct s5p_gpio_bank y5;
  187. struct s5p_gpio_bank y6;
  188. struct s5p_gpio_bank res1[0x3];
  189. struct s5p_gpio_bank c4;
  190. struct s5p_gpio_bank res2[0x48];
  191. struct s5p_gpio_bank x0;
  192. struct s5p_gpio_bank x1;
  193. struct s5p_gpio_bank x2;
  194. struct s5p_gpio_bank x3;
  195. };
  196. struct exynos5_gpio_part2 {
  197. struct s5p_gpio_bank e0;
  198. struct s5p_gpio_bank e1;
  199. struct s5p_gpio_bank f0;
  200. struct s5p_gpio_bank f1;
  201. struct s5p_gpio_bank g0;
  202. struct s5p_gpio_bank g1;
  203. struct s5p_gpio_bank g2;
  204. struct s5p_gpio_bank h0;
  205. struct s5p_gpio_bank h1;
  206. };
  207. struct exynos5_gpio_part3 {
  208. struct s5p_gpio_bank v0;
  209. struct s5p_gpio_bank v1;
  210. struct s5p_gpio_bank res1[0x1];
  211. struct s5p_gpio_bank v2;
  212. struct s5p_gpio_bank v3;
  213. struct s5p_gpio_bank res2[0x1];
  214. struct s5p_gpio_bank v4;
  215. };
  216. struct exynos5_gpio_part4 {
  217. struct s5p_gpio_bank z;
  218. };
  219. /* functions */
  220. void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg);
  221. void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en);
  222. void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio);
  223. void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en);
  224. unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio);
  225. void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode);
  226. void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode);
  227. void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
  228. /* GPIO pins per bank */
  229. #define GPIO_PER_BANK 8
  230. #define S5P_GPIO_PART_SHIFT (24)
  231. #define S5P_GPIO_PART_MASK (0xff)
  232. #define S5P_GPIO_BANK_SHIFT (8)
  233. #define S5P_GPIO_BANK_MASK (0xffff)
  234. #define S5P_GPIO_PIN_MASK (0xff)
  235. #define S5P_GPIO_SET_PART(x) \
  236. (((x) & S5P_GPIO_PART_MASK) << S5P_GPIO_PART_SHIFT)
  237. #define S5P_GPIO_GET_PART(x) \
  238. (((x) >> S5P_GPIO_PART_SHIFT) & S5P_GPIO_PART_MASK)
  239. #define S5P_GPIO_SET_PIN(x) \
  240. ((x) & S5P_GPIO_PIN_MASK)
  241. #define EXYNOS4_GPIO_SET_BANK(part, bank) \
  242. ((((unsigned)&(((struct exynos4_gpio_part##part *) \
  243. EXYNOS4_GPIO_PART##part##_BASE)->bank) \
  244. - EXYNOS4_GPIO_PART##part##_BASE) \
  245. & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
  246. #define EXYNOS4X12_GPIO_SET_BANK(part, bank) \
  247. ((((unsigned)&(((struct exynos4x12_gpio_part##part *) \
  248. EXYNOS4X12_GPIO_PART##part##_BASE)->bank) \
  249. - EXYNOS4X12_GPIO_PART##part##_BASE) \
  250. & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
  251. #define EXYNOS5_GPIO_SET_BANK(part, bank) \
  252. ((((unsigned)&(((struct exynos5420_gpio_part##part *) \
  253. EXYNOS5420_GPIO_PART##part##_BASE)->bank) \
  254. - EXYNOS5_GPIO_PART##part##_BASE) \
  255. & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
  256. #define EXYNOS5420_GPIO_SET_BANK(part, bank) \
  257. ((((unsigned)&(((struct exynos5420_gpio_part##part *) \
  258. EXYNOS5420_GPIO_PART##part##_BASE)->bank) \
  259. - EXYNOS5420_GPIO_PART##part##_BASE) \
  260. & S5P_GPIO_BANK_MASK) << S5P_GPIO_BANK_SHIFT)
  261. #define exynos4_gpio_get(part, bank, pin) \
  262. (S5P_GPIO_SET_PART(part) | \
  263. EXYNOS4_GPIO_SET_BANK(part, bank) | \
  264. S5P_GPIO_SET_PIN(pin))
  265. #define exynos4x12_gpio_get(part, bank, pin) \
  266. (S5P_GPIO_SET_PART(part) | \
  267. EXYNOS4X12_GPIO_SET_BANK(part, bank) | \
  268. S5P_GPIO_SET_PIN(pin))
  269. #define exynos5420_gpio_get(part, bank, pin) \
  270. (S5P_GPIO_SET_PART(part) | \
  271. EXYNOS5420_GPIO_SET_BANK(part, bank) | \
  272. S5P_GPIO_SET_PIN(pin))
  273. #define exynos5_gpio_get(part, bank, pin) \
  274. (S5P_GPIO_SET_PART(part) | \
  275. EXYNOS5_GPIO_SET_BANK(part, bank) | \
  276. S5P_GPIO_SET_PIN(pin))
  277. static inline unsigned int s5p_gpio_base(int gpio)
  278. {
  279. unsigned gpio_part = S5P_GPIO_GET_PART(gpio);
  280. switch (gpio_part) {
  281. case 1:
  282. return samsung_get_base_gpio_part1();
  283. case 2:
  284. return samsung_get_base_gpio_part2();
  285. case 3:
  286. return samsung_get_base_gpio_part3();
  287. case 4:
  288. return samsung_get_base_gpio_part4();
  289. default:
  290. return 0;
  291. }
  292. }
  293. #endif
  294. /* Pin configurations */
  295. #define GPIO_INPUT 0x0
  296. #define GPIO_OUTPUT 0x1
  297. #define GPIO_IRQ 0xf
  298. #define GPIO_FUNC(x) (x)
  299. /* Pull mode */
  300. #define GPIO_PULL_NONE 0x0
  301. #define GPIO_PULL_DOWN 0x1
  302. #define GPIO_PULL_UP 0x3
  303. /* Drive Strength level */
  304. #define GPIO_DRV_1X 0x0
  305. #define GPIO_DRV_3X 0x1
  306. #define GPIO_DRV_2X 0x2
  307. #define GPIO_DRV_4X 0x3
  308. #define GPIO_DRV_FAST 0x0
  309. #define GPIO_DRV_SLOW 0x1
  310. #endif