gpio.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. /*
  30. * Number BF537/6/4 BF561 BF533/2/1
  31. * BF527/5/2
  32. *
  33. * GPIO_0 PF0 PF0 PF0
  34. * GPIO_1 PF1 PF1 PF1
  35. * GPIO_2 PF2 PF2 PF2
  36. * GPIO_3 PF3 PF3 PF3
  37. * GPIO_4 PF4 PF4 PF4
  38. * GPIO_5 PF5 PF5 PF5
  39. * GPIO_6 PF6 PF6 PF6
  40. * GPIO_7 PF7 PF7 PF7
  41. * GPIO_8 PF8 PF8 PF8
  42. * GPIO_9 PF9 PF9 PF9
  43. * GPIO_10 PF10 PF10 PF10
  44. * GPIO_11 PF11 PF11 PF11
  45. * GPIO_12 PF12 PF12 PF12
  46. * GPIO_13 PF13 PF13 PF13
  47. * GPIO_14 PF14 PF14 PF14
  48. * GPIO_15 PF15 PF15 PF15
  49. * GPIO_16 PG0 PF16
  50. * GPIO_17 PG1 PF17
  51. * GPIO_18 PG2 PF18
  52. * GPIO_19 PG3 PF19
  53. * GPIO_20 PG4 PF20
  54. * GPIO_21 PG5 PF21
  55. * GPIO_22 PG6 PF22
  56. * GPIO_23 PG7 PF23
  57. * GPIO_24 PG8 PF24
  58. * GPIO_25 PG9 PF25
  59. * GPIO_26 PG10 PF26
  60. * GPIO_27 PG11 PF27
  61. * GPIO_28 PG12 PF28
  62. * GPIO_29 PG13 PF29
  63. * GPIO_30 PG14 PF30
  64. * GPIO_31 PG15 PF31
  65. * GPIO_32 PH0 PF32
  66. * GPIO_33 PH1 PF33
  67. * GPIO_34 PH2 PF34
  68. * GPIO_35 PH3 PF35
  69. * GPIO_36 PH4 PF36
  70. * GPIO_37 PH5 PF37
  71. * GPIO_38 PH6 PF38
  72. * GPIO_39 PH7 PF39
  73. * GPIO_40 PH8 PF40
  74. * GPIO_41 PH9 PF41
  75. * GPIO_42 PH10 PF42
  76. * GPIO_43 PH11 PF43
  77. * GPIO_44 PH12 PF44
  78. * GPIO_45 PH13 PF45
  79. * GPIO_46 PH14 PF46
  80. * GPIO_47 PH15 PF47
  81. */
  82. #ifndef __ARCH_BLACKFIN_GPIO_H__
  83. #define __ARCH_BLACKFIN_GPIO_H__
  84. #define gpio_bank(x) ((x) >> 4)
  85. #define gpio_bit(x) (1<<((x) & 0xF))
  86. #define gpio_sub_n(x) ((x) & 0xF)
  87. #define GPIO_BANKSIZE 16
  88. #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE)
  89. #include <mach/gpio.h>
  90. #define GPIO_0 0
  91. #define GPIO_1 1
  92. #define GPIO_2 2
  93. #define GPIO_3 3
  94. #define GPIO_4 4
  95. #define GPIO_5 5
  96. #define GPIO_6 6
  97. #define GPIO_7 7
  98. #define GPIO_8 8
  99. #define GPIO_9 9
  100. #define GPIO_10 10
  101. #define GPIO_11 11
  102. #define GPIO_12 12
  103. #define GPIO_13 13
  104. #define GPIO_14 14
  105. #define GPIO_15 15
  106. #define GPIO_16 16
  107. #define GPIO_17 17
  108. #define GPIO_18 18
  109. #define GPIO_19 19
  110. #define GPIO_20 20
  111. #define GPIO_21 21
  112. #define GPIO_22 22
  113. #define GPIO_23 23
  114. #define GPIO_24 24
  115. #define GPIO_25 25
  116. #define GPIO_26 26
  117. #define GPIO_27 27
  118. #define GPIO_28 28
  119. #define GPIO_29 29
  120. #define GPIO_30 30
  121. #define GPIO_31 31
  122. #define GPIO_32 32
  123. #define GPIO_33 33
  124. #define GPIO_34 34
  125. #define GPIO_35 35
  126. #define GPIO_36 36
  127. #define GPIO_37 37
  128. #define GPIO_38 38
  129. #define GPIO_39 39
  130. #define GPIO_40 40
  131. #define GPIO_41 41
  132. #define GPIO_42 42
  133. #define GPIO_43 43
  134. #define GPIO_44 44
  135. #define GPIO_45 45
  136. #define GPIO_46 46
  137. #define GPIO_47 47
  138. #define PERIPHERAL_USAGE 1
  139. #define GPIO_USAGE 0
  140. #ifndef __ASSEMBLY__
  141. /***********************************************************
  142. *
  143. * FUNCTIONS: Blackfin General Purpose Ports Access Functions
  144. *
  145. * INPUTS/OUTPUTS:
  146. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  147. *
  148. *
  149. * DESCRIPTION: These functions abstract direct register access
  150. * to Blackfin processor General Purpose
  151. * Ports Regsiters
  152. *
  153. * CAUTION: These functions do not belong to the GPIO Driver API
  154. *************************************************************
  155. * MODIFICATION HISTORY :
  156. **************************************************************/
  157. #ifndef BF548_FAMILY
  158. void set_gpio_dir(unsigned, unsigned short);
  159. void set_gpio_inen(unsigned, unsigned short);
  160. void set_gpio_polar(unsigned, unsigned short);
  161. void set_gpio_edge(unsigned, unsigned short);
  162. void set_gpio_both(unsigned, unsigned short);
  163. void set_gpio_data(unsigned, unsigned short);
  164. void set_gpio_maska(unsigned, unsigned short);
  165. void set_gpio_maskb(unsigned, unsigned short);
  166. void set_gpio_toggle(unsigned);
  167. void set_gpiop_dir(unsigned, unsigned short);
  168. void set_gpiop_inen(unsigned, unsigned short);
  169. void set_gpiop_polar(unsigned, unsigned short);
  170. void set_gpiop_edge(unsigned, unsigned short);
  171. void set_gpiop_both(unsigned, unsigned short);
  172. void set_gpiop_data(unsigned, unsigned short);
  173. void set_gpiop_maska(unsigned, unsigned short);
  174. void set_gpiop_maskb(unsigned, unsigned short);
  175. unsigned short get_gpio_dir(unsigned);
  176. unsigned short get_gpio_inen(unsigned);
  177. unsigned short get_gpio_polar(unsigned);
  178. unsigned short get_gpio_edge(unsigned);
  179. unsigned short get_gpio_both(unsigned);
  180. unsigned short get_gpio_maska(unsigned);
  181. unsigned short get_gpio_maskb(unsigned);
  182. unsigned short get_gpio_data(unsigned);
  183. unsigned short get_gpiop_dir(unsigned);
  184. unsigned short get_gpiop_inen(unsigned);
  185. unsigned short get_gpiop_polar(unsigned);
  186. unsigned short get_gpiop_edge(unsigned);
  187. unsigned short get_gpiop_both(unsigned);
  188. unsigned short get_gpiop_maska(unsigned);
  189. unsigned short get_gpiop_maskb(unsigned);
  190. unsigned short get_gpiop_data(unsigned);
  191. struct gpio_port_t {
  192. unsigned short data;
  193. unsigned short dummy1;
  194. unsigned short data_clear;
  195. unsigned short dummy2;
  196. unsigned short data_set;
  197. unsigned short dummy3;
  198. unsigned short toggle;
  199. unsigned short dummy4;
  200. unsigned short maska;
  201. unsigned short dummy5;
  202. unsigned short maska_clear;
  203. unsigned short dummy6;
  204. unsigned short maska_set;
  205. unsigned short dummy7;
  206. unsigned short maska_toggle;
  207. unsigned short dummy8;
  208. unsigned short maskb;
  209. unsigned short dummy9;
  210. unsigned short maskb_clear;
  211. unsigned short dummy10;
  212. unsigned short maskb_set;
  213. unsigned short dummy11;
  214. unsigned short maskb_toggle;
  215. unsigned short dummy12;
  216. unsigned short dir;
  217. unsigned short dummy13;
  218. unsigned short polar;
  219. unsigned short dummy14;
  220. unsigned short edge;
  221. unsigned short dummy15;
  222. unsigned short both;
  223. unsigned short dummy16;
  224. unsigned short inen;
  225. };
  226. #endif
  227. #ifdef CONFIG_PM
  228. unsigned int bfin_pm_standby_setup(void);
  229. void bfin_pm_standby_restore(void);
  230. void bfin_gpio_pm_hibernate_restore(void);
  231. void bfin_gpio_pm_hibernate_suspend(void);
  232. #ifndef CONFIG_BF54x
  233. #define PM_WAKE_RISING 0x1
  234. #define PM_WAKE_FALLING 0x2
  235. #define PM_WAKE_HIGH 0x4
  236. #define PM_WAKE_LOW 0x8
  237. #define PM_WAKE_BOTH_EDGES (PM_WAKE_RISING | PM_WAKE_FALLING)
  238. #define PM_WAKE_IGNORE 0xF0
  239. int gpio_pm_wakeup_request(unsigned gpio, unsigned char type);
  240. void gpio_pm_wakeup_free(unsigned gpio);
  241. struct gpio_port_s {
  242. unsigned short data;
  243. unsigned short maska;
  244. unsigned short maskb;
  245. unsigned short dir;
  246. unsigned short polar;
  247. unsigned short edge;
  248. unsigned short both;
  249. unsigned short inen;
  250. unsigned short fer;
  251. unsigned short reserved;
  252. unsigned short mux;
  253. };
  254. #endif /*CONFIG_BF54x*/
  255. #endif /*CONFIG_PM*/
  256. /***********************************************************
  257. *
  258. * FUNCTIONS: Blackfin GPIO Driver
  259. *
  260. * INPUTS/OUTPUTS:
  261. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  262. *
  263. *
  264. * DESCRIPTION: Blackfin GPIO Driver API
  265. *
  266. * CAUTION:
  267. *************************************************************
  268. * MODIFICATION HISTORY :
  269. **************************************************************/
  270. int bfin_gpio_request(unsigned gpio, const char *label);
  271. void bfin_gpio_free(unsigned gpio);
  272. int bfin_gpio_irq_request(unsigned gpio, const char *label);
  273. void bfin_gpio_irq_free(unsigned gpio);
  274. int bfin_gpio_direction_input(unsigned gpio);
  275. int bfin_gpio_direction_output(unsigned gpio, int value);
  276. int bfin_gpio_get_value(unsigned gpio);
  277. void bfin_gpio_set_value(unsigned gpio, int value);
  278. #ifndef BF548_FAMILY
  279. #define bfin_gpio_set_value(gpio, value) set_gpio_data(gpio, value)
  280. #endif
  281. #ifdef CONFIG_GPIOLIB
  282. #include <asm-generic/gpio.h> /* cansleep wrappers */
  283. static inline int gpio_get_value(unsigned int gpio)
  284. {
  285. if (gpio < MAX_BLACKFIN_GPIOS)
  286. return bfin_gpio_get_value(gpio);
  287. else
  288. return __gpio_get_value(gpio);
  289. }
  290. static inline void gpio_set_value(unsigned int gpio, int value)
  291. {
  292. if (gpio < MAX_BLACKFIN_GPIOS)
  293. bfin_gpio_set_value(gpio, value);
  294. else
  295. __gpio_set_value(gpio, value);
  296. }
  297. static inline int gpio_cansleep(unsigned int gpio)
  298. {
  299. return __gpio_cansleep(gpio);
  300. }
  301. #else /* !CONFIG_GPIOLIB */
  302. static inline int gpio_request(unsigned gpio, const char *label)
  303. {
  304. return bfin_gpio_request(gpio, label);
  305. }
  306. static inline void gpio_free(unsigned gpio)
  307. {
  308. return bfin_gpio_free(gpio);
  309. }
  310. static inline int gpio_direction_input(unsigned gpio)
  311. {
  312. return bfin_gpio_direction_input(gpio);
  313. }
  314. static inline int gpio_direction_output(unsigned gpio, int value)
  315. {
  316. return bfin_gpio_direction_output(gpio, value);
  317. }
  318. static inline int gpio_get_value(unsigned gpio)
  319. {
  320. return bfin_gpio_get_value(gpio);
  321. }
  322. static inline void gpio_set_value(unsigned gpio, int value)
  323. {
  324. return bfin_gpio_set_value(gpio, value);
  325. }
  326. #include <asm-generic/gpio.h> /* cansleep wrappers */
  327. #endif /* !CONFIG_GPIOLIB */
  328. #include <asm/irq.h>
  329. static inline int gpio_to_irq(unsigned gpio)
  330. {
  331. return (gpio + GPIO_IRQ_BASE);
  332. }
  333. static inline int irq_to_gpio(unsigned irq)
  334. {
  335. return (irq - GPIO_IRQ_BASE);
  336. }
  337. #endif /* __ASSEMBLY__ */
  338. #endif /* __ARCH_BLACKFIN_GPIO_H__ */