Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: GPL-2.0+ |
| 3 | */ |
| 4 | |
| 5 | /* |
| 6 | * MPC8xx I/O port pin manipulation functions |
| 7 | * Roughly based on iopin_8260.h |
| 8 | */ |
| 9 | |
| 10 | #ifndef _ASM_IOPIN_8XX_H_ |
| 11 | #define _ASM_IOPIN_8XX_H_ |
| 12 | |
| 13 | #include <linux/types.h> |
| 14 | #include <asm/8xx_immap.h> |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 15 | #include <asm/io.h> |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 16 | |
| 17 | #ifdef __KERNEL__ |
| 18 | |
| 19 | typedef struct { |
| 20 | u_char port:2; /* port number (A=0, B=1, C=2, D=3) */ |
| 21 | u_char pin:5; /* port pin (0-31) */ |
| 22 | u_char flag:1; /* for whatever */ |
| 23 | } iopin_t; |
| 24 | |
| 25 | #define IOPIN_PORTA 0 |
| 26 | #define IOPIN_PORTB 1 |
| 27 | #define IOPIN_PORTC 2 |
| 28 | #define IOPIN_PORTD 3 |
| 29 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 30 | static inline void iopin_set_high(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 31 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 32 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 33 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 34 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 35 | ushort __iomem *datp = &immap->im_ioport.iop_padat; |
| 36 | |
| 37 | setbits_be16(datp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 38 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 39 | uint __iomem *datp = &immap->im_cpm.cp_pbdat; |
| 40 | |
| 41 | setbits_be32(datp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 42 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 43 | ushort __iomem *datp = &immap->im_ioport.iop_pcdat; |
| 44 | |
| 45 | setbits_be16(datp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 46 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 47 | ushort __iomem *datp = &immap->im_ioport.iop_pddat; |
| 48 | |
| 49 | setbits_be16(datp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 53 | static inline void iopin_set_low(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 54 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 55 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 56 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 57 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 58 | ushort __iomem *datp = &immap->im_ioport.iop_padat; |
| 59 | |
| 60 | clrbits_be16(datp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 61 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 62 | uint __iomem *datp = &immap->im_cpm.cp_pbdat; |
| 63 | |
| 64 | clrbits_be32(datp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 65 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 66 | ushort __iomem *datp = &immap->im_ioport.iop_pcdat; |
| 67 | |
| 68 | clrbits_be16(datp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 69 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 70 | ushort __iomem *datp = &immap->im_ioport.iop_pddat; |
| 71 | |
| 72 | clrbits_be16(datp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 76 | static inline uint iopin_is_high(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 77 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 78 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 79 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 80 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 81 | ushort __iomem *datp = &immap->im_ioport.iop_padat; |
| 82 | |
| 83 | return (in_be16(datp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 84 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 85 | uint __iomem *datp = &immap->im_cpm.cp_pbdat; |
| 86 | |
| 87 | return (in_be32(datp) >> (31 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 88 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 89 | ushort __iomem *datp = &immap->im_ioport.iop_pcdat; |
| 90 | |
| 91 | return (in_be16(datp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 92 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 93 | ushort __iomem *datp = &immap->im_ioport.iop_pddat; |
| 94 | |
| 95 | return (in_be16(datp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 96 | } |
| 97 | return 0; |
| 98 | } |
| 99 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 100 | static inline uint iopin_is_low(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 101 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 102 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 103 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 104 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 105 | ushort __iomem *datp = &immap->im_ioport.iop_padat; |
| 106 | |
| 107 | return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 108 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 109 | uint __iomem *datp = &immap->im_cpm.cp_pbdat; |
| 110 | |
| 111 | return ((in_be32(datp) >> (31 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 112 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 113 | ushort __iomem *datp = &immap->im_ioport.iop_pcdat; |
| 114 | |
| 115 | return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 116 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 117 | ushort __iomem *datp = &immap->im_ioport.iop_pddat; |
| 118 | |
| 119 | return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 120 | } |
| 121 | return 0; |
| 122 | } |
| 123 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 124 | static inline void iopin_set_out(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 125 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 126 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 127 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 128 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 129 | ushort __iomem *dirp = &immap->im_ioport.iop_padir; |
| 130 | |
| 131 | setbits_be16(dirp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 132 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 133 | uint __iomem *dirp = &immap->im_cpm.cp_pbdir; |
| 134 | |
| 135 | setbits_be32(dirp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 136 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 137 | ushort __iomem *dirp = &immap->im_ioport.iop_pcdir; |
| 138 | |
| 139 | setbits_be16(dirp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 140 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 141 | ushort __iomem *dirp = &immap->im_ioport.iop_pddir; |
| 142 | |
| 143 | setbits_be16(dirp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 147 | static inline void iopin_set_in(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 148 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 149 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 150 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 151 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 152 | ushort __iomem *dirp = &immap->im_ioport.iop_padir; |
| 153 | |
| 154 | clrbits_be16(dirp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 155 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 156 | uint __iomem *dirp = &immap->im_cpm.cp_pbdir; |
| 157 | |
| 158 | clrbits_be32(dirp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 159 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 160 | ushort __iomem *dirp = &immap->im_ioport.iop_pcdir; |
| 161 | |
| 162 | clrbits_be16(dirp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 163 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 164 | ushort __iomem *dirp = &immap->im_ioport.iop_pddir; |
| 165 | |
| 166 | clrbits_be16(dirp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 170 | static inline uint iopin_is_out(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 171 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 172 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 173 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 174 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 175 | ushort __iomem *dirp = &immap->im_ioport.iop_padir; |
| 176 | |
| 177 | return (in_be16(dirp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 178 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 179 | uint __iomem *dirp = &immap->im_cpm.cp_pbdir; |
| 180 | |
| 181 | return (in_be32(dirp) >> (31 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 182 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 183 | ushort __iomem *dirp = &immap->im_ioport.iop_pcdir; |
| 184 | |
| 185 | return (in_be16(dirp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 186 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 187 | ushort __iomem *dirp = &immap->im_ioport.iop_pddir; |
| 188 | |
| 189 | return (in_be16(dirp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 190 | } |
| 191 | return 0; |
| 192 | } |
| 193 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 194 | static inline uint iopin_is_in(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 195 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 196 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 197 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 198 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 199 | ushort __iomem *dirp = &immap->im_ioport.iop_padir; |
| 200 | |
| 201 | return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 202 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 203 | uint __iomem *dirp = &immap->im_cpm.cp_pbdir; |
| 204 | |
| 205 | return ((in_be32(dirp) >> (31 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 206 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 207 | ushort __iomem *dirp = &immap->im_ioport.iop_pcdir; |
| 208 | |
| 209 | return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 210 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 211 | ushort __iomem *dirp = &immap->im_ioport.iop_pddir; |
| 212 | |
| 213 | return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 214 | } |
| 215 | return 0; |
| 216 | } |
| 217 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 218 | static inline void iopin_set_odr(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 219 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 220 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 221 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 222 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 223 | ushort __iomem *odrp = &immap->im_ioport.iop_paodr; |
| 224 | |
| 225 | setbits_be16(odrp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 226 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 227 | ushort __iomem *odrp = &immap->im_cpm.cp_pbodr; |
| 228 | |
| 229 | setbits_be16(odrp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 233 | static inline void iopin_set_act(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 234 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 235 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 236 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 237 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 238 | ushort __iomem *odrp = &immap->im_ioport.iop_paodr; |
| 239 | |
| 240 | clrbits_be16(odrp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 241 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 242 | ushort __iomem *odrp = &immap->im_cpm.cp_pbodr; |
| 243 | |
| 244 | clrbits_be16(odrp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 245 | } |
| 246 | } |
| 247 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 248 | static inline uint iopin_is_odr(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 249 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 250 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 251 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 252 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 253 | ushort __iomem *odrp = &immap->im_ioport.iop_paodr; |
| 254 | |
| 255 | return (in_be16(odrp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 256 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 257 | ushort __iomem *odrp = &immap->im_cpm.cp_pbodr; |
| 258 | |
| 259 | return (in_be16(odrp) >> (31 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 260 | } |
| 261 | return 0; |
| 262 | } |
| 263 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 264 | static inline uint iopin_is_act(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 265 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 266 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 267 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 268 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 269 | ushort __iomem *odrp = &immap->im_ioport.iop_paodr; |
| 270 | |
| 271 | return ((in_be16(odrp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 272 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 273 | ushort __iomem *odrp = &immap->im_cpm.cp_pbodr; |
| 274 | |
| 275 | return ((in_be16(odrp) >> (31 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 280 | static inline void iopin_set_ded(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 281 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 282 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 283 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 284 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 285 | ushort __iomem *parp = &immap->im_ioport.iop_papar; |
| 286 | |
| 287 | setbits_be16(parp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 288 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 289 | uint __iomem *parp = &immap->im_cpm.cp_pbpar; |
| 290 | |
| 291 | setbits_be32(parp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 292 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 293 | ushort __iomem *parp = &immap->im_ioport.iop_pcpar; |
| 294 | |
| 295 | setbits_be16(parp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 296 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 297 | ushort __iomem *parp = &immap->im_ioport.iop_pdpar; |
| 298 | |
| 299 | setbits_be16(parp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 303 | static inline void iopin_set_gen(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 304 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 305 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 306 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 307 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 308 | ushort __iomem *parp = &immap->im_ioport.iop_papar; |
| 309 | |
| 310 | clrbits_be16(parp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 311 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 312 | uint __iomem *parp = &immap->im_cpm.cp_pbpar; |
| 313 | |
| 314 | clrbits_be32(parp, 1 << (31 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 315 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 316 | ushort __iomem *parp = &immap->im_ioport.iop_pcpar; |
| 317 | |
| 318 | clrbits_be16(parp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 319 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 320 | ushort __iomem *parp = &immap->im_ioport.iop_pdpar; |
| 321 | |
| 322 | clrbits_be16(parp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 326 | static inline uint iopin_is_ded(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 327 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 328 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 329 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 330 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 331 | ushort __iomem *parp = &immap->im_ioport.iop_papar; |
| 332 | |
| 333 | return (in_be16(parp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 334 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 335 | uint __iomem *parp = &immap->im_cpm.cp_pbpar; |
| 336 | |
| 337 | return (in_be32(parp) >> (31 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 338 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 339 | ushort __iomem *parp = &immap->im_ioport.iop_pcpar; |
| 340 | |
| 341 | return (in_be16(parp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 342 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 343 | ushort __iomem *parp = &immap->im_ioport.iop_pdpar; |
| 344 | |
| 345 | return (in_be16(parp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 346 | } |
| 347 | return 0; |
| 348 | } |
| 349 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 350 | static inline uint iopin_is_gen(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 351 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 352 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 353 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 354 | if (iopin->port == IOPIN_PORTA) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 355 | ushort __iomem *parp = &immap->im_ioport.iop_papar; |
| 356 | |
| 357 | return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 358 | } else if (iopin->port == IOPIN_PORTB) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 359 | uint __iomem *parp = &immap->im_cpm.cp_pbpar; |
| 360 | |
| 361 | return ((in_be32(parp) >> (31 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 362 | } else if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 363 | ushort __iomem *parp = &immap->im_ioport.iop_pcpar; |
| 364 | |
| 365 | return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 366 | } else if (iopin->port == IOPIN_PORTD) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 367 | ushort __iomem *parp = &immap->im_ioport.iop_pdpar; |
| 368 | |
| 369 | return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 374 | static inline void iopin_set_opt2(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 375 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 376 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 377 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 378 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 379 | ushort __iomem *sorp = &immap->im_ioport.iop_pcso; |
| 380 | |
| 381 | setbits_be16(sorp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 385 | static inline void iopin_set_opt1(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 386 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 387 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 388 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 389 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 390 | ushort __iomem *sorp = &immap->im_ioport.iop_pcso; |
| 391 | |
| 392 | clrbits_be16(sorp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 393 | } |
| 394 | } |
| 395 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 396 | static inline uint iopin_is_opt2(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 397 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 398 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 399 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 400 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 401 | ushort __iomem *sorp = &immap->im_ioport.iop_pcso; |
| 402 | |
| 403 | return (in_be16(sorp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 404 | } |
| 405 | return 0; |
| 406 | } |
| 407 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 408 | static inline uint iopin_is_opt1(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 409 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 410 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 411 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 412 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 413 | ushort __iomem *sorp = &immap->im_ioport.iop_pcso; |
| 414 | |
| 415 | return ((in_be16(sorp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 416 | } |
| 417 | return 0; |
| 418 | } |
| 419 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 420 | static inline void iopin_set_falledge(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 421 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 422 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 423 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 424 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 425 | ushort __iomem *intp = &immap->im_ioport.iop_pcint; |
| 426 | |
| 427 | setbits_be16(intp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 431 | static inline void iopin_set_anyedge(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 432 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 433 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 434 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 435 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 436 | ushort __iomem *intp = &immap->im_ioport.iop_pcint; |
| 437 | |
| 438 | clrbits_be16(intp, 1 << (15 - iopin->pin)); |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 439 | } |
| 440 | } |
| 441 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 442 | static inline uint iopin_is_falledge(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 443 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 444 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 445 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 446 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 447 | ushort __iomem *intp = &immap->im_ioport.iop_pcint; |
| 448 | |
| 449 | return (in_be16(intp) >> (15 - iopin->pin)) & 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 450 | } |
| 451 | return 0; |
| 452 | } |
| 453 | |
Christophe Leroy | 48f896d | 2017-07-06 10:33:17 +0200 | [diff] [blame] | 454 | static inline uint iopin_is_anyedge(iopin_t *iopin) |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 455 | { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 456 | immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR; |
| 457 | |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 458 | if (iopin->port == IOPIN_PORTC) { |
Christophe Leroy | 394f9b3 | 2017-07-06 10:33:13 +0200 | [diff] [blame] | 459 | ushort __iomem *intp = &immap->im_ioport.iop_pcint; |
| 460 | |
| 461 | return ((in_be16(intp) >> (15 - iopin->pin)) & 1) ^ 1; |
Christophe Leroy | 069fa83 | 2017-07-06 10:23:22 +0200 | [diff] [blame] | 462 | } |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | #endif /* __KERNEL__ */ |
| 467 | |
| 468 | #endif /* _ASM_IOPIN_8XX_H_ */ |