From patchwork Fri Dec 8 09:29:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 10102065 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 E408060360 for ; Fri, 8 Dec 2017 09:49:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D672A28B45 for ; Fri, 8 Dec 2017 09:49:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAEC828B8C; Fri, 8 Dec 2017 09:49:45 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 652D628B45 for ; Fri, 8 Dec 2017 09:49:45 +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=v+A5XM0VqlaUuw8ur/KQJASoImP5qzi8Misb+7HHoas=; b=c3acwAB8lh4jcDboIW0otpEatE 4YkoDjYKAarCekxz8ySxe8+DRWPbiEyFHKQ8NtunSwMLneJ3rSRdlitXbrOge/G7qnA8P+u/wqDI8 qHGooN+RvlyMPsgfdjZQdinjyzaTNxNN7P00+NpvVcIZID9xT+O9TeiNkIVuMLTEd4nHwZM9x/jLk KfGIaxfT/XJXaVwwYiMqiFiRw9W1Z0+JRbp1AQO7cLepMVEn4N4VYOeVRNNSJOzCYx129KEl6/UKE aRyqzsHxvr79+Kg485pKFZ9g27IpAqBwxzZ6Ntg9JnDAWfhj3UkIy/mqbpB7nb6KzeDzN9GZSGAWY QLbsW5Zg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eNFHs-0000zN-Ji; Fri, 08 Dec 2017 09:49:44 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eNFFl-0007Zi-RB for linux-arm-kernel@bombadil.infradead.org; Fri, 08 Dec 2017 09:47:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=//jguEBZiPipl7FSUv/KJ6UF5x/QI5gWr1ZSArGzzEQ=; b=p3D2xheLCA4lz1S94bm5nIuVv rHOtp3KO1/Gi6afOMblkptWYDsOX/Djii23u/QjvzFqGbieiACx5bNxzfrWvu+zeARmtwT2Cd0pNP ZBnDDctix1ikikv4BNF9Qa96dY1ma8SWaofbxTWRRboSUZ0kx4TXpIjLWgtCv+AC0nJY4HrwVPBHX 8P43YVE9qM63sVP88sq9VGaGQ1nArmvz1pp0yS36IQpwVvLy4lGPYltUsYWYFhy5wipTa1B+AlFsg k3cmSHncLZYyvTSmfs+fZYvEUYBUf00d3SGdPioZ6zrKLSME5jFA0FqxTZ6g3153V7HidWda4tiWq crIVEZf4A==; Received: from smtp.codeaurora.org ([198.145.29.96]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eNF0F-0007Og-4K for linux-arm-kernel@lists.infradead.org; Fri, 08 Dec 2017 09:31:33 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A93D0607EA; Fri, 8 Dec 2017 09:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1512725468; bh=iF+v/R5byar7MdydxH9bLf2k2+twli+p5OGR7WOGHGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PgklH56kScS+zN/b0ByiV8BDqyCQQmtDujDL7YqfI5aecnUiq7wBdjy5BobYPU27p TzupzYDd4pLBKasbqGccNt/GqRoeteIlLu6qEeV/mXFFmCtnIUQOUFGQMC//cpJE49 XHvT05RoxS1BAeOOw5oooNMYQ2y/rcFhn202I2aM= Received: from srichara-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: sricharan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3EB85608BA; Fri, 8 Dec 2017 09:31:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1512725467; bh=iF+v/R5byar7MdydxH9bLf2k2+twli+p5OGR7WOGHGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OgyELC/DTv/meem1KB8RxcDgxnjSE6bjQ1A4JN66u7aIq5yuQ0QDQ28A/17JaN/ry xOh7K/m7LD/0THJfPIzzyAg0KogD2I3WGFfrddw75ZehZ8wsM2PHxbplkafZ2OyKHR lp3tZnXD/I+IFywCIg6Uy9SOV6lcD6l/MA/IQ8J8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3EB85608BA 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=sricharan@codeaurora.org From: Sricharan R To: mturquette@linaro.org, sboyd@codeaurora.org, devicetree@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, viresh.kumar@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 10/12] clk: qcom: Add safe switch hook for krait mux clocks Date: Fri, 8 Dec 2017 14:59:59 +0530 Message-Id: <1512725401-4944-11-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1512725401-4944-1-git-send-email-sricharan@codeaurora.org> References: <1512725401-4944-1-git-send-email-sricharan@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171208_093131_450138_DB875804 X-CRM114-Status: GOOD ( 23.93 ) 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: sricharan@codeaurora.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 When the Hfplls are reprogrammed during the rate change, the primary muxes which are sourced from the same hfpll for higher frequencies, needs to be switched to the 'safe secondary mux' as the parent for that small window. This is done by registering a clk notifier for the muxes and switching to the safe parent in the PRE_RATE_CHANGE notifier and back to the original parent in the POST_RATE_CHANGE notifier. Signed-off-by: Sricharan R --- drivers/clk/qcom/clk-krait.c | 2 ++ drivers/clk/qcom/clk-krait.h | 3 +++ drivers/clk/qcom/krait-cc.c | 56 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/drivers/clk/qcom/clk-krait.c b/drivers/clk/qcom/clk-krait.c index 6099307..1627a6e 100644 --- a/drivers/clk/qcom/clk-krait.c +++ b/drivers/clk/qcom/clk-krait.c @@ -60,6 +60,8 @@ static int krait_mux_set_parent(struct clk_hw *hw, u8 index) if (__clk_is_enabled(hw->clk)) __krait_mux_set_sel(mux, sel); + mux->reparent = true; + return 0; } diff --git a/drivers/clk/qcom/clk-krait.h b/drivers/clk/qcom/clk-krait.h index af89782..f9e1279 100644 --- a/drivers/clk/qcom/clk-krait.h +++ b/drivers/clk/qcom/clk-krait.h @@ -23,6 +23,9 @@ struct krait_mux_clk { u32 shift; u32 en_mask; bool lpl; + u8 safe_sel; + u8 old_index; + bool reparent; struct clk_hw hw; struct notifier_block clk_nb; diff --git a/drivers/clk/qcom/krait-cc.c b/drivers/clk/qcom/krait-cc.c index f5ffb1a..ec899ad 100644 --- a/drivers/clk/qcom/krait-cc.c +++ b/drivers/clk/qcom/krait-cc.c @@ -35,6 +35,49 @@ 0, }; +/* + * Notifier function for switching the muxes to safe parent + * while the hfpll is getting reprogrammed. + */ +static int krait_notifier_cb(struct notifier_block *nb, + unsigned long event, + void *data) +{ + int ret = 0; + struct krait_mux_clk *mux = container_of(nb, struct krait_mux_clk, + clk_nb); + /* Switch to safe parent */ + if (event == PRE_RATE_CHANGE) { + mux->old_index = krait_mux_clk_ops.get_parent(&mux->hw); + ret = krait_mux_clk_ops.set_parent(&mux->hw, mux->safe_sel); + mux->reparent = false; + /* + * By the time POST_RATE_CHANGE notifier is called, + * clk framework itself would have changed the parent for the new rate. + * Only otherwise, put back to the old parent. + */ + } else if (event == POST_RATE_CHANGE) { + if (!mux->reparent) + ret = krait_mux_clk_ops.set_parent(&mux->hw, + mux->old_index); + } + + return notifier_from_errno(ret); +} + +static int krait_notifier_register(struct device *dev, struct clk *clk, + struct krait_mux_clk *mux) +{ + int ret = 0; + + mux->clk_nb.notifier_call = krait_notifier_cb; + ret = clk_notifier_register(clk, &mux->clk_nb); + if (ret) + dev_err(dev, "failed to register clock notifier: %d\n", ret); + + return ret; +} + static int krait_add_div(struct device *dev, int id, const char *s, unsigned int offset) { @@ -79,6 +122,7 @@ krait_add_sec_mux(struct device *dev, int id, const char *s, unsigned int offset, bool unique_aux) { + int ret; struct krait_mux_clk *mux; static const char *sec_mux_list[] = { "acpu_aux", @@ -102,6 +146,7 @@ mux->shift = 2; mux->parent_map = sec_mux_map; mux->hw.init = &init; + mux->safe_sel = 0; init.name = kasprintf(GFP_KERNEL, "krait%s_sec_mux", s); if (!init.name) @@ -117,6 +162,11 @@ clk = devm_clk_register(dev, &mux->hw); + ret = krait_notifier_register(dev, clk, mux); + if (ret) + goto unique_aux; + +unique_aux: if (unique_aux) kfree(sec_mux_list[0]); err_aux: @@ -128,6 +178,7 @@ krait_add_pri_mux(struct device *dev, int id, const char *s, unsigned int offset) { + int ret; struct krait_mux_clk *mux; const char *p_names[3]; struct clk_init_data init = { @@ -148,6 +199,7 @@ mux->lpl = id >= 0; mux->parent_map = pri_mux_map; mux->hw.init = &init; + mux->safe_sel = 2; init.name = kasprintf(GFP_KERNEL, "krait%s_pri_mux", s); if (!init.name) @@ -173,6 +225,10 @@ clk = devm_clk_register(dev, &mux->hw); + ret = krait_notifier_register(dev, clk, mux); + if (ret) + goto err_p3; +err_p3: kfree(p_names[2]); err_p2: kfree(p_names[1]);