Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp910415pxf; Thu, 18 Mar 2021 14:48:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq7vE2xMxOCf3EXe7h+dGK55ee10/YqDws8ipyiyJK8OYJDlInFAvM5r3/5J2y/hAQ845L X-Received: by 2002:a17:906:4e91:: with SMTP id v17mr690324eju.331.1616104136504; Thu, 18 Mar 2021 14:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616104136; cv=none; d=google.com; s=arc-20160816; b=AtFdu44BTve7/OjPQHC6LZfuVJGLCu6iqzAsVphTn+CR+JuolXaPAhUOG97JJIMGfF sGw06f7N9LmSN+z+OJhp32ludV2JHodiUA+jthICIE6aQ2EJeCjMr1PVWzGJFCKEcugr xjzrXm5YMaS/yNUvm8ZfMEJt1wrqW4qpujHNwzkcpeC9oYygNwWuT82B7QFqUY8RJ1FX k2Mp+6Hjcd05FXbya36a2CgkQX+Js6Y2ndvKeWk3oGcJbVQxAR9S/wzCwlf4+L4C6B2f rULXMtpRnp+QUijggJ8xlkTE6wIMGzS4JCWQwB5yXbCU7aXRACVWAWV/av2+E5KnPgNp q6RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:importance:content-transfer-encoding :mime-version:subject:references:in-reply-to:message-id:cc:to:from :date:dkim-signature; bh=zU1WLLpE0lA50jM3MsK5RrXJ+mqo3UY4TvgZN01Q8MQ=; b=taoxdvQeNdmhvVU//MDDLuLod4WWp3o5ECnvopUv24wNbJfs9tn2Q0YqhDwOf5p/EX GqvzKHe+8nweOWVK0nAAdlm8XsGbI0aKKySZ9gQFabaMF3PuFdLc5IbsJeYQvzolBr0+ 8K1BVMM0Rg52p/PzVd8uAo+Tp9qBXdMeFfkuKQx0fBNW65c93N5Kzb8PfIs3sqNjZRxT HuBHyJsPq/fjJTvMCg8v18g1Fhky8cDblKarbhM0xt7DVvsmga0U9vZhMvi8KLBYCaYo Erb9AWkTvFDT6eDtNe6Glgw8g3Kyce1cDlrfz6DK/yqdiJsTwBFMb0JyMrhHWYbqhGia 7q5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@libero.it header.s=s2021 header.b=OfGisVIg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=libero.it Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y13si2601520edc.327.2021.03.18.14.48.32; Thu, 18 Mar 2021 14:48:56 -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=@libero.it header.s=s2021 header.b=OfGisVIg; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=libero.it Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233171AbhCRVre (ORCPT + 99 others); Thu, 18 Mar 2021 17:47:34 -0400 Received: from smtp-17-i2.italiaonline.it ([213.209.12.17]:33466 "EHLO libero.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230297AbhCRVrN (ORCPT ); Thu, 18 Mar 2021 17:47:13 -0400 Received: from oxapps-33-150.iol.local ([10.101.8.196]) by smtp-17.iol.local with ESMTPA id N0U1lu0o0tpGHN0U1lgazL; Thu, 18 Mar 2021 22:47:10 +0100 x-libjamoibt: 1601 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=libero.it; s=s2021; t=1616104030; bh=zU1WLLpE0lA50jM3MsK5RrXJ+mqo3UY4TvgZN01Q8MQ=; h=From; b=OfGisVIgW3s9Cv541xGM3eph9PCdbmSzYs4cdtPtyWzWSQu2iXOS0/AjpzoFLVSBe mgxDfETx2VO0IYW2dxPIklejH5TIIknc4PEAXwDJIw3wtLvSoLradMbUwAMqvgevOH zhVCbkNOTUXSvQGM2YRWbIKzJgn8WkjYRTBpA4AkgxVw5KVfLkZOx3bChZqRASidk5 e9L6VoFVVRAGZES0bspb2a5wLi/MA88CEbtQtn2qBYsr1jNe9TQZsOKzHoRWyqL+To Tsj3/TnExPjYlRpI0HsQWdbk/4QlzCPmRhhNqDB155pIL3f9yhRy4kG6M7xEq38BES j5HIT85uqkNPQ== X-CNFS-Analysis: v=2.4 cv=Q7IXX66a c=1 sm=1 tr=0 ts=6053ca5e cx=a_exe a=jCUSjkGoK4+H1w5URwD4kw==:117 a=UPWQtH3J-JgA:10 a=IkcTkHD0fZMA:10 a=_gZzKa99_6AA:10 a=VwQbUJbxAAAA:8 a=Cpx6WUeuaVtrzDQEF6EA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 Date: Thu, 18 Mar 2021 22:47:09 +0100 (CET) From: Dario Binacchi To: Tomi Valkeinen , linux-kernel@vger.kernel.org, Jyri Sarha Cc: Daniel Vetter , David Airlie , dri-devel@lists.freedesktop.org Message-ID: <1180006566.16525.1616104029554@mail1.libero.it> In-Reply-To: <7df3a270-1cc4-7a71-5e55-49a0dfb2c21f@kernel.org> References: <20210314151342.23404-1-dariobin@libero.it> <7df3a270-1cc4-7a71-5e55-49a0dfb2c21f@kernel.org> Subject: Re: [PATCH] drm/tilcdc: fix LCD pixel clock setting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal X-Mailer: Open-Xchange Mailer v7.10.3-Rev27 X-Originating-IP: 87.20.116.197 X-Originating-Client: open-xchange-appsuite x-libjamsun: jcRFwHSewQzI0vrj1avgPo+KJzlCx/Nw x-libjamv: bgul+MiGx2U= X-CMAE-Envelope: MS4xfChI96gLjikM0Juy1Jf+WHh/deHymc/eQCyjleA4QKoTlWfrxIg5QYkfsG+xs/bi0NW4e0tEab4TXaUPeNCJe7TQTrsSUR1BE3x56DkGcd1KeUSSt19y d9OJ1Zd0x9Ygvp9JtVDs+wJHPVW+nZdsAQSfdHQFXReU53yh9FBXoT181m0lUcpiDR/C5yNcgPmiMrZdcUBohSNjNwmB9Cma2y1qOdQNHfcpXsVka4ym0Pm7 JCd2CBw2yPvbLeAMA03ZZDaRis5ZPNQm1/Pf7SygPiJ6M4SOlBLVVUoas4RIEoeP2agFJG56r54RNAuzDrtHtyOITET4+TvHydkoZlxX4MYdrrZqEOFco8uR ekkIPbAw Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Il 17/03/2021 09:19 Tomi Valkeinen ha scritto: > > > On 14/03/2021 17:13, Dario Binacchi wrote: > > As reported by TI spruh73x RM, the LCD pixel clock (LCD_PCLK) frequency > > is obtained by dividing LCD_CLK, the LCD controller reference clock, > > for CLKDIV: > > > > LCD_PCLK = LCD_CLK / CLKDIV > > > > where CLKDIV must be greater than 1. > > > > Therefore LCD_CLK must be set to 'req_rate * CLKDIV' instead of req_rate > > The above doesn't make sense, the code already sets LCD_CLK to 'req_rate > * clkdiv', not req_rate. > > > and the real LCD_CLK rate must be compared with 'req_rate * CLKDIV' and > > not with req_rate. > > This is true, the code looks at the wrong value. > > > Passing req_rate instead of 'req_rate * CLKDIV' to the tilcdc_pclk_diff > > routine caused it to fail even if LCD_CLK was properly set. > > > > Signed-off-by: Dario Binacchi > > > > --- > > > > drivers/gpu/drm/tilcdc/tilcdc_crtc.c | 9 +++++---- > > 1 file changed, 5 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > > index 30213708fc99..02f56c9a5da5 100644 > > --- a/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > > +++ b/drivers/gpu/drm/tilcdc/tilcdc_crtc.c > > @@ -203,7 +203,7 @@ static void tilcdc_crtc_set_clk(struct drm_crtc *crtc) > > struct drm_device *dev = crtc->dev; > > struct tilcdc_drm_private *priv = dev->dev_private; > > struct tilcdc_crtc *tilcdc_crtc = to_tilcdc_crtc(crtc); > > - unsigned long clk_rate, real_rate, req_rate; > > + unsigned long clk_rate, real_rate, req_rate, clk_div_rate; > > unsigned int clkdiv; > > int ret; > > > > @@ -211,10 +211,11 @@ static void tilcdc_crtc_set_clk(struct drm_crtc *crtc) > > > > /* mode.clock is in KHz, set_rate wants parameter in Hz */ > > req_rate = crtc->mode.clock * 1000; > > - > > - ret = clk_set_rate(priv->clk, req_rate * clkdiv); > > + /* LCD clock divisor input rate */ > > + clk_div_rate = req_rate * clkdiv; > > "clk_div_rate" sounds a bit odd to me. Why not lcd_fck_rate, as that's > the name used later? Or lcd_clk_rate. Or maybe lcd_clk_req_rate... I prefer lcd_clk_rate. How about adding an additional patch that changes the variable names to make the code more readable? req_rate -> lcd_pclk_rate clk_rate -> real_lcd_clk_rate And add a comment to the function which highlights the relationship LCD_CLK = LCD_PCLK * CLDIV ? > > > + ret = clk_set_rate(priv->clk, clk_div_rate); > > clk_rate = clk_get_rate(priv->clk); > > - if (ret < 0 || tilcdc_pclk_diff(req_rate, clk_rate) > 5) { > > + if (ret < 0 || tilcdc_pclk_diff(clk_div_rate, clk_rate) > 5) { > > /* > > * If we fail to set the clock rate (some architectures don't > > * use the common clock framework yet and may not implement > > > > I think this fix is fine, but looking at the current code, it's calling > tilcdc_pclk_diff(), but doesn't actually provide pixel clocks to the > function, but fclk. Yes, I agree. Thanks and regards, Dario > > Tomi