Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Google Inc. |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <display.h> |
| 9 | #include <edid.h> |
| 10 | #include <errno.h> |
| 11 | |
| 12 | int 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 | |
| 21 | int 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 Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 25 | struct display_plat *disp_uc_plat; |
| 26 | int ret; |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 27 | |
| 28 | if (!ops || !ops->enable) |
| 29 | return -ENOSYS; |
Simon Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 30 | ret = ops->enable(dev, panel_bpp, timing); |
| 31 | if (ret) |
| 32 | return ret; |
| 33 | |
| 34 | disp_uc_plat = dev_get_uclass_platdata(dev); |
| 35 | disp_uc_plat->in_use = true; |
| 36 | |
| 37 | return 0; |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | int display_read_timing(struct udevice *dev, struct display_timing *timing) |
| 41 | { |
| 42 | struct dm_display_ops *ops = display_get_ops(dev); |
| 43 | int panel_bits_per_colour; |
| 44 | u8 buf[EDID_EXT_SIZE]; |
| 45 | int ret; |
| 46 | |
Jacob Chen | eab314f | 2016-03-14 11:20:14 +0800 | [diff] [blame] | 47 | if (ops && ops->read_timing) |
| 48 | return ops->read_timing(dev, timing); |
| 49 | |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 50 | if (!ops || !ops->read_edid) |
| 51 | return -ENOSYS; |
| 52 | ret = ops->read_edid(dev, buf, sizeof(buf)); |
| 53 | if (ret < 0) |
| 54 | return ret; |
| 55 | |
| 56 | return edid_get_timing(buf, ret, timing, &panel_bits_per_colour); |
| 57 | } |
| 58 | |
Simon Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 59 | bool display_in_use(struct udevice *dev) |
| 60 | { |
| 61 | struct display_plat *disp_uc_plat = dev_get_uclass_platdata(dev); |
| 62 | |
| 63 | return disp_uc_plat->in_use; |
| 64 | } |
| 65 | |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 66 | UCLASS_DRIVER(display) = { |
| 67 | .id = UCLASS_DISPLAY, |
| 68 | .name = "display", |
| 69 | .per_device_platdata_auto_alloc_size = sizeof(struct display_plat), |
| 70 | }; |