Skip to content

Commit 9e6e038

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]>
1 parent 98dea1b commit 9e6e038

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

drivers/video/backlight/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,12 @@ config BACKLIGHT_PWM
265265
If you have a LCD backlight adjustable by PWM, say Y to enable
266266
this driver.
267267

268+
config BACKLIGHT_RPI
269+
tristate "Raspberry Pi display firmware driven backlight"
270+
help
271+
If you have the Raspberry Pi DSI touchscreen display, say Y to
272+
enable the mailbox-controlled backlight driver.
273+
268274
config BACKLIGHT_DA903X
269275
tristate "Backlight Driver for DA9030/DA9034 using WLED"
270276
depends on PMIC_DA903X

drivers/video/backlight/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ obj-$(CONFIG_BACKLIGHT_PANDORA) += pandora_bl.o
5050
obj-$(CONFIG_BACKLIGHT_PCF50633) += pcf50633-backlight.o
5151
obj-$(CONFIG_BACKLIGHT_PM8941_WLED) += pm8941-wled.o
5252
obj-$(CONFIG_BACKLIGHT_PWM) += pwm_bl.o
53+
obj-$(CONFIG_BACKLIGHT_RPI) += rpi_backlight.o
5354
obj-$(CONFIG_BACKLIGHT_SAHARA) += kb3886_bl.o
5455
obj-$(CONFIG_BACKLIGHT_SKY81452) += sky81452-backlight.o
5556
obj-$(CONFIG_BACKLIGHT_TOSA) += tosa_bl.o
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
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.fb_blank != FB_BLANK_UNBLANK ||
36+
bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
37+
brightness = 0;
38+
39+
ret = rpi_firmware_property(gbl->fw,
40+
RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT,
41+
&brightness, sizeof(brightness));
42+
if (ret) {
43+
dev_err(gbl->dev, "Failed to set brightness\n");
44+
return ret;
45+
}
46+
47+
if (brightness < 0) {
48+
dev_err(gbl->dev, "Backlight change failed\n");
49+
return -EAGAIN;
50+
}
51+
52+
return 0;
53+
}
54+
55+
static const struct backlight_ops rpi_backlight_ops = {
56+
.options = BL_CORE_SUSPENDRESUME,
57+
.update_status = rpi_backlight_update_status,
58+
};
59+
60+
static int rpi_backlight_probe(struct platform_device *pdev)
61+
{
62+
struct backlight_properties props;
63+
struct backlight_device *bl;
64+
struct rpi_backlight *gbl;
65+
struct device_node *fw_node;
66+
67+
gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL);
68+
if (gbl == NULL)
69+
return -ENOMEM;
70+
71+
gbl->dev = &pdev->dev;
72+
73+
fw_node = of_parse_phandle(pdev->dev.of_node, "firmware", 0);
74+
if (!fw_node) {
75+
dev_err(&pdev->dev, "Missing firmware node\n");
76+
return -ENOENT;
77+
}
78+
79+
gbl->fw = rpi_firmware_get(fw_node);
80+
if (!gbl->fw)
81+
return -EPROBE_DEFER;
82+
83+
memset(&props, 0, sizeof(props));
84+
props.type = BACKLIGHT_RAW;
85+
props.max_brightness = 255;
86+
bl = devm_backlight_device_register(&pdev->dev, dev_name(&pdev->dev),
87+
&pdev->dev, gbl, &rpi_backlight_ops,
88+
&props);
89+
if (IS_ERR(bl)) {
90+
dev_err(&pdev->dev, "failed to register backlight\n");
91+
return PTR_ERR(bl);
92+
}
93+
94+
bl->props.brightness = 255;
95+
backlight_update_status(bl);
96+
97+
platform_set_drvdata(pdev, bl);
98+
return 0;
99+
}
100+
101+
static const struct of_device_id rpi_backlight_of_match[] = {
102+
{ .compatible = "raspberrypi,rpi-backlight" },
103+
{ /* sentinel */ }
104+
};
105+
MODULE_DEVICE_TABLE(of, rpi_backlight_of_match);
106+
107+
static struct platform_driver rpi_backlight_driver = {
108+
.driver = {
109+
.name = "rpi-backlight",
110+
.of_match_table = of_match_ptr(rpi_backlight_of_match),
111+
},
112+
.probe = rpi_backlight_probe,
113+
};
114+
115+
module_platform_driver(rpi_backlight_driver);
116+
117+
MODULE_AUTHOR("Gordon Hollingworth <[email protected]>");
118+
MODULE_DESCRIPTION("Raspberry Pi mailbox based Backlight Driver");
119+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)