From patchwork Tue Aug 19 13:07:31 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: 4742951 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 706D19F377 for ; Tue, 19 Aug 2014 13:14:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 59AFA2014A for ; Tue, 19 Aug 2014 13:14:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2406120123 for ; Tue, 19 Aug 2014 13:14:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XJj8w-0005ih-I8; Tue, 19 Aug 2014 13:08:06 +0000 Received: from smarthost01c.mail.zen.net.uk ([212.23.1.5]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XJj8u-0005cN-26 for linux-arm-kernel@lists.infradead.org; Tue, 19 Aug 2014 13:08:04 +0000 Received: from [82.69.122.217] (helo=linaro1) by smarthost01c.mail.zen.net.uk with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1XJj8N-00019W-VR; Tue, 19 Aug 2014 13:07:32 +0000 Message-ID: <1408453651.3746.41.camel@linaro1.home> Subject: [PATCH] video: ARM CLCD: Ensure bits-per-pixel is a power of 2 and <= 32 From: "Jon Medhurst (Tixy)" To: Tomi Valkeinen , Russell King , Jean-Christophe Plagniol-Villard Date: Tue, 19 Aug 2014 14:07:31 +0100 X-Mailer: Evolution 3.12.2-1+b1 Mime-Version: 1.0 X-Originating-smarthost01c-IP: [82.69.122.217] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140819_060804_272389_FB1A8F97 X-CRM114-Status: GOOD ( 11.24 ) X-Spam-Score: -0.7 (/) Cc: linux-arm-kernel@lists.infradead.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Pawel Moll X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the device-tree specifies a max-memory-bandwidth property then the CLCD driver uses that to calculate the bits-per-pixel supported, however, 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. Acked-by: Pawel Moll Signed-off-by: Jon Medhurst --- This fixes code which is new in 3.17 (commit d10715be03) and so I assume is a candidate for adding to a coming -rc ? Without the fix, people can be left (as I was) with a blank non-functioning screen even if they create a valid device-tree for the new driver functionality. drivers/video/fbdev/amba-clcd.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/video/fbdev/amba-clcd.c b/drivers/video/fbdev/amba-clcd.c index beadd3e..98b66b7 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; + int bpp; u32 max_bandwidth; u32 tft_r0b0g0[3]; @@ -667,11 +669,15 @@ 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 * + if (!err) { + bpp = 8 * max_bandwidth / (fb->panel->mode.xres * fb->panel->mode.yres * fb->panel->mode.refresh); - else - fb->panel->bpp = 32; + 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;