]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/avr32/include/asm/arch-common/portmux-pio.h
2 * Copyright (C) 2006, 2008 Atmel Corporation
4 * SPDX-License-Identifier: GPL-2.0+
6 #ifndef __AVR32_PORTMUX_PIO_H__
7 #define __AVR32_PORTMUX_PIO_H__
11 /* PIO register offsets */
12 #define PIO_PER 0x0000
13 #define PIO_PDR 0x0004
14 #define PIO_PSR 0x0008
15 #define PIO_OER 0x0010
16 #define PIO_ODR 0x0014
17 #define PIO_OSR 0x0018
18 #define PIO_IFER 0x0020
19 #define PIO_IFDR 0x0024
20 #define PIO_ISFR 0x0028
21 #define PIO_SODR 0x0030
22 #define PIO_CODR 0x0034
23 #define PIO_ODSR 0x0038
24 #define PIO_PDSR 0x003c
25 #define PIO_IER 0x0040
26 #define PIO_IDR 0x0044
27 #define PIO_IMR 0x0048
28 #define PIO_ISR 0x004c
29 #define PIO_MDER 0x0050
30 #define PIO_MDDR 0x0054
31 #define PIO_MDSR 0x0058
32 #define PIO_PUDR 0x0060
33 #define PIO_PUER 0x0064
34 #define PIO_PUSR 0x0068
35 #define PIO_ASR 0x0070
36 #define PIO_BSR 0x0074
37 #define PIO_ABSR 0x0078
38 #define PIO_OWER 0x00a0
39 #define PIO_OWDR 0x00a4
40 #define PIO_OWSR 0x00a8
42 /* Hardware register access */
43 #define pio_readl(base, reg) \
44 __raw_readl((void *)base + PIO_##reg)
45 #define pio_writel(base, reg, value) \
46 __raw_writel((value), (void *)base + PIO_##reg)
48 /* Portmux API starts here. See doc/README.AVR32-port-muxing */
50 enum portmux_function
{
55 /* Pull-down, buskeeper and drive strength are not supported */
56 #define PORTMUX_DIR_INPUT (0 << 0)
57 #define PORTMUX_DIR_OUTPUT (1 << 0)
58 #define PORTMUX_INIT_LOW (0 << 1)
59 #define PORTMUX_INIT_HIGH (1 << 1)
60 #define PORTMUX_PULL_UP (1 << 2)
61 #define PORTMUX_PULL_DOWN (0)
62 #define PORTMUX_BUSKEEPER PORTMUX_PULL_UP
63 #define PORTMUX_DRIVE_MIN (0)
64 #define PORTMUX_DRIVE_LOW (0)
65 #define PORTMUX_DRIVE_HIGH (0)
66 #define PORTMUX_DRIVE_MAX (0)
67 #define PORTMUX_OPEN_DRAIN (1 << 3)
69 void portmux_select_peripheral(void *port
, unsigned long pin_mask
,
70 enum portmux_function func
, unsigned long flags
);
71 void portmux_select_gpio(void *port
, unsigned long pin_mask
,
74 /* Internal helper functions */
76 static inline void __pio_set_output_value(void *port
, unsigned int pin
,
80 * value will usually be constant, but it's pretty cheap
84 pio_writel(port
, SODR
, 1 << pin
);
86 pio_writel(port
, CODR
, 1 << pin
);
89 static inline int __pio_get_input_value(void *port
, unsigned int pin
)
91 return (pio_readl(port
, PDSR
) >> pin
) & 1;
94 void pio_set_output_value(unsigned int pin
, int value
);
95 int pio_get_input_value(unsigned int pin
);
97 /* GPIO API starts here */
100 * GCC doesn't realize that the constant case is extremely trivial,
101 * so we need to help it make the right decision by using
104 __attribute__((always_inline
))
105 static inline void gpio_set_value(unsigned int pin
, int value
)
107 if (__builtin_constant_p(pin
))
108 __pio_set_output_value(pio_pin_to_port(pin
), pin
& 0x1f, value
);
110 pio_set_output_value(pin
, value
);
113 __attribute__((always_inline
))
114 static inline int gpio_get_value(unsigned int pin
)
116 if (__builtin_constant_p(pin
))
117 return __pio_get_input_value(pio_pin_to_port(pin
), pin
& 0x1f);
119 return pio_get_input_value(pin
);
122 #endif /* __AVR32_PORTMUX_PIO_H__ */