cros_ec_keyb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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_report_key(idev, keycodes[pos],
  169. new_state);
  170. }
  171. }
  172. ckdev->old_kb_state[col] = kb_state[col];
  173. }
  174. input_sync(ckdev->idev);
  175. }
  176. /**
  177. * cros_ec_keyb_report_bs - Report non-matrixed buttons or switches
  178. *
  179. * This takes a bitmap of buttons or switches from the EC and reports events,
  180. * syncing at the end.
  181. *
  182. * @ckdev: The keyboard device.
  183. * @ev_type: The input event type (e.g., EV_KEY).
  184. * @mask: A bitmap of buttons from the EC.
  185. */
  186. static void cros_ec_keyb_report_bs(struct cros_ec_keyb *ckdev,
  187. unsigned int ev_type, u32 mask)
  188. {
  189. struct input_dev *idev = ckdev->bs_idev;
  190. int i;
  191. for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) {
  192. const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i];
  193. if (map->ev_type != ev_type)
  194. continue;
  195. input_event(idev, ev_type, map->code,
  196. !!(mask & BIT(map->bit)) ^ map->inverted);
  197. }
  198. input_sync(idev);
  199. }
  200. static int cros_ec_keyb_work(struct notifier_block *nb,
  201. unsigned long queued_during_suspend, void *_notify)
  202. {
  203. struct cros_ec_keyb *ckdev = container_of(nb, struct cros_ec_keyb,
  204. notifier);
  205. u32 val;
  206. unsigned int ev_type;
  207. /*
  208. * If not wake enabled, discard key state changes during
  209. * suspend. Switches will be re-checked in
  210. * cros_ec_keyb_resume() to be sure nothing is lost.
  211. */
  212. if (queued_during_suspend && !device_may_wakeup(ckdev->dev))
  213. return NOTIFY_OK;
  214. switch (ckdev->ec->event_data.event_type) {
  215. case EC_MKBP_EVENT_KEY_MATRIX:
  216. pm_wakeup_event(ckdev->dev, 0);
  217. if (ckdev->ec->event_size != ckdev->cols) {
  218. dev_err(ckdev->dev,
  219. "Discarded incomplete key matrix event.\n");
  220. return NOTIFY_OK;
  221. }
  222. cros_ec_keyb_process(ckdev,
  223. ckdev->ec->event_data.data.key_matrix,
  224. ckdev->ec->event_size);
  225. break;
  226. case EC_MKBP_EVENT_SYSRQ:
  227. pm_wakeup_event(ckdev->dev, 0);
  228. val = get_unaligned_le32(&ckdev->ec->event_data.data.sysrq);
  229. dev_dbg(ckdev->dev, "sysrq code from EC: %#x\n", val);
  230. handle_sysrq(val);
  231. break;
  232. case EC_MKBP_EVENT_BUTTON:
  233. case EC_MKBP_EVENT_SWITCH:
  234. pm_wakeup_event(ckdev->dev, 0);
  235. if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) {
  236. val = get_unaligned_le32(
  237. &ckdev->ec->event_data.data.buttons);
  238. ev_type = EV_KEY;
  239. } else {
  240. val = get_unaligned_le32(
  241. &ckdev->ec->event_data.data.switches);
  242. ev_type = EV_SW;
  243. }
  244. cros_ec_keyb_report_bs(ckdev, ev_type, val);
  245. break;
  246. default:
  247. return NOTIFY_DONE;
  248. }
  249. return NOTIFY_OK;
  250. }
  251. /*
  252. * Walks keycodes flipping bit in buffer COLUMNS deep where bit is ROW. Used by
  253. * ghosting logic to ignore NULL or virtual keys.
  254. */
  255. static void cros_ec_keyb_compute_valid_keys(struct cros_ec_keyb *ckdev)
  256. {
  257. int row, col;
  258. int row_shift = ckdev->row_shift;
  259. unsigned short *keymap = ckdev->idev->keycode;
  260. unsigned short code;
  261. BUG_ON(ckdev->idev->keycodesize != sizeof(*keymap));
  262. for (col = 0; col < ckdev->cols; col++) {
  263. for (row = 0; row < ckdev->rows; row++) {
  264. code = keymap[MATRIX_SCAN_CODE(row, col, row_shift)];
  265. if (code && (code != KEY_BATTERY))
  266. ckdev->valid_keys[col] |= 1 << row;
  267. }
  268. dev_dbg(ckdev->dev, "valid_keys[%02d] = 0x%02x\n",
  269. col, ckdev->valid_keys[col]);
  270. }
  271. }
  272. /**
  273. * cros_ec_keyb_info - Wrap the EC command EC_CMD_MKBP_INFO
  274. *
  275. * This wraps the EC_CMD_MKBP_INFO, abstracting out all of the marshalling and
  276. * unmarshalling and different version nonsense into something simple.
  277. *
  278. * @ec_dev: The EC device
  279. * @info_type: Either EC_MKBP_INFO_SUPPORTED or EC_MKBP_INFO_CURRENT.
  280. * @event_type: Either EC_MKBP_EVENT_BUTTON or EC_MKBP_EVENT_SWITCH. Actually
  281. * in some cases this could be EC_MKBP_EVENT_KEY_MATRIX or
  282. * EC_MKBP_EVENT_HOST_EVENT too but we don't use in this driver.
  283. * @result: Where we'll store the result; a union
  284. * @result_size: The size of the result. Expected to be the size of one of
  285. * the elements in the union.
  286. *
  287. * Returns 0 if no error or -error upon error.
  288. */
  289. static int cros_ec_keyb_info(struct cros_ec_device *ec_dev,
  290. enum ec_mkbp_info_type info_type,
  291. enum ec_mkbp_event event_type,
  292. union ec_response_get_next_data *result,
  293. size_t result_size)
  294. {
  295. struct ec_params_mkbp_info *params;
  296. struct cros_ec_command *msg;
  297. int ret;
  298. msg = kzalloc(sizeof(*msg) + max_t(size_t, result_size,
  299. sizeof(*params)), GFP_KERNEL);
  300. if (!msg)
  301. return -ENOMEM;
  302. msg->command = EC_CMD_MKBP_INFO;
  303. msg->version = 1;
  304. msg->outsize = sizeof(*params);
  305. msg->insize = result_size;
  306. params = (struct ec_params_mkbp_info *)msg->data;
  307. params->info_type = info_type;
  308. params->event_type = event_type;
  309. ret = cros_ec_cmd_xfer(ec_dev, msg);
  310. if (ret < 0) {
  311. dev_warn(ec_dev->dev, "Transfer error %d/%d: %d\n",
  312. (int)info_type, (int)event_type, ret);
  313. } else if (msg->result == EC_RES_INVALID_VERSION) {
  314. /* With older ECs we just return 0 for everything */
  315. memset(result, 0, result_size);
  316. ret = 0;
  317. } else if (msg->result != EC_RES_SUCCESS) {
  318. dev_warn(ec_dev->dev, "Error getting info %d/%d: %d\n",
  319. (int)info_type, (int)event_type, msg->result);
  320. ret = -EPROTO;
  321. } else if (ret != result_size) {
  322. dev_warn(ec_dev->dev, "Wrong size %d/%d: %d != %zu\n",
  323. (int)info_type, (int)event_type,
  324. ret, result_size);
  325. ret = -EPROTO;
  326. } else {
  327. memcpy(result, msg->data, result_size);
  328. ret = 0;
  329. }
  330. kfree(msg);
  331. return ret;
  332. }
  333. /**
  334. * cros_ec_keyb_query_switches - Query the state of switches and report
  335. *
  336. * This will ask the EC about the current state of switches and report to the
  337. * kernel. Note that we don't query for buttons because they are more
  338. * transitory and we'll get an update on the next release / press.
  339. *
  340. * @ckdev: The keyboard device
  341. *
  342. * Returns 0 if no error or -error upon error.
  343. */
  344. static int cros_ec_keyb_query_switches(struct cros_ec_keyb *ckdev)
  345. {
  346. struct cros_ec_device *ec_dev = ckdev->ec;
  347. union ec_response_get_next_data event_data = {};
  348. int ret;
  349. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_CURRENT,
  350. EC_MKBP_EVENT_SWITCH, &event_data,
  351. sizeof(event_data.switches));
  352. if (ret)
  353. return ret;
  354. cros_ec_keyb_report_bs(ckdev, EV_SW,
  355. get_unaligned_le32(&event_data.switches));
  356. return 0;
  357. }
  358. /**
  359. * cros_ec_keyb_resume - Resume the keyboard
  360. *
  361. * We use the resume notification as a chance to query the EC for switches.
  362. *
  363. * @dev: The keyboard device
  364. *
  365. * Returns 0 if no error or -error upon error.
  366. */
  367. static __maybe_unused int cros_ec_keyb_resume(struct device *dev)
  368. {
  369. struct cros_ec_keyb *ckdev = dev_get_drvdata(dev);
  370. if (ckdev->bs_idev)
  371. return cros_ec_keyb_query_switches(ckdev);
  372. return 0;
  373. }
  374. /**
  375. * cros_ec_keyb_register_bs - Register non-matrix buttons/switches
  376. *
  377. * Handles all the bits of the keyboard driver related to non-matrix buttons
  378. * and switches, including asking the EC about which are present and telling
  379. * the kernel to expect them.
  380. *
  381. * If this device has no support for buttons and switches we'll return no error
  382. * but the ckdev->bs_idev will remain NULL when this function exits.
  383. *
  384. * @ckdev: The keyboard device
  385. *
  386. * Returns 0 if no error or -error upon error.
  387. */
  388. static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev)
  389. {
  390. struct cros_ec_device *ec_dev = ckdev->ec;
  391. struct device *dev = ckdev->dev;
  392. struct input_dev *idev;
  393. union ec_response_get_next_data event_data = {};
  394. const char *phys;
  395. u32 buttons;
  396. u32 switches;
  397. int ret;
  398. int i;
  399. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED,
  400. EC_MKBP_EVENT_BUTTON, &event_data,
  401. sizeof(event_data.buttons));
  402. if (ret)
  403. return ret;
  404. buttons = get_unaligned_le32(&event_data.buttons);
  405. ret = cros_ec_keyb_info(ec_dev, EC_MKBP_INFO_SUPPORTED,
  406. EC_MKBP_EVENT_SWITCH, &event_data,
  407. sizeof(event_data.switches));
  408. if (ret)
  409. return ret;
  410. switches = get_unaligned_le32(&event_data.switches);
  411. if (!buttons && !switches)
  412. return 0;
  413. /*
  414. * We call the non-matrix buttons/switches 'input1', if present.
  415. * Allocate phys before input dev, to ensure correct tear-down
  416. * ordering.
  417. */
  418. phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input1", ec_dev->phys_name);
  419. if (!phys)
  420. return -ENOMEM;
  421. idev = devm_input_allocate_device(dev);
  422. if (!idev)
  423. return -ENOMEM;
  424. idev->name = "cros_ec_buttons";
  425. idev->phys = phys;
  426. __set_bit(EV_REP, idev->evbit);
  427. idev->id.bustype = BUS_VIRTUAL;
  428. idev->id.version = 1;
  429. idev->id.product = 0;
  430. idev->dev.parent = dev;
  431. input_set_drvdata(idev, ckdev);
  432. ckdev->bs_idev = idev;
  433. for (i = 0; i < ARRAY_SIZE(cros_ec_keyb_bs); i++) {
  434. const struct cros_ec_bs_map *map = &cros_ec_keyb_bs[i];
  435. if ((map->ev_type == EV_KEY && (buttons & BIT(map->bit))) ||
  436. (map->ev_type == EV_SW && (switches & BIT(map->bit))))
  437. input_set_capability(idev, map->ev_type, map->code);
  438. }
  439. ret = cros_ec_keyb_query_switches(ckdev);
  440. if (ret) {
  441. dev_err(dev, "cannot query switches\n");
  442. return ret;
  443. }
  444. ret = input_register_device(ckdev->bs_idev);
  445. if (ret) {
  446. dev_err(dev, "cannot register input device\n");
  447. return ret;
  448. }
  449. return 0;
  450. }
  451. /**
  452. * cros_ec_keyb_register_bs - Register matrix keys
  453. *
  454. * Handles all the bits of the keyboard driver related to matrix keys.
  455. *
  456. * @ckdev: The keyboard device
  457. *
  458. * Returns 0 if no error or -error upon error.
  459. */
  460. static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev)
  461. {
  462. struct cros_ec_device *ec_dev = ckdev->ec;
  463. struct device *dev = ckdev->dev;
  464. struct input_dev *idev;
  465. const char *phys;
  466. int err;
  467. err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols);
  468. if (err)
  469. return err;
  470. ckdev->valid_keys = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
  471. if (!ckdev->valid_keys)
  472. return -ENOMEM;
  473. ckdev->old_kb_state = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL);
  474. if (!ckdev->old_kb_state)
  475. return -ENOMEM;
  476. /*
  477. * We call the keyboard matrix 'input0'. Allocate phys before input
  478. * dev, to ensure correct tear-down ordering.
  479. */
  480. phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input0", ec_dev->phys_name);
  481. if (!phys)
  482. return -ENOMEM;
  483. idev = devm_input_allocate_device(dev);
  484. if (!idev)
  485. return -ENOMEM;
  486. idev->name = CROS_EC_DEV_NAME;
  487. idev->phys = phys;
  488. __set_bit(EV_REP, idev->evbit);
  489. idev->id.bustype = BUS_VIRTUAL;
  490. idev->id.version = 1;
  491. idev->id.product = 0;
  492. idev->dev.parent = dev;
  493. ckdev->ghost_filter = of_property_read_bool(dev->of_node,
  494. "google,needs-ghost-filter");
  495. err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows, ckdev->cols,
  496. NULL, idev);
  497. if (err) {
  498. dev_err(dev, "cannot build key matrix\n");
  499. return err;
  500. }
  501. ckdev->row_shift = get_count_order(ckdev->cols);
  502. input_set_capability(idev, EV_MSC, MSC_SCAN);
  503. input_set_drvdata(idev, ckdev);
  504. ckdev->idev = idev;
  505. cros_ec_keyb_compute_valid_keys(ckdev);
  506. err = input_register_device(ckdev->idev);
  507. if (err) {
  508. dev_err(dev, "cannot register input device\n");
  509. return err;
  510. }
  511. return 0;
  512. }
  513. static int cros_ec_keyb_probe(struct platform_device *pdev)
  514. {
  515. struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
  516. struct device *dev = &pdev->dev;
  517. struct cros_ec_keyb *ckdev;
  518. int err;
  519. if (!dev->of_node)
  520. return -ENODEV;
  521. ckdev = devm_kzalloc(dev, sizeof(*ckdev), GFP_KERNEL);
  522. if (!ckdev)
  523. return -ENOMEM;
  524. ckdev->ec = ec;
  525. ckdev->dev = dev;
  526. dev_set_drvdata(dev, ckdev);
  527. err = cros_ec_keyb_register_matrix(ckdev);
  528. if (err) {
  529. dev_err(dev, "cannot register matrix inputs: %d\n", err);
  530. return err;
  531. }
  532. err = cros_ec_keyb_register_bs(ckdev);
  533. if (err) {
  534. dev_err(dev, "cannot register non-matrix inputs: %d\n", err);
  535. return err;
  536. }
  537. ckdev->notifier.notifier_call = cros_ec_keyb_work;
  538. err = blocking_notifier_chain_register(&ckdev->ec->event_notifier,
  539. &ckdev->notifier);
  540. if (err) {
  541. dev_err(dev, "cannot register notifier: %d\n", err);
  542. return err;
  543. }
  544. device_init_wakeup(ckdev->dev, true);
  545. return 0;
  546. }
  547. static int cros_ec_keyb_remove(struct platform_device *pdev)
  548. {
  549. struct cros_ec_keyb *ckdev = dev_get_drvdata(&pdev->dev);
  550. blocking_notifier_chain_unregister(&ckdev->ec->event_notifier,
  551. &ckdev->notifier);
  552. return 0;
  553. }
  554. #ifdef CONFIG_OF
  555. static const struct of_device_id cros_ec_keyb_of_match[] = {
  556. { .compatible = "google,cros-ec-keyb" },
  557. {},
  558. };
  559. MODULE_DEVICE_TABLE(of, cros_ec_keyb_of_match);
  560. #endif
  561. static SIMPLE_DEV_PM_OPS(cros_ec_keyb_pm_ops, NULL, cros_ec_keyb_resume);
  562. static struct platform_driver cros_ec_keyb_driver = {
  563. .probe = cros_ec_keyb_probe,
  564. .remove = cros_ec_keyb_remove,
  565. .driver = {
  566. .name = "cros-ec-keyb",
  567. .of_match_table = of_match_ptr(cros_ec_keyb_of_match),
  568. .pm = &cros_ec_keyb_pm_ops,
  569. },
  570. };
  571. module_platform_driver(cros_ec_keyb_driver);
  572. MODULE_LICENSE("GPL v2");
  573. MODULE_DESCRIPTION("ChromeOS EC keyboard driver");
  574. MODULE_ALIAS("platform:cros-ec-keyb");