From patchwork Wed Oct 14 13:55:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1382148 X-Patchwork-Delegate: monstr@monstr.eu Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=J4SW5Pos; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CBDV175STz9sS8 for ; Thu, 15 Oct 2020 00:56:25 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 45405823DE; Wed, 14 Oct 2020 15:56:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="J4SW5Pos"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E73E882367; Wed, 14 Oct 2020 15:55:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x541.google.com (mail-ed1-x541.google.com [IPv6:2a00:1450:4864:20::541]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E41BE82367 for ; Wed, 14 Oct 2020 15:55:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: phobos.denx.de; spf=none smtp.mailfrom=monstr@monstr.eu Received: by mail-ed1-x541.google.com with SMTP id v19so3214180edx.9 for ; Wed, 14 Oct 2020 06:55:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ihTkxl6wpQ1vFKQcmxCmBg8llVvIhUQTfCL7bP5Fo6o=; b=J4SW5PosVWU/pVaKJ0RgR5VGG3Dk7KzoQuiwnTg1AhrHiNviFVNLFkE5Gh6fG58W+i ppHx5LVEtwNfhUNLwmCQkQc8QdQ7SkO4Om+i6UgxQSBY9fAOxtp7jBFkSK0G3TlOwPKl 7T+eTyAxaJd38TRLGbnhSeB7NQQBMVyjfKBG7KXwW/H+JrDpzJBqM6sX595FO71Bps8L At6U3uSjI3X6lRTIW2DR9egMiGxLc6E7mLBqtzSBkTDEmFiKqIPVttNr8rtORpFzWTOL GTlw6hpHfOpK6nJEj5HrH6WcstSQ5gvho/3NRKH/TUyE8xWA3/Of/neL04dq/blUFu4u BJ6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=ihTkxl6wpQ1vFKQcmxCmBg8llVvIhUQTfCL7bP5Fo6o=; b=EuJFG2+Fb5v+UQxw6w39Kur7+t7qAErS3mAOycTbi/ZSKtZcZBtsC34CN7i4x75rug e8hJODJ3u+9dhFeK+DHZNKrVjupe7O7ezvMJ0hGEQ5nfEP8YzFyxy3oDmxem50bxgFIG ZEh9ZwOOvlFTGNb7zXgxyWgycEz70ywX/S8j4TVfZcAntb3V6ARD845EP+dtXU40J1jv 9IP8F63XZ6+Knz/+t4kxQ2vIX+NlWi+xuMEHHd8l1PPzkZ7ydKbc5cowC3Nb6QcwWTAM 795Qj7/KvVHS8McFn7Wgd9pOj87Qx1yarZduXwnS4esCzAg3YiVSk/UGL8rUdAYv6+JJ Fhew== X-Gm-Message-State: AOAM530oTwhizukQiMm9ra+rkTDjniJeoeS+/I8Oy9B9iEIOKl0lK2U+ WkM8ol+ZN3yONQDYNlUf/flr6yw4Tuk2sA== X-Google-Smtp-Source: ABdhPJz8d+DvquNR9j/rqKNlePQoEzDichK0WxDEQ3vfuI1GMvDP4xnQ6Fc/qIymT809nDrrziiDXA== X-Received: by 2002:a50:cc0c:: with SMTP id m12mr5191214edi.292.1602683756333; Wed, 14 Oct 2020 06:55:56 -0700 (PDT) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id f20sm1738917ejc.90.2020.10.14.06.55.55 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 14 Oct 2020 06:55:55 -0700 (PDT) From: Michal Simek To: u-boot@lists.denx.de, git@xilinx.com Cc: Simon Glass Subject: [PATCH 1/3] dm: core: Add support for getting node from aliases Date: Wed, 14 Oct 2020 15:55:48 +0200 Message-Id: <6d2d5a6486d423df01fe5ddc6628a043b0d7539b.1602683746.git.michal.simek@xilinx.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Add support for getting a node/property from aliases. The similar functionality is provided for chosen node and this implemenatation is copy of it. Signed-off-by: Michal Simek Reviewed-by: Simon Glass --- drivers/core/ofnode.c | 22 ++++++++++++++++++++++ include/dm/ofnode.h | 22 ++++++++++++++++++++++ test/dm/ofnode.c | 22 ++++++++++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 7d1b89514c7d..a68076bf3517 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -476,6 +476,28 @@ ofnode ofnode_get_chosen_node(const char *name) return ofnode_path(prop); } +const void *ofnode_read_aliases_prop(const char *propname, int *sizep) +{ + ofnode node; + + node = ofnode_path("/aliases"); + + return ofnode_read_prop(node, propname, sizep); +} + +ofnode ofnode_get_aliases_node(const char *name) +{ + const char *prop; + + prop = ofnode_read_aliases_prop(name, NULL); + if (!prop) + return ofnode_null(); + + debug("%s: node_path: %s\n", __func__, prop); + + return ofnode_path(prop); +} + int ofnode_get_child_count(ofnode parent) { ofnode child; diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 4b7af3705601..ced7f6ffb250 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -605,6 +605,28 @@ const char *ofnode_read_chosen_string(const char *propname); */ ofnode ofnode_get_chosen_node(const char *propname); +/** + * ofnode_read_aliases_prop() - get the value of a aliases property + * + * This looks for a property within the /aliases node and returns its value + * + * @propname: Property name to look for + * @sizep: Returns size of property, or FDT_ERR_... error code if function + * returns NULL + * @return property value if found, else NULL + */ +const void *ofnode_read_aliases_prop(const char *propname, int *sizep); + +/** + * ofnode_get_aliases_node() - get a referenced node from the aliases node + * + * This looks up a named property in the aliases node and uses that as a path to + * look up a code. + * + * @return the referenced node if present, else ofnode_null() + */ +ofnode ofnode_get_aliases_node(const char *propname); + struct display_timing; /** * ofnode_decode_display_timing() - decode display timings diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 01ac3c2094c8..fb1ceb131805 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -207,6 +207,28 @@ static int dm_test_ofnode_read_chosen(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_read_chosen, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); +static int dm_test_ofnode_read_aliases(struct unit_test_state *uts) +{ + const void *val; + ofnode node; + int size; + + node = ofnode_get_aliases_node("eth3"); + ut_assert(ofnode_valid(node)); + ut_asserteq_str("sbe5", ofnode_get_name(node)); + + node = ofnode_get_aliases_node("unknown"); + ut_assert(!ofnode_valid(node)); + + val = ofnode_read_aliases_prop("spi0", &size); + ut_assertnonnull(val); + ut_asserteq(7, size); + ut_asserteq_str("/spi@0", (const char *)val); + + return 0; +} +DM_TEST(dm_test_ofnode_read_aliases, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + static int dm_test_ofnode_get_child_count(struct unit_test_state *uts) { ofnode node, child_node;