of_gpio.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * OF helpers for the GPIO API
  3. *
  4. * Copyright (c) 2007-2008 MontaVista Software, Inc.
  5. *
  6. * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #ifndef __LINUX_OF_GPIO_H
  14. #define __LINUX_OF_GPIO_H
  15. #include <linux/compiler.h>
  16. #include <linux/kernel.h>
  17. #include <linux/errno.h>
  18. #include <linux/gpio.h>
  19. struct device_node;
  20. /*
  21. * This is Linux-specific flags. By default controllers' and Linux' mapping
  22. * match, but GPIO controllers are free to translate their own flags to
  23. * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended.
  24. */
  25. enum of_gpio_flags {
  26. OF_GPIO_ACTIVE_LOW = 0x1,
  27. };
  28. #ifdef CONFIG_OF_GPIO
  29. /*
  30. * OF GPIO chip for memory mapped banks
  31. */
  32. struct of_mm_gpio_chip {
  33. struct gpio_chip gc;
  34. void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
  35. void __iomem *regs;
  36. };
  37. static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
  38. {
  39. return container_of(gc, struct of_mm_gpio_chip, gc);
  40. }
  41. extern int of_get_gpio_flags(struct device_node *np, int index,
  42. enum of_gpio_flags *flags);
  43. extern unsigned int of_gpio_count(struct device_node *np);
  44. extern int of_mm_gpiochip_add(struct device_node *np,
  45. struct of_mm_gpio_chip *mm_gc);
  46. extern int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np,
  47. const void *gpio_spec, u32 *flags);
  48. #else /* CONFIG_OF_GPIO */
  49. /* Drivers may not strictly depend on the GPIO support, so let them link. */
  50. static inline int of_get_gpio_flags(struct device_node *np, int index,
  51. enum of_gpio_flags *flags)
  52. {
  53. return -ENOSYS;
  54. }
  55. static inline unsigned int of_gpio_count(struct device_node *np)
  56. {
  57. return 0;
  58. }
  59. #endif /* CONFIG_OF_GPIO */
  60. /**
  61. * of_get_gpio - Get a GPIO number to use with GPIO API
  62. * @np: device node to get GPIO from
  63. * @index: index of the GPIO
  64. *
  65. * Returns GPIO number to use with Linux generic GPIO API, or one of the errno
  66. * value on the error condition.
  67. */
  68. static inline int of_get_gpio(struct device_node *np, int index)
  69. {
  70. return of_get_gpio_flags(np, index, NULL);
  71. }
  72. #endif /* __LINUX_OF_GPIO_H */