From 5b2ee2c4a200961fa92ab1f2f2502ee41905257e Mon Sep 17 00:00:00 2001 From: Julien Stephan Date: Mon, 30 Jun 2025 12:08:15 +0200 Subject: [PATCH 1/2] video: display: refactor display_read_timing to avoid code duplication Commit 2dcf143398ad ("dm: video: Repurpose the 'displayport' uclass to 'display'") left the display_read_edid() function unused by mistake. Mark the function as static and reuse it within display_read_timing() to avoid code duplication. Signed-off-by: Julien Stephan --- drivers/video/display-uclass.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/video/display-uclass.c b/drivers/video/display-uclass.c index 61a73e1bc2a..57e730538df 100644 --- a/drivers/video/display-uclass.c +++ b/drivers/video/display-uclass.c @@ -10,7 +10,7 @@ #include #include -int display_read_edid(struct udevice *dev, u8 *buf, int buf_size) +static int display_read_edid(struct udevice *dev, u8 *buf, int buf_size) { struct dm_display_ops *ops = display_get_ops(dev); @@ -59,9 +59,7 @@ int display_read_timing(struct udevice *dev, struct display_timing *timing) if (ops && ops->read_timing) return ops->read_timing(dev, timing); - if (!ops || !ops->read_edid) - return -ENOSYS; - ret = ops->read_edid(dev, buf, sizeof(buf)); + ret = display_read_edid(dev, buf, sizeof(buf)); if (ret < 0) return ret; From 5e9b0b56ad8c2a4289b2b506ad3d0f3acd0d20ba Mon Sep 17 00:00:00 2001 From: Julien Stephan Date: Mon, 30 Jun 2025 12:08:16 +0200 Subject: [PATCH 2/2] cmd: add new command to read edid Add a new command to read EDID info from connected display. When applicable EDID can also be retrieved by commands such as: i2c dev x i2c edid 0x50 but the new read_edid function relies on the implementation of the read_edid callback from DISPLAY driver. Signed-off-by: Julien Stephan --- cmd/Kconfig | 6 ++++++ cmd/Makefile | 1 + cmd/read_edid.c | 38 ++++++++++++++++++++++++++++++++++ drivers/video/display-uclass.c | 2 +- include/display.h | 10 +++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 cmd/read_edid.c diff --git a/cmd/Kconfig b/cmd/Kconfig index f21d27cb27f..3018e33ca7d 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1608,6 +1608,12 @@ config CMD_READ help Provides low-level access to the data in a partition. +config CMD_READ_EDID + bool "read_edid - Read display EDID" + depends on DISPLAY + help + Read and parse edid from connected display device. + config CMD_REMOTEPROC bool "remoteproc" depends on REMOTEPROC diff --git a/cmd/Makefile b/cmd/Makefile index 80cf70b7fe8..7cb379c05a0 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -154,6 +154,7 @@ obj-$(CONFIG_CMD_WOL) += wol.o obj-$(CONFIG_CMD_QFW) += qfw.o obj-$(CONFIG_CMD_READ) += read.o obj-$(CONFIG_CMD_WRITE) += read.o +obj-$(CONFIG_CMD_READ_EDID) += read_edid.o obj-$(CONFIG_CMD_REGINFO) += reginfo.o obj-$(CONFIG_CMD_REMOTEPROC) += remoteproc.o obj-$(CONFIG_CMD_RNG) += rng.o diff --git a/cmd/read_edid.c b/cmd/read_edid.c new file mode 100644 index 00000000000..428dddca8bb --- /dev/null +++ b/cmd/read_edid.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2025 BayLibre, SAS + */ + +#include +#include +#include +#include + +static int do_read_edid(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + struct udevice *dev; + int ret; + u8 edid[EDID_EXT_SIZE]; + + /* Get the first display device (UCLASS_DISPLAY) */ + ret = uclass_first_device_err(UCLASS_DISPLAY, &dev); + if (ret) { + printf("Cannot get display device: %d\n", ret); + return CMD_RET_FAILURE; + } + + ret = display_read_edid(dev, edid, EDID_EXT_SIZE); + if (ret) { + printf("Cannot read edid: %d\n", ret); + return CMD_RET_FAILURE; + } + + edid_print_info((struct edid1_info *)edid); + + return CMD_RET_SUCCESS; +} + +U_BOOT_CMD(read_edid, 1, 0, do_read_edid, + "Read and print EDID from display", + "" +); diff --git a/drivers/video/display-uclass.c b/drivers/video/display-uclass.c index 57e730538df..85dac12a197 100644 --- a/drivers/video/display-uclass.c +++ b/drivers/video/display-uclass.c @@ -10,7 +10,7 @@ #include #include -static int display_read_edid(struct udevice *dev, u8 *buf, int buf_size) +int display_read_edid(struct udevice *dev, u8 *buf, int buf_size) { struct dm_display_ops *ops = display_get_ops(dev); diff --git a/include/display.h b/include/display.h index e8d8aaa15fb..26b965daba9 100644 --- a/include/display.h +++ b/include/display.h @@ -25,6 +25,16 @@ struct display_plat { bool in_use; }; +/** + * display_read_edid() - Read edid from display + * + * @dev: Device to read from + * @buf: Buffer to read into (should be EDID_SIZE bytes) + * @buf_size: Buffer size (should be EDID_SIZE) + * Return number of bytes read, <= 0 for error + */ +int display_read_edid(struct udevice *dev, u8 *buf, int buf_size); + /** * display_read_timing() - Read timing information *