* [RFC PATCH v2 1/4] drivers/mfd: sensehat: Raspberry Pi Sense HAT core 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 12:48 ` nsaenzju
2021-08-20 18:07 ` [RFC PATCH vs 2/4] drivers/input/joystick: sensehat: Raspberry Pi Sense HAT joystick driver Charles Mirabile
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Charles Mirabile @ 2021-08-20 18:07 UTC (permalink / raw)
To: linux-kernel
Cc: Charles Mirabile, Lee Jones, Serge Schneider, Stefan Wahren,
Nicolas Saenz Julienne, linux-rpi-kernel, fedora-rpi,
Mwesigwa Guma, Joel Savitz
This patch adds the core driver file, containing methods to communicate
with the board over I2C. We also add the header file shared by all
three drivers, containing common data and definitions. In addition, we
add a config option to toggle compilation of the driver.
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/mfd/Kconfig | 8 ++
drivers/mfd/Makefile | 1 +
drivers/mfd/sensehat-core.c | 168 +++++++++++++++++++++++++++++++++++
include/linux/mfd/sensehat.h | 55 ++++++++++++
4 files changed, 232 insertions(+)
create mode 100644 drivers/mfd/sensehat-core.c
create mode 100644 include/linux/mfd/sensehat.h
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 6a3fd2d75f96..569972f0738f 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -11,6 +11,14 @@ config MFD_CORE
select IRQ_DOMAIN
default n
+config MFD_SENSEHAT_CORE
+ tristate "Raspberry Pi Sense HAT core functions"
+ depends on I2C
+ select MFD_CORE
+ help
+ This is the core driver for the Raspberry Pi Sense HAT. This provides
+ the necessary functions to communicate with the hardware.
+
config MFD_CS5535
tristate "AMD CS5535 and CS5536 southbridge core functions"
select MFD_CORE
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 8116c19d5fd4..d23262dc6a27 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -263,6 +263,7 @@ obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o
obj-$(CONFIG_MFD_ROHM_BD957XMUF) += rohm-bd9576.o
obj-$(CONFIG_MFD_STMFX) += stmfx.o
obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o
+obj-$(CONFIG_MFD_SENSEHAT_CORE) += sensehat-core.o
obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o
obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
diff --git a/drivers/mfd/sensehat-core.c b/drivers/mfd/sensehat-core.c
new file mode 100644
index 000000000000..295b0abe2375
--- /dev/null
+++ b/drivers/mfd/sensehat-core.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Raspberry Pi Sense HAT core 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
+ *
+ * This driver is based on wm8350 implementation and was refactored to use the
+ * misc device subsystem rather than the deprecated framebuffer subsystem.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+
+#include <linux/mfd/sensehat.h>
+
+#define RPISENSE_DISPLAY 0x00
+#define RPISENSE_WAI 0xF0
+#define RPISENSE_VER 0xF1
+#define RPISENSE_KEYS 0xF2
+#define RPISENSE_EE_WP 0xF3
+
+#define RPISENSE_ID 's'
+
+static struct platform_device *
+sensehat_client_dev_register(struct sensehat *sensehat, const char *name);
+
+static int sensehat_probe(struct i2c_client *i2c,
+ const struct i2c_device_id *id)
+{
+ int ret;
+
+ struct sensehat *sensehat = devm_kzalloc(&i2c->dev, sizeof(*sensehat), GFP_KERNEL);
+
+ if (!sensehat)
+ return -ENOMEM;
+
+ i2c_set_clientdata(i2c, sensehat);
+ sensehat->dev = &i2c->dev;
+ sensehat->i2c_client = i2c;
+
+
+ ret = i2c_smbus_read_byte_data(sensehat->i2c_client, RPISENSE_WAI);
+ if (ret < 0) {
+ dev_err(sensehat->dev, "failed to read from device");
+ return ret;
+ }
+
+ if (ret != RPISENSE_ID) {
+ dev_err(sensehat->dev, "expected device ID %i, got %i",
+ RPISENSE_ID, ret);
+ return -EINVAL;
+ }
+
+ ret = i2c_smbus_read_byte_data(sensehat->i2c_client, RPISENSE_VER);
+ if (ret < 0)
+ return ret;
+
+ dev_info(sensehat->dev,
+ "Raspberry Pi Sense HAT firmware version %i\n", ret);
+
+ sensehat->joystick.pdev = sensehat_client_dev_register(sensehat,
+ "sensehat-joystick");
+
+ if (IS_ERR(sensehat->joystick.pdev)) {
+ dev_err(sensehat->dev, "failed to register sensehat-joystick");
+ return PTR_ERR(sensehat->joystick.pdev);
+ }
+
+ sensehat->display.pdev = sensehat_client_dev_register(sensehat,
+ "sensehat-display");
+
+ if (IS_ERR(sensehat->display.pdev)) {
+ dev_err(sensehat->dev, "failed to register sensehat-display");
+ return PTR_ERR(sensehat->display.pdev);
+ }
+
+ return 0;
+}
+
+static struct platform_device *
+sensehat_client_dev_register(struct sensehat *sensehat, const char *name)
+{
+ long ret = -ENOMEM;
+ struct platform_device *pdev = platform_device_alloc(name, -1);
+
+ if (!pdev)
+ goto alloc_fail;
+
+ pdev->dev.parent = sensehat->dev;
+ platform_set_drvdata(pdev, sensehat);
+
+ ret = platform_device_add(pdev);
+ if (ret)
+ goto add_fail;
+
+ ret = devm_add_action_or_reset(sensehat->dev,
+ (void *)platform_device_unregister, pdev);
+ if (ret)
+ goto alloc_fail;
+
+ return pdev;
+
+add_fail:
+ platform_device_put(pdev);
+alloc_fail:
+ return ERR_PTR(ret);
+}
+
+int sensehat_get_joystick_state(struct sensehat *sensehat)
+{
+ int ret = i2c_smbus_read_byte_data(sensehat->i2c_client, RPISENSE_KEYS);
+
+ return ret < 0 ? ret : ret & 0x1f;
+}
+EXPORT_SYMBOL_GPL(sensehat_get_joystick_state);
+
+int sensehat_update_display(struct sensehat *sensehat)
+{
+ int i, j, ret;
+ struct sensehat_display *display = &sensehat->display;
+ struct {u8 reg, pixel_data[8][3][8]; } msg;
+
+ msg.reg = RPISENSE_DISPLAY;
+ for (i = 0; i < 8; ++i) {
+ for (j = 0; j < 8; ++j) {
+ msg.pixel_data[i][0][j] = display->gamma[display->vmem[i][j].r];
+ msg.pixel_data[i][1][j] = display->gamma[display->vmem[i][j].g];
+ msg.pixel_data[i][2][j] = display->gamma[display->vmem[i][j].b];
+ }
+ }
+
+ ret = i2c_master_send(sensehat->i2c_client, (u8 *)&msg, sizeof(msg));
+ if (ret < 0)
+ dev_err(sensehat->dev, "Update to 8x8 LED matrix display failed");
+ return ret;
+}
+EXPORT_SYMBOL_GPL(sensehat_update_display);
+
+static const struct i2c_device_id sensehat_i2c_id[] = {
+ { "sensehat", 0 },
+ { "rpi-sense", 0 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, sensehat_i2c_id);
+
+static struct i2c_driver sensehat_driver = {
+ .driver = {
+ .name = "sensehat",
+ },
+ .probe = sensehat_probe,
+ .id_table = sensehat_i2c_id,
+};
+
+module_i2c_driver(sensehat_driver);
+
+MODULE_DESCRIPTION("Raspberry Pi Sense HAT core driver");
+MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/sensehat.h b/include/linux/mfd/sensehat.h
new file mode 100644
index 000000000000..2701c3ff25bc
--- /dev/null
+++ b/include/linux/mfd/sensehat.h
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Raspberry Pi Sense HAT core 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
+ */
+
+#ifndef __LINUX_MFD_RPISENSE_H_
+#define __LINUX_MFD_RPISENSE_H_
+#include <linux/miscdevice.h>
+
+#define SENSEDISP_IOC_MAGIC 0xF1
+
+#define SENSEDISP_IOGET_GAMMA _IO(SENSEDISP_IOC_MAGIC, 0)
+#define SENSEDISP_IOSET_GAMMA _IO(SENSEDISP_IOC_MAGIC, 1)
+#define SENSEDISP_IORESET_GAMMA _IO(SENSEDISP_IOC_MAGIC, 2)
+
+struct sensehat {
+ struct device *dev;
+ struct i2c_client *i2c_client;
+
+ /* Client devices */
+ struct sensehat_joystick {
+ struct platform_device *pdev;
+ struct input_dev *keys_dev;
+ struct gpio_desc *keys_desc;
+ int keys_irq;
+ } joystick;
+
+ struct sensehat_display {
+ struct platform_device *pdev;
+ struct miscdevice mdev;
+ struct mutex rw_mtx;
+ u8 gamma[32];
+ struct {
+ u16 b:5, u:1, g:5, r:5;
+ } vmem[8][8];
+ } display;
+};
+
+enum gamma_preset {
+ GAMMA_DEFAULT = 0,
+ GAMMA_LOWLIGHT,
+ GAMMA_PRESET_COUNT,
+};
+
+int sensehat_get_joystick_state(struct sensehat *sensehat);
+int sensehat_update_display(struct sensehat *sensehat);
+
+#endif
--
2.27.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [RFC PATCH v2 1/4] drivers/mfd: sensehat: Raspberry Pi Sense HAT core driver
2021-08-20 18:07 ` [RFC PATCH v2 1/4] drivers/mfd: sensehat: Raspberry Pi Sense HAT core driver Charles Mirabile
@ 2021-08-30 12:48 ` nsaenzju
0 siblings, 0 replies; 11+ messages in thread
From: nsaenzju @ 2021-08-30 12:48 UTC (permalink / raw)
To: Charles Mirabile, linux-kernel
Cc: Lee Jones, 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 adds the core driver file, containing methods to communicate
> with the board over I2C. We also add the header file shared by all
> three drivers, containing common data and definitions. In addition, we
> add a config option to toggle compilation of the driver.
>
> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
> Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
> ---
Correct me if I'm wrong, but it seems to me that you could completely avoid
this driver if you used 'simple-mfd-i2c.c'. See 'kontron,sl28cpld' for an
example of how it's used.
Regards,
Nicolas
^ permalink raw reply [flat|nested] 11+ 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 ` [RFC PATCH v2 1/4] drivers/mfd: sensehat: Raspberry Pi Sense HAT core driver Charles Mirabile
@ 2021-08-20 18:07 ` Charles Mirabile
2021-08-30 13:00 ` nsaenzju
2021-08-20 18:08 ` [RFC PATCH v2 3/4] drivers/auxdisplay: senshat Raspberry Pi Sense HAT display driver Charles Mirabile
2021-08-20 18:08 ` [RFC PATCH v2 4/4] sensehat: Add device tree overlay (do not merge) Charles Mirabile
3 siblings, 1 reply; 11+ 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] 11+ 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; 11+ 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] 11+ messages in thread
* [RFC PATCH v2 3/4] drivers/auxdisplay: senshat Raspberry Pi Sense HAT display driver
2021-08-20 18:07 [RFC PATCH v2 0/4] Raspberry Pi Sense HAT driver Charles Mirabile
2021-08-20 18:07 ` [RFC PATCH v2 1/4] drivers/mfd: sensehat: Raspberry Pi Sense HAT core 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-20 18:08 ` Charles Mirabile
2021-08-30 13:28 ` nsaenzju
2021-08-20 18:08 ` [RFC PATCH v2 4/4] sensehat: Add device tree overlay (do not merge) Charles Mirabile
3 siblings, 1 reply; 11+ messages in thread
From: Charles Mirabile @ 2021-08-20 18:08 UTC (permalink / raw)
To: linux-kernel
Cc: Charles Mirabile, Miguel Ojeda, Serge Schneider, Stefan Wahren,
Nicolas Saenz Julienne, linux-rpi-kernel, fedora-rpi,
Mwesigwa Guma, Joel Savitz
This patch implements control of the 8x8 RGB LED matrix display.
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/auxdisplay/Kconfig | 7 +
drivers/auxdisplay/Makefile | 1 +
drivers/auxdisplay/sensehat-display.c | 233 ++++++++++++++++++++++++++
3 files changed, 241 insertions(+)
create mode 100644 drivers/auxdisplay/sensehat-display.c
diff --git a/drivers/auxdisplay/Kconfig b/drivers/auxdisplay/Kconfig
index 1509cb74705a..24f5d68cfbff 100644
--- a/drivers/auxdisplay/Kconfig
+++ b/drivers/auxdisplay/Kconfig
@@ -193,6 +193,13 @@ config ARM_CHARLCD
line and the Linux version on the second line, but that's
still useful.
+config SENSEHAT_DISPLAY
+ tristate "Raspberry pi Sense HAT display driver"
+ select MFD_SENSEHAT_CORE
+ help
+ This is a driver for the Raspberry Pi Sensehat 8x8 RBG-LED matrix
+ you can access it as a misc device at /dev/sense-hat
+
menuconfig PARPORT_PANEL
tristate "Parallel port LCD/Keypad Panel support"
depends on PARPORT
diff --git a/drivers/auxdisplay/Makefile b/drivers/auxdisplay/Makefile
index 307771027c89..7e9aa479586a 100644
--- a/drivers/auxdisplay/Makefile
+++ b/drivers/auxdisplay/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_HD44780) += hd44780.o
obj-$(CONFIG_HT16K33) += ht16k33.o
obj-$(CONFIG_PARPORT_PANEL) += panel.o
obj-$(CONFIG_LCD2S) += lcd2s.o
+obj-$(CONFIG_SENSEHAT_DISPLAY) += sensehat-display.o
diff --git a/drivers/auxdisplay/sensehat-display.c b/drivers/auxdisplay/sensehat-display.c
new file mode 100644
index 000000000000..8a618a198351
--- /dev/null
+++ b/drivers/auxdisplay/sensehat-display.c
@@ -0,0 +1,233 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Raspberry Pi Sense HAT 8x8 LED matrix display 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/kernel.h>
+#include <linux/errno.h>
+#include <linux/string.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/uaccess.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/mod_devicetable.h>
+
+#include <linux/mfd/sensehat.h>
+
+#define GAMMA_SIZE sizeof_field(struct sensehat_display, gamma)
+#define VMEM_SIZE sizeof_field(struct sensehat_display, vmem)
+
+static bool lowlight;
+module_param(lowlight, bool, 0);
+MODULE_PARM_DESC(lowlight, "Reduce LED matrix brightness to one third");
+
+static const u8 gamma_presets[][GAMMA_SIZE] = {
+ [GAMMA_DEFAULT] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
+ 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11,
+ 0x12, 0x14, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F,
+ },
+ [GAMMA_LOWLIGHT] = {
+ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+ 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02,
+ 0x03, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06,
+ 0x06, 0x07, 0x07, 0x08, 0x08, 0x09, 0x0A, 0x0A,
+ },
+};
+
+static const struct file_operations sensehat_display_fops;
+
+static int sensehat_display_probe(struct platform_device *pdev)
+{
+ int ret;
+
+ struct sensehat *sensehat = dev_get_drvdata(&pdev->dev);
+ struct sensehat_display *sensehat_display = &sensehat->display;
+
+ memcpy(sensehat_display->gamma, gamma_presets[lowlight], GAMMA_SIZE);
+
+ memset(sensehat_display->vmem, 0, VMEM_SIZE);
+
+ mutex_init(&sensehat_display->rw_mtx);
+
+ sensehat_display->mdev = (struct miscdevice) {
+ .minor = MISC_DYNAMIC_MINOR,
+ .name = "sense-hat",
+ .mode = 0666,
+ .fops = &sensehat_display_fops,
+ };
+
+ ret = misc_register(&sensehat_display->mdev);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "Could not register 8x8 LED matrix display.\n");
+ return ret;
+ }
+
+ dev_info(&pdev->dev, "8x8 LED matrix display registered with minor number %i",
+ sensehat_display->mdev.minor);
+
+ sensehat_update_display(sensehat);
+ return 0;
+}
+
+static int sensehat_display_remove(struct platform_device *pdev)
+{
+ struct sensehat *sensehat = dev_get_drvdata(&pdev->dev);
+ struct sensehat_display *sensehat_display = &sensehat->display;
+
+ misc_deregister(&sensehat_display->mdev);
+ return 0;
+}
+
+static loff_t sensehat_display_llseek(struct file *filp, loff_t pos, int whence)
+{
+ loff_t base;
+
+ switch (whence) {
+ case SEEK_SET:
+ base = 0;
+ break;
+ case SEEK_CUR:
+ base = filp->f_pos;
+ break;
+ case SEEK_END:
+ base = VMEM_SIZE;
+ break;
+ default:
+ return -EINVAL;
+ }
+ base += pos;
+ if (base < 0 || base >= VMEM_SIZE)
+ return -EINVAL;
+ filp->f_pos = base;
+ return base;
+}
+
+static ssize_t
+sensehat_display_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
+{
+ struct sensehat *sensehat = container_of(filp->private_data, struct sensehat, display.mdev);
+ struct sensehat_display *sensehat_display = &sensehat->display;
+ ssize_t retval = -EFAULT;
+
+ if (*f_pos >= VMEM_SIZE)
+ return 0;
+ if (*f_pos + count > VMEM_SIZE)
+ count = VMEM_SIZE - *f_pos;
+ if (mutex_lock_interruptible(&sensehat_display->rw_mtx))
+ return -ERESTARTSYS;
+ if (copy_to_user(buf, sensehat_display->vmem + *f_pos, count))
+ goto out;
+ *f_pos += count;
+ retval = count;
+out:
+ mutex_unlock(&sensehat_display->rw_mtx);
+ return retval;
+}
+
+static ssize_t
+sensehat_display_write(struct file *filp, const char __user *buf, size_t count, loff_t *f_pos)
+{
+ struct sensehat *sensehat = container_of(filp->private_data, struct sensehat, display.mdev);
+ struct sensehat_display *sensehat_display = &sensehat->display;
+ u8 temp[VMEM_SIZE];
+
+ if (*f_pos >= VMEM_SIZE)
+ return -EFBIG;
+ if (*f_pos + count > VMEM_SIZE)
+ count = VMEM_SIZE - *f_pos;
+ if (copy_from_user(temp, buf, count))
+ return -EFAULT;
+ if (mutex_lock_interruptible(&sensehat_display->rw_mtx))
+ return -ERESTARTSYS;
+ memcpy(sensehat_display->vmem + *f_pos, temp, count);
+ sensehat_update_display(sensehat);
+ *f_pos += count;
+ mutex_unlock(&sensehat_display->rw_mtx);
+ return count;
+}
+
+static long sensehat_display_ioctl(struct file *filp, unsigned int cmd,
+ unsigned long arg)
+{
+ struct sensehat *sensehat = container_of(filp->private_data, struct sensehat, display.mdev);
+ struct sensehat_display *sensehat_display = &sensehat->display;
+ void __user *user_ptr = (void __user *)arg;
+ u8 temp[GAMMA_SIZE];
+ int ret;
+
+ if (mutex_lock_interruptible(&sensehat_display->rw_mtx))
+ return -ERESTARTSYS;
+ switch (cmd) {
+ case SENSEDISP_IOGET_GAMMA:
+ if (copy_to_user(user_ptr, sensehat_display->gamma, GAMMA_SIZE)) {
+ ret = -EFAULT;
+ goto out_unlock;
+ }
+ ret = 0;
+ goto out_unlock;
+ case SENSEDISP_IOSET_GAMMA:
+ if (copy_from_user(temp, user_ptr, GAMMA_SIZE)) {
+ ret = -EFAULT;
+ goto out_unlock;
+ }
+ ret = 0;
+ goto out_update;
+ case SENSEDISP_IORESET_GAMMA:
+ if (arg < GAMMA_DEFAULT || arg >= GAMMA_PRESET_COUNT) {
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+ memcpy(temp, gamma_presets[arg], GAMMA_SIZE);
+ ret = 0;
+ goto out_update;
+ default:
+ ret = -EINVAL;
+ goto out_unlock;
+ }
+out_update:
+ memcpy(sensehat_display->gamma, temp, GAMMA_SIZE);
+ sensehat_update_display(sensehat);
+out_unlock:
+ mutex_unlock(&sensehat_display->rw_mtx);
+ return ret;
+}
+
+static const struct file_operations sensehat_display_fops = {
+ .owner = THIS_MODULE,
+ .llseek = sensehat_display_llseek,
+ .read = sensehat_display_read,
+ .write = sensehat_display_write,
+ .unlocked_ioctl = sensehat_display_ioctl,
+};
+
+static struct platform_device_id sensehat_display_device_id[] = {
+ { .name = "sensehat-display" },
+ { },
+};
+MODULE_DEVICE_TABLE(platform, sensehat_display_device_id);
+
+static struct platform_driver sensehat_display_driver = {
+ .probe = sensehat_display_probe,
+ .remove = sensehat_display_remove,
+ .driver = {
+ .name = "sensehat-display",
+ },
+};
+
+module_platform_driver(sensehat_display_driver);
+
+MODULE_DESCRIPTION("Raspberry Pi Sense HAT 8x8 LED matrix display driver");
+MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
+MODULE_LICENSE("GPL");
--
2.27.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [RFC PATCH v2 3/4] drivers/auxdisplay: senshat Raspberry Pi Sense HAT display driver
2021-08-20 18:08 ` [RFC PATCH v2 3/4] drivers/auxdisplay: senshat Raspberry Pi Sense HAT display driver Charles Mirabile
@ 2021-08-30 13:28 ` nsaenzju
2021-09-16 11:00 ` Matthias Brugger
0 siblings, 1 reply; 11+ messages in thread
From: nsaenzju @ 2021-08-30 13:28 UTC (permalink / raw)
To: Charles Mirabile, linux-kernel
Cc: Miguel Ojeda, Serge Schneider, Stefan Wahren, linux-rpi-kernel,
fedora-rpi, Mwesigwa Guma, Joel Savitz
Hi Charles,
On Fri, 2021-08-20 at 14:08 -0400, Charles Mirabile wrote:
> This patch implements control of the 8x8 RGB LED matrix display.
It'd be nice to get a more information on the i2c interface, and what each byte
is supposed to represent.
> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
> Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
> ---
[...]
> +static long sensehat_display_ioctl(struct file *filp, unsigned int cmd,
> + unsigned long arg)
> +{
> + struct sensehat *sensehat = container_of(filp->private_data, struct sensehat, display.mdev);
> + struct sensehat_display *sensehat_display = &sensehat->display;
> + void __user *user_ptr = (void __user *)arg;
> + u8 temp[GAMMA_SIZE];
> + int ret;
> +
> + if (mutex_lock_interruptible(&sensehat_display->rw_mtx))
> + return -ERESTARTSYS;
> + switch (cmd) {
> + case SENSEDISP_IOGET_GAMMA:
> + if (copy_to_user(user_ptr, sensehat_display->gamma, GAMMA_SIZE)) {
> + ret = -EFAULT;
> + goto out_unlock;
> + }
> + ret = 0;
> + goto out_unlock;
> + case SENSEDISP_IOSET_GAMMA:
> + if (copy_from_user(temp, user_ptr, GAMMA_SIZE)) {
> + ret = -EFAULT;
> + goto out_unlock;
> + }
> + ret = 0;
> + goto out_update;
> + case SENSEDISP_IORESET_GAMMA:
> + if (arg < GAMMA_DEFAULT || arg >= GAMMA_PRESET_COUNT) {
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> + memcpy(temp, gamma_presets[arg], GAMMA_SIZE);
> + ret = 0;
> + goto out_update;
> + default:
> + ret = -EINVAL;
> + goto out_unlock;
> + }
> +out_update:
> + memcpy(sensehat_display->gamma, temp, GAMMA_SIZE);
> + sensehat_update_display(sensehat);
> +out_unlock:
> + mutex_unlock(&sensehat_display->rw_mtx);
> + return ret;
> +}
> +
> +static const struct file_operations sensehat_display_fops = {
> + .owner = THIS_MODULE,
> + .llseek = sensehat_display_llseek,
> + .read = sensehat_display_read,
> + .write = sensehat_display_write,
> + .unlocked_ioctl = sensehat_display_ioctl,
> +};
I doubt this approach will make it upstream. This should use an already
existing kernel interface, or if not good enough, extend it. I'm sure this is
not the first RGB led matrix to show up anyway. Maybe drivers/leds has
infrastructure to deal with this. Or else a fb device?
I presume you want to keep the IOCTL in order to be able to run RPi specific
aplications/libraries. It'll be up to them to change once we settle on a proper
way of handling this, not the other way around. Note that the RPi engineers
have always preffered using official kernel interfaces when available, so I
don't think this'll be problematic.
Regards,
Nicolas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC PATCH v2 3/4] drivers/auxdisplay: senshat Raspberry Pi Sense HAT display driver
2021-08-30 13:28 ` nsaenzju
@ 2021-09-16 11:00 ` Matthias Brugger
0 siblings, 0 replies; 11+ messages in thread
From: Matthias Brugger @ 2021-09-16 11:00 UTC (permalink / raw)
To: nsaenzju, Charles Mirabile, linux-kernel
Cc: Miguel Ojeda, Serge Schneider, Stefan Wahren, linux-rpi-kernel,
fedora-rpi, Mwesigwa Guma, Joel Savitz
On 30/08/2021 15:28, nsaenzju@redhat.com wrote:
> Hi Charles,
>
> On Fri, 2021-08-20 at 14:08 -0400, Charles Mirabile wrote:
>> This patch implements control of the 8x8 RGB LED matrix display.
>
> It'd be nice to get a more information on the i2c interface, and what each byte
> is supposed to represent.
>
>> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
>> Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
>> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
>> ---
>
> [...]
>
>> +static long sensehat_display_ioctl(struct file *filp, unsigned int cmd,
>> + unsigned long arg)
>> +{
>> + struct sensehat *sensehat = container_of(filp->private_data, struct sensehat, display.mdev);
>> + struct sensehat_display *sensehat_display = &sensehat->display;
>> + void __user *user_ptr = (void __user *)arg;
>> + u8 temp[GAMMA_SIZE];
>> + int ret;
>> +
>> + if (mutex_lock_interruptible(&sensehat_display->rw_mtx))
>> + return -ERESTARTSYS;
>> + switch (cmd) {
>> + case SENSEDISP_IOGET_GAMMA:
>> + if (copy_to_user(user_ptr, sensehat_display->gamma, GAMMA_SIZE)) {
>> + ret = -EFAULT;
>> + goto out_unlock;
>> + }
>> + ret = 0;
>> + goto out_unlock;
>> + case SENSEDISP_IOSET_GAMMA:
>> + if (copy_from_user(temp, user_ptr, GAMMA_SIZE)) {
>> + ret = -EFAULT;
>> + goto out_unlock;
>> + }
>> + ret = 0;
>> + goto out_update;
>> + case SENSEDISP_IORESET_GAMMA:
>> + if (arg < GAMMA_DEFAULT || arg >= GAMMA_PRESET_COUNT) {
>> + ret = -EINVAL;
>> + goto out_unlock;
>> + }
>> + memcpy(temp, gamma_presets[arg], GAMMA_SIZE);
>> + ret = 0;
>> + goto out_update;
>> + default:
>> + ret = -EINVAL;
>> + goto out_unlock;
>> + }
>> +out_update:
>> + memcpy(sensehat_display->gamma, temp, GAMMA_SIZE);
>> + sensehat_update_display(sensehat);
>> +out_unlock:
>> + mutex_unlock(&sensehat_display->rw_mtx);
>> + return ret;
>> +}
>> +
>> +static const struct file_operations sensehat_display_fops = {
>> + .owner = THIS_MODULE,
>> + .llseek = sensehat_display_llseek,
>> + .read = sensehat_display_read,
>> + .write = sensehat_display_write,
>> + .unlocked_ioctl = sensehat_display_ioctl,
>> +};
>
> I doubt this approach will make it upstream. This should use an already
> existing kernel interface, or if not good enough, extend it. I'm sure this is
> not the first RGB led matrix to show up anyway. Maybe drivers/leds has
> infrastructure to deal with this. Or else a fb device?
I'm working on upstreaming that again and my approach is to use framebuffer for
this. What is the reason you decided against framebuffer?
Regards,
Matthias
>
> I presume you want to keep the IOCTL in order to be able to run RPi specific
> aplications/libraries. It'll be up to them to change once we settle on a proper
> way of handling this, not the other way around. Note that the RPi engineers
> have always preffered using official kernel interfaces when available, so I
> don't think this'll be problematic.
>
> Regards,
> Nicolas
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [RFC PATCH v2 4/4] sensehat: Add device tree overlay (do not merge)
2021-08-20 18:07 [RFC PATCH v2 0/4] Raspberry Pi Sense HAT driver Charles Mirabile
` (2 preceding siblings ...)
2021-08-20 18:08 ` [RFC PATCH v2 3/4] drivers/auxdisplay: senshat Raspberry Pi Sense HAT display driver Charles Mirabile
@ 2021-08-20 18:08 ` Charles Mirabile
2021-08-30 12:45 ` nsaenzju
2021-09-16 10:57 ` Matthias Brugger
3 siblings, 2 replies; 11+ messages in thread
From: Charles Mirabile @ 2021-08-20 18:08 UTC (permalink / raw)
To: linux-kernel
Cc: Charles Mirabile, Rob Herring, devicetree, Serge Schneider,
Stefan Wahren, Nicolas Saenz Julienne, linux-rpi-kernel,
fedora-rpi, Mwesigwa Guma, Joel Savitz
This patch is an RFC. The overlay included here is suitable for the
Sense HAT but we are not sure where overlays like this should go, or if we
should even include it, because the Raspberry Pi kernel tree already
includes that device tree blob that this was based on and most
distributions for the Raspberry Pi include those blobs.
The overlay is just in the root of the source tree since we did not know
where to put it so this patch should not be merged in this state.
Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
Signed-off-by: Joel Savitz <jsavitz@redhat.com>
---
sensehat.dtbs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 sensehat.dtbs
diff --git a/sensehat.dtbs b/sensehat.dtbs
new file mode 100644
index 000000000000..3f1c12c8f75f
--- /dev/null
+++ b/sensehat.dtbs
@@ -0,0 +1,51 @@
+/dts-v1/;
+
+/ {
+ compatible = "brcm,bcm2835";
+
+ fragment@0 {
+ target = <0xffffffff>;
+
+ __overlay__ {
+ #address-cells = <0x01>;
+ #size-cells = <0x00>;
+ status = "okay";
+
+ sensehat@46 {
+ compatible = "raspberrypi,sensehat";
+ reg = <0x46>;
+ keys-int-gpios = <0xffffffff 0x17 0x01>;
+ status = "okay";
+ };
+
+ lsm9ds1-magn@1c {
+ compatible = "st,lsm9ds1-magn";
+ reg = <0x1c>;
+ status = "okay";
+ };
+
+ lsm9ds1-accel6a {
+ compatible = "st,lsm9ds1-accel";
+ reg = <0x6a>;
+ status = "okay";
+ };
+
+ lps25h-press@5c {
+ compatible = "st,lps25h-press";
+ reg = <0x5c>;
+ status = "okay";
+ };
+
+ hts221-humid@5f {
+ compatible = "st,hts221-humid\0st,hts221";
+ reg = <0x5f>;
+ status = "okay";
+ };
+ };
+ };
+
+ __fixups__ {
+ i2c1 = "/fragment@0:target:0";
+ gpio = "/fragment@0/__overlay__/sensehat@46:keys-int-gpios:0";
+ };
+};
--
2.27.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [RFC PATCH v2 4/4] sensehat: Add device tree overlay (do not merge)
2021-08-20 18:08 ` [RFC PATCH v2 4/4] sensehat: Add device tree overlay (do not merge) Charles Mirabile
@ 2021-08-30 12:45 ` nsaenzju
2021-09-16 10:57 ` Matthias Brugger
1 sibling, 0 replies; 11+ messages in thread
From: nsaenzju @ 2021-08-30 12:45 UTC (permalink / raw)
To: Charles Mirabile, linux-kernel
Cc: Rob Herring, devicetree, Serge Schneider, Stefan Wahren,
linux-rpi-kernel, fedora-rpi, Mwesigwa Guma, Joel Savitz
Hi Charles,
On Fri, 2021-08-20 at 14:08 -0400, Charles Mirabile wrote:
> This patch is an RFC. The overlay included here is suitable for the
> Sense HAT but we are not sure where overlays like this should go, or if we
> should even include it, because the Raspberry Pi kernel tree already
> includes that device tree blob that this was based on and most
> distributions for the Raspberry Pi include those blobs.
>
> The overlay is just in the root of the source tree since we did not know
> where to put it so this patch should not be merged in this state.
>
> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
> Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
> ---
Once we get this merged, and since upstream doesn't yet mantain overlays, I
suggest you merge this overlay in the downstream rpi kernel repo, who actively
maintain them. AFAIK a number of distros use that repo as the base for their
devicetrees.
That said, I think providing a devicetree binding for this driver is a must for
it to be merged (in yaml form).
Regards,
Nicolas
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFC PATCH v2 4/4] sensehat: Add device tree overlay (do not merge)
2021-08-20 18:08 ` [RFC PATCH v2 4/4] sensehat: Add device tree overlay (do not merge) Charles Mirabile
2021-08-30 12:45 ` nsaenzju
@ 2021-09-16 10:57 ` Matthias Brugger
1 sibling, 0 replies; 11+ messages in thread
From: Matthias Brugger @ 2021-09-16 10:57 UTC (permalink / raw)
To: Charles Mirabile, linux-kernel
Cc: Rob Herring, devicetree, Serge Schneider, Stefan Wahren,
Nicolas Saenz Julienne, linux-rpi-kernel, fedora-rpi,
Mwesigwa Guma, Joel Savitz
On 20/08/2021 20:08, Charles Mirabile wrote:
> This patch is an RFC. The overlay included here is suitable for the
> Sense HAT but we are not sure where overlays like this should go, or if we
> should even include it, because the Raspberry Pi kernel tree already
> includes that device tree blob that this was based on and most
> distributions for the Raspberry Pi include those blobs.
>
> The overlay is just in the root of the source tree since we did not know
> where to put it so this patch should not be merged in this state.
>
> Signed-off-by: Charles Mirabile <cmirabil@redhat.com>
> Signed-off-by: Mwesigwa Guma <mguma@redhat.com>
> Signed-off-by: Joel Savitz <jsavitz@redhat.com>
> ---
> sensehat.dtbs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 51 insertions(+)
> create mode 100644 sensehat.dtbs
>
> diff --git a/sensehat.dtbs b/sensehat.dtbs
> new file mode 100644
> index 000000000000..3f1c12c8f75f
> --- /dev/null
> +++ b/sensehat.dtbs
> @@ -0,0 +1,51 @@
> +/dts-v1/;
> +
> +/ {
> + compatible = "brcm,bcm2835";
> +
> + fragment@0 {
> + target = <0xffffffff>;
> +
> + __overlay__ {
> + #address-cells = <0x01>;
> + #size-cells = <0x00>;
> + status = "okay";
> +
> + sensehat@46 {
> + compatible = "raspberrypi,sensehat";
> + reg = <0x46>;
> + keys-int-gpios = <0xffffffff 0x17 0x01>;
> + status = "okay";
> + };
> +
> + lsm9ds1-magn@1c {
> + compatible = "st,lsm9ds1-magn";
> + reg = <0x1c>;
> + status = "okay";
> + };
> +
> + lsm9ds1-accel6a {
> + compatible = "st,lsm9ds1-accel";
> + reg = <0x6a>;
> + status = "okay";
> + };
> +
> + lps25h-press@5c {
> + compatible = "st,lps25h-press";
> + reg = <0x5c>;
> + status = "okay";
> + };
> +
> + hts221-humid@5f {
> + compatible = "st,hts221-humid\0st,hts221";
Isn't "st,hts221" good enough?
> + reg = <0x5f>;
> + status = "okay";
> + };
> + };
> + };
> +
> + __fixups__ {
> + i2c1 = "/fragment@0:target:0";
> + gpio = "/fragment@0/__overlay__/sensehat@46:keys-int-gpios:0";
> + };
> +};
>
As Nicolas said, yaml bindings are a must. The overlay can be added as for
convenience to the series but it should be made clear that it is not supposed to
be upstreamed.
Regards,
Matthias
^ permalink raw reply [flat|nested] 11+ messages in thread