Skip to content

Commit 069a6c0

Browse files
sumitsemwallumag
authored andcommitted
drm: panel: Add LG sw43408 panel driver
LG SW43408 is 1080x2160@60Hz, 4-lane MIPI-DSI panel, used in some Google Pixel-3 phones. Signed-off-by: Sumit Semwal <[email protected]> [vinod: Add DSC support] Signed-off-by: Vinod Koul <[email protected]> [caleb: cleanup and support turning off the panel] Signed-off-by: Caleb Connolly <[email protected]> [DB: partially rewrote the driver and fixed DSC programming] Reviewed-by: Marijn Suijten <[email protected]> Signed-off-by: Dmitry Baryshkov <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent b724455 commit 069a6c0

File tree

4 files changed

+340
-0
lines changed

4 files changed

+340
-0
lines changed

MAINTAINERS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6764,6 +6764,14 @@ S: Maintained
67646764
F: Documentation/devicetree/bindings/display/panel/jadard,jd9365da-h3.yaml
67656765
F: drivers/gpu/drm/panel/panel-jadard-jd9365da-h3.c
67666766

6767+
DRM DRIVER FOR LG SW43408 PANELS
6768+
M: Sumit Semwal <[email protected]>
6769+
M: Caleb Connolly <[email protected]>
6770+
S: Maintained
6771+
T: git git://anongit.freedesktop.org/drm/drm-misc
6772+
F: Documentation/devicetree/bindings/display/panel/lg,sw43408.yaml
6773+
F: drivers/gpu/drm/panel/panel-lg-sw43408.c
6774+
67676775
DRM DRIVER FOR LOGICVC DISPLAY CONTROLLER
67686776
M: Paul Kocialkowski <[email protected]>
67696777
S: Supported

drivers/gpu/drm/panel/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,17 @@ config DRM_PANEL_LG_LG4573
335335
Say Y here if you want to enable support for LG4573 RGB panel.
336336
To compile this driver as a module, choose M here.
337337

338+
config DRM_PANEL_LG_SW43408
339+
tristate "LG SW43408 panel"
340+
depends on OF
341+
depends on DRM_MIPI_DSI
342+
depends on BACKLIGHT_CLASS_DEVICE
343+
help
344+
Say Y here if you want to enable support for LG sw43408 panel.
345+
The panel has a 1080x2160@60Hz resolution and uses 24 bit RGB per
346+
pixel. It provides a MIPI DSI interface to the host and has a
347+
built-in LED backlight.
348+
338349
config DRM_PANEL_MAGNACHIP_D53E6EA8966
339350
tristate "Magnachip D53E6EA8966 DSI panel"
340351
depends on OF && SPI

