Skip to content

Commit 4b868fc

Browse files
committed
Add Raspberry Pi Sense HAT support
1 parent dcf857a commit 4b868fc

File tree

17 files changed

+746
-0
lines changed

17 files changed

+746
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ dtb-$(RPI_DT_OVERLAYS) += rpi-dac-overlay.dtb
3939
dtb-$(RPI_DT_OVERLAYS) += rpi-display-overlay.dtb
4040
dtb-$(RPI_DT_OVERLAYS) += rpi-ft5406-overlay.dtb
4141
dtb-$(RPI_DT_OVERLAYS) += rpi-proto-overlay.dtb
42+
dtb-$(RPI_DT_OVERLAYS) += rpi-sense-overlay.dtb
4243
dtb-$(RPI_DT_OVERLAYS) += sdhost-overlay.dtb
4344
dtb-$(RPI_DT_OVERLAYS) += spi-bcm2708-overlay.dtb
4445
dtb-$(RPI_DT_OVERLAYS) += spi-bcm2835-overlay.dtb

arch/arm/boot/dts/overlays/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,12 @@ Load: dtoverlay=rpi-proto
442442
Params: <None>
443443

444444

445+
Name: rpi-sense
446+
Info: Raspberry Pi Sense HAT
447+
Load: dtoverlay=rpi-sense
448+
Params: <None>
449+
450+
445451
Name: sdhost
446452
Info: Selects the bcm2835-sdhost SD/MMC driver, optionally with overclock
447453
Load: dtoverlay=sdhost,<param>=<val>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// rpi-sense HAT
2+
/dts-v1/;
3+
/plugin/;
4+
5+
/ {
6+
compatible = "brcm,bcm2708", "brcm,bcm2709";
7+
8+
fragment@0 {
9+
target = <&i2c1>;
10+
__overlay__ {
11+
#address-cells = <1>;
12+
#size-cells = <0>;
13+
status = "okay";
14+
15+
rpi-sense@46 {
16+
compatible = "rpi,rpi-sense";
17+
reg = <0x46>;
18+
keys-int-gpios = <&gpio 23 1>;
19+
status = "okay";
20+
};
21+
22+
lsm9ds1-magn@1c {
23+
compatible = "st,lsm9ds1-magn";
24+
reg = <0x1c>;
25+
status = "okay";
26+
};
27+
28+
lsm9ds1-accel6a {
29+
compatible = "st,lsm9ds1-accel";
30+
reg = <0x6a>;
31+
status = "okay";
32+
};
33+
34+
lps25h-press@5c {
35+
compatible = "st,lps25h-press";
36+
reg = <0x5c>;
37+
status = "okay";
38+
};
39+
40+
hts221-humid@5f {
41+
compatible = "st,hts221-humid";
42+
reg = <0x5f>;
43+
status = "okay";
44+
};
45+
};
46+
};
47+
};

arch/arm/configs/bcm2709_defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,7 @@ CONFIG_JOYSTICK_IFORCE=m
534534
CONFIG_JOYSTICK_IFORCE_USB=y
535535
CONFIG_JOYSTICK_XPAD=m
536536
CONFIG_JOYSTICK_XPAD_FF=y
537+
CONFIG_JOYSTICK_RPISENSE=m
537538
CONFIG_INPUT_TOUCHSCREEN=y
538539
CONFIG_TOUCHSCREEN_ADS7846=m
539540
CONFIG_TOUCHSCREEN_EGALAX=m
@@ -789,6 +790,7 @@ CONFIG_VIDEO_MT9V011=m
789790
CONFIG_FB=y
790791
CONFIG_FB_BCM2708=y
791792
CONFIG_FB_SSD1307=m
793+
CONFIG_FB_RPISENSE=m
792794
# CONFIG_BACKLIGHT_GENERIC is not set
793795
CONFIG_BACKLIGHT_GPIO=m
794796
CONFIG_FRAMEBUFFER_CONSOLE=y

