bfin_gpio.c 30 KB

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