gpio.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * Copyright 2006-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #ifndef __ARCH_BLACKFIN_GPIO_H__
  7. #define __ARCH_BLACKFIN_GPIO_H__
  8. #define gpio_bank(x) ((x) >> 4)
  9. #define gpio_bit(x) (1<<((x) & 0xF))
  10. #define gpio_sub_n(x) ((x) & 0xF)
  11. #define GPIO_BANKSIZE 16
  12. #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
  13. #include <mach/gpio.h>
  14. #define PERIPHERAL_USAGE 1
  15. #define GPIO_USAGE 0
  16. #ifndef BFIN_GPIO_PINT
  17. # define BFIN_GPIO_PINT 0
  18. #endif
  19. #ifndef __ASSEMBLY__
  20. #include <linux/compiler.h>
  21. /***********************************************************
  22. *
  23. * FUNCTIONS: Blackfin General Purpose Ports Access Functions
  24. *
  25. * INPUTS/OUTPUTS:
  26. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  27. *
  28. *
  29. * DESCRIPTION: These functions abstract direct register access
  30. * to Blackfin processor General Purpose
  31. * Ports Regsiters
  32. *
  33. * CAUTION: These functions do not belong to the GPIO Driver API
  34. *************************************************************
  35. * MODIFICATION HISTORY :
  36. **************************************************************/
  37. #if !BFIN_GPIO_PINT
  38. void set_gpio_dir(unsigned, unsigned short);
  39. void set_gpio_inen(unsigned, unsigned short);
  40. void set_gpio_polar(unsigned, unsigned short);
  41. void set_gpio_edge(unsigned, unsigned short);
  42. void set_gpio_both(unsigned, unsigned short);
  43. void set_gpio_data(unsigned, unsigned short);
  44. void set_gpio_maska(unsigned, unsigned short);
  45. void set_gpio_maskb(unsigned, unsigned short);
  46. void set_gpio_toggle(unsigned);
  47. void set_gpiop_dir(unsigned, unsigned short);
  48. void set_gpiop_inen(unsigned, unsigned short);
  49. void set_gpiop_polar(unsigned, unsigned short);
  50. void set_gpiop_edge(unsigned, unsigned short);
  51. void set_gpiop_both(unsigned, unsigned short);
  52. void set_gpiop_data(unsigned, unsigned short);
  53. void set_gpiop_maska(unsigned, unsigned short);
  54. void set_gpiop_maskb(unsigned, unsigned short);
  55. unsigned short get_gpio_dir(unsigned);
  56. unsigned short get_gpio_inen(unsigned);
  57. unsigned short get_gpio_polar(unsigned);
  58. unsigned short get_gpio_edge(unsigned);
  59. unsigned short get_gpio_both(unsigned);
  60. unsigned short get_gpio_maska(unsigned);
  61. unsigned short get_gpio_maskb(unsigned);
  62. unsigned short get_gpio_data(unsigned);
  63. unsigned short get_gpiop_dir(unsigned);
  64. unsigned short get_gpiop_inen(unsigned);
  65. unsigned short get_gpiop_polar(unsigned);
  66. unsigned short get_gpiop_edge(unsigned);
  67. unsigned short get_gpiop_both(unsigned);
  68. unsigned short get_gpiop_maska(unsigned);
  69. unsigned short get_gpiop_maskb(unsigned);
  70. unsigned short get_gpiop_data(unsigned);
  71. struct gpio_port_t {
  72. unsigned short data;
  73. unsigned short dummy1;
  74. unsigned short data_clear;
  75. unsigned short dummy2;
  76. unsigned short data_set;
  77. unsigned short dummy3;
  78. unsigned short toggle;
  79. unsigned short dummy4;
  80. unsigned short maska;
  81. unsigned short dummy5;
  82. unsigned short maska_clear;
  83. unsigned short dummy6;
  84. unsigned short maska_set;
  85. unsigned short dummy7;
  86. unsigned short maska_toggle;
  87. unsigned short dummy8;
  88. unsigned short maskb;
  89. unsigned short dummy9;
  90. unsigned short maskb_clear;
  91. unsigned short dummy10;
  92. unsigned short maskb_set;
  93. unsigned short dummy11;
  94. unsigned short maskb_toggle;
  95. unsigned short dummy12;
  96. unsigned short dir;
  97. unsigned short dummy13;
  98. unsigned short polar;
  99. unsigned short dummy14;
  100. unsigned short edge;
  101. unsigned short dummy15;
  102. unsigned short both;
  103. unsigned short dummy16;
  104. unsigned short inen;
  105. };
  106. #endif
  107. #ifdef BFIN_SPECIAL_GPIO_BANKS
  108. void bfin_special_gpio_free(unsigned gpio);
  109. int bfin_special_gpio_request(unsigned gpio, const char *label);
  110. # ifdef CONFIG_PM
  111. void bfin_special_gpio_pm_hibernate_restore(void);
  112. void bfin_special_gpio_pm_hibernate_suspend(void);
  113. # endif
  114. #endif
  115. #ifdef CONFIG_PM
  116. int bfin_pm_standby_ctrl(unsigned ctrl);
  117. static inline int bfin_pm_standby_setup(void)
  118. {
  119. return bfin_pm_standby_ctrl(1);
  120. }
  121. static inline void bfin_pm_standby_restore(void)
  122. {
  123. bfin_pm_standby_ctrl(0);
  124. }
  125. void bfin_gpio_pm_hibernate_restore(void);
  126. void bfin_gpio_pm_hibernate_suspend(void);
  127. # if !BFIN_GPIO_PINT
  128. int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
  129. struct gpio_port_s {
  130. unsigned short data;
  131. unsigned short maska;
  132. unsigned short maskb;
  133. unsigned short dir;
  134. unsigned short polar;
  135. unsigned short edge;
  136. unsigned short both;
  137. unsigned short inen;
  138. unsigned short fer;
  139. unsigned short reserved;
  140. unsigned short mux;
  141. };
  142. # endif
  143. #endif /*CONFIG_PM*/
  144. /***********************************************************
  145. *
  146. * FUNCTIONS: Blackfin GPIO Driver
  147. *
  148. * INPUTS/OUTPUTS:
  149. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  150. *
  151. *
  152. * DESCRIPTION: Blackfin GPIO Driver API
  153. *
  154. * CAUTION:
  155. *************************************************************
  156. * MODIFICATION HISTORY :
  157. **************************************************************/
  158. int bfin_gpio_request(unsigned gpio, const char *label);
  159. void bfin_gpio_free(unsigned gpio);
  160. int bfin_gpio_irq_request(unsigned gpio, const char *label);
  161. void bfin_gpio_irq_free(unsigned gpio);
  162. int bfin_gpio_direction_input(unsigned gpio);
  163. int bfin_gpio_direction_output(unsigned gpio, int value);
  164. int bfin_gpio_get_value(unsigned gpio);
  165. void bfin_gpio_set_value(unsigned gpio, int value);
  166. #include <asm/irq.h>
  167. #include <asm/errno.h>
  168. #ifdef CONFIG_GPIOLIB
  169. #include <asm-generic/gpio.h> /* cansleep wrappers */
  170. static inline int gpio_get_value(unsigned int gpio)
  171. {
  172. if (gpio < MAX_BLACKFIN_GPIOS)
  173. return bfin_gpio_get_value(gpio);
  174. else
  175. return __gpio_get_value(gpio);
  176. }
  177. static inline void gpio_set_value(unsigned int gpio, int value)
  178. {
  179. if (gpio < MAX_BLACKFIN_GPIOS)
  180. bfin_gpio_set_value(gpio, value);
  181. else
  182. __gpio_set_value(gpio, value);
  183. }
  184. static inline int gpio_cansleep(unsigned int gpio)
  185. {
  186. return __gpio_cansleep(gpio);
  187. }
  188. static inline int gpio_to_irq(unsigned gpio)
  189. {
  190. return __gpio_to_irq(gpio);
  191. }
  192. #else /* !CONFIG_GPIOLIB */
  193. static inline int gpio_request(unsigned gpio, const char *label)
  194. {
  195. return bfin_gpio_request(gpio, label);
  196. }
  197. static inline void gpio_free(unsigned gpio)
  198. {
  199. return bfin_gpio_free(gpio);
  200. }
  201. static inline int gpio_direction_input(unsigned gpio)
  202. {
  203. return bfin_gpio_direction_input(gpio);
  204. }
  205. static inline int gpio_direction_output(unsigned gpio, int value)
  206. {
  207. return bfin_gpio_direction_output(gpio, value);
  208. }
  209. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  210. {
  211. return -EINVAL;
  212. }
  213. static inline int __gpio_get_value(unsigned gpio)
  214. {
  215. return bfin_gpio_get_value(gpio);
  216. }
  217. static inline void __gpio_set_value(unsigned gpio, int value)
  218. {
  219. return bfin_gpio_set_value(gpio, value);
  220. }
  221. static inline int gpio_get_value(unsigned gpio)
  222. {
  223. return __gpio_get_value(gpio);
  224. }
  225. static inline void gpio_set_value(unsigned gpio, int value)
  226. {
  227. return __gpio_set_value(gpio, value);
  228. }
  229. static inline int gpio_to_irq(unsigned gpio)
  230. {
  231. if (likely(gpio < MAX_BLACKFIN_GPIOS))
  232. return gpio + GPIO_IRQ_BASE;
  233. return -EINVAL;
  234. }
  235. #include <asm-generic/gpio.h> /* cansleep wrappers */
  236. #endif /* !CONFIG_GPIOLIB */
  237. static inline int irq_to_gpio(unsigned irq)
  238. {
  239. return (irq - GPIO_IRQ_BASE);
  240. }
  241. #endif /* __ASSEMBLY__ */
  242. #endif /* __ARCH_BLACKFIN_GPIO_H__ */