blob: 5f0e818eb1c6b77a9693697d2a69f8c14e652480 [file] [log] [blame]
Dima Zavin0f88be22009-01-20 19:25:50 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
Duy Truongf3ac7b32013-02-13 01:07:28 -08005 * Copyright (c) 2009-2012, The Linux Foundation. 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>
Kinson Chikea646242011-09-01 13:53:16 -070041#include <dev/ssbi.h>
Dima Zavind6455cd2009-01-26 16:35:06 -080042#include <kernel/event.h>
Dima Zavin0f88be22009-01-20 19:25:50 -080043#include <kernel/timer.h>
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080044#include <reg.h>
David Ng6e1711f2010-01-19 15:27:00 -080045#include <platform/iomap.h>
Greg Griscod6250552011-06-29 14:40:23 -070046#include <platform/timer.h>
47#include <platform.h>
Dima Zavin0f88be22009-01-20 19:25:50 -080048
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -080049#define LINUX_MACHTYPE_8660_QT 3298
50
Dima Zavin0f88be22009-01-20 19:25:50 -080051struct gpio_kp {
52 struct gpio_keypad_info *keypad_info;
53 struct timer timer;
Dima Zavind6455cd2009-01-26 16:35:06 -080054 event_t full_scan;
Dima Zavin0f88be22009-01-20 19:25:50 -080055 int current_output;
56 unsigned int some_keys_pressed:2;
57 unsigned long keys_pressed[0];
58};
59
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080060struct gpio_qwerty_kp {
61 struct qwerty_keypad_info *keypad_info;
62 struct timer timer;
63 event_t full_scan;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080064 unsigned int some_keys_pressed:2;
65 unsigned long keys_pressed[0];
66};
67
68static struct gpio_qwerty_kp *qwerty_keypad;
Dima Zavin0f88be22009-01-20 19:25:50 -080069/* TODO: Support multiple keypads? */
70static struct gpio_kp *keypad;
71
72static void check_output(struct gpio_kp *kp, int out, int polarity)
73{
74 struct gpio_keypad_info *kpinfo = kp->keypad_info;
75 int key_index;
76 int in;
77 int gpio;
78 int changed = 0;
79
80 key_index = out * kpinfo->ninputs;
81 for (in = 0; in < kpinfo->ninputs; in++, key_index++) {
82 gpio = kpinfo->input_gpios[in];
83 changed = 0;
84 if (gpio_get(gpio) ^ !polarity) {
85 if (kp->some_keys_pressed < 3)
86 kp->some_keys_pressed++;
87 changed = !bitmap_set(kp->keys_pressed, key_index);
88 } else {
89 changed = bitmap_clear(kp->keys_pressed, key_index);
90 }
91 if (changed) {
92 int state = bitmap_test(kp->keys_pressed, key_index);
93 keys_post_event(kpinfo->keymap[key_index], state);
94 }
95 }
96
97 /* sets up the right state for the next poll cycle */
98 gpio = kpinfo->output_gpios[out];
99 if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE)
100 gpio_set(gpio, !polarity);
101 else
102 gpio_config(gpio, GPIO_INPUT);
103}
104
105static enum handler_return
106gpio_keypad_timer_func(struct timer *timer, time_t now, void *arg)
107{
108 struct gpio_kp *kp = keypad;
109 struct gpio_keypad_info *kpinfo = kp->keypad_info;
110 int polarity = !!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH);
Dima Zavin42f13d32009-01-29 11:47:57 -0800111 int out;
Dima Zavin0f88be22009-01-20 19:25:50 -0800112 int gpio;
113
114 out = kp->current_output;
115 if (out == kpinfo->noutputs) {
116 out = 0;
117 kp->some_keys_pressed = 0;
118 } else {
119 check_output(kp, out, polarity);
120 out++;
121 }
122
123 kp->current_output = out;
124 if (out < kpinfo->noutputs) {
125 gpio = kpinfo->output_gpios[out];
126 if (kpinfo->flags & GPIOKPF_DRIVE_INACTIVE)
127 gpio_set(gpio, polarity);
128 else
129 gpio_config(gpio, polarity ? GPIO_OUTPUT : 0);
130 timer_set_oneshot(timer, kpinfo->settle_time,
131 gpio_keypad_timer_func, NULL);
132 goto done;
133 }
134
135 if (/*!kp->use_irq*/ 1 || kp->some_keys_pressed) {
Dima Zavind6455cd2009-01-26 16:35:06 -0800136 event_signal(&kp->full_scan, false);
Dima Zavin0f88be22009-01-20 19:25:50 -0800137 timer_set_oneshot(timer, kpinfo->poll_time,
138 gpio_keypad_timer_func, NULL);
139 goto done;
140 }
141
Dima Zavin0f88be22009-01-20 19:25:50 -0800142done:
143 return INT_RESCHEDULE;
144}
145
146void gpio_keypad_init(struct gpio_keypad_info *kpinfo)
147{
Dima Zavin0f88be22009-01-20 19:25:50 -0800148 int key_count;
149 int output_val;
150 int output_cfg;
151 int i;
152 int len;
153
154 ASSERT(kpinfo->keymap && kpinfo->input_gpios && kpinfo->output_gpios);
155 key_count = kpinfo->ninputs * kpinfo->noutputs;
156
157 len = sizeof(struct gpio_kp) + (sizeof(unsigned long) *
158 BITMAP_NUM_WORDS(key_count));
159 keypad = malloc(len);
160 ASSERT(keypad);
161
162 memset(keypad, 0, len);
163 keypad->keypad_info = kpinfo;
164
165 output_val = (!!(kpinfo->flags & GPIOKPF_ACTIVE_HIGH)) ^
166 (!!(kpinfo->flags & GPIOKPF_DRIVE_INACTIVE));
167 output_cfg = kpinfo->flags & GPIOKPF_DRIVE_INACTIVE ? GPIO_OUTPUT : 0;
168 for (i = 0; i < kpinfo->noutputs; i++) {
169 gpio_set(kpinfo->output_gpios[i], output_val);
170 gpio_config(kpinfo->output_gpios[i], output_cfg);
171 }
172 for (i = 0; i < kpinfo->ninputs; i++)
173 gpio_config(kpinfo->input_gpios[i], GPIO_INPUT);
174
175 keypad->current_output = kpinfo->noutputs;
176
Dima Zavind6455cd2009-01-26 16:35:06 -0800177 event_init(&keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL);
Dima Zavin0f88be22009-01-20 19:25:50 -0800178 timer_initialize(&keypad->timer);
179 timer_set_oneshot(&keypad->timer, 0, gpio_keypad_timer_func, NULL);
Dima Zavind6455cd2009-01-26 16:35:06 -0800180
181 /* wait for the keypad to complete one full scan */
182 event_wait(&keypad->full_scan);
Dima Zavin0f88be22009-01-20 19:25:50 -0800183}
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800184
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800185int pm8058_gpio_config(int gpio, struct pm8058_gpio *param)
186{
187 int rc;
Chandan Uddarajubedca152010-06-02 23:05:15 -0700188 write_func wr_function = (qwerty_keypad->keypad_info)->wr_func;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800189 unsigned char bank[8];
190 static int dir_map[] = {
191 PM8058_GPIO_MODE_OFF,
192 PM8058_GPIO_MODE_OUTPUT,
193 PM8058_GPIO_MODE_INPUT,
194 PM8058_GPIO_MODE_BOTH,
195 };
196
197 if (param == 0) {
198 dprintf (INFO, "pm8058_gpio struct not defined\n");
199 return -1;
200 }
201
202 /* Select banks and configure the gpio */
203 bank[0] = PM8058_GPIO_WRITE |
204 ((param->vin_sel << PM8058_GPIO_VIN_SHIFT) &
205 PM8058_GPIO_VIN_MASK) |
206 PM8058_GPIO_MODE_ENABLE;
207 bank[1] = PM8058_GPIO_WRITE |
208 ((1 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
209 ((dir_map[param->direction] << PM8058_GPIO_MODE_SHIFT) &
210 PM8058_GPIO_MODE_MASK) |
211 ((param->direction & PM_GPIO_DIR_OUT) ?
212 PM8058_GPIO_OUT_BUFFER : 0);
213 bank[2] = PM8058_GPIO_WRITE |
214 ((2 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
215 ((param->pull << PM8058_GPIO_PULL_SHIFT) &
216 PM8058_GPIO_PULL_MASK);
217 bank[3] = PM8058_GPIO_WRITE |
218 ((3 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
219 ((param->out_strength << PM8058_GPIO_OUT_STRENGTH_SHIFT) &
220 PM8058_GPIO_OUT_STRENGTH_MASK);
221 bank[4] = PM8058_GPIO_WRITE |
222 ((4 << PM8058_GPIO_BANK_SHIFT) & PM8058_GPIO_BANK_MASK) |
223 ((param->function << PM8058_GPIO_FUNC_SHIFT) &
224 PM8058_GPIO_FUNC_MASK);
225
Chandan Uddarajubedca152010-06-02 23:05:15 -0700226 rc = (*wr_function)(bank, 5, SSBI_REG_ADDR_GPIO(gpio));
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800227 if (rc) {
228 dprintf(INFO, "Failed on 1st ssbi_write(): rc=%d.\n", rc);
229 return 1;
230 }
231 return 0;
232}
233
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800234int pm8058_gpio_config_kypd_drv(int gpio_start, int num_gpios, unsigned mach_id)
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800235{
236 int rc;
237 struct pm8058_gpio kypd_drv = {
238 .direction = PM_GPIO_DIR_OUT,
239 .pull = PM_GPIO_PULL_NO,
240 .vin_sel = 2,
241 .out_strength = PM_GPIO_STRENGTH_LOW,
242 .function = PM_GPIO_FUNC_1,
243 .inv_int_pol = 1,
244 };
245
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800246 if(mach_id == LINUX_MACHTYPE_8660_QT)
247 kypd_drv.function = PM_GPIO_FUNC_NORMAL;
248
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800249 while (num_gpios--) {
250 rc = pm8058_gpio_config(gpio_start++, &kypd_drv);
251 if (rc) {
252 dprintf(INFO, "FAIL pm8058_gpio_config(): rc=%d.\n", rc);
253 return rc;
254 }
255 }
256
257 return 0;
258}
259
260int pm8058_gpio_config_kypd_sns(int gpio_start, int num_gpios)
261{
262 int rc;
263 struct pm8058_gpio kypd_sns = {
264 .direction = PM_GPIO_DIR_IN,
265 .pull = PM_GPIO_PULL_UP1,
266 .vin_sel = 2,
267 .out_strength = PM_GPIO_STRENGTH_NO,
268 .function = PM_GPIO_FUNC_NORMAL,
269 .inv_int_pol = 1,
270 };
271
272 while (num_gpios--) {
273 rc = pm8058_gpio_config(gpio_start++, &kypd_sns);
274 if (rc) {
275 dprintf(INFO, "FAIL pm8058_gpio_config(): rc=%d.\n", rc);
276 return rc;
277 }
278 }
279
280 return 0;
281}
282
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800283static void ssbi_gpio_init(unsigned int mach_id)
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800284{
Dima Zavinaacfed22011-01-14 15:40:29 -0800285 unsigned char kypd_cntl_init;
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800286 unsigned char kypd_scan_init = 0x20;
Chandan Uddarajubedca152010-06-02 23:05:15 -0700287 int rows = (qwerty_keypad->keypad_info)->rows;
288 int columns = (qwerty_keypad->keypad_info)->columns;
289 write_func wr_function = (qwerty_keypad->keypad_info)->wr_func;
Dima Zavinaacfed22011-01-14 15:40:29 -0800290 unsigned char drv_bits[] = {
291 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7 };
292 unsigned char sns_bits[] = { 0, 0, 0, 0, 0, 0, 1, 2, 3 };
293
Ajay Dudani35e7aae2011-01-20 22:24:16 -0800294 kypd_cntl_init = ((drv_bits[rows] << 2) | (sns_bits[columns] << 5) | (1 << 7));
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800295
Chandan Uddarajubedca152010-06-02 23:05:15 -0700296 if ((*wr_function)(&kypd_cntl_init, 1, SSBI_REG_KYPD_CNTL_ADDR))
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800297 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");
298
Chandan Uddarajubedca152010-06-02 23:05:15 -0700299 if ((*wr_function)(&kypd_scan_init, 1, SSBI_REG_KYPD_SCAN_ADDR))
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800300 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_SCAN register\n");
301
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800302 if(mach_id == LINUX_MACHTYPE_8660_QT)
303 {
304 pm8058_gpio_config_kypd_sns(QT_PMIC_GPIO_KYPD_SNS, rows);
305 pm8058_gpio_config_kypd_drv(QT_PMIC_GPIO_KYPD_DRV, columns, mach_id);
306 }
307 else
308 {
309 pm8058_gpio_config_kypd_sns(SSBI_OFFSET_ADDR_GPIO_KYPD_SNS, columns);
310 pm8058_gpio_config_kypd_drv(SSBI_OFFSET_ADDR_GPIO_KYPD_DRV, rows, mach_id);
311 }
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800312}
313
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800314static enum handler_return
315scan_qwerty_keypad(struct timer *timer, time_t now, void *arg)
316{
Chandan Uddarajubedca152010-06-02 23:05:15 -0700317 unsigned int rows = (qwerty_keypad->keypad_info)->rows;
318 unsigned int columns = (qwerty_keypad->keypad_info)->columns;
319 unsigned int num_of_ssbi_reads = (qwerty_keypad->keypad_info)->num_of_reads;
320 read_func rd_function = (qwerty_keypad->keypad_info)->rd_func;
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800321 unsigned char column_new_keys = 0x00;
322 unsigned char column_old_keys = 0x00;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800323 int shift = 0;
Ajay Dudani25478462011-04-11 19:36:57 -0700324 static int key_detected = -1;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800325
Chandan Uddarajubedca152010-06-02 23:05:15 -0700326 if ((*rd_function)((qwerty_keypad->keypad_info)->rec_keys, num_of_ssbi_reads,
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800327 SSBI_REG_KYPD_REC_DATA_ADDR))
328 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");
329
Chandan Uddarajubedca152010-06-02 23:05:15 -0700330 if ((*rd_function)((qwerty_keypad->keypad_info)->old_keys, num_of_ssbi_reads,
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800331 SSBI_REG_KYPD_OLD_DATA_ADDR))
332 dprintf (CRITICAL, "Error in initializing SSBI_REG_KYPD_CNTL register\n");
333
334 while (rows--) {
Dima Zavin80906902011-01-14 15:40:55 -0800335 columns = qwerty_keypad->keypad_info->columns;
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800336 if (((qwerty_keypad->keypad_info)->rec_keys[rows]
337 != (qwerty_keypad->keypad_info)->old_keys[rows])
338 && ((qwerty_keypad->keypad_info)->rec_keys[rows] != 0x00)
339 && ((qwerty_keypad->keypad_info)->old_keys[rows] != 0x00)) {
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800340 while (columns--) {
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800341 column_new_keys = ((qwerty_keypad->keypad_info)->rec_keys[rows]);
342 column_old_keys = ((qwerty_keypad->keypad_info)->old_keys[rows]);
343 if (((0x01 << columns) & (~column_new_keys))
344 && !((0x01 << columns) & (~column_old_keys))) {
Chandan Uddarajubedca152010-06-02 23:05:15 -0700345 shift = (rows * 8) + columns;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800346 if ((qwerty_keypad->keypad_info)->keymap[shift]) {
Chandan Uddaraju2aba2732010-02-24 13:31:43 -0800347 if (shift != key_detected) {
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800348 key_detected = shift;
349 keys_post_event((qwerty_keypad->keypad_info)->keymap[shift], 1);
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800350 }
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800351 }
352 }
353 }
354 }
355 }
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800356
357 event_signal(&qwerty_keypad->full_scan, false);
358 return INT_RESCHEDULE;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800359}
360
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800361static enum handler_return
362scan_qt_keypad(struct timer *timer, time_t now, void *arg)
363{
364 unsigned int gpio;
365 unsigned int last_state=0;
366 unsigned int new_state=0;
367 unsigned int bits_changed;
Ajay Dudani25478462011-04-11 19:36:57 -0700368 static int key_detected=-1;
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800369
370 /* Row GPIOs 8,9,10 are used for sensing here */
Greg Griscod6250552011-06-29 14:40:23 -0700371 for (gpio=8;gpio<=10;gpio++)
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800372 {
373 bool status;
374 status = pm8058_gpio_get(gpio);
Greg Griscod6250552011-06-29 14:40:23 -0700375 if (status == 0)
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800376 new_state |= (1<<(gpio-8));
377 }
378
379 bits_changed = last_state ^ new_state;
380
Greg Griscod6250552011-06-29 14:40:23 -0700381 if (bits_changed)
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800382 {
Greg Griscod6250552011-06-29 14:40:23 -0700383 int shift = 0;
384 for (unsigned int rows = 0; rows < (qwerty_keypad->keypad_info)->rows; rows++)
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800385 {
Greg Griscod6250552011-06-29 14:40:23 -0700386 if ((bits_changed & (1<<rows)) == 0)
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800387 continue;
Greg Griscod6250552011-06-29 14:40:23 -0700388 shift = rows * 8 + 3;
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800389 }
390 if ((qwerty_keypad->keypad_info)->keymap[shift])
391 {
392 if (shift != key_detected)
393 {
394 key_detected = shift;
395 keys_post_event((qwerty_keypad->keypad_info)->keymap[shift], 1);
396 timer_set_oneshot(timer,(qwerty_keypad->keypad_info)->poll_time,
397 scan_qt_keypad, NULL);
398 return INT_RESCHEDULE;
399 }
400 }
401 }
402 event_signal(&qwerty_keypad->full_scan, false);
403 return INT_RESCHEDULE;
404}
405
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800406void ssbi_keypad_init(struct qwerty_keypad_info *qwerty_kp)
407{
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800408 unsigned int mach_id;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800409 int len;
410
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800411 len = sizeof(struct gpio_qwerty_kp);
412 qwerty_keypad = malloc(len);
413 ASSERT(qwerty_keypad);
414
415 memset(qwerty_keypad, 0, len);
416 qwerty_keypad->keypad_info = qwerty_kp;
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800417
418 event_init(&qwerty_keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL);
419 timer_initialize(&qwerty_keypad->timer);
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800420
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800421 mach_id = board_machtype();
Subbaraman Narayanamurthy8f0b0452011-03-11 18:30:10 -0800422 ssbi_gpio_init(mach_id);
423
424 if(mach_id == LINUX_MACHTYPE_8660_QT)
425 {
426 mdelay((qwerty_keypad->keypad_info)->settle_time);
427#ifdef QT_8660_KEYPAD_HW_BUG
428 timer_set_oneshot(&qwerty_keypad->timer, 0, scan_qt_keypad, NULL);
429#endif
430 }
431 else
432 timer_set_oneshot(&qwerty_keypad->timer, 0, scan_qwerty_keypad, NULL);
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -0800433
434 /* wait for the keypad to complete one full scan */
435 event_wait(&qwerty_keypad->full_scan);
436}
437
Shashank Mittalb3be37f2012-01-16 22:59:49 -0800438static enum handler_return
439scan_qwerty_gpio_keypad(struct timer *timer, time_t now, void *arg)
440{
441 int i=0;
442 int num =0;
443 uint8_t key_status;
444 struct qwerty_keypad_info *keypad = qwerty_keypad->keypad_info;
445
446 num = keypad->mapsize;
447
448 for(i=0; i < num; i++)
449 {
450 /*continue if not interested in key*/
451 if(!keypad->keymap[i])
452 continue;
453
454 /*read key gpio*/
455 keypad->key_gpio_get(keypad->gpiomap[i], &key_status);
456
457 /*Post event if key pressed*/
458 if(key_status)
459 {
460 keys_post_event(keypad->keymap[i], 1);
461 goto done;
462 }
463 }
464
465done:
466 event_signal(&qwerty_keypad->full_scan, false);
467 return INT_RESCHEDULE;
468}
469
470void ssbi_gpio_keypad_init(struct qwerty_keypad_info *qwerty_kp)
471{
472 int len;
473
474 len = sizeof(struct gpio_qwerty_kp);
475 qwerty_keypad = malloc(len);
476 ASSERT(qwerty_keypad);
477
478 memset(qwerty_keypad, 0, len);
479 qwerty_keypad->keypad_info = qwerty_kp;
480
481 event_init(&qwerty_keypad->full_scan, false, EVENT_FLAG_AUTOUNSIGNAL);
482 timer_initialize(&qwerty_keypad->timer);
483
484 timer_set_oneshot(&qwerty_keypad->timer, 0, scan_qwerty_gpio_keypad, NULL);
485
486 /* wait for the keypad to complete one full scan */
487 event_wait(&qwerty_keypad->full_scan);
488}
489
Shashank Mittal37040832010-08-24 15:57:57 -0700490void pmic_write(unsigned address, unsigned data)
491{
492 write_func wr_function = &i2c_ssbi_write_bytes;
Greg Griscod6250552011-06-29 14:40:23 -0700493 if (wr_function == NULL)
Shashank Mittal37040832010-08-24 15:57:57 -0700494 return;
Greg Griscod6250552011-06-29 14:40:23 -0700495 if ((*wr_function)((unsigned char *) &data, 1, address))
Shashank Mittal37040832010-08-24 15:57:57 -0700496 dprintf (CRITICAL, "Error in initializing register\n");
497
498}
Chandan Uddarajuc009e4d2010-09-08 17:06:45 -0700499void toshiba_pmic_gpio_init(unsigned gpio)
500{
501 pmic_write(gpio,0x85);
502 pmic_write(gpio,0x98);
503 pmic_write(gpio,0xB8);
504 pmic_write(gpio,0xC6);
505}