Skip to content

Commit 87ca97e

Browse files
WhatAmISupposedToPutHerejannau
authored andcommitted
gpu: drm: adp: Add a backlight driver for the Summit LCD
This is the display panel used for the touchbar on laptops that have it. Signed-off-by: Sasha Finkelstein <fnkl.kernel@gmail.com>
1 parent c49dd66 commit 87ca97e

1 file changed

Lines changed: 104 additions & 0 deletions

File tree

drivers/gpu/drm/adp/panel-summit.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
3+
#include <linux/backlight.h>
4+
#include <drm/drm_mipi_dsi.h>
5+
#include <video/mipi_display.h>
6+
7+
struct summit_data {
8+
struct mipi_dsi_device *dsi;
9+
struct backlight_device *bl;
10+
};
11+
12+
static int summit_set_brightness(struct device *dev)
13+
{
14+
struct summit_data *panel = dev_get_drvdata(dev);
15+
int level = backlight_get_brightness(panel->bl);
16+
ssize_t err = mipi_dsi_dcs_write(panel->dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
17+
&level, 1);
18+
if (err < 0)
19+
return err;
20+
return 0;
21+
}
22+
23+
static int summit_bl_update_status(struct backlight_device *dev)
24+
{
25+
return summit_set_brightness(&dev->dev);
26+
}
27+
28+
static int summit_bl_get_brightness(struct backlight_device *dev)
29+
{
30+
return backlight_get_brightness(dev);
31+
}
32+
33+
static const struct backlight_ops summit_bl_ops = {
34+
.get_brightness = summit_bl_get_brightness,
35+
.update_status = summit_bl_update_status,
36+
};
37+
38+
static int summit_probe(struct mipi_dsi_device *dsi)
39+
{
40+
struct backlight_properties props = { 0 };
41+
struct device *dev = &dsi->dev;
42+
struct summit_data *panel;
43+
panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
44+
if (!panel)
45+
return -ENOMEM;
46+
47+
mipi_dsi_set_drvdata(dsi, panel);
48+
panel->dsi = dsi;
49+
props.max_brightness = 255;
50+
props.type = BACKLIGHT_RAW;
51+
52+
panel->bl = devm_backlight_device_register(dev, dev_name(dev),
53+
dev, panel, &summit_bl_ops, &props);
54+
if (IS_ERR(panel->bl)) {
55+
return PTR_ERR(panel->bl);
56+
}
57+
58+
return mipi_dsi_attach(dsi);
59+
}
60+
61+
static void summit_remove(struct mipi_dsi_device *dsi)
62+
{
63+
mipi_dsi_detach(dsi);
64+
}
65+
66+
static int summit_resume(struct device *dev)
67+
{
68+
return summit_set_brightness(dev);
69+
}
70+
71+
static int summit_suspend(struct device *dev)
72+
{
73+
int level = 0;
74+
struct summit_data *panel = dev_get_drvdata(dev);
75+
ssize_t err = mipi_dsi_dcs_write(panel->dsi, MIPI_DCS_SET_DISPLAY_BRIGHTNESS,
76+
&level, 1);
77+
if (err < 0)
78+
return err;
79+
return 0;
80+
}
81+
82+
static DEFINE_SIMPLE_DEV_PM_OPS(summit_pm_ops, summit_suspend,
83+
summit_resume);
84+
85+
static const struct of_device_id summit_of_match[] = {
86+
{ .compatible = "apple,summit" },
87+
{},
88+
};
89+
90+
MODULE_DEVICE_TABLE(of, summit_of_match);
91+
92+
static struct mipi_dsi_driver summit_driver = {
93+
.probe = summit_probe,
94+
.remove = summit_remove,
95+
.driver = {
96+
.name = "panel-summit",
97+
.of_match_table = summit_of_match,
98+
.pm = pm_sleep_ptr(&summit_pm_ops),
99+
},
100+
};
101+
module_mipi_dsi_driver(summit_driver);
102+
103+
MODULE_DESCRIPTION("Summit Display Panel Driver");
104+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)