blob: a41b332332560ed158431ce797bbdfbd1c7943e9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Christophe Leroy069fa832017-07-06 10:23:22 +02002
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 Leroyb3510fb2018-03-16 17:20:41 +010012#include <asm/immap_8xx.h>
Christophe Leroy394f9b32017-07-06 10:33:13 +020013#include <asm/io.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020014
15#ifdef __KERNEL__
16
17typedef 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 Leroy48f896d2017-07-06 10:33:17 +020028static inline void iopin_set_high(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +020029{
Christophe Leroy394f9b32017-07-06 10:33:13 +020030 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
31
Christophe Leroy069fa832017-07-06 10:23:22 +020032 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020033 ushort __iomem *datp = &immap->im_ioport.iop_padat;
34
35 setbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020036 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020037 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
38
39 setbits_be32(datp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020040 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020041 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
42
43 setbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020044 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020045 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
46
47 setbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020048 }
49}
50
Christophe Leroy48f896d2017-07-06 10:33:17 +020051static inline void iopin_set_low(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +020052{
Christophe Leroy394f9b32017-07-06 10:33:13 +020053 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
54
Christophe Leroy069fa832017-07-06 10:23:22 +020055 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020056 ushort __iomem *datp = &immap->im_ioport.iop_padat;
57
58 clrbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020059 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020060 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
61
62 clrbits_be32(datp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020063 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020064 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
65
66 clrbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020067 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020068 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
69
70 clrbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020071 }
72}
73
Christophe Leroy48f896d2017-07-06 10:33:17 +020074static inline uint iopin_is_high(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +020075{
Christophe Leroy394f9b32017-07-06 10:33:13 +020076 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
77
Christophe Leroy069fa832017-07-06 10:23:22 +020078 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020079 ushort __iomem *datp = &immap->im_ioport.iop_padat;
80
81 return (in_be16(datp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020082 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020083 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
84
85 return (in_be32(datp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020086 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020087 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
88
89 return (in_be16(datp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020090 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020091 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
92
93 return (in_be16(datp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020094 }
95 return 0;
96}
97
Christophe Leroy48f896d2017-07-06 10:33:17 +020098static inline uint iopin_is_low(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +020099{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200100 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
101
Christophe Leroy069fa832017-07-06 10:23:22 +0200102 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200103 ushort __iomem *datp = &immap->im_ioport.iop_padat;
104
105 return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200106 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200107 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
108
109 return ((in_be32(datp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200110 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200111 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
112
113 return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200114 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200115 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
116
117 return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200118 }
119 return 0;
120}
121
Christophe Leroy48f896d2017-07-06 10:33:17 +0200122static inline void iopin_set_out(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200123{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200124 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
125
Christophe Leroy069fa832017-07-06 10:23:22 +0200126 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200127 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
128
129 setbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200130 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200131 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
132
133 setbits_be32(dirp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200134 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200135 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
136
137 setbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200138 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200139 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
140
141 setbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200142 }
143}
144
Christophe Leroy48f896d2017-07-06 10:33:17 +0200145static inline void iopin_set_in(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200146{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200147 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
148
Christophe Leroy069fa832017-07-06 10:23:22 +0200149 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200150 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
151
152 clrbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200153 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200154 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
155
156 clrbits_be32(dirp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200157 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200158 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
159
160 clrbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200161 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200162 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
163
164 clrbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200165 }
166}
167
Christophe Leroy48f896d2017-07-06 10:33:17 +0200168static inline uint iopin_is_out(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200169{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200170 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
171
Christophe Leroy069fa832017-07-06 10:23:22 +0200172 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200173 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
174
175 return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200176 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200177 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
178
179 return (in_be32(dirp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200180 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200181 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
182
183 return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200184 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200185 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
186
187 return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200188 }
189 return 0;
190}
191
Christophe Leroy48f896d2017-07-06 10:33:17 +0200192static inline uint iopin_is_in(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200193{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200194 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
195
Christophe Leroy069fa832017-07-06 10:23:22 +0200196 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200197 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
198
199 return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200200 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200201 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
202
203 return ((in_be32(dirp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200204 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200205 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
206
207 return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200208 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200209 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
210
211 return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200212 }
213 return 0;
214}
215
Christophe Leroy48f896d2017-07-06 10:33:17 +0200216static inline void iopin_set_odr(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200217{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200218 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
219
Christophe Leroy069fa832017-07-06 10:23:22 +0200220 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200221 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
222
223 setbits_be16(odrp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200224 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200225 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
226
227 setbits_be16(odrp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200228 }
229}
230
Christophe Leroy48f896d2017-07-06 10:33:17 +0200231static inline void iopin_set_act(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200232{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200233 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
234
Christophe Leroy069fa832017-07-06 10:23:22 +0200235 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200236 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
237
238 clrbits_be16(odrp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200239 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200240 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
241
242 clrbits_be16(odrp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200243 }
244}
245
Christophe Leroy48f896d2017-07-06 10:33:17 +0200246static inline uint iopin_is_odr(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200247{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200248 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
249
Christophe Leroy069fa832017-07-06 10:23:22 +0200250 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200251 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
252
253 return (in_be16(odrp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200254 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200255 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
256
257 return (in_be16(odrp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200258 }
259 return 0;
260}
261
Christophe Leroy48f896d2017-07-06 10:33:17 +0200262static inline uint iopin_is_act(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200263{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200264 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
265
Christophe Leroy069fa832017-07-06 10:23:22 +0200266 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200267 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
268
269 return ((in_be16(odrp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200270 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200271 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
272
273 return ((in_be16(odrp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200274 }
275 return 0;
276}
277
Christophe Leroy48f896d2017-07-06 10:33:17 +0200278static inline void iopin_set_ded(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200279{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200280 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
281
Christophe Leroy069fa832017-07-06 10:23:22 +0200282 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200283 ushort __iomem *parp = &immap->im_ioport.iop_papar;
284
285 setbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200286 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200287 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
288
289 setbits_be32(parp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200290 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200291 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
292
293 setbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200294 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200295 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
296
297 setbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200298 }
299}
300
Christophe Leroy48f896d2017-07-06 10:33:17 +0200301static inline void iopin_set_gen(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200302{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200303 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
304
Christophe Leroy069fa832017-07-06 10:23:22 +0200305 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200306 ushort __iomem *parp = &immap->im_ioport.iop_papar;
307
308 clrbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200309 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200310 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
311
312 clrbits_be32(parp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200313 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200314 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
315
316 clrbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200317 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200318 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
319
320 clrbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200321 }
322}
323
Christophe Leroy48f896d2017-07-06 10:33:17 +0200324static inline uint iopin_is_ded(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200325{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200326 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
327
Christophe Leroy069fa832017-07-06 10:23:22 +0200328 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200329 ushort __iomem *parp = &immap->im_ioport.iop_papar;
330
331 return (in_be16(parp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200332 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200333 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
334
335 return (in_be32(parp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200336 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200337 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
338
339 return (in_be16(parp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200340 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200341 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
342
343 return (in_be16(parp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200344 }
345 return 0;
346}
347
Christophe Leroy48f896d2017-07-06 10:33:17 +0200348static inline uint iopin_is_gen(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200349{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200350 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
351
Christophe Leroy069fa832017-07-06 10:23:22 +0200352 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200353 ushort __iomem *parp = &immap->im_ioport.iop_papar;
354
355 return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200356 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200357 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
358
359 return ((in_be32(parp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200360 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200361 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
362
363 return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200364 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200365 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
366
367 return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200368 }
369 return 0;
370}
371
Christophe Leroy48f896d2017-07-06 10:33:17 +0200372static inline void iopin_set_opt2(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200373{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200374 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
375
Christophe Leroy069fa832017-07-06 10:23:22 +0200376 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200377 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
378
379 setbits_be16(sorp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200380 }
381}
382
Christophe Leroy48f896d2017-07-06 10:33:17 +0200383static inline void iopin_set_opt1(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200384{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200385 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
386
Christophe Leroy069fa832017-07-06 10:23:22 +0200387 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200388 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
389
390 clrbits_be16(sorp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200391 }
392}
393
Christophe Leroy48f896d2017-07-06 10:33:17 +0200394static inline uint iopin_is_opt2(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200395{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200396 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
397
Christophe Leroy069fa832017-07-06 10:23:22 +0200398 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200399 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
400
401 return (in_be16(sorp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200402 }
403 return 0;
404}
405
Christophe Leroy48f896d2017-07-06 10:33:17 +0200406static inline uint iopin_is_opt1(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200407{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200408 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
409
Christophe Leroy069fa832017-07-06 10:23:22 +0200410 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200411 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
412
413 return ((in_be16(sorp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200414 }
415 return 0;
416}
417
Christophe Leroy48f896d2017-07-06 10:33:17 +0200418static inline void iopin_set_falledge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200419{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200420 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
421
Christophe Leroy069fa832017-07-06 10:23:22 +0200422 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200423 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
424
425 setbits_be16(intp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200426 }
427}
428
Christophe Leroy48f896d2017-07-06 10:33:17 +0200429static inline void iopin_set_anyedge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200430{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200431 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
432
Christophe Leroy069fa832017-07-06 10:23:22 +0200433 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200434 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
435
436 clrbits_be16(intp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200437 }
438}
439
Christophe Leroy48f896d2017-07-06 10:33:17 +0200440static inline uint iopin_is_falledge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200441{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200442 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
443
Christophe Leroy069fa832017-07-06 10:23:22 +0200444 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200445 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
446
447 return (in_be16(intp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200448 }
449 return 0;
450}
451
Christophe Leroy48f896d2017-07-06 10:33:17 +0200452static inline uint iopin_is_anyedge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200453{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200454 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
455
Christophe Leroy069fa832017-07-06 10:23:22 +0200456 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200457 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
458
459 return ((in_be16(intp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200460 }
461 return 0;
462}
463
464#endif /* __KERNEL__ */
465
466#endif /* _ASM_IOPIN_8XX_H_ */