From: Fabio Baltieri <fabiobaltieri@chromium.org>
To: Simon Glass <sjg@chromium.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
Tzung-Bi Shih <tzungbi@kernel.org>,
linux-input@vger.kernel.org, devicetree@vger.kernel.org,
chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/3] Input: cros_ec_keyb: add function key support
Date: Mon, 15 Dec 2025 13:09:24 +0000 [thread overview]
Message-ID: <aUAIhNMTPQVl3b4W@google.com> (raw)
In-Reply-To: <CAFLszThUU4hfb4vY4mmGHQadRKThG3e=9cAKRy_ampKwA_XNcA@mail.gmail.com>
Hey Simon,
On Thu, Dec 11, 2025 at 06:29:01AM -0700, Simon Glass wrote:
> > @@ -44,6 +52,13 @@
> > * @bs_idev: The input device for non-matrix buttons and switches (or NULL).
> > * @notifier: interrupt event notifier for transport devices
> > * @vdata: vivaldi function row data
> > + * @fn_key: coordinate of the function key
> > + * @fn_keymap: array of coordinate and codes for the function keys
> > + * @fn_keymap_len: number of entries in the fn_keymap array
> > + * @fn_key_status: active function keys bitmap
> > + * @normal_key_status: active normal keys bitmap
> > + * @fn_key_pressed: tracks the function key status
> > + * @fn_key_triggered: tracks where any function key fired
> > */
> > struct cros_ec_keyb {
> > unsigned int rows;
> > @@ -61,6 +76,14 @@ struct cros_ec_keyb {
> > struct notifier_block notifier;
> >
> > struct vivaldi_data vdata;
> > +
> > + uint32_t fn_key;
>
> Normally we use u32/u8 these days
Okay, I did notice the file was a bit of a mix, I'll change them in v2.
>
> > + uint32_t *fn_keymap;
> > + int fn_keymap_len;
> > + uint32_t fn_key_status;
> > + uint8_t normal_key_status[CROS_EC_KEYBOARD_COLS_MAX];
> > + bool fn_key_pressed;
> > + bool fn_key_triggered;
> > };
> >
> > /**
> > @@ -166,16 +189,108 @@ static bool cros_ec_keyb_has_ghosting(struct cros_ec_keyb *ckdev, uint8_t *buf)
> > return false;
> > }
> >
> > +static bool cros_ec_key_is(int row, int col, uint32_t key)
> > +{
> > + if (row == KEY_ROW(key) && col == KEY_COL(key))
> > + return true;
> > +
> > + return false;
> > +}
> > +
> > +static void cros_ec_keyb_process_one(struct cros_ec_keyb *ckdev,
> > + int row, int col, bool state)
> > +{
> > + struct input_dev *idev = ckdev->idev;
> > + const unsigned short *keycodes = idev->keycode;
> > + int pos = MATRIX_SCAN_CODE(row, col, ckdev->row_shift);
> > + unsigned int code = keycodes[pos];
> > +
> > + dev_dbg(ckdev->dev, "changed: [r%d c%d]: byte %02x\n", row, col, state);
> > +
> > + if (ckdev->fn_keymap) {
> > + if (cros_ec_key_is(row, col, ckdev->fn_key)) {
> > + ckdev->fn_key_pressed = state;
> > +
> > + if (state) {
> > + ckdev->fn_key_triggered = false;
> > + } else if (!ckdev->fn_key_triggered) {
> > + /*
> > + * Send the original code if nothing else has
> > + * been pressed together with Fn.
> > + */
> > + input_event(idev, EV_MSC, MSC_SCAN, pos);
> > + input_report_key(idev, code, true);
> > + input_sync(ckdev->idev);
>
> What is this function? I might be missing a patch?
input_sync? it sends an EV_SYN, been there from the start, though I
noticed I miss one two lines below, was relying on the rest of the
function to send it but I changed the logic at some point and broke that
path, will fix that.
>
> > +
> > + input_event(idev, EV_MSC, MSC_SCAN, pos);
> > + input_report_key(idev, code, false);
> > + }
> > +
> > + return;
> > + }
> > +
> > + if (!state) {
> > + /* Key release, may need to release the Fn code */
> > + for (int i = 0; i < ckdev->fn_keymap_len; i++) {
> > + if (!cros_ec_key_is(row, col,
> > + ckdev->fn_keymap[i]))
> > + continue;
> > +
> > + if ((ckdev->fn_key_status & BIT(i)) == 0)
> > + continue;
> > +
> > + code = KEY_VAL(ckdev->fn_keymap[i]);
> > + ckdev->fn_key_status &= ~BIT(i);
> > +
> > + input_event(idev, EV_MSC, MSC_SCAN, pos);
> > + input_report_key(idev, code, state);
> > +
> > + return;
> > + }
> > +
> > + if ((ckdev->normal_key_status[col] & BIT(row)) == 0)
> > + /* Discard, key press code was not sent */
> > + return;
> > + } else if (ckdev->fn_key_pressed) {
> > + /* Key press while holding Fn */
> > + ckdev->fn_key_triggered = true;
> > +
> > + for (int i = 0; i < ckdev->fn_keymap_len; i++) {
> > + if (!cros_ec_key_is(row, col,
> > + ckdev->fn_keymap[i]))
> > + continue;
> > +
> > + code = KEY_VAL(ckdev->fn_keymap[i]);
> > + ckdev->fn_key_status |= BIT(i);
> > +
> > + input_event(idev, EV_MSC, MSC_SCAN, pos);
> > + input_report_key(idev, code, state);
> > +
> > + return;
> > + }
> > +
> > + /* Do not emit a code if the key is not mapped */
> > + return;
> > + }
> > + }
>
> I think this function could do with splitting a bit
Yeah, I don't love it either but there's a lot of logic intertwined in
there, tried to split it myself and ended up breaking stuff, the logic
for the fn key itsel though can go that's a good 16 lines, I'll start
with that, send a v2 and then go from there.
> Can the sandbox driver support this too?
Not sure what you are referring to, can you give me a pointer?
Hey thanks for the review, good to hear from you. :-)
Cheers,
Fabio
--
Fabio Baltieri
next prev parent reply other threads:[~2025-12-15 13:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 15:47 [PATCH v1 0/3] Input: cros_ec_keyb: add function key support Fabio Baltieri
2025-12-09 15:47 ` [PATCH v1 1/3] Input: cros_ec_keyb: clarify key event error message Fabio Baltieri
2025-12-11 13:29 ` Simon Glass
2025-12-13 9:40 ` Dmitry Torokhov
2025-12-09 15:47 ` [PATCH v1 2/3] Input: cros_ec_keyb: add function key support Fabio Baltieri
2025-12-11 13:29 ` Simon Glass
2025-12-15 13:09 ` Fabio Baltieri [this message]
2025-12-09 15:47 ` [PATCH v1 3/3] dt-bindings: google,cros-ec-keyb: add fn-key and f-keymap props Fabio Baltieri
2025-12-09 17:24 ` Rob Herring (Arm)
2025-12-09 19:22 ` Rob Herring
2025-12-10 18:00 ` Fabio Baltieri
2025-12-12 4:44 ` Dmitry Torokhov
2025-12-16 12:23 ` Fabio Baltieri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aUAIhNMTPQVl3b4W@google.com \
--to=fabiobaltieri@chromium.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=groeck@chromium.org \
--cc=krzk+dt@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sjg@chromium.org \
--cc=tzungbi@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).