From patchwork Wed Aug 20 12:41:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jon Medhurst \(Tixy\)" X-Patchwork-Id: 35690 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 450362055D for ; Wed, 20 Aug 2014 12:41:13 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf11120588iec.8 for ; Wed, 20 Aug 2014 05:41:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:message-id:subject:from:to:cc:date :mime-version:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=ROmVkkPOwav11fUFv4A9/YomGuedYeCVIkcJkvvKhRU=; b=Yj17fR1GYspfsB6+lmag2SRleftB5N7tpYaAk+TEAvqMP0Z5wT4U2I7KDyTVTPBtVv gXQ0AI1pBoHLv+MgrspMvTmrjybFtb7isn+o9RA2Pw3EyLLhHleHMimSAJWXQ0nZt7mN nmGD1WooBo6aeJn+7xjlSFDSq8uRsrxPOF8/74h525I19/PFG2Z0DIFBTk8sdMsMdUL2 0WSGhA4EHbl4q7w6JntLhRCXsI03RUq/iXMIKzAPhPuRpABjdnmwKDYrQgMjw48k4JnD U/0oZGbFtuIQerlxzCE4VVWpAfriwyGssheDFR8KTUNwyDgZ/oetFHn75xdg7QRswV6r e7ag== X-Gm-Message-State: ALoCoQl9Riag/xpUz2fkIUbgFPCbAaD38bEYOyMqtL6bLPw49C/Fy/tENDgh3vGvaMtlN6QYexGJ X-Received: by 10.182.213.105 with SMTP id nr9mr25812657obc.36.1408538472818; Wed, 20 Aug 2014 05:41:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.100 with SMTP id j91ls249158qga.44.gmail; Wed, 20 Aug 2014 05:41:12 -0700 (PDT) X-Received: by 10.52.183.65 with SMTP id ek1mr1079061vdc.70.1408538472731; Wed, 20 Aug 2014 05:41:12 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id n4si10479961vcm.58.2014.08.20.05.41.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Aug 2014 05:41:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id la4so8895309vcb.23 for ; Wed, 20 Aug 2014 05:41:12 -0700 (PDT) X-Received: by 10.52.119.229 with SMTP id kx5mr809113vdb.40.1408538472656; Wed, 20 Aug 2014 05:41:12 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp50541vcb; Wed, 20 Aug 2014 05:41:12 -0700 (PDT) X-Received: by 10.66.90.229 with SMTP id bz5mr52089187pab.80.1408538471755; Wed, 20 Aug 2014 05:41:11 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jo9si31523201pbc.219.2014.08.20.05.41.10 for ; Wed, 20 Aug 2014 05:41:11 -0700 (PDT) Received-SPF: none (google.com: linux-fbdev-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752384AbaHTMlJ (ORCPT ); Wed, 20 Aug 2014 08:41:09 -0400 Received: from smarthost01d.mail.zen.net.uk ([212.23.1.7]:54065 "EHLO smarthost01d.mail.zen.net.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752193AbaHTMlJ (ORCPT ); Wed, 20 Aug 2014 08:41:09 -0400 Received: from [82.69.122.217] (helo=linaro1) by smarthost01d.mail.zen.net.uk with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XK5CK-0001cQ-QB; Wed, 20 Aug 2014 12:41:04 +0000 Message-ID: <1408538464.3858.43.camel@linaro1.home> Subject: [PATCH v2] video: ARM CLCD: Fix calculation of bits-per-pixel From: "Jon Medhurst (Tixy)" To: Russell King - ARM Linux , Tomi Valkeinen , Jean-Christophe Plagniol-Villard Cc: linux-fbdev@vger.kernel.org, Pawel Moll , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Date: Wed, 20 Aug 2014 13:41:04 +0100 X-Mailer: Evolution 3.12.2-1+b1 Mime-Version: 1.0 X-Originating-smarthost01d-IP: [82.69.122.217] Sender: linux-fbdev-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: tixy@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.178 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , If the device-tree specifies a max-memory-bandwidth property then the CLCD driver uses that to calculate the bits-per-pixel supported, however, this calculation is faulty for two reasons. 1. It doesn't ensure that the result is a sane value, i.e. a power of 2 and <= 32 as the rest of the code assumes. 2. It uses the displayed resolution and calculates the average bandwidth across the whole frame. It should instead calculate the peak bandwidth based on the pixel clock. This patch fixes both the above. Signed-off-by: Jon Medhurst Acked-by: Pawel Moll --- Changes since v1: - Changed formula for calculating bits per pixel - Changed commit message and subject, was: "video: ARM CLCD: Ensure bits-per-pixel is a power of 2 and <= 32" drivers/video/fbdev/amba-clcd.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/video/fbdev/amba-clcd.c b/drivers/video/fbdev/amba-clcd.c index beadd3e..a7b6217 100644 --- a/drivers/video/fbdev/amba-clcd.c +++ b/drivers/video/fbdev/amba-clcd.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -650,6 +651,7 @@ static int clcdfb_of_init_display(struct clcd_fb *fb) { struct device_node *endpoint; int err; + unsigned int bpp; u32 max_bandwidth; u32 tft_r0b0g0[3]; @@ -667,11 +669,22 @@ static int clcdfb_of_init_display(struct clcd_fb *fb) err = of_property_read_u32(fb->dev->dev.of_node, "max-memory-bandwidth", &max_bandwidth); - if (!err) - fb->panel->bpp = 8 * max_bandwidth / (fb->panel->mode.xres * - fb->panel->mode.yres * fb->panel->mode.refresh); - else - fb->panel->bpp = 32; + if (!err) { + /* + * max_bandwidth is in bytes per second and pixclock in + * pico-seconds, so the maximum allowed bits per pixel is + * 8 * max_bandwidth / (PICOS2KHZ(pixclock) * 1000) + * Rearrange this calculation to avoid overflow and then ensure + * result is a valid format. + */ + bpp = max_bandwidth / (1000 / 8) + / PICOS2KHZ(fb->panel->mode.pixclock); + bpp = rounddown_pow_of_two(bpp); + if (bpp > 32) + bpp = 32; + } else + bpp = 32; + fb->panel->bpp = bpp; #ifdef CONFIG_CPU_BIG_ENDIAN fb->panel->cntl |= CNTL_BEBO;