arch/arm/configs/bcmrpi_defconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ CONFIG_JOYSTICK_IFORCE=m
527527
CONFIG_JOYSTICK_IFORCE_USB=y
528528
CONFIG_JOYSTICK_XPAD=m
529529
CONFIG_JOYSTICK_XPAD_FF=y
530+
CONFIG_JOYSTICK_RPISENSE=m
530531
CONFIG_INPUT_TOUCHSCREEN=y
531532
CONFIG_TOUCHSCREEN_ADS7846=m
532533
CONFIG_TOUCHSCREEN_EGALAX=m
@@ -782,6 +783,7 @@ CONFIG_VIDEO_MT9V011=m
782783
CONFIG_FB=y
783784
CONFIG_FB_BCM2708=y
784785
CONFIG_FB_SSD1307=m
786+
CONFIG_FB_RPISENSE=m
785787
# CONFIG_BACKLIGHT_GENERIC is not set
786788
CONFIG_BACKLIGHT_GPIO=m
787789
CONFIG_FRAMEBUFFER_CONSOLE=y

drivers/input/joystick/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,12 @@ config JOYSTICK_MAPLE
329329
To compile this as a module choose M here: the module will be called
330330
maplecontrol.
331331

332+
config JOYSTICK_RPISENSE
333+
tristate "Raspberry Pi Sense HAT joystick"
334+
depends on GPIOLIB && INPUT
335+
select MFD_RPISENSE_CORE
336+
337+
help
338+
This is the joystick driver for the Raspberry Pi Sense HAT
339+
332340
endif

drivers/input/joystick/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o
3232
obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
3333
obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
3434
obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o
35+
obj-$(CONFIG_JOYSTICK_RPISENSE) += rpisense-js.o
3536

