cros_ec_keyb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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/platform_data/cros_ec_commands.h>
  25. #include <linux/platform_data/cros_ec_proto.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_status(ec_dev, msg);
  311. if (ret == -ENOPROTOOPT) {
  312. /* With older ECs we just return 0 for everything */
  313. memset(result, 0, result_size);
  314. ret = 0;
  315. } else if (ret < 0) {
  316. dev_warn(ec_dev->dev, "Transfer error %d/%d: %d\n",
  317. (int)info_type, (int)event_type, ret);
  318. } else if (ret != result_size) {
  319. dev_warn(ec_dev->dev, "Wrong size %d/%d: %d != %zu\n",
  320. (int)info_type, (int)event_type,
  321. ret, result_size);
  322. ret = -EPROTO;
  323. } else {
  324. memcpy(result, msg->data, result_size);
  325. ret = 0;
  326. }
  327. kfree(msg);
  328. return ret;
  329. }
  330. /**
  331. * cros_ec_keyb_query_switches - Query the state of switches and report
  332. *
  333. * This will ask the EC about the current state of switches and report to the
  334. * kernel. Note that we don't query for buttons because they are more
  335. * transitory and we'll get an update on the next release / press.
  336. *
  337. * @ckdev: The keyboard device
  338. *
  339. * Returns 0 if no error or -error upon error.
  340. */
  341. static int cros_ec_keyb_query_switches(struct cros_ec_keyb *ckdev)
  342. {
  343. struct cros_ec_device *ec_dev = ckdev->ec;
  344. union ec_response_get_next_data event_data = {};
  345. int ret;
  346. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_CURRENT,
  347. EC_MKBP_EVENT_SWITCH, &event_data,
  348. sizeof(event_data.switches));
  349. if (ret)
  350. return ret;
  351. cros_ec_keyb_report_bs(ckdev, EV_SW,
  352. get_unaligned_le32(&event_data.switches));
  353. return 0;
  354. }
  355. /**
  356. * cros_ec_keyb_resume - Resume the keyboard
  357. *
  358. * We use the resume notification as a chance to query the EC for switches.
  359. *
  360. * @dev: The keyboard device
  361. *
  362. * Returns 0 if no error or -error upon error.
  363. */
  364. static __maybe_unused int cros_ec_keyb_resume(struct device *dev)
  365. {
  366. struct cros_ec_keyb *ckdev = dev_get_drvdata(dev);
  367. if (ckdev->bs_idev)
  368. return cros_ec_keyb_query_switches(ckdev);
  369. return 0;
  370. }
  371. /**
  372. * cros_ec_keyb_register_bs - Register non-matrix buttons/switches
  373. *
  374. * Handles all the bits of the keyboard driver related to non-matrix buttons
  375. * and switches, including asking the EC about which are present and telling
  376. * the kernel to expect them.
  377. *
  378. * If this device has no support for buttons and switches we'll return no error
  379. * but the ckdev->bs_idev will remain NULL when this function exits.
  380. *
  381. * @ckdev: The keyboard device
  382. *
  383. * Returns 0 if no error or -error upon error.
  384. */
  385. static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev)
  386. {
  387. struct cros_ec_device *ec_dev = ckdev->ec;
  388. struct device *dev = ckdev->dev;
  389. struct input_dev *idev;
  390. union ec_response_get_next_data event_data = {};
  391. const char *phys;
  392. u32 buttons;
  393. u32 switches;
  394. int ret;
  395. int i;
  396. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED,
  397. EC_MKBP_EVENT_BUTTON, &event_data,
  398. sizeof(event_data.buttons));
  399. if (ret)
  400. return ret;
  401. buttons = get_unaligned_le32(&event_data.buttons);
  402. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED,
  403. EC_MKBP_EVENT_SWITCH, &event_data,
  404. sizeof(event_data.switches));
  405. if (ret)
  406. return ret;
  407. switches = get_unaligned_le32(&event_data.switches);
  408. if (!buttons && !switches)
  409. return 0;
  410. /*
  411. * We call the non-matrix buttons/switches 'input1', if present.
  412. * Allocate phys before input dev, to ensure correct tear-down
  413. * ordering.
  414. */
  415. phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input1", ec_dev->phys_name);
  416. if (!phys)
  417. return -ENOMEM;
  418. idev = devm_input_allocate_device(dev);
  419. if (!idev)
  420. return -ENOMEM;
  421. idev->name = "cros_ec_buttons";
  422. idev->phys = phys;
  423. __set_bit(EV_REP, idev->evbit);
  424. idev->id.bustype = BUS_VIRTUAL;
  425. idev->id.version = 1;
  426. idev->id.product = 0;
  427. idev->dev.parent = dev;
  428. input_set_drvdata(idev, ckdev);
  429. ckdev->bs_idev = idev;
  430. for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) {
  431. const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i];
  432. if ((map->ev_type == EV_KEY && (buttons & BIT(map->bit))) ||
  433. (map->ev_type == EV_SW && (switches & BIT(map->bit))))
  434. input_set_capability(idev, map->ev_type, map->code);
  435. }
  436. ret = cros_ec_keyb_query_switches(ckdev);
  437. if (ret) {
  438. dev_err(dev, "cannot query switches\n");
  439. return ret;
  440. }
  441. ret = input_register_device(ckdev->bs_idev);
  442. if (ret) {
  443. dev_err(dev, "cannot register input device\n");
  444. return ret;
  445. }
  446. return 0;
  447. }
  448. /**
  449. * cros_ec_keyb_register_bs - Register matrix keys
  450. *
  451. * Handles all the bits of the keyboard driver related to matrix keys.
  452. *
  453. * @ckdev: The keyboard device
  454. *
  455. * Returns 0 if no error or -error upon error.
  456. */
  457. static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev)
  458. {
  459. struct cros_ec_device *ec_dev = ckdev->ec;
  460. struct device *dev = ckdev->dev;
  461. struct input_dev *idev;
  462. const char *phys;
  463. int err;
  464. err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols);
  465. if (err)
  466. return err;
  467. ckdev->valid_keys = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
  468. if (!ckdev->valid_keys)
  469. return -ENOMEM;
  470. ckdev->old_kb_state = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
  471. if (!ckdev->old_kb_state)
  472. return -ENOMEM;
  473. /*
  474. * We call the keyboard matrix 'input0'. Allocate phys before input
  475. * dev, to ensure correct tear-down ordering.
  476. */
  477. phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input0", ec_dev->phys_name);
  478. if (!phys)
  479. return -ENOMEM;
  480. idev = devm_input_allocate_device(dev);
  481. if (!idev)
  482. return -ENOMEM;
  483. idev->name = CROS_EC_DEV_NAME;
  484. idev->phys = phys;
  485. __set_bit(EV_REP, idev->evbit);
  486. idev->id.bustype = BUS_VIRTUAL;
  487. idev->id.version = 1;
  488. idev->id.product = 0;
  489. idev->dev.parent = dev;
  490. ckdev->ghost_filter = of_property_read_bool(dev->of_node,
  491. "google,needs-ghost-filter");
  492. err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows, ckdev->cols,
  493. NULL, idev);
  494. if (err) {
  495. dev_err(dev, "cannot build key matrix\n");
  496. return err;
  497. }
  498. ckdev->row_shift = get_count_order(ckdev->cols);
  499. input_set_capability(idev, EV_MSC, MSC_SCAN);
  500. input_set_drvdata(idev, ckdev);
  501. ckdev->idev = idev;
  502. cros_ec_keyb_compute_valid_keys(ckdev);
  503. err = input_register_device(ckdev->idev);
  504. if (err) {
  505. dev_err(dev, "cannot register input device\n");
  506. return err;
  507. }
  508. return 0;
  509. }
  510. static int cros_ec_keyb_probe(struct platform_device *pdev)
  511. {
  512. struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
  513. struct device *dev = &pdev->dev;
  514. struct cros_ec_keyb *ckdev;
  515. int err;
  516. if (!dev->of_node)
  517. return -ENODEV;
  518. ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL);
  519. if (!ckdev)
  520. return -ENOMEM;
  521. ckdev->ec = ec;
  522. ckdev->dev = dev;
  523. dev_set_drvdata(dev, ckdev);
  524. err = cros_ec_keyb_register_matrix(ckdev);
  525. if (err) {
  526. dev_err(dev, "cannot register matrix inputs: %d\n", err);
  527. return err;
  528. }
  529. err = cros_ec_keyb_register_bs(ckdev);
  530. if (err) {
  531. dev_err(dev, "cannot register non-matrix inputs: %d\n", err);
  532. return err;
  533. }
  534. ckdev->notifier.notifier_call = cros_ec_keyb_work;
  535. err = blocking_notifier_chain_register(&ckdev->ec->event_notifier,
  536. &ckdev->notifier);
  537. if (err) {
  538. dev_err(dev, "cannot register notifier: %d\n", err);
  539. return err;
  540. }
  541. device_init_wakeup(ckdev->dev, true);
  542. return 0;
  543. }
  544. static int cros_ec_keyb_remove(struct platform_device *pdev)
  545. {
  546. struct cros_ec_keyb *ckdev = dev_get_drvdata(&pdev->dev);
  547. blocking_notifier_chain_unregister(&ckdev->ec->event_notifier,
  548. &ckdev->notifier);
  549. return 0;
  550. }
  551. #ifdef CONFIG_OF
  552. static const struct of_device_id cros_ec_keyb_of_match[] = {
  553. { .compatible = "google,cros-ec-keyb" },
  554. {},
  555. };
  556. MODULE_DEVICE_TABLE(of, cros_ec_keyb_of_match);
  557. #endif
  558. static SIMPLE_DEV_PM_OPS(cros_ec_keyb_pm_ops, NULL, cros_ec_keyb_resume);
  559. static struct platform_driver cros_ec_keyb_driver = {
  560. .probe = cros_ec_keyb_probe,
  561. .remove = cros_ec_keyb_remove,
  562. .driver = {
  563. .name = "cros-ec-keyb",
  564. .of_match_table = of_match_ptr(cros_ec_keyb_of_match),
  565. .pm = &cros_ec_keyb_pm_ops,
  566. },
  567. };
  568. module_platform_driver(cros_ec_keyb_driver);
  569. MODULE_LICENSE("GPL v2");
  570. MODULE_DESCRIPTION("ChromeOS EC keyboard driver");
  571. MODULE_ALIAS("platform:cros-ec-keyb");