gpio.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* $OpenBSD: gpio.h,v 1.8 2011/10/03 20:24:51 matthieu Exp $ */
  2. /*
  3. * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #ifndef _SYS_GPIO_H_
  18. #define _SYS_GPIO_H_
  19. /* GPIO pin states */
  20. #define GPIO_PIN_LOW 0x00 /* low level (logical 0) */
  21. #define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */
  22. /* Max name length of a pin */
  23. #define GPIOPINMAXNAME 64
  24. /* GPIO pin configuration flags */
  25. #define GPIO_PIN_INPUT 0x0001 /* input direction */
  26. #define GPIO_PIN_OUTPUT 0x0002 /* output direction */
  27. #define GPIO_PIN_INOUT 0x0004 /* bi-directional */
  28. #define GPIO_PIN_OPENDRAIN 0x0008 /* open-drain output */
  29. #define GPIO_PIN_PUSHPULL 0x0010 /* push-pull output */
  30. #define GPIO_PIN_TRISTATE 0x0020 /* output disabled */
  31. #define GPIO_PIN_PULLUP 0x0040 /* internal pull-up enabled */
  32. #define GPIO_PIN_PULLDOWN 0x0080 /* internal pull-down enabled */
  33. #define GPIO_PIN_INVIN 0x0100 /* invert input */
  34. #define GPIO_PIN_INVOUT 0x0200 /* invert output */
  35. #define GPIO_PIN_USER 0x0400 /* user != 0 can access */
  36. #define GPIO_PIN_SET 0x8000 /* set for securelevel access */
  37. /* GPIO controller description */
  38. struct gpio_info {
  39. int gpio_npins; /* total number of pins available */
  40. };
  41. /* GPIO pin operation (read/write/toggle) */
  42. struct gpio_pin_op {
  43. char gp_name[GPIOPINMAXNAME]; /* pin name */
  44. int gp_pin; /* pin number */
  45. int gp_value; /* value */
  46. };
  47. /* GPIO pin configuration */
  48. struct gpio_pin_set {
  49. char gp_name[GPIOPINMAXNAME];
  50. int gp_pin;
  51. int gp_caps;
  52. int gp_flags;
  53. char gp_name2[GPIOPINMAXNAME]; /* new name */
  54. };
  55. /* Attach/detach device drivers that use GPIO pins */
  56. struct gpio_attach {
  57. char ga_dvname[16]; /* device name */
  58. int ga_offset; /* pin number */
  59. u_int32_t ga_mask; /* binary mask */
  60. u_int32_t ga_flags; /* flags */
  61. };
  62. #define GPIOINFO _IOR('G', 0, struct gpio_info)
  63. #define GPIOPINREAD _IOWR('G', 1, struct gpio_pin_op)
  64. #define GPIOPINWRITE _IOWR('G', 2, struct gpio_pin_op)
  65. #define GPIOPINTOGGLE _IOWR('G', 3, struct gpio_pin_op)
  66. #define GPIOPINSET _IOWR('G', 4, struct gpio_pin_set)
  67. #define GPIOPINUNSET _IOWR('G', 5, struct gpio_pin_set)
  68. #define GPIOATTACH _IOWR('G', 6, struct gpio_attach)
  69. #define GPIODETACH _IOWR('G', 7, struct gpio_attach)
  70. #endif /* !_SYS_GPIO_H_ */