Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | // SPDX-License-Identifier: GPL-2.0+ /* * LG LH400WV3-SD04 DSI panel driver * * Copyright (c) 2025 Svyatoslav Ryhel <clamor95@gmail.com> */ #include <backlight.h> #include <dm.h> #include <panel.h> #include <log.h> #include <mipi_dsi.h> #include <linux/delay.h> #include <power/regulator.h> #include <asm/gpio.h> struct lg_lh400wv3_priv { struct udevice *avci; struct udevice *iovcc; struct udevice *backlight; struct gpio_desc reset_gpio; }; static struct display_timing default_timing = { .pixelclock.typ = 29816000, .hactive.typ = 480, .hfront_porch.typ = 10, .hback_porch.typ = 10, .hsync_len.typ = 10, .vactive.typ = 800, .vfront_porch.typ = 4, .vback_porch.typ = 4, .vsync_len.typ = 4, }; #define dsi_generic_write_seq(dsi, cmd, seq...) do { \ static const u8 b[] = { cmd, seq }; \ int ret; \ ret = mipi_dsi_dcs_write_buffer(dsi, b, ARRAY_SIZE(b)); \ if (ret < 0) \ return ret; \ } while (0) static int lg_lh400wv3_enable_backlight(struct udevice *dev) { struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); struct mipi_dsi_device *dsi = plat->device; int ret; dsi_generic_write_seq(dsi, MIPI_DCS_EXIT_INVERT_MODE); dsi_generic_write_seq(dsi, MIPI_DCS_SET_TEAR_ON); ret = mipi_dsi_dcs_set_pixel_format(dsi, MIPI_DCS_PIXEL_FMT_24BIT | MIPI_DCS_PIXEL_FMT_24BIT << 4); if (ret < 0) { log_debug("%s: failed to set pixel format: %d\n", __func__, ret); return ret; } dsi_generic_write_seq(dsi, 0xb2, 0x00, 0xc8); dsi_generic_write_seq(dsi, 0xb3, 0x00); dsi_generic_write_seq(dsi, 0xb4, 0x04); dsi_generic_write_seq(dsi, 0xb5, 0x42, 0x10, 0x10, 0x00, 0x20); dsi_generic_write_seq(dsi, 0xb6, 0x0b, 0x0f, 0x3c, 0x13, 0x13, 0xe8); dsi_generic_write_seq(dsi, 0xb7, 0x4c, 0x06, 0x0c, 0x00, 0x00); dsi_generic_write_seq(dsi, 0xc0, 0x01, 0x11); dsi_generic_write_seq(dsi, 0xc3, 0x07, 0x03, 0x04, 0x04, 0x04); dsi_generic_write_seq(dsi, 0xc4, 0x12, 0x24, 0x18, 0x18, 0x02, 0x49); dsi_generic_write_seq(dsi, 0xc5, 0x65); dsi_generic_write_seq(dsi, 0xc6, 0x41, 0x63); dsi_generic_write_seq(dsi, 0xd0, 0x00, 0x46, 0x74, 0x32, 0x1d, 0x03, 0x51, 0x15, 0x04); dsi_generic_write_seq(dsi, 0xd1, 0x00, 0x46, 0x74, 0x32, 0x1d, 0x03, 0x51, 0x15, 0x04); dsi_generic_write_seq(dsi, 0xd2, 0x00, 0x46, 0x74, 0x32, 0x1f, 0x03, 0x51, 0x15, 0x04); dsi_generic_write_seq(dsi, 0xd3, 0x00, 0x46, 0x74, 0x32, 0x1f, 0x03, 0x51, 0x15, 0x04); dsi_generic_write_seq(dsi, 0xd4, 0x01, 0x46, 0x74, 0x25, 0x00, 0x03, 0x51, 0x15, 0x04); dsi_generic_write_seq(dsi, 0xd5, 0x01, 0x46, 0x74, 0x25, 0x00, 0x03, 0x51, 0x15, 0x04); dsi_generic_write_seq(dsi, MIPI_DCS_SET_COLUMN_ADDRESS, 0x00, 0x00, 0x01, 0xdf); dsi_generic_write_seq(dsi, MIPI_DCS_SET_PAGE_ADDRESS, 0x00, 0x00, 0x03, 0x1f); ret = mipi_dsi_dcs_exit_sleep_mode(dsi); if (ret < 0) { log_debug("%s: failed to exit sleep mode: %d\n", __func__, ret); return ret; } mdelay(120); dsi_generic_write_seq(dsi, MIPI_DCS_WRITE_MEMORY_START); ret = mipi_dsi_dcs_set_display_on(dsi); if (ret < 0) { log_debug("%s: failed to set display on: %d\n", __func__, ret); return ret; } return 0; } static int lg_lh400wv3_set_backlight(struct udevice *dev, int percent) { struct lg_lh400wv3_priv *priv = dev_get_priv(dev); int ret; ret = backlight_enable(priv->backlight); if (ret) return ret; return backlight_set_brightness(priv->backlight, percent); } static int lg_lh400wv3_timings(struct udevice *dev, struct display_timing *timing) { memcpy(timing, &default_timing, sizeof(*timing)); return 0; } static int lg_lh400wv3_of_to_plat(struct udevice *dev) { struct lg_lh400wv3_priv *priv = dev_get_priv(dev); int ret; ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, "backlight", &priv->backlight); if (ret) { log_debug("%s: cannot get backlight: ret = %d\n", __func__, ret); return ret; } ret = device_get_supply_regulator(dev, "avci-supply", &priv->avci); if (ret) { log_debug("%s: cannot get avci-supply: ret = %d\n", __func__, ret); return ret; } ret = device_get_supply_regulator(dev, "iovcc-supply", &priv->iovcc); if (ret) { log_debug("%s: cannot get iovcc-supply: ret = %d\n", __func__, ret); return ret; } ret = gpio_request_by_name(dev, "reset-gpios", 0, &priv->reset_gpio, GPIOD_IS_OUT); if (ret) { log_debug("%s: cannot decode reset-gpios (%d)\n", __func__, ret); return ret; } return 0; } static int lg_lh400wv3_hw_init(struct udevice *dev) { struct lg_lh400wv3_priv *priv = dev_get_priv(dev); int ret; ret = dm_gpio_set_value(&priv->reset_gpio, 1); if (ret) { log_debug("%s: error entering reset (%d)\n", __func__, ret); return ret; } ret = regulator_set_enable_if_allowed(priv->iovcc, 1); if (ret) { log_debug("%s: enabling iovcc-supply failed (%d)\n", __func__, ret); return ret; } ret = regulator_set_enable_if_allowed(priv->avci, 1); if (ret) { log_debug("%s: enabling avci-supply failed (%d)\n", __func__, ret); return ret; } mdelay(1); ret = dm_gpio_set_value(&priv->reset_gpio, 0); if (ret) { log_debug("%s: error exiting reset (%d)\n", __func__, ret); return ret; } mdelay(10); return 0; } static int lg_lh400wv3_probe(struct udevice *dev) { struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); /* fill characteristics of DSI data link */ plat->lanes = 2; plat->format = MIPI_DSI_FMT_RGB888; plat->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_LPM; return lg_lh400wv3_hw_init(dev); } static const struct panel_ops lg_lh400wv3_ops = { .enable_backlight = lg_lh400wv3_enable_backlight, .set_backlight = lg_lh400wv3_set_backlight, .get_display_timing = lg_lh400wv3_timings, }; static const struct udevice_id lg_lh400wv3_ids[] = { { .compatible = "lg,lh400wv3-sd04" }, { } }; U_BOOT_DRIVER(lg_lh400wv3) = { .name = "lg_lh400wv3", .id = UCLASS_PANEL, .of_match = lg_lh400wv3_ids, .ops = &lg_lh400wv3_ops, .of_to_plat = lg_lh400wv3_of_to_plat, .probe = lg_lh400wv3_probe, .plat_auto = sizeof(struct mipi_dsi_panel_plat), .priv_auto = sizeof(struct lg_lh400wv3_priv), }; |