Commit 94f9e09c authored by Antonino A. Daplas's avatar Antonino A. Daplas Committed by Linus Torvalds

[PATCH] fbdev: imsttfb: Driver cleanups

- remove unneeded casts

- the pseudo_palette, if using the generic drawing functions, must always be
  u32 regardless of the bpp

- use framebuffer_alloc/framebuffer_release to allocate memory
Signed-off-by: default avatarAntonino Daplas <adaplas@pol.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 1d204ef3
...@@ -323,6 +323,7 @@ struct imstt_par { ...@@ -323,6 +323,7 @@ struct imstt_par {
unsigned long cmap_regs_phys; unsigned long cmap_regs_phys;
__u8 *cmap_regs; __u8 *cmap_regs;
__u32 ramdac; __u32 ramdac;
__u32 palette[16];
}; };
enum { enum {
...@@ -657,7 +658,7 @@ set_imstt_regvals_tvp (struct imstt_par *par, u_int bpp) ...@@ -657,7 +658,7 @@ set_imstt_regvals_tvp (struct imstt_par *par, u_int bpp)
static void static void
set_imstt_regvals (struct fb_info *info, u_int bpp) set_imstt_regvals (struct fb_info *info, u_int bpp)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
struct imstt_regvals *init = &par->init; struct imstt_regvals *init = &par->init;
__u32 ctl, pitch, byteswap, scr; __u32 ctl, pitch, byteswap, scr;
...@@ -749,7 +750,7 @@ set_imstt_regvals (struct fb_info *info, u_int bpp) ...@@ -749,7 +750,7 @@ set_imstt_regvals (struct fb_info *info, u_int bpp)
static inline void static inline void
set_offset (struct fb_var_screeninfo *var, struct fb_info *info) set_offset (struct fb_var_screeninfo *var, struct fb_info *info)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
__u32 off = var->yoffset * (info->fix.line_length >> 3) __u32 off = var->yoffset * (info->fix.line_length >> 3)
+ ((var->xoffset * (var->bits_per_pixel >> 3)) >> 3); + ((var->xoffset * (var->bits_per_pixel >> 3)) >> 3);
write_reg_le32(par->dc_regs, SSR, off); write_reg_le32(par->dc_regs, SSR, off);
...@@ -863,7 +864,7 @@ imsttfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) ...@@ -863,7 +864,7 @@ imsttfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
static int static int
imsttfb_set_par(struct fb_info *info) imsttfb_set_par(struct fb_info *info)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
if (!compute_imstt_regvals(par, info->var.xres, info->var.yres)) if (!compute_imstt_regvals(par, info->var.xres, info->var.yres))
return -EINVAL; return -EINVAL;
...@@ -881,7 +882,7 @@ static int ...@@ -881,7 +882,7 @@ static int
imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue, imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue,
u_int transp, struct fb_info *info) u_int transp, struct fb_info *info)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
u_int bpp = info->var.bits_per_pixel; u_int bpp = info->var.bits_per_pixel;
if (regno > 255) if (regno > 255)
...@@ -905,14 +906,17 @@ imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue, ...@@ -905,14 +906,17 @@ imsttfb_setcolreg (u_int regno, u_int red, u_int green, u_int blue,
if (regno < 16) if (regno < 16)
switch (bpp) { switch (bpp) {
case 16: case 16:
((u16 *)info->pseudo_palette)[regno] = (regno << (info->var.green.length == 5 ? 10 : 11)) | (regno << 5) | regno; par->palette[regno] =
(regno << (info->var.green.length ==
5 ? 10 : 11)) | (regno << 5) | regno;
break; break;
case 24: case 24:
((u32 *)info->pseudo_palette)[regno] = (regno << 16) | (regno << 8) | regno; par->palette[regno] =
(regno << 16) | (regno << 8) | regno;
break; break;
case 32: { case 32: {
int i = (regno << 8) | regno; int i = (regno << 8) | regno;
((u32 *)info->pseudo_palette)[regno] = (i << 16) | i; par->palette[regno] = (i << 16) |i;
break; break;
} }
} }
...@@ -935,7 +939,7 @@ imsttfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) ...@@ -935,7 +939,7 @@ imsttfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
static int static int
imsttfb_blank(int blank, struct fb_info *info) imsttfb_blank(int blank, struct fb_info *info)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
__u32 ctrl; __u32 ctrl;
ctrl = read_reg_le32(par->dc_regs, STGCTL); ctrl = read_reg_le32(par->dc_regs, STGCTL);
...@@ -989,7 +993,7 @@ imsttfb_blank(int blank, struct fb_info *info) ...@@ -989,7 +993,7 @@ imsttfb_blank(int blank, struct fb_info *info)
static void static void
imsttfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) imsttfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
__u32 Bpp, line_pitch, bgc, dx, dy, width, height; __u32 Bpp, line_pitch, bgc, dx, dy, width, height;
bgc = rect->color; bgc = rect->color;
...@@ -1033,7 +1037,7 @@ imsttfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect) ...@@ -1033,7 +1037,7 @@ imsttfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
static void static void
imsttfb_copyarea(struct fb_info *info, const struct fb_copyarea *area) imsttfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
__u32 Bpp, line_pitch, fb_offset_old, fb_offset_new, sp, dp_octl; __u32 Bpp, line_pitch, fb_offset_old, fb_offset_new, sp, dp_octl;
__u32 cnt, bltctl, sx, sy, dx, dy, height, width; __u32 cnt, bltctl, sx, sy, dx, dy, height, width;
...@@ -1195,7 +1199,7 @@ imstt_set_cursor(struct imstt_par *par, struct fb_image *d, int on) ...@@ -1195,7 +1199,7 @@ imstt_set_cursor(struct imstt_par *par, struct fb_image *d, int on)
static int static int
imsttfb_cursor(struct fb_info *info, struct fb_cursor *cursor) imsttfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
u32 flags = cursor->set, fg, bg, xx, yy; u32 flags = cursor->set, fg, bg, xx, yy;
if (cursor->dest == NULL && cursor->rop == ROP_XOR) if (cursor->dest == NULL && cursor->rop == ROP_XOR)
...@@ -1266,7 +1270,7 @@ static int ...@@ -1266,7 +1270,7 @@ static int
imsttfb_ioctl(struct inode *inode, struct file *file, u_int cmd, imsttfb_ioctl(struct inode *inode, struct file *file, u_int cmd,
u_long arg, struct fb_info *info) u_long arg, struct fb_info *info)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
void __user *argp = (void __user *)arg; void __user *argp = (void __user *)arg;
__u32 reg[2]; __u32 reg[2];
__u8 idx[2]; __u8 idx[2];
...@@ -1350,7 +1354,7 @@ static struct fb_ops imsttfb_ops = { ...@@ -1350,7 +1354,7 @@ static struct fb_ops imsttfb_ops = {
static void __devinit static void __devinit
init_imstt(struct fb_info *info) init_imstt(struct fb_info *info)
{ {
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
__u32 i, tmp, *ip, *end; __u32 i, tmp, *ip, *end;
tmp = read_reg_le32(par->dc_regs, PRC); tmp = read_reg_le32(par->dc_regs, PRC);
...@@ -1413,7 +1417,7 @@ init_imstt(struct fb_info *info) ...@@ -1413,7 +1417,7 @@ init_imstt(struct fb_info *info)
if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len if ((info->var.xres * info->var.yres) * (info->var.bits_per_pixel >> 3) > info->fix.smem_len
|| !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) { || !(compute_imstt_regvals(par, info->var.xres, info->var.yres))) {
printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel); printk("imsttfb: %ux%ux%u not supported\n", info->var.xres, info->var.yres, info->var.bits_per_pixel);
kfree(info); framebuffer_release(info);
return; return;
} }
...@@ -1449,7 +1453,7 @@ init_imstt(struct fb_info *info) ...@@ -1449,7 +1453,7 @@ init_imstt(struct fb_info *info)
fb_alloc_cmap(&info->cmap, 0, 0); fb_alloc_cmap(&info->cmap, 0, 0);
if (register_framebuffer(info) < 0) { if (register_framebuffer(info) < 0) {
kfree(info); framebuffer_release(info);
return; return;
} }
...@@ -1474,26 +1478,21 @@ imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1474,26 +1478,21 @@ imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
printk(KERN_ERR "imsttfb: no OF node for pci device\n"); printk(KERN_ERR "imsttfb: no OF node for pci device\n");
#endif /* CONFIG_PPC_OF */ #endif /* CONFIG_PPC_OF */
size = sizeof(struct fb_info) + sizeof(struct imstt_par) + info = framebuffer_alloc(sizeof(struct imstt_par), &pdev->dev);
sizeof(u32) * 16;
info = kmalloc(size, GFP_KERNEL);
if (!info) { if (!info) {
printk(KERN_ERR "imsttfb: Can't allocate memory\n"); printk(KERN_ERR "imsttfb: Can't allocate memory\n");
return -ENOMEM; return -ENOMEM;
} }
memset(info, 0, size); par = info->par;
par = (struct imstt_par *) (info + 1);
addr = pci_resource_start (pdev, 0); addr = pci_resource_start (pdev, 0);
size = pci_resource_len (pdev, 0); size = pci_resource_len (pdev, 0);
if (!request_mem_region(addr, size, "imsttfb")) { if (!request_mem_region(addr, size, "imsttfb")) {
printk(KERN_ERR "imsttfb: Can't reserve memory region\n"); printk(KERN_ERR "imsttfb: Can't reserve memory region\n");
kfree(info); framebuffer_release(info);
return -ENODEV; return -ENODEV;
} }
...@@ -1516,14 +1515,13 @@ imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -1516,14 +1515,13 @@ imsttfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
} }
info->fix.smem_start = addr; info->fix.smem_start = addr;
info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ? 0x400000 : 0x800000); info->screen_base = (__u8 *)ioremap(addr, par->ramdac == IBM ?
0x400000 : 0x800000);
info->fix.mmio_start = addr + 0x800000; info->fix.mmio_start = addr + 0x800000;
par->dc_regs = ioremap(addr + 0x800000, 0x1000); par->dc_regs = ioremap(addr + 0x800000, 0x1000);
par->cmap_regs_phys = addr + 0x840000; par->cmap_regs_phys = addr + 0x840000;
par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000); par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000);
info->par = par; info->pseudo_palette = par->palette;
info->pseudo_palette = (void *) (par + 1);
info->device = &pdev->dev;
init_imstt(info); init_imstt(info);
pci_set_drvdata(pdev, info); pci_set_drvdata(pdev, info);
...@@ -1534,7 +1532,7 @@ static void __devexit ...@@ -1534,7 +1532,7 @@ static void __devexit
imsttfb_remove(struct pci_dev *pdev) imsttfb_remove(struct pci_dev *pdev)
{ {
struct fb_info *info = pci_get_drvdata(pdev); struct fb_info *info = pci_get_drvdata(pdev);
struct imstt_par *par = (struct imstt_par *) info->par; struct imstt_par *par = info->par;
int size = pci_resource_len(pdev, 0); int size = pci_resource_len(pdev, 0);
unregister_framebuffer(info); unregister_framebuffer(info);
...@@ -1542,7 +1540,7 @@ imsttfb_remove(struct pci_dev *pdev) ...@@ -1542,7 +1540,7 @@ imsttfb_remove(struct pci_dev *pdev)
iounmap(par->dc_regs); iounmap(par->dc_regs);
iounmap(info->screen_base); iounmap(info->screen_base);
release_mem_region(info->fix.smem_start, size); release_mem_region(info->fix.smem_start, size);
kfree(info); framebuffer_release(info);
} }
#ifndef MODULE #ifndef MODULE
......
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