gpio.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. # if !BFIN_GPIO_PINT
  129. int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl);
  130. struct gpio_port_s {
  131. unsigned short data;
  132. unsigned short maska;
  133. unsigned short maskb;
  134. unsigned short dir;
  135. unsigned short polar;
  136. unsigned short edge;
  137. unsigned short both;
  138. unsigned short inen;
  139. unsigned short fer;
  140. unsigned short reserved;
  141. unsigned short mux;
  142. };
  143. # endif
  144. #endif /*CONFIG_PM*/
  145. /***********************************************************
  146. *
  147. * FUNCTIONS: Blackfin GPIO Driver
  148. *
  149. * INPUTS/OUTPUTS:
  150. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  151. *
  152. *
  153. * DESCRIPTION: Blackfin GPIO Driver API
  154. *
  155. * CAUTION:
  156. *************************************************************
  157. * MODIFICATION HISTORY :
  158. **************************************************************/
  159. int bfin_gpio_request(unsigned gpio, const char *label);
  160. void bfin_gpio_free(unsigned gpio);
  161. int bfin_gpio_irq_request(unsigned gpio, const char *label);
  162. void bfin_gpio_irq_free(unsigned gpio);
  163. int bfin_gpio_direction_input(unsigned gpio);
  164. int bfin_gpio_direction_output(unsigned gpio, int value);
  165. int bfin_gpio_get_value(unsigned gpio);
  166. void bfin_gpio_set_value(unsigned gpio, int value);
  167. #include <asm/irq.h>
  168. #include <asm/errno.h>
  169. #ifdef CONFIG_GPIOLIB
  170. #include <asm-generic/gpio.h> /* cansleep wrappers */
  171. static inline int gpio_get_value(unsigned int gpio)
  172. {
  173. if (gpio < MAX_BLACKFIN_GPIOS)
  174. return bfin_gpio_get_value(gpio);
  175. else
  176. return __gpio_get_value(gpio);
  177. }
  178. static inline void gpio_set_value(unsigned int gpio, int value)
  179. {
  180. if (gpio < MAX_BLACKFIN_GPIOS)
  181. bfin_gpio_set_value(gpio, value);
  182. else
  183. __gpio_set_value(gpio, value);
  184. }
  185. static inline int gpio_cansleep(unsigned int gpio)
  186. {
  187. return __gpio_cansleep(gpio);
  188. }
  189. static inline int gpio_to_irq(unsigned gpio)
  190. {
  191. return __gpio_to_irq(gpio);
  192. }
  193. #else /* !CONFIG_GPIOLIB */
  194. static inline int gpio_request(unsigned gpio, const char *label)
  195. {
  196. return bfin_gpio_request(gpio, label);
  197. }
  198. static inline void gpio_free(unsigned gpio)
  199. {
  200. return bfin_gpio_free(gpio);
  201. }
  202. static inline int gpio_direction_input(unsigned gpio)
  203. {
  204. return bfin_gpio_direction_input(gpio);
  205. }
  206. static inline int gpio_direction_output(unsigned gpio, int value)
  207. {
  208. return bfin_gpio_direction_output(gpio, value);
  209. }
  210. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  211. {
  212. return -EINVAL;
  213. }
  214. static inline int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
  215. {
  216. int err;
  217. err = bfin_gpio_request(gpio, label);
  218. if (err)
  219. return err;
  220. if (flags & GPIOF_DIR_IN)
  221. err = bfin_gpio_direction_input(gpio);
  222. else
  223. err = bfin_gpio_direction_output(gpio,
  224. (flags & GPIOF_INIT_HIGH) ? 1 : 0);
  225. if (err)
  226. bfin_gpio_free(gpio);
  227. return err;
  228. }
  229. static inline int gpio_request_array(const struct gpio *array, size_t num)
  230. {
  231. int i, err;
  232. for (i = 0; i < num; i++, array++) {
  233. err = gpio_request_one(array->gpio, array->flags, array->label);
  234. if (err)
  235. goto err_free;
  236. }
  237. return 0;
  238. err_free:
  239. while (i--)
  240. bfin_gpio_free((--array)->gpio);
  241. return err;
  242. }
  243. static inline void gpio_free_array(const struct gpio *array, size_t num)
  244. {
  245. while (num--)
  246. bfin_gpio_free((array++)->gpio);
  247. }
  248. static inline int __gpio_get_value(unsigned gpio)
  249. {
  250. return bfin_gpio_get_value(gpio);
  251. }
  252. static inline void __gpio_set_value(unsigned gpio, int value)
  253. {
  254. return bfin_gpio_set_value(gpio, value);
  255. }
  256. static inline int gpio_get_value(unsigned gpio)
  257. {
  258. return __gpio_get_value(gpio);
  259. }
  260. static inline void gpio_set_value(unsigned gpio, int value)
  261. {
  262. return __gpio_set_value(gpio, value);
  263. }
  264. static inline int gpio_to_irq(unsigned gpio)
  265. {
  266. if (likely(gpio < MAX_BLACKFIN_GPIOS))
  267. return gpio + GPIO_IRQ_BASE;
  268. return -EINVAL;
  269. }
  270. #include <asm-generic/gpio.h> /* cansleep wrappers */
  271. #endif /* !CONFIG_GPIOLIB */
  272. static inline int irq_to_gpio(unsigned irq)
  273. {
  274. return (irq - GPIO_IRQ_BASE);
  275. }
  276. #endif /* __ASSEMBLY__ */
  277. #endif /* __ARCH_BLACKFIN_GPIO_H__ */