Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1624733pxk; Tue, 1 Sep 2020 03:39:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDQS8KHUHZvbtS3sIOTp6XK7aqR8gZLPVki53I57J5HMN6Mu3wc9gUDScoP68fe0Iw2jug X-Received: by 2002:a05:6402:7cf:: with SMTP id u15mr1230013edy.90.1598956784182; Tue, 01 Sep 2020 03:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598956784; cv=none; d=google.com; s=arc-20160816; b=HBN8j9X0dfq5x1AtUb9w4rrrcRsvO5WiGa7JpE+fH9uxCUcz7BK2oY4tyzkVhEC6mY ydtvI4xf7wwM+S8Mtk0FSVFImpTBQ+DTzSbBw0eMIt+fcBJYt9hZ1pA36iEGbU76/8YP BNhhji/nkZD0akB9BWUd70dyPw9NOJPhSl4uwXAyfz9YAAJ/y57Zgx3DBE8nQSJRktlK yxA9dYjCAYpP/4KSVfa+bgm3KyQG1nRn+I7RmHSXY4js3VrMi5ZHsfrAauDa7XCSYJTh eOujXzDM7sBBSprtNxPEm0//XEh+E2Iwc5Bnu05dnOS7Il1CjkYmbGbTr1a1iWXXWr/u pfBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:organization:from:cc:to:subject :dkim-signature:dkim-filter; bh=idjv0axlrodit456qbHuz2JQWB1ZsRMsjn/wpW2Q1D4=; b=V76CL1C9VntNMI/4djCXTOeFPg7yua8Td3CC3MTtOInOo+vjJaw1DAkvN3cQL014G6 anb81GAdHG6m4swSycPeCwHaoHZfj7UwwDo0Ev9fHE0EjDCo+GkU5RPMAq3VmGxMHiue ObwhDnIVLDTgmHxfUBsE6R/BstVB0XCGumSqsmmuFU4ZboS/TR3+PbbrvUsZ7jZcODtc Vu/nw8WMvj4479iYFaY28dID3W2vMsqYUrdLR56yeBirfW203pGw9w11CzQEX556tNaQ UY8StRkYOgYAJQ/6rVD68dsm1Hwmh8toLQncZSrafpjD182dkSvxiKpsnSwElhJT8pVi dJBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="L/xoqPx8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f18si293614edm.539.2020.09.01.03.39.19; Tue, 01 Sep 2020 03:39:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="L/xoqPx8"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726122AbgIAKgi (ORCPT + 99 others); Tue, 1 Sep 2020 06:36:38 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:40819 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbgIAKgV (ORCPT ); Tue, 1 Sep 2020 06:36:21 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20200901103617epoutp0227dd784c7606406c014dc5d3945eeca4~wook3Jw120971409714epoutp02s for ; Tue, 1 Sep 2020 10:36:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20200901103617epoutp0227dd784c7606406c014dc5d3945eeca4~wook3Jw120971409714epoutp02s DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1598956577; bh=idjv0axlrodit456qbHuz2JQWB1ZsRMsjn/wpW2Q1D4=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=L/xoqPx8Rz8Y+ZyDvw65i3loarLFxewAlLpvYDuB0BcrP1rsZu44pJBKvkUWUJ71V XzCf0Yx8A+CtZ05NXFu3p4r7sPLDnjDTfw40nw6C1aH9iJCwjx7n8Oe1Mxe80HwRJA b8KZiqNy1FUYhmGK6BS5gu7+x0mZZjlLi7lJHp8g= Received: from epsnrtp2.localdomain (unknown [182.195.42.163]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20200901103617epcas1p1a261c7321f84e9c4b9d40b4cd4271b5f~wookaqvNR2021120211epcas1p1d; Tue, 1 Sep 2020 10:36:17 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.40.152]) by epsnrtp2.localdomain (Postfix) with ESMTP id 4Bgk4v0VDjzMqYkW; Tue, 1 Sep 2020 10:36:15 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id 6E.58.28578.E142E4F5; Tue, 1 Sep 2020 19:36:14 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200901103614epcas1p101638e69f9b8ed03529c27a53301bdb5~woohX_fBy2021120211epcas1p1Q; Tue, 1 Sep 2020 10:36:14 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200901103614epsmtrp1d5b8ff1bf682a25fb052d7e5fa6756d5~woohXQNUj1120511205epsmtrp1b; Tue, 1 Sep 2020 10:36:14 +0000 (GMT) X-AuditID: b6c32a39-8dfff70000006fa2-c3-5f4e241ed233 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 65.FB.08303.E142E4F5; Tue, 1 Sep 2020 19:36:14 +0900 (KST) Received: from [10.113.221.102] (unknown [10.113.221.102]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200901103613epsmtip2149c19c055d00c90b8a328041abe6a8e~woohB_jYB2969129691epsmtip2W; Tue, 1 Sep 2020 10:36:13 +0000 (GMT) Subject: Re: [PATCH v4 62/78] drm/vc4: hdmi: Adjust HSM clock rate depending on pixel rate To: Maxime Ripard Cc: Nicolas Saenz Julienne , Eric Anholt , dri-devel@lists.freedesktop.org, linux-rpi-kernel@lists.infradead.org, bcm-kernel-feedback-list@broadcom.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Dave Stevenson , Tim Gover , Phil Elwell From: Chanwoo Choi Organization: Samsung Electronics Message-ID: <863374f5-d75c-4251-b9f2-e112e2f6c7aa@samsung.com> Date: Tue, 1 Sep 2020 19:48:41 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:59.0) Gecko/20100101 Thunderbird/59.0 MIME-Version: 1.0 In-Reply-To: <20200901094509.spgxtkfybebo7mmb@gilmour.lan> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLJsWRmVeSWpSXmKPExsWy7bCmga6cil+8wYFjVhZre4+yWLydu5jF 4srX92wWBxovM1psenyN1eLyrjlsFhNvb2C3mPHjH6PFtlnL2SzW3XrNZvFo6n1GB26PpvfH 2Dxm3T/L5nHn3Hk2j/vdx5k8Ni+p92g9+ovFY/Ppao/Pm+QCOKKybTJSE1NSixRS85LzUzLz 0m2VvIPjneNNzQwMdQ0tLcyVFPISc1NtlVx8AnTdMnOA7lRSKEvMKQUKBSQWFyvp29kU5ZeW pCpk5BeX2CqlFqTkFFgW6BUn5haX5qXrJefnWhkaGBiZAhUmZGfsurSQvWCpVsXka+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anF51xw2i4m3N7BbzPjxj9Fi26zlbBbrbr1ms3g09T6jA7dH0/tj bB6z7p9l87hz7jybx/3u40wem5fUe7Qe/cXisfl0tcfnTXIBHFFcNimpOZllqUX6dglcGbsu LWQvWKpVMfnaO8YGxklKXYycHBICJhKdF04xdTFycQgJ7GCUmN01kQUiISkx7eJR5i5GDiBb WOLw4WKImreMEic2rQSrERaIkTjWv58RxBYRUJW40ruXGcRmFuhilmjcwQfR8IlJYsLlA2AN bAJaEvtf3GADsfkFFCWu/ngM1swrYCfRce4VWA2LgIrE2mk/wGpEBcIkdi55zARRIyhxcuYT sBpOASuJE6/ns0Ms05PYcf0XK4QtLnHryXwmCFteYvvbOcwTGIVnIWmfhaRlFpKWWUhaFjCy rGKUTC0ozk3PLTYsMMpLLdcrTswtLs1L10vOz93ECI5ILa0djHtWfdA7xMjEwXiIUYKDWUmE d+YN33gh3pTEyqrUovz4otKc1OJDjNIcLErivF9nLYwTEkhPLEnNTk0tSC2CyTJxcEo1MO1a uZppU5OCZOr9CVZO3S832aW43u4sL6uZWrzSe03UpcptfXwbp8998S1y+SeXS5yOAhndejcV b+ms23DedjdfkOy542wWGybV37E5F3OhYn5trzf3qRYj0e8VRsLSZTv0PG7zNBz99Sxq4X4h Y+Z7N1IWJV3dK3ru6I6G4jXZpqKS6WvmPZz7M7/7vIOUrJnR9ccTfzB0S1iL/D7BujK/0+hQ ekDwjnlbj7Kt3VF9lInl3oup38U+cx7pD//63ntPRvbvqyWLC+7dPNkvs/3Eh56DvxjTqiLL nZ6+fvjMu1Xc1q05pMnWx+6pZsTMCUuE3h4pUVmkdWy+z79r8zJ3qQtKsevpzJj6IilqJpcS S3FGoqEWc1FxIgAsn9abNwMAAA== X-CMS-MailID: 20200901103614epcas1p101638e69f9b8ed03529c27a53301bdb5 X-Msg-Generator: CA X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200708174513epcas1p2c059db88d8dad1d58aae3651b3c98c2b References: <5919dccdd4a792936e6cb7eb55983c530c9a468d.1594230107.git-series.maxime@cerno.tech> <95172a9a-e861-5e5d-bf51-2ec03c730237@samsung.com> <20200901094509.spgxtkfybebo7mmb@gilmour.lan> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Maxime, On 9/1/20 6:45 PM, Maxime Ripard wrote: > Hi Chanwoo, > > On Tue, Sep 01, 2020 at 01:36:17PM +0900, Chanwoo Choi wrote: >> On 7/9/20 2:42 AM, Maxime Ripard wrote: >>> The HSM clock needs to be setup at around 101% of the pixel rate. This >>> was done previously by setting the clock rate to 163.7MHz at probe time and >>> only check in mode_valid whether the mode pixel clock was under the pixel >>> clock +1% or not. >>> >>> However, with 4k we need to change that frequency to a higher frequency >>> than 163.7MHz, and yet want to have the lowest clock as possible to have a >>> decent power saving. >>> >>> Let's change that logic a bit by setting the clock rate of the HSM clock >>> to the pixel rate at encoder_enable time. This would work for the >>> BCM2711 that support 4k resolutions and has a clock that can provide it, >>> but we still have to take care of a 4k panel plugged on a BCM283x SoCs >>> that wouldn't be able to use those modes, so let's define the limit in >>> the variant. >>> >>> Signed-off-by: Maxime Ripard >>> --- >>> drivers/gpu/drm/vc4/vc4_hdmi.c | 79 ++++++++++++++++------------------- >>> drivers/gpu/drm/vc4/vc4_hdmi.h | 3 +- >>> 2 files changed, 41 insertions(+), 41 deletions(-) >>> >>> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c >>> index 17797b14cde4..9f30fab744f2 100644 >>> --- a/drivers/gpu/drm/vc4/vc4_hdmi.c >>> +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c >>> @@ -53,7 +53,6 @@ >>> #include "vc4_hdmi_regs.h" >>> #include "vc4_regs.h" >>> >>> -#define HSM_CLOCK_FREQ 163682864 >>> #define CEC_CLOCK_FREQ 40000 >>> >>> static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused) >>> @@ -326,6 +325,7 @@ static void vc4_hdmi_encoder_disable(struct drm_encoder *encoder) >>> HDMI_WRITE(HDMI_VID_CTL, >>> HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_ENABLE); >>> >>> + clk_disable_unprepare(vc4_hdmi->hsm_clock); >>> clk_disable_unprepare(vc4_hdmi->pixel_clock); >>> >>> ret = pm_runtime_put(&vc4_hdmi->pdev->dev); >>> @@ -423,6 +423,7 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder) >>> struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder); >>> struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder); >>> bool debug_dump_regs = false; >>> + unsigned long pixel_rate, hsm_rate; >>> int ret; >>> >>> ret = pm_runtime_get_sync(&vc4_hdmi->pdev->dev); >>> @@ -431,9 +432,8 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder) >>> return; >>> } >>> >>> - ret = clk_set_rate(vc4_hdmi->pixel_clock, >>> - mode->clock * 1000 * >>> - ((mode->flags & DRM_MODE_FLAG_DBLCLK) ? 2 : 1)); >>> + pixel_rate = mode->clock * 1000 * ((mode->flags & DRM_MODE_FLAG_DBLCLK) ? 2 : 1); >>> + ret = clk_set_rate(vc4_hdmi->pixel_clock, pixel_rate); >>> if (ret) { >>> DRM_ERROR("Failed to set pixel clock rate: %d\n", ret); >>> return; >>> @@ -445,6 +445,36 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder) >>> return; >>> } >>> >>> + /* >>> + * As stated in RPi's vc4 firmware "HDMI state machine (HSM) clock must >>> + * be faster than pixel clock, infinitesimally faster, tested in >>> + * simulation. Otherwise, exact value is unimportant for HDMI >>> + * operation." This conflicts with bcm2835's vc4 documentation, which >>> + * states HSM's clock has to be at least 108% of the pixel clock. >>> + * >>> + * Real life tests reveal that vc4's firmware statement holds up, and >>> + * users are able to use pixel clocks closer to HSM's, namely for >>> + * 1920x1200@60Hz. So it was decided to have leave a 1% margin between >>> + * both clocks. Which, for RPi0-3 implies a maximum pixel clock of >>> + * 162MHz. >>> + * >>> + * Additionally, the AXI clock needs to be at least 25% of >>> + * pixel clock, but HSM ends up being the limiting factor. >>> + */ >>> + hsm_rate = max_t(unsigned long, 120000000, (pixel_rate / 100) * 101); >>> + ret = clk_set_rate(vc4_hdmi->hsm_clock, hsm_rate); >>> + if (ret) { >>> + DRM_ERROR("Failed to set HSM clock rate: %d\n", ret); >>> + return; >>> + } >>> + >>> + ret = clk_prepare_enable(vc4_hdmi->hsm_clock); >>> + if (ret) { >>> + DRM_ERROR("Failed to turn on HSM clock: %d\n", ret); >>> + clk_disable_unprepare(vc4_hdmi->pixel_clock); >>> + return; >>> + } >> >> About vc4_hdmi->hsm_clock instance, usually, we need to enable the clock >> with clk_prepare_enable() and then touch the clock like clk_set_rate(). >> I think that need to enable the clock before calling clk_set_rate(). >> >> When I tested this patchset, it is well working because I think that >> vc4_hdmi->hsm_clock was already enabled on other side. > > There's no clear rule here on the ordering (at least enforced by the > framework). There's clocks that need to be disabled to change their rate > (CLK_SET_RATE_GATE) and some that need to be enabled to change their > rate (CLK_SET_RATE_UNGATE). > > Generally speaking, it seems more logical to me to have first the rate > changed and then the clock enabled since it won't create any "hiccup", > but I could very well see the opposite to be preferred. If it doesn't cause the problem on h/w, I agree. Thanks for the explanation. -- Best Regards, Chanwoo Choi Samsung Electronics