Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mfd: Add Raspberry Pi Sense HAT core driver #1043

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm/boot/dts/overlays/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ dtb-$(RPI_DT_OVERLAYS) += rpi-dac-overlay.dtb
dtb-$(RPI_DT_OVERLAYS) += rpi-display-overlay.dtb
dtb-$(RPI_DT_OVERLAYS) += rpi-ft5406-overlay.dtb
dtb-$(RPI_DT_OVERLAYS) += rpi-proto-overlay.dtb
dtb-$(RPI_DT_OVERLAYS) += rpi-sense-overlay.dtb
dtb-$(RPI_DT_OVERLAYS) += sdhost-overlay.dtb
dtb-$(RPI_DT_OVERLAYS) += spi-bcm2708-overlay.dtb
dtb-$(RPI_DT_OVERLAYS) += spi-bcm2835-overlay.dtb
Expand Down
6 changes: 6 additions & 0 deletions arch/arm/boot/dts/overlays/README
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ Load: dtoverlay=rpi-proto
Params: <None>


Name: rpi-sense
Info: Raspberry Pi Sense HAT
Load: dtoverlay=rpi-sense
Params: <None>


Name: sdhost
Info: Selects the bcm2835-sdhost SD/MMC driver, optionally with overclock
Load: dtoverlay=sdhost,<param>=<val>
Expand Down
47 changes: 47 additions & 0 deletions arch/arm/boot/dts/overlays/rpi-sense-overlay.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// rpi-sense HAT
/dts-v1/;
/plugin/;

/ {
compatible = "brcm,bcm2708", "brcm,bcm2709";

fragment@0 {
target = <&i2c1>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;
status = "okay";

rpi-sense@46 {
compatible = "rpi,rpi-sense";
reg = <0x46>;
keys-int-gpios = <&gpio 23 1>;
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";
reg = <0x5f>;
status = "okay";
};
};
};
};
2 changes: 2 additions & 0 deletions arch/arm/configs/bcm2709_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ CONFIG_JOYSTICK_IFORCE=m
CONFIG_JOYSTICK_IFORCE_USB=y
CONFIG_JOYSTICK_XPAD=m
CONFIG_JOYSTICK_XPAD_FF=y
CONFIG_JOYSTICK_RPISENSE=m
CONFIG_INPUT_TOUCHSCREEN=y
CONFIG_TOUCHSCREEN_ADS7846=m
CONFIG_TOUCHSCREEN_EGALAX=m
Expand Down Expand Up @@ -789,6 +790,7 @@ CONFIG_VIDEO_MT9V011=m
CONFIG_FB=y
CONFIG_FB_BCM2708=y
CONFIG_FB_SSD1307=m
CONFIG_FB_RPISENSE=m
# CONFIG_BACKLIGHT_GENERIC is not set
CONFIG_BACKLIGHT_GPIO=m
CONFIG_FRAMEBUFFER_CONSOLE=y
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/configs/bcmrpi_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ CONFIG_JOYSTICK_IFORCE=m
CONFIG_JOYSTICK_IFORCE_USB=y
CONFIG_JOYSTICK_XPAD=m
CONFIG_JOYSTICK_XPAD_FF=y
CONFIG_JOYSTICK_RPISENSE=m
CONFIG_INPUT_TOUCHSCREEN=y
CONFIG_TOUCHSCREEN_ADS7846=m
CONFIG_TOUCHSCREEN_EGALAX=m
Expand Down Expand Up @@ -782,6 +783,7 @@ CONFIG_VIDEO_MT9V011=m
CONFIG_FB=y
CONFIG_FB_BCM2708=y
CONFIG_FB_SSD1307=m
CONFIG_FB_RPISENSE=m
# CONFIG_BACKLIGHT_GENERIC is not set
CONFIG_BACKLIGHT_GPIO=m
CONFIG_FRAMEBUFFER_CONSOLE=y
Expand Down
8 changes: 8 additions & 0 deletions drivers/input/joystick/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,12 @@ config JOYSTICK_MAPLE
To compile this as a module choose M here: the module will be called
maplecontrol.

config JOYSTICK_RPISENSE
tristate "Raspberry Pi Sense HAT joystick"
depends on GPIOLIB && INPUT
select MFD_RPISENSE_CORE

