bfin_gpio.c 31 KB

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