blob: d43e81cb84350a35a042d1a056a887898967c284 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Quanta I2C Keyboard Driver
2 *
3 * Copyright (C) 2009 Quanta Computer Inc.
Duy Truong790f06d2013-02-13 16:38:12 -08004 * Copyright (c) 2010, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07005 * Author: Hsin Wu <hsin.wu@quantatw.com>
6 * Author: Austin Lai <austin.lai@quantatw.com>
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 */
18
19 /*
20 *
21 * The Driver with I/O communications via the I2C Interface for ON2 of AP BU.
22 * And it is only working on the nuvoTon WPCE775x Embedded Controller.
23 *
24 */
25
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/module.h>
29#include <linux/slab.h>
30#include <linux/jiffies.h>
31#include <linux/i2c.h>
32#include <linux/mutex.h>
33#include <linux/interrupt.h>
34#include <linux/input.h>
35#include <linux/keyboard.h>
36#include <linux/gpio.h>
37#include <linux/delay.h>
38
39#include <linux/input/qci_kbd.h>
40
41/* Keyboard special scancode */
42#define RC_KEY_FN 0x70
43#define RC_KEY_BREAK 0x80
44#define KEY_ACK_FA 0xFA
45#define SCAN_EMUL0 0xE0
46#define SCAN_EMUL1 0xE1
47#define SCAN_PAUSE1 0x1D
48#define SCAN_PAUSE2 0x45
49#define SCAN_LIDSW_OPEN 0x70
50#define SCAN_LIDSW_CLOSE 0x71
51
52/* Keyboard keycodes */
53#define NOKEY KEY_RESERVED
54#define KEY_LEFTWIN KEY_LEFTMETA
55#define KEY_RIGHTWIN KEY_RIGHTMETA
56#define KEY_APPS KEY_COMPOSE
57#define KEY_PRINTSCR KEY_SYSRQ
58
59#define KEYBOARD_ID_NAME "qci-i2ckbd"
60#define KEYBOARD_NAME "Quanta Keyboard"
61#define KEYBOARD_DEVICE "/i2c/input0"
62#define KEYBOARD_CMD_ENABLE 0xF4
63#define KEYBOARD_CMD_SET_LED 0xED
64
65/*-----------------------------------------------------------------------------
66 * Keyboard scancode to linux keycode translation table
67 *---------------------------------------------------------------------------*/
68
69static const unsigned char on2_keycode[256] = {
70 [0] = NOKEY,
71 [1] = NOKEY,
72 [2] = NOKEY,
73 [3] = KEY_5,
74 [4] = KEY_7,
75 [5] = KEY_9,
76 [6] = KEY_MINUS,
77 [7] = NOKEY,
78 [8] = NOKEY,
79 [9] = NOKEY,
80 [10] = NOKEY,
81 [11] = KEY_LEFTBRACE,
82 [12] = KEY_F10,
83 [13] = KEY_INSERT,
84 [14] = KEY_F11,
85 [15] = KEY_ESC,
86 [16] = NOKEY,
87 [17] = NOKEY,
88 [18] = NOKEY,
89 [19] = KEY_4,
90 [20] = KEY_6,
91 [21] = KEY_8,
92 [22] = KEY_0,
93 [23] = KEY_EQUAL,
94 [24] = NOKEY,
95 [25] = NOKEY,
96 [26] = NOKEY,
97 [27] = KEY_P,
98 [28] = KEY_F9,
99 [29] = KEY_DELETE,
100 [30] = KEY_F12,
101 [31] = KEY_GRAVE,
102 [32] = KEY_W,
103 [33] = NOKEY,
104 [34] = NOKEY,
105 [35] = KEY_R,
106 [36] = KEY_T,
107 [37] = KEY_U,
108 [38] = KEY_O,
109 [39] = KEY_RIGHTBRACE,
110 [40] = NOKEY,
111 [41] = NOKEY,
112 [42] = NOKEY,
113 [43] = KEY_APOSTROPHE,
114 [44] = KEY_BACKSPACE,
115 [45] = NOKEY,
116 [46] = KEY_F8,
117 [47] = KEY_F5,
118 [48] = KEY_S,
119 [49] = NOKEY,
120 [50] = NOKEY,
121 [51] = KEY_E,
122 [52] = KEY_H,
123 [53] = KEY_Y,
124 [54] = KEY_I,
125 [55] = KEY_ENTER,
126 [56] = NOKEY,
127 [57] = NOKEY,
128 [58] = NOKEY,
129 [59] = KEY_SEMICOLON,
130 [60] = KEY_3,
131 [61] = KEY_PAGEUP,
132 [62] = KEY_Q,
133 [63] = KEY_TAB,
134 [64] = KEY_A,
135 [65] = NOKEY,
136 [66] = NOKEY,
137 [67] = KEY_F,
138 [68] = KEY_G,
139 [69] = KEY_J,
140 [70] = KEY_L,
141 [71] = NOKEY,
142 [72] = KEY_RIGHTSHIFT,
143 [73] = NOKEY,
144 [74] = NOKEY,
145 [75] = KEY_SLASH,
146 [76] = KEY_2,
147 [77] = KEY_PAGEDOWN,
148 [78] = KEY_F4,
149 [79] = KEY_F1,
150 [80] = KEY_Z,
151 [81] = NOKEY,
152 [82] = NOKEY,
153 [83] = KEY_D,
154 [84] = KEY_V,
155 [85] = KEY_N,
156 [86] = KEY_K,
157 [87] = NOKEY,
158 [88] = KEY_LEFTSHIFT,
159 [89] = KEY_RIGHTCTRL,
160 [90] = NOKEY,
161 [91] = KEY_DOT,
162 [92] = KEY_UP,
163 [93] = KEY_RIGHT,
164 [94] = KEY_F3,
165 [95] = KEY_F2,
166 [96] = NOKEY,
167 [97] = NOKEY,
168 [98] = KEY_RIGHTALT,
169 [99] = KEY_X,
170 [100] = KEY_C,
171 [101] = KEY_B,
172 [102] = KEY_COMMA,
173 [103] = NOKEY,
174 [104] = NOKEY,
175 [105] = NOKEY,
176 [106] = NOKEY,
177 [107] = NOKEY,
178 [108] = KEY_PRINTSCR,
179 [109] = KEY_DOWN,
180 [110] = KEY_1,
181 [111] = KEY_CAPSLOCK,
182 [112] = KEY_F24,
183 [113] = KEY_HOME,
184 [114] = KEY_LEFTALT,
185 [115] = NOKEY,
186 [116] = KEY_SPACE,
187 [117] = KEY_BACKSLASH,
188 [118] = KEY_M,
189 [119] = KEY_COMPOSE,
190 [120] = NOKEY,
191 [121] = KEY_LEFTCTRL,
192 [122] = NOKEY,
193 [123] = NOKEY,
194 [124] = KEY_PAUSE,
195 [125] = KEY_LEFT,
196 [126] = KEY_F7,
197 [127] = KEY_F6,
198 [128] = NOKEY,
199 [129] = NOKEY,
200 [130] = NOKEY,
201 [131] = NOKEY,
202 [132] = NOKEY,
203 [133] = NOKEY,
204 [134] = NOKEY,
205 [135] = NOKEY,
206 [136] = NOKEY,
207 [137] = NOKEY,
208 [138] = NOKEY,
209 [139] = NOKEY,
210 [140] = NOKEY,
211 [141] = NOKEY,
212 [142] = NOKEY,
213 [143] = NOKEY,
214 [144] = NOKEY,
215 [145] = NOKEY,
216 [146] = NOKEY,
217 [147] = NOKEY,
218 [148] = NOKEY,
219 [149] = NOKEY,
220 [150] = NOKEY,
221 [151] = NOKEY,
222 [152] = NOKEY,
223 [153] = NOKEY,
224 [154] = NOKEY,
225 [155] = NOKEY,
226 [156] = NOKEY,
227 [157] = NOKEY,
228 [158] = NOKEY,
229 [159] = NOKEY,
230 [160] = NOKEY,
231 [161] = NOKEY,
232 [162] = NOKEY,
233 [163] = NOKEY,
234 [164] = NOKEY,
235 [165] = NOKEY,
236 [166] = NOKEY,
237 [167] = NOKEY,
238 [168] = NOKEY,
239 [169] = NOKEY,
240 [170] = NOKEY,
241 [171] = NOKEY,
242 [172] = NOKEY,
243 [173] = NOKEY,
244 [174] = NOKEY,
245 [175] = NOKEY,
246 [176] = NOKEY,
247 [177] = NOKEY,
248 [178] = NOKEY,
249 [179] = NOKEY,
250 [180] = NOKEY,
251 [181] = NOKEY,
252 [182] = NOKEY,
253 [183] = NOKEY,
254 [184] = NOKEY,
255 [185] = NOKEY,
256 [186] = NOKEY,
257 [187] = NOKEY,
258 [188] = NOKEY,
259 [189] = KEY_HOME,
260 [190] = NOKEY,
261 [191] = NOKEY,
262 [192] = NOKEY,
263 [193] = NOKEY,
264 [194] = NOKEY,
265 [195] = NOKEY,
266 [196] = NOKEY,
267 [197] = NOKEY,
268 [198] = NOKEY,
269 [199] = NOKEY,
270 [200] = NOKEY,
271 [201] = NOKEY,
272 [202] = NOKEY,
273 [203] = NOKEY,
274 [204] = NOKEY,
275 [205] = KEY_END,
276 [206] = NOKEY,
277 [207] = NOKEY,
278 [208] = NOKEY,
279 [209] = NOKEY,
280 [210] = NOKEY,
281 [211] = NOKEY,
282 [212] = NOKEY,
283 [213] = NOKEY,
284 [214] = NOKEY,
285 [215] = NOKEY,
286 [216] = NOKEY,
287 [217] = NOKEY,
288 [218] = NOKEY,
289 [219] = NOKEY,
290 [220] = KEY_VOLUMEUP,
291 [221] = KEY_BRIGHTNESSUP,
292 [222] = NOKEY,
293 [223] = NOKEY,
294 [224] = NOKEY,
295 [225] = NOKEY,
296 [226] = NOKEY,
297 [227] = NOKEY,
298 [228] = NOKEY,
299 [229] = NOKEY,
300 [230] = NOKEY,
301 [231] = NOKEY,
302 [232] = NOKEY,
303 [233] = NOKEY,
304 [234] = NOKEY,
305 [235] = NOKEY,
306 [236] = NOKEY,
307 [237] = KEY_VOLUMEDOWN,
308 [238] = NOKEY,
309 [239] = NOKEY,
310 [240] = NOKEY,
311 [241] = NOKEY,
312 [242] = NOKEY,
313 [243] = NOKEY,
314 [244] = NOKEY,
315 [245] = NOKEY,
316 [246] = NOKEY,
317 [247] = NOKEY,
318 [248] = NOKEY,
319 [249] = NOKEY,
320 [250] = NOKEY,
321 [251] = NOKEY,
322 [252] = NOKEY,
323 [253] = KEY_BRIGHTNESSDOWN,
324 [254] = NOKEY,
325 [255] = NOKEY,
326};
327
328static const u8 emul0_map[128] = {
329 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
330 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 96, 97, 0, 0,
331 113, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114, 0,
332 115, 0, 0, 0, 0, 98, 0, 99, 100, 0, 0, 0, 0, 0, 0, 0,
333 0, 0, 0, 0, 0, 0, 0, 102, 103, 104, 0, 105, 0, 106, 0, 107,
334 108, 109, 110, 111, 0, 0, 0, 0, 0, 0, 0, 139, 0, 150, 0, 0,
335 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
336 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
337};
338
339/*-----------------------------------------------------------------------------
340 * Global variables
341 *---------------------------------------------------------------------------*/
342
343struct input_dev *g_qci_keyboard_dev;
344
345/* General structure to hold the driver data */
346struct i2ckbd_drv_data {
347 struct i2c_client *ki2c_client;
348 struct work_struct work;
349 struct input_dev *qcikbd_dev;
350 struct mutex kb_mutex;
351 unsigned int qcikbd_gpio; /* GPIO used for interrupt */
352 unsigned int qcikbd_irq;
353 unsigned int key_down;
354 unsigned int escape;
355 unsigned int pause_seq;
356 unsigned int fn;
357 unsigned char led_status;
358 bool standard_scancodes;
359 bool kb_leds;
360 bool event_led;
361 bool emul0;
362 bool emul1;
363 bool pause1;
364};
365#ifdef CONFIG_PM
366static int qcikbd_suspend(struct device *dev)
367{
368 struct i2ckbd_drv_data *context = input_get_drvdata(g_qci_keyboard_dev);
369
370 enable_irq_wake(context->qcikbd_irq);
371 return 0;
372}
373
374static int qcikbd_resume(struct device *dev)
375{
376 struct i2ckbd_drv_data *context = input_get_drvdata(g_qci_keyboard_dev);
377 struct i2c_client *ikbdclient = context->ki2c_client;
378
379 disable_irq_wake(context->qcikbd_irq);
380
381 /* consume any keypress generated while suspended */
382 i2c_smbus_read_byte(ikbdclient);
383 return 0;
384}
385#endif
386static int __devinit qcikbd_probe(struct i2c_client *client,
387 const struct i2c_device_id *id);
388static int __devexit qcikbd_remove(struct i2c_client *kbd);
389
390static const struct i2c_device_id qcikbd_idtable[] = {
391 { KEYBOARD_ID_NAME, 0 },
392 { }
393};
394
395MODULE_DEVICE_TABLE(i2c, qcikbd_idtable);
396
397#ifdef CONFIG_PM
398static struct dev_pm_ops qcikbd_pm_ops = {
399 .suspend = qcikbd_suspend,
400 .resume = qcikbd_resume,
401};
402#endif
403static struct i2c_driver i2ckbd_driver = {
404 .driver = {
405 .owner = THIS_MODULE,
406 .name = KEYBOARD_ID_NAME,
407#ifdef CONFIG_PM
408 .pm = &qcikbd_pm_ops,
409#endif
410 },
411 .probe = qcikbd_probe,
412 .remove = __devexit_p(qcikbd_remove),
413 .id_table = qcikbd_idtable,
414};
415
416/*-----------------------------------------------------------------------------
417 * Driver functions
418 *---------------------------------------------------------------------------*/
419
420#ifdef CONFIG_KEYBOARD_QCIKBD_LID
421static void process_lid(struct input_dev *ikbdev, unsigned char scancode)
422{
423 if (scancode == SCAN_LIDSW_OPEN)
424 input_report_switch(ikbdev, SW_LID, 0);
425 else if (scancode == SCAN_LIDSW_CLOSE)
426 input_report_switch(ikbdev, SW_LID, 1);
427 else
428 return;
429 input_sync(ikbdev);
430}
431#endif
432
433static irqreturn_t qcikbd_interrupt(int irq, void *dev_id)
434{
435 struct i2ckbd_drv_data *ikbd_drv_data = dev_id;
436 schedule_work(&ikbd_drv_data->work);
437 return IRQ_HANDLED;
438}
439
440static void qcikbd_work_handler(struct work_struct *_work)
441{
442 unsigned char scancode;
443 unsigned char scancode_only;
444 unsigned int keycode;
445
446 struct i2ckbd_drv_data *ikbd_drv_data =
447 container_of(_work, struct i2ckbd_drv_data, work);
448
449 struct i2c_client *ikbdclient = ikbd_drv_data->ki2c_client;
450 struct input_dev *ikbdev = ikbd_drv_data->qcikbd_dev;
451
452 mutex_lock(&ikbd_drv_data->kb_mutex);
453
454 if ((ikbd_drv_data->kb_leds) && (ikbd_drv_data->event_led)) {
455 i2c_smbus_write_byte(ikbdclient, KEYBOARD_CMD_SET_LED);
456 i2c_smbus_write_byte(ikbdclient, ikbd_drv_data->led_status);
457 ikbd_drv_data->event_led = 0;
458 goto work_exit;
459 }
460
461 scancode = i2c_smbus_read_byte(ikbdclient);
462
463 if (scancode == KEY_ACK_FA)
464 goto work_exit;
465
466 if (ikbd_drv_data->standard_scancodes) {
467 /* pause key is E1 1D 45 */
468 if (scancode == SCAN_EMUL1) {
469 ikbd_drv_data->emul1 = 1;
470 goto work_exit;
471 }
472 if (ikbd_drv_data->emul1) {
473 ikbd_drv_data->emul1 = 0;
474 if ((scancode & 0x7f) == SCAN_PAUSE1)
475 ikbd_drv_data->pause1 = 1;
476 goto work_exit;
477 }
478 if (ikbd_drv_data->pause1) {
479 ikbd_drv_data->pause1 = 0;
480 if ((scancode & 0x7f) == SCAN_PAUSE2) {
481 input_report_key(ikbdev, KEY_PAUSE,
482 !(scancode & 0x80));
483 input_sync(ikbdev);
484 }
485 goto work_exit;
486 }
487
488 if (scancode == SCAN_EMUL0) {
489 ikbd_drv_data->emul0 = 1;
490 goto work_exit;
491 }
492 if (ikbd_drv_data->emul0) {
493 ikbd_drv_data->emul0 = 0;
494 scancode_only = scancode & 0x7f;
495#ifdef CONFIG_KEYBOARD_QCIKBD_LID
496 if ((scancode_only == SCAN_LIDSW_OPEN) ||
497 (scancode_only == SCAN_LIDSW_CLOSE)) {
498 process_lid(ikbdev, scancode);
499 goto work_exit;
500 }
501#endif
502 keycode = emul0_map[scancode_only];
503 if (!keycode) {
504 dev_err(&ikbdev->dev,
505 "Unrecognized scancode %02x %02x\n",
506 SCAN_EMUL0, scancode);
507 goto work_exit;
508 }
509 } else {
510 keycode = scancode & 0x7f;
511 }
512 /* MS bit of scancode indicates direction of keypress */
513 ikbd_drv_data->key_down = !(scancode & 0x80);
514 if (keycode) {
515 input_event(ikbdev, EV_MSC, MSC_SCAN, scancode);
516 input_report_key(ikbdev, keycode,
517 ikbd_drv_data->key_down);
518 input_sync(ikbdev);
519 }
520 goto work_exit;
521 }
522
523 mutex_unlock(&ikbd_drv_data->kb_mutex);
524
525 if (scancode == RC_KEY_FN) {
526 ikbd_drv_data->fn = 0x80; /* select keycode table > 0x7F */
527 } else {
528 ikbd_drv_data->key_down = 1;
529 if (scancode & RC_KEY_BREAK) {
530 ikbd_drv_data->key_down = 0;
531 if ((scancode & 0x7F) == RC_KEY_FN)
532 ikbd_drv_data->fn = 0;
533 }
534 keycode = on2_keycode[(scancode & 0x7F) | ikbd_drv_data->fn];
535 if (keycode != NOKEY) {
536 input_report_key(ikbdev,
537 keycode,
538 ikbd_drv_data->key_down);
539 input_sync(ikbdev);
540 }
541 }
542 return;
543
544work_exit:
545 mutex_unlock(&ikbd_drv_data->kb_mutex);
546}
547
548static int qcikbd_input_event(struct input_dev *dev, unsigned int type,
549 unsigned int code, int value)
550{
551 struct i2ckbd_drv_data *ikbd_drv_data = input_get_drvdata(dev);
552 struct input_dev *ikbdev = ikbd_drv_data->qcikbd_dev;
553
554 if (type != EV_LED)
555 return -EINVAL;
556
557 ikbd_drv_data->led_status =
558 (test_bit(LED_SCROLLL, ikbdev->led) ? 1 : 0) |
559 (test_bit(LED_NUML, ikbdev->led) ? 2 : 0) |
560 (test_bit(LED_CAPSL, ikbdev->led) ? 4 : 0);
561 ikbd_drv_data->event_led = 1;
562
563 schedule_work(&ikbd_drv_data->work);
564 return 0;
565}
566
567static int qcikbd_open(struct input_dev *dev)
568{
569 struct i2ckbd_drv_data *ikbd_drv_data = input_get_drvdata(dev);
570 struct i2c_client *ikbdclient = ikbd_drv_data->ki2c_client;
571
572 /* Send F4h - enable keyboard */
573 i2c_smbus_write_byte(ikbdclient, KEYBOARD_CMD_ENABLE);
574 return 0;
575}
576
577static int __devinit qcikbd_probe(struct i2c_client *client,
578 const struct i2c_device_id *id)
579{
580 int err;
581 int i;
582 struct i2ckbd_drv_data *context;
583 struct qci_kbd_platform_data *pdata = client->dev.platform_data;
584
585 if (!pdata) {
586 pr_err("[KBD] platform data not supplied\n");
587 return -EINVAL;
588 }
589
590 context = kzalloc(sizeof(struct i2ckbd_drv_data), GFP_KERNEL);
591 if (!context)
592 return -ENOMEM;
593 i2c_set_clientdata(client, context);
594 context->ki2c_client = client;
595 context->qcikbd_gpio = client->irq;
596 client->driver = &i2ckbd_driver;
597
598 INIT_WORK(&context->work, qcikbd_work_handler);
599 mutex_init(&context->kb_mutex);
600
601 err = gpio_request(context->qcikbd_gpio, "qci-kbd");
602 if (err) {
603 pr_err("[KBD] err gpio request\n");
604 goto gpio_request_fail;
605 }
606
607 context->qcikbd_irq = gpio_to_irq(context->qcikbd_gpio);
608 err = request_irq(context->qcikbd_irq,
609 qcikbd_interrupt,
610 IRQF_TRIGGER_FALLING,
611 KEYBOARD_ID_NAME,
612 context);
613 if (err) {
614 pr_err("[KBD] err unable to get IRQ\n");
615 goto request_irq_fail;
616 }
617
618 context->standard_scancodes = pdata->standard_scancodes;
619 context->kb_leds = pdata->kb_leds;
620 context->qcikbd_dev = input_allocate_device();
621 if (!context->qcikbd_dev) {
622 pr_err("[KBD]allocting memory err\n");
623 err = -ENOMEM;
624 goto allocate_fail;
625 }
626
627 context->qcikbd_dev->name = KEYBOARD_NAME;
628 context->qcikbd_dev->phys = KEYBOARD_DEVICE;
629 context->qcikbd_dev->id.bustype = BUS_I2C;
630 context->qcikbd_dev->id.vendor = 0x1050;
631 context->qcikbd_dev->id.product = 0x0006;
632 context->qcikbd_dev->id.version = 0x0004;
633 context->qcikbd_dev->open = qcikbd_open;
634 set_bit(EV_KEY, context->qcikbd_dev->evbit);
635 __set_bit(MSC_SCAN, context->qcikbd_dev->mscbit);
636
637 if (pdata->repeat)
638 set_bit(EV_REP, context->qcikbd_dev->evbit);
639
640 /* Enable all supported keys */
641 for (i = 1; i < ARRAY_SIZE(on2_keycode) ; i++)
642 set_bit(on2_keycode[i], context->qcikbd_dev->keybit);
643
644 set_bit(KEY_POWER, context->qcikbd_dev->keybit);
645 set_bit(KEY_END, context->qcikbd_dev->keybit);
646 set_bit(KEY_VOLUMEUP, context->qcikbd_dev->keybit);
647 set_bit(KEY_VOLUMEDOWN, context->qcikbd_dev->keybit);
648 set_bit(KEY_ZOOMIN, context->qcikbd_dev->keybit);
649 set_bit(KEY_ZOOMOUT, context->qcikbd_dev->keybit);
650
651#ifdef CONFIG_KEYBOARD_QCIKBD_LID
652 set_bit(EV_SW, context->qcikbd_dev->evbit);
653 set_bit(SW_LID, context->qcikbd_dev->swbit);
654#endif
655
656 if (context->kb_leds) {
657 context->qcikbd_dev->event = qcikbd_input_event;
658 __set_bit(EV_LED, context->qcikbd_dev->evbit);
659 __set_bit(LED_NUML, context->qcikbd_dev->ledbit);
660 __set_bit(LED_CAPSL, context->qcikbd_dev->ledbit);
661 __set_bit(LED_SCROLLL, context->qcikbd_dev->ledbit);
662 }
663
664 input_set_drvdata(context->qcikbd_dev, context);
665 err = input_register_device(context->qcikbd_dev);
666 if (err) {
667 pr_err("[KBD] err input register device\n");
668 goto register_fail;
669 }
670 g_qci_keyboard_dev = context->qcikbd_dev;
671 return 0;
672register_fail:
673 input_free_device(context->qcikbd_dev);
674
675allocate_fail:
676 free_irq(context->qcikbd_irq, context);
677
678request_irq_fail:
679 gpio_free(context->qcikbd_gpio);
680
681gpio_request_fail:
682 i2c_set_clientdata(client, NULL);
683 kfree(context);
684 return err;
685}
686
687static int __devexit qcikbd_remove(struct i2c_client *dev)
688{
689 struct i2ckbd_drv_data *context = i2c_get_clientdata(dev);
690
691 free_irq(context->qcikbd_irq, context);
692 gpio_free(context->qcikbd_gpio);
693 input_free_device(context->qcikbd_dev);
694 input_unregister_device(context->qcikbd_dev);
695 kfree(context);
696
697 return 0;
698}
699
700static int __init qcikbd_init(void)
701{
702 return i2c_add_driver(&i2ckbd_driver);
703}
704
705static void __exit qcikbd_exit(void)
706{
707 i2c_del_driver(&i2ckbd_driver);
708}
709
710struct input_dev *nkbc_keypad_get_input_dev(void)
711{
712 return g_qci_keyboard_dev;
713}
714EXPORT_SYMBOL(nkbc_keypad_get_input_dev);
715module_init(qcikbd_init);
716module_exit(qcikbd_exit);
717
718MODULE_AUTHOR("Quanta Computer Inc.");
719MODULE_DESCRIPTION("Quanta Embedded Controller I2C Keyboard Driver");
720MODULE_LICENSE("GPL v2");
721