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