From patchwork Sat Jul 13 08:45:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Nazzareno Trimarchi X-Patchwork-Id: 3220 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id D7E6A40F45 for ; Sat, 13 Jul 2024 10:45:56 +0200 (CEST) Received: by mail-ed1-f69.google.com with SMTP id 4fb4d7f45d1cf-58bd84067fdsf2687690a12.0 for ; Sat, 13 Jul 2024 01:45:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720860356; cv=pass; d=google.com; s=arc-20160816; b=IZprUkT/8n5qPx0ztRyXfCf+mW5nBWhzPbgkBmAYrneUK7jwy2stDpMQsms7uI5JUo mErjctZdndW8k0TCt6dA725R/07FaZHeI9TEgqEKux2CpwYVs9wWIGgaNMtHMDcR+mJt nt+lCvAaoT7Qy7E091/QE/BsWO80KuaxiDHx39gLJSot9apetMlVBP0m8+a2gvZQhdtn dNx5BG+b8LyjfBj6FVgp6BBXHidcvuFusP8DXOeSa+4ap00BlDjJ0S2tjZIqiDvbRIZ2 QQUNdOhSpTUVJ/vyEH9wI+2ABAdos/MbI5RDaR/JCms8os01ycL+CBhlH33B6p4aaIoP TU7g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=EGw9hIRkwT3tSjEQ3nqYOOdBA4Irx2tY4/xRaMl3SAU=; fh=U6Vf+jVT99Cq+w3LKL/MJRnHkju3Vw6crIGScINHBRw=; b=M4ZeCq3qnSb3F0isutlOhqE0B493FCzTEbS1Zb+ql7Ak95iyUzVSKOJljTx96vFO6D VbPasF55/z2z6XLUawHP3pJ1vS1dz+B46Wn/Zb/zqnUlGM0AeT+1vWovh3EUD5ad9sM2 LHUMEmjs0usxFdEXPQQU4/EzxzzhehMaTCgWIYJ5EIHW2GQuk6z6PYj3HJD2IgVaiDoa VUNYIN4NYunuhkUocObHSsc62Tdt7x1Vw+s3iWcNUP+qJm7AE/8SrhneopDX8+BkGkks ZNtmHaATzG3bqILxkhJw2OuX6lsoBZaDV/Y+gLD1LT+NzkFA0UdvTIMKyaedT2L73z8c 0pCA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GxVzgc29; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1720860356; x=1721465156; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence: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; bh=EGw9hIRkwT3tSjEQ3nqYOOdBA4Irx2tY4/xRaMl3SAU=; b=ojJnDPtCrWWFP6S1dD5zKb+kWpNr/wvRA94wJGKl5ouW6im9X0dy6o8SQpVUYQ9O+F 9ddHNe/D8hDrGJ9oDFTUrND7XAN2NelK2TwmeNaxzeTPRevhC5BC5PcNw57q96zrZoNv zAUODzKeBEv7w7wC9eij0bHWCgPaORtkKUVLg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720860356; x=1721465156; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EGw9hIRkwT3tSjEQ3nqYOOdBA4Irx2tY4/xRaMl3SAU=; b=bkuJ2vWfb9D/4aDrQMyk31HofmLhNQfhhMDI3CRO1u9iflPrEmILzkn0sQFHDLjLkF 8YIPOZiqA/e4NxxY/TC3bELXVLX9a4Z8z8haZC8HaTUE3emqAOTGZNqCcS+1Gi79mgsy 4xIHZX6q+jfqi+B/XJ0cKpN2wKqyMUxtw8JOEMa02SxiRJtSXjfMIfK8dCKoARLatMkS F8a+70k7b9g8ylT+uxkJ7mwYpYyHrP8qWs/COjtSZm/YkED79/E+5igF03R5hROeXIkB lqE5jddFOlyvZ0nAcwWdE61Tei7U4RtrK53rVW/SE5bhqH14d3o/axgS9kxrLbli+1XA xU7g== X-Forwarded-Encrypted: i=2; AJvYcCWBtwg/qy6uJB9J0h+3FRJ+a5ocLmSCb3x9Oq1L/r0TKgx9utE3sEnlAjGJYxwByABogeVNr0oBvdb4OJZYNR+ZoeiRMsg1ZHEAI8Xd83tsaCXYQhjxu8tT7JL+uA== X-Gm-Message-State: AOJu0Yxy/mBeJ5vTncgIqbR1pcE7f6jfvMgu4bMbkJ8ADUDwfEkPe9DC RzFR+IJOWrsp9TsOU3HFvpo2yDdJzZwNceZmgTXJufhGKlorFz3M9hi6YtiP0MGHFQ== X-Google-Smtp-Source: AGHT+IEMLDwUIkwoJAGBqpgJ/9G4JH2k4Wkq7Za4fpJD0lQRC69PtOZNWy+AqF5GVd7V5aZwbDoGcQ== X-Received: by 2002:a50:ee0b:0:b0:58d:836e:5d83 with SMTP id 4fb4d7f45d1cf-594ba59f8eamr8185667a12.22.1720860356580; Sat, 13 Jul 2024 01:45:56 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:48f:b0:57d:2188:f507 with SMTP id 4fb4d7f45d1cf-598267117b9ls1569831a12.2.-pod-prod-07-eu; Sat, 13 Jul 2024 01:45:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVMIXWRegLr6+4qZvPKvM9pDZQt2G1gGPvx+YGCT1M9mQ2aVENjoArnQhEk9JDSepqY7GBfEe9O5gPHmf43eofh67aBOLR1H+L/pnb4JA3qvI2M X-Received: by 2002:a17:906:260d:b0:a72:b287:1e04 with SMTP id a640c23a62f3a-a780b70106fmr762609866b.34.1720860354876; Sat, 13 Jul 2024 01:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720860354; cv=none; d=google.com; s=arc-20160816; b=y1FxbRfhQvJ9WQESxupZG38u3nvWmMEBkRMT9Yy5iXXU4aHV0sc/GsC1OhW/gdpnCw cs50Xzj6XjoRXeqWvE+Q32lMonkEBr/m0vIGvFmlwSdkfCX+Vx0P6iXCxdtSEvjo4+iu 9MXhRZ5IVXgC6Cbhp2Pm30anFhUjA6JO20l31bMVGng2/MzKWWg80IrPIATtYLLhq23Y Jakhe3X1ZAKuWAbvmzPwgDykZTUEqOkPEyycQLJ3Hs+wb2LdvdWOUwb+o8i0cijCEz9Z 2JbsDKuSNJFpSjFLvaj6RJ6k4luK/wR2q+MKan6WleucxvuWWPUUtFOLwpLDQ0stQQAO 2Sew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=Z3W0hoRpyMm4WoJgMyNV8HWNsiT1Mc0t5TiaWe9taTw=; fh=C/EzQxJh8QKJud29KecolqYGROV4Cj/h1Kc3niIfg18=; b=YpaGDGsKJA4jyXs6npBp4W68vVIAyzUt4BpyzB9VZjyuWfcOEYj7AFqpYaRVaJIarb oil8GlcJGk+Hd/PwJp7r8kNVFpMfuXUtWrUJ0h7c32tgbPcGu2EcPzaenS7qVHYw5AoY 7Et/lVdZrAKHkaDoX3FGLtW8VCMfx1QRiTnEA6puLdMcS0i3VSQ2YAEbxz5ZEL2i2P0r fwEVRHLOIF/4Lhk2PYY3o6VZC3XBzosrKxi3L6BOoyIy0ketGYtziku0i6zxY50NSp3M r8sgZNQ0omvVqS65MKaV/zMo1UzICokhnQ9jI1jfmK2IsBN0/1GDzR6LiVK6Jk5S0YO0 ULsQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GxVzgc29; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass 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 a640c23a62f3a-a79bc588acbsor14183166b.2.2024.07.13.01.45.54 for (Google Transport Security); Sat, 13 Jul 2024 01:45:54 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AJvYcCWtyPxsu7QCALIvD7ju2pa3WgqXeT5xN8Fx7qBdgQMTyj2NPrBuRxjXKRbqODlne3freB8xNrYMf89MHths8XctYVx6AWN6KqjiFXRcSzwDZiaB X-Received: by 2002:a17:906:3ad8:b0:a77:e48d:bb1 with SMTP id a640c23a62f3a-a780b68a2ebmr761278566b.2.1720860354353; Sat, 13 Jul 2024 01:45:54 -0700 (PDT) Received: from panicking.amarulasolutions.com (93-35-128-17.ip55.fastwebnet.it. [93.35.128.17]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a79bc7f1e20sm31483966b.116.2024.07.13.01.45.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Jul 2024 01:45:53 -0700 (PDT) From: Michael Trimarchi To: Michael Trimarchi Cc: Dario Binacchi , Patrick Barsanti , linux-amarula@amarulasolutions.com, Ye Li Subject: [PATCH 14/21] video: Add video link framework Date: Sat, 13 Jul 2024 10:45:19 +0200 Message-ID: <20240713084526.922537-14-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240713084526.922537-1-michael@amarulasolutions.com> References: <20240713084526.922537-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=GxVzgc29; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" 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: , The video link framework bases a port-endpoint gragh in DTB to connect the video components in uclass like: video, display, bridge, and panel. Using the port-endpoint gragh, we manage multiple video link and user can select one of them for splash screen. Signed-off-by: Ye Li Signed-off-by: Michael Trimarchi --- common/stdio.c | 4 + drivers/video/Kconfig | 6 + drivers/video/Makefile | 1 + drivers/video/bmp.c | 11 +- drivers/video/video_link.c | 533 +++++++++++++++++++++++++++++++++++++ include/video_link.h | 19 ++ 6 files changed, 573 insertions(+), 1 deletion(-) 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 a61220ce4b..66360c97ed 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -340,6 +341,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 7808ae7919..d2432d67a4 100644 --- a/drivers/video/Kconfig +++ b/drivers/video/Kconfig @@ -798,6 +798,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 f3f70cd04a..9fd3645994 100644 --- a/drivers/video/Makefile +++ b/drivers/video/Makefile @@ -27,6 +27,7 @@ obj-$(CONFIG_$(SPL_TPL_)SIMPLE_PANEL) += simple_panel.o obj-$(CONFIG_VIDEO_LOGO) += u_boot_logo.o obj-$(CONFIG_$(SPL_TPL_)BMP) += bmp.o +obj-$(CONFIG_VIDEO_LINK) += video_link.o endif obj-$(CONFIG_BACKLIGHT_LM3533) += lm3533_backlight.o diff --git a/drivers/video/bmp.c b/drivers/video/bmp.c index 291ed36440..3ac835d45d 100644 --- a/drivers/video/bmp.c +++ b/drivers/video/bmp.c @@ -17,6 +17,7 @@ #include #include #include +#include #include /* @@ -124,7 +125,15 @@ int bmp_display(ulong addr, int x, int y) } addr = map_to_sysmem(bmp); - ret = uclass_first_device_err(UCLASS_VIDEO, &dev); + if (IS_ENABLED(CONFIG_VIDEO_LINK)) { + dev = video_link_get_video_device(); + if (!dev) + ret = -ENODEV; + else + ret = 0; + } else { + ret = uclass_first_device_err(UCLASS_VIDEO, &dev); + } if (!ret) { bool align = false; diff --git a/drivers/video/video_link.c b/drivers/video/video_link.c new file mode 100644 index 0000000000..52d37e8230 --- /dev/null +++ b/drivers/video/video_link.c @@ -0,0 +1,533 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2020 NXP + * + */ + +#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 = 0; +ulong curr_video_link = 0; +bool video_off = false; + +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_get_endpoint_count(ofnode node) +{ + ofnode endpoint; + int num = 0; + + for_each_endpoint_of_node(node, endpoint) + num++; + + return num; +} + +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; +} + +ofnode ofnode_graph_get_endpoint_by_regs( + const ofnode parent, int port_reg, int reg) +{ + struct of_endpoint endpoint; + ofnode node; + + for_each_endpoint_of_node(parent, node) { + ofnode_graph_parse_endpoint(node, &endpoint); + if (((port_reg == -1) || (endpoint.port == port_reg)) && + ((reg == -1) || (endpoint.id == reg))) { + debug("get node %s\n", ofnode_get_name(node)); + + return node; + } + } + + return ofnode_null(); +} + +ofnode ofnode_graph_get_remote_endpoint(ofnode node) +{ + ofnode remote; + u32 phandle; + int ret; + + ret = ofnode_read_u32(node, "remote-endpoint", &phandle); + if (ret) { + printf("required remote-endpoint property isn't provided\n"); + return ofnode_null(); + } + + remote = ofnode_get_by_phandle(phandle); + if (!ofnode_valid(remote)) { + printf("failed to find remote-endpoint\n"); + return ofnode_null(); + } + + return remote; +} + +ofnode ofnode_graph_get_port_parent(ofnode node) +{ + unsigned int depth; + + if (!ofnode_valid(node)) + return ofnode_null(); + + /* + * Preserve usecount for passed in node as of_get_next_parent() + * will do of_node_put() on it. + */ + + /* Walk 3 levels up only if there is 'ports' node. */ + for (depth = 3; depth && ofnode_valid(node); depth--) { + node = ofnode_get_parent(node); + const char *name = ofnode_get_name(node); + if (depth == 2 && strcmp(name, "ports")) + break; + } + return node; +} + +ofnode ofnode_graph_get_remote_port_parent(ofnode node) +{ + ofnode np, pp; + + /* Get remote endpoint node. */ + np = ofnode_graph_get_remote_endpoint(node); + + pp = ofnode_graph_get_port_parent(np); + + return pp; +} + +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; + + ret = uclass_find_device_by_ofnode(UCLASS_DSI_HOST, node, pdev); + if (!ret) + return 0; + + ret = uclass_find_device_by_ofnode(UCLASS_VIDEO_BRIDGE, 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]; + } else { + 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; +} + +#ifdef CONFIG_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 0000000000..5350bfa9e9 --- /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