blob: c8f7022ea63d20ae45840aa5022f8ee0dea5ca54 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glasscd9c2072016-01-21 19:44:59 -07002/*
3 * Copyright (c) 2016 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glasscd9c2072016-01-21 19:44:59 -07005 */
6
7#include <common.h>
8#include <backlight.h>
9#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Simon Glasscd9c2072016-01-21 19:44:59 -070011#include <panel.h>
12#include <asm/gpio.h>
13#include <power/regulator.h>
14
Simon Glasscd9c2072016-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 Glass1a9f3da2017-06-12 06:21:38 -060026 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
Simon Glasscd9c2072016-01-21 19:44:59 -070027 dm_gpio_set_value(&priv->enable, 1);
28 ret = backlight_enable(priv->backlight);
Simon Glass1a9f3da2017-06-12 06:21:38 -060029 debug("%s: done, ret = %d\n", __func__, ret);
Simon Glasscd9c2072016-01-21 19:44:59 -070030 if (ret)
31 return ret;
32
33 return 0;
34}
35
Simon Glassa4f737a2018-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 Glassd1998a92020-12-03 16:55:21 -070051static int simple_panel_of_to_plat(struct udevice *dev)
Simon Glasscd9c2072016-01-21 19:44:59 -070052{
53 struct simple_panel_priv *priv = dev_get_priv(dev);
54 int ret;
55
Simon Glasse23c6c22016-03-06 19:27:48 -070056 if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
57 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
58 "power-supply", &priv->reg);
59 if (ret) {
Marcel Ziswiler28c694c2016-09-28 11:24:06 +020060 debug("%s: Warning: cannot get power supply: ret=%d\n",
Simon Glasse23c6c22016-03-06 19:27:48 -070061 __func__, ret);
62 if (ret != -ENOENT)
63 return ret;
64 }
Simon Glasscd9c2072016-01-21 19:44:59 -070065 }
66 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
67 "backlight", &priv->backlight);
68 if (ret) {
69 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
Simon Glassa4f737a2018-10-01 12:22:41 -060070 return log_ret(ret);
Simon Glasscd9c2072016-01-21 19:44:59 -070071 }
72 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
73 GPIOD_IS_OUT);
74 if (ret) {
75 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
76 __func__, ret);
77 if (ret != -ENOENT)
Simon Glassa4f737a2018-10-01 12:22:41 -060078 return log_ret(ret);
Simon Glasscd9c2072016-01-21 19:44:59 -070079 }
80
81 return 0;
82}
83
84static int simple_panel_probe(struct udevice *dev)
85{
86 struct simple_panel_priv *priv = dev_get_priv(dev);
87 int ret;
88
Simon Glasse23c6c22016-03-06 19:27:48 -070089 if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
Simon Glasscd9c2072016-01-21 19:44:59 -070090 debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
91 ret = regulator_set_enable(priv->reg, true);
92 if (ret)
93 return ret;
94 }
95
96 return 0;
97}
98
99static const struct panel_ops simple_panel_ops = {
100 .enable_backlight = simple_panel_enable_backlight,
Simon Glassa4f737a2018-10-01 12:22:41 -0600101 .set_backlight = simple_panel_set_backlight,
Simon Glasscd9c2072016-01-21 19:44:59 -0700102};
103
104static const struct udevice_id simple_panel_ids[] = {
105 { .compatible = "simple-panel" },
Simon Glassd7659212016-01-30 16:37:50 -0700106 { .compatible = "auo,b133xtn01" },
Simon Glassbb5930d2016-02-21 21:09:01 -0700107 { .compatible = "auo,b116xw03" },
108 { .compatible = "auo,b133htn01" },
Peter Robinsonea166372020-04-20 20:27:32 +0100109 { .compatible = "boe,nv140fhmn49" },
Heiko Schocher85288ff2019-05-27 08:14:39 +0200110 { .compatible = "lg,lb070wv8" },
Alper Nebi Yasak92a81432020-10-28 00:41:54 +0300111 { .compatible = "sharp,lq123p1jx31" },
Alper Nebi Yasakf4576802020-10-28 00:41:55 +0300112 { .compatible = "boe,nv101wxmn51" },
Simon Glasscd9c2072016-01-21 19:44:59 -0700113 { }
114};
115
116U_BOOT_DRIVER(simple_panel) = {
117 .name = "simple_panel",
118 .id = UCLASS_PANEL,
119 .of_match = simple_panel_ids,
120 .ops = &simple_panel_ops,
Simon Glassd1998a92020-12-03 16:55:21 -0700121 .of_to_plat = simple_panel_of_to_plat,
Simon Glasscd9c2072016-01-21 19:44:59 -0700122 .probe = simple_panel_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700123 .priv_auto = sizeof(struct simple_panel_priv),
Simon Glasscd9c2072016-01-21 19:44:59 -0700124};