Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009, Code Aurora Forum. All rights reserved. |
| 6 | * |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google, Inc. nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this |
| 18 | * software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 24 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 30 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | #include <assert.h> |
| 35 | #include <bits.h> |
Dima Zavin | 42f13d3 | 2009-01-29 11:47:57 -0800 | [diff] [blame] | 36 | #include <stdlib.h> |
| 37 | #include <string.h> |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 38 | #include <dev/keys.h> |
| 39 | #include <dev/gpio.h> |
| 40 | #include <dev/gpio_keypad.h> |
Dima Zavin | d6455cd | 2009-01-26 16:35:06 -0800 | [diff] [blame] | 41 | #include <kernel/event.h> |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 42 | #include <kernel/timer.h> |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 43 | #include <reg.h> |
David Ng | 6e1711f | 2010-01-19 15:27:00 -0800 | [diff] [blame] | 44 | #include <platform/iomap.h> |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 45 | |
| 46 | struct gpio_kp { |
| 47 | struct gpio_keypad_info *keypad_info; |
| 48 | struct timer timer; |
Dima Zavin | d6455cd | 2009-01-26 16:35:06 -0800 | [diff] [blame] | 49 | event_t full_scan; |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 50 | int current_output; |
| 51 | unsigned int some_keys_pressed:2; |
| 52 | unsigned long keys_pressed[0]; |
| 53 | }; |
| 54 | |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 55 | struct gpio_qwerty_kp { |
| 56 | struct qwerty_keypad_info *keypad_info; |
| 57 | struct timer timer; |
| 58 | event_t full_scan; |
| 59 | int num_of_scans; |
| 60 | unsigned int some_keys_pressed:2; |
| 61 | unsigned long keys_pressed[0]; |
| 62 | }; |
| 63 | |
| 64 | static struct gpio_qwerty_kp *qwerty_keypad; |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 65 | /* TODO: Support multiple keypads? */ |
| 66 | static struct gpio_kp *keypad; |
| 67 | |
| 68 | static void check_output(struct gpio_kp *kp, int out, int polarity) |
| 69 | { |
| 70 | struct gpio_keypad_info *kpinfo = kp->keypad_info; |
| 71 | int key_index; |
| 72 | int in; |
| 73 | int gpio; |
| 74 | int changed = 0; |
| 75 | |
| 76 | key_index = out * kpinfo->ninputs; |
| 77 | for (in = 0; in < kpinfo->ninputs; in++, key_index++) { |
| 78 | gpio = kpinfo->input_gpios[in]; |
| 79 | changed = 0; |
| 80 | if (gpio_get(gpio) ^ !polarity) { |
| 81 | if (kp->some_keys_pressed < 3) |
| 82 | kp->some_keys_pressed++; |
| 83 | changed = !bitmap_set(kp->keys_pressed, key_index); |
| 84 | } else { |
| 85 | changed = bitmap_clear(kp->keys_pressed, key_index); |
| 86 | } |
| 87 | if (changed) { |
| 88 | int state = bitmap_test(kp->keys_pressed, key_index); |
| 89 | keys_post_event(kpinfo->keymap[key_index], state); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | /* sets up the right state for the next poll cycle */ |
| 94 | gpio = kpinfo->output_gpios[out]; |
| 95 | if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE) |
| 96 | gpio_set(gpio, !polarity); |
| 97 | else |
| 98 | gpio_config(gpio, GPIO_INPUT); |
| 99 | } |
| 100 | |
| 101 | static enum handler_return |
| 102 | gpio_keypad_timer_func(struct timer *timer, time_t now, void *arg) |
| 103 | { |
| 104 | struct gpio_kp *kp = keypad; |
| 105 | struct gpio_keypad_info *kpinfo = kp->keypad_info; |
| 106 | int polarity = !!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH); |
Dima Zavin | 42f13d3 | 2009-01-29 11:47:57 -0800 | [diff] [blame] | 107 | int out; |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 108 | int gpio; |
| 109 | |
| 110 | out = kp->current_output; |
| 111 | if (out == kpinfo->noutputs) { |
| 112 | out = 0; |
| 113 | kp->some_keys_pressed = 0; |
| 114 | } else { |
| 115 | check_output(kp, out, polarity); |
| 116 | out++; |
| 117 | } |
| 118 | |
| 119 | kp->current_output = out; |
| 120 | if (out < kpinfo->noutputs) { |
| 121 | gpio = kpinfo->output_gpios[out]; |
| 122 | if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE) |
| 123 | gpio_set(gpio, polarity); |
| 124 | else |
| 125 | gpio_config(gpio, polarity ? GPIO_OUTPUT : 0); |
| 126 | timer_set_oneshot(timer, kpinfo->settle_time, |
| 127 | gpio_keypad_timer_func, NULL); |
| 128 | goto done; |
| 129 | } |
| 130 | |
| 131 | if (/*!kp->use_irq*/ 1 || kp->some_keys_pressed) { |
Dima Zavin | d6455cd | 2009-01-26 16:35:06 -0800 | [diff] [blame] | 132 | event_signal(&kp->full_scan, false); |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 133 | timer_set_oneshot(timer, kpinfo->poll_time, |
| 134 | gpio_keypad_timer_func, NULL); |
| 135 | goto done; |
| 136 | } |
| 137 | |
| 138 | #if 0 |
| 139 | /* No keys are pressed, reenable interrupt */ |
| 140 | for (out = 0; out < kpinfo->noutputs; out++) { |
| 141 | if (gpio_keypad_flags & GPIOKPF_DRIVE_INACTIVE) |
| 142 | gpio_set(kpinfo->output_gpios[out], polarity); |
| 143 | else |
| 144 | gpio_config(kpinfo->output_gpios[out], polarity ? GPIO_OUTPUT : 0); |
| 145 | } |
| 146 | for (in = 0; in < kpinfo->ninputs; in++) |
| 147 | enable_irq(gpio_to_irq(kpinfo->input_gpios[in])); |
| 148 | return INT_RESCHEDULE; |
| 149 | #endif |
| 150 | |
| 151 | done: |
| 152 | return INT_RESCHEDULE; |
| 153 | } |
| 154 | |
| 155 | void gpio_keypad_init(struct gpio_keypad_info *kpinfo) |
| 156 | { |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 157 | int key_count; |
| 158 | int output_val; |
| 159 | int output_cfg; |
| 160 | int i; |
| 161 | int len; |
| 162 | |
| 163 | ASSERT(kpinfo->keymap && kpinfo->input_gpios && kpinfo->output_gpios); |
| 164 | key_count = kpinfo->ninputs * kpinfo->noutputs; |
| 165 | |
| 166 | len = sizeof(struct gpio_kp) + (sizeof(unsigned long) * |
| 167 | BITMAP_NUM_WORDS(key_count)); |
| 168 | keypad = malloc(len); |
| 169 | ASSERT(keypad); |
| 170 | |
| 171 | memset(keypad, 0, len); |
| 172 | keypad->keypad_info = kpinfo; |
| 173 | |
| 174 | output_val = (!!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH)) ^ |
| 175 | (!!(kpinfo->flags & GPIOKPF_DRIVE_INACTIVE)); |
| 176 | output_cfg = kpinfo->flags & GPIOKPF_DRIVE_INACTIVE ? GPIO_OUTPUT : 0; |
| 177 | for (i = 0; i < kpinfo->noutputs; i++) { |
| 178 | gpio_set(kpinfo->output_gpios[i], output_val); |
| 179 | gpio_config(kpinfo->output_gpios[i], output_cfg); |
| 180 | } |
| 181 | for (i = 0; i < kpinfo->ninputs; i++) |
| 182 | gpio_config(kpinfo->input_gpios[i], GPIO_INPUT); |
| 183 | |
| 184 | keypad->current_output = kpinfo->noutputs; |
| 185 | |
Dima Zavin | d6455cd | 2009-01-26 16:35:06 -0800 | [diff] [blame] | 186 | event_init(&keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL); |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 187 | timer_initialize(&keypad->timer); |
| 188 | timer_set_oneshot(&keypad->timer, 0, gpio_keypad_timer_func, NULL); |
Dima Zavin | d6455cd | 2009-01-26 16:35:06 -0800 | [diff] [blame] | 189 | |
| 190 | /* wait for the keypad to complete one full scan */ |
| 191 | event_wait(&keypad->full_scan); |
Dima Zavin | 0f88be2 | 2009-01-20 19:25:50 -0800 | [diff] [blame] | 192 | } |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 193 | |
| 194 | int i2c_ssbi_poll_for_device_ready(void) |
| 195 | { |
| 196 | unsigned long timeout = SSBI_TIMEOUT_US; |
| 197 | |
| 198 | while (!(readl(MSM_SSBI_BASE + SSBI2_STATUS) & SSBI_STATUS_READY)) { |
| 199 | if (--timeout == 0) { |
| 200 | dprintf(INFO, "In Device ready function:Timeout, status %x\n", readl(MSM_SSBI_BASE + SSBI2_STATUS)); |
| 201 | return 1; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | int i2c_ssbi_poll_for_read_completed(void) |
| 209 | { |
| 210 | unsigned long timeout = SSBI_TIMEOUT_US; |
| 211 | |
| 212 | while (!(readl(MSM_SSBI_BASE + SSBI2_STATUS) & SSBI_STATUS_RD_READY)) { |
| 213 | if (--timeout == 0) { |
| 214 | dprintf(INFO, "In read completed function:Timeout, status %x\n", readl(MSM_SSBI_BASE + SSBI2_STATUS)); |
| 215 | return 1; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | int i2c_ssbi_read_bytes(unsigned char *buffer, unsigned short length, |
| 223 | unsigned short slave_addr) |
| 224 | { |
| 225 | int ret = 0; |
| 226 | unsigned char *buf = buffer; |
| 227 | unsigned short len = length; |
| 228 | unsigned short addr = slave_addr; |
| 229 | unsigned long read_cmd = SSBI_CMD_READ(addr); |
| 230 | unsigned long mode2 = readl(MSM_SSBI_BASE + SSBI2_MODE2); |
| 231 | |
| 232 | //buf = alloc(len * sizeof(8)); |
| 233 | if (mode2 & SSBI_MODE2_SSBI2_MODE) |
| 234 | writel(SSBI_MODE2_REG_ADDR_15_8(mode2, addr), |
| 235 | MSM_SSBI_BASE + SSBI2_MODE2); |
| 236 | |
| 237 | while (len) { |
| 238 | ret = i2c_ssbi_poll_for_device_ready(); |
| 239 | if (ret) { |
| 240 | dprintf (CRITICAL, "Error: device not ready\n"); |
| 241 | return ret; |
| 242 | } |
| 243 | |
| 244 | writel(read_cmd, MSM_SSBI_BASE + SSBI2_CMD); |
| 245 | |
| 246 | ret = i2c_ssbi_poll_for_read_completed(); |
| 247 | if (ret) { |
| 248 | dprintf (CRITICAL, "Error: read not completed\n"); |
| 249 | return ret; |
| 250 | } |
| 251 | |
| 252 | *buf++ = readl(MSM_SSBI_BASE + SSBI2_RD) & SSBI_RD_REG_DATA_MASK; |
| 253 | len--; |
| 254 | } |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | int i2c_ssbi_write_bytes(unsigned char *buffer, unsigned short length, |
| 259 | unsigned short slave_addr) |
| 260 | { |
| 261 | int ret = 0; |
| 262 | unsigned long timeout = SSBI_TIMEOUT_US; |
| 263 | unsigned char *buf = buffer; |
| 264 | unsigned short len = length; |
| 265 | unsigned short addr = slave_addr; |
| 266 | unsigned long mode2 = readl(MSM_SSBI_BASE + SSBI2_MODE2); |
| 267 | |
| 268 | if (mode2 & SSBI_MODE2_SSBI2_MODE) |
| 269 | writel(SSBI_MODE2_REG_ADDR_15_8(mode2, addr), |
| 270 | MSM_SSBI_BASE + SSBI2_MODE2); |
| 271 | |
| 272 | while (len) { |
| 273 | ret = i2c_ssbi_poll_for_device_ready(); |
| 274 | if (ret) { |
| 275 | dprintf (CRITICAL, "Error: device not ready\n"); |
| 276 | return ret; |
| 277 | } |
| 278 | |
| 279 | writel(SSBI_CMD_WRITE(addr, *buf++), MSM_SSBI_BASE + SSBI2_CMD); |
| 280 | |
| 281 | while (readl(MSM_SSBI_BASE + SSBI2_STATUS) & SSBI_STATUS_MCHN_BUSY) { |
| 282 | if (--timeout == 0) { |
| 283 | dprintf(INFO, "In Device ready function:Timeout, status %x\n", readl(MSM_SSBI_BASE + SSBI2_STATUS)); |
| 284 | return 1; |
| 285 | } |
| 286 | } |
| 287 | len--; |
| 288 | } |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | int pm8058_gpio_config(int gpio, struct pm8058_gpio *param) |
| 293 | { |
| 294 | int rc; |
| 295 | unsigned char bank[8]; |
| 296 | static int dir_map[] = { |
| 297 | PM8058_GPIO_MODE_OFF, |
| 298 | PM8058_GPIO_MODE_OUTPUT, |
| 299 | PM8058_GPIO_MODE_INPUT, |
| 300 | PM8058_GPIO_MODE_BOTH, |
| 301 | }; |
| 302 | |
| 303 | if (param == 0) { |
| 304 | dprintf (INFO, "pm8058_gpio struct not defined\n"); |
| 305 | return -1; |
| 306 | } |
| 307 | |
| 308 | /* Select banks and configure the gpio */ |
| 309 | bank[0] = PM8058_GPIO_WRITE | |
| 310 | ((param->vin_sel << PM8058_GPIO_VIN_SHIFT) & |
| 311 | PM8058_GPIO_VIN_MASK) | |
| 312 | PM8058_GPIO_MODE_ENABLE; |
| 313 | bank[1] = PM8058_GPIO_WRITE | |
| 314 | ((1 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) | |
| 315 | ((dir_map[param->direction] << PM8058_GPIO_MODE_SHIFT) & |
| 316 | PM8058_GPIO_MODE_MASK) | |
| 317 | ((param->direction & PM_GPIO_DIR_OUT) ? |
| 318 | PM8058_GPIO_OUT_BUFFER : 0); |
| 319 | bank[2] = PM8058_GPIO_WRITE | |
| 320 | ((2 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) | |
| 321 | ((param->pull << PM8058_GPIO_PULL_SHIFT) & |
| 322 | PM8058_GPIO_PULL_MASK); |
| 323 | bank[3] = PM8058_GPIO_WRITE | |
| 324 | ((3 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) | |
| 325 | ((param->out_strength << PM8058_GPIO_OUT_STRENGTH_SHIFT) & |
| 326 | PM8058_GPIO_OUT_STRENGTH_MASK); |
| 327 | bank[4] = PM8058_GPIO_WRITE | |
| 328 | ((4 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) | |
| 329 | ((param->function << PM8058_GPIO_FUNC_SHIFT) & |
| 330 | PM8058_GPIO_FUNC_MASK); |
| 331 | |
| 332 | rc = i2c_ssbi_write_bytes(bank, 5, SSBI_REG_ADDR_GPIO(gpio)); |
| 333 | if (rc) { |
| 334 | dprintf(INFO, "Failed on 1st ssbi_write(): rc=%d.\n", rc); |
| 335 | return 1; |
| 336 | } |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | int pm8058_gpio_config_kypd_drv(int gpio_start, int num_gpios) |
| 341 | { |
| 342 | int rc; |
| 343 | struct pm8058_gpio kypd_drv = { |
| 344 | .direction = PM_GPIO_DIR_OUT, |
| 345 | .pull = PM_GPIO_PULL_NO, |
| 346 | .vin_sel = 2, |
| 347 | .out_strength = PM_GPIO_STRENGTH_LOW, |
| 348 | .function = PM_GPIO_FUNC_1, |
| 349 | .inv_int_pol = 1, |
| 350 | }; |
| 351 | |
| 352 | while (num_gpios--) { |
| 353 | rc = pm8058_gpio_config(gpio_start++, &kypd_drv); |
| 354 | if (rc) { |
| 355 | dprintf(INFO, "FAIL pm8058_gpio_config(): rc=%d.\n", rc); |
| 356 | return rc; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | int pm8058_gpio_config_kypd_sns(int gpio_start, int num_gpios) |
| 364 | { |
| 365 | int rc; |
| 366 | struct pm8058_gpio kypd_sns = { |
| 367 | .direction = PM_GPIO_DIR_IN, |
| 368 | .pull = PM_GPIO_PULL_UP1, |
| 369 | .vin_sel = 2, |
| 370 | .out_strength = PM_GPIO_STRENGTH_NO, |
| 371 | .function = PM_GPIO_FUNC_NORMAL, |
| 372 | .inv_int_pol = 1, |
| 373 | }; |
| 374 | |
| 375 | while (num_gpios--) { |
| 376 | rc = pm8058_gpio_config(gpio_start++, &kypd_sns); |
| 377 | if (rc) { |
| 378 | dprintf(INFO, "FAIL pm8058_gpio_config(): rc=%d.\n", rc); |
| 379 | return rc; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static enum handler_return |
| 387 | scan_qwerty_keypad(struct timer *timer, time_t now, void *arg) |
| 388 | { |
| 389 | int rows = (qwerty_keypad->keypad_info)->rows; |
Chandan Uddaraju | a342574 | 2010-02-09 22:45:33 -0800 | [diff] [blame^] | 390 | int columns = NUM_OF_KYPD_SNS_GPIOS; |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 391 | unsigned char column_keys = 0x00; |
| 392 | int shift = 0; |
| 393 | static int key_detected = 0; |
| 394 | |
| 395 | if (i2c_ssbi_read_bytes((qwerty_keypad->keypad_info)->rec_keys, NUM_OF_SSBI_READS, |
| 396 | SSBI_REG_KYPD_REC_DATA_ADDR)) |
| 397 | dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n"); |
| 398 | |
| 399 | if (i2c_ssbi_read_bytes((qwerty_keypad->keypad_info)->old_keys, NUM_OF_SSBI_READS, |
| 400 | SSBI_REG_KYPD_OLD_DATA_ADDR)) |
| 401 | dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n"); |
| 402 | |
| 403 | while (rows--) { |
| 404 | if ((qwerty_keypad->keypad_info)->rec_keys[rows] |
| 405 | != (qwerty_keypad->keypad_info)->old_keys[rows]) { |
| 406 | while (columns--) { |
| 407 | column_keys = ((qwerty_keypad->keypad_info)->rec_keys[rows]); |
| 408 | if ((0x01 << columns) & (~column_keys)) { |
| 409 | shift = (rows * (qwerty_keypad->keypad_info)->columns) + columns; |
| 410 | if ((qwerty_keypad->keypad_info)->keymap[shift]) { |
| 411 | if (shift != key_detected) { |
| 412 | // key_changed((qwerty_keypad->keypad_info)->keymap[shift], 1); |
| 413 | key_detected = shift; |
| 414 | keys_post_event((qwerty_keypad->keypad_info)->keymap[shift], 1); |
| 415 | event_signal(&qwerty_keypad->full_scan, false); |
| 416 | timer_set_oneshot(timer, (qwerty_keypad->keypad_info)->poll_time, |
| 417 | scan_qwerty_keypad, NULL); |
| 418 | return INT_RESCHEDULE; |
| 419 | |
| 420 | } |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 421 | } |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | if (qwerty_keypad->num_of_scans < 10) |
| 427 | { |
| 428 | (qwerty_keypad->num_of_scans)++; |
| 429 | timer_set_oneshot(timer, (qwerty_keypad->keypad_info)->settle_time, |
| 430 | scan_qwerty_keypad, NULL); |
| 431 | return INT_RESCHEDULE; |
| 432 | } |
| 433 | |
| 434 | event_signal(&qwerty_keypad->full_scan, false); |
| 435 | return INT_RESCHEDULE; |
| 436 | |
| 437 | } |
| 438 | |
| 439 | void ssbi_gpio_init(void) |
| 440 | { |
Chandan Uddaraju | a342574 | 2010-02-09 22:45:33 -0800 | [diff] [blame^] | 441 | unsigned char kypd_cntl_init = 0x84; |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 442 | unsigned char kypd_scan_init = 0x20; |
| 443 | |
| 444 | if (i2c_ssbi_write_bytes(&kypd_cntl_init, 1, SSBI_REG_KYPD_CNTL_ADDR)) |
| 445 | dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n"); |
| 446 | |
| 447 | if (i2c_ssbi_write_bytes(&kypd_scan_init, 1, SSBI_REG_KYPD_SCAN_ADDR)) |
| 448 | dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_SCAN register\n"); |
| 449 | |
| 450 | pm8058_gpio_config_kypd_sns(SSBI_OFFSET_ADDR_GPIO_KYPD_SNS, NUM_OF_KYPD_SNS_GPIOS); |
| 451 | pm8058_gpio_config_kypd_drv(SSBI_OFFSET_ADDR_GPIO_KYPD_DRV, NUM_OF_KYPD_DRV_GPIOS); |
| 452 | |
| 453 | |
| 454 | } |
| 455 | |
| 456 | void ssbi_keypad_init(struct qwerty_keypad_info *qwerty_kp) |
| 457 | { |
David Ng | 6e1711f | 2010-01-19 15:27:00 -0800 | [diff] [blame] | 458 | int *modem_stat_check = (MSM_SHARED_BASE + 0x14); |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 459 | int len; |
| 460 | |
| 461 | /* Wait for modem to be ready before keypad init */ |
| 462 | while (readl(modem_stat_check) != 1); |
| 463 | |
| 464 | ssbi_gpio_init(); |
| 465 | |
| 466 | len = sizeof(struct gpio_qwerty_kp); |
| 467 | qwerty_keypad = malloc(len); |
| 468 | ASSERT(qwerty_keypad); |
| 469 | |
| 470 | memset(qwerty_keypad, 0, len); |
| 471 | qwerty_keypad->keypad_info = qwerty_kp; |
| 472 | qwerty_keypad->num_of_scans = 0; |
| 473 | |
| 474 | event_init(&qwerty_keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL); |
| 475 | timer_initialize(&qwerty_keypad->timer); |
| 476 | timer_set_oneshot(&qwerty_keypad->timer, 0, scan_qwerty_keypad, NULL); |
| 477 | |
| 478 | /* wait for the keypad to complete one full scan */ |
| 479 | event_wait(&qwerty_keypad->full_scan); |
| 480 | } |
| 481 | |