blob: 76a30427a59f2efa57230e54b0ce8a423aaa816f [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass6aa801b2016-01-21 19:44:59 -07002/*
3 * Copyright (c) 2016 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass6aa801b2016-01-21 19:44:59 -07005 */
6
7#include <common.h>
8#include <backlight.h>
9#include <dm.h>
Svyatoslav Ryhela12d7402024-01-08 18:45:01 +020010#include <edid.h>
11#include <i2c.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +030013#include <mipi_dsi.h>
Simon Glass6aa801b2016-01-21 19:44:59 -070014#include <panel.h>
15#include <asm/gpio.h>
16#include <power/regulator.h>
17
Svyatoslav Ryhela12d7402024-01-08 18:45:01 +020018#define EDID_I2C_ADDR 0x50
19
Simon Glass6aa801b2016-01-21 19:44:59 -070020struct simple_panel_priv {
21 struct udevice *reg;
22 struct udevice *backlight;
23 struct gpio_desc enable;
24};
25
26static int simple_panel_enable_backlight(struct udevice *dev)
27{
28 struct simple_panel_priv *priv = dev_get_priv(dev);
29 int ret;
30
Simon Glasscc06f142017-06-12 06:21:38 -060031 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
Simon Glass6aa801b2016-01-21 19:44:59 -070032 dm_gpio_set_value(&priv->enable, 1);
33 ret = backlight_enable(priv->backlight);
Simon Glasscc06f142017-06-12 06:21:38 -060034 debug("%s: done, ret = %d\n", __func__, ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070035 if (ret)
36 return ret;
37
38 return 0;
39}
40
Simon Glassfe68a452018-10-01 12:22:41 -060041static int simple_panel_set_backlight(struct udevice *dev, int percent)
42{
43 struct simple_panel_priv *priv = dev_get_priv(dev);
44 int ret;
45
46 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
47 dm_gpio_set_value(&priv->enable, 1);
48 ret = backlight_set_brightness(priv->backlight, percent);
49 debug("%s: done, ret = %d\n", __func__, ret);
50 if (ret)
51 return ret;
52
53 return 0;
54}
55
Svyatoslav Ryhela12d7402024-01-08 18:45:01 +020056#if CONFIG_IS_ENABLED(I2C_EDID) && CONFIG_IS_ENABLED(DM_I2C)
57static int simple_panel_get_edid_timing(struct udevice *dev,
58 struct display_timing *timings)
59{
60 struct udevice *panel_ddc, *panel_edid;
61 struct display_timing edid_timing;
62 u8 edid_buf[EDID_SIZE] = { 0 };
63 int ret, bpc;
64 /* Check for DDC i2c if no timings are provided */
65 ret = uclass_get_device_by_phandle(UCLASS_I2C, dev,
66 "ddc-i2c-bus",
67 &panel_ddc);
68 if (ret) {
69 log_debug("%s: cannot get DDC i2c bus: error %d\n",
70 __func__, ret);
71 return ret;
72 }
73
74 ret = dm_i2c_probe(panel_ddc, EDID_I2C_ADDR, 0, &panel_edid);
75 if (ret) {
76 log_debug("%s: cannot probe EDID: error %d\n",
77 __func__, ret);
78 return ret;
79 }
80
81 ret = dm_i2c_read(panel_edid, 0, edid_buf, sizeof(edid_buf));
82 if (ret) {
83 log_debug("%s: cannot dump EDID buffer: error %d\n",
84 __func__, ret);
85 return ret;
86 }
87
88 ret = edid_get_timing(edid_buf, sizeof(edid_buf),
89 &edid_timing, &bpc);
90 if (ret) {
91 log_debug("%s: cannot decode EDID info: error %d\n",
92 __func__, ret);
93 return ret;
94 }
95
96 memcpy(timings, &edid_timing, sizeof(*timings));
97
98 return 0;
99}
100#else
101static int simple_panel_get_edid_timing(struct udevice *dev,
102 struct display_timing *timings)
103{
104 return -ENOTSUPP;
105}
106#endif
107
Svyatoslav Ryhelf9260032023-03-27 11:11:49 +0300108static int simple_panel_get_display_timing(struct udevice *dev,
109 struct display_timing *timings)
110{
111 const void *blob = gd->fdt_blob;
Svyatoslav Ryhela12d7402024-01-08 18:45:01 +0200112 int ret;
113
114 /* Check for timing subnode if panel node first */
115 ret = fdtdec_decode_display_timing(blob, dev_of_offset(dev),
116 0, timings);
117 if (!ret)
118 return ret;
Svyatoslav Ryhelf9260032023-03-27 11:11:49 +0300119
Svyatoslav Ryhela12d7402024-01-08 18:45:01 +0200120 return simple_panel_get_edid_timing(dev, timings);
Svyatoslav Ryhelf9260032023-03-27 11:11:49 +0300121}
122
Simon Glassaad29ae2020-12-03 16:55:21 -0700123static int simple_panel_of_to_plat(struct udevice *dev)
Simon Glass6aa801b2016-01-21 19:44:59 -0700124{
125 struct simple_panel_priv *priv = dev_get_priv(dev);
126 int ret;
127
Marek Vasutbbdd1352023-02-28 02:55:22 +0100128 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
Simon Glass29199212016-03-06 19:27:48 -0700129 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
130 "power-supply", &priv->reg);
131 if (ret) {
Marcel Ziswiler07e0c272016-09-28 11:24:06 +0200132 debug("%s: Warning: cannot get power supply: ret=%d\n",
Simon Glass29199212016-03-06 19:27:48 -0700133 __func__, ret);
134 if (ret != -ENOENT)
135 return ret;
136 }
Simon Glass6aa801b2016-01-21 19:44:59 -0700137 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +0530138
Simon Glass6aa801b2016-01-21 19:44:59 -0700139 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
Nikhil M Jainc76eda62023-01-31 15:35:16 +0530140 "backlight", &priv->backlight);
Simon Glass6aa801b2016-01-21 19:44:59 -0700141 if (ret) {
142 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
Nikhil M Jainc76eda62023-01-31 15:35:16 +0530143 if (ret != -ENOENT)
144 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -0700145 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +0530146
Simon Glass6aa801b2016-01-21 19:44:59 -0700147 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
148 GPIOD_IS_OUT);
149 if (ret) {
150 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
151 __func__, ret);
152 if (ret != -ENOENT)
Simon Glassfe68a452018-10-01 12:22:41 -0600153 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -0700154 }
155
156 return 0;
157}
158
159static int simple_panel_probe(struct udevice *dev)
160{
161 struct simple_panel_priv *priv = dev_get_priv(dev);
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300162 struct mipi_dsi_panel_plat *plat = dev_get_plat(dev);
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200163 struct mipi_dsi_panel_plat *dsi_data =
164 (struct mipi_dsi_panel_plat *)dev_get_driver_data(dev);
Simon Glass6aa801b2016-01-21 19:44:59 -0700165 int ret;
166
Svyatoslav Ryhela085c732023-10-03 09:25:33 +0300167 ret = regulator_set_enable_if_allowed(priv->reg, true);
168 if (ret && ret != -ENOSYS) {
169 debug("%s: failed to enable regulator '%s' %d\n",
170 __func__, priv->reg->name, ret);
171 return ret;
Simon Glass6aa801b2016-01-21 19:44:59 -0700172 }
173
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200174 if (dsi_data)
175 memcpy(plat, dsi_data, sizeof(struct mipi_dsi_panel_plat));
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300176
Simon Glass6aa801b2016-01-21 19:44:59 -0700177 return 0;
178}
179
180static const struct panel_ops simple_panel_ops = {
181 .enable_backlight = simple_panel_enable_backlight,
Simon Glassfe68a452018-10-01 12:22:41 -0600182 .set_backlight = simple_panel_set_backlight,
Svyatoslav Ryhelf9260032023-03-27 11:11:49 +0300183 .get_display_timing = simple_panel_get_display_timing,
Simon Glass6aa801b2016-01-21 19:44:59 -0700184};
185
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200186static const struct mipi_dsi_panel_plat panasonic_vvx10f004b00 = {
187 .mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
188 MIPI_DSI_CLOCK_NON_CONTINUOUS,
189 .format = MIPI_DSI_FMT_RGB888,
190 .lanes = 4,
191};
192
Simon Glass6aa801b2016-01-21 19:44:59 -0700193static const struct udevice_id simple_panel_ids[] = {
194 { .compatible = "simple-panel" },
Simon Glassfad72182016-01-30 16:37:50 -0700195 { .compatible = "auo,b133xtn01" },
Simon Glassa1015ad2016-02-21 21:09:01 -0700196 { .compatible = "auo,b116xw03" },
197 { .compatible = "auo,b133htn01" },
Peter Robinson6a0e7a62020-04-20 20:27:32 +0100198 { .compatible = "boe,nv140fhmn49" },
Heiko Schocher8ab5d502019-05-27 08:14:39 +0200199 { .compatible = "lg,lb070wv8" },
Alper Nebi Yasak641c7a22020-10-28 00:41:54 +0300200 { .compatible = "sharp,lq123p1jx31" },
Alper Nebi Yasak4cdbb252020-10-28 00:41:55 +0300201 { .compatible = "boe,nv101wxmn51" },
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300202 { .compatible = "panasonic,vvx10f004b00",
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200203 .data = (ulong)&panasonic_vvx10f004b00 },
Simon Glass6aa801b2016-01-21 19:44:59 -0700204 { }
205};
206
207U_BOOT_DRIVER(simple_panel) = {
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300208 .name = "simple_panel",
209 .id = UCLASS_PANEL,
210 .of_match = simple_panel_ids,
211 .ops = &simple_panel_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700212 .of_to_plat = simple_panel_of_to_plat,
Simon Glass6aa801b2016-01-21 19:44:59 -0700213 .probe = simple_panel_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700214 .priv_auto = sizeof(struct simple_panel_priv),
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300215 .plat_auto = sizeof(struct mipi_dsi_panel_plat),
Simon Glass6aa801b2016-01-21 19:44:59 -0700216};