gpio.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 s5pc210_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 s5pc210_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 s5pc210_gpio_part3 {
  74. struct s5p_gpio_bank z;
  75. };
  76. /* functions */
  77. void s5p_gpio_cfg_pin(struct s5p_gpio_bank *bank, int gpio, int cfg);
  78. void s5p_gpio_direction_output(struct s5p_gpio_bank *bank, int gpio, int en);
  79. void s5p_gpio_direction_input(struct s5p_gpio_bank *bank, int gpio);
  80. void s5p_gpio_set_value(struct s5p_gpio_bank *bank, int gpio, int en);
  81. unsigned int s5p_gpio_get_value(struct s5p_gpio_bank *bank, int gpio);
  82. void s5p_gpio_set_pull(struct s5p_gpio_bank *bank, int gpio, int mode);
  83. void s5p_gpio_set_drv(struct s5p_gpio_bank *bank, int gpio, int mode);
  84. void s5p_gpio_set_rate(struct s5p_gpio_bank *bank, int gpio, int mode);
  85. /* GPIO pins per bank */
  86. #define GPIO_PER_BANK 8
  87. #define s5pc210_gpio_part1_get_nr(bank, pin) \
  88. ((((((unsigned int) &(((struct s5pc210_gpio_part1 *) \
  89. S5PC210_GPIO_PART1_BASE)->bank)) \
  90. - S5PC210_GPIO_PART1_BASE) / sizeof(struct s5p_gpio_bank)) \
  91. * GPIO_PER_BANK) + pin)
  92. #define GPIO_PART1_MAX ((sizeof(struct s5pc210_gpio_part1) \
  93. / sizeof(struct s5p_gpio_bank)) * GPIO_PER_BANK)
  94. #define s5pc210_gpio_part2_get_nr(bank, pin) \
  95. (((((((unsigned int) &(((struct s5pc210_gpio_part2 *) \
  96. S5PC210_GPIO_PART2_BASE)->bank)) \
  97. - S5PC210_GPIO_PART2_BASE) / sizeof(struct s5p_gpio_bank)) \
  98. * GPIO_PER_BANK) + pin) + GPIO_PART1_MAX)
  99. static inline unsigned int s5p_gpio_base(int nr)
  100. {
  101. if (nr < GPIO_PART1_MAX)
  102. return S5PC210_GPIO_PART1_BASE;
  103. else
  104. return S5PC210_GPIO_PART2_BASE;
  105. return 0;
  106. }
  107. #endif
  108. /* Pin configurations */
  109. #define GPIO_INPUT 0x0
  110. #define GPIO_OUTPUT 0x1
  111. #define GPIO_IRQ 0xf
  112. #define GPIO_FUNC(x) (x)
  113. /* Pull mode */
  114. #define GPIO_PULL_NONE 0x0
  115. #define GPIO_PULL_DOWN 0x1
  116. #define GPIO_PULL_UP 0x3
  117. /* Drive Strength level */
  118. #define GPIO_DRV_1X 0x0
  119. #define GPIO_DRV_3X 0x1
  120. #define GPIO_DRV_2X 0x2
  121. #define GPIO_DRV_4X 0x3
  122. #define GPIO_DRV_FAST 0x0
  123. #define GPIO_DRV_SLOW 0x1
  124. #endif