bfin_gpio.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. /*
  2. * File: arch/blackfin/kernel/bfin_gpio.c
  3. * Based on:
  4. * Author: Michael Hennerich (hennerich@blackfin.uclinux.org)
  5. *
  6. * Created:
  7. * Description: GPIO Abstraction Layer
  8. *
  9. * Modified:
  10. * Copyright 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. #include <linux/delay.h>
  30. #include <linux/module.h>
  31. #include <linux/err.h>
  32. #include <linux/proc_fs.h>
  33. #include <asm/blackfin.h>
  34. #include <asm/gpio.h>
  35. #include <asm/portmux.h>
  36. #include <linux/irq.h>
  37. #if ANOMALY_05000311 || ANOMALY_05000323
  38. enum {
  39. AWA_data = SYSCR,
  40. AWA_data_clear = SYSCR,
  41. AWA_data_set = SYSCR,
  42. AWA_toggle = SYSCR,
  43. AWA_maska = BFIN_UART_SCR,
  44. AWA_maska_clear = BFIN_UART_SCR,
  45. AWA_maska_set = BFIN_UART_SCR,
  46. AWA_maska_toggle = BFIN_UART_SCR,
  47. AWA_maskb = BFIN_UART_GCTL,
  48. AWA_maskb_clear = BFIN_UART_GCTL,
  49. AWA_maskb_set = BFIN_UART_GCTL,
  50. AWA_maskb_toggle = BFIN_UART_GCTL,
  51. AWA_dir = SPORT1_STAT,
  52. AWA_polar = SPORT1_STAT,
  53. AWA_edge = SPORT1_STAT,
  54. AWA_both = SPORT1_STAT,
  55. #if ANOMALY_05000311
  56. AWA_inen = TIMER_ENABLE,
  57. #elif ANOMALY_05000323
  58. AWA_inen = DMA1_1_CONFIG,
  59. #endif
  60. };
  61. /* Anomaly Workaround */
  62. #define AWA_DUMMY_READ(name) bfin_read16(AWA_ ## name)
  63. #else
  64. #define AWA_DUMMY_READ(...) do { } while (0)
  65. #endif
  66. static struct gpio_port_t * const gpio_array[] = {
  67. #if defined(BF533_FAMILY) || defined(BF538_FAMILY)
  68. (struct gpio_port_t *) FIO_FLAG_D,
  69. #elif defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  70. (struct gpio_port_t *) PORTFIO,
  71. (struct gpio_port_t *) PORTGIO,
  72. (struct gpio_port_t *) PORTHIO,
  73. #elif defined(BF561_FAMILY)
  74. (struct gpio_port_t *) FIO0_FLAG_D,
  75. (struct gpio_port_t *) FIO1_FLAG_D,
  76. (struct gpio_port_t *) FIO2_FLAG_D,
  77. #elif defined(CONFIG_BF54x)
  78. (struct gpio_port_t *)PORTA_FER,
  79. (struct gpio_port_t *)PORTB_FER,
  80. (struct gpio_port_t *)PORTC_FER,
  81. (struct gpio_port_t *)PORTD_FER,
  82. (struct gpio_port_t *)PORTE_FER,
  83. (struct gpio_port_t *)PORTF_FER,
  84. (struct gpio_port_t *)PORTG_FER,
  85. (struct gpio_port_t *)PORTH_FER,
  86. (struct gpio_port_t *)PORTI_FER,
  87. (struct gpio_port_t *)PORTJ_FER,
  88. #else
  89. # error no gpio arrays defined
  90. #endif
  91. };
  92. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  93. static unsigned short * const port_fer[] = {
  94. (unsigned short *) PORTF_FER,
  95. (unsigned short *) PORTG_FER,
  96. (unsigned short *) PORTH_FER,
  97. };
  98. # if !defined(BF537_FAMILY)
  99. static unsigned short * const port_mux[] = {
  100. (unsigned short *) PORTF_MUX,
  101. (unsigned short *) PORTG_MUX,
  102. (unsigned short *) PORTH_MUX,
  103. };
  104. static const
  105. u8 pmux_offset[][16] = {
  106. # if defined(CONFIG_BF52x)
  107. { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 4, 6, 8, 8, 10, 10 }, /* PORTF */
  108. { 0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 8, 10, 10, 10, 12, 12 }, /* PORTG */
  109. { 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 4, 4, 4, 4, 4 }, /* PORTH */
  110. # elif defined(CONFIG_BF51x)
  111. { 0, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6, 8, 8, 8, 8, 10 }, /* PORTF */
  112. { 0, 0, 0, 2, 4, 6, 6, 6, 8, 10, 10, 12, 14, 14, 14, 14 }, /* PORTG */
  113. { 0, 0, 0, 0, 2, 2, 4, 6, 10, 10, 10, 10, 10, 10, 10, 10 }, /* PORTH */
  114. # endif
  115. };
  116. # endif
  117. #endif
  118. static unsigned short reserved_gpio_map[GPIO_BANK_NUM];
  119. static unsigned short reserved_peri_map[gpio_bank(MAX_RESOURCES)];
  120. static unsigned short reserved_gpio_irq_map[GPIO_BANK_NUM];
  121. #define RESOURCE_LABEL_SIZE 16
  122. static struct str_ident {
  123. char name[RESOURCE_LABEL_SIZE];
  124. } str_ident[MAX_RESOURCES];
  125. #if defined(CONFIG_PM)
  126. static struct gpio_port_s gpio_bank_saved[GPIO_BANK_NUM];
  127. #endif
  128. inline int check_gpio(unsigned gpio)
  129. {
  130. #if defined(CONFIG_BF54x)
  131. if (gpio == GPIO_PB15 || gpio == GPIO_PC14 || gpio == GPIO_PC15
  132. || gpio == GPIO_PH14 || gpio == GPIO_PH15
  133. || gpio == GPIO_PJ14 || gpio == GPIO_PJ15)
  134. return -EINVAL;
  135. #endif
  136. if (gpio >= MAX_BLACKFIN_GPIOS)
  137. return -EINVAL;
  138. return 0;
  139. }
  140. static void gpio_error(unsigned gpio)
  141. {
  142. printk(KERN_ERR "bfin-gpio: GPIO %d wasn't requested!\n", gpio);
  143. }
  144. static void set_label(unsigned short ident, const char *label)
  145. {
  146. if (label) {
  147. strncpy(str_ident[ident].name, label,
  148. RESOURCE_LABEL_SIZE);
  149. str_ident[ident].name[RESOURCE_LABEL_SIZE - 1] = 0;
  150. }
  151. }
  152. static char *get_label(unsigned short ident)
  153. {
  154. return (*str_ident[ident].name ? str_ident[ident].name : "UNKNOWN");
  155. }
  156. static int cmp_label(unsigned short ident, const char *label)
  157. {
  158. if (label == NULL) {
  159. dump_stack();
  160. printk(KERN_ERR "Please provide none-null label\n");
  161. }
  162. if (label)
  163. return strcmp(str_ident[ident].name, label);
  164. else
  165. return -EINVAL;
  166. }
  167. static void port_setup(unsigned gpio, unsigned short usage)
  168. {
  169. if (check_gpio(gpio))
  170. return;
  171. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  172. if (usage == GPIO_USAGE)
  173. *port_fer[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  174. else
  175. *port_fer[gpio_bank(gpio)] |= gpio_bit(gpio);
  176. SSYNC();
  177. #elif defined(CONFIG_BF54x)
  178. if (usage == GPIO_USAGE)
  179. gpio_array[gpio_bank(gpio)]->port_fer &= ~gpio_bit(gpio);
  180. else
  181. gpio_array[gpio_bank(gpio)]->port_fer |= gpio_bit(gpio);
  182. SSYNC();
  183. #endif
  184. }
  185. #ifdef BF537_FAMILY
  186. static struct {
  187. unsigned short res;
  188. unsigned short offset;
  189. } port_mux_lut[] = {
  190. {.res = P_PPI0_D13, .offset = 11},
  191. {.res = P_PPI0_D14, .offset = 11},
  192. {.res = P_PPI0_D15, .offset = 11},
  193. {.res = P_SPORT1_TFS, .offset = 11},
  194. {.res = P_SPORT1_TSCLK, .offset = 11},
  195. {.res = P_SPORT1_DTPRI, .offset = 11},
  196. {.res = P_PPI0_D10, .offset = 10},
  197. {.res = P_PPI0_D11, .offset = 10},
  198. {.res = P_PPI0_D12, .offset = 10},
  199. {.res = P_SPORT1_RSCLK, .offset = 10},
  200. {.res = P_SPORT1_RFS, .offset = 10},
  201. {.res = P_SPORT1_DRPRI, .offset = 10},
  202. {.res = P_PPI0_D8, .offset = 9},
  203. {.res = P_PPI0_D9, .offset = 9},
  204. {.res = P_SPORT1_DRSEC, .offset = 9},
  205. {.res = P_SPORT1_DTSEC, .offset = 9},
  206. {.res = P_TMR2, .offset = 8},
  207. {.res = P_PPI0_FS3, .offset = 8},
  208. {.res = P_TMR3, .offset = 7},
  209. {.res = P_SPI0_SSEL4, .offset = 7},
  210. {.res = P_TMR4, .offset = 6},
  211. {.res = P_SPI0_SSEL5, .offset = 6},
  212. {.res = P_TMR5, .offset = 5},
  213. {.res = P_SPI0_SSEL6, .offset = 5},
  214. {.res = P_UART1_RX, .offset = 4},
  215. {.res = P_UART1_TX, .offset = 4},
  216. {.res = P_TMR6, .offset = 4},
  217. {.res = P_TMR7, .offset = 4},
  218. {.res = P_UART0_RX, .offset = 3},
  219. {.res = P_UART0_TX, .offset = 3},
  220. {.res = P_DMAR0, .offset = 3},
  221. {.res = P_DMAR1, .offset = 3},
  222. {.res = P_SPORT0_DTSEC, .offset = 1},
  223. {.res = P_SPORT0_DRSEC, .offset = 1},
  224. {.res = P_CAN0_RX, .offset = 1},
  225. {.res = P_CAN0_TX, .offset = 1},
  226. {.res = P_SPI0_SSEL7, .offset = 1},
  227. {.res = P_SPORT0_TFS, .offset = 0},
  228. {.res = P_SPORT0_DTPRI, .offset = 0},
  229. {.res = P_SPI0_SSEL2, .offset = 0},
  230. {.res = P_SPI0_SSEL3, .offset = 0},
  231. };
  232. static void portmux_setup(unsigned short per)
  233. {
  234. u16 y, offset, muxreg;
  235. u16 function = P_FUNCT2MUX(per);
  236. for (y = 0; y < ARRAY_SIZE(port_mux_lut); y++) {
  237. if (port_mux_lut[y].res == per) {
  238. /* SET PORTMUX REG */
  239. offset = port_mux_lut[y].offset;
  240. muxreg = bfin_read_PORT_MUX();
  241. if (offset != 1)
  242. muxreg &= ~(1 << offset);
  243. else
  244. muxreg &= ~(3 << 1);
  245. muxreg |= (function << offset);
  246. bfin_write_PORT_MUX(muxreg);
  247. }
  248. }
  249. }
  250. #elif defined(CONFIG_BF54x)
  251. inline void portmux_setup(unsigned short per)
  252. {
  253. u32 pmux;
  254. u16 ident = P_IDENT(per);
  255. u16 function = P_FUNCT2MUX(per);
  256. pmux = gpio_array[gpio_bank(ident)]->port_mux;
  257. pmux &= ~(0x3 << (2 * gpio_sub_n(ident)));
  258. pmux |= (function & 0x3) << (2 * gpio_sub_n(ident));
  259. gpio_array[gpio_bank(ident)]->port_mux = pmux;
  260. }
  261. inline u16 get_portmux(unsigned short per)
  262. {
  263. u32 pmux;
  264. u16 ident = P_IDENT(per);
  265. pmux = gpio_array[gpio_bank(ident)]->port_mux;
  266. return (pmux >> (2 * gpio_sub_n(ident)) & 0x3);
  267. }
  268. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  269. inline void portmux_setup(unsigned short per)
  270. {
  271. u16 pmux, ident = P_IDENT(per), function = P_FUNCT2MUX(per);
  272. u8 offset = pmux_offset[gpio_bank(ident)][gpio_sub_n(ident)];
  273. pmux = *port_mux[gpio_bank(ident)];
  274. pmux &= ~(3 << offset);
  275. pmux |= (function & 3) << offset;
  276. *port_mux[gpio_bank(ident)] = pmux;
  277. SSYNC();
  278. }
  279. #else
  280. # define portmux_setup(...) do { } while (0)
  281. #endif
  282. #ifndef CONFIG_BF54x
  283. /***********************************************************
  284. *
  285. * FUNCTIONS: Blackfin General Purpose Ports Access Functions
  286. *
  287. * INPUTS/OUTPUTS:
  288. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  289. *
  290. *
  291. * DESCRIPTION: These functions abstract direct register access
  292. * to Blackfin processor General Purpose
  293. * Ports Regsiters
  294. *
  295. * CAUTION: These functions do not belong to the GPIO Driver API
  296. *************************************************************
  297. * MODIFICATION HISTORY :
  298. **************************************************************/
  299. /* Set a specific bit */
  300. #define SET_GPIO(name) \
  301. void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
  302. { \
  303. unsigned long flags; \
  304. local_irq_save_hw(flags); \
  305. if (arg) \
  306. gpio_array[gpio_bank(gpio)]->name |= gpio_bit(gpio); \
  307. else \
  308. gpio_array[gpio_bank(gpio)]->name &= ~gpio_bit(gpio); \
  309. AWA_DUMMY_READ(name); \
  310. local_irq_restore_hw(flags); \
  311. } \
  312. EXPORT_SYMBOL(set_gpio_ ## name);
  313. SET_GPIO(dir) /* set_gpio_dir() */
  314. SET_GPIO(inen) /* set_gpio_inen() */
  315. SET_GPIO(polar) /* set_gpio_polar() */
  316. SET_GPIO(edge) /* set_gpio_edge() */
  317. SET_GPIO(both) /* set_gpio_both() */
  318. #define SET_GPIO_SC(name) \
  319. void set_gpio_ ## name(unsigned gpio, unsigned short arg) \
  320. { \
  321. unsigned long flags; \
  322. if (ANOMALY_05000311 || ANOMALY_05000323) \
  323. local_irq_save_hw(flags); \
  324. if (arg) \
  325. gpio_array[gpio_bank(gpio)]->name ## _set = gpio_bit(gpio); \
  326. else \
  327. gpio_array[gpio_bank(gpio)]->name ## _clear = gpio_bit(gpio); \
  328. if (ANOMALY_05000311 || ANOMALY_05000323) { \
  329. AWA_DUMMY_READ(name); \
  330. local_irq_restore_hw(flags); \
  331. } \
  332. } \
  333. EXPORT_SYMBOL(set_gpio_ ## name);
  334. SET_GPIO_SC(maska)
  335. SET_GPIO_SC(maskb)
  336. SET_GPIO_SC(data)
  337. void set_gpio_toggle(unsigned gpio)
  338. {
  339. unsigned long flags;
  340. if (ANOMALY_05000311 || ANOMALY_05000323)
  341. local_irq_save_hw(flags);
  342. gpio_array[gpio_bank(gpio)]->toggle = gpio_bit(gpio);
  343. if (ANOMALY_05000311 || ANOMALY_05000323) {
  344. AWA_DUMMY_READ(toggle);
  345. local_irq_restore_hw(flags);
  346. }
  347. }
  348. EXPORT_SYMBOL(set_gpio_toggle);
  349. /*Set current PORT date (16-bit word)*/
  350. #define SET_GPIO_P(name) \
  351. void set_gpiop_ ## name(unsigned gpio, unsigned short arg) \
  352. { \
  353. unsigned long flags; \
  354. if (ANOMALY_05000311 || ANOMALY_05000323) \
  355. local_irq_save_hw(flags); \
  356. gpio_array[gpio_bank(gpio)]->name = arg; \
  357. if (ANOMALY_05000311 || ANOMALY_05000323) { \
  358. AWA_DUMMY_READ(name); \
  359. local_irq_restore_hw(flags); \
  360. } \
  361. } \
  362. EXPORT_SYMBOL(set_gpiop_ ## name);
  363. SET_GPIO_P(data)
  364. SET_GPIO_P(dir)
  365. SET_GPIO_P(inen)
  366. SET_GPIO_P(polar)
  367. SET_GPIO_P(edge)
  368. SET_GPIO_P(both)
  369. SET_GPIO_P(maska)
  370. SET_GPIO_P(maskb)
  371. /* Get a specific bit */
  372. #define GET_GPIO(name) \
  373. unsigned short get_gpio_ ## name(unsigned gpio) \
  374. { \
  375. unsigned long flags; \
  376. unsigned short ret; \
  377. if (ANOMALY_05000311 || ANOMALY_05000323) \
  378. local_irq_save_hw(flags); \
  379. ret = 0x01 & (gpio_array[gpio_bank(gpio)]->name >> gpio_sub_n(gpio)); \
  380. if (ANOMALY_05000311 || ANOMALY_05000323) { \
  381. AWA_DUMMY_READ(name); \
  382. local_irq_restore_hw(flags); \
  383. } \
  384. return ret; \
  385. } \
  386. EXPORT_SYMBOL(get_gpio_ ## name);
  387. GET_GPIO(data)
  388. GET_GPIO(dir)
  389. GET_GPIO(inen)
  390. GET_GPIO(polar)
  391. GET_GPIO(edge)
  392. GET_GPIO(both)
  393. GET_GPIO(maska)
  394. GET_GPIO(maskb)
  395. /*Get current PORT date (16-bit word)*/
  396. #define GET_GPIO_P(name) \
  397. unsigned short get_gpiop_ ## name(unsigned gpio) \
  398. { \
  399. unsigned long flags; \
  400. unsigned short ret; \
  401. if (ANOMALY_05000311 || ANOMALY_05000323) \
  402. local_irq_save_hw(flags); \
  403. ret = (gpio_array[gpio_bank(gpio)]->name); \
  404. if (ANOMALY_05000311 || ANOMALY_05000323) { \
  405. AWA_DUMMY_READ(name); \
  406. local_irq_restore_hw(flags); \
  407. } \
  408. return ret; \
  409. } \
  410. EXPORT_SYMBOL(get_gpiop_ ## name);
  411. GET_GPIO_P(data)
  412. GET_GPIO_P(dir)
  413. GET_GPIO_P(inen)
  414. GET_GPIO_P(polar)
  415. GET_GPIO_P(edge)
  416. GET_GPIO_P(both)
  417. GET_GPIO_P(maska)
  418. GET_GPIO_P(maskb)
  419. #ifdef CONFIG_PM
  420. static unsigned short wakeup_map[GPIO_BANK_NUM];
  421. static unsigned char wakeup_flags_map[MAX_BLACKFIN_GPIOS];
  422. static const unsigned int sic_iwr_irqs[] = {
  423. #if defined(BF533_FAMILY)
  424. IRQ_PROG_INTB
  425. #elif defined(BF537_FAMILY)
  426. IRQ_PROG_INTB, IRQ_PORTG_INTB, IRQ_MAC_TX
  427. #elif defined(BF538_FAMILY)
  428. IRQ_PORTF_INTB
  429. #elif defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  430. IRQ_PORTF_INTB, IRQ_PORTG_INTB, IRQ_PORTH_INTB
  431. #elif defined(BF561_FAMILY)
  432. IRQ_PROG0_INTB, IRQ_PROG1_INTB, IRQ_PROG2_INTB
  433. #else
  434. # error no SIC_IWR defined
  435. #endif
  436. };
  437. /***********************************************************
  438. *
  439. * FUNCTIONS: Blackfin PM Setup API
  440. *
  441. * INPUTS/OUTPUTS:
  442. * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS
  443. * type -
  444. * PM_WAKE_RISING
  445. * PM_WAKE_FALLING
  446. * PM_WAKE_HIGH
  447. * PM_WAKE_LOW
  448. * PM_WAKE_BOTH_EDGES
  449. *
  450. * DESCRIPTION: Blackfin PM Driver API
  451. *
  452. * CAUTION:
  453. *************************************************************
  454. * MODIFICATION HISTORY :
  455. **************************************************************/
  456. int gpio_pm_wakeup_request(unsigned gpio, unsigned char type)
  457. {
  458. unsigned long flags;
  459. if ((check_gpio(gpio) < 0) || !type)
  460. return -EINVAL;
  461. local_irq_save_hw(flags);
  462. wakeup_map[gpio_bank(gpio)] |= gpio_bit(gpio);
  463. wakeup_flags_map[gpio] = type;
  464. local_irq_restore_hw(flags);
  465. return 0;
  466. }
  467. EXPORT_SYMBOL(gpio_pm_wakeup_request);
  468. void gpio_pm_wakeup_free(unsigned gpio)
  469. {
  470. unsigned long flags;
  471. if (check_gpio(gpio) < 0)
  472. return;
  473. local_irq_save_hw(flags);
  474. wakeup_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  475. local_irq_restore_hw(flags);
  476. }
  477. EXPORT_SYMBOL(gpio_pm_wakeup_free);
  478. static int bfin_gpio_wakeup_type(unsigned gpio, unsigned char type)
  479. {
  480. port_setup(gpio, GPIO_USAGE);
  481. set_gpio_dir(gpio, 0);
  482. set_gpio_inen(gpio, 1);
  483. if (type & (PM_WAKE_RISING | PM_WAKE_FALLING))
  484. set_gpio_edge(gpio, 1);
  485. else
  486. set_gpio_edge(gpio, 0);
  487. if ((type & (PM_WAKE_BOTH_EDGES)) == (PM_WAKE_BOTH_EDGES))
  488. set_gpio_both(gpio, 1);
  489. else
  490. set_gpio_both(gpio, 0);
  491. if ((type & (PM_WAKE_FALLING | PM_WAKE_LOW)))
  492. set_gpio_polar(gpio, 1);
  493. else
  494. set_gpio_polar(gpio, 0);
  495. SSYNC();
  496. return 0;
  497. }
  498. u32 bfin_pm_standby_setup(void)
  499. {
  500. u16 bank, mask, i, gpio;
  501. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  502. mask = wakeup_map[gpio_bank(i)];
  503. bank = gpio_bank(i);
  504. gpio_bank_saved[bank].maskb = gpio_array[bank]->maskb;
  505. gpio_array[bank]->maskb = 0;
  506. if (mask) {
  507. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  508. gpio_bank_saved[bank].fer = *port_fer[bank];
  509. #endif
  510. gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
  511. gpio_bank_saved[bank].polar = gpio_array[bank]->polar;
  512. gpio_bank_saved[bank].dir = gpio_array[bank]->dir;
  513. gpio_bank_saved[bank].edge = gpio_array[bank]->edge;
  514. gpio_bank_saved[bank].both = gpio_array[bank]->both;
  515. gpio_bank_saved[bank].reserved =
  516. reserved_gpio_map[bank];
  517. gpio = i;
  518. while (mask) {
  519. if ((mask & 1) && (wakeup_flags_map[gpio] !=
  520. PM_WAKE_IGNORE)) {
  521. reserved_gpio_map[gpio_bank(gpio)] |=
  522. gpio_bit(gpio);
  523. bfin_gpio_wakeup_type(gpio,
  524. wakeup_flags_map[gpio]);
  525. set_gpio_data(gpio, 0); /*Clear*/
  526. }
  527. gpio++;
  528. mask >>= 1;
  529. }
  530. bfin_internal_set_wake(sic_iwr_irqs[bank], 1);
  531. gpio_array[bank]->maskb_set = wakeup_map[gpio_bank(i)];
  532. }
  533. }
  534. AWA_DUMMY_READ(maskb_set);
  535. return 0;
  536. }
  537. void bfin_pm_standby_restore(void)
  538. {
  539. u16 bank, mask, i;
  540. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  541. mask = wakeup_map[gpio_bank(i)];
  542. bank = gpio_bank(i);
  543. if (mask) {
  544. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  545. *port_fer[bank] = gpio_bank_saved[bank].fer;
  546. #endif
  547. gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
  548. gpio_array[bank]->dir = gpio_bank_saved[bank].dir;
  549. gpio_array[bank]->polar = gpio_bank_saved[bank].polar;
  550. gpio_array[bank]->edge = gpio_bank_saved[bank].edge;
  551. gpio_array[bank]->both = gpio_bank_saved[bank].both;
  552. reserved_gpio_map[bank] =
  553. gpio_bank_saved[bank].reserved;
  554. bfin_internal_set_wake(sic_iwr_irqs[bank], 0);
  555. }
  556. gpio_array[bank]->maskb = gpio_bank_saved[bank].maskb;
  557. }
  558. AWA_DUMMY_READ(maskb);
  559. }
  560. void bfin_gpio_pm_hibernate_suspend(void)
  561. {
  562. int i, bank;
  563. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  564. bank = gpio_bank(i);
  565. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  566. gpio_bank_saved[bank].fer = *port_fer[bank];
  567. #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  568. gpio_bank_saved[bank].mux = *port_mux[bank];
  569. #else
  570. if (bank == 0)
  571. gpio_bank_saved[bank].mux = bfin_read_PORT_MUX();
  572. #endif
  573. #endif
  574. gpio_bank_saved[bank].data = gpio_array[bank]->data;
  575. gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
  576. gpio_bank_saved[bank].polar = gpio_array[bank]->polar;
  577. gpio_bank_saved[bank].dir = gpio_array[bank]->dir;
  578. gpio_bank_saved[bank].edge = gpio_array[bank]->edge;
  579. gpio_bank_saved[bank].both = gpio_array[bank]->both;
  580. gpio_bank_saved[bank].maska = gpio_array[bank]->maska;
  581. }
  582. AWA_DUMMY_READ(maska);
  583. }
  584. void bfin_gpio_pm_hibernate_restore(void)
  585. {
  586. int i, bank;
  587. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  588. bank = gpio_bank(i);
  589. #if defined(CONFIG_BF52x) || defined(BF537_FAMILY) || defined(CONFIG_BF51x)
  590. #if defined(CONFIG_BF52x) || defined(CONFIG_BF51x)
  591. *port_mux[bank] = gpio_bank_saved[bank].mux;
  592. #else
  593. if (bank == 0)
  594. bfin_write_PORT_MUX(gpio_bank_saved[bank].mux);
  595. #endif
  596. *port_fer[bank] = gpio_bank_saved[bank].fer;
  597. #endif
  598. gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
  599. gpio_array[bank]->data_set = gpio_bank_saved[bank].data
  600. & gpio_bank_saved[bank].dir;
  601. gpio_array[bank]->dir = gpio_bank_saved[bank].dir;
  602. gpio_array[bank]->polar = gpio_bank_saved[bank].polar;
  603. gpio_array[bank]->edge = gpio_bank_saved[bank].edge;
  604. gpio_array[bank]->both = gpio_bank_saved[bank].both;
  605. gpio_array[bank]->maska = gpio_bank_saved[bank].maska;
  606. }
  607. AWA_DUMMY_READ(maska);
  608. }
  609. #endif
  610. #else /* CONFIG_BF54x */
  611. #ifdef CONFIG_PM
  612. u32 bfin_pm_standby_setup(void)
  613. {
  614. return 0;
  615. }
  616. void bfin_pm_standby_restore(void)
  617. {
  618. }
  619. void bfin_gpio_pm_hibernate_suspend(void)
  620. {
  621. int i, bank;
  622. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  623. bank = gpio_bank(i);
  624. gpio_bank_saved[bank].fer = gpio_array[bank]->port_fer;
  625. gpio_bank_saved[bank].mux = gpio_array[bank]->port_mux;
  626. gpio_bank_saved[bank].data = gpio_array[bank]->data;
  627. gpio_bank_saved[bank].inen = gpio_array[bank]->inen;
  628. gpio_bank_saved[bank].dir = gpio_array[bank]->dir_set;
  629. }
  630. }
  631. void bfin_gpio_pm_hibernate_restore(void)
  632. {
  633. int i, bank;
  634. for (i = 0; i < MAX_BLACKFIN_GPIOS; i += GPIO_BANKSIZE) {
  635. bank = gpio_bank(i);
  636. gpio_array[bank]->port_mux = gpio_bank_saved[bank].mux;
  637. gpio_array[bank]->port_fer = gpio_bank_saved[bank].fer;
  638. gpio_array[bank]->inen = gpio_bank_saved[bank].inen;
  639. gpio_array[bank]->dir_set = gpio_bank_saved[bank].dir;
  640. gpio_array[bank]->data_set = gpio_bank_saved[bank].data
  641. | gpio_bank_saved[bank].dir;
  642. }
  643. }
  644. #endif
  645. unsigned short get_gpio_dir(unsigned gpio)
  646. {
  647. return (0x01 & (gpio_array[gpio_bank(gpio)]->dir_clear >> gpio_sub_n(gpio)));
  648. }
  649. EXPORT_SYMBOL(get_gpio_dir);
  650. #endif /* CONFIG_BF54x */
  651. /***********************************************************
  652. *
  653. * FUNCTIONS: Blackfin Peripheral Resource Allocation
  654. * and PortMux Setup
  655. *
  656. * INPUTS/OUTPUTS:
  657. * per Peripheral Identifier
  658. * label String
  659. *
  660. * DESCRIPTION: Blackfin Peripheral Resource Allocation and Setup API
  661. *
  662. * CAUTION:
  663. *************************************************************
  664. * MODIFICATION HISTORY :
  665. **************************************************************/
  666. int peripheral_request(unsigned short per, const char *label)
  667. {
  668. unsigned long flags;
  669. unsigned short ident = P_IDENT(per);
  670. /*
  671. * Don't cares are pins with only one dedicated function
  672. */
  673. if (per & P_DONTCARE)
  674. return 0;
  675. if (!(per & P_DEFINED))
  676. return -ENODEV;
  677. local_irq_save_hw(flags);
  678. /* If a pin can be muxed as either GPIO or peripheral, make
  679. * sure it is not already a GPIO pin when we request it.
  680. */
  681. if (unlikely(!check_gpio(ident) &&
  682. reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
  683. if (system_state == SYSTEM_BOOTING)
  684. dump_stack();
  685. printk(KERN_ERR
  686. "%s: Peripheral %d is already reserved as GPIO by %s !\n",
  687. __func__, ident, get_label(ident));
  688. local_irq_restore_hw(flags);
  689. return -EBUSY;
  690. }
  691. if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
  692. /*
  693. * Pin functions like AMC address strobes my
  694. * be requested and used by several drivers
  695. */
  696. #ifdef CONFIG_BF54x
  697. if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) {
  698. #else
  699. if (!(per & P_MAYSHARE)) {
  700. #endif
  701. /*
  702. * Allow that the identical pin function can
  703. * be requested from the same driver twice
  704. */
  705. if (cmp_label(ident, label) == 0)
  706. goto anyway;
  707. if (system_state == SYSTEM_BOOTING)
  708. dump_stack();
  709. printk(KERN_ERR
  710. "%s: Peripheral %d function %d is already reserved by %s !\n",
  711. __func__, ident, P_FUNCT2MUX(per), get_label(ident));
  712. local_irq_restore_hw(flags);
  713. return -EBUSY;
  714. }
  715. }
  716. anyway:
  717. reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
  718. portmux_setup(per);
  719. port_setup(ident, PERIPHERAL_USAGE);
  720. local_irq_restore_hw(flags);
  721. set_label(ident, label);
  722. return 0;
  723. }
  724. EXPORT_SYMBOL(peripheral_request);
  725. int peripheral_request_list(const unsigned short per[], const char *label)
  726. {
  727. u16 cnt;
  728. int ret;
  729. for (cnt = 0; per[cnt] != 0; cnt++) {
  730. ret = peripheral_request(per[cnt], label);
  731. if (ret < 0) {
  732. for ( ; cnt > 0; cnt--)
  733. peripheral_free(per[cnt - 1]);
  734. return ret;
  735. }
  736. }
  737. return 0;
  738. }
  739. EXPORT_SYMBOL(peripheral_request_list);
  740. void peripheral_free(unsigned short per)
  741. {
  742. unsigned long flags;
  743. unsigned short ident = P_IDENT(per);
  744. if (per & P_DONTCARE)
  745. return;
  746. if (!(per & P_DEFINED))
  747. return;
  748. local_irq_save_hw(flags);
  749. if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
  750. local_irq_restore_hw(flags);
  751. return;
  752. }
  753. if (!(per & P_MAYSHARE))
  754. port_setup(ident, GPIO_USAGE);
  755. reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
  756. set_label(ident, "free");
  757. local_irq_restore_hw(flags);
  758. }
  759. EXPORT_SYMBOL(peripheral_free);
  760. void peripheral_free_list(const unsigned short per[])
  761. {
  762. u16 cnt;
  763. for (cnt = 0; per[cnt] != 0; cnt++)
  764. peripheral_free(per[cnt]);
  765. }
  766. EXPORT_SYMBOL(peripheral_free_list);
  767. /***********************************************************
  768. *
  769. * FUNCTIONS: Blackfin GPIO Driver
  770. *
  771. * INPUTS/OUTPUTS:
  772. * gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
  773. * label String
  774. *
  775. * DESCRIPTION: Blackfin GPIO Driver API
  776. *
  777. * CAUTION:
  778. *************************************************************
  779. * MODIFICATION HISTORY :
  780. **************************************************************/
  781. int bfin_gpio_request(unsigned gpio, const char *label)
  782. {
  783. unsigned long flags;
  784. if (check_gpio(gpio) < 0)
  785. return -EINVAL;
  786. local_irq_save_hw(flags);
  787. /*
  788. * Allow that the identical GPIO can
  789. * be requested from the same driver twice
  790. * Do nothing and return -
  791. */
  792. if (cmp_label(gpio, label) == 0) {
  793. local_irq_restore_hw(flags);
  794. return 0;
  795. }
  796. if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  797. if (system_state == SYSTEM_BOOTING)
  798. dump_stack();
  799. printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
  800. gpio, get_label(gpio));
  801. local_irq_restore_hw(flags);
  802. return -EBUSY;
  803. }
  804. if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  805. if (system_state == SYSTEM_BOOTING)
  806. dump_stack();
  807. printk(KERN_ERR
  808. "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
  809. gpio, get_label(gpio));
  810. local_irq_restore_hw(flags);
  811. return -EBUSY;
  812. }
  813. if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  814. printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!"
  815. " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio);
  816. }
  817. #ifndef CONFIG_BF54x
  818. else { /* Reset POLAR setting when acquiring a gpio for the first time */
  819. set_gpio_polar(gpio, 0);
  820. }
  821. #endif
  822. reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
  823. set_label(gpio, label);
  824. local_irq_restore_hw(flags);
  825. port_setup(gpio, GPIO_USAGE);
  826. return 0;
  827. }
  828. EXPORT_SYMBOL(bfin_gpio_request);
  829. void bfin_gpio_free(unsigned gpio)
  830. {
  831. unsigned long flags;
  832. if (check_gpio(gpio) < 0)
  833. return;
  834. might_sleep();
  835. local_irq_save_hw(flags);
  836. if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
  837. if (system_state == SYSTEM_BOOTING)
  838. dump_stack();
  839. gpio_error(gpio);
  840. local_irq_restore_hw(flags);
  841. return;
  842. }
  843. reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  844. set_label(gpio, "free");
  845. local_irq_restore_hw(flags);
  846. }
  847. EXPORT_SYMBOL(bfin_gpio_free);
  848. int bfin_gpio_irq_request(unsigned gpio, const char *label)
  849. {
  850. unsigned long flags;
  851. if (check_gpio(gpio) < 0)
  852. return -EINVAL;
  853. local_irq_save_hw(flags);
  854. if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  855. if (system_state == SYSTEM_BOOTING)
  856. dump_stack();
  857. printk(KERN_ERR
  858. "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
  859. gpio, get_label(gpio));
  860. local_irq_restore_hw(flags);
  861. return -EBUSY;
  862. }
  863. if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))
  864. printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved by %s! "
  865. "(Documentation/blackfin/bfin-gpio-notes.txt)\n",
  866. gpio, get_label(gpio));
  867. reserved_gpio_irq_map[gpio_bank(gpio)] |= gpio_bit(gpio);
  868. set_label(gpio, label);
  869. local_irq_restore_hw(flags);
  870. port_setup(gpio, GPIO_USAGE);
  871. return 0;
  872. }
  873. void bfin_gpio_irq_free(unsigned gpio)
  874. {
  875. unsigned long flags;
  876. if (check_gpio(gpio) < 0)
  877. return;
  878. local_irq_save_hw(flags);
  879. if (unlikely(!(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
  880. if (system_state == SYSTEM_BOOTING)
  881. dump_stack();
  882. gpio_error(gpio);
  883. local_irq_restore_hw(flags);
  884. return;
  885. }
  886. reserved_gpio_irq_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  887. set_label(gpio, "free");
  888. local_irq_restore_hw(flags);
  889. }
  890. static inline void __bfin_gpio_direction_input(unsigned gpio)
  891. {
  892. #ifdef CONFIG_BF54x
  893. gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio);
  894. #else
  895. gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
  896. #endif
  897. gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
  898. }
  899. int bfin_gpio_direction_input(unsigned gpio)
  900. {
  901. unsigned long flags;
  902. if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  903. gpio_error(gpio);
  904. return -EINVAL;
  905. }
  906. local_irq_save_hw(flags);
  907. __bfin_gpio_direction_input(gpio);
  908. AWA_DUMMY_READ(inen);
  909. local_irq_restore_hw(flags);
  910. return 0;
  911. }
  912. EXPORT_SYMBOL(bfin_gpio_direction_input);
  913. void bfin_gpio_irq_prepare(unsigned gpio)
  914. {
  915. #ifdef CONFIG_BF54x
  916. unsigned long flags;
  917. #endif
  918. port_setup(gpio, GPIO_USAGE);
  919. #ifdef CONFIG_BF54x
  920. local_irq_save_hw(flags);
  921. __bfin_gpio_direction_input(gpio);
  922. local_irq_restore_hw(flags);
  923. #endif
  924. }
  925. void bfin_gpio_set_value(unsigned gpio, int arg)
  926. {
  927. if (arg)
  928. gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
  929. else
  930. gpio_array[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
  931. }
  932. EXPORT_SYMBOL(bfin_gpio_set_value);
  933. int bfin_gpio_direction_output(unsigned gpio, int value)
  934. {
  935. unsigned long flags;
  936. if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  937. gpio_error(gpio);
  938. return -EINVAL;
  939. }
  940. local_irq_save_hw(flags);
  941. gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
  942. gpio_set_value(gpio, value);
  943. #ifdef CONFIG_BF54x
  944. gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio);
  945. #else
  946. gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
  947. #endif
  948. AWA_DUMMY_READ(dir);
  949. local_irq_restore_hw(flags);
  950. return 0;
  951. }
  952. EXPORT_SYMBOL(bfin_gpio_direction_output);
  953. int bfin_gpio_get_value(unsigned gpio)
  954. {
  955. #ifdef CONFIG_BF54x
  956. return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio)));
  957. #else
  958. unsigned long flags;
  959. if (unlikely(get_gpio_edge(gpio))) {
  960. int ret;
  961. local_irq_save_hw(flags);
  962. set_gpio_edge(gpio, 0);
  963. ret = get_gpio_data(gpio);
  964. set_gpio_edge(gpio, 1);
  965. local_irq_restore_hw(flags);
  966. return ret;
  967. } else
  968. return get_gpio_data(gpio);
  969. #endif
  970. }
  971. EXPORT_SYMBOL(bfin_gpio_get_value);
  972. /* If we are booting from SPI and our board lacks a strong enough pull up,
  973. * the core can reset and execute the bootrom faster than the resistor can
  974. * pull the signal logically high. To work around this (common) error in
  975. * board design, we explicitly set the pin back to GPIO mode, force /CS
  976. * high, and wait for the electrons to do their thing.
  977. *
  978. * This function only makes sense to be called from reset code, but it
  979. * lives here as we need to force all the GPIO states w/out going through
  980. * BUG() checks and such.
  981. */
  982. void bfin_reset_boot_spi_cs(unsigned short pin)
  983. {
  984. unsigned short gpio = P_IDENT(pin);
  985. port_setup(gpio, GPIO_USAGE);
  986. gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
  987. AWA_DUMMY_READ(data_set);
  988. udelay(1);
  989. }
  990. #if defined(CONFIG_PROC_FS)
  991. static int gpio_proc_read(char *buf, char **start, off_t offset,
  992. int len, int *unused_i, void *unused_v)
  993. {
  994. int c, irq, gpio, outlen = 0;
  995. for (c = 0; c < MAX_RESOURCES; c++) {
  996. irq = reserved_gpio_irq_map[gpio_bank(c)] & gpio_bit(c);
  997. gpio = reserved_gpio_map[gpio_bank(c)] & gpio_bit(c);
  998. if (!check_gpio(c) && (gpio || irq))
  999. len = sprintf(buf, "GPIO_%d: \t%s%s \t\tGPIO %s\n", c,
  1000. get_label(c), (gpio && irq) ? " *" : "",
  1001. get_gpio_dir(c) ? "OUTPUT" : "INPUT");
  1002. else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c))
  1003. len = sprintf(buf, "GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c));
  1004. else
  1005. continue;
  1006. buf += len;
  1007. outlen += len;
  1008. }
  1009. return outlen;
  1010. }
  1011. static __init int gpio_register_proc(void)
  1012. {
  1013. struct proc_dir_entry *proc_gpio;
  1014. proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
  1015. if (proc_gpio)
  1016. proc_gpio->read_proc = gpio_proc_read;
  1017. return proc_gpio != NULL;
  1018. }
  1019. __initcall(gpio_register_proc);
  1020. #endif
  1021. #ifdef CONFIG_GPIOLIB
  1022. int bfin_gpiolib_direction_input(struct gpio_chip *chip, unsigned gpio)
  1023. {
  1024. return bfin_gpio_direction_input(gpio);
  1025. }
  1026. int bfin_gpiolib_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
  1027. {
  1028. return bfin_gpio_direction_output(gpio, level);
  1029. }
  1030. int bfin_gpiolib_get_value(struct gpio_chip *chip, unsigned gpio)
  1031. {
  1032. return bfin_gpio_get_value(gpio);
  1033. }
  1034. void bfin_gpiolib_set_value(struct gpio_chip *chip, unsigned gpio, int value)
  1035. {
  1036. return bfin_gpio_set_value(gpio, value);
  1037. }
  1038. int bfin_gpiolib_gpio_request(struct gpio_chip *chip, unsigned gpio)
  1039. {
  1040. return bfin_gpio_request(gpio, chip->label);
  1041. }
  1042. void bfin_gpiolib_gpio_free(struct gpio_chip *chip, unsigned gpio)
  1043. {
  1044. return bfin_gpio_free(gpio);
  1045. }
  1046. static struct gpio_chip bfin_chip = {
  1047. .label = "Blackfin-GPIOlib",
  1048. .direction_input = bfin_gpiolib_direction_input,
  1049. .get = bfin_gpiolib_get_value,
  1050. .direction_output = bfin_gpiolib_direction_output,
  1051. .set = bfin_gpiolib_set_value,
  1052. .request = bfin_gpiolib_gpio_request,
  1053. .free = bfin_gpiolib_gpio_free,
  1054. .base = 0,
  1055. .ngpio = MAX_BLACKFIN_GPIOS,
  1056. };
  1057. static int __init bfin_gpiolib_setup(void)
  1058. {
  1059. return gpiochip_add(&bfin_chip);
  1060. }
  1061. arch_initcall(bfin_gpiolib_setup);
  1062. #endif