Skip to content

Commit ca1eadb

Browse files
bebarinodtor
authored andcommitted
Input: cros-ec-keyb - allow skipping keyboard registration
If the device is a detachable (and therefore lacks full keyboard), we may still want to load this driver because the device might have some other buttons or switches (e.g. volume and power buttons or a tablet mode switch). In such case we do not want to register the "main" keyboard device to allow userspace detect when the detachable keyboard is disconnected and adjust the system behavior for the tablet mode. Originally it was suggested to simply skip keyboard registration if row and columns properties didn't exist, but that approach did not convey the intent strongly enough and also had a slight problem for migrating existing DTBs without updating the kernel first, so it was decided to introduce new google,cros-ec-keyb-switches to explicitly mark devices that only have axillary buttons and switches. Reviewed-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Link: https://lore.kernel.org/r/20220516183452.942008-3-swboyd@chromium.org Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 52dc6d3 commit ca1eadb

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

drivers/input/keyboard/cros_ec_keyb.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,13 @@ static __maybe_unused int cros_ec_keyb_resume(struct device *dev)
439439
* but the ckdev->bs_idev will remain NULL when this function exits.
440440
*
441441
* @ckdev: The keyboard device
442+
* @expect_buttons_switches: Indicates that EC must report button and/or
443+
* switch events
442444
*
443445
* Returns 0 if no error or -error upon error.
444446
*/
445-
static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev)
447+
static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev,
448+
bool expect_buttons_switches)
446449
{
447450
struct cros_ec_device *ec_dev = ckdev->ec;
448451
struct device *dev = ckdev->dev;
@@ -469,7 +472,7 @@ static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev)
469472
switches = get_unaligned_le32(&event_data.switches);
470473

471474
if (!buttons && !switches)
472-
return 0;
475+
return expect_buttons_switches ? -EINVAL : 0;
473476

474477
/*
475478
* We call the non-matrix buttons/switches 'input1', if present.
@@ -520,7 +523,7 @@ static int cros_ec_keyb_register_bs(struct cros_ec_keyb *ckdev)
520523
}
521524

522525
/**
523-
* cros_ec_keyb_register_bs - Register matrix keys
526+
* cros_ec_keyb_register_matrix - Register matrix keys
524527
*
525528
* Handles all the bits of the keyboard driver related to matrix keys.
526529
*
@@ -659,12 +662,12 @@ static const struct attribute_group cros_ec_keyb_attr_group = {
659662
.attrs = cros_ec_keyb_attrs,
660663
};
661664

662-
663665
static int cros_ec_keyb_probe(struct platform_device *pdev)
664666
{
665667
struct cros_ec_device *ec = dev_get_drvdata(pdev->dev.parent);
666668
struct device *dev = &pdev->dev;
667669
struct cros_ec_keyb *ckdev;
670+
bool buttons_switches_only = device_get_match_data(dev);
668671
int err;
669672

670673
if (!dev->of_node)
@@ -678,21 +681,24 @@ static int cros_ec_keyb_probe(struct platform_device *pdev)
678681
ckdev->dev = dev;
679682
dev_set_drvdata(dev, ckdev);
680683

681-
err = cros_ec_keyb_register_matrix(ckdev);
682-
if (err) {
683-
dev_err(dev, "cannot register matrix inputs: %d\n", err);
684-
return err;
684+
if (!buttons_switches_only) {
685+
err = cros_ec_keyb_register_matrix(ckdev);
686+
if (err) {
687+
dev_err(dev, "cannot register matrix inputs: %d\n",
688+
err);
689+
return err;
690+
}
685691
}
686692

687-
err = cros_ec_keyb_register_bs(ckdev);
693+
err = cros_ec_keyb_register_bs(ckdev, buttons_switches_only);
688694
if (err) {
689695
dev_err(dev, "cannot register non-matrix inputs: %d\n", err);
690696
return err;
691697
}
692698

693699
err = devm_device_add_group(dev, &cros_ec_keyb_attr_group);
694700
if (err) {
695-
dev_err(dev, "failed to create attributes. err=%d\n", err);
701+
dev_err(dev, "failed to create attributes: %d\n", err);
696702
return err;
697703
}
698704

@@ -721,7 +727,8 @@ static int cros_ec_keyb_remove(struct platform_device *pdev)
721727
#ifdef CONFIG_OF
722728
static const struct of_device_id cros_ec_keyb_of_match[] = {
723729
{ .compatible = "google,cros-ec-keyb" },
724-
{},
730+
{ .compatible = "google,cros-ec-keyb-switches", .data = (void *)true },
731+
{}
725732
};
726733
MODULE_DEVICE_TABLE(of, cros_ec_keyb_of_match);
727734
#endif

0 commit comments

Comments
 (0)