gpio.h 7.8 KB

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