2 * GPIO driver for TI DaVinci DA8xx SOCs.
4 * (C) Copyright 2011 Guralp Systems Ltd.
5 * Laurence Withers <lwithers@guralp.com>
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <asm/arch/hardware.h>
14 #include <asm/arch/davinci_misc.h>
16 static struct gpio_registry
{
18 char name
[GPIO_NAME_SIZE
];
19 } gpio_registry
[MAX_NUM_GPIOS
];
21 #if defined(CONFIG_SOC_DA8XX)
22 #define pinmux(x) (&davinci_syscfg_regs->pinmux[x])
24 #if defined(CONFIG_SOC_DA8XX) && !defined(CONFIG_SOC_DA850)
25 static const struct pinmux_config gpio_pinmux
[] = {
26 { pinmux(13), 8, 6 }, /* GP0[0] */
42 { pinmux(15), 8, 6 }, /* GP1[0] */
58 { pinmux(17), 8, 6 }, /* GP2[0] */
74 { pinmux(10), 8, 1 }, /* GP3[0] */
90 { pinmux(12), 8, 4 }, /* GP4[0] */
100 { pinmux(11), 8, 7 },
101 { pinmux(12), 8, 0 },
102 { pinmux(12), 8, 1 },
103 { pinmux(12), 8, 2 },
104 { pinmux(12), 8, 3 },
106 { pinmux(7), 8, 3 }, /* GP5[0] */
122 { pinmux(5), 8, 1 }, /* GP6[0] */
138 { pinmux(1), 8, 0 }, /* GP7[0] */
155 #else /* CONFIG_SOC_DA8XX && CONFIG_SOC_DA850 */
156 static const struct pinmux_config gpio_pinmux
[] = {
157 { pinmux(1), 8, 7 }, /* GP0[0] */
173 { pinmux(4), 8, 7 }, /* GP1[0] */
189 { pinmux(6), 8, 7 }, /* GP2[0] */
205 { pinmux(8), 8, 7 }, /* GP3[0] */
221 { pinmux(10), 8, 7 }, /* GP4[0] */
222 { pinmux(10), 8, 6 },
223 { pinmux(10), 8, 5 },
224 { pinmux(10), 8, 4 },
225 { pinmux(10), 8, 3 },
226 { pinmux(10), 8, 2 },
227 { pinmux(10), 8, 1 },
228 { pinmux(10), 8, 0 },
237 { pinmux(12), 8, 7 }, /* GP5[0] */
238 { pinmux(12), 8, 6 },
239 { pinmux(12), 8, 5 },
240 { pinmux(12), 8, 4 },
241 { pinmux(12), 8, 3 },
242 { pinmux(12), 8, 2 },
243 { pinmux(12), 8, 1 },
244 { pinmux(12), 8, 0 },
245 { pinmux(11), 8, 7 },
246 { pinmux(11), 8, 6 },
247 { pinmux(11), 8, 5 },
248 { pinmux(11), 8, 4 },
249 { pinmux(11), 8, 3 },
250 { pinmux(11), 8, 2 },
251 { pinmux(11), 8, 1 },
252 { pinmux(11), 8, 0 },
253 { pinmux(19), 8, 6 }, /* GP6[0] */
254 { pinmux(19), 8, 5 },
255 { pinmux(19), 8, 4 },
256 { pinmux(19), 8, 3 },
257 { pinmux(19), 8, 2 },
258 { pinmux(16), 8, 1 },
259 { pinmux(14), 8, 1 },
260 { pinmux(14), 8, 0 },
261 { pinmux(13), 8, 7 },
262 { pinmux(13), 8, 6 },
263 { pinmux(13), 8, 5 },
264 { pinmux(13), 8, 4 },
265 { pinmux(13), 8, 3 },
266 { pinmux(13), 8, 2 },
267 { pinmux(13), 8, 1 },
268 { pinmux(13), 8, 0 },
269 { pinmux(18), 8, 1 }, /* GP7[0] */
270 { pinmux(18), 8, 0 },
271 { pinmux(17), 8, 7 },
272 { pinmux(17), 8, 6 },
273 { pinmux(17), 8, 5 },
274 { pinmux(17), 8, 4 },
275 { pinmux(17), 8, 3 },
276 { pinmux(17), 8, 2 },
277 { pinmux(17), 8, 1 },
278 { pinmux(17), 8, 0 },
279 { pinmux(16), 8, 7 },
280 { pinmux(16), 8, 6 },
281 { pinmux(16), 8, 5 },
282 { pinmux(16), 8, 4 },
283 { pinmux(16), 8, 3 },
284 { pinmux(16), 8, 2 },
285 { pinmux(19), 8, 0 }, /* GP8[0] */
293 { pinmux(19), 8, 1 },
294 { pinmux(19), 8, 0 },
295 { pinmux(18), 8, 7 },
296 { pinmux(18), 8, 6 },
297 { pinmux(18), 8, 5 },
298 { pinmux(18), 8, 4 },
299 { pinmux(18), 8, 3 },
300 { pinmux(18), 8, 2 },
302 #endif /* CONFIG_SOC_DA8XX && !CONFIG_SOC_DA850 */
303 #else /* !CONFIG_SOC_DA8XX */
304 #define davinci_configure_pin_mux(a, b)
305 #endif /* CONFIG_SOC_DA8XX */
307 int gpio_request(unsigned gpio
, const char *label
)
309 if (gpio
>= MAX_NUM_GPIOS
)
312 if (gpio_registry
[gpio
].is_registered
)
315 gpio_registry
[gpio
].is_registered
= 1;
316 strncpy(gpio_registry
[gpio
].name
, label
, GPIO_NAME_SIZE
);
317 gpio_registry
[gpio
].name
[GPIO_NAME_SIZE
- 1] = 0;
319 davinci_configure_pin_mux(&gpio_pinmux
[gpio
], 1);
324 int gpio_free(unsigned gpio
)
326 if (gpio
>= MAX_NUM_GPIOS
)
329 if (!gpio_registry
[gpio
].is_registered
)
332 gpio_registry
[gpio
].is_registered
= 0;
333 gpio_registry
[gpio
].name
[0] = '\0';
334 /* Do not configure as input or change pin mux here */
338 int gpio_direction_input(unsigned gpio
)
340 struct davinci_gpio
*bank
;
342 bank
= GPIO_BANK(gpio
);
343 setbits_le32(&bank
->dir
, 1U << GPIO_BIT(gpio
));
347 int gpio_direction_output(unsigned gpio
, int value
)
349 struct davinci_gpio
*bank
;
351 bank
= GPIO_BANK(gpio
);
352 clrbits_le32(&bank
->dir
, 1U << GPIO_BIT(gpio
));
353 gpio_set_value(gpio
, value
);
357 int gpio_get_value(unsigned gpio
)
359 struct davinci_gpio
*bank
;
362 bank
= GPIO_BANK(gpio
);
363 ip
= in_le32(&bank
->in_data
) & (1U << GPIO_BIT(gpio
));
367 int gpio_set_value(unsigned gpio
, int value
)
369 struct davinci_gpio
*bank
;
371 bank
= GPIO_BANK(gpio
);
374 bank
->set_data
= 1U << GPIO_BIT(gpio
);
376 bank
->clr_data
= 1U << GPIO_BIT(gpio
);
383 unsigned gpio
, dir
, val
;
384 struct davinci_gpio
*bank
;
386 for (gpio
= 0; gpio
< MAX_NUM_GPIOS
; ++gpio
) {
387 bank
= GPIO_BANK(gpio
);
388 dir
= in_le32(&bank
->dir
) & (1U << GPIO_BIT(gpio
));
389 val
= gpio_get_value(gpio
);
391 printf("% 4d: %s: %d [%c] %s\n",
392 gpio
, dir
? " in" : "out", val
,
393 gpio_registry
[gpio
].is_registered
? 'x' : ' ',
394 gpio_registry
[gpio
].name
);