qci_kbd.c 17 KB

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