From patchwork Fri Feb 17 10:46:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Dybcio X-Patchwork-Id: 58487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp817018wrn; Fri, 17 Feb 2023 02:48:41 -0800 (PST) X-Google-Smtp-Source: AK7set9J/qRprcQzbIg1KiCp7Om0E/7cFTrgeo/Fgvj4B93JGN3szABiKITptL7U9XiMvVdj2t74 X-Received: by 2002:a17:902:fa8c:b0:19a:b754:4053 with SMTP id lc12-20020a170902fa8c00b0019ab7544053mr415537plb.26.1676630921561; Fri, 17 Feb 2023 02:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676630921; cv=none; d=google.com; s=arc-20160816; b=lo+QEeTqiAxheRWtpgdmZpCroEbG5XeuW59zI/mZzAIMGogoU11amhInpBcl7OyzKa d/hKldojfSNXphdG57DbS7BAVZur3fp17a8A2LD6V7j/39kfZ2IybSOwEOdSDpuZQtBc NjcH8Z/+ViyQ24x+y0IjwaZwsMriTRuV5bnACOUUCcfZA9rAxTjhFsJOxZ4MkJUFaQ1+ DQQ+98q/h/dZDNeUAvY2n06FDXJj4V0dQJI6IU/Hz95frAs7esDBYBSs2xlEZCBepmJr IJiHFiCbewqXKkMiHZ8wotezTpY9Q32/q3RNaufCzkQtwboMQBHNRpeV4IbjMHCJ3OIz 8anQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=3MHWwA73OFZ3bR5+vwT2j4l8Utx4DnHts3Akf3ykMvM=; b=Cmqif1bIu8bx2GItEsY91RNAI7LbmPUmmy41HnYfMqVppCFO4eEBTrfnzwnr5IJF7h zqyJuM34UpyN5DT419lEHraJ94Z766g1GhT5pQawMaUjksVJ8J3p/yKLi61MX5ZtoSoy u5MIIaAMu+Ohd+4mDAEwUNHHrvMzoSUe1Kv1dBvOrnEDJbSjRaWAJ3liF3ivWjhuE+DV r7I1Av82O9QVM34RZGL55kGvpzhT/Xg6VrE6DMPHhgLSSnf2TAeNkVBZUWdGT5v53b+n /PU4YcbHtR2iJlcKhNNNKY2ipiAGKesgEYD6jsVafY66V3QRZYloo2pasvkAaq1MQc6H d5mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fyw4+Y3e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a170902c74a00b0019b0b007981si2723989plq.531.2023.02.17.02.48.29; Fri, 17 Feb 2023 02:48:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fyw4+Y3e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229983AbjBQKq4 (ORCPT + 99 others); Fri, 17 Feb 2023 05:46:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229936AbjBQKqp (ORCPT ); Fri, 17 Feb 2023 05:46:45 -0500 Received: from mail-lj1-x22b.google.com (mail-lj1-x22b.google.com [IPv6:2a00:1450:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 673EC63BF6 for ; Fri, 17 Feb 2023 02:46:42 -0800 (PST) Received: by mail-lj1-x22b.google.com with SMTP id z10so550523ljq.2 for ; Fri, 17 Feb 2023 02:46:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=3MHWwA73OFZ3bR5+vwT2j4l8Utx4DnHts3Akf3ykMvM=; b=fyw4+Y3eRRE5bsRDzpmxCSgFPMKgW2p91G/B1LKmextL5NeHfxtCME/byuSNUmtebq jPPAUrP+JNub257PY1pzLOS7hOujW3TnMN8P8MpyKxbnHB5sgdyDRqCjQXdtYTM8PJLh U+T34qgPfR/K0/THAPEM0n5BLlDZ0bPyxVJhbLwT3bPcx2BRBI47GnU+mDwunpibppA5 NkkvbbBKxSzsZoFFHyLDWlMK4HBDqU/e0vwVQ4n19fIAujggfgwh3nF7CchySkrnHpsV CpDruNpaSF16itos68qu47p6JWO16wTnToXWnvxFHGZlcLV6n3zrbEGnVXTo67B7GNKU o9tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3MHWwA73OFZ3bR5+vwT2j4l8Utx4DnHts3Akf3ykMvM=; b=r+8onaFs643Mej99/4NpaklRygGibZElQ7fy+LJKoZBlKYeyHSDTSM/+15+M+DoKtE j/qsoiiEkJMuq90/xk3dERg/MKSdV9YiAL38rmPW0zjadblMlwX036CAGwrnXfmD+klz k97k/ddLX7Y4VYRzUGL7aKApJx+uxL4USiYHvMwdHuPYx4EgZz6rpvLu1l+lI4uUROU1 bxplx6C9FtWfrhklYaAe8ylXjEyJ5Ayc31fXSDMLvggMiDfDFD4JPCxeqp1EfcqfsTOT aSKn+i4N3UYmWlSBxN0aXYiMRE/OosnXdX4QOzgG27P5lV6KUFbB024Hrm5cAlAxMYm4 w0yA== X-Gm-Message-State: AO0yUKUGH6xYWtI54SVfSkH2RdfKhJB+zW2r1vUXbiz+RDvYeGc9QfFc 8CHs2JqoGIktyyvZRqU8yj8T1w== X-Received: by 2002:a2e:b808:0:b0:293:4ae3:a0c4 with SMTP id u8-20020a2eb808000000b002934ae3a0c4mr50038ljo.2.1676630800626; Fri, 17 Feb 2023 02:46:40 -0800 (PST) Received: from [192.168.1.101] (abxh117.neoplus.adsl.tpnet.pl. [83.9.1.117]) by smtp.gmail.com with ESMTPSA id c13-20020a05651221ad00b004b53eb60e3csm645940lft.256.2023.02.17.02.46.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Feb 2023 02:46:40 -0800 (PST) From: Konrad Dybcio Date: Fri, 17 Feb 2023 11:46:27 +0100 Subject: [PATCH v5 06/10] interconnect: qcom: rpm: Handle interface clocks MIME-Version: 1.0 Message-Id: <20230217-topic-icc-fixes-v5-v5-6-c9a550f9fdb9@linaro.org> References: <20230217-topic-icc-fixes-v5-v5-0-c9a550f9fdb9@linaro.org> In-Reply-To: <20230217-topic-icc-fixes-v5-v5-0-c9a550f9fdb9@linaro.org> To: Andy Gross , Bjorn Andersson , Georgi Djakov , Evan Green , Jun Nie , Greg Kroah-Hartman , Brian Masney , Dmitry Baryshkov , Yassine Oudjana Cc: Georgi Djakov , Bryan O'Donoghue , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Konrad Dybcio X-Mailer: b4 0.12.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1676630791; l=8870; i=konrad.dybcio@linaro.org; s=20230215; h=from:subject:message-id; bh=lrK4CgyASlp1FXP4xhjPdSbXvbaRtdChuTXbzfLQdS8=; b=N33qYbmOwCd4yPi9aA4tJuN4kKdJue8femdZMV6wSx3v00aLU1IocY6drY+n3sMr7MqlANxUdZXQ kn9osv54BlaqMSTrRmaoECQxlGNQOyrKgKK2sNzRie2N4IaPdja5 X-Developer-Key: i=konrad.dybcio@linaro.org; a=ed25519; pk=iclgkYvtl2w05SSXO5EjjSYlhFKsJ+5OSZBjOkQuEms= X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758074945183048998?= X-GMAIL-MSGID: =?utf-8?q?1758074945183048998?= Some (but not all) providers (or their specific nodes) require specific clocks to be turned on before they can be accessed. Failure to ensure that results in a seemingly random system crash (which would usually happen at boot with the interconnect driver built-in), resulting in the platform not booting up properly. Limit the number of bus_clocks to 2 (which is the maximum that SMD RPM interconnect supports anyway) and handle non-scaling clocks separately. Update MSM8996 and SDM660 drivers to make sure they do not regress with this change. This unfortunately has to be done in one patch to prevent either compile errors or broken bisect. Signed-off-by: Konrad Dybcio --- drivers/interconnect/qcom/icc-rpm.c | 48 ++++++++++++++++++++++++++++--------- drivers/interconnect/qcom/icc-rpm.h | 10 ++++++-- drivers/interconnect/qcom/msm8996.c | 22 +++++++---------- drivers/interconnect/qcom/sdm660.c | 16 +++++-------- 4 files changed, 60 insertions(+), 36 deletions(-) diff --git a/drivers/interconnect/qcom/icc-rpm.c b/drivers/interconnect/qcom/icc-rpm.c index f78c13e6c5ce..1b382a2f2710 100644 --- a/drivers/interconnect/qcom/icc-rpm.c +++ b/drivers/interconnect/qcom/icc-rpm.c @@ -441,28 +441,43 @@ int qnoc_probe(struct platform_device *pdev) qnodes = desc->nodes; num_nodes = desc->num_nodes; - if (desc->num_bus_clocks) { - cds = desc->bus_clocks; - cd_num = desc->num_bus_clocks; + if (desc->num_intf_clocks) { + cds = desc->intf_clocks; + cd_num = desc->num_intf_clocks; } else { - cds = bus_clocks; - cd_num = ARRAY_SIZE(bus_clocks); + /* 0 intf clocks is perfectly fine */ + cd_num = 0; } - qp = devm_kzalloc(dev, struct_size(qp, bus_clks, cd_num), GFP_KERNEL); + qp = devm_kzalloc(dev, struct_size(qp, intf_clks, cd_num), GFP_KERNEL); if (!qp) return -ENOMEM; - qp->bus_clk_rate = devm_kcalloc(dev, cd_num, sizeof(*qp->bus_clk_rate), - GFP_KERNEL); - if (!qp->bus_clk_rate) - return -ENOMEM; - data = devm_kzalloc(dev, struct_size(data, nodes, num_nodes), GFP_KERNEL); if (!data) return -ENOMEM; + for (i = 0; i < cd_num; i++) + qp->intf_clks[i].id = cds[i]; + qp->num_intf_clks = cd_num; + + if (desc->num_bus_clocks) { + cds = desc->bus_clocks; + cd_num = desc->num_bus_clocks; + } else { + cds = bus_clocks; + cd_num = ARRAY_SIZE(bus_clocks); + } + + /* + * This is not realistic, scaling is only possible with an + * always-active and an active-only clock, or at least one + * of them in some very bizzare cases. + */ + if (WARN_ON(cd_num > 2)) + cd_num = 2; + for (i = 0; i < cd_num; i++) qp->bus_clks[i].id = cds[i]; qp->num_bus_clks = cd_num; @@ -503,6 +518,14 @@ int qnoc_probe(struct platform_device *pdev) if (ret) return ret; + ret = devm_clk_bulk_get(dev, qp->num_intf_clks, qp->intf_clks); + if (ret) + return ret; + + ret = clk_bulk_prepare_enable(qp->num_intf_clks, qp->intf_clks); + if (ret) + return ret; + if (desc->has_bus_pd) { ret = dev_pm_domain_attach(dev, true); if (ret) @@ -521,6 +544,7 @@ int qnoc_probe(struct platform_device *pdev) ret = icc_provider_add(provider); if (ret) { dev_err(dev, "error adding interconnect provider: %d\n", ret); + clk_bulk_disable_unprepare(qp->num_intf_clks, qp->intf_clks); clk_bulk_disable_unprepare(qp->num_bus_clks, qp->bus_clks); return ret; } @@ -554,6 +578,7 @@ int qnoc_probe(struct platform_device *pdev) return 0; err: icc_nodes_remove(provider); + clk_bulk_disable_unprepare(qp->num_intf_clks, qp->intf_clks); clk_bulk_disable_unprepare(qp->num_bus_clks, qp->bus_clks); icc_provider_del(provider); @@ -566,6 +591,7 @@ 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_intf_clks, qp->intf_clks); clk_bulk_disable_unprepare(qp->num_bus_clks, qp->bus_clks); icc_provider_del(&qp->provider); diff --git a/drivers/interconnect/qcom/icc-rpm.h b/drivers/interconnect/qcom/icc-rpm.h index d4401f35f6d2..729573f0d9fe 100644 --- a/drivers/interconnect/qcom/icc-rpm.h +++ b/drivers/interconnect/qcom/icc-rpm.h @@ -24,20 +24,24 @@ enum qcom_icc_type { * struct qcom_icc_provider - Qualcomm specific interconnect provider * @provider: generic interconnect provider * @num_bus_clks: the total number of bus_clks clk_bulk_data entries + * @num_intf_clks: the total number of intf_clks clk_bulk_data entries * @type: the ICC provider type * @regmap: regmap for QoS registers read/write access * @qos_offset: offset to QoS registers * @bus_clk_rate: bus clock rate in Hz * @bus_clks: the clk_bulk_data table of bus clocks + * @intf_clks: the clk_bulk_data table of interface clocks */ struct qcom_icc_provider { struct icc_provider provider; int num_bus_clks; + int num_intf_clks; enum qcom_icc_type type; struct regmap *regmap; unsigned int qos_offset; - u64 *bus_clk_rate; - struct clk_bulk_data bus_clks[]; + u64 bus_clk_rate[2]; + struct clk_bulk_data bus_clks[2]; + struct clk_bulk_data intf_clks[]; }; /** @@ -93,6 +97,8 @@ struct qcom_icc_desc { size_t num_nodes; const char * const *bus_clocks; size_t num_bus_clocks; + const char * const *intf_clocks; + size_t num_intf_clocks; bool has_bus_pd; enum qcom_icc_type type; const struct regmap_config *regmap_cfg; diff --git a/drivers/interconnect/qcom/msm8996.c b/drivers/interconnect/qcom/msm8996.c index 69fc50a6fa5c..1a5e0ad36cc4 100644 --- a/drivers/interconnect/qcom/msm8996.c +++ b/drivers/interconnect/qcom/msm8996.c @@ -21,21 +21,17 @@ #include "smd-rpm.h" #include "msm8996.h" -static const char * const bus_mm_clocks[] = { - "bus", - "bus_a", +static const char * const mm_intf_clocks[] = { "iface" }; -static const char * const bus_a0noc_clocks[] = { +static const char * const a0noc_intf_clocks[] = { "aggre0_snoc_axi", "aggre0_cnoc_ahb", "aggre0_noc_mpu_cfg" }; -static const char * const bus_a2noc_clocks[] = { - "bus", - "bus_a", +static const char * const a2noc_intf_clocks[] = { "aggre2_ufs_axi", "ufs_axi" }; @@ -1821,8 +1817,8 @@ static const struct qcom_icc_desc msm8996_a0noc = { .type = QCOM_ICC_NOC, .nodes = a0noc_nodes, .num_nodes = ARRAY_SIZE(a0noc_nodes), - .bus_clocks = bus_a0noc_clocks, - .num_bus_clocks = ARRAY_SIZE(bus_a0noc_clocks), + .intf_clocks = a0noc_intf_clocks, + .num_intf_clocks = ARRAY_SIZE(a0noc_intf_clocks), .has_bus_pd = true, .regmap_cfg = &msm8996_a0noc_regmap_config }; @@ -1866,8 +1862,8 @@ static const struct qcom_icc_desc msm8996_a2noc = { .type = QCOM_ICC_NOC, .nodes = a2noc_nodes, .num_nodes = ARRAY_SIZE(a2noc_nodes), - .bus_clocks = bus_a2noc_clocks, - .num_bus_clocks = ARRAY_SIZE(bus_a2noc_clocks), + .intf_clocks = a2noc_intf_clocks, + .num_intf_clocks = ARRAY_SIZE(a2noc_intf_clocks), .regmap_cfg = &msm8996_a2noc_regmap_config }; @@ -2005,8 +2001,8 @@ static const struct qcom_icc_desc msm8996_mnoc = { .type = QCOM_ICC_NOC, .nodes = mnoc_nodes, .num_nodes = ARRAY_SIZE(mnoc_nodes), - .bus_clocks = bus_mm_clocks, - .num_bus_clocks = ARRAY_SIZE(bus_mm_clocks), + .intf_clocks = mm_intf_clocks, + .num_intf_clocks = ARRAY_SIZE(mm_intf_clocks), .regmap_cfg = &msm8996_mnoc_regmap_config }; diff --git a/drivers/interconnect/qcom/sdm660.c b/drivers/interconnect/qcom/sdm660.c index a22ba821efbf..0e8a96f4ce90 100644 --- a/drivers/interconnect/qcom/sdm660.c +++ b/drivers/interconnect/qcom/sdm660.c @@ -127,15 +127,11 @@ enum { SDM660_SNOC, }; -static const char * const bus_mm_clocks[] = { - "bus", - "bus_a", +static const char * const mm_intf_clocks[] = { "iface", }; -static const char * const bus_a2noc_clocks[] = { - "bus", - "bus_a", +static const char * const a2noc_intf_clocks[] = { "ipa", "ufs_axi", "aggre2_ufs_axi", @@ -1516,8 +1512,8 @@ static const struct qcom_icc_desc sdm660_a2noc = { .type = QCOM_ICC_NOC, .nodes = sdm660_a2noc_nodes, .num_nodes = ARRAY_SIZE(sdm660_a2noc_nodes), - .bus_clocks = bus_a2noc_clocks, - .num_bus_clocks = ARRAY_SIZE(bus_a2noc_clocks), + .intf_clocks = a2noc_intf_clocks, + .num_intf_clocks = ARRAY_SIZE(a2noc_intf_clocks), .regmap_cfg = &sdm660_a2noc_regmap_config, }; @@ -1659,8 +1655,8 @@ static const struct qcom_icc_desc sdm660_mnoc = { .type = QCOM_ICC_NOC, .nodes = sdm660_mnoc_nodes, .num_nodes = ARRAY_SIZE(sdm660_mnoc_nodes), - .bus_clocks = bus_mm_clocks, - .num_bus_clocks = ARRAY_SIZE(bus_mm_clocks), + .intf_clocks = mm_intf_clocks, + .num_intf_clocks = ARRAY_SIZE(mm_intf_clocks), .regmap_cfg = &sdm660_mnoc_regmap_config, };