2 * Copyright (c) 2016 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
13 #include <power/regulator.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 struct simple_panel_priv {
19 struct udevice *backlight;
20 struct gpio_desc enable;
23 static int simple_panel_enable_backlight(struct udevice *dev)
25 struct simple_panel_priv *priv = dev_get_priv(dev);
28 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
29 dm_gpio_set_value(&priv->enable, 1);
30 ret = backlight_enable(priv->backlight);
31 debug("%s: done, ret = %d\n", __func__, ret);
38 static int simple_panel_ofdata_to_platdata(struct udevice *dev)
40 struct simple_panel_priv *priv = dev_get_priv(dev);
43 if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
44 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
45 "power-supply", &priv->reg);
47 debug("%s: Warning: cannot get power supply: ret=%d\n",
53 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
54 "backlight", &priv->backlight);
56 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
59 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
62 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
71 static int simple_panel_probe(struct udevice *dev)
73 struct simple_panel_priv *priv = dev_get_priv(dev);
76 if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
77 debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
78 ret = regulator_set_enable(priv->reg, true);
86 static const struct panel_ops simple_panel_ops = {
87 .enable_backlight = simple_panel_enable_backlight,
90 static const struct udevice_id simple_panel_ids[] = {
91 { .compatible = "simple-panel" },
92 { .compatible = "auo,b133xtn01" },
93 { .compatible = "auo,b116xw03" },
94 { .compatible = "auo,b133htn01" },
98 U_BOOT_DRIVER(simple_panel) = {
99 .name = "simple_panel",
101 .of_match = simple_panel_ids,
102 .ops = &simple_panel_ops,
103 .ofdata_to_platdata = simple_panel_ofdata_to_platdata,
104 .probe = simple_panel_probe,
105 .priv_auto_alloc_size = sizeof(struct simple_panel_priv),