Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2601175imm; Fri, 24 Aug 2018 02:01:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbNgRXgTdr8NZB+rftWKeNfDkZz139cLcyKuV/ozxkxVuJR5lrfvUBrXTJ1K3WlzZgvsu2C X-Received: by 2002:a62:4083:: with SMTP id f3-v6mr945631pfd.229.1535101289627; Fri, 24 Aug 2018 02:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535101289; cv=none; d=google.com; s=arc-20160816; b=Pppt1pyHnymRpBJiYGgY+z7R+edAV3V9um2kDUWVnukYBrCYwU3zjx12DW5nwhgWIv R83t/3h/hu7KHa1ytUOqe6UvNvkqcBaR8XJbKU7sBELRWx5Q4aY2feTop1g4pQmzG3ki LvdLMKwSEvcZC8gJ+y0TWWZXgX3RLvcbZvwXsmX0uEt0RQU733wVTGXQopZibKOBRXR8 Wg9KL6pJl7K8OCkLdlG6JivHvSlpGn/kuHlCMAKrQy5KuNaSmZojgNefZw65MITYOs/6 ya3R9NlOGAFumk0GJMc70x14Toibso17X+dtXzF+5f8puFHiozLgJKVrAriYiYnsKUCX +pXg== 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:message-id:subject:cc:to:from:date :arc-authentication-results; bh=EyFirAXF6MxraP0bgyS3UDbkg95IN2xrsXA/Rn3mS5o=; b=0L6IKBWFRaOD90D9/sVZev8J/XH7OjuX7hOXvyu0ecP26KgYTD5rZUmeBryr4rNqub MQmCfnZFR7bZ2aZJ/GdCmBTTJcPYSyuWQEffw40rhI5fv7q09SdmJBwh/twDbyoICJdT 2AMSq6ZOmt2g2vcRRv3yRiyrdHs9AWAJ47MfhLRq1K5TWxdq/R+yhY32ABEzKM8yj/7u DBHms1f71gkpp7qxHyZUJ+dTWXxWJc0wgqhvnCf+xkQIF5qBeKUkDERZ6xYSM75ACK9I cHpfn3O2oZSPE0PlnJNWI1h2Ymx56gLk+bXM8rtTxs5FO8wCl7DbwYYVBawUjWPaknWz j7tw== 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 j2-v6si6860801pfc.102.2018.08.24.02.01.13; Fri, 24 Aug 2018 02:01:29 -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 S1726993AbeHXMdd (ORCPT + 99 others); Fri, 24 Aug 2018 08:33:33 -0400 Received: from mail.bootlin.com ([62.4.15.54]:44858 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726382AbeHXMdd (ORCPT ); Fri, 24 Aug 2018 08:33:33 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 93C13206DE; Fri, 24 Aug 2018 10:59:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (AAubervilliers-681-1-53-19.w90-88.abo.wanadoo.fr [90.88.170.19]) by mail.bootlin.com (Postfix) with ESMTPSA id 4DC4C206DE; Fri, 24 Aug 2018 10:59:41 +0200 (CEST) Date: Fri, 24 Aug 2018 10:59:39 +0200 From: Boris Brezillon To: Peter Rosin Cc: linux-kernel@vger.kernel.org, David Airlie , Nicolas Ferre , Alexandre Belloni , dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 1/2] drm/atmel-hlcdc: prefer a higher rate clock as pixel-clock base Message-ID: <20180824105939.24fe8013@bbrezillon> In-Reply-To: <20180824085501.9740-2-peda@axentia.se> References: <20180824085501.9740-1-peda@axentia.se> <20180824085501.9740-2-peda@axentia.se> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 24 Aug 2018 10:55:00 +0200 Peter Rosin wrote: > If the divider used to get the pixel-clock is small, the granularity > of the frequencies possible for the pixel-clock is quite coarse. E.g. > requesting a pixel-clock of 65MHz with a sys_clk of 132MHz results > in the divider being set to 3 ending up with 44MHz. > > By preferring the doubled sys_clk as base, the divider instead ends > up as 5 yielding a pixel-clock of 52.8Mhz, which is a definite > improvement. > > While at it, clamp the divider so that it does not overflow in case > it gets big. > > Signed-off-by: Peter Rosin > --- > drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c > index c38a479ada98..71c9cd90d2ae 100644 > --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c > +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c > @@ -101,18 +101,22 @@ static void atmel_hlcdc_crtc_mode_set_nofb(struct drm_crtc *c) > (adj->crtc_hdisplay - 1) | > ((adj->crtc_vdisplay - 1) << 16)); > > - cfg = 0; > + cfg = ATMEL_HLCDC_CLKSEL; > > - prate = clk_get_rate(crtc->dc->hlcdc->sys_clk); > + prate = 2 * clk_get_rate(crtc->dc->hlcdc->sys_clk); > mode_rate = adj->crtc_clock * 1000; > - if ((prate / 2) < mode_rate) { > - prate *= 2; > - cfg |= ATMEL_HLCDC_CLKSEL; > - } > > div = DIV_ROUND_UP(prate, mode_rate); > if (div < 2) > div = 2; I'm nitpicking, but can you add braces around the if() block? Looks good otherwise. > + else if (ATMEL_HLCDC_CLKDIV(div) & ~ATMEL_HLCDC_CLKDIV_MASK) { > + /* the divider ended up too big, try a lower base rate */ > + cfg &= ~ATMEL_HLCDC_CLKSEL; > + prate /= 2; > + div = DIV_ROUND_UP(prate, mode_rate); > + if (ATMEL_HLCDC_CLKDIV(div) & ~ATMEL_HLCDC_CLKDIV_MASK) > + div = ATMEL_HLCDC_CLKDIV_MASK; > + } > > cfg |= ATMEL_HLCDC_CLKDIV(div); >