// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2020 Theobroma Systems Design und Consulting GmbH
*/
#include <linux/delay.h>
#include <linux/gpio/consumer.h>
#include <linux/media-bus-format.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/regulator/consumer.h>
#include <video/display_timing.h>
#include <video/mipi_display.h>
#include <drm/drm_mipi_dsi.h>
#include <drm/drm_modes.h>
#include <drm/drm_panel.h>
struct ltk050h3146w_cmd {
char cmd;
char data;
};
struct ltk050h3146w;
struct ltk050h3146w_desc {
const unsigned long mode_flags;
const struct drm_display_mode *mode;
void (*init)(struct mipi_dsi_multi_context *dsi_ctx);
};
struct ltk050h3146w {
struct device *dev;
struct drm_panel panel;
struct gpio_desc *reset_gpio;
struct regulator *vci;
struct regulator *iovcc;
const struct ltk050h3146w_desc *panel_desc;
};
static const struct ltk050h3146w_cmd page1_cmds[] = {
{ 0 x22, 0 x0A }, /* BGR SS GS */
{ 0 x31, 0 x00 }, /* column inversion */
{ 0 x53, 0 xA2 }, /* VCOM1 */
{ 0 x55, 0 xA2 }, /* VCOM2 */
{ 0 x50, 0 x81 }, /* VREG1OUT=5V */
{ 0 x51, 0 x85 }, /* VREG2OUT=-5V */
{ 0 x62, 0 x0D }, /* EQT Time setting */
/*
* The vendor init selected page 1 here _again_
* Is this supposed to be page 2?
*/
{ 0 xA0, 0 x00 },
{ 0 xA1, 0 x1A },
{ 0 xA2, 0 x28 },
{ 0 xA3, 0 x13 },
{ 0 xA4, 0 x16 },
{ 0 xA5, 0 x29 },
{ 0 xA6, 0 x1D },
{ 0 xA7, 0 x1E },
{ 0 xA8, 0 x84 },
{ 0 xA9, 0 x1C },
{ 0 xAA, 0 x28 },
{ 0 xAB, 0 x75 },
{ 0 xAC, 0 x1A },
{ 0 xAD, 0 x19 },
{ 0 xAE, 0 x4D },
{ 0 xAF, 0 x22 },
{ 0 xB0, 0 x28 },
{ 0 xB1, 0 x54 },
{ 0 xB2, 0 x66 },
{ 0 xB3, 0 x39 },
{ 0 xC0, 0 x00 },
{ 0 xC1, 0 x1A },
{ 0 xC2, 0 x28 },
{ 0 xC3, 0 x13 },
{ 0 xC4, 0 x16 },
{ 0 xC5, 0 x29 },
{ 0 xC6, 0 x1D },
{ 0 xC7, 0 x1E },
{ 0 xC8, 0 x84 },
{ 0 xC9, 0 x1C },
{ 0 xCA, 0 x28 },
{ 0 xCB, 0 x75 },
{ 0 xCC, 0 x1A },
{ 0 xCD, 0 x19 },
{ 0 xCE, 0 x4D },
{ 0 xCF, 0 x22 },
{ 0 xD0, 0 x28 },
{ 0 xD1, 0 x54 },
{ 0 xD2, 0 x66 },
{ 0 xD3, 0 x39 },
};
static const struct ltk050h3146w_cmd page3_cmds[] = {
{ 0 x01, 0 x00 },
{ 0 x02, 0 x00 },
{ 0 x03, 0 x73 },
{ 0 x04, 0 x00 },
{ 0 x05, 0 x00 },
{ 0 x06, 0 x0a },
{ 0 x07, 0 x00 },
{ 0 x08, 0 x00 },
{ 0 x09, 0 x01 },
{ 0 x0a, 0 x00 },
{ 0 x0b, 0 x00 },
{ 0 x0c, 0 x01 },
{ 0 x0d, 0 x00 },
{ 0 x0e, 0 x00 },
{ 0 x0f, 0 x1d },
{ 0 x10, 0 x1d },
{ 0 x11, 0 x00 },
{ 0 x12, 0 x00 },
{ 0 x13, 0 x00 },
{ 0 x14, 0 x00 },
{ 0 x15, 0 x00 },
{ 0 x16, 0 x00 },
{ 0 x17, 0 x00 },
{ 0 x18, 0 x00 },
{ 0 x19, 0 x00 },
{ 0 x1a, 0 x00 },
{ 0 x1b, 0 x00 },
{ 0 x1c, 0 x00 },
{ 0 x1d, 0 x00 },
{ 0 x1e, 0 x40 },
{ 0 x1f, 0 x80 },
{ 0 x20, 0 x06 },
{ 0 x21, 0 x02 },
{ 0 x22, 0 x00 },
{ 0 x23, 0 x00 },
{ 0 x24, 0 x00 },
{ 0 x25, 0 x00 },
{ 0 x26, 0 x00 },
{ 0 x27, 0 x00 },
{ 0 x28, 0 x33 },
{ 0 x29, 0 x03 },
{ 0 x2a, 0 x00 },
{ 0 x2b, 0 x00 },
{ 0 x2c, 0 x00 },
{ 0 x2d, 0 x00 },
{ 0 x2e, 0 x00 },
{ 0 x2f, 0 x00 },
{ 0 x30, 0 x00 },
{ 0 x31, 0 x00 },
{ 0 x32, 0 x00 },
{ 0 x33, 0 x00 },
{ 0 x34, 0 x04 },
{ 0 x35, 0 x00 },
{ 0 x36, 0 x00 },
{ 0 x37, 0 x00 },
{ 0 x38, 0 x3C },
{ 0 x39, 0 x35 },
{ 0 x3A, 0 x01 },
{ 0 x3B, 0 x40 },
{ 0 x3C, 0 x00 },
{ 0 x3D, 0 x01 },
{ 0 x3E, 0 x00 },
{ 0 x3F, 0 x00 },
{ 0 x40, 0 x00 },
{ 0 x41, 0 x88 },
{ 0 x42, 0 x00 },
{ 0 x43, 0 x00 },
{ 0 x44, 0 x1F },
{ 0 x50, 0 x01 },
{ 0 x51, 0 x23 },
{ 0 x52, 0 x45 },
{ 0 x53, 0 x67 },
{ 0 x54, 0 x89 },
{ 0 x55, 0 xab },
{ 0 x56, 0 x01 },
{ 0 x57, 0 x23 },
{ 0 x58, 0 x45 },
{ 0 x59, 0 x67 },
{ 0 x5a, 0 x89 },
{ 0 x5b, 0 xab },
{ 0 x5c, 0 xcd },
{ 0 x5d, 0 xef },
{ 0 x5e, 0 x11 },
{ 0 x5f, 0 x01 },
{ 0 x60, 0 x00 },
{ 0 x61, 0 x15 },
{ 0 x62, 0 x14 },
{ 0 x63, 0 x0E },
{ 0 x64, 0 x0F },
{ 0 x65, 0 x0C },
{ 0 x66, 0 x0D },
{ 0 x67, 0 x06 },
{ 0 x68, 0 x02 },
{ 0 x69, 0 x07 },
{ 0 x6a, 0 x02 },
{ 0 x6b, 0 x02 },
{ 0 x6c, 0 x02 },
{ 0 x6d, 0 x02 },
{ 0 x6e, 0 x02 },
{ 0 x6f, 0 x02 },
{ 0 x70, 0 x02 },
{ 0 x71, 0 x02 },
{ 0 x72, 0 x02 },
{ 0 x73, 0 x02 },
{ 0 x74, 0 x02 },
{ 0 x75, 0 x01 },
{ 0 x76, 0 x00 },
{ 0 x77, 0 x14 },
{ 0 x78, 0 x15 },
{ 0 x79, 0 x0E },
{ 0 x7a, 0 x0F },
{ 0 x7b, 0 x0C },
{ 0 x7c, 0 x0D },
{ 0 x7d, 0 x06 },
{ 0 x7e, 0 x02 },
{ 0 x7f, 0 x07 },
{ 0 x80, 0 x02 },
{ 0 x81, 0 x02 },
{ 0 x82, 0 x02 },
{ 0 x83, 0 x02 },
{ 0 x84, 0 x02 },
{ 0 x85, 0 x02 },
{ 0 x86, 0 x02 },
{ 0 x87, 0 x02 },
{ 0 x88, 0 x02 },
{ 0 x89, 0 x02 },
{ 0 x8A, 0 x02 },
};
static const struct ltk050h3146w_cmd page4_cmds[] = {
{ 0 x70, 0 x00 },
{ 0 x71, 0 x00 },
{ 0 x82, 0 x0F }, /* VGH_MOD clamp level=15v */
{ 0 x84, 0 x0F }, /* VGH clamp level 15V */
{ 0 x85, 0 x0D }, /* VGL clamp level (-10V) */
{ 0 x32, 0 xAC },
{ 0 x8C, 0 x80 },
{ 0 x3C, 0 xF5 },
{ 0 xB5, 0 x07 }, /* GAMMA OP */
{ 0 x31, 0 x45 }, /* SOURCE OP */
{ 0 x3A, 0 x24 }, /* PS_EN OFF */
{ 0 x88, 0 x33 }, /* LVD */
};
static inline
struct ltk050h3146w *panel_to_ltk050h3146w(struct drm_panel *panel)
{
return container_of(panel, struct ltk050h3146w, panel);
}
static void ltk050h3148w_init_sequence(struct mipi_dsi_multi_context *dsi_ctx)
{
/*
* Init sequence was supplied by the panel vendor without much
* documentation.
*/
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb9, 0 xff, 0 x83, 0 x94);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb1, 0 x50, 0 x15, 0 x75, 0 x09, 0 x32, 0 x44,
0 x71, 0 x31, 0 x55, 0 x2f);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xba, 0 x63, 0 x03, 0 x68, 0 x6b, 0 xb2, 0 xc0);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd2, 0 x88);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb2, 0 x00, 0 x80, 0 x64, 0 x10, 0 x07);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb4, 0 x05, 0 x70, 0 x05, 0 x70, 0 x01, 0 x70,
0 x01, 0 x0c, 0 x86, 0 x75, 0 x00, 0 x3f, 0 x01, 0 x74,
0 x01, 0 x74, 0 x01, 0 x74, 0 x01, 0 x0c, 0 x86);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd3, 0 x00, 0 x00, 0 x07, 0 x07, 0 x40, 0 x1e,
0 x08, 0 x00, 0 x32, 0 x10, 0 x08, 0 x00, 0 x08, 0 x54,
0 x15, 0 x10, 0 x05, 0 x04, 0 x02, 0 x12, 0 x10, 0 x05,
0 x07, 0 x33, 0 x34, 0 x0c, 0 x0c, 0 x37, 0 x10, 0 x07,
0 x17, 0 x11, 0 x40);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd5, 0 x19, 0 x19, 0 x18, 0 x18, 0 x1b, 0 x1b,
0 x1a, 0 x1a, 0 x04, 0 x05, 0 x06, 0 x07, 0 x00, 0 x01,
0 x02, 0 x03, 0 x20, 0 x21, 0 x18, 0 x18, 0 x22, 0 x23,
0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18,
0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18,
0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd6, 0 x18, 0 x18, 0 x19, 0 x19, 0 x1b, 0 x1b,
0 x1a, 0 x1a, 0 x03, 0 x02, 0 x01, 0 x00, 0 x07, 0 x06,
0 x05, 0 x04, 0 x23, 0 x22, 0 x18, 0 x18, 0 x21, 0 x20,
0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18,
0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18,
0 x18, 0 x18, 0 x18, 0 x18, 0 x18, 0 x18);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xe0, 0 x00, 0 x03, 0 x09, 0 x11, 0 x11, 0 x14,
0 x18, 0 x16, 0 x2e, 0 x3d, 0 x4d, 0 x4d, 0 x58, 0 x6c,
0 x72, 0 x78, 0 x88, 0 x8b, 0 x86, 0 xa4, 0 xb2, 0 x58,
0 x55, 0 x59, 0 x5b, 0 x5d, 0 x60, 0 x64, 0 x7f, 0 x00,
0 x03, 0 x09, 0 x0f, 0 x11, 0 x14, 0 x18, 0 x16, 0 x2e,
0 x3d, 0 x4d, 0 x4d, 0 x58, 0 x6d, 0 x73, 0 x78, 0 x88,
0 x8b, 0 x87, 0 xa5, 0 xb2, 0 x58, 0 x55, 0 x58, 0 x5b,
0 x5d, 0 x61, 0 x65, 0 x7f);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xcc, 0 x0b);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc0, 0 x1f, 0 x31);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb6, 0 xc4, 0 xc4);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xbd, 0 x01);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb1, 0 x00);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xbd, 0 x00);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc6, 0 xef);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd4, 0 x02);
mipi_dsi_dcs_set_tear_on_multi(dsi_ctx, 1 );
mipi_dsi_msleep(dsi_ctx, 60 );
}
static const struct drm_display_mode ltk050h3148w_mode = {
.hdisplay = 720 ,
.hsync_start = 720 + 12 ,
.hsync_end = 720 + 12 + 6 ,
.htotal = 720 + 12 + 6 + 24 ,
.vdisplay = 1280 ,
.vsync_start = 1280 + 9 ,
.vsync_end = 1280 + 9 + 2 ,
.vtotal = 1280 + 9 + 2 + 16 ,
.clock = 59756 ,
.width_mm = 62 ,
.height_mm = 110 ,
};
static const struct ltk050h3146w_desc ltk050h3148w_data = {
.mode = <k050h3148w_mode,
.init = ltk050h3148w_init_sequence,
.mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
MIPI_DSI_MODE_VIDEO_BURST,
};
static void ltk050h3146w_init_sequence(struct mipi_dsi_multi_context *dsi_ctx)
{
/*
* Init sequence was supplied by the panel vendor without much
* documentation.
*/
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xdf, 0 x93, 0 x65, 0 xf8);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb0, 0 x01, 0 x03, 0 x02, 0 x00, 0 x64, 0 x06,
0 x01);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb2, 0 x00, 0 xb5);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb3, 0 x00, 0 xb5);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb7, 0 x00, 0 xbf, 0 x00, 0 x00, 0 xbf, 0 x00);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb9, 0 x00, 0 xc4, 0 x23, 0 x07);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xbb, 0 x02, 0 x01, 0 x24, 0 x00, 0 x28, 0 x0f,
0 x28, 0 x04, 0 xcc, 0 xcc, 0 xcc);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xbc, 0 x0f, 0 x04);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xbe, 0 x1e, 0 xf2);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc0, 0 x26, 0 x03);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc1, 0 x00, 0 x12);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc3, 0 x04, 0 x02, 0 x02, 0 x76, 0 x01, 0 x80,
0 x80);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc4, 0 x24, 0 x80, 0 xb4, 0 x81, 0 x12, 0 x0f,
0 x16, 0 x00, 0 x00);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc8, 0 x7f, 0 x72, 0 x67, 0 x5d, 0 x5d, 0 x50,
0 x56, 0 x41, 0 x59, 0 x57, 0 x55, 0 x70, 0 x5b, 0 x5f,
0 x4f, 0 x47, 0 x38, 0 x23, 0 x08, 0 x7f, 0 x72, 0 x67,
0 x5d, 0 x5d, 0 x50, 0 x56, 0 x41, 0 x59, 0 x57, 0 x55,
0 x70, 0 x5b, 0 x5f, 0 x4f, 0 x47, 0 x38, 0 x23, 0 x08);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd0, 0 x1e, 0 x1f, 0 x57, 0 x58, 0 x48, 0 x4a,
0 x44, 0 x46, 0 x40, 0 x1f, 0 x42, 0 x1f, 0 x1f, 0 x1f,
0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd1, 0 x1e, 0 x1f, 0 x57, 0 x58, 0 x49, 0 x4b,
0 x45, 0 x47, 0 x41, 0 x1f, 0 x43, 0 x1f, 0 x1f, 0 x1f,
0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd2, 0 x1f, 0 x1e, 0 x17, 0 x18, 0 x07, 0 x05,
0 x0b, 0 x09, 0 x03, 0 x1f, 0 x01, 0 x1f, 0 x1f, 0 x1f,
0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd3, 0 x1f, 0 x1e, 0 x17, 0 x18, 0 x06, 0 x04,
0 x0a, 0 x08, 0 x02, 0 x1f, 0 x00, 0 x1f, 0 x1f, 0 x1f,
0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f, 0 x1f);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd4, 0 x00, 0 x00, 0 x00, 0 x0c, 0 x06, 0 x20,
0 x01, 0 x02, 0 x00, 0 x60, 0 x15, 0 xb0, 0 x30, 0 x03,
0 x04, 0 x00, 0 x60, 0 x72, 0 x0a, 0 x00, 0 x60, 0 x08);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xd5, 0 x00, 0 x06, 0 x06, 0 x00, 0 x30, 0 x00,
0 x00, 0 x00, 0 x00, 0 x00, 0 xbc, 0 x50, 0 x00, 0 x05,
0 x21, 0 x00, 0 x60);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xdd, 0 x2c, 0 xa3, 0 x00);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xde, 0 x02);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb2, 0 x32, 0 x1c);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xb7, 0 x3b, 0 x70, 0 x00, 0 x04);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc1, 0 x11);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xbb, 0 x21, 0 x22, 0 x23, 0 x24, 0 x36, 0 x37);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xc2, 0 x20, 0 x38, 0 x1e, 0 x84);
mipi_dsi_dcs_write_seq_multi(dsi_ctx, 0 xde, 0 x00);
mipi_dsi_dcs_set_tear_on_multi(dsi_ctx, 1 );
mipi_dsi_msleep(dsi_ctx, 60 );
}
static const struct drm_display_mode ltk050h3146w_mode = {
.hdisplay = 720 ,
.hsync_start = 720 + 42 ,
.hsync_end = 720 + 42 + 8 ,
.htotal = 720 + 42 + 8 + 42 ,
.vdisplay = 1280 ,
.vsync_start = 1280 + 12 ,
.vsync_end = 1280 + 12 + 4 ,
.vtotal = 1280 + 12 + 4 + 18 ,
.clock = 64018 ,
.width_mm = 62 ,
.height_mm = 110 ,
};
static const struct ltk050h3146w_desc ltk050h3146w_data = {
.mode = <k050h3146w_mode,
.init = ltk050h3146w_init_sequence,
.mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
MIPI_DSI_MODE_LPM | MIPI_DSI_MODE_NO_EOT_PACKET,
};
static void ltk050h3146w_a2_select_page(struct mipi_dsi_multi_context *dsi_ctx, int page)
{
u8 d[4 ] = { 0 xff, 0 x98, 0 x81, page };
mipi_dsi_dcs_write_buffer_multi(dsi_ctx, d, ARRAY_SIZE(d));
}
static void ltk050h3146w_a2_write_page(struct mipi_dsi_multi_context *dsi_ctx, int page,
const struct ltk050h3146w_cmd *cmds,
int num)
{
ltk050h3146w_a2_select_page(dsi_ctx, page);
for (int i = 0 ; i < num; i++)
mipi_dsi_generic_write_multi(dsi_ctx, &cmds[i],
sizeof (struct ltk050h3146w_cmd));
}
static void ltk050h3146w_a2_init_sequence(struct mipi_dsi_multi_context *dsi_ctx)
{
/*
* Init sequence was supplied by the panel vendor without much
* documentation.
*/
ltk050h3146w_a2_write_page(dsi_ctx, 3 , page3_cmds,
ARRAY_SIZE(page3_cmds));
ltk050h3146w_a2_write_page(dsi_ctx, 4 , page4_cmds,
ARRAY_SIZE(page4_cmds));
ltk050h3146w_a2_write_page(dsi_ctx, 1 , page1_cmds,
ARRAY_SIZE(page1_cmds));
ltk050h3146w_a2_select_page(dsi_ctx, 0 );
/* vendor code called this without param, where there should be one */
mipi_dsi_dcs_set_tear_on_multi(dsi_ctx, 0 );
mipi_dsi_msleep(dsi_ctx, 60 );
}
static const struct drm_display_mode ltk050h3146w_a2_mode = {
.hdisplay = 720 ,
.hsync_start = 720 + 42 ,
.hsync_end = 720 + 42 + 10 ,
.htotal = 720 + 42 + 10 + 60 ,
.vdisplay = 1280 ,
.vsync_start = 1280 + 18 ,
.vsync_end = 1280 + 18 + 4 ,
.vtotal = 1280 + 18 + 4 + 12 ,
.clock = 65595 ,
.width_mm = 62 ,
.height_mm = 110 ,
};
static const struct ltk050h3146w_desc ltk050h3146w_a2_data = {
.mode = <k050h3146w_a2_mode,
.init = ltk050h3146w_a2_init_sequence,
.mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST |
MIPI_DSI_MODE_LPM | MIPI_DSI_MODE_NO_EOT_PACKET,
};
static int ltk050h3146w_unprepare(struct drm_panel *panel)
{
struct ltk050h3146w *ctx = panel_to_ltk050h3146w(panel);
struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
if (dsi_ctx.accum_err)
return dsi_ctx.accum_err;
regulator_disable(ctx->iovcc);
regulator_disable(ctx->vci);
return 0 ;
}
static int ltk050h3146w_prepare(struct drm_panel *panel)
{
struct ltk050h3146w *ctx = panel_to_ltk050h3146w(panel);
struct mipi_dsi_device *dsi = to_mipi_dsi_device(ctx->dev);
struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
dev_dbg(ctx->dev, "Resetting the panel\n" );
dsi_ctx.accum_err = regulator_enable(ctx->vci);
if (dsi_ctx.accum_err) {
dev_err(ctx->dev, "Failed to enable vci supply: %d\n" , dsi_ctx.accum_err);
return dsi_ctx.accum_err;
}
dsi_ctx.accum_err = regulator_enable(ctx->iovcc);
if (dsi_ctx.accum_err) {
dev_err(ctx->dev, "Failed to enable iovcc supply: %d\n" , dsi_ctx.accum_err);
goto disable_vci;
}
gpiod_set_value_cansleep(ctx->reset_gpio, 1 );
usleep_range(5000 , 6000 );
gpiod_set_value_cansleep(ctx->reset_gpio, 0 );
msleep(20 );
ctx->panel_desc->init(&dsi_ctx);
mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
/* T9: 120ms */
mipi_dsi_msleep(&dsi_ctx, 120 );
mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
mipi_dsi_msleep(&dsi_ctx, 50 );
if (dsi_ctx.accum_err)
goto disable_iovcc;
return 0 ;
disable_iovcc:
regulator_disable(ctx->iovcc);
disable_vci:
regulator_disable(ctx->vci);
return dsi_ctx.accum_err;
}
static int ltk050h3146w_get_modes(struct drm_panel *panel,
struct drm_connector *connector)
{
struct ltk050h3146w *ctx = panel_to_ltk050h3146w(panel);
struct drm_display_mode *mode;
mode = drm_mode_duplicate(connector->dev, ctx->panel_desc->mode);
if (!mode)
return -ENOMEM;
drm_mode_set_name(mode);
mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
connector->display_info.width_mm = mode->width_mm;
connector->display_info.height_mm = mode->height_mm;
drm_mode_probed_add(connector, mode);
return 1 ;
}
static const struct drm_panel_funcs ltk050h3146w_funcs = {
.unprepare = ltk050h3146w_unprepare,
.prepare = ltk050h3146w_prepare,
.get_modes = ltk050h3146w_get_modes,
};
static int ltk050h3146w_probe(struct mipi_dsi_device *dsi)
{
struct device *dev = &dsi->dev;
struct ltk050h3146w *ctx;
int ret;
ctx = devm_drm_panel_alloc(dev, struct ltk050h3146w, panel,
<k050h3146w_funcs,
DRM_MODE_CONNECTOR_DSI);
if (IS_ERR(ctx))
return PTR_ERR(ctx);
ctx->panel_desc = of_device_get_match_data(dev);
if (!ctx->panel_desc)
return -EINVAL;
ctx->reset_gpio = devm_gpiod_get_optional(dev, "reset" , GPIOD_OUT_LOW);
if (IS_ERR(ctx->reset_gpio))
return dev_err_probe(dev, PTR_ERR(ctx->reset_gpio), "cannot get reset gpio\n" );
ctx->vci = devm_regulator_get(dev, "vci" );
if (IS_ERR(ctx->vci))
return dev_err_probe(dev, PTR_ERR(ctx->vci), "Failed to request vci regulator\n" );
ctx->iovcc = devm_regulator_get(dev, "iovcc" );
if (IS_ERR(ctx->iovcc))
return dev_err_probe(dev, PTR_ERR(ctx->iovcc),
"Failed to request iovcc regulator\n" );
mipi_dsi_set_drvdata(dsi, ctx);
ctx->dev = dev;
dsi->lanes = 4 ;
dsi->format = MIPI_DSI_FMT_RGB888;
dsi->mode_flags = ctx->panel_desc->mode_flags;
ret = drm_panel_of_backlight(&ctx->panel);
if (ret)
return ret;
drm_panel_add(&ctx->panel);
ret = mipi_dsi_attach(dsi);
if (ret < 0 ) {
dev_err(dev, "mipi_dsi_attach failed: %d\n" , ret);
drm_panel_remove(&ctx->panel);
return ret;
}
return 0 ;
}
static void ltk050h3146w_remove(struct mipi_dsi_device *dsi)
{
struct ltk050h3146w *ctx = mipi_dsi_get_drvdata(dsi);
int ret;
ret = mipi_dsi_detach(dsi);
if (ret < 0 )
dev_err(&dsi->dev, "Failed to detach from DSI host: %d\n" , ret);
drm_panel_remove(&ctx->panel);
}
static const struct of_device_id ltk050h3146w_of_match[] = {
{
.compatible = "leadtek,ltk050h3146w" ,
.data = <k050h3146w_data,
},
{
.compatible = "leadtek,ltk050h3146w-a2" ,
.data = <k050h3146w_a2_data,
},
{
.compatible = "leadtek,ltk050h3148w" ,
.data = <k050h3148w_data,
},
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, ltk050h3146w_of_match);
static struct mipi_dsi_driver ltk050h3146w_driver = {
.driver = {
.name = "panel-leadtek-ltk050h3146w" ,
.of_match_table = ltk050h3146w_of_match,
},
.probe = ltk050h3146w_probe,
.remove = ltk050h3146w_remove,
};
module_mipi_dsi_driver(ltk050h3146w_driver);
MODULE_AUTHOR("Heiko Stuebner <heiko.stuebner@theobroma-systems.com>" );
MODULE_DESCRIPTION("DRM driver for Leadtek LTK050H3146W MIPI DSI panel" );
MODULE_LICENSE("GPL v2" );
Messung V0.5 in Prozent C=94 H=98 G=95
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet am 2026-06-05)
¤
*© Formatika GbR, Deutschland