bfin_gpio.c 31 KB

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