cros_ec_keyb.c 17 KB

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