cros_ec_keyb.c 17 KB

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