From patchwork Fri Aug 31 14:01:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Georgi Djakov X-Patchwork-Id: 145650 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp819552ljw; Fri, 31 Aug 2018 07:02:05 -0700 (PDT) X-Google-Smtp-Source: ANB0VdarfYpMkqVIbXHoI4lJSna4NbnXMxFdZuq/YvuG+z4wvEaR02/nxJUk5lLO1YL9QdROZccC X-Received: by 2002:a25:81d0:: with SMTP id n16-v6mr4451016ybm.379.1535724125588; Fri, 31 Aug 2018 07:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535724125; cv=none; d=google.com; s=arc-20160816; b=wgsrnpJMrAf6NPT5S1giWeMdfcTu9hMWxHVAyq8DOBZFWtU1Fak4aFBlqSfiQZt7Ms uKyY8D3tOvLH4xVGTxTu8fcaxZrpi53C4HfOaDR792/VH4h/C5a7+u5TnCyu1rde4Dlk O/O0YVXiJHS7FxXtDkoQ9aSnuNJYF5A5kJ+v/aBvyG4D/NHwQYk8qjVv/tWX3hWdG96v l/jSzl6YZhQS5K8oCPsujxx/be4N2EC9WaGE7ZVqW8hL9P65RSINkXxOu9vYTwMJ6xBg c8oGOeGCr7mvsjManTggfDSrvcySPsT8/w+6sT5eKe4r5GZY8qTmQFFKfxSJfiCIOFr4 hIAw== 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=MtSPle3SlRFRMpEaYEZP3RDeAjImas6dWHd7Hlp6qQA=; b=tR9R26+g76gzwyS94V2lHtj0+6bQAfHDwRkcaZWvQzRwxQTZ4S22P+j0EsNckkn+Nx gQnnhi952evKPqf29OurAnN+gP8f2g8UAEJ1bP8DpaOCAB1taVkj6H4RPcB5Ke36tEYn EHUHvUYKhZ4i9tR3zNM6QgrNxAgo1tl2dveCCx6AH00o0og2l5hFlRNh4TnEtzzp69T1 dx66Wlb6rYAPpM/ql6WxB90TIsSTCgI48F4NKgzV7HH5pWHJjfg4Z3y9Gna+sVHd6QD+ oKajGznkpfIo5GW+RB5l0HGk3fqVlzAHNE7iTLl4/LTdrlxkSUWYnvD9Gi0QrUV0aSny FmFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gzRNV4ME; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id m11-v6si9688094pgk.468.2018.08.31.07.02.05; Fri, 31 Aug 2018 07:02:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=gzRNV4ME; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1728732AbeHaSJk (ORCPT + 32 others); Fri, 31 Aug 2018 14:09:40 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:34343 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728707AbeHaSJj (ORCPT ); Fri, 31 Aug 2018 14:09:39 -0400 Received: by mail-wr1-f67.google.com with SMTP id g33-v6so11352469wrd.1 for ; Fri, 31 Aug 2018 07:02:00 -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=MtSPle3SlRFRMpEaYEZP3RDeAjImas6dWHd7Hlp6qQA=; b=gzRNV4MEde8iRf5EIs4NuX3pw0rEHqwREhWNu6/aZ7mIN3lYQzGsYurB9pupFrxcgc 8fhDH3yQd1ssdRomxHAyNB/3YHNuCWnkDEPmJaHCQAKP3LyMt/d1hEX7gu+y9SvesTAv x1pZ++KZbVxtP1s+GUmnytuhYbSlB9Z7pfnTs= 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=MtSPle3SlRFRMpEaYEZP3RDeAjImas6dWHd7Hlp6qQA=; b=C7wA+CRMTeIz/BSlLNJC1q4akox5I39XUrlInn77ZW3dCSifOBp44F2iSbcvRYxQe8 InF4eGr6H7K5ucmy1CMFHodzlW9SW0SpZAg27jaF8468PHa0r1jEE/uEzu7cnlJszdRX j+k/6ahCc4OFPJmtLQmmgzcPNLjPxrbgjRYkyF2apAXKMcSRjDKUnnRglXiz/YaBsWag zMPnISYyO5hr0ld48+/exxQCfddbYI5foLIEaJjQZF6d7kWMSllBHHCPavwYSLtgYa/2 J0dDHHi588uSN9uq7L8l4/jLGYFDVPNEJQjZAivfXzeUpbyzY4MWHk66A30kEkG9p/07 EIEw== X-Gm-Message-State: APzg51DpxSCjs93ZXOVuz4NaJrPNjhAhwMY0kPCdfzgHMPaHScK3QRCQ lLNqWIwpYW3jQBrq4K+AUA1I1A== X-Received: by 2002:adf:a4d1:: with SMTP id h17-v6mr10487020wrb.167.1535724119562; Fri, 31 Aug 2018 07:01:59 -0700 (PDT) Received: from localhost.localdomain ([212.45.67.2]) by smtp.googlemail.com with ESMTPSA id m68-v6sm8624513wmb.10.2018.08.31.07.01.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 31 Aug 2018 07:01:58 -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, maxime.ripard@bootlin.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 v9 3/8] interconnect: Allow endpoints translation via DT Date: Fri, 31 Aug 2018 17:01:46 +0300 Message-Id: <20180831140151.13972-4-georgi.djakov@linaro.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180831140151.13972-1-georgi.djakov@linaro.org> References: <20180831140151.13972-1-georgi.djakov@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 6d932245a610..ed0a6783ffc4 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 7fd6e8d0696c..dc48e441d005 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) { }