From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Charles Mirabile <cmirabil@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
Serge Schneider <serge@raspberrypi.org>,
Stefan Wahren <stefan.wahren@i2se.com>,
Nicolas Saenz Julienne <nsaenzju@redhat.com>,
Mattias Brugger <mbrugger@suse.com>,
linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
fedora-rpi@googlegroups.com, Mwesigwa Guma <mguma@redhat.com>,
Joel Savitz <jsavitz@redhat.com>
Subject: Re: [PATCH V5 2/6] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver
Date: Fri, 10 Dec 2021 15:17:29 -0800 [thread overview]
Message-ID: <YbPgCdkVpEJw5XQM@google.com> (raw)
In-Reply-To: <20211210221033.912430-3-cmirabil@redhat.com>
Hi Charles,
On Fri, Dec 10, 2021 at 05:10:29PM -0500, Charles Mirabile wrote:
> This patch implements support for the joystick.
> It supports left/right/up/down/enter and is
> attached via i2c and a gpio pin for irq.
This is not really a joystick, at least not in current incarnation, but
rather a set of keys. I'd also question whether the selected set is
right for the application, I'd look into BTN_DPAD_* maybe?
Or, if you want it to be a joystick, map ABS_X/ABS_Y.
>
> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
> Co-developed-by: Mwesigwa Guma <mguma@redhat.com>
> Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
> Co-developed-by: Joel Savitz <jsavitz@redhat.com>
> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
> ---
> drivers/input/joystick/Kconfig | 8 ++
> drivers/input/joystick/Makefile | 1 +
> drivers/input/joystick/sensehat-joystick.c | 119 +++++++++++++++++++++
> 3 files changed, 128 insertions(+)
> create mode 100644 drivers/input/joystick/sensehat-joystick.c
>
> diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
> index 3b23078bc7b5..d5c5ffe13903 100644
> --- a/drivers/input/joystick/Kconfig
> +++ b/drivers/input/joystick/Kconfig
> @@ -399,4 +399,12 @@ config JOYSTICK_N64
> Say Y here if you want enable support for the four
> built-in controller ports on the Nintendo 64 console.
>
> +config JOYSTICK_SENSEHAT
> + tristate "Raspberry Pi Sense HAT joystick"
> + depends on GPIOLIB && INPUT && I2C
I do not see I2C accessed directly in this driver, nor GPIO interface.
You also do not need to depend on INPUT explicitly here.
> + select MFD_SENSEHAT_CORE
> +
> + help
> + This is the joystick driver for the Raspberry Pi Sense HAT
> +
> endif
> diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
> index 5174b8aba2dd..39c8b5c6e5ae 100644
> --- a/drivers/input/joystick/Makefile
> +++ b/drivers/input/joystick/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_JOYSTICK_N64) += n64joy.o
> obj-$(CONFIG_JOYSTICK_PSXPAD_SPI) += psxpad-spi.o
> obj-$(CONFIG_JOYSTICK_PXRC) += pxrc.o
> obj-$(CONFIG_JOYSTICK_QWIIC) += qwiic-joystick.o
> +obj-$(CONFIG_JOYSTICK_SENSEHAT) += sensehat-joystick.o
> obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o
> obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o
> obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o
> diff --git a/drivers/input/joystick/sensehat-joystick.c b/drivers/input/joystick/sensehat-joystick.c
> new file mode 100644
> index 000000000000..1f6bb09b4d1f
> --- /dev/null
> +++ b/drivers/input/joystick/sensehat-joystick.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Raspberry Pi Sense HAT joystick driver
> + * http://raspberrypi.org
> + *
> + * Copyright (C) 2015 Raspberry Pi
> + * Copyright (C) 2021 Charles Mirabile, Mwesigwa Guma, Joel Savitz
> + *
> + * Original Author: Serge Schneider
> + * Revised for upstream Linux by: Charles Mirabile, Mwesigwa Guma, Joel Savitz
> + */
> +
> +#include <linux/module.h>
> +#include <linux/input.h>
> +#include <linux/i2c.h>
Don't think you need this.
> +#include <linux/interrupt.h>
> +#include <linux/gpio/consumer.h>
Not needed.
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/mfd/sensehat.h>
> +
> +#define SENSEHAT_KEYS 0xF2
> +
> +static int sensehat_get_joystick_state(struct sensehat *sensehat);
> +
> +static unsigned char keymap[] = {
> + KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,
> +};
Because you allowing manipulating keymap from userspace you need to make
a copy of it when setting up input device so that changes do would not
persist across bind/unbind.
This array needs to be marked const.
> +
> +static irqreturn_t sensehat_joystick_report(int n, void *cookie)
> +{
> + int i;
> + static s32 prev_keys;
> + struct sensehat *sensehat = cookie;
> + struct sensehat_joystick *sensehat_joystick = &sensehat->joystick;
> + s32 keys = sensehat_get_joystick_state(sensehat);
> + s32 changes = keys ^ prev_keys;
> +
> + prev_keys = keys;
> + for (i = 0; i < ARRAY_SIZE(keymap); ++i) {
> + if (changes & (1 << i)) {
> + input_report_key(sensehat_joystick->keys_dev, keymap[i],
> + keys & (1 << i));
> + }
> + }
If you go with keys/buttons approach, then use
bitmap_xor()/for_each_set_bit() - see
drivers/input/keyboard/cypress-sf.c::cypress_sf_irq_handler() for
example of use.
> + input_sync(sensehat_joystick->keys_dev);
> + return IRQ_HANDLED;
> +}
> +
> +static int sensehat_joystick_probe(struct platform_device *pdev)
> +{
> + int ret;
Please call it "error";
> + int i;
> + struct sensehat *sensehat = dev_get_drvdata(&pdev->dev);
> + struct sensehat_joystick *sensehat_joystick = &sensehat->joystick;
This structure (struct sensehat_joystick) should probably be private to
this driver.
> +
> + sensehat_joystick->keys_dev = devm_input_allocate_device(&pdev->dev);
> + if (!sensehat_joystick->keys_dev) {
> + dev_err(&pdev->dev, "Could not allocate input device.\n");
> + return -ENOMEM;
> + }
> +
> + for (i = 0; i < ARRAY_SIZE(keymap); i++) {
> + set_bit(keymap[i], sensehat_joystick->keys_dev->keybit);
> + }
> +
> + sensehat_joystick->keys_dev->name = "Raspberry Pi Sense HAT Joystick";
> + sensehat_joystick->keys_dev->phys = "rpi-sense-joy/input0";
> + sensehat_joystick->keys_dev->id.bustype = BUS_I2C;
> + sensehat_joystick->keys_dev->evbit[0] =
> + BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
> + sensehat_joystick->keys_dev->keycode = keymap;
> + sensehat_joystick->keys_dev->keycodesize = sizeof(unsigned char);
> + sensehat_joystick->keys_dev->keycodemax = ARRAY_SIZE(keymap);
> +
> + ret = input_register_device(sensehat_joystick->keys_dev);
> + if (ret) {
> + dev_err(&pdev->dev, "Could not register input device.\n");
> + return ret;
> + }
> +
> + ret = devm_request_threaded_irq(&pdev->dev, sensehat->i2c_client->irq,
> + NULL, sensehat_joystick_report,
> + IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Do not specify trigger type, whoever set up client's interrupt should
have set up appropriate trigger.
> + "keys", sensehat);
> +
> + if (ret) {
> + dev_err(&pdev->dev, "IRQ request failed.\n");
> + return ret;
> + }
> + return 0;
> +}
> +
> +int sensehat_get_joystick_state(struct sensehat *sensehat)
> +{
> + unsigned int reg;
> + int ret = regmap_read(sensehat->regmap, SENSEHAT_KEYS, ®);
> +
> + return ret < 0 ? ret : reg;
I do not see the point in having this wrapper.
> +}
> +
> +static struct platform_device_id sensehat_joystick_device_id[] = {
> + { .name = "sensehat-joystick" },
> + {},
> +};
> +MODULE_DEVICE_TABLE(platform, sensehat_joystick_device_id);
> +
> +static struct platform_driver sensehat_joystick_driver = {
> + .probe = sensehat_joystick_probe,
> + .driver = {
> + .name = "sensehat-joystick",
> + },
> +};
> +
> +module_platform_driver(sensehat_joystick_driver);
> +
> +MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver");
> +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
> +MODULE_LICENSE("GPL");
> --
> 2.31.1
>
Thanks.
--
Dmitry
WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Charles Mirabile <cmirabil@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
Serge Schneider <serge@raspberrypi.org>,
Stefan Wahren <stefan.wahren@i2se.com>,
Nicolas Saenz Julienne <nsaenzju@redhat.com>,
Mattias Brugger <mbrugger@suse.com>,
linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
fedora-rpi@googlegroups.com, Mwesigwa Guma <mguma@redhat.com>,
Joel Savitz <jsavitz@redhat.com>
Subject: Re: [PATCH V5 2/6] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver
Date: Fri, 10 Dec 2021 15:17:29 -0800 [thread overview]
Message-ID: <YbPgCdkVpEJw5XQM@google.com> (raw)
In-Reply-To: <20211210221033.912430-3-cmirabil@redhat.com>
Hi Charles,
On Fri, Dec 10, 2021 at 05:10:29PM -0500, Charles Mirabile wrote:
> This patch implements support for the joystick.
> It supports left/right/up/down/enter and is
> attached via i2c and a gpio pin for irq.
This is not really a joystick, at least not in current incarnation, but
rather a set of keys. I'd also question whether the selected set is
right for the application, I'd look into BTN_DPAD_* maybe?
Or, if you want it to be a joystick, map ABS_X/ABS_Y.
>
> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
> Co-developed-by: Mwesigwa Guma <mguma@redhat.com>
> Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
> Co-developed-by: Joel Savitz <jsavitz@redhat.com>
> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
> ---
> drivers/input/joystick/Kconfig | 8 ++
> drivers/input/joystick/Makefile | 1 +
> drivers/input/joystick/sensehat-joystick.c | 119 +++++++++++++++++++++
> 3 files changed, 128 insertions(+)
> create mode 100644 drivers/input/joystick/sensehat-joystick.c
>
> diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
> index 3b23078bc7b5..d5c5ffe13903 100644
> --- a/drivers/input/joystick/Kconfig
> +++ b/drivers/input/joystick/Kconfig
> @@ -399,4 +399,12 @@ config JOYSTICK_N64
> Say Y here if you want enable support for the four
> built-in controller ports on the Nintendo 64 console.
>
> +config JOYSTICK_SENSEHAT
> + tristate "Raspberry Pi Sense HAT joystick"
> + depends on GPIOLIB && INPUT && I2C
I do not see I2C accessed directly in this driver, nor GPIO interface.
You also do not need to depend on INPUT explicitly here.
> + select MFD_SENSEHAT_CORE
> +
> + help
> + This is the joystick driver for the Raspberry Pi Sense HAT
> +
> endif
> diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
> index 5174b8aba2dd..39c8b5c6e5ae 100644
> --- a/drivers/input/joystick/Makefile
> +++ b/drivers/input/joystick/Makefile
> @@ -28,6 +28,7 @@ obj-$(CONFIG_JOYSTICK_N64) += n64joy.o
> obj-$(CONFIG_JOYSTICK_PSXPAD_SPI) += psxpad-spi.o
> obj-$(CONFIG_JOYSTICK_PXRC) += pxrc.o
> obj-$(CONFIG_JOYSTICK_QWIIC) += qwiic-joystick.o
> +obj-$(CONFIG_JOYSTICK_SENSEHAT) += sensehat-joystick.o
> obj-$(CONFIG_JOYSTICK_SIDEWINDER) += sidewinder.o
> obj-$(CONFIG_JOYSTICK_SPACEBALL) += spaceball.o
> obj-$(CONFIG_JOYSTICK_SPACEORB) += spaceorb.o
> diff --git a/drivers/input/joystick/sensehat-joystick.c b/drivers/input/joystick/sensehat-joystick.c
> new file mode 100644
> index 000000000000..1f6bb09b4d1f
> --- /dev/null
> +++ b/drivers/input/joystick/sensehat-joystick.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Raspberry Pi Sense HAT joystick driver
> + * http://raspberrypi.org
> + *
> + * Copyright (C) 2015 Raspberry Pi
> + * Copyright (C) 2021 Charles Mirabile, Mwesigwa Guma, Joel Savitz
> + *
> + * Original Author: Serge Schneider
> + * Revised for upstream Linux by: Charles Mirabile, Mwesigwa Guma, Joel Savitz
> + */
> +
> +#include <linux/module.h>
> +#include <linux/input.h>
> +#include <linux/i2c.h>
Don't think you need this.
> +#include <linux/interrupt.h>
> +#include <linux/gpio/consumer.h>
Not needed.
> +#include <linux/platform_device.h>
> +#include <linux/regmap.h>
> +#include <linux/mfd/sensehat.h>
> +
> +#define SENSEHAT_KEYS 0xF2
> +
> +static int sensehat_get_joystick_state(struct sensehat *sensehat);
> +
> +static unsigned char keymap[] = {
> + KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,
> +};
Because you allowing manipulating keymap from userspace you need to make
a copy of it when setting up input device so that changes do would not
persist across bind/unbind.
This array needs to be marked const.
> +
> +static irqreturn_t sensehat_joystick_report(int n, void *cookie)
> +{
> + int i;
> + static s32 prev_keys;
> + struct sensehat *sensehat = cookie;
> + struct sensehat_joystick *sensehat_joystick = &sensehat->joystick;
> + s32 keys = sensehat_get_joystick_state(sensehat);
> + s32 changes = keys ^ prev_keys;
> +
> + prev_keys = keys;
> + for (i = 0; i < ARRAY_SIZE(keymap); ++i) {
> + if (changes & (1 << i)) {
> + input_report_key(sensehat_joystick->keys_dev, keymap[i],
> + keys & (1 << i));
> + }
> + }
If you go with keys/buttons approach, then use
bitmap_xor()/for_each_set_bit() - see
drivers/input/keyboard/cypress-sf.c::cypress_sf_irq_handler() for
example of use.
> + input_sync(sensehat_joystick->keys_dev);
> + return IRQ_HANDLED;
> +}
> +
> +static int sensehat_joystick_probe(struct platform_device *pdev)
> +{
> + int ret;
Please call it "error";
> + int i;
> + struct sensehat *sensehat = dev_get_drvdata(&pdev->dev);
> + struct sensehat_joystick *sensehat_joystick = &sensehat->joystick;
This structure (struct sensehat_joystick) should probably be private to
this driver.
> +
> + sensehat_joystick->keys_dev = devm_input_allocate_device(&pdev->dev);
> + if (!sensehat_joystick->keys_dev) {
> + dev_err(&pdev->dev, "Could not allocate input device.\n");
> + return -ENOMEM;
> + }
> +
> + for (i = 0; i < ARRAY_SIZE(keymap); i++) {
> + set_bit(keymap[i], sensehat_joystick->keys_dev->keybit);
> + }
> +
> + sensehat_joystick->keys_dev->name = "Raspberry Pi Sense HAT Joystick";
> + sensehat_joystick->keys_dev->phys = "rpi-sense-joy/input0";
> + sensehat_joystick->keys_dev->id.bustype = BUS_I2C;
> + sensehat_joystick->keys_dev->evbit[0] =
> + BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
> + sensehat_joystick->keys_dev->keycode = keymap;
> + sensehat_joystick->keys_dev->keycodesize = sizeof(unsigned char);
> + sensehat_joystick->keys_dev->keycodemax = ARRAY_SIZE(keymap);
> +
> + ret = input_register_device(sensehat_joystick->keys_dev);
> + if (ret) {
> + dev_err(&pdev->dev, "Could not register input device.\n");
> + return ret;
> + }
> +
> + ret = devm_request_threaded_irq(&pdev->dev, sensehat->i2c_client->irq,
> + NULL, sensehat_joystick_report,
> + IRQF_TRIGGER_RISING | IRQF_ONESHOT,
Do not specify trigger type, whoever set up client's interrupt should
have set up appropriate trigger.
> + "keys", sensehat);
> +
> + if (ret) {
> + dev_err(&pdev->dev, "IRQ request failed.\n");
> + return ret;
> + }
> + return 0;
> +}
> +
> +int sensehat_get_joystick_state(struct sensehat *sensehat)
> +{
> + unsigned int reg;
> + int ret = regmap_read(sensehat->regmap, SENSEHAT_KEYS, ®);
> +
> + return ret < 0 ? ret : reg;
I do not see the point in having this wrapper.
> +}
> +
> +static struct platform_device_id sensehat_joystick_device_id[] = {
> + { .name = "sensehat-joystick" },
> + {},
> +};
> +MODULE_DEVICE_TABLE(platform, sensehat_joystick_device_id);
> +
> +static struct platform_driver sensehat_joystick_driver = {
> + .probe = sensehat_joystick_probe,
> + .driver = {
> + .name = "sensehat-joystick",
> + },
> +};
> +
> +module_platform_driver(sensehat_joystick_driver);
> +
> +MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver");
> +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
> +MODULE_LICENSE("GPL");
> --
> 2.31.1
>
Thanks.
--
Dmitry
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2021-12-10 23:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-10 22:10 [PATCH V5 0/6] Raspberry Pi Sense HAT driver Charles Mirabile
2021-12-10 22:10 ` Charles Mirabile
2021-12-10 22:10 ` [PATCH V5 1/6] drivers/mfd: sensehat: Raspberry Pi Sense HAT core driver Charles Mirabile
2021-12-10 22:10 ` Charles Mirabile
2021-12-11 20:53 ` Thomas Weißschuh
2021-12-11 20:53 ` Thomas Weißschuh
2021-12-12 11:43 ` Stefan Wahren
2021-12-12 11:43 ` Stefan Wahren
2021-12-13 11:49 ` Nicolas Saenz Julienne
2021-12-13 11:49 ` Nicolas Saenz Julienne
2021-12-10 22:10 ` [PATCH V5 2/6] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver Charles Mirabile
2021-12-10 22:10 ` Charles Mirabile
2021-12-10 23:17 ` Dmitry Torokhov [this message]
2021-12-10 23:17 ` Dmitry Torokhov
2021-12-10 22:10 ` [PATCH V5 3/6] drivers/auxdisplay: sensehat: Raspberry Pi Sense HAT display driver Charles Mirabile
2021-12-10 22:10 ` Charles Mirabile
2021-12-11 18:38 ` Miguel Ojeda
2021-12-11 18:38 ` Miguel Ojeda
2021-12-10 22:10 ` [PATCH V5 4/6] dt-bindings: mfd: sensehat: Add Raspberry Pi Sense HAT schema Charles Mirabile
2021-12-10 22:10 ` Charles Mirabile
2021-12-11 19:59 ` Rob Herring
2021-12-11 19:59 ` Rob Herring
2021-12-13 17:09 ` Rob Herring
2021-12-13 17:09 ` Rob Herring
2021-12-10 22:10 ` [PATCH V5 5/6] MAINTAINERS: Add sensehat driver authors to MAINTAINERS Charles Mirabile
2021-12-10 22:10 ` Charles Mirabile
2021-12-10 22:10 ` [PATCH V5 6/6] DO NOT MERGE: full sensehat device tree overlay for raspberry pi 4 Charles Mirabile
2021-12-10 22:10 ` Charles Mirabile
2021-12-13 11:29 ` [PATCH V5 0/6] Raspberry Pi Sense HAT driver Nicolas Saenz Julienne
2021-12-13 11:29 ` Nicolas Saenz Julienne
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=YbPgCdkVpEJw5XQM@google.com \
--to=dmitry.torokhov@gmail.com \
--cc=cmirabil@redhat.com \
--cc=fedora-rpi@googlegroups.com \
--cc=jsavitz@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=mbrugger@suse.com \
--cc=mguma@redhat.com \
--cc=nsaenzju@redhat.com \
--cc=serge@raspberrypi.org \
--cc=stefan.wahren@i2se.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.