gpio.h 6.5 KB

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