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