Pull ec into release branch
[pandora-kernel.git] / include / asm-arm / arch-omap / gpio.h
1 /*
2  * linux/include/asm-arm/arch-omap/gpio.h
3  *
4  * OMAP GPIO handling defines and functions
5  *
6  * Copyright (C) 2003-2005 Nokia Corporation
7  *
8  * Written by Juha Yrjölä <juha.yrjola@nokia.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  *
24  */
25
26 #ifndef __ASM_ARCH_OMAP_GPIO_H
27 #define __ASM_ARCH_OMAP_GPIO_H
28
29 #include <asm/hardware.h>
30 #include <asm/arch/irqs.h>
31 #include <asm/io.h>
32
33 #define OMAP_MPUIO_BASE                 (void __iomem *)0xfffb5000
34
35 #ifdef CONFIG_ARCH_OMAP730
36 #define OMAP_MPUIO_INPUT_LATCH          0x00
37 #define OMAP_MPUIO_OUTPUT               0x02
38 #define OMAP_MPUIO_IO_CNTL              0x04
39 #define OMAP_MPUIO_KBR_LATCH            0x08
40 #define OMAP_MPUIO_KBC                  0x0a
41 #define OMAP_MPUIO_GPIO_EVENT_MODE      0x0c
42 #define OMAP_MPUIO_GPIO_INT_EDGE        0x0e
43 #define OMAP_MPUIO_KBD_INT              0x10
44 #define OMAP_MPUIO_GPIO_INT             0x12
45 #define OMAP_MPUIO_KBD_MASKIT           0x14
46 #define OMAP_MPUIO_GPIO_MASKIT          0x16
47 #define OMAP_MPUIO_GPIO_DEBOUNCING      0x18
48 #define OMAP_MPUIO_LATCH                0x1a
49 #else
50 #define OMAP_MPUIO_INPUT_LATCH          0x00
51 #define OMAP_MPUIO_OUTPUT               0x04
52 #define OMAP_MPUIO_IO_CNTL              0x08
53 #define OMAP_MPUIO_KBR_LATCH            0x10
54 #define OMAP_MPUIO_KBC                  0x14
55 #define OMAP_MPUIO_GPIO_EVENT_MODE      0x18
56 #define OMAP_MPUIO_GPIO_INT_EDGE        0x1c
57 #define OMAP_MPUIO_KBD_INT              0x20
58 #define OMAP_MPUIO_GPIO_INT             0x24
59 #define OMAP_MPUIO_KBD_MASKIT           0x28
60 #define OMAP_MPUIO_GPIO_MASKIT          0x2c
61 #define OMAP_MPUIO_GPIO_DEBOUNCING      0x30
62 #define OMAP_MPUIO_LATCH                0x34
63 #endif
64
65 #define OMAP_MPUIO(nr)          (OMAP_MAX_GPIO_LINES + (nr))
66 #define OMAP_GPIO_IS_MPUIO(nr)  ((nr) >= OMAP_MAX_GPIO_LINES)
67
68 #define OMAP_GPIO_IRQ(nr)       (OMAP_GPIO_IS_MPUIO(nr) ? \
69                                  IH_MPUIO_BASE + ((nr) & 0x0f) : \
70                                  IH_GPIO_BASE + (nr))
71
72 extern int omap_gpio_init(void);        /* Call from board init only */
73 extern int omap_request_gpio(int gpio);
74 extern void omap_free_gpio(int gpio);
75 extern void omap_set_gpio_direction(int gpio, int is_input);
76 extern void omap_set_gpio_dataout(int gpio, int enable);
77 extern int omap_get_gpio_datain(int gpio);
78
79 /*-------------------------------------------------------------------------*/
80
81 /* wrappers for "new style" GPIO calls. the old OMAP-specfic ones should
82  * eventually be removed (along with this errno.h inclusion), and maybe
83  * gpios should put MPUIOs last too.
84  */
85
86 #include <asm/errno.h>
87
88 static inline int gpio_request(unsigned gpio, const char *label)
89 {
90         return omap_request_gpio(gpio);
91 }
92
93 static inline void gpio_free(unsigned gpio)
94 {
95         omap_free_gpio(gpio);
96 }
97
98 static inline int __gpio_set_direction(unsigned gpio, int is_input)
99 {
100         if (cpu_class_is_omap2()) {
101                 if (gpio > OMAP_MAX_GPIO_LINES)
102                         return -EINVAL;
103         } else {
104                 if (gpio > (OMAP_MAX_GPIO_LINES + 16 /* MPUIO */))
105                         return -EINVAL;
106         }
107         omap_set_gpio_direction(gpio, is_input);
108         return 0;
109 }
110
111 static inline int gpio_direction_input(unsigned gpio)
112 {
113         return __gpio_set_direction(gpio, 1);
114 }
115
116 static inline int gpio_direction_output(unsigned gpio, int value)
117 {
118         omap_set_gpio_dataout(gpio, value);
119         return __gpio_set_direction(gpio, 0);
120 }
121
122 static inline int gpio_get_value(unsigned gpio)
123 {
124         return omap_get_gpio_datain(gpio);
125 }
126
127 static inline void gpio_set_value(unsigned gpio, int value)
128 {
129         omap_set_gpio_dataout(gpio, value);
130 }
131
132 #include <asm-generic/gpio.h>           /* cansleep wrappers */
133
134 static inline int gpio_to_irq(unsigned gpio)
135 {
136         return OMAP_GPIO_IRQ(gpio);
137 }
138
139 static inline int irq_to_gpio(unsigned irq)
140 {
141         if (cpu_class_is_omap1() && (irq < (IH_MPUIO_BASE + 16)))
142                 return (irq - IH_MPUIO_BASE) + OMAP_MAX_GPIO_LINES;
143         return irq - IH_GPIO_BASE;
144 }
145
146 #endif