* [PATCH v2] video: ARM CLCD: Fix calculation of bits-per-pixel
@ 2014-08-20 12:41 Jon Medhurst (Tixy)
2014-08-20 13:03 ` Pawel Moll
2014-08-26 9:52 ` Tomi Valkeinen
0 siblings, 2 replies; 3+ messages in thread
From: Jon Medhurst (Tixy) @ 2014-08-20 12:41 UTC (permalink / raw)
To: linux-arm-kernel
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 <tixy@linaro.org>
---
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 <linux/list.h>
#include <linux/amba/bus.h>
#include <linux/amba/clcd.h>
+#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/hardirq.h>
#include <linux/dma-mapping.h>
@@ -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;
--
2.1.0.rc1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] video: ARM CLCD: Fix calculation of bits-per-pixel
2014-08-20 12:41 [PATCH v2] video: ARM CLCD: Fix calculation of bits-per-pixel Jon Medhurst (Tixy)
@ 2014-08-20 13:03 ` Pawel Moll
2014-08-26 9:52 ` Tomi Valkeinen
1 sibling, 0 replies; 3+ messages in thread
From: Pawel Moll @ 2014-08-20 13:03 UTC (permalink / raw)
To: linux-arm-kernel
On Wed, 2014-08-20 at 13:41 +0100, Jon Medhurst (Tixy) wrote:
> 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 <tixy@linaro.org>
Acked-by: Pawel Moll <pawel.moll@arm.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] video: ARM CLCD: Fix calculation of bits-per-pixel
2014-08-20 12:41 [PATCH v2] video: ARM CLCD: Fix calculation of bits-per-pixel Jon Medhurst (Tixy)
2014-08-20 13:03 ` Pawel Moll
@ 2014-08-26 9:52 ` Tomi Valkeinen
1 sibling, 0 replies; 3+ messages in thread
From: Tomi Valkeinen @ 2014-08-26 9:52 UTC (permalink / raw)
To: linux-arm-kernel
[-- Attachment #1: Type: text/plain, Size: 707 bytes --]
On 20/08/14 15:41, Jon Medhurst (Tixy) wrote:
> 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 <tixy@linaro.org>
Thanks, queued for 3.17 fbdev fixes.
Tomi
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-08-26 9:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-20 12:41 [PATCH v2] video: ARM CLCD: Fix calculation of bits-per-pixel Jon Medhurst (Tixy)
2014-08-20 13:03 ` Pawel Moll
2014-08-26 9:52 ` Tomi Valkeinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).