1 // SPDX-License-Identifier: GPL-2.0-only
3 * Driver for the Samsung S6E3FA7 panel.
5 * Copyright (c) 2022-2024, The Linux Foundation. All rights reserved.
6 * Generated with linux-mdss-dsi-panel-driver-generator from vendor device tree:
7 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
10 #include <linux/backlight.h>
11 #include <linux/delay.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/module.h>
16 #include <video/mipi_display.h>
18 #include <drm/drm_mipi_dsi.h>
19 #include <drm/drm_modes.h>
20 #include <drm/drm_panel.h>
22 struct s6e3fa7_panel {
23 struct drm_panel panel;
24 struct mipi_dsi_device *dsi;
25 struct gpio_desc *reset_gpio;
28 static inline struct s6e3fa7_panel *to_s6e3fa7_panel(struct drm_panel *panel)
30 return container_of(panel, struct s6e3fa7_panel, panel);
33 static void s6e3fa7_panel_reset(struct s6e3fa7_panel *ctx)
35 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
36 usleep_range(1000, 2000);
37 gpiod_set_value_cansleep(ctx->reset_gpio, 0);
38 usleep_range(10000, 11000);
41 static int s6e3fa7_panel_on(struct s6e3fa7_panel *ctx)
43 struct mipi_dsi_device *dsi = ctx->dsi;
44 struct device *dev = &dsi->dev;
47 ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
49 dev_err(dev, "Failed to exit sleep mode: %d\n", ret);
54 ret = mipi_dsi_dcs_set_tear_on(dsi, MIPI_DSI_DCS_TEAR_MODE_VBLANK);
56 dev_err(dev, "Failed to set tear on: %d\n", ret);
60 mipi_dsi_dcs_write_seq(dsi, 0xf0, 0x5a, 0x5a);
61 mipi_dsi_dcs_write_seq(dsi, 0xf4,
62 0xbb, 0x23, 0x19, 0x3a, 0x9f, 0x0f, 0x09, 0xc0,
63 0x00, 0xb4, 0x37, 0x70, 0x79, 0x69);
64 mipi_dsi_dcs_write_seq(dsi, 0xf0, 0xa5, 0xa5);
65 mipi_dsi_dcs_write_seq(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, 0x20);
67 ret = mipi_dsi_dcs_set_display_on(dsi);
69 dev_err(dev, "Failed to set display on: %d\n", ret);
76 static int s6e3fa7_panel_prepare(struct drm_panel *panel)
78 struct s6e3fa7_panel *ctx = to_s6e3fa7_panel(panel);
79 struct device *dev = &ctx->dsi->dev;
82 s6e3fa7_panel_reset(ctx);
84 ret = s6e3fa7_panel_on(ctx);
86 dev_err(dev, "Failed to initialize panel: %d\n", ret);
87 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
94 static int s6e3fa7_panel_unprepare(struct drm_panel *panel)
96 struct s6e3fa7_panel *ctx = to_s6e3fa7_panel(panel);
98 gpiod_set_value_cansleep(ctx->reset_gpio, 1);
103 static int s6e3fa7_panel_disable(struct drm_panel *panel)
105 struct s6e3fa7_panel *ctx = to_s6e3fa7_panel(panel);
106 struct mipi_dsi_device *dsi = ctx->dsi;
107 struct device *dev = &dsi->dev;
110 ret = mipi_dsi_dcs_set_display_off(dsi);
112 dev_err(dev, "Failed to set display off: %d\n", ret);
116 ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
118 dev_err(dev, "Failed to enter sleep mode: %d\n", ret);
126 static const struct drm_display_mode s6e3fa7_panel_mode = {
127 .clock = (1080 + 32 + 32 + 78) * (2220 + 32 + 4 + 78) * 60 / 1000,
129 .hsync_start = 1080 + 32,
130 .hsync_end = 1080 + 32 + 32,
131 .htotal = 1080 + 32 + 32 + 78,
133 .vsync_start = 2220 + 32,
134 .vsync_end = 2220 + 32 + 4,
135 .vtotal = 2220 + 32 + 4 + 78,
140 static int s6e3fa7_panel_get_modes(struct drm_panel *panel,
141 struct drm_connector *connector)
143 struct drm_display_mode *mode;
145 mode = drm_mode_duplicate(connector->dev, &s6e3fa7_panel_mode);
149 drm_mode_set_name(mode);
151 mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
152 connector->display_info.width_mm = mode->width_mm;
153 connector->display_info.height_mm = mode->height_mm;
154 drm_mode_probed_add(connector, mode);
159 static const struct drm_panel_funcs s6e3fa7_panel_funcs = {
160 .prepare = s6e3fa7_panel_prepare,
161 .unprepare = s6e3fa7_panel_unprepare,
162 .disable = s6e3fa7_panel_disable,
163 .get_modes = s6e3fa7_panel_get_modes,
166 static int s6e3fa7_panel_bl_update_status(struct backlight_device *bl)
168 struct mipi_dsi_device *dsi = bl_get_data(bl);
169 u16 brightness = backlight_get_brightness(bl);
172 ret = mipi_dsi_dcs_set_display_brightness_large(dsi, brightness);
179 static int s6e3fa7_panel_bl_get_brightness(struct backlight_device *bl)
181 struct mipi_dsi_device *dsi = bl_get_data(bl);
185 ret = mipi_dsi_dcs_get_display_brightness_large(dsi, &brightness);
192 static const struct backlight_ops s6e3fa7_panel_bl_ops = {
193 .update_status = s6e3fa7_panel_bl_update_status,
194 .get_brightness = s6e3fa7_panel_bl_get_brightness,
197 static struct backlight_device *
198 s6e3fa7_panel_create_backlight(struct mipi_dsi_device *dsi)
200 struct device *dev = &dsi->dev;
201 const struct backlight_properties props = {
202 .type = BACKLIGHT_RAW,
204 .max_brightness = 1023,
207 return devm_backlight_device_register(dev, dev_name(dev), dev, dsi,
208 &s6e3fa7_panel_bl_ops, &props);
211 static int s6e3fa7_panel_probe(struct mipi_dsi_device *dsi)
213 struct device *dev = &dsi->dev;
214 struct s6e3fa7_panel *ctx;
217 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
221 ctx->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
222 if (IS_ERR(ctx->reset_gpio))
223 return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio),
224 "Failed to get reset-gpios\n");
227 mipi_dsi_set_drvdata(dsi, ctx);
230 dsi->format = MIPI_DSI_FMT_RGB888;
231 dsi->mode_flags = MIPI_DSI_MODE_VIDEO_BURST |
232 MIPI_DSI_CLOCK_NON_CONTINUOUS | MIPI_DSI_MODE_LPM;
234 drm_panel_init(&ctx->panel, dev, &s6e3fa7_panel_funcs,
235 DRM_MODE_CONNECTOR_DSI);
236 ctx->panel.prepare_prev_first = true;
238 ctx->panel.backlight = s6e3fa7_panel_create_backlight(dsi);
239 if (IS_ERR(ctx->panel.backlight))
240 return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight),
241 "Failed to create backlight\n");
243 drm_panel_add(&ctx->panel);
245 ret = mipi_dsi_attach(dsi);
247 dev_err(dev, "Failed to attach to DSI host: %d\n", ret);
248 drm_panel_remove(&ctx->panel);
255 static void s6e3fa7_panel_remove(struct mipi_dsi_device *dsi)
257 struct s6e3fa7_panel *ctx = mipi_dsi_get_drvdata(dsi);
260 ret = mipi_dsi_detach(dsi);
262 dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n", ret);
264 drm_panel_remove(&ctx->panel);
267 static const struct of_device_id s6e3fa7_panel_of_match[] = {
268 { .compatible = "samsung,s6e3fa7-ams559nk06" },
271 MODULE_DEVICE_TABLE(of, s6e3fa7_panel_of_match);
273 static struct mipi_dsi_driver s6e3fa7_panel_driver = {
274 .probe = s6e3fa7_panel_probe,
275 .remove = s6e3fa7_panel_remove,
277 .name = "panel-samsung-s6e3fa7",
278 .of_match_table = s6e3fa7_panel_of_match,
281 module_mipi_dsi_driver(s6e3fa7_panel_driver);
284 MODULE_DESCRIPTION("DRM driver for Samsung S6E3FA7 command mode DSI panel");
285 MODULE_LICENSE("GPL");