2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (C) 2006 M. Warner Losh.
5 * Copyright (C) 2012 Ian Lepore. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #ifndef _ARM_AT91_GPIO_H
32 #define _ARM_AT91_GPIO_H
35 #include <sys/types.h>
37 #include <sys/ioccom.h>
39 /* Userland GPIO API for Atmel AT91 series SOC.
41 * Open /dev/pioN (where N is 0 for PIOA, 1 for PIOB, etc), and use ioctl(2)
42 * calls to configure the pin(s) as needed.
44 * The userland interrupt support allows you to use read(2) and/or select(2) to
45 * get notified of interrupts on PIO pins for which you enabled interrupt
46 * notifications. Each time an interrupt occurs on a given pin, that pin number
47 * is written into a buffer as a uint8_t. Thus, reading from /dev/pioN delivers
48 * info on which interrupt(s) have occurred since the last read. You can also
49 * use select() to block until an interrupt occurs (you still need to read() to
50 * consume the interrupt number bytes from the buffer.)
55 uint32_t output_status; /* Current state of output pins */
56 uint32_t input_status; /* 1->out 0->in bitmask */
57 uint32_t highz_status; /* 1->highz 0->driven bitmask */
58 uint32_t pullup_status; /* 1->floating 0->pullup engaged */
59 uint32_t glitch_status; /* 0-> no glitch filter 1->gf */
60 uint32_t enabled_status; /* 1->used for pio 0->other */
61 uint32_t periph_status; /* 0->A periph 1->B periph */
62 uint32_t intr_status; /* 1-> ISR enabled, 0->disabled */
63 uint32_t extra_status[8];/* Extra status info, device depend */
68 uint32_t cfgmask; /* which things change */
69 #define AT91_GPIO_CFG_INPUT 0x01 /* configure input/output pins */
70 #define AT91_GPIO_CFG_HI_Z 0x02 /* HiZ */
71 #define AT91_GPIO_CFG_PULLUP 0x04 /* Enable/disable pullup resistors */
72 #define AT91_GPIO_CFG_GLITCH 0x08 /* Glitch filtering */
73 #define AT91_GPIO_CFG_GPIO 0x10 /* Use pin for PIO or peripheral */
74 #define AT91_GPIO_CFG_PERIPH 0x20 /* Select which peripheral to use */
75 #define AT91_GPIO_CFG_INTR 0x40 /* Select pin for interrupts */
76 uint32_t iomask; /* Mask of bits to change */
77 uint32_t input; /* or output */
78 uint32_t hi_z; /* Disable output */
79 uint32_t pullup; /* Enable pullup resistor */
80 uint32_t glitch; /* Glitch filtering */
81 uint32_t gpio; /* Enabled for PIO (1) or periph (0) */
82 uint32_t periph; /* Select periph A (0) or periph B (1) */
83 uint32_t intr; /* Enable interrupt (1), or not (0) */
88 uint32_t clockpin; /* clock pin MASK */
89 uint32_t datapin; /* Data pin MASK */
90 uint32_t bits; /* bits to clock out (all 32) */
93 struct at91_gpio_bang_many
95 uint32_t clockpin; /* clock pin MASK */
96 uint32_t datapin; /* Data pin MASK */
97 void *bits; /* bits to clock out */
98 uint32_t numbits; /* Number of bits to clock out */
101 #define AT91_GPIO_SET _IOW('g', 0, uint32_t) /* Turn bits on */
102 #define AT91_GPIO_CLR _IOW('g', 1, uint32_t) /* Turn bits off */
103 #define AT91_GPIO_READ _IOR('g', 2, uint32_t) /* Read input bit state */
104 #define AT91_GPIO_INFO _IOR('g', 3, struct at91_gpio_info) /* State of pio cfg */
105 #define AT91_GPIO_CFG _IOW('g', 4, struct at91_gpio_cfg) /* Configure pio */
106 #define AT91_GPIO_BANG _IOW('g', 5, struct at91_gpio_bang) /* bit bang 32 bits */
107 #define AT91_GPIO_BANG_MANY _IOW('g', 6, struct at91_gpio_bang_many)/* bit bang >32 bits */
109 #endif /* _ARM_AT91_GPIO_H */