Raspberry Pi Sense HAT driver
cover Raspberry Pi Sense HAT driver
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 this 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
Though the driver is split into three modules, they are interdependent and meaningless in isolation. As such, we have grouped them together.
This is a request for comments. Please let us know if you have any suggestions, complements, or harsh criticism. ;)
Known issue:
- We do not know how to integrate the device tree overlay into mainline Linux. Fortunately, most Linux distrubtions designed for the Raspberry Pi already include the approriate device tree overlay as a part of their importation of all overlays from the downstream Raspberry Pi kernel. Suggestions are welcome and appreciated.
For more information about the Sense HAT, visit:
https://www.raspberrypi.org/products/sense-hat/
Joel Savitz (3):
drivers/mfd: rpisense: Raspberry Pi senseHAT core driver drivers/mfd: rpisense: Raspberry Pi senseHAT joystick driver drivers/mfd: rpisense: Raspberry Pi senseHAT 8x8 LED matrix display
driver
drivers/mfd/Kconfig | 10 ++ drivers/mfd/Makefile | 3 + drivers/mfd/rpisense-core.c | 170 +++++++++++++++++++++++ drivers/mfd/rpisense-display.c | 242 +++++++++++++++++++++++++++++++++ drivers/mfd/rpisense-js.c | 132 ++++++++++++++++++ include/linux/mfd/rpisense.h | 55 ++++++++ 6 files changed, 612 insertions(+) create mode 100644 drivers/mfd/rpisense-core.c create mode 100644 drivers/mfd/rpisense-display.c create mode 100644 drivers/mfd/rpisense-js.c create mode 100644 include/linux/mfd/rpisense.h
Signature · 1 line
2.27.0
RFC PATCH 1/3 drivers/mfd: rpisense: Raspberry Pi senseHAT core driver
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.
--- drivers/mfd/Kconfig | 10 +++ drivers/mfd/Makefile | 1 + drivers/mfd/rpisense-core.c | 170 +++++++++++++++++++++++++++++++++++ include/linux/mfd/rpisense.h | 55 ++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 drivers/mfd/rpisense-core.c create mode 100644 include/linux/mfd/rpisense.h
drivers/mfd/Kconfig +10 -0
@@ -11,6 +11,16 @@ config MFD_CORE select IRQ_DOMAIN default n +config MFD_RPISENSE + tristate "Raspberry Pi Sense HAT driver" + depends on I2C && GPIOLIB + select MFD_CORE + help + This is the driver for the Raspberry Pi Sense HAT. This provides + the necessary functions to communicate with the hardware as well + as a joystick and display interface. Linux communicates with the + hardwire using the GPIO pins via the I2C protocol. + config MFD_CS5535 tristate "AMD CS5535 and CS5536 southbridge core functions" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -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_RPISENSE) += rpisense-core.o obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
drivers/mfd/rpisense-core.c new file +170 -0
170 lines not on this page · raw message
include/linux/mfd/rpisense.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [RFC PATCH 1/3] drivers/mfd: rpisense: Raspberry Pi senseHAT core driver
Quoted 7 lines · Joel Savitz
drivers/mfd/Kconfig +0
-0@@ -11,6 +11,16 @@ config MFD_CORE select IRQ_DOMAIN default n
drivers/mfd/Kconfig config MFD_CORE · line 22
Quoted 10 lines
drivers/mfd/Kconfig +9
-0+config MFD_RPISENSE + tristate "Raspberry Pi Sense HAT driver" + depends on I2C && GPIOLIB + select MFD_CORE + help + This is the driver for the Raspberry Pi Sense HAT. This provides + the necessary functions to communicate with the hardware as well + as a joystick and display interface. Linux communicates with the + hardwire using the GPIO pins via the I2C protocol.
hardware
What is HAT, please?
Signature · 1 line
~Randy
Re: [RFC PATCH 1/3] drivers/mfd: rpisense: Raspberry Pi senseHAT core driver
In reply to Joel SavitzAm 07.08.21 um 02:27 schrieb Joel Savitz:
Quoted 22 lines
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 <[email protected]>Signed-off-by Mwesigwa Guma <[email protected]>Signed-off-by Joel Savitz <[email protected]>--- drivers/mfd/Kconfig | 10 +++ drivers/mfd/Makefile | 1 + drivers/mfd/rpisense-core.c | 170 +++++++++++++++++++++++++++++++++++ include/linux/mfd/rpisense.h | 55 ++++++++++++ 4 files changed, 236 insertions(+) create mode 100644 drivers/mfd/rpisense-core.c create mode 100644 include/linux/mfd/rpisense.hdrivers/mfd/Kconfig +0
-0
drivers/mfd/Kconfig config MFD_CORE · line 14
Quoted 4 lines
drivers/mfd/Kconfig +1
-0@@ -11,6 +11,16 @@ config MFD_CORE select IRQ_DOMAIN default n +config MFD_RPISENSE
RPI is not used before in config options. I suggest MFG_RASPBERRYPI_SENSE
Quoted 64 lines
drivers/mfd/Kconfig +9
-0+ tristate "Raspberry Pi Sense HAT driver" + depends on I2C && GPIOLIB + select MFD_CORE + help + This is the driver for the Raspberry Pi Sense HAT. This provides + the necessary functions to communicate with the hardware as well + as a joystick and display interface. Linux communicates with the + hardwire using the GPIO pins via the I2C protocol. + config MFD_CS5535 tristate "AMD CS5535 and CS5536 southbridge core functions" select MFD_COREdrivers/mfd/Makefile +1
-0@@ -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_RPISENSE) += rpisense-core.o obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.odrivers/mfd/rpisense-core.c new file +34
-0@@ -0,0 +1,170 @@ +// 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/rpisense.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 * +rpisense_client_dev_register (struct rpisense *rpisense,const char *name);
drivers/mfd/rpisense-core.c line 44
Quoted 10 lines
drivers/mfd/rpisense-core.c new file +10
-0+ +static int rpisense_probe (struct i2c_client *i2c, +const struct i2c_device_id *id) +{ +int ret; + +struct rpisense *rpisense =devm_kzalloc (&i2c->dev,sizeof (*rpisense),GFP_KERNEL ); + +if (rpisense ==NULL ) +return -ENOMEM ;
The more common style is: if (!rpisense)
Quoted 6 lines
drivers/mfd/rpisense-core.c new file +6
-0+ +i2c_set_clientdata (i2c, rpisense); + rpisense->dev = &i2c->dev; + rpisense->i2c_client = i2c; + +
drivers/mfd/rpisense-core.c line 60
Quoted 10 lines
drivers/mfd/rpisense-core.c new file +10
-0+ ret =i2c_smbus_read_byte_data (rpisense->i2c_client,RPISENSE_WAI ); +if (ret <0 ) +return ret; + +if (ret !=RPISENSE_ID ) +return -EINVAL ; + + ret =i2c_smbus_read_byte_data (rpisense->i2c_client,RPISENSE_VER ); +if (ret <0 ) +return ret;
Not sure about all the error cases, but i think the last two deserve a log entry.
Quoted 27 lines
drivers/mfd/rpisense-core.c new file +27
-0+ +dev_info (rpisense->dev, +"Raspberry Pi Sense HAT firmware version %i\n" , ret); + + rpisense->joystick.pdev =rpisense_client_dev_register (rpisense, +"rpi-sense-js" ); + +if (IS_ERR (rpisense->joystick.pdev)) { +dev_err (rpisense->dev,"failed to register rpisense-js" ); +return PTR_ERR (rpisense->joystick.pdev); + } + + rpisense->display.pdev =rpisense_client_dev_register (rpisense, +"rpi-sense-fb" ); + +if (IS_ERR (rpisense->display.pdev)) { +dev_err (rpisense->dev,"failed to register rpisense-fb" ); +return PTR_ERR (rpisense->display.pdev); + } + +return 0 ; +} + +static struct platform_device * +rpisense_client_dev_register (struct rpisense *rpisense,const char *name) +{ +long ret = -ENOMEM ;
drivers/mfd/rpisense-core.c line 97
Quoted 10 lines
drivers/mfd/rpisense-core.c new file +10
-0+struct platform_device *pdev =platform_device_alloc (name,-1 ); + +if (pdev ==NULL ) + goto alloc_fail; + + pdev->dev.parent = rpisense->dev; +platform_set_drvdata (pdev, rpisense); + + ret =platform_device_add (pdev); +if (ret !=0 )
Similiar as above: if (ret)
Quoted 44 lines
drivers/mfd/rpisense-core.c new file +44
-0+ goto add_fail; + + ret =devm_add_action_or_reset (rpisense->dev, + (void *)platform_device_unregister, pdev); +if (ret !=0 ) + goto alloc_fail; + +return pdev; + +add_fail: +platform_device_put (pdev); +alloc_fail: +return ERR_PTR (ret); +} + +int rpisense_get_joystick_state (struct rpisense *rpisense) +{ +int ret =i2c_smbus_read_byte_data (rpisense->i2c_client,RPISENSE_KEYS ); + +return ret <0 ? ret : ret &0x1f ; +} +EXPORT_SYMBOL_GPL (rpisense_get_joystick_state); + +int rpisense_update_display (struct rpisense *rpisense) +{ +int i, j, ret; +struct rpisense_display *display = &rpisense->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 (rpisense->i2c_client, (u8 *)&msg,sizeof (msg)); +if (ret <0 ) +dev_err (rpisense->dev,"Update to 8x8 LED matrix display failed" ); +return ret; +} +EXPORT_SYMBOL_GPL (rpisense_update_display);
drivers/mfd/rpisense-core.c line 151
Quoted 10 lines
drivers/mfd/rpisense-core.c new file +10
-0+ +static const struct i2c_device_id rpisense_i2c_id[] = { + {"rpi-sense" ,0 }, + { } +}; +MODULE_DEVICE_TABLE (i2c, rpisense_i2c_id); + +#ifdef CONFIG_OF +static const struct of_device_id rpisense_core_id[] = { + { .compatible = "rpi,rpi-sense" },
The vendor is raspberrypi, which is already listed in Documentation
<https://elixir.bootlin.com/linux/latest/source/Documentation>/devicetree
<https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree>/bindings
<https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings>/vendor-prefixes.yaml
<https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/vendor-prefixes.yaml>
Not sure about the compatible. It must be added to the bindings, but unsure this should go to Documentation
<https://elixir.bootlin.com/linux/latest/source/Documentation>/devicetree
<https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree>/bindings
<https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings>/trivial-devices.yaml
<https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/trivial-devices.yaml>
or a separate YAML file.
Best regards
RFC PATCH 2/3 drivers/mfd: rpisense: Raspberry Pi senseHAT joystick driver
In reply to Joel SavitzThis patch implements support for the joystick, including a threaded IRQ routine.
--- drivers/mfd/Makefile | 1 + drivers/mfd/rpisense-js.c | 132 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 drivers/mfd/rpisense-js.c
drivers/mfd/Makefile +1 -0
@@ -264,6 +264,7 @@ 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_RPISENSE) += rpisense-core.o +obj-$(CONFIG_MFD_RPISENSE) += rpisense-js.o obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
drivers/mfd/rpisense-js.c new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [RFC PATCH 2/3] drivers/mfd: rpisense: Raspberry Pi senseHAT joystick driver
Quoted 3 lines · Joel Savitz
This patch implements support for the joystick, including a threaded IRQ routine.
If you look at this on it's own, remember the cover letter doesn't go into git, it's not overly descriptive. We know it's a patch. What does the "threaded IRQ routine" do in the context, why is that specifically called out.
Something like:
A simple joystick with up/down/left/right and enter attached via i2c
Quoted 6 lines
Signed-off-by Charles Mirabile <[email protected]>Signed-off-by Mwesigwa Guma <[email protected]>Signed-off-by Joel Savitz <[email protected]>--- drivers/mfd/Makefile | 1 + drivers/mfd/rpisense-js.c | 132 ++++++++++++++++++++++++++++++++++++++
This driver should be in drivers/input/joystick/
drivers/mfd/Makefile obj-$(CONFIG_MFD_ROHM_BD957XMUF) += rohm-bd9576.o · line 267
Quoted 12 lines
2 files changed, 133 insertions(+) create mode 100644 drivers/mfd/rpisense-js.cdrivers/mfd/Makefile +1
-0@@ -264,6 +264,7 @@ 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_RPISENSE) += rpisense-core.o +obj-$(CONFIG_MFD_RPISENSE) += rpisense-js.o
While it's unlikely that these will be used without one another I still believe this needs it's own Kconfig entry.
Quoted 130 lines
drivers/mfd/Makefile +0
-0obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.odrivers/mfd/rpisense-js.c new file +121
-0@@ -0,0 +1,132 @@ +// 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/rpisense.h> + +static unsigned char keymap[] = {KEY_DOWN ,KEY_RIGHT ,KEY_UP ,KEY_ENTER ,KEY_LEFT ,}; + +static irqreturn_t rpisense_js_report (int n,void *cookie) +{ +int i; +static s32 prev_keys; +struct rpisense *rpisense = cookie; +struct rpisense_js *rpisense_js = &rpisense->joystick; +s32 keys =rpisense_get_joystick_state (rpisense); +s32 changes = keys ^ prev_keys; + + prev_keys = keys; +for (i =0 ; i <ARRAY_SIZE (keymap); ++i) { +if (changes & (1 <<i)) { +input_report_key (rpisense_js->keys_dev, + keymap[i], keys & (1 <<i)); + } + } +input_sync (rpisense_js->keys_dev); +return IRQ_HANDLED ; +} + +static int rpisense_js_probe (struct platform_device *pdev) +{ +int ret; +int i; +struct rpisense *rpisense =dev_get_drvdata (&pdev->dev); +struct rpisense_js *rpisense_js = &rpisense->joystick; + + rpisense_js->keys_desc =devm_gpiod_get (&rpisense->i2c_client->dev, +"keys-int" ,GPIOD_IN ); +if (IS_ERR (rpisense_js->keys_desc)) { +dev_warn (&pdev->dev,"Failed to get keys-int descriptor.\n" ); +return PTR_ERR (rpisense_js->keys_desc); + } + + + rpisense_js->keys_dev =devm_input_allocate_device (&pdev->dev); +if (rpisense_js->keys_dev ==NULL ) { +dev_err (&pdev->dev,"Could not allocate input device.\n" ); +return -ENOMEM ; + } + +for (i =0 ; i <ARRAY_SIZE (keymap); i++) { +set_bit (keymap[i], + rpisense_js->keys_dev->keybit); + } + + rpisense_js->keys_dev->name ="Raspberry Pi Sense HAT Joystick" ; + rpisense_js->keys_dev->phys ="rpi-sense-joy/input0" ; + rpisense_js->keys_dev->id.bustype =BUS_I2C ; + rpisense_js->keys_dev->evbit[0 ] =BIT_MASK (EV_KEY ) |BIT_MASK (EV_REP ); + rpisense_js->keys_dev->keycode = keymap; + rpisense_js->keys_dev->keycodesize =sizeof (unsigned char ); + rpisense_js->keys_dev->keycodemax =ARRAY_SIZE (keymap); + + ret =input_register_device (rpisense_js->keys_dev); +if (ret) { +dev_err (&pdev->dev,"Could not register input device.\n" ); +return ret; + } + + ret =gpiod_direction_input (rpisense_js->keys_desc); +if (ret) { +dev_err (&pdev->dev,"Could not set keys-int direction.\n" ); +return ret; + } + + rpisense_js->keys_irq =gpiod_to_irq (rpisense_js->keys_desc); +if (rpisense_js->keys_irq <0 ) { +dev_err (&pdev->dev,"Could not determine keys-int IRQ.\n" ); +return rpisense_js->keys_irq; + } + + ret =devm_request_threaded_irq (&pdev->dev, rpisense_js->keys_irq, +NULL , rpisense_js_report,IRQF_TRIGGER_RISING |IRQF_ONESHOT , +"keys" , rpisense); + +if (ret) { +dev_err (&pdev->dev,"IRQ request failed.\n" ); +return ret; + } +return 0 ; +} + +#ifdef CONFIG_OF +static const struct of_device_id rpisense_js_id[] = { + { .compatible ="rpi,rpi-sense-js" }, + { }, +}; +MODULE_DEVICE_TABLE (of, rpisense_js_id); +#endif + +static struct platform_device_id rpisense_js_device_id[] = { + { .name ="rpi-sense-js" }, + { }, +}; +MODULE_DEVICE_TABLE (platform, rpisense_js_device_id); + +static struct platform_driver rpisense_js_driver = {
drivers/mfd/rpisense-js.c line 131
Quoted 10 lines
drivers/mfd/rpisense-js.c new file +10
-0+ .probe = rpisense_js_probe, + .driver = { + .name = "rpi-sense-js", + }, +}; + +module_platform_driver (rpisense_js_driver); + +MODULE_DESCRIPTION ("Raspberry Pi Sense HAT joystick driver" ); +MODULE_AUTHOR ("Serge Schneider <[email protected]>" );
If you're leaving Serge as the module author should be copied in the patch series.
Quoted 9 lines
drivers/mfd/rpisense-js.c new file +1
-1+MODULE_LICENSE ("GPL" ); --2.27.0
_______________________________________________
linux-rpi-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rpi-kernel
kernel test robot
build botRe: [RFC PATCH 2/3] drivers/mfd: rpisense: Raspberry Pi senseHAT joystick driver
In reply to Joel Savitz[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]
Hi Joel,
[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on lee-mfd/for-mfd-next]
[also build test ERROR on linux/master linus/master v5.14-rc4 next-20210806] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Joel-Savitz/Raspberry-Pi-Sense-HAT-driver/20210807-082859 base: https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git for-mfd-next config: mips-buildonly-randconfig-r004-20210808 (attached as .config) compiler: mips64-linux-gcc (GCC) 10.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/3de478e79fa7f81e0d89102c8b557981506495ff
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Joel-Savitz/Raspberry-Pi-Sense-HAT-driver/20210807-082859 git checkout 3de478e79fa7f81e0d89102c8b557981506495ff
# save the attached .config to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-10.3.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
mips64-linux-ld: drivers/mfd/rpisense-js.o: in function `rpisense_js_report':
>> rpisense-js.c:(.text.rpisense_js_report+0xac): undefined reference to `input_event' >> mips64-linux-ld: rpisense-js.c:(.text.rpisense_js_report+0xcc): undefined reference to `input_event' mips64-linux-ld: drivers/mfd/rpisense-js.o: in function `rpisense_js_probe': >> rpisense-js.c:(.text.rpisense_js_probe+0x68): undefined reference to `devm_input_allocate_device' >> mips64-linux-ld: rpisense-js.c:(.text.rpisense_js_probe+0x158): undefined reference to `input_register_device'
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RFC PATCH 3/3 drivers/mfd: rpisense: Raspberry Pi senseHAT 8x8 LED matrix display driver
In reply to Joel SavitzThis patch implements control of the 8x8 RGB LED matrix display.
--- drivers/mfd/Makefile | 1 + drivers/mfd/rpisense-display.c | 242 +++++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+) create mode 100644 drivers/mfd/rpisense-display.c
drivers/mfd/Makefile +1 -0
@@ -265,6 +265,7 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o obj-$(CONFIG_MFD_RPISENSE) += rpisense-core.o obj-$(CONFIG_MFD_RPISENSE) += rpisense-js.o +obj-$(CONFIG_MFD_RPISENSE) += rpisense-display.o obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
drivers/mfd/rpisense-display.c new file +242 -0
242 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [RFC PATCH 3/3] drivers/mfd: rpisense: Raspberry Pi senseHAT 8x8 LED matrix display driver
Quoted 9 lines · Joel Savitz
This patch implements control of the 8x8 RGB LED matrix display.
Signed-off-by Charles Mirabile <[email protected]>Signed-off-by Mwesigwa Guma <[email protected]>Signed-off-by Joel Savitz <[email protected]>--- drivers/mfd/Makefile | 1 + drivers/mfd/rpisense-display.c | 242 +++++++++++++++++++++++++++++++++
I suspect this better fits in drivers/auxdisplay/
Quoted 235 lines
2 files changed, 243 insertions(+) create mode 100644 drivers/mfd/rpisense-display.cdrivers/mfd/Makefile +1
-0@@ -265,6 +265,7 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o obj-$(CONFIG_MFD_RPISENSE) += rpisense-core.o obj-$(CONFIG_MFD_RPISENSE) += rpisense-js.o +obj-$(CONFIG_MFD_RPISENSE) += rpisense-display.o obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.odrivers/mfd/rpisense-display.c new file +214
-0@@ -0,0 +1,242 @@ +// 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/rpisense.h> + +#define GAMMA_SIZE sizeof_field(struct rpisense_display, gamma) +#define VMEM_SIZE sizeof_field(struct rpisense_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 rpisense_display_fops; + +static int rpisense_display_probe (struct platform_device *pdev) +{ +int ret; + +struct rpisense *rpisense =dev_get_drvdata (&pdev->dev); +struct rpisense_display *rpisense_display = &rpisense->display; + +memcpy (rpisense_display->gamma, gamma_presets[lowlight],GAMMA_SIZE ); + +memset (rpisense_display->vmem,0 ,VMEM_SIZE ); + +mutex_init (&rpisense_display->rw_mtx); + + rpisense_display->mdev = (struct miscdevice ) { + .minor =MISC_DYNAMIC_MINOR , + .name ="sense-hat" , + .mode =0666 , + .fops = &rpisense_display_fops, + }; + + ret =misc_register (&rpisense_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" , + rpisense_display->mdev.minor); + +rpisense_update_display (rpisense); +return 0 ; +} + +static int rpisense_display_remove (struct platform_device *pdev) +{ +struct rpisense *rpisense =dev_get_drvdata (&pdev->dev); +struct rpisense_display *rpisense_display = &rpisense->display; + +misc_deregister (&rpisense_display->mdev); +return 0 ; +} + +static loff_t rpisense_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 +rpisense_display_read (struct file *filp,char __user *buf,size_t count,loff_t *f_pos) +{ + struct rpisense *rpisense = container_of(filp->private_data, struct rpisense, display.mdev); +struct rpisense_display *rpisense_display = &rpisense->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 (&rpisense_display->rw_mtx)) +return -ERESTARTSYS ; +if (copy_to_user (buf, rpisense_display->vmem + *f_pos, count)) + goto out; + *f_pos += count; + retval = count; +out: +mutex_unlock (&rpisense_display->rw_mtx); +return retval; +} + +static ssize_t +rpisense_display_write (struct file *filp,const char __user *buf,size_t count,loff_t *f_pos) +{ + struct rpisense *rpisense = container_of(filp->private_data, struct rpisense, display.mdev); +struct rpisense_display *rpisense_display = &rpisense->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 (&rpisense_display->rw_mtx)) +return -ERESTARTSYS ; +memcpy (rpisense_display->vmem + *f_pos, temp, count); +rpisense_update_display (rpisense); + *f_pos += count; +mutex_unlock (&rpisense_display->rw_mtx); +return count; +} + +static long rpisense_display_ioctl (struct file *filp,unsigned int cmd, +unsigned long arg) +{ + struct rpisense *rpisense = container_of(filp->private_data, struct rpisense, display.mdev); +struct rpisense_display *rpisense_display = &rpisense->display; +void __user *user_ptr = (void __user *)arg; +u8 temp[GAMMA_SIZE ]; +int ret; + +if (mutex_lock_interruptible (&rpisense_display->rw_mtx)) +return -ERESTARTSYS ; +switch (cmd) { +case SENSEDISP_IOGET_GAMMA : +if (copy_to_user (user_ptr, rpisense_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 (rpisense_display->gamma, temp,GAMMA_SIZE ); +rpisense_update_display (rpisense); +out_unlock: +mutex_unlock (&rpisense_display->rw_mtx); +return ret; +} + +static const struct file_operations rpisense_display_fops = { + .owner =THIS_MODULE , + .llseek = rpisense_display_llseek, + .read = rpisense_display_read, + .write = rpisense_display_write, + .unlocked_ioctl = rpisense_display_ioctl, +}; +
drivers/mfd/rpisense-display.c line 224
Quoted 10 lines
drivers/mfd/rpisense-display.c new file +10
-0+#ifdef CONFIG_OF +static const struct of_device_id rpisense_display_id[] = { + { .compatible ="rpi,rpi-sense-fb" }, + { }, +}; +MODULE_DEVICE_TABLE (of, rpisense_display_id); +#endif + +static struct platform_device_id rpisense_display_device_id[] = { + { .name ="rpi-sense-fb" },
I don't think -fb is the best name for this device, it's not a framebuffer display/driver.
Quoted 5 lines
drivers/mfd/rpisense-display.c new file +5
-0+ { }, +}; +MODULE_DEVICE_TABLE (platform, rpisense_display_device_id); + +static struct platform_driver rpisense_display_driver = {
drivers/mfd/rpisense-display.c line 239
Quoted 10 lines
drivers/mfd/rpisense-display.c new file +10
-0+ .probe = rpisense_display_probe, + .remove = rpisense_display_remove, + .driver = { + .name = "rpi-sense-fb", + }, +}; + +module_platform_driver (rpisense_display_driver); + +MODULE_DESCRIPTION ("Raspberry Pi Sense HAT 8x8 LED matrix display driver" );
Again include the original author in the cc:
Quoted 11 lines
drivers/mfd/rpisense-display.c new file +3
-1+MODULE_AUTHOR ("Serge Schneider <[email protected]>" ); +MODULE_LICENSE ("GPL" ); + --2.27.0
_______________________________________________
linux-rpi-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rpi-kernel
Hi Joel,
Am 07.08.21 um 02:27 schrieb Joel Savitz:
Quoted 26 lines
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 this driver in this repo:
https://github.com/underground-software/sensehat/tree/master/tests
-color_testdisplays various solid colors on the LED panel
-framebuffer_testdiplays a single lit cell that is controllable via the arrow keys or the joystickThough the driver is split into three modules, they are interdependent and meaningless in isolation. As such, we have grouped them together.
This is a request for comments. Please let us know if you have any suggestions, complements, or harsh criticism. ;)
Quoted 7 lines
Known issue:
- We do not know how to integrate the device tree overlay into mainline Linux. Fortunately, most Linux distrubtions designed for the Raspberry Pi already include the approriate device tree overlay as a part of their importation of all overlays from the downstream Raspberry Pi kernel. Suggestions are welcome and appreciated.
AFAIK the overlay support isn't complete yet. In order to give a chance to test with mainline, developers provided patches against a specific board DTS (e.g. RPi 3B) and tag them as DO NOT MERGE.