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