Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2995298imb; Mon, 4 Mar 2019 21:07:13 -0800 (PST) X-Google-Smtp-Source: APXvYqx844PpKCjfHDCymbSwZdgY/QYmPo2urkUSABBA5Q6NWgvh1xn/XL9hximP0duEmO6QVYO0 X-Received: by 2002:a62:e214:: with SMTP id a20mr42812pfi.192.1551762433323; Mon, 04 Mar 2019 21:07:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551762433; cv=none; d=google.com; s=arc-20160816; b=Yu3fX0q8LQ38FprBCfV7qpWWFB9T0bKJGz2ZuhtqqHKmFlq8L96uwNl2dwn3q5oEMx FkmHdHQMhvF/4qXVnWm3DoLsZIqtHoj4740fqzaifReO5S/6s6p/kFGk5YmKFVAjHbL5 07EnSHFDhlmFRBySb9AAGB+DdJbUH3z/AvxsLm8re82aZYe0Wqk4CwPf0ehHqPGMgRB5 N/mHh2cLiP22oiP9jFnClMIoedlLSQ6Vxj7AuaGk6zb4tTFL+cW5sjcVX1BZehMx1QTS dpFxUO2+ll/2pTocWfFd8qhU0UB5+Q5aehKi2BRE+hmybPZ1s3wp354+WeqJ+2iUPB3t 5yxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=VPmuibXVo8gWM8stMUdaGCFJ/Fb7twjiGxIn5bdCxRc=; b=yBnqPXKNwAqk0sPKuamhwS/2pB2tqXBW36tXwGgoIBl+8NKCshhw187y+iXjTx02J1 IDECYEIRZMO8I6WrP4IWC1KVxJfoVq4GtRUjlNubEkUtFksv1wmbrozttDaQxpKGPM4t W8bv5z+R3Pj6pG4LGVDwTuJOgSearYVukm0kzqcYBU+X36nDkmuA6Y0itkDG9rku5uAy Vn3jYNrkOYAkR9Qd7d/r3b5pDereYCMkOm3itS4MtH0tRWTunqJRe1wTSLRFb95OzAA9 CnXtBGmPPZNVmtQKiUTkzTi5TEa4Ck8WglTl14Az9fKSw912MQHeRb+XQ5yFe33uAWhe ohJQ== ARC-Authentication-Results: i=1; mx.google.com; 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 a1si7588679pld.152.2019.03.04.21.06.39; Mon, 04 Mar 2019 21:07:13 -0800 (PST) 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; 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 S1727038AbfCEFGI (ORCPT + 99 others); Tue, 5 Mar 2019 00:06:08 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:59665 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1725924AbfCEFGG (ORCPT ); Tue, 5 Mar 2019 00:06:06 -0500 X-UUID: 3a89430512b8437c9de0b7271488aa1e-20190305 X-UUID: 3a89430512b8437c9de0b7271488aa1e-20190305 Received: from mtkmrs01.mediatek.inc [(172.21.131.159)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1632267032; Tue, 05 Mar 2019 13:05:55 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 5 Mar 2019 13:05:54 +0800 Received: from mtkslt210.mediatek.inc (10.21.14.14) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 5 Mar 2019 13:05:54 +0800 From: Weiyi Lu To: Nicolas Boichat , Matthias Brugger , Stephen Boyd , Rob Herring CC: James Liao , Fan Chen , , , , , , , Weiyi Lu , Owen Chen Subject: [PATCH v5 1/9] clk: mediatek: Disable tuner_en before change PLL rate Date: Tue, 5 Mar 2019 13:05:38 +0800 Message-ID: <20190305050546.23431-3-weiyi.lu@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190305050546.23431-1-weiyi.lu@mediatek.com> References: <20190305050546.23431-1-weiyi.lu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Owen Chen PLLs with tuner_en bit, such as APLL1, need to disable tuner_en before apply new frequency settings, or the new frequency settings (pcw) will not be applied. The tuner_en bit will be disabled during changing PLL rate and be restored after new settings applied. Fixes: e2f744a82d725 (clk: mediatek: Add MT2712 clock support) Cc: Signed-off-by: Owen Chen Signed-off-by: Weiyi Lu --- drivers/clk/mediatek/clk-pll.c | 48 ++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index f54e4015b0b1..18842d660317 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -88,6 +88,32 @@ static unsigned long __mtk_pll_recalc_rate(struct mtk_clk_pll *pll, u32 fin, return ((unsigned long)vco + postdiv - 1) / postdiv; } +static void __mtk_pll_tuner_enable(struct mtk_clk_pll *pll) +{ + u32 r; + + if (pll->tuner_en_addr) { + r = readl(pll->tuner_en_addr) | BIT(pll->data->tuner_en_bit); + writel(r, pll->tuner_en_addr); + } else if (pll->tuner_addr) { + r = readl(pll->tuner_addr) | AUDPLL_TUNER_EN; + writel(r, pll->tuner_addr); + } +} + +static void __mtk_pll_tuner_disable(struct mtk_clk_pll *pll) +{ + u32 r; + + if (pll->tuner_en_addr) { + r = readl(pll->tuner_en_addr) & ~BIT(pll->data->tuner_en_bit); + writel(r, pll->tuner_en_addr); + } else if (pll->tuner_addr) { + r = readl(pll->tuner_addr) & ~AUDPLL_TUNER_EN; + writel(r, pll->tuner_addr); + } +} + static void mtk_pll_set_rate_regs(struct mtk_clk_pll *pll, u32 pcw, int postdiv) { @@ -96,6 +122,9 @@ static void mtk_pll_set_rate_regs(struct mtk_clk_pll *pll, u32 pcw, pll_en = readl(pll->base_addr + REG_CON0) & CON0_BASE_EN; + /* disable tuner */ + __mtk_pll_tuner_disable(pll); + /* set postdiv */ val = readl(pll->pd_addr); val &= ~(POSTDIV_MASK << pll->data->pd_shift); @@ -122,6 +151,9 @@ static void mtk_pll_set_rate_regs(struct mtk_clk_pll *pll, u32 pcw, if (pll->tuner_addr) writel(con1 + 1, pll->tuner_addr); + /* restore tuner_en */ + __mtk_pll_tuner_enable(pll); + if (pll_en) udelay(20); } @@ -228,13 +260,7 @@ static int mtk_pll_prepare(struct clk_hw *hw) r |= pll->data->en_mask; writel(r, pll->base_addr + REG_CON0); - if (pll->tuner_en_addr) { - r = readl(pll->tuner_en_addr) | BIT(pll->data->tuner_en_bit); - writel(r, pll->tuner_en_addr); - } else if (pll->tuner_addr) { - r = readl(pll->tuner_addr) | AUDPLL_TUNER_EN; - writel(r, pll->tuner_addr); - } + __mtk_pll_tuner_enable(pll); udelay(20); @@ -258,13 +284,7 @@ static void mtk_pll_unprepare(struct clk_hw *hw) writel(r, pll->base_addr + REG_CON0); } - if (pll->tuner_en_addr) { - r = readl(pll->tuner_en_addr) & ~BIT(pll->data->tuner_en_bit); - writel(r, pll->tuner_en_addr); - } else if (pll->tuner_addr) { - r = readl(pll->tuner_addr) & ~AUDPLL_TUNER_EN; - writel(r, pll->tuner_addr); - } + __mtk_pll_tuner_disable(pll); r = readl(pll->base_addr + REG_CON0); r &= ~CON0_BASE_EN; -- 2.18.0