Skip to content

Commit ad42b6d

Browse files
P33Mpopcornmix
P33M
authored andcommitted
rpi_display: add backlight driver and overlay
Add a mailbox-driven backlight controller for the Raspberry Pi DSI touchscreen display. Requires updated GPU firmware to recognise the mailbox request. Signed-off-by: Gordon Hollingworth <[email protected]> Add Raspberry Pi firmware driver to the dependencies of backlight driver Otherwise the backlight driver fails to build if the firmware loading driver is not in the kernel Signed-off-by: Alex Riesen <[email protected]>
1 parent 7d8c5d1 commit ad42b6d

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

drivers/video/backlight/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,13 @@ config BACKLIGHT_PWM
249249
If you have a LCD backlight adjustable by PWM, say Y to enable
250250
this driver.
251251

252+
config BACKLIGHT_RPI
253+
tristate "Raspberry Pi display firmware driven backlight"
254+
depends on RASPBERRYPI_FIRMWARE
255+
help
256+
If you have the Raspberry Pi DSI touchscreen display, say Y to
257+
enable the mailbox-controlled backlight driver.
258+
252259
config BACKLIGHT_DA903X
253260
tristate "Backlight Driver for DA9030/DA9034 using WLED"
254261
depends on PMIC_DA903X

drivers/video/backlight/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ obj-$(CONFIG_BACKLIGHT_PANDORA) += pandora_bl.o
5252
obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o
5353
obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o
5454
obj-$(CONFIG_BACKLIGHT_QCOM_WLED) += qcom-wled.o
55+
obj-$(CONFIG_BACKLIGHT_RPI) += rpi_backlight.o
5556
obj-$(CONFIG_BACKLIGHT_RT4831) += rt4831-backlight.o
5657
obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o
5758
obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* rpi_bl.c - Backlight controller through VPU
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*/
8+
9+
#include <linux/backlight.h>
10+
#include <linux/err.h>
11+
#include <linux/fb.h>
12+
#include <linux/gpio.h>
13+
#include <linux/init.h>
14+
#include <linux/kernel.h>
15+
#include <linux/module.h>
16+
#include <linux/of.h>
17+
#include <linux/of_gpio.h>
18+
#include <linux/platform_device.h>
19+
#include <linux/slab.h>
20+
#include <soc/bcm2835/raspberrypi-firmware.h>
21+
22+
struct rpi_backlight {
23+
struct device *dev;
24+
struct device *fbdev;
25+
struct rpi_firmware *fw;
26+
};
27+
28+
static int rpi_backlight_update_status(struct backlight_device *bl)
29+
{
30+
struct rpi_backlight *gbl = bl_get_data(bl);
31+
int brightness = bl->props.brightness;
32+
int ret;
33+
34+
if (bl->props.power != FB_BLANK_UNBLANK ||
35+
bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
36+
brightness = 0;
37+
38+
ret = rpi_firmware_property(gbl->fw,
39+
RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT,
40+
&brightness, sizeof(brightness));
41+
if (ret) {
42+
dev_err(gbl->dev, "Failed to set brightness\n");
43+
return ret;
44+
}
45+
46+
if (brightness < 0) {
47+
dev_err(gbl->dev, "Backlight change failed\n");
48+
return -EAGAIN;
49+
}
50+
51+
return 0;
52+
}
53+
54+
static const struct backlight_ops rpi_backlight_ops = {
55+
.options = BL_CORE_SUSPENDRESUME,
56+
.update_status = rpi_backlight_update_status,
57+
};
58+
59+
static int rpi_backlight_probe(struct platform_device *pdev)
60+
{
61+
struct backlight_properties props;
62+
struct backlight_device *bl;
63+
struct rpi_backlight *gbl;
64+
struct device_node *fw_node;
65+
66+
gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL);
67+
if (gbl == NULL)
68+
return -ENOMEM;
69+
70+
gbl->dev = &pdev->dev;
71+
72+
fw_node = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
73+
if (!fw_node) {
74+
dev_err(&pdev->dev, "Missing firmware node\n");
75+
return -ENOENT;
76+
}
77+
78+
gbl->fw = rpi_firmware_get(fw_node);
79+
if (!gbl->fw)
80+
return -EPROBE_DEFER;
81+
82+
memset(&props, 0, sizeof(props));
83+
props.type = BACKLIGHT_RAW;
84+
props.max_brightness = 255;
85+
bl = devm_backlight_device_register(&pdev->dev, dev_name(&pdev->dev),
86+
&pdev->dev, gbl, &rpi_backlight_ops,
87+
&props);
88+
if (IS_ERR(bl)) {
89+
dev_err(&pdev->dev, "failed to register backlight\n");
90+
return PTR_ERR(bl);
91+
}
92+
93+
bl->props.brightness = 255;
94+
backlight_update_status(bl);
95+
96+
platform_set_drvdata(pdev, bl);
97+
return 0;
98+
}
99+
100+
static const struct of_device_id rpi_backlight_of_match[] = {
101+
{ .compatible = "raspberrypi,rpi-backlight" },
102+
{ /* sentinel */ }
103+
};
104+
MODULE_DEVICE_TABLE(of, rpi_backlight_of_match);
105+
106+
static struct platform_driver rpi_backlight_driver = {
107+
.driver = {
108+
.name = "rpi-backlight",
109+
.of_match_table = of_match_ptr(rpi_backlight_of_match),
110+
},
111+
.probe = rpi_backlight_probe,
112+
};
113+
114+
module_platform_driver(rpi_backlight_driver);
115+
116+
MODULE_AUTHOR("Gordon Hollingworth <[email protected]>");
117+
MODULE_DESCRIPTION("Raspberry Pi mailbox based Backlight Driver");
118+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)