1285431Szbb/* $NetBSD: gpio.h,v 1.7 2009/09/25 20:27:50 mbalmer Exp $ */ 2285431Szbb/* $OpenBSD: gpio.h,v 1.7 2008/11/26 14:51:20 mbalmer Exp $ */ 3285431Szbb/*- 4285431Szbb * Copyright (c) 2009, Oleksandr Tymoshenko <gonzo@FreeBSD.org> 5285431Szbb * All rights reserved. 6285431Szbb * 7285431Szbb * Redistribution and use in source and binary forms, with or without 8285431Szbb * modification, are permitted provided that the following conditions 9285431Szbb * are met: 10285431Szbb * 1. Redistributions of source code must retain the above copyright 11285431Szbb * notice unmodified, this list of conditions, and the following 12285431Szbb * disclaimer. 13285431Szbb * 2. Redistributions in binary form must reproduce the above copyright 14285431Szbb * notice, this list of conditions and the following disclaimer in the 15285431Szbb * documentation and/or other materials provided with the distribution. 16285431Szbb * 17285431Szbb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18285431Szbb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19285431Szbb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20285431Szbb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21285431Szbb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22285431Szbb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23285431Szbb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24285431Szbb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25285431Szbb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26285431Szbb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27285431Szbb * SUCH DAMAGE. 28285431Szbb * 29285431Szbb * $FreeBSD$ 30285431Szbb * 31285431Szbb */ 32285431Szbb 33285431Szbb/* 34285431Szbb * Copyright (c) 2009 Marc Balmer <marc@msys.ch> 35285431Szbb * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org> 36285431Szbb * 37285431Szbb * Permission to use, copy, modify, and distribute this software for any 38285431Szbb * purpose with or without fee is hereby granted, provided that the above 39285431Szbb * copyright notice and this permission notice appear in all copies. 40285431Szbb * 41285431Szbb * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 42285431Szbb * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 43285431Szbb * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 44285431Szbb * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 45285431Szbb * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 46285431Szbb * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 47285431Szbb * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 48285431Szbb */ 49285431Szbb 50285431Szbb#ifndef __GPIO_H__ 51285431Szbb#define __GPIO_H__ 52285431Szbb 53285431Szbb#include <sys/ioccom.h> 54285431Szbb 55285431Szbb/* GPIO pin states */ 56285431Szbb#define GPIO_PIN_LOW 0x00 /* low level (logical 0) */ 57285431Szbb#define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */ 58285431Szbb 59285431Szbb/* Max name length of a pin */ 60285431Szbb#define GPIOMAXNAME 64 61285431Szbb 62285431Szbb/* GPIO pin configuration flags */ 63285431Szbb#define GPIO_PIN_INPUT 0x0001 /* input direction */ 64285431Szbb#define GPIO_PIN_OUTPUT 0x0002 /* output direction */ 65285431Szbb#define GPIO_PIN_OPENDRAIN 0x0004 /* open-drain output */ 66285431Szbb#define GPIO_PIN_PUSHPULL 0x0008 /* push-pull output */ 67285431Szbb#define GPIO_PIN_TRISTATE 0x0010 /* output disabled */ 68285431Szbb#define GPIO_PIN_PULLUP 0x0020 /* internal pull-up enabled */ 69285431Szbb#define GPIO_PIN_PULLDOWN 0x0040 /* internal pull-down enabled */ 70285431Szbb#define GPIO_PIN_INVIN 0x0080 /* invert input */ 71285431Szbb#define GPIO_PIN_INVOUT 0x0100 /* invert output */ 72285431Szbb#define GPIO_PIN_PULSATE 0x0200 /* pulsate in hardware */ 73285431Szbb 74285431Szbbstruct gpio_pin { 75285431Szbb uint32_t gp_pin; /* pin number */ 76285431Szbb char gp_name[GPIOMAXNAME]; /* human-readable name */ 77285431Szbb uint32_t gp_caps; /* capabilities */ 78285431Szbb uint32_t gp_flags; /* current flags */ 79285431Szbb}; 80285431Szbb 81285431Szbb/* GPIO pin request (read/write/toggle) */ 82285431Szbbstruct gpio_req { 83285431Szbb uint32_t gp_pin; /* pin number */ 84285431Szbb uint32_t gp_value; /* value */ 85285431Szbb}; 86285431Szbb 87285431Szbb/* 88285431Szbb * ioctls 89285431Szbb */ 90285431Szbb#define GPIOMAXPIN _IOR('G', 0, int) 91285431Szbb#define GPIOGETCONFIG _IOWR('G', 1, struct gpio_pin) 92285431Szbb#define GPIOSETCONFIG _IOW('G', 2, struct gpio_pin) 93285431Szbb#define GPIOGET _IOWR('G', 3, struct gpio_req) 94285431Szbb#define GPIOSET _IOW('G', 4, struct gpio_req) 95285431Szbb#define GPIOTOGGLE _IOWR('G', 5, struct gpio_req) 96285431Szbb 97285431Szbb#endif /* __GPIO_H__ */ 98285431Szbb