blob: 2da3d1d14e958c9853f7a04edc5bc13492275e99 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass7d3d7762016-01-21 19:45:00 -07002/*
3 * Copyright 2014 Google Inc.
Simon Glass7d3d7762016-01-21 19:45:00 -07004 */
5
Patrick Delaunay81313352021-04-27 11:02:19 +02006#define LOG_CATEGORY UCLASS_DISPLAY
7
Simon Glass7d3d7762016-01-21 19:45:00 -07008#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);
Simon Glass365b7f72016-11-13 14:22:07 -070027 struct display_plat *disp_uc_plat;
28 int ret;
Simon Glass7d3d7762016-01-21 19:45:00 -070029
30 if (!ops || !ops->enable)
31 return -ENOSYS;
Simon Glass365b7f72016-11-13 14:22:07 -070032 ret = ops->enable(dev, panel_bpp, timing);
33 if (ret)
34 return ret;
35
Simon Glass71fa5b42020-12-03 16:55:18 -070036 disp_uc_plat = dev_get_uclass_plat(dev);
Simon Glass365b7f72016-11-13 14:22:07 -070037 disp_uc_plat->in_use = true;
38
39 return 0;
Simon Glass7d3d7762016-01-21 19:45:00 -070040}
41
Neil Armstrongfaa419c2019-07-04 15:52:07 +020042static 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
Simon Glass7d3d7762016-01-21 19:45:00 -070053int 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
Jacob Chen4b28a902016-03-14 11:20:14 +080060 if (ops && ops->read_timing)
61 return ops->read_timing(dev, timing);
62
Simon Glass7d3d7762016-01-21 19:45:00 -070063 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
Neil Armstrongfaa419c2019-07-04 15:52:07 +020069 return edid_get_timing_validate(buf, ret, timing,
70 &panel_bits_per_colour,
71 display_mode_valid, dev);
Simon Glass7d3d7762016-01-21 19:45:00 -070072}
73
Simon Glass365b7f72016-11-13 14:22:07 -070074bool display_in_use(struct udevice *dev)
75{
Simon Glass71fa5b42020-12-03 16:55:18 -070076 struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev);
Simon Glass365b7f72016-11-13 14:22:07 -070077
78 return disp_uc_plat->in_use;
79}
80
Simon Glass7d3d7762016-01-21 19:45:00 -070081UCLASS_DRIVER(display) = {
82 .id = UCLASS_DISPLAY,
83 .name = "display",
Simon Glass71fa5b42020-12-03 16:55:18 -070084 .per_device_plat_auto = sizeof(struct display_plat),
Simon Glass7d3d7762016-01-21 19:45:00 -070085};