remarkable-linux/drivers/video/hitfb.c
Tejun Heo 5a0e3ad6af include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files.  percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.

percpu.h -> slab.h dependency is about to be removed.  Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability.  As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.

  http://userweb.kernel.org/~tj/misc/slabh-sweep.py

The script does the followings.

* Scan files for gfp and slab usages and update includes such that
  only the necessary includes are there.  ie. if only gfp is used,
  gfp.h, if slab is used, slab.h.

* When the script inserts a new include, it looks at the include
  blocks and try to put the new include such that its order conforms
  to its surrounding.  It's put in the include block which contains
  core kernel includes, in the same order that the rest are ordered -
  alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
  doesn't seem to be any matching order.

* If the script can't find a place to put a new include (mostly
  because the file doesn't have fitting include block), it prints out
  an error message indicating which .h file needs to be added to the
  file.

The conversion was done in the following steps.

1. The initial automatic conversion of all .c files updated slightly
   over 4000 files, deleting around 700 includes and adding ~480 gfp.h
   and ~3000 slab.h inclusions.  The script emitted errors for ~400
   files.

2. Each error was manually checked.  Some didn't need the inclusion,
   some needed manual addition while adding it to implementation .h or
   embedding .c file was more appropriate for others.  This step added
   inclusions to around 150 files.

3. The script was run again and the output was compared to the edits
   from #2 to make sure no file was left behind.

4. Several build tests were done and a couple of problems were fixed.
   e.g. lib/decompress_*.c used malloc/free() wrappers around slab
   APIs requiring slab.h to be added manually.

5. The script was run on all .h files but without automatically
   editing them as sprinkling gfp.h and slab.h inclusions around .h
   files could easily lead to inclusion dependency hell.  Most gfp.h
   inclusion directives were ignored as stuff from gfp.h was usually
   wildly available and often used in preprocessor macros.  Each
   slab.h inclusion directive was examined and added manually as
   necessary.

6. percpu.h was updated not to include slab.h.

7. Build test were done on the following configurations and failures
   were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
   distributed build env didn't work with gcov compiles) and a few
   more options had to be turned off depending on archs to make things
   build (like ipr on powerpc/64 which failed due to missing writeq).

   * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
   * powerpc and powerpc64 SMP allmodconfig
   * sparc and sparc64 SMP allmodconfig
   * ia64 SMP allmodconfig
   * s390 SMP allmodconfig
   * alpha SMP allmodconfig
   * um on x86_64 SMP allmodconfig

8. percpu.h modifications were reverted so that it could be applied as
   a separate patch and serve as bisection point.

Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.

Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-30 22:02:32 +09:00

502 lines
11 KiB
C

