1 /* $NetBSD: gpio.h,v 1.7 2009/09/25 20:27:50 mbalmer Exp $ */ 2 /* $OpenBSD: gpio.h,v 1.7 2008/11/26 14:51:20 mbalmer Exp $ */ 3 /* 4 * Copyright (c) 2009 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 /* GPIO pin states */ 24 #define GPIO_PIN_LOW 0x00 /* low level (logical 0) */ 25 #define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */ 26 27 /* Max name length of a pin */ 28 #define GPIOMAXNAME 64 29 30 /* GPIO pin configuration flags */ 31 #define GPIO_PIN_INPUT 0x0001 /* input direction */ 32 #define GPIO_PIN_OUTPUT 0x0002 /* output direction */ 33 #define GPIO_PIN_INOUT 0x0004 /* bi-directional */ 34 #define GPIO_PIN_OPENDRAIN 0x0008 /* open-drain output */ 35 #define GPIO_PIN_PUSHPULL 0x0010 /* push-pull output */ 36 #define GPIO_PIN_TRISTATE 0x0020 /* output disabled */ 37 #define GPIO_PIN_PULLUP 0x0040 /* internal pull-up enabled */ 38 #define GPIO_PIN_PULLDOWN 0x0080 /* internal pull-down enabled */ 39 #define GPIO_PIN_INVIN 0x0100 /* invert input */ 40 #define GPIO_PIN_INVOUT 0x0200 /* invert output */ 41 #define GPIO_PIN_USER 0x0400 /* user != 0 can access */ 42 #define GPIO_PIN_PULSATE 0x0800 /* pulsate in hardware */ 43 #define GPIO_PIN_SET 0x8000 /* set for securelevel access */ 44 45 /* GPIO controller description */ 46 struct gpio_info { 47 int gpio_npins; /* total number of pins available */ 48 }; 49 50 /* GPIO pin request (read/write/toggle) */ 51 struct gpio_req { 52 char gp_name[GPIOMAXNAME]; /* pin name */ 53 int gp_pin; /* pin number */ 54 int gp_value; /* value */ 55 }; 56 57 /* GPIO pin configuration */ 58 struct gpio_set { 59 char gp_name[GPIOMAXNAME]; 60 int gp_pin; 61 int gp_caps; 62 int gp_flags; 63 char gp_name2[GPIOMAXNAME]; /* new name */ 64 }; 65 66 /* Attach/detach device drivers that use GPIO pins */ 67 struct gpio_attach { 68 char ga_dvname[16]; /* device name */ 69 int ga_offset; /* pin number */ 70 u_int32_t ga_mask; /* binary mask */ 71 }; 72 73 /* GPIO pin control (old API) */ 74 struct gpio_pin_ctl { 75 int gp_pin; /* pin number */ 76 int gp_caps; /* pin capabilities (read-only) */ 77 int gp_flags; /* pin configuration flags */ 78 }; 79 80 /* GPIO pin operation (read/write/toggle) (old API) */ 81 struct gpio_pin_op { 82 int gp_pin; /* pin number */ 83 int gp_value; /* value */ 84 }; 85 86 #define GPIOINFO _IOR('G', 0, struct gpio_info) 87 88 /* the old API, kept for backwards compatibility */ 89 #define GPIOPINREAD _IOWR('G', 1, struct gpio_pin_op) 90 #define GPIOPINWRITE _IOWR('G', 2, struct gpio_pin_op) 91 #define GPIOPINTOGGLE _IOWR('G', 3, struct gpio_pin_op) 92 #define GPIOPINCTL _IOWR('G', 4, struct gpio_pin_ctl) 93 94 /* the new API */ 95 #define GPIOSET _IOWR('G', 5, struct gpio_set) 96 #define GPIOUNSET _IOWR('G', 6, struct gpio_set) 97 #define GPIOREAD _IOWR('G', 7, struct gpio_req) 98 #define GPIOWRITE _IOWR('G', 8, struct gpio_req) 99 #define GPIOTOGGLE _IOWR('G', 9, struct gpio_req) 100 #define GPIOATTACH _IOWR('G', 10, struct gpio_attach) 101 #define GPIODETACH _IOWR('G', 11, struct gpio_attach) 102 103 #endif /* !_SYS_GPIO_H_ */ 104