blob: c73f24295a4057893872321bc6a3fe617d9623ea [file] [log] [blame]
Simon Glasscd9c2072016-01-21 19:44:59 -07001/*
2 * Copyright (c) 2016 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <backlight.h>
10#include <dm.h>
11#include <panel.h>
12#include <asm/gpio.h>
13#include <power/regulator.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17struct simple_panel_priv {
18 struct udevice *reg;
19 struct udevice *backlight;
20 struct gpio_desc enable;
21};
22
23static int simple_panel_enable_backlight(struct udevice *dev)
24{
25 struct simple_panel_priv *priv = dev_get_priv(dev);
26 int ret;
27
28 dm_gpio_set_value(&priv->enable, 1);
29 ret = backlight_enable(priv->backlight);
30 if (ret)
31 return ret;
32
33 return 0;
34}
35
36static int simple_panel_ofdata_to_platdata(struct udevice *dev)
37{
38 struct simple_panel_priv *priv = dev_get_priv(dev);
39 int ret;
40
41 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
42 "power-supply", &priv->reg);
43 if (ret) {
44 debug("%s: Warning: cnnot get power supply: ret=%d\n",
45 __func__, ret);
46 if (ret != -ENOENT)
47 return ret;
48 }
49 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
50 "backlight", &priv->backlight);
51 if (ret) {
52 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
53 return ret;
54 }
55 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
56 GPIOD_IS_OUT);
57 if (ret) {
58 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
59 __func__, ret);
60 if (ret != -ENOENT)
61 return ret;
62 }
63
64 return 0;
65}
66
67static int simple_panel_probe(struct udevice *dev)
68{
69 struct simple_panel_priv *priv = dev_get_priv(dev);
70 int ret;
71
72 if (priv->reg) {
73 debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
74 ret = regulator_set_enable(priv->reg, true);
75 if (ret)
76 return ret;
77 }
78
79 return 0;
80}
81
82static const struct panel_ops simple_panel_ops = {
83 .enable_backlight = simple_panel_enable_backlight,
84};
85
86static const struct udevice_id simple_panel_ids[] = {
87 { .compatible = "simple-panel" },
Simon Glassd7659212016-01-30 16:37:50 -070088 { .compatible = "auo,b133xtn01" },
Simon Glasscd9c2072016-01-21 19:44:59 -070089 { }
90};
91
92U_BOOT_DRIVER(simple_panel) = {
93 .name = "simple_panel",
94 .id = UCLASS_PANEL,
95 .of_match = simple_panel_ids,
96 .ops = &simple_panel_ops,
97 .ofdata_to_platdata = simple_panel_ofdata_to_platdata,
98 .probe = simple_panel_probe,
99 .priv_auto_alloc_size = sizeof(struct simple_panel_priv),
100};