bfin_gpio.c 31 KB

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