drivers/input/joystick/rpisense-js.c

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Raspberry Pi Sense HAT joystick driver
3+
* http://raspberrypi.org
4+
*
5+
* Copyright (C) 2015 Raspberry Pi
6+
*
7+
* Author: Serge Schneider
8+
*
9+
* This program is free software; you can redistribute it and/or modify it
10+
* under the terms of the GNU General Public License as published by the
11+
* Free Software Foundation; either version 2 of the License, or (at your
12+
* option) any later version.
13+
*
14+
*/
15+
16+
#include <linux/module.h>
17+
18+
#include <linux/mfd/rpisense/joystick.h>
19+
#include <linux/mfd/rpisense/core.h>
20+
21+
struct rpisense *rpisense;
22+
unsigned char keymap[5] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,};
23+
24+
static void keys_work_fn(struct work_struct *work)
25+
{
26+
int i;
27+
static s32 prev_keys;
28+
struct rpisense_js *rpisense_js = &rpisense->joystick;
29+
s32 keys = rpisense_reg_read(rpisense, RPISENSE_KEYS);
30+
s32 changes = keys ^ prev_keys;
31+
32+
prev_keys = keys;
33+
for (i = 0; i < 5; i++) {
34+
if (changes & 1) {
35+
input_report_key(rpisense_js->keys_dev,
36+
keymap[i], keys & 1);
37+
}
38+
changes >>= 1;
39+
keys >>= 1;
40+
}
41+
input_sync(rpisense_js->keys_dev);
42+
}
43+
44+
static irqreturn_t keys_irq_handler(int irq, void *pdev)
45+
{
46+
struct rpisense_js *rpisense_js = &rpisense->joystick;
47+
48+
schedule_work(&rpisense_js->keys_work_s);
49+
return IRQ_HANDLED;
50+
}
51+
52+
static int rpisense_js_probe(struct platform_device *pdev)
53+
{
54+
int ret;
55+
int i;
56+
struct rpisense_js *rpisense_js;
57+
58+
rpisense = rpisense_get_dev();
59+
rpisense_js = &rpisense->joystick;
60+
61+
INIT_WORK(&rpisense_js->keys_work_s, keys_work_fn);
62+
63+
rpisense_js->keys_dev = input_allocate_device();
64+
if (!rpisense_js->keys_dev) {
65+
dev_err(&pdev->dev, "Could not allocate input device.\n");
66+
return -ENOMEM;
67+
}
68+
69+
rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY);
70+
for (i = 0; i < ARRAY_SIZE(keymap); i++) {
71+
set_bit(keymap[i],
72+
rpisense_js->keys_dev->keybit);
73+
}
74+
75+
rpisense_js->keys_dev->name = "Raspberry Pi Sense HAT Joystick";
76+
rpisense_js->keys_dev->phys = "rpi-sense-joy/input0";
77+
rpisense_js->keys_dev->id.bustype = BUS_I2C;
78+
rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
79+
rpisense_js->keys_dev->keycode = keymap;
80+
rpisense_js->keys_dev->keycodesize = sizeof(unsigned char);
81+
rpisense_js->keys_dev->keycodemax = ARRAY_SIZE(keymap);
82+
83+
ret = input_register_device(rpisense_js->keys_dev);
84+
if (ret) {
85+
dev_err(&pdev->dev, "Could not register input device.\n");
86+
goto err_keys_alloc;
87+
}
88+
89+
ret = gpiod_direction_input(rpisense_js->keys_desc);
90+
if (ret) {
91+
dev_err(&pdev->dev, "Could not set keys-int direction.\n");
92+
goto err_keys_reg;
93+
}
94+
95+
rpisense_js->keys_irq = gpiod_to_irq(rpisense_js->keys_desc);
96+
if (rpisense_js->keys_irq < 0) {
97+
dev_err(&pdev->dev, "Could not determine keys-int IRQ.\n");
98+
ret = rpisense_js->keys_irq;
99+
goto err_keys_reg;
100+
}
101+
102+
ret = devm_request_irq(&pdev->dev, rpisense_js->keys_irq,
103+
keys_irq_handler, IRQF_TRIGGER_RISING,
104+
"keys", &pdev->dev);
105+
if (ret) {
106+
dev_err(&pdev->dev, "IRQ request failed.\n");
107+
goto err_keys_reg;
108+
}
109+
return 0;
110+
err_keys_reg:
111+
input_unregister_device(rpisense_js->keys_dev);
112+
err_keys_alloc:
113+
input_free_device(rpisense_js->keys_dev);
114+
return ret;
115+
}
116+
117+
static int rpisense_js_remove(struct platform_device *pdev)
118+
{
119+
struct rpisense_js *rpisense_js = &rpisense->joystick;
120+
121+
input_unregister_device(rpisense_js->keys_dev);
122+
input_free_device(rpisense_js->keys_dev);
123+
return 0;
124+
}
125+
126+
#ifdef CONFIG_OF
127+
static const struct of_device_id rpisense_js_id[] = {
128+
{ .compatible = "rpi,rpi-sense-js" },
129+
{ },
130+
};
131+
MODULE_DEVICE_TABLE(of, rpisense_js_id);
132+
#endif
133+
134+
static struct platform_device_id rpisense_js_device_id[] = {
135+
{ .name = "rpi-sense-js" },
136+
{ },
137+
};
138+
MODULE_DEVICE_TABLE(platform, rpisense_js_device_id);
139+
140+
static struct platform_driver rpisense_js_driver = {
141+
.probe = rpisense_js_probe,
142+
.remove = rpisense_js_remove,
143+
.driver = {
144+
.name = "rpi-sense-js",
145+
.owner = THIS_MODULE,
146+
},
147+
};
148+
149+
module_platform_driver(rpisense_js_driver);
150+
151+
MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver");
152+
MODULE_AUTHOR("Serge Schneider <[email protected]>");
153+
MODULE_LICENSE("GPL");

drivers/mfd/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ config MFD_CORE
1010
select IRQ_DOMAIN
1111
default n
1212

13+
config MFD_RPISENSE_CORE
14+
tristate "Raspberry Pi Sense HAT core functions"
15+
depends on I2C
16+
select MFD_CORE
17+
help
18+
This is the core driver for the Raspberry Pi Sense HAT. This provides
19+
the necessary functions to communicate with the hardware.
20+
1321
config MFD_CS5535
1422
tristate "AMD CS5535 and CS5536 southbridge core functions"
1523
select MFD_CORE

drivers/mfd/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,5 @@ obj-$(CONFIG_MFD_RT5033) += rt5033.o
181181

182182
intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o
183183
obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o
184+
185+
obj-$(CONFIG_MFD_RPISENSE_CORE) += rpisense-core.o

0 commit comments

Comments
 (0)