1 /*
2  * Copyright 2014 Google Inc.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <display.h>
10 #include <edid.h>
11 #include <errno.h>
12 
13 int display_read_edid(struct udevice *dev, u8 *buf, int buf_size)
14 {
15 	struct dm_display_ops *ops = display_get_ops(dev);
16 
17 	if (!ops || !ops->read_edid)
18 		return -ENOSYS;
19 	return ops->read_edid(dev, buf, buf_size);
20 }
21 
22 int display_enable(struct udevice *dev, int panel_bpp,
23 			const struct display_timing *timing)
24 {
25 	struct dm_display_ops *ops = display_get_ops(dev);
26 
27 	if (!ops || !ops->enable)
28 		return -ENOSYS;
29 	return ops->enable(dev, panel_bpp, timing);
30 }
31 
32 int display_read_timing(struct udevice *dev, struct display_timing *timing)
33 {
34 	struct dm_display_ops *ops = display_get_ops(dev);
35 	int panel_bits_per_colour;
36 	u8 buf[EDID_EXT_SIZE];
37 	int ret;
38 
39 	if (!ops || !ops->read_edid)
40 		return -ENOSYS;
41 	ret = ops->read_edid(dev, buf, sizeof(buf));
42 	if (ret < 0)
43 		return ret;
44 
45 	return edid_get_timing(buf, ret, timing, &panel_bits_per_colour);
46 }
47 
48 UCLASS_DRIVER(display) = {
49 	.id		= UCLASS_DISPLAY,
50 	.name		= "display",
51 	.per_device_platdata_auto_alloc_size	= sizeof(struct display_plat),
52 };
53