Skip to content

Commit 2942198

Browse files
XECDesignpopcornmix
authored andcommitted
rpisense-fb: add low-light mode and gamma control
1 parent 9d7d418 commit 2942198

File tree

2 files changed

+68
-6
lines changed

2 files changed

+68
-6
lines changed

drivers/video/fbdev/rpisense-fb.c

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,43 @@
1919
#include <linux/string.h>
2020
#include <linux/mm.h>
2121
#include <linux/slab.h>
22+
#include <linux/uaccess.h>
2223
#include <linux/delay.h>
2324
#include <linux/fb.h>
2425
#include <linux/init.h>
2526

2627
#include <linux/mfd/rpisense/framebuffer.h>
2728
#include <linux/mfd/rpisense/core.h>
2829

30+
static bool lowlight;
31+
module_param(lowlight, bool, 0);
32+
MODULE_PARM_DESC(lowlight, "Reduce LED matrix brightness to one third");
33+
2934
struct rpisense *rpisense;
3035

3136
struct rpisense_fb_param {
3237
char __iomem *vmem;
3338
u8 *vmem_work;
3439
u32 vmemsize;
35-
u8 gamma[32];
40+
u8 *gamma;
3641
};
3742

43+
static u8 gamma_default[32] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
44+
0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07,
45+
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11,
46+
0x12, 0x14, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F,};
47+
48+
static u8 gamma_low[32] = {0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
49+
0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02,
50+
0x03, 0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06,
51+
0x06, 0x07, 0x07, 0x08, 0x08, 0x09, 0x0A, 0x0A,};
52+
53+
static u8 gamma_user[32];
54+
3855
static struct rpisense_fb_param rpisense_fb_param = {
3956
.vmem = NULL,
4057
.vmemsize = 128,
41-
.gamma = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
42-
0x02, 0x02, 0x03, 0x03, 0x04, 0x05, 0x06, 0x07,
43-
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0E, 0x0F, 0x11,
44-
0x12, 0x14, 0x15, 0x17, 0x19, 0x1B, 0x1D, 0x1F,},
58+
.gamma = gamma_default,
4559
};
4660

4761
static struct fb_deferred_io rpisense_fb_defio;
@@ -127,13 +141,54 @@ static struct fb_deferred_io rpisense_fb_defio = {
127141
.deferred_io = rpisense_fb_deferred_io,
128142
};
129143

144+
static int rpisense_fb_ioctl(struct fb_info *info, unsigned int cmd,
145+
unsigned long arg)
146+
{
147+
switch (cmd) {
148+
case SENSEFB_FBIOGET_GAMMA:
149+
if (copy_to_user((void __user *) arg, rpisense_fb_param.gamma,
150+
sizeof(u8[32])))
151+
return -EFAULT;
152+
return 0;
153+
case SENSEFB_FBIOSET_GAMMA:
154+
if (copy_from_user(gamma_user, (void __user *)arg,
155+
sizeof(u8[32])))
156+
return -EFAULT;
157+
rpisense_fb_param.gamma = gamma_user;
158+
schedule_delayed_work(&info->deferred_work,
159+
rpisense_fb_defio.delay);
160+
return 0;
161+
case SENSEFB_FBIORESET_GAMMA:
162+
switch (arg) {
163+
case 0:
164+
rpisense_fb_param.gamma = gamma_default;
165+
break;
166+
case 1:
167+
rpisense_fb_param.gamma = gamma_low;
168+
break;
169+
case 2:
170+
rpisense_fb_param.gamma = gamma_user;
171+
break;
172+
default:
173+
return -EINVAL;
174+
}
175+
schedule_delayed_work(&info->deferred_work,
176+
rpisense_fb_defio.delay);
177+
break;
178+
default:
179+
return -EINVAL;
180+
}
181+
return 0;
182+
}
183+
130184
static struct fb_ops rpisense_fb_ops = {
131185
.owner = THIS_MODULE,
132186
.fb_read = fb_sys_read,
133187
.fb_write = rpisense_fb_write,
134188
.fb_fillrect = rpisense_fb_fillrect,
135189
.fb_copyarea = rpisense_fb_copyarea,
136190
.fb_imageblit = rpisense_fb_imageblit,
191+
.fb_ioctl = rpisense_fb_ioctl,
137192
};
138193

139194
static int rpisense_fb_probe(struct platform_device *pdev)
@@ -171,6 +226,9 @@ static int rpisense_fb_probe(struct platform_device *pdev)
171226
info->screen_base = rpisense_fb_param.vmem;
172227
info->screen_size = rpisense_fb_param.vmemsize;
173228

229+
if (lowlight)
230+
rpisense_fb_param.gamma = gamma_low;
231+
174232
fb_deferred_io_init(info);
175233

176234
ret = register_framebuffer(info);

include/linux/mfd/rpisense/framebuffer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
#ifndef __LINUX_RPISENSE_FB_H_
1717
#define __LINUX_RPISENSE_FB_H_
1818

19-
#include <linux/platform_device.h>
19+
#define SENSEFB_FBIO_IOC_MAGIC 0xF1
20+
21+
#define SENSEFB_FBIOGET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 0)
22+
#define SENSEFB_FBIOSET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 1)
23+
#define SENSEFB_FBIORESET_GAMMA _IO(SENSEFB_FBIO_IOC_MAGIC, 2)
2024

2125
struct rpisense;
2226

0 commit comments

Comments
 (0)