Re: [PATCH v7 2/2] Input: cros_ec_keyb - add function key support

From: Dmitry Torokhov

Date: Sat Feb 21 2026 - 19:40:44 EST


Hi Fabio,

On Wed, Feb 11, 2026 at 05:34:21PM +0000, Fabio Baltieri wrote:
>
> +/* Returns true if there is a KEY_FN code defined in the normal keymap */
> +static bool cros_ec_keyb_has_fn_key(struct cros_ec_keyb *ckdev)
> +{
> + struct input_dev *idev = ckdev->idev;
> + const unsigned short *keycodes = idev->keycode;
> +
> + for (int row = 0; row < ckdev->rows; row++) {
> + for (int col = 0; col < ckdev->cols; col++) {
> + int pos = MATRIX_SCAN_CODE(row, col, ckdev->row_shift);
> +
> + if (keycodes[pos] == KEY_FN)
> + return true;
> + }

We can simply scan the bottom half of the map linearly, I think this is
simpler.

> + }
> +
> + return false;
> +}
> +
> +/*
> + * Returns true if there is a KEY_FN defined and at least one key in the fn
> + * layer keymap
> + */
> +static bool cros_ec_keyb_has_fn_map(struct cros_ec_keyb *ckdev)
> +{
> + if (!cros_ec_keyb_has_fn_key(ckdev))
> + return false;
> +
> + for (int row = 0; row < ckdev->rows; row++) {
> + for (int col = 0; col < ckdev->cols; col++) {
> + if (cros_ec_keyb_fn_code(ckdev, row, col, NULL) != 0)
> + return true;

Same here.

I made a bunch of changes to your patch and then a bunch of changes to
the driver in general. Please take a look.

Thanks.

--
Dmitry