xref: /rk3399_rockchip-uboot/arch/powerpc/include/asm/iopin_8xx.h (revision ba3da7348ac9aaa1cc0a9ccbc8b3c9367d87ca4b)
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>
14907208c4SChristophe Leroy #include <asm/8xx_immap.h>
15*ba3da734SChristophe 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 
30907208c4SChristophe Leroy static __inline__ void
31907208c4SChristophe Leroy iopin_set_high(iopin_t *iopin)
32907208c4SChristophe Leroy {
33*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
34*ba3da734SChristophe Leroy 
35907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
36*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_padat;
37*ba3da734SChristophe Leroy 
38*ba3da734SChristophe Leroy 		setbits_be16(datp, 1 << (15 - iopin->pin));
39907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
40*ba3da734SChristophe Leroy 		uint __iomem *datp = &immap->im_cpm.cp_pbdat;
41*ba3da734SChristophe Leroy 
42*ba3da734SChristophe Leroy 		setbits_be32(datp, 1 << (31 - iopin->pin));
43907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
44*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
45*ba3da734SChristophe Leroy 
46*ba3da734SChristophe Leroy 		setbits_be16(datp, 1 << (15 - iopin->pin));
47907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
48*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pddat;
49*ba3da734SChristophe Leroy 
50*ba3da734SChristophe Leroy 		setbits_be16(datp, 1 << (15 - iopin->pin));
51907208c4SChristophe Leroy 	}
52907208c4SChristophe Leroy }
53907208c4SChristophe Leroy 
54907208c4SChristophe Leroy static __inline__ void
55907208c4SChristophe Leroy iopin_set_low(iopin_t *iopin)
56907208c4SChristophe Leroy {
57*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
58*ba3da734SChristophe Leroy 
59907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
60*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_padat;
61*ba3da734SChristophe Leroy 
62*ba3da734SChristophe Leroy 		clrbits_be16(datp, 1 << (15 - iopin->pin));
63907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
64*ba3da734SChristophe Leroy 		uint __iomem *datp = &immap->im_cpm.cp_pbdat;
65*ba3da734SChristophe Leroy 
66*ba3da734SChristophe Leroy 		clrbits_be32(datp, 1 << (31 - iopin->pin));
67907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
68*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
69*ba3da734SChristophe Leroy 
70*ba3da734SChristophe Leroy 		clrbits_be16(datp, 1 << (15 - iopin->pin));
71907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
72*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pddat;
73*ba3da734SChristophe Leroy 
74*ba3da734SChristophe Leroy 		clrbits_be16(datp, 1 << (15 - iopin->pin));
75907208c4SChristophe Leroy 	}
76907208c4SChristophe Leroy }
77907208c4SChristophe Leroy 
78907208c4SChristophe Leroy static __inline__ uint
79907208c4SChristophe Leroy iopin_is_high(iopin_t *iopin)
80907208c4SChristophe Leroy {
81*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
82*ba3da734SChristophe Leroy 
83907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
84*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_padat;
85*ba3da734SChristophe Leroy 
86*ba3da734SChristophe Leroy 		return (in_be16(datp) >> (15 - iopin->pin)) & 1;
87907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
88*ba3da734SChristophe Leroy 		uint __iomem *datp = &immap->im_cpm.cp_pbdat;
89*ba3da734SChristophe Leroy 
90*ba3da734SChristophe Leroy 		return (in_be32(datp) >> (31 - iopin->pin)) & 1;
91907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
92*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
93*ba3da734SChristophe Leroy 
94*ba3da734SChristophe Leroy 		return (in_be16(datp) >> (15 - iopin->pin)) & 1;
95907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
96*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pddat;
97*ba3da734SChristophe Leroy 
98*ba3da734SChristophe Leroy 		return (in_be16(datp) >> (15 - iopin->pin)) & 1;
99907208c4SChristophe Leroy 	}
100907208c4SChristophe Leroy 	return 0;
101907208c4SChristophe Leroy }
102907208c4SChristophe Leroy 
103907208c4SChristophe Leroy static __inline__ uint
104907208c4SChristophe Leroy iopin_is_low(iopin_t *iopin)
105907208c4SChristophe Leroy {
106*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
107*ba3da734SChristophe Leroy 
108907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
109*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_padat;
110*ba3da734SChristophe Leroy 
111*ba3da734SChristophe Leroy 		return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
112907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
113*ba3da734SChristophe Leroy 		uint __iomem *datp = &immap->im_cpm.cp_pbdat;
114*ba3da734SChristophe Leroy 
115*ba3da734SChristophe Leroy 		return ((in_be32(datp) >> (31 - iopin->pin)) & 1) ^ 1;
116907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
117*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pcdat;
118*ba3da734SChristophe Leroy 
119*ba3da734SChristophe Leroy 		return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
120907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
121*ba3da734SChristophe Leroy 		ushort __iomem *datp = &immap->im_ioport.iop_pddat;
122*ba3da734SChristophe Leroy 
123*ba3da734SChristophe Leroy 		return ((in_be16(datp) >> (15 - iopin->pin)) & 1) ^ 1;
124907208c4SChristophe Leroy 	}
125907208c4SChristophe Leroy 	return 0;
126907208c4SChristophe Leroy }
127907208c4SChristophe Leroy 
128907208c4SChristophe Leroy static __inline__ void
129907208c4SChristophe Leroy iopin_set_out(iopin_t *iopin)
130907208c4SChristophe Leroy {
131*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
132*ba3da734SChristophe Leroy 
133907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
134*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_padir;
135*ba3da734SChristophe Leroy 
136*ba3da734SChristophe Leroy 		setbits_be16(dirp, 1 << (15 - iopin->pin));
137907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
138*ba3da734SChristophe Leroy 		uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
139*ba3da734SChristophe Leroy 
140*ba3da734SChristophe Leroy 		setbits_be32(dirp, 1 << (31 - iopin->pin));
141907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
142*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
143*ba3da734SChristophe Leroy 
144*ba3da734SChristophe Leroy 		setbits_be16(dirp, 1 << (15 - iopin->pin));
145907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
146*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
147*ba3da734SChristophe Leroy 
148*ba3da734SChristophe Leroy 		setbits_be16(dirp, 1 << (15 - iopin->pin));
149907208c4SChristophe Leroy 	}
150907208c4SChristophe Leroy }
151907208c4SChristophe Leroy 
152907208c4SChristophe Leroy static __inline__ void
153907208c4SChristophe Leroy iopin_set_in(iopin_t *iopin)
154907208c4SChristophe Leroy {
155*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
156*ba3da734SChristophe Leroy 
157907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
158*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_padir;
159*ba3da734SChristophe Leroy 
160*ba3da734SChristophe Leroy 		clrbits_be16(dirp, 1 << (15 - iopin->pin));
161907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
162*ba3da734SChristophe Leroy 		uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
163*ba3da734SChristophe Leroy 
164*ba3da734SChristophe Leroy 		clrbits_be32(dirp, 1 << (31 - iopin->pin));
165907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
166*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
167*ba3da734SChristophe Leroy 
168*ba3da734SChristophe Leroy 		clrbits_be16(dirp, 1 << (15 - iopin->pin));
169907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
170*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
171*ba3da734SChristophe Leroy 
172*ba3da734SChristophe Leroy 		clrbits_be16(dirp, 1 << (15 - iopin->pin));
173907208c4SChristophe Leroy 	}
174907208c4SChristophe Leroy }
175907208c4SChristophe Leroy 
176907208c4SChristophe Leroy static __inline__ uint
177907208c4SChristophe Leroy iopin_is_out(iopin_t *iopin)
178907208c4SChristophe Leroy {
179*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
180*ba3da734SChristophe Leroy 
181907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
182*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_padir;
183*ba3da734SChristophe Leroy 
184*ba3da734SChristophe Leroy 		return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
185907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
186*ba3da734SChristophe Leroy 		uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
187*ba3da734SChristophe Leroy 
188*ba3da734SChristophe Leroy 		return (in_be32(dirp) >> (31 - iopin->pin)) & 1;
189907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
190*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
191*ba3da734SChristophe Leroy 
192*ba3da734SChristophe Leroy 		return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
193907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
194*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
195*ba3da734SChristophe Leroy 
196*ba3da734SChristophe Leroy 		return (in_be16(dirp) >> (15 - iopin->pin)) & 1;
197907208c4SChristophe Leroy 	}
198907208c4SChristophe Leroy 	return 0;
199907208c4SChristophe Leroy }
200907208c4SChristophe Leroy 
201907208c4SChristophe Leroy static __inline__ uint
202907208c4SChristophe Leroy iopin_is_in(iopin_t *iopin)
203907208c4SChristophe Leroy {
204*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
205*ba3da734SChristophe Leroy 
206907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
207*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_padir;
208*ba3da734SChristophe Leroy 
209*ba3da734SChristophe Leroy 		return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
210907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
211*ba3da734SChristophe Leroy 		uint __iomem *dirp = &immap->im_cpm.cp_pbdir;
212*ba3da734SChristophe Leroy 
213*ba3da734SChristophe Leroy 		return ((in_be32(dirp) >> (31 - iopin->pin)) & 1) ^ 1;
214907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
215*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pcdir;
216*ba3da734SChristophe Leroy 
217*ba3da734SChristophe Leroy 		return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
218907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
219*ba3da734SChristophe Leroy 		ushort __iomem *dirp = &immap->im_ioport.iop_pddir;
220*ba3da734SChristophe Leroy 
221*ba3da734SChristophe Leroy 		return ((in_be16(dirp) >> (15 - iopin->pin)) & 1) ^ 1;
222907208c4SChristophe Leroy 	}
223907208c4SChristophe Leroy 	return 0;
224907208c4SChristophe Leroy }
225907208c4SChristophe Leroy 
226907208c4SChristophe Leroy static __inline__ void
227907208c4SChristophe Leroy iopin_set_odr(iopin_t *iopin)
228907208c4SChristophe Leroy {
229*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
230*ba3da734SChristophe Leroy 
231907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
232*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
233*ba3da734SChristophe Leroy 
234*ba3da734SChristophe Leroy 		setbits_be16(odrp, 1 << (15 - iopin->pin));
235907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
236*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
237*ba3da734SChristophe Leroy 
238*ba3da734SChristophe Leroy 		setbits_be16(odrp, 1 << (31 - iopin->pin));
239907208c4SChristophe Leroy 	}
240907208c4SChristophe Leroy }
241907208c4SChristophe Leroy 
242907208c4SChristophe Leroy static __inline__ void
243907208c4SChristophe Leroy iopin_set_act(iopin_t *iopin)
244907208c4SChristophe Leroy {
245*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
246*ba3da734SChristophe Leroy 
247907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
248*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
249*ba3da734SChristophe Leroy 
250*ba3da734SChristophe Leroy 		clrbits_be16(odrp, 1 << (15 - iopin->pin));
251907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
252*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
253*ba3da734SChristophe Leroy 
254*ba3da734SChristophe Leroy 		clrbits_be16(odrp, 1 << (31 - iopin->pin));
255907208c4SChristophe Leroy 	}
256907208c4SChristophe Leroy }
257907208c4SChristophe Leroy 
258907208c4SChristophe Leroy static __inline__ uint
259907208c4SChristophe Leroy iopin_is_odr(iopin_t *iopin)
260907208c4SChristophe Leroy {
261*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
262*ba3da734SChristophe Leroy 
263907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
264*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
265*ba3da734SChristophe Leroy 
266*ba3da734SChristophe Leroy 		return (in_be16(odrp) >> (15 - iopin->pin)) & 1;
267907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
268*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
269*ba3da734SChristophe Leroy 
270*ba3da734SChristophe Leroy 		return (in_be16(odrp) >> (31 - iopin->pin)) & 1;
271907208c4SChristophe Leroy 	}
272907208c4SChristophe Leroy 	return 0;
273907208c4SChristophe Leroy }
274907208c4SChristophe Leroy 
275907208c4SChristophe Leroy static __inline__ uint
276907208c4SChristophe Leroy iopin_is_act(iopin_t *iopin)
277907208c4SChristophe Leroy {
278*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
279*ba3da734SChristophe Leroy 
280907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
281*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_ioport.iop_paodr;
282*ba3da734SChristophe Leroy 
283*ba3da734SChristophe Leroy 		return ((in_be16(odrp) >> (15 - iopin->pin)) & 1) ^ 1;
284907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
285*ba3da734SChristophe Leroy 		ushort __iomem *odrp = &immap->im_cpm.cp_pbodr;
286*ba3da734SChristophe Leroy 
287*ba3da734SChristophe Leroy 		return ((in_be16(odrp) >> (31 - iopin->pin)) & 1) ^ 1;
288907208c4SChristophe Leroy 	}
289907208c4SChristophe Leroy 	return 0;
290907208c4SChristophe Leroy }
291907208c4SChristophe Leroy 
292907208c4SChristophe Leroy static __inline__ void
293907208c4SChristophe Leroy iopin_set_ded(iopin_t *iopin)
294907208c4SChristophe Leroy {
295*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
296*ba3da734SChristophe Leroy 
297907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
298*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_papar;
299*ba3da734SChristophe Leroy 
300*ba3da734SChristophe Leroy 		setbits_be16(parp, 1 << (15 - iopin->pin));
301907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
302*ba3da734SChristophe Leroy 		uint __iomem *parp = &immap->im_cpm.cp_pbpar;
303*ba3da734SChristophe Leroy 
304*ba3da734SChristophe Leroy 		setbits_be32(parp, 1 << (31 - iopin->pin));
305907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
306*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
307*ba3da734SChristophe Leroy 
308*ba3da734SChristophe Leroy 		setbits_be16(parp, 1 << (15 - iopin->pin));
309907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
310*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
311*ba3da734SChristophe Leroy 
312*ba3da734SChristophe Leroy 		setbits_be16(parp, 1 << (15 - iopin->pin));
313907208c4SChristophe Leroy 	}
314907208c4SChristophe Leroy }
315907208c4SChristophe Leroy 
316907208c4SChristophe Leroy static __inline__ void
317907208c4SChristophe Leroy iopin_set_gen(iopin_t *iopin)
318907208c4SChristophe Leroy {
319*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
320*ba3da734SChristophe Leroy 
321907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
322*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_papar;
323*ba3da734SChristophe Leroy 
324*ba3da734SChristophe Leroy 		clrbits_be16(parp, 1 << (15 - iopin->pin));
325907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
326*ba3da734SChristophe Leroy 		uint __iomem *parp = &immap->im_cpm.cp_pbpar;
327*ba3da734SChristophe Leroy 
328*ba3da734SChristophe Leroy 		clrbits_be32(parp, 1 << (31 - iopin->pin));
329907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
330*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
331*ba3da734SChristophe Leroy 
332*ba3da734SChristophe Leroy 		clrbits_be16(parp, 1 << (15 - iopin->pin));
333907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
334*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
335*ba3da734SChristophe Leroy 
336*ba3da734SChristophe Leroy 		clrbits_be16(parp, 1 << (15 - iopin->pin));
337907208c4SChristophe Leroy 	}
338907208c4SChristophe Leroy }
339907208c4SChristophe Leroy 
340907208c4SChristophe Leroy static __inline__ uint
341907208c4SChristophe Leroy iopin_is_ded(iopin_t *iopin)
342907208c4SChristophe Leroy {
343*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
344*ba3da734SChristophe Leroy 
345907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
346*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_papar;
347*ba3da734SChristophe Leroy 
348*ba3da734SChristophe Leroy 		return (in_be16(parp) >> (15 - iopin->pin)) & 1;
349907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
350*ba3da734SChristophe Leroy 		uint __iomem *parp = &immap->im_cpm.cp_pbpar;
351*ba3da734SChristophe Leroy 
352*ba3da734SChristophe Leroy 		return (in_be32(parp) >> (31 - iopin->pin)) & 1;
353907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
354*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
355*ba3da734SChristophe Leroy 
356*ba3da734SChristophe Leroy 		return (in_be16(parp) >> (15 - iopin->pin)) & 1;
357907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
358*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
359*ba3da734SChristophe Leroy 
360*ba3da734SChristophe Leroy 		return (in_be16(parp) >> (15 - iopin->pin)) & 1;
361907208c4SChristophe Leroy 	}
362907208c4SChristophe Leroy 	return 0;
363907208c4SChristophe Leroy }
364907208c4SChristophe Leroy 
365907208c4SChristophe Leroy static __inline__ uint
366907208c4SChristophe Leroy iopin_is_gen(iopin_t *iopin)
367907208c4SChristophe Leroy {
368*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
369*ba3da734SChristophe Leroy 
370907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTA) {
371*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_papar;
372*ba3da734SChristophe Leroy 
373*ba3da734SChristophe Leroy 		return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
374907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTB) {
375*ba3da734SChristophe Leroy 		uint __iomem *parp = &immap->im_cpm.cp_pbpar;
376*ba3da734SChristophe Leroy 
377*ba3da734SChristophe Leroy 		return ((in_be32(parp) >> (31 - iopin->pin)) & 1) ^ 1;
378907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTC) {
379*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pcpar;
380*ba3da734SChristophe Leroy 
381*ba3da734SChristophe Leroy 		return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
382907208c4SChristophe Leroy 	} else if (iopin->port == IOPIN_PORTD) {
383*ba3da734SChristophe Leroy 		ushort __iomem *parp = &immap->im_ioport.iop_pdpar;
384*ba3da734SChristophe Leroy 
385*ba3da734SChristophe Leroy 		return ((in_be16(parp) >> (15 - iopin->pin)) & 1) ^ 1;
386907208c4SChristophe Leroy 	}
387907208c4SChristophe Leroy 	return 0;
388907208c4SChristophe Leroy }
389907208c4SChristophe Leroy 
390907208c4SChristophe Leroy static __inline__ void
391907208c4SChristophe Leroy iopin_set_opt2(iopin_t *iopin)
392907208c4SChristophe Leroy {
393*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
394*ba3da734SChristophe Leroy 
395907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
396*ba3da734SChristophe Leroy 		ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
397*ba3da734SChristophe Leroy 
398*ba3da734SChristophe Leroy 		setbits_be16(sorp, 1 << (15 - iopin->pin));
399907208c4SChristophe Leroy 	}
400907208c4SChristophe Leroy }
401907208c4SChristophe Leroy 
402907208c4SChristophe Leroy static __inline__ void
403907208c4SChristophe Leroy iopin_set_opt1(iopin_t *iopin)
404907208c4SChristophe Leroy {
405*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
406*ba3da734SChristophe Leroy 
407907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
408*ba3da734SChristophe Leroy 		ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
409*ba3da734SChristophe Leroy 
410*ba3da734SChristophe Leroy 		clrbits_be16(sorp, 1 << (15 - iopin->pin));
411907208c4SChristophe Leroy 	}
412907208c4SChristophe Leroy }
413907208c4SChristophe Leroy 
414907208c4SChristophe Leroy static __inline__ uint
415907208c4SChristophe Leroy iopin_is_opt2(iopin_t *iopin)
416907208c4SChristophe Leroy {
417*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
418*ba3da734SChristophe Leroy 
419907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
420*ba3da734SChristophe Leroy 		ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
421*ba3da734SChristophe Leroy 
422*ba3da734SChristophe Leroy 		return (in_be16(sorp) >> (15 - iopin->pin)) & 1;
423907208c4SChristophe Leroy 	}
424907208c4SChristophe Leroy 	return 0;
425907208c4SChristophe Leroy }
426907208c4SChristophe Leroy 
427907208c4SChristophe Leroy static __inline__ uint
428907208c4SChristophe Leroy iopin_is_opt1(iopin_t *iopin)
429907208c4SChristophe Leroy {
430*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
431*ba3da734SChristophe Leroy 
432907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
433*ba3da734SChristophe Leroy 		ushort __iomem *sorp = &immap->im_ioport.iop_pcso;
434*ba3da734SChristophe Leroy 
435*ba3da734SChristophe Leroy 		return ((in_be16(sorp) >> (15 - iopin->pin)) & 1) ^ 1;
436907208c4SChristophe Leroy 	}
437907208c4SChristophe Leroy 	return 0;
438907208c4SChristophe Leroy }
439907208c4SChristophe Leroy 
440907208c4SChristophe Leroy static __inline__ void
441907208c4SChristophe Leroy iopin_set_falledge(iopin_t *iopin)
442907208c4SChristophe Leroy {
443*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
444*ba3da734SChristophe Leroy 
445907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
446*ba3da734SChristophe Leroy 		ushort __iomem *intp = &immap->im_ioport.iop_pcint;
447*ba3da734SChristophe Leroy 
448*ba3da734SChristophe Leroy 		setbits_be16(intp, 1 << (15 - iopin->pin));
449907208c4SChristophe Leroy 	}
450907208c4SChristophe Leroy }
451907208c4SChristophe Leroy 
452907208c4SChristophe Leroy static __inline__ void
453907208c4SChristophe Leroy iopin_set_anyedge(iopin_t *iopin)
454907208c4SChristophe Leroy {
455*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
456*ba3da734SChristophe Leroy 
457907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
458*ba3da734SChristophe Leroy 		ushort __iomem *intp = &immap->im_ioport.iop_pcint;
459*ba3da734SChristophe Leroy 
460*ba3da734SChristophe Leroy 		clrbits_be16(intp, 1 << (15 - iopin->pin));
461907208c4SChristophe Leroy 	}
462907208c4SChristophe Leroy }
463907208c4SChristophe Leroy 
464907208c4SChristophe Leroy static __inline__ uint
465907208c4SChristophe Leroy iopin_is_falledge(iopin_t *iopin)
466907208c4SChristophe Leroy {
467*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
468*ba3da734SChristophe Leroy 
469907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
470*ba3da734SChristophe Leroy 		ushort __iomem *intp = &immap->im_ioport.iop_pcint;
471*ba3da734SChristophe Leroy 
472*ba3da734SChristophe Leroy 		return (in_be16(intp) >> (15 - iopin->pin)) & 1;
473907208c4SChristophe Leroy 	}
474907208c4SChristophe Leroy 	return 0;
475907208c4SChristophe Leroy }
476907208c4SChristophe Leroy 
477907208c4SChristophe Leroy static __inline__ uint
478907208c4SChristophe Leroy iopin_is_anyedge(iopin_t *iopin)
479907208c4SChristophe Leroy {
480*ba3da734SChristophe Leroy 	immap_t __iomem *immap = (immap_t __iomem *)CONFIG_SYS_IMMR;
481*ba3da734SChristophe Leroy 
482907208c4SChristophe Leroy 	if (iopin->port == IOPIN_PORTC) {
483*ba3da734SChristophe Leroy 		ushort __iomem *intp = &immap->im_ioport.iop_pcint;
484*ba3da734SChristophe Leroy 
485*ba3da734SChristophe Leroy 		return ((in_be16(intp) >> (15 - iopin->pin)) & 1) ^ 1;
486907208c4SChristophe Leroy 	}
487907208c4SChristophe Leroy 	return 0;
488907208c4SChristophe Leroy }
489907208c4SChristophe Leroy 
490907208c4SChristophe Leroy #endif /* __KERNEL__ */
491907208c4SChristophe Leroy 
492907208c4SChristophe Leroy #endif /* _ASM_IOPIN_8XX_H_ */
493