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 | |
Patrick Delaunay | b953ec2 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_DISPLAY |
| 7 | |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <dm.h> |
| 10 | #include <display.h> |
| 11 | #include <edid.h> |
| 12 | #include <errno.h> |
| 13 | |
| 14 | int display_read_edid(struct udevice *dev, u8 *buf, int buf_size) |
| 15 | { |
| 16 | struct dm_display_ops *ops = display_get_ops(dev); |
| 17 | |
| 18 | if (!ops || !ops->read_edid) |
| 19 | return -ENOSYS; |
| 20 | return ops->read_edid(dev, buf, buf_size); |
| 21 | } |
| 22 | |
| 23 | int display_enable(struct udevice *dev, int panel_bpp, |
| 24 | const struct display_timing *timing) |
| 25 | { |
| 26 | struct dm_display_ops *ops = display_get_ops(dev); |
Simon Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 27 | struct display_plat *disp_uc_plat; |
| 28 | int ret; |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 29 | |
| 30 | if (!ops || !ops->enable) |
| 31 | return -ENOSYS; |
Simon Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 32 | ret = ops->enable(dev, panel_bpp, timing); |
| 33 | if (ret) |
| 34 | return ret; |
| 35 | |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 36 | disp_uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 37 | disp_uc_plat->in_use = true; |
| 38 | |
| 39 | return 0; |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Neil Armstrong | eb4ee4e | 2019-07-04 15:52:07 +0200 | [diff] [blame] | 42 | static bool display_mode_valid(void *priv, const struct display_timing *timing) |
| 43 | { |
| 44 | struct udevice *dev = priv; |
| 45 | struct dm_display_ops *ops = display_get_ops(dev); |
| 46 | |
| 47 | if (ops && ops->mode_valid) |
| 48 | return ops->mode_valid(dev, timing); |
| 49 | |
| 50 | return true; |
| 51 | } |
| 52 | |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 53 | int display_read_timing(struct udevice *dev, struct display_timing *timing) |
| 54 | { |
| 55 | struct dm_display_ops *ops = display_get_ops(dev); |
| 56 | int panel_bits_per_colour; |
| 57 | u8 buf[EDID_EXT_SIZE]; |
| 58 | int ret; |
| 59 | |
Jacob Chen | eab314f | 2016-03-14 11:20:14 +0800 | [diff] [blame] | 60 | if (ops && ops->read_timing) |
| 61 | return ops->read_timing(dev, timing); |
| 62 | |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 63 | if (!ops || !ops->read_edid) |
| 64 | return -ENOSYS; |
| 65 | ret = ops->read_edid(dev, buf, sizeof(buf)); |
| 66 | if (ret < 0) |
| 67 | return ret; |
| 68 | |
Neil Armstrong | eb4ee4e | 2019-07-04 15:52:07 +0200 | [diff] [blame] | 69 | return edid_get_timing_validate(buf, ret, timing, |
| 70 | &panel_bits_per_colour, |
| 71 | display_mode_valid, dev); |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Simon Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 74 | bool display_in_use(struct udevice *dev) |
| 75 | { |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 76 | struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | 1b68283 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 77 | |
| 78 | return disp_uc_plat->in_use; |
| 79 | } |
| 80 | |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 81 | UCLASS_DRIVER(display) = { |
| 82 | .id = UCLASS_DISPLAY, |
| 83 | .name = "display", |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 84 | .per_device_plat_auto = sizeof(struct display_plat), |
Simon Glass | 2dcf143 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 85 | }; |