From patchwork Thu Jun 14 21:53:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia Lin X-Patchwork-Id: 10465377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0020960348 for ; Thu, 14 Jun 2018 21:59:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DE43A28B1E for ; Thu, 14 Jun 2018 21:59:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0D2828B9B; Thu, 14 Jun 2018 21:59:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 72EDB28B1E for ; Thu, 14 Jun 2018 21:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=mAFt6Iydbc1RShDB2n+t3Gh2RL7/bjJG+4mTUEUZWVE=; b=MqDSxQB7465D404VmJPOALgQvS XMMr0oG3Wn7O9ioaMPnyQhU96jv5z9Y8MonjnMxaf+svcaBg8ljLdQbV3c8nDrvf8lQafxRcQPmJW 0QZTkT5JOG8X/MLVyubR7EPVkAm6/131qoIQFfMreS2fzO9ajJhgIvI7WWRd8FlSJAs0BjxrVC9qs 1ASb+Y2+Iv0AiY5Wspqx1IVnWIlVQ3ySv+Kg+8eUYba0/D8fa91zfJ6DHMmLihyrrg9gqb/KR+Exk eQXmK7d5RTX2679VS0cajTZ476MOp3vaJUW6HLNyGZKWQkYsJ7+68I2TIGK9a9hUrbUpiSZBcV5F2 /65kSd0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTaH8-0004Qp-3X; Thu, 14 Jun 2018 21:59:26 +0000 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fTaDh-0001wq-AD for linux-arm-kernel@lists.infradead.org; Thu, 14 Jun 2018 21:56:53 +0000 Received: by mail-wr0-x242.google.com with SMTP id w10-v6so7938020wrk.9 for ; Thu, 14 Jun 2018 14:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NA6D8yIX1YmkRdYhsjqPAYpG4ug++O5i6Tz0TH/uadU=; b=F6s01LQ4bya7W7YWgyQxW/AlN++9ap+4GjsMWMbEufrJl+bdZtVxB9MBVvhRfuTqMa 7a2zh0fXvnUBmsPbYza/6YR/rjE5dxIdjg/ck7ONz4AgTf7R2L8y6c4Zo31XFXk0VmNM dU6499+iXxBl/YhEHowz8rPJR4qF97qP67FAwxrnVnV1pgIRd2y56sE5hlhnNotEtGzP K5uywM3NzxQU/CwnpKzXXUaZ9+s4M0ot9KJerGOmdBu7nJzUR06p1hH5UP5ijk9telcO 6G2ZoPIpgY7T7l3QPH6GXlzmlWnC3Bv3j8+3tkZEqctFxVoEe9ApDhvXxQ6owAmy3Ysl IMMA== 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=NA6D8yIX1YmkRdYhsjqPAYpG4ug++O5i6Tz0TH/uadU=; b=HWGHKL+a6zYef0TMsJ7tDWMEbfPRVe16q2XbyLiwTcBlJlwPjSpRkb4ACMDOdUvXjt BYX05RcY4EYdnh2qHI0MMRMHx4OfOftKbm+dqHrCemNgkpmzUUVxDddxTlokRxnUE54K 3/ZoTvqrWdbpbq8i15s4/jTTnHJzehCTFtUdnQKD3He7ls8v4Bw4XZe/1J1GLJ+w6nSR j9c8Kq2lAVfuQf+aSNks/zMl4YbnQLp3kfRLRAq2zHeCP64+L7ZVJp04kspzmwdSLJae 2u1s5uQpU+YI0R7WThCMg3Kir0V+OwrTzDtl2cJfvwHTrdzD39leTBio/Dwwb9SmPJRy vhoA== X-Gm-Message-State: APt69E1xgYUmvJ852fPMkX9OEDItz638twFqxbo1GF/jiKM2RFq53gDH rxqx2l4/lHjRdFSm3pOOLaY= X-Google-Smtp-Source: ADUXVKK5wnENNaneEM4uONiCN5VyZC3i+rH8/Zp7Qvi6EM+8Vv6LK32UQzbTPFzWQJQZteY8wVMYZA== X-Received: by 2002:adf:eb0c:: with SMTP id s12-v6mr4026105wrn.174.1529013340817; Thu, 14 Jun 2018 14:55:40 -0700 (PDT) Received: from gcc67.tetaneutral.net (gcc67.tetaneutral.net. [2a03:7220:8080:c00::1]) by smtp.gmail.com with ESMTPSA id i76-v6sm285367wmd.20.2018.06.14.14.55.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Jun 2018 14:55:40 -0700 (PDT) From: ilia.lin@gmail.com To: ilia.lin@gmail.com Subject: [PATCH v13 7/8] clk: qcom: cpu-8996: Add support to switch below 600Mhz Date: Thu, 14 Jun 2018 23:53:54 +0200 Message-Id: <20180614215358.11264-8-ilia.lin@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180614215358.11264-1-ilia.lin@gmail.com> References: <20180614215358.11264-1-ilia.lin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180614_145553_384785_D9933319 X-CRM114-Status: GOOD ( 18.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Rajendra Nayak , Stephen Boyd , linux-arm-msm@vger.kernel.org, Michael Turquette , Will Deacon , linux-kernel@vger.kernel.org, Amit Kucheria , David Brown , Rob Herring , Ilia Lin , Andy Gross , linux-soc@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rajendra Nayak The CPU clock controller's primary PLL operates on a single VCO range, between 600MHz and 3GHz. However the CPUs do support OPPs with frequencies between 300MHz and 600MHz. In order to support running the CPUs at those frequencies we end up having to lock the PLL at twice the rate and drive the CPU clk via the PLL/2 output and SMUX. So for frequencies above 600MHz we follow the following path Primary PLL --> PLL_EARLY --> PMUX(1) --> CPU clk and for frequencies between 300MHz and 600MHz we follow Primary PLL --> PLL/2 --> SMUX(1) --> PMUX(0) --> CPU clk Signed-off-by: Rajendra Nayak Signed-off-by: Ilia Lin Tested-by: Amit Kucheria --- drivers/clk/qcom/clk-cpu-8996.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/clk/qcom/clk-cpu-8996.c b/drivers/clk/qcom/clk-cpu-8996.c index 620fdc2266ba..ff5c0a5740d2 100644 --- a/drivers/clk/qcom/clk-cpu-8996.c +++ b/drivers/clk/qcom/clk-cpu-8996.c @@ -68,6 +68,8 @@ enum _pmux_input { NUM_OF_PMUX_INPUTS }; +#define DIV_2_THRESHOLD 600000000 + static const u8 prim_pll_regs[PLL_OFF_MAX_REGS] = { [PLL_OFF_L_VAL] = 0x04, [PLL_OFF_ALPHA_VAL] = 0x08, @@ -95,10 +97,11 @@ static const u8 alt_pll_regs[PLL_OFF_MAX_REGS] = { static const struct alpha_pll_config hfpll_config = { .l = 60, - .config_ctl_val = 0x200d4828, + .config_ctl_val = 0x200d4aa8, .config_ctl_hi_val = 0x006, .pre_div_mask = BIT(12), .post_div_mask = 0x3 << 8, + .post_div_val = 0x1 << 8, .main_output_mask = BIT(0), .early_output_mask = BIT(3), }; @@ -140,7 +143,7 @@ static const struct alpha_pll_config altpll_config = { .vco_mask = 0x3 << 20, .config_ctl_val = 0x4001051b, .post_div_mask = 0x3 << 8, - .post_div_val = 0x1, + .post_div_val = 0x1 << 8, .main_output_mask = BIT(0), .early_output_mask = BIT(3), }; @@ -181,6 +184,7 @@ struct clk_cpu_8996_mux { u8 width; struct notifier_block nb; struct clk_hw *pll; + struct clk_hw *pll_div_2; struct clk_regmap clkr; }; @@ -226,6 +230,13 @@ clk_cpu_8996_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) struct clk_cpu_8996_mux *cpuclk = to_clk_cpu_8996_mux_hw(hw); struct clk_hw *parent = cpuclk->pll; + if (cpuclk->pll_div_2 && req->rate < DIV_2_THRESHOLD) { + if (req->rate < (DIV_2_THRESHOLD / 2)) + return -EINVAL; + + parent = cpuclk->pll_div_2; + } + req->best_parent_rate = clk_hw_round_rate(parent, req->rate); req->best_parent_hw = parent; @@ -237,13 +248,19 @@ int cpu_clk_notifier_cb(struct notifier_block *nb, unsigned long event, { int ret; struct clk_cpu_8996_mux *cpuclk = to_clk_cpu_8996_mux_nb(nb); + struct clk_notifier_data *cnd = data; switch (event) { case PRE_RATE_CHANGE: ret = clk_cpu_8996_mux_set_parent(&cpuclk->clkr.hw, ALT_INDEX); break; case POST_RATE_CHANGE: - ret = clk_cpu_8996_mux_set_parent(&cpuclk->clkr.hw, PLL_INDEX); + if (cnd->new_rate < DIV_2_THRESHOLD) + ret = clk_cpu_8996_mux_set_parent(&cpuclk->clkr.hw, + DIV_2_INDEX); + else + ret = clk_cpu_8996_mux_set_parent(&cpuclk->clkr.hw, + PLL_INDEX); break; default: ret = 0; @@ -295,6 +312,7 @@ static struct clk_cpu_8996_mux pwrcl_pmux = { .shift = 0, .width = 2, .pll = &pwrcl_pll.clkr.hw, + .pll_div_2 = &pwrcl_smux.clkr.hw, .nb.notifier_call = cpu_clk_notifier_cb, .clkr.hw.init = &(struct clk_init_data) { .name = "pwrcl_pmux", @@ -315,6 +333,7 @@ static struct clk_cpu_8996_mux perfcl_pmux = { .shift = 0, .width = 2, .pll = &perfcl_pll.clkr.hw, + .pll_div_2 = &perfcl_smux.clkr.hw, .nb.notifier_call = cpu_clk_notifier_cb, .clkr.hw.init = &(struct clk_init_data) { .name = "perfcl_pmux",