blob: efb122b534acee377628241658681d4aa26ecdff [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass6aa801b2016-01-21 19:44:59 -07002/*
3 * Copyright (c) 2016 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glass6aa801b2016-01-21 19:44:59 -07005 */
6
7#include <common.h>
8#include <backlight.h>
9#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +030011#include <mipi_dsi.h>
Simon Glass6aa801b2016-01-21 19:44:59 -070012#include <panel.h>
13#include <asm/gpio.h>
14#include <power/regulator.h>
15
Simon Glass6aa801b2016-01-21 19:44:59 -070016struct simple_panel_priv {
17 struct udevice *reg;
18 struct udevice *backlight;
19 struct gpio_desc enable;
20};
21
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +030022/* List of supported DSI panels */
23enum {
24 PANEL_NON_DSI,
25 PANASONIC_VVX10F004B00,
26};
27
28static 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 Glass6aa801b2016-01-21 19:44:59 -070035static int simple_panel_enable_backlight(struct udevice *dev)
36{
37 struct simple_panel_priv *priv = dev_get_priv(dev);
38 int ret;
39
Simon Glasscc06f142017-06-12 06:21:38 -060040 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
Simon Glass6aa801b2016-01-21 19:44:59 -070041 dm_gpio_set_value(&priv->enable, 1);
42 ret = backlight_enable(priv->backlight);
Simon Glasscc06f142017-06-12 06:21:38 -060043 debug("%s: done, ret = %d\n", __func__, ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070044 if (ret)
45 return ret;
46
47 return 0;
48}
49
Simon Glassfe68a452018-10-01 12:22:41 -060050static 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 Ryhelf9260032023-03-27 11:11:49 +030065static 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 Glassaad29ae2020-12-03 16:55:21 -070074static int simple_panel_of_to_plat(struct udevice *dev)
Simon Glass6aa801b2016-01-21 19:44:59 -070075{
76 struct simple_panel_priv *priv = dev_get_priv(dev);
77 int ret;
78
Marek Vasutbbdd1352023-02-28 02:55:22 +010079 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
Simon Glass29199212016-03-06 19:27:48 -070080 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
81 "power-supply", &priv->reg);
82 if (ret) {
Marcel Ziswiler07e0c272016-09-28 11:24:06 +020083 debug("%s: Warning: cannot get power supply: ret=%d\n",
Simon Glass29199212016-03-06 19:27:48 -070084 __func__, ret);
85 if (ret != -ENOENT)
86 return ret;
87 }
Simon Glass6aa801b2016-01-21 19:44:59 -070088 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +053089
Simon Glass6aa801b2016-01-21 19:44:59 -070090 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
Nikhil M Jainc76eda62023-01-31 15:35:16 +053091 "backlight", &priv->backlight);
Simon Glass6aa801b2016-01-21 19:44:59 -070092 if (ret) {
93 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
Nikhil M Jainc76eda62023-01-31 15:35:16 +053094 if (ret != -ENOENT)
95 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070096 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +053097
Simon Glass6aa801b2016-01-21 19:44:59 -070098 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 Glassfe68a452018-10-01 12:22:41 -0600104 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -0700105 }
106
107 return 0;
108}
109
110static int simple_panel_probe(struct udevice *dev)
111{
112 struct simple_panel_priv *priv = dev_get_priv(dev);
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300113 struct mipi_dsi_panel_plat *plat = dev_get_plat(dev);
114 const u32 dsi_data = dev_get_driver_data(dev);
Simon Glass6aa801b2016-01-21 19:44:59 -0700115 int ret;
116
Svyatoslav Ryhela085c732023-10-03 09:25:33 +0300117 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 Glass6aa801b2016-01-21 19:44:59 -0700122 }
123
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300124 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 Glass6aa801b2016-01-21 19:44:59 -0700134 return 0;
135}
136
137static const struct panel_ops simple_panel_ops = {
138 .enable_backlight = simple_panel_enable_backlight,
Simon Glassfe68a452018-10-01 12:22:41 -0600139 .set_backlight = simple_panel_set_backlight,
Svyatoslav Ryhelf9260032023-03-27 11:11:49 +0300140 .get_display_timing = simple_panel_get_display_timing,
Simon Glass6aa801b2016-01-21 19:44:59 -0700141};
142
143static const struct udevice_id simple_panel_ids[] = {
144 { .compatible = "simple-panel" },
Simon Glassfad72182016-01-30 16:37:50 -0700145 { .compatible = "auo,b133xtn01" },
Simon Glassa1015ad2016-02-21 21:09:01 -0700146 { .compatible = "auo,b116xw03" },
147 { .compatible = "auo,b133htn01" },
Peter Robinson6a0e7a62020-04-20 20:27:32 +0100148 { .compatible = "boe,nv140fhmn49" },
Heiko Schocher8ab5d502019-05-27 08:14:39 +0200149 { .compatible = "lg,lb070wv8" },
Alper Nebi Yasak641c7a22020-10-28 00:41:54 +0300150 { .compatible = "sharp,lq123p1jx31" },
Alper Nebi Yasak4cdbb252020-10-28 00:41:55 +0300151 { .compatible = "boe,nv101wxmn51" },
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300152 { .compatible = "panasonic,vvx10f004b00",
153 .data = PANASONIC_VVX10F004B00 },
Simon Glass6aa801b2016-01-21 19:44:59 -0700154 { }
155};
156
157U_BOOT_DRIVER(simple_panel) = {
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300158 .name = "simple_panel",
159 .id = UCLASS_PANEL,
160 .of_match = simple_panel_ids,
161 .ops = &simple_panel_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700162 .of_to_plat = simple_panel_of_to_plat,
Simon Glass6aa801b2016-01-21 19:44:59 -0700163 .probe = simple_panel_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700164 .priv_auto = sizeof(struct simple_panel_priv),
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300165 .plat_auto = sizeof(struct mipi_dsi_panel_plat),
Simon Glass6aa801b2016-01-21 19:44:59 -0700166};