bfin_gpio.c 30 KB

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