Skip to content

Commit 7939cec

Browse files
ukleinekhdeller
authored andcommitted
fbdev: au1100fb: Don't store device specific data in global variables
Using global data to store device specific data is a bad pattern that breaks if there is more than one device. So expand driver data and drop the global variables. While there is probably no machine that has two or more au1100fb devices, this makes the driver a better template for new drivers and saves some memory if there is no such bound device. bloat-o-meter reports (for ARCH=arm allmodconfig + CONFIG_FB_AU1100=y and ignoring the rename of the init function): add/remove: 1/4 grow/shrink: 2/2 up/down: 1360/-4800 (-3440) Function old new delta au1100fb_drv_probe 2648 3328 +680 $a 12808 13484 +676 au1100fb_drv_resume 404 400 -4 au1100fb_fix 68 - -68 au1100fb_var 160 - -160 fbregs 2048 - -2048 $d 9525 7009 -2516 Total: Before=38664, After=35224, chg -8.90% Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 26a4cfa commit 7939cec

2 files changed

Lines changed: 34 additions & 36 deletions

File tree

drivers/video/fbdev/au1100fb.c

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,6 @@ struct fb_bitfield rgb_bitfields[][4] =
8484
{ { 8, 4, 0 }, { 4, 4, 0 }, { 0, 4, 0 }, { 0, 0, 0 } },
8585
};
8686

87-
static struct fb_fix_screeninfo au1100fb_fix = {
88-
.id = "AU1100 FB",
89-
.xpanstep = 1,
90-
.ypanstep = 1,
91-
.type = FB_TYPE_PACKED_PIXELS,
92-
.accel = FB_ACCEL_NONE,
93-
};
94-
95-
static struct fb_var_screeninfo au1100fb_var = {
96-
.activate = FB_ACTIVATE_NOW,
97-
.height = -1,
98-
.width = -1,
99-
.vmode = FB_VMODE_NONINTERLACED,
100-
};
101-
10287
/* fb_blank
10388
* Blank the screen. Depending on the mode, the screen will be
10489
* activated with the backlight color, or desactivated
@@ -432,19 +417,26 @@ static int au1100fb_drv_probe(struct platform_device *dev)
432417
return -EFAULT;
433418
}
434419

435-
au1100fb_fix.mmio_start = regs_res->start;
436-
au1100fb_fix.mmio_len = resource_size(regs_res);
420+
fbdev->info.fix = (struct fb_fix_screeninfo) {
421+
.mmio_start = regs_res->start,
422+
.mmio_len = resource_size(regs_res),
423+
.id = "AU1100 FB",
424+
.xpanstep = 1,
425+
.ypanstep = 1,
426+
.type = FB_TYPE_PACKED_PIXELS,
427+
.accel = FB_ACCEL_NONE,
428+
};
437429

438430
if (!devm_request_mem_region(&dev->dev,
439-
au1100fb_fix.mmio_start,
440-
au1100fb_fix.mmio_len,
431+
fbdev->info.fix.mmio_start,
432+
fbdev->info.fix.mmio_len,
441433
DRIVER_NAME)) {
442434
print_err("fail to lock memory region at 0x%08lx",
443-
au1100fb_fix.mmio_start);
435+
fbdev->info.fix.mmio_start);
444436
return -EBUSY;
445437
}
446438

447-
fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(au1100fb_fix.mmio_start);
439+
fbdev->regs = (struct au1100fb_regs*)KSEG1ADDR(fbdev->info.fix.mmio_start);
448440

449441
print_dbg("Register memory map at %p", fbdev->regs);
450442
print_dbg("phys=0x%08x, size=%d", fbdev->regs_phys, fbdev->regs_len);
@@ -469,22 +461,27 @@ static int au1100fb_drv_probe(struct platform_device *dev)
469461
return -ENOMEM;
470462
}
471463

472-
au1100fb_fix.smem_start = fbdev->fb_phys;
473-
au1100fb_fix.smem_len = fbdev->fb_len;
464+
fbdev->info.fix.smem_start = fbdev->fb_phys;
465+
fbdev->info.fix.smem_len = fbdev->fb_len;
474466

475467
print_dbg("Framebuffer memory map at %p", fbdev->fb_mem);
476468
print_dbg("phys=0x%08x, size=%dK", fbdev->fb_phys, fbdev->fb_len / 1024);
477469

478470
/* load the panel info into the var struct */
479-
au1100fb_var.bits_per_pixel = fbdev->panel->bpp;
480-
au1100fb_var.xres = fbdev->panel->xres;
481-
au1100fb_var.xres_virtual = au1100fb_var.xres;
482-
au1100fb_var.yres = fbdev->panel->yres;
483-
au1100fb_var.yres_virtual = au1100fb_var.yres;
471+
fbdev->info.var = (struct fb_var_screeninfo) {
472+
.activate = FB_ACTIVATE_NOW,
473+
.height = -1,
474+
.width = -1,
475+
.vmode = FB_VMODE_NONINTERLACED,
476+
.bits_per_pixel = fbdev->panel->bpp,
477+
.xres = fbdev->panel->xres,
478+
.xres_virtual = fbdev->panel->xres,
479+
.yres = fbdev->panel->yres,
480+
.yres_virtual = fbdev->panel->yres,
481+
};
484482

485483
fbdev->info.screen_base = fbdev->fb_mem;
486484
fbdev->info.fbops = &au1100fb_ops;
487-
fbdev->info.fix = au1100fb_fix;
488485

489486
fbdev->info.pseudo_palette =
490487
devm_kcalloc(&dev->dev, 16, sizeof(u32), GFP_KERNEL);
@@ -497,8 +494,6 @@ static int au1100fb_drv_probe(struct platform_device *dev)
497494
return -EFAULT;
498495
}
499496

500-
fbdev->info.var = au1100fb_var;
501-
502497
/* Set h/w registers */
503498
au1100fb_setmode(fbdev);
504499

@@ -545,9 +540,7 @@ void au1100fb_drv_remove(struct platform_device *dev)
545540
}
546541

547542
#ifdef CONFIG_PM
548-
static struct au1100fb_regs fbregs;
549-
550-
int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
543+
static int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
551544
{
552545
struct au1100fb_device *fbdev = platform_get_drvdata(dev);
553546

@@ -559,7 +552,7 @@ int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
559552

560553
clk_disable(fbdev->lcdclk);
561554

562-
memcpy(&fbregs, fbdev->regs, sizeof(struct au1100fb_regs));
555+
memcpy(&fbdev->pm_regs, fbdev->regs, sizeof(struct au1100fb_regs));
563556

564557
return 0;
565558
}
@@ -572,7 +565,7 @@ int au1100fb_drv_resume(struct platform_device *dev)
572565
if (!fbdev)
573566
return 0;
574567

575-
memcpy(fbdev->regs, &fbregs, sizeof(struct au1100fb_regs));
568+
memcpy(fbdev->regs, &fbdev->pm_regs, sizeof(struct au1100fb_regs));
576569

577570
ret = clk_enable(fbdev->lcdclk);
578571
if (ret)

drivers/video/fbdev/au1100fb.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ struct au1100fb_device {
105105
size_t regs_len;
106106
unsigned int regs_phys;
107107

108+
#ifdef CONFIG_PM
109+
/* stores the register values during suspend */
110+
struct au1100fb_regs pm_regs;
111+
#endif
112+
108113
unsigned char* fb_mem; /* FrameBuffer memory map */
109114
size_t fb_len;
110115
dma_addr_t fb_phys;

0 commit comments

Comments
 (0)