blob: 3f85dad1a101f488841ddceab1fb2bd7204a8c0b [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 Jadic4263042012-03-29 16:18:11 -070066 if(board_platform_id() == MPQ8064)
67 {
68 switch (id) {
69
70 case GSBI_ID_5:
71 /* configure rx gpio */
72 gpio_tlmm_config(52, 1, GPIO_INPUT, GPIO_NO_PULL,
73 GPIO_8MA, GPIO_DISABLE);
74 /* configure tx gpio */
75 gpio_tlmm_config(51, 1, GPIO_OUTPUT, GPIO_NO_PULL,
76 GPIO_8MA, GPIO_DISABLE);
77 break;
78
79 default:
80 ASSERT(0);
81 }
82 }
83 else if(board_platform_id() == APQ8064)
Amol Jadia63aaff2012-02-01 15:51:50 -080084 {
85 switch (id) {
Amol Jadi0c04df82011-10-14 17:40:21 -070086
Amol Jadia63aaff2012-02-01 15:51:50 -080087 case GSBI_ID_1:
88 /* configure rx gpio */
89 gpio_tlmm_config(19, 1, GPIO_INPUT, GPIO_NO_PULL,
90 GPIO_8MA, GPIO_DISABLE);
91 /* configure tx gpio */
92 gpio_tlmm_config(18, 1, GPIO_OUTPUT, GPIO_NO_PULL,
93 GPIO_8MA, GPIO_DISABLE);
94 break;
Amol Jadi0c04df82011-10-14 17:40:21 -070095
Amol Jadi0c04df82011-10-14 17:40:21 -070096
Amol Jadia63aaff2012-02-01 15:51:50 -080097 case GSBI_ID_7:
98 /* configure rx gpio */
99 gpio_tlmm_config(83, 1, GPIO_INPUT, GPIO_NO_PULL,
100 GPIO_8MA, GPIO_DISABLE);
101 /* configure tx gpio */
102 gpio_tlmm_config(82, 2, GPIO_OUTPUT, GPIO_NO_PULL,
103 GPIO_8MA, GPIO_DISABLE);
104 break;
105
106 default:
107 ASSERT(0);
108 }
109 }
110 else
111 {
112 switch (id) {
113
114 case GSBI_ID_3:
115 /* configure rx gpio */
116 gpio_tlmm_config(15, 1, GPIO_INPUT, GPIO_NO_PULL,
117 GPIO_8MA, GPIO_DISABLE);
118 /* configure tx gpio */
119 gpio_tlmm_config(14, 1, GPIO_OUTPUT, GPIO_NO_PULL,
120 GPIO_8MA, GPIO_DISABLE);
121 break;
122
123 case GSBI_ID_5:
124 /* configure rx gpio */
125 gpio_tlmm_config(23, 1, GPIO_INPUT, GPIO_NO_PULL,
126 GPIO_8MA, GPIO_DISABLE);
127 /* configure tx gpio */
128 gpio_tlmm_config(22, 1, GPIO_OUTPUT, GPIO_NO_PULL,
129 GPIO_8MA, GPIO_DISABLE);
130 break;
131
Neeti Desai46940292012-07-17 14:28:35 -0700132 case GSBI_ID_8:
133 /* configure rx gpio */
134 gpio_tlmm_config(35, 1, GPIO_INPUT, GPIO_NO_PULL,
135 GPIO_8MA, GPIO_DISABLE);
136 /* configure tx gpio */
137 gpio_tlmm_config(34, 1, GPIO_OUTPUT, GPIO_NO_PULL,
138 GPIO_8MA, GPIO_DISABLE);
139 break;
140
Amol Jadia63aaff2012-02-01 15:51:50 -0800141 default:
142 ASSERT(0);
143 }
Amol Jadic52c8a32011-07-12 11:27:04 -0700144 }
145}
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800146
147struct pm8xxx_gpio_init {
148 uint32_t gpio;
149 struct pm8921_gpio config;
150};
151
152#define PM8XXX_GPIO_INIT(_gpio, _dir, _buf, _val, _pull, _vin, _out_strength, \
153 _func, _inv, _disable) \
154{ \
155 .gpio = _gpio, \
156 .config = { \
157 .direction = _dir, \
158 .output_buffer = _buf, \
159 .output_value = _val, \
160 .pull = _pull, \
161 .vin_sel = _vin, \
162 .out_strength = _out_strength, \
163 .function = _func, \
164 .inv_int_pol = _inv, \
165 .disable_pin = _disable, \
166 } \
167}
168
169#define PM8XXX_GPIO_OUTPUT(_gpio, _val) \
170 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \
171 PM_GPIO_PULL_NO, 2, \
172 PM_GPIO_STRENGTH_HIGH, \
173 PM_GPIO_FUNC_NORMAL, 1, 0)
174
175
176#define PM8XXX_GPIO_INPUT(_gpio, _pull) \
177 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, 0, 0, \
178 _pull, 2, \
179 PM_GPIO_STRENGTH_NO, \
180 PM_GPIO_FUNC_NORMAL, 1, 0)
181
182/* Initial pm8038 GPIO configurations */
183static struct pm8xxx_gpio_init pm8038_keypad_gpios[] = {
184 /* keys GPIOs */
Ajay Dudanidc85e4a2012-03-08 20:09:17 -0800185 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_30),
186 PM8XXX_GPIO_INPUT(PM_GPIO(8), PM_GPIO_PULL_UP_30),
187 PM8XXX_GPIO_INPUT(PM_GPIO(10), PM_GPIO_PULL_UP_30),
188 PM8XXX_GPIO_INPUT(PM_GPIO(11), PM_GPIO_PULL_UP_30),
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800189};
190
191static struct pm8xxx_gpio_init pm8921_keypad_gpios[] = {
192 /* keys GPIOs */
193 PM8XXX_GPIO_INPUT(PM_GPIO(1), PM_GPIO_PULL_UP_31_5),
194 PM8XXX_GPIO_INPUT(PM_GPIO(2), PM_GPIO_PULL_UP_31_5),
195 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_31_5),
196 PM8XXX_GPIO_INPUT(PM_GPIO(4), PM_GPIO_PULL_UP_31_5),
197 PM8XXX_GPIO_INPUT(PM_GPIO(5), PM_GPIO_PULL_UP_31_5),
198 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
199};
200
Amol Jadi76071672012-02-03 12:19:36 -0800201/* pm8921 GPIO configuration for APQ8064 keypad */
202static struct pm8xxx_gpio_init pm8921_keypad_gpios_apq[] = {
203 /* keys GPIOs */
204 PM8XXX_GPIO_INPUT(PM_GPIO(35), PM_GPIO_PULL_UP_31_5),
205 PM8XXX_GPIO_INPUT(PM_GPIO(38), PM_GPIO_PULL_UP_31_5),
206 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
207};
208
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700209/* pm8917 GPIO configuration for APQ8064 keypad */
210static struct pm8xxx_gpio_init pm8917_keypad_gpios_apq[] = {
211 /* keys GPIOs */
212 PM8XXX_GPIO_INPUT(PM_GPIO(35), PM_GPIO_PULL_UP_31_5),
213 PM8XXX_GPIO_INPUT(PM_GPIO(30), PM_GPIO_PULL_UP_31_5),
214 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
215};
216
Neeti Desai7c303362012-09-18 11:50:22 -0700217/* pm8917 GPIO configuration for MSM8930 keypad */
218static struct pm8xxx_gpio_init pm8917_keypad_gpios[] = {
219 /* keys GPIOs */
220 PM8XXX_GPIO_INPUT(PM_GPIO(27), PM_GPIO_PULL_UP_30),
221 PM8XXX_GPIO_INPUT(PM_GPIO(28), PM_GPIO_PULL_UP_30),
222 PM8XXX_GPIO_INPUT(PM_GPIO(36), PM_GPIO_PULL_UP_30),
223 PM8XXX_GPIO_INPUT(PM_GPIO(37), PM_GPIO_PULL_UP_30),
224};
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700225
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800226void msm8960_keypad_gpio_init()
227{
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700228 int i = 0;
229 int num = 0;
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800230
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700231 num = ARRAY_SIZE(pm8921_keypad_gpios);
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800232
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700233 for(i=0; i < num; i++)
234 {
235 pm8921_gpio_config(pm8921_keypad_gpios[i].gpio,
236 &(pm8921_keypad_gpios[i].config));
237 }
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800238}
239
240void msm8930_keypad_gpio_init()
241{
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700242 int i = 0;
243 int num = 0;
Neeti Desai7c303362012-09-18 11:50:22 -0700244 struct pm8xxx_gpio_init *gpio_array;
245 uint32_t pmic_type;
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800246
Neeti Desai7c303362012-09-18 11:50:22 -0700247 pmic_type = board_pmic_type();
248
249 if (pmic_type == PMIC_IS_PM8917)
250 {
251 num = ARRAY_SIZE(pm8917_keypad_gpios);
252 gpio_array = pm8917_keypad_gpios;
253 }
254 else
255 {
256 num = ARRAY_SIZE(pm8038_keypad_gpios);
257 gpio_array = pm8038_keypad_gpios;
258 }
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800259
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700260 for(i=0; i < num; i++)
261 {
Neeti Desai7c303362012-09-18 11:50:22 -0700262 pm8921_gpio_config(gpio_array[i].gpio,
263 &(gpio_array[i].config));
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700264 }
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800265}
Amol Jadi76071672012-02-03 12:19:36 -0800266
267void apq8064_keypad_gpio_init()
268{
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700269 int i = 0;
270 int num = 0;
271 struct pm8xxx_gpio_init *gpio_array;
272 uint32_t pmic_type;
Amol Jadi76071672012-02-03 12:19:36 -0800273
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700274 pmic_type = board_pmic_type();
275
276 if (pmic_type == PMIC_IS_PM8917)
277 {
278 num = ARRAY_SIZE(pm8917_keypad_gpios_apq);
279 gpio_array = pm8917_keypad_gpios_apq;
280 }
281 else
282 {
Amol Jadi76071672012-02-03 12:19:36 -0800283 num = ARRAY_SIZE(pm8921_keypad_gpios_apq);
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700284 gpio_array = pm8921_keypad_gpios_apq;
285 }
Amol Jadi76071672012-02-03 12:19:36 -0800286
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700287 for(i = 0; i < num; i++)
288 {
289 pm8921_gpio_config(gpio_array[i].gpio,
290 &(gpio_array[i].config));
291 }
Amol Jadi76071672012-02-03 12:19:36 -0800292}
293
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700294#define PM8921_GPIO_OUTPUT_FUNC(_gpio, _val, _func) \
295 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \
296 PM_GPIO_PULL_NO, 2, \
297 PM_GPIO_STRENGTH_HIGH, \
298 _func, 0, 0)
299
300
301#define PM8921_GPIO_OUTPUT_BUFCONF(_gpio, _val, _strength, _bufconf) \
302 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT,\
303 PM_GPIO_OUT_BUF_##_bufconf, _val, \
304 PM_GPIO_PULL_NO, 2, \
305 PM_GPIO_STRENGTH_##_strength, \
306 PM_GPIO_FUNC_NORMAL, 0, 0)
307
308
309static struct pm8xxx_gpio_init pm8921_display_gpios_apq[] = {
310 /* Display GPIOs */
311 /* Bl: ON, PWM mode */
312 PM8921_GPIO_OUTPUT_FUNC(PM_GPIO(26), 1, PM_GPIO_FUNC_2),
313 /* LCD1_PWR_EN_N */
314 PM8921_GPIO_OUTPUT_BUFCONF(PM_GPIO(36), 0, LOW, OPEN_DRAIN),
315 /* DISP_RESET_N */
316 PM8921_GPIO_OUTPUT_BUFCONF(PM_GPIO(25), 1, LOW, CMOS),
317};
318
319void apq8064_display_gpio_init()
320{
321 int i = 0;
322 int num = 0;
323
324 num = ARRAY_SIZE(pm8921_display_gpios_apq);
325
326 for (i = 0; i < num; i++) {
327 pm8921_gpio_config(pm8921_display_gpios_apq[i].gpio,
328 &(pm8921_display_gpios_apq[i].config));
329 }
330}