gpio.h 2.3 KB

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