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> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 11 | #include <mipi_dsi.h> |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 12 | #include <panel.h> |
| 13 | #include <asm/gpio.h> |
| 14 | #include <power/regulator.h> |
| 15 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 16 | struct simple_panel_priv { |
| 17 | struct udevice *reg; |
| 18 | struct udevice *backlight; |
| 19 | struct gpio_desc enable; |
| 20 | }; |
| 21 | |
| 22 | static int simple_panel_enable_backlight(struct udevice *dev) |
| 23 | { |
| 24 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 25 | int ret; |
| 26 | |
Simon Glass | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 27 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 28 | dm_gpio_set_value(&priv->enable, 1); |
| 29 | ret = backlight_enable(priv->backlight); |
Simon Glass | cc06f14 | 2017-06-12 06:21:38 -0600 | [diff] [blame] | 30 | debug("%s: done, ret = %d\n", __func__, ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 31 | if (ret) |
| 32 | return ret; |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 37 | static int simple_panel_set_backlight(struct udevice *dev, int percent) |
| 38 | { |
| 39 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 40 | int ret; |
| 41 | |
| 42 | debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name); |
| 43 | dm_gpio_set_value(&priv->enable, 1); |
| 44 | ret = backlight_set_brightness(priv->backlight, percent); |
| 45 | debug("%s: done, ret = %d\n", __func__, ret); |
| 46 | if (ret) |
| 47 | return ret; |
| 48 | |
| 49 | return 0; |
| 50 | } |
| 51 | |
Svyatoslav Ryhel | f926003 | 2023-03-27 11:11:49 +0300 | [diff] [blame] | 52 | static int simple_panel_get_display_timing(struct udevice *dev, |
| 53 | struct display_timing *timings) |
| 54 | { |
| 55 | const void *blob = gd->fdt_blob; |
| 56 | |
| 57 | return fdtdec_decode_display_timing(blob, dev_of_offset(dev), |
| 58 | 0, timings); |
| 59 | } |
| 60 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 61 | static int simple_panel_of_to_plat(struct udevice *dev) |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 62 | { |
| 63 | struct simple_panel_priv *priv = dev_get_priv(dev); |
| 64 | int ret; |
| 65 | |
Marek Vasut | bbdd135 | 2023-02-28 02:55:22 +0100 | [diff] [blame] | 66 | if (CONFIG_IS_ENABLED(DM_REGULATOR)) { |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 67 | ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev, |
| 68 | "power-supply", &priv->reg); |
| 69 | if (ret) { |
Marcel Ziswiler | 07e0c27 | 2016-09-28 11:24:06 +0200 | [diff] [blame] | 70 | debug("%s: Warning: cannot get power supply: ret=%d\n", |
Simon Glass | 2919921 | 2016-03-06 19:27:48 -0700 | [diff] [blame] | 71 | __func__, ret); |
| 72 | if (ret != -ENOENT) |
| 73 | return ret; |
| 74 | } |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 75 | } |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 76 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 77 | ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev, |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 78 | "backlight", &priv->backlight); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 79 | if (ret) { |
| 80 | debug("%s: Cannot get backlight: ret=%d\n", __func__, ret); |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 81 | if (ret != -ENOENT) |
| 82 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 83 | } |
Nikhil M Jain | c76eda6 | 2023-01-31 15:35:16 +0530 | [diff] [blame] | 84 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 85 | ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable, |
| 86 | GPIOD_IS_OUT); |
| 87 | if (ret) { |
| 88 | debug("%s: Warning: cannot get enable GPIO: ret=%d\n", |
| 89 | __func__, ret); |
| 90 | if (ret != -ENOENT) |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 91 | return log_ret(ret); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int simple_panel_probe(struct udevice *dev) |
| 98 | { |
| 99 | struct simple_panel_priv *priv = dev_get_priv(dev); |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 100 | struct mipi_dsi_panel_plat *plat = dev_get_plat(dev); |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame^] | 101 | struct mipi_dsi_panel_plat *dsi_data = |
| 102 | (struct mipi_dsi_panel_plat *)dev_get_driver_data(dev); |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 103 | int ret; |
| 104 | |
Svyatoslav Ryhel | a085c73 | 2023-10-03 09:25:33 +0300 | [diff] [blame] | 105 | ret = regulator_set_enable_if_allowed(priv->reg, true); |
| 106 | if (ret && ret != -ENOSYS) { |
| 107 | debug("%s: failed to enable regulator '%s' %d\n", |
| 108 | __func__, priv->reg->name, ret); |
| 109 | return ret; |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame^] | 112 | if (dsi_data) |
| 113 | memcpy(plat, dsi_data, sizeof(struct mipi_dsi_panel_plat)); |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 114 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | static const struct panel_ops simple_panel_ops = { |
| 119 | .enable_backlight = simple_panel_enable_backlight, |
Simon Glass | fe68a45 | 2018-10-01 12:22:41 -0600 | [diff] [blame] | 120 | .set_backlight = simple_panel_set_backlight, |
Svyatoslav Ryhel | f926003 | 2023-03-27 11:11:49 +0300 | [diff] [blame] | 121 | .get_display_timing = simple_panel_get_display_timing, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 122 | }; |
| 123 | |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame^] | 124 | static const struct mipi_dsi_panel_plat panasonic_vvx10f004b00 = { |
| 125 | .mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE | |
| 126 | MIPI_DSI_CLOCK_NON_CONTINUOUS, |
| 127 | .format = MIPI_DSI_FMT_RGB888, |
| 128 | .lanes = 4, |
| 129 | }; |
| 130 | |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 131 | static const struct udevice_id simple_panel_ids[] = { |
| 132 | { .compatible = "simple-panel" }, |
Simon Glass | fad7218 | 2016-01-30 16:37:50 -0700 | [diff] [blame] | 133 | { .compatible = "auo,b133xtn01" }, |
Simon Glass | a1015ad | 2016-02-21 21:09:01 -0700 | [diff] [blame] | 134 | { .compatible = "auo,b116xw03" }, |
| 135 | { .compatible = "auo,b133htn01" }, |
Peter Robinson | 6a0e7a6 | 2020-04-20 20:27:32 +0100 | [diff] [blame] | 136 | { .compatible = "boe,nv140fhmn49" }, |
Heiko Schocher | 8ab5d50 | 2019-05-27 08:14:39 +0200 | [diff] [blame] | 137 | { .compatible = "lg,lb070wv8" }, |
Alper Nebi Yasak | 641c7a2 | 2020-10-28 00:41:54 +0300 | [diff] [blame] | 138 | { .compatible = "sharp,lq123p1jx31" }, |
Alper Nebi Yasak | 4cdbb25 | 2020-10-28 00:41:55 +0300 | [diff] [blame] | 139 | { .compatible = "boe,nv101wxmn51" }, |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 140 | { .compatible = "panasonic,vvx10f004b00", |
Svyatoslav Ryhel | 0405999 | 2024-01-08 18:45:00 +0200 | [diff] [blame^] | 141 | .data = (ulong)&panasonic_vvx10f004b00 }, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 142 | { } |
| 143 | }; |
| 144 | |
| 145 | U_BOOT_DRIVER(simple_panel) = { |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 146 | .name = "simple_panel", |
| 147 | .id = UCLASS_PANEL, |
| 148 | .of_match = simple_panel_ids, |
| 149 | .ops = &simple_panel_ops, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 150 | .of_to_plat = simple_panel_of_to_plat, |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 151 | .probe = simple_panel_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 152 | .priv_auto = sizeof(struct simple_panel_priv), |
Svyatoslav Ryhel | 47508aa | 2023-03-27 11:11:50 +0300 | [diff] [blame] | 153 | .plat_auto = sizeof(struct mipi_dsi_panel_plat), |
Simon Glass | 6aa801b | 2016-01-21 19:44:59 -0700 | [diff] [blame] | 154 | }; |