Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / sys / gpio.h @ 13

History | View | Annotate | Download (3.98 KB)

1
/* $NetBSD: gpio.h,v 1.14 2015/09/06 06:01:02 dholland 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                0x0001        /* input direction */
35
#define GPIO_PIN_OUTPUT                0x0002        /* output direction */
36
#define GPIO_PIN_INOUT                0x0004        /* bi-directional */
37
#define GPIO_PIN_OPENDRAIN        0x0008        /* open-drain output */
38
#define GPIO_PIN_PUSHPULL        0x0010        /* push-pull output */
39
#define GPIO_PIN_TRISTATE        0x0020        /* output disabled */
40
#define GPIO_PIN_PULLUP                0x0040        /* internal pull-up enabled */
41
#define GPIO_PIN_PULLDOWN        0x0080        /* internal pull-down enabled */
42
#define GPIO_PIN_INVIN                0x0100        /* invert input */
43
#define GPIO_PIN_INVOUT                0x0200        /* invert output */
44
#define GPIO_PIN_USER                0x0400        /* user != 0 can access */
45
#define GPIO_PIN_PULSATE        0x0800        /* pulsate in hardware */
46
#define GPIO_PIN_SET                0x8000        /* set for securelevel access */
47

    
48
/* GPIO controller description */
49
struct gpio_info {
50
        int gpio_npins;                /* total number of pins available */
51
};
52

    
53
/* GPIO pin request (read/write/toggle) */
54
struct gpio_req {
55
        char                gp_name[GPIOMAXNAME];        /* pin name */
56
        int                gp_pin;                        /* pin number */
57
        int                gp_value;                /* value */
58
};
59

    
60
/* GPIO pin configuration */
61
struct gpio_set {
62
        char        gp_name[GPIOMAXNAME];
63
        int        gp_pin;
64
        int        gp_caps;
65
        int        gp_flags;
66
        char        gp_name2[GPIOMAXNAME];        /* new name */
67
};
68

    
69
/* Attach device drivers that use GPIO pins */
70
struct gpio_attach {
71
        char                ga_dvname[16];        /* device name */
72
        int                ga_offset;        /* pin number */
73
        uint32_t        ga_mask;        /* binary mask */
74
        uint32_t        ga_flags;        /* driver dependent flags */
75
};
76

    
77
/* gpio(4) API */
78
#define GPIOINFO                _IOR('G', 0, struct gpio_info)
79
#define GPIOSET                        _IOWR('G', 5, struct gpio_set)
80
#define GPIOUNSET                _IOWR('G', 6, struct gpio_set)
81
#define GPIOREAD                _IOWR('G', 7, struct gpio_req)
82
#define GPIOWRITE                _IOWR('G', 8, struct gpio_req)
83
#define GPIOTOGGLE                _IOWR('G', 9, struct gpio_req)
84
#define GPIOATTACH                _IOWR('G', 10, struct gpio_attach)
85

    
86
#ifdef COMPAT_50
87
/* Old structure to attach/detach devices */
88
struct gpio_attach50 {
89
        char                ga_dvname[16];        /* device name */
90
        int                ga_offset;        /* pin number */
91
        uint32_t        ga_mask;        /* binary mask */
92
};
93

    
94
/* GPIO pin control (old API) */
95
struct gpio_pin_ctl {
96
        int gp_pin;                /* pin number */
97
        int gp_caps;                /* pin capabilities (read-only) */
98
        int gp_flags;                /* pin configuration flags */
99
};
100

    
101
/* GPIO pin operation (read/write/toggle) (old API) */
102
struct gpio_pin_op {
103
        int gp_pin;                /* pin number */
104
        int gp_value;                /* value */
105
};
106

    
107
/* the old API */
108
#define GPIOPINREAD                _IOWR('G', 1, struct gpio_pin_op)
109
#define GPIOPINWRITE                _IOWR('G', 2, struct gpio_pin_op)
110
#define GPIOPINTOGGLE                _IOWR('G', 3, struct gpio_pin_op)
111
#define GPIOPINCTL                _IOWR('G', 4, struct gpio_pin_ctl)
112
#define GPIOATTACH50                _IOWR('G', 10, struct gpio_attach50)
113
#define GPIODETACH50                _IOWR('G', 11, struct gpio_attach50)
114
#define GPIODETACH                _IOWR('G', 11, struct gpio_attach)
115
#endif        /* COMPAT_50 */
116

    
117
#endif        /* !_SYS_GPIO_H_ */