2 * Copyright (C) 2006, 2008 Atmel Corporation
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 #ifndef __AVR32_PORTMUX_PIO_H__
23 #define __AVR32_PORTMUX_PIO_H__
27 /* PIO register offsets */
28 #define PIO_PER 0x0000
29 #define PIO_PDR 0x0004
30 #define PIO_PSR 0x0008
31 #define PIO_OER 0x0010
32 #define PIO_ODR 0x0014
33 #define PIO_OSR 0x0018
34 #define PIO_IFER 0x0020
35 #define PIO_IFDR 0x0024
36 #define PIO_ISFR 0x0028
37 #define PIO_SODR 0x0030
38 #define PIO_CODR 0x0034
39 #define PIO_ODSR 0x0038
40 #define PIO_PDSR 0x003c
41 #define PIO_IER 0x0040
42 #define PIO_IDR 0x0044
43 #define PIO_IMR 0x0048
44 #define PIO_ISR 0x004c
45 #define PIO_MDER 0x0050
46 #define PIO_MDDR 0x0054
47 #define PIO_MDSR 0x0058
48 #define PIO_PUDR 0x0060
49 #define PIO_PUER 0x0064
50 #define PIO_PUSR 0x0068
51 #define PIO_ASR 0x0070
52 #define PIO_BSR 0x0074
53 #define PIO_ABSR 0x0078
54 #define PIO_OWER 0x00a0
55 #define PIO_OWDR 0x00a4
56 #define PIO_OWSR 0x00a8
58 /* Hardware register access */
59 #define pio_readl(base, reg) \
60 __raw_readl((void *)base + PIO_##reg)
61 #define pio_writel(base, reg, value) \
62 __raw_writel((value), (void *)base + PIO_##reg)
64 /* Portmux API starts here. See doc/README.AVR32-port-muxing */
66 enum portmux_function {
71 /* Pull-down, buskeeper and drive strength are not supported */
72 #define PORTMUX_DIR_INPUT (0 << 0)
73 #define PORTMUX_DIR_OUTPUT (1 << 0)
74 #define PORTMUX_INIT_LOW (0 << 1)
75 #define PORTMUX_INIT_HIGH (1 << 1)
76 #define PORTMUX_PULL_UP (1 << 2)
77 #define PORTMUX_PULL_DOWN (0)
78 #define PORTMUX_BUSKEEPER PORTMUX_PULL_UP
79 #define PORTMUX_DRIVE_MIN (0)
80 #define PORTMUX_DRIVE_LOW (0)
81 #define PORTMUX_DRIVE_HIGH (0)
82 #define PORTMUX_DRIVE_MAX (0)
83 #define PORTMUX_OPEN_DRAIN (1 << 3)
85 void portmux_select_peripheral(void *port, unsigned long pin_mask,
86 enum portmux_function func, unsigned long flags);
87 void portmux_select_gpio(void *port, unsigned long pin_mask,
90 /* Internal helper functions */
92 static inline void __pio_set_output_value(void *port, unsigned int pin,
96 * value will usually be constant, but it's pretty cheap
100 pio_writel(port, SODR, 1 << pin);
102 pio_writel(port, CODR, 1 << pin);
105 static inline int __pio_get_input_value(void *port, unsigned int pin)
107 return (pio_readl(port, PDSR) >> pin) & 1;
110 void pio_set_output_value(unsigned int pin, int value);
111 int pio_get_input_value(unsigned int pin);
113 /* GPIO API starts here */
116 * GCC doesn't realize that the constant case is extremely trivial,
117 * so we need to help it make the right decision by using
120 __attribute__((always_inline))
121 static inline void gpio_set_value(unsigned int pin, int value)
123 if (__builtin_constant_p(pin))
124 __pio_set_output_value(pio_pin_to_port(pin), pin & 0x1f, value);
126 pio_set_output_value(pin, value);
129 __attribute__((always_inline))
130 static inline int gpio_get_value(unsigned int pin)
132 if (__builtin_constant_p(pin))
133 return __pio_get_input_value(pio_pin_to_port(pin), pin & 0x1f);
135 return pio_get_input_value(pin);
138 #endif /* __AVR32_PORTMUX_PIO_H__ */