cirrusfb: code improvements

This patch does some "short-range" code improvements like merging identical
switch clauses, replacing conditional branches with calculation of values,
merging only once-used functions into place they are called from.

Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Antonino Daplas <adaplas@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Krzysztof Helt 2007-10-16 01:29:13 -07:00 committed by Linus Torvalds
parent 9199ec5c5f
commit 060b6002b1

View file

@ -647,31 +647,17 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
{ -1, -1 } }; { -1, -1 } };
switch (var->bits_per_pixel) { switch (var->bits_per_pixel) {
case 0 ... 1: case 1:
var->bits_per_pixel = 1;
nom = 4; nom = 4;
den = 8; den = 8;
break; /* 8 pixel per byte, only 1/4th of mem usable */ break; /* 8 pixel per byte, only 1/4th of mem usable */
case 2 ... 8: case 8:
var->bits_per_pixel = 8; case 16:
nom = 1; case 24:
case 32:
nom = var->bits_per_pixel / 8;
den = 1; den = 1;
break; /* 1 pixel == 1 byte */ break; /* 1 pixel == 1 byte */
case 9 ... 16:
var->bits_per_pixel = 16;
nom = 2;
den = 1;
break; /* 2 bytes per pixel */
case 17 ... 24:
var->bits_per_pixel = 24;
nom = 3;
den = 1;
break; /* 3 bytes per pixel */
case 25 ... 32:
var->bits_per_pixel = 32;
nom = 4;
den = 1;
break; /* 4 bytes per pixel */
default: default:
printk(KERN_ERR "cirrusfb: mode %dx%dx%d rejected..." printk(KERN_ERR "cirrusfb: mode %dx%dx%d rejected..."
"color depth not supported.\n", "color depth not supported.\n",
@ -732,19 +718,15 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
case 1: case 1:
var->red.offset = 0; var->red.offset = 0;
var->red.length = 1; var->red.length = 1;
var->green.offset = 0; var->green = var->red;
var->green.length = 1; var->blue = var->red;
var->blue.offset = 0;
var->blue.length = 1;
break; break;
case 8: case 8:
var->red.offset = 0; var->red.offset = 0;
var->red.length = 6; var->red.length = 6;
var->green.offset = 0; var->green = var->red;
var->green.length = 6; var->blue = var->red;
var->blue.offset = 0;
var->blue.length = 6;
break; break;
case 16: case 16:
@ -763,20 +745,6 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
break; break;
case 24: case 24:
if (isPReP) {
var->red.offset = 8;
var->green.offset = 16;
var->blue.offset = 24;
} else {
var->red.offset = 16;
var->green.offset = 8;
var->blue.offset = 0;
}
var->red.length = 8;
var->green.length = 8;
var->blue.length = 8;
break;
case 32: case 32:
if (isPReP) { if (isPReP) {
var->red.offset = 8; var->red.offset = 8;
@ -828,7 +796,7 @@ static int cirrusfb_decode_var(const struct fb_var_screeninfo *var,
{ {
long freq; long freq;
long maxclock; long maxclock;
int maxclockidx = 0; int maxclockidx = var->bits_per_pixel >> 3;
struct cirrusfb_info *cinfo = info->par; struct cirrusfb_info *cinfo = info->par;
int xres, hfront, hsync, hback; int xres, hfront, hsync, hback;
int yres, vfront, vsync, vback; int yres, vfront, vsync, vback;
@ -837,31 +805,18 @@ static int cirrusfb_decode_var(const struct fb_var_screeninfo *var,
case 1: case 1:
regs->line_length = var->xres_virtual / 8; regs->line_length = var->xres_virtual / 8;
regs->visual = FB_VISUAL_MONO10; regs->visual = FB_VISUAL_MONO10;
maxclockidx = 0;
break; break;
case 8: case 8:
regs->line_length = var->xres_virtual; regs->line_length = var->xres_virtual;
regs->visual = FB_VISUAL_PSEUDOCOLOR; regs->visual = FB_VISUAL_PSEUDOCOLOR;
maxclockidx = 1;
break; break;
case 16: case 16:
regs->line_length = var->xres_virtual * 2;
regs->visual = FB_VISUAL_DIRECTCOLOR;
maxclockidx = 2;
break;
case 24: case 24:
regs->line_length = var->xres_virtual * 3;
regs->visual = FB_VISUAL_DIRECTCOLOR;
maxclockidx = 3;
break;
case 32: case 32:
regs->line_length = var->xres_virtual * 4; regs->line_length = var->xres_virtual * maxclockidx;
regs->visual = FB_VISUAL_DIRECTCOLOR; regs->visual = FB_VISUAL_DIRECTCOLOR;
maxclockidx = 4;
break; break;
default: default:
@ -874,7 +829,7 @@ static int cirrusfb_decode_var(const struct fb_var_screeninfo *var,
regs->type = FB_TYPE_PACKED_PIXELS; regs->type = FB_TYPE_PACKED_PIXELS;
/* convert from ps to kHz */ /* convert from ps to kHz */
freq = 1000000000 / var->pixclock; freq = PICOS2KHZ(var->pixclock);
DPRINTK("desired pixclock: %ld kHz\n", freq); DPRINTK("desired pixclock: %ld kHz\n", freq);
@ -1213,7 +1168,8 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
break; break;
case BT_PICCOLO: case BT_PICCOLO:
DPRINTK("(for Piccolo)\n"); case BT_SPECTRUM:
DPRINTK("(for Piccolo/Spectrum)\n");
/* ### ueberall 0x22? */ /* ### ueberall 0x22? */
/* ##vorher 1c MCLK select */ /* ##vorher 1c MCLK select */
vga_wseq(regbase, CL_SEQR1F, 0x22); vga_wseq(regbase, CL_SEQR1F, 0x22);
@ -1229,15 +1185,6 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
vga_wseq(regbase, CL_SEQRF, 0xd0); vga_wseq(regbase, CL_SEQRF, 0xd0);
break; break;
case BT_SPECTRUM:
DPRINTK("(for Spectrum)\n");
/* ### ueberall 0x22? */
/* ##vorher 1c MCLK select */
vga_wseq(regbase, CL_SEQR1F, 0x22);
/* evtl d0? avoid FIFO underruns..? */
vga_wseq(regbase, CL_SEQRF, 0xb0);
break;
case BT_PICASSO4: case BT_PICASSO4:
case BT_ALPINE: case BT_ALPINE:
case BT_GD5480: case BT_GD5480:
@ -1306,19 +1253,7 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
break; break;
case BT_PICCOLO: case BT_PICCOLO:
/* ### vorher 1c MCLK select */
vga_wseq(regbase, CL_SEQR1F, 0x22);
/* Fast Page-Mode writes */
vga_wseq(regbase, CL_SEQRF, 0xb0);
break;
case BT_PICASSO: case BT_PICASSO:
/* ### vorher 1c MCLK select */
vga_wseq(regbase, CL_SEQR1F, 0x22);
/* Fast Page-Mode writes */
vga_wseq(regbase, CL_SEQRF, 0xb0);
break;
case BT_SPECTRUM: case BT_SPECTRUM:
/* ### vorher 1c MCLK select */ /* ### vorher 1c MCLK select */
vga_wseq(regbase, CL_SEQR1F, 0x22); vga_wseq(regbase, CL_SEQR1F, 0x22);
@ -1385,6 +1320,7 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
break; break;
case BT_PICCOLO: case BT_PICCOLO:
case BT_SPECTRUM:
vga_wseq(regbase, CL_SEQR7, 0x87); vga_wseq(regbase, CL_SEQR7, 0x87);
/* Fast Page-Mode writes */ /* Fast Page-Mode writes */
vga_wseq(regbase, CL_SEQRF, 0xb0); vga_wseq(regbase, CL_SEQRF, 0xb0);
@ -1400,14 +1336,6 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
vga_wseq(regbase, CL_SEQR1F, 0x22); vga_wseq(regbase, CL_SEQR1F, 0x22);
break; break;
case BT_SPECTRUM:
vga_wseq(regbase, CL_SEQR7, 0x87);
/* Fast Page-Mode writes */
vga_wseq(regbase, CL_SEQRF, 0xb0);
/* MCLK select */
vga_wseq(regbase, CL_SEQR1F, 0x22);
break;
case BT_PICASSO4: case BT_PICASSO4:
vga_wseq(regbase, CL_SEQR7, 0x27); vga_wseq(regbase, CL_SEQR7, 0x27);
/* vga_wseq(regbase, CL_SEQR1F, 0x1c); */ /* vga_wseq(regbase, CL_SEQR1F, 0x1c); */
@ -1473,6 +1401,7 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
break; break;
case BT_PICCOLO: case BT_PICCOLO:
case BT_SPECTRUM:
vga_wseq(regbase, CL_SEQR7, 0x85); vga_wseq(regbase, CL_SEQR7, 0x85);
/* Fast Page-Mode writes */ /* Fast Page-Mode writes */
vga_wseq(regbase, CL_SEQRF, 0xb0); vga_wseq(regbase, CL_SEQRF, 0xb0);
@ -1488,14 +1417,6 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
vga_wseq(regbase, CL_SEQR1F, 0x22); vga_wseq(regbase, CL_SEQR1F, 0x22);
break; break;
case BT_SPECTRUM:
vga_wseq(regbase, CL_SEQR7, 0x85);
/* Fast Page-Mode writes */
vga_wseq(regbase, CL_SEQRF, 0xb0);
/* MCLK select */
vga_wseq(regbase, CL_SEQR1F, 0x22);
break;
case BT_PICASSO4: case BT_PICASSO4:
vga_wseq(regbase, CL_SEQR7, 0x25); vga_wseq(regbase, CL_SEQR7, 0x25);
/* vga_wseq(regbase, CL_SEQR1F, 0x1c); */ /* vga_wseq(regbase, CL_SEQR1F, 0x1c); */
@ -1662,18 +1583,7 @@ static int cirrusfb_setcolreg(unsigned regno, unsigned red, unsigned green,
(green << info->var.green.offset) | (green << info->var.green.offset) |
(blue << info->var.blue.offset); (blue << info->var.blue.offset);
switch (info->var.bits_per_pixel) { cinfo->pseudo_palette[regno] = v;
case 8:
cinfo->pseudo_palette[regno] = v;
break;
case 16:
cinfo->pseudo_palette[regno] = v;
break;
case 24:
case 32:
cinfo->pseudo_palette[regno] = v;
break;
}
return 0; return 0;
} }
@ -1743,12 +1653,8 @@ static int cirrusfb_pan_display(struct fb_var_screeninfo *var,
vga_wcrt(cinfo->regbase, CL_CRT1B, tmp2); vga_wcrt(cinfo->regbase, CL_CRT1B, tmp2);
/* construct bit 19 of screen start address */ /* construct bit 19 of screen start address */
if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19) { if (cirrusfb_board_info[cinfo->btype].scrn_start_bit19)
tmp2 = 0; vga_wcrt(cinfo->regbase, CL_CRT1D, (base >> 12) & 0x80);
if (base & 0x80000)
tmp2 = 0x80;
vga_wcrt(cinfo->regbase, CL_CRT1D, tmp2);
}
/* write pixel panning value to AR33; this does not quite work in 8bpp /* write pixel panning value to AR33; this does not quite work in 8bpp
* *
@ -2139,38 +2045,15 @@ static void switch_monitor(struct cirrusfb_info *cinfo, int on)
/* Linux 2.6-style accelerated functions */ /* Linux 2.6-style accelerated functions */
/******************************************/ /******************************************/
static void cirrusfb_prim_fillrect(struct fb_info *info,
const struct fb_fillrect *region)
{
struct cirrusfb_info *cinfo = info->par;
int m; /* bytes per pixel */
u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
cinfo->pseudo_palette[region->color] : region->color;
if (info->var.bits_per_pixel == 1) {
cirrusfb_RectFill(cinfo->regbase,
info->var.bits_per_pixel,
region->dx / 8, region->dy,
region->width / 8, region->height,
color,
cinfo->currentmode.line_length);
} else {
m = (info->var.bits_per_pixel + 7) / 8;
cirrusfb_RectFill(cinfo->regbase,
info->var.bits_per_pixel,
region->dx * m, region->dy,
region->width * m, region->height,
color,
cinfo->currentmode.line_length);
}
return;
}
static void cirrusfb_fillrect(struct fb_info *info, static void cirrusfb_fillrect(struct fb_info *info,
const struct fb_fillrect *region) const struct fb_fillrect *region)
{ {
struct fb_fillrect modded; struct fb_fillrect modded;
int vxres, vyres; int vxres, vyres;
struct cirrusfb_info *cinfo = info->par;
int m = info->var.bits_per_pixel;
u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
cinfo->pseudo_palette[region->color] : region->color;
if (info->state != FBINFO_STATE_RUNNING) if (info->state != FBINFO_STATE_RUNNING)
return; return;
@ -2193,30 +2076,12 @@ static void cirrusfb_fillrect(struct fb_info *info,
if (modded.dy + modded.height > vyres) if (modded.dy + modded.height > vyres)
modded.height = vyres - modded.dy; modded.height = vyres - modded.dy;
cirrusfb_prim_fillrect(info, &modded); cirrusfb_RectFill(cinfo->regbase,
} info->var.bits_per_pixel,
(region->dx * m) / 8, region->dy,
static void cirrusfb_prim_copyarea(struct fb_info *info, (region->width * m) / 8, region->height,
const struct fb_copyarea *area) color,
{ cinfo->currentmode.line_length);
struct cirrusfb_info *cinfo = info->par;
int m; /* bytes per pixel */
if (info->var.bits_per_pixel == 1) {
cirrusfb_BitBLT(cinfo->regbase, info->var.bits_per_pixel,
area->sx / 8, area->sy,
area->dx / 8, area->dy,
area->width / 8, area->height,
cinfo->currentmode.line_length);
} else {
m = (info->var.bits_per_pixel + 7) / 8;
cirrusfb_BitBLT(cinfo->regbase, info->var.bits_per_pixel,
area->sx * m, area->sy,
area->dx * m, area->dy,
area->width * m, area->height,
cinfo->currentmode.line_length);
}
return;
} }
static void cirrusfb_copyarea(struct fb_info *info, static void cirrusfb_copyarea(struct fb_info *info,
@ -2224,13 +2089,8 @@ static void cirrusfb_copyarea(struct fb_info *info,
{ {
struct fb_copyarea modded; struct fb_copyarea modded;
u32 vxres, vyres; u32 vxres, vyres;
struct cirrusfb_info *cinfo = info->par;
modded.sx = area->sx; int m = info->var.bits_per_pixel;
modded.sy = area->sy;
modded.dx = area->dx;
modded.dy = area->dy;
modded.width = area->width;
modded.height = area->height;
if (info->state != FBINFO_STATE_RUNNING) if (info->state != FBINFO_STATE_RUNNING)
return; return;
@ -2241,6 +2101,7 @@ static void cirrusfb_copyarea(struct fb_info *info,
vxres = info->var.xres_virtual; vxres = info->var.xres_virtual;
vyres = info->var.yres_virtual; vyres = info->var.yres_virtual;
memcpy(&modded, area, sizeof(struct fb_copyarea));
if (!modded.width || !modded.height || if (!modded.width || !modded.height ||
modded.sx >= vxres || modded.sy >= vyres || modded.sx >= vxres || modded.sy >= vyres ||
@ -2256,7 +2117,12 @@ static void cirrusfb_copyarea(struct fb_info *info,
if (modded.dy + modded.height > vyres) if (modded.dy + modded.height > vyres)
modded.height = vyres - modded.dy; modded.height = vyres - modded.dy;
cirrusfb_prim_copyarea(info, &modded); cirrusfb_BitBLT(cinfo->regbase, info->var.bits_per_pixel,
(area->sx * m) / 8, area->sy,
(area->dx * m) / 8, area->dy,
(area->width * m) / 8, area->height,
cinfo->currentmode.line_length);
} }
static void cirrusfb_imageblit(struct fb_info *info, static void cirrusfb_imageblit(struct fb_info *info,
@ -2366,7 +2232,6 @@ static void cirrusfb_pci_unmap(struct fb_info *info)
if (release_io_ports) if (release_io_ports)
release_region(0x3C0, 32); release_region(0x3C0, 32);
pci_release_regions(pdev); pci_release_regions(pdev);
framebuffer_release(info);
} }
#endif /* CONFIG_PCI */ #endif /* CONFIG_PCI */
@ -2383,7 +2248,6 @@ static void __devexit cirrusfb_zorro_unmap(struct cirrusfb_info *cinfo)
if (zorro_resource_start(cinfo->zdev) > 0x01000000) if (zorro_resource_start(cinfo->zdev) > 0x01000000)
iounmap(info->screen_base); iounmap(info->screen_base);
} }
framebuffer_release(cinfo->info);
} }
#endif /* CONFIG_ZORRO */ #endif /* CONFIG_ZORRO */
@ -2481,6 +2345,7 @@ err_dealloc_cmap:
fb_dealloc_cmap(&info->cmap); fb_dealloc_cmap(&info->cmap);
err_unmap_cirrusfb: err_unmap_cirrusfb:
cinfo->unmap(info); cinfo->unmap(info);
framebuffer_release(info);
return err; return err;
} }
@ -2495,6 +2360,7 @@ static void __devexit cirrusfb_cleanup(struct fb_info *info)
fb_dealloc_cmap(&info->cmap); fb_dealloc_cmap(&info->cmap);
printk("Framebuffer unregistered\n"); printk("Framebuffer unregistered\n");
cinfo->unmap(info); cinfo->unmap(info);
framebuffer_release(info);
DPRINTK("EXIT\n"); DPRINTK("EXIT\n");
} }