uboot/drivers/video/display-uclass.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0+
   2/*
   3 * Copyright 2014 Google Inc.
   4 */
   5
   6#define LOG_CATEGORY UCLASS_DISPLAY
   7
   8#include <common.h>
   9#include <dm.h>
  10#include <display.h>
  11#include <edid.h>
  12#include <errno.h>
  13
  14int display_read_edid(struct udevice *dev, u8 *buf, int buf_size)
  15{
  16        struct dm_display_ops *ops = display_get_ops(dev);
  17
  18        if (!ops || !ops->read_edid)
  19                return -ENOSYS;
  20        return ops->read_edid(dev, buf, buf_size);
  21}
  22
  23int display_enable(struct udevice *dev, int panel_bpp,
  24                        const struct display_timing *timing)
  25{
  26        struct dm_display_ops *ops = display_get_ops(dev);
  27        struct display_plat *disp_uc_plat;
  28        int ret;
  29
  30        if (!ops || !ops->enable)
  31                return -ENOSYS;
  32        ret = ops->enable(dev, panel_bpp, timing);
  33        if (ret)
  34                return ret;
  35
  36        disp_uc_plat = dev_get_uclass_plat(dev);
  37        disp_uc_plat->in_use = true;
  38
  39        return 0;
  40}
  41
  42static bool display_mode_valid(void *priv, const struct display_timing *timing)
  43{
  44        struct udevice *dev = priv;
  45        struct dm_display_ops *ops = display_get_ops(dev);
  46
  47        if (ops && ops->mode_valid)
  48                return ops->mode_valid(dev, timing);
  49
  50        return true;
  51}
  52
  53int display_read_timing(struct udevice *dev, struct display_timing *timing)
  54{
  55        struct dm_display_ops *ops = display_get_ops(dev);
  56        int panel_bits_per_colour;
  57        u8 buf[EDID_EXT_SIZE];
  58        int ret;
  59
  60        if (ops && ops->read_timing)
  61                return ops->read_timing(dev, timing);
  62
  63        if (!ops || !ops->read_edid)
  64                return -ENOSYS;
  65        ret = ops->read_edid(dev, buf, sizeof(buf));
  66        if (ret < 0)
  67                return ret;
  68
  69        return edid_get_timing_validate(buf, ret, timing,
  70                                        &panel_bits_per_colour,
  71                                        display_mode_valid, dev);
  72}
  73
  74bool display_in_use(struct udevice *dev)
  75{
  76        struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev);
  77
  78        return disp_uc_plat->in_use;
  79}
  80
  81UCLASS_DRIVER(display) = {
  82        .id             = UCLASS_DISPLAY,
  83        .name           = "display",
  84        .per_device_plat_auto   = sizeof(struct display_plat),
  85};
  86