Skip to content

Commit fdedc02

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 49ccce7 commit fdedc02

File tree

9 files changed

+157
-0
lines changed

9 files changed

+157
-0
lines changed

arch/arm/boot/dts/overlays/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ dtb-$(RPI_DT_OVERLAYS) += pps-gpio-overlay.dtb
3838
dtb-$(RPI_DT_OVERLAYS) += pwm-overlay.dtb
3939
dtb-$(RPI_DT_OVERLAYS) += pwm-2chan-overlay.dtb
4040
dtb-$(RPI_DT_OVERLAYS) += raspidac3-overlay.dtb
41+
dtb-$(RPI_DT_OVERLAYS) += rpi-backlight-overlay.dtb
4142
dtb-$(RPI_DT_OVERLAYS) += rpi-dac-overlay.dtb
4243
dtb-$(RPI_DT_OVERLAYS) += rpi-display-overlay.dtb
4344
dtb-$(RPI_DT_OVERLAYS) += rpi-ft5406-overlay.dtb

arch/arm/boot/dts/overlays/README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ Load: dtoverlay=raspidac3
463463
Params: <None>
464464

465465

466+
Name: rpi-backlight
467+
Info: Raspberry Pi official display backlight driver
468+
Load: dtoverlay=rpi-backlight
469+
Params: <None>
470+
471+
466472
Name: rpi-dac
467473
Info: Configures the RPi DAC audio card
468474
Load: dtoverlay=rpi-dac
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Devicetree overlay for mailbox-driven Raspberry Pi DSI Display
3+
* backlight controller
4+
*/
5+
/dts-v1/;
6+
/plugin/;
7+
8+
/ {
9+
compatible = "brcm,bcm2708";
10+
11+
fragment@0 {
12+
target-path = "/";
13+
__overlay__ {
14+
rpi_backlight: rpi_backlight {
15+
compatible = "raspberrypi,rpi-backlight";
16+
firmware = <&firmware>;
17+
status = "okay";
18+
};
19+
};
20+
};
21+
};

arch/arm/configs/bcm2709_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ CONFIG_FB_UDL=m
801801
CONFIG_FB_SSD1307=m
802802
CONFIG_FB_RPISENSE=m
803803
# CONFIG_BACKLIGHT_GENERIC is not set
804+
CONFIG_BACKLIGHT_RPI=m
804805
CONFIG_BACKLIGHT_GPIO=m
805806
CONFIG_FRAMEBUFFER_CONSOLE=y
806807
CONFIG_LOGO=y

arch/arm/configs/bcmrpi_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ CONFIG_FB_UDL=m
794794
CONFIG_FB_SSD1307=m
795795
CONFIG_FB_RPISENSE=m
796796
# CONFIG_BACKLIGHT_GENERIC is not set
797+
CONFIG_BACKLIGHT_RPI=m
797798
CONFIG_BACKLIGHT_GPIO=m
798799
CONFIG_FRAMEBUFFER_CONSOLE=y
799800
CONFIG_LOGO=y

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");

include/soc/bcm2835/raspberrypi-firmware.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ enum rpi_firmware_property_tag {
112112
RPI_FIRMWARE_FRAMEBUFFER_SET_OVERSCAN = 0x0004800a,
113113
RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE = 0x0004800b,
114114
RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC = 0x0004800e,
115+
RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT = 0x0004800f,
115116

116117
RPI_FIRMWARE_VCHIQ_INIT = 0x00048010,
117118

0 commit comments

Comments
 (0)