Lines Matching +full:non +full:- +full:inverted
1 // SPDX-License-Identifier: GPL-2.0
6 // This driver uses the ChromeOS EC byte-level message-based protocol for
19 #include <linux/input/vivaldi-fmap.h>
33 * struct cros_ec_keyb - Structure representing EC keyboard device
38 * @ghost_filter: true to enable the matrix key-ghosting filter
44 * @bs_idev: The input device for non-matrix buttons and switches (or NULL).
67 * struct cros_ec_bs_map - Mapping between Linux keycodes and EC button/switch
73 * @inverted: If the #define and EV_SW have opposite meanings, this is true.
80 bool inverted; member
83 /* cros_ec_keyb_bs - Map EC button/switch #defines into kernel ones */
122 .inverted = true,
138 struct device *dev = ckdev->dev; in cros_ec_keyb_has_ghosting()
139 uint8_t *valid_keys = ckdev->valid_keys; in cros_ec_keyb_has_ghosting()
154 for (col1 = 0; col1 < ckdev->cols; col1++) { in cros_ec_keyb_has_ghosting()
156 for (col2 = col1 + 1; col2 < ckdev->cols; col2++) { in cros_ec_keyb_has_ghosting()
178 struct input_dev *idev = ckdev->idev; in cros_ec_keyb_process()
183 if (ckdev->ghost_filter && cros_ec_keyb_has_ghosting(ckdev, kb_state)) { in cros_ec_keyb_process()
185 * Simple-minded solution: ignore this state. The obvious in cros_ec_keyb_process()
189 dev_dbg(ckdev->dev, "ghosting found\n"); in cros_ec_keyb_process()
193 for (col = 0; col < ckdev->cols; col++) { in cros_ec_keyb_process()
194 for (row = 0; row < ckdev->rows; row++) { in cros_ec_keyb_process()
195 int pos = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); in cros_ec_keyb_process()
196 const unsigned short *keycodes = idev->keycode; in cros_ec_keyb_process()
199 old_state = ckdev->old_kb_state[col] & (1 << row); in cros_ec_keyb_process()
201 dev_dbg(ckdev->dev, in cros_ec_keyb_process()
210 ckdev->old_kb_state[col] = kb_state[col]; in cros_ec_keyb_process()
212 input_sync(ckdev->idev); in cros_ec_keyb_process()
216 * cros_ec_keyb_report_bs - Report non-matrixed buttons or switches
229 struct input_dev *idev = ckdev->bs_idev; in cros_ec_keyb_report_bs()
235 if (map->ev_type != ev_type) in cros_ec_keyb_report_bs()
238 input_event(idev, ev_type, map->code, in cros_ec_keyb_report_bs()
239 !!(mask & BIT(map->bit)) ^ map->inverted); in cros_ec_keyb_report_bs()
254 * suspend. Switches will be re-checked in in cros_ec_keyb_work()
257 if (queued_during_suspend && !device_may_wakeup(ckdev->dev)) in cros_ec_keyb_work()
260 switch (ckdev->ec->event_data.event_type) { in cros_ec_keyb_work()
262 pm_wakeup_event(ckdev->dev, 0); in cros_ec_keyb_work()
264 if (ckdev->ec->event_size != ckdev->cols) { in cros_ec_keyb_work()
265 dev_err(ckdev->dev, in cros_ec_keyb_work()
271 ckdev->ec->event_data.data.key_matrix, in cros_ec_keyb_work()
272 ckdev->ec->event_size); in cros_ec_keyb_work()
276 pm_wakeup_event(ckdev->dev, 0); in cros_ec_keyb_work()
278 val = get_unaligned_le32(&ckdev->ec->event_data.data.sysrq); in cros_ec_keyb_work()
279 dev_dbg(ckdev->dev, "sysrq code from EC: %#x\n", val); in cros_ec_keyb_work()
285 pm_wakeup_event(ckdev->dev, 0); in cros_ec_keyb_work()
287 if (ckdev->ec->event_data.event_type == EC_MKBP_EVENT_BUTTON) { in cros_ec_keyb_work()
289 &ckdev->ec->event_data.data.buttons); in cros_ec_keyb_work()
293 &ckdev->ec->event_data.data.switches); in cros_ec_keyb_work()
313 int row_shift = ckdev->row_shift; in cros_ec_keyb_compute_valid_keys()
314 unsigned short *keymap = ckdev->idev->keycode; in cros_ec_keyb_compute_valid_keys()
317 BUG_ON(ckdev->idev->keycodesize != sizeof(*keymap)); in cros_ec_keyb_compute_valid_keys()
319 for (col = 0; col < ckdev->cols; col++) { in cros_ec_keyb_compute_valid_keys()
320 for (row = 0; row < ckdev->rows; row++) { in cros_ec_keyb_compute_valid_keys()
323 ckdev->valid_keys[col] |= 1 << row; in cros_ec_keyb_compute_valid_keys()
325 dev_dbg(ckdev->dev, "valid_keys[%02d] = 0x%02x\n", in cros_ec_keyb_compute_valid_keys()
326 col, ckdev->valid_keys[col]); in cros_ec_keyb_compute_valid_keys()
331 * cros_ec_keyb_info - Wrap the EC command EC_CMD_MKBP_INFO
345 * Returns 0 if no error or -error upon error.
360 return -ENOMEM; in cros_ec_keyb_info()
362 msg->command = EC_CMD_MKBP_INFO; in cros_ec_keyb_info()
363 msg->version = 1; in cros_ec_keyb_info()
364 msg->outsize = sizeof(*params); in cros_ec_keyb_info()
365 msg->insize = result_size; in cros_ec_keyb_info()
366 params = (struct ec_params_mkbp_info *)msg->data; in cros_ec_keyb_info()
367 params->info_type = info_type; in cros_ec_keyb_info()
368 params->event_type = event_type; in cros_ec_keyb_info()
371 if (ret == -ENOPROTOOPT) { in cros_ec_keyb_info()
376 dev_warn(ec_dev->dev, "Transfer error %d/%d: %d\n", in cros_ec_keyb_info()
379 dev_warn(ec_dev->dev, "Wrong size %d/%d: %d != %zu\n", in cros_ec_keyb_info()
382 ret = -EPROTO; in cros_ec_keyb_info()
384 memcpy(result, msg->data, result_size); in cros_ec_keyb_info()
394 * cros_ec_keyb_query_switches - Query the state of switches and report
402 * Returns 0 if no error or -error upon error.
406 struct cros_ec_device *ec_dev = ckdev->ec; in cros_ec_keyb_query_switches()
423 * cros_ec_keyb_resume - Resume the keyboard
429 * Returns 0 if no error or -error upon error.
435 if (ckdev->bs_idev) in cros_ec_keyb_resume()
442 * cros_ec_keyb_register_bs - Register non-matrix buttons/switches
444 * Handles all the bits of the keyboard driver related to non-matrix buttons
449 * but the ckdev->bs_idev will remain NULL when this function exits.
455 * Returns 0 if no error or -error upon error.
460 struct cros_ec_device *ec_dev = ckdev->ec; in cros_ec_keyb_register_bs()
461 struct device *dev = ckdev->dev; in cros_ec_keyb_register_bs()
485 return expect_buttons_switches ? -EINVAL : 0; in cros_ec_keyb_register_bs()
488 * We call the non-matrix buttons/switches 'input1', if present. in cros_ec_keyb_register_bs()
489 * Allocate phys before input dev, to ensure correct tear-down in cros_ec_keyb_register_bs()
492 phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input1", ec_dev->phys_name); in cros_ec_keyb_register_bs()
494 return -ENOMEM; in cros_ec_keyb_register_bs()
498 return -ENOMEM; in cros_ec_keyb_register_bs()
500 idev->name = "cros_ec_buttons"; in cros_ec_keyb_register_bs()
501 idev->phys = phys; in cros_ec_keyb_register_bs()
502 __set_bit(EV_REP, idev->evbit); in cros_ec_keyb_register_bs()
504 idev->id.bustype = BUS_VIRTUAL; in cros_ec_keyb_register_bs()
505 idev->id.version = 1; in cros_ec_keyb_register_bs()
506 idev->id.product = 0; in cros_ec_keyb_register_bs()
507 idev->dev.parent = dev; in cros_ec_keyb_register_bs()
510 ckdev->bs_idev = idev; in cros_ec_keyb_register_bs()
515 if ((map->ev_type == EV_KEY && (buttons & BIT(map->bit))) || in cros_ec_keyb_register_bs()
516 (map->ev_type == EV_SW && (switches & BIT(map->bit)))) in cros_ec_keyb_register_bs()
517 input_set_capability(idev, map->ev_type, map->code); in cros_ec_keyb_register_bs()
526 ret = input_register_device(ckdev->bs_idev); in cros_ec_keyb_register_bs()
537 u32 *physmap = ckdev->vdata.function_row_physmap; in cros_ec_keyb_parse_vivaldi_physmap()
543 n_physmap = device_property_count_u32(ckdev->dev, in cros_ec_keyb_parse_vivaldi_physmap()
544 "function-row-physmap"); in cros_ec_keyb_parse_vivaldi_physmap()
549 dev_warn(ckdev->dev, in cros_ec_keyb_parse_vivaldi_physmap()
555 error = device_property_read_u32_array(ckdev->dev, in cros_ec_keyb_parse_vivaldi_physmap()
556 "function-row-physmap", in cros_ec_keyb_parse_vivaldi_physmap()
559 dev_warn(ckdev->dev, in cros_ec_keyb_parse_vivaldi_physmap()
560 "failed to parse function-row-physmap property: %d\n", in cros_ec_keyb_parse_vivaldi_physmap()
572 scancode = MATRIX_SCAN_CODE(row, col, ckdev->row_shift); in cros_ec_keyb_parse_vivaldi_physmap()
576 ckdev->vdata.num_function_row_keys = n_physmap; in cros_ec_keyb_parse_vivaldi_physmap()
580 * cros_ec_keyb_register_matrix - Register matrix keys
586 * Returns 0 if no error or -error upon error.
590 struct cros_ec_device *ec_dev = ckdev->ec; in cros_ec_keyb_register_matrix()
591 struct device *dev = ckdev->dev; in cros_ec_keyb_register_matrix()
596 err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols); in cros_ec_keyb_register_matrix()
600 ckdev->valid_keys = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL); in cros_ec_keyb_register_matrix()
601 if (!ckdev->valid_keys) in cros_ec_keyb_register_matrix()
602 return -ENOMEM; in cros_ec_keyb_register_matrix()
604 ckdev->old_kb_state = devm_kzalloc(dev, ckdev->cols, GFP_KERNEL); in cros_ec_keyb_register_matrix()
605 if (!ckdev->old_kb_state) in cros_ec_keyb_register_matrix()
606 return -ENOMEM; in cros_ec_keyb_register_matrix()
610 * dev, to ensure correct tear-down ordering. in cros_ec_keyb_register_matrix()
612 phys = devm_kasprintf(dev, GFP_KERNEL, "%s/input0", ec_dev->phys_name); in cros_ec_keyb_register_matrix()
614 return -ENOMEM; in cros_ec_keyb_register_matrix()
618 return -ENOMEM; in cros_ec_keyb_register_matrix()
620 idev->name = CROS_EC_DEV_NAME; in cros_ec_keyb_register_matrix()
621 idev->phys = phys; in cros_ec_keyb_register_matrix()
622 __set_bit(EV_REP, idev->evbit); in cros_ec_keyb_register_matrix()
624 idev->id.bustype = BUS_VIRTUAL; in cros_ec_keyb_register_matrix()
625 idev->id.version = 1; in cros_ec_keyb_register_matrix()
626 idev->id.product = 0; in cros_ec_keyb_register_matrix()
627 idev->dev.parent = dev; in cros_ec_keyb_register_matrix()
629 ckdev->ghost_filter = device_property_read_bool(dev, in cros_ec_keyb_register_matrix()
630 "google,needs-ghost-filter"); in cros_ec_keyb_register_matrix()
632 err = matrix_keypad_build_keymap(NULL, NULL, ckdev->rows, ckdev->cols, in cros_ec_keyb_register_matrix()
639 ckdev->row_shift = get_count_order(ckdev->cols); in cros_ec_keyb_register_matrix()
643 ckdev->idev = idev; in cros_ec_keyb_register_matrix()
647 err = input_register_device(ckdev->idev); in cros_ec_keyb_register_matrix()
661 const struct vivaldi_data *data = &ckdev->vdata; in function_row_physmap_show()
681 !ckdev->vdata.num_function_row_keys) in cros_ec_keyb_attr_is_visible()
684 return attr->mode; in cros_ec_keyb_attr_is_visible()
696 struct device *dev = &pdev->dev; in cros_ec_keyb_probe()
705 ec = dev_get_drvdata(pdev->dev.parent); in cros_ec_keyb_probe()
707 return -EPROBE_DEFER; in cros_ec_keyb_probe()
711 return -ENOMEM; in cros_ec_keyb_probe()
713 ckdev->ec = ec; in cros_ec_keyb_probe()
714 ckdev->dev = dev; in cros_ec_keyb_probe()
728 dev_err(dev, "cannot register non-matrix inputs: %d\n", err); in cros_ec_keyb_probe()
732 ckdev->notifier.notifier_call = cros_ec_keyb_work; in cros_ec_keyb_probe()
733 err = blocking_notifier_chain_register(&ckdev->ec->event_notifier, in cros_ec_keyb_probe()
734 &ckdev->notifier); in cros_ec_keyb_probe()
740 device_init_wakeup(ckdev->dev, true); in cros_ec_keyb_probe()
746 struct cros_ec_keyb *ckdev = dev_get_drvdata(&pdev->dev); in cros_ec_keyb_remove()
748 blocking_notifier_chain_unregister(&ckdev->ec->event_notifier, in cros_ec_keyb_remove()
749 &ckdev->notifier); in cros_ec_keyb_remove()
762 { .compatible = "google,cros-ec-keyb" },
763 { .compatible = "google,cros-ec-keyb-switches", .data = (void *)true },
775 .name = "cros-ec-keyb",
787 MODULE_ALIAS("platform:cros-ec-keyb");