Merge branch 'tip/perf/urgent-3' of git://git.kernel.org/pub/scm/linux/kernel/git...
[pandora-kernel.git] / arch / arm / mach-msm / include / mach / gpio.h
1 /*
2  * Copyright (C) 2007 Google, Inc.
3  * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
4  * Author: Mike Lockwood <lockwood@android.com>
5  *
6  * This software is licensed under the terms of the GNU General Public
7  * License version 2, as published by the Free Software Foundation, and
8  * may be copied, distributed, and modified under those terms.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16 #ifndef __ASM_ARCH_MSM_GPIO_H
17 #define __ASM_ARCH_MSM_GPIO_H
18
19 #include <asm-generic/gpio.h>
20
21 #define gpio_get_value  __gpio_get_value
22 #define gpio_set_value  __gpio_set_value
23 #define gpio_cansleep   __gpio_cansleep
24 #define gpio_to_irq     __gpio_to_irq
25
26 /**
27  * struct msm_gpio - GPIO pin description
28  * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config()
29  * @label - textual label
30  *
31  * Usually, GPIO's are operated by sets.
32  * This struct accumulate all GPIO information in single source
33  * and facilitete group operations provided by msm_gpios_xxx()
34  */
35 struct msm_gpio {
36         u32 gpio_cfg;
37         const char *label;
38 };
39
40 /**
41  * msm_gpios_request_enable() - request and enable set of GPIOs
42  *
43  * Request and configure set of GPIO's
44  * In case of error, all operations rolled back.
45  * Return error code.
46  *
47  * @table: GPIO table
48  * @size:  number of entries in @table
49  */
50 int msm_gpios_request_enable(const struct msm_gpio *table, int size);
51
52 /**
53  * msm_gpios_disable_free() - disable and free set of GPIOs
54  *
55  * @table: GPIO table
56  * @size:  number of entries in @table
57  */
58 void msm_gpios_disable_free(const struct msm_gpio *table, int size);
59
60 /**
61  * msm_gpios_request() - request set of GPIOs
62  * In case of error, all operations rolled back.
63  * Return error code.
64  *
65  * @table: GPIO table
66  * @size:  number of entries in @table
67  */
68 int msm_gpios_request(const struct msm_gpio *table, int size);
69
70 /**
71  * msm_gpios_free() - free set of GPIOs
72  *
73  * @table: GPIO table
74  * @size:  number of entries in @table
75  */
76 void msm_gpios_free(const struct msm_gpio *table, int size);
77
78 /**
79  * msm_gpios_enable() - enable set of GPIOs
80  * In case of error, all operations rolled back.
81  * Return error code.
82  *
83  * @table: GPIO table
84  * @size:  number of entries in @table
85  */
86 int msm_gpios_enable(const struct msm_gpio *table, int size);
87
88 /**
89  * msm_gpios_disable() - disable set of GPIOs
90  *
91  * @table: GPIO table
92  * @size:  number of entries in @table
93  */
94 void msm_gpios_disable(const struct msm_gpio *table, int size);
95
96 /* GPIO TLMM (Top Level Multiplexing) Definitions */
97
98 /* GPIO TLMM: Function -- GPIO specific */
99
100 /* GPIO TLMM: Direction */
101 enum {
102         GPIO_INPUT,
103         GPIO_OUTPUT,
104 };
105
106 /* GPIO TLMM: Pullup/Pulldown */
107 enum {
108         GPIO_NO_PULL,
109         GPIO_PULL_DOWN,
110         GPIO_KEEPER,
111         GPIO_PULL_UP,
112 };
113
114 /* GPIO TLMM: Drive Strength */
115 enum {
116         GPIO_2MA,
117         GPIO_4MA,
118         GPIO_6MA,
119         GPIO_8MA,
120         GPIO_10MA,
121         GPIO_12MA,
122         GPIO_14MA,
123         GPIO_16MA,
124 };
125
126 enum {
127         GPIO_ENABLE,
128         GPIO_DISABLE,
129 };
130
131 #define GPIO_CFG(gpio, func, dir, pull, drvstr) \
132         ((((gpio) & 0x3FF) << 4)        |         \
133          ((func) & 0xf)                  |        \
134          (((dir) & 0x1) << 14)           |        \
135          (((pull) & 0x3) << 15)          |        \
136          (((drvstr) & 0xF) << 17))
137
138 /**
139  * extract GPIO pin from bit-field used for gpio_tlmm_config
140  */
141 #define GPIO_PIN(gpio_cfg)    (((gpio_cfg) >>  4) & 0x3ff)
142 #define GPIO_FUNC(gpio_cfg)   (((gpio_cfg) >>  0) & 0xf)
143 #define GPIO_DIR(gpio_cfg)    (((gpio_cfg) >> 14) & 0x1)
144 #define GPIO_PULL(gpio_cfg)   (((gpio_cfg) >> 15) & 0x3)
145 #define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf)
146
147 int gpio_tlmm_config(unsigned config, unsigned disable);
148
149 #endif /* __ASM_ARCH_MSM_GPIO_H */