| 1 | /* $NetBSD: gpio.h,v 1.15 2015/11/21 09:06:03 mlelstv Exp $ */ |
| 2 | /* $OpenBSD: gpio.h,v 1.7 2008/11/26 14:51:20 mbalmer Exp $ */ |
| 3 | /* |
| 4 | * Copyright (c) 2009, 2011 Marc Balmer <marc@msys.ch> |
| 5 | * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> |
| 6 | * |
| 7 | * Permission to use, copy, modify, and distribute this software for any |
| 8 | * purpose with or without fee is hereby granted, provided that the above |
| 9 | * copyright notice and this permission notice appear in all copies. |
| 10 | * |
| 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 12 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 13 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 14 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 16 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 | */ |
| 19 | |
| 20 | #ifndef _SYS_GPIO_H_ |
| 21 | #define _SYS_GPIO_H_ |
| 22 | |
| 23 | #include <sys/ioccom.h> |
| 24 | #include <sys/time.h> |
| 25 | |
| 26 | /* GPIO pin states */ |
| 27 | #define GPIO_PIN_LOW 0x00 /* low level (logical 0) */ |
| 28 | #define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */ |
| 29 | |
| 30 | /* Max name length of a pin */ |
| 31 | #define GPIOMAXNAME 64 |
| 32 | |
| 33 | /* GPIO pin configuration flags */ |
| 34 | #define GPIO_PIN_INPUT 0x00000001 /* input direction */ |
| 35 | #define GPIO_PIN_OUTPUT 0x00000002 /* output direction */ |
| 36 | #define GPIO_PIN_INOUT 0x00000004 /* bi-directional */ |
| 37 | #define GPIO_PIN_OPENDRAIN 0x00000008 /* open-drain output */ |
| 38 | #define GPIO_PIN_PUSHPULL 0x00000010 /* push-pull output */ |
| 39 | #define GPIO_PIN_TRISTATE 0x00000020 /* output disabled */ |
| 40 | #define GPIO_PIN_PULLUP 0x00000040 /* internal pull-up enabled */ |
| 41 | #define GPIO_PIN_PULLDOWN 0x00000080 /* internal pull-down enabled */ |
| 42 | #define GPIO_PIN_INVIN 0x00000100 /* invert input */ |
| 43 | #define GPIO_PIN_INVOUT 0x00000200 /* invert output */ |
| 44 | #define GPIO_PIN_USER 0x00000400 /* user != 0 can access */ |
| 45 | #define GPIO_PIN_PULSATE 0x00000800 /* pulsate in hardware */ |
| 46 | #define GPIO_PIN_SET 0x00008000 /* set for securelevel access */ |
| 47 | #define GPIO_PIN_ALT0 0x00010000 /* alternate function 0 */ |
| 48 | #define GPIO_PIN_ALT1 0x00020000 /* alternate function 1 */ |
| 49 | #define GPIO_PIN_ALT2 0x00040000 /* alternate function 2 */ |
| 50 | #define GPIO_PIN_ALT3 0x00080000 /* alternate function 3 */ |
| 51 | #define GPIO_PIN_ALT4 0x00100000 /* alternate function 4 */ |
| 52 | #define GPIO_PIN_ALT5 0x00200000 /* alternate function 5 */ |
| 53 | #define GPIO_PIN_ALT6 0x00400000 /* alternate function 6 */ |
| 54 | #define GPIO_PIN_ALT7 0x00800000 /* alternate function 7 */ |
| 55 | #define GPIO_PIN_EVENTS 0x10000000 /* deliver events */ |
| 56 | #define GPIO_PIN_LEVEL 0x20000000 /* interrupt on level/edge */ |
| 57 | #define GPIO_PIN_FALLING 0x40000000 /* interrupt on falling/rising */ |
| 58 | |
| 59 | /* GPIO controller description */ |
| 60 | struct gpio_info { |
| 61 | int gpio_npins; /* total number of pins available */ |
| 62 | }; |
| 63 | |
| 64 | /* GPIO pin request (read/write/toggle) */ |
| 65 | struct gpio_req { |
| 66 | char gp_name[GPIOMAXNAME]; /* pin name */ |
| 67 | int gp_pin; /* pin number */ |
| 68 | int gp_value; /* value */ |
| 69 | }; |
| 70 | |
| 71 | /* GPIO pin configuration */ |
| 72 | struct gpio_set { |
| 73 | char gp_name[GPIOMAXNAME]; |
| 74 | int gp_pin; |
| 75 | int gp_caps; |
| 76 | int gp_flags; |
| 77 | char gp_name2[GPIOMAXNAME]; /* new name */ |
| 78 | }; |
| 79 | |
| 80 | /* Attach device drivers that use GPIO pins */ |
| 81 | struct gpio_attach { |
| 82 | char ga_dvname[16]; /* device name */ |
| 83 | int ga_offset; /* pin number */ |
| 84 | uint32_t ga_mask; /* binary mask */ |
| 85 | uint32_t ga_flags; /* driver dependent flags */ |
| 86 | }; |
| 87 | |
| 88 | /* gpio(4) API */ |
| 89 | #define GPIOINFO _IOR('G', 0, struct gpio_info) |
| 90 | #define GPIOSET _IOWR('G', 5, struct gpio_set) |
| 91 | #define GPIOUNSET _IOWR('G', 6, struct gpio_set) |
| 92 | #define GPIOREAD _IOWR('G', 7, struct gpio_req) |
| 93 | #define GPIOWRITE _IOWR('G', 8, struct gpio_req) |
| 94 | #define GPIOTOGGLE _IOWR('G', 9, struct gpio_req) |
| 95 | #define GPIOATTACH _IOWR('G', 10, struct gpio_attach) |
| 96 | |
| 97 | #ifdef COMPAT_50 |
| 98 | /* Old structure to attach/detach devices */ |
| 99 | struct gpio_attach50 { |
| 100 | char ga_dvname[16]; /* device name */ |
| 101 | int ga_offset; /* pin number */ |
| 102 | uint32_t ga_mask; /* binary mask */ |
| 103 | }; |
| 104 | |
| 105 | /* GPIO pin control (old API) */ |
| 106 | struct gpio_pin_ctl { |
| 107 | int gp_pin; /* pin number */ |
| 108 | int gp_caps; /* pin capabilities (read-only) */ |
| 109 | int gp_flags; /* pin configuration flags */ |
| 110 | }; |
| 111 | |
| 112 | /* GPIO pin operation (read/write/toggle) (old API) */ |
| 113 | struct gpio_pin_op { |
| 114 | int gp_pin; /* pin number */ |
| 115 | int gp_value; /* value */ |
| 116 | }; |
| 117 | |
| 118 | /* the old API */ |
| 119 | #define GPIOPINREAD _IOWR('G', 1, struct gpio_pin_op) |
| 120 | #define GPIOPINWRITE _IOWR('G', 2, struct gpio_pin_op) |
| 121 | #define GPIOPINTOGGLE _IOWR('G', 3, struct gpio_pin_op) |
| 122 | #define GPIOPINCTL _IOWR('G', 4, struct gpio_pin_ctl) |
| 123 | #define GPIOATTACH50 _IOWR('G', 10, struct gpio_attach50) |
| 124 | #define GPIODETACH50 _IOWR('G', 11, struct gpio_attach50) |
| 125 | #define GPIODETACH _IOWR('G', 11, struct gpio_attach) |
| 126 | #endif /* COMPAT_50 */ |
| 127 | |
| 128 | #endif /* !_SYS_GPIO_H_ */ |
| 129 | |