blob: e752eb07c4d6ea761c455a3acf80024a293766ba [file] [log] [blame]
Simon Glass2dcf1432016-01-21 19:45:00 -07001/*
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
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 Glass1b682832016-11-13 14:22:07 -070026 struct display_plat *disp_uc_plat;
27 int ret;
Simon Glass2dcf1432016-01-21 19:45:00 -070028
29 if (!ops || !ops->enable)
30 return -ENOSYS;
Simon Glass1b682832016-11-13 14:22:07 -070031 ret = ops->enable(dev, panel_bpp, timing);
32 if (ret)
33 return ret;
34
35 disp_uc_plat = dev_get_uclass_platdata(dev);
36 disp_uc_plat->in_use = true;
37
38 return 0;
Simon Glass2dcf1432016-01-21 19:45:00 -070039}
40
41int display_read_timing(struct udevice *dev, struct display_timing *timing)
42{
43 struct dm_display_ops *ops = display_get_ops(dev);
44 int panel_bits_per_colour;
45 u8 buf[EDID_EXT_SIZE];
46 int ret;
47
Jacob Cheneab314f2016-03-14 11:20:14 +080048 if (ops && ops->read_timing)
49 return ops->read_timing(dev, timing);
50
Simon Glass2dcf1432016-01-21 19:45:00 -070051 if (!ops || !ops->read_edid)
52 return -ENOSYS;
53 ret = ops->read_edid(dev, buf, sizeof(buf));
54 if (ret < 0)
55 return ret;
56
57 return edid_get_timing(buf, ret, timing, &panel_bits_per_colour);
58}
59
Simon Glass1b682832016-11-13 14:22:07 -070060bool display_in_use(struct udevice *dev)
61{
62 struct display_plat *disp_uc_plat = dev_get_uclass_platdata(dev);
63
64 return disp_uc_plat->in_use;
65}
66
Simon Glass2dcf1432016-01-21 19:45:00 -070067UCLASS_DRIVER(display) = {
68 .id = UCLASS_DISPLAY,
69 .name = "display",
70 .per_device_platdata_auto_alloc_size = sizeof(struct display_plat),
71};