]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/sys/gpio.h
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / sys / gpio.h
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, Oleksandr Tymoshenko <gonzo@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  *
31  */
32
33 /*
34  * Copyright (c) 2009 Marc Balmer <marc@msys.ch>
35  * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
36  *
37  * Permission to use, copy, modify, and distribute this software for any
38  * purpose with or without fee is hereby granted, provided that the above
39  * copyright notice and this permission notice appear in all copies.
40  *
41  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
42  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
43  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
44  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
45  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
46  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
47  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
48  */
49
50 #ifndef __GPIO_H__
51 #define __GPIO_H__
52
53 #include <sys/ioccom.h>
54
55 /* GPIO pin states */
56 #define GPIO_PIN_LOW            0x00    /* low level (logical 0) */
57 #define GPIO_PIN_HIGH           0x01    /* high level (logical 1) */
58
59 /* Max name length of a pin */
60 #define GPIOMAXNAME             64
61
62 /* GPIO pin configuration flags */
63 #define GPIO_PIN_INPUT          0x0001  /* input direction */
64 #define GPIO_PIN_OUTPUT         0x0002  /* output direction */
65 #define GPIO_PIN_OPENDRAIN      0x0004  /* open-drain output */
66 #define GPIO_PIN_PUSHPULL       0x0008  /* push-pull output */
67 #define GPIO_PIN_TRISTATE       0x0010  /* output disabled */
68 #define GPIO_PIN_PULLUP         0x0020  /* internal pull-up enabled */
69 #define GPIO_PIN_PULLDOWN       0x0040  /* internal pull-down enabled */
70 #define GPIO_PIN_INVIN          0x0080  /* invert input */
71 #define GPIO_PIN_INVOUT         0x0100  /* invert output */
72 #define GPIO_PIN_PULSATE        0x0200  /* pulsate in hardware */
73
74 struct gpio_pin {
75         uint32_t gp_pin;                        /* pin number */
76         char gp_name[GPIOMAXNAME];              /* human-readable name */
77         uint32_t gp_caps;                       /* capabilities */
78         uint32_t gp_flags;                      /* current flags */
79 };
80
81 /* GPIO pin request (read/write/toggle) */
82 struct gpio_req {
83         uint32_t gp_pin;                        /* pin number */
84         uint32_t gp_value;                      /* value */
85 };
86
87 /*
88  * ioctls
89  */
90 #define GPIOMAXPIN              _IOR('G', 0, int)
91 #define GPIOGETCONFIG           _IOWR('G', 1, struct gpio_pin)
92 #define GPIOSETCONFIG           _IOW('G', 2, struct gpio_pin)
93 #define GPIOGET                 _IOWR('G', 3, struct gpio_req)
94 #define GPIOSET                 _IOW('G', 4, struct gpio_req)
95 #define GPIOTOGGLE              _IOWR('G', 5, struct gpio_req)
96
97 #endif /* __GPIO_H__ */