From patchwork Fri Dec 4 07:53:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jun Nie X-Patchwork-Id: 337731 Delivered-To: patch@linaro.org Received: by 2002:a92:5e16:0:0:0:0:0 with SMTP id s22csp38046ilb; Thu, 3 Dec 2020 23:55:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5uuuC5/nOV7Rv9lhSR4IMCvYEohOpqxcclpqHwCFpl9tXfWjd4g97C/9qoRrVzl9psMny X-Received: by 2002:a17:906:4881:: with SMTP id v1mr5732345ejq.465.1607068536461; Thu, 03 Dec 2020 23:55:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607068536; cv=none; d=google.com; s=arc-20160816; b=wc5G2WX0dssPI6l4Ewssucex2Xt4/957TRa9mN5i3LFUxRzavUQkV+TvO9+2YAgDHv iuVblAYKtJwy6H0anU+75l1SGM/sntv1hzgjXHvAmNO51wjHFUFC4TYBgv1tCqHB28s/ SsiOa3PLisxRnqtzgpOlTlaXHZHDcORsTwFtCglpByzW7deIiJxeUFqgU3kbE9NpBTlU tkJt4eJV40SnrtKoEqEWkEWUBrYz80ZNdd35shCnJ48fDU2AXuFCmi/JLUy6bE6vFM6G 6wXdmi9ktsDVndkvHLcYY16ham85b/KXdStyi1h6XqTLpd37VF87FG/5SBL912gcNGsh Mu+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=Ffh6MHUF3pcIH20QeFw4DyMogPpGQ0qYgD+VOcKz+Uo=; b=tjrk+zq/KAUxkdFwCqkw3i8kLsK4piklmKPMwlmnWiQy6ddc8RawOiEnXcZWXP6CvN DADphHIOXtTc6zjuQgk5+5DiI7rm2fmETDTmDk/eTID5ns3lGOGMzowyjrMtKJqpym1t kMUjIi3hpc7P1zplRigCTIlCEDflbHAoVBhpdQ2p77wE09Ij0q0s3uHT+7lbkUtRgWm6 F69iS+988sDG8kR3cG/MNqoyG5XCNdPjhv/oiHjoxAr13XcFO5gNBL/oqMZ0sD8AZGzl 9eyM+SNEh8OhnixY106Xcl/VFYyy3Y3W2TdKikYzfhh8ec02rCqQBNTNlWCQQn9/7X4Q yVIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ifrWHC1q; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id v22si2494355edt.77.2020.12.03.23.55.36; Thu, 03 Dec 2020 23:55:36 -0800 (PST) Received-SPF: pass (google.com: domain of devicetree-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=ifrWHC1q; spf=pass (google.com: domain of devicetree-owner@vger.kernel.org designates 23.128.96.18 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 S2387449AbgLDHza (ORCPT + 6 others); Fri, 4 Dec 2020 02:55:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387438AbgLDHz3 (ORCPT ); Fri, 4 Dec 2020 02:55:29 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8152EC08E863 for ; Thu, 3 Dec 2020 23:54:19 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id m9so3041757pgb.4 for ; Thu, 03 Dec 2020 23:54:19 -0800 (PST) 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=Ffh6MHUF3pcIH20QeFw4DyMogPpGQ0qYgD+VOcKz+Uo=; b=ifrWHC1qNTOfLpfFReqng90ivM/9dXxNnwH2izb+t37SN4zVdigjjG7dikglKgHxdy Q3Pc+8941sR8KhIGMdRxovzWNFtdiehXE8iSELA3APiijQZCtsT/eP1bl7K9E9daBIHb dojUEi7lUagAEa/JJ0JsRXCVzJyUbNjyc5kbOYDcnvY1E9zoi5RxcnKQypc6lAdLgVk2 GvNM/VZCWlIsVZj0yr9Mw4z/cKbmlR0/TnXprxeZHnouAxOorhkYiFEF7Up9/JBL8y6Z MK/nB8JTTWgeDiwLLU+d3kfLSqWogAaZlvMKQ6lbIULp9zVG4rAFZbL8Br1sZTPVHQLP eNhg== 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=Ffh6MHUF3pcIH20QeFw4DyMogPpGQ0qYgD+VOcKz+Uo=; b=JDBoNEuucjNjuZ2jqIN3FYS/5/NNBJGD1U/FLfMvgVGP+MlrHyOWfgB7Jlz/V5LGRd bQ61HfeqEM5g5S/eYJVm7oZ8r20JjJMVGBxvCE2VVIejjYMQ6qc0bplH/amjuh3gYLdm s8CVVk+GAfAxrbL+plM+0ib3vx5BKn3F+uHYjJm1M5fPL1FBmcChmTaF0NGRf4Uru6hU O+aF3o0CDn9H4O4wfMk6Ce84jy9251agTbYgrPFLyv+GEJYprkgeNSe0qdkH44O3fOr9 f24C3rx01PvYUTEKN+oXCk8nypzly5Mqe2L0TsMxStYBOjj5S5fN9cjpCON0QfsVgi/g d3XA== X-Gm-Message-State: AOAM531+u+PiQG2ItIE4P9j9XR/VRPPRf37DjlOnBUMCRJ6hrGlw6+Xp SibAQ2Wq63W7JjnKWRWy8/468rgd18I2mw== X-Received: by 2002:a63:a902:: with SMTP id u2mr6548638pge.263.1607068458748; Thu, 03 Dec 2020 23:54:18 -0800 (PST) Received: from localhost.localdomain (li519-153.members.linode.com. [66.175.222.153]) by smtp.gmail.com with ESMTPSA id l190sm3822262pfl.205.2020.12.03.23.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2020 23:54:18 -0800 (PST) From: Jun Nie To: devicetree@vger.kernel.org, georgi.djakov@linaro.org, bjorn.andersson@linaro.org, agross@kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, robh@kernel.org Cc: vincent.knecht@mailoo.org, shawn.guo@linaro.org, Jun Nie Subject: [PATCH v2 2/5] interconnect: qcom: qcs404: use shared code Date: Fri, 4 Dec 2020 15:53:42 +0800 Message-Id: <20201204075345.5161-3-jun.nie@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201204075345.5161-1-jun.nie@linaro.org> References: <20201204075345.5161-1-jun.nie@linaro.org> Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Use shared code for aggregate functionalities and probe function to remove duplicated code. Signed-off-by: Jun Nie --- drivers/interconnect/qcom/qcs404.c | 242 +---------------------------- 1 file changed, 8 insertions(+), 234 deletions(-) -- 2.17.1 diff --git a/drivers/interconnect/qcom/qcs404.c b/drivers/interconnect/qcom/qcs404.c index 9820709b43db..36a7e30a00be 100644 --- a/drivers/interconnect/qcom/qcs404.c +++ b/drivers/interconnect/qcom/qcs404.c @@ -9,15 +9,12 @@ #include #include #include -#include -#include #include -#include +#include -#include "smd-rpm.h" -#define RPM_BUS_MASTER_REQ 0x73616d62 -#define RPM_BUS_SLAVE_REQ 0x766c7362 +#include "smd-rpm.h" +#include "icc-rpm.h" enum { QCS404_MASTER_AMPSS_M0 = 1, @@ -95,67 +92,11 @@ enum { QCS404_SLAVE_LPASS, }; -#define to_qcom_provider(_provider) \ - container_of(_provider, struct qcom_icc_provider, provider) - -static const struct clk_bulk_data bus_clocks[] = { +static const struct clk_bulk_data qcs404_bus_clocks[] = { { .id = "bus" }, { .id = "bus_a" }, }; -/** - * struct qcom_icc_provider - Qualcomm specific interconnect provider - * @provider: generic interconnect provider - * @bus_clks: the clk_bulk_data table of bus clocks - * @num_clks: the total number of clk_bulk_data entries - */ -struct qcom_icc_provider { - struct icc_provider provider; - struct clk_bulk_data *bus_clks; - int num_clks; -}; - -#define QCS404_MAX_LINKS 12 - -/** - * struct qcom_icc_node - Qualcomm specific interconnect nodes - * @name: the node name used in debugfs - * @id: a unique node identifier - * @links: an array of nodes where we can go next while traversing - * @num_links: the total number of @links - * @buswidth: width of the interconnect between a node and the bus (bytes) - * @mas_rpm_id: RPM id for devices that are bus masters - * @slv_rpm_id: RPM id for devices that are bus slaves - * @rate: current bus clock rate in Hz - */ -struct qcom_icc_node { - unsigned char *name; - u16 id; - u16 links[QCS404_MAX_LINKS]; - u16 num_links; - u16 buswidth; - int mas_rpm_id; - int slv_rpm_id; - u64 rate; -}; - -struct qcom_icc_desc { - struct qcom_icc_node **nodes; - size_t num_nodes; -}; - -#define DEFINE_QNODE(_name, _id, _buswidth, _mas_rpm_id, _slv_rpm_id, \ - ...) \ - static struct qcom_icc_node _name = { \ - .name = #_name, \ - .id = _id, \ - .buswidth = _buswidth, \ - .mas_rpm_id = _mas_rpm_id, \ - .slv_rpm_id = _slv_rpm_id, \ - .num_links = ARRAY_SIZE(((int[]){ __VA_ARGS__ })), \ - .links = { __VA_ARGS__ }, \ - } - DEFINE_QNODE(mas_apps_proc, QCS404_MASTER_AMPSS_M0, 8, 0, -1, QCS404_SLAVE_EBI_CH0, QCS404_BIMC_SNOC_SLV); DEFINE_QNODE(mas_oxili, QCS404_MASTER_GRAPHICS_3D, 8, -1, -1, QCS404_SLAVE_EBI_CH0, QCS404_BIMC_SNOC_SLV); DEFINE_QNODE(mas_mdp, QCS404_MASTER_MDP_PORT0, 8, -1, -1, QCS404_SLAVE_EBI_CH0, QCS404_BIMC_SNOC_SLV); @@ -327,178 +268,11 @@ static struct qcom_icc_desc qcs404_snoc = { .num_nodes = ARRAY_SIZE(qcs404_snoc_nodes), }; -static int qcom_icc_set(struct icc_node *src, struct icc_node *dst) -{ - struct qcom_icc_provider *qp; - struct qcom_icc_node *qn; - struct icc_provider *provider; - struct icc_node *n; - u64 sum_bw; - u64 max_peak_bw; - u64 rate; - u32 agg_avg = 0; - u32 agg_peak = 0; - int ret, i; - - qn = src->data; - provider = src->provider; - qp = to_qcom_provider(provider); - - list_for_each_entry(n, &provider->nodes, node_list) - provider->aggregate(n, 0, n->avg_bw, n->peak_bw, - &agg_avg, &agg_peak); - - sum_bw = icc_units_to_bps(agg_avg); - max_peak_bw = icc_units_to_bps(agg_peak); - - /* send bandwidth request message to the RPM processor */ - if (qn->mas_rpm_id != -1) { - ret = qcom_icc_rpm_smd_send(QCOM_SMD_RPM_ACTIVE_STATE, - RPM_BUS_MASTER_REQ, - qn->mas_rpm_id, - sum_bw); - if (ret) { - pr_err("qcom_icc_rpm_smd_send mas %d error %d\n", - qn->mas_rpm_id, ret); - return ret; - } - } - - if (qn->slv_rpm_id != -1) { - ret = qcom_icc_rpm_smd_send(QCOM_SMD_RPM_ACTIVE_STATE, - RPM_BUS_SLAVE_REQ, - qn->slv_rpm_id, - sum_bw); - if (ret) { - pr_err("qcom_icc_rpm_smd_send slv error %d\n", - ret); - return ret; - } - } - - rate = max(sum_bw, max_peak_bw); - - do_div(rate, qn->buswidth); - - if (qn->rate == rate) - return 0; - - for (i = 0; i < qp->num_clks; i++) { - ret = clk_set_rate(qp->bus_clks[i].clk, rate); - if (ret) { - pr_err("%s clk_set_rate error: %d\n", - qp->bus_clks[i].id, ret); - return ret; - } - } - - qn->rate = rate; - return 0; -} - -static int qnoc_probe(struct platform_device *pdev) +static int qcs404_qnoc_probe(struct platform_device *pdev) { - struct device *dev = &pdev->dev; - const struct qcom_icc_desc *desc; - struct icc_onecell_data *data; - struct icc_provider *provider; - struct qcom_icc_node **qnodes; - struct qcom_icc_provider *qp; - struct icc_node *node; - size_t num_nodes, i; - int ret; - - /* wait for the RPM proxy */ - if (!qcom_icc_rpm_smd_available()) - return -EPROBE_DEFER; - - desc = of_device_get_match_data(dev); - if (!desc) - return -EINVAL; - - qnodes = desc->nodes; - num_nodes = desc->num_nodes; - - qp = devm_kzalloc(dev, sizeof(*qp), GFP_KERNEL); - if (!qp) - return -ENOMEM; - - data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes), - GFP_KERNEL); - if (!data) - return -ENOMEM; - - qp->bus_clks = devm_kmemdup(dev, bus_clocks, sizeof(bus_clocks), - GFP_KERNEL); - if (!qp->bus_clks) - return -ENOMEM; - - qp->num_clks = ARRAY_SIZE(bus_clocks); - ret = devm_clk_bulk_get(dev, qp->num_clks, qp->bus_clks); - if (ret) - return ret; - - ret = clk_bulk_prepare_enable(qp->num_clks, qp->bus_clks); - if (ret) - return ret; - - provider = &qp->provider; - INIT_LIST_HEAD(&provider->nodes); - provider->dev = dev; - provider->set = qcom_icc_set; - provider->aggregate = icc_std_aggregate; - provider->xlate = of_icc_xlate_onecell; - provider->data = data; - - ret = icc_provider_add(provider); - if (ret) { - dev_err(dev, "error adding interconnect provider: %d\n", ret); - clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks); - return ret; - } - - for (i = 0; i < num_nodes; i++) { - size_t j; - - node = icc_node_create(qnodes[i]->id); - if (IS_ERR(node)) { - ret = PTR_ERR(node); - goto err; - } - - node->name = qnodes[i]->name; - node->data = qnodes[i]; - icc_node_add(node, provider); - - dev_dbg(dev, "registered node %s\n", node->name); - - /* populate links */ - for (j = 0; j < qnodes[i]->num_links; j++) - icc_link_create(node, qnodes[i]->links[j]); - - data->nodes[i] = node; - } - data->num_nodes = num_nodes; - - platform_set_drvdata(pdev, qp); - - return 0; -err: - icc_nodes_remove(provider); - clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks); - icc_provider_del(provider); - - return ret; -} - -static int qnoc_remove(struct platform_device *pdev) -{ - struct qcom_icc_provider *qp = platform_get_drvdata(pdev); - - icc_nodes_remove(&qp->provider); - clk_bulk_disable_unprepare(qp->num_clks, qp->bus_clks); - return icc_provider_del(&qp->provider); + return qnoc_probe(pdev, sizeof(qcs404_bus_clocks), + ARRAY_SIZE(qcs404_bus_clocks), qcs404_bus_clocks); } static const struct of_device_id qcs404_noc_of_match[] = { @@ -510,7 +284,7 @@ static const struct of_device_id qcs404_noc_of_match[] = { MODULE_DEVICE_TABLE(of, qcs404_noc_of_match); static struct platform_driver qcs404_noc_driver = { - .probe = qnoc_probe, + .probe = qcs404_qnoc_probe, .remove = qnoc_remove, .driver = { .name = "qnoc-qcs404",