Skip to contentSkip to conversation

s3c2410fb: fix clockrate calculation

PATCH Ben Dooks 2 participants 3 messages Aug 20, 2009 – Aug 27, 2009

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

In the final part of the calculation for the tft display clockrate we divide the output pf s3c2410fb_calc_pixclk() by 2 which leaves us with a rounding error if the result is odd.

Change to using DIV_ROUND_UP() to ensure that we always choose a higher divisor and thus a lower frequency.

---
 drivers/video/s3c2410fb.c |    4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
drivers/video/s3c2410fb.c +3 -1
Index: b/drivers/video/s3c2410fb.c
===================================================================
@@ -369,7 +369,9 @@ static void s3c2410fb_activate_var(struc
 	void __iomem *regs = fbi->io;
 	int type = fbi->regs.lcdcon1 & S3C2410_LCDCON1_TFT;
 	struct fb_var_screeninfo *var = &info->var;
-	int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock) / 2;
+	int clkdiv;
+
+	clkdiv = DIV_ROUND_UP(s3c2410fb_calc_pixclk(fbi, var->pixclock), 2);
 
 	printk(KERN_INFO "%s: pixclock=%d, clkdiv=%d\n",
 	       __func__, var->pixclock, clkdiv);
Signature · 9 lines
Ben ([email protected], http://www.fluff.org/)

  'a smiley only costs 4 bytes'

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
#1 lore raw
Quoted 18 lines · On Thu, 20 Aug 2009 22:50:47 +0100 Ben Dooks <[email protected]> wrote:

In the final part of the calculation for the tft display clockrate we divide the output pf s3c2410fb_calc_pixclk() by 2 which leaves us with a rounding error if the result is odd.

Change to using DIV_ROUND_UP() to ensure that we always choose a higher divisor and thus a lower frequency.

---
 drivers/video/s3c2410fb.c |    4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

Index: b/drivers/video/s3c2410fb.c
===================================================================

drivers/video/s3c2410fb.c static void s3c2410fb_activate_var(struc · line 377

Quoted 10 lines
drivers/video/s3c2410fb.c +3 -1
@@ -369,7 +369,9 @@ static void s3c2410fb_activate_var(struc
 	void __iomem *regs = fbi->io;
 	int type = fbi->regs.lcdcon1 & S3C2410_LCDCON1_TFT;
 	struct fb_var_screeninfo *var = &info->var;
-	int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock) / 2;
+	int clkdiv;
+
+	clkdiv = DIV_ROUND_UP(s3c2410fb_calc_pixclk(fbi, var->pixclock), 2);
 
 	printk(KERN_INFO "%s: pixclock=%d, clkdiv=%d\n",
 	       __func__, var->pixclock, clkdiv);

The changelog forgot to tell us what the impact of this bug is, so I cannot work out whether we need this fix in 2.6.32, 2.6.31, 2.6.30.x, ....

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july

author
#2 lore raw
Quoted 29 lines · Andrew Morton
Quoted 26 lines · On Thu, 20 Aug 2009 22:50:47 +0100 Ben Dooks <[email protected]> wrote:

In the final part of the calculation for the tft display clockrate we divide the output pf s3c2410fb_calc_pixclk() by 2 which leaves us with a rounding error if the result is odd.

Change to using DIV_ROUND_UP() to ensure that we always choose a higher divisor and thus a lower frequency.

---
 drivers/video/s3c2410fb.c |    4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

Index: b/drivers/video/s3c2410fb.c
===================================================================

drivers/video/s3c2410fb.c +3 -1
@@ -369,7 +369,9 @@ static void s3c2410fb_activate_var(struc
 	void __iomem *regs = fbi->io;
 	int type = fbi->regs.lcdcon1 & S3C2410_LCDCON1_TFT;
 	struct fb_var_screeninfo *var = &info->var;
-	int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock) / 2;
+	int clkdiv;
+
+	clkdiv = DIV_ROUND_UP(s3c2410fb_calc_pixclk(fbi, var->pixclock), 2);
 
Quoted 5 lines

drivers/video/s3c2410fb.c static void s3c2410fb_activate_var(struc · line 377

Quoted 2 lines
drivers/video/s3c2410fb.c +0 -0
 	printk(KERN_INFO "%s: pixclock=%d, clkdiv=%d\n",
 	       __func__, var->pixclock, clkdiv);

The changelog forgot to tell us what the impact of this bug is, so I cannot work out whether we need this fix in 2.6.32, 2.6.31, 2.6.30.x, ....

Sorry, found this whilst working on a new machine and the pix clock being too fast for the display. The machine is not yet merged into the mainline so this not an important fix.

Signature · 9 lines
Ben Dooks, Software Engineer, Simtec Electronics

http://www.simtec.co.uk/

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july