blob: fa69b9f030a5b3ddd2fa73268cdc85a40e9ecc7d [file] [log] [blame]
Gregory Bean1de238e2010-04-30 22:15:16 -07001/*
2 * Copyright (C) 2007 Google, Inc.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 * Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved.
Gregory Bean1de238e2010-04-30 22:15:16 -07004 * 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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070019#ifdef CONFIG_ARCH_MSM8X60
20#define ARCH_NR_GPIOS 512
21#endif
Pavel Machek923a0812010-06-02 11:11:12 -070022
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include <linux/interrupt.h>
24#include <asm-generic/gpio.h>
25#include <mach/irqs.h>
26
27#define FIRST_BOARD_GPIO NR_GPIO_IRQS
28
29extern struct irq_chip msm_gpio_irq_extn;
30
31static inline int gpio_get_value(unsigned gpio)
32{
33 return __gpio_get_value(gpio);
34}
35
36static inline void gpio_set_value(unsigned gpio, int value)
37{
38 __gpio_set_value(gpio, value);
39}
40
41static inline int gpio_cansleep(unsigned gpio)
42{
43 return __gpio_cansleep(gpio);
44}
45
46static inline int gpio_to_irq(unsigned gpio)
47{
48 return __gpio_to_irq(gpio);
49}
50
51/**
52 * struct msm_gpio - GPIO pin description
53 * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config()
54 * @label - textual label
55 *
56 * Usually, GPIO's are operated by sets.
57 * This struct accumulate all GPIO information in single source
58 * and facilitete group operations provided by msm_gpios_xxx()
59 */
60struct msm_gpio {
61 u32 gpio_cfg;
62 const char *label;
63};
64
65/**
66 * msm_gpios_request_enable() - request and enable set of GPIOs
67 *
68 * Request and configure set of GPIO's
69 * In case of error, all operations rolled back.
70 * Return error code.
71 *
72 * @table: GPIO table
73 * @size: number of entries in @table
74 */
75int msm_gpios_request_enable(const struct msm_gpio *table, int size);
76
77/**
78 * msm_gpios_disable_free() - disable and free set of GPIOs
79 *
80 * @table: GPIO table
81 * @size: number of entries in @table
82 */
83void msm_gpios_disable_free(const struct msm_gpio *table, int size);
84
85/**
86 * msm_gpios_request() - request set of GPIOs
87 * In case of error, all operations rolled back.
88 * Return error code.
89 *
90 * @table: GPIO table
91 * @size: number of entries in @table
92 */
93int msm_gpios_request(const struct msm_gpio *table, int size);
94
95/**
96 * msm_gpios_free() - free set of GPIOs
97 *
98 * @table: GPIO table
99 * @size: number of entries in @table
100 */
101void msm_gpios_free(const struct msm_gpio *table, int size);
102
103/**
104 * msm_gpios_enable() - enable set of GPIOs
105 * In case of error, all operations rolled back.
106 * Return error code.
107 *
108 * @table: GPIO table
109 * @size: number of entries in @table
110 */
111int msm_gpios_enable(const struct msm_gpio *table, int size);
112
113/**
114 * msm_gpios_disable() - disable set of GPIOs
115 *
116 * @table: GPIO table
117 * @size: number of entries in @table
118 */
119int msm_gpios_disable(const struct msm_gpio *table, int size);
120
121/**
122 * msm_gpios_show_resume_irq() - show the interrupts that could have triggered
123 * resume
124 */
125void msm_gpio_show_resume_irq(void);
126
127/* GPIO TLMM (Top Level Multiplexing) Definitions */
128
129/* GPIO TLMM: Function -- GPIO specific */
130
131/* GPIO TLMM: Direction */
132enum {
133 GPIO_CFG_INPUT,
134 GPIO_CFG_OUTPUT,
135};
136
137/* GPIO TLMM: Pullup/Pulldown */
138enum {
139 GPIO_CFG_NO_PULL,
140 GPIO_CFG_PULL_DOWN,
141 GPIO_CFG_KEEPER,
142 GPIO_CFG_PULL_UP,
143};
144
145/* GPIO TLMM: Drive Strength */
146enum {
147 GPIO_CFG_2MA,
148 GPIO_CFG_4MA,
149 GPIO_CFG_6MA,
150 GPIO_CFG_8MA,
151 GPIO_CFG_10MA,
152 GPIO_CFG_12MA,
153 GPIO_CFG_14MA,
154 GPIO_CFG_16MA,
155};
156
157enum {
158 GPIO_CFG_ENABLE,
159 GPIO_CFG_DISABLE,
160};
161
162#define GPIO_CFG(gpio, func, dir, pull, drvstr) \
163 ((((gpio) & 0x3FF) << 4) | \
164 ((func) & 0xf) | \
165 (((dir) & 0x1) << 14) | \
166 (((pull) & 0x3) << 15) | \
167 (((drvstr) & 0xF) << 17))
168
169/**
170 * extract GPIO pin from bit-field used for gpio_tlmm_config
171 */
172#define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff)
173#define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf)
174#define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1)
175#define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3)
176#define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf)
177
178int gpio_tlmm_config(unsigned config, unsigned disable);
179
180enum msm_tlmm_hdrive_tgt {
181 TLMM_HDRV_SDC4_CLK = 0,
182 TLMM_HDRV_SDC4_CMD,
183 TLMM_HDRV_SDC4_DATA,
184 TLMM_HDRV_SDC3_CLK,
185 TLMM_HDRV_SDC3_CMD,
186 TLMM_HDRV_SDC3_DATA,
187 TLMM_HDRV_SDC1_CLK,
188 TLMM_HDRV_SDC1_CMD,
189 TLMM_HDRV_SDC1_DATA,
190};
191
192enum msm_tlmm_pull_tgt {
193 TLMM_PULL_SDC4_CMD = 0,
194 TLMM_PULL_SDC4_DATA,
195 TLMM_PULL_SDC3_CLK,
196 TLMM_PULL_SDC3_CMD,
197 TLMM_PULL_SDC3_DATA,
198 TLMM_PULL_SDC1_CLK,
199 TLMM_PULL_SDC1_CMD,
200 TLMM_PULL_SDC1_DATA,
201};
202
203#ifdef CONFIG_MSM_V2_TLMM
204void msm_tlmm_set_hdrive(enum msm_tlmm_hdrive_tgt tgt, int drv_str);
205void msm_tlmm_set_pull(enum msm_tlmm_pull_tgt tgt, int pull);
206
207/*
208 * A GPIO can be set as a direct-connect IRQ. This can be used to bypass
209 * the normal summary-interrupt mechanism for those GPIO lines deemed to be
210 * higher priority or otherwise worthy of special treatment, but resources
211 * are limited: only a few DC interrupt lines are available.
212 * Care must be taken when usurping a GPIO in this manner, as the summary
213 * interrupt controller has no idea that the GPIO has been taken away from it.
214 * Clients can still register to receive the summary interrupt assigned
215 * to that GPIO, which will uninstall it as a direct connect IRQ with
216 * no warning.
217 *
218 * The irq passed to this function is the DC IRQ number, not the
219 * irq number seen by the scorpion when the interrupt triggers. For example,
220 * if 0 is specified, then when DC IRQ 0 triggers, the scorpion will see
221 * interrupt TLMM_MSM_DIR_CONN_IRQ_0.
222 *
223 * input_polarity parameter specifies when the gpio should raise the direct
224 * interrupt. A value of 0 means that it is active low, anything else means
225 * active high
226 *
227 */
228int msm_gpio_install_direct_irq(unsigned gpio, unsigned irq,
229 unsigned int input_polarity);
230#else
231static inline void msm_tlmm_set_hdrive(enum msm_tlmm_hdrive_tgt tgt,
232 int drv_str) {}
233static inline void msm_tlmm_set_pull(enum msm_tlmm_pull_tgt tgt, int pull) {}
234static inline int msm_gpio_install_direct_irq(unsigned gpio, unsigned irq,
235 unsigned int input_polarity)
236{
237 return -ENOSYS;
238}
239#endif
Pavel Machek923a0812010-06-02 11:11:12 -0700240
Gregory Bean1de238e2010-04-30 22:15:16 -0700241#endif /* __ASM_ARCH_MSM_GPIO_H */