blob: 61a73e1bc2a629eae6a9210434641a9babaf9dea [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 <dm.h>
9#include <display.h>
10#include <edid.h>
11#include <errno.h>
12
13int 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
22int 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);
Simon Glass365b7f72016-11-13 14:22:07 -070026 struct display_plat *disp_uc_plat;
27 int ret;
Simon Glass7d3d7762016-01-21 19:45:00 -070028
29 if (!ops || !ops->enable)
30 return -ENOSYS;
Simon Glass365b7f72016-11-13 14:22:07 -070031 ret = ops->enable(dev, panel_bpp, timing);
32 if (ret)
33 return ret;
34
Simon Glass71fa5b42020-12-03 16:55:18 -070035 disp_uc_plat = dev_get_uclass_plat(dev);
Simon Glass365b7f72016-11-13 14:22:07 -070036 disp_uc_plat->in_use = true;
37
38 return 0;
Simon Glass7d3d7762016-01-21 19:45:00 -070039}
40
Neil Armstrongfaa419c2019-07-04 15:52:07 +020041static bool display_mode_valid(void *priv, const struct display_timing *timing)
42{
43 struct udevice *dev = priv;
44 struct dm_display_ops *ops = display_get_ops(dev);
45
46 if (ops && ops->mode_valid)
47 return ops->mode_valid(dev, timing);
48
49 return true;
50}
51
Simon Glass7d3d7762016-01-21 19:45:00 -070052int display_read_timing(struct udevice *dev, struct display_timing *timing)
53{
54 struct dm_display_ops *ops = display_get_ops(dev);
55 int panel_bits_per_colour;
56 u8 buf[EDID_EXT_SIZE];
57 int ret;
58
Jacob Chen4b28a902016-03-14 11:20:14 +080059 if (ops && ops->read_timing)
60 return ops->read_timing(dev, timing);
61
Simon Glass7d3d7762016-01-21 19:45:00 -070062 if (!ops || !ops->read_edid)
63 return -ENOSYS;
64 ret = ops->read_edid(dev, buf, sizeof(buf));
65 if (ret < 0)
66 return ret;
67
Neil Armstrongfaa419c2019-07-04 15:52:07 +020068 return edid_get_timing_validate(buf, ret, timing,
69 &panel_bits_per_colour,
70 display_mode_valid, dev);
Simon Glass7d3d7762016-01-21 19:45:00 -070071}
72
Simon Glass365b7f72016-11-13 14:22:07 -070073bool display_in_use(struct udevice *dev)
74{
Simon Glass71fa5b42020-12-03 16:55:18 -070075 struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev);
Simon Glass365b7f72016-11-13 14:22:07 -070076
77 return disp_uc_plat->in_use;
78}
79
Simon Glass7d3d7762016-01-21 19:45:00 -070080UCLASS_DRIVER(display) = {
81 .id = UCLASS_DISPLAY,
82 .name = "display",
Simon Glass71fa5b42020-12-03 16:55:18 -070083 .per_device_plat_auto = sizeof(struct display_plat),
Simon Glass7d3d7762016-01-21 19:45:00 -070084};