1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2016 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
13 #include <power/regulator.h>
15 struct simple_panel_priv {
17 struct udevice *backlight;
18 struct gpio_desc enable;
21 static int simple_panel_enable_backlight(struct udevice *dev)
23 struct simple_panel_priv *priv = dev_get_priv(dev);
26 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
27 dm_gpio_set_value(&priv->enable, 1);
28 ret = backlight_enable(priv->backlight);
29 debug("%s: done, ret = %d\n", __func__, ret);
36 static int simple_panel_set_backlight(struct udevice *dev, int percent)
38 struct simple_panel_priv *priv = dev_get_priv(dev);
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);
51 static int simple_panel_of_to_plat(struct udevice *dev)
53 struct simple_panel_priv *priv = dev_get_priv(dev);
56 if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
57 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
58 "power-supply", &priv->reg);
60 debug("%s: Warning: cannot get power supply: ret=%d\n",
66 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
67 "backlight", &priv->backlight);
69 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
72 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
75 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
84 static int simple_panel_probe(struct udevice *dev)
86 struct simple_panel_priv *priv = dev_get_priv(dev);
89 if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
90 debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
91 ret = regulator_set_enable(priv->reg, true);
99 static const struct panel_ops simple_panel_ops = {
100 .enable_backlight = simple_panel_enable_backlight,
101 .set_backlight = simple_panel_set_backlight,
104 static const struct udevice_id simple_panel_ids[] = {
105 { .compatible = "simple-panel" },
106 { .compatible = "auo,b133xtn01" },
107 { .compatible = "auo,b116xw03" },
108 { .compatible = "auo,b133htn01" },
109 { .compatible = "boe,nv140fhmn49" },
110 { .compatible = "lg,lb070wv8" },
114 U_BOOT_DRIVER(simple_panel) = {
115 .name = "simple_panel",
117 .of_match = simple_panel_ids,
118 .ops = &simple_panel_ops,
119 .of_to_plat = simple_panel_of_to_plat,
120 .probe = simple_panel_probe,
121 .priv_auto = sizeof(struct simple_panel_priv),