bfin_gpio.c 31 KB

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