cros_ec_keyb.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. /*
  2. * ChromeOS EC keyboard driver
  3. *
  4. * Copyright (C) 2012 Google, Inc
  5. *
  6. * This software is licensed under the terms of the GNU General Public
  7. * License version 2, as published by the Free Software Foundation, and
  8. * may be copied, distributed, and modified under those terms.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * This driver uses the Chrome OS EC byte-level message-based protocol for
  16. * communicating the keyboard state (which keys are pressed) from a keyboard EC
  17. * to the AP over some bus (such as i2c, lpc, spi). The EC does debouncing,
  18. * but everything else (including deghosting) is done here. The main
  19. * motivation for this is to keep the EC firmware as simple as possible, since
  20. * it cannot be easily upgraded and EC flash/IRAM space is relatively
  21. * expensive.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/bitops.h>
  25. #include <linux/i2c.h>
  26. #include <linux/input.h>
  27. #include <linux/interrupt.h>
  28. #include <linux/kernel.h>
  29. #include <linux/notifier.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/slab.h>
  32. #include <linux/sysrq.h>
  33. #include <linux/input/matrix_keypad.h>
  34. #include <linux/mfd/cros_ec.h>
  35. #include <linux/mfd/cros_ec_commands.h>
  36. #include <asm/unaligned.h>
  37. /*
  38. * @rows: Number of rows in the keypad
  39. * @cols: Number of columns in the keypad
  40. * @row_shift: log2 or number of rows, rounded up
  41. * @keymap_data: Matrix keymap data used to convert to keyscan values
  42. * @ghost_filter: true to enable the matrix key-ghosting filter
  43. * @valid_keys: bitmap of existing keys for each matrix column
  44. * @old_kb_state: bitmap of keys pressed last scan
  45. * @dev: Device pointer
  46. * @ec: Top level ChromeOS device to use to talk to EC
  47. * @idev: The input device for the matrix keys.
  48. * @bs_idev: The input device for non-matrix buttons and switches (or NULL).
  49. * @notifier: interrupt event notifier for transport devices
  50. */
  51. struct cros_ec_keyb {
  52. unsigned int rows;
  53. unsigned int cols;
  54. int row_shift;
  55. const struct matrix_keymap_data *keymap_data;
  56. bool ghost_filter;
  57. uint8_t *valid_keys;
  58. uint8_t *old_kb_state;
  59. struct device *dev;
  60. struct cros_ec_device *ec;
  61. struct input_dev *idev;
  62. struct input_dev *bs_idev;
  63. struct notifier_block notifier;
  64. };
  65. /**
  66. * cros_ec_bs_map - Struct mapping Linux keycodes to EC button/switch bitmap
  67. * #defines
  68. *
  69. * @ev_type: The type of the input event to generate (e.g., EV_KEY).
  70. * @code: A linux keycode
  71. * @bit: A #define like EC_MKBP_POWER_BUTTON or EC_MKBP_LID_OPEN
  72. * @inverted: If the #define and EV_SW have opposite meanings, this is true.
  73. * Only applicable to switches.
  74. */
  75. struct cros_ec_bs_map {
  76. unsigned int ev_type;
  77. unsigned int code;
  78. u8 bit;
  79. bool inverted;
  80. };
  81. /* cros_ec_keyb_bs - Map EC button/switch #defines into kernel ones */
  82. static const struct cros_ec_bs_map cros_ec_keyb_bs[] = {
  83. /* Buttons */
  84. {
  85. .ev_type = EV_KEY,
  86. .code = KEY_POWER,
  87. .bit = EC_MKBP_POWER_BUTTON,
  88. },
  89. {
  90. .ev_type = EV_KEY,
  91. .code = KEY_VOLUMEUP,
  92. .bit = EC_MKBP_VOL_UP,
  93. },
  94. {
  95. .ev_type = EV_KEY,
  96. .code = KEY_VOLUMEDOWN,
  97. .bit = EC_MKBP_VOL_DOWN,
  98. },
  99. /* Switches */
  100. {
  101. .ev_type = EV_SW,
  102. .code = SW_LID,
  103. .bit = EC_MKBP_LID_OPEN,
  104. .inverted = true,
  105. },
  106. {
  107. .ev_type = EV_SW,
  108. .code = SW_TABLET_MODE,
  109. .bit = EC_MKBP_TABLET_MODE,
  110. },
  111. };
  112. /*
  113. * Returns true when there is at least one combination of pressed keys that
  114. * results in ghosting.
  115. */
  116. static bool cros_ec_keyb_has_ghosting(struct cros_ec_keyb *ckdev, uint8_t *buf)
  117. {
  118. int col1, col2, buf1, buf2;
  119. struct device *dev = ckdev->dev;
  120. uint8_t *valid_keys = ckdev->valid_keys;
  121. /*
  122. * Ghosting happens if for any pressed key X there are other keys
  123. * pressed both in the same row and column of X as, for instance,
  124. * in the following diagram:
  125. *
  126. * . . Y . g .
  127. * . . . . . .
  128. * . . . . . .
  129. * . . X . Z .
  130. *
  131. * In this case only X, Y, and Z are pressed, but g appears to be
  132. * pressed too (see Wikipedia).
  133. */
  134. for (col1 = 0; col1 < ckdev->cols; col1++) {
  135. buf1 = buf[col1] & valid_keys[col1];
  136. for (col2 = col1 + 1; col2 < ckdev->cols; col2++) {
  137. buf2 = buf[col2] & valid_keys[col2];
  138. if (hweight8(buf1 & buf2) > 1) {
  139. dev_dbg(dev, "ghost found at: B[%02d]:0x%02x & B[%02d]:0x%02x",
  140. col1, buf1, col2, buf2);
  141. return true;
  142. }
  143. }
  144. }
  145. return false;
  146. }
  147. /*
  148. * Compares the new keyboard state to the old one and produces key
  149. * press/release events accordingly. The keyboard state is 13 bytes (one byte
  150. * per column)
  151. */
  152. static void cros_ec_keyb_process(struct cros_ec_keyb *ckdev,
  153. uint8_t *kb_state, int len)
  154. {
  155. struct input_dev *idev = ckdev->idev;
  156. int col, row;
  157. int new_state;
  158. int old_state;
  159. int num_cols;
  160. num_cols = len;
  161. if (ckdev->ghost_filter && cros_ec_keyb_has_ghosting(ckdev, kb_state)) {
  162. /*
  163. * Simple-minded solution: ignore this state. The obvious
  164. * improvement is to only ignore changes to keys involved in
  165. * the ghosting, but process the other changes.
  166. */
  167. dev_dbg(ckdev->dev, "ghosting found\n");
  168. return;
  169. }
  170. for (col = 0; col < ckdev->cols; col++) {
  171. for (row = 0; row < ckdev->rows; row++) {
  172. int pos = MATRIX_SCAN_CODE(row, col, ckdev->row_shift);
  173. const unsigned short *keycodes = idev->keycode;
  174. new_state = kb_state[col] & (1 << row);
  175. old_state = ckdev->old_kb_state[col] & (1 << row);
  176. if (new_state != old_state) {
  177. dev_dbg(ckdev->dev,
  178. "changed: [r%d c%d]: byte %02x\n",
  179. row, col, new_state);
  180. input_report_key(idev, keycodes[pos],
  181. new_state);
  182. }
  183. }
  184. ckdev->old_kb_state[col] = kb_state[col];
  185. }
  186. input_sync(ckdev->idev);
  187. }
  188. /**
  189. * cros_ec_keyb_report_bs - Report non-matrixed buttons or switches
  190. *
  191. * This takes a bitmap of buttons or switches from the EC and reports events,
  192. * syncing at the end.
  193. *
  194. * @ckdev: The keyboard device.
  195. * @ev_type: The input event type (e.g., EV_KEY).
  196. * @mask: A bitmap of buttons from the EC.
  197. */
  198. static void cros_ec_keyb_report_bs(struct cros_ec_keyb *ckdev,
  199. unsigned int ev_type, u32 mask)
  200. {
  201. struct input_dev *idev = ckdev->bs_idev;
  202. int i;
  203. for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) {
  204. const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i];
  205. if (map->ev_type != ev_type)
  206. continue;
  207. input_event(idev, ev_type, map->code,
  208. !!(mask & BIT(map->bit)) ^ map->inverted);
  209. }
  210. input_sync(idev);
  211. }
  212. static int cros_ec_keyb_work(struct notifier_block *nb,
  213. unsigned long queued_during_suspend, void *_notify)
  214. {
  215. struct cros_ec_keyb *ckdev = container_of(nb, struct cros_ec_keyb,
  216. notifier);
  217. u32 val;
  218. unsigned int ev_type;
  219. switch (ckdev->ec->event_data.event_type) {
  220. case EC_MKBP_EVENT_KEY_MATRIX:
  221. /*
  222. * If EC is not the wake source, discard key state changes
  223. * during suspend.
  224. */
  225. if (queued_during_suspend)
  226. return NOTIFY_OK;
  227. if (ckdev->ec->event_size != ckdev->cols) {
  228. dev_err(ckdev->dev,
  229. "Discarded incomplete key matrix event.\n");
  230. return NOTIFY_OK;
  231. }
  232. cros_ec_keyb_process(ckdev,
  233. ckdev->ec->event_data.data.key_matrix,
  234. ckdev->ec->event_size);
  235. break;
  236. case EC_MKBP_EVENT_SYSRQ:
  237. val = get_unaligned_le32(&ckdev->ec->event_data.data.sysrq);
  238. dev_dbg(ckdev->dev, "sysrq code from EC: %#x\n", val);
  239. handle_sysrq(val);
  240. break;
  241. case EC_MKBP_EVENT_BUTTON:
  242. case EC_MKBP_EVENT_SWITCH:
  243. /*
  244. * If EC is not the wake source, discard key state
  245. * changes during suspend. Switches will be re-checked in
  246. * cros_ec_keyb_resume() to be sure nothing is lost.
  247. */
  248. if (queued_during_suspend)
  249. return NOTIFY_OK;
  250. if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) {
  251. val = get_unaligned_le32(
  252. &ckdev->ec->event_data.data.buttons);
  253. ev_type = EV_KEY;
  254. } else {
  255. val = get_unaligned_le32(
  256. &ckdev->ec->event_data.data.switches);
  257. ev_type = EV_SW;
  258. }
  259. cros_ec_keyb_report_bs(ckdev, ev_type, val);
  260. break;
  261. default:
  262. return NOTIFY_DONE;
  263. }
  264. return NOTIFY_OK;
  265. }
  266. /*
  267. * Walks keycodes flipping bit in buffer COLUMNS deep where bit is ROW. Used by
  268. * ghosting logic to ignore NULL or virtual keys.
  269. */
  270. static void cros_ec_keyb_compute_valid_keys(struct cros_ec_keyb *ckdev)
  271. {
  272. int row, col;
  273. int row_shift = ckdev->row_shift;
  274. unsigned short *keymap = ckdev->idev->keycode;
  275. unsigned short code;
  276. BUG_ON(ckdev->idev->keycodesize != sizeof(*keymap));
  277. for (col = 0; col < ckdev->cols; col++) {
  278. for (row = 0; row < ckdev->rows; row++) {
  279. code = keymap[MATRIX_SCAN_CODE(row, col, row_shift)];
  280. if (code && (code != KEY_BATTERY))
  281. ckdev->valid_keys[col] |= 1 << row;
  282. }
  283. dev_dbg(ckdev->dev, "valid_keys[%02d] = 0x%02x\n",
  284. col, ckdev->valid_keys[col]);
  285. }
  286. }
  287. /**
  288. * cros_ec_keyb_info - Wrap the EC command EC_CMD_MKBP_INFO
  289. *
  290. * This wraps the EC_CMD_MKBP_INFO, abstracting out all of the marshalling and
  291. * unmarshalling and different version nonsense into something simple.
  292. *
  293. * @ec_dev: The EC device
  294. * @info_type: Either EC_MKBP_INFO_SUPPORTED or EC_MKBP_INFO_CURRENT.
  295. * @event_type: Either EC_MKBP_EVENT_BUTTON or EC_MKBP_EVENT_SWITCH. Actually
  296. * in some cases this could be EC_MKBP_EVENT_KEY_MATRIX or
  297. * EC_MKBP_EVENT_HOST_EVENT too but we don't use in this driver.
  298. * @result: Where we'll store the result; a union
  299. * @result_size: The size of the result. Expected to be the size of one of
  300. * the elements in the union.
  301. *
  302. * Returns 0 if no error or -error upon error.
  303. */
  304. static int cros_ec_keyb_info(struct cros_ec_device *ec_dev,
  305. enum ec_mkbp_info_type info_type,
  306. enum ec_mkbp_event event_type,
  307. union ec_response_get_next_data *result,
  308. size_t result_size)
  309. {
  310. struct ec_params_mkbp_info *params;
  311. struct cros_ec_command *msg;
  312. int ret;
  313. msg = kzalloc(sizeof(*msg) + max_t(size_t, result_size,
  314. sizeof(*params)), GFP_KERNEL);
  315. if (!msg)
  316. return -ENOMEM;
  317. msg->command = EC_CMD_MKBP_INFO;
  318. msg->version = 1;
  319. msg->outsize = sizeof(*params);
  320. msg->insize = result_size;
  321. params = (struct ec_params_mkbp_info *)msg->data;
  322. params->info_type = info_type;
  323. params->event_type = event_type;
  324. ret = cros_ec_cmd_xfer(ec_dev, msg);
  325. if (ret < 0) {
  326. dev_warn(ec_dev->dev, "Transfer error %d/%d: %d\n",
  327. (int)info_type, (int)event_type, ret);
  328. } else if (msg->result == EC_RES_INVALID_VERSION) {
  329. /* With older ECs we just return 0 for everything */
  330. memset(result, 0, result_size);
  331. ret = 0;
  332. } else if (msg->result != EC_RES_SUCCESS) {
  333. dev_warn(ec_dev->dev, "Error getting info %d/%d: %d\n",
  334. (int)info_type, (int)event_type, msg->result);
  335. ret = -EPROTO;
  336. } else if (ret != result_size) {
  337. dev_warn(ec_dev->dev, "Wrong size %d/%d: %d != %zu\n",
  338. (int)info_type, (int)event_type,
  339. ret, result_size);
  340. ret = -EPROTO;
  341. } else {
  342. memcpy(result, msg->data, result_size);
  343. ret = 0;
  344. }
  345. kfree(msg);
  346. return ret;
  347. }
  348. /**
  349. * cros_ec_keyb_query_switches - Query the state of switches and report
  350. *
  351. * This will ask the EC about the current state of switches and report to the
  352. * kernel. Note that we don't query for buttons because they are more
  353. * transitory and we'll get an update on the next release / press.
  354. *
  355. * @ckdev: The keyboard device
  356. *
  357. * Returns 0 if no error or -error upon error.
  358. */
  359. static int cros_ec_keyb_query_switches(struct cros_ec_keyb *ckdev)
  360. {
  361. struct cros_ec_device *ec_dev = ckdev->ec;
  362. union ec_response_get_next_data event_data = {};
  363. int ret;
  364. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_CURRENT,
  365. EC_MKBP_EVENT_SWITCH, &event_data,
  366. sizeof(event_data.switches));
  367. if (ret)
  368. return ret;
  369. cros_ec_keyb_report_bs(ckdev, EV_SW,
  370. get_unaligned_le32(&event_data.switches));
  371. return 0;
  372. }
  373. /**
  374. * cros_ec_keyb_resume - Resume the keyboard
  375. *
  376. * We use the resume notification as a chance to query the EC for switches.
  377. *
  378. * @dev: The keyboard device
  379. *
  380. * Returns 0 if no error or -error upon error.
  381. */
  382. static __maybe_unused int cros_ec_keyb_resume(struct device *dev)
  383. {
  384. struct cros_ec_keyb *ckdev = dev_get_drvdata(dev);
  385. if (ckdev->bs_idev)
  386. return cros_ec_keyb_query_switches(ckdev);
  387. return 0;
  388. }
  389. /**
  390. * cros_ec_keyb_register_bs - Register non-matrix buttons/switches
  391. *
  392. * Handles all the bits of the keyboard driver related to non-matrix buttons
  393. * and switches, including asking the EC about which are present and telling
  394. * the kernel to expect them.
  395. *
  396. * If this device has no support for buttons and switches we'll return no error
  397. * but the ckdev->bs_idev will remain NULL when this function exits.
  398. *
  399. * @ckdev: The keyboard device
  400. *
  401. * Returns 0 if no error or -error upon error.
  402. */
  403. static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev)
  404. {
  405. struct cros_ec_device *ec_dev = ckdev->ec;
  406. struct device *dev = ckdev->dev;
  407. struct input_dev *idev;
  408. union ec_response_get_next_data event_data = {};
  409. const char *phys;
  410. u32 buttons;
  411. u32 switches;
  412. int ret;
  413. int i;
  414. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED,
  415. EC_MKBP_EVENT_BUTTON, &event_data,
  416. sizeof(event_data.buttons));
  417. if (ret)
  418. return ret;
  419. buttons = get_unaligned_le32(&event_data.buttons);
  420. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED,
  421. EC_MKBP_EVENT_SWITCH, &event_data,
  422. sizeof(event_data.switches));
  423. if (ret)
  424. return ret;
  425. switches = get_unaligned_le32(&event_data.switches);
  426. if (!buttons && !switches)
  427. return 0;
  428. /*
  429. * We call the non-matrix buttons/switches 'input1', if present.
  430. * Allocate phys before input dev, to ensure correct tear-down
  431. * ordering.
  432. */
  433. phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input1", ec_dev->phys_name);
  434. if (!phys)
  435. return -ENOMEM;
  436. idev = devm_input_allocate_device(dev);
  437. if (!idev)
  438. return -ENOMEM;
  439. idev->name = "cros_ec_buttons";
  440. idev->phys = phys;
  441. __set_bit(EV_REP, idev->evbit);
  442. idev->id.bustype = BUS_VIRTUAL;
  443. idev->id.version = 1;
  444. idev->id.product = 0;
  445. idev->dev.parent = dev;
  446. input_set_drvdata(idev, ckdev);
  447. ckdev->bs_idev = idev;
  448. for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) {
  449. const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i];
  450. if (buttons & BIT(map->bit))
  451. input_set_capability(idev, map->ev_type, map->code);
  452. }
  453. ret = cros_ec_keyb_query_switches(ckdev);
  454. if (ret) {
  455. dev_err(dev, "cannot query switches\n");
  456. return ret;
  457. }
  458. ret = input_register_device(ckdev->bs_idev);
  459. if (ret) {
  460. dev_err(dev, "cannot register input device\n");
  461. return ret;
  462. }
  463. return 0;
  464. }
  465. /**
  466. * cros_ec_keyb_register_bs - Register matrix keys
  467. *
  468. * Handles all the bits of the keyboard driver related to matrix keys.
  469. *
  470. * @ckdev: The keyboard device
  471. *
  472. * Returns 0 if no error or -error upon error.
  473. */
  474. static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev)
  475. {
  476. struct cros_ec_device *ec_dev = ckdev->ec;
  477. struct device *dev = ckdev->dev;
  478. struct input_dev *idev;
  479. const char *phys;
  480. int err;
  481. err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols);
  482. if (err)
  483. return err;
  484. ckdev->valid_keys = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
  485. if (!ckdev->valid_keys)
  486. return -ENOMEM;
  487. ckdev->old_kb_state = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
  488. if (!ckdev->old_kb_state)
  489. return -ENOMEM;
  490. /*
  491. * We call the keyboard matrix 'input0'. Allocate phys before input
  492. * dev, to ensure correct tear-down ordering.
  493. */
  494. phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input0", ec_dev->phys_name);
  495. if (!phys)
  496. return -ENOMEM;
  497. idev = devm_input_allocate_device(dev);
  498. if (!idev)
  499. return -ENOMEM;
  500. idev->name = CROS_EC_DEV_NAME;
  501. idev->phys = phys;
  502. __set_bit(EV_REP, idev->evbit);
  503. idev->id.bustype = BUS_VIRTUAL;
  504. idev->id.version = 1;
  505. idev->id.product = 0;
  506. idev->dev.parent = dev;
  507. ckdev->ghost_filter = of_property_read_bool(dev->of_node,
  508. "google,needs-ghost-filter");
  509. err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows, ckdev->cols,
  510. NULL, idev);
  511. if (err) {
  512. dev_err(dev, "cannot build key matrix\n");
  513. return err;
  514. }
  515. ckdev->row_shift = get_count_order(ckdev->cols);
  516. input_set_capability(idev, EV_MSC, MSC_SCAN);
  517. input_set_drvdata(idev, ckdev);
  518. ckdev->idev = idev;
  519. cros_ec_keyb_compute_valid_keys(ckdev);
  520. err = input_register_device(ckdev->idev);
  521. if (err) {
  522. dev_err(dev, "cannot register input device\n");
  523. return err;
  524. }
  525. return 0;
  526. }
  527. static int cros_ec_keyb_probe(struct platform_device *pdev)
  528. {
  529. struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
  530. struct device *dev = &pdev->dev;
  531. struct cros_ec_keyb *ckdev;
  532. int err;
  533. if (!dev->of_node)
  534. return -ENODEV;
  535. ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL);
  536. if (!ckdev)
  537. return -ENOMEM;
  538. ckdev->ec = ec;
  539. ckdev->dev = dev;
  540. dev_set_drvdata(dev, ckdev);
  541. err = cros_ec_keyb_register_matrix(ckdev);
  542. if (err) {
  543. dev_err(dev, "cannot register matrix inputs: %d\n", err);
  544. return err;
  545. }
  546. err = cros_ec_keyb_register_bs(ckdev);
  547. if (err) {
  548. dev_err(dev, "cannot register non-matrix inputs: %d\n", err);
  549. return err;
  550. }
  551. ckdev->notifier.notifier_call = cros_ec_keyb_work;
  552. err = blocking_notifier_chain_register(&ckdev->ec->event_notifier,
  553. &ckdev->notifier);
  554. if (err) {
  555. dev_err(dev, "cannot register notifier: %d\n", err);
  556. return err;
  557. }
  558. return 0;
  559. }
  560. static int cros_ec_keyb_remove(struct platform_device *pdev)
  561. {
  562. struct cros_ec_keyb *ckdev = dev_get_drvdata(&pdev->dev);
  563. blocking_notifier_chain_unregister(&ckdev->ec->event_notifier,
  564. &ckdev->notifier);
  565. return 0;
  566. }
  567. #ifdef CONFIG_OF
  568. static const struct of_device_id cros_ec_keyb_of_match[] = {
  569. { .compatible = "google,cros-ec-keyb" },
  570. {},
  571. };
  572. MODULE_DEVICE_TABLE(of, cros_ec_keyb_of_match);
  573. #endif
  574. static SIMPLE_DEV_PM_OPS(cros_ec_keyb_pm_ops, NULL, cros_ec_keyb_resume);
  575. static struct platform_driver cros_ec_keyb_driver = {
  576. .probe = cros_ec_keyb_probe,
  577. .remove = cros_ec_keyb_remove,
  578. .driver = {
  579. .name = "cros-ec-keyb",
  580. .of_match_table = of_match_ptr(cros_ec_keyb_of_match),
  581. .pm = &cros_ec_keyb_pm_ops,
  582. },
  583. };
  584. module_platform_driver(cros_ec_keyb_driver);
  585. MODULE_LICENSE("GPL");
  586. MODULE_DESCRIPTION("ChromeOS EC keyboard driver");
  587. MODULE_ALIAS("platform:cros-ec-keyb");