diff mbox series

[1/2] Input: cros-ec-keyb: Only register keyboard if rows/columns exist

Message ID 20220413033334.1514008-2-swboyd@chromium.org (mailing list archive)
State New
Headers show
Series Input: cros-ec-keyb: Don't register keyboard if doesn't exist | expand

Commit Message

Stephen Boyd April 13, 2022, 3:33 a.m. UTC
If the device is a detachable, we may still probe this device because
there are some button switches, e.g. volume buttons and power buttons,
registered by this driver. Let's allow the device node to be missing row
and column device properties to indicate that the keyboard matrix
shouldn't be registered. This removes an input device on Trogdor devices
such as Wormdingler that don't have a matrix keyboard, but still have
power and volume buttons. That helps userspace understand there isn't
a keyboard present when the detachable keyboard is disconnected.

Cc: Benson Leung <bleung@chromium.org>
Cc: Guenter Roeck <groeck@chromium.org>
Cc: Douglas Anderson <dianders@chromium.org>
Cc: Hsin-Yi Wang <hsinyi@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---

I tried to use mkbp info to query the number of rows and columns, but my
EC firmware doesn't have commit 8505881ed0b9 ("mkbp: Separate MKBP_INFO
host command from the keyboard driver") so it always returns 8 and 13
for the rows and columns. Sigh. With updated firmware we could query it,
or we could rely on DT like we do already.

Originally I was setting the properties to 0, but
matrix_keypad_parse_properties() spits out an error message in that case
and so it seems better to delete the properties and check for their
existence instead. Another alternative would be to change the compatible
to be "google,cros-ec-keyb-switches" or something that indicates there
are only switches and no matrix keyboard.

 drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Doug Anderson April 13, 2022, 8:44 p.m. UTC | #1
Hi,

On Tue, Apr 12, 2022 at 8:33 PM Stephen Boyd <swboyd@chromium.org> wrote:
>
> If the device is a detachable, we may still probe this device because
> there are some button switches, e.g. volume buttons and power buttons,
> registered by this driver. Let's allow the device node to be missing row
> and column device properties to indicate that the keyboard matrix
> shouldn't be registered. This removes an input device on Trogdor devices
> such as Wormdingler that don't have a matrix keyboard, but still have
> power and volume buttons. That helps userspace understand there isn't
> a keyboard present when the detachable keyboard is disconnected.
>
> Cc: Benson Leung <bleung@chromium.org>
> Cc: Guenter Roeck <groeck@chromium.org>
> Cc: Douglas Anderson <dianders@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>
> I tried to use mkbp info to query the number of rows and columns, but my
> EC firmware doesn't have commit 8505881ed0b9 ("mkbp: Separate MKBP_INFO
> host command from the keyboard driver") so it always returns 8 and 13
> for the rows and columns. Sigh. With updated firmware we could query it,
> or we could rely on DT like we do already.
>
> Originally I was setting the properties to 0, but
> matrix_keypad_parse_properties() spits out an error message in that case
> and so it seems better to delete the properties and check for their
> existence instead. Another alternative would be to change the compatible
> to be "google,cros-ec-keyb-switches" or something that indicates there
> are only switches and no matrix keyboard.
>
>  drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
>  1 file changed, 9 insertions(+)

I do wonder if there will be any unintentional side effects here.
Specifically, even though there is truly no keyboard here, I wonder if
anything in the system is relying on the EC to simulate keypresses
even on tablets where the keyboard isn't actually there...

OK, I guess not. While I think it _used_ to be the case that you could
simulate keyboard inputs from the EC console even for devices w/out a
keyboard, it doesn't seem to be the case anymore. I just tried it and
nothing made it through to the AP.

Seems reasonable to me:

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Dmitry Torokhov April 25, 2022, 3:47 a.m. UTC | #2
Hi Stephen,

