blob: 6c604f9bedb6a20f566963cdcde02582236cd51c [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>
10#include <panel.h>
11#include <asm/gpio.h>
12#include <power/regulator.h>
13
Simon Glasscd9c2072016-01-21 19:44:59 -070014struct simple_panel_priv {
15 struct udevice *reg;
16 struct udevice *backlight;
17 struct gpio_desc enable;
18};
19
20static int simple_panel_enable_backlight(struct udevice *dev)
21{
22 struct simple_panel_priv *priv = dev_get_priv(dev);
23 int ret;
24
Simon Glass1a9f3da2017-06-12 06:21:38 -060025 debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
Simon Glasscd9c2072016-01-21 19:44:59 -070026 dm_gpio_set_value(&priv->enable, 1);
27 ret = backlight_enable(priv->backlight);
Simon Glass1a9f3da2017-06-12 06:21:38 -060028 debug("%s: done, ret = %d\n", __func__, ret);
Simon Glasscd9c2072016-01-21 19:44:59 -070029 if (ret)
30 return ret;
31
32 return 0;
33}
34
35static int simple_panel_ofdata_to_platdata(struct udevice *dev)
36{
37 struct simple_panel_priv *priv = dev_get_priv(dev);
38 int ret;
39
Simon Glasse23c6c22016-03-06 19:27:48 -070040 if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
41 ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
42 "power-supply", &priv->reg);
43 if (ret) {
Marcel Ziswiler28c694c2016-09-28 11:24:06 +020044 debug("%s: Warning: cannot get power supply: ret=%d\n",
Simon Glasse23c6c22016-03-06 19:27:48 -070045 __func__, ret);
46 if (ret != -ENOENT)
47 return ret;
48 }
Simon Glasscd9c2072016-01-21 19:44:59 -070049 }
50 ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
51 "backlight", &priv->backlight);
52 if (ret) {
53 debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
54 return ret;
55 }
56 ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
57 GPIOD_IS_OUT);
58 if (ret) {
59 debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
60 __func__, ret);
61 if (ret != -ENOENT)
62 return ret;
63 }
64
65 return 0;
66}
67
68static int simple_panel_probe(struct udevice *dev)
69{
70 struct simple_panel_priv *priv = dev_get_priv(dev);
71 int ret;
72
Simon Glasse23c6c22016-03-06 19:27:48 -070073 if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
Simon Glasscd9c2072016-01-21 19:44:59 -070074 debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
75 ret = regulator_set_enable(priv->reg, true);
76 if (ret)
77 return ret;
78 }
79
80 return 0;
81}
82
83static const struct panel_ops simple_panel_ops = {
84 .enable_backlight = simple_panel_enable_backlight,
85};
86
87static const struct udevice_id simple_panel_ids[] = {
88 { .compatible = "simple-panel" },
Simon Glassd7659212016-01-30 16:37:50 -070089 { .compatible = "auo,b133xtn01" },
Simon Glassbb5930d2016-02-21 21:09:01 -070090 { .compatible = "auo,b116xw03" },
91 { .compatible = "auo,b133htn01" },
Simon Glasscd9c2072016-01-21 19:44:59 -070092 { }
93};
94
95U_BOOT_DRIVER(simple_panel) = {
96 .name = "simple_panel",
97 .id = UCLASS_PANEL,
98 .of_match = simple_panel_ids,
99 .ops = &simple_panel_ops,
100 .ofdata_to_platdata = simple_panel_ofdata_to_platdata,
101 .probe = simple_panel_probe,
102 .priv_auto_alloc_size = sizeof(struct simple_panel_priv),
103};