Received: by 10.213.65.68 with SMTP id h4csp2240042imn; Sun, 8 Apr 2018 23:19:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx48WuRNHLBJVvPvdm9kgMkDj/ANBrlgrDXbixTk7OkVZObizV0joJs2Hb1jeFkyDb8XmGRN3 X-Received: by 2002:a17:902:8b81:: with SMTP id ay1-v6mr8296720plb.57.1523254752926; Sun, 08 Apr 2018 23:19:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523254752; cv=none; d=google.com; s=arc-20160816; b=sNpvP6/rvRbIkCQfmYxaOAeiiOQDrpPFrRrIP9n4YD9F7tplDRioqf7FPZ/EbHpVeT QmvC6BnzAmFqpC+yW6TWwP0e6MOabTyaBny9LtO3R9qTu6X7/jFl20MKp6oV36bfNSlx IeVrraddwh1zmIJxIRDO9MaypuvisWXMqUS0dyIc+H/SNt98dv92EK7oOw56eV6fQBAl R31yWjcsL5MbHGXs8PVncX25Q6ukt6Hw68TBnYqmgE3Mt7HYGgUxd8e4WvPw/TncwYmd diP8mDlbn1xHjNFrZTXmrJrI+GXGZWYl0YdAuNTAiiWz3IL+dUEWbEg+nUoUx4YPd2K0 SM5Q== 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:dmarc-filter:dkim-signature:dkim-signature :arc-authentication-results; bh=8X68k7zenX6G8Hy1C0X8YGKEXj7rPIfVbzu7ZTd3+t8=; b=gcb+xqqi2xKaEzllI9RHq1nv2IRK51eniUCNgM05vlWRk8sJ6vSX2DOwZeQm32d8NK oxWC9TFyl60H0q4hxgsT7bDrHpz8R2b6f8S0AfUoTw3Gejxx8y4frwKJ+2SfkB7xqDTr KPpOF2HyrHMVdoPay3+G5kk3J9nMyj9gAUHIFvNZnz8oErosFOFdMdcnWOjwYBYfwbol HJ6Hz5GArCtDOvHXHiuU8qxc3sCYf1HlYm1+o5nsaM74XViUbR7ZU6fIAR3GuDZts0IN wcwY0gI0cXgmGZhaey/hMV1vYU7l3PRD5ORwyFz+nQ6G/pPgiwljwm3pmo/9AMX47bLc 3bBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=gIkXLb8P; dkim=pass header.i=@codeaurora.org header.s=default header.b=JTnuwbdB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r8-v6si16242192pli.12.2018.04.08.23.18.35; Sun, 08 Apr 2018 23:19:12 -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=@codeaurora.org header.s=default header.b=gIkXLb8P; dkim=pass header.i=@codeaurora.org header.s=default header.b=JTnuwbdB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752248AbeDIGP1 (ORCPT + 99 others); Mon, 9 Apr 2018 02:15:27 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:55996 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751669AbeDIGPY (ORCPT ); Mon, 9 Apr 2018 02:15:24 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id CC86860F61; Mon, 9 Apr 2018 06:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523254523; bh=T1D5v55rJeIUu4UZpW+fMA0Pg0qEk+kBVSAcv0zkdPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gIkXLb8PpD1jFMniF7/Voh8KQYadZVKS1tCo1Hgx/6qMvVFQ6gLnGBhhxLrPPjRRy chDf+ki2FYAm9Up5OEapqCqWvqv87SQ5YbYF1M/+baJ1+QEHV04ONadWJkxe+4YcX4 vNC5z4FfAadIAEybZe1pmuL6xaW2P0zcpP8g/2Yk= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from anischal-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: anischal@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id D43266076A; Mon, 9 Apr 2018 06:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1523254522; bh=T1D5v55rJeIUu4UZpW+fMA0Pg0qEk+kBVSAcv0zkdPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JTnuwbdB8jKB+F6GMemIiN1bvCECWbcWtDIv6OXh+B5MDMJSyRGwPsgtYYopE7NuB upaj4kUyjeN5Rydoyh6RgkSMTeUgh9sJOpGYsnLRhVcr3mApr1qEWhAPkC4umVv12r ZyhgbXhf/DhfeuNv90+0foToR7ksZxZTmTbSIcXc= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D43266076A Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=anischal@codeaurora.org From: Amit Nischal To: Stephen Boyd , Michael Turquette Cc: Andy Gross , David Brown , Rajendra Nayak , Odelu Kukatla , Taniya Das , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Amit Nischal Subject: [PATCH v4 2/3] clk: qcom: Configure the RCGs to a safe source as needed Date: Mon, 9 Apr 2018 11:44:52 +0530 Message-Id: <1523254493-5313-3-git-send-email-anischal@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1523254493-5313-1-git-send-email-anischal@codeaurora.org> References: <1523254493-5313-1-git-send-email-anischal@codeaurora.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For some root clock generators, there could be child branches which are controlled by an entity other than application processor subsystem. For such RCGs, as per application processor subsystem clock driver, all of its downstream clocks are disabled and RCG is in disabled state but in reality downstream clocks can be left enabled before. So in this scenario, when RCG is disabled as per clock driver's point of view and when rate scaling request comes before downstream clock enable request, then RCG fails to update its configuration because in reality RCG is on and it expects its new source to alredy be in enable state but in reality new source is off. In order to avoid having the RCG to go into an invalid state, add support to cache the rate of RCG during set_rate(), defer actual RCG configuration update to be done during clk_enable() as at this point of time, both its new parent and safe source will be already enabled and RCG can safely switch to new parent. During clk_disable() request, configure it to safe source as both its parents, safe source and current parent will be enabled and RCG can safely execute a switch. Also add support to have safe configuration frequency table structure for each shared RCG. Signed-off-by: Taniya Das Signed-off-by: Amit Nischal --- drivers/clk/qcom/clk-rcg.h | 7 +- drivers/clk/qcom/clk-rcg2.c | 173 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 178 insertions(+), 2 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg.h b/drivers/clk/qcom/clk-rcg.h index 2a7489a..9d9d59d 100644 --- a/drivers/clk/qcom/clk-rcg.h +++ b/drivers/clk/qcom/clk-rcg.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, The Linux Foundation. All rights reserved. + * Copyright (c) 2013, 2018, The Linux Foundation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -144,8 +144,10 @@ struct clk_dyn_rcg { * @cmd_rcgr: corresponds to *_CMD_RCGR * @mnd_width: number of bits in m/n/d values * @hid_width: number of bits in half integer divider + * @safe_src_index: safe src index value * @parent_map: map from software's parent index to hardware's src_sel field * @freq_tbl: frequency table + * @current_freq: last cached frequency when using branches with shared RCGs * @clkr: regmap clock handle * */ @@ -153,8 +155,10 @@ struct clk_rcg2 { u32 cmd_rcgr; u8 mnd_width; u8 hid_width; + const u8 safe_src_index; const struct parent_map *parent_map; const struct freq_tbl *freq_tbl; + unsigned long current_freq; struct clk_regmap clkr; }; @@ -167,5 +171,6 @@ struct clk_rcg2 { extern const struct clk_ops clk_byte2_ops; extern const struct clk_ops clk_pixel_ops; extern const struct clk_ops clk_gfx3d_ops; +extern const struct clk_ops clk_rcg2_shared_ops; #endif diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index 984de9c..4d971bf 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, The Linux Foundation. All rights reserved. + * Copyright (c) 2013, 2018 The Linux Foundation. All rights reserved. * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and @@ -790,3 +790,174 @@ static int clk_gfx3d_set_rate(struct clk_hw *hw, unsigned long rate, .determine_rate = clk_gfx3d_determine_rate, }; EXPORT_SYMBOL_GPL(clk_gfx3d_ops); + +static int clk_rcg2_set_force_enable(struct clk_hw *hw) +{ + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + const char *name = clk_hw_get_name(hw); + int ret, count; + + /* Force enable bit */ + ret = regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, + CMD_ROOT_EN, CMD_ROOT_EN); + if (ret) + return ret; + + /* wait for RCG to turn ON */ + for (count = 500; count > 0; count--) { + if (clk_rcg2_is_enabled(hw)) + return 0; + + /* Delay for 1usec and retry polling the status bit */ + udelay(1); + } + if (!count) + pr_err("%s: RCG did not turn on\n", name); + + return -ETIMEDOUT; +} + +static int clk_rcg2_clear_force_enable(struct clk_hw *hw) +{ + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + + /* Clear force enable bit */ + return regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, + CMD_ROOT_EN, 0); +} + +static int +clk_rcg2_shared_force_enable_clear(struct clk_hw *hw, unsigned long rate) +{ + int ret; + + ret = clk_rcg2_set_force_enable(hw); + if (ret) + return ret; + + /* set clock rate */ + ret = __clk_rcg2_set_rate(hw, rate, CEIL); + if (ret) + return ret; + + return clk_rcg2_clear_force_enable(hw); +} + +static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + int ret; + + /* + * Return if the RCG is currently disabled. This configuration + * update will happen as part of the RCG enable sequence. + */ + if (!__clk_is_enabled(hw->clk)) { + rcg->current_freq = rate; + return 0; + } + + ret = clk_rcg2_shared_force_enable_clear(hw, rate); + if (ret) + return ret; + + /* Update current frequency with the requested frequency. */ + rcg->current_freq = rate; + + return ret; +} + +static int clk_rcg2_shared_set_rate_and_parent(struct clk_hw *hw, + unsigned long rate, unsigned long parent_rate, u8 index) +{ + return clk_rcg2_shared_set_rate(hw, rate, parent_rate); +} + +static unsigned long +clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) +{ + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + + if (!__clk_is_enabled(hw->clk) && rcg->current_freq) + return rcg->current_freq; + + return rcg->current_freq = clk_rcg2_recalc_rate(hw, parent_rate); +} + +static unsigned long clk_rcg2_get_safe_src_rate(struct clk_hw *hw) +{ + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + int index; + + index = qcom_find_src_index(hw, rcg->parent_map, rcg->safe_src_index); + if (index < 0) + index = 0; + + return clk_hw_get_rate(clk_hw_get_parent_by_index(hw, index)); +} + +static int clk_rcg2_shared_enable(struct clk_hw *hw) +{ + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + struct freq_tbl safe_src_freq_tbl = { 0 }; + + safe_src_freq_tbl.freq = clk_rcg2_get_safe_src_rate(hw); + + if (rcg->current_freq == safe_src_freq_tbl.freq) { + safe_src_freq_tbl.src = rcg->safe_src_index; + /* + * Reconfigure the RCG - Incase if any other sub system updates + * the div or src without the knowledge of application processor + * subsystem and RCG could run at different rate other than + * software cached rate. + */ + clk_rcg2_set_force_enable(hw); + clk_rcg2_configure(rcg, &safe_src_freq_tbl); + clk_rcg2_clear_force_enable(hw); + + return 0; + } + + /* + * Switch from safe source to the stashed mux selection. The current + * parent has already been prepared and enabled at this point, and + * the safe source is always on while application processor subsystem + * is online. Therefore, the RCG can safely switch its source. + */ + + return clk_rcg2_shared_force_enable_clear(hw, rcg->current_freq); +} + +static void clk_rcg2_shared_disable(struct clk_hw *hw) +{ + struct clk_rcg2 *rcg = to_clk_rcg2(hw); + struct freq_tbl safe_src_freq_tbl = { 0 }; + + safe_src_freq_tbl.src = rcg->safe_src_index; + safe_src_freq_tbl.freq = clk_rcg2_get_safe_src_rate(hw); + + /* + * Park the RCG at a safe configuration - sourced off from safe source. + * Force enable and disable the RCG while configuring it to safeguard + * against any update signal coming from the downstream clock. + * The current parent is still prepared and enabled at this point, and + * the safe source is always on while application processor subsystem + * is online. Therefore, the RCG can safely switch its parent. + */ + clk_rcg2_set_force_enable(hw); + clk_rcg2_configure(rcg, &safe_src_freq_tbl); + clk_rcg2_clear_force_enable(hw); +} + +const struct clk_ops clk_rcg2_shared_ops = { + .enable = clk_rcg2_shared_enable, + .disable = clk_rcg2_shared_disable, + .get_parent = clk_rcg2_get_parent, + .set_parent = clk_rcg2_set_parent, + .recalc_rate = clk_rcg2_shared_recalc_rate, + .determine_rate = clk_rcg2_determine_rate, + .set_rate = clk_rcg2_shared_set_rate, + .set_rate_and_parent = clk_rcg2_shared_set_rate_and_parent, +}; +EXPORT_SYMBOL_GPL(clk_rcg2_shared_ops); -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation