Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <backlight.h> |
| 9 | #include <dm.h> |
Svyatoslav Ryhel | a12d740 | 2024-01-08 18:45:01 +0200 | [diff] [blame] | 10 | #include <edid.h> |
| 11 | #include <i2c.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 13 | #include <mipi_dsi.h> |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 14 | #include <panel.h> |
| 15 | #include <asm/gpio.h> |
| 16 | #include <power/regulator.h> |
| 17 | |
Svyatoslav Ryhel | a12d740 | 2024-01-08 18:45:01 +0200 | [diff] [blame] | 18 | #define EDID_I2C_ADDR 0x50 |
| 19 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 20 | struct simple_panel_priv { |
| 21 | struct udevice *reg; |
| 22 | struct udevice *backlight; |
| 23 | struct gpio_desc enable; |
| 24 | }; |
| 25 | |
| 26 | static int simple_panel_enable_backlight(struct udevice *dev) |
| 27 | { |
| 28 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 29 | int ret; |
| 30 | |
Simon Glass | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 31 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 32 | dm_gpio_set_value(&priv->enable, 1); |
| 33 | ret = backlight_enable(priv->backlight); |
Simon Glass | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 34 | debug("%s: done, ret = %d\n", __func__, ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 35 | if (ret) |
| 36 | return ret; |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 41 | static 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 Ryhel | a12d740 | 2024-01-08 18:45:01 +0200 | [diff] [blame] | 56 | #if CONFIG_IS_ENABLED(I2C_EDID) && CONFIG_IS_ENABLED(DM_I2C) |
| 57 | static 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 |
| 101 | static int simple_panel_get_edid_timing(struct udevice *dev, |
| 102 | struct display_timing *timings) |
| 103 | { |
| 104 | return -ENOTSUPP; |
| 105 | } |
| 106 | #endif |
| 107 | |
Svyatoslav Ryhel | f926003 | 2023-03-27 11:11:49 +0300 | [diff] [blame] | 108 | static int simple_panel_get_display_timing(struct udevice *dev, |
| 109 | struct display_timing *timings) |
| 110 | { |
| 111 | const void *blob = gd->fdt_blob; |
Svyatoslav Ryhel | a12d740 | 2024-01-08 18:45:01 +0200 | [diff] [blame] | 112 | 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 Ryhel | f926003 | 2023-03-27 11:11:49 +0300 | [diff] [blame] | 119 | |
Svyatoslav Ryhel | a12d740 | 2024-01-08 18:45:01 +0200 | [diff] [blame] | 120 | return simple_panel_get_edid_timing(dev, timings); |
Svyatoslav Ryhel | f926003 | 2023-03-27 11:11:49 +0300 | [diff] [blame] | 121 | } |
| 122 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 123 | static int simple_panel_of_to_plat(struct udevice *dev) |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 124 | { |
| 125 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 126 | int ret; |
| 127 | |
Marek Vasut | bbdd135 | 2023-02-28 02:55:22 +0100 | [diff] [blame] | 128 | if (CONFIG_IS_ENABLED(DM_REGULATOR)) { |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 129 | ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, |
| 130 | "power-supply", &priv->reg); |
| 131 | if (ret) { |
Marcel Ziswiler | 07e0c27 | 2016-09-28 11:24:06 +0200 | [diff] [blame] | 132 | debug("%s: Warning: cannot get power supply: ret=%d\n", |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 133 | __func__, ret); |
| 134 | if (ret != -ENOENT) |
| 135 | return ret; |
| 136 | } |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 137 | } |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 138 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 139 | ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 140 | "backlight", &priv->backlight); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 141 | if (ret) { |
| 142 | debug("%s: Cannot get backlight: ret=%d\n", __func__, ret); |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 143 | if (ret != -ENOENT) |
| 144 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 145 | } |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 146 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 147 | 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 Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 153 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static int simple_panel_probe(struct udevice *dev) |
| 160 | { |
| 161 | struct simple_panel_priv *priv = dev_get_priv(dev); |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 162 | struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame] | 163 | struct mipi_dsi_panel_plat *dsi_data = |
| 164 | (struct mipi_dsi_panel_plat *)dev_get_driver_data(dev); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 165 | int ret; |
| 166 | |
Svyatoslav Ryhel | a085c73 | 2023-10-03 09:25:33 +0300 | [diff] [blame] | 167 | 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 Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame] | 174 | if (dsi_data) |
| 175 | memcpy(plat, dsi_data, sizeof(struct mipi_dsi_panel_plat)); |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 176 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static const struct panel_ops simple_panel_ops = { |
| 181 | .enable_backlight = simple_panel_enable_backlight, |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 182 | .set_backlight = simple_panel_set_backlight, |
Svyatoslav Ryhel | f926003 | 2023-03-27 11:11:49 +0300 | [diff] [blame] | 183 | .get_display_timing = simple_panel_get_display_timing, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame] | 186 | static 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 Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 193 | static const struct udevice_id simple_panel_ids[] = { |
| 194 | { .compatible = "simple-panel" }, |
Simon Glass | fad7218 | 2016-01-30 16:37:50 -0700 | [diff] [blame] | 195 | { .compatible = "auo,b133xtn01" }, |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 196 | { .compatible = "auo,b116xw03" }, |
| 197 | { .compatible = "auo,b133htn01" }, |
Peter Robinson | 6a0e7a6 | 2020-04-20 20:27:32 +0100 | [diff] [blame] | 198 | { .compatible = "boe,nv140fhmn49" }, |
Heiko Schocher | 8ab5d50 | 2019-05-27 08:14:39 +0200 | [diff] [blame] | 199 | { .compatible = "lg,lb070wv8" }, |
Alper Nebi Yasak | 641c7a2 | 2020-10-28 00:41:54 +0300 | [diff] [blame] | 200 | { .compatible = "sharp,lq123p1jx31" }, |
Alper Nebi Yasak | 4cdbb25 | 2020-10-28 00:41:55 +0300 | [diff] [blame] | 201 | { .compatible = "boe,nv101wxmn51" }, |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 202 | { .compatible = "panasonic,vvx10f004b00", |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame] | 203 | .data = (ulong)&panasonic_vvx10f004b00 }, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 204 | { } |
| 205 | }; |
| 206 | |
| 207 | U_BOOT_DRIVER(simple_panel) = { |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 208 | .name = "simple_panel", |
| 209 | .id = UCLASS_PANEL, |
| 210 | .of_match = simple_panel_ids, |
| 211 | .ops = &simple_panel_ops, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 212 | .of_to_plat = simple_panel_of_to_plat, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 213 | .probe = simple_panel_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 214 | .priv_auto = sizeof(struct simple_panel_priv), |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 215 | .plat_auto = sizeof(struct mipi_dsi_panel_plat), |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 216 | }; |