blob: 52db86341c05f822e4367150670863dd08ba83f9 [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 Jadicd43ea02011-02-15 20:56:04 -080036
37void gpio_tlmm_config(uint32_t gpio, uint8_t func,
Ajay Dudanib01e5062011-12-03 23:23:42 -080038 uint8_t dir, uint8_t pull,
39 uint8_t drvstr, uint32_t enable)
Amol Jadicd43ea02011-02-15 20:56:04 -080040{
Ajay Dudanib01e5062011-12-03 23:23:42 -080041 unsigned int val = 0;
42 val |= pull;
43 val |= func << 2;
44 val |= drvstr << 6;
45 val |= enable << 9;
46 unsigned int *addr = (unsigned int *)GPIO_CONFIG_ADDR(gpio);
47 writel(val, addr);
48 return;
Amol Jadicd43ea02011-02-15 20:56:04 -080049}
50
51void gpio_set(uint32_t gpio, uint32_t dir)
52{
Ajay Dudanib01e5062011-12-03 23:23:42 -080053 unsigned int *addr = (unsigned int *)GPIO_IN_OUT_ADDR(gpio);
54 writel(dir, addr);
55 return;
Amol Jadicd43ea02011-02-15 20:56:04 -080056}
Amol Jadic52c8a32011-07-12 11:27:04 -070057
58/* Configure gpio for uart - based on gsbi id */
59void gpio_config_uart_dm(uint8_t id)
60{
Ajay Dudanib01e5062011-12-03 23:23:42 -080061 switch (id) {
Amol Jadi0c04df82011-10-14 17:40:21 -070062
63 case GSBI_ID_3:
64 /* configure rx gpio */
65 gpio_tlmm_config(15, 1, GPIO_INPUT, GPIO_NO_PULL,
Ajay Dudanib01e5062011-12-03 23:23:42 -080066 GPIO_8MA, GPIO_DISABLE);
Amol Jadi0c04df82011-10-14 17:40:21 -070067 /* configure tx gpio */
68 gpio_tlmm_config(14, 1, GPIO_OUTPUT, GPIO_NO_PULL,
Ajay Dudanib01e5062011-12-03 23:23:42 -080069 GPIO_8MA, GPIO_DISABLE);
Amol Jadi0c04df82011-10-14 17:40:21 -070070 break;
71
Amol Jadic52c8a32011-07-12 11:27:04 -070072 case GSBI_ID_5:
73 /* configure rx gpio */
74 gpio_tlmm_config(23, 1, GPIO_INPUT, GPIO_NO_PULL,
Ajay Dudanib01e5062011-12-03 23:23:42 -080075 GPIO_8MA, GPIO_DISABLE);
Amol Jadic52c8a32011-07-12 11:27:04 -070076 /* configure tx gpio */
77 gpio_tlmm_config(22, 1, GPIO_OUTPUT, GPIO_NO_PULL,
Ajay Dudanib01e5062011-12-03 23:23:42 -080078 GPIO_8MA, GPIO_DISABLE);
Amol Jadic52c8a32011-07-12 11:27:04 -070079 break;
Amol Jadi0c04df82011-10-14 17:40:21 -070080
Amol Jadic52c8a32011-07-12 11:27:04 -070081 default:
82 ASSERT(0);
83 }
84}
Shashank Mittalb3be37f2012-01-16 22:59:49 -080085
86struct pm8xxx_gpio_init {
87 uint32_t gpio;
88 struct pm8921_gpio config;
89};
90
91#define PM8XXX_GPIO_INIT(_gpio, _dir, _buf, _val, _pull, _vin, _out_strength, \
92 _func, _inv, _disable) \
93{ \
94 .gpio = _gpio, \
95 .config = { \
96 .direction = _dir, \
97 .output_buffer = _buf, \
98 .output_value = _val, \
99 .pull = _pull, \
100 .vin_sel = _vin, \
101 .out_strength = _out_strength, \
102 .function = _func, \
103 .inv_int_pol = _inv, \
104 .disable_pin = _disable, \
105 } \
106}
107
108#define PM8XXX_GPIO_OUTPUT(_gpio, _val) \
109 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \
110 PM_GPIO_PULL_NO, 2, \
111 PM_GPIO_STRENGTH_HIGH, \
112 PM_GPIO_FUNC_NORMAL, 1, 0)
113
114
115#define PM8XXX_GPIO_INPUT(_gpio, _pull) \
116 PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, 0, 0, \
117 _pull, 2, \
118 PM_GPIO_STRENGTH_NO, \
119 PM_GPIO_FUNC_NORMAL, 1, 0)
120
121/* Initial pm8038 GPIO configurations */
122static struct pm8xxx_gpio_init pm8038_keypad_gpios[] = {
123 /* keys GPIOs */
124 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_1_5),
125 PM8XXX_GPIO_INPUT(PM_GPIO(8), PM_GPIO_PULL_UP_1_5),
126 PM8XXX_GPIO_INPUT(PM_GPIO(10), PM_GPIO_PULL_UP_1_5),
127 PM8XXX_GPIO_INPUT(PM_GPIO(11), PM_GPIO_PULL_UP_1_5),
128};
129
130static struct pm8xxx_gpio_init pm8921_keypad_gpios[] = {
131 /* keys GPIOs */
132 PM8XXX_GPIO_INPUT(PM_GPIO(1), PM_GPIO_PULL_UP_31_5),
133 PM8XXX_GPIO_INPUT(PM_GPIO(2), PM_GPIO_PULL_UP_31_5),
134 PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_31_5),
135 PM8XXX_GPIO_INPUT(PM_GPIO(4), PM_GPIO_PULL_UP_31_5),
136 PM8XXX_GPIO_INPUT(PM_GPIO(5), PM_GPIO_PULL_UP_31_5),
137 PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0),
138};
139
140void msm8960_keypad_gpio_init()
141{
142 int i = 0;
143 int num = 0;
144
145 num = ARRAY_SIZE(pm8921_keypad_gpios);
146
147 for(i=0; i < num; i++)
148 {
149 pm8921_gpio_config(pm8921_keypad_gpios[i].gpio,
150 &(pm8921_keypad_gpios[i].config));
151 }
152}
153
154void msm8930_keypad_gpio_init()
155{
156 int i = 0;
157 int num = 0;
158
159 num = ARRAY_SIZE(pm8038_keypad_gpios);
160
161 for(i=0; i < num; i++)
162 {
163 pm8921_gpio_config(pm8038_keypad_gpios[i].gpio,
164 &(pm8038_keypad_gpios[i].config));
165 }
166}