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