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 /* The inline versions use the static inlines in the driver header */
19 #include "gpio-davinci.h"
22 * The get/set/clear functions will inline when called with constant
23 * parameters referencing built-in GPIOs, for low-overhead bitbanging.
25 * gpio_set_value() will inline only on traditional Davinci style controllers
26 * with distinct set/clear registers.
28 * Otherwise, calls with variable parameters or referencing external
29 * GPIOs (e.g. on GPIO expander chips) use outlined functions.
31 static inline void gpio_set_value(unsigned gpio
, int value
)
33 if (__builtin_constant_p(value
) && gpio
< davinci_soc_info
.gpio_num
) {
34 struct davinci_gpio_controller
*ctlr
;
37 ctlr
= __gpio_to_controller(gpio
);
39 if (ctlr
->set_data
!= ctlr
->clr_data
) {
40 mask
= __gpio_mask(gpio
);
42 __raw_writel(mask
, ctlr
->set_data
);
44 __raw_writel(mask
, ctlr
->clr_data
);
49 __gpio_set_value(gpio
, value
);
52 /* Returns zero or nonzero; works for gpios configured as inputs OR
53 * as outputs, at least for built-in GPIOs.
55 * NOTE: for built-in GPIOs, changes in reported values are synchronized
56 * to the GPIO clock. This is easily seen after calling gpio_set_value()
57 * and then immediately gpio_get_value(), where the gpio_get_value() will
58 * return the old value until the GPIO clock ticks and the new value gets
61 static inline int gpio_get_value(unsigned gpio
)
63 struct davinci_gpio_controller
*ctlr
;
65 if (!__builtin_constant_p(gpio
) || gpio
>= davinci_soc_info
.gpio_num
)
66 return __gpio_get_value(gpio
);
68 ctlr
= __gpio_to_controller(gpio
);
69 return __gpio_mask(gpio
) & __raw_readl(ctlr
->in_data
);
72 static inline int gpio_cansleep(unsigned gpio
)
74 if (__builtin_constant_p(gpio
) && gpio
< davinci_soc_info
.gpio_num
)
77 return __gpio_cansleep(gpio
);
80 static inline int irq_to_gpio(unsigned irq
)
82 /* don't support the reverse mapping */
86 #endif /* __DAVINCI_GPIO_H */