uboot/drivers/video/simple_panel.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright (c) 2016 Google, Inc
   4 * Written by Simon Glass <sjg@chromium.org>
   5 */
   6
   7#include <common.h>
   8#include <backlight.h>
   9#include <dm.h>
  10#include <log.h>
  11#include <panel.h>
  12#include <asm/gpio.h>
  13#include <power/regulator.h>
  14
  15struct simple_panel_priv {
  16        struct udevice *reg;
  17        struct udevice *backlight;
  18        struct gpio_desc enable;
  19};
  20
  21static int simple_panel_enable_backlight(struct udevice *dev)
  22{
  23        struct simple_panel_priv *priv = dev_get_priv(dev);
  24        int ret;
  25
  26        debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
  27        dm_gpio_set_value(&priv->enable, 1);
  28        ret = backlight_enable(priv->backlight);
  29        debug("%s: done, ret = %d\n", __func__, ret);
  30        if (ret)
  31                return ret;
  32
  33        return 0;
  34}
  35
  36static int simple_panel_set_backlight(struct udevice *dev, int percent)
  37{
  38        struct simple_panel_priv *priv = dev_get_priv(dev);
  39        int ret;
  40
  41        debug("%s: start, backlight = '%s'\n", __func__, priv->backlight->name);
  42        dm_gpio_set_value(&priv->enable, 1);
  43        ret = backlight_set_brightness(priv->backlight, percent);
  44        debug("%s: done, ret = %d\n", __func__, ret);
  45        if (ret)
  46                return ret;
  47
  48        return 0;
  49}
  50
  51static int simple_panel_of_to_plat(struct udevice *dev)
  52{
  53        struct simple_panel_priv *priv = dev_get_priv(dev);
  54        int ret;
  55
  56        if (IS_ENABLED(CONFIG_DM_REGULATOR)) {
  57                ret = uclass_get_device_by_phandle(UCLASS_REGULATOR, dev,
  58                                                   "power-supply", &priv->reg);
  59                if (ret) {
  60                        debug("%s: Warning: cannot get power supply: ret=%d\n",
  61                              __func__, ret);
  62                        if (ret != -ENOENT)
  63                                return ret;
  64                }
  65        }
  66        ret = uclass_get_device_by_phandle(UCLASS_PANEL_BACKLIGHT, dev,
  67                                           "backlight", &priv->backlight);
  68        if (ret) {
  69                debug("%s: Cannot get backlight: ret=%d\n", __func__, ret);
  70                return log_ret(ret);
  71        }
  72        ret = gpio_request_by_name(dev, "enable-gpios", 0, &priv->enable,
  73                                   GPIOD_IS_OUT);
  74        if (ret) {
  75                debug("%s: Warning: cannot get enable GPIO: ret=%d\n",
  76                      __func__, ret);
  77                if (ret != -ENOENT)
  78                        return log_ret(ret);
  79        }
  80
  81        return 0;
  82}
  83
  84static int simple_panel_probe(struct udevice *dev)
  85{
  86        struct simple_panel_priv *priv = dev_get_priv(dev);
  87        int ret;
  88
  89        if (IS_ENABLED(CONFIG_DM_REGULATOR) && priv->reg) {
  90                debug("%s: Enable regulator '%s'\n", __func__, priv->reg->name);
  91                ret = regulator_set_enable(priv->reg, true);
  92                if (ret)
  93                        return ret;
  94        }
  95
  96        return 0;
  97}
  98
  99static const struct panel_ops simple_panel_ops = {
 100        .enable_backlight       = simple_panel_enable_backlight,
 101        .set_backlight          = simple_panel_set_backlight,
 102};
 103
 104static const struct udevice_id simple_panel_ids[] = {
 105        { .compatible = "simple-panel" },
 106        { .compatible = "auo,b133xtn01" },
 107        { .compatible = "auo,b116xw03" },
 108        { .compatible = "auo,b133htn01" },
 109        { .compatible = "boe,nv140fhmn49" },
 110        { .compatible = "lg,lb070wv8" },
 111        { .compatible = "sharp,lq123p1jx31" },
 112        { .compatible = "boe,nv101wxmn51" },
 113        { }
 114};
 115
 116U_BOOT_DRIVER(simple_panel) = {
 117        .name   = "simple_panel",
 118        .id     = UCLASS_PANEL,
 119        .of_match = simple_panel_ids,
 120        .ops    = &simple_panel_ops,
 121        .of_to_plat     = simple_panel_of_to_plat,
 122        .probe          = simple_panel_probe,
 123        .priv_auto      = sizeof(struct simple_panel_priv),
 124};
 125