1907208c4SChristophe Leroy /*
2907208c4SChristophe Leroy * SPDX-License-Identifier: GPL-2.0+
3907208c4SChristophe Leroy */
4907208c4SChristophe Leroy
5907208c4SChristophe Leroy /*
6907208c4SChristophe Leroy * MPC8xx I/O port pin manipulation functions
7907208c4SChristophe Leroy * Roughly based on iopin_8260.h
8907208c4SChristophe Leroy */
9907208c4SChristophe Leroy
10907208c4SChristophe Leroy #ifndef _ASM_IOPIN_8XX_H_
11907208c4SChristophe Leroy #define _ASM_IOPIN_8XX_H_
12907208c4SChristophe Leroy
13907208c4SChristophe Leroy #include <linux/types.h>
14*87e4c602SChristophe Leroy #include <asm/immap_8xx.h>
15ba3da734SChristophe Leroy #include <asm/io.h>
16907208c4SChristophe Leroy
17907208c4SChristophe Leroy #ifdef __KERNEL__
18907208c4SChristophe Leroy
19907208c4SChristophe Leroy typedef struct {
20907208c4SChristophe Leroy u_char port:2; /* port number (A=0, B=1, C=2, D=3) */
21907208c4SChristophe Leroy u_char pin:5; /* port pin (0-31) */
22907208c4SChristophe Leroy u_char flag:1; /* for whatever */
23907208c4SChristophe Leroy } iopin_t;
24907208c4SChristophe Leroy
25907208c4SChristophe Leroy #define IOPIN_PORTA 0
26907208c4SChristophe Leroy #define IOPIN_PORTB 1
27907208c4SChristophe Leroy #define IOPIN_PORTC 2
28907208c4SChristophe Leroy #define IOPIN_PORTD 3
29907208c4SChristophe Leroy
iopin_set_high(iopin_t * iopin)3070fd0710SChristophe Leroy static inline void iopin_set_high(iopin_t *iopin)
31907208c4SChristophe Leroy {
32ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
33ba3da734SChristophe Leroy
34907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
35ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_padat;
36ba3da734SChristophe Leroy
37ba3da734SChristophe Leroy setbits_be16(datp, 1 << (15 - iopin->pin));
38907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
39ba3da734SChristophe Leroy uint __iomem *datp = &immap->im_cpm.cp_pbdat;
40ba3da734SChristophe Leroy
41ba3da734SChristophe Leroy setbits_be32(datp, 1 << (31 - iopin->pin));
42907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
43ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
44ba3da734SChristophe Leroy
45ba3da734SChristophe Leroy setbits_be16(datp, 1 << (15 - iopin->pin));
46907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
47ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pddat;
48ba3da734SChristophe Leroy
49ba3da734SChristophe Leroy setbits_be16(datp, 1 << (15 - iopin->pin));
50907208c4SChristophe Leroy }
51907208c4SChristophe Leroy }
52907208c4SChristophe Leroy
iopin_set_low(iopin_t * iopin)5370fd0710SChristophe Leroy static inline void iopin_set_low(iopin_t *iopin)
54907208c4SChristophe Leroy {
55ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
56ba3da734SChristophe Leroy
57907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
58ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_padat;
59ba3da734SChristophe Leroy
60ba3da734SChristophe Leroy clrbits_be16(datp, 1 << (15 - iopin->pin));
61907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
62ba3da734SChristophe Leroy uint __iomem *datp = &immap->im_cpm.cp_pbdat;
63ba3da734SChristophe Leroy
64ba3da734SChristophe Leroy clrbits_be32(datp, 1 << (31 - iopin->pin));
65907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
66ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
67ba3da734SChristophe Leroy
68ba3da734SChristophe Leroy clrbits_be16(datp, 1 << (15 - iopin->pin));
69907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
70ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pddat;
71ba3da734SChristophe Leroy
72ba3da734SChristophe Leroy clrbits_be16(datp, 1 << (15 - iopin->pin));
73907208c4SChristophe Leroy }
74907208c4SChristophe Leroy }
75907208c4SChristophe Leroy
iopin_is_high(iopin_t * iopin)7670fd0710SChristophe Leroy static inline uint iopin_is_high(iopin_t *iopin)
77907208c4SChristophe Leroy {
78ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
79ba3da734SChristophe Leroy
80907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
81ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_padat;
82ba3da734SChristophe Leroy
83ba3da734SChristophe Leroy return (in_be16(datp) >> (15 - iopin->pin)) & 1;
84907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
85ba3da734SChristophe Leroy uint __iomem *datp = &immap->im_cpm.cp_pbdat;
86ba3da734SChristophe Leroy
87ba3da734SChristophe Leroy return (in_be32(datp) >> (31 - iopin->pin)) & 1;
88907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
89ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
90ba3da734SChristophe Leroy
91ba3da734SChristophe Leroy return (in_be16(datp) >> (15 - iopin->pin)) & 1;
92907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
93ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pddat;
94ba3da734SChristophe Leroy
95ba3da734SChristophe Leroy return (in_be16(datp) >> (15 - iopin->pin)) & 1;
96907208c4SChristophe Leroy }
97907208c4SChristophe Leroy return 0;
98907208c4SChristophe Leroy }
99907208c4SChristophe Leroy
iopin_is_low(iopin_t * iopin)10070fd0710SChristophe Leroy static inline uint iopin_is_low(iopin_t *iopin)
101907208c4SChristophe Leroy {
102ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
103ba3da734SChristophe Leroy
104907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
105ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_padat;
106ba3da734SChristophe Leroy
107ba3da734SChristophe Leroy return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
108907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
109ba3da734SChristophe Leroy uint __iomem *datp = &immap->im_cpm.cp_pbdat;
110ba3da734SChristophe Leroy
111ba3da734SChristophe Leroy return ((in_be32(datp) >> (31 - iopin->pin)) & 1) ^ 1;
112907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
113ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
114ba3da734SChristophe Leroy
115ba3da734SChristophe Leroy return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
116907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
117ba3da734SChristophe Leroy ushort __iomem *datp = &immap->im_ioport.iop_pddat;
118ba3da734SChristophe Leroy
119ba3da734SChristophe Leroy return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
120907208c4SChristophe Leroy }
121907208c4SChristophe Leroy return 0;
122907208c4SChristophe Leroy }
123907208c4SChristophe Leroy
iopin_set_out(iopin_t * iopin)12470fd0710SChristophe Leroy static inline void iopin_set_out(iopin_t *iopin)
125907208c4SChristophe Leroy {
126ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
127ba3da734SChristophe Leroy
128907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
129ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_padir;
130ba3da734SChristophe Leroy
131ba3da734SChristophe Leroy setbits_be16(dirp, 1 << (15 - iopin->pin));
132907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
133ba3da734SChristophe Leroy uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
134ba3da734SChristophe Leroy
135ba3da734SChristophe Leroy setbits_be32(dirp, 1 << (31 - iopin->pin));
136907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
137ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
138ba3da734SChristophe Leroy
139ba3da734SChristophe Leroy setbits_be16(dirp, 1 << (15 - iopin->pin));
140907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
141ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
142ba3da734SChristophe Leroy
143ba3da734SChristophe Leroy setbits_be16(dirp, 1 << (15 - iopin->pin));
144907208c4SChristophe Leroy }
145907208c4SChristophe Leroy }
146907208c4SChristophe Leroy
iopin_set_in(iopin_t * iopin)14770fd0710SChristophe Leroy static inline void iopin_set_in(iopin_t *iopin)
148907208c4SChristophe Leroy {
149ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
150ba3da734SChristophe Leroy
151907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
152ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_padir;
153ba3da734SChristophe Leroy
154ba3da734SChristophe Leroy clrbits_be16(dirp, 1 << (15 - iopin->pin));
155907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
156ba3da734SChristophe Leroy uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
157ba3da734SChristophe Leroy
158ba3da734SChristophe Leroy clrbits_be32(dirp, 1 << (31 - iopin->pin));
159907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
160ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
161ba3da734SChristophe Leroy
162ba3da734SChristophe Leroy clrbits_be16(dirp, 1 << (15 - iopin->pin));
163907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
164ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
165ba3da734SChristophe Leroy
166ba3da734SChristophe Leroy clrbits_be16(dirp, 1 << (15 - iopin->pin));
167907208c4SChristophe Leroy }
168907208c4SChristophe Leroy }
169907208c4SChristophe Leroy
iopin_is_out(iopin_t * iopin)17070fd0710SChristophe Leroy static inline uint iopin_is_out(iopin_t *iopin)
171907208c4SChristophe Leroy {
172ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
173ba3da734SChristophe Leroy
174907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
175ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_padir;
176ba3da734SChristophe Leroy
177ba3da734SChristophe Leroy return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
178907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
179ba3da734SChristophe Leroy uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
180ba3da734SChristophe Leroy
181ba3da734SChristophe Leroy return (in_be32(dirp) >> (31 - iopin->pin)) & 1;
182907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
183ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
184ba3da734SChristophe Leroy
185ba3da734SChristophe Leroy return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
186907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
187ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
188ba3da734SChristophe Leroy
189ba3da734SChristophe Leroy return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
190907208c4SChristophe Leroy }
191907208c4SChristophe Leroy return 0;
192907208c4SChristophe Leroy }
193907208c4SChristophe Leroy
iopin_is_in(iopin_t * iopin)19470fd0710SChristophe Leroy static inline uint iopin_is_in(iopin_t *iopin)
195907208c4SChristophe Leroy {
196ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
197ba3da734SChristophe Leroy
198907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
199ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_padir;
200ba3da734SChristophe Leroy
201ba3da734SChristophe Leroy return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
202907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
203ba3da734SChristophe Leroy uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
204ba3da734SChristophe Leroy
205ba3da734SChristophe Leroy return ((in_be32(dirp) >> (31 - iopin->pin)) & 1) ^ 1;
206907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
207ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
208ba3da734SChristophe Leroy
209ba3da734SChristophe Leroy return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
210907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
211ba3da734SChristophe Leroy ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
212ba3da734SChristophe Leroy
213ba3da734SChristophe Leroy return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
214907208c4SChristophe Leroy }
215907208c4SChristophe Leroy return 0;
216907208c4SChristophe Leroy }
217907208c4SChristophe Leroy
iopin_set_odr(iopin_t * iopin)21870fd0710SChristophe Leroy static inline void iopin_set_odr(iopin_t *iopin)
219907208c4SChristophe Leroy {
220ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
221ba3da734SChristophe Leroy
222907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
223ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
224ba3da734SChristophe Leroy
225ba3da734SChristophe Leroy setbits_be16(odrp, 1 << (15 - iopin->pin));
226907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
227ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
228ba3da734SChristophe Leroy
229ba3da734SChristophe Leroy setbits_be16(odrp, 1 << (31 - iopin->pin));
230907208c4SChristophe Leroy }
231907208c4SChristophe Leroy }
232907208c4SChristophe Leroy
iopin_set_act(iopin_t * iopin)23370fd0710SChristophe Leroy static inline void iopin_set_act(iopin_t *iopin)
234907208c4SChristophe Leroy {
235ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
236ba3da734SChristophe Leroy
237907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
238ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
239ba3da734SChristophe Leroy
240ba3da734SChristophe Leroy clrbits_be16(odrp, 1 << (15 - iopin->pin));
241907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
242ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
243ba3da734SChristophe Leroy
244ba3da734SChristophe Leroy clrbits_be16(odrp, 1 << (31 - iopin->pin));
245907208c4SChristophe Leroy }
246907208c4SChristophe Leroy }
247907208c4SChristophe Leroy
iopin_is_odr(iopin_t * iopin)24870fd0710SChristophe Leroy static inline uint iopin_is_odr(iopin_t *iopin)
249907208c4SChristophe Leroy {
250ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
251ba3da734SChristophe Leroy
252907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
253ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
254ba3da734SChristophe Leroy
255ba3da734SChristophe Leroy return (in_be16(odrp) >> (15 - iopin->pin)) & 1;
256907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
257ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
258ba3da734SChristophe Leroy
259ba3da734SChristophe Leroy return (in_be16(odrp) >> (31 - iopin->pin)) & 1;
260907208c4SChristophe Leroy }
261907208c4SChristophe Leroy return 0;
262907208c4SChristophe Leroy }
263907208c4SChristophe Leroy
iopin_is_act(iopin_t * iopin)26470fd0710SChristophe Leroy static inline uint iopin_is_act(iopin_t *iopin)
265907208c4SChristophe Leroy {
266ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
267ba3da734SChristophe Leroy
268907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
269ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
270ba3da734SChristophe Leroy
271ba3da734SChristophe Leroy return ((in_be16(odrp) >> (15 - iopin->pin)) & 1) ^ 1;
272907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
273ba3da734SChristophe Leroy ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
274ba3da734SChristophe Leroy
275ba3da734SChristophe Leroy return ((in_be16(odrp) >> (31 - iopin->pin)) & 1) ^ 1;
276907208c4SChristophe Leroy }
277907208c4SChristophe Leroy return 0;
278907208c4SChristophe Leroy }
279907208c4SChristophe Leroy
iopin_set_ded(iopin_t * iopin)28070fd0710SChristophe Leroy static inline void iopin_set_ded(iopin_t *iopin)
281907208c4SChristophe Leroy {
282ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
283ba3da734SChristophe Leroy
284907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
285ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_papar;
286ba3da734SChristophe Leroy
287ba3da734SChristophe Leroy setbits_be16(parp, 1 << (15 - iopin->pin));
288907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
289ba3da734SChristophe Leroy uint __iomem *parp = &immap->im_cpm.cp_pbpar;
290ba3da734SChristophe Leroy
291ba3da734SChristophe Leroy setbits_be32(parp, 1 << (31 - iopin->pin));
292907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
293ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
294ba3da734SChristophe Leroy
295ba3da734SChristophe Leroy setbits_be16(parp, 1 << (15 - iopin->pin));
296907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
297ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
298ba3da734SChristophe Leroy
299ba3da734SChristophe Leroy setbits_be16(parp, 1 << (15 - iopin->pin));
300907208c4SChristophe Leroy }
301907208c4SChristophe Leroy }
302907208c4SChristophe Leroy
iopin_set_gen(iopin_t * iopin)30370fd0710SChristophe Leroy static inline void iopin_set_gen(iopin_t *iopin)
304907208c4SChristophe Leroy {
305ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
306ba3da734SChristophe Leroy
307907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
308ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_papar;
309ba3da734SChristophe Leroy
310ba3da734SChristophe Leroy clrbits_be16(parp, 1 << (15 - iopin->pin));
311907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
312ba3da734SChristophe Leroy uint __iomem *parp = &immap->im_cpm.cp_pbpar;
313ba3da734SChristophe Leroy
314ba3da734SChristophe Leroy clrbits_be32(parp, 1 << (31 - iopin->pin));
315907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
316ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
317ba3da734SChristophe Leroy
318ba3da734SChristophe Leroy clrbits_be16(parp, 1 << (15 - iopin->pin));
319907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
320ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
321ba3da734SChristophe Leroy
322ba3da734SChristophe Leroy clrbits_be16(parp, 1 << (15 - iopin->pin));
323907208c4SChristophe Leroy }
324907208c4SChristophe Leroy }
325907208c4SChristophe Leroy
iopin_is_ded(iopin_t * iopin)32670fd0710SChristophe Leroy static inline uint iopin_is_ded(iopin_t *iopin)
327907208c4SChristophe Leroy {
328ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
329ba3da734SChristophe Leroy
330907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
331ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_papar;
332ba3da734SChristophe Leroy
333ba3da734SChristophe Leroy return (in_be16(parp) >> (15 - iopin->pin)) & 1;
334907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
335ba3da734SChristophe Leroy uint __iomem *parp = &immap->im_cpm.cp_pbpar;
336ba3da734SChristophe Leroy
337ba3da734SChristophe Leroy return (in_be32(parp) >> (31 - iopin->pin)) & 1;
338907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
339ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
340ba3da734SChristophe Leroy
341ba3da734SChristophe Leroy return (in_be16(parp) >> (15 - iopin->pin)) & 1;
342907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
343ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
344ba3da734SChristophe Leroy
345ba3da734SChristophe Leroy return (in_be16(parp) >> (15 - iopin->pin)) & 1;
346907208c4SChristophe Leroy }
347907208c4SChristophe Leroy return 0;
348907208c4SChristophe Leroy }
349907208c4SChristophe Leroy
iopin_is_gen(iopin_t * iopin)35070fd0710SChristophe Leroy static inline uint iopin_is_gen(iopin_t *iopin)
351907208c4SChristophe Leroy {
352ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
353ba3da734SChristophe Leroy
354907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTA) {
355ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_papar;
356ba3da734SChristophe Leroy
357ba3da734SChristophe Leroy return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
358907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTB) {
359ba3da734SChristophe Leroy uint __iomem *parp = &immap->im_cpm.cp_pbpar;
360ba3da734SChristophe Leroy
361ba3da734SChristophe Leroy return ((in_be32(parp) >> (31 - iopin->pin)) & 1) ^ 1;
362907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTC) {
363ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
364ba3da734SChristophe Leroy
365ba3da734SChristophe Leroy return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
366907208c4SChristophe Leroy } else if (iopin->port == IOPIN_PORTD) {
367ba3da734SChristophe Leroy ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
368ba3da734SChristophe Leroy
369ba3da734SChristophe Leroy return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
370907208c4SChristophe Leroy }
371907208c4SChristophe Leroy return 0;
372907208c4SChristophe Leroy }
373907208c4SChristophe Leroy
iopin_set_opt2(iopin_t * iopin)37470fd0710SChristophe Leroy static inline void iopin_set_opt2(iopin_t *iopin)
375907208c4SChristophe Leroy {
376ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
377ba3da734SChristophe Leroy
378907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
379ba3da734SChristophe Leroy ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
380ba3da734SChristophe Leroy
381ba3da734SChristophe Leroy setbits_be16(sorp, 1 << (15 - iopin->pin));
382907208c4SChristophe Leroy }
383907208c4SChristophe Leroy }
384907208c4SChristophe Leroy
iopin_set_opt1(iopin_t * iopin)38570fd0710SChristophe Leroy static inline void iopin_set_opt1(iopin_t *iopin)
386907208c4SChristophe Leroy {
387ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
388ba3da734SChristophe Leroy
389907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
390ba3da734SChristophe Leroy ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
391ba3da734SChristophe Leroy
392ba3da734SChristophe Leroy clrbits_be16(sorp, 1 << (15 - iopin->pin));
393907208c4SChristophe Leroy }
394907208c4SChristophe Leroy }
395907208c4SChristophe Leroy
iopin_is_opt2(iopin_t * iopin)39670fd0710SChristophe Leroy static inline uint iopin_is_opt2(iopin_t *iopin)
397907208c4SChristophe Leroy {
398ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
399ba3da734SChristophe Leroy
400907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
401ba3da734SChristophe Leroy ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
402ba3da734SChristophe Leroy
403ba3da734SChristophe Leroy return (in_be16(sorp) >> (15 - iopin->pin)) & 1;
404907208c4SChristophe Leroy }
405907208c4SChristophe Leroy return 0;
406907208c4SChristophe Leroy }
407907208c4SChristophe Leroy
iopin_is_opt1(iopin_t * iopin)40870fd0710SChristophe Leroy static inline uint iopin_is_opt1(iopin_t *iopin)
409907208c4SChristophe Leroy {
410ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
411ba3da734SChristophe Leroy
412907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
413ba3da734SChristophe Leroy ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
414ba3da734SChristophe Leroy
415ba3da734SChristophe Leroy return ((in_be16(sorp) >> (15 - iopin->pin)) & 1) ^ 1;
416907208c4SChristophe Leroy }
417907208c4SChristophe Leroy return 0;
418907208c4SChristophe Leroy }
419907208c4SChristophe Leroy
iopin_set_falledge(iopin_t * iopin)42070fd0710SChristophe Leroy static inline void iopin_set_falledge(iopin_t *iopin)
421907208c4SChristophe Leroy {
422ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
423ba3da734SChristophe Leroy
424907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
425ba3da734SChristophe Leroy ushort __iomem *intp = &immap->im_ioport.iop_pcint;
426ba3da734SChristophe Leroy
427ba3da734SChristophe Leroy setbits_be16(intp, 1 << (15 - iopin->pin));
428907208c4SChristophe Leroy }
429907208c4SChristophe Leroy }
430907208c4SChristophe Leroy
iopin_set_anyedge(iopin_t * iopin)43170fd0710SChristophe Leroy static inline void iopin_set_anyedge(iopin_t *iopin)
432907208c4SChristophe Leroy {
433ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
434ba3da734SChristophe Leroy
435907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
436ba3da734SChristophe Leroy ushort __iomem *intp = &immap->im_ioport.iop_pcint;
437ba3da734SChristophe Leroy
438ba3da734SChristophe Leroy clrbits_be16(intp, 1 << (15 - iopin->pin));
439907208c4SChristophe Leroy }
440907208c4SChristophe Leroy }
441907208c4SChristophe Leroy
iopin_is_falledge(iopin_t * iopin)44270fd0710SChristophe Leroy static inline uint iopin_is_falledge(iopin_t *iopin)
443907208c4SChristophe Leroy {
444ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
445ba3da734SChristophe Leroy
446907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
447ba3da734SChristophe Leroy ushort __iomem *intp = &immap->im_ioport.iop_pcint;
448ba3da734SChristophe Leroy
449ba3da734SChristophe Leroy return (in_be16(intp) >> (15 - iopin->pin)) & 1;
450907208c4SChristophe Leroy }
451907208c4SChristophe Leroy return 0;
452907208c4SChristophe Leroy }
453907208c4SChristophe Leroy
iopin_is_anyedge(iopin_t * iopin)45470fd0710SChristophe Leroy static inline uint iopin_is_anyedge(iopin_t *iopin)
455907208c4SChristophe Leroy {
456ba3da734SChristophe Leroy immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
457ba3da734SChristophe Leroy
458907208c4SChristophe Leroy if (iopin->port == IOPIN_PORTC) {
459ba3da734SChristophe Leroy ushort __iomem *intp = &immap->im_ioport.iop_pcint;
460ba3da734SChristophe Leroy
461ba3da734SChristophe Leroy return ((in_be16(intp) >> (15 - iopin->pin)) & 1) ^ 1;
462907208c4SChristophe Leroy }
463907208c4SChristophe Leroy return 0;
464907208c4SChristophe Leroy }
465907208c4SChristophe Leroy
466907208c4SChristophe Leroy #endif /* __KERNEL__ */
467907208c4SChristophe Leroy
468907208c4SChristophe Leroy #endif /* _ASM_IOPIN_8XX_H_ */
469