1 From cf000173e9ee4a80ac245e5feb042c18c5643d6c Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <pelwell@users.noreply.github.com>
3 Date: Tue, 14 Jul 2015 14:32:47 +0100
4 Subject: [PATCH] mfd: Add Raspberry Pi Sense HAT core driver
6 mfd: Add rpi_sense_core of compatible string
8 drivers/input/joystick/Kconfig | 8 +
9 drivers/input/joystick/Makefile | 2 +-
10 drivers/input/joystick/rpisense-js.c | 153 ++++++++++++
11 drivers/mfd/Kconfig | 8 +
12 drivers/mfd/Makefile | 1 +
13 drivers/mfd/rpisense-core.c | 165 +++++++++++++
14 drivers/video/fbdev/Kconfig | 13 +
15 drivers/video/fbdev/Makefile | 1 +
16 drivers/video/fbdev/rpisense-fb.c | 293 +++++++++++++++++++++++
17 include/linux/mfd/rpisense/core.h | 47 ++++
18 include/linux/mfd/rpisense/framebuffer.h | 32 +++
19 include/linux/mfd/rpisense/joystick.h | 35 +++
20 12 files changed, 757 insertions(+), 1 deletion(-)
21 create mode 100644 drivers/input/joystick/rpisense-js.c
22 create mode 100644 drivers/mfd/rpisense-core.c
23 create mode 100644 drivers/video/fbdev/rpisense-fb.c
24 create mode 100644 include/linux/mfd/rpisense/core.h
25 create mode 100644 include/linux/mfd/rpisense/framebuffer.h
26 create mode 100644 include/linux/mfd/rpisense/joystick.h
28 --- a/drivers/input/joystick/Kconfig
29 +++ b/drivers/input/joystick/Kconfig
30 @@ -383,4 +383,12 @@ config JOYSTICK_FSIA6B
31 To compile this driver as a module, choose M here: the
32 module will be called fsia6b.
34 +config JOYSTICK_RPISENSE
35 + tristate "Raspberry Pi Sense HAT joystick"
36 + depends on GPIOLIB && INPUT
37 + select MFD_RPISENSE_CORE
40 + This is the joystick driver for the Raspberry Pi Sense HAT
43 --- a/drivers/input/joystick/Makefile
44 +++ b/drivers/input/joystick/Makefile
45 @@ -37,4 +37,4 @@ obj-$(CONFIG_JOYSTICK_WARRIOR) += warri
46 obj-$(CONFIG_JOYSTICK_WALKERA0701) += walkera0701.o
47 obj-$(CONFIG_JOYSTICK_XPAD) += xpad.o
48 obj-$(CONFIG_JOYSTICK_ZHENHUA) += zhenhua.o
50 +obj-$(CONFIG_JOYSTICK_RPISENSE) += rpisense-js.o
52 +++ b/drivers/input/joystick/rpisense-js.c
55 + * Raspberry Pi Sense HAT joystick driver
56 + * http://raspberrypi.org
58 + * Copyright (C) 2015 Raspberry Pi
60 + * Author: Serge Schneider
62 + * This program is free software; you can redistribute it and/or modify it
63 + * under the terms of the GNU General Public License as published by the
64 + * Free Software Foundation; either version 2 of the License, or (at your
65 + * option) any later version.
69 +#include <linux/module.h>
71 +#include <linux/mfd/rpisense/joystick.h>
72 +#include <linux/mfd/rpisense/core.h>
74 +static struct rpisense *rpisense;
75 +static unsigned char keymap[5] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,};
77 +static void keys_work_fn(struct work_struct *work)
80 + static s32 prev_keys;
81 + struct rpisense_js *rpisense_js = &rpisense->joystick;
82 + s32 keys = rpisense_reg_read(rpisense, RPISENSE_KEYS);
83 + s32 changes = keys ^ prev_keys;
86 + for (i = 0; i < 5; i++) {
88 + input_report_key(rpisense_js->keys_dev,
89 + keymap[i], keys & 1);
94 + input_sync(rpisense_js->keys_dev);
97 +static irqreturn_t keys_irq_handler(int irq, void *pdev)
99 + struct rpisense_js *rpisense_js = &rpisense->joystick;
101 + schedule_work(&rpisense_js->keys_work_s);
102 + return IRQ_HANDLED;
105 +static int rpisense_js_probe(struct platform_device *pdev)
109 + struct rpisense_js *rpisense_js;
111 + rpisense = rpisense_get_dev();
112 + rpisense_js = &rpisense->joystick;
114 + INIT_WORK(&rpisense_js->keys_work_s, keys_work_fn);
116 + rpisense_js->keys_dev = input_allocate_device();
117 + if (!rpisense_js->keys_dev) {
118 + dev_err(&pdev->dev, "Could not allocate input device.\n");
122 + rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY);
123 + for (i = 0; i < ARRAY_SIZE(keymap); i++) {
125 + rpisense_js->keys_dev->keybit);
128 + rpisense_js->keys_dev->name = "Raspberry Pi Sense HAT Joystick";
129 + rpisense_js->keys_dev->phys = "rpi-sense-joy/input0";
130 + rpisense_js->keys_dev->id.bustype = BUS_I2C;
131 + rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
132 + rpisense_js->keys_dev->keycode = keymap;
133 + rpisense_js->keys_dev->keycodesize = sizeof(unsigned char);
134 + rpisense_js->keys_dev->keycodemax = ARRAY_SIZE(keymap);
136 + ret = input_register_device(rpisense_js->keys_dev);
138 + dev_err(&pdev->dev, "Could not register input device.\n");
139 + goto err_keys_alloc;
142 + ret = gpiod_direction_input(rpisense_js->keys_desc);
144 + dev_err(&pdev->dev, "Could not set keys-int direction.\n");
148 + rpisense_js->keys_irq = gpiod_to_irq(rpisense_js->keys_desc);
149 + if (rpisense_js->keys_irq < 0) {
150 + dev_err(&pdev->dev, "Could not determine keys-int IRQ.\n");
151 + ret = rpisense_js->keys_irq;
155 + ret = devm_request_irq(&pdev->dev, rpisense_js->keys_irq,
156 + keys_irq_handler, IRQF_TRIGGER_RISING,
157 + "keys", &pdev->dev);
159 + dev_err(&pdev->dev, "IRQ request failed.\n");
164 + input_unregister_device(rpisense_js->keys_dev);
166 + input_free_device(rpisense_js->keys_dev);
170 +static int rpisense_js_remove(struct platform_device *pdev)
172 + struct rpisense_js *rpisense_js = &rpisense->joystick;
174 + input_unregister_device(rpisense_js->keys_dev);
175 + input_free_device(rpisense_js->keys_dev);
180 +static const struct of_device_id rpisense_js_id[] = {
181 + { .compatible = "rpi,rpi-sense-js" },
184 +MODULE_DEVICE_TABLE(of, rpisense_js_id);
187 +static struct platform_device_id rpisense_js_device_id[] = {
188 + { .name = "rpi-sense-js" },
191 +MODULE_DEVICE_TABLE(platform, rpisense_js_device_id);
193 +static struct platform_driver rpisense_js_driver = {
194 + .probe = rpisense_js_probe,
195 + .remove = rpisense_js_remove,
197 + .name = "rpi-sense-js",
198 + .owner = THIS_MODULE,
202 +module_platform_driver(rpisense_js_driver);
204 +MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver");
205 +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
206 +MODULE_LICENSE("GPL");
207 --- a/drivers/mfd/Kconfig
208 +++ b/drivers/mfd/Kconfig
209 @@ -11,6 +11,14 @@ config MFD_CORE
213 +config MFD_RPISENSE_CORE
214 + tristate "Raspberry Pi Sense HAT core functions"
218 + This is the core driver for the Raspberry Pi Sense HAT. This provides
219 + the necessary functions to communicate with the hardware.
222 tristate "AMD CS5535 and CS5536 southbridge core functions"
224 --- a/drivers/mfd/Makefile
225 +++ b/drivers/mfd/Makefile
226 @@ -263,6 +263,7 @@ obj-$(CONFIG_MFD_ROHM_BD71828) += rohm-b
227 obj-$(CONFIG_MFD_ROHM_BD718XX) += rohm-bd718x7.o
228 obj-$(CONFIG_MFD_STMFX) += stmfx.o
229 obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o
230 +obj-$(CONFIG_MFD_RPISENSE_CORE) += rpisense-core.o
232 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
233 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o
235 +++ b/drivers/mfd/rpisense-core.c
238 + * Raspberry Pi Sense HAT core driver
239 + * http://raspberrypi.org
241 + * Copyright (C) 2015 Raspberry Pi
243 + * Author: Serge Schneider
245 + * This program is free software; you can redistribute it and/or modify it
246 + * under the terms of the GNU General Public License as published by the
247 + * Free Software Foundation; either version 2 of the License, or (at your
248 + * option) any later version.
250 + * This driver is based on wm8350 implementation.
253 +#include <linux/module.h>
254 +#include <linux/moduleparam.h>
255 +#include <linux/err.h>
256 +#include <linux/init.h>
257 +#include <linux/i2c.h>
258 +#include <linux/platform_device.h>
259 +#include <linux/mfd/rpisense/core.h>
260 +#include <linux/slab.h>
262 +static struct rpisense *rpisense;
264 +static void rpisense_client_dev_register(struct rpisense *rpisense,
266 + struct platform_device **pdev)
270 + *pdev = platform_device_alloc(name, -1);
271 + if (*pdev == NULL) {
272 + dev_err(rpisense->dev, "Failed to allocate %s\n", name);
276 + (*pdev)->dev.parent = rpisense->dev;
277 + platform_set_drvdata(*pdev, rpisense);
278 + ret = platform_device_add(*pdev);
280 + dev_err(rpisense->dev, "Failed to register %s: %d\n",
282 + platform_device_put(*pdev);
287 +static int rpisense_probe(struct i2c_client *i2c,
288 + const struct i2c_device_id *id)
291 + struct rpisense_js *rpisense_js;
293 + rpisense = devm_kzalloc(&i2c->dev, sizeof(struct rpisense), GFP_KERNEL);
294 + if (rpisense == NULL)
297 + i2c_set_clientdata(i2c, rpisense);
298 + rpisense->dev = &i2c->dev;
299 + rpisense->i2c_client = i2c;
301 + ret = rpisense_reg_read(rpisense, RPISENSE_WAI);
308 + ret = rpisense_reg_read(rpisense, RPISENSE_VER);
312 + dev_info(rpisense->dev,
313 + "Raspberry Pi Sense HAT firmware version %i\n", ret);
315 + rpisense_js = &rpisense->joystick;
316 + rpisense_js->keys_desc = devm_gpiod_get(&i2c->dev,
317 + "keys-int", GPIOD_IN);
318 + if (IS_ERR(rpisense_js->keys_desc)) {
319 + dev_warn(&i2c->dev, "Failed to get keys-int descriptor.\n");
320 + rpisense_js->keys_desc = gpio_to_desc(23);
321 + if (rpisense_js->keys_desc == NULL) {
322 + dev_err(&i2c->dev, "GPIO23 fallback failed.\n");
323 + return PTR_ERR(rpisense_js->keys_desc);
326 + rpisense_client_dev_register(rpisense, "rpi-sense-js",
327 + &(rpisense->joystick.pdev));
328 + rpisense_client_dev_register(rpisense, "rpi-sense-fb",
329 + &(rpisense->framebuffer.pdev));
334 +static int rpisense_remove(struct i2c_client *i2c)
336 + struct rpisense *rpisense = i2c_get_clientdata(i2c);
338 + platform_device_unregister(rpisense->joystick.pdev);
342 +struct rpisense *rpisense_get_dev(void)
346 +EXPORT_SYMBOL_GPL(rpisense_get_dev);
348 +s32 rpisense_reg_read(struct rpisense *rpisense, int reg)
350 + int ret = i2c_smbus_read_byte_data(rpisense->i2c_client, reg);
353 + dev_err(rpisense->dev, "Read from reg %d failed\n", reg);
354 + /* Due to the BCM270x I2C clock stretching bug, some values
355 + * may have MSB set. Clear it to avoid incorrect values.
359 +EXPORT_SYMBOL_GPL(rpisense_reg_read);
361 +int rpisense_block_write(struct rpisense *rpisense, const char *buf, int count)
363 + int ret = i2c_master_send(rpisense->i2c_client, buf, count);
366 + dev_err(rpisense->dev, "Block write failed\n");
369 +EXPORT_SYMBOL_GPL(rpisense_block_write);
371 +static const struct i2c_device_id rpisense_i2c_id[] = {
372 + { "rpi-sense", 0 },
375 +MODULE_DEVICE_TABLE(i2c, rpisense_i2c_id);
378 +static const struct of_device_id rpisense_core_id[] = {
379 + { .compatible = "rpi,rpi-sense" },
382 +MODULE_DEVICE_TABLE(of, rpisense_core_id);
386 +static struct i2c_driver rpisense_driver = {
388 + .name = "rpi-sense",
389 + .owner = THIS_MODULE,
391 + .probe = rpisense_probe,
392 + .remove = rpisense_remove,
393 + .id_table = rpisense_i2c_id,
396 +module_i2c_driver(rpisense_driver);
398 +MODULE_DESCRIPTION("Raspberry Pi Sense HAT core driver");
399 +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
400 +MODULE_LICENSE("GPL");
402 --- a/drivers/video/fbdev/Kconfig
403 +++ b/drivers/video/fbdev/Kconfig
404 @@ -2249,6 +2249,19 @@ config FB_SM712
405 called sm712fb. If you want to compile it as a module, say M
406 here and read <file:Documentation/kbuild/modules.rst>.
409 + tristate "Raspberry Pi Sense HAT framebuffer"
411 + select MFD_RPISENSE_CORE
413 + select FB_SYS_FILLRECT
414 + select FB_SYS_COPYAREA
415 + select FB_SYS_IMAGEBLIT
416 + select FB_DEFERRED_IO
419 + This is the framebuffer driver for the Raspberry Pi Sense HAT
421 source "drivers/video/fbdev/omap/Kconfig"
422 source "drivers/video/fbdev/omap2/Kconfig"
423 source "drivers/video/fbdev/mmp/Kconfig"
424 --- a/drivers/video/fbdev/Makefile
425 +++ b/drivers/video/fbdev/Makefile
426 @@ -130,6 +130,7 @@ obj-$(CONFIG_FB_MX3) += mx3fb.o
427 obj-$(CONFIG_FB_DA8XX) += da8xx-fb.o
428 obj-$(CONFIG_FB_SSD1307) += ssd1307fb.o
429 obj-$(CONFIG_FB_SIMPLE) += simplefb.o
430 +obj-$(CONFIG_FB_RPISENSE) += rpisense-fb.o
432 # the test framebuffer is last
433 obj-$(CONFIG_FB_VIRTUAL) += vfb.o
435 +++ b/drivers/video/fbdev/rpisense-fb.c
438 + * Raspberry Pi Sense HAT framebuffer driver
439 + * http://raspberrypi.org
441 + * Copyright (C) 2015 Raspberry Pi
443 + * Author: Serge Schneider
445 + * This program is free software; you can redistribute it and/or modify it
446 + * under the terms of the GNU General Public License as published by the
447 + * Free Software Foundation; either version 2 of the License, or (at your
448 + * option) any later version.
452 +#include <linux/module.h>
453 +#include <linux/kernel.h>
454 +#include <linux/errno.h>
455 +#include <linux/string.h>
456 +#include <linux/mm.h>
457 +#include <linux/slab.h>
458 +#include <linux/uaccess.h>
459 +#include <linux/delay.h>
460 +#include <linux/fb.h>
461 +#include <linux/init.h>
463 +#include <linux/mfd/rpisense/framebuffer.h>
464 +#include <linux/mfd/rpisense/core.h>
466 +static bool lowlight;
467 +module_param(lowlight, bool, 0);
468 +MODULE_PARM_DESC(lowlight, "Reduce LED matrix brightness to one third");
470 +static struct rpisense *rpisense;
472 +struct rpisense_fb_param {
473 + char __iomem *vmem;
479 +static u8 gamma_default[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
480 + 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07,
481 + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11,
482 + 0x12, 0x14, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F,};
484 +static u8 gamma_low[32] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
485 + 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02,
486 + 0x03, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06,
487 + 0x06, 0x07, 0x07, 0x08, 0x08, 0x09, 0x0A, 0x0A,};
489 +static u8 gamma_user[32];
491 +static struct rpisense_fb_param rpisense_fb_param = {
494 + .gamma = gamma_default,
497 +static struct fb_deferred_io rpisense_fb_defio;
499 +static struct fb_fix_screeninfo rpisense_fb_fix = {
500 + .id = "RPi-Sense FB",
501 + .type = FB_TYPE_PACKED_PIXELS,
502 + .visual = FB_VISUAL_TRUECOLOR,
506 + .accel = FB_ACCEL_NONE,
510 +static struct fb_var_screeninfo rpisense_fb_var = {
515 + .bits_per_pixel = 16,
517 + .green = {5, 6, 0},
521 +static ssize_t rpisense_fb_write(struct fb_info *info,
522 + const char __user *buf, size_t count,
525 + ssize_t res = fb_sys_write(info, buf, count, ppos);
527 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
531 +static void rpisense_fb_fillrect(struct fb_info *info,
532 + const struct fb_fillrect *rect)
534 + sys_fillrect(info, rect);
535 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
538 +static void rpisense_fb_copyarea(struct fb_info *info,
539 + const struct fb_copyarea *area)
541 + sys_copyarea(info, area);
542 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
545 +static void rpisense_fb_imageblit(struct fb_info *info,
546 + const struct fb_image *image)
548 + sys_imageblit(info, image);
549 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
552 +static void rpisense_fb_deferred_io(struct fb_info *info,
553 + struct list_head *pagelist)
557 + u8 *vmem_work = rpisense_fb_param.vmem_work;
558 + u16 *mem = (u16 *)rpisense_fb_param.vmem;
559 + u8 *gamma = rpisense_fb_param.gamma;
562 + for (j = 0; j < 8; j++) {
563 + for (i = 0; i < 8; i++) {
564 + vmem_work[(j * 24) + i + 1] =
565 + gamma[(mem[(j * 8) + i] >> 11) & 0x1F];
566 + vmem_work[(j * 24) + (i + 8) + 1] =
567 + gamma[(mem[(j * 8) + i] >> 6) & 0x1F];
568 + vmem_work[(j * 24) + (i + 16) + 1] =
569 + gamma[(mem[(j * 8) + i]) & 0x1F];
572 + rpisense_block_write(rpisense, vmem_work, 193);
575 +static struct fb_deferred_io rpisense_fb_defio = {
577 + .deferred_io = rpisense_fb_deferred_io,
580 +static int rpisense_fb_ioctl(struct fb_info *info, unsigned int cmd,
584 + case SENSEFB_FBIOGET_GAMMA:
585 + if (copy_to_user((void __user *) arg, rpisense_fb_param.gamma,
589 + case SENSEFB_FBIOSET_GAMMA:
590 + if (copy_from_user(gamma_user, (void __user *)arg,
593 + rpisense_fb_param.gamma = gamma_user;
594 + schedule_delayed_work(&info->deferred_work,
595 + rpisense_fb_defio.delay);
597 + case SENSEFB_FBIORESET_GAMMA:
600 + rpisense_fb_param.gamma = gamma_default;
603 + rpisense_fb_param.gamma = gamma_low;
606 + rpisense_fb_param.gamma = gamma_user;
611 + schedule_delayed_work(&info->deferred_work,
612 + rpisense_fb_defio.delay);
620 +static struct fb_ops rpisense_fb_ops = {
621 + .owner = THIS_MODULE,
622 + .fb_read = fb_sys_read,
623 + .fb_write = rpisense_fb_write,
624 + .fb_fillrect = rpisense_fb_fillrect,
625 + .fb_copyarea = rpisense_fb_copyarea,
626 + .fb_imageblit = rpisense_fb_imageblit,
627 + .fb_ioctl = rpisense_fb_ioctl,
630 +static int rpisense_fb_probe(struct platform_device *pdev)
632 + struct fb_info *info;
634 + struct rpisense_fb *rpisense_fb;
636 + rpisense = rpisense_get_dev();
637 + rpisense_fb = &rpisense->framebuffer;
639 + rpisense_fb_param.vmem = vzalloc(rpisense_fb_param.vmemsize);
640 + if (!rpisense_fb_param.vmem)
643 + rpisense_fb_param.vmem_work = devm_kmalloc(&pdev->dev, 193, GFP_KERNEL);
644 + if (!rpisense_fb_param.vmem_work)
647 + info = framebuffer_alloc(0, &pdev->dev);
649 + dev_err(&pdev->dev, "Could not allocate framebuffer.\n");
652 + rpisense_fb->info = info;
654 + rpisense_fb_fix.smem_start = (unsigned long)rpisense_fb_param.vmem;
655 + rpisense_fb_fix.smem_len = rpisense_fb_param.vmemsize;
657 + info->fbops = &rpisense_fb_ops;
658 + info->fix = rpisense_fb_fix;
659 + info->var = rpisense_fb_var;
660 + info->fbdefio = &rpisense_fb_defio;
661 + info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
662 + info->screen_base = rpisense_fb_param.vmem;
663 + info->screen_size = rpisense_fb_param.vmemsize;
666 + rpisense_fb_param.gamma = gamma_low;
668 + fb_deferred_io_init(info);
670 + ret = register_framebuffer(info);
672 + dev_err(&pdev->dev, "Could not register framebuffer.\n");
676 + fb_info(info, "%s frame buffer device\n", info->fix.id);
677 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
680 + framebuffer_release(info);
682 + vfree(rpisense_fb_param.vmem);
686 +static int rpisense_fb_remove(struct platform_device *pdev)
688 + struct rpisense_fb *rpisense_fb = &rpisense->framebuffer;
689 + struct fb_info *info = rpisense_fb->info;
692 + unregister_framebuffer(info);
693 + fb_deferred_io_cleanup(info);
694 + framebuffer_release(info);
695 + vfree(rpisense_fb_param.vmem);
702 +static const struct of_device_id rpisense_fb_id[] = {
703 + { .compatible = "rpi,rpi-sense-fb" },
706 +MODULE_DEVICE_TABLE(of, rpisense_fb_id);
709 +static struct platform_device_id rpisense_fb_device_id[] = {
710 + { .name = "rpi-sense-fb" },
713 +MODULE_DEVICE_TABLE(platform, rpisense_fb_device_id);
715 +static struct platform_driver rpisense_fb_driver = {
716 + .probe = rpisense_fb_probe,
717 + .remove = rpisense_fb_remove,
719 + .name = "rpi-sense-fb",
720 + .owner = THIS_MODULE,
724 +module_platform_driver(rpisense_fb_driver);
726 +MODULE_DESCRIPTION("Raspberry Pi Sense HAT framebuffer driver");
727 +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
728 +MODULE_LICENSE("GPL");
731 +++ b/include/linux/mfd/rpisense/core.h
734 + * Raspberry Pi Sense HAT core driver
735 + * http://raspberrypi.org
737 + * Copyright (C) 2015 Raspberry Pi
739 + * Author: Serge Schneider
741 + * This program is free software; you can redistribute it and/or modify it
742 + * under the terms of the GNU General Public License as published by the
743 + * Free Software Foundation; either version 2 of the License, or (at your
744 + * option) any later version.
748 +#ifndef __LINUX_MFD_RPISENSE_CORE_H_
749 +#define __LINUX_MFD_RPISENSE_CORE_H_
751 +#include <linux/mfd/rpisense/joystick.h>
752 +#include <linux/mfd/rpisense/framebuffer.h>
757 +#define RPISENSE_FB 0x00
758 +#define RPISENSE_WAI 0xF0
759 +#define RPISENSE_VER 0xF1
760 +#define RPISENSE_KEYS 0xF2
761 +#define RPISENSE_EE_WP 0xF3
763 +#define RPISENSE_ID 's'
766 + struct device *dev;
767 + struct i2c_client *i2c_client;
769 + /* Client devices */
770 + struct rpisense_js joystick;
771 + struct rpisense_fb framebuffer;
774 +struct rpisense *rpisense_get_dev(void);
775 +s32 rpisense_reg_read(struct rpisense *rpisense, int reg);
776 +int rpisense_reg_write(struct rpisense *rpisense, int reg, u16 val);
777 +int rpisense_block_write(struct rpisense *rpisense, const char *buf, int count);
781 +++ b/include/linux/mfd/rpisense/framebuffer.h
784 + * Raspberry Pi Sense HAT framebuffer driver
785 + * http://raspberrypi.org
787 + * Copyright (C) 2015 Raspberry Pi
789 + * Author: Serge Schneider
791 + * This program is free software; you can redistribute it and/or modify it
792 + * under the terms of the GNU General Public License as published by the
793 + * Free Software Foundation; either version 2 of the License, or (at your
794 + * option) any later version.
798 +#ifndef __LINUX_RPISENSE_FB_H_
799 +#define __LINUX_RPISENSE_FB_H_
801 +#define SENSEFB_FBIO_IOC_MAGIC 0xF1
803 +#define SENSEFB_FBIOGET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 0)
804 +#define SENSEFB_FBIOSET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 1)
805 +#define SENSEFB_FBIORESET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 2)
809 +struct rpisense_fb {
810 + struct platform_device *pdev;
811 + struct fb_info *info;
816 +++ b/include/linux/mfd/rpisense/joystick.h
819 + * Raspberry Pi Sense HAT joystick driver
820 + * http://raspberrypi.org
822 + * Copyright (C) 2015 Raspberry Pi
824 + * Author: Serge Schneider
826 + * This program is free software; you can redistribute it and/or modify it
827 + * under the terms of the GNU General Public License as published by the
828 + * Free Software Foundation; either version 2 of the License, or (at your
829 + * option) any later version.
833 +#ifndef __LINUX_RPISENSE_JOYSTICK_H_
834 +#define __LINUX_RPISENSE_JOYSTICK_H_
836 +#include <linux/input.h>
837 +#include <linux/interrupt.h>
838 +#include <linux/gpio/consumer.h>
839 +#include <linux/platform_device.h>
843 +struct rpisense_js {
844 + struct platform_device *pdev;
845 + struct input_dev *keys_dev;
846 + struct gpio_desc *keys_desc;
847 + struct work_struct keys_work_s;