gpio.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * (C) Copyright 2007-2012
  3. * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
  4. * Tom Cubie <tangliang@allwinnertech.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef _SUNXI_GPIO_H
  9. #define _SUNXI_GPIO_H
  10. #include <linux/types.h>
  11. #include <asm/arch/cpu.h>
  12. /*
  13. * sunxi has 9 banks of gpio, they are:
  14. * PA0 - PA17 | PB0 - PB23 | PC0 - PC24
  15. * PD0 - PD27 | PE0 - PE31 | PF0 - PF5
  16. * PG0 - PG9 | PH0 - PH27 | PI0 - PI12
  17. */
  18. #define SUNXI_GPIO_A 0
  19. #define SUNXI_GPIO_B 1
  20. #define SUNXI_GPIO_C 2
  21. #define SUNXI_GPIO_D 3
  22. #define SUNXI_GPIO_E 4
  23. #define SUNXI_GPIO_F 5
  24. #define SUNXI_GPIO_G 6
  25. #define SUNXI_GPIO_H 7
  26. #define SUNXI_GPIO_I 8
  27. /*
  28. * This defines the number of GPIO banks for the _main_ GPIO controller.
  29. * You should fix up the padding in struct sunxi_gpio_reg below if you
  30. * change this.
  31. */
  32. #define SUNXI_GPIO_BANKS 9
  33. /*
  34. * sun6i/sun8i and later SoCs have an additional GPIO controller (R_PIO)
  35. * at a different register offset.
  36. *
  37. * sun6i has 2 banks:
  38. * PL0 - PL8 | PM0 - PM7
  39. *
  40. * sun8i has 1 bank:
  41. * PL0 - PL11
  42. */
  43. #define SUNXI_GPIO_L 11
  44. #define SUNXI_GPIO_M 12
  45. struct sunxi_gpio {
  46. u32 cfg[4];
  47. u32 dat;
  48. u32 drv[2];
  49. u32 pull[2];
  50. };
  51. /* gpio interrupt control */
  52. struct sunxi_gpio_int {
  53. u32 cfg[3];
  54. u32 ctl;
  55. u32 sta;
  56. u32 deb; /* interrupt debounce */
  57. };
  58. struct sunxi_gpio_reg {
  59. struct sunxi_gpio gpio_bank[SUNXI_GPIO_BANKS];
  60. u8 res[0xbc];
  61. struct sunxi_gpio_int gpio_int;
  62. };
  63. #define BANK_TO_GPIO(bank) (((bank) < SUNXI_GPIO_L) ? \
  64. &((struct sunxi_gpio_reg *)SUNXI_PIO_BASE)->gpio_bank[bank] : \
  65. &((struct sunxi_gpio_reg *)SUNXI_R_PIO_BASE)->gpio_bank[(bank) - SUNXI_GPIO_L])
  66. #define GPIO_BANK(pin) ((pin) >> 5)
  67. #define GPIO_NUM(pin) ((pin) & 0x1f)
  68. #define GPIO_CFG_INDEX(pin) (((pin) & 0x1f) >> 3)
  69. #define GPIO_CFG_OFFSET(pin) ((((pin) & 0x1f) & 0x7) << 2)
  70. #define GPIO_DRV_INDEX(pin) (((pin) & 0x1f) >> 4)
  71. #define GPIO_DRV_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1)
  72. #define GPIO_PULL_INDEX(pin) (((pin) & 0x1f) >> 4)
  73. #define GPIO_PULL_OFFSET(pin) ((((pin) & 0x1f) & 0xf) << 1)
  74. /* GPIO bank sizes */
  75. #define SUNXI_GPIO_A_NR 32
  76. #define SUNXI_GPIO_B_NR 32
  77. #define SUNXI_GPIO_C_NR 32
  78. #define SUNXI_GPIO_D_NR 32
  79. #define SUNXI_GPIO_E_NR 32
  80. #define SUNXI_GPIO_F_NR 32
  81. #define SUNXI_GPIO_G_NR 32
  82. #define SUNXI_GPIO_H_NR 32
  83. #define SUNXI_GPIO_I_NR 32
  84. #define SUNXI_GPIO_L_NR 32
  85. #define SUNXI_GPIO_M_NR 32
  86. #define SUNXI_GPIO_NEXT(__gpio) \
  87. ((__gpio##_START) + (__gpio##_NR) + 0)
  88. enum sunxi_gpio_number {
  89. SUNXI_GPIO_A_START = 0,
  90. SUNXI_GPIO_B_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_A),
  91. SUNXI_GPIO_C_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_B),
  92. SUNXI_GPIO_D_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_C),
  93. SUNXI_GPIO_E_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_D),
  94. SUNXI_GPIO_F_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_E),
  95. SUNXI_GPIO_G_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_F),
  96. SUNXI_GPIO_H_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_G),
  97. SUNXI_GPIO_I_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_H),
  98. SUNXI_GPIO_L_START = 352,
  99. SUNXI_GPIO_M_START = SUNXI_GPIO_NEXT(SUNXI_GPIO_L),
  100. };
  101. /* SUNXI GPIO number definitions */
  102. #define SUNXI_GPA(_nr) (SUNXI_GPIO_A_START + (_nr))
  103. #define SUNXI_GPB(_nr) (SUNXI_GPIO_B_START + (_nr))
  104. #define SUNXI_GPC(_nr) (SUNXI_GPIO_C_START + (_nr))
  105. #define SUNXI_GPD(_nr) (SUNXI_GPIO_D_START + (_nr))
  106. #define SUNXI_GPE(_nr) (SUNXI_GPIO_E_START + (_nr))
  107. #define SUNXI_GPF(_nr) (SUNXI_GPIO_F_START + (_nr))
  108. #define SUNXI_GPG(_nr) (SUNXI_GPIO_G_START + (_nr))
  109. #define SUNXI_GPH(_nr) (SUNXI_GPIO_H_START + (_nr))
  110. #define SUNXI_GPI(_nr) (SUNXI_GPIO_I_START + (_nr))
  111. #define SUNXI_GPL(_nr) (SUNXI_GPIO_L_START + (_nr))
  112. #define SUNXI_GPM(_nr) (SUNXI_GPIO_M_START + (_nr))
  113. /* GPIO pin function config */
  114. #define SUNXI_GPIO_INPUT 0
  115. #define SUNXI_GPIO_OUTPUT 1
  116. #define SUNXI_GPA0_EMAC 2
  117. #define SUN7I_GPA0_GMAC 5
  118. #define SUNXI_GPB0_TWI0 2
  119. #define SUN4I_GPB22_UART0_TX 2
  120. #define SUN4I_GPB23_UART0_RX 2
  121. #define SUN5I_GPB19_UART0_TX 2
  122. #define SUN5I_GPB20_UART0_RX 2
  123. #define SUN5I_GPG3_SDC1 2
  124. #define SUN5I_GPG3_UART1_TX 4
  125. #define SUN5I_GPG4_UART1_RX 4
  126. #define SUNXI_GPC6_SDC2 3
  127. #define SUNXI_GPF0_SDC0 2
  128. #define SUNXI_GPF2_SDC0 2
  129. #ifdef CONFIG_MACH_SUN8I
  130. #define SUNXI_GPF2_UART0_TX 3
  131. #define SUNXI_GPF4_UART0_RX 3
  132. #else
  133. #define SUNXI_GPF2_UART0_TX 4
  134. #define SUNXI_GPF4_UART0_RX 4
  135. #endif
  136. #define SUN4I_GPG0_SDC1 4
  137. #define SUN4I_GPH22_SDC1 5
  138. #define SUN6I_GPH20_UART0_TX 2
  139. #define SUN6I_GPH21_UART0_RX 2
  140. #define SUN4I_GPI4_SDC3 2
  141. #define SUNXI_GPL0_R_P2WI_SCK 3
  142. #define SUNXI_GPL1_R_P2WI_SDA 3
  143. #define SUN8I_GPL2_R_UART_TX 2
  144. #define SUN8I_GPL3_R_UART_RX 2
  145. /* GPIO pin pull-up/down config */
  146. #define SUNXI_GPIO_PULL_DISABLE 0
  147. #define SUNXI_GPIO_PULL_UP 1
  148. #define SUNXI_GPIO_PULL_DOWN 2
  149. void sunxi_gpio_set_cfgbank(struct sunxi_gpio *pio, int bank_offset, u32 val);
  150. void sunxi_gpio_set_cfgpin(u32 pin, u32 val);
  151. int sunxi_gpio_get_cfgbank(struct sunxi_gpio *pio, int bank_offset);
  152. int sunxi_gpio_get_cfgpin(u32 pin);
  153. int sunxi_gpio_set_drv(u32 pin, u32 val);
  154. int sunxi_gpio_set_pull(u32 pin, u32 val);
  155. int sunxi_name_to_gpio(const char *name);
  156. #define name_to_gpio(name) sunxi_name_to_gpio(name)
  157. #endif /* _SUNXI_GPIO_H */