/*
* linux/drivers/video/hitfb.c -- Hitachi LCD frame buffer device
*
* (C) 1999 Mihai Spatar
* (C) 2000 YAEGASHI Takeshi
* (C) 2003, 2004 Paul Mundt
* (C) 2003, 2004, 2006 Andriy Skulysh
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file COPYING in the main directory of this archive for
* more details.
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/fb.h>
#include <asm/machvec.h>
#include <asm/uaccess.h>
#include <asm/pgtable.h>
#include <asm/io.h>
#include <asm/hd64461.h>
#include <cpu/dac.h>
#define WIDTH 640
static struct fb_var_screeninfo hitfb_var __initdata = {
.activate = FB_ACTIVATE_NOW,
.height = -1,
.width = -1,
.vmode = FB_VMODE_NONINTERLACED,
};
static struct fb_fix_screeninfo hitfb_fix __initdata = {
.id = "Hitachi HD64461",
.type = FB_TYPE_PACKED_PIXELS,
.accel = FB_ACCEL_NONE,
};
static inline void hitfb_accel_wait(void)
{
while (fb_readw(HD64461_GRCFGR) & HD64461_GRCFGR_ACCSTATUS) ;
}
static inline void hitfb_accel_start(int truecolor)
{
if (truecolor) {
fb_writew(6, HD64461_GRCFGR);
} else {
fb_writew(7, HD64461_GRCFGR);
}
}
static inline void hitfb_accel_set_dest(int truecolor, u16 dx, u16 dy,
u16 width, u16 height)
{
u32 saddr = WIDTH * dy + dx;
if (truecolor)
saddr <<= 1;
fb_writew(width-1, HD64461_BBTDWR);
fb_writew(height-1, HD64461_BBTDHR);
fb_writew(saddr & 0xffff, HD64461_BBTDSARL);
fb_writew(saddr >> 16, HD64461_BBTDSARH);
}
static inline void hitfb_accel_bitblt(int truecolor, u16 sx, u16 sy, u16 dx,
u16 dy, u16 width, u16 height, u16 rop,
u32 mask_addr)
{
u32 saddr, daddr;
u32 maddr = 0;
height--;
width--;
fb_writew(rop, HD64461_BBTROPR);
if ((sy < dy) || ((sy == dy) && (sx <= dx))) {
saddr = WIDTH * (sy + height) + sx + width;
daddr = WIDTH * (dy + height) + dx + width;
if (mask_addr) {
if (truecolor)
maddr = ((width >> 3) + 1) * (height + 1) - 1;
else
maddr =
(((width >> 4) + 1) * (height + 1) - 1) * 2;
fb_writew((1 << 5) | 1, HD64461_BBTMDR);
} else
fb_writew(1, HD64461_BBTMDR);
} else {
saddr = WIDTH * sy + sx;
daddr = WIDTH * dy + dx;
if (mask_addr) {
fb_writew((1 << 5), HD64461_BBTMDR);
} else {
fb_writew(0, HD64461_BBTMDR);
}
}
if (truecolor) {
saddr <<= 1;
daddr <<= 1;
}
fb_writew(width, HD64461_BBTDWR);
fb_writew(height, HD64461_BBTDHR);
fb_writew(saddr & 0xffff, HD64461_BBTSSARL);
fb_writew(saddr >> 16, HD64461_BBTSSARH);
fb_writew(daddr & 0xffff, HD64461_BBTDSARL);
fb_writew(daddr >> 16, HD64461_BBTDSARH);
if (mask_addr) {
maddr += mask_addr;
fb_writew(maddr & 0xffff, HD64461_BBTMARL);
fb_writew(maddr >> 16, HD64461_BBTMARH);
}
hitfb_accel_start(truecolor);
}
static void hitfb_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
{
if (rect->rop != ROP_COPY)
cfb_fillrect(p, rect);
else {
hitfb_accel_wait();
fb_writew(0x00f0, HD64461_BBTROPR);
fb_writew(16, HD64461_BBTMDR);
if (p->var.bits_per_pixel == 16) {
fb_writew(((u32 *) (p->pseudo_palette))[rect->color],
HD64461_GRSCR);
hitfb_accel_set_dest(1, rect->dx, rect->dy, rect->width,
rect->height);
hitfb_accel_start(1);
} else {
fb_writew(rect->color, HD64461_GRSCR);
hitfb_accel_set_dest(0, rect->dx, rect->dy, rect->width,
rect->height);
hitfb_accel_start(0);
}
}
}
static void hitfb_copyarea(struct fb_info *p, const struct fb_copyarea *area)
{
hitfb_accel_wait();
hitfb_accel_bitblt(p->var.bits_per_pixel == 16, area->sx, area->sy,
area->dx, area->dy, area->width, area->height,
0x00cc, 0);
}
static int hitfb_pan_display(struct fb_var_screeninfo *var,
struct fb_info *info)
{
int xoffset = var->xoffset;
int yoffset = var->yoffset;
if (xoffset != 0)
return -EINVAL;
fb_writew((yoffset*info->fix.line_length)>>10, HD64461_LCDCBAR);
return 0;
}
int hitfb_blank(int blank_mode, struct fb_info *info)
{
unsigned short v;
if (blank_mode) {
v = fb_readw(HD64461_LDR1);
v &= ~HD64461_LDR1_DON;
fb_writew(v, HD64461_LDR1);
v = fb_readw(HD64461_LCDCCR);
v |= HD64461_LCDCCR_MOFF;
fb_writew(v, HD64461_LCDCCR);
v = fb_readw(HD64461_STBCR);
v |= HD64461_STBCR_SLCDST;
fb_writew(v, HD64461_STBCR);
} else {
v = fb_readw(HD64461_STBCR);
v &= ~HD64461_STBCR_SLCDST;
fb_writew(v, HD64461_STBCR);
v = fb_readw(HD64461_LCDCCR);
v &= ~(HD64461_LCDCCR_MOFF | HD64461_LCDCCR_STREQ);
fb_writew(v, HD64461_LCDCCR);
do {
v = fb_readw(HD64461_LCDCCR);
} while(v&HD64461_LCDCCR_STBACK);
v = fb_readw(HD64461_LDR1);
v |= HD64461_LDR1_DON;
fb_writew(v, HD64461_LDR1);
}
return 0;
}
static int hitfb_setcolreg(unsigned regno, unsigned red, unsigned green,
unsigned blue, unsigned transp, struct fb_info *info)
{
if (regno >= 256)
return 1;
switch (info->var.bits_per_pixel) {
case 8:
fb_writew(regno << 8, HD64461_CPTWAR);
fb_writew(red >> 10, HD64461_CPTWDR);
fb_writew(green >> 10, HD64461_CPTWDR);
fb_writew(blue >> 10, HD64461_CPTWDR);
break;
case 16:
if (regno >= 16)
return 1;
((u32 *) (info->pseudo_palette))[regno] =
((red & 0xf800)) |
((green & 0xfc00) >> 5) | ((blue & 0xf800) >> 11);
break;
}
return 0;
}
static int hitfb_sync(struct fb_info *info)
{
hitfb_accel_wait();
return 0;
}
static int hitfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
{
int maxy;
var->xres = info->var.xres;
var->xres_virtual = info->var.xres;
var->yres = info->var.yres;
if ((var->bits_per_pixel != 8) && (var->bits_per_pixel != 16))
var->bits_per_pixel = info->var.bits_per_pixel;
if (var->yres_virtual < var->yres)
var->yres_virtual = var->yres;
maxy = info->fix.smem_len / var->xres;
if (var->bits_per_pixel == 16)
maxy /= 2;
if (var->yres_virtual > maxy)
var->yres_virtual = maxy;
var->xoffset = 0;
var->yoffset = 0;
switch (var->bits_per_pixel) {
case 8:
var->red.offset = 0;
var->red.length = 8;
var->green.offset = 0;
var->green.length = 8;
var->blue.offset = 0;
var->blue.length = 8;
var->transp.offset = 0;
var->transp.length = 0;
break;
case 16: /* RGB 565 */
var->red.offset = 11;
var->red.length = 5;
var->green.offset = 5;
var->green.length = 6;
var->blue.offset = 0;
var->blue.length = 5;
var->transp.offset = 0;
var->transp.length = 0;
break;
}
return 0;
}
static int hitfb_set_par(struct fb_info *info)
{
unsigned short ldr3;
switch (info->var.bits_per_pixel) {
case 8:
info->fix.line_length = info->var.xres;
info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
info->fix.ypanstep = 16;
break;
case 16:
info->fix.line_length = info->var.xres*2;
info->fix.visual = FB_VISUAL_TRUECOLOR;
info->fix.ypanstep = 8;
break;
}
fb_writew(info->fix.line_length, HD64461_LCDCLOR);
ldr3 = fb_readw(HD64461_LDR3);
ldr3 &= ~15;
ldr3 |= (info->var.bits_per_pixel == 8) ? 4 : 8;
fb_writew(ldr3, HD64461_LDR3);
return 0;
}
static struct fb_ops hitfb_ops = {
.owner = THIS_MODULE,
.fb_check_var = hitfb_check_var,
.fb_set_par = hitfb_set_par,
.fb_setcolreg = hitfb_setcolreg,
.fb_blank = hitfb_blank,
.fb_sync = hitfb_sync,
.fb_pan_display = hitfb_pan_display,
.fb_fillrect = hitfb_fillrect,
.fb_copyarea = hitfb_copyarea,
.fb_imageblit = cfb_imageblit,
};
static int __devinit hitfb_probe(struct platform_device *dev)
{
unsigned short lcdclor, ldr3, ldvndr;
struct fb_info *info;
int ret;
if (fb_get_options("hitfb", NULL))
return -ENODEV;
hitfb_fix.mmio_start = HD64461_IO_OFFSET(0x1000);
hitfb_fix.mmio_len = 0x1000;
hitfb_fix.smem_start = HD64461_IO_OFFSET(0x02000000);
hitfb_fix.smem_len = 512 * 1024;
lcdclor = fb_readw(HD64461_LCDCLOR);
ldvndr = fb_readw(HD64461_LDVNDR);
ldr3 = fb_readw(HD64461_LDR3);
switch (ldr3 & 15) {
default:
case 4:
hitfb_var.bits_per_pixel = 8;
hitfb_var.xres = lcdclor;
break;
case 8:
hitfb_var.bits_per_pixel = 16;
hitfb_var.xres = lcdclor / 2;
break;
}
hitfb_fix.line_length = lcdclor;
hitfb_fix.visual = (hitfb_var.bits_per_pixel == 8) ?
FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
hitfb_var.yres = ldvndr + 1;
hitfb_var.xres_virtual = hitfb_var.xres;
hitfb_var.yres_virtual = hitfb_fix.smem_len / lcdclor;
switch (hitfb_var.bits_per_pixel) {
case 8:
hitfb_var.red.offset = 0;
hitfb_var.red.length = 8;
hitfb_var.green.offset = 0;
hitfb_var.green.length = 8;
hitfb_var.blue.offset = 0;
hitfb_var.blue.length = 8;
hitfb_var.transp.offset = 0;
hitfb_var.transp.length = 0;
break;
case 16: /* RGB 565 */
hitfb_var.red.offset = 11;
hitfb_var.red.length = 5;
hitfb_var.green.offset = 5;
hitfb_var.green.length = 6;
hitfb_var.blue.offset = 0;
hitfb_var.blue.length = 5;
hitfb_var.transp.offset = 0;
hitfb_var.transp.length = 0;
break;
}
info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
if (unlikely(!info))
return -ENOMEM;
info->fbops = &hitfb_ops;
info->var = hitfb_var;
info->fix = hitfb_fix;
info->pseudo_palette = info->par;
info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
info->screen_base = (void *)hitfb_fix.smem_start;
ret = fb_alloc_cmap(&info->cmap, 256, 0);
if (unlikely(ret < 0))
goto err_fb;
ret = register_framebuffer(info);
if (unlikely(ret < 0))
goto err;
platform_set_drvdata(dev, info);
printk(KERN_INFO "fb%d: %s frame buffer device\n",
info->node, info->fix.id);
return 0;
err:
fb_dealloc_cmap(&info->cmap);
err_fb:
framebuffer_release(info);
return ret;
}
static int __exit hitfb_remove(struct platform_device *dev)
{
struct fb_info *info = platform_get_drvdata(dev);
unregister_framebuffer(info);
fb_dealloc_cmap(&info->cmap);
framebuffer_release(info);
return 0;
}
static int hitfb_suspend(struct device *dev)
{
u16 v;
hitfb_blank(1,0);
v = fb_readw(HD64461_STBCR);
v |= HD64461_STBCR_SLCKE_IST;
fb_writew(v, HD64461_STBCR);
return 0;
}
static int hitfb_resume(struct device *dev)
{
u16 v;
v = fb_readw(HD64461_STBCR);
v &= ~HD64461_STBCR_SLCKE_OST;
msleep(100);
v = fb_readw(HD64461_STBCR);
v &= ~HD64461_STBCR_SLCKE_IST;
fb_writew(v, HD64461_STBCR);
hitfb_blank(0,0);
return 0;
}
static const struct dev_pm_ops hitfb_dev_pm_ops = {
.suspend = hitfb_suspend,
.resume = hitfb_resume,
};
static struct platform_driver hitfb_driver = {
.probe = hitfb_probe,
.remove = __exit_p(hitfb_remove),
.driver = {
.name = "hitfb",
.owner = THIS_MODULE,
.pm = &hitfb_dev_pm_ops,
},
};
static struct platform_device hitfb_device = {
.name = "hitfb",
.id = -1,
};
static int __init hitfb_init(void)
{
int ret;
ret = platform_driver_register(&hitfb_driver);
if (!ret) {
ret = platform_device_register(&hitfb_device);
if (ret)
platform_driver_unregister(&hitfb_driver);
}
return ret;
}
static void __exit hitfb_exit(void)
{
platform_device_unregister(&hitfb_device);
platform_driver_unregister(&hitfb_driver);
}
module_init(hitfb_init);
module_exit(hitfb_exit);
MODULE_LICENSE("GPL");