gpio-pxa.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Written by Philipp Zabel <philipp.zabel@gmail.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. */
  19. #ifndef __MACH_PXA_GPIO_PXA_H
  20. #define __MACH_PXA_GPIO_PXA_H
  21. #include <mach/irqs.h>
  22. #include <mach/hardware.h>
  23. #define GPIO_REGS_VIRT io_p2v(0x40E00000)
  24. #define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2))
  25. #define GPIO_REG(x) (*(volatile u32 *)(GPIO_REGS_VIRT + (x)))
  26. /* GPIO Pin Level Registers */
  27. #define GPLR0 GPIO_REG(BANK_OFF(0) + 0x00)
  28. #define GPLR1 GPIO_REG(BANK_OFF(1) + 0x00)
  29. #define GPLR2 GPIO_REG(BANK_OFF(2) + 0x00)
  30. #define GPLR3 GPIO_REG(BANK_OFF(3) + 0x00)
  31. /* GPIO Pin Direction Registers */
  32. #define GPDR0 GPIO_REG(BANK_OFF(0) + 0x0c)
  33. #define GPDR1 GPIO_REG(BANK_OFF(1) + 0x0c)
  34. #define GPDR2 GPIO_REG(BANK_OFF(2) + 0x0c)
  35. #define GPDR3 GPIO_REG(BANK_OFF(3) + 0x0c)
  36. /* GPIO Pin Output Set Registers */
  37. #define GPSR0 GPIO_REG(BANK_OFF(0) + 0x18)
  38. #define GPSR1 GPIO_REG(BANK_OFF(1) + 0x18)
  39. #define GPSR2 GPIO_REG(BANK_OFF(2) + 0x18)
  40. #define GPSR3 GPIO_REG(BANK_OFF(3) + 0x18)
  41. /* GPIO Pin Output Clear Registers */
  42. #define GPCR0 GPIO_REG(BANK_OFF(0) + 0x24)
  43. #define GPCR1 GPIO_REG(BANK_OFF(1) + 0x24)
  44. #define GPCR2 GPIO_REG(BANK_OFF(2) + 0x24)
  45. #define GPCR3 GPIO_REG(BANK_OFF(3) + 0x24)
  46. /* GPIO Rising Edge Detect Registers */
  47. #define GRER0 GPIO_REG(BANK_OFF(0) + 0x30)
  48. #define GRER1 GPIO_REG(BANK_OFF(1) + 0x30)
  49. #define GRER2 GPIO_REG(BANK_OFF(2) + 0x30)
  50. #define GRER3 GPIO_REG(BANK_OFF(3) + 0x30)
  51. /* GPIO Falling Edge Detect Registers */
  52. #define GFER0 GPIO_REG(BANK_OFF(0) + 0x3c)
  53. #define GFER1 GPIO_REG(BANK_OFF(1) + 0x3c)
  54. #define GFER2 GPIO_REG(BANK_OFF(2) + 0x3c)
  55. #define GFER3 GPIO_REG(BANK_OFF(3) + 0x3c)
  56. /* GPIO Edge Detect Status Registers */
  57. #define GEDR0 GPIO_REG(BANK_OFF(0) + 0x48)
  58. #define GEDR1 GPIO_REG(BANK_OFF(1) + 0x48)
  59. #define GEDR2 GPIO_REG(BANK_OFF(2) + 0x48)
  60. #define GEDR3 GPIO_REG(BANK_OFF(3) + 0x48)
  61. /* GPIO Alternate Function Select Registers */
  62. #define GAFR0_L GPIO_REG(0x0054)
  63. #define GAFR0_U GPIO_REG(0x0058)
  64. #define GAFR1_L GPIO_REG(0x005C)
  65. #define GAFR1_U GPIO_REG(0x0060)
  66. #define GAFR2_L GPIO_REG(0x0064)
  67. #define GAFR2_U GPIO_REG(0x0068)
  68. #define GAFR3_L GPIO_REG(0x006C)
  69. #define GAFR3_U GPIO_REG(0x0070)
  70. /* More handy macros. The argument is a literal GPIO number. */
  71. #define GPIO_bit(x) (1 << ((x) & 0x1f))
  72. #define GPLR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x00)
  73. #define GPDR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x0c)
  74. #define GPSR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x18)
  75. #define GPCR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x24)
  76. #define GRER(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x30)
  77. #define GFER(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x3c)
  78. #define GEDR(x) GPIO_REG(BANK_OFF((x) >> 5) + 0x48)
  79. #define GAFR(x) GPIO_REG(0x54 + (((x) & 0x70) >> 2))
  80. #define NR_BUILTIN_GPIO PXA_GPIO_IRQ_NUM
  81. #define gpio_to_bank(gpio) ((gpio) >> 5)
  82. #ifdef CONFIG_CPU_PXA26x
  83. /* GPIO86/87/88/89 on PXA26x have their direction bits in GPDR2 inverted,
  84. * as well as their Alternate Function value being '1' for GPIO in GAFRx.
  85. */
  86. static inline int __gpio_is_inverted(unsigned gpio)
  87. {
  88. return cpu_is_pxa25x() && gpio > 85;
  89. }
  90. #else
  91. static inline int __gpio_is_inverted(unsigned gpio) { return 0; }
  92. #endif
  93. /*
  94. * On PXA25x and PXA27x, GAFRx and GPDRx together decide the alternate
  95. * function of a GPIO, and GPDRx cannot be altered once configured. It
  96. * is attributed as "occupied" here (I know this terminology isn't
  97. * accurate, you are welcome to propose a better one :-)
  98. */
  99. static inline int __gpio_is_occupied(unsigned gpio)
  100. {
  101. if (cpu_is_pxa27x() || cpu_is_pxa25x()) {
  102. int af = (GAFR(gpio) >> ((gpio & 0xf) * 2)) & 0x3;
  103. int dir = GPDR(gpio) & GPIO_bit(gpio);
  104. if (__gpio_is_inverted(gpio))
  105. return af != 1 || dir == 0;
  106. else
  107. return af != 0 || dir != 0;
  108. } else
  109. return GPDR(gpio) & GPIO_bit(gpio);
  110. }
  111. #include <plat/gpio-pxa.h>
  112. #endif /* __MACH_PXA_GPIO_PXA_H */