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 | // SPDX-License-Identifier: GPL-2.0+ /* * LG LD070WX3-SL01 DSI panel driver * * Copyright (c) 2023 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> struct lg_ld070wx3_priv { struct udevice *vdd; struct udevice *vcc; struct udevice *backlight; }; static struct display_timing default_timing = { .pixelclock.typ = 70000000, .hactive.typ = 800, .hfront_porch.typ = 32, .hback_porch.typ = 48, .hsync_len.typ = 8, .vactive.typ = 1280, .vfront_porch.typ = 5, .vback_porch.typ = 3, .vsync_len.typ = 1, }; static void dcs_write_one(struct mipi_dsi_device *dsi, u8 cmd, u8 data) { mipi_dsi_dcs_write(dsi, cmd, &data, 1); } static int lg_ld070wx3_enable_backlight(struct udevice *dev) { struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); struct mipi_dsi_device *dsi = plat->device; int ret; ret = mipi_dsi_dcs_soft_reset(dsi); if (ret < 0) { log_debug("%s: failed to soft reset panel: %d\n", __func__, ret); return ret; } /* Delay before sending new command after soft reset */ mdelay(20); /* Differential input impedance selection */ dcs_write_one(dsi, 0xAE, 0x0B); /* Enter test mode 1 and 2*/ dcs_write_one(dsi, 0xEE, 0xEA); dcs_write_one(dsi, 0xEF, 0x5F); /* Increased MIPI CLK driving ability */ dcs_write_one(dsi, 0xF2, 0x68); /* Exit test mode 1 and 2 */ dcs_write_one(dsi, 0xEE, 0x00); dcs_write_one(dsi, 0xEF, 0x00); return 0; } static int lg_ld070wx3_set_backlight(struct udevice *dev, int percent) { struct lg_ld070wx3_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_ld070wx3_timings(struct udevice *dev, struct display_timing *timing) { memcpy(timing, &default_timing, sizeof(*timing)); return 0; } static int lg_ld070wx3_of_to_plat(struct udevice *dev) { struct lg_ld070wx3_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 = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, "vdd-supply", &priv->vdd); if (ret) { log_debug("%s: cannot get vdd-supply: ret = %d\n", __func__, ret); return ret; } ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, "vcc-supply", &priv->vcc); if (ret) { log_debug("%s: cannot get vcc-supply: ret = %d\n", __func__, ret); return ret; } return 0; } static int lg_ld070wx3_hw_init(struct udevice *dev) { struct lg_ld070wx3_priv *priv = dev_get_priv(dev); int ret; ret = regulator_set_enable_if_allowed(priv->vcc, 1); if (ret) { log_debug("%s: enabling vcc-supply failed (%d)\n", __func__, ret); return ret; } ret = regulator_set_enable_if_allowed(priv->vdd, 1); if (ret) { log_debug("%s: enabling vdd-supply failed (%d)\n", __func__, ret); return ret; } /* * According to spec delay between enabling supply is 0, * for regulators to reach required voltage ~5ms needed. * MIPI interface signal for setup requires additional * 110ms which in total results in 115ms. */ mdelay(115); return 0; } static int lg_ld070wx3_probe(struct udevice *dev) { struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); /* fill characteristics of DSI data link */ plat->lanes = 4; plat->format = MIPI_DSI_FMT_RGB888; plat->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_LPM; return lg_ld070wx3_hw_init(dev); } static const struct panel_ops lg_ld070wx3_ops = { .enable_backlight = lg_ld070wx3_enable_backlight, .set_backlight = lg_ld070wx3_set_backlight, .get_display_timing = lg_ld070wx3_timings, }; static const struct udevice_id lg_ld070wx3_ids[] = { { .compatible = "lg,ld070wx3-sl01" }, { } }; U_BOOT_DRIVER(lg_ld070wx3) = { .name = "lg_ld070wx3", .id = UCLASS_PANEL, .of_match = lg_ld070wx3_ids, .ops = &lg_ld070wx3_ops, .of_to_plat = lg_ld070wx3_of_to_plat, .probe = lg_ld070wx3_probe, .plat_auto = sizeof(struct mipi_dsi_panel_plat), .priv_auto = sizeof(struct lg_ld070wx3_priv), }; |