From patchwork Tue Apr 23 13:28:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Djakov X-Patchwork-Id: 162696 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3790142jan; Tue, 23 Apr 2019 06:28:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwWxmlVmN3wmKlgnq28R9sC4AWt95ZRimB0vp6JZZ+JINXh+nHPH/CW23i8pT2pgMqAl/j5 X-Received: by 2002:a17:902:8c8b:: with SMTP id t11mr26532562plo.15.1556026116025; Tue, 23 Apr 2019 06:28:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556026116; cv=none; d=google.com; s=arc-20160816; b=lRhx6K+k0BUJHpE19+IyrPARa4P371z2BMribDCW1Mnm1pekuKG/IjfjMy0QHLRdUD VyrzffBGIAzByipWM0ooqvjdtawZF4aygeYQcSBFqe0x1F5Dkk279tZ/Z09yiwkIWShb 3niMnCzqMpgjcOHLQHiBCO+XLKdDmQXDvYvJv9PfGjZh01QimO0gBnD4LEOlg0C6BYRv Hro+958Bp6nP83Lqfw6y4fGAq4c1SAxHfkzkCk44kQU7nTwcMcFyJmaWrQFslfCFy0eO t6Q7akgDO5hfX5mTF94jPOVnwYvboYE8F3O5745VZqlhMlDYpIxQ6KGlkM7L5tODG6f6 y8dQ== 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=TmzrLG0HhMUllGPErHueXstJu/wyUlmgrIkCuicVsiY=; b=v7dHP+EPwFe9U9jwOwfPSsOpd8CAr9MRzyDO+RkTEPEYZmYcH7fTcRI+A3POQdQ2t1 F0Vehyu00OClE8fIPPaSSQkCT43rk/ZM5pcII2TCGlr5tRlNaFt4zMrcF44fuyuzkkK+ oV2G6fu0W1QS9cFuODx6THGBpW8RYLBjxsrJV+9aKL86jpC7FEwqKkUa65PS/JhqgTuS Ey913Cf8vDv3DeVI+ZxPzczbV4/HoLVJPsL7akdj6SyOIBkMpK5OUJy/L2WpBoNxbV+b VQQV4Az0hBY2k4ajEocuu1UX0VmypEP+pCEzquVHcX2KOO2Ju/33rwu/0QY29JJLzJh0 PjoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pjyiAvWp; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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. [209.132.180.67]) by mx.google.com with ESMTP id b98si13403900plb.375.2019.04.23.06.28.35; Tue, 23 Apr 2019 06:28:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pjyiAvWp; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1727955AbfDWN2f (ORCPT + 7 others); Tue, 23 Apr 2019 09:28:35 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:41123 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727922AbfDWN2d (ORCPT ); Tue, 23 Apr 2019 09:28:33 -0400 Received: by mail-lj1-f196.google.com with SMTP id k8so979091lja.8 for ; Tue, 23 Apr 2019 06:28:31 -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=TmzrLG0HhMUllGPErHueXstJu/wyUlmgrIkCuicVsiY=; b=pjyiAvWpRnfInL1U8vVm5G28PPwIa7vHVRINhbLFwD7Hh8RLqG1XBvcg6uhiz5Q7I/ oDN/v1CW3tmWtHRBfdLsTUhN3j1Ez8EdsbehRXTSLKgBkdXvWs6FxQ/neadA2MdMxyCv /T86u/ZwKidHvmiwKNAiXKqlT6ADVxSxocN6dT4P477jUUBupKtT35G3+nr8vkHzgvWd +6GveAO2cO7rhe58ZHp0+Kgisl4ilC3MIdSjLoHz7+E1PvM3J4aYUIFnfv5nb5ygA7N5 5dlcgCZuU9fe0qw3ewVCgh0ZKTnuzxJOcl7hkfXbZa6WVywG4g0j32gsnzFs0ERahaVm My7g== 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=TmzrLG0HhMUllGPErHueXstJu/wyUlmgrIkCuicVsiY=; b=WKAX9uLLRLaAQc0eYxqbaXjeM42KUAcmlojvPf6oWjw0oqc+hDtkLpO+crs6oyqL5U cg7tpViocxyCJw8K+mivHVbzeZAm24sBwzBDIl1bofY2IXq+XCtzgTEijfMbT66mPBiQ ZGbEUDGNx8iMNWHL54tqHZrfLMSsntvEB+Chk8DQ9Uws6K4uPA1QU8KGY0gYUR93F3lG +Wvi1CEOmQBVpIwYXb+x7e7KkfpT829gks0HnKggCGuNya8rLBWMcVGjOvTodrQ1Bl/R SyskxCfPktULbWn1coz6G+1O0kBUumZJMhnGVFAHtgxAGjMhjOH/u7OS0KL81qcRLETH ZY7w== X-Gm-Message-State: APjAAAWP8Z12tH5hD1ebX+MWYV2egRhKddCdVbif7JFkcAikeZRxH+Fb pZkg0Wxdoe5KD4epGY+ZKsazLQ== X-Received: by 2002:a2e:500d:: with SMTP id e13mr13748245ljb.169.1556026110607; Tue, 23 Apr 2019 06:28:30 -0700 (PDT) Received: from localhost.localdomain ([212.45.67.2]) by smtp.googlemail.com with ESMTPSA id y206sm4617107lfc.72.2019.04.23.06.28.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Apr 2019 06:28:29 -0700 (PDT) From: Georgi Djakov To: vireshk@kernel.org, sboyd@kernel.org, nm@ti.com, robh+dt@kernel.org, mark.rutland@arm.com, rjw@rjwysocki.net Cc: jcrouse@codeaurora.org, vincent.guittot@linaro.org, bjorn.andersson@linaro.org, amit.kucheria@linaro.org, seansw@qti.qualcomm.com, daidavid1@codeaurora.org, evgreen@chromium.org, sibis@codeaurora.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, georgi.djakov@linaro.org Subject: [PATCH v2 2/5] interconnect: Add of_icc_get_by_index() helper function Date: Tue, 23 Apr 2019 16:28:20 +0300 Message-Id: <20190423132823.7915-3-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190423132823.7915-1-georgi.djakov@linaro.org> References: <20190423132823.7915-1-georgi.djakov@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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 --- drivers/interconnect/core.c | 45 ++++++++++++++++++++++++++++-------- include/linux/interconnect.h | 6 +++++ 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c index 871eb4bc4efc..a7c3c262c974 100644 --- a/drivers/interconnect/core.c +++ b/drivers/interconnect/core.c @@ -295,9 +295,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 @@ -309,13 +309,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) @@ -335,12 +334,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); @@ -383,6 +376,38 @@ struct icc_path *of_icc_get(struct device *dev, const char *name) return path; } + +/** + * 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) +{ + int idx = 0; + + if (!dev || !dev->of_node) + return ERR_PTR(-ENODEV); + + if (name) { + idx = of_property_match_string(dev->of_node, + "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 dc25864755ba..0e430b3b6519 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); @@ -45,6 +46,11 @@ static inline struct icc_path *of_icc_get(struct device *dev, return NULL; } +struct icc_path *of_icc_get_by_index(struct device *dev, int idx) +{ + return NULL; +} + static inline void icc_put(struct icc_path *path) { } From patchwork Tue Apr 23 13:28:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Djakov X-Patchwork-Id: 162697 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3790183jan; Tue, 23 Apr 2019 06:28:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqy9MU/Bgl0KMKn2aBiQufrU+9IbJQFzLGwoy6O6f1Qzuyb5JE29QppaZJXp/IlEk86IROAs X-Received: by 2002:a63:3145:: with SMTP id x66mr10762428pgx.89.1556026118282; Tue, 23 Apr 2019 06:28:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556026118; cv=none; d=google.com; s=arc-20160816; b=cDPpkl4bSt6x3kO+JWiJ7r+lqbNuz7HD7VMgyyeNT77d/jd1qT/UYUq6dL1Joecqhc TWGFsPTwK//PG2yap7vBRkZe8FLF5kBZ16cww6yswzdV+p7H/3M2+5lDp8vo6UtQCRlT gEsDkK7/KMN47LqRFuDcN2qdKJjDKxsZcr9O1zfHP0QETRbn87/OEl1hN30VREjyHBRR lQK4Ll6J2XazOCqOZzAOintLZ4o4t4SI0mTSL3HYcUUD75KqaTbE2WYA6fqUG6XGCBG4 ueeNpzD9JW/sb8Ou6bNA1bKyMj/1Taoqp8qimgVjJ+uOwLjk1E5jl4cS1Oaj2WWR1PE8 UR3A== 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=QtHDB3QMogv515ITSyvJXMA+IzhZoNxGiv5NT5h1biw=; b=yVTAu3agWh1e3LotCp1Vv/GQ+t/OkgVvOkFW98LHjRQNOOUnlWVr/ADH6W4L8IVTRy 8hgkb4HotBTslyJlaj+Rax4A9dNi9eZ7xlVOuEBqUwzkBrRLWNFTWVtf25ENORSS8Uhn q0byvYgr+TpdWVIyk7jQVXeLGRv2zI0Ohtyd5Ywsh9vRnI/w6BQIe/LjDpbwJhxaXADh WLDEUU/sUrIq8vDljfzunpluSmi4C8/IWCD7Yf3a5zqG19KhadQtdpzl5og1+7Y4tc/O 0pdaPJum49vSAhI11AYqmqcF+9fcbtXWBSWZpyx6KYHgVfSXi92jIHyiUuHhFIzkquO0 rwQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pFONKqXy; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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. [209.132.180.67]) by mx.google.com with ESMTP id j9si15727083plk.125.2019.04.23.06.28.38; Tue, 23 Apr 2019 06:28:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pFONKqXy; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1727467AbfDWN2g (ORCPT + 7 others); Tue, 23 Apr 2019 09:28:36 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34399 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727952AbfDWN2f (ORCPT ); Tue, 23 Apr 2019 09:28:35 -0400 Received: by mail-lj1-f196.google.com with SMTP id y16so2704576ljg.1 for ; Tue, 23 Apr 2019 06:28:33 -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=QtHDB3QMogv515ITSyvJXMA+IzhZoNxGiv5NT5h1biw=; b=pFONKqXyBmUDG4wQo07YI3Wbdza5aMEyIASoDSFX6o8AcxMLF6619lBuscNbCsqJvB p2JTMAdUlew+S99HAcKB+uoxUm0qYmzo7ESgwwJMLJjrQ33GweVt+eNFpiURepbvGhym 9n9J7H6WkH2EJc4fjiX5IQC6wb3jOLTdCEZCCokb8qol1sQT4/x2RytS/0jzzkNSX+YL B9zXytaOQ2hMXoEeeX1OK39hUhxqBVp8ke0S6ejVkQVka9fRxpw4iYmtnGaRAP3x6Y6v k/Nd4rPgF5A3w8bWt3iRW4SnGnpcL6qpid8/Psn3Qjwd6soR+zOq1XJ3QMf9v0fQdNA4 ptuQ== 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=QtHDB3QMogv515ITSyvJXMA+IzhZoNxGiv5NT5h1biw=; b=lx41zQ2CZVl+QmJTk2nuHkQCpotG/KiM2V4yMf2vQW57RD/pXS5kha+DUJ/haZXMic 8oYcc+HFXXt7ZLFGuQVfu+dsR0gkWL1qb6yLA/lYRXvSjo/wMxrteVYhGi4RCMRExjxE rkuiL3TdGCONxqIP1wyMd3deI6r0xT28SyVGWvOUuPWf8+WOuSBhLzzlyEvJk4fWvD1O POFhmeFM5hVycLgugC4iH12LHbxn1Lpp5nMShu1Tt1Jenzi7BJFXG+/b7U96qZfkwV47 G5+DTpjXGXQLNUPfPVTMW8u29+Hc0p0oRR8rIKwdIQgOpZiXVb8ss20fT+GJwbvUz3NC addQ== X-Gm-Message-State: APjAAAXbK/2++UEzvC2Bz/LmAGKZO5vyeCUHe+XhpB/8VAHodjngyaeq XNSvU/1r9ToRsDVzWALm9spVrw== X-Received: by 2002:a2e:9ac3:: with SMTP id p3mr14664445ljj.109.1556026112981; Tue, 23 Apr 2019 06:28:32 -0700 (PDT) Received: from localhost.localdomain ([212.45.67.2]) by smtp.googlemail.com with ESMTPSA id y206sm4617107lfc.72.2019.04.23.06.28.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Apr 2019 06:28:32 -0700 (PDT) From: Georgi Djakov To: vireshk@kernel.org, sboyd@kernel.org, nm@ti.com, robh+dt@kernel.org, mark.rutland@arm.com, rjw@rjwysocki.net Cc: jcrouse@codeaurora.org, vincent.guittot@linaro.org, bjorn.andersson@linaro.org, amit.kucheria@linaro.org, seansw@qti.qualcomm.com, daidavid1@codeaurora.org, evgreen@chromium.org, sibis@codeaurora.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, georgi.djakov@linaro.org Subject: [PATCH v2 3/5] OPP: Add support for parsing the interconnect bandwidth Date: Tue, 23 Apr 2019 16:28:21 +0300 Message-Id: <20190423132823.7915-4-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190423132823.7915-1-georgi.djakov@linaro.org> References: <20190423132823.7915-1-georgi.djakov@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The OPP bindings now support bandwidth values, so add support to parse it from device tree and store it into the new dev_pm_opp_icc_bw struct, which is part of the dev_pm_opp. Also add and export the dev_pm_opp_set_paths() and dev_pm_opp_put_paths() helpers, to set (and release) an interconnect paths to a device. The bandwidth of these paths will be updated when the OPPs are switched. Signed-off-by: Georgi Djakov --- drivers/opp/core.c | 87 ++++++++++++++++++++++++++++++++++- drivers/opp/of.c | 102 +++++++++++++++++++++++++++++++++++++++++ drivers/opp/opp.h | 9 ++++ include/linux/pm_opp.h | 14 ++++++ 4 files changed, 210 insertions(+), 2 deletions(-) diff --git a/drivers/opp/core.c b/drivers/opp/core.c index 0420f7e8ad5b..97ee39ecdebd 100644 --- a/drivers/opp/core.c +++ b/drivers/opp/core.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -876,6 +877,8 @@ static struct opp_table *_allocate_opp_table(struct device *dev, int index) ret); } + _of_find_paths(opp_table, dev); + BLOCKING_INIT_NOTIFIER_HEAD(&opp_table->head); INIT_LIST_HEAD(&opp_table->opp_list); kref_init(&opp_table->kref); @@ -1129,11 +1132,12 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_remove_all_dynamic); struct dev_pm_opp *_opp_allocate(struct opp_table *table) { struct dev_pm_opp *opp; - int count, supply_size; + int count, supply_size, icc_size; /* Allocate space for at least one supply */ count = table->regulator_count > 0 ? table->regulator_count : 1; supply_size = sizeof(*opp->supplies) * count; + icc_size = sizeof(*opp->bandwidth) * table->path_count; /* allocate new OPP node and supplies structures */ opp = kzalloc(sizeof(*opp) + supply_size, GFP_KERNEL); @@ -1141,7 +1145,8 @@ struct dev_pm_opp *_opp_allocate(struct opp_table *table) return NULL; /* Put the supplies at the end of the OPP structure as an empty array */ - opp->supplies = (struct dev_pm_opp_supply *)(opp + 1); + opp->bandwidth = (struct dev_pm_opp_icc_bw *)(opp + 1); + opp->supplies = (struct dev_pm_opp_supply *)(opp + icc_size + 1); INIT_LIST_HEAD(&opp->node); return opp; @@ -1637,6 +1642,84 @@ void dev_pm_opp_put_clkname(struct opp_table *opp_table) } EXPORT_SYMBOL_GPL(dev_pm_opp_put_clkname); +/** + * dev_pm_opp_set_paths() - Set interconnect path for a device + * @dev: Device for which interconnect path is being set. + * + * This must be called before any OPPs are initialized for the device. + */ +struct opp_table *dev_pm_opp_set_paths(struct device *dev) +{ + struct opp_table *opp_table; + int ret, i; + + opp_table = dev_pm_opp_get_opp_table(dev); + if (!opp_table) + return ERR_PTR(-ENOMEM); + + /* This should be called before OPPs are initialized */ + if (WARN_ON(!list_empty(&opp_table->opp_list))) { + ret = -EBUSY; + goto err; + } + + /* Another CPU that shares the OPP table has set the path */ + if (opp_table->paths) + return opp_table; + + opp_table->paths = kmalloc_array(opp_table->path_count, + sizeof(*opp_table->paths), GFP_KERNEL); + + /* Find interconnect path(s) for the device */ + for (i = 0; i < opp_table->path_count; i++) { + opp_table->paths[i] = of_icc_get_by_index(dev, i); + if (IS_ERR(opp_table->paths[i])) { + ret = PTR_ERR(opp_table->paths[i]); + if (ret != -EPROBE_DEFER) + dev_err(dev, "%s: Couldn't find path%d: %d\n", + __func__, i, ret); + goto err; + } + } + + return opp_table; + +err: + dev_pm_opp_put_opp_table(opp_table); + + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_set_paths); + +/** + * dev_pm_opp_put_paths() - Release interconnect path resources + * @opp_table: OPP table returned from dev_pm_opp_set_paths(). + */ +void dev_pm_opp_put_paths(struct opp_table *opp_table) +{ + int i; + + if (!opp_table->paths) { + pr_err("%s: Doesn't have paths set\n", __func__); + return; + } + + /* Make sure there are no concurrent readers while updating opp_table */ + WARN_ON(!list_empty(&opp_table->opp_list)); + + for (i = opp_table->path_count - 1; i >= 0; i--) + icc_put(opp_table->paths[i]); + + _free_set_opp_data(opp_table); + + kfree(opp_table->paths); + opp_table->paths = NULL; + opp_table->path_count = 0; + + dev_pm_opp_put_opp_table(opp_table); +} +EXPORT_SYMBOL_GPL(dev_pm_opp_put_paths); + /** * dev_pm_opp_register_set_opp_helper() - Register custom set OPP helper * @dev: Device for which the helper is getting registered. diff --git a/drivers/opp/of.c b/drivers/opp/of.c index c10c782d15aa..00af23280bc6 100644 --- a/drivers/opp/of.c +++ b/drivers/opp/of.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -363,6 +364,45 @@ static int _of_opp_alloc_required_opps(struct opp_table *opp_table, return ret; } +int _of_find_paths(struct opp_table *opp_table, struct device *dev) +{ + struct device_node *np; + int ret, i, count, num_paths; + + np = of_node_get(dev->of_node); + if (np) { + count = of_count_phandle_with_args(np, "interconnects", + "#interconnect-cells"); + if (count % 2) { + dev_err(dev, "%s: Invalid interconnects values\n", + __func__); + ret = -EINVAL; + goto put_of_node; + } + + num_paths = count / 2; + opp_table->paths = kcalloc(num_paths, sizeof(*opp_table->paths), + GFP_KERNEL); + if (!opp_table->paths) { + ret = -ENOMEM; + goto put_of_node; + } + + for (i = 0; i < num_paths; i++) + opp_table->paths[i] = of_icc_get_by_index(dev, i); + + opp_table->path_count = num_paths; + of_node_put(np); + } + + return 0; + +put_of_node: + of_node_put(np); + + return ret; +} + static bool _opp_is_supported(struct device *dev, struct opp_table *opp_table, struct device_node *np) { @@ -539,6 +579,64 @@ static int opp_parse_supplies(struct dev_pm_opp *opp, struct device *dev, return ret; } +static int opp_parse_icc_bw(struct dev_pm_opp *opp, struct device *dev, + struct opp_table *opp_table) +{ + struct property *prop = NULL; + u32 *bandwidth; + char name[] = "bandwidth-MBps"; + int count, i, j, ret; + + /* Search for "bandwidth-MBps" */ + prop = of_find_property(opp->np, name, NULL); + + /* Missing property is not a problem */ + if (!prop) { + dev_dbg(dev, "%s: Missing %s property\n", __func__, name); + return 0; + } + + if (!prop->value) { + dev_dbg(dev, "%s: Missing %s value\n", __func__, name); + return -ENODATA; + } + + /* + * Bandwidth consists of average and peak values like: + * bandwidth-MBps = + */ + count = prop->length / sizeof(u32); + if (count % 2) { + dev_err(dev, "%s: Invalid %s values\n", __func__, name); + return -EINVAL; + } + + if (opp_table->path_count != count / 2) { + dev_err(dev, "%s Mismatch between values and paths (%d %d)\n", + __func__, opp_table->path_count, count / 2); + return -EINVAL; + } + + bandwidth = kmalloc_array(count, sizeof(*bandwidth), GFP_KERNEL); + if (!bandwidth) + return -ENOMEM; + + ret = of_property_read_u32_array(opp->np, name, bandwidth, count); + if (ret) { + dev_err(dev, "%s: Error parsing %s: %d\n", __func__, name, ret); + goto free_bandwidth; + } + for (i = 0, j = 0; i < count; i++) { + opp->bandwidth[i].avg = MBps_to_icc(bandwidth[j++]); + opp->bandwidth[i].peak = MBps_to_icc(bandwidth[j++]); + } + +free_bandwidth: + kfree(bandwidth); + + return ret; +} + /** * dev_pm_opp_of_remove_table() - Free OPP table entries created from static DT * entries @@ -635,6 +733,10 @@ static struct dev_pm_opp *_opp_add_static_v2(struct opp_table *opp_table, if (opp_table->is_genpd) new_opp->pstate = pm_genpd_opp_to_performance_state(dev, new_opp); + ret = opp_parse_icc_bw(new_opp, dev, opp_table); + if (ret) + goto free_opp; + ret = _opp_add(dev, new_opp, opp_table, rate_not_available); if (ret) { /* Don't return error for duplicate OPPs */ diff --git a/drivers/opp/opp.h b/drivers/opp/opp.h index 569b3525aa67..70a537f2dbd3 100644 --- a/drivers/opp/opp.h +++ b/drivers/opp/opp.h @@ -24,6 +24,7 @@ struct clk; struct regulator; +struct icc_path; /* Lock to allow exclusive modification to the device and opp lists */ extern struct mutex opp_table_lock; @@ -62,6 +63,7 @@ extern struct list_head opp_tables; * @rate: Frequency in hertz * @level: Performance level * @supplies: Power supplies voltage/current values + * @bandwidth: Interconnect bandwidth values * @clock_latency_ns: Latency (in nanoseconds) of switching to this OPP's * frequency from any other OPP's frequency. * @required_opps: List of OPPs that are required by this OPP. @@ -84,6 +86,7 @@ struct dev_pm_opp { unsigned int level; struct dev_pm_opp_supply *supplies; + struct dev_pm_opp_icc_bw *bandwidth; unsigned long clock_latency_ns; @@ -150,6 +153,8 @@ enum opp_table_access { * @regulator_count: Number of power supply regulators. Its value can be -1 * (uninitialized), 0 (no opp-microvolt property) or > 0 (has opp-microvolt * property). + * @paths: Interconnect path handles + * @path_count: Number of interconnect paths * @genpd_performance_state: Device's power domain support performance state. * @is_genpd: Marks if the OPP table belongs to a genpd. * @set_opp: Platform specific set_opp callback @@ -194,6 +199,8 @@ struct opp_table { struct clk *clk; struct regulator **regulators; int regulator_count; + struct icc_path **paths; + unsigned int path_count; bool genpd_performance_state; bool is_genpd; @@ -228,12 +235,14 @@ void _of_clear_opp_table(struct opp_table *opp_table); struct opp_table *_managed_opp(struct device *dev, int index); void _of_opp_free_required_opps(struct opp_table *opp_table, struct dev_pm_opp *opp); +int _of_find_paths(struct opp_table *opp_table, struct device *dev); #else static inline void _of_init_opp_table(struct opp_table *opp_table, struct device *dev, int index) {} static inline void _of_clear_opp_table(struct opp_table *opp_table) {} static inline struct opp_table *_managed_opp(struct device *dev, int index) { return NULL; } static inline void _of_opp_free_required_opps(struct opp_table *opp_table, struct dev_pm_opp *opp) {} +static inline int _of_find_paths(struct opp_table *opp_table, struct device *dev) { return 0; } #endif #ifdef CONFIG_DEBUG_FS diff --git a/include/linux/pm_opp.h b/include/linux/pm_opp.h index 24c757a32a7b..dabee09a92b8 100644 --- a/include/linux/pm_opp.h +++ b/include/linux/pm_opp.h @@ -43,6 +43,18 @@ struct dev_pm_opp_supply { unsigned long u_amp; }; +/** + * struct dev_pm_opp_icc_bw - Interconnect bandwidth values + * @avg: Average bandwidth corresponding to this OPP (in icc units) + * @peak: Peak bandwidth corresponding to this OPP (in icc units) + * + * This structure stores the bandwidth values for a single interconnect path. + */ +struct dev_pm_opp_icc_bw { + u32 avg; + u32 peak; +}; + /** * struct dev_pm_opp_info - OPP freq/voltage/current values * @rate: Target clk rate in hz @@ -127,6 +139,8 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * con void dev_pm_opp_put_regulators(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char * name); void dev_pm_opp_put_clkname(struct opp_table *opp_table); +struct opp_table *dev_pm_opp_set_paths(struct device *dev); +void dev_pm_opp_put_paths(struct opp_table *opp_table); struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev, int (*set_opp)(struct dev_pm_set_opp_data *data)); void dev_pm_opp_unregister_set_opp_helper(struct opp_table *opp_table); struct opp_table *dev_pm_opp_set_genpd_virt_dev(struct device *dev, struct device *virt_dev, int index); From patchwork Tue Apr 23 13:28:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Djakov X-Patchwork-Id: 162699 Delivered-To: patch@linaro.org Received: by 2002:a02:c6d8:0:0:0:0:0 with SMTP id r24csp3790311jan; Tue, 23 Apr 2019 06:28:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoMtbZ5gjRVc1Sjn8Lr8gocNRLPxTodVmr7FpP7/oLDL6OoFkfmHUTxAuBYulYqDCLf42r X-Received: by 2002:a63:e110:: with SMTP id z16mr7360090pgh.165.1556026124956; Tue, 23 Apr 2019 06:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556026124; cv=none; d=google.com; s=arc-20160816; b=JFJJ1VYnFnmjHhsy99bvLa4W4abFiZ8VE0XjlebLuKQGS4hA4AW+YhURSVMkF+wKR/ 4seSPsGdOpSdKJs2jVVTu+xzlMr77j1s3K/mTRFEN6nRnIOS4aFeu89WK9CGs795JC3a vPEAGBLdWfXQKgtRxVlLIBapBAUq0InVgvBgNs/kgku8alBfbYeTXcCjMBrSQOtkb9yP SXZdAVj/WXywNLR2GegTgVlDjRPmc3yNbNsoEOZ/jbdyNu6cph5oH4rE6mGkZdWrkaPQ mDmuk9gB2e1dgQ4E2yHhSPm2QHyOV4UsEsr6uao6zdJYhmoBBUo78oKgTZwsrrRKOH03 JWsA== 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=WBZVH8tY60kvdDXDwV8aJHdGVIEg5lBCBmcPhKf9y2Y=; b=CxhqRfSgbPvmIgIlXrHUTO0arq1YZG6XyjmKKaVsY1itsMxhFjYeiWcF1gQFfTpVff DlRYUAXXTemOpeYxKSVtJ8UFAbp2kk5+rDNElqs63JyzJKMRqRqOJ8eFfe/IdkhkUq5+ oGkajy2LAlqwOY7Hp0DEj8JwFGqDzvkpfCSuWhmyJzFCRHC/4G86tETzihFbCN2pt7XE kmnkRpNeiLTNcmsv7nCg2LhqFmsPNPxfMbF7bkPxX1YVhdcOUY/cFAHBHQaXC/7vDw+0 Lo87Jx7UY2oph3WZTgRr7NvbP2FK4HH7Hph4cxsdMc4a1/qR1O87aJhF5f90U94+SDZY VZPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mx7tfKFC; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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. [209.132.180.67]) by mx.google.com with ESMTP id i1si16358435pfr.150.2019.04.23.06.28.44; Tue, 23 Apr 2019 06:28:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mx7tfKFC; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1727745AbfDWN2o (ORCPT + 7 others); Tue, 23 Apr 2019 09:28:44 -0400 Received: from mail-lj1-f195.google.com ([209.85.208.195]:34410 "EHLO mail-lj1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727980AbfDWN2k (ORCPT ); Tue, 23 Apr 2019 09:28:40 -0400 Received: by mail-lj1-f195.google.com with SMTP id y16so2704792ljg.1 for ; Tue, 23 Apr 2019 06:28:38 -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=WBZVH8tY60kvdDXDwV8aJHdGVIEg5lBCBmcPhKf9y2Y=; b=mx7tfKFCrLM+my8sDW7dzzb2SBOnGloSVzmUgLj2SrdsqiYsq+Uq1lnU07zY7h6C5e y0YhFrKkNWfdkTfdMdlbNuKmiaMApa4h+ey7j9Jz639toJrjKFCByOrQXzoM/XHNorPX XJxuAJhHm0Tv57dwC1lVcrZvp1gxj1OPAsHwveMyKCONalWR2wAGlI6E1Q94EM+yggSP XsQNCgnxVz1nZZPTFmuMjHl8RLk2dSsx/7CxPZg8ylVSR+MMKw2rAlrD8vOBAYJhThDL taL/1wBYpNLKnmLsVnUxn7DEHk9MjQ3LCh0f9wXjbuB6Jk14ibwh/E24H+FkhD6mc00m s6xw== 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=WBZVH8tY60kvdDXDwV8aJHdGVIEg5lBCBmcPhKf9y2Y=; b=E1riKx3miPG4cmoE/bQqybjaCk0iB1Mu1lILDc1RG9cgDJf01vgtL7EmB06S/hDkHQ WcU3T7xLDDXYbjBxg7lEgyWDidn+Iyw4WOTF1bw6uW8eaHVcE6LzfAQS1rvBHbnRjlAE x+xZ1MQb0z0HU3mtXo8e2v5ulDbZ82NIqrH6jztuB0fWmHfiNaM381ELGXL6cPqUY6wM nzDVOIdsTQYyCPtObmaSgkOfyoC8ycJ6A3RRm5S2YhDngSArZXXWXsoK8ezmN5Iv1EMq UO4ABR4KquN+Om4KV0QvDrdv7/nsdrl6eU1gTqnQv5c2BCw3vyvTJLvF6rErB5xWe9Ng WQRw== X-Gm-Message-State: APjAAAVx/asb3+MOEortiTXn4lSv2i9E+QdwK794hE2nMzQU16cxRfzy luUCDO36FfOkP795aMKfMx2Dhw== X-Received: by 2002:a2e:1203:: with SMTP id t3mr3028829lje.180.1556026117559; Tue, 23 Apr 2019 06:28:37 -0700 (PDT) Received: from localhost.localdomain ([212.45.67.2]) by smtp.googlemail.com with ESMTPSA id y206sm4617107lfc.72.2019.04.23.06.28.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 23 Apr 2019 06:28:36 -0700 (PDT) From: Georgi Djakov To: vireshk@kernel.org, sboyd@kernel.org, nm@ti.com, robh+dt@kernel.org, mark.rutland@arm.com, rjw@rjwysocki.net Cc: jcrouse@codeaurora.org, vincent.guittot@linaro.org, bjorn.andersson@linaro.org, amit.kucheria@linaro.org, seansw@qti.qualcomm.com, daidavid1@codeaurora.org, evgreen@chromium.org, sibis@codeaurora.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, georgi.djakov@linaro.org Subject: [PATCH v2 5/5] cpufreq: dt: Add support for interconnect bandwidth scaling Date: Tue, 23 Apr 2019 16:28:23 +0300 Message-Id: <20190423132823.7915-6-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190423132823.7915-1-georgi.djakov@linaro.org> References: <20190423132823.7915-1-georgi.djakov@linaro.org> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org In addition to clocks and regulators, some devices can scale the bandwidth of their on-chip interconnect - for example between CPU and DDR memory. Add support for that, so that platforms which support it can make use of it. Signed-off-by: Georgi Djakov --- drivers/cpufreq/cpufreq-dt.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index bde28878725b..8a20f4d0243e 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,7 @@ static int resources_available(void) struct device *cpu_dev; struct regulator *cpu_reg; struct clk *cpu_clk; + struct icc_path *cpu_path; int ret = 0; const char *name; @@ -124,6 +126,19 @@ static int resources_available(void) clk_put(cpu_clk); + cpu_path = of_icc_get(cpu_dev, NULL); + ret = PTR_ERR_OR_ZERO(cpu_path); + if (ret) { + if (ret == -EPROBE_DEFER) + dev_dbg(cpu_dev, "defer icc path: %d\n", ret); + else + dev_err(cpu_dev, "failed to get icc path: %d\n", ret); + + return ret; + } + + icc_put(cpu_path); + name = find_supply_name(cpu_dev); /* Platform doesn't require regulator */ if (!name) @@ -203,10 +218,18 @@ static int cpufreq_init(struct cpufreq_policy *policy) } } + opp_table = dev_pm_opp_set_paths(cpu_dev); + if (IS_ERR(opp_table)) { + ret = PTR_ERR(opp_table); + dev_err(cpu_dev, "Failed to set interconnect path for cpu%d: %d\n", + policy->cpu, ret); + goto out_put_regulator; + } + priv = kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) { ret = -ENOMEM; - goto out_put_regulator; + goto out_put_path; } priv->reg_name = name; @@ -288,6 +311,8 @@ static int cpufreq_init(struct cpufreq_policy *policy) if (priv->have_static_opps) dev_pm_opp_of_cpumask_remove_table(policy->cpus); kfree(priv); +out_put_path: + dev_pm_opp_put_paths(opp_table); out_put_regulator: if (name) dev_pm_opp_put_regulators(opp_table);