Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp282258img; Wed, 20 Mar 2019 20:24:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPPSDbgN5duKMox42ssnacobeIyX4RCGPQkNi2nQ6jL6XR/TZ8yGtlY7EASo14Gnn3MKIb X-Received: by 2002:a65:62d6:: with SMTP id m22mr1323696pgv.443.1553138660272; Wed, 20 Mar 2019 20:24:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553138660; cv=none; d=google.com; s=arc-20160816; b=eZu0R0snwGDyxdQLbmuwhA7NYEFy6LWsYEPqmHkLLPGSTFzKJK1IC0ewQE8sAEh7R6 Lyb05YLAWJ5/YKaxqh2ma0Oe8Kz8d6GzcgEzleLQ5lqBz5ztsAWKLZ9/92fv5XSt2iuk 4XXuWt2QB5DuAopxl/HPvT1oYigTUwEDeWtlWBIECK4GGXL+OlQdXQ3C2w1A48PrWI7k 02BvE9uNn0VcQ2lU8T7/tiqe0AjMS2+AsoJPH0E/A5OsU86XaAeApDVL+Tb/xpX1q8BB t3LtBbGlxrCUYN6Lsu1rb4vGJF8m77TSeWJ1dsBmHeJcAVyBLp6sLJuiwHxm0JKuvM5X 5+jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=Yp162WvVjETSo8GPrr+qOVTUEgPppzYXAgMBR5kYpSU=; b=kumGBNqBrnsJgu3dfWP2QuXoaM7taJD46RKQgVbApmUk0A9OTskNxLjhEX3i5fM487 CO+VE39KCWCX6V8DSqVRFVMoUvOuhS3T3mzrjRvQHIsvnqJJXv8h3nzsV5fcpRokHkLZ bhnWTh2wNJxl7DcS2HBFlZtJxMcBPeAIEwimPt/JHiTzUosFOtZYgJ4vNxQsoy7qIqAa nI1DBaonviNiJi22GAcvCV7m7gSBK6RrhWh+TDOx7HKx+pD4AZZEYtWnV+8V+D6relLc weSsLeiR8NwKuH98zHSRjkmveJ34+yyDNoVAm1gXaOCjICJv60sde+YlSHajBplUItV+ Y/8A== 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 a98si3655149pla.267.2019.03.20.20.24.00; Wed, 20 Mar 2019 20:24:20 -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; 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 S1727861AbfCUDXU (ORCPT + 99 others); Wed, 20 Mar 2019 23:23:20 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:61326 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727507AbfCUDXT (ORCPT ); Wed, 20 Mar 2019 23:23:19 -0400 X-UUID: 82149459e4c245f492e9744ce3bae319-20190321 X-UUID: 82149459e4c245f492e9744ce3bae319-20190321 Received: from mtkmrs01.mediatek.inc [(172.21.131.159)] by mailgw02.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 1385589213; Thu, 21 Mar 2019 11:23:13 +0800 Received: from mtkcas09.mediatek.inc (172.21.101.178) by mtkmbs08n2.mediatek.inc (172.21.101.56) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Thu, 21 Mar 2019 11:23:12 +0800 Received: from [172.21.77.4] (172.21.77.4) by mtkcas09.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Thu, 21 Mar 2019 11:23:12 +0800 Message-ID: <1553138590.18216.26.camel@mtksdaap41> Subject: Re: [PATCH v6 1/8] drm/mediatek: recalculate hdmi phy clock of MT2701 by querying hardware From: CK Hu To: wangyan wang CC: Michael Turquette , Stephen Boyd , Matthias Brugger , "Philipp Zabel" , David Airlie , "Daniel Vetter" , chunhui dai , "Colin Ian King" , Sean Wang , "Ryder Lee" , , , , , , Date: Thu, 21 Mar 2019 11:23:10 +0800 In-Reply-To: <1551866854.1001.6.camel@mtksdaap41> References: <20190225020912.29120-1-wangyan.wang@mediatek.com> <20190225020912.29120-2-wangyan.wang@mediatek.com> <1551866854.1001.6.camel@mtksdaap41> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-SNTS-SMTP: 33F5F639D58E9339469006AC6A7E3800AE5E60B36126227855B0C18855B1DF962000:8 X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Wangyan: On Wed, 2019-03-06 at 18:07 +0800, CK Hu wrote: > Hi, Wangyan: > > On Mon, 2019-02-25 at 10:09 +0800, wangyan wang wrote: > > From: chunhui dai > > > > Recalculate the rate of this clock, by querying hardware. > > > > Signed-off-by: chunhui dai > > Signed-off-by: wangyan wang > > --- > > drivers/gpu/drm/mediatek/mtk_hdmi_phy.c | 7 ++---- > > drivers/gpu/drm/mediatek/mtk_hdmi_phy.h | 3 +-- > > drivers/gpu/drm/mediatek/mtk_mt2701_hdmi_phy.c | 35 ++++++++++++++++++++++++++ > > drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c | 8 ++++++ > > 4 files changed, 46 insertions(+), 7 deletions(-) > > > > diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi_phy.c b/drivers/gpu/drm/mediatek/mtk_hdmi_phy.c > > index 4ef9c57ffd44..13c5e65b9ead 100644 > > --- a/drivers/gpu/drm/mediatek/mtk_hdmi_phy.c > > +++ b/drivers/gpu/drm/mediatek/mtk_hdmi_phy.c > > @@ -29,12 +29,9 @@ long mtk_hdmi_pll_round_rate(struct clk_hw *hw, unsigned long rate, > > return rate; > > } > > > > -unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw, > > - unsigned long parent_rate) > > +u32 mtk_hdmi_phy_read(struct mtk_hdmi_phy *hdmi_phy, u32 offset) > > { > > - struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw); > > - > > - return hdmi_phy->pll_rate; > > + return readl(hdmi_phy->regs + offset); > > } > > > > void mtk_hdmi_phy_clear_bits(struct mtk_hdmi_phy *hdmi_phy, u32 offset, > > diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi_phy.h b/drivers/gpu/drm/mediatek/mtk_hdmi_phy.h > > index f39b1fc66612..fdad8b17a915 100644 > > --- a/drivers/gpu/drm/mediatek/mtk_hdmi_phy.h > > +++ b/drivers/gpu/drm/mediatek/mtk_hdmi_phy.h > > @@ -41,6 +41,7 @@ struct mtk_hdmi_phy { > > unsigned int ibias_up; > > }; > > > > +u32 mtk_hdmi_phy_read(struct mtk_hdmi_phy *hdmi_phy, u32 offset); > > void mtk_hdmi_phy_clear_bits(struct mtk_hdmi_phy *hdmi_phy, u32 offset, > > u32 bits); > > void mtk_hdmi_phy_set_bits(struct mtk_hdmi_phy *hdmi_phy, u32 offset, > > @@ -50,8 +51,6 @@ void mtk_hdmi_phy_mask(struct mtk_hdmi_phy *hdmi_phy, u32 offset, > > struct mtk_hdmi_phy *to_mtk_hdmi_phy(struct clk_hw *hw); > > long mtk_hdmi_pll_round_rate(struct clk_hw *hw, unsigned long rate, > > unsigned long *parent_rate); > > -unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw, > > - unsigned long parent_rate); > > > > extern struct platform_driver mtk_hdmi_phy_driver; > > extern struct mtk_hdmi_phy_conf mtk_hdmi_phy_8173_conf; > > diff --git a/drivers/gpu/drm/mediatek/mtk_mt2701_hdmi_phy.c b/drivers/gpu/drm/mediatek/mtk_mt2701_hdmi_phy.c > > index fcc42dc6ea7f..b25c9dfc432a 100644 > > --- a/drivers/gpu/drm/mediatek/mtk_mt2701_hdmi_phy.c > > +++ b/drivers/gpu/drm/mediatek/mtk_mt2701_hdmi_phy.c > > @@ -153,6 +153,41 @@ static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate, > > RG_HDMITX_DRV_IBIAS_MASK); > > return 0; > > } > > +static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw, > > + unsigned long parent_rate) > > +{ > > + struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw); > > + unsigned long out_rate, val; > > + > > + val = (mtk_hdmi_phy_read(hdmi_phy, HDMI_CON6) > > + & RG_HTPLL_PREDIV_MASK) >> RG_HTPLL_PREDIV; > > + switch (val) { > > + case 0x00: > > + out_rate = parent_rate; > > + break; > > + case 0x01: > > + out_rate = parent_rate / 2; > > + break; > > + default: > > + out_rate = parent_rate / 4; > > + break; > > + } > > + > > + val = (mtk_hdmi_phy_read(hdmi_phy, HDMI_CON6) > > + & RG_HTPLL_FBKDIV_MASK) >> RG_HTPLL_FBKDIV; > > + out_rate *= (val + 1) * 2; > > + val = (mtk_hdmi_phy_read(hdmi_phy, HDMI_CON2) > > + & RG_HDMITX_TX_POSDIV_MASK); > > + > > + out_rate >>= (val >> RG_HDMITX_TX_POSDIV); > > + > > + if (mtk_hdmi_phy_read(hdmi_phy, HDMI_CON2) & RG_HDMITX_EN_TX_POSDIV) > > + out_rate = out_rate / 5; > > + > > All the register you read here is set in mtk_hdmi_pll_set_rate(), so I > think you could determine the out_rate in mtk_hdmi_pll_set_rate(). As offline discuss, you mention that when cat /sys/kernel/debug/ckl/clk_summary, mtk_hdmi_pll_recalc_rate() is called, so read register to get the real clock. The clk_summary call clk_core_get_rate() to get rate, and clk_core_get_rate() would check the flag CLK_GET_RATE_NOCACHE to call __clk_recalc_rates(), but mtk_hdmi_phy does not have this flag, so this function would not be called when clk_summary. So I still think you could determine the out_rate in mtk_hdmi_pll_set_rate(). Regards, CK > > Regards, > CK > > > + hdmi_phy->pll_rate = out_rate; > > + > > + return hdmi_phy->pll_rate; > > +} > > > > static const struct clk_ops mtk_hdmi_phy_pll_ops = { > > .prepare = mtk_hdmi_pll_prepare, > > diff --git a/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c b/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c > > index ed5916b27658..cb23c1e4692a 100644 > > --- a/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c > > +++ b/drivers/gpu/drm/mediatek/mtk_mt8173_hdmi_phy.c > > @@ -285,6 +285,14 @@ static int mtk_hdmi_pll_set_rate(struct clk_hw *hw, unsigned long rate, > > return 0; > > } > > > > +static unsigned long mtk_hdmi_pll_recalc_rate(struct clk_hw *hw, > > + unsigned long parent_rate) > > +{ > > + struct mtk_hdmi_phy *hdmi_phy = to_mtk_hdmi_phy(hw); > > + > > + return hdmi_phy->pll_rate; > > +} > > + > > static const struct clk_ops mtk_hdmi_phy_pll_ops = { > > .prepare = mtk_hdmi_pll_prepare, > > .unprepare = mtk_hdmi_pll_unprepare, >