Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/linux-dm
[pandora-kernel.git] / arch / arm / mach-davinci / include / mach / gpio.h
1 /*
2  * TI DaVinci GPIO Support
3  *
4  * Copyright (c) 2006 David Brownell
5  * Copyright (c) 2007, MontaVista Software, Inc. <source@mvista.com>
6  *
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.
11  */
12
13 #ifndef __DAVINCI_GPIO_H
14 #define __DAVINCI_GPIO_H
15
16 #include <asm-generic/gpio.h>
17
18 /* The inline versions use the static inlines in the driver header */
19 #include "gpio-davinci.h"
20
21 /*
22  * The get/set/clear functions will inline when called with constant
23  * parameters referencing built-in GPIOs, for low-overhead bitbanging.
24  *
25  * gpio_set_value() will inline only on traditional Davinci style controllers
26  * with distinct set/clear registers.
27  *
28  * Otherwise, calls with variable parameters or referencing external
29  * GPIOs (e.g. on GPIO expander chips) use outlined functions.
30  */
31 static inline void gpio_set_value(unsigned gpio, int value)
32 {
33         if (__builtin_constant_p(value) && gpio < davinci_soc_info.gpio_num) {
34                 struct davinci_gpio_controller *ctlr;
35                 u32                             mask;
36
37                 ctlr = __gpio_to_controller(gpio);
38
39                 if (ctlr->set_data != ctlr->clr_data) {
40                         mask = __gpio_mask(gpio);
41                         if (value)
42                                 __raw_writel(mask, ctlr->set_data);
43                         else
44                                 __raw_writel(mask, ctlr->clr_data);
45                         return;
46                 }
47         }
48
49         __gpio_set_value(gpio, value);
50 }
51
52 /* Returns zero or nonzero; works for gpios configured as inputs OR
53  * as outputs, at least for built-in GPIOs.
54  *
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
59  * latched.
60  */
61 static inline int gpio_get_value(unsigned gpio)
62 {
63         struct davinci_gpio_controller *ctlr;
64
65         if (!__builtin_constant_p(gpio) || gpio >= davinci_soc_info.gpio_num)
66                 return __gpio_get_value(gpio);
67
68         ctlr = __gpio_to_controller(gpio);
69         return __gpio_mask(gpio) & __raw_readl(ctlr->in_data);
70 }
71
72 static inline int gpio_cansleep(unsigned gpio)
73 {
74         if (__builtin_constant_p(gpio) && gpio < davinci_soc_info.gpio_num)
75                 return 0;
76         else
77                 return __gpio_cansleep(gpio);
78 }
79
80 static inline int irq_to_gpio(unsigned irq)
81 {
82         /* don't support the reverse mapping */
83         return -ENOSYS;
84 }
85
86 #endif                          /* __DAVINCI_GPIO_H */