blob: b6c5b058b2e967bbbd47ab3c3ce5ca52c7804409 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasscd9c2072016-01-21 19:44:59 -07002/*
3 * Copyright (c) 2016 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glasscd9c2072016-01-21 19:44:59 -07005 */
6
Simon Glasscd9c2072016-01-21 19:44:59 -07007#include <backlight.h>
8#include <dm.h>
Svyatoslav Ryhel25ca3312024-01-08 18:45:01 +02009#include <edid.h>
10#include <i2c.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Svyatoslav Ryhelcc54a922023-03-27 11:11:50 +030012#include <mipi_dsi.h>
Simon Glasscd9c2072016-01-21 19:44:59 -070013#include <panel.h>
14#include <asm/gpio.h>
15#include <power/regulator.h>
16
Svyatoslav Ryhel25ca3312024-01-08 18:45:01 +020017#define EDID_I2C_ADDR 0x50
18
Simon Glasscd9c2072016-01-21 19:44:59 -070019struct simple_panel_priv {
20 struct udevice *reg;
21 struct udevice *backlight;
22 struct gpio_desc enable;
23};
24
25static int simple_panel_enable_backlight(struct udevice *dev)
26{
27 struct simple_panel_priv *priv = dev_get_priv(dev);
28 int ret;
29
Simon Glass1a9f3da2017-06-12 06:21:38 -060030 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
Simon Glasscd9c2072016-01-21 19:44:59 -070031 dm_gpio_set_value(&priv->enable, 1);
32 ret = backlight_enable(priv->backlight);
Simon Glass1a9f3da2017-06-12 06:21:38 -060033 debug("%s: done, ret = %d\n", __func__, ret);
Simon Glasscd9c2072016-01-21 19:44:59 -070034 if (ret)
35 return ret;
36
37 return 0;
38}
39
Simon Glassa4f737a2018-10-01 12:22:41 -060040static int simple_panel_set_backlight(struct udevice *dev, int percent)
41{
42 struct simple_panel_priv *priv = dev_get_priv(dev);
43 int ret;
44
45 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
46 dm_gpio_set_value(&priv->enable, 1);
47 ret = backlight_set_brightness(priv->backlight, percent);
48 debug("%s: done, ret = %d\n", __func__, ret);
49 if (ret)
50 return ret;
51
52 return 0;
53}
54
Svyatoslav Ryhel25ca3312024-01-08 18:45:01 +020055#if CONFIG_IS_ENABLED(I2C_EDID) && CONFIG_IS_ENABLED(DM_I2C)
56static int simple_panel_get_edid_timing(struct udevice *dev,
57 struct display_timing *timings)
58{
59 struct udevice *panel_ddc, *panel_edid;
60 struct display_timing edid_timing;
61 u8 edid_buf[EDID_SIZE] = { 0 };
62 int ret, bpc;
63 /* Check for DDC i2c if no timings are provided */
64 ret = uclass_get_device_by_phandle(UCLASS_I2C, dev,
65 "ddc-i2c-bus",
66 &panel_ddc);
67 if (ret) {
68 log_debug("%s: cannot get DDC i2c bus: error %d\n",
69 __func__, ret);
70 return ret;
71 }
72
73 ret = dm_i2c_probe(panel_ddc, EDID_I2C_ADDR, 0, &panel_edid);
74 if (ret) {
75 log_debug("%s: cannot probe EDID: error %d\n",
76 __func__, ret);
77 return ret;
78 }
79
80 ret = dm_i2c_read(panel_edid, 0, edid_buf, sizeof(edid_buf));
81 if (ret) {
82 log_debug("%s: cannot dump EDID buffer: error %d\n",
83 __func__, ret);
84 return ret;
85 }
86
87 ret = edid_get_timing(edid_buf, sizeof(edid_buf),
88 &edid_timing, &bpc);
89 if (ret) {
90 log_debug("%s: cannot decode EDID info: error %d\n",
91 __func__, ret);
92 return ret;
93 }
94
95 memcpy(timings, &edid_timing, sizeof(*timings));
96
97 return 0;
98}
99#else
100static int simple_panel_get_edid_timing(struct udevice *dev,
101 struct display_timing *timings)
102{
103 return -ENOTSUPP;
104}
105#endif
106
Svyatoslav Ryhel86cb1bd2023-03-27 11:11:49 +0300107static int simple_panel_get_display_timing(struct udevice *dev,
108 struct display_timing *timings)
109{
110 const void *blob = gd->fdt_blob;
Svyatoslav Ryhel25ca3312024-01-08 18:45:01 +0200111 int ret;
Svyatoslav Ryhel86cb1bd2023-03-27 11:11:49 +0300112
Svyatoslav Ryhel25ca3312024-01-08 18:45:01 +0200113 /* Check for timing subnode if panel node first */
114 ret = fdtdec_decode_display_timing(blob, dev_of_offset(dev),
115 0, timings);
116 if (!ret)
117 return ret;
118
119 return simple_panel_get_edid_timing(dev, timings);
Svyatoslav Ryhel86cb1bd2023-03-27 11:11:49 +0300120}
121
Simon Glassd1998a92020-12-03 16:55:21 -0700122static int simple_panel_of_to_plat(struct udevice *dev)
Simon Glasscd9c2072016-01-21 19:44:59 -0700123{
124 struct simple_panel_priv *priv = dev_get_priv(dev);
125 int ret;
126
Marek Vasut641c5952023-02-28 02:55:22 +0100127 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
Simon Glasse23c6c22016-03-06 19:27:48 -0700128 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
129 "power-supply", &priv->reg);
130 if (ret) {
Marcel Ziswiler28c694c2016-09-28 11:24:06 +0200131 debug("%s: Warning: cannot get power supply: ret=%d\n",
Simon Glasse23c6c22016-03-06 19:27:48 -0700132 __func__, ret);
133 if (ret != -ENOENT)
134 return ret;
135 }
Simon Glasscd9c2072016-01-21 19:44:59 -0700136 }
Nikhil M Jain3ebe3c72023-01-31 15:35:16 +0530137
Simon Glasscd9c2072016-01-21 19:44:59 -0700138 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
Nikhil M Jain3ebe3c72023-01-31 15:35:16 +0530139 "backlight", &priv->backlight);
Simon Glasscd9c2072016-01-21 19:44:59 -0700140 if (ret) {
141 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
Nikhil M Jain3ebe3c72023-01-31 15:35:16 +0530142 if (ret != -ENOENT)
143 return log_ret(ret);
Simon Glasscd9c2072016-01-21 19:44:59 -0700144 }
Nikhil M Jain3ebe3c72023-01-31 15:35:16 +0530145
Simon Glasscd9c2072016-01-21 19:44:59 -0700146 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
147 GPIOD_IS_OUT);
148 if (ret) {
149 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
150 __func__, ret);
151 if (ret != -ENOENT)
Simon Glassa4f737a2018-10-01 12:22:41 -0600152 return log_ret(ret);
Simon Glasscd9c2072016-01-21 19:44:59 -0700153 }
154
155 return 0;
156}
157
158static int simple_panel_probe(struct udevice *dev)
159{
160 struct simple_panel_priv *priv = dev_get_priv(dev);
Svyatoslav Ryhelcc54a922023-03-27 11:11:50 +0300161 struct mipi_dsi_panel_plat *plat = dev_get_plat(dev);
Svyatoslav Ryhel02bb9972024-01-08 18:45:00 +0200162 struct mipi_dsi_panel_plat *dsi_data =
163 (struct mipi_dsi_panel_plat *)dev_get_driver_data(dev);
Simon Glasscd9c2072016-01-21 19:44:59 -0700164 int ret;
165
Svyatoslav Ryhel66ac14f2023-10-03 09:25:33 +0300166 ret = regulator_set_enable_if_allowed(priv->reg, true);
167 if (ret && ret != -ENOSYS) {
168 debug("%s: failed to enable regulator '%s' %d\n",
169 __func__, priv->reg->name, ret);
170 return ret;
Simon Glasscd9c2072016-01-21 19:44:59 -0700171 }
172
Svyatoslav Ryhel02bb9972024-01-08 18:45:00 +0200173 if (dsi_data)
174 memcpy(plat, dsi_data, sizeof(struct mipi_dsi_panel_plat));
Svyatoslav Ryhelcc54a922023-03-27 11:11:50 +0300175
Simon Glasscd9c2072016-01-21 19:44:59 -0700176 return 0;
177}
178
179static const struct panel_ops simple_panel_ops = {
180 .enable_backlight = simple_panel_enable_backlight,
Simon Glassa4f737a2018-10-01 12:22:41 -0600181 .set_backlight = simple_panel_set_backlight,
Svyatoslav Ryhel86cb1bd2023-03-27 11:11:49 +0300182 .get_display_timing = simple_panel_get_display_timing,
Simon Glasscd9c2072016-01-21 19:44:59 -0700183};
184
Svyatoslav Ryhel02bb9972024-01-08 18:45:00 +0200185static const struct mipi_dsi_panel_plat panasonic_vvx10f004b00 = {
186 .mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
187 MIPI_DSI_CLOCK_NON_CONTINUOUS,
188 .format = MIPI_DSI_FMT_RGB888,
189 .lanes = 4,
190};
191
Simon Glasscd9c2072016-01-21 19:44:59 -0700192static const struct udevice_id simple_panel_ids[] = {
193 { .compatible = "simple-panel" },
Simon Glassd7659212016-01-30 16:37:50 -0700194 { .compatible = "auo,b133xtn01" },
Simon Glassbb5930d2016-02-21 21:09:01 -0700195 { .compatible = "auo,b116xw03" },
196 { .compatible = "auo,b133htn01" },
Peter Robinsonea166372020-04-20 20:27:32 +0100197 { .compatible = "boe,nv140fhmn49" },
Heiko Schocher85288ff2019-05-27 08:14:39 +0200198 { .compatible = "lg,lb070wv8" },
Alper Nebi Yasak92a81432020-10-28 00:41:54 +0300199 { .compatible = "sharp,lq123p1jx31" },
Alper Nebi Yasakf4576802020-10-28 00:41:55 +0300200 { .compatible = "boe,nv101wxmn51" },
Svyatoslav Ryhelcc54a922023-03-27 11:11:50 +0300201 { .compatible = "panasonic,vvx10f004b00",
Svyatoslav Ryhel02bb9972024-01-08 18:45:00 +0200202 .data = (ulong)&panasonic_vvx10f004b00 },
Simon Glasscd9c2072016-01-21 19:44:59 -0700203 { }
204};
205
206U_BOOT_DRIVER(simple_panel) = {
Svyatoslav Ryhelcc54a922023-03-27 11:11:50 +0300207 .name = "simple_panel",
208 .id = UCLASS_PANEL,
209 .of_match = simple_panel_ids,
210 .ops = &simple_panel_ops,
Simon Glassd1998a92020-12-03 16:55:21 -0700211 .of_to_plat = simple_panel_of_to_plat,
Simon Glasscd9c2072016-01-21 19:44:59 -0700212 .probe = simple_panel_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700213 .priv_auto = sizeof(struct simple_panel_priv),
Svyatoslav Ryhelcc54a922023-03-27 11:11:50 +0300214 .plat_auto = sizeof(struct mipi_dsi_panel_plat),
Simon Glasscd9c2072016-01-21 19:44:59 -0700215};