Commit b0831941 authored by Krzysztof Helt's avatar Krzysztof Helt Committed by Linus Torvalds

s3c2410fb: code cleanup

This patch cleans up the driver a bit. It contains
coding style fixes (pointed by Lindent and checkpatch),
white space clean ups and few minor code improvements.
Signed-off-by: default avatarKrzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: default avatarAntonino Daplas <adaplas@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1d677a6d
......@@ -102,7 +102,6 @@
#include "s3c2410fb.h"
static struct s3c2410fb_mach_info *mach_info;
/* Debugging stuff */
......@@ -119,19 +118,20 @@ static int debug = 0;
/* s3c2410fb_set_lcdaddr
*
* initialise lcd controller address pointers
*/
*/
static void s3c2410fb_set_lcdaddr(struct s3c2410fb_info *fbi)
{
struct fb_var_screeninfo *var = &fbi->fb->var;
unsigned long saddr1, saddr2, saddr3;
int line_length = var->xres * var->bits_per_pixel;
saddr1 = fbi->fb->fix.smem_start >> 1;
saddr2 = fbi->fb->fix.smem_start;
saddr2 += (var->xres * var->yres * var->bits_per_pixel)/8;
saddr2>>= 1;
saddr2 += (line_length * var->yres) / 8;
saddr2 >>= 1;
saddr3 = S3C2410_OFFSIZE(0) | S3C2410_PAGEWIDTH((var->xres * var->bits_per_pixel / 16) & 0x3ff);
saddr3 = S3C2410_OFFSIZE(0) |
S3C2410_PAGEWIDTH((line_length / 16) & 0x3ff);
dprintk("LCDSADDR1 = 0x%08lx\n", saddr1);
dprintk("LCDSADDR2 = 0x%08lx\n", saddr2);
......@@ -145,8 +145,7 @@ static void s3c2410fb_set_lcdaddr(struct s3c2410fb_info *fbi)
/* s3c2410fb_calc_pixclk()
*
* calculate divisor for clk->pixclk
*/
*/
static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi,
unsigned long pixclk)
{
......@@ -159,8 +158,8 @@ static unsigned int s3c2410fb_calc_pixclk(struct s3c2410fb_info *fbi,
*/
div = (unsigned long long)clk * pixclk;
do_div(div,1000000UL);
do_div(div,1000000UL);
do_div(div, 1000000UL);
do_div(div, 1000000UL);
dprintk("pixclk %ld, divisor is %ld\n", pixclk, (long)div);
return div;
......@@ -198,6 +197,8 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
else if (var->bits_per_pixel < fbi->mach_info->bpp.min)
var->bits_per_pixel = fbi->mach_info->bpp.min;
var->transp.offset = 0;
var->transp.length = 0;
/* set r/g/b positions */
switch (var->bits_per_pixel) {
case 1:
......@@ -207,11 +208,9 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
var->red.length = var->bits_per_pixel;
var->green = var->red;
var->blue = var->red;
var->transp.offset = 0;
var->transp.length = 0;
break;
case 8:
if ( fbi->mach_info->type != S3C2410_LCDCON1_TFT ) {
if (fbi->mach_info->type != S3C2410_LCDCON1_TFT) {
/* 8 bpp 332 */
var->red.length = 3;
var->red.offset = 5;
......@@ -219,14 +218,11 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
var->green.offset = 2;
var->blue.length = 2;
var->blue.offset = 0;
var->transp.length = 0;
} else {
var->red.offset = 0;
var->red.length = var->bits_per_pixel;
var->red.length = 8;
var->green = var->red;
var->blue = var->red;
var->transp.offset = 0;
var->transp.length = 0;
}
break;
case 12:
......@@ -237,12 +233,11 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
var->green.offset = 4;
var->blue.length = 4;
var->blue.offset = 0;
var->transp.length = 0;
break;
default:
case 16:
if (fbi->regs.lcdcon5 & S3C2410_LCDCON5_FRM565 ) {
if (fbi->regs.lcdcon5 & S3C2410_LCDCON5_FRM565) {
/* 16 bpp, 565 format */
var->red.offset = 11;
var->green.offset = 5;
......@@ -250,7 +245,6 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
var->red.length = 5;
var->green.length = 6;
var->blue.length = 5;
var->transp.length = 0;
} else {
/* 16 bpp, 5551 format */
var->red.offset = 11;
......@@ -259,7 +253,6 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
var->red.length = 5;
var->green.length = 5;
var->blue.length = 5;
var->transp.length = 0;
}
break;
case 24:
......@@ -270,7 +263,6 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
var->green.offset = 8;
var->blue.length = 8;
var->blue.offset = 0;
var->transp.length = 0;
break;
......@@ -278,13 +270,11 @@ static int s3c2410fb_check_var(struct fb_var_screeninfo *var,
return 0;
}
/* s3c2410fb_activate_var
*
* activate (set) the controller from the given framebuffer
* information
*/
*/
static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
struct fb_var_screeninfo *var)
{
......@@ -319,7 +309,8 @@ static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
default:
/* invalid pixel depth */
dev_err(fbi->dev, "invalid bpp %d\n", var->bits_per_pixel);
dev_err(fbi->dev, "invalid bpp %d\n",
var->bits_per_pixel);
}
else
switch (var->bits_per_pixel) {
......@@ -341,19 +332,18 @@ static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
default:
/* invalid pixel depth */
dev_err(fbi->dev, "invalid bpp %d\n", var->bits_per_pixel);
dev_err(fbi->dev, "invalid bpp %d\n",
var->bits_per_pixel);
}
/* check to see if we need to update sync/borders */
if (!fbi->mach_info->fixed_syncs) {
dprintk("setting vert: up=%d, low=%d, sync=%d\n",
var->upper_margin, var->lower_margin,
var->vsync_len);
var->upper_margin, var->lower_margin, var->vsync_len);
dprintk("setting horz: lft=%d, rt=%d, sync=%d\n",
var->left_margin, var->right_margin,
var->hsync_len);
var->left_margin, var->right_margin, var->hsync_len);
fbi->regs.lcdcon2 =
S3C2410_LCDCON2_VBPD(var->upper_margin - 1) |
......@@ -373,7 +363,7 @@ static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
fbi->regs.lcdcon2 &= ~S3C2410_LCDCON2_LINEVAL(0x3ff);
fbi->regs.lcdcon2 |= S3C2410_LCDCON2_LINEVAL(var->yres - 1);
switch(fbi->mach_info->type) {
switch (fbi->mach_info->type) {
case S3C2410_LCDCON1_DSCAN4:
case S3C2410_LCDCON1_STN8:
hs = var->xres / 8;
......@@ -385,15 +375,12 @@ static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
case S3C2410_LCDCON1_TFT:
hs = var->xres;
break;
}
/* Special cases : STN color displays */
if ( ((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN8BPP) \
|| ((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN12BPP) ) {
if (((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN8BPP) ||
((fbi->regs.lcdcon1 & S3C2410_LCDCON1_MODEMASK) == S3C2410_LCDCON1_STN12BPP))
hs = hs * 3;
}
fbi->regs.lcdcon3 &= ~S3C2410_LCDCON3_HOZVAL(0x7ff);
fbi->regs.lcdcon3 |= S3C2410_LCDCON3_HOZVAL(hs - 1);
......@@ -402,11 +389,10 @@ static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
int clkdiv = s3c2410fb_calc_pixclk(fbi, var->pixclock);
if (fbi->mach_info->type == S3C2410_LCDCON1_TFT) {
clkdiv = (clkdiv / 2) -1;
clkdiv = (clkdiv / 2) - 1;
if (clkdiv < 0)
clkdiv = 0;
}
else {
} else {
clkdiv = (clkdiv / 2);
if (clkdiv < 2)
clkdiv = 2;
......@@ -437,9 +423,8 @@ static void s3c2410fb_activate_var(struct s3c2410fb_info *fbi,
writel(fbi->regs.lcdcon1, S3C2410_LCDCON1);
}
/*
* s3c2410fb_set_par - Optional function. Alters the hardware state.
* s3c2410fb_set_par - Alters the hardware state.
* @info: frame buffer structure that represents a single frame buffer
*
*/
......@@ -448,20 +433,19 @@ static int s3c2410fb_set_par(struct fb_info *info)
struct s3c2410fb_info *fbi = info->par;
struct fb_var_screeninfo *var = &info->var;
switch (var->bits_per_pixel)
{
switch (var->bits_per_pixel) {
case 16:
fbi->fb->fix.visual = FB_VISUAL_TRUECOLOR;
info->fix.visual = FB_VISUAL_TRUECOLOR;
break;
case 1:
fbi->fb->fix.visual = FB_VISUAL_MONO01;
info->fix.visual = FB_VISUAL_MONO01;
break;
default:
fbi->fb->fix.visual = FB_VISUAL_PSEUDOCOLOR;
info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
break;
}
fbi->fb->fix.line_length = (var->width*var->bits_per_pixel)/8;
info->fix.line_length = (var->width * var->bits_per_pixel) / 8;
/* activate this new configuration */
......@@ -493,7 +477,8 @@ static void schedule_palette_update(struct s3c2410fb_info *fbi,
}
/* from pxafb.c */
static inline unsigned int chan_to_field(unsigned int chan, struct fb_bitfield *bf)
static inline unsigned int chan_to_field(unsigned int chan,
struct fb_bitfield *bf)
{
chan &= 0xffff;
chan >>= 16 - bf->length;
......@@ -507,18 +492,19 @@ static int s3c2410fb_setcolreg(unsigned regno,
struct s3c2410fb_info *fbi = info->par;
unsigned int val;
/* dprintk("setcol: regno=%d, rgb=%d,%d,%d\n", regno, red, green, blue); */
/* dprintk("setcol: regno=%d, rgb=%d,%d,%d\n",
regno, red, green, blue); */
switch (fbi->fb->fix.visual) {
switch (info->fix.visual) {
case FB_VISUAL_TRUECOLOR:
/* true-colour, use pseuo-palette */
/* true-colour, use pseudo-palette */
if (regno < 16) {
u32 *pal = fbi->fb->pseudo_palette;
u32 *pal = info->pseudo_palette;
val = chan_to_field(red, &fbi->fb->var.red);
val |= chan_to_field(green, &fbi->fb->var.green);
val |= chan_to_field(blue, &fbi->fb->var.blue);
val = chan_to_field(red, &info->var.red);
val |= chan_to_field(green, &info->var.green);
val |= chan_to_field(blue, &info->var.blue);
pal[regno] = val;
}
......@@ -545,8 +531,7 @@ static int s3c2410fb_setcolreg(unsigned regno,
return 0;
}
/**
/*
* s3c2410fb_blank
* @blank_mode: the blank mode we want.
* @info: frame buffer structure that represents a single frame buffer
......@@ -579,11 +564,13 @@ static int s3c2410fb_blank(int blank_mode, struct fb_info *info)
return 0;
}
static int s3c2410fb_debug_show(struct device *dev, struct device_attribute *attr, char *buf)
static int s3c2410fb_debug_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", debug ? "on" : "off");
}
static int s3c2410fb_debug_store(struct device *dev, struct device_attribute *attr,
static int s3c2410fb_debug_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t len)
{
if (mach_info == NULL)
......@@ -607,10 +594,7 @@ static int s3c2410fb_debug_store(struct device *dev, struct device_attribute *at
return len;
}
static DEVICE_ATTR(debug, 0666,
s3c2410fb_debug_show,
s3c2410fb_debug_store);
static DEVICE_ATTR(debug, 0666, s3c2410fb_debug_show, s3c2410fb_debug_store);
static struct fb_ops s3c2410fb_ops = {
.owner = THIS_MODULE,
......@@ -623,7 +607,6 @@ static struct fb_ops s3c2410fb_ops = {
.fb_imageblit = cfb_imageblit,
};
/*
* s3c2410fb_map_video_memory():
* Allocates the DRAM memory for the frame buffer. This buffer is
......@@ -661,7 +644,8 @@ static int __init s3c2410fb_map_video_memory(struct s3c2410fb_info *fbi)
static inline void s3c2410fb_unmap_video_memory(struct s3c2410fb_info *fbi)
{
dma_free_writecombine(fbi->dev,fbi->map_size,fbi->map_cpu, fbi->map_dma);
dma_free_writecombine(fbi->dev, fbi->map_size, fbi->map_cpu,
fbi->map_dma);
}
static inline void modify_gpio(void __iomem *reg,
......@@ -673,11 +657,9 @@ static inline void modify_gpio(void __iomem *reg,
writel(tmp | set, reg);
}
/*
* s3c2410fb_init_registers - Initialise all LCD-related registers
*/
static int s3c2410fb_init_registers(struct s3c2410fb_info *fbi)
{
unsigned long flags;
......@@ -721,13 +703,13 @@ static int s3c2410fb_init_registers(struct s3c2410fb_info *fbi)
static void s3c2410fb_write_palette(struct s3c2410fb_info *fbi)
{
unsigned int i;
unsigned long ent;
void __iomem *regs = fbi->io;
fbi->palette_ready = 0;
for (i = 0; i < 256; i++) {
if ((ent = fbi->palette_buffer[i]) == PALETTE_BUFF_CLEAR)
unsigned long ent = fbi->palette_buffer[i];
if (ent == PALETTE_BUFF_CLEAR)
continue;
writel(ent, regs + S3C2410_TFTPAL(i));
......@@ -761,7 +743,7 @@ static irqreturn_t s3c2410fb_irq(int irq, void *dev_id)
return IRQ_HANDLED;
}
static char driver_name[]="s3c2410fb";
static char driver_name[] = "s3c2410fb";
static int __init s3c2410fb_probe(struct platform_device *pdev)
{
......@@ -777,7 +759,8 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
mach_info = pdev->dev.platform_data;
if (mach_info == NULL) {
dev_err(&pdev->dev,"no platform data for lcd, cannot attach\n");
dev_err(&pdev->dev,
"no platform data for lcd, cannot attach\n");
return -EINVAL;
}
......@@ -790,9 +773,8 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
}
fbinfo = framebuffer_alloc(sizeof(struct s3c2410fb_info), &pdev->dev);
if (!fbinfo) {
if (!fbinfo)
return -ENOMEM;
}
info = fbinfo->par;
info->fb = fbinfo;
......@@ -800,12 +782,12 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (res == NULL) {
dev_err(&pdev->dev, "failed to get memory registersn");
dev_err(&pdev->dev, "failed to get memory registers\n");
ret = -ENXIO;
goto dealloc_fb;
}
size = (res->end - res->start)+1;
size = (res->end - res->start) + 1;
info->mem = request_mem_region(res->start, size, pdev->name);
if (info->mem == NULL) {
dev_err(&pdev->dev, "failed to get memory region\n");
......@@ -859,13 +841,19 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
fbinfo->var.yres_virtual = mach_info->yres.defval;
fbinfo->var.bits_per_pixel = mach_info->bpp.defval;
fbinfo->var.upper_margin = S3C2410_LCDCON2_GET_VBPD(mregs->lcdcon2) + 1;
fbinfo->var.lower_margin = S3C2410_LCDCON2_GET_VFPD(mregs->lcdcon2) + 1;
fbinfo->var.vsync_len = S3C2410_LCDCON2_GET_VSPW(mregs->lcdcon2) + 1;
fbinfo->var.upper_margin =
S3C2410_LCDCON2_GET_VBPD(mregs->lcdcon2) + 1;
fbinfo->var.lower_margin =
S3C2410_LCDCON2_GET_VFPD(mregs->lcdcon2) + 1;
fbinfo->var.vsync_len =
S3C2410_LCDCON2_GET_VSPW(mregs->lcdcon2) + 1;
fbinfo->var.left_margin = S3C2410_LCDCON3_GET_HFPD(mregs->lcdcon3) + 1;
fbinfo->var.right_margin = S3C2410_LCDCON3_GET_HBPD(mregs->lcdcon3) + 1;
fbinfo->var.hsync_len = S3C2410_LCDCON4_GET_HSPW(mregs->lcdcon4) + 1;
fbinfo->var.left_margin =
S3C2410_LCDCON3_GET_HFPD(mregs->lcdcon3) + 1;
fbinfo->var.right_margin =
S3C2410_LCDCON3_GET_HBPD(mregs->lcdcon3) + 1;
fbinfo->var.hsync_len =
S3C2410_LCDCON4_GET_HSPW(mregs->lcdcon4) + 1;
fbinfo->var.red.offset = 11;
fbinfo->var.green.offset = 5;
......@@ -904,20 +892,21 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
/* Initialize video memory */
ret = s3c2410fb_map_video_memory(info);
if (ret) {
printk( KERN_ERR "Failed to allocate video RAM: %d\n", ret);
printk(KERN_ERR "Failed to allocate video RAM: %d\n", ret);
ret = -ENOMEM;
goto release_clock;
}
dprintk("got video memory\n");
ret = s3c2410fb_init_registers(info);
s3c2410fb_init_registers(info);
ret = s3c2410fb_check_var(&fbinfo->var, fbinfo);
s3c2410fb_check_var(&fbinfo->var, fbinfo);
ret = register_framebuffer(fbinfo);
if (ret < 0) {
printk(KERN_ERR "Failed to register framebuffer device: %d\n", ret);
printk(KERN_ERR "Failed to register framebuffer device: %d\n",
ret);
goto free_video_memory;
}
......@@ -935,7 +924,7 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
clk_disable(info->clk);
clk_put(info->clk);
release_irq:
free_irq(irq,info);
free_irq(irq, info);
release_regs:
iounmap(info->io);
release_mem:
......@@ -949,8 +938,7 @@ static int __init s3c2410fb_probe(struct platform_device *pdev)
/* s3c2410fb_stop_lcd
*
* shutdown the lcd controller
*/
*/
static void s3c2410fb_stop_lcd(struct s3c2410fb_info *fbi)
{
unsigned long flags;
......@@ -984,7 +972,7 @@ static int s3c2410fb_remove(struct platform_device *pdev)
}
irq = platform_get_irq(pdev, 0);
free_irq(irq,info);
free_irq(irq, info);
release_resource(info->mem);
kfree(info->mem);
......@@ -997,7 +985,6 @@ static int s3c2410fb_remove(struct platform_device *pdev)
#ifdef CONFIG_PM
/* suspend and resume support for the lcd controller */
static int s3c2410fb_suspend(struct platform_device *dev, pm_message_t state)
{
struct fb_info *fbinfo = platform_get_drvdata(dev);
......@@ -1054,10 +1041,10 @@ static void __exit s3c2410fb_cleanup(void)
platform_driver_unregister(&s3c2410fb_driver);
}
module_init(s3c2410fb_init);
module_exit(s3c2410fb_cleanup);
MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>, Ben Dooks <ben-linux@fluff.org>");
MODULE_AUTHOR("Arnaud Patard <arnaud.patard@rtp-net.org>, "
"Ben Dooks <ben-linux@fluff.org>");
MODULE_DESCRIPTION("Framebuffer driver for the s3c2410");
MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment