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