gpio.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * File: arch/blackfin/kernel/bfin_gpio.h
  3. * Based on:
  4. * Author: Michael Hennerich (hennerich@blackfin.uclinux.org)
  5. *
  6. * Created:
  7. * Description:
  8. *
  9. * Modified:
  10. * Copyright 2004-2008 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #ifndef __ARCH_BLACKFIN_GPIO_H__
  30. #define __ARCH_BLACKFIN_GPIO_H__
  31. #define gpio_bank(x) ((x) >> 4)
  32. #define gpio_bit(x) (1<<((x) & 0xF))
  33. #define gpio_sub_n(x) ((x) & 0xF)
  34. #define GPIO_BANKSIZE 16
  35. #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
  36. #include <mach/gpio.h>
  37. #define GPIO_0 0
  38. #define GPIO_1 1
  39. #define GPIO_2 2
  40. #define GPIO_3 3
  41. #define GPIO_4 4
  42. #define GPIO_5 5
  43. #define GPIO_6 6
  44. #define GPIO_7 7
  45. #define GPIO_8 8
  46. #define GPIO_9 9
  47. #define GPIO_10 10
  48. #define GPIO_11 11
  49. #define GPIO_12 12
  50. #define GPIO_13 13
  51. #define GPIO_14 14
  52. #define GPIO_15 15
  53. #define GPIO_16 16
  54. #define GPIO_17 17
  55. #define GPIO_18 18
  56. #define GPIO_19 19
  57. #define GPIO_20 20
  58. #define GPIO_21 21
  59. #define GPIO_22 22
  60. #define GPIO_23 23
  61. #define GPIO_24 24
  62. #define GPIO_25 25
  63. #define GPIO_26 26
  64. #define GPIO_27 27
  65. #define GPIO_28 28
  66. #define GPIO_29 29
  67. #define GPIO_30 30
  68. #define GPIO_31 31
  69. #define GPIO_32 32
  70. #define GPIO_33 33
  71. #define GPIO_34 34
  72. #define GPIO_35 35
  73. #define GPIO_36 36
  74. #define GPIO_37 37
  75. #define GPIO_38 38
  76. #define GPIO_39 39
  77. #define GPIO_40 40
  78. #define GPIO_41 41
  79. #define GPIO_42 42
  80. #define GPIO_43 43
  81. #define GPIO_44 44
  82. #define GPIO_45 45
  83. #define GPIO_46 46
  84. #define GPIO_47 47
  85. #define PERIPHERAL_USAGE 1
  86. #define GPIO_USAGE 0
  87. #ifndef __ASSEMBLY__
  88. /***********************************************************
  89. *
  90. * FUNCTIONS: Blackfin General Purpose Ports Access Functions
  91. *
  92. * INPUTS/OUTPUTS:
  93. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  94. *
  95. *
  96. * DESCRIPTION: These functions abstract direct register access
  97. * to Blackfin processor General Purpose
  98. * Ports Regsiters
  99. *
  100. * CAUTION: These functions do not belong to the GPIO Driver API
  101. *************************************************************
  102. * MODIFICATION HISTORY :
  103. **************************************************************/
  104. #ifndef BF548_FAMILY
  105. void set_gpio_dir(unsigned, unsigned short);
  106. void set_gpio_inen(unsigned, unsigned short);
  107. void set_gpio_polar(unsigned, unsigned short);
  108. void set_gpio_edge(unsigned, unsigned short);
  109. void set_gpio_both(unsigned, unsigned short);
  110. void set_gpio_data(unsigned, unsigned short);
  111. void set_gpio_maska(unsigned, unsigned short);
  112. void set_gpio_maskb(unsigned, unsigned short);
  113. void set_gpio_toggle(unsigned);
  114. void set_gpiop_dir(unsigned, unsigned short);
  115. void set_gpiop_inen(unsigned, unsigned short);
  116. void set_gpiop_polar(unsigned, unsigned short);
  117. void set_gpiop_edge(unsigned, unsigned short);
  118. void set_gpiop_both(unsigned, unsigned short);
  119. void set_gpiop_data(unsigned, unsigned short);
  120. void set_gpiop_maska(unsigned, unsigned short);
  121. void set_gpiop_maskb(unsigned, unsigned short);
  122. unsigned short get_gpio_dir(unsigned);
  123. unsigned short get_gpio_inen(unsigned);
  124. unsigned short get_gpio_polar(unsigned);
  125. unsigned short get_gpio_edge(unsigned);
  126. unsigned short get_gpio_both(unsigned);
  127. unsigned short get_gpio_maska(unsigned);
  128. unsigned short get_gpio_maskb(unsigned);
  129. unsigned short get_gpio_data(unsigned);
  130. unsigned short get_gpiop_dir(unsigned);
  131. unsigned short get_gpiop_inen(unsigned);
  132. unsigned short get_gpiop_polar(unsigned);
  133. unsigned short get_gpiop_edge(unsigned);
  134. unsigned short get_gpiop_both(unsigned);
  135. unsigned short get_gpiop_maska(unsigned);
  136. unsigned short get_gpiop_maskb(unsigned);
  137. unsigned short get_gpiop_data(unsigned);
  138. struct gpio_port_t {
  139. unsigned short data;
  140. unsigned short dummy1;
  141. unsigned short data_clear;
  142. unsigned short dummy2;
  143. unsigned short data_set;
  144. unsigned short dummy3;
  145. unsigned short toggle;
  146. unsigned short dummy4;
  147. unsigned short maska;
  148. unsigned short dummy5;
  149. unsigned short maska_clear;
  150. unsigned short dummy6;
  151. unsigned short maska_set;
  152. unsigned short dummy7;
  153. unsigned short maska_toggle;
  154. unsigned short dummy8;
  155. unsigned short maskb;
  156. unsigned short dummy9;
  157. unsigned short maskb_clear;
  158. unsigned short dummy10;
  159. unsigned short maskb_set;
  160. unsigned short dummy11;
  161. unsigned short maskb_toggle;
  162. unsigned short dummy12;
  163. unsigned short dir;
  164. unsigned short dummy13;
  165. unsigned short polar;
  166. unsigned short dummy14;
  167. unsigned short edge;
  168. unsigned short dummy15;
  169. unsigned short both;
  170. unsigned short dummy16;
  171. unsigned short inen;
  172. };
  173. #endif
  174. #ifdef CONFIG_PM
  175. unsigned int bfin_pm_standby_setup(void);
  176. void bfin_pm_standby_restore(void);
  177. void bfin_gpio_pm_hibernate_restore(void);
  178. void bfin_gpio_pm_hibernate_suspend(void);
  179. #ifndef CONFIG_BF54x
  180. #define PM_WAKE_RISING 0x1
  181. #define PM_WAKE_FALLING 0x2
  182. #define PM_WAKE_HIGH 0x4
  183. #define PM_WAKE_LOW 0x8
  184. #define PM_WAKE_BOTH_EDGES (PM_WAKE_RISING | PM_WAKE_FALLING)
  185. #define PM_WAKE_IGNORE 0xF0
  186. int gpio_pm_wakeup_request(unsigned gpio, unsigned char type);
  187. void gpio_pm_wakeup_free(unsigned gpio);
  188. struct gpio_port_s {
  189. unsigned short data;
  190. unsigned short maska;
  191. unsigned short maskb;
  192. unsigned short dir;
  193. unsigned short polar;
  194. unsigned short edge;
  195. unsigned short both;
  196. unsigned short inen;
  197. unsigned short fer;
  198. unsigned short reserved;
  199. unsigned short mux;
  200. };
  201. #endif /*CONFIG_BF54x*/
  202. #endif /*CONFIG_PM*/
  203. /***********************************************************
  204. *
  205. * FUNCTIONS: Blackfin GPIO Driver
  206. *
  207. * INPUTS/OUTPUTS:
  208. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  209. *
  210. *
  211. * DESCRIPTION: Blackfin GPIO Driver API
  212. *
  213. * CAUTION:
  214. *************************************************************
  215. * MODIFICATION HISTORY :
  216. **************************************************************/
  217. int bfin_gpio_request(unsigned gpio, const char *label);
  218. void bfin_gpio_free(unsigned gpio);
  219. int bfin_gpio_irq_request(unsigned gpio, const char *label);
  220. void bfin_gpio_irq_free(unsigned gpio);
  221. int bfin_gpio_direction_input(unsigned gpio);
  222. int bfin_gpio_direction_output(unsigned gpio, int value);
  223. int bfin_gpio_get_value(unsigned gpio);
  224. void bfin_gpio_set_value(unsigned gpio, int value);
  225. #ifdef CONFIG_GPIOLIB
  226. #include <asm-generic/gpio.h> /* cansleep wrappers */
  227. static inline int gpio_get_value(unsigned int gpio)
  228. {
  229. if (gpio < MAX_BLACKFIN_GPIOS)
  230. return bfin_gpio_get_value(gpio);
  231. else
  232. return __gpio_get_value(gpio);
  233. }
  234. static inline void gpio_set_value(unsigned int gpio, int value)
  235. {
  236. if (gpio < MAX_BLACKFIN_GPIOS)
  237. bfin_gpio_set_value(gpio, value);
  238. else
  239. __gpio_set_value(gpio, value);
  240. }
  241. static inline int gpio_cansleep(unsigned int gpio)
  242. {
  243. return __gpio_cansleep(gpio);
  244. }
  245. #else /* !CONFIG_GPIOLIB */
  246. static inline int gpio_request(unsigned gpio, const char *label)
  247. {
  248. return bfin_gpio_request(gpio, label);
  249. }
  250. static inline void gpio_free(unsigned gpio)
  251. {
  252. return bfin_gpio_free(gpio);
  253. }
  254. static inline int gpio_direction_input(unsigned gpio)
  255. {
  256. return bfin_gpio_direction_input(gpio);
  257. }
  258. static inline int gpio_direction_output(unsigned gpio, int value)
  259. {
  260. return bfin_gpio_direction_output(gpio, value);
  261. }
  262. static inline int gpio_get_value(unsigned gpio)
  263. {
  264. return bfin_gpio_get_value(gpio);
  265. }
  266. static inline void gpio_set_value(unsigned gpio, int value)
  267. {
  268. return bfin_gpio_set_value(gpio, value);
  269. }
  270. #include <asm-generic/gpio.h> /* cansleep wrappers */
  271. #endif /* !CONFIG_GPIOLIB */
  272. #include <asm/irq.h>
  273. static inline int gpio_to_irq(unsigned gpio)
  274. {
  275. return (gpio + GPIO_IRQ_BASE);
  276. }
  277. static inline int irq_to_gpio(unsigned irq)
  278. {
  279. return (irq - GPIO_IRQ_BASE);
  280. }
  281. #endif /* __ASSEMBLY__ */
  282. #endif /* __ARCH_BLACKFIN_GPIO_H__ */