blob: 4fc2e4eeffb2b1ce176e275660496f9b5ab21aeb [file] [log] [blame]
Dima Zavin0f88be22009-01-20 19:25:50 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
Chandan Uddarajubedca152010-06-02 23:05:15 -07005 * Copyright (c) 2009-2010, Code Aurora Forum. All rights reserved.
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -08006 *
Dima Zavin0f88be22009-01-20 19:25:50 -08007 * 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 Zavin42f13d32009-01-29 11:47:57 -080036#include <stdlib.h>
37#include <string.h>
Dima Zavin0f88be22009-01-20 19:25:50 -080038#include <dev/keys.h>
39#include <dev/gpio.h>
40#include <dev/gpio_keypad.h>
Dima Zavind6455cd2009-01-26 16:35:06 -080041#include <kernel/event.h>
Dima Zavin0f88be22009-01-20 19:25:50 -080042#include <kernel/timer.h>
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080043#include <reg.h>
David Ng6e1711f2010-01-19 15:27:00 -080044#include <platform/iomap.h>
Dima Zavin0f88be22009-01-20 19:25:50 -080045
46struct gpio_kp {
47 struct gpio_keypad_info *keypad_info;
48 struct timer timer;
Dima Zavind6455cd2009-01-26 16:35:06 -080049 event_t full_scan;
Dima Zavin0f88be22009-01-20 19:25:50 -080050 int current_output;
51 unsigned int some_keys_pressed:2;
52 unsigned long keys_pressed[0];
53};
54
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080055struct 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
64static struct gpio_qwerty_kp *qwerty_keypad;
Dima Zavin0f88be22009-01-20 19:25:50 -080065/* TODO: Support multiple keypads? */
66static struct gpio_kp *keypad;
67
68static 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
101static enum handler_return
102gpio_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 Zavin42f13d32009-01-29 11:47:57 -0800107 int out;
Dima Zavin0f88be22009-01-20 19:25:50 -0800108 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 Zavind6455cd2009-01-26 16:35:06 -0800132 event_signal(&kp->full_scan, false);
Dima Zavin0f88be22009-01-20 19:25:50 -0800133 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
151done:
152 return INT_RESCHEDULE;
153}
154
155void gpio_keypad_init(struct gpio_keypad_info *kpinfo)
156{
Dima Zavin0f88be22009-01-20 19:25:50 -0800157 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 Zavind6455cd2009-01-26 16:35:06 -0800186 event_init(&keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL);
Dima Zavin0f88be22009-01-20 19:25:50 -0800187 timer_initialize(&keypad->timer);
188 timer_set_oneshot(&keypad->timer, 0, gpio_keypad_timer_func, NULL);
Dima Zavind6455cd2009-01-26 16:35:06 -0800189
190 /* wait for the keypad to complete one full scan */
191 event_wait(&keypad->full_scan);
Dima Zavin0f88be22009-01-20 19:25:50 -0800192}
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800193
194int 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
208int 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
222int 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
258int 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
Chandan Uddarajubedca152010-06-02 23:05:15 -0700292int pa1_ssbi2_read_bytes(unsigned char *buffer, unsigned short length,
293 unsigned short slave_addr)
294{
295 unsigned val = 0x0;
296 unsigned temp = 0x0000;
297 unsigned char *buf = buffer;
298 unsigned short len = length;
299 unsigned short addr = slave_addr;
300 unsigned long timeout = SSBI_TIMEOUT_US;
301
302 while(len)
303 {
304 val |= ((addr << PA1_SSBI2_REG_ADDR_SHIFT) |
305 (PA1_SSBI2_CMD_READ << PA1_SSBI2_CMD_RDWRN_SHIFT));
306 writel(val, PA1_SSBI2_CMD);
307 while(!((temp = readl(PA1_SSBI2_RD_STATUS)) & (1 << PA1_SSBI2_TRANS_DONE_SHIFT))) {
308 if (--timeout == 0) {
309 dprintf(INFO, "In Device ready function:Timeout\n");
310 return 1;
311 }
312 }
313 len--;
314 *buf++ = (temp & (PA1_SSBI2_REG_DATA_MASK << PA1_SSBI2_REG_DATA_SHIFT));
315 }
316 return 0;
317}
318
319int pa1_ssbi2_write_bytes(unsigned char *buffer, unsigned short length,
320 unsigned short slave_addr)
321{
322 unsigned val;
323 unsigned char *buf = buffer;
324 unsigned short len = length;
325 unsigned short addr = slave_addr;
326 unsigned temp = 0x00;
327 unsigned char written_data1 = 0x00;
328 unsigned long timeout = SSBI_TIMEOUT_US;
329 //unsigned char written_data2 = 0x00;
330
331 while(len)
332 {
333 temp = 0x00;
334 written_data1 = 0x00;
335 val = (addr << PA1_SSBI2_REG_ADDR_SHIFT) |
336 (PA1_SSBI2_CMD_WRITE << PA1_SSBI2_CMD_RDWRN_SHIFT) |
337 (*buf & 0xFF);
338 writel(val, PA1_SSBI2_CMD);
339 while(!((temp = readl(PA1_SSBI2_RD_STATUS)) & (1 << PA1_SSBI2_TRANS_DONE_SHIFT))) {
340 if (--timeout == 0) {
341 dprintf(INFO, "In Device write function:Timeout\n");
342 return 1;
343 }
344 }
345 len--;
346 buf++;
347 }
348 return 0;
349}
350
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800351int pm8058_gpio_config(int gpio, struct pm8058_gpio *param)
352{
353 int rc;
Chandan Uddarajubedca152010-06-02 23:05:15 -0700354 write_func wr_function = (qwerty_keypad->keypad_info)->wr_func;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800355 unsigned char bank[8];
356 static int dir_map[] = {
357 PM8058_GPIO_MODE_OFF,
358 PM8058_GPIO_MODE_OUTPUT,
359 PM8058_GPIO_MODE_INPUT,
360 PM8058_GPIO_MODE_BOTH,
361 };
362
363 if (param == 0) {
364 dprintf (INFO, "pm8058_gpio struct not defined\n");
365 return -1;
366 }
367
368 /* Select banks and configure the gpio */
369 bank[0] = PM8058_GPIO_WRITE |
370 ((param->vin_sel << PM8058_GPIO_VIN_SHIFT) &
371 PM8058_GPIO_VIN_MASK) |
372 PM8058_GPIO_MODE_ENABLE;
373 bank[1] = PM8058_GPIO_WRITE |
374 ((1 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
375 ((dir_map[param->direction] << PM8058_GPIO_MODE_SHIFT) &
376 PM8058_GPIO_MODE_MASK) |
377 ((param->direction & PM_GPIO_DIR_OUT) ?
378 PM8058_GPIO_OUT_BUFFER : 0);
379 bank[2] = PM8058_GPIO_WRITE |
380 ((2 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
381 ((param->pull << PM8058_GPIO_PULL_SHIFT) &
382 PM8058_GPIO_PULL_MASK);
383 bank[3] = PM8058_GPIO_WRITE |
384 ((3 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
385 ((param->out_strength << PM8058_GPIO_OUT_STRENGTH_SHIFT) &
386 PM8058_GPIO_OUT_STRENGTH_MASK);
387 bank[4] = PM8058_GPIO_WRITE |
388 ((4 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
389 ((param->function << PM8058_GPIO_FUNC_SHIFT) &
390 PM8058_GPIO_FUNC_MASK);
391
Chandan Uddarajubedca152010-06-02 23:05:15 -0700392 rc = (*wr_function)(bank, 5, SSBI_REG_ADDR_GPIO(gpio));
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800393 if (rc) {
394 dprintf(INFO, "Failed on 1st ssbi_write(): rc=%d.\n", rc);
395 return 1;
396 }
397 return 0;
398}
399
400int pm8058_gpio_config_kypd_drv(int gpio_start, int num_gpios)
401{
402 int rc;
403 struct pm8058_gpio kypd_drv = {
404 .direction = PM_GPIO_DIR_OUT,
405 .pull = PM_GPIO_PULL_NO,
406 .vin_sel = 2,
407 .out_strength = PM_GPIO_STRENGTH_LOW,
408 .function = PM_GPIO_FUNC_1,
409 .inv_int_pol = 1,
410 };
411
412 while (num_gpios--) {
413 rc = pm8058_gpio_config(gpio_start++, &kypd_drv);
414 if (rc) {
415 dprintf(INFO, "FAIL pm8058_gpio_config(): rc=%d.\n", rc);
416 return rc;
417 }
418 }
419
420 return 0;
421}
422
423int pm8058_gpio_config_kypd_sns(int gpio_start, int num_gpios)
424{
425 int rc;
426 struct pm8058_gpio kypd_sns = {
427 .direction = PM_GPIO_DIR_IN,
428 .pull = PM_GPIO_PULL_UP1,
429 .vin_sel = 2,
430 .out_strength = PM_GPIO_STRENGTH_NO,
431 .function = PM_GPIO_FUNC_NORMAL,
432 .inv_int_pol = 1,
433 };
434
435 while (num_gpios--) {
436 rc = pm8058_gpio_config(gpio_start++, &kypd_sns);
437 if (rc) {
438 dprintf(INFO, "FAIL pm8058_gpio_config(): rc=%d.\n", rc);
439 return rc;
440 }
441 }
442
443 return 0;
444}
445
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800446void ssbi_gpio_init(void)
447{
448 unsigned char kypd_cntl_init = 0x84;
449 unsigned char kypd_scan_init = 0x20;
Chandan Uddarajubedca152010-06-02 23:05:15 -0700450 int rows = (qwerty_keypad->keypad_info)->rows;
451 int columns = (qwerty_keypad->keypad_info)->columns;
452 write_func wr_function = (qwerty_keypad->keypad_info)->wr_func;
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800453
Chandan Uddarajubedca152010-06-02 23:05:15 -0700454 if ((*wr_function)(&kypd_cntl_init, 1, SSBI_REG_KYPD_CNTL_ADDR))
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800455 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");
456
Chandan Uddarajubedca152010-06-02 23:05:15 -0700457 if ((*wr_function)(&kypd_scan_init, 1, SSBI_REG_KYPD_SCAN_ADDR))
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800458 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_SCAN register\n");
459
Chandan Uddarajubedca152010-06-02 23:05:15 -0700460 pm8058_gpio_config_kypd_sns(SSBI_OFFSET_ADDR_GPIO_KYPD_SNS, columns);
461 pm8058_gpio_config_kypd_drv(SSBI_OFFSET_ADDR_GPIO_KYPD_DRV, rows);
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800462}
463
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800464static enum handler_return
465scan_qwerty_keypad(struct timer *timer, time_t now, void *arg)
466{
Chandan Uddarajubedca152010-06-02 23:05:15 -0700467 unsigned int rows = (qwerty_keypad->keypad_info)->rows;
468 unsigned int columns = (qwerty_keypad->keypad_info)->columns;
469 unsigned int num_of_ssbi_reads = (qwerty_keypad->keypad_info)->num_of_reads;
470 read_func rd_function = (qwerty_keypad->keypad_info)->rd_func;
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800471 unsigned char column_new_keys = 0x00;
472 unsigned char column_old_keys = 0x00;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800473 int shift = 0;
474 static int key_detected = 0;
475
Chandan Uddarajubedca152010-06-02 23:05:15 -0700476 if ((*rd_function)((qwerty_keypad->keypad_info)->rec_keys, num_of_ssbi_reads,
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800477 SSBI_REG_KYPD_REC_DATA_ADDR))
478 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");
479
Chandan Uddarajubedca152010-06-02 23:05:15 -0700480 if ((*rd_function)((qwerty_keypad->keypad_info)->old_keys, num_of_ssbi_reads,
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800481 SSBI_REG_KYPD_OLD_DATA_ADDR))
482 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");
483
484 while (rows--) {
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800485 if (((qwerty_keypad->keypad_info)->rec_keys[rows]
486 != (qwerty_keypad->keypad_info)->old_keys[rows])
487 && ((qwerty_keypad->keypad_info)->rec_keys[rows] != 0x00)
488 && ((qwerty_keypad->keypad_info)->old_keys[rows] != 0x00)) {
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800489 while (columns--) {
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800490 column_new_keys = ((qwerty_keypad->keypad_info)->rec_keys[rows]);
491 column_old_keys = ((qwerty_keypad->keypad_info)->old_keys[rows]);
492 if (((0x01 << columns) & (~column_new_keys))
493 && !((0x01 << columns) & (~column_old_keys))) {
Chandan Uddarajubedca152010-06-02 23:05:15 -0700494 shift = (rows * 8) + columns;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800495 if ((qwerty_keypad->keypad_info)->keymap[shift]) {
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800496 if (shift != key_detected) {
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800497 key_detected = shift;
498 keys_post_event((qwerty_keypad->keypad_info)->keymap[shift], 1);
499 event_signal(&qwerty_keypad->full_scan, false);
500 timer_set_oneshot(timer, (qwerty_keypad->keypad_info)->poll_time,
501 scan_qwerty_keypad, NULL);
502 return INT_RESCHEDULE;
503
504 }
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800505 }
506 }
507 }
508 }
509 }
510 if (qwerty_keypad->num_of_scans < 10)
511 {
512 (qwerty_keypad->num_of_scans)++;
513 timer_set_oneshot(timer, (qwerty_keypad->keypad_info)->settle_time,
514 scan_qwerty_keypad, NULL);
515 return INT_RESCHEDULE;
516 }
517
518 event_signal(&qwerty_keypad->full_scan, false);
519 return INT_RESCHEDULE;
520
521}
522
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800523void ssbi_keypad_init(struct qwerty_keypad_info *qwerty_kp)
524{
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800525 int len;
526
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800527 len = sizeof(struct gpio_qwerty_kp);
528 qwerty_keypad = malloc(len);
529 ASSERT(qwerty_keypad);
530
531 memset(qwerty_keypad, 0, len);
532 qwerty_keypad->keypad_info = qwerty_kp;
Chandan Uddarajubedca152010-06-02 23:05:15 -0700533 ssbi_gpio_init();
534
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800535 qwerty_keypad->num_of_scans = 0;
536
537 event_init(&qwerty_keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL);
538 timer_initialize(&qwerty_keypad->timer);
539 timer_set_oneshot(&qwerty_keypad->timer, 0, scan_qwerty_keypad, NULL);
540
541 /* wait for the keypad to complete one full scan */
542 event_wait(&qwerty_keypad->full_scan);
543}
544
Shashank Mittal37040832010-08-24 15:57:57 -0700545void pmic_write(unsigned address, unsigned data)
546{
547 write_func wr_function = &i2c_ssbi_write_bytes;
548 if(wr_function == NULL)
549 return;
550 if ((*wr_function)(&data, 1, address))
551 dprintf (CRITICAL, "Error in initializing register\n");
552
553}
554