bfin_gpio.c 31 KB

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