Received: by 10.213.65.68 with SMTP id h4csp3276953imn; Tue, 3 Apr 2018 01:54:45 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+7j7KDBAl1+bEPReV/v1lWFkX80AKZtzBN9GaN89WvDMffcK8b7xL5H6dD83bch+RmCXVv X-Received: by 10.101.100.132 with SMTP id e4mr8548215pgv.240.1522745685725; Tue, 03 Apr 2018 01:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522745685; cv=none; d=google.com; s=arc-20160816; b=fewpTuUeIv4M/DvRZTFn7tTYZP1Oo2EgW+a0pox+KPa5lp7v4YH39lYCnSIlH/4SBD VFSAciyD/T5+bhyPV1YZ20UIBaHWdCYoobnlDbjwcbB/oozru6qqdI6UOAURl8C3grhu s3QAE2dfj+s5HwggFnLOM30VANYN1pbe7K9P1vKoytHo3QVlcYOrJiP+VnSrt3M+51OJ z0AC04F6kufNipQeJUlq8ZzMyaPrlGsWpj6A+a2a+G8k/MMfPPbk7QEOynw9a4Htnhfb 0+Ce9YTnTv+MztsR2Zq+OFmtmgtSjcyb9FwegRDzsr1vFbVuu6sIm3Gq0Tp4FJVB+ufE Il2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=JqGBQHqC/5Bnlo/kDdLpDEOBPkB0ImMYJL3RP7yV7s0=; b=qUcmXavxD0qn+kcD6TOgfJiK2vxtFDI4lcETXbPAK0ynIFxzzUukf/6ooyZoNkvwfj IHtXPZ9O6wTRqTgG1vasAuJi8UNIBz4eocUXyqUSLe9qctA8krVSWvEU2gH70v7wTk7u p2PNPQkCGAxQzcJwoBerNyjenVHqLkrJLWYNNpb0relBR+1l4CumP5fff7l+egtDr19j DSvitLXU3nf+YaAn2VI5P065Xyl06Wgr9TobGzFbLOt3So+LSZ3T7i/ir78DIbB24cx9 oApDjUOcePhHOMG3Y1+Fb8u0wKm2KHANQ1v7C0pSzGwo4XLtbNaEUDu5DftxtNmocxxI uKBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=VthCEz+w; dkim=pass header.i=@codeaurora.org header.s=default header.b=TY3g/x9l; 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 l6si1601125pgq.562.2018.04.03.01.54.31; Tue, 03 Apr 2018 01:54:45 -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=VthCEz+w; dkim=pass header.i=@codeaurora.org header.s=default header.b=TY3g/x9l; 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 S1755380AbeDCIwv (ORCPT + 99 others); Tue, 3 Apr 2018 04:52:51 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:54546 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755154AbeDCIwt (ORCPT ); Tue, 3 Apr 2018 04:52:49 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6EC11602BA; Tue, 3 Apr 2018 08:52:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1522745568; bh=WYYkP2vZ2952Br1+HIOib5r++AOC3AaJ5TN8bzXH7E8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VthCEz+wnOEE53/02FaNRj8DaeQSuRkdnUo0RBUV3rs0DAO9WGAIGoB4j85a0s4Sa tk4MTcfKUporWUpcbu0p6f4c9W0p94BS2l7RqtDAAsuOepOKT7AkTMihm8ePH3m8BT pL9Z7K02uG397GzkMYDZRSxZ0dE2a2bP6bd4FlzU= 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 mail.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 16855602BA; Tue, 3 Apr 2018 08:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1522745567; bh=WYYkP2vZ2952Br1+HIOib5r++AOC3AaJ5TN8bzXH7E8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TY3g/x9lFa3ip7tn+TdeaG548pW/gTfz9qpBJyTpqK6Md/ink0F/23o1LoaIglhGf 6HyBRdq4YpLp8F1s1Dpso+Z1R/FO7VKDWkwYnEn5b0TwY3ihqWM4hh6+AuprsK/1Ku IU2+jqoDMfFzjK4HRGosMFAjXfZwe3N9KHk96pz4= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Tue, 03 Apr 2018 14:22:47 +0530 From: Amit Nischal To: Stephen Boyd Cc: Michael Turquette , Stephen Boyd , 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, linux-clk-owner@vger.kernel.org Subject: Re: [PATCH v2 2/4] clk: qcom: Configure the RCGs to a safe source as needed In-Reply-To: <152150582284.254778.15552235408861080239@swboyd.mtv.corp.google.com> References: <1520493495-3084-1-git-send-email-anischal@codeaurora.org> <1520493495-3084-3-git-send-email-anischal@codeaurora.org> <152150582284.254778.15552235408861080239@swboyd.mtv.corp.google.com> Message-ID: <07dbf890975c1178bc4cc2360c25526a@codeaurora.org> X-Sender: anischal@codeaurora.org User-Agent: Roundcube Webmail/1.2.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-03-20 06:00, Stephen Boyd wrote: > Quoting Amit Nischal (2018-03-07 23:18:13) >> 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 >> actual >> downstream clocks can be left enabled before. > > s/actual/reality? Thanks for the review. I will address this in next patch series. > >> >> 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 actual >> RCG > > s/actual/reality? > I will address this in next patch series. >> is on and it expects its new source to alredy in enable state but in > > s/alredy/already be/ I will address this in next patch series. > >> reality new source is in off state. In order to avoid letting the RCG >> to > > s/is in off state/is off/ > s/letting/having/ I will address this in next patch series. > >> go into an invalid state, add support to just cache the rate of RCG >> during > > s/just// I will address this in next patch series. > >> 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 >> --- >> diff --git a/drivers/clk/qcom/clk-rcg.h b/drivers/clk/qcom/clk-rcg.h >> index 2a7489a..205fa34 100644 >> --- a/drivers/clk/qcom/clk-rcg.h >> +++ b/drivers/clk/qcom/clk-rcg.h >> @@ -146,6 +146,9 @@ struct clk_dyn_rcg { >> * @hid_width: number of bits in half integer divider >> * @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 >> + * @safe_src_freq_tbl : frequency table of safe source when using >> branches >> + * with shared RCGs >> * @clkr: regmap clock handle >> * >> */ >> @@ -155,6 +158,8 @@ struct clk_rcg2 { >> u8 hid_width; >> const struct parent_map *parent_map; >> const struct freq_tbl *freq_tbl; >> + unsigned long current_freq; >> + const struct freq_tbl *safe_src_freq_tbl; > > Can we store safe_src index instead? And then construct the frequency > table entry on the fly at the call site? I think it would greatly > clarify that we don't really care about the rate of the clk at all. > Instead, all we care about is making sure the mux is set to whatever > source selection can provide an always on signal. > We will address the above in the V3 series of the patch set. We will be generating the safe frequency table on the fly taking the safe source frequency index input from the RCG clock. >> struct clk_regmap clkr; >> }; >> >> @@ -167,5 +172,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 e63db10..a52de54 100644 >> --- a/drivers/clk/qcom/clk-rcg2.c >> +++ b/drivers/clk/qcom/clk-rcg2.c >> @@ -790,3 +790,158 @@ static int clk_gfx3d_set_rate(struct clk_hw *hw, >> unsigned long rate, >> .determine_rate = clk_gfx3d_determine_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)) { >> + if (!rcg->current_freq) { >> + if (!clk_rcg2_get_parent(hw)) > > This is checking for 0 source selection of parent? So basically if > source is XO selected then return what we know is the XO speed? We > should be able to do that by returning parent_rate though? > >> + rcg->current_freq = >> + rcg->safe_src_freq_tbl->freq; >> + else >> + rcg->current_freq = >> + clk_rcg2_recalc_rate(hw, >> parent_rate); >> + } >> + >> + return rcg->current_freq; >> + } >> + >> + return rcg->current_freq = clk_rcg2_recalc_rate(hw, >> parent_rate); > > I don't get this function. > > To simplify just return cached rate if it's set and clk is off, > otherwise read the hardware? > > if (!__clk_is_enabled(hw->clk) && rcg->current_freq) > return rcg->current_freq; > > return clk_rcg2_recalc_rate(hw, parent_rate); > > I would also rename current_freq to something like cached_freq and then > *only* assign it when someone calls clk_set_rate() (and save around the > frequency table pointer instead of raw frequency). Out of boot, we will > return the right frequency and clk_set_rate() called before enable will > cache the rate to what we want. Thanks for your valuable suggestion. We will fix this in the next patch series. But we would like to have one modification i.e. to update the current_freq value with the clk_rcg2_recalc_rate(). Reason for the same is given below. So the final logic would be: static unsigned long clk_rcg2_shared_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { ... if (!__clk_is_enabled(hw->clk) && rcg->current_freq) return rcg->current_freq; return rcg->current_freq = clk_rcg2_recalc_rate(hw, parent_rate); } Updation of current_freq is required in recalc_rate() because in a case where clk_enable() is called before the set_rate()[which actually updates the current_freq] then inside the clk_rcg2_shared_enable(), current_freq value will be 0 and clk_rcg2_shared_force_enable_clear() will configure the RCG with the first frequency entry in the frequency table and RCG will get enable at rate which BOOT has not configured. > >> +} >> + >> +static int clk_rcg2_shared_enable(struct clk_hw *hw) >> +{ >> + struct clk_rcg2 *rcg = to_clk_rcg2(hw); >> + >> + if (rcg->current_freq == rcg->safe_src_freq_tbl->freq) { >> + clk_rcg2_set_force_enable(hw); >> + clk_rcg2_configure(rcg, 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); > > Not much is different between clk_rcg2_shared_force_enable_clear() and > the three lines above inside that if condition. The only difference is > we don't search for a rate in the frequency table. Ugh, but we can't > change the frequency table because of hw clk control stuff that relies > on the table in software matching the table in hardware? Sad. > > Can we at least change the if condition above to be something like: > > if (rcg->force_safe_src) { > clk_rcg2_set_force_enable(... > > And then set the force_safe_src bool when we want enable to skip normal > rate restoration behavior? We should be able to use that flag in other > places too, like where we check for the clk being enabled in software > or > not. As per the new implementation in V3 series, we think there is no need to have one new flag. > >> +} >> + >> +static void clk_rcg2_shared_disable(struct clk_hw *hw) >> +{ >> + struct clk_rcg2 *rcg = to_clk_rcg2(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, rcg->safe_src_freq_tbl); >> + clk_rcg2_clear_force_enable(hw); >> +} >> + > > Yeah, all this stuff would get simpler if we stopped using frequencies. > Hopefully I made sense! > > -- > To unsubscribe from this list: send the line "unsubscribe linux-clk" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html