gpio.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2011 The Chromium OS Authors.
  3. * Copyright (c) 2011, NVIDIA Corp. All rights reserved.
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #ifndef _ASM_GENERIC_GPIO_H_
  23. #define _ASM_GENERIC_GPIO_H_
  24. /*
  25. * Generic GPIO API for U-Boot
  26. *
  27. * GPIOs are numbered from 0 to GPIO_COUNT-1 which value is defined
  28. * by the SOC/architecture.
  29. *
  30. * Each GPIO can be an input or output. If an input then its value can
  31. * be read as 0 or 1. If an output then its value can be set to 0 or 1.
  32. * If you try to write an input then the value is undefined. If you try
  33. * to read an output, barring something very unusual, you will get
  34. * back the value of the output that you previously set.
  35. *
  36. * In some cases the operation may fail, for example if the GPIO number
  37. * is out of range, or the GPIO is not available because its pin is
  38. * being used by another function. In that case, functions may return
  39. * an error value of -1.
  40. */
  41. /**
  42. * Request a gpio. This should be called before any of the other functions
  43. * are used on this gpio.
  44. *
  45. * @param gp GPIO number
  46. * @param label User label for this GPIO
  47. * @return 0 if ok, -1 on error
  48. */
  49. int gpio_request(unsigned gpio, const char *label);
  50. /**
  51. * Stop using the GPIO. This function should not alter pin configuration.
  52. *
  53. * @param gpio GPIO number
  54. * @return 0 if ok, -1 on error
  55. */
  56. int gpio_free(unsigned gpio);
  57. /**
  58. * Make a GPIO an input.
  59. *
  60. * @param gpio GPIO number
  61. * @return 0 if ok, -1 on error
  62. */
  63. int gpio_direction_input(unsigned gpio);
  64. /**
  65. * Make a GPIO an output, and set its value.
  66. *
  67. * @param gpio GPIO number
  68. * @param value GPIO value (0 for low or 1 for high)
  69. * @return 0 if ok, -1 on error
  70. */
  71. int gpio_direction_output(unsigned gpio, int value);
  72. /**
  73. * Get a GPIO's value. This will work whether the GPIO is an input
  74. * or an output.
  75. *
  76. * @param gpio GPIO number
  77. * @return 0 if low, 1 if high, -1 on error
  78. */
  79. int gpio_get_value(unsigned gpio);
  80. /**
  81. * Set an output GPIO's value. The GPIO must already be an output or
  82. * this function may have no effect.
  83. *
  84. * @param gpio GPIO number
  85. * @param value GPIO value (0 for low or 1 for high)
  86. * @return 0 if ok, -1 on error
  87. */
  88. int gpio_set_value(unsigned gpio, int value);
  89. #endif /* _ASM_GENERIC_GPIO_H_ */