bfin_gpio.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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. # if defined(BF527_FAMILY)
  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(BF518_FAMILY)
  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(BF548_FAMILY)
  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(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
  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(BF548_FAMILY)
  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(BF548_FAMILY)
  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(BF527_FAMILY) || defined(BF518_FAMILY)
  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 BF548_FAMILY
  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(BF527_FAMILY) || defined(BF518_FAMILY)
  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(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
  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(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
  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(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
  572. gpio_bank_saved[bank].fer = *port_fer[bank];
  573. #if defined(BF527_FAMILY) || defined(BF518_FAMILY)
  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(BF527_FAMILY) || defined(BF537_FAMILY) || defined(BF518_FAMILY)
  596. #if defined(BF527_FAMILY) || defined(BF518_FAMILY)
  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 /* BF548_FAMILY */
  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 /* BF548_FAMILY */
  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. dump_stack();
  691. printk(KERN_ERR
  692. "%s: Peripheral %d is already reserved as GPIO by %s !\n",
  693. __func__, ident, get_label(ident));
  694. local_irq_restore_hw(flags);
  695. return -EBUSY;
  696. }
  697. if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
  698. /*
  699. * Pin functions like AMC address strobes my
  700. * be requested and used by several drivers
  701. */
  702. #ifdef BF548_FAMILY
  703. if (!((per & P_MAYSHARE) && get_portmux(per) == P_FUNCT2MUX(per))) {
  704. #else
  705. if (!(per & P_MAYSHARE)) {
  706. #endif
  707. /*
  708. * Allow that the identical pin function can
  709. * be requested from the same driver twice
  710. */
  711. if (cmp_label(ident, label) == 0)
  712. goto anyway;
  713. dump_stack();
  714. printk(KERN_ERR
  715. "%s: Peripheral %d function %d is already reserved by %s !\n",
  716. __func__, ident, P_FUNCT2MUX(per), get_label(ident));
  717. local_irq_restore_hw(flags);
  718. return -EBUSY;
  719. }
  720. }
  721. anyway:
  722. reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
  723. portmux_setup(per);
  724. port_setup(ident, PERIPHERAL_USAGE);
  725. local_irq_restore_hw(flags);
  726. set_label(ident, label);
  727. return 0;
  728. }
  729. EXPORT_SYMBOL(peripheral_request);
  730. int peripheral_request_list(const unsigned short per[], const char *label)
  731. {
  732. u16 cnt;
  733. int ret;
  734. for (cnt = 0; per[cnt] != 0; cnt++) {
  735. ret = peripheral_request(per[cnt], label);
  736. if (ret < 0) {
  737. for ( ; cnt > 0; cnt--)
  738. peripheral_free(per[cnt - 1]);
  739. return ret;
  740. }
  741. }
  742. return 0;
  743. }
  744. EXPORT_SYMBOL(peripheral_request_list);
  745. void peripheral_free(unsigned short per)
  746. {
  747. unsigned long flags;
  748. unsigned short ident = P_IDENT(per);
  749. if (per & P_DONTCARE)
  750. return;
  751. if (!(per & P_DEFINED))
  752. return;
  753. local_irq_save_hw(flags);
  754. if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
  755. local_irq_restore_hw(flags);
  756. return;
  757. }
  758. if (!(per & P_MAYSHARE))
  759. port_setup(ident, GPIO_USAGE);
  760. reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
  761. set_label(ident, "free");
  762. local_irq_restore_hw(flags);
  763. }
  764. EXPORT_SYMBOL(peripheral_free);
  765. void peripheral_free_list(const unsigned short per[])
  766. {
  767. u16 cnt;
  768. for (cnt = 0; per[cnt] != 0; cnt++)
  769. peripheral_free(per[cnt]);
  770. }
  771. EXPORT_SYMBOL(peripheral_free_list);
  772. /***********************************************************
  773. *
  774. * FUNCTIONS: Blackfin GPIO Driver
  775. *
  776. * INPUTS/OUTPUTS:
  777. * gpio PIO Number between 0 and MAX_BLACKFIN_GPIOS
  778. * label String
  779. *
  780. * DESCRIPTION: Blackfin GPIO Driver API
  781. *
  782. * CAUTION:
  783. *************************************************************
  784. * MODIFICATION HISTORY :
  785. **************************************************************/
  786. int bfin_gpio_request(unsigned gpio, const char *label)
  787. {
  788. unsigned long flags;
  789. if (check_gpio(gpio) < 0)
  790. return -EINVAL;
  791. local_irq_save_hw(flags);
  792. /*
  793. * Allow that the identical GPIO can
  794. * be requested from the same driver twice
  795. * Do nothing and return -
  796. */
  797. if (cmp_label(gpio, label) == 0) {
  798. local_irq_restore_hw(flags);
  799. return 0;
  800. }
  801. if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  802. dump_stack();
  803. printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
  804. gpio, get_label(gpio));
  805. local_irq_restore_hw(flags);
  806. return -EBUSY;
  807. }
  808. if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  809. dump_stack();
  810. printk(KERN_ERR
  811. "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
  812. gpio, get_label(gpio));
  813. local_irq_restore_hw(flags);
  814. return -EBUSY;
  815. }
  816. if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  817. printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved as gpio-irq!"
  818. " (Documentation/blackfin/bfin-gpio-notes.txt)\n", gpio);
  819. }
  820. #ifndef BF548_FAMILY
  821. else { /* Reset POLAR setting when acquiring a gpio for the first time */
  822. set_gpio_polar(gpio, 0);
  823. }
  824. #endif
  825. reserved_gpio_map[gpio_bank(gpio)] |= gpio_bit(gpio);
  826. set_label(gpio, label);
  827. local_irq_restore_hw(flags);
  828. port_setup(gpio, GPIO_USAGE);
  829. return 0;
  830. }
  831. EXPORT_SYMBOL(bfin_gpio_request);
  832. void bfin_gpio_free(unsigned gpio)
  833. {
  834. unsigned long flags;
  835. if (check_gpio(gpio) < 0)
  836. return;
  837. might_sleep();
  838. local_irq_save_hw(flags);
  839. if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
  840. dump_stack();
  841. gpio_error(gpio);
  842. local_irq_restore_hw(flags);
  843. return;
  844. }
  845. reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  846. set_label(gpio, "free");
  847. local_irq_restore_hw(flags);
  848. }
  849. EXPORT_SYMBOL(bfin_gpio_free);
  850. int bfin_gpio_irq_request(unsigned gpio, const char *label)
  851. {
  852. unsigned long flags;
  853. if (check_gpio(gpio) < 0)
  854. return -EINVAL;
  855. local_irq_save_hw(flags);
  856. if (unlikely(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  857. dump_stack();
  858. printk(KERN_ERR
  859. "bfin-gpio: GPIO %d is already reserved as gpio-irq !\n",
  860. gpio);
  861. local_irq_restore_hw(flags);
  862. return -EBUSY;
  863. }
  864. if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  865. dump_stack();
  866. printk(KERN_ERR
  867. "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
  868. gpio, get_label(gpio));
  869. local_irq_restore_hw(flags);
  870. return -EBUSY;
  871. }
  872. if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))
  873. printk(KERN_NOTICE "bfin-gpio: GPIO %d is already reserved by %s! "
  874. "(Documentation/blackfin/bfin-gpio-notes.txt)\n",
  875. gpio, get_label(gpio));
  876. reserved_gpio_irq_map[gpio_bank(gpio)] |= gpio_bit(gpio);
  877. set_label(gpio, label);
  878. local_irq_restore_hw(flags);
  879. port_setup(gpio, GPIO_USAGE);
  880. return 0;
  881. }
  882. void bfin_gpio_irq_free(unsigned gpio)
  883. {
  884. unsigned long flags;
  885. if (check_gpio(gpio) < 0)
  886. return;
  887. local_irq_save_hw(flags);
  888. if (unlikely(!(reserved_gpio_irq_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
  889. dump_stack();
  890. gpio_error(gpio);
  891. local_irq_restore_hw(flags);
  892. return;
  893. }
  894. reserved_gpio_irq_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
  895. set_label(gpio, "free");
  896. local_irq_restore_hw(flags);
  897. }
  898. static inline void __bfin_gpio_direction_input(unsigned gpio)
  899. {
  900. #ifdef BF548_FAMILY
  901. gpio_array[gpio_bank(gpio)]->dir_clear = gpio_bit(gpio);
  902. #else
  903. gpio_array[gpio_bank(gpio)]->dir &= ~gpio_bit(gpio);
  904. #endif
  905. gpio_array[gpio_bank(gpio)]->inen |= gpio_bit(gpio);
  906. }
  907. int bfin_gpio_direction_input(unsigned gpio)
  908. {
  909. unsigned long flags;
  910. if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  911. gpio_error(gpio);
  912. return -EINVAL;
  913. }
  914. local_irq_save_hw(flags);
  915. __bfin_gpio_direction_input(gpio);
  916. AWA_DUMMY_READ(inen);
  917. local_irq_restore_hw(flags);
  918. return 0;
  919. }
  920. EXPORT_SYMBOL(bfin_gpio_direction_input);
  921. void bfin_gpio_irq_prepare(unsigned gpio)
  922. {
  923. #ifdef BF548_FAMILY
  924. unsigned long flags;
  925. #endif
  926. port_setup(gpio, GPIO_USAGE);
  927. #ifdef BF548_FAMILY
  928. local_irq_save_hw(flags);
  929. __bfin_gpio_direction_input(gpio);
  930. local_irq_restore_hw(flags);
  931. #endif
  932. }
  933. void bfin_gpio_set_value(unsigned gpio, int arg)
  934. {
  935. if (arg)
  936. gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
  937. else
  938. gpio_array[gpio_bank(gpio)]->data_clear = gpio_bit(gpio);
  939. }
  940. EXPORT_SYMBOL(bfin_gpio_set_value);
  941. int bfin_gpio_direction_output(unsigned gpio, int value)
  942. {
  943. unsigned long flags;
  944. if (!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
  945. gpio_error(gpio);
  946. return -EINVAL;
  947. }
  948. local_irq_save_hw(flags);
  949. gpio_array[gpio_bank(gpio)]->inen &= ~gpio_bit(gpio);
  950. gpio_set_value(gpio, value);
  951. #ifdef BF548_FAMILY
  952. gpio_array[gpio_bank(gpio)]->dir_set = gpio_bit(gpio);
  953. #else
  954. gpio_array[gpio_bank(gpio)]->dir |= gpio_bit(gpio);
  955. #endif
  956. AWA_DUMMY_READ(dir);
  957. local_irq_restore_hw(flags);
  958. return 0;
  959. }
  960. EXPORT_SYMBOL(bfin_gpio_direction_output);
  961. int bfin_gpio_get_value(unsigned gpio)
  962. {
  963. #ifdef BF548_FAMILY
  964. return (1 & (gpio_array[gpio_bank(gpio)]->data >> gpio_sub_n(gpio)));
  965. #else
  966. unsigned long flags;
  967. if (unlikely(get_gpio_edge(gpio))) {
  968. int ret;
  969. local_irq_save_hw(flags);
  970. set_gpio_edge(gpio, 0);
  971. ret = get_gpio_data(gpio);
  972. set_gpio_edge(gpio, 1);
  973. local_irq_restore_hw(flags);
  974. return ret;
  975. } else
  976. return get_gpio_data(gpio);
  977. #endif
  978. }
  979. EXPORT_SYMBOL(bfin_gpio_get_value);
  980. /* If we are booting from SPI and our board lacks a strong enough pull up,
  981. * the core can reset and execute the bootrom faster than the resistor can
  982. * pull the signal logically high. To work around this (common) error in
  983. * board design, we explicitly set the pin back to GPIO mode, force /CS
  984. * high, and wait for the electrons to do their thing.
  985. *
  986. * This function only makes sense to be called from reset code, but it
  987. * lives here as we need to force all the GPIO states w/out going through
  988. * BUG() checks and such.
  989. */
  990. void bfin_reset_boot_spi_cs(unsigned short pin)
  991. {
  992. unsigned short gpio = P_IDENT(pin);
  993. port_setup(gpio, GPIO_USAGE);
  994. gpio_array[gpio_bank(gpio)]->data_set = gpio_bit(gpio);
  995. AWA_DUMMY_READ(data_set);
  996. udelay(1);
  997. }
  998. #if defined(CONFIG_PROC_FS)
  999. static int gpio_proc_read(char *buf, char **start, off_t offset,
  1000. int len, int *unused_i, void *unused_v)
  1001. {
  1002. int c, irq, gpio, outlen = 0;
  1003. for (c = 0; c < MAX_RESOURCES; c++) {
  1004. irq = reserved_gpio_irq_map[gpio_bank(c)] & gpio_bit(c);
  1005. gpio = reserved_gpio_map[gpio_bank(c)] & gpio_bit(c);
  1006. if (!check_gpio(c) && (gpio || irq))
  1007. len = sprintf(buf, "GPIO_%d: \t%s%s \t\tGPIO %s\n", c,
  1008. get_label(c), (gpio && irq) ? " *" : "",
  1009. get_gpio_dir(c) ? "OUTPUT" : "INPUT");
  1010. else if (reserved_peri_map[gpio_bank(c)] & gpio_bit(c))
  1011. len = sprintf(buf, "GPIO_%d: \t%s \t\tPeripheral\n", c, get_label(c));
  1012. else
  1013. continue;
  1014. buf += len;
  1015. outlen += len;
  1016. }
  1017. return outlen;
  1018. }
  1019. static __init int gpio_register_proc(void)
  1020. {
  1021. struct proc_dir_entry *proc_gpio;
  1022. proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
  1023. if (proc_gpio)
  1024. proc_gpio->read_proc = gpio_proc_read;
  1025. return proc_gpio != NULL;
  1026. }
  1027. __initcall(gpio_register_proc);
  1028. #endif
  1029. #ifdef CONFIG_GPIOLIB
  1030. int bfin_gpiolib_direction_input(struct gpio_chip *chip, unsigned gpio)
  1031. {
  1032. return bfin_gpio_direction_input(gpio);
  1033. }
  1034. int bfin_gpiolib_direction_output(struct gpio_chip *chip, unsigned gpio, int level)
  1035. {
  1036. return bfin_gpio_direction_output(gpio, level);
  1037. }
  1038. int bfin_gpiolib_get_value(struct gpio_chip *chip, unsigned gpio)
  1039. {
  1040. return bfin_gpio_get_value(gpio);
  1041. }
  1042. void bfin_gpiolib_set_value(struct gpio_chip *chip, unsigned gpio, int value)
  1043. {
  1044. return bfin_gpio_set_value(gpio, value);
  1045. }
  1046. int bfin_gpiolib_gpio_request(struct gpio_chip *chip, unsigned gpio)
  1047. {
  1048. return bfin_gpio_request(gpio, chip->label);
  1049. }
  1050. void bfin_gpiolib_gpio_free(struct gpio_chip *chip, unsigned gpio)
  1051. {
  1052. return bfin_gpio_free(gpio);
  1053. }
  1054. static struct gpio_chip bfin_chip = {
  1055. .label = "Blackfin-GPIOlib",
  1056. .direction_input = bfin_gpiolib_direction_input,
  1057. .get = bfin_gpiolib_get_value,
  1058. .direction_output = bfin_gpiolib_direction_output,
  1059. .set = bfin_gpiolib_set_value,
  1060. .request = bfin_gpiolib_gpio_request,
  1061. .free = bfin_gpiolib_gpio_free,
  1062. .base = 0,
  1063. .ngpio = MAX_BLACKFIN_GPIOS,
  1064. };
  1065. static int __init bfin_gpiolib_setup(void)
  1066. {
  1067. return gpiochip_add(&bfin_chip);
  1068. }
  1069. arch_initcall(bfin_gpiolib_setup);
  1070. #endif