1 From 55156257cde6621241755a89527280404c488da1 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 | 1 +
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(+)
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 @@ -400,4 +400,12 @@ config JOYSTICK_N64
31 Say Y here if you want enable support for the four
32 built-in controller ports on the Nintendo 64 console.
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 @@ -39,3 +39,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
49 +obj-$(CONFIG_JOYSTICK_RPISENSE) += rpisense-js.o
51 +++ b/drivers/input/joystick/rpisense-js.c
54 + * Raspberry Pi Sense HAT joystick driver
55 + * http://raspberrypi.org
57 + * Copyright (C) 2015 Raspberry Pi
59 + * Author: Serge Schneider
61 + * This program is free software; you can redistribute it and/or modify it
62 + * under the terms of the GNU General Public License as published by the
63 + * Free Software Foundation; either version 2 of the License, or (at your
64 + * option) any later version.
68 +#include <linux/module.h>
70 +#include <linux/mfd/rpisense/joystick.h>
71 +#include <linux/mfd/rpisense/core.h>
73 +static struct rpisense *rpisense;
74 +static unsigned char keymap[5] = {KEY_DOWN, KEY_RIGHT, KEY_UP, KEY_ENTER, KEY_LEFT,};
76 +static void keys_work_fn(struct work_struct *work)
79 + static s32 prev_keys;
80 + struct rpisense_js *rpisense_js = &rpisense->joystick;
81 + s32 keys = rpisense_reg_read(rpisense, RPISENSE_KEYS);
82 + s32 changes = keys ^ prev_keys;
85 + for (i = 0; i < 5; i++) {
87 + input_report_key(rpisense_js->keys_dev,
88 + keymap[i], keys & 1);
93 + input_sync(rpisense_js->keys_dev);
96 +static irqreturn_t keys_irq_handler(int irq, void *pdev)
98 + struct rpisense_js *rpisense_js = &rpisense->joystick;
100 + schedule_work(&rpisense_js->keys_work_s);
101 + return IRQ_HANDLED;
104 +static int rpisense_js_probe(struct platform_device *pdev)
108 + struct rpisense_js *rpisense_js;
110 + rpisense = rpisense_get_dev();
111 + rpisense_js = &rpisense->joystick;
113 + INIT_WORK(&rpisense_js->keys_work_s, keys_work_fn);
115 + rpisense_js->keys_dev = input_allocate_device();
116 + if (!rpisense_js->keys_dev) {
117 + dev_err(&pdev->dev, "Could not allocate input device.\n");
121 + rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY);
122 + for (i = 0; i < ARRAY_SIZE(keymap); i++) {
124 + rpisense_js->keys_dev->keybit);
127 + rpisense_js->keys_dev->name = "Raspberry Pi Sense HAT Joystick";
128 + rpisense_js->keys_dev->phys = "rpi-sense-joy/input0";
129 + rpisense_js->keys_dev->id.bustype = BUS_I2C;
130 + rpisense_js->keys_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
131 + rpisense_js->keys_dev->keycode = keymap;
132 + rpisense_js->keys_dev->keycodesize = sizeof(unsigned char);
133 + rpisense_js->keys_dev->keycodemax = ARRAY_SIZE(keymap);
135 + ret = input_register_device(rpisense_js->keys_dev);
137 + dev_err(&pdev->dev, "Could not register input device.\n");
138 + goto err_keys_alloc;
141 + ret = gpiod_direction_input(rpisense_js->keys_desc);
143 + dev_err(&pdev->dev, "Could not set keys-int direction.\n");
147 + rpisense_js->keys_irq = gpiod_to_irq(rpisense_js->keys_desc);
148 + if (rpisense_js->keys_irq < 0) {
149 + dev_err(&pdev->dev, "Could not determine keys-int IRQ.\n");
150 + ret = rpisense_js->keys_irq;
154 + ret = devm_request_irq(&pdev->dev, rpisense_js->keys_irq,
155 + keys_irq_handler, IRQF_TRIGGER_RISING,
156 + "keys", &pdev->dev);
158 + dev_err(&pdev->dev, "IRQ request failed.\n");
163 + input_unregister_device(rpisense_js->keys_dev);
165 + input_free_device(rpisense_js->keys_dev);
169 +static int rpisense_js_remove(struct platform_device *pdev)
171 + struct rpisense_js *rpisense_js = &rpisense->joystick;
173 + input_unregister_device(rpisense_js->keys_dev);
174 + input_free_device(rpisense_js->keys_dev);
179 +static const struct of_device_id rpisense_js_id[] = {
180 + { .compatible = "rpi,rpi-sense-js" },
183 +MODULE_DEVICE_TABLE(of, rpisense_js_id);
186 +static struct platform_device_id rpisense_js_device_id[] = {
187 + { .name = "rpi-sense-js" },
190 +MODULE_DEVICE_TABLE(platform, rpisense_js_device_id);
192 +static struct platform_driver rpisense_js_driver = {
193 + .probe = rpisense_js_probe,
194 + .remove = rpisense_js_remove,
196 + .name = "rpi-sense-js",
197 + .owner = THIS_MODULE,
201 +module_platform_driver(rpisense_js_driver);
203 +MODULE_DESCRIPTION("Raspberry Pi Sense HAT joystick driver");
204 +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
205 +MODULE_LICENSE("GPL");
206 --- a/drivers/mfd/Kconfig
207 +++ b/drivers/mfd/Kconfig
208 @@ -11,6 +11,14 @@ config MFD_CORE
212 +config MFD_RPISENSE_CORE
213 + tristate "Raspberry Pi Sense HAT core functions"
217 + This is the core driver for the Raspberry Pi Sense HAT. This provides
218 + the necessary functions to communicate with the hardware.
221 tristate "AMD CS5535 and CS5536 southbridge core functions"
223 --- a/drivers/mfd/Makefile
224 +++ b/drivers/mfd/Makefile
225 @@ -266,6 +266,7 @@ obj-$(CONFIG_MFD_STMFX) += stmfx.o
226 obj-$(CONFIG_MFD_KHADAS_MCU) += khadas-mcu.o
227 obj-$(CONFIG_MFD_ACER_A500_EC) += acer-ec-a500.o
228 obj-$(CONFIG_MFD_QCOM_PM8008) += qcom-pm8008.o
229 +obj-$(CONFIG_MFD_RPISENSE_CORE) += rpisense-core.o
231 obj-$(CONFIG_SGI_MFD_IOC3) += ioc3.o
232 obj-$(CONFIG_MFD_SIMPLE_MFD_I2C) += simple-mfd-i2c.o
234 +++ b/drivers/mfd/rpisense-core.c
237 + * Raspberry Pi Sense HAT core driver
238 + * http://raspberrypi.org
240 + * Copyright (C) 2015 Raspberry Pi
242 + * Author: Serge Schneider
244 + * This program is free software; you can redistribute it and/or modify it
245 + * under the terms of the GNU General Public License as published by the
246 + * Free Software Foundation; either version 2 of the License, or (at your
247 + * option) any later version.
249 + * This driver is based on wm8350 implementation.
252 +#include <linux/module.h>
253 +#include <linux/moduleparam.h>
254 +#include <linux/err.h>
255 +#include <linux/init.h>
256 +#include <linux/i2c.h>
257 +#include <linux/platform_device.h>
258 +#include <linux/mfd/rpisense/core.h>
259 +#include <linux/slab.h>
261 +static struct rpisense *rpisense;
263 +static void rpisense_client_dev_register(struct rpisense *rpisense,
265 + struct platform_device **pdev)
269 + *pdev = platform_device_alloc(name, -1);
270 + if (*pdev == NULL) {
271 + dev_err(rpisense->dev, "Failed to allocate %s\n", name);
275 + (*pdev)->dev.parent = rpisense->dev;
276 + platform_set_drvdata(*pdev, rpisense);
277 + ret = platform_device_add(*pdev);
279 + dev_err(rpisense->dev, "Failed to register %s: %d\n",
281 + platform_device_put(*pdev);
286 +static int rpisense_probe(struct i2c_client *i2c,
287 + const struct i2c_device_id *id)
290 + struct rpisense_js *rpisense_js;
292 + rpisense = devm_kzalloc(&i2c->dev, sizeof(struct rpisense), GFP_KERNEL);
293 + if (rpisense == NULL)
296 + i2c_set_clientdata(i2c, rpisense);
297 + rpisense->dev = &i2c->dev;
298 + rpisense->i2c_client = i2c;
300 + ret = rpisense_reg_read(rpisense, RPISENSE_WAI);
307 + ret = rpisense_reg_read(rpisense, RPISENSE_VER);
311 + dev_info(rpisense->dev,
312 + "Raspberry Pi Sense HAT firmware version %i\n", ret);
314 + rpisense_js = &rpisense->joystick;
315 + rpisense_js->keys_desc = devm_gpiod_get(&i2c->dev,
316 + "keys-int", GPIOD_IN);
317 + if (IS_ERR(rpisense_js->keys_desc)) {
318 + dev_warn(&i2c->dev, "Failed to get keys-int descriptor.\n");
319 + rpisense_js->keys_desc = gpio_to_desc(23);
320 + if (rpisense_js->keys_desc == NULL) {
321 + dev_err(&i2c->dev, "GPIO23 fallback failed.\n");
322 + return PTR_ERR(rpisense_js->keys_desc);
325 + rpisense_client_dev_register(rpisense, "rpi-sense-js",
326 + &(rpisense->joystick.pdev));
327 + rpisense_client_dev_register(rpisense, "rpi-sense-fb",
328 + &(rpisense->framebuffer.pdev));
333 +static int rpisense_remove(struct i2c_client *i2c)
335 + struct rpisense *rpisense = i2c_get_clientdata(i2c);
337 + platform_device_unregister(rpisense->joystick.pdev);
341 +struct rpisense *rpisense_get_dev(void)
345 +EXPORT_SYMBOL_GPL(rpisense_get_dev);
347 +s32 rpisense_reg_read(struct rpisense *rpisense, int reg)
349 + int ret = i2c_smbus_read_byte_data(rpisense->i2c_client, reg);
352 + dev_err(rpisense->dev, "Read from reg %d failed\n", reg);
353 + /* Due to the BCM270x I2C clock stretching bug, some values
354 + * may have MSB set. Clear it to avoid incorrect values.
358 +EXPORT_SYMBOL_GPL(rpisense_reg_read);
360 +int rpisense_block_write(struct rpisense *rpisense, const char *buf, int count)
362 + int ret = i2c_master_send(rpisense->i2c_client, buf, count);
365 + dev_err(rpisense->dev, "Block write failed\n");
368 +EXPORT_SYMBOL_GPL(rpisense_block_write);
370 +static const struct i2c_device_id rpisense_i2c_id[] = {
371 + { "rpi-sense", 0 },
374 +MODULE_DEVICE_TABLE(i2c, rpisense_i2c_id);
377 +static const struct of_device_id rpisense_core_id[] = {
378 + { .compatible = "rpi,rpi-sense" },
381 +MODULE_DEVICE_TABLE(of, rpisense_core_id);
385 +static struct i2c_driver rpisense_driver = {
387 + .name = "rpi-sense",
388 + .owner = THIS_MODULE,
390 + .probe = rpisense_probe,
391 + .remove = rpisense_remove,
392 + .id_table = rpisense_i2c_id,
395 +module_i2c_driver(rpisense_driver);
397 +MODULE_DESCRIPTION("Raspberry Pi Sense HAT core driver");
398 +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
399 +MODULE_LICENSE("GPL");
401 --- a/drivers/video/fbdev/Kconfig
402 +++ b/drivers/video/fbdev/Kconfig
403 @@ -2252,6 +2252,19 @@ config FB_SM712
404 called sm712fb. If you want to compile it as a module, say M
405 here and read <file:Documentation/kbuild/modules.rst>.
408 + tristate "Raspberry Pi Sense HAT framebuffer"
410 + select MFD_RPISENSE_CORE
412 + select FB_SYS_FILLRECT
413 + select FB_SYS_COPYAREA
414 + select FB_SYS_IMAGEBLIT
415 + select FB_DEFERRED_IO
418 + This is the framebuffer driver for the Raspberry Pi Sense HAT
420 source "drivers/video/fbdev/omap/Kconfig"
421 source "drivers/video/fbdev/omap2/Kconfig"
422 source "drivers/video/fbdev/mmp/Kconfig"
423 --- a/drivers/video/fbdev/Makefile
424 +++ b/drivers/video/fbdev/Makefile
425 @@ -130,6 +130,7 @@ obj-$(CONFIG_FB_MX3) += mx3fb.o
426 obj-$(CONFIG_FB_DA8XX) += da8xx-fb.o
427 obj-$(CONFIG_FB_SSD1307) += ssd1307fb.o
428 obj-$(CONFIG_FB_SIMPLE) += simplefb.o
429 +obj-$(CONFIG_FB_RPISENSE) += rpisense-fb.o
431 # the test framebuffer is last
432 obj-$(CONFIG_FB_VIRTUAL) += vfb.o
434 +++ b/drivers/video/fbdev/rpisense-fb.c
437 + * Raspberry Pi Sense HAT framebuffer driver
438 + * http://raspberrypi.org
440 + * Copyright (C) 2015 Raspberry Pi
442 + * Author: Serge Schneider
444 + * This program is free software; you can redistribute it and/or modify it
445 + * under the terms of the GNU General Public License as published by the
446 + * Free Software Foundation; either version 2 of the License, or (at your
447 + * option) any later version.
451 +#include <linux/module.h>
452 +#include <linux/kernel.h>
453 +#include <linux/errno.h>
454 +#include <linux/string.h>
455 +#include <linux/mm.h>
456 +#include <linux/slab.h>
457 +#include <linux/uaccess.h>
458 +#include <linux/delay.h>
459 +#include <linux/fb.h>
460 +#include <linux/init.h>
462 +#include <linux/mfd/rpisense/framebuffer.h>
463 +#include <linux/mfd/rpisense/core.h>
465 +static bool lowlight;
466 +module_param(lowlight, bool, 0);
467 +MODULE_PARM_DESC(lowlight, "Reduce LED matrix brightness to one third");
469 +static struct rpisense *rpisense;
471 +struct rpisense_fb_param {
472 + char __iomem *vmem;
478 +static u8 gamma_default[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
479 + 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07,
480 + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11,
481 + 0x12, 0x14, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F,};
483 +static u8 gamma_low[32] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
484 + 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02,
485 + 0x03, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06,
486 + 0x06, 0x07, 0x07, 0x08, 0x08, 0x09, 0x0A, 0x0A,};
488 +static u8 gamma_user[32];
490 +static struct rpisense_fb_param rpisense_fb_param = {
493 + .gamma = gamma_default,
496 +static struct fb_deferred_io rpisense_fb_defio;
498 +static struct fb_fix_screeninfo rpisense_fb_fix = {
499 + .id = "RPi-Sense FB",
500 + .type = FB_TYPE_PACKED_PIXELS,
501 + .visual = FB_VISUAL_TRUECOLOR,
505 + .accel = FB_ACCEL_NONE,
509 +static struct fb_var_screeninfo rpisense_fb_var = {
514 + .bits_per_pixel = 16,
516 + .green = {5, 6, 0},
520 +static ssize_t rpisense_fb_write(struct fb_info *info,
521 + const char __user *buf, size_t count,
524 + ssize_t res = fb_sys_write(info, buf, count, ppos);
526 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
530 +static void rpisense_fb_fillrect(struct fb_info *info,
531 + const struct fb_fillrect *rect)
533 + sys_fillrect(info, rect);
534 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
537 +static void rpisense_fb_copyarea(struct fb_info *info,
538 + const struct fb_copyarea *area)
540 + sys_copyarea(info, area);
541 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
544 +static void rpisense_fb_imageblit(struct fb_info *info,
545 + const struct fb_image *image)
547 + sys_imageblit(info, image);
548 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
551 +static void rpisense_fb_deferred_io(struct fb_info *info,
552 + struct list_head *pagelist)
556 + u8 *vmem_work = rpisense_fb_param.vmem_work;
557 + u16 *mem = (u16 *)rpisense_fb_param.vmem;
558 + u8 *gamma = rpisense_fb_param.gamma;
561 + for (j = 0; j < 8; j++) {
562 + for (i = 0; i < 8; i++) {
563 + vmem_work[(j * 24) + i + 1] =
564 + gamma[(mem[(j * 8) + i] >> 11) & 0x1F];
565 + vmem_work[(j * 24) + (i + 8) + 1] =
566 + gamma[(mem[(j * 8) + i] >> 6) & 0x1F];
567 + vmem_work[(j * 24) + (i + 16) + 1] =
568 + gamma[(mem[(j * 8) + i]) & 0x1F];
571 + rpisense_block_write(rpisense, vmem_work, 193);
574 +static struct fb_deferred_io rpisense_fb_defio = {
576 + .deferred_io = rpisense_fb_deferred_io,
579 +static int rpisense_fb_ioctl(struct fb_info *info, unsigned int cmd,
583 + case SENSEFB_FBIOGET_GAMMA:
584 + if (copy_to_user((void __user *) arg, rpisense_fb_param.gamma,
588 + case SENSEFB_FBIOSET_GAMMA:
589 + if (copy_from_user(gamma_user, (void __user *)arg,
592 + rpisense_fb_param.gamma = gamma_user;
593 + schedule_delayed_work(&info->deferred_work,
594 + rpisense_fb_defio.delay);
596 + case SENSEFB_FBIORESET_GAMMA:
599 + rpisense_fb_param.gamma = gamma_default;
602 + rpisense_fb_param.gamma = gamma_low;
605 + rpisense_fb_param.gamma = gamma_user;
610 + schedule_delayed_work(&info->deferred_work,
611 + rpisense_fb_defio.delay);
619 +static struct fb_ops rpisense_fb_ops = {
620 + .owner = THIS_MODULE,
621 + .fb_read = fb_sys_read,
622 + .fb_write = rpisense_fb_write,
623 + .fb_fillrect = rpisense_fb_fillrect,
624 + .fb_copyarea = rpisense_fb_copyarea,
625 + .fb_imageblit = rpisense_fb_imageblit,
626 + .fb_ioctl = rpisense_fb_ioctl,
629 +static int rpisense_fb_probe(struct platform_device *pdev)
631 + struct fb_info *info;
633 + struct rpisense_fb *rpisense_fb;
635 + rpisense = rpisense_get_dev();
636 + rpisense_fb = &rpisense->framebuffer;
638 + rpisense_fb_param.vmem = vzalloc(rpisense_fb_param.vmemsize);
639 + if (!rpisense_fb_param.vmem)
642 + rpisense_fb_param.vmem_work = devm_kmalloc(&pdev->dev, 193, GFP_KERNEL);
643 + if (!rpisense_fb_param.vmem_work)
646 + info = framebuffer_alloc(0, &pdev->dev);
648 + dev_err(&pdev->dev, "Could not allocate framebuffer.\n");
651 + rpisense_fb->info = info;
653 + rpisense_fb_fix.smem_start = (unsigned long)rpisense_fb_param.vmem;
654 + rpisense_fb_fix.smem_len = rpisense_fb_param.vmemsize;
656 + info->fbops = &rpisense_fb_ops;
657 + info->fix = rpisense_fb_fix;
658 + info->var = rpisense_fb_var;
659 + info->fbdefio = &rpisense_fb_defio;
660 + info->flags = FBINFO_FLAG_DEFAULT | FBINFO_VIRTFB;
661 + info->screen_base = rpisense_fb_param.vmem;
662 + info->screen_size = rpisense_fb_param.vmemsize;
665 + rpisense_fb_param.gamma = gamma_low;
667 + fb_deferred_io_init(info);
669 + ret = register_framebuffer(info);
671 + dev_err(&pdev->dev, "Could not register framebuffer.\n");
675 + fb_info(info, "%s frame buffer device\n", info->fix.id);
676 + schedule_delayed_work(&info->deferred_work, rpisense_fb_defio.delay);
679 + framebuffer_release(info);
681 + vfree(rpisense_fb_param.vmem);
685 +static int rpisense_fb_remove(struct platform_device *pdev)
687 + struct rpisense_fb *rpisense_fb = &rpisense->framebuffer;
688 + struct fb_info *info = rpisense_fb->info;
691 + unregister_framebuffer(info);
692 + fb_deferred_io_cleanup(info);
693 + framebuffer_release(info);
694 + vfree(rpisense_fb_param.vmem);
701 +static const struct of_device_id rpisense_fb_id[] = {
702 + { .compatible = "rpi,rpi-sense-fb" },
705 +MODULE_DEVICE_TABLE(of, rpisense_fb_id);
708 +static struct platform_device_id rpisense_fb_device_id[] = {
709 + { .name = "rpi-sense-fb" },
712 +MODULE_DEVICE_TABLE(platform, rpisense_fb_device_id);
714 +static struct platform_driver rpisense_fb_driver = {
715 + .probe = rpisense_fb_probe,
716 + .remove = rpisense_fb_remove,
718 + .name = "rpi-sense-fb",
719 + .owner = THIS_MODULE,
723 +module_platform_driver(rpisense_fb_driver);
725 +MODULE_DESCRIPTION("Raspberry Pi Sense HAT framebuffer driver");
726 +MODULE_AUTHOR("Serge Schneider <serge@raspberrypi.org>");
727 +MODULE_LICENSE("GPL");
730 +++ b/include/linux/mfd/rpisense/core.h
733 + * Raspberry Pi Sense HAT core driver
734 + * http://raspberrypi.org
736 + * Copyright (C) 2015 Raspberry Pi
738 + * Author: Serge Schneider
740 + * This program is free software; you can redistribute it and/or modify it
741 + * under the terms of the GNU General Public License as published by the
742 + * Free Software Foundation; either version 2 of the License, or (at your
743 + * option) any later version.
747 +#ifndef __LINUX_MFD_RPISENSE_CORE_H_
748 +#define __LINUX_MFD_RPISENSE_CORE_H_
750 +#include <linux/mfd/rpisense/joystick.h>
751 +#include <linux/mfd/rpisense/framebuffer.h>
756 +#define RPISENSE_FB 0x00
757 +#define RPISENSE_WAI 0xF0
758 +#define RPISENSE_VER 0xF1
759 +#define RPISENSE_KEYS 0xF2
760 +#define RPISENSE_EE_WP 0xF3
762 +#define RPISENSE_ID 's'
765 + struct device *dev;
766 + struct i2c_client *i2c_client;
768 + /* Client devices */
769 + struct rpisense_js joystick;
770 + struct rpisense_fb framebuffer;
773 +struct rpisense *rpisense_get_dev(void);
774 +s32 rpisense_reg_read(struct rpisense *rpisense, int reg);
775 +int rpisense_reg_write(struct rpisense *rpisense, int reg, u16 val);
776 +int rpisense_block_write(struct rpisense *rpisense, const char *buf, int count);
780 +++ b/include/linux/mfd/rpisense/framebuffer.h
783 + * Raspberry Pi Sense HAT framebuffer driver
784 + * http://raspberrypi.org
786 + * Copyright (C) 2015 Raspberry Pi
788 + * Author: Serge Schneider
790 + * This program is free software; you can redistribute it and/or modify it
791 + * under the terms of the GNU General Public License as published by the
792 + * Free Software Foundation; either version 2 of the License, or (at your
793 + * option) any later version.
797 +#ifndef __LINUX_RPISENSE_FB_H_
798 +#define __LINUX_RPISENSE_FB_H_
800 +#define SENSEFB_FBIO_IOC_MAGIC 0xF1
802 +#define SENSEFB_FBIOGET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 0)
803 +#define SENSEFB_FBIOSET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 1)
804 +#define SENSEFB_FBIORESET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 2)
808 +struct rpisense_fb {
809 + struct platform_device *pdev;
810 + struct fb_info *info;
815 +++ b/include/linux/mfd/rpisense/joystick.h
818 + * Raspberry Pi Sense HAT joystick driver
819 + * http://raspberrypi.org
821 + * Copyright (C) 2015 Raspberry Pi
823 + * Author: Serge Schneider
825 + * This program is free software; you can redistribute it and/or modify it
826 + * under the terms of the GNU General Public License as published by the
827 + * Free Software Foundation; either version 2 of the License, or (at your
828 + * option) any later version.
832 +#ifndef __LINUX_RPISENSE_JOYSTICK_H_
833 +#define __LINUX_RPISENSE_JOYSTICK_H_
835 +#include <linux/input.h>
836 +#include <linux/interrupt.h>
837 +#include <linux/gpio/consumer.h>
838 +#include <linux/platform_device.h>
842 +struct rpisense_js {
843 + struct platform_device *pdev;
844 + struct input_dev *keys_dev;
845 + struct gpio_desc *keys_desc;
846 + struct work_struct keys_work_s;