Shashank Mittal | b3be37f | 2012-01-16 22:59:49 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 2 | * |
| 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 Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 32 | #include <platform/gpio.h> |
| 33 | #include <gsbi.h> |
Shashank Mittal | b3be37f | 2012-01-16 22:59:49 -0800 | [diff] [blame] | 34 | #include <dev/pm8921.h> |
| 35 | #include <sys/types.h> |
Amol Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 36 | #include <smem.h> |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 37 | |
| 38 | void gpio_tlmm_config(uint32_t gpio, uint8_t func, |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 39 | uint8_t dir, uint8_t pull, |
| 40 | uint8_t drvstr, uint32_t enable) |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 41 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 42 | 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 Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void gpio_set(uint32_t gpio, uint32_t dir) |
| 53 | { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 54 | unsigned int *addr = (unsigned int *)GPIO_IN_OUT_ADDR(gpio); |
| 55 | writel(dir, addr); |
| 56 | return; |
Amol Jadi | cd43ea0 | 2011-02-15 20:56:04 -0800 | [diff] [blame] | 57 | } |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 58 | |
Amol Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 59 | /* 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 Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 63 | /* Configure gpio for uart - based on gsbi id */ |
| 64 | void gpio_config_uart_dm(uint8_t id) |
| 65 | { |
Amol Jadi | c426304 | 2012-03-29 16:18:11 -0700 | [diff] [blame] | 66 | 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 Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 84 | { |
| 85 | switch (id) { |
Amol Jadi | 0c04df8 | 2011-10-14 17:40:21 -0700 | [diff] [blame] | 86 | |
Amol Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 87 | 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 Jadi | 0c04df8 | 2011-10-14 17:40:21 -0700 | [diff] [blame] | 95 | |
Amol Jadi | 0c04df8 | 2011-10-14 17:40:21 -0700 | [diff] [blame] | 96 | |
Amol Jadi | a63aaff | 2012-02-01 15:51:50 -0800 | [diff] [blame] | 97 | 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 | |
| 132 | default: |
| 133 | ASSERT(0); |
| 134 | } |
Amol Jadi | c52c8a3 | 2011-07-12 11:27:04 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
Shashank Mittal | b3be37f | 2012-01-16 22:59:49 -0800 | [diff] [blame] | 137 | |
| 138 | struct pm8xxx_gpio_init { |
| 139 | uint32_t gpio; |
| 140 | struct pm8921_gpio config; |
| 141 | }; |
| 142 | |
| 143 | #define PM8XXX_GPIO_INIT(_gpio, _dir, _buf, _val, _pull, _vin, _out_strength, \ |
| 144 | _func, _inv, _disable) \ |
| 145 | { \ |
| 146 | .gpio = _gpio, \ |
| 147 | .config = { \ |
| 148 | .direction = _dir, \ |
| 149 | .output_buffer = _buf, \ |
| 150 | .output_value = _val, \ |
| 151 | .pull = _pull, \ |
| 152 | .vin_sel = _vin, \ |
| 153 | .out_strength = _out_strength, \ |
| 154 | .function = _func, \ |
| 155 | .inv_int_pol = _inv, \ |
| 156 | .disable_pin = _disable, \ |
| 157 | } \ |
| 158 | } |
| 159 | |
| 160 | #define PM8XXX_GPIO_OUTPUT(_gpio, _val) \ |
| 161 | PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \ |
| 162 | PM_GPIO_PULL_NO, 2, \ |
| 163 | PM_GPIO_STRENGTH_HIGH, \ |
| 164 | PM_GPIO_FUNC_NORMAL, 1, 0) |
| 165 | |
| 166 | |
| 167 | #define PM8XXX_GPIO_INPUT(_gpio, _pull) \ |
| 168 | PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_IN, 0, 0, \ |
| 169 | _pull, 2, \ |
| 170 | PM_GPIO_STRENGTH_NO, \ |
| 171 | PM_GPIO_FUNC_NORMAL, 1, 0) |
| 172 | |
| 173 | /* Initial pm8038 GPIO configurations */ |
| 174 | static struct pm8xxx_gpio_init pm8038_keypad_gpios[] = { |
| 175 | /* keys GPIOs */ |
Ajay Dudani | dc85e4a | 2012-03-08 20:09:17 -0800 | [diff] [blame] | 176 | PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_30), |
| 177 | PM8XXX_GPIO_INPUT(PM_GPIO(8), PM_GPIO_PULL_UP_30), |
| 178 | PM8XXX_GPIO_INPUT(PM_GPIO(10), PM_GPIO_PULL_UP_30), |
| 179 | PM8XXX_GPIO_INPUT(PM_GPIO(11), PM_GPIO_PULL_UP_30), |
Shashank Mittal | b3be37f | 2012-01-16 22:59:49 -0800 | [diff] [blame] | 180 | }; |
| 181 | |
| 182 | static struct pm8xxx_gpio_init pm8921_keypad_gpios[] = { |
| 183 | /* keys GPIOs */ |
| 184 | PM8XXX_GPIO_INPUT(PM_GPIO(1), PM_GPIO_PULL_UP_31_5), |
| 185 | PM8XXX_GPIO_INPUT(PM_GPIO(2), PM_GPIO_PULL_UP_31_5), |
| 186 | PM8XXX_GPIO_INPUT(PM_GPIO(3), PM_GPIO_PULL_UP_31_5), |
| 187 | PM8XXX_GPIO_INPUT(PM_GPIO(4), PM_GPIO_PULL_UP_31_5), |
| 188 | PM8XXX_GPIO_INPUT(PM_GPIO(5), PM_GPIO_PULL_UP_31_5), |
| 189 | PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0), |
| 190 | }; |
| 191 | |
Amol Jadi | 7607167 | 2012-02-03 12:19:36 -0800 | [diff] [blame] | 192 | /* pm8921 GPIO configuration for APQ8064 keypad */ |
| 193 | static struct pm8xxx_gpio_init pm8921_keypad_gpios_apq[] = { |
| 194 | /* keys GPIOs */ |
| 195 | PM8XXX_GPIO_INPUT(PM_GPIO(35), PM_GPIO_PULL_UP_31_5), |
| 196 | PM8XXX_GPIO_INPUT(PM_GPIO(38), PM_GPIO_PULL_UP_31_5), |
| 197 | PM8XXX_GPIO_OUTPUT(PM_GPIO(9), 0), |
| 198 | }; |
| 199 | |
Shashank Mittal | b3be37f | 2012-01-16 22:59:49 -0800 | [diff] [blame] | 200 | void msm8960_keypad_gpio_init() |
| 201 | { |
| 202 | int i = 0; |
| 203 | int num = 0; |
| 204 | |
| 205 | num = ARRAY_SIZE(pm8921_keypad_gpios); |
| 206 | |
| 207 | for(i=0; i < num; i++) |
| 208 | { |
| 209 | pm8921_gpio_config(pm8921_keypad_gpios[i].gpio, |
| 210 | &(pm8921_keypad_gpios[i].config)); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | void msm8930_keypad_gpio_init() |
| 215 | { |
| 216 | int i = 0; |
| 217 | int num = 0; |
| 218 | |
| 219 | num = ARRAY_SIZE(pm8038_keypad_gpios); |
| 220 | |
| 221 | for(i=0; i < num; i++) |
| 222 | { |
| 223 | pm8921_gpio_config(pm8038_keypad_gpios[i].gpio, |
| 224 | &(pm8038_keypad_gpios[i].config)); |
| 225 | } |
| 226 | } |
Amol Jadi | 7607167 | 2012-02-03 12:19:36 -0800 | [diff] [blame] | 227 | |
| 228 | void apq8064_keypad_gpio_init() |
| 229 | { |
| 230 | int i = 0; |
| 231 | int num = 0; |
| 232 | |
| 233 | num = ARRAY_SIZE(pm8921_keypad_gpios_apq); |
| 234 | |
| 235 | for(i=0; i < num; i++) |
| 236 | { |
| 237 | pm8921_gpio_config(pm8921_keypad_gpios_apq[i].gpio, |
| 238 | &(pm8921_keypad_gpios_apq[i].config)); |
| 239 | } |
| 240 | } |
| 241 | |
Shashank Mittal | 4bfb2e3 | 2012-04-16 10:56:27 -0700 | [diff] [blame] | 242 | #define PM8921_GPIO_OUTPUT_FUNC(_gpio, _val, _func) \ |
| 243 | PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT, 0, _val, \ |
| 244 | PM_GPIO_PULL_NO, 2, \ |
| 245 | PM_GPIO_STRENGTH_HIGH, \ |
| 246 | _func, 0, 0) |
| 247 | |
| 248 | |
| 249 | #define PM8921_GPIO_OUTPUT_BUFCONF(_gpio, _val, _strength, _bufconf) \ |
| 250 | PM8XXX_GPIO_INIT(_gpio, PM_GPIO_DIR_OUT,\ |
| 251 | PM_GPIO_OUT_BUF_##_bufconf, _val, \ |
| 252 | PM_GPIO_PULL_NO, 2, \ |
| 253 | PM_GPIO_STRENGTH_##_strength, \ |
| 254 | PM_GPIO_FUNC_NORMAL, 0, 0) |
| 255 | |
| 256 | |
| 257 | static struct pm8xxx_gpio_init pm8921_display_gpios_apq[] = { |
| 258 | /* Display GPIOs */ |
| 259 | /* Bl: ON, PWM mode */ |
| 260 | PM8921_GPIO_OUTPUT_FUNC(PM_GPIO(26), 1, PM_GPIO_FUNC_2), |
| 261 | /* LCD1_PWR_EN_N */ |
| 262 | PM8921_GPIO_OUTPUT_BUFCONF(PM_GPIO(36), 0, LOW, OPEN_DRAIN), |
| 263 | /* DISP_RESET_N */ |
| 264 | PM8921_GPIO_OUTPUT_BUFCONF(PM_GPIO(25), 1, LOW, CMOS), |
| 265 | }; |
| 266 | |
| 267 | void apq8064_display_gpio_init() |
| 268 | { |
| 269 | int i = 0; |
| 270 | int num = 0; |
| 271 | |
| 272 | num = ARRAY_SIZE(pm8921_display_gpios_apq); |
| 273 | |
| 274 | for (i = 0; i < num; i++) { |
| 275 | pm8921_gpio_config(pm8921_display_gpios_apq[i].gpio, |
| 276 | &(pm8921_display_gpios_apq[i].config)); |
| 277 | } |
| 278 | } |