brcm2708: update 4.1 patches
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0161-rpisense-fb-add-low-light-mode-and-gamma-control.patch
1 From d8e09d724eb21172cd21d2475b619be2f8b4a878 Mon Sep 17 00:00:00 2001
2 From: Serge Schneider <serge@raspberrypi.org>
3 Date: Mon, 17 Aug 2015 18:06:16 +0100
4 Subject: [PATCH 161/222] rpisense-fb: add low-light mode and gamma control
5
6 ---
7 drivers/video/fbdev/rpisense-fb.c | 68 +++++++++++++++++++++++++++++---
8 include/linux/mfd/rpisense/framebuffer.h | 6 ++-
9 2 files changed, 68 insertions(+), 6 deletions(-)
10
11 --- a/drivers/video/fbdev/rpisense-fb.c
12 +++ b/drivers/video/fbdev/rpisense-fb.c
13 @@ -19,6 +19,7 @@
14 #include <linux/string.h>
15 #include <linux/mm.h>
16 #include <linux/slab.h>
17 +#include <linux/uaccess.h>
18 #include <linux/delay.h>
19 #include <linux/fb.h>
20 #include <linux/init.h>
21 @@ -26,22 +27,35 @@
22 #include <linux/mfd/rpisense/framebuffer.h>
23 #include <linux/mfd/rpisense/core.h>
24
25 +static bool lowlight;
26 +module_param(lowlight, bool, 0);
27 +MODULE_PARM_DESC(lowlight, "Reduce LED matrix brightness to one third");
28 +
29 struct rpisense *rpisense;
30
31 struct rpisense_fb_param {
32 char __iomem *vmem;
33 u8 *vmem_work;
34 u32 vmemsize;
35 - u8 gamma[32];
36 + u8 *gamma;
37 };
38
39 +static u8 gamma_default[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
40 + 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07,
41 + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11,
42 + 0x12, 0x14, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F,};
43 +
44 +static u8 gamma_low[32] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
45 + 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02,
46 + 0x03, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06,
47 + 0x06, 0x07, 0x07, 0x08, 0x08, 0x09, 0x0A, 0x0A,};
48 +
49 +static u8 gamma_user[32];
50 +
51 static struct rpisense_fb_param rpisense_fb_param = {
52 .vmem = NULL,
53 .vmemsize = 128,
54 - .gamma = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
55 - 0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07,
56 - 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11,
57 - 0x12, 0x14, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F,},
58 + .gamma = gamma_default,
59 };
60
61 static struct fb_deferred_io rpisense_fb_defio;
62 @@ -127,6 +141,46 @@ static struct fb_deferred_io rpisense_fb
63 .deferred_io = rpisense_fb_deferred_io,
64 };
65
66 +static int rpisense_fb_ioctl(struct fb_info *info, unsigned int cmd,
67 + unsigned long arg)
68 +{
69 + switch (cmd) {
70 + case SENSEFB_FBIOGET_GAMMA:
71 + if (copy_to_user((void __user *) arg, rpisense_fb_param.gamma,
72 + sizeof(u8[32])))
73 + return -EFAULT;
74 + return 0;
75 + case SENSEFB_FBIOSET_GAMMA:
76 + if (copy_from_user(gamma_user, (void __user *)arg,
77 + sizeof(u8[32])))
78 + return -EFAULT;
79 + rpisense_fb_param.gamma = gamma_user;
80 + schedule_delayed_work(&info->deferred_work,
81 + rpisense_fb_defio.delay);
82 + return 0;
83 + case SENSEFB_FBIORESET_GAMMA:
84 + switch (arg) {
85 + case 0:
86 + rpisense_fb_param.gamma = gamma_default;
87 + break;
88 + case 1:
89 + rpisense_fb_param.gamma = gamma_low;
90 + break;
91 + case 2:
92 + rpisense_fb_param.gamma = gamma_user;
93 + break;
94 + default:
95 + return -EINVAL;
96 + }
97 + schedule_delayed_work(&info->deferred_work,
98 + rpisense_fb_defio.delay);
99 + break;
100 + default:
101 + return -EINVAL;
102 + }
103 + return 0;
104 +}
105 +
106 static struct fb_ops rpisense_fb_ops = {
107 .owner = THIS_MODULE,
108 .fb_read = fb_sys_read,
109 @@ -134,6 +188,7 @@ static struct fb_ops rpisense_fb_ops = {
110 .fb_fillrect = rpisense_fb_fillrect,
111 .fb_copyarea = rpisense_fb_copyarea,
112 .fb_imageblit = rpisense_fb_imageblit,
113 + .fb_ioctl = rpisense_fb_ioctl,
114 };
115
116 static int rpisense_fb_probe(struct platform_device *pdev)
117 @@ -171,6 +226,9 @@ static int rpisense_fb_probe(struct plat
118 info->screen_base = rpisense_fb_param.vmem;
119 info->screen_size = rpisense_fb_param.vmemsize;
120
121 + if (lowlight)
122 + rpisense_fb_param.gamma = gamma_low;
123 +
124 fb_deferred_io_init(info);
125
126 ret = register_framebuffer(info);
127 --- a/include/linux/mfd/rpisense/framebuffer.h
128 +++ b/include/linux/mfd/rpisense/framebuffer.h
129 @@ -16,7 +16,11 @@
130 #ifndef __LINUX_RPISENSE_FB_H_
131 #define __LINUX_RPISENSE_FB_H_
132
133 -#include <linux/platform_device.h>
134 +#define SENSEFB_FBIO_IOC_MAGIC 0xF1
135 +
136 +#define SENSEFB_FBIOGET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 0)
137 +#define SENSEFB_FBIOSET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 1)
138 +#define SENSEFB_FBIORESET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 2)
139
140 struct rpisense;
141