2 * GPIO driver for TI DaVinci DA8xx SOCs.
4 * (C) Copyright 2011 Guralp Systems Ltd.
5 * Laurence Withers <lwithers@guralp.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/arch/gpio.h>
27 #include <asm/arch/hardware.h>
28 #include <asm/arch/davinci_misc.h>
30 static struct gpio_registry
{
32 char name
[GPIO_NAME_SIZE
];
33 } gpio_registry
[MAX_NUM_GPIOS
];
35 #define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
37 static const struct pinmux_config gpio_pinmux
[] = {
38 { pinmux(1), 8, 7 }, /* GP0[0] */
54 { pinmux(4), 8, 7 }, /* GP1[0] */
70 { pinmux(6), 8, 7 }, /* GP2[0] */
86 { pinmux(8), 8, 7 }, /* GP3[0] */
102 { pinmux(10), 8, 7 }, /* GP4[0] */
103 { pinmux(10), 8, 6 },
104 { pinmux(10), 8, 5 },
105 { pinmux(10), 8, 4 },
106 { pinmux(10), 8, 3 },
107 { pinmux(10), 8, 2 },
108 { pinmux(10), 8, 1 },
109 { pinmux(10), 8, 0 },
118 { pinmux(12), 8, 7 }, /* GP5[0] */
119 { pinmux(12), 8, 6 },
120 { pinmux(12), 8, 5 },
121 { pinmux(12), 8, 4 },
122 { pinmux(12), 8, 3 },
123 { pinmux(12), 8, 2 },
124 { pinmux(12), 8, 1 },
125 { pinmux(12), 8, 0 },
126 { pinmux(11), 8, 7 },
127 { pinmux(11), 8, 6 },
128 { pinmux(11), 8, 5 },
129 { pinmux(11), 8, 4 },
130 { pinmux(11), 8, 3 },
131 { pinmux(11), 8, 2 },
132 { pinmux(11), 8, 1 },
133 { pinmux(11), 8, 0 },
134 { pinmux(19), 8, 6 }, /* GP6[0] */
135 { pinmux(19), 8, 5 },
136 { pinmux(19), 8, 4 },
137 { pinmux(19), 8, 3 },
138 { pinmux(19), 8, 2 },
139 { pinmux(16), 8, 1 },
140 { pinmux(14), 8, 1 },
141 { pinmux(14), 8, 0 },
142 { pinmux(13), 8, 7 },
143 { pinmux(13), 8, 6 },
144 { pinmux(13), 8, 5 },
145 { pinmux(13), 8, 4 },
146 { pinmux(13), 8, 3 },
147 { pinmux(13), 8, 2 },
148 { pinmux(13), 8, 1 },
149 { pinmux(13), 8, 0 },
150 { pinmux(18), 8, 1 }, /* GP7[0] */
151 { pinmux(18), 8, 0 },
152 { pinmux(17), 8, 7 },
153 { pinmux(17), 8, 6 },
154 { pinmux(17), 8, 5 },
155 { pinmux(17), 8, 4 },
156 { pinmux(17), 8, 3 },
157 { pinmux(17), 8, 2 },
158 { pinmux(17), 8, 1 },
159 { pinmux(17), 8, 0 },
160 { pinmux(16), 8, 7 },
161 { pinmux(16), 8, 6 },
162 { pinmux(16), 8, 5 },
163 { pinmux(16), 8, 4 },
164 { pinmux(16), 8, 3 },
165 { pinmux(16), 8, 2 },
166 { pinmux(19), 8, 0 }, /* GP8[0] */
174 { pinmux(19), 8, 1 },
175 { pinmux(19), 8, 0 },
176 { pinmux(18), 8, 7 },
177 { pinmux(18), 8, 6 },
178 { pinmux(18), 8, 5 },
179 { pinmux(18), 8, 4 },
180 { pinmux(18), 8, 3 },
181 { pinmux(18), 8, 2 },
184 int gpio_request(int gp
, const char *label
)
186 if (gp
>= MAX_NUM_GPIOS
)
189 if (gpio_registry
[gp
].is_registered
)
192 gpio_registry
[gp
].is_registered
= 1;
193 strncpy(gpio_registry
[gp
].name
, label
, GPIO_NAME_SIZE
);
194 gpio_registry
[gp
].name
[GPIO_NAME_SIZE
- 1] = 0;
196 davinci_configure_pin_mux(&gpio_pinmux
[gp
], 1);
201 void gpio_free(int gp
)
203 gpio_registry
[gp
].is_registered
= 0;
206 void gpio_toggle_value(int gp
)
208 struct davinci_gpio
*bank
;
210 bank
= GPIO_BANK(gp
);
211 gpio_set_value(gp
, !gpio_get_value(gp
));
214 int gpio_direction_input(int gp
)
216 struct davinci_gpio
*bank
;
218 bank
= GPIO_BANK(gp
);
219 setbits_le32(&bank
->dir
, 1U << GPIO_BIT(gp
));
223 int gpio_direction_output(int gp
, int value
)
225 struct davinci_gpio
*bank
;
227 bank
= GPIO_BANK(gp
);
228 clrbits_le32(&bank
->dir
, 1U << GPIO_BIT(gp
));
229 gpio_set_value(gp
, value
);
233 int gpio_get_value(int gp
)
235 struct davinci_gpio
*bank
;
238 bank
= GPIO_BANK(gp
);
239 ip
= in_le32(&bank
->in_data
) & (1U << GPIO_BIT(gp
));
243 void gpio_set_value(int gp
, int value
)
245 struct davinci_gpio
*bank
;
247 bank
= GPIO_BANK(gp
);
250 bank
->set_data
= 1U << GPIO_BIT(gp
);
252 bank
->clr_data
= 1U << GPIO_BIT(gp
);
258 struct davinci_gpio
*bank
;
260 for (gp
= 0; gp
< MAX_NUM_GPIOS
; ++gp
) {
261 bank
= GPIO_BANK(gp
);
262 dir
= in_le32(&bank
->dir
) & (1U << GPIO_BIT(gp
));
263 val
= gpio_get_value(gp
);
265 printf("% 4d: %s: %d [%c] %s\n",
266 gp
, dir
? " in" : "out", val
,
267 gpio_registry
[gp
].is_registered
? 'x' : ' ',
268 gpio_registry
[gp
].name
);