blob: 068108e915537203caf933ededbbd09dbfbb548f [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
6#include <common.h>
7#include <dm.h>
8#include <display.h>
9#include <edid.h>
10#include <errno.h>
11
12int display_read_edid(struct udevice *dev, u8 *buf, int buf_size)
13{
14 struct dm_display_ops *ops = display_get_ops(dev);
15
16 if (!ops || !ops->read_edid)
17 return -ENOSYS;
18 return ops->read_edid(dev, buf, buf_size);
19}
20
21int display_enable(struct udevice *dev, int panel_bpp,
22 const struct display_timing *timing)
23{
24 struct dm_display_ops *ops = display_get_ops(dev);
Simon Glass365b7f72016-11-13 14:22:07 -070025 struct display_plat *disp_uc_plat;
26 int ret;
Simon Glass7d3d7762016-01-21 19:45:00 -070027
28 if (!ops || !ops->enable)
29 return -ENOSYS;
Simon Glass365b7f72016-11-13 14:22:07 -070030 ret = ops->enable(dev, panel_bpp, timing);
31 if (ret)
32 return ret;
33
Simon Glass71fa5b42020-12-03 16:55:18 -070034 disp_uc_plat = dev_get_uclass_plat(dev);
Simon Glass365b7f72016-11-13 14:22:07 -070035 disp_uc_plat->in_use = true;
36
37 return 0;
Simon Glass7d3d7762016-01-21 19:45:00 -070038}
39
Neil Armstrongfaa419c2019-07-04 15:52:07 +020040static bool display_mode_valid(void *priv, const struct display_timing *timing)
41{
42 struct udevice *dev = priv;
43 struct dm_display_ops *ops = display_get_ops(dev);
44
45 if (ops && ops->mode_valid)
46 return ops->mode_valid(dev, timing);
47
48 return true;
49}
50
Simon Glass7d3d7762016-01-21 19:45:00 -070051int display_read_timing(struct udevice *dev, struct display_timing *timing)
52{
53 struct dm_display_ops *ops = display_get_ops(dev);
54 int panel_bits_per_colour;
55 u8 buf[EDID_EXT_SIZE];
56 int ret;
57
Jacob Chen4b28a902016-03-14 11:20:14 +080058 if (ops && ops->read_timing)
59 return ops->read_timing(dev, timing);
60
Simon Glass7d3d7762016-01-21 19:45:00 -070061 if (!ops || !ops->read_edid)
62 return -ENOSYS;
63 ret = ops->read_edid(dev, buf, sizeof(buf));
64 if (ret < 0)
65 return ret;
66
Neil Armstrongfaa419c2019-07-04 15:52:07 +020067 return edid_get_timing_validate(buf, ret, timing,
68 &panel_bits_per_colour,
69 display_mode_valid, dev);
Simon Glass7d3d7762016-01-21 19:45:00 -070070}
71
Simon Glass365b7f72016-11-13 14:22:07 -070072bool display_in_use(struct udevice *dev)
73{
Simon Glass71fa5b42020-12-03 16:55:18 -070074 struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev);
Simon Glass365b7f72016-11-13 14:22:07 -070075
76 return disp_uc_plat->in_use;
77}
78
Simon Glass7d3d7762016-01-21 19:45:00 -070079UCLASS_DRIVER(display) = {
80 .id = UCLASS_DISPLAY,
81 .name = "display",
Simon Glass71fa5b42020-12-03 16:55:18 -070082 .per_device_plat_auto = sizeof(struct display_plat),
Simon Glass7d3d7762016-01-21 19:45:00 -070083};