Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Google Inc. |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Delaunay | 8131335 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_DISPLAY |
| 7 | |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 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); |
Simon Glass | 365b7f7 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 26 | struct display_plat *disp_uc_plat; |
| 27 | int ret; |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 28 | |
| 29 | if (!ops || !ops->enable) |
| 30 | return -ENOSYS; |
Simon Glass | 365b7f7 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 31 | ret = ops->enable(dev, panel_bpp, timing); |
| 32 | if (ret) |
| 33 | return ret; |
| 34 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 35 | disp_uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | 365b7f7 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 36 | disp_uc_plat->in_use = true; |
| 37 | |
| 38 | return 0; |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 39 | } |
| 40 | |
Neil Armstrong | faa419c | 2019-07-04 15:52:07 +0200 | [diff] [blame] | 41 | static 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 Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 52 | int 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 Chen | 4b28a90 | 2016-03-14 11:20:14 +0800 | [diff] [blame] | 59 | if (ops && ops->read_timing) |
| 60 | return ops->read_timing(dev, timing); |
| 61 | |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 62 | 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 Armstrong | faa419c | 2019-07-04 15:52:07 +0200 | [diff] [blame] | 68 | return edid_get_timing_validate(buf, ret, timing, |
| 69 | &panel_bits_per_colour, |
| 70 | display_mode_valid, dev); |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Simon Glass | 365b7f7 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 73 | bool display_in_use(struct udevice *dev) |
| 74 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 75 | struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev); |
Simon Glass | 365b7f7 | 2016-11-13 14:22:07 -0700 | [diff] [blame] | 76 | |
| 77 | return disp_uc_plat->in_use; |
| 78 | } |
| 79 | |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 80 | UCLASS_DRIVER(display) = { |
| 81 | .id = UCLASS_DISPLAY, |
| 82 | .name = "display", |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 83 | .per_device_plat_auto = sizeof(struct display_plat), |
Simon Glass | 7d3d776 | 2016-01-21 19:45:00 -0700 | [diff] [blame] | 84 | }; |