blob: 092906c82c9a9a7cf8b025cc37ce69a73d3adcf8 [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>
Simon Glass6aa801b2016-01-21 19:44:59 -070011#include <panel.h>
12#include <asm/gpio.h>
13#include <power/regulator.h>
14
Simon Glass6aa801b2016-01-21 19:44:59 -070015struct simple_panel_priv {
16 struct udevice *reg;
17 struct udevice *backlight;
18 struct gpio_desc enable;
19};
20
21static int simple_panel_enable_backlight(struct udevice *dev)
22{
23 struct simple_panel_priv *priv = dev_get_priv(dev);
24 int ret;
25
Simon Glasscc06f142017-06-12 06:21:38 -060026 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
Simon Glass6aa801b2016-01-21 19:44:59 -070027 dm_gpio_set_value(&priv->enable, 1);
28 ret = backlight_enable(priv->backlight);
Simon Glasscc06f142017-06-12 06:21:38 -060029 debug("%s: done, ret = %d\n", __func__, ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070030 if (ret)
31 return ret;
32
33 return 0;
34}
35
Simon Glassfe68a452018-10-01 12:22:41 -060036static int simple_panel_set_backlight(struct udevice *dev, int percent)
37{
38 struct simple_panel_priv *priv = dev_get_priv(dev);
39 int ret;
40
41 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
42 dm_gpio_set_value(&priv->enable, 1);
43 ret = backlight_set_brightness(priv->backlight, percent);
44 debug("%s: done, ret = %d\n", __func__, ret);
45 if (ret)
46 return ret;
47
48 return 0;
49}
50
Simon Glassaad29ae2020-12-03 16:55:21 -070051static int simple_panel_of_to_plat(struct udevice *dev)
Simon Glass6aa801b2016-01-21 19:44:59 -070052{
53 struct simple_panel_priv *priv = dev_get_priv(dev);
54 int ret;
55
Marek Vasutbbdd1352023-02-28 02:55:22 +010056 if (CONFIG_IS_ENABLED(DM_REGULATOR)) {
Simon Glass29199212016-03-06 19:27:48 -070057 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
58 "power-supply", &priv->reg);
59 if (ret) {
Marcel Ziswiler07e0c272016-09-28 11:24:06 +020060 debug("%s: Warning: cannot get power supply: ret=%d\n",
Simon Glass29199212016-03-06 19:27:48 -070061 __func__, ret);
62 if (ret != -ENOENT)
63 return ret;
64 }
Simon Glass6aa801b2016-01-21 19:44:59 -070065 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +053066
Simon Glass6aa801b2016-01-21 19:44:59 -070067 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
Nikhil M Jainc76eda62023-01-31 15:35:16 +053068 "backlight", &priv->backlight);
Simon Glass6aa801b2016-01-21 19:44:59 -070069 if (ret) {
70 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
Nikhil M Jainc76eda62023-01-31 15:35:16 +053071 if (ret != -ENOENT)
72 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070073 }
Nikhil M Jainc76eda62023-01-31 15:35:16 +053074
Simon Glass6aa801b2016-01-21 19:44:59 -070075 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
76 GPIOD_IS_OUT);
77 if (ret) {
78 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
79 __func__, ret);
80 if (ret != -ENOENT)
Simon Glassfe68a452018-10-01 12:22:41 -060081 return log_ret(ret);
Simon Glass6aa801b2016-01-21 19:44:59 -070082 }
83
84 return 0;
85}
86
87static int simple_panel_probe(struct udevice *dev)
88{
89 struct simple_panel_priv *priv = dev_get_priv(dev);
90 int ret;
91
Marek Vasutbbdd1352023-02-28 02:55:22 +010092 if (CONFIG_IS_ENABLED(DM_REGULATOR) && priv->reg) {
Simon Glass6aa801b2016-01-21 19:44:59 -070093 debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
94 ret = regulator_set_enable(priv->reg, true);
95 if (ret)
96 return ret;
97 }
98
99 return 0;
100}
101
102static const struct panel_ops simple_panel_ops = {
103 .enable_backlight = simple_panel_enable_backlight,
Simon Glassfe68a452018-10-01 12:22:41 -0600104 .set_backlight = simple_panel_set_backlight,
Simon Glass6aa801b2016-01-21 19:44:59 -0700105};
106
107static const struct udevice_id simple_panel_ids[] = {
108 { .compatible = "simple-panel" },
Simon Glassfad72182016-01-30 16:37:50 -0700109 { .compatible = "auo,b133xtn01" },
Simon Glassa1015ad2016-02-21 21:09:01 -0700110 { .compatible = "auo,b116xw03" },
111 { .compatible = "auo,b133htn01" },
Peter Robinson6a0e7a62020-04-20 20:27:32 +0100112 { .compatible = "boe,nv140fhmn49" },
Heiko Schocher8ab5d502019-05-27 08:14:39 +0200113 { .compatible = "lg,lb070wv8" },
Alper Nebi Yasak641c7a22020-10-28 00:41:54 +0300114 { .compatible = "sharp,lq123p1jx31" },
Alper Nebi Yasak4cdbb252020-10-28 00:41:55 +0300115 { .compatible = "boe,nv101wxmn51" },
Simon Glass6aa801b2016-01-21 19:44:59 -0700116 { }
117};
118
119U_BOOT_DRIVER(simple_panel) = {
120 .name = "simple_panel",
121 .id = UCLASS_PANEL,
122 .of_match = simple_panel_ids,
123 .ops = &simple_panel_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700124 .of_to_plat = simple_panel_of_to_plat,
Simon Glass6aa801b2016-01-21 19:44:59 -0700125 .probe = simple_panel_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700126 .priv_auto = sizeof(struct simple_panel_priv),
Simon Glass6aa801b2016-01-21 19:44:59 -0700127};