]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/glsdk-u-boot.git/blob - arch/powerpc/include/asm/iopin_8xx.h
nios2: Move individual board linker scripts to common script in cpu tree.
[glsdk/glsdk-u-boot.git] / arch / powerpc / include / asm / iopin_8xx.h
1 /*
2  * See file CREDITS for list of people who contributed to this
3  * project.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18  * MA 02111-1307 USA
19  */
21 /*
22  * MPC8xx I/O port pin manipulation functions
23  * Roughly based on iopin_8260.h
24  */
26 #ifndef _ASM_IOPIN_8XX_H_
27 #define _ASM_IOPIN_8XX_H_
29 #include <linux/types.h>
30 #include <asm/8xx_immap.h>
32 #ifdef __KERNEL__
34 typedef struct {
35         u_char port:2;  /* port number (A=0, B=1, C=2, D=3) */
36         u_char pin:5;   /* port pin (0-31) */
37         u_char flag:1;  /* for whatever */
38 } iopin_t;
40 #define IOPIN_PORTA     0
41 #define IOPIN_PORTB     1
42 #define IOPIN_PORTC     2
43 #define IOPIN_PORTD     3
45 extern __inline__ void
46 iopin_set_high(iopin_t *iopin)
47 {
48         if (iopin->port == IOPIN_PORTA) {
49                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
50                 *datp |= (1 << (15 - iopin->pin));
51         } else if (iopin->port == IOPIN_PORTB) {
52                 volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
53                 *datp |= (1 << (31 - iopin->pin));
54         } else if (iopin->port == IOPIN_PORTC) {
55                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
56                 *datp |= (1 << (15 - iopin->pin));
57         } else if (iopin->port == IOPIN_PORTD) {
58                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
59                 *datp |= (1 << (15 - iopin->pin));
60         }
61 }
63 extern __inline__ void
64 iopin_set_low(iopin_t *iopin)
65 {
66         if (iopin->port == IOPIN_PORTA) {
67                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
68                 *datp &= ~(1 << (15 - iopin->pin));
69         } else if (iopin->port == IOPIN_PORTB) {
70                 volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
71                 *datp &= ~(1 << (31 - iopin->pin));
72         } else if (iopin->port == IOPIN_PORTC) {
73                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
74                 *datp &= ~(1 << (15 - iopin->pin));
75         } else if (iopin->port == IOPIN_PORTD) {
76                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
77                 *datp &= ~(1 << (15 - iopin->pin));
78         }
79 }
81 extern __inline__ uint
82 iopin_is_high(iopin_t *iopin)
83 {
84         if (iopin->port == IOPIN_PORTA) {
85                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
86                 return (*datp >> (15 - iopin->pin)) & 1;
87         } else if (iopin->port == IOPIN_PORTB) {
88                 volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
89                 return (*datp >> (31 - iopin->pin)) & 1;
90         } else if (iopin->port == IOPIN_PORTC) {
91                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
92                 return (*datp >> (15 - iopin->pin)) & 1;
93         } else if (iopin->port == IOPIN_PORTD) {
94                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
95                 return (*datp >> (15 - iopin->pin)) & 1;
96         }
97         return 0;
98 }
100 extern __inline__ uint
101 iopin_is_low(iopin_t *iopin)
103         if (iopin->port == IOPIN_PORTA) {
104                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padat;
105                 return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
106         } else if (iopin->port == IOPIN_PORTB) {
107                 volatile uint *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdat;
108                 return ((*datp >> (31 - iopin->pin)) & 1) ^ 1;
109         } else if (iopin->port == IOPIN_PORTC) {
110                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdat;
111                 return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
112         } else if (iopin->port == IOPIN_PORTD) {
113                 volatile ushort *datp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat;
114                 return ((*datp >> (15 - iopin->pin)) & 1) ^ 1;
115         }
116         return 0;
119 extern __inline__ void
120 iopin_set_out(iopin_t *iopin)
122         if (iopin->port == IOPIN_PORTA) {
123                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
124                 *dirp |= (1 << (15 - iopin->pin));
125         } else if (iopin->port == IOPIN_PORTB) {
126                 volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
127                 *dirp |= (1 << (31 - iopin->pin));
128         } else if (iopin->port == IOPIN_PORTC) {
129                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
130                 *dirp |= (1 << (15 - iopin->pin));
131         } else if (iopin->port == IOPIN_PORTD) {
132                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
133                 *dirp |= (1 << (15 - iopin->pin));
134         }
137 extern __inline__ void
138 iopin_set_in(iopin_t *iopin)
140         if (iopin->port == IOPIN_PORTA) {
141                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
142                 *dirp &= ~(1 << (15 - iopin->pin));
143         } else if (iopin->port == IOPIN_PORTB) {
144                 volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
145                 *dirp &= ~(1 << (31 - iopin->pin));
146         } else if (iopin->port == IOPIN_PORTC) {
147                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
148                 *dirp &= ~(1 << (15 - iopin->pin));
149         } else if (iopin->port == IOPIN_PORTD) {
150                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
151                 *dirp &= ~(1 << (15 - iopin->pin));
152         }
155 extern __inline__ uint
156 iopin_is_out(iopin_t *iopin)
158         if (iopin->port == IOPIN_PORTA) {
159                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
160                 return (*dirp >> (15 - iopin->pin)) & 1;
161         } else if (iopin->port == IOPIN_PORTB) {
162                 volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
163                 return (*dirp >> (31 - iopin->pin)) & 1;
164         } else if (iopin->port == IOPIN_PORTC) {
165                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
166                 return (*dirp >> (15 - iopin->pin)) & 1;
167         } else if (iopin->port == IOPIN_PORTD) {
168                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
169                 return (*dirp >> (15 - iopin->pin)) & 1;
170         }
171         return 0;
174 extern __inline__ uint
175 iopin_is_in(iopin_t *iopin)
177         if (iopin->port == IOPIN_PORTA) {
178                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_padir;
179                 return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
180         } else if (iopin->port == IOPIN_PORTB) {
181                 volatile uint *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbdir;
182                 return ((*dirp >> (31 - iopin->pin)) & 1) ^ 1;
183         } else if (iopin->port == IOPIN_PORTC) {
184                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcdir;
185                 return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
186         } else if (iopin->port == IOPIN_PORTD) {
187                 volatile ushort *dirp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir;
188                 return ((*dirp >> (15 - iopin->pin)) & 1) ^ 1;
189         }
190         return 0;
193 extern __inline__ void
194 iopin_set_odr(iopin_t *iopin)
196         if (iopin->port == IOPIN_PORTA) {
197                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
198                 *odrp |= (1 << (15 - iopin->pin));
199         } else if (iopin->port == IOPIN_PORTB) {
200                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
201                 *odrp |= (1 << (31 - iopin->pin));
202         }
205 extern __inline__ void
206 iopin_set_act(iopin_t *iopin)
208         if (iopin->port == IOPIN_PORTA) {
209                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
210                 *odrp &= ~(1 << (15 - iopin->pin));
211         } else if (iopin->port == IOPIN_PORTB) {
212                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
213                 *odrp &= ~(1 << (31 - iopin->pin));
214         }
217 extern __inline__ uint
218 iopin_is_odr(iopin_t *iopin)
220         if (iopin->port == IOPIN_PORTA) {
221                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
222                 return (*odrp >> (15 - iopin->pin)) & 1;
223         } else if (iopin->port == IOPIN_PORTB) {
224                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
225                 return (*odrp >> (31 - iopin->pin)) & 1;
226         }
227         return 0;
230 extern __inline__ uint
231 iopin_is_act(iopin_t *iopin)
233         if (iopin->port == IOPIN_PORTA) {
234                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_paodr;
235                 return ((*odrp >> (15 - iopin->pin)) & 1) ^ 1;
236         } else if (iopin->port == IOPIN_PORTB) {
237                 volatile ushort *odrp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbodr;
238                 return ((*odrp >> (31 - iopin->pin)) & 1) ^ 1;
239         }
240         return 0;
243 extern __inline__ void
244 iopin_set_ded(iopin_t *iopin)
246         if (iopin->port == IOPIN_PORTA) {
247                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
248                 *parp |= (1 << (15 - iopin->pin));
249         } else if (iopin->port == IOPIN_PORTB) {
250                 volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
251                 *parp |= (1 << (31 - iopin->pin));
252         } else if (iopin->port == IOPIN_PORTC) {
253                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
254                 *parp |= (1 << (15 - iopin->pin));
255         } else if (iopin->port == IOPIN_PORTD) {
256                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
257                 *parp |= (1 << (15 - iopin->pin));
258         }
261 extern __inline__ void
262 iopin_set_gen(iopin_t *iopin)
264         if (iopin->port == IOPIN_PORTA) {
265                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
266                 *parp &= ~(1 << (15 - iopin->pin));
267         } else if (iopin->port == IOPIN_PORTB) {
268                 volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
269                 *parp &= ~(1 << (31 - iopin->pin));
270         } else if (iopin->port == IOPIN_PORTC) {
271                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
272                 *parp &= ~(1 << (15 - iopin->pin));
273         } else if (iopin->port == IOPIN_PORTD) {
274                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
275                 *parp &= ~(1 << (15 - iopin->pin));
276         }
279 extern __inline__ uint
280 iopin_is_ded(iopin_t *iopin)
282         if (iopin->port == IOPIN_PORTA) {
283                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
284                 return (*parp >> (15 - iopin->pin)) & 1;
285         } else if (iopin->port == IOPIN_PORTB) {
286                 volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
287                 return (*parp >> (31 - iopin->pin)) & 1;
288         } else if (iopin->port == IOPIN_PORTC) {
289                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
290                 return (*parp >> (15 - iopin->pin)) & 1;
291         } else if (iopin->port == IOPIN_PORTD) {
292                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
293                 return (*parp >> (15 - iopin->pin)) & 1;
294         }
295         return 0;
298 extern __inline__ uint
299 iopin_is_gen(iopin_t *iopin)
301         if (iopin->port == IOPIN_PORTA) {
302                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_papar;
303                 return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
304         } else if (iopin->port == IOPIN_PORTB) {
305                 volatile uint *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_cpm.cp_pbpar;
306                 return ((*parp >> (31 - iopin->pin)) & 1) ^ 1;
307         } else if (iopin->port == IOPIN_PORTC) {
308                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcpar;
309                 return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
310         } else if (iopin->port == IOPIN_PORTD) {
311                 volatile ushort *parp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar;
312                 return ((*parp >> (15 - iopin->pin)) & 1) ^ 1;
313         }
314         return 0;
317 extern __inline__ void
318 iopin_set_opt2(iopin_t *iopin)
320         if (iopin->port == IOPIN_PORTC) {
321                 volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
322                 *sorp |= (1 << (15 - iopin->pin));
323         }
326 extern __inline__ void
327 iopin_set_opt1(iopin_t *iopin)
329         if (iopin->port == IOPIN_PORTC) {
330                 volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
331                 *sorp &= ~(1 << (15 - iopin->pin));
332         }
335 extern __inline__ uint
336 iopin_is_opt2(iopin_t *iopin)
338         if (iopin->port == IOPIN_PORTC) {
339                 volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
340                 return (*sorp >> (15 - iopin->pin)) & 1;
341         }
342         return 0;
345 extern __inline__ uint
346 iopin_is_opt1(iopin_t *iopin)
348         if (iopin->port == IOPIN_PORTC) {
349                 volatile ushort *sorp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcso;
350                 return ((*sorp >> (15 - iopin->pin)) & 1) ^ 1;
351         }
352         return 0;
355 extern __inline__ void
356 iopin_set_falledge(iopin_t *iopin)
358         if (iopin->port == IOPIN_PORTC) {
359                 volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
360                 *intp |= (1 << (15 - iopin->pin));
361         }
364 extern __inline__ void
365 iopin_set_anyedge(iopin_t *iopin)
367         if (iopin->port == IOPIN_PORTC) {
368                 volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
369                 *intp &= ~(1 << (15 - iopin->pin));
370         }
373 extern __inline__ uint
374 iopin_is_falledge(iopin_t *iopin)
376         if (iopin->port == IOPIN_PORTC) {
377                 volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
378                 return (*intp >> (15 - iopin->pin)) & 1;
379         }
380         return 0;
383 extern __inline__ uint
384 iopin_is_anyedge(iopin_t *iopin)
386         if (iopin->port == IOPIN_PORTC) {
387                 volatile ushort *intp = &((immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pcint;
388                 return ((*intp >> (15 - iopin->pin)) & 1) ^ 1;
389         }
390         return 0;
393 #endif /* __KERNEL__ */
395 #endif /* _ASM_IOPIN_8XX_H_ */