Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp766211ybz; Fri, 24 Apr 2020 08:56:52 -0700 (PDT) X-Google-Smtp-Source: APiQypL3hSOQQs39WPzydiPkTDbl0JcJJ0LUQd4ZQYPDcezgVA6pr5yJ1+/QTLh5QEhizU5BvR8E X-Received: by 2002:aa7:d455:: with SMTP id q21mr7721373edr.235.1587743812343; Fri, 24 Apr 2020 08:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587743812; cv=none; d=google.com; s=arc-20160816; b=mKwhL7zYJ0K5r0jm/LXsrZM873tgHuwAhJJwyqkDJvPQ3PD2rTiGyUwpPrglJkvCWl kZAeMmohVNu9XgQ6oV5Z2SBx+atg3/F5JAeMXZXMCYhrrW8LX5lmJLdK9Xuc24ec7Zio ghvme1ZaoSSJRZ90YnkK9yLC7mc9vfoMmD33JkuZdvmDVoAnWZz/Lwrk9b2S5qaM7MNs fyPgo7rYbNZ1Ifjw02UGL4vge+ThQDnoaro503Nv+WmU5WOlNJgU5HA5ZaA9H6dDabq+ ryRsU3k4bWDjyf5RFjmuxpTe532XDrbzqZ9bfUa5NPeLbHw6UExt5Z/lE3saXbnw8J1h WDCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/iFrHWjpEQFllhiousMPvh6YDgZDuc/kiivc+CfG0N0=; b=rLl1USQJqPls6R4DBQxAuvY0aSJlzQgwYVyE3JrA9vBCWzsT++K49hAiTlpoV/F5Y2 nE0Qg6HDr/EcGjnex5ykRN4fFyEETnpsSs4+JUlqKWmA3un/GV2UaRY38Azy5fe4Arcd VYdh95FbdE/us6KHUO5rN07LB1qNsr1wYBe8/jqFiWp4fvdBzVF5ePLk1JU3Y6kS4eis GPanuK3XPTARCfUbB9PAY3SJ+DE8XyvXYreANhCz3hJzMejOJi9zaXHIvhWHtlACT+xP NltAy5bFowOoM9vdeGmKb75nl/ZcjpXO8IGnEqCG1BLltxAct4WntdgBbk8SBnkqDUYA nQlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k2Jv5JZj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rl27si3330992ejb.17.2020.04.24.08.56.28; Fri, 24 Apr 2020 08:56:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k2Jv5JZj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728594AbgDXPyT (ORCPT + 99 others); Fri, 24 Apr 2020 11:54:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727089AbgDXPyM (ORCPT ); Fri, 24 Apr 2020 11:54:12 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA1F9C09B047 for ; Fri, 24 Apr 2020 08:54:11 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id y24so11393196wma.4 for ; Fri, 24 Apr 2020 08:54:11 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=/iFrHWjpEQFllhiousMPvh6YDgZDuc/kiivc+CfG0N0=; b=k2Jv5JZjKSfYr+XoQhrnCnBUBxfvlT9jRIOks01E1OALGMCFTUVTfzLu8e25uINL+s HcuzdygMlZpzicpal5ELlxboPiw6SJDZlwVP9ynqj76BcTroj8sTwPc7RkzjgZRfdnYa PK1eCAgOLeU7H/OKhtBbFq+5TGk7PPGgIIgWQ8+BLGvimEojnDyzt/nw5XoKifw8WAFZ RB/JqwfkewoWiG9Qpg3j24hjUy2RPJvrp/DuKTQi+zb6EvPQv5G7h4ZlF2xiA6AgUda8 q1/ikJF7Xi1qpfLSR+GHuRZof2PVBg0YcJhMx6GJafk9kkt7n/j9poGgMvTury7LAyYk yLPg== 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:mime-version:content-transfer-encoding; bh=/iFrHWjpEQFllhiousMPvh6YDgZDuc/kiivc+CfG0N0=; b=G0Y1Ht9D0Cly+1RhhRm9p8t2Mu6UwSXF++3QKkiD3DynHvmZsGhyuurq8bYHWexbPx V8BvVjt31R8SOVZLEw26xbef1SmaSm0q+e+tQvGHOkUNOuPYlFB3ajnbZT56/gOz3QQ7 s+gDwykQ+i9ETNyhukGZpR9M14ohDYQWRffXk1pKsg6yGWUReWC3YLCjMcPBN6nGrXKI NKTGhCwHE+Ih1Jo8j97zIEI53Zw1v3Kt4biTTHlp4wzBrhw5Fip4iJR9WBPSN5egOOD0 1kr6nuqHeFvxtNjl/ut/jJBBVacaQlnYFf2avpTkKP2dHfni4OdTnItjbYAflZCEuW6T uZdA== X-Gm-Message-State: AGi0PuZt6+mtgwDSf1xakGLBjfNOZ5kK9i3b4S+bL/JC9ICzab21JOnV F5k5OV81Pc5jSW+wRFUfUCI7Fw== X-Received: by 2002:a1c:9a16:: with SMTP id c22mr10439609wme.38.1587743650649; Fri, 24 Apr 2020 08:54:10 -0700 (PDT) Received: from localhost.localdomain ([87.120.218.65]) by smtp.googlemail.com with ESMTPSA id z76sm3923583wmc.9.2020.04.24.08.54.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2020 08:54:10 -0700 (PDT) From: Georgi Djakov To: vireshk@kernel.org, nm@ti.com, sboyd@kernel.org, robh+dt@kernel.org, rjw@rjwysocki.net, saravanak@google.com, sibis@codeaurora.org Cc: rnayak@codeaurora.org, bjorn.andersson@linaro.org, vincent.guittot@linaro.org, jcrouse@codeaurora.org, evgreen@chromium.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, georgi.djakov@linaro.org Subject: [PATCH v7 3/7] interconnect: Add of_icc_get_by_index() helper function Date: Fri, 24 Apr 2020 18:54:00 +0300 Message-Id: <20200424155404.10746-4-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200424155404.10746-1-georgi.djakov@linaro.org> References: <20200424155404.10746-1-georgi.djakov@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is the same as the traditional of_icc_get() function, but the difference is that it takes index as an argument, instead of name. Signed-off-by: Georgi Djakov --- v7: * Addressed review comments from Sibi. * Re-based patch. v2: https://lore.kernel.org/r/20190423132823.7915-3-georgi.djakov@linaro.org drivers/interconnect/core.c | 68 +++++++++++++++++++++++++++--------- include/linux/interconnect.h | 6 ++++ 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c index 2c6515e3ecf1..648237f4de49 100644 --- a/drivers/interconnect/core.c +++ b/drivers/interconnect/core.c @@ -351,9 +351,9 @@ static struct icc_node *of_icc_get_from_provider(struct of_phandle_args *spec) } /** - * of_icc_get() - get a path handle from a DT node based on name + * of_icc_get_by_index() - get a path handle from a DT node based on index * @dev: device pointer for the consumer device - * @name: interconnect path name + * @idx: interconnect path index * * This function will search for a path between two endpoints and return an * icc_path handle on success. Use icc_put() to release constraints when they @@ -365,13 +365,12 @@ static struct icc_node *of_icc_get_from_provider(struct of_phandle_args *spec) * Return: icc_path pointer on success or ERR_PTR() on error. NULL is returned * when the API is disabled or the "interconnects" DT property is missing. */ -struct icc_path *of_icc_get(struct device *dev, const char *name) +struct icc_path *of_icc_get_by_index(struct device *dev, int idx) { struct icc_path *path = ERR_PTR(-EPROBE_DEFER); struct icc_node *src_node, *dst_node; struct device_node *np = NULL; struct of_phandle_args src_args, dst_args; - int idx = 0; int ret; if (!dev || !dev->of_node) @@ -391,12 +390,6 @@ struct icc_path *of_icc_get(struct device *dev, const char *name) * lets support only global ids and extend this in the future if needed * without breaking DT compatibility. */ - if (name) { - idx = of_property_match_string(np, "interconnect-names", name); - if (idx < 0) - return ERR_PTR(idx); - } - ret = of_parse_phandle_with_args(np, "interconnects", "#interconnect-cells", idx * 2, &src_args); @@ -439,12 +432,8 @@ struct icc_path *of_icc_get(struct device *dev, const char *name) return path; } - if (name) - path->name = kstrdup_const(name, GFP_KERNEL); - else - path->name = kasprintf(GFP_KERNEL, "%s-%s", - src_node->name, dst_node->name); - + path->name = kasprintf(GFP_KERNEL, "%s-%s", + src_node->name, dst_node->name); if (!path->name) { kfree(path); return ERR_PTR(-ENOMEM); @@ -452,6 +441,53 @@ struct icc_path *of_icc_get(struct device *dev, const char *name) return path; } +EXPORT_SYMBOL_GPL(of_icc_get_by_index); + +/** + * of_icc_get() - get a path handle from a DT node based on name + * @dev: device pointer for the consumer device + * @name: interconnect path name + * + * This function will search for a path between two endpoints and return an + * icc_path handle on success. Use icc_put() to release constraints when they + * are not needed anymore. + * If the interconnect API is disabled, NULL is returned and the consumer + * drivers will still build. Drivers are free to handle this specifically, + * but they don't have to. + * + * Return: icc_path pointer on success or ERR_PTR() on error. NULL is returned + * when the API is disabled or the "interconnects" DT property is missing. + */ +struct icc_path *of_icc_get(struct device *dev, const char *name) +{ + struct device_node *np = NULL; + int idx = 0; + + if (!dev || !dev->of_node) + return ERR_PTR(-ENODEV); + + np = dev->of_node; + + /* + * When the consumer DT node do not have "interconnects" property + * return a NULL path to skip setting constraints. + */ + if (!of_find_property(np, "interconnects", NULL)) + return NULL; + + /* + * We use a combination of phandle and specifier for endpoint. For now + * lets support only global ids and extend this in the future if needed + * without breaking DT compatibility. + */ + if (name) { + idx = of_property_match_string(np, "interconnect-names", name); + if (idx < 0) + return ERR_PTR(idx); + } + + return of_icc_get_by_index(dev, idx); +} EXPORT_SYMBOL_GPL(of_icc_get); /** diff --git a/include/linux/interconnect.h b/include/linux/interconnect.h index d70a914cba11..34e97231a6ab 100644 --- a/include/linux/interconnect.h +++ b/include/linux/interconnect.h @@ -28,6 +28,7 @@ struct device; struct icc_path *icc_get(struct device *dev, const int src_id, const int dst_id); struct icc_path *of_icc_get(struct device *dev, const char *name); +struct icc_path *of_icc_get_by_index(struct device *dev, int idx); void icc_put(struct icc_path *path); int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw); void icc_set_tag(struct icc_path *path, u32 tag); @@ -46,6 +47,11 @@ static inline struct icc_path *of_icc_get(struct device *dev, return NULL; } +static inline struct icc_path *of_icc_get_by_index(struct device *dev, int idx) +{ + return NULL; +} + static inline void icc_put(struct icc_path *path) { }