linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v2 0/4] Raspberry Pi Sense HAT driver
@ 2021-08-20 18:07 Charles Mirabile
  2021-08-20 18:07 ` [RFC PATCH vs 2/4] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver Charles Mirabile
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Mirabile @ 2021-08-20 18:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Charles Mirabile, Lee Jones, Dmitry Torokhov, linux-input,
	Miguel Ojeda, Rob Herring, devicetree, Serge Schneider,
	Stefan Wahren, Nicolas Saenz Julienne, linux-rpi-kernel,
	fedora-rpi, Mwesigwa Guma, Joel Savitz

This patch series adds a set of drivers for operating the Sense HAT
peripheral device. This board is an add on for the Raspberry Pi that is
designed to connect using the GPIO connector via I2C.

It features:
	- a joystick
	- an 8x8 RGB LED matrix display
	- a whole bunch of environmental sensors with their own drivers
	(those are already in upstream Linux)

This is a refactor of the work of Serge Schneider, the author of a
version of this driver that is currently in the Raspberry Pi downstream
kernel. We modified his code to make it suitable for upstream Linux.

A couple of tests are available for the driver in this repo:
https://github.com/underground-software/sensehat/tree/master/tests
	- color_test displays various solid colors on the LED panel
	- framebuffer_test diplays a single lit cell that is
	  controllable via the arrow keys or the joystick

Known issue:
	- We are not sure how to integrate the device tree overlay for the
	Sense HAT into mainline Linux, or if we even should at this time.

Fortunately, most Linux distrubtions that can run on the Raspberry Pi
already include an appropriate device tree overlay since they often import
all of the overlays from the downstream Raspberry Pi kernel.

We have included a hypothetical overlay that would work for the sensehat
as a fourth patch in this series but we just put it in the root of the
source tree for the time being so that patch should not be merged unless a
consensus is reached that the overlay should be in the tree, and a proper
location is found to put it.

Suggestions are welcome and appreciated.

For more information about the Sense HAT, visit:
https://www.raspberrypi.org/products/sense-hat/

Changes since v1:
	- We included a device tree overlay for the Sense HAT
	- Based on Feedback from v1 we:
		- Changed the style of a few lines
		- Adding more error logging
		- Changed the compatible strings to use the more common
		"raspberrypi" instead of just "rpi"
		- Renamed everything from rpisense to sensehat

Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
Signed-off-by: Joel Savitz <jsavitz@redhat.com>

Charles Mirabile (4):
  Add core driver and config
  Add joystick driver and config
  Add display driver and config
  Add sensehat device tree overlay

 arch/arm/boot/dts/sensehat.dtbs            |  51 +++++
 drivers/auxdisplay/Kconfig                 |   7 +
 drivers/auxdisplay/Makefile                |   1 +
 drivers/auxdisplay/sensehat-display.c      | 234 +++++++++++++++++++++
 drivers/input/joystick/Kconfig             |   8 +
 drivers/input/joystick/Makefile            |   1 +
 drivers/input/joystick/sensehat-joystick.c | 124 +++++++++++
 drivers/mfd/Kconfig                        |   8 +
 drivers/mfd/Makefile                       |   1 +
 drivers/mfd/sensehat-core.c                | 168 +++++++++++++++
 include/linux/mfd/sensehat.h               |  55 +++++
 11 files changed, 658 insertions(+)
 create mode 100644 arch/arm/boot/dts/sensehat.dtbs
 create mode 100644 drivers/auxdisplay/sensehat-display.c
 create mode 100644 drivers/input/joystick/sensehat-joystick.c
 create mode 100644 drivers/mfd/sensehat-core.c
 create mode 100644 include/linux/mfd/sensehat.h

-- 
2.27.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [RFC PATCH vs 2/4] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver
  2021-08-20 18:07 [RFC PATCH v2 0/4] Raspberry Pi Sense HAT driver Charles Mirabile
@ 2021-08-20 18:07 ` Charles Mirabile
  2021-08-30 13:00   ` nsaenzju
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Mirabile @ 2021-08-20 18:07 UTC (permalink / raw)
  To: linux-kernel
  Cc: Charles Mirabile, Dmitry Torokhov, linux-input, Serge Schneider,
	Stefan Wahren, Nicolas Saenz Julienne, linux-rpi-kernel,
	fedora-rpi, Mwesigwa Guma, Joel Savitz

This patch implements support for the joystick.
It supports left/right/up/down/enter attached via i2c

Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
Signed-off-by: Mwesigwa Guma <mguma@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 | 124 +++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 drivers/input/joystick/sensehat-joystick.c

diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 3b23078bc7b5..d2f78353b74c 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
+	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..4aca125bc29d
--- /dev/null
+++ b/drivers/input/joystick/sensehat-joystick.c
@@ -0,0 +1,124 @@
+// 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>
+#include <linux/interrupt.h>
+#include <linux/gpio/consumer.h>
+#include <linux/platform_device.h>
+
+#include <linux/mfd/sensehat.h>
+
+static unsigned char keymap[] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,};
+
+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));
+		}
+	}
+	input_sync(sensehat_joystick->keys_dev);
+	return IRQ_HANDLED;
+}
+
+static int sensehat_joystick_probe(struct platform_device *pdev)
+{
+	int ret;
+	int i;
+	struct sensehat *sensehat = dev_get_drvdata(&pdev->dev);
+	struct sensehat_joystick *sensehat_joystick = &sensehat->joystick;
+
+	sensehat_joystick->keys_desc = devm_gpiod_get(&sensehat->i2c_client->dev,
+						"keys-int", GPIOD_IN);
+	if (IS_ERR(sensehat_joystick->keys_desc)) {
+		dev_warn(&pdev->dev, "Failed to get keys-int descriptor.\n");
+		return PTR_ERR(sensehat_joystick->keys_desc);
+	}
+
+
+	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 = gpiod_direction_input(sensehat_joystick->keys_desc);
+	if (ret) {
+		dev_err(&pdev->dev, "Could not set keys-int direction.\n");
+		return ret;
+	}
+
+	sensehat_joystick->keys_irq = gpiod_to_irq(sensehat_joystick->keys_desc);
+	if (sensehat_joystick->keys_irq < 0) {
+		dev_err(&pdev->dev, "Could not determine keys-int IRQ.\n");
+		return sensehat_joystick->keys_irq;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, sensehat_joystick->keys_irq,
+		NULL, sensehat_joystick_report, IRQF_TRIGGER_RISING | IRQF_ONESHOT,
+		"keys", sensehat);
+
+	if (ret) {
+		dev_err(&pdev->dev, "IRQ request failed.\n");
+		return ret;
+	}
+	return 0;
+}
+
+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.27.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH vs 2/4] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver
  2021-08-20 18:07 ` [RFC PATCH vs 2/4] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver Charles Mirabile
