Received: by 10.223.164.221 with SMTP id h29csp3520409wrb; Tue, 31 Oct 2017 00:21:37 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TNbk0xsQmII9xLiOHLIdNW766zDaZ5vwp/zvmhPDLij0NBB6s3kDArM5HunM41ebTRCsio X-Received: by 10.101.100.6 with SMTP id a6mr842341pgv.288.1509434497538; Tue, 31 Oct 2017 00:21:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509434497; cv=none; d=google.com; s=arc-20160816; b=epnJJqloxFaAJ2T1tJfxEWceBjiza+AZsnw/ElCxGT/ctWcaVJuAp5lBcFArOexecW 0Q1sEQO++E3X6dVKhwwUHLSqicNV+DzJxPeWi2VEuKFPA244kF04CnkvAWuch9NUjUdk iImUzCXKpt8Go+U6rBM26QbzeG1JpAkzYU+tl+CaknYu3X36sUniSa30vIyRyye81kfO 1W+2cC6BaI5haaxS9chj99dUzXPWSp1chgAlhlBCUm8C5YQbVw299M3HoBj/wg5Tl+19 YuwBH9aTxblMl5py1X3AXKEpYgcYJLsKqNEem2RJz1MDqQUc8Uwgrr/37T91P78zrSOI 4m2Q== 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=eXt74JLcom8l8kk1oOK5nkGEGD9MCNfvExBGHI04WgY=; b=NTBXql1fW0gzz+sUwmgJj2DEk72P8bUxWHRYddYn3SjpK56JjPZrhblIjTVJB0pRM8 pntjUy8eDHQyqGsFi3e/Bp7mhagwipsbPdftlmRyMwmUy16goNk2GDwP1ejhMfExH1CH NuLXV4JN7A+gAzPDEx0BGzh+xoQEW2BmVxgRv2AuHsCjMh2Tb1PT1bOAzubGEE73gUB+ OJEZi15VtUCkZ3xvBT7WI3LZhzKY4+mKW2ZeAWuG8g5wIkKC1/zasdNJmaieUJ3RyTx1 xr2yHhPIfBfvt2LaOoxxnDwzHwZdBTqKeAao6ZfiuskQamqRXZISyJ5sPmHkO2WbuSnN Cefg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=AvvqLlE+; dkim=pass header.i=@codeaurora.org header.s=default header.b=hiva1x8F; 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 p25si867738pgn.126.2017.10.31.00.21.24; Tue, 31 Oct 2017 00:21:37 -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=AvvqLlE+; dkim=pass header.i=@codeaurora.org header.s=default header.b=hiva1x8F; 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 S1753237AbdJaHUe (ORCPT + 99 others); Tue, 31 Oct 2017 03:20:34 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:55370 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753040AbdJaHU3 (ORCPT ); Tue, 31 Oct 2017 03:20:29 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 629376050D; Tue, 31 Oct 2017 07:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1509434429; bh=2UXqNPqxflYhrH1ScfCs0dz9h3bJQvrult2hYoS0qdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AvvqLlE+NflRzsw82R4/XfNgHh9OZx9PE3TAUfU8e+jXQHTnQS4BQJh+DptbMnjoI 9eCvalFsJebI1XMEVcJg6qeMZ0GcZasIGVBhxPsS/sKnwiyEiXFxDDleZm11hH2Qbr MHo6tPZ8oQR7ppvPF62Bse/AaygyvDt4ifm4tcV4= 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 CC1B26050D; Tue, 31 Oct 2017 07:20:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1509434424; bh=2UXqNPqxflYhrH1ScfCs0dz9h3bJQvrult2hYoS0qdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hiva1x8FkN1RgmybG2qJhyWCcdnameS06Qh1hFo42Eak+1KZnm6yAHAp7UOO+LNbU jP8b6V7XNAgakHTeK08Of3OQZgGKPsfVxNfF9drUpfcoJAmJip8MC7FDmH2GGTOm8j rv6LizQClI7ydNKwMSQt79J3ccAML/Hhc5r1KYWU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org CC1B26050D 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 , 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 2/2] clk: qcom: Modify RCG shared ops to support freq_tbl without XO entry Date: Tue, 31 Oct 2017 12:49:40 +0530 Message-Id: <1509434380-24372-3-git-send-email-anischal@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1509434380-24372-1-git-send-email-anischal@codeaurora.org> References: <1509434380-24372-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 There could be some clock sources where there is no entry corresponding XO in their frequency table, for such sources rcg2_shared_ops would wrongly configure the RCG registers during enable/disable, which leads to mismatch between the hardware and software rate so modify the shared ops to handle such cases. Signed-off-by: Amit Nischal --- drivers/clk/qcom/clk-rcg2.c | 79 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 9 deletions(-) diff --git a/drivers/clk/qcom/clk-rcg2.c b/drivers/clk/qcom/clk-rcg2.c index ac9ce61..8f7ca0c 100644 --- a/drivers/clk/qcom/clk-rcg2.c +++ b/drivers/clk/qcom/clk-rcg2.c @@ -48,6 +48,14 @@ #define N_REG 0xc #define D_REG 0x10 +static struct freq_tbl cxo_f = { + .freq = 19200000, + .src = 0, + .pre_div = 1, + .m = 0, + .n = 0, +}; + enum freq_policy { FLOOR, CEIL, @@ -359,7 +367,7 @@ static int clk_rcg2_set_floor_rate_and_parent(struct clk_hw *hw, }; EXPORT_SYMBOL_GPL(clk_rcg2_floor_ops); -static int clk_rcg2_shared_force_enable(struct clk_hw *hw, unsigned long rate) +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); @@ -373,22 +381,41 @@ static int clk_rcg2_shared_force_enable(struct clk_hw *hw, unsigned long rate) /* wait for RCG to turn ON */ for (count = 500; count > 0; count--) { - ret = clk_rcg2_is_enabled(hw); - if (ret) - break; + 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 RCG */ + return regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, + CMD_ROOT_EN, 0); +} + +static int clk_rcg2_shared_force_enable(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; - /* clear force enable RCG */ - return regmap_update_bits(rcg->clkr.regmap, rcg->cmd_rcgr + CMD_REG, - CMD_ROOT_EN, 0); + return clk_rcg2_clear_force_enable(hw); } static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate, @@ -399,6 +426,11 @@ static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate, /* cache the rate */ rcg->current_freq = rate; + /* + * 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)) return 0; @@ -410,6 +442,12 @@ static int clk_rcg2_shared_set_rate(struct clk_hw *hw, unsigned long rate, { struct clk_rcg2 *rcg = to_clk_rcg2(hw); + if (!__clk_is_enabled(hw->clk)) { + if (!rcg->current_freq) + rcg->current_freq = cxo_f.freq; + return rcg->current_freq; + } + return rcg->current_freq = clk_rcg2_recalc_rate(hw, parent_rate); } @@ -417,6 +455,20 @@ static int clk_rcg2_shared_enable(struct clk_hw *hw) { struct clk_rcg2 *rcg = to_clk_rcg2(hw); + if (rcg->current_freq == cxo_f.freq) { + clk_rcg2_set_force_enable(hw); + clk_rcg2_configure(rcg, &cxo_f); + clk_rcg2_clear_force_enable(hw); + + return 0; + } + + /* + * Switch from CXO to the stashed mux selection. The current + * parent has already been prepared and enabled at this point, + * and the CXO source is always on while application processor + * subsystem is online. Therefore, the RCG can safely be switched. + */ return clk_rcg2_shared_force_enable(hw, rcg->current_freq); } @@ -424,8 +476,17 @@ static void clk_rcg2_shared_disable(struct clk_hw *hw) { struct clk_rcg2 *rcg = to_clk_rcg2(hw); - /* switch to XO, which is the lowest entry in the freq table */ - clk_rcg2_shared_set_rate(hw, rcg->freq_tbl[0].freq, 0); + /* + * Park the RCG at a safe configuration - sourced off the CXO. + * 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 CXO source is always on while application processor + * subsystem is online. Therefore, the RCG can safely be switched. + */ + clk_rcg2_set_force_enable(hw); + clk_rcg2_configure(rcg, &cxo_f); + clk_rcg2_clear_force_enable(hw); } const struct clk_ops 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 From 1585307876516009024@xxx Tue Nov 28 11:10:05 +0000 2017 X-GM-THRID: 1585307876516009024 X-Gmail-Labels: Inbox,Category Promotions,HistoricalUnread