bfin_gpio.c 31 KB

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