@ 2021-08-30 13:00   ` nsaenzju
  0 siblings, 0 replies; 3+ messages in thread
From: nsaenzju @ 2021-08-30 13:00 UTC (permalink / raw)
  To: Charles Mirabile, linux-kernel
  Cc: Dmitry Torokhov, linux-input, Serge Schneider, Stefan Wahren,
	linux-rpi-kernel, fedora-rpi, Mwesigwa Guma, Joel Savitz

On Fri, 2021-08-20 at 14:07 -0400, Charles Mirabile wrote:
> This patch implements support for the joystick.
> It supports left/right/up/down/enter attached via i2c
> 
> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
> Signed-off-by: Mwesigwa Guma <mguma@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 | 124 +++++++++++++++++++++
>  3 files changed, 133 insertions(+)
>  create mode 100644 drivers/input/joystick/sensehat-joystick.c
> 
> diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
> index 3b23078bc7b5..d2f78353b74c 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
> +	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..4aca125bc29d
> --- /dev/null
> +++ b/drivers/input/joystick/sensehat-joystick.c
> @@ -0,0 +1,124 @@
> +// 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>
> +#include <linux/interrupt.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/platform_device.h>
> +
> +#include <linux/mfd/sensehat.h>
> +
> +static unsigned char keymap[] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,};

I'm not sure devices outputing KEY_* events fits input/joystick. Maybe
input/misc or input/keyboard? Or else use 'BTN_DPAD_UP/DOWN/LEFT/RIGHT'. Which
is what game controllers seem to do.

Regards,
Nicolas



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-08-30 13:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-20 18:07 [RFC PATCH v2 0/4] Raspberry Pi Sense HAT driver Charles Mirabile
2021-08-20 18:07 ` [RFC PATCH vs 2/4] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver Charles Mirabile
2021-08-30 13:00   ` nsaenzju

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).