gpio-au1000.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /*
  2. * GPIO functions for Au1000, Au1500, Au1100, Au1550, Au1200
  3. *
  4. * Copyright (c) 2009 Manuel Lauss.
  5. *
  6. * Licensed under the terms outlined in the file COPYING.
  7. */
  8. #ifndef _ALCHEMY_GPIO_AU1000_H_
  9. #define _ALCHEMY_GPIO_AU1000_H_
  10. #include <asm/mach-au1x00/au1000.h>
  11. /* The default GPIO numberspace as documented in the Alchemy manuals.
  12. * GPIO0-31 from GPIO1 block, GPIO200-215 from GPIO2 block.
  13. */
  14. #define ALCHEMY_GPIO1_BASE 0
  15. #define ALCHEMY_GPIO2_BASE 200
  16. #define ALCHEMY_GPIO1_NUM 32
  17. #define ALCHEMY_GPIO2_NUM 16
  18. #define ALCHEMY_GPIO1_MAX (ALCHEMY_GPIO1_BASE + ALCHEMY_GPIO1_NUM - 1)
  19. #define ALCHEMY_GPIO2_MAX (ALCHEMY_GPIO2_BASE + ALCHEMY_GPIO2_NUM - 1)
  20. #define MAKE_IRQ(intc, off) (AU1000_INTC##intc##_INT_BASE + (off))
  21. /* GPIO1 registers within SYS_ area */
  22. #define SYS_TRIOUTRD 0x100
  23. #define SYS_TRIOUTCLR 0x100
  24. #define SYS_OUTPUTRD 0x108
  25. #define SYS_OUTPUTSET 0x108
  26. #define SYS_OUTPUTCLR 0x10C
  27. #define SYS_PINSTATERD 0x110
  28. #define SYS_PININPUTEN 0x110
  29. /* register offsets within GPIO2 block */
  30. #define GPIO2_DIR 0x00
  31. #define GPIO2_OUTPUT 0x08
  32. #define GPIO2_PINSTATE 0x0C
  33. #define GPIO2_INTENABLE 0x10
  34. #define GPIO2_ENABLE 0x14
  35. struct gpio;
  36. static inline int au1000_gpio1_to_irq(int gpio)
  37. {
  38. return MAKE_IRQ(1, gpio - ALCHEMY_GPIO1_BASE);
  39. }
  40. static inline int au1000_gpio2_to_irq(int gpio)
  41. {
  42. return -ENXIO;
  43. }
  44. static inline int au1000_irq_to_gpio(int irq)
  45. {
  46. if ((irq >= AU1000_GPIO0_INT) && (irq <= AU1000_GPIO31_INT))
  47. return ALCHEMY_GPIO1_BASE + (irq - AU1000_GPIO0_INT) + 0;
  48. return -ENXIO;
  49. }
  50. static inline int au1500_gpio1_to_irq(int gpio)
  51. {
  52. gpio -= ALCHEMY_GPIO1_BASE;
  53. switch (gpio) {
  54. case 0 ... 15:
  55. case 20:
  56. case 23 ... 28: return MAKE_IRQ(1, gpio);
  57. }
  58. return -ENXIO;
  59. }
  60. static inline int au1500_gpio2_to_irq(int gpio)
  61. {
  62. gpio -= ALCHEMY_GPIO2_BASE;
  63. switch (gpio) {
  64. case 0 ... 3: return MAKE_IRQ(1, 16 + gpio - 0);
  65. case 4 ... 5: return MAKE_IRQ(1, 21 + gpio - 4);
  66. case 6 ... 7: return MAKE_IRQ(1, 29 + gpio - 6);
  67. }
  68. return -ENXIO;
  69. }
  70. static inline int au1500_irq_to_gpio(int irq)
  71. {
  72. switch (irq) {
  73. case AU1500_GPIO0_INT ... AU1500_GPIO15_INT:
  74. case AU1500_GPIO20_INT:
  75. case AU1500_GPIO23_INT ... AU1500_GPIO28_INT:
  76. return ALCHEMY_GPIO1_BASE + (irq - AU1500_GPIO0_INT) + 0;
  77. case AU1500_GPIO200_INT ... AU1500_GPIO203_INT:
  78. return ALCHEMY_GPIO2_BASE + (irq - AU1500_GPIO200_INT) + 0;
  79. case AU1500_GPIO204_INT ... AU1500_GPIO205_INT:
  80. return ALCHEMY_GPIO2_BASE + (irq - AU1500_GPIO204_INT) + 4;
  81. case AU1500_GPIO206_INT ... AU1500_GPIO207_INT:
  82. return ALCHEMY_GPIO2_BASE + (irq - AU1500_GPIO206_INT) + 6;
  83. case AU1500_GPIO208_215_INT:
  84. return ALCHEMY_GPIO2_BASE + 8;
  85. }
  86. return -ENXIO;
  87. }
  88. static inline int au1100_gpio1_to_irq(int gpio)
  89. {
  90. return MAKE_IRQ(1, gpio - ALCHEMY_GPIO1_BASE);
  91. }
  92. static inline int au1100_gpio2_to_irq(int gpio)
  93. {
  94. gpio -= ALCHEMY_GPIO2_BASE;
  95. if ((gpio >= 8) && (gpio <= 15))
  96. return MAKE_IRQ(0, 29); /* shared GPIO208_215 */
  97. return -ENXIO;
  98. }
  99. static inline int au1100_irq_to_gpio(int irq)
  100. {
  101. switch (irq) {
  102. case AU1100_GPIO0_INT ... AU1100_GPIO31_INT:
  103. return ALCHEMY_GPIO1_BASE + (irq - AU1100_GPIO0_INT) + 0;
  104. case AU1100_GPIO208_215_INT:
  105. return ALCHEMY_GPIO2_BASE + 8;
  106. }
  107. return -ENXIO;
  108. }
  109. static inline int au1550_gpio1_to_irq(int gpio)
  110. {
  111. gpio -= ALCHEMY_GPIO1_BASE;
  112. switch (gpio) {
  113. case 0 ... 15:
  114. case 20 ... 28: return MAKE_IRQ(1, gpio);
  115. case 16 ... 17: return MAKE_IRQ(1, 18 + gpio - 16);
  116. }
  117. return -ENXIO;
  118. }
  119. static inline int au1550_gpio2_to_irq(int gpio)
  120. {
  121. gpio -= ALCHEMY_GPIO2_BASE;
  122. switch (gpio) {
  123. case 0: return MAKE_IRQ(1, 16);
  124. case 1 ... 5: return MAKE_IRQ(1, 17); /* shared GPIO201_205 */
  125. case 6 ... 7: return MAKE_IRQ(1, 29 + gpio - 6);
  126. case 8 ... 15: return MAKE_IRQ(1, 31); /* shared GPIO208_215 */
  127. }
  128. return -ENXIO;
  129. }
  130. static inline int au1550_irq_to_gpio(int irq)
  131. {
  132. switch (irq) {
  133. case AU1550_GPIO0_INT ... AU1550_GPIO15_INT:
  134. return ALCHEMY_GPIO1_BASE + (irq - AU1550_GPIO0_INT) + 0;
  135. case AU1550_GPIO200_INT:
  136. case AU1550_GPIO201_205_INT:
  137. return ALCHEMY_GPIO2_BASE + (irq - AU1550_GPIO200_INT) + 0;
  138. case AU1550_GPIO16_INT ... AU1550_GPIO28_INT:
  139. return ALCHEMY_GPIO1_BASE + (irq - AU1550_GPIO16_INT) + 16;
  140. case AU1550_GPIO206_INT ... AU1550_GPIO208_215_INT:
  141. return ALCHEMY_GPIO2_BASE + (irq - AU1550_GPIO206_INT) + 6;
  142. }
  143. return -ENXIO;
  144. }
  145. static inline int au1200_gpio1_to_irq(int gpio)
  146. {
  147. return MAKE_IRQ(1, gpio - ALCHEMY_GPIO1_BASE);
  148. }
  149. static inline int au1200_gpio2_to_irq(int gpio)
  150. {
  151. gpio -= ALCHEMY_GPIO2_BASE;
  152. switch (gpio) {
  153. case 0 ... 2: return MAKE_IRQ(0, 5 + gpio - 0);
  154. case 3: return MAKE_IRQ(0, 22);
  155. case 4 ... 7: return MAKE_IRQ(0, 24 + gpio - 4);
  156. case 8 ... 15: return MAKE_IRQ(0, 28); /* shared GPIO208_215 */
  157. }
  158. return -ENXIO;
  159. }
  160. static inline int au1200_irq_to_gpio(int irq)
  161. {
  162. switch (irq) {
  163. case AU1200_GPIO0_INT ... AU1200_GPIO31_INT:
  164. return ALCHEMY_GPIO1_BASE + (irq - AU1200_GPIO0_INT) + 0;
  165. case AU1200_GPIO200_INT ... AU1200_GPIO202_INT:
  166. return ALCHEMY_GPIO2_BASE + (irq - AU1200_GPIO200_INT) + 0;
  167. case AU1200_GPIO203_INT:
  168. return ALCHEMY_GPIO2_BASE + 3;
  169. case AU1200_GPIO204_INT ... AU1200_GPIO208_215_INT:
  170. return ALCHEMY_GPIO2_BASE + (irq - AU1200_GPIO204_INT) + 4;
  171. }
  172. return -ENXIO;
  173. }
  174. /*
  175. * GPIO1 block macros for common linux gpio functions.
  176. */
  177. static inline void alchemy_gpio1_set_value(int gpio, int v)
  178. {
  179. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR);
  180. unsigned long mask = 1 << (gpio - ALCHEMY_GPIO1_BASE);
  181. unsigned long r = v ? SYS_OUTPUTSET : SYS_OUTPUTCLR;
  182. __raw_writel(mask, base + r);
  183. wmb();
  184. }
  185. static inline int alchemy_gpio1_get_value(int gpio)
  186. {
  187. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR);
  188. unsigned long mask = 1 << (gpio - ALCHEMY_GPIO1_BASE);
  189. return __raw_readl(base + SYS_PINSTATERD) & mask;
  190. }
  191. static inline int alchemy_gpio1_direction_input(int gpio)
  192. {
  193. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR);
  194. unsigned long mask = 1 << (gpio - ALCHEMY_GPIO1_BASE);
  195. __raw_writel(mask, base + SYS_TRIOUTCLR);
  196. wmb();
  197. return 0;
  198. }
  199. static inline int alchemy_gpio1_direction_output(int gpio, int v)
  200. {
  201. /* hardware switches to "output" mode when one of the two
  202. * "set_value" registers is accessed.
  203. */
  204. alchemy_gpio1_set_value(gpio, v);
  205. return 0;
  206. }
  207. static inline int alchemy_gpio1_is_valid(int gpio)
  208. {
  209. return ((gpio >= ALCHEMY_GPIO1_BASE) && (gpio <= ALCHEMY_GPIO1_MAX));
  210. }
  211. static inline int alchemy_gpio1_to_irq(int gpio)
  212. {
  213. switch (alchemy_get_cputype()) {
  214. case ALCHEMY_CPU_AU1000:
  215. return au1000_gpio1_to_irq(gpio);
  216. case ALCHEMY_CPU_AU1100:
  217. return au1100_gpio1_to_irq(gpio);
  218. case ALCHEMY_CPU_AU1500:
  219. return au1500_gpio1_to_irq(gpio);
  220. case ALCHEMY_CPU_AU1550:
  221. return au1550_gpio1_to_irq(gpio);
  222. case ALCHEMY_CPU_AU1200:
  223. return au1200_gpio1_to_irq(gpio);
  224. }
  225. return -ENXIO;
  226. }
  227. /*
  228. * GPIO2 block macros for common linux GPIO functions. The 'gpio'
  229. * parameter must be in range of ALCHEMY_GPIO2_BASE..ALCHEMY_GPIO2_MAX.
  230. */
  231. static inline void __alchemy_gpio2_mod_dir(int gpio, int to_out)
  232. {
  233. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
  234. unsigned long mask = 1 << (gpio - ALCHEMY_GPIO2_BASE);
  235. unsigned long d = __raw_readl(base + GPIO2_DIR);
  236. if (to_out)
  237. d |= mask;
  238. else
  239. d &= ~mask;
  240. __raw_writel(d, base + GPIO2_DIR);
  241. wmb();
  242. }
  243. static inline void alchemy_gpio2_set_value(int gpio, int v)
  244. {
  245. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
  246. unsigned long mask;
  247. mask = ((v) ? 0x00010001 : 0x00010000) << (gpio - ALCHEMY_GPIO2_BASE);
  248. __raw_writel(mask, base + GPIO2_OUTPUT);
  249. wmb();
  250. }
  251. static inline int alchemy_gpio2_get_value(int gpio)
  252. {
  253. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
  254. return __raw_readl(base + GPIO2_PINSTATE) & (1 << (gpio - ALCHEMY_GPIO2_BASE));
  255. }
  256. static inline int alchemy_gpio2_direction_input(int gpio)
  257. {
  258. unsigned long flags;
  259. local_irq_save(flags);
  260. __alchemy_gpio2_mod_dir(gpio, 0);
  261. local_irq_restore(flags);
  262. return 0;
  263. }
  264. static inline int alchemy_gpio2_direction_output(int gpio, int v)
  265. {
  266. unsigned long flags;
  267. alchemy_gpio2_set_value(gpio, v);
  268. local_irq_save(flags);
  269. __alchemy_gpio2_mod_dir(gpio, 1);
  270. local_irq_restore(flags);
  271. return 0;
  272. }
  273. static inline int alchemy_gpio2_is_valid(int gpio)
  274. {
  275. return ((gpio >= ALCHEMY_GPIO2_BASE) && (gpio <= ALCHEMY_GPIO2_MAX));
  276. }
  277. static inline int alchemy_gpio2_to_irq(int gpio)
  278. {
  279. switch (alchemy_get_cputype()) {
  280. case ALCHEMY_CPU_AU1000:
  281. return au1000_gpio2_to_irq(gpio);
  282. case ALCHEMY_CPU_AU1100:
  283. return au1100_gpio2_to_irq(gpio);
  284. case ALCHEMY_CPU_AU1500:
  285. return au1500_gpio2_to_irq(gpio);
  286. case ALCHEMY_CPU_AU1550:
  287. return au1550_gpio2_to_irq(gpio);
  288. case ALCHEMY_CPU_AU1200:
  289. return au1200_gpio2_to_irq(gpio);
  290. }
  291. return -ENXIO;
  292. }
  293. /**********************************************************************/
  294. /* On Au1000, Au1500 and Au1100 GPIOs won't work as inputs before
  295. * SYS_PININPUTEN is written to at least once. On Au1550/Au1200 this
  296. * register enables use of GPIOs as wake source.
  297. */
  298. static inline void alchemy_gpio1_input_enable(void)
  299. {
  300. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1000_SYS_PHYS_ADDR);
  301. __raw_writel(0, base + SYS_PININPUTEN); /* the write op is key */
  302. wmb();
  303. }
  304. /* GPIO2 shared interrupts and control */
  305. static inline void __alchemy_gpio2_mod_int(int gpio2, int en)
  306. {
  307. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
  308. unsigned long r = __raw_readl(base + GPIO2_INTENABLE);
  309. if (en)
  310. r |= 1 << gpio2;
  311. else
  312. r &= ~(1 << gpio2);
  313. __raw_writel(r, base + GPIO2_INTENABLE);
  314. wmb();
  315. }
  316. /**
  317. * alchemy_gpio2_enable_int - Enable a GPIO2 pins' shared irq contribution.
  318. * @gpio2: The GPIO2 pin to activate (200...215).
  319. *
  320. * GPIO208-215 have one shared interrupt line to the INTC. They are
  321. * and'ed with a per-pin enable bit and finally or'ed together to form
  322. * a single irq request (useful for active-high sources).
  323. * With this function, a pins' individual contribution to the int request
  324. * can be enabled. As with all other GPIO-based interrupts, the INTC
  325. * must be programmed to accept the GPIO208_215 interrupt as well.
  326. *
  327. * NOTE: Calling this macro is only necessary for GPIO208-215; all other
  328. * GPIO2-based interrupts have their own request to the INTC. Please
  329. * consult your Alchemy databook for more information!
  330. *
  331. * NOTE: On the Au1550, GPIOs 201-205 also have a shared interrupt request
  332. * line to the INTC, GPIO201_205. This function can be used for those
  333. * as well.
  334. *
  335. * NOTE: 'gpio2' parameter must be in range of the GPIO2 numberspace
  336. * (200-215 by default). No sanity checks are made,
  337. */
  338. static inline void alchemy_gpio2_enable_int(int gpio2)
  339. {
  340. unsigned long flags;
  341. gpio2 -= ALCHEMY_GPIO2_BASE;
  342. /* Au1100/Au1500 have GPIO208-215 enable bits at 0..7 */
  343. switch (alchemy_get_cputype()) {
  344. case ALCHEMY_CPU_AU1100:
  345. case ALCHEMY_CPU_AU1500:
  346. gpio2 -= 8;
  347. }
  348. local_irq_save(flags);
  349. __alchemy_gpio2_mod_int(gpio2, 1);
  350. local_irq_restore(flags);
  351. }
  352. /**
  353. * alchemy_gpio2_disable_int - Disable a GPIO2 pins' shared irq contribution.
  354. * @gpio2: The GPIO2 pin to activate (200...215).
  355. *
  356. * see function alchemy_gpio2_enable_int() for more information.
  357. */
  358. static inline void alchemy_gpio2_disable_int(int gpio2)
  359. {
  360. unsigned long flags;
  361. gpio2 -= ALCHEMY_GPIO2_BASE;
  362. /* Au1100/Au1500 have GPIO208-215 enable bits at 0..7 */
  363. switch (alchemy_get_cputype()) {
  364. case ALCHEMY_CPU_AU1100:
  365. case ALCHEMY_CPU_AU1500:
  366. gpio2 -= 8;
  367. }
  368. local_irq_save(flags);
  369. __alchemy_gpio2_mod_int(gpio2, 0);
  370. local_irq_restore(flags);
  371. }
  372. /**
  373. * alchemy_gpio2_enable - Activate GPIO2 block.
  374. *
  375. * The GPIO2 block must be enabled excplicitly to work. On systems
  376. * where this isn't done by the bootloader, this macro can be used.
  377. */
  378. static inline void alchemy_gpio2_enable(void)
  379. {
  380. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
  381. __raw_writel(3, base + GPIO2_ENABLE); /* reset, clock enabled */
  382. wmb();
  383. __raw_writel(1, base + GPIO2_ENABLE); /* clock enabled */
  384. wmb();
  385. }
  386. /**
  387. * alchemy_gpio2_disable - disable GPIO2 block.
  388. *
  389. * Disable and put GPIO2 block in low-power mode.
  390. */
  391. static inline void alchemy_gpio2_disable(void)
  392. {
  393. void __iomem *base = (void __iomem *)KSEG1ADDR(AU1500_GPIO2_PHYS_ADDR);
  394. __raw_writel(2, base + GPIO2_ENABLE); /* reset, clock disabled */
  395. wmb();
  396. }
  397. /**********************************************************************/
  398. /* wrappers for on-chip gpios; can be used before gpio chips have been
  399. * registered with gpiolib.
  400. */
  401. static inline int alchemy_gpio_direction_input(int gpio)
  402. {
  403. return (gpio >= ALCHEMY_GPIO2_BASE) ?
  404. alchemy_gpio2_direction_input(gpio) :
  405. alchemy_gpio1_direction_input(gpio);
  406. }
  407. static inline int alchemy_gpio_direction_output(int gpio, int v)
  408. {
  409. return (gpio >= ALCHEMY_GPIO2_BASE) ?
  410. alchemy_gpio2_direction_output(gpio, v) :
  411. alchemy_gpio1_direction_output(gpio, v);
  412. }
  413. static inline int alchemy_gpio_get_value(int gpio)
  414. {
  415. return (gpio >= ALCHEMY_GPIO2_BASE) ?
  416. alchemy_gpio2_get_value(gpio) :
  417. alchemy_gpio1_get_value(gpio);
  418. }
  419. static inline void alchemy_gpio_set_value(int gpio, int v)
  420. {
  421. if (gpio >= ALCHEMY_GPIO2_BASE)
  422. alchemy_gpio2_set_value(gpio, v);
  423. else
  424. alchemy_gpio1_set_value(gpio, v);
  425. }
  426. static inline int alchemy_gpio_is_valid(int gpio)
  427. {
  428. return (gpio >= ALCHEMY_GPIO2_BASE) ?
  429. alchemy_gpio2_is_valid(gpio) :
  430. alchemy_gpio1_is_valid(gpio);
  431. }
  432. static inline int alchemy_gpio_cansleep(int gpio)
  433. {
  434. return 0; /* Alchemy never gets tired */
  435. }
  436. static inline int alchemy_gpio_to_irq(int gpio)
  437. {
  438. return (gpio >= ALCHEMY_GPIO2_BASE) ?
  439. alchemy_gpio2_to_irq(gpio) :
  440. alchemy_gpio1_to_irq(gpio);
  441. }
  442. static inline int alchemy_irq_to_gpio(int irq)
  443. {
  444. switch (alchemy_get_cputype()) {
  445. case ALCHEMY_CPU_AU1000:
  446. return au1000_irq_to_gpio(irq);
  447. case ALCHEMY_CPU_AU1100:
  448. return au1100_irq_to_gpio(irq);
  449. case ALCHEMY_CPU_AU1500:
  450. return au1500_irq_to_gpio(irq);
  451. case ALCHEMY_CPU_AU1550:
  452. return au1550_irq_to_gpio(irq);
  453. case ALCHEMY_CPU_AU1200:
  454. return au1200_irq_to_gpio(irq);
  455. }
  456. return -ENXIO;
  457. }
  458. /**********************************************************************/
  459. /* Linux gpio framework integration.
  460. *
  461. * 4 use cases of Au1000-Au1200 GPIOS:
  462. *(1) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=y:
  463. * Board must register gpiochips.
  464. *(2) GPIOLIB=y, ALCHEMY_GPIO_INDIRECT=n:
  465. * 2 (1 for Au1000) gpio_chips are registered.
  466. *
  467. *(3) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=y:
  468. * the boards' gpio.h must provide the linux gpio wrapper functions,
  469. *
  470. *(4) GPIOLIB=n, ALCHEMY_GPIO_INDIRECT=n:
  471. * inlinable gpio functions are provided which enable access to the
  472. * Au1000 gpios only by using the numbers straight out of the data-
  473. * sheets.
  474. * Cases 1 and 3 are intended for boards which want to provide their own
  475. * GPIO namespace and -operations (i.e. for example you have 8 GPIOs
  476. * which are in part provided by spare Au1000 GPIO pins and in part by
  477. * an external FPGA but you still want them to be accssible in linux
  478. * as gpio0-7. The board can of course use the alchemy_gpioX_* functions
  479. * as required).
  480. */
  481. #ifndef CONFIG_GPIOLIB
  482. #ifndef CONFIG_ALCHEMY_GPIO_INDIRECT /* case (4) */
  483. static inline int gpio_direction_input(int gpio)
  484. {
  485. return alchemy_gpio_direction_input(gpio);
  486. }
  487. static inline int gpio_direction_output(int gpio, int v)
  488. {
  489. return alchemy_gpio_direction_output(gpio, v);
  490. }
  491. static inline int gpio_get_value(int gpio)
  492. {
  493. return alchemy_gpio_get_value(gpio);
  494. }
  495. static inline void gpio_set_value(int gpio, int v)
  496. {
  497. alchemy_gpio_set_value(gpio, v);
  498. }
  499. static inline int gpio_get_value_cansleep(unsigned gpio)
  500. {
  501. return gpio_get_value(gpio);
  502. }
  503. static inline void gpio_set_value_cansleep(unsigned gpio, int value)
  504. {
  505. gpio_set_value(gpio, value);
  506. }
  507. static inline int gpio_is_valid(int gpio)
  508. {
  509. return alchemy_gpio_is_valid(gpio);
  510. }
  511. static inline int gpio_cansleep(int gpio)
  512. {
  513. return alchemy_gpio_cansleep(gpio);
  514. }
  515. static inline int gpio_to_irq(int gpio)
  516. {
  517. return alchemy_gpio_to_irq(gpio);
  518. }
  519. static inline int irq_to_gpio(int irq)
  520. {
  521. return alchemy_irq_to_gpio(irq);
  522. }
  523. static inline int gpio_request(unsigned gpio, const char *label)
  524. {
  525. return 0;
  526. }
  527. static inline int gpio_request_one(unsigned gpio,
  528. unsigned long flags, const char *label)
  529. {
  530. return 0;
  531. }
  532. static inline int gpio_request_array(struct gpio *array, size_t num)
  533. {
  534. return 0;
  535. }
  536. static inline void gpio_free(unsigned gpio)
  537. {
  538. }
  539. static inline void gpio_free_array(struct gpio *array, size_t num)
  540. {
  541. }
  542. static inline int gpio_set_debounce(unsigned gpio, unsigned debounce)
  543. {
  544. return -ENOSYS;
  545. }
  546. static inline int gpio_export(unsigned gpio, bool direction_may_change)
  547. {
  548. return -ENOSYS;
  549. }
  550. static inline int gpio_export_link(struct device *dev, const char *name,
  551. unsigned gpio)
  552. {
  553. return -ENOSYS;
  554. }
  555. static inline int gpio_sysfs_set_active_low(unsigned gpio, int value)
  556. {
  557. return -ENOSYS;
  558. }
  559. static inline void gpio_unexport(unsigned gpio)
  560. {
  561. }
  562. #endif /* !CONFIG_ALCHEMY_GPIO_INDIRECT */
  563. #else /* CONFIG GPIOLIB */
  564. /* using gpiolib to provide up to 2 gpio_chips for on-chip gpios */
  565. #ifndef CONFIG_ALCHEMY_GPIO_INDIRECT /* case (2) */
  566. /* get everything through gpiolib */
  567. #define gpio_to_irq __gpio_to_irq
  568. #define gpio_get_value __gpio_get_value
  569. #define gpio_set_value __gpio_set_value
  570. #define gpio_cansleep __gpio_cansleep
  571. #define irq_to_gpio alchemy_irq_to_gpio
  572. #include <asm-generic/gpio.h>
  573. #endif /* !CONFIG_ALCHEMY_GPIO_INDIRECT */
  574. #endif /* !CONFIG_GPIOLIB */
  575. #endif /* _ALCHEMY_GPIO_AU1000_H_ */