5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <asm/processor.h>
29 #if defined(CFG_440_GPIO_TABLE)
30 gpio_param_s gpio_tab[GPIO_GROUP_MAX][GPIO_MAX] = CFG_440_GPIO_TABLE;
33 #if defined(GPIO0_OSRL)
34 /* Only some 4xx variants support alternate funtions on the GPIO's */
35 void gpio_config(int pin, int in_out, int gpio_alt, int out_val)
44 if (pin >= GPIO_MAX) {
49 if (pin >= GPIO_MAX/2) {
51 pin2 = (pin - GPIO_MAX/2) << 1;
54 mask = 0x80000000 >> pin;
55 mask2 = 0xc0000000 >> (pin2 << 1);
57 /* first set TCR to 0 */
58 out32(GPIO0_TCR + offs, in32(GPIO0_TCR + offs) & ~mask);
60 if (in_out == GPIO_OUT) {
61 val = in32(GPIO0_OSRL + offs + offs2) & ~mask2;
64 val |= GPIO_ALT1_SEL >> pin2;
67 val |= GPIO_ALT2_SEL >> pin2;
70 val |= GPIO_ALT3_SEL >> pin2;
73 out32(GPIO0_OSRL + offs + offs2, val);
75 /* setup requested output value */
76 if (out_val == GPIO_OUT_0)
77 out32(GPIO0_OR + offs, in32(GPIO0_OR + offs) & ~mask);
78 else if (out_val == GPIO_OUT_1)
79 out32(GPIO0_OR + offs, in32(GPIO0_OR + offs) | mask);
81 /* now configure TCR to drive output if selected */
82 out32(GPIO0_TCR + offs, in32(GPIO0_TCR + offs) | mask);
84 val = in32(GPIO0_ISR1L + offs + offs2) & ~mask2;
85 val |= GPIO_IN_SEL >> pin2;
86 out32(GPIO0_ISR1L + offs + offs2, val);
89 #endif /* GPIO_OSRL */
91 void gpio_write_bit(int pin, int val)
95 if (pin >= GPIO_MAX) {
101 out32(GPIO0_OR + offs, in32(GPIO0_OR + offs) | GPIO_VAL(pin));
103 out32(GPIO0_OR + offs, in32(GPIO0_OR + offs) & ~GPIO_VAL(pin));
106 #if defined(CFG_440_GPIO_TABLE)
107 void gpio_set_chip_configuration(void)
109 unsigned char i=0, j=0, offs=0, gpio_core;
110 unsigned long reg, core_add;
112 for (gpio_core=0; gpio_core<GPIO_GROUP_MAX; gpio_core++) {
115 /* GPIO config of the GPIOs 0 to 31 */
116 for (i=0; i<GPIO_MAX; i++, j++) {
117 if (i == GPIO_MAX/2) {
122 core_add = gpio_tab[gpio_core][i].add;
124 if ((gpio_tab[gpio_core][i].in_out == GPIO_IN) ||
125 (gpio_tab[gpio_core][i].in_out == GPIO_BI)) {
127 switch (gpio_tab[gpio_core][i].alt_nb) {
132 reg = in32(GPIO_IS1(core_add+offs))
133 & ~(GPIO_MASK >> (j*2));
134 reg = reg | (GPIO_IN_SEL >> (j*2));
135 out32(GPIO_IS1(core_add+offs), reg);
139 reg = in32(GPIO_IS2(core_add+offs))
140 & ~(GPIO_MASK >> (j*2));
141 reg = reg | (GPIO_IN_SEL >> (j*2));
142 out32(GPIO_IS2(core_add+offs), reg);
146 reg = in32(GPIO_IS3(core_add+offs))
147 & ~(GPIO_MASK >> (j*2));
148 reg = reg | (GPIO_IN_SEL >> (j*2));
149 out32(GPIO_IS3(core_add+offs), reg);
154 if ((gpio_tab[gpio_core][i].in_out == GPIO_OUT) ||
155 (gpio_tab[gpio_core][i].in_out == GPIO_BI)) {
157 switch (gpio_tab[gpio_core][i].alt_nb) {
159 if (gpio_core == GPIO0) {
160 reg = in32(GPIO0_TCR) | (0x80000000 >> (j));
161 out32(GPIO0_TCR, reg);
164 if (gpio_core == GPIO1) {
165 reg = in32(GPIO1_TCR) | (0x80000000 >> (j));
166 out32(GPIO1_TCR, reg);
169 reg = in32(GPIO_OS(core_add+offs))
170 & ~(GPIO_MASK >> (j*2));
171 out32(GPIO_OS(core_add+offs), reg);
172 reg = in32(GPIO_TS(core_add+offs))
173 & ~(GPIO_MASK >> (j*2));
174 out32(GPIO_TS(core_add+offs), reg);
178 reg = in32(GPIO_OS(core_add+offs))
179 & ~(GPIO_MASK >> (j*2));
180 reg = reg | (GPIO_ALT1_SEL >> (j*2));
181 out32(GPIO_OS(core_add+offs), reg);
182 reg = in32(GPIO_TS(core_add+offs))
183 & ~(GPIO_MASK >> (j*2));
184 reg = reg | (GPIO_ALT1_SEL >> (j*2));
185 out32(GPIO_TS(core_add+offs), reg);
189 reg = in32(GPIO_OS(core_add+offs))
190 & ~(GPIO_MASK >> (j*2));
191 reg = reg | (GPIO_ALT2_SEL >> (j*2));
192 out32(GPIO_OS(core_add+offs), reg);
193 reg = in32(GPIO_TS(core_add+offs))
194 & ~(GPIO_MASK >> (j*2));
195 reg = reg | (GPIO_ALT2_SEL >> (j*2));
196 out32(GPIO_TS(core_add+offs), reg);
200 reg = in32(GPIO_OS(core_add+offs))
201 & ~(GPIO_MASK >> (j*2));
202 reg = reg | (GPIO_ALT3_SEL >> (j*2));
203 out32(GPIO_OS(core_add+offs), reg);
204 reg = in32(GPIO_TS(core_add+offs))
205 & ~(GPIO_MASK >> (j*2));
206 reg = reg | (GPIO_ALT3_SEL >> (j*2));
207 out32(GPIO_TS(core_add+offs), reg);
214 #endif /* CFG_440_GPIO_TABLE */