1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2016 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
12 #include <power/regulator.h>
14 struct simple_panel_priv {
16 struct udevice *backlight;
17 struct gpio_desc enable;
20 static int simple_panel_enable_backlight(struct udevice *dev)
22 struct simple_panel_priv *priv = dev_get_priv(dev);
25 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
26 dm_gpio_set_value(&priv->enable, 1);
27 ret = backlight_enable(priv->backlight);
28 debug("%s: done, ret = %d\n", __func__, ret);
35 static int simple_panel_set_backlight(struct udevice *dev, int percent)
37 struct simple_panel_priv *priv = dev_get_priv(dev);
40 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
41 dm_gpio_set_value(&priv->enable, 1);
42 ret = backlight_set_brightness(priv->backlight, percent);
43 debug("%s: done, ret = %d\n", __func__, ret);
50 static int simple_panel_ofdata_to_platdata(struct udevice *dev)
52 struct simple_panel_priv *priv = dev_get_priv(dev);
55 if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
56 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
57 "power-supply", &priv->reg);
59 debug("%s: Warning: cannot get power supply: ret=%d\n",
65 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
66 "backlight", &priv->backlight);
68 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
71 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
74 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
83 static int simple_panel_probe(struct udevice *dev)
85 struct simple_panel_priv *priv = dev_get_priv(dev);
88 if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
89 debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
90 ret = regulator_set_enable(priv->reg, true);
98 static const struct panel_ops simple_panel_ops = {
99 .enable_backlight = simple_panel_enable_backlight,
100 .set_backlight = simple_panel_set_backlight,
103 static const struct udevice_id simple_panel_ids[] = {
104 { .compatible = "simple-panel" },
105 { .compatible = "auo,b133xtn01" },
106 { .compatible = "auo,b116xw03" },
107 { .compatible = "auo,b133htn01" },
108 { .compatible = "lg,lb070wv8" },
112 U_BOOT_DRIVER(simple_panel) = {
113 .name = "simple_panel",
115 .of_match = simple_panel_ids,
116 .ops = &simple_panel_ops,
117 .ofdata_to_platdata = simple_panel_ofdata_to_platdata,
118 .probe = simple_panel_probe,
119 .priv_auto_alloc_size = sizeof(struct simple_panel_priv),