On Tue, Apr 12, 2022 at 08:33:33PM -0700, Stephen Boyd wrote:
> If the device is a detachable, we may still probe this device because
> there are some button switches, e.g. volume buttons and power buttons,
> registered by this driver. Let's allow the device node to be missing row
> and column device properties to indicate that the keyboard matrix
> shouldn't be registered. This removes an input device on Trogdor devices
> such as Wormdingler that don't have a matrix keyboard, but still have
> power and volume buttons. That helps userspace understand there isn't
> a keyboard present when the detachable keyboard is disconnected.
> 
> Cc: Benson Leung <bleung@chromium.org>
> Cc: Guenter Roeck <groeck@chromium.org>
> Cc: Douglas Anderson <dianders@chromium.org>
> Cc: Hsin-Yi Wang <hsinyi@chromium.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
> 
> I tried to use mkbp info to query the number of rows and columns, but my
> EC firmware doesn't have commit 8505881ed0b9 ("mkbp: Separate MKBP_INFO
> host command from the keyboard driver") so it always returns 8 and 13
> for the rows and columns. Sigh. With updated firmware we could query it,
> or we could rely on DT like we do already.
> 
> Originally I was setting the properties to 0, but
> matrix_keypad_parse_properties() spits out an error message in that case
> and so it seems better to delete the properties and check for their
> existence instead. Another alternative would be to change the compatible
> to be "google,cros-ec-keyb-switches" or something that indicates there
> are only switches and no matrix keyboard.
> 
>  drivers/input/keyboard/cros_ec_keyb.c | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
> index 6534dfca60b4..ac9a953bff02 100644
> --- a/drivers/input/keyboard/cros_ec_keyb.c
> +++ b/drivers/input/keyboard/cros_ec_keyb.c
> @@ -537,6 +537,15 @@ static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev)
>  	u32 key_pos;
>  	unsigned int row, col, scancode, n_physmap;
>  
> +	/*
> +	 * No rows and columns? There isn't a matrix but maybe there are
> +	 * switches to register in cros_ec_keyb_register_bs() because this is a
> +	 * detachable device.
> +	 */
> +	if (!device_property_read_bool(dev, "keypad,num-rows") &&
> +	    !device_property_read_bool(dev, "keypad,num-cols"))

Why are we abusing device_property_read_bool() for properties that are
not flags instead of using device_property_present()?

> +		return 0;
> +
>  	err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols);
>  	if (err)
>  		return err;
> -- 
> https://chromeos.dev
> 

Thanks.
Stephen Boyd April 25, 2022, 8:12 p.m. UTC | #3
Quoting Dmitry Torokhov (2022-04-24 20:47:03)
> >
> > +     /*
> > +      * No rows and columns? There isn't a matrix but maybe there are
> > +      * switches to register in cros_ec_keyb_register_bs() because this is a
> > +      * detachable device.
> > +      */
> > +     if (!device_property_read_bool(dev, "keypad,num-rows") &&
> > +         !device_property_read_bool(dev, "keypad,num-cols"))
>
> Why are we abusing device_property_read_bool() for properties that are
> not flags instead of using device_property_present()?
>

Because I wrote this using DT APIs first and wasn't aware that
device_property_present() was a thing. I'll resend it with that API
usage.
diff mbox series

Patch

diff --git a/drivers/input/keyboard/cros_ec_keyb.c b/drivers/input/keyboard/cros_ec_keyb.c
index 6534dfca60b4..ac9a953bff02 100644
--- a/drivers/input/keyboard/cros_ec_keyb.c
+++ b/drivers/input/keyboard/cros_ec_keyb.c
@@ -537,6 +537,15 @@  static int cros_ec_keyb_register_matrix(struct cros_ec_keyb *ckdev)
 	u32 key_pos;
 	unsigned int row, col, scancode, n_physmap;
 
+	/*
+	 * No rows and columns? There isn't a matrix but maybe there are
+	 * switches to register in cros_ec_keyb_register_bs() because this is a
+	 * detachable device.
+	 */
+	if (!device_property_read_bool(dev, "keypad,num-rows") &&
+	    !device_property_read_bool(dev, "keypad,num-cols"))
+		return 0;
+
 	err = matrix_keypad_parse_properties(dev, &ckdev->rows, &ckdev->cols);
 	if (err)
 		return err;