blob: 57d259124085d07d1e8dafde42613f2688b40197 [file] [log] [blame]
Aparna Mallavarapu2269a2f2013-01-07 19:44:48 +05301/* Copyright (c) 2012-2013, The Linux Foundation. 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.
Amol Jadif34df2f2012-10-19 13:38:16 -070012 * * Neither the name of The Linux Foundation. nor the names of its
Amol Jadicd43ea02011-02-15 20:56:04 -080013 * 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 */
Amol Jadif34df2f2012-10-19 13:38:16 -070072 gpio_tlmm_config(52, 2, GPIO_INPUT, GPIO_NO_PULL,
Amol Jadic4263042012-03-29 16:18:11 -070073 GPIO_8MA, GPIO_DISABLE);
74 /* configure tx gpio */
Amol Jadif34df2f2012-10-19 13:38:16 -070075 gpio_tlmm_config(51, 2, GPIO_OUTPUT, GPIO_NO_PULL,
Amol Jadic4263042012-03-29 16:18:11 -070076 GPIO_8MA, GPIO_DISABLE);
77 break;
78
79 default:
80 ASSERT(0);
81 }
82 }
Amol Jadi117ef3a2012-09-20 13:32:55 -070083 else if((board_platform_id() == APQ8064) ||
Aparna Mallavarapu2269a2f2013-01-07 19:44:48 +053084 (board_platform_id() == APQ8064AA) ||
Amol Jadi117ef3a2012-09-20 13:32:55 -070085 (board_platform_id() == APQ8064AB))
Amol Jadia63aaff2012-02-01 15:51:50 -080086 {
87 switch (id) {
Amol Jadi0c04df82011-10-14 17:40:21 -070088
Amol Jadia63aaff2012-02-01 15:51:50 -080089 case GSBI_ID_1:
90 /* configure rx gpio */
91 gpio_tlmm_config(19, 1, GPIO_INPUT, GPIO_NO_PULL,
92 GPIO_8MA, GPIO_DISABLE);
93 /* configure tx gpio */
94 gpio_tlmm_config(18, 1, GPIO_OUTPUT, GPIO_NO_PULL,
95 GPIO_8MA, GPIO_DISABLE);
96 break;
Amol Jadi0c04df82011-10-14 17:40:21 -070097
V S Ramanjaneya Kumar Tc633fe12013-01-08 14:55:54 -050098 case GSBI_ID_2:
99 /* configure rx gpio */
100 gpio_tlmm_config(22, 1, GPIO_INPUT, GPIO_NO_PULL,
101 GPIO_8MA, GPIO_DISABLE);
102 /* configure tx gpio */
103 gpio_tlmm_config(23, 1, GPIO_OUTPUT, GPIO_NO_PULL,
104 GPIO_8MA, GPIO_DISABLE);
105 break;
106
Amol Jadi0c04df82011-10-14 17:40:21 -0700107
Amol Jadia63aaff2012-02-01 15:51:50 -0800108 case GSBI_ID_7:
109 /* configure rx gpio */
110 gpio_tlmm_config(83, 1, GPIO_INPUT, GPIO_NO_PULL,
111 GPIO_8MA, GPIO_DISABLE);
112 /* configure tx gpio */
113 gpio_tlmm_config(82, 2, GPIO_OUTPUT, GPIO_NO_PULL,
114 GPIO_8MA, GPIO_DISABLE);
115 break;
116
117 default:
118 ASSERT(0);
119 }
120 }
121 else
122 {
123 switch (id) {
124
125 case GSBI_ID_3:
126 /* configure rx gpio */
127 gpio_tlmm_config(15, 1, GPIO_INPUT, GPIO_NO_PULL,
128 GPIO_8MA, GPIO_DISABLE);
129 /* configure tx gpio */
130 gpio_tlmm_config(14, 1, GPIO_OUTPUT, GPIO_NO_PULL,
131 GPIO_8MA, GPIO_DISABLE);
132 break;
133
134 case GSBI_ID_5:
135 /* configure rx gpio */
136 gpio_tlmm_config(23, 1, GPIO_INPUT, GPIO_NO_PULL,
137 GPIO_8MA, GPIO_DISABLE);
138 /* configure tx gpio */
139 gpio_tlmm_config(22, 1, GPIO_OUTPUT, GPIO_NO_PULL,
140 GPIO_8MA, GPIO_DISABLE);
141 break;
142
Neeti Desai46940292012-07-17 14:28:35 -0700143 case GSBI_ID_8:
144 /* configure rx gpio */
145 gpio_tlmm_config(35, 1, GPIO_INPUT, GPIO_NO_PULL,
146 GPIO_8MA, GPIO_DISABLE);
147 /* configure tx gpio */
148 gpio_tlmm_config(34, 1, GPIO_OUTPUT, GPIO_NO_PULL,
149 GPIO_8MA, GPIO_DISABLE);
150 break;
151
Amol Jadia63aaff2012-02-01 15:51:50 -0800152 default:
153 ASSERT(0);
154 }
Amol Jadic52c8a32011-07-12 11:27:04 -0700155 }
156}
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800157
158struct pm8xxx_gpio_init {
159 uint32_t gpio;
160 struct pm8921_gpio config;
161};
162
163#define PM8XXX_GPIO_INIT(_gpio, _dir, _buf, _val, _pull, _vin, _out_strength, \
164 _func, _inv, _disable) \
165{ \
166 .gpio = _gpio, \
167 .config = { \
168 .direction = _dir, \
169 .output_buffer = _buf, \
170 .output_value = _val, \
171 .pull = _pull, \
172 .vin_sel = _vin, \
173 .out_strength = _out_strength, \
174 .function = _func, \
175 .inv_int_pol = _inv, \
176 .disable_pin = _disable, \
177 } \
178}
179
180#define PM8XXX_GPIO_OUTPUT(_gpio, _val) \
181 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \
182 PM_GPIO_PULL_NO, 2, \
183 PM_GPIO_STRENGTH_HIGH, \
184 PM_GPIO_FUNC_NORMAL, 1, 0)
185
186
187#define PM8XXX_GPIO_INPUT(_gpio, _pull) \
188 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, 0, 0, \
189 _pull, 2, \
190 PM_GPIO_STRENGTH_NO, \
191 PM_GPIO_FUNC_NORMAL, 1, 0)
192
193/* Initial pm8038 GPIO configurations */
194static struct pm8xxx_gpio_init pm8038_keypad_gpios[] = {
195 /* keys GPIOs */
Ajay Dudanidc85e4a2012-03-08 20:09:17 -0800196 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_30),
197 PM8XXX_GPIO_INPUT(PM_GPIO(8), PM_GPIO_PULL_UP_30),
198 PM8XXX_GPIO_INPUT(PM_GPIO(10), PM_GPIO_PULL_UP_30),
199 PM8XXX_GPIO_INPUT(PM_GPIO(11), PM_GPIO_PULL_UP_30),
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800200};
201
202static struct pm8xxx_gpio_init pm8921_keypad_gpios[] = {
203 /* keys GPIOs */
204 PM8XXX_GPIO_INPUT(PM_GPIO(1), PM_GPIO_PULL_UP_31_5),
205 PM8XXX_GPIO_INPUT(PM_GPIO(2), PM_GPIO_PULL_UP_31_5),
206 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_31_5),
207 PM8XXX_GPIO_INPUT(PM_GPIO(4), PM_GPIO_PULL_UP_31_5),
208 PM8XXX_GPIO_INPUT(PM_GPIO(5), PM_GPIO_PULL_UP_31_5),
209 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
210};
211
Amol Jadi76071672012-02-03 12:19:36 -0800212/* pm8921 GPIO configuration for APQ8064 keypad */
213static struct pm8xxx_gpio_init pm8921_keypad_gpios_apq[] = {
214 /* keys GPIOs */
215 PM8XXX_GPIO_INPUT(PM_GPIO(35), PM_GPIO_PULL_UP_31_5),
216 PM8XXX_GPIO_INPUT(PM_GPIO(38), PM_GPIO_PULL_UP_31_5),
217 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
218};
219
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700220/* pm8917 GPIO configuration for APQ8064 keypad */
221static struct pm8xxx_gpio_init pm8917_keypad_gpios_apq[] = {
222 /* keys GPIOs */
223 PM8XXX_GPIO_INPUT(PM_GPIO(35), PM_GPIO_PULL_UP_31_5),
224 PM8XXX_GPIO_INPUT(PM_GPIO(30), PM_GPIO_PULL_UP_31_5),
225 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
226};
227
Neeti Desai7c303362012-09-18 11:50:22 -0700228/* pm8917 GPIO configuration for MSM8930 keypad */
229static struct pm8xxx_gpio_init pm8917_keypad_gpios[] = {
230 /* keys GPIOs */
231 PM8XXX_GPIO_INPUT(PM_GPIO(27), PM_GPIO_PULL_UP_30),
232 PM8XXX_GPIO_INPUT(PM_GPIO(28), PM_GPIO_PULL_UP_30),
233 PM8XXX_GPIO_INPUT(PM_GPIO(36), PM_GPIO_PULL_UP_30),
234 PM8XXX_GPIO_INPUT(PM_GPIO(37), PM_GPIO_PULL_UP_30),
235};
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700236
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800237void msm8960_keypad_gpio_init()
238{
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700239 int i = 0;
240 int num = 0;
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800241
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700242 num = ARRAY_SIZE(pm8921_keypad_gpios);
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800243
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700244 for(i=0; i < num; i++)
245 {
246 pm8921_gpio_config(pm8921_keypad_gpios[i].gpio,
247 &(pm8921_keypad_gpios[i].config));
248 }
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800249}
250
251void msm8930_keypad_gpio_init()
252{
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700253 int i = 0;
254 int num = 0;
Neeti Desai7c303362012-09-18 11:50:22 -0700255 struct pm8xxx_gpio_init *gpio_array;
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800256
Channagoud Kadabi80e776b2013-02-15 19:52:12 -0800257 if (platform_pmic_type(PMIC_IS_PM8917))
Neeti Desai7c303362012-09-18 11:50:22 -0700258 {
259 num = ARRAY_SIZE(pm8917_keypad_gpios);
260 gpio_array = pm8917_keypad_gpios;
261 }
262 else
263 {
264 num = ARRAY_SIZE(pm8038_keypad_gpios);
265 gpio_array = pm8038_keypad_gpios;
266 }
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800267
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700268 for(i=0; i < num; i++)
269 {
Neeti Desai7c303362012-09-18 11:50:22 -0700270 pm8921_gpio_config(gpio_array[i].gpio,
271 &(gpio_array[i].config));
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700272 }
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800273}
Amol Jadi76071672012-02-03 12:19:36 -0800274
275void apq8064_keypad_gpio_init()
276{
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700277 int i = 0;
278 int num = 0;
279 struct pm8xxx_gpio_init *gpio_array;
Amol Jadi76071672012-02-03 12:19:36 -0800280
Channagoud Kadabi80e776b2013-02-15 19:52:12 -0800281 if (platform_pmic_type(PMIC_IS_PM8917))
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700282 {
283 num = ARRAY_SIZE(pm8917_keypad_gpios_apq);
284 gpio_array = pm8917_keypad_gpios_apq;
285 }
286 else
287 {
Amol Jadi76071672012-02-03 12:19:36 -0800288 num = ARRAY_SIZE(pm8921_keypad_gpios_apq);
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700289 gpio_array = pm8921_keypad_gpios_apq;
290 }
Amol Jadi76071672012-02-03 12:19:36 -0800291
Deepa Dinamanib8b16432012-08-24 15:48:45 -0700292 for(i = 0; i < num; i++)
293 {
294 pm8921_gpio_config(gpio_array[i].gpio,
295 &(gpio_array[i].config));
296 }
Amol Jadi76071672012-02-03 12:19:36 -0800297}
298
Shashank Mittal4bfb2e32012-04-16 10:56:27 -0700299#define PM8921_GPIO_OUTPUT_FUNC(_gpio, _val, _func) \
300 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \
301 PM_GPIO_PULL_NO, 2, \
302 PM_GPIO_STRENGTH_HIGH, \
303 _func, 0, 0)
304
305
306#define PM8921_GPIO_OUTPUT_BUFCONF(_gpio, _val, _strength, _bufconf) \
307 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT,\
308 PM_GPIO_OUT_BUF_##_bufconf, _val, \
309 PM_GPIO_PULL_NO, 2, \
310 PM_GPIO_STRENGTH_##_strength, \
311 PM_GPIO_FUNC_NORMAL, 0, 0)
312
313
314static struct pm8xxx_gpio_init pm8921_display_gpios_apq[] = {
315 /* Display GPIOs */
316 /* Bl: ON, PWM mode */
317 PM8921_GPIO_OUTPUT_FUNC(PM_GPIO(26), 1, PM_GPIO_FUNC_2),
318 /* LCD1_PWR_EN_N */
319 PM8921_GPIO_OUTPUT_BUFCONF(PM_GPIO(36), 0, LOW, OPEN_DRAIN),
320 /* DISP_RESET_N */
321 PM8921_GPIO_OUTPUT_BUFCONF(PM_GPIO(25), 1, LOW, CMOS),
322};
323
324void apq8064_display_gpio_init()
325{
326 int i = 0;
327 int num = 0;
328
329 num = ARRAY_SIZE(pm8921_display_gpios_apq);
330
331 for (i = 0; i < num; i++) {
332 pm8921_gpio_config(pm8921_display_gpios_apq[i].gpio,
333 &(pm8921_display_gpios_apq[i].config));
334 }
335}