From patchwork Wed Dec 2 10:26:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dario Binacchi X-Patchwork-Id: 5108 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 40AE73F336 for ; Wed, 2 Dec 2026 11:27:40 +0100 (CET) Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4b9fde3044dsf94510755e9.0 for ; Wed, 02 Dec 2026 02:27:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1796207260; cv=pass; d=google.com; s=arc-20260327; b=k/JY8XQCU6gzLqfjOXcJtUD/cJHBoKwi5zyEWWLjKxDn8kDBRBVKgRVZHKdokLxZaF mIFUVSQOA/uLV/aduXhOp2Kz/tYRHNn78U0BKJQ0d97KJf3vNy2p4k78jUXEgUC/PH3c ID4T91vDCKXQ1d0cZLFX1q++bZwlfr/eUPyNNb0/aT3wVCX2ksTNcSM2BpS2MfkCL4Kb duzQbtWqHz2vWsRFE/QGHUO1BX6BMYj5lHZ8jSqMoT0zxowK7WRF3KNYpgM1i9Z7fRRh MGg0N0aDeqpJ4cpxT3Qp6qBo5TagAFFWjlmxLWzJICMu9ZXSWgwwVICdXS2MXezk2B0S TSEg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=64/1HOag1u9Wb2E97/uNg5DHKSVsUWtO3qR4/oLMEmw=; fh=dZzR3Lvf8pj3FqiSJGi5A7tyfCZsesETmLMMVVKT+Ak=; b=MHbtMHM1wBtoQfXQmxYLUIHufjQnZQKPgpEHqGcyY/qUfWpmN9K2Qlxq4/+wbqkE32 QEvkQfPrmwFcO4ANmMgOynV+kQJcYFUMFt8LW7WuDQdIz7sJM08g/nASIO7sSEnszMsl kHcmPKvz3CDTIAflqvyaV9LlFdU9wdKwWR8q0jP/M0mkv7azt4fPBAxqyn21gSYIhNWs /UYAxw1FEIP+Qzjfexz9IJnRVetEwkDehHEfVLG41pvKWfq1fndU3UXxRNSWez+doJEX hxgZUSA8wv5N8S0y/yKJOh7aTtakNKaaiM3Tv+DjRlnuIcMJaJZbw8pZd0bH7W1CLIZ9 S5dA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=IYQND0ot; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1796207260; x=1796812060; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:content-type :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=64/1HOag1u9Wb2E97/uNg5DHKSVsUWtO3qR4/oLMEmw=; b=pwQwWvDhClF2FIU2UpJpKIBFJgOU6tw0jp2aIk1qoyqwiHp1bgBCvvUBYR49jahNy7 Vb5NO823Xop5zeI6QKIoXiEdHif0culOZeQBigi5UKq7DDtYJN/xX30HoAfSjZXz71vj o5r52/DrH5W5GGZtOGkMceBaa1a0Bt/bDDpyI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796207260; x=1796812060; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :content-type:x-original-authentication-results:x-original-sender :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-gg:x-beenthere:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=64/1HOag1u9Wb2E97/uNg5DHKSVsUWtO3qR4/oLMEmw=; b=CAW19NbIx7EdgG7lFdtamLmsM6DXEU4LR7N83wyf4l6eua0FDRNrFKMXhNX/z/+yNN 9mnh8yKOizvFMVQ1LWbj8xAd3TYkQfKgDOBJE8t/3pFsvpdGUW08gXuYm3PvHQicyZLV 1I7eBnSpciNHKaphHpbxBosdsBpnkbUUvEkxgapgCE6jBOrkUJFHjfPZHGbfc9dcXG6/ OXt3RrQT5H1iGeifK7kwQ+aXUo0+VW4/3sbeUz2wDqcGl+4jNV2y7Dn/bXaJVPd2d2Et hTZYZk+SRF5QF6jGIagxYye4ss+7iVv2QXuysCYPO5GE1TQjWLH6RC+gNtheFUAUup4H 2HBw== X-Forwarded-Encrypted: i=2; AL+hErG4MWSkTluZtvtL9PzV6nhBaeGwlvFYjPfoagU+yxEeChmPi5DlJbX7P/vG76THe4rl6ufHHrleH0IMe+y/@patchwork.amarulasolutions.com X-Gm-Message-State: APuU4Z/WWvqI5Ezu5bZDAAl8r/OHaM2T7nlstymH+zi+OGyNAX/G6Ep1 O7WFJQheHtjPPlN2BtKJDqUg1Q/VFnXLqGy124FwkfFd1CZoM5Ugf36eOUdEC1XD1P5I9A== X-Received: by 2002:a05:600c:828e:b0:4a1:cd83:b23e with SMTP id 5b1f17b1804b1-4bb88786ddemr723225475e9.0.1796207259911; Wed, 02 Dec 2026 02:27:39 -0800 (PST) X-BeenThere: linux-amarula@amarulasolutions.com; h="ATskLdd/8lNJ8ps+Xsw1EEMtjrxgk3epBzVXEv/+KihoiU3Oog==" Received: by 2002:a05:600c:4e8f:b0:4a1:dae5:1dd with SMTP id 5b1f17b1804b1-4bb892755cbls110024255e9.2.-pod-prod-06-eu; Wed, 02 Dec 2026 02:27:38 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErEu53r+mvMuVFuhQAjWqqUG2K8UCxCNHewSoruc6isZ0a2XVcpmIL0c7sEO9ECo2wHoCZSuqL8tYC4UWT6B@amarulasolutions.com X-Received: by 2002:a05:600c:19d2:b0:4bb:d8f0:2088 with SMTP id 5b1f17b1804b1-4bbd8f02139mr20424035e9.4.1796207258305; Wed, 02 Dec 2026 02:27:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796207258; cv=none; d=google.com; s=arc-20260327; b=SFzZxqQnnrIa9gEVIrWb04ZOfuu3Qk2Z0ZkB6fDu7qlDLoB428fI6at8TA0rFCwJkn IMcK1Hl4zv9vTZz/tCojXT8bPbuPvt4Z3sD7/h1MA7JvQhuCbBzjp6qQwAHiQ6U831m2 o1h92wuIsWfckW84ArUm1E4F0xylUrGJpIr0zPymGo4Lzz8SGxQT0kKDCefVSXw9ie0p oEgYMB34nRSp09VK83G0iqh2qEPpjX1UJBRUttLuBGQs+WRfCB/ikgN0iUPcFEYg1vrZ ZhpXtRiHDDIZcaRvgqH31MG3L4xnXbDwBYiQ9v+QqoamE4zPDipeDdBKSr+I1v83J14c b3gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=ySZFse/9mXkFcQqLKAiyVlBWAzzX5wJHwsXYEIfm1uQ=; fh=em+l0gXQKaXnNBt2X8IvRrCMtY58ygPH3g4LQ5oI0AA=; b=DAUcAJdczdKd6wZJkfDCYMUjwEI0Gz83qnVrfJZhPQq+nFH7Ef+B2mYAIQGQRz6Mue YzpzC4xrK/C/EW9sIvX8Wb5gTlIjUE8U5tBba305kd45An6s8y2vUthIqMzvQW44PfaH DsZe9eQswueZKBK45ZyP43ZqEXXVXLLc5m6XXVNj2DzCNP0wb/WrSz/cy0XQ63SykzeS KhZ91ke71bVcVvXD/svGSc7yEl1Q5Icw0Y3jtQVNWhrUEvcRbV8QDNuQcFgTIMV+1+xS gonAETyBIU23+wQMOGJxaq8TZuF5YfKymKe47E99mFjkfWBZNXvLSGuPEZ+4JzcDQDSK T5dg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=IYQND0ot; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5b1f17b1804b1-4bb8849eadfsor59524935e9.10.2026.12.02.02.27.38 for (Google Transport Security); Wed, 02 Dec 2026 02:27:38 -0800 (PST) Received-SPF: pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AL+hErFo0SVGErhsG5Sm9xpKMrWp94mUlXka+RSzNoxJmoPPdA28r+TEZXWjlHnMcys6TBjIt+ryXkGvwoPFv8xU@amarulasolutions.com X-Gm-Gg: AZFdTZfZWDr0dXr1JaPK0f2TG4smrtTv9Vmkjkay8zFIBg6FfgobFWLbNrc5t0wlTbu Nk0WA0RFnFCLCJWoTjYGtDMtt3bb0PyOI55wWRKVw2vZFCygIvheXQfjcn/zzvVrf0Ho+wPT/VL 3QuCekBMjYzzTY883pDQkiXkWHfp8IRi3n1QFyN91tFhBZAm0fojQQYLz7251ztGcHjacjnaum6 MvjKOPUFm+/Lv2xVwQY0to+aMIW8DLYirPLArE9gQIK0yomgDi17RbueYDM9f5A+AGm5dQRTUwI E+/cj7FjMAIQrQcAtIl6YrItoyBXzSMU6LfPSXusX+iEgoRGXmeaQAjM563dgFG14/LnXbSScL2 51+/0cpmsVJjf4SipI6guQaKAk3CLVKTsW/lbvkAsWTbLhRt/hdRt2L5732xyOP+EbVpa3f4FI8 q4PV0ePFME1w4ssM4N2AUv3GuWHZbkE44mma4udvYxugrj37FdGuy/yvtjFwNykWdsuNyU3Ze1z 5F6gYGd8auxrhwXL+sndfd+Z4FJDUMUQpp3BuuWs48rcvbqzNMoeghbU5am9w4LTBst4nl/ylB3 DR4NX9UlZbposBG4jhUeo/e8655jFQ0e0dmxX/ERkcL7zxnOZiCZeRGZsqfNAdmiNL1DMlS0GoI vd9IYVSlqj7gufHn3+8TS1YYW1Sos/acySmzZOeyTyg== X-Received: by 2002:a05:600c:3b98:b0:4bb:7033:c92f with SMTP id 5b1f17b1804b1-4bb88826810mr789362185e9.11.1796207257842; Wed, 02 Dec 2026 02:27:37 -0800 (PST) Received: from localhost.localdomain ([2001:b07:6474:ebbf:6962:3ebc:7df:e6bf]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbbaeb1e4csm366823865e9.13.2026.12.02.02.27.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Dec 2026 02:27:37 -0800 (PST) From: Dario Binacchi To: u-boot@lists.u-boot-project.org Cc: Heiko Schocher , linux-amarula@amarulasolutions.com, Peng Fan , simon.holesch@bshg.com, Marek Vasut , Valeriy.Yatsenko@bshg.com, Leonhard Hesse , michael@amarulasolutions.com, Miquel Raynal , Ye Li , Dario Binacchi , Anatolij Gustschin , David Lechner , Johan Jonker , Julien Stephan , Tom Rini Subject: [PATCH v3 08/26] video: Add video link framework Date: Wed, 2 Dec 2026 11:26:19 +0100 Message-ID: <20261202102716.572884-9-dario.binacchi@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261202102716.572884-1-dario.binacchi@amarulasolutions.com> References: <20261202102716.572884-1-dario.binacchi@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: dario.binacchi@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=IYQND0ot; spf=pass (google.com: domain of dario.binacchi@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=dario.binacchi@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=neutral header.i=@amarulasolutions.com Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Michael Trimarchi The video link framework uses the port-endpoint graph of the device tree to connect the video components (video, display, bridge and panel uclasses). Several video links can be described this way, and the user can select one of them for the splash screen. Signed-off-by: Ye Li Signed-off-by: Michael Trimarchi Signed-off-by: Dario Binacchi --- (no changes since v2) Changes in v2: - Look up a device as a bridge before looking it up as a DSI host - Reword commit message common/stdio.c | 4 + drivers/video/Kconfig | 6 + drivers/video/Makefile | 1 + drivers/video/video_link.c | 448 +++++++++++++++++++++++++++++++++++++ include/video_link.h | 19 ++ 5 files changed, 478 insertions(+) create mode 100644 drivers/video/video_link.c create mode 100644 include/video_link.h diff --git a/common/stdio.c b/common/stdio.c index 271a37e959ca..b441710388c3 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -321,6 +322,9 @@ int stdio_add_devices(void) struct udevice *vdev; int ret; + if (IS_ENABLED(CONFIG_VIDEO_LINK)) + video_link_init(); + if (!IS_ENABLED(CONFIG_SYS_CONSOLE_IS_IN_ENV)) { for (ret = uclass_first_device_check(UCLASS_VIDEO, &vdev); diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig index de0197b21cdb..cc21afbe8ff5 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -973,6 +973,12 @@ config VIDEO_SEPS525 source "drivers/video/zynqmp/Kconfig" source "drivers/video/nexell/Kconfig" +config VIDEO_LINK + bool "Enable video link framework support" + help + This option enables a video link framework basing on port-endpoint graph + to connect video components. + config CONSOLE_SCROLL_LINES int "Number of lines to scroll the console by" default 1 diff --git a/drivers/video/Makefile b/drivers/video/Makefile index 7a7b54e6b53b..6e6d1ba29cdb 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -29,6 +29,7 @@ obj-$(CONFIG_$(PHASE_)SIMPLE_PANEL) += simple_panel.o obj-$(CONFIG_VIDEO_LOGO) += u_boot_logo.bmp.o obj-$(CONFIG_$(PHASE_)BMP) += bmp.o +obj-$(CONFIG_VIDEO_LINK) += video_link.o endif obj-$(CONFIG_BACKLIGHT_AAT2870) += aat2870_backlight.o diff --git a/drivers/video/video_link.c b/drivers/video/video_link.c new file mode 100644 index 000000000000..aab4b2a9ed99 --- /dev/null +++ b/drivers/video/video_link.c @@ -0,0 +1,448 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 NXP + * + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct of_endpoint { + unsigned int port; + unsigned int id; + ofnode local_node; +}; + +#define MAX_LINKS 3 +#define MAX_LINK_DEVICES 5 + +struct video_link { + struct udevice *link_devs[MAX_LINK_DEVICES]; + int dev_num; +}; + +struct video_link video_links[MAX_LINKS]; +struct video_link temp_stack; +ulong video_links_num; +ulong curr_video_link; +bool video_off; + +ofnode ofnode_get_child_by_name(ofnode parent, const char *name) +{ + ofnode child; + const char *child_name; + + for (child = ofnode_first_subnode(parent); + ofnode_valid(child); + child = ofnode_next_subnode(child)) { + child_name = ofnode_get_name(child); + + if (!strncmp(child_name, name, strlen(name))) + break; + } + return child; +} + +ofnode ofnode_graph_get_next_endpoint(ofnode parent, + ofnode prev) +{ + ofnode endpoint; + ofnode port; + const char *name; + + if (!ofnode_valid(prev)) { + ofnode node; + + node = ofnode_find_subnode(parent, "ports"); + if (ofnode_valid(node)) + parent = node; + + port = ofnode_get_child_by_name(parent, "port"); + if (!ofnode_valid(port)) { + debug("no port node found in 0x%lx\n", parent.of_offset); + return ofnode_null(); + } + + endpoint = ofnode_first_subnode(port); + if (ofnode_valid(endpoint)) { + debug("get next endpoint %s\n", ofnode_get_name(endpoint)); + return endpoint; + } + } else { + port = ofnode_get_parent(prev); + endpoint = ofnode_next_subnode(prev); + if (ofnode_valid(endpoint)) { + debug("get next endpoint %s\n", ofnode_get_name(endpoint)); + return endpoint; + } + } + + debug("port %s\n", ofnode_get_name(port)); + + while (1) { + do { + port = ofnode_next_subnode(port); + if (!ofnode_valid(port)) + return ofnode_null(); + + name = ofnode_get_name(port); + } while (strncmp(name, "port", 4)); + + /* + * Now that we have a port node, get the next endpoint by + * getting the next child. If the previous endpoint is NULL this + * will return the first child. + */ + endpoint = ofnode_first_subnode(port); + if (ofnode_valid(endpoint)) { + debug("get next endpoint %s\n", ofnode_get_name(endpoint)); + return endpoint; + } + } + + return ofnode_null(); +} + +#define for_each_endpoint_of_node(parent, child) \ + for (child = ofnode_graph_get_next_endpoint(parent, ofnode_null()); ofnode_valid(child); \ + child = ofnode_graph_get_next_endpoint(parent, child)) + +int ofnode_graph_parse_endpoint(ofnode node, + struct of_endpoint *endpoint) +{ + ofnode port_node = ofnode_get_parent(node); + + memset(endpoint, 0, sizeof(*endpoint)); + + endpoint->local_node = node; + /* + * It doesn't matter whether the two calls below succeed. + * If they don't then the default value 0 is used. + */ + ofnode_read_u32(port_node, "reg", &endpoint->port); + ofnode_read_u32(node, "reg", &endpoint->id); + + return 0; +} + +int find_device_by_ofnode(ofnode node, struct udevice **pdev) +{ + int ret; + + if (!ofnode_is_enabled(node)) + return -2; + + ret = uclass_find_device_by_ofnode(UCLASS_DISPLAY, node, pdev); + if (!ret) + return 0; + + /* + * A bridge may bind its DSI host to its own node: in that case the + * bridge, not the host, is the device in the video link. + */ + ret = uclass_find_device_by_ofnode(UCLASS_VIDEO_BRIDGE, node, pdev); + if (!ret) + return 0; + + ret = uclass_find_device_by_ofnode(UCLASS_DSI_HOST, node, pdev); + if (!ret) + return 0; + + ret = uclass_find_device_by_ofnode(UCLASS_PANEL, node, pdev); + if (!ret) + return 0; + + return -1; +} + +static void video_link_stack_push(struct udevice *dev) +{ + if (temp_stack.dev_num < MAX_LINK_DEVICES) { + temp_stack.link_devs[temp_stack.dev_num] = dev; + temp_stack.dev_num++; + } +} + +static void video_link_stack_pop(void) +{ + if (temp_stack.dev_num > 0) { + temp_stack.link_devs[temp_stack.dev_num] = NULL; + temp_stack.dev_num--; + } +} + +static int duplicate_video_link(void) +{ + if (video_links_num < MAX_LINKS) { + video_links[video_links_num] = temp_stack; + video_links_num++; + + debug("duplicate links num %lu, temp_stack num %d\n", + video_links_num, temp_stack.dev_num); + return 0; + } + + return -ENODEV; +} + +static void video_link_add_node(struct udevice *peer_dev, struct udevice *dev, ofnode dev_node) +{ + int ret = 0; + ofnode remote, endpoint_node; + struct udevice *remote_dev; + bool find = false; + + debug("endpoint cnt %d\n", ofnode_graph_get_endpoint_count(dev_node)); + + video_link_stack_push(dev); + + for_each_endpoint_of_node(dev_node, endpoint_node) { + remote = ofnode_graph_get_remote_port_parent(endpoint_node); + if (!ofnode_valid(remote)) + continue; + + debug("remote %s\n", ofnode_get_name(remote)); + ret = find_device_by_ofnode(remote, &remote_dev); + if (!ret) { + debug("remote dev %s\n", remote_dev->name); + + if (peer_dev && peer_dev == remote_dev) + continue; + + /* it is possible that ofnode of remote_dev is not equal to remote */ + video_link_add_node(dev, remote_dev, remote); + + find = true; + } + } + + /* leaf node or no valid new endpoint, now copy the entire stack to a new video link */ + if (!find) { + ret = duplicate_video_link(); + if (ret) + printf("video link is full\n"); + } + + video_link_stack_pop(); +} + +struct udevice *video_link_get_next_device(struct udevice *curr_dev) +{ + int i, ret; + + if (video_off) + return NULL; + + if (curr_video_link >= video_links_num) { + printf("current video link is not correct\n"); + return NULL; + } + + for (i = 0; i < video_links[curr_video_link].dev_num; i++) { + if (video_links[curr_video_link].link_devs[i] == curr_dev) { + if ((i + 1) < video_links[curr_video_link].dev_num) { + ret = device_probe(video_links[curr_video_link].link_devs[i + 1]); + if (ret) { + printf("probe device is failed, ret %d\n", ret); + return NULL; + } + + return video_links[curr_video_link].link_devs[i + 1]; + } + + debug("fail to find next device, already last one\n"); + return NULL; + } + } + + return NULL; +} + +struct udevice *video_link_get_video_device(void) +{ + int ret; + + if (video_off) + return NULL; + + if (curr_video_link >= video_links_num) + return NULL; + + if (video_links[curr_video_link].dev_num == 0) + return NULL; + + ret = device_probe(video_links[curr_video_link].link_devs[0]); + if (ret) { + printf("probe video device failed, ret %d\n", ret); + return NULL; + } + + return video_links[curr_video_link].link_devs[0]; +} + +int video_link_get_display_timings(struct display_timing *timings) +{ + int i = 0; + int ret; + struct udevice *dev; + + if (video_off) + return -EPERM; + + if (curr_video_link >= video_links_num) + return -ENODEV; + + if (video_links[curr_video_link].dev_num == 0) + return -ENODEV; + + for (i = video_links[curr_video_link].dev_num - 1; i >= 0 ; i--) { + dev = video_links[curr_video_link].link_devs[i]; + if (device_get_uclass_id(dev) == UCLASS_PANEL) { + ret = device_probe(video_links[curr_video_link].link_devs[i]); + if (ret) { + printf("fail to probe panel device %s\n", dev->name); + return ret; + } + + ret = panel_get_display_timing(dev, timings); + if (ret) { + ret = ofnode_decode_display_timing(dev_ofnode(dev), 0, timings); + if (ret) { + printf("fail to get panel timing %s\n", dev->name); + return ret; + } + } + + return 0; + } else if (device_get_uclass_id(dev) == UCLASS_DISPLAY || + device_get_uclass_id(dev) == UCLASS_VIDEO) { + ret = ofnode_decode_display_timing(dev_ofnode(dev), 0, timings); + if (!ret) + return 0; + } + } + + return -EINVAL; +} + +static void list_videolink(bool current_only) +{ + ulong index = 0; + int j; + bool match; + + /* dump the link */ + debug("video link number: %lu\n", video_links_num); + + for (index = 0; index < video_links_num; index++) { + match = false; + if (curr_video_link == index) + match = true; + else if (current_only) + continue; + + printf("[%c]-Video Link %lu", (match) ? '*' : ' ', index); + + if (match) { + struct udevice *video_dev = video_link_get_video_device(); + + if (video_dev) { + printf(" (%u x %u)", video_get_xsize(video_dev), + video_get_ysize(video_dev)); + } + } + + printf("\n"); + + for (j = 0; j < video_links[index].dev_num; j++) { + printf("\t[%d] %s, %s\n", j, video_links[index].link_devs[j]->name, + dev_get_uclass_name(video_links[index].link_devs[j])); + } + } +} + +static int do_videolink(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) +{ + char cmd = 'l'; + int ret = 0; + + if (argc > 1) + cmd = argv[1][0]; + + switch (cmd) { + case 'l': /* list */ + list_videolink(false); + break; + default: + ret = CMD_RET_USAGE; + break; + } + + return ret; +} + +int video_link_init(void) +{ + struct udevice *dev; + ulong env_id; + int off; + + memset(&video_links, 0, sizeof(video_links)); + memset(&temp_stack, 0, sizeof(temp_stack)); + + for (uclass_find_first_device(UCLASS_VIDEO, &dev); + dev; + uclass_find_next_device(&dev)) { + video_link_add_node(NULL, dev, dev_ofnode(dev)); + } + + if (video_links_num == 0) { + printf("Fail to setup video link\n"); + return -ENODEV; + } + + /* Read the env variable for default video link */ + off = env_get_yesno("video_off"); + if (off == 1) { + video_off = true; + return 0; + } + + env_id = env_get_ulong("video_link", 10, 0); + if (env_id < video_links_num) + curr_video_link = env_id; + + list_videolink(true); + + return 0; +} + +int video_link_shut_down(void) +{ + struct udevice *video_dev = video_link_get_video_device(); + + if (video_dev) + device_remove(video_dev, DM_REMOVE_NORMAL); + + return 0; +} + +#if CONFIG_IS_ENABLED(SYS_LONGHELP) +static char video_link_help_text[] = + "list\n" + " - show video link info, set video_link variable to select link"; +#endif + +U_BOOT_CMD(videolink, 5, 1, do_videolink, + "list and select video link", video_link_help_text +); diff --git a/include/video_link.h b/include/video_link.h new file mode 100644 index 000000000000..5350bfa9e9d1 --- /dev/null +++ b/include/video_link.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2020 NXP + */ + +#ifndef __VIDEO_LINK +#define __VIDEO_LINK + +int video_link_init(void); + +int video_link_shut_down(void); + +struct udevice *video_link_get_next_device(struct udevice *curr_dev); + +struct udevice *video_link_get_video_device(void); + +int video_link_get_display_timings(struct display_timing *timings); + +#endif