blob: 15679a2db55b6c0a265b4a6b8f45d2163cca49d4 [file] [log] [blame]
Christophe Leroy069fa832017-07-06 10:23:22 +02001/*
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 Leroy394f9b32017-07-06 10:33:13 +020015#include <asm/io.h>
Christophe Leroy069fa832017-07-06 10:23:22 +020016
17#ifdef __KERNEL__
18
19typedef 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 Leroy48f896d2017-07-06 10:33:17 +020030static inline void iopin_set_high(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +020031{
Christophe Leroy394f9b32017-07-06 10:33:13 +020032 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
33
Christophe Leroy069fa832017-07-06 10:23:22 +020034 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020035 ushort __iomem *datp = &immap->im_ioport.iop_padat;
36
37 setbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020038 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020039 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
40
41 setbits_be32(datp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020042 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020043 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
44
45 setbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020046 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020047 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
48
49 setbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020050 }
51}
52
Christophe Leroy48f896d2017-07-06 10:33:17 +020053static inline void iopin_set_low(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +020054{
Christophe Leroy394f9b32017-07-06 10:33:13 +020055 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
56
Christophe Leroy069fa832017-07-06 10:23:22 +020057 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020058 ushort __iomem *datp = &immap->im_ioport.iop_padat;
59
60 clrbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020061 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020062 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
63
64 clrbits_be32(datp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020065 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020066 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
67
68 clrbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020069 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020070 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
71
72 clrbits_be16(datp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +020073 }
74}
75
Christophe Leroy48f896d2017-07-06 10:33:17 +020076static inline uint iopin_is_high(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +020077{
Christophe Leroy394f9b32017-07-06 10:33:13 +020078 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
79
Christophe Leroy069fa832017-07-06 10:23:22 +020080 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020081 ushort __iomem *datp = &immap->im_ioport.iop_padat;
82
83 return (in_be16(datp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020084 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020085 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
86
87 return (in_be32(datp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020088 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020089 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
90
91 return (in_be16(datp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020092 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +020093 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
94
95 return (in_be16(datp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +020096 }
97 return 0;
98}
99
Christophe Leroy48f896d2017-07-06 10:33:17 +0200100static inline uint iopin_is_low(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200101{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200102 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
103
Christophe Leroy069fa832017-07-06 10:23:22 +0200104 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200105 ushort __iomem *datp = &immap->im_ioport.iop_padat;
106
107 return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200108 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200109 uint __iomem *datp = &immap->im_cpm.cp_pbdat;
110
111 return ((in_be32(datp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200112 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200113 ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
114
115 return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200116 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200117 ushort __iomem *datp = &immap->im_ioport.iop_pddat;
118
119 return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200120 }
121 return 0;
122}
123
Christophe Leroy48f896d2017-07-06 10:33:17 +0200124static inline void iopin_set_out(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200125{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200126 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
127
Christophe Leroy069fa832017-07-06 10:23:22 +0200128 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200129 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
130
131 setbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200132 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200133 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
134
135 setbits_be32(dirp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200136 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200137 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
138
139 setbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200140 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200141 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
142
143 setbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200144 }
145}
146
Christophe Leroy48f896d2017-07-06 10:33:17 +0200147static inline void iopin_set_in(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200148{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200149 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
150
Christophe Leroy069fa832017-07-06 10:23:22 +0200151 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200152 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
153
154 clrbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200155 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200156 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
157
158 clrbits_be32(dirp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200159 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200160 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
161
162 clrbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200163 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200164 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
165
166 clrbits_be16(dirp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200167 }
168}
169
Christophe Leroy48f896d2017-07-06 10:33:17 +0200170static inline uint iopin_is_out(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200171{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200172 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
173
Christophe Leroy069fa832017-07-06 10:23:22 +0200174 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200175 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
176
177 return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200178 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200179 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
180
181 return (in_be32(dirp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200182 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200183 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
184
185 return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200186 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200187 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
188
189 return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200190 }
191 return 0;
192}
193
Christophe Leroy48f896d2017-07-06 10:33:17 +0200194static inline uint iopin_is_in(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200195{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200196 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
197
Christophe Leroy069fa832017-07-06 10:23:22 +0200198 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200199 ushort __iomem *dirp = &immap->im_ioport.iop_padir;
200
201 return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200202 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200203 uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
204
205 return ((in_be32(dirp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200206 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200207 ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
208
209 return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200210 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200211 ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
212
213 return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200214 }
215 return 0;
216}
217
Christophe Leroy48f896d2017-07-06 10:33:17 +0200218static inline void iopin_set_odr(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200219{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200220 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
221
Christophe Leroy069fa832017-07-06 10:23:22 +0200222 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200223 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
224
225 setbits_be16(odrp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200226 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200227 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
228
229 setbits_be16(odrp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200230 }
231}
232
Christophe Leroy48f896d2017-07-06 10:33:17 +0200233static inline void iopin_set_act(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200234{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200235 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
236
Christophe Leroy069fa832017-07-06 10:23:22 +0200237 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200238 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
239
240 clrbits_be16(odrp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200241 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200242 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
243
244 clrbits_be16(odrp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200245 }
246}
247
Christophe Leroy48f896d2017-07-06 10:33:17 +0200248static inline uint iopin_is_odr(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200249{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200250 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
251
Christophe Leroy069fa832017-07-06 10:23:22 +0200252 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200253 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
254
255 return (in_be16(odrp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200256 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200257 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
258
259 return (in_be16(odrp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200260 }
261 return 0;
262}
263
Christophe Leroy48f896d2017-07-06 10:33:17 +0200264static inline uint iopin_is_act(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200265{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200266 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
267
Christophe Leroy069fa832017-07-06 10:23:22 +0200268 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200269 ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
270
271 return ((in_be16(odrp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200272 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200273 ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
274
275 return ((in_be16(odrp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200276 }
277 return 0;
278}
279
Christophe Leroy48f896d2017-07-06 10:33:17 +0200280static inline void iopin_set_ded(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200281{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200282 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
283
Christophe Leroy069fa832017-07-06 10:23:22 +0200284 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200285 ushort __iomem *parp = &immap->im_ioport.iop_papar;
286
287 setbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200288 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200289 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
290
291 setbits_be32(parp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200292 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200293 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
294
295 setbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200296 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200297 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
298
299 setbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200300 }
301}
302
Christophe Leroy48f896d2017-07-06 10:33:17 +0200303static inline void iopin_set_gen(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200304{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200305 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
306
Christophe Leroy069fa832017-07-06 10:23:22 +0200307 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200308 ushort __iomem *parp = &immap->im_ioport.iop_papar;
309
310 clrbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200311 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200312 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
313
314 clrbits_be32(parp, 1 << (31 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200315 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200316 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
317
318 clrbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200319 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200320 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
321
322 clrbits_be16(parp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200323 }
324}
325
Christophe Leroy48f896d2017-07-06 10:33:17 +0200326static inline uint iopin_is_ded(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200327{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200328 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
329
Christophe Leroy069fa832017-07-06 10:23:22 +0200330 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200331 ushort __iomem *parp = &immap->im_ioport.iop_papar;
332
333 return (in_be16(parp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200334 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200335 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
336
337 return (in_be32(parp) >> (31 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200338 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200339 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
340
341 return (in_be16(parp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200342 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200343 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
344
345 return (in_be16(parp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200346 }
347 return 0;
348}
349
Christophe Leroy48f896d2017-07-06 10:33:17 +0200350static inline uint iopin_is_gen(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200351{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200352 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
353
Christophe Leroy069fa832017-07-06 10:23:22 +0200354 if (iopin->port == IOPIN_PORTA) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200355 ushort __iomem *parp = &immap->im_ioport.iop_papar;
356
357 return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200358 } else if (iopin->port == IOPIN_PORTB) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200359 uint __iomem *parp = &immap->im_cpm.cp_pbpar;
360
361 return ((in_be32(parp) >> (31 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200362 } else if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200363 ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
364
365 return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200366 } else if (iopin->port == IOPIN_PORTD) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200367 ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
368
369 return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200370 }
371 return 0;
372}
373
Christophe Leroy48f896d2017-07-06 10:33:17 +0200374static inline void iopin_set_opt2(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200375{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200376 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
377
Christophe Leroy069fa832017-07-06 10:23:22 +0200378 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200379 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
380
381 setbits_be16(sorp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200382 }
383}
384
Christophe Leroy48f896d2017-07-06 10:33:17 +0200385static inline void iopin_set_opt1(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200386{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200387 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
388
Christophe Leroy069fa832017-07-06 10:23:22 +0200389 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200390 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
391
392 clrbits_be16(sorp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200393 }
394}
395
Christophe Leroy48f896d2017-07-06 10:33:17 +0200396static inline uint iopin_is_opt2(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200397{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200398 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
399
Christophe Leroy069fa832017-07-06 10:23:22 +0200400 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200401 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
402
403 return (in_be16(sorp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200404 }
405 return 0;
406}
407
Christophe Leroy48f896d2017-07-06 10:33:17 +0200408static inline uint iopin_is_opt1(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200409{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200410 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
411
Christophe Leroy069fa832017-07-06 10:23:22 +0200412 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200413 ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
414
415 return ((in_be16(sorp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200416 }
417 return 0;
418}
419
Christophe Leroy48f896d2017-07-06 10:33:17 +0200420static inline void iopin_set_falledge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200421{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200422 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
423
Christophe Leroy069fa832017-07-06 10:23:22 +0200424 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200425 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
426
427 setbits_be16(intp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200428 }
429}
430
Christophe Leroy48f896d2017-07-06 10:33:17 +0200431static inline void iopin_set_anyedge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200432{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200433 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
434
Christophe Leroy069fa832017-07-06 10:23:22 +0200435 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200436 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
437
438 clrbits_be16(intp, 1 << (15 - iopin->pin));
Christophe Leroy069fa832017-07-06 10:23:22 +0200439 }
440}
441
Christophe Leroy48f896d2017-07-06 10:33:17 +0200442static inline uint iopin_is_falledge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200443{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200444 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
445
Christophe Leroy069fa832017-07-06 10:23:22 +0200446 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200447 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
448
449 return (in_be16(intp) >> (15 - iopin->pin)) & 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200450 }
451 return 0;
452}
453
Christophe Leroy48f896d2017-07-06 10:33:17 +0200454static inline uint iopin_is_anyedge(iopin_t *iopin)
Christophe Leroy069fa832017-07-06 10:23:22 +0200455{
Christophe Leroy394f9b32017-07-06 10:33:13 +0200456 immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
457
Christophe Leroy069fa832017-07-06 10:23:22 +0200458 if (iopin->port == IOPIN_PORTC) {
Christophe Leroy394f9b32017-07-06 10:33:13 +0200459 ushort __iomem *intp = &immap->im_ioport.iop_pcint;
460
461 return ((in_be16(intp) >> (15 - iopin->pin)) & 1) ^ 1;
Christophe Leroy069fa832017-07-06 10:23:22 +0200462 }
463 return 0;
464}
465
466#endif /* __KERNEL__ */
467
468#endif /* _ASM_IOPIN_8XX_H_ */