blob: f854df633aac866755a194d7cf92beac2e079835 [file] [log] [blame]
Wolfgang Denk8123eee2006-03-12 22:41:33 +01001/*
2 * MPC85xx I/O port pin manipulation functions
3 */
4
5#ifndef _ASM_IOPIN_85xx_H_
6#define _ASM_IOPIN_85xx_H_
7
8#include <linux/types.h>
9#include <asm/immap_85xx.h>
10
11#ifdef __KERNEL__
12
13typedef struct {
14 u_char port:2; /* port number (A=0, B=1, C=2, D=3) */
15 u_char pin:5; /* port pin (0-31) */
16 u_char flag:1; /* for whatever */
17} iopin_t;
18
19#define IOPIN_PORTA 0
20#define IOPIN_PORTB 1
21#define IOPIN_PORTC 2
22#define IOPIN_PORTD 3
23
24extern __inline__ void iopin_set_high (iopin_t * iopin)
25{
26 volatile uint *datp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdata;
27 datp[iopin->port * 8] |= (1 << (31 - iopin->pin));
28}
29
30extern __inline__ void iopin_set_low (iopin_t * iopin)
31{
32 volatile uint *datp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdata;
33 datp[iopin->port * 8] &= ~(1 << (31 - iopin->pin));
34}
35
36extern __inline__ uint iopin_is_high (iopin_t * iopin)
37{
38 volatile uint *datp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdata;
39 return (datp[iopin->port * 8] >> (31 - iopin->pin)) & 1;
40}
41
42extern __inline__ uint iopin_is_low (iopin_t * iopin)
43{
44 volatile uint *datp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdata;
45 return ((datp[iopin->port * 8] >> (31 - iopin->pin)) & 1) ^ 1;
46}
47
48extern __inline__ void iopin_set_out (iopin_t * iopin)
49{
50 volatile uint *dirp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdira;
51 dirp[iopin->port * 8] |= (1 << (31 - iopin->pin));
52}
53
54extern __inline__ void iopin_set_in (iopin_t * iopin)
55{
56 volatile uint *dirp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdira;
57 dirp[iopin->port * 8] &= ~(1 << (31 - iopin->pin));
58}
59
60extern __inline__ uint iopin_is_out (iopin_t * iopin)
61{
62 volatile uint *dirp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdira;
63 return (dirp[iopin->port * 8] >> (31 - iopin->pin)) & 1;
64}
65
66extern __inline__ uint iopin_is_in (iopin_t * iopin)
67{
68 volatile uint *dirp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.pdira;
69 return ((dirp[iopin->port * 8] >> (31 - iopin->pin)) & 1) ^ 1;
70}
71
72extern __inline__ void iopin_set_odr (iopin_t * iopin)
73{
74 volatile uint *odrp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.podra;
75 odrp[iopin->port * 8] |= (1 << (31 - iopin->pin));
76}
77
78extern __inline__ void iopin_set_act (iopin_t * iopin)
79{
80 volatile uint *odrp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.podra;
81 odrp[iopin->port * 8] &= ~(1 << (31 - iopin->pin));
82}
83
84extern __inline__ uint iopin_is_odr (iopin_t * iopin)
85{
86 volatile uint *odrp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.podra;
87 return (odrp[iopin->port * 8] >> (31 - iopin->pin)) & 1;
88}
89
90extern __inline__ uint iopin_is_act (iopin_t * iopin)
91{
92 volatile uint *odrp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.podra;
93 return ((odrp[iopin->port * 8] >> (31 - iopin->pin)) & 1) ^ 1;
94}
95
96extern __inline__ void iopin_set_ded (iopin_t * iopin)
97{
98 volatile uint *parp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.ppara;
99 parp[iopin->port * 8] |= (1 << (31 - iopin->pin));
100}
101
102extern __inline__ void iopin_set_gen (iopin_t * iopin)
103{
104 volatile uint *parp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.ppara;
105 parp[iopin->port * 8] &= ~(1 << (31 - iopin->pin));
106}
107
108extern __inline__ uint iopin_is_ded (iopin_t * iopin)
109{
110 volatile uint *parp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.ppara;
111 return (parp[iopin->port * 8] >> (31 - iopin->pin)) & 1;
112}
113
114extern __inline__ uint iopin_is_gen (iopin_t * iopin)
115{
116 volatile uint *parp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.ppara;
117 return ((parp[iopin->port * 8] >> (31 - iopin->pin)) & 1) ^ 1;
118}
119
120extern __inline__ void iopin_set_opt2 (iopin_t * iopin)
121{
122 volatile uint *sorp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.psora;
123 sorp[iopin->port * 8] |= (1 << (31 - iopin->pin));
124}
125
126extern __inline__ void iopin_set_opt1 (iopin_t * iopin)
127{
128 volatile uint *sorp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.psora;
129 sorp[iopin->port * 8] &= ~(1 << (31 - iopin->pin));
130}
131
132extern __inline__ uint iopin_is_opt2 (iopin_t * iopin)
133{
134 volatile uint *sorp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.psora;
135 return (sorp[iopin->port * 8] >> (31 - iopin->pin)) & 1;
136}
137
138extern __inline__ uint iopin_is_opt1 (iopin_t * iopin)
139{
140 volatile uint *sorp = &((immap_t *) CFG_IMMR)->im_cpm.im_cpm_iop.psora;
141 return ((sorp[iopin->port * 8] >> (31 - iopin->pin)) & 1) ^ 1;
142}
143
144#endif /* __KERNEL__ */
145
146#endif /* _ASM_IOPIN_85xx_H_ */