From: "Thomas Weißschuh" <thomas@t-8ch.de>
To: Anshul Dalal <anshulusr@gmail.com>
Cc: linux-input@vger.kernel.org, devicetree@vger.kernel.org,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Jeff LaBundy <jeff@labundy.com>,
Shuah Khan <skhan@linuxfoundation.org>,
linux-kernel-mentees@lists.linuxfoundation.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/2] input: joystick: driver for Adafruit Seesaw Gamepad
Date: Wed, 1 Nov 2023 09:45:14 +0100 [thread overview]
Message-ID: <2241e06f-ef90-4299-97cd-cfb8fd569065@t-8ch.de> (raw)
In-Reply-To: <152d15c4-10bb-45fe-9b9c-b323535a921f@gmail.com>
Hi Anshul,
On 2023-11-01 09:50:36+0530, Anshul Dalal wrote:
> On 10/31/23 07:53, Thomas Weißschuh wrote:
> > Oct 31, 2023 03:10:50 Anshul Dalal <anshulusr@gmail.com>:
> >> Thanks for the review! The requested changes will be addressed in the
> >> next patch version though I had a few comments below:
> >>
> >> On 10/27/23 11:44, Thomas Weißschuh wrote:
> >>> Hi Anshul,
> >>>
> >>> thanks for the reworks!
> >>>
> >>> Some more comments inline.
> >>>
> >>> On 2023-10-27 10:48:11+0530, Anshul Dalal wrote:
> >
> > [..]
> >
> >>>> +struct seesaw_button_description {
> >>>> + unsigned int code;
> >>>> + unsigned int bit;
> >>>> +};
> >>>> +
> >>>> +static const struct seesaw_button_description seesaw_buttons[] = {
> >>>> + {
> >>>> + .code = BTN_EAST,
> >>>> + .bit = SEESAW_BUTTON_A,
> >>>> + },
> >>>> + {
> >>>> + .code = BTN_SOUTH,
> >>>> + .bit = SEESAW_BUTTON_B,
> >>>> + },
> >>>> + {
> >>>> + .code = BTN_NORTH,
> >>>> + .bit = SEESAW_BUTTON_X,
> >>>> + },
> >>>> + {
> >>>> + .code = BTN_WEST,
> >>>> + .bit = SEESAW_BUTTON_Y,
> >>>> + },
> >>>> + {
> >>>> + .code = BTN_START,
> >>>> + .bit = SEESAW_BUTTON_START,
> >>>> + },
> >>>> + {
> >>>> + .code = BTN_SELECT,
> >>>> + .bit = SEESAW_BUTTON_SELECT,
> >>>> + },
> >>>> +};
> >>>
> >>> This looks very much like a sparse keymap which can be implemented with
> >>> the helpers from <linux/input/sparse-keymap.h>.
> >>>
> >>
> >> When going through the API provided by sparse-keymap, I could only see
> >> the use for sparse_keymap_report_entry here. Which leads to the
> >> following refactored code:
> >>
> >> static const struct key_entry seesaw_buttons_new[] = {
> >> {KE_KEY, SEESAW_BUTTON_A, {BTN_SOUTH}},
> >> {KE_KEY, SEESAW_BUTTON_B, {BTN_EAST}},
> >
> > No braces I think.
> >
>
> Since the last field in key_entry is a union, the braces seem to be
> required.
Indeed.
To make the union more visible explicit this could be done:
{ KE_KEY, SEESAW_BUTTON_A, .keycode = BTN_SOUTH }
>
> >> ...
> >> };
> >>
> >> for (i = 0; i < ARRAY_SIZE(seesaw_buttons_new); i++) {
> >> sparse_keymap_report_entry(input, &seesaw_buttons_new[i],
> >> data.button_state & BIT(seesaw_buttons_new[i].code),
> >> false);
> >> }
> >>
> >> I don't think this significantly improves the code unless you had some
> >> other way to use the API in mind.
> >
> > I thought about sparse_keymap_setup() and sparse_keymap_report_event().
> >
> > It does not significantly change the code but would be a standard API.
> >
>
> Thanks for pointing me in the right direction, do you think the
> following implementation of the API is acceptable for the driver. Since
> I couldn't find a driver for any similar device using the API in this
> manner.
>
> inside seesaw_probe():
>
> err = sparse_keymap_setup(seesaw->input_dev, seesaw_buttons_new, NULL);
> if (err) {
> dev_err(&client->dev,
> "failed to set up input device keymap: %d\n", err);
> return err;
> }
Yes, and it replaces the calls to input_set_capability().
> inside seesaw_poll():
>
> for (i = 0; i < ARRAY_SIZE(seesaw_buttons_new); i++) {
> if (!sparse_keymap_report_event(
> input, seesaw_buttons_new[i].code,
> data.button_state & BIT(seesaw_buttons_new[i].code),
> false)) {
> dev_err_ratelimited(
> &input->dev,
> "failed to report event for keycode: %d",
> seesaw_buttons_new[i].keycode);
> return;
> }
> }
for_each_set_bit(i, (long *)&SEESAW_BUTTON_MASK, BITS_PER_TYPE(SEESAW_BUTTON_MASK))
sparse_keymap_report_event(input, BIT(i), data.button_state & BIT(i), false);
The sparse keymap takes care of the translation.
Notes:
SEESAW_BUTTON_MASK is now an actual variable instead of a macro.
It should be 'static const' in that case.
When using the sparse keymap APIs the driver also needs to depend on
INPUT_SPARSEKMAP.
Thomas
next prev parent reply other threads:[~2023-11-01 8:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-27 5:18 [PATCH v6 1/2] dt-bindings: input: bindings " Anshul Dalal
2023-10-27 5:18 ` [PATCH v6 2/2] input: joystick: driver " Anshul Dalal
2023-10-27 6:14 ` Thomas Weißschuh
2023-10-31 2:09 ` Anshul Dalal
2023-10-31 2:23 ` Thomas Weißschuh
2023-11-01 4:20 ` Anshul Dalal
2023-11-01 8:45 ` Thomas Weißschuh [this message]
2023-11-25 22:39 ` Jeff LaBundy
2023-10-30 6:56 ` Dmitry Torokhov
2023-10-31 2:05 ` Anshul Dalal
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=2241e06f-ef90-4299-97cd-cfb8fd569065@t-8ch.de \
--to=thomas@t-8ch.de \
--cc=anshulusr@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=jeff@labundy.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--cc=skhan@linuxfoundation.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
all inboxes | Powered by JetHome®