From patchwork Fri Aug 10 14:52:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Djakov X-Patchwork-Id: 143943 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp49775ljj; Fri, 10 Aug 2018 07:52:52 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxII2o0mA/hi3UONDBsZQPn2CupeWrCnuhyLVgEpAxy7F+5ERl0nRG8cTMaYkwHCh2fxaVN X-Received: by 2002:a63:4924:: with SMTP id w36-v6mr6839237pga.143.1533912772218; Fri, 10 Aug 2018 07:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533912772; cv=none; d=google.com; s=arc-20160816; b=N6N/QRvMZSE2lzhPQ9Rg2LmgMnyXMuWen2AgmzIh831uqQelpJNo66HfTI20y3YxZH AiD0k2UOOrPf7WFgvP9itiggtPV1NK7SeWn+WREzmboSVnC6Hcc2xO2LFU4NCBsIQxKF HD/LXPG6eNZcB7FnCK/Kk40zgav65nDxW34ZNZrfO8acqVDY6nfnypUksE07KLuupKUC ZfSQVQ9uAIx77NlOEQlSoY+YLk1L5NTxkjF1bquFNgyMmvyIPFVClqGFuzBplt3YD0by CAshOUuvBa48Bz7bxtg7s1ssJbR+SOlavVBVo7zwXoc08CVXMYFUpyiOp51z88+HhWNH m+gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=fDa6F+JrMAbwz8QNQ6MREvsk7u6fmv3IW/3SwDiD83I=; b=Mh6zJ1fgkb24dvSU0KA59OTwBSbwOJfumRoQL2d+PUOx5WV73PCkuREYAep/thZhqD dXi06TU7DtZNg/C2pqafOtLY7hImTvvqpxwhRj9LbUonibP9cEcVcdX9mVVYMjETNoyw tEv437Ho4I0Nrabf1rXQeNcvYzxtijvK2DNHUYeSC603nzsqDWzimpTFA9kmU5ztL6FA AU4SIGKD01uI1Ld1SXfvwtvY3541C1uCIzPynv1Nm07kjkGPi9d+Fg0B2KJ7deTW3uj3 eiuq7OADv7dIFejkoAxOf5QRXKhQZtR/+oBHH06JNBq2+dl6g0jYQdyt75hcF2p03uVU rUCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ea8P/LTF"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 j14-v6si9789508pgh.22.2018.08.10.07.52.52; Fri, 10 Aug 2018 07:52:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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="Ea8P/LTF"; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1728443AbeHJRXD (ORCPT + 10 others); Fri, 10 Aug 2018 13:23:03 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:44557 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728429AbeHJRXD (ORCPT ); Fri, 10 Aug 2018 13:23:03 -0400 Received: by mail-wr1-f65.google.com with SMTP id r16-v6so8526429wrt.11 for ; Fri, 10 Aug 2018 07:52:49 -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; bh=fDa6F+JrMAbwz8QNQ6MREvsk7u6fmv3IW/3SwDiD83I=; b=Ea8P/LTFFa6AYRg+RuaprWNj/iR6f/cpPyi8WAUaT925QFM0vg32OQGxz3zI7v2/ni 4jkHXgAqcvcaQ8w2NuIgBRMaGke1laRQY8ipQp++5/JAXkPSm+jKr19zQXkx0veuhXzd JI1HviBNCo5nrERkRhIaGtxphJH9pw+GhpeXE= 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=fDa6F+JrMAbwz8QNQ6MREvsk7u6fmv3IW/3SwDiD83I=; b=tUyohCJZPF20kID20HWGJPPv1em465/OjTkfyeWHnrpEV7HbqY3woxsNdlyIjfCS6Z bPf96BkFYs38HMnKELR1jshu4KqswWy4q4DLwjDpmwXca1L3cQnmglH+bqSil0UADBBD n4twWq95or6Lo0LhBaj2dflv7yZoLhvLL/Eqo2boap0gNKTMB5ksQrf93JOkQPIJyF19 4wAiBxx4BuvDSd62OMLGyZcLjgIMhyF9APugUygFZV0P1x6B03NyQRlOLjJCBPayExyV BC6MpiarXHzvX+2BMWAGB7b07eKLxFCG+ervo71SslpNEN4vpgyDMycEO2bkrYqDDFm+ COtA== X-Gm-Message-State: AOUpUlGa0OxbpZBXoBHNSW1Qj69P3rryVKRAGWG3MLSinkibRJBTHKtz N3cLin0lAmkhWebvxEkCjbE4wCQ5wJg= X-Received: by 2002:adf:b2f4:: with SMTP id g107-v6mr4664061wrd.53.1533912768351; Fri, 10 Aug 2018 07:52:48 -0700 (PDT) Received: from localhost.localdomain ([212.45.67.2]) by smtp.googlemail.com with ESMTPSA id 9-v6sm19842700wrb.48.2018.08.10.07.52.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 10 Aug 2018 07:52:47 -0700 (PDT) From: Georgi Djakov To: linux-pm@vger.kernel.org, gregkh@linuxfoundation.org Cc: rjw@rjwysocki.net, robh+dt@kernel.org, mturquette@baylibre.com, khilman@baylibre.com, vincent.guittot@linaro.org, skannan@codeaurora.org, bjorn.andersson@linaro.org, amit.kucheria@linaro.org, seansw@qti.qualcomm.com, daidavid1@codeaurora.org, evgreen@chromium.org, mark.rutland@arm.com, lorenzo.pieralisi@arm.com, abailon@baylibre.com, arnd@arndb.de, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, georgi.djakov@linaro.org Subject: [PATCH v8 3/8] interconnect: Allow endpoints translation via DT Date: Fri, 10 Aug 2018 17:52:28 +0300 Message-Id: <20180810145233.16466-4-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180810145233.16466-1-georgi.djakov@linaro.org> References: <20180810145233.16466-1-georgi.djakov@linaro.org> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Currently we support only platform data for specifying the interconnect endpoints. As now the endpoints are hard-coded into the consumer driver this may lead to complications when a single driver is used by multiple SoCs, which may have different interconnect topology. To avoid cluttering the consumer drivers, introduce a translation function to help us get the board specific interconnect data from device-tree. Signed-off-by: Georgi Djakov Reviewed-by: Evan Green --- drivers/interconnect/core.c | 78 ++++++++++++++++++++++++++++++++++++ include/linux/interconnect.h | 7 ++++ 2 files changed, 85 insertions(+) diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c index 9ca39aca4982..8f874d1b0a0f 100644 --- a/drivers/interconnect/core.c +++ b/drivers/interconnect/core.c @@ -15,6 +15,7 @@ #include #include #include +#include #include static DEFINE_IDR(icc_idr); @@ -192,6 +193,83 @@ static int apply_constraints(struct icc_path *path) return ret; } +/** + * 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 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. NULL is also returned when the "interconnects" + * DT property is missing. + * + * 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; + struct of_phandle_args src_args, dst_args; + u32 src_id, dst_id; + int idx = 0; + int ret; + + 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 is 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); + if (ret) + return ERR_PTR(ret); + + of_node_put(src_args.np); + + if (!src_args.args_count || src_args.args_count > 1) + return ERR_PTR(-EINVAL); + + src_id = src_args.args[0]; + + ret = of_parse_phandle_with_args(np, "interconnects", + "#interconnect-cells", idx * 2 + 1, + &dst_args); + if (ret) + return ERR_PTR(ret); + + of_node_put(dst_args.np); + + if (!dst_args.args_count || dst_args.args_count > 1) + return ERR_PTR(-EINVAL); + + dst_id = dst_args.args[0]; + + return icc_get(dev, src_id, dst_id); +} +EXPORT_SYMBOL_GPL(of_icc_get); + /** * icc_set() - set constraints on an interconnect path between two endpoints * @path: reference to the path returned by icc_get() diff --git a/include/linux/interconnect.h b/include/linux/interconnect.h index 593215371fd6..ae6744da9bc2 100644 --- a/include/linux/interconnect.h +++ b/include/linux/interconnect.h @@ -17,6 +17,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); void icc_put(struct icc_path *path); int icc_set(struct icc_path *path, u32 avg_bw, u32 peak_bw); @@ -28,6 +29,12 @@ static inline struct icc_path *icc_get(struct device *dev, const int src_id, return NULL; } +static inline struct icc_path *of_icc_get(struct device *dev, + const char *name) +{ + return NULL; +} + static inline void icc_put(struct icc_path *path) { }