drivers/gpu/drm/panel/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK050H3146W) += panel-leadtek-ltk050h3146w.o
3434
obj-$(CONFIG_DRM_PANEL_LEADTEK_LTK500HD1829) += panel-leadtek-ltk500hd1829.o
3535
obj-$(CONFIG_DRM_PANEL_LG_LB035Q02) += panel-lg-lb035q02.o
3636
obj-$(CONFIG_DRM_PANEL_LG_LG4573) += panel-lg-lg4573.o
37+
obj-$(CONFIG_DRM_PANEL_LG_SW43408) += panel-lg-sw43408.o
3738
obj-$(CONFIG_DRM_PANEL_MAGNACHIP_D53E6EA8966) += panel-magnachip-d53e6ea8966.o
3839
obj-$(CONFIG_DRM_PANEL_NEC_NL8048HL11) += panel-nec-nl8048hl11.o
3940
obj-$(CONFIG_DRM_PANEL_NEWVISION_NV3051D) += panel-newvision-nv3051d.o
Lines changed: 320 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,320 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Copyright (C) 2019-2024 Linaro Ltd
4+
* Author: Sumit Semwal <[email protected]>
5+
* Dmitry Baryshkov <[email protected]>
6+
*/
7+
8+
#include <linux/backlight.h>
9+
#include <linux/delay.h>
10+
#include <linux/gpio/consumer.h>
11+
#include <linux/module.h>
12+
#include <linux/of.h>
13+
#include <linux/regulator/consumer.h>
14+
15+
#include <video/mipi_display.h>
16+
17+
#include <drm/drm_mipi_dsi.h>
18+
#include <drm/drm_panel.h>
19+
#include <drm/drm_probe_helper.h>
20+
#include <drm/display/drm_dsc.h>
21+
#include <drm/display/drm_dsc_helper.h>
22+
23+
#define NUM_SUPPLIES 2
24+
25+
struct sw43408_panel {
26+
struct drm_panel base;
27+
struct mipi_dsi_device *link;
28+
29+
struct regulator_bulk_data supplies[NUM_SUPPLIES];
30+
31+
struct gpio_desc *reset_gpio;
32+
33+
struct drm_dsc_config dsc;
34+
};
35+
36+
static inline struct sw43408_panel *to_panel_info(struct drm_panel *panel)
37+
{
38+
return container_of(panel, struct sw43408_panel, base);
39+
}
40+
41+
static int sw43408_unprepare(struct drm_panel *panel)
42+
{
43+
struct sw43408_panel *ctx = to_panel_info(panel);
44+
int ret;
45+
46+
ret = mipi_dsi_dcs_set_display_off(ctx->link);
47+
if (ret < 0)
48+
dev_err(panel->dev, "set_display_off cmd failed ret = %d\n", ret);
49+
50+
ret = mipi_dsi_dcs_enter_sleep_mode(ctx->link);
51+
if (ret < 0)
52+
dev_err(panel->dev, "enter_sleep cmd failed ret = %d\n", ret);
53+
54+
msleep(100);
55+
56+
gpiod_set_value(ctx->reset_gpio, 1);
57+
58+
return regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
59+
}
60+
61+
static int sw43408_program(struct drm_panel *panel)
62+
{
63+
struct sw43408_panel *ctx = to_panel_info(panel);
64+
struct drm_dsc_picture_parameter_set pps;
65+
66+
mipi_dsi_dcs_write_seq(ctx->link, MIPI_DCS_SET_GAMMA_CURVE, 0x02);
67+
68+
mipi_dsi_dcs_set_tear_on(ctx->link, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
69+
70+
mipi_dsi_dcs_write_seq(ctx->link, 0x53, 0x0c, 0x30);
71+
mipi_dsi_dcs_write_seq(ctx->link, 0x55, 0x00, 0x70, 0xdf, 0x00, 0x70, 0xdf);
72+
mipi_dsi_dcs_write_seq(ctx->link, 0xf7, 0x01, 0x49, 0x0c);
73+
74+
mipi_dsi_dcs_exit_sleep_mode(ctx->link);
75+
76+
msleep(135);
77+
78+
/* COMPRESSION_MODE moved after setting the PPS */
79+
80+
mipi_dsi_dcs_write_seq(ctx->link, 0xb0, 0xac);
81+
mipi_dsi_dcs_write_seq(ctx->link, 0xe5,
82+
0x00, 0x3a, 0x00, 0x3a, 0x00, 0x0e, 0x10);
83+
mipi_dsi_dcs_write_seq(ctx->link, 0xb5,
84+
0x75, 0x60, 0x2d, 0x5d, 0x80, 0x00, 0x0a, 0x0b,
85+
0x00, 0x05, 0x0b, 0x00, 0x80, 0x0d, 0x0e, 0x40,
86+
0x00, 0x0c, 0x00, 0x16, 0x00, 0xb8, 0x00, 0x80,
87+
0x0d, 0x0e, 0x40, 0x00, 0x0c, 0x00, 0x16, 0x00,
88+
0xb8, 0x00, 0x81, 0x00, 0x03, 0x03, 0x03, 0x01,
89+
0x01);
90+
msleep(85);
91+
mipi_dsi_dcs_write_seq(ctx->link, 0xcd,
92+
0x00, 0x00, 0x00, 0x19, 0x19, 0x19, 0x19, 0x19,
93+
0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19,
94+
0x16, 0x16);
95+
mipi_dsi_dcs_write_seq(ctx->link, 0xcb, 0x80, 0x5c, 0x07, 0x03, 0x28);
96+
mipi_dsi_dcs_write_seq(ctx->link, 0xc0, 0x02, 0x02, 0x0f);
97+
mipi_dsi_dcs_write_seq(ctx->link, 0x55, 0x04, 0x61, 0xdb, 0x04, 0x70, 0xdb);
98+
mipi_dsi_dcs_write_seq(ctx->link, 0xb0, 0xca);
99+
100+
mipi_dsi_dcs_set_display_on(ctx->link);
101+
102+
msleep(50);
103+
104+
ctx->link->mode_flags &= ~MIPI_DSI_MODE_LPM;
105+
106+
drm_dsc_pps_payload_pack(&pps, ctx->link->dsc);
107+
mipi_dsi_picture_parameter_set(ctx->link, &pps);
108+
109+
ctx->link->mode_flags |= MIPI_DSI_MODE_LPM;
110+
111+
/*
112+
* This panel uses PPS selectors with offset:
113+
* PPS 1 if pps_identifier is 0
114+
* PPS 2 if pps_identifier is 1
115+
*/
116+
mipi_dsi_compression_mode_ext(ctx->link, true,
117+
MIPI_DSI_COMPRESSION_DSC, 1);
118+
119+
return 0;
120+
}
121+
122+
static int sw43408_prepare(struct drm_panel *panel)
123+
{
124+
struct sw43408_panel *ctx = to_panel_info(panel);
125+
int ret;
126+
127+
ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
128+
if (ret < 0)
129+
return ret;
130+
131+
usleep_range(5000, 6000);
132+
133+
gpiod_set_value(ctx->reset_gpio, 0);
134+
usleep_range(9000, 10000);
135+
gpiod_set_value(ctx->reset_gpio, 1);
136+
usleep_range(1000, 2000);
137+
gpiod_set_value(ctx->reset_gpio, 0);
138+
usleep_range(9000, 10000);
139+
140+
ret = sw43408_program(panel);
141+
if (ret)
142+
goto poweroff;
143+
144+
return 0;
145+
146+
poweroff:
147+
gpiod_set_value(ctx->reset_gpio, 1);
148+
regulator_bulk_disable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
149+
return ret;
150+
}
151+
152+
static const struct drm_display_mode sw43408_mode = {
153+
.clock = (1080 + 20 + 32 + 20) * (2160 + 20 + 4 + 20) * 60 / 1000,
154+
155+
.hdisplay = 1080,
156+
.hsync_start = 1080 + 20,
157+
.hsync_end = 1080 + 20 + 32,
158+
.htotal = 1080 + 20 + 32 + 20,
159+
160+
.vdisplay = 2160,
161+
.vsync_start = 2160 + 20,
162+
.vsync_end = 2160 + 20 + 4,
163+
.vtotal = 2160 + 20 + 4 + 20,
164+
165+
.width_mm = 62,
166+
.height_mm = 124,
167+
168+
.type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
169+
};
170+
171+
static int sw43408_get_modes(struct drm_panel *panel,
172+
struct drm_connector *connector)
173+
{
174+
return drm_connector_helper_get_modes_fixed(connector, &sw43408_mode);
175+
}
176+
177+
static int sw43408_backlight_update_status(struct backlight_device *bl)
178+
{
179+
struct mipi_dsi_device *dsi = bl_get_data(bl);
180+
u16 brightness = backlight_get_brightness(bl);
181+
182+
return mipi_dsi_dcs_set_display_brightness_large(dsi, brightness);
183+
}
184+
185+
const struct backlight_ops sw43408_backlight_ops = {
186+
.update_status = sw43408_backlight_update_status,
187+
};
188+
189+
static int sw43408_backlight_init(struct sw43408_panel *ctx)
190+
{
191+
struct device *dev = &ctx->link->dev;
192+
const struct backlight_properties props = {
193+
.type = BACKLIGHT_PLATFORM,
194+
.brightness = 255,
195+
.max_brightness = 255,
196+
};
197+
198+
ctx->base.backlight = devm_backlight_device_register(dev, dev_name(dev), dev,
199+
ctx->link,
200+
&sw43408_backlight_ops,
201+
&props);
202+
203+
if (IS_ERR(ctx->base.backlight))
204+
return dev_err_probe(dev, PTR_ERR(ctx->base.backlight),
205+
"Failed to create backlight\n");
206+
207+
return 0;
208+
}
209+
210+
static const struct drm_panel_funcs sw43408_funcs = {
211+
.unprepare = sw43408_unprepare,
212+
.prepare = sw43408_prepare,
213+
.get_modes = sw43408_get_modes,
214+
};
215+
216+
static const struct of_device_id sw43408_of_match[] = {
217+
{ .compatible = "lg,sw43408", },
218+
{ /* sentinel */ }
219+
};
220+
MODULE_DEVICE_TABLE(of, sw43408_of_match);
221+
222+
static int sw43408_add(struct sw43408_panel *ctx)
223+
{
224+
struct device *dev = &ctx->link->dev;
225+
int ret;
226+
227+
ctx->supplies[0].supply = "vddi"; /* 1.88 V */
228+
ctx->supplies[0].init_load_uA = 62000;
229+
ctx->supplies[1].supply = "vpnl"; /* 3.0 V */
230+
ctx->supplies[1].init_load_uA = 857000;
231+
232+
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ctx->supplies),
233+
ctx->supplies);
234+
if (ret < 0)
235+
return ret;
236+
237+
ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
238+
if (IS_ERR(ctx->reset_gpio)) {
239+
ret = PTR_ERR(ctx->reset_gpio);
240+
return dev_err_probe(dev, ret, "cannot get reset gpio\n");
241+
}
242+
243+
ret = sw43408_backlight_init(ctx);
244+
if (ret < 0)
245+
return ret;
246+
247+
ctx->base.prepare_prev_first = true;
248+
249+
drm_panel_init(&ctx->base, dev, &sw43408_funcs, DRM_MODE_CONNECTOR_DSI);
250+
251+
drm_panel_add(&ctx->base);
252+
return ret;
253+
}
254+
255+
static int sw43408_probe(struct mipi_dsi_device *dsi)
256+
{
257+
struct sw43408_panel *ctx;
258+
int ret;
259+
260+
ctx = devm_kzalloc(&dsi->dev, sizeof(*ctx), GFP_KERNEL);
261+
if (!ctx)
262+
return -ENOMEM;
263+
264+
dsi->mode_flags = MIPI_DSI_MODE_LPM;
265+
dsi->format = MIPI_DSI_FMT_RGB888;
266+
dsi->lanes = 4;
267+
268+
ctx->link = dsi;
269+
mipi_dsi_set_drvdata(dsi, ctx);
270+
271+
ret = sw43408_add(ctx);
272+
if (ret < 0)
273+
return ret;
274+
275+
/* The panel works only in the DSC mode. Set DSC params. */
276+
ctx->dsc.dsc_version_major = 0x1;
277+
ctx->dsc.dsc_version_minor = 0x1;
278+
279+
/* slice_count * slice_width == width */
280+
ctx->dsc.slice_height = 16;
281+
ctx->dsc.slice_width = 540;
282+
ctx->dsc.slice_count = 2;
283+
ctx->dsc.bits_per_component = 8;
284+
ctx->dsc.bits_per_pixel = 8 << 4;
285+
ctx->dsc.block_pred_enable = true;
286+
287+
dsi->dsc = &ctx->dsc;
288+
289+
return mipi_dsi_attach(dsi);
290+
}
291+
292+
static void sw43408_remove(struct mipi_dsi_device *dsi)
293+
{
294+
struct sw43408_panel *ctx = mipi_dsi_get_drvdata(dsi);
295+
int ret;
296+
297+
ret = sw43408_unprepare(&ctx->base);
298+
if (ret < 0)
299+
dev_err(&dsi->dev, "failed to unprepare panel: %d\n", ret);
300+
301+
ret = mipi_dsi_detach(dsi);
302+
if (ret < 0)
303+
dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", ret);
304+
305+
drm_panel_remove(&ctx->base);
306+
}
307+
308+
static struct mipi_dsi_driver sw43408_driver = {
309+
.driver = {
310+
.name = "panel-lg-sw43408",
311+
.of_match_table = sw43408_of_match,
312+
},
313+
.probe = sw43408_probe,
314+
.remove = sw43408_remove,
315+
};
316+
module_mipi_dsi_driver(sw43408_driver);
317+
318+
MODULE_AUTHOR("Sumit Semwal <[email protected]>");
319+
MODULE_DESCRIPTION("LG SW436408 MIPI-DSI LED panel");
320+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)