1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <common.h>
24#include <mpc83xx.h>
25#include <asm/gpio.h>
26#include <asm/io.h>
27
28#ifndef CONFIG_MPC83XX_GPIO_0_INIT_DIRECTION
29#define CONFIG_MPC83XX_GPIO_0_INIT_DIRECTION 0
30#endif
31#ifndef CONFIG_MPC83XX_GPIO_1_INIT_DIRECTION
32#define CONFIG_MPC83XX_GPIO_1_INIT_DIRECTION 0
33#endif
34#ifndef CONFIG_MPC83XX_GPIO_0_INIT_OPEN_DRAIN
35#define CONFIG_MPC83XX_GPIO_0_INIT_OPEN_DRAIN 0
36#endif
37#ifndef CONFIG_MPC83XX_GPIO_1_INIT_OPEN_DRAIN
38#define CONFIG_MPC83XX_GPIO_1_INIT_OPEN_DRAIN 0
39#endif
40#ifndef CONFIG_MPC83XX_GPIO_0_INIT_VALUE
41#define CONFIG_MPC83XX_GPIO_0_INIT_VALUE 0
42#endif
43#ifndef CONFIG_MPC83XX_GPIO_1_INIT_VALUE
44#define CONFIG_MPC83XX_GPIO_1_INIT_VALUE 0
45#endif
46
47static unsigned int gpio_output_value[MPC83XX_GPIO_CTRLRS];
48
49
50
51
52
53int gpio_request(unsigned gpio, const char *label)
54{
55 if (gpio >= MAX_NUM_GPIOS)
56 return -1;
57
58 return 0;
59}
60
61int gpio_free(unsigned gpio)
62{
63
64 return 0;
65}
66
67
68int gpio_direction_input(unsigned gpio)
69{
70 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
71 unsigned int ctrlr;
72 unsigned int line;
73 unsigned int line_mask;
74
75
76 ctrlr = gpio >> 5;
77 line = gpio & (0x1F);
78
79
80 line_mask = 1 << (31 - line);
81
82 clrbits_be32(&im->gpio[ctrlr].dir, line_mask);
83
84 return 0;
85}
86
87
88int gpio_direction_output(unsigned gpio, int value)
89{
90 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
91 unsigned int ctrlr;
92 unsigned int line;
93 unsigned int line_mask;
94
95 if (value != 0 && value != 1) {
96 printf("Error: Value parameter must be 0 or 1.\n");
97 return -1;
98 }
99
100 gpio_set_value(gpio, value);
101
102
103 ctrlr = gpio >> 5;
104 line = gpio & (0x1F);
105
106
107 line_mask = 1 << (31 - line);
108
109
110 setbits_be32(&im->gpio[ctrlr].dir, line_mask);
111
112 return 0;
113}
114
115
116int gpio_get_value(unsigned gpio)
117{
118 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
119 unsigned int ctrlr;
120 unsigned int line;
121 unsigned int line_mask;
122
123
124 ctrlr = gpio >> 5;
125 line = gpio & (0x1F);
126
127
128 line_mask = 1 << (31 - line);
129
130
131 return (in_be32(&im->gpio[ctrlr].dat) & line_mask) != 0;
132}
133
134
135int gpio_set_value(unsigned gpio, int value)
136{
137 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
138 unsigned int ctrlr;
139 unsigned int line;
140 unsigned int line_mask;
141
142 if (value != 0 && value != 1) {
143 printf("Error: Value parameter must be 0 or 1.\n");
144 return -1;
145 }
146
147
148 ctrlr = gpio >> 5;
149 line = gpio & (0x1F);
150
151
152 line_mask = 1 << (31 - line);
153
154
155 gpio_output_value[ctrlr] =
156 (gpio_output_value[ctrlr] & ~line_mask) | \
157 (value ? line_mask : 0);
158
159
160 out_be32(&im->gpio[ctrlr].dat, gpio_output_value[ctrlr]);
161
162 return 0;
163}
164
165
166void mpc83xx_gpio_init_f(void)
167{
168 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
169
170#if MPC83XX_GPIO_CTRLRS >= 1
171 out_be32(&im->gpio[0].dir, CONFIG_MPC83XX_GPIO_0_INIT_DIRECTION);
172 out_be32(&im->gpio[0].odr, CONFIG_MPC83XX_GPIO_0_INIT_OPEN_DRAIN);
173 out_be32(&im->gpio[0].dat, CONFIG_MPC83XX_GPIO_0_INIT_VALUE);
174 out_be32(&im->gpio[0].ier, 0xFFFFFFFF);
175 out_be32(&im->gpio[0].imr, 0);
176 out_be32(&im->gpio[0].icr, 0);
177#endif
178
179#if MPC83XX_GPIO_CTRLRS >= 2
180 out_be32(&im->gpio[1].dir, CONFIG_MPC83XX_GPIO_1_INIT_DIRECTION);
181 out_be32(&im->gpio[1].odr, CONFIG_MPC83XX_GPIO_1_INIT_OPEN_DRAIN);
182 out_be32(&im->gpio[1].dat, CONFIG_MPC83XX_GPIO_1_INIT_VALUE);
183 out_be32(&im->gpio[1].ier, 0xFFFFFFFF);
184 out_be32(&im->gpio[1].imr, 0);
185 out_be32(&im->gpio[1].icr, 0);
186#endif
187}
188
189
190void mpc83xx_gpio_init_r(void)
191{
192#if MPC83XX_GPIO_CTRLRS >= 1
193 gpio_output_value[0] = CONFIG_MPC83XX_GPIO_0_INIT_VALUE;
194#endif
195
196#if MPC83XX_GPIO_CTRLRS >= 2
197 gpio_output_value[1] = CONFIG_MPC83XX_GPIO_1_INIT_VALUE;
198#endif
199}
200