2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-01-22 02:44:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <backlight.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <panel.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <power/regulator.h>
|
|
|
|
|
|
|
|
struct simple_panel_priv {
|
|
|
|
struct udevice *reg;
|
|
|
|
struct udevice *backlight;
|
|
|
|
struct gpio_desc enable;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int simple_panel_enable_backlight(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct simple_panel_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
2017-06-12 12:21:38 +00:00
|
|
|
debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
|
2016-01-22 02:44:59 +00:00
|
|
|
dm_gpio_set_value(&priv->enable, 1);
|
|
|
|
ret = backlight_enable(priv->backlight);
|
2017-06-12 12:21:38 +00:00
|
|
|
debug("%s: done, ret = %d\n", __func__, ret);
|
2016-01-22 02:44:59 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-01 18:22:41 +00:00
|
|
|
static int simple_panel_set_backlight(struct udevice *dev, int percent)
|
|
|
|
{
|
|
|
|
struct simple_panel_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
|
|
|
|
dm_gpio_set_value(&priv->enable, 1);
|
|
|
|
ret = backlight_set_brightness(priv->backlight, percent);
|
|
|
|
debug("%s: done, ret = %d\n", __func__, ret);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-22 02:44:59 +00:00
|
|
|
static int simple_panel_ofdata_to_platdata(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct simple_panel_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
2016-03-07 02:27:48 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
|
|
|
|
ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
|
|
|
|
"power-supply", &priv->reg);
|
|
|
|
if (ret) {
|
2016-09-28 09:24:06 +00:00
|
|
|
debug("%s: Warning: cannot get power supply: ret=%d\n",
|
2016-03-07 02:27:48 +00:00
|
|
|
__func__, ret);
|
|
|
|
if (ret != -ENOENT)
|
|
|
|
return ret;
|
|
|
|
}
|
2016-01-22 02:44:59 +00:00
|
|
|
}
|
|
|
|
ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
|
|
|
|
"backlight", &priv->backlight);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
|
2018-10-01 18:22:41 +00:00
|
|
|
return log_ret(ret);
|
2016-01-22 02:44:59 +00:00
|
|
|
}
|
|
|
|
ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
|
|
|
|
GPIOD_IS_OUT);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
|
|
|
|
__func__, ret);
|
|
|
|
if (ret != -ENOENT)
|
2018-10-01 18:22:41 +00:00
|
|
|
return log_ret(ret);
|
2016-01-22 02:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int simple_panel_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct simple_panel_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
2016-03-07 02:27:48 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
|
2016-01-22 02:44:59 +00:00
|
|
|
debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
|
|
|
|
ret = regulator_set_enable(priv->reg, true);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct panel_ops simple_panel_ops = {
|
|
|
|
.enable_backlight = simple_panel_enable_backlight,
|
2018-10-01 18:22:41 +00:00
|
|
|
.set_backlight = simple_panel_set_backlight,
|
2016-01-22 02:44:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id simple_panel_ids[] = {
|
|
|
|
{ .compatible = "simple-panel" },
|
2016-01-30 23:37:50 +00:00
|
|
|
{ .compatible = "auo,b133xtn01" },
|
2016-02-22 04:09:01 +00:00
|
|
|
{ .compatible = "auo,b116xw03" },
|
|
|
|
{ .compatible = "auo,b133htn01" },
|
2020-04-20 19:27:32 +00:00
|
|
|
{ .compatible = "boe,nv140fhmn49" },
|
2019-05-27 06:14:39 +00:00
|
|
|
{ .compatible = "lg,lb070wv8" },
|
2016-01-22 02:44:59 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(simple_panel) = {
|
|
|
|
.name = "simple_panel",
|
|
|
|
.id = UCLASS_PANEL,
|
|
|
|
.of_match = simple_panel_ids,
|
|
|
|
.ops = &simple_panel_ops,
|
|
|
|
.ofdata_to_platdata = simple_panel_ofdata_to_platdata,
|
|
|
|
.probe = simple_panel_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct simple_panel_priv),
|
|
|
|
};
|