blob: 783d4c153fbf4efb34030de9e4966c65e8e198ed [file] [log] [blame]
Shashank Mittalb3be37f2012-01-16 22:59:49 -08001/* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Amol Jadicd43ea02011-02-15 20:56:04 -08002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <reg.h>
31#include <platform/iomap.h>
Amol Jadic52c8a32011-07-12 11:27:04 -070032#include <platform/gpio.h>
33#include <gsbi.h>
Shashank Mittalb3be37f2012-01-16 22:59:49 -080034#include <dev/pm8921.h>
35#include <sys/types.h>
Amol Jadia63aaff2012-02-01 15:51:50 -080036#include <smem.h>
Amol Jadicd43ea02011-02-15 20:56:04 -080037
38void gpio_tlmm_config(uint32_t gpio, uint8_t func,
Ajay Dudanib01e5062011-12-03 23:23:42 -080039 uint8_t dir, uint8_t pull,
40 uint8_t drvstr, uint32_t enable)
Amol Jadicd43ea02011-02-15 20:56:04 -080041{
Ajay Dudanib01e5062011-12-03 23:23:42 -080042 unsigned int val = 0;
43 val |= pull;
44 val |= func << 2;
45 val |= drvstr << 6;
46 val |= enable << 9;
47 unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
48 writel(val, addr);
49 return;
Amol Jadicd43ea02011-02-15 20:56:04 -080050}
51
52void gpio_set(uint32_t gpio, uint32_t dir)
53{
Ajay Dudanib01e5062011-12-03 23:23:42 -080054 unsigned int *addr = (unsigned int *)GPIO_IN_OUT_ADDR(gpio);
55 writel(dir, addr);
56 return;
Amol Jadicd43ea02011-02-15 20:56:04 -080057}
Amol Jadic52c8a32011-07-12 11:27:04 -070058
Amol Jadia63aaff2012-02-01 15:51:50 -080059/* TODO: this and other code below in this file should ideally by in target dir.
60 * keeping it here for this brigup.
61 */
62
Amol Jadic52c8a32011-07-12 11:27:04 -070063/* Configure gpio for uart - based on gsbi id */
64void gpio_config_uart_dm(uint8_t id)
65{
Amol Jadia63aaff2012-02-01 15:51:50 -080066 if(board_platform_id() == APQ8064)
67 {
68 switch (id) {
Amol Jadi0c04df82011-10-14 17:40:21 -070069
Amol Jadia63aaff2012-02-01 15:51:50 -080070 case GSBI_ID_1:
71 /* configure rx gpio */
72 gpio_tlmm_config(19, 1, GPIO_INPUT, GPIO_NO_PULL,
73 GPIO_8MA, GPIO_DISABLE);
74 /* configure tx gpio */
75 gpio_tlmm_config(18, 1, GPIO_OUTPUT, GPIO_NO_PULL,
76 GPIO_8MA, GPIO_DISABLE);
77 break;
Amol Jadi0c04df82011-10-14 17:40:21 -070078
Amol Jadi0c04df82011-10-14 17:40:21 -070079
Amol Jadia63aaff2012-02-01 15:51:50 -080080 case GSBI_ID_7:
81 /* configure rx gpio */
82 gpio_tlmm_config(83, 1, GPIO_INPUT, GPIO_NO_PULL,
83 GPIO_8MA, GPIO_DISABLE);
84 /* configure tx gpio */
85 gpio_tlmm_config(82, 2, GPIO_OUTPUT, GPIO_NO_PULL,
86 GPIO_8MA, GPIO_DISABLE);
87 break;
88
89 default:
90 ASSERT(0);
91 }
92 }
93 else
94 {
95 switch (id) {
96
97 case GSBI_ID_3:
98 /* configure rx gpio */
99 gpio_tlmm_config(15, 1, GPIO_INPUT, GPIO_NO_PULL,
100 GPIO_8MA, GPIO_DISABLE);
101 /* configure tx gpio */
102 gpio_tlmm_config(14, 1, GPIO_OUTPUT, GPIO_NO_PULL,
103 GPIO_8MA, GPIO_DISABLE);
104 break;
105
106 case GSBI_ID_5:
107 /* configure rx gpio */
108 gpio_tlmm_config(23, 1, GPIO_INPUT, GPIO_NO_PULL,
109 GPIO_8MA, GPIO_DISABLE);
110 /* configure tx gpio */
111 gpio_tlmm_config(22, 1, GPIO_OUTPUT, GPIO_NO_PULL,
112 GPIO_8MA, GPIO_DISABLE);
113 break;
114
115 default:
116 ASSERT(0);
117 }
Amol Jadic52c8a32011-07-12 11:27:04 -0700118 }
119}
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800120
121struct pm8xxx_gpio_init {
122 uint32_t gpio;
123 struct pm8921_gpio config;
124};
125
126#define PM8XXX_GPIO_INIT(_gpio, _dir, _buf, _val, _pull, _vin, _out_strength, \
127 _func, _inv, _disable) \
128{ \
129 .gpio = _gpio, \
130 .config = { \
131 .direction = _dir, \
132 .output_buffer = _buf, \
133 .output_value = _val, \
134 .pull = _pull, \
135 .vin_sel = _vin, \
136 .out_strength = _out_strength, \
137 .function = _func, \
138 .inv_int_pol = _inv, \
139 .disable_pin = _disable, \
140 } \
141}
142
143#define PM8XXX_GPIO_OUTPUT(_gpio, _val) \
144 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \
145 PM_GPIO_PULL_NO, 2, \
146 PM_GPIO_STRENGTH_HIGH, \
147 PM_GPIO_FUNC_NORMAL, 1, 0)
148
149
150#define PM8XXX_GPIO_INPUT(_gpio, _pull) \
151 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, 0, 0, \
152 _pull, 2, \
153 PM_GPIO_STRENGTH_NO, \
154 PM_GPIO_FUNC_NORMAL, 1, 0)
155
156/* Initial pm8038 GPIO configurations */
157static struct pm8xxx_gpio_init pm8038_keypad_gpios[] = {
158 /* keys GPIOs */
Ajay Dudanidc85e4a2012-03-08 20:09:17 -0800159 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_30),
160 PM8XXX_GPIO_INPUT(PM_GPIO(8), PM_GPIO_PULL_UP_30),
161 PM8XXX_GPIO_INPUT(PM_GPIO(10), PM_GPIO_PULL_UP_30),
162 PM8XXX_GPIO_INPUT(PM_GPIO(11), PM_GPIO_PULL_UP_30),
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800163};
164
165static struct pm8xxx_gpio_init pm8921_keypad_gpios[] = {
166 /* keys GPIOs */
167 PM8XXX_GPIO_INPUT(PM_GPIO(1), PM_GPIO_PULL_UP_31_5),
168 PM8XXX_GPIO_INPUT(PM_GPIO(2), PM_GPIO_PULL_UP_31_5),
169 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_31_5),
170 PM8XXX_GPIO_INPUT(PM_GPIO(4), PM_GPIO_PULL_UP_31_5),
171 PM8XXX_GPIO_INPUT(PM_GPIO(5), PM_GPIO_PULL_UP_31_5),
172 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
173};
174
Amol Jadi76071672012-02-03 12:19:36 -0800175/* pm8921 GPIO configuration for APQ8064 keypad */
176static struct pm8xxx_gpio_init pm8921_keypad_gpios_apq[] = {
177 /* keys GPIOs */
178 PM8XXX_GPIO_INPUT(PM_GPIO(35), PM_GPIO_PULL_UP_31_5),
179 PM8XXX_GPIO_INPUT(PM_GPIO(38), PM_GPIO_PULL_UP_31_5),
180 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
181};
182
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800183void msm8960_keypad_gpio_init()
184{
185 int i = 0;
186 int num = 0;
187
188 num = ARRAY_SIZE(pm8921_keypad_gpios);
189
190 for(i=0; i < num; i++)
191 {
192 pm8921_gpio_config(pm8921_keypad_gpios[i].gpio,
193 &(pm8921_keypad_gpios[i].config));
194 }
195}
196
197void msm8930_keypad_gpio_init()
198{
199 int i = 0;
200 int num = 0;
201
202 num = ARRAY_SIZE(pm8038_keypad_gpios);
203
204 for(i=0; i < num; i++)
205 {
206 pm8921_gpio_config(pm8038_keypad_gpios[i].gpio,
207 &(pm8038_keypad_gpios[i].config));
208 }
209}
Amol Jadi76071672012-02-03 12:19:36 -0800210
211void apq8064_keypad_gpio_init()
212{
213 int i = 0;
214 int num = 0;
215
216 num = ARRAY_SIZE(pm8921_keypad_gpios_apq);
217
218 for(i=0; i < num; i++)
219 {
220 pm8921_gpio_config(pm8921_keypad_gpios_apq[i].gpio,
221 &(pm8921_keypad_gpios_apq[i].config));
222 }
223}
224