blob: 064c113d2d0905e3d41c1ad26a96812d31cc5f17 [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
22static int simple_panel_enable_backlight(struct udevice *dev)
23{
24 struct simple_panel_priv *priv = dev_get_priv(dev);
25 int ret;
26
Simon Glasscc06f142017-06-12 06:21:38 -060027 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
Simon Glass6aa801b2016-01-21 19:44:59 -070028 dm_gpio_set_value(&priv->enable, 1);
29 ret = backlight_enable(priv->backlight);
Simon Glasscc06f142017-06-12 06:21:38 -060030 debug("%s: done, ret = %d\n", __func__, ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070031 if (ret)
32 return ret;
33
34 return 0;
35}
36
Simon Glassfe68a452018-10-01 12:22:41 -060037static 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 Ryhelf9260032023-03-27 11:11:49 +030052static 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 Glassaad29ae2020-12-03 16:55:21 -070061static int simple_panel_of_to_plat(struct udevice *dev)
Simon Glass6aa801b2016-01-21 19:44:59 -070062{
63 struct simple_panel_priv *priv = dev_get_priv(dev);
64 int ret;
65
Marek Vasutbbdd1352023-02-28 02:55:22 +010066 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
Simon Glass29199212016-03-06 19:27:48 -070067 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
68 "power-supply", &priv->reg);
69 if (ret) {
Marcel Ziswiler07e0c272016-09-28 11:24:06 +020070 debug("%s: Warning: cannot get power supply: ret=%d\n",
Simon Glass29199212016-03-06 19:27:48 -070071 __func__, ret);
72 if (ret != -ENOENT)
73 return ret;
74 }
Simon Glass6aa801b2016-01-21 19:44:59 -070075 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +053076
Simon Glass6aa801b2016-01-21 19:44:59 -070077 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
Nikhil M Jainc76eda62023-01-31 15:35:16 +053078 "backlight", &priv->backlight);
Simon Glass6aa801b2016-01-21 19:44:59 -070079 if (ret) {
80 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
Nikhil M Jainc76eda62023-01-31 15:35:16 +053081 if (ret != -ENOENT)
82 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070083 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +053084
Simon Glass6aa801b2016-01-21 19:44:59 -070085 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 Glassfe68a452018-10-01 12:22:41 -060091 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070092 }
93
94 return 0;
95}
96
97static int simple_panel_probe(struct udevice *dev)
98{
99 struct simple_panel_priv *priv = dev_get_priv(dev);
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300100 struct mipi_dsi_panel_plat *plat = dev_get_plat(dev);
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200101 struct mipi_dsi_panel_plat *dsi_data =
102 (struct mipi_dsi_panel_plat *)dev_get_driver_data(dev);
Simon Glass6aa801b2016-01-21 19:44:59 -0700103 int ret;
104
Svyatoslav Ryhela085c732023-10-03 09:25:33 +0300105 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 Glass6aa801b2016-01-21 19:44:59 -0700110 }
111
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200112 if (dsi_data)
113 memcpy(plat, dsi_data, sizeof(struct mipi_dsi_panel_plat));
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300114
Simon Glass6aa801b2016-01-21 19:44:59 -0700115 return 0;
116}
117
118static const struct panel_ops simple_panel_ops = {
119 .enable_backlight = simple_panel_enable_backlight,
Simon Glassfe68a452018-10-01 12:22:41 -0600120 .set_backlight = simple_panel_set_backlight,
Svyatoslav Ryhelf9260032023-03-27 11:11:49 +0300121 .get_display_timing = simple_panel_get_display_timing,
Simon Glass6aa801b2016-01-21 19:44:59 -0700122};
123
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200124static 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 Glass6aa801b2016-01-21 19:44:59 -0700131static const struct udevice_id simple_panel_ids[] = {
132 { .compatible = "simple-panel" },
Simon Glassfad72182016-01-30 16:37:50 -0700133 { .compatible = "auo,b133xtn01" },
Simon Glassa1015ad2016-02-21 21:09:01 -0700134 { .compatible = "auo,b116xw03" },
135 { .compatible = "auo,b133htn01" },
Peter Robinson6a0e7a62020-04-20 20:27:32 +0100136 { .compatible = "boe,nv140fhmn49" },
Heiko Schocher8ab5d502019-05-27 08:14:39 +0200137 { .compatible = "lg,lb070wv8" },
Alper Nebi Yasak641c7a22020-10-28 00:41:54 +0300138 { .compatible = "sharp,lq123p1jx31" },
Alper Nebi Yasak4cdbb252020-10-28 00:41:55 +0300139 { .compatible = "boe,nv101wxmn51" },
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300140 { .compatible = "panasonic,vvx10f004b00",
Svyatoslav Ryhel04059992024-01-08 18:45:00 +0200141 .data = (ulong)&panasonic_vvx10f004b00 },
Simon Glass6aa801b2016-01-21 19:44:59 -0700142 { }
143};
144
145U_BOOT_DRIVER(simple_panel) = {
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300146 .name = "simple_panel",
147 .id = UCLASS_PANEL,
148 .of_match = simple_panel_ids,
149 .ops = &simple_panel_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700150 .of_to_plat = simple_panel_of_to_plat,
Simon Glass6aa801b2016-01-21 19:44:59 -0700151 .probe = simple_panel_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700152 .priv_auto = sizeof(struct simple_panel_priv),
Svyatoslav Ryhel47508aa2023-03-27 11:11:50 +0300153 .plat_auto = sizeof(struct mipi_dsi_panel_plat),
Simon Glass6aa801b2016-01-21 19:44:59 -0700154};