2
* TI DaVinci GPIO Support
4
* Copyright (c) 2006 David Brownell
5
* Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
13
#ifndef __DAVINCI_GPIO_H
14
#define __DAVINCI_GPIO_H
16
#include <asm-generic/gpio.h>
18
#define __ARM_GPIOLIB_COMPLEX
20
/* The inline versions use the static inlines in the driver header */
21
#include "gpio-davinci.h"
24
* The get/set/clear functions will inline when called with constant
25
* parameters referencing built-in GPIOs, for low-overhead bitbanging.
27
* gpio_set_value() will inline only on traditional Davinci style controllers
28
* with distinct set/clear registers.
30
* Otherwise, calls with variable parameters or referencing external
31
* GPIOs (e.g. on GPIO expander chips) use outlined functions.
33
static inline void gpio_set_value(unsigned gpio, int value)
35
if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) {
36
struct davinci_gpio_controller *ctlr;
39
ctlr = __gpio_to_controller(gpio);
41
if (ctlr->set_data != ctlr->clr_data) {
42
mask = __gpio_mask(gpio);
44
__raw_writel(mask, ctlr->set_data);
46
__raw_writel(mask, ctlr->clr_data);
51
__gpio_set_value(gpio, value);
54
/* Returns zero or nonzero; works for gpios configured as inputs OR
55
* as outputs, at least for built-in GPIOs.
57
* NOTE: for built-in GPIOs, changes in reported values are synchronized
58
* to the GPIO clock. This is easily seen after calling gpio_set_value()
59
* and then immediately gpio_get_value(), where the gpio_get_value() will
60
* return the old value until the GPIO clock ticks and the new value gets
63
static inline int gpio_get_value(unsigned gpio)
65
struct davinci_gpio_controller *ctlr;
67
if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
68
return __gpio_get_value(gpio);
70
ctlr = __gpio_to_controller(gpio);
71
return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
74
static inline int gpio_cansleep(unsigned gpio)
76
if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num)
79
return __gpio_cansleep(gpio);
82
static inline int irq_to_gpio(unsigned irq)
84
/* don't support the reverse mapping */
88
#endif /* __DAVINCI_GPIO_H */