help
This is the joystick driver for the Raspberry Pi Sense HAT

endif
1 change: 1 addition & 0 deletions drivers/input/joystick/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ obj-$(CONFIG_JOYSTICK_WARRIOR) += warrior.o
obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o
obj-$(CONFIG_JOYSTICK_RPISENSE) += rpisense-js.o

153 changes: 153 additions & 0 deletions drivers/input/joystick/rpisense-js.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Raspberry Pi Sense HAT joystick driver
* http://raspberrypi.org
*
* Copyright (C) 2015 Raspberry Pi
*
* Author: Serge Schneider
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
*/

#include <linux/module.h>

#include <linux/mfd/rpisense/joystick.h>
#include <linux/mfd/rpisense/core.h>

struct rpisense *rpisense;
unsigned char keymap[5] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,};

static void keys_work_fn(struct work_struct *work)
{
int i;
static s32 prev_keys;
struct rpisense_js *rpisense_js = &rpisense->joystick;
s32 keys = rpisense_reg_read(rpisense, RPISENSE_KEYS);
s32 changes = keys ^ prev_keys;

prev_keys = keys;
for (i = 0; i < 5; i++) {
if (changes & 1) {
input_report_key(rpisense_js->keys_dev,
keymap[i], keys & 1);
}
changes >>= 1;
keys >>= 1;
}
input_sync(rpisense_js->keys_dev);
}

static irqreturn_t keys_irq_handler(int irq, void *pdev)
{
struct rpisense_js *rpisense_js = &rpisense->joystick;

schedule_work(&rpisense_js->keys_work_s);
return IRQ_HANDLED;
}

static int rpisense_js_probe(struct platform_device *pdev)
{
int ret;
int i;
struct rpisense_js *rpisense_js;

rpisense = rpisense_get_dev();
rpisense_js = &rpisense->joystick;

INIT_WORK(&rpisense_js->keys_work_s, keys_work_fn);

rpisense_js->keys_dev = input_allocate_device();
if (!rpisense_js->keys_dev) {
dev_err(&pdev->dev, "Could not allocate input device.\n");
return -ENOMEM;
}

rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY);
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");
goto err_keys_alloc;
}

ret = gpiod_direction_input(rpisense_js->keys_desc);
if (ret) {
dev_err(&pdev->dev, "Could not set keys-int direction.\n");
goto err_keys_reg;
}

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");
ret = rpisense_js->keys_irq;
goto err_keys_reg;
}

ret = devm_request_irq(&pdev->dev, rpisense_js->keys_irq,
keys_irq_handler, IRQF_TRIGGER_RISING,
"keys", &pdev->dev);
if (ret) {
dev_err(&pdev->dev, "IRQ request failed.\n");
goto err_keys_reg;
}
return 0;
err_keys_reg:
input_unregister_device(rpisense_js->keys_dev);
err_keys_alloc:
input_free_device(rpisense_js->keys_dev);
return ret;
}

static int rpisense_js_remove(struct platform_device *pdev)
{
struct rpisense_js *rpisense_js = &rpisense->joystick;

input_unregister_device(rpisense_js->keys_dev);
input_free_device(rpisense_js->keys_dev);
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 = {
.probe = rpisense_js_probe,
.remove = rpisense_js_remove,
.driver = {
.name = "rpi-sense-js",
.owner = THIS_MODULE,
},
};

module_platform_driver(rpisense_js_driver);

MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver");
MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
MODULE_LICENSE("GPL");
8 changes: 8 additions & 0 deletions drivers/mfd/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ config MFD_CORE
select IRQ_DOMAIN
default n

config MFD_RPISENSE_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
Expand Down
2 changes: 2 additions & 0 deletions drivers/mfd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,5 @@ obj-$(CONFIG_MFD_RT5033) += rt5033.o

intel-soc-pmic-objs := intel_soc_pmic_core.o intel_soc_pmic_crc.o
obj-$(CONFIG_INTEL_SOC_PMIC) += intel-soc-pmic.o

obj-$(CONFIG_MFD_RPISENSE_CORE) += rpisense-core.o
Loading