blob: 174bd39eec92339e5cb48cf1d159b1ee93084295 [file] [log] [blame]
Ajay Dudani232ce812009-12-02 00:14:11 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Duy Truongf3ac7b32013-02-13 01:07:28 -08005 * Copyright (c) 2009-2010, The Linux Foundation. All rights reserved.
Shashank Mittal37040832010-08-24 15:57:57 -07006 *
Ajay Dudani232ce812009-12-02 00:14:11 -08007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
Chandan Uddaraju14e57eb2010-06-28 12:11:06 -070031#ifndef __PLATFORM_MSM7X30_GPIO_HW_H
32#define __PLATFORM_MSM7X30_GPIO_HW_H
Ajay Dudani232ce812009-12-02 00:14:11 -080033
Shashank Mittal37040832010-08-24 15:57:57 -070034#define MSM_GPIO1_BASE 0xAC001000
35#define MSM_GPIO2_BASE 0xAC101000
Ajay Dudani232ce812009-12-02 00:14:11 -080036
Shashank Mittal37040832010-08-24 15:57:57 -070037#define GPIO1_REG(off) (MSM_GPIO1_BASE + (off))
38#define GPIO2_REG(off) (MSM_GPIO2_BASE + 0x400 + (off))
Ajay Dudani232ce812009-12-02 00:14:11 -080039
40/* output value */
Ajay Dudanib01e5062011-12-03 23:23:42 -080041#define GPIO_OUT_0 GPIO1_REG(0x00) /* gpio 15-0 */
42#define GPIO_OUT_1 GPIO2_REG(0x00) /* gpio 43-16 */
43#define GPIO_OUT_2 GPIO1_REG(0x04) /* gpio 67-44 */
44#define GPIO_OUT_3 GPIO1_REG(0x08) /* gpio 94-68 */
45#define GPIO_OUT_4 GPIO1_REG(0x0C) /* gpio 106-95 */
46#define GPIO_OUT_5 GPIO1_REG(0x50) /* gpio 133-107 */
47#define GPIO_OUT_6 GPIO1_REG(0xC4) /* gpio 150-134 */
48#define GPIO_OUT_7 GPIO1_REG(0x214) /* gpio 181-151 */
Ajay Dudani232ce812009-12-02 00:14:11 -080049
50/* same pin map as above, output enable */
Shashank Mittal37040832010-08-24 15:57:57 -070051#define GPIO_OE_0 GPIO1_REG(0x10)
Ajay Dudani232ce812009-12-02 00:14:11 -080052#define GPIO_OE_1 GPIO2_REG(0x08)
Shashank Mittal37040832010-08-24 15:57:57 -070053#define GPIO_OE_2 GPIO1_REG(0x14)
54#define GPIO_OE_3 GPIO1_REG(0x18)
55#define GPIO_OE_4 GPIO1_REG(0x1C)
56#define GPIO_OE_5 GPIO1_REG(0x54)
57#define GPIO_OE_6 GPIO1_REG(0xC8)
58#define GPIO_OE_7 GPIO1_REG(0x218)
Ajay Dudani232ce812009-12-02 00:14:11 -080059
60/* same pin map as above, input read */
Shashank Mittal37040832010-08-24 15:57:57 -070061#define GPIO_IN_0 GPIO1_REG(0x34)
Ajay Dudani232ce812009-12-02 00:14:11 -080062#define GPIO_IN_1 GPIO2_REG(0x20)
Shashank Mittal37040832010-08-24 15:57:57 -070063#define GPIO_IN_2 GPIO1_REG(0x38)
64#define GPIO_IN_3 GPIO1_REG(0x3C)
65#define GPIO_IN_4 GPIO1_REG(0x40)
66#define GPIO_IN_5 GPIO1_REG(0x44)
67#define GPIO_IN_6 GPIO1_REG(0xCC)
68#define GPIO_IN_7 GPIO1_REG(0x21C)
Ajay Dudani232ce812009-12-02 00:14:11 -080069
70/* same pin map as above, 1=edge 0=level interrup */
Shashank Mittal37040832010-08-24 15:57:57 -070071#define GPIO_INT_EDGE_0 GPIO1_REG(0x60)
Ajay Dudani232ce812009-12-02 00:14:11 -080072#define GPIO_INT_EDGE_1 GPIO2_REG(0x50)
Shashank Mittal37040832010-08-24 15:57:57 -070073#define GPIO_INT_EDGE_2 GPIO1_REG(0x64)
74#define GPIO_INT_EDGE_3 GPIO1_REG(0x68)
75#define GPIO_INT_EDGE_4 GPIO1_REG(0x6C)
76#define GPIO_INT_EDGE_5 GPIO1_REG(0xC0)
77#define GPIO_INT_EDGE_6 GPIO1_REG(0xD0)
78#define GPIO_INT_EDGE_7 GPIO1_REG(0x240)
Ajay Dudani232ce812009-12-02 00:14:11 -080079
80/* same pin map as above, 1=positive 0=negative */
Shashank Mittal37040832010-08-24 15:57:57 -070081#define GPIO_INT_POS_0 GPIO1_REG(0x70)
Ajay Dudani232ce812009-12-02 00:14:11 -080082#define GPIO_INT_POS_1 GPIO2_REG(0x58)
Shashank Mittal37040832010-08-24 15:57:57 -070083#define GPIO_INT_POS_2 GPIO1_REG(0x74)
84#define GPIO_INT_POS_3 GPIO1_REG(0x78)
85#define GPIO_INT_POS_4 GPIO1_REG(0x7C)
86#define GPIO_INT_POS_5 GPIO1_REG(0xBC)
87#define GPIO_INT_POS_6 GPIO1_REG(0xD4)
88#define GPIO_INT_POS_7 GPIO1_REG(0x228)
Ajay Dudani232ce812009-12-02 00:14:11 -080089
90/* same pin map as above, interrupt enable */
Shashank Mittal37040832010-08-24 15:57:57 -070091#define GPIO_INT_EN_0 GPIO1_REG(0x80)
Ajay Dudani232ce812009-12-02 00:14:11 -080092#define GPIO_INT_EN_1 GPIO2_REG(0x60)
Shashank Mittal37040832010-08-24 15:57:57 -070093#define GPIO_INT_EN_2 GPIO1_REG(0x84)
94#define GPIO_INT_EN_3 GPIO1_REG(0x88)
95#define GPIO_INT_EN_4 GPIO1_REG(0x8C)
96#define GPIO_INT_EN_5 GPIO1_REG(0xB8)
97#define GPIO_INT_EN_6 GPIO1_REG(0xD8)
98#define GPIO_INT_EN_7 GPIO1_REG(0x22C)
Ajay Dudani232ce812009-12-02 00:14:11 -080099
100/* same pin map as above, write 1 to clear interrupt */
Shashank Mittal37040832010-08-24 15:57:57 -0700101#define GPIO_INT_CLEAR_0 GPIO1_REG(0x90)
Ajay Dudani232ce812009-12-02 00:14:11 -0800102#define GPIO_INT_CLEAR_1 GPIO2_REG(0x68)
Shashank Mittal37040832010-08-24 15:57:57 -0700103#define GPIO_INT_CLEAR_2 GPIO1_REG(0x94)
104#define GPIO_INT_CLEAR_3 GPIO1_REG(0x98)
105#define GPIO_INT_CLEAR_4 GPIO1_REG(0x9C)
106#define GPIO_INT_CLEAR_5 GPIO1_REG(0xB4)
107#define GPIO_INT_CLEAR_6 GPIO1_REG(0xDC)
108#define GPIO_INT_CLEAR_7 GPIO1_REG(0x230)
Ajay Dudani232ce812009-12-02 00:14:11 -0800109
110/* same pin map as above, 1=interrupt pending */
Shashank Mittal37040832010-08-24 15:57:57 -0700111#define GPIO_INT_STATUS_0 GPIO1_REG(0xA0)
Ajay Dudani232ce812009-12-02 00:14:11 -0800112#define GPIO_INT_STATUS_1 GPIO2_REG(0x70)
Shashank Mittal37040832010-08-24 15:57:57 -0700113#define GPIO_INT_STATUS_2 GPIO1_REG(0xA4)
114#define GPIO_INT_STATUS_3 GPIO1_REG(0xA8)
115#define GPIO_INT_STATUS_4 GPIO1_REG(0xAC)
116#define GPIO_INT_STATUS_5 GPIO1_REG(0xB0)
117#define GPIO_INT_STATUS_6 GPIO1_REG(0xE0)
118#define GPIO_INT_STATUS_7 GPIO1_REG(0x234)
Ajay Dudani232ce812009-12-02 00:14:11 -0800119
Chandan Uddaraju14e57eb2010-06-28 12:11:06 -0700120#define GPIO_OUT_VAL_REG_BASE 0xABC00000
121#define GPIO_ALT_FUNC_PAGE_REG (GPIO_OUT_VAL_REG_BASE + 0x20)
122#define GPIO_ALT_FUNC_CFG_REG (GPIO_OUT_VAL_REG_BASE + 0x24)
123
Shashank Mittal37040832010-08-24 15:57:57 -0700124/* GPIO TLMM: Direction */
125#define GPIO_INPUT 0
126#define GPIO_OUTPUT 1
127
128/* GPIO TLMM: Pullup/Pulldown */
129#define GPIO_NO_PULL 0
130#define GPIO_PULL_DOWN 1
131#define GPIO_KEEPER 2
132#define GPIO_PULL_UP 3
133
134/* GPIO TLMM: Drive Strength */
135#define GPIO_2MA 0
136#define GPIO_4MA 1
137#define GPIO_6MA 2
138#define GPIO_8MA 3
139#define GPIO_10MA 4
140#define GPIO_12MA 5
141#define GPIO_14MA 6
142#define GPIO_16MA 7
143
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700144#define GPIO38_GPIO_CNTRL 0x175
145
Shashank Mittal37040832010-08-24 15:57:57 -0700146/* GPIO TLMM: Status */
147#define GPIO_ENABLE 0
148#define GPIO_DISABLE 1
149
150#define GPIO_CFG(gpio, func, dir, pull, drvstr) \
151 ((((gpio) & 0x3FF) << 4) | \
152 ((func) & 0xf) | \
153 (((dir) & 0x1) << 14) | \
154 (((pull) & 0x3) << 15) | \
155 (((drvstr) & 0xF) << 17))
156
157/**
158 * struct msm_gpio - GPIO pin description
159 * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config()
160 * @label - textual label
161 *
162 * Usually, GPIO's are operated by sets.
163 * This struct accumulate all GPIO information in single source
164 * and facilitete group operations provided by msm_gpios_xxx()
165 */
166struct msm_gpio {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800167 unsigned gpio_cfg;
168 const char *label;
Shashank Mittal37040832010-08-24 15:57:57 -0700169};
170
171/**
172 * extract GPIO pin from bit-field used for gpio_tlmm_config
173 */
174#define GPIO_PIN(gpio_cfg) (((gpio_cfg) >> 4) & 0x3ff)
175#define GPIO_FUNC(gpio_cfg) (((gpio_cfg) >> 0) & 0xf)
176#define GPIO_DIR(gpio_cfg) (((gpio_cfg) >> 14) & 0x1)
177#define GPIO_PULL(gpio_cfg) (((gpio_cfg) >> 15) & 0x3)
178#define GPIO_DRVSTR(gpio_cfg) (((gpio_cfg) >> 17) & 0xf)
179
Ajay Dudani232ce812009-12-02 00:14:11 -0800180#endif