From patchwork Mon Aug 20 09:09:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Wiklander X-Patchwork-Id: 144551 Delivered-To: patches@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp3721998ljj; Mon, 20 Aug 2018 02:10:12 -0700 (PDT) X-Received: by 2002:a2e:2e02:: with SMTP id u2-v6mr32082498lju.77.1534756212043; Mon, 20 Aug 2018 02:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534756212; cv=none; d=google.com; s=arc-20160816; b=AUfEM/BKLRYXSLdZVdZqq8Pcsp8Y79FXc6Bz7iDxS2Oe09iRniDjNtdadkEWuQSXYz JBB1ewnjrD7hwKReAsPlwEUpoV5xTt6ReSOC4+Jb5JnnjxLU6ALccFCcnZyNVp0/azWp piNacLqnNApW9uZaJStEtfHxaAAcPXOuLceog2M9gxgb9B2vJkdNh/iuQzPeI+EcdwRB 2Rao/XDsVhYKAkcL3wfOxNESyAqS3IN/s8s8VrApxlq28DadlnEkNL0rUnWEvmuSht56 x7Vj54+CzTd1mPtrk8eU1dI0afeD8ZyBnc4wym5mq2CeTCQKj6p5yC8g0YiafKhcbtNb ifjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=WB0r/QnU5Maqf0pqVTMNOqHxmR20pieSek+3MYJad+w=; b=kgvGHeM7aIYlt/na3zqdQNSNGpxI2GxcLjej2xIi5KUQWveGrgwXzLapfXJIIO+Lin C2OWuUDdhqt7XS60iYS0BqflqwdCZskCtLv+0gNFVMq54BCxxzpv5C+GRChW4Wqbmb6Z kynJ/wy+SPCZJ+arrrDFrUSRSyYy4kZjcskAUX4ZVwyc0Jo48KWvWvfEeEIkcO/uaYe+ 3OiHbIoQ+srOOsCrZ9jIVWIySxVvTwbSaqVj5YuIfVDMKVrrb0Wxnzeh28Qe2dyeNjQB IUM0ob5moND5dupcggeZjXax9lY4Pt7Qk5ypAg0SKRnKRbQVU23prxGG1+yHdI170VQa 4mEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dBSvcoPI; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g80-v6sor1602558ljf.80.2018.08.20.02.10.11 for (Google Transport Security); Mon, 20 Aug 2018 02:10:12 -0700 (PDT) Received-SPF: pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dBSvcoPI; spf=pass (google.com: domain of jens.wiklander@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=jens.wiklander@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=WB0r/QnU5Maqf0pqVTMNOqHxmR20pieSek+3MYJad+w=; b=dBSvcoPIiAVEo9Rdpn7YuwABz9p1qZI8aNwj4pMyXKOPTlMzsguOtMkRroqaV+gFni SA4nH4ahFNqtvnOTNmq6NsnB3uBe5sRLudClAwr1HN0J+m5bO8ZGkuLIwGemNPA72pLA 7jSDangUWKE23dp435btpHvKiDy7GeVG0qT5E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=WB0r/QnU5Maqf0pqVTMNOqHxmR20pieSek+3MYJad+w=; b=Xvh10kvao0nHW4Bt6vrNhh+7cwWUUMjMSI/tTIr3EXT0x9Hkbr81WON6P7Bp1VK3p1 QS6NJsbU74/IomoVUmdvxEbNS4AraFFd+s5uKUzjLMeNSlsai/IaM5qdM6X8B4sPAenh 4P1glaFCh7l7rIntm3dCD74GhBFQgo2URKV8dmuxRHqwke3j0cO8o8zp+vwzyR9IStyL dq0kvIZgixyd9a3GnjdVhx/4aJoK4lfAgJItiodhRWCHAZuMKPXR2BikTFboCOD9X9Pt 0/BDe2gnDE1nUfKRbttzkvZxkzJe62rMzKDofZyfcJsmd3EP2HmBniNTVSWMr+ORvwyA xtkA== X-Gm-Message-State: AOUpUlGDSjegVb0/n8i5yPHDGZBMpaZmx1FrSwwwi79L7ZT3lxYeWz+y TSSqgJOmH4EKIGkdl7fidsOK2IdG X-Google-Smtp-Source: AA+uWPzpqI6ci7GJQ06tWm1SrhuVaIraoHat2Aavupj0xC3faosgeE4QZdQoZlu74OEePs4qN1zMiw== X-Received: by 2002:a2e:590e:: with SMTP id n14-v6mr29878018ljb.128.1534756211657; Mon, 20 Aug 2018 02:10:11 -0700 (PDT) Return-Path: Received: from jax.urgonet (h-84-105.A175.priv.bahnhof.se. [79.136.84.105]) by smtp.gmail.com with ESMTPSA id i2-v6sm1041025lfa.78.2018.08.20.02.10.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Aug 2018 02:10:10 -0700 (PDT) From: Jens Wiklander To: u-boot@lists.denx.de Cc: Simon Glass , Jens Wiklander Subject: [PATCH v2 1/3] ofnode: add ofnode_by_prop_value() Date: Mon, 20 Aug 2018 11:09:58 +0200 Message-Id: <20180820091000.3241-2-jens.wiklander@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180820091000.3241-1-jens.wiklander@linaro.org> References: <20180820091000.3241-1-jens.wiklander@linaro.org> Adds ofnode_by_prop_value() to search for nodes with a given property and value, an ofnode version of fdt_node_offset_by_prop_value(). Signed-off-by: Jens Wiklander --- drivers/core/of_access.c | 27 +++++++++++++++++++++++++++ drivers/core/ofnode.c | 14 ++++++++++++++ include/dm/of_access.h | 16 ++++++++++++++++ include/dm/ofnode.h | 14 ++++++++++++++ 4 files changed, 71 insertions(+) -- 2.17.1 Reviewed-by: Simon Glass diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 0729dfcdb3b8..14c020a687b7 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -376,6 +376,33 @@ struct device_node *of_find_compatible_node(struct device_node *from, return np; } +static int of_device_has_prop_value(const struct device_node *device, + const char *propname, const void *propval, + int proplen) +{ + struct property *prop = of_find_property(device, propname, NULL); + + if (!prop || !prop->value || prop->length != proplen) + return 0; + return !memcmp(prop->value, propval, proplen); +} + +struct device_node *of_find_node_by_prop_value(struct device_node *from, + const char *propname, + const void *propval, int proplen) +{ + struct device_node *np; + + for_each_of_allnodes_from(from, np) { + if (of_device_has_prop_value(np, propname, propval, proplen) && + of_node_get(np)) + break; + } + of_node_put(from); + + return np; +} + struct device_node *of_find_node_by_phandle(phandle handle) { struct device_node *np; diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 0cfb0fbabb00..a7e192772324 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -777,3 +777,17 @@ ofnode ofnode_by_compatible(ofnode from, const char *compat) gd->fdt_blob, ofnode_to_offset(from), compat)); } } + +ofnode ofnode_by_prop_value(ofnode from, const char *propname, + const void *propval, int proplen) +{ + if (of_live_active()) { + return np_to_ofnode(of_find_node_by_prop_value( + (struct device_node *)ofnode_to_np(from), propname, + propval, proplen)); + } else { + return offset_to_ofnode(fdt_node_offset_by_prop_value( + gd->fdt_blob, ofnode_to_offset(from), + propname, propval, proplen)); + } +} diff --git a/include/dm/of_access.h b/include/dm/of_access.h index dd1abb8e97b4..5ed1a0cdb427 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -193,6 +193,22 @@ static inline struct device_node *of_find_node_by_path(const char *path) struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compatible); +/** + * of_find_node_by_prop_value() - find a node with a given property value + * + * Find a node based on a property value. + * @from: Node to start searching from or NULL. the node you pass will not be + * searched, only the next one will; typically, you pass what the previous + * call returned. + * @propname: property name to check + * @propval: property value to search for + * @proplen: length of the value in propval + * @return node pointer or NULL if not found + */ +struct device_node *of_find_node_by_prop_value(struct device_node *from, + const char *propname, + const void *propval, + int proplen); /** * of_find_node_by_phandle() - Find a node given a phandle * diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ab36b74c4ca4..c06d77849c73 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -702,6 +702,20 @@ int ofnode_read_resource_byname(ofnode node, const char *name, */ ofnode ofnode_by_compatible(ofnode from, const char *compat); +/** + * ofnode_by_prop_value() - Find the next node with given property value + * + * Find the next node after @from that has a @propname with a value + * @propval and a length @proplen. + * + * @from: ofnode to start from (use ofnode_null() to start at the + * beginning) @propname: property name to check @propval: property value to + * search for @proplen: length of the value in propval @return ofnode + * found, or ofnode_null() if none + */ +ofnode ofnode_by_prop_value(ofnode from, const char *propname, + const void *propval, int proplen); + /** * ofnode_for_each_subnode() - iterate over all subnodes of a parent *