📄 epson1355fb.c
字号:
if (__put_user(v, dst)) return n; src++, dst++; n -= 2; } if (n) { u8 v = fb_readb(src); if (__put_user(v, ((u8 *) dst))) return n; } return 0;}static ssize_tepson1355fb_read(struct file *file, char *buf, size_t count, loff_t * ppos){ struct inode *inode = file->f_dentry->d_inode; int fbidx = iminor(inode); struct fb_info *info = registered_fb[fbidx]; unsigned long p = *ppos; /* from fbmem.c except for our own copy_*_user */ if (!info || !info->screen_base) return -ENODEV; if (p >= info->fix.smem_len) return 0; if (count >= info->fix.smem_len) count = info->fix.smem_len; if (count + p > info->fix.smem_len) count = info->fix.smem_len - p; if (count) { char *base_addr; base_addr = info->screen_base; count -= copy_to_user16(buf, base_addr + p, count); if (!count) return -EFAULT; *ppos += count; } return count;}static ssize_tepson1355fb_write(struct file *file, const char *buf, size_t count, loff_t * ppos){ struct inode *inode = file->f_dentry->d_inode; int fbidx = iminor(inode); struct fb_info *info = registered_fb[fbidx]; unsigned long p = *ppos; int err; /* from fbmem.c except for our own copy_*_user */ if (!info || !info->screen_base) return -ENODEV; /* from fbmem.c except for our own copy_*_user */ if (p > info->fix.smem_len) return -ENOSPC; if (count >= info->fix.smem_len) count = info->fix.smem_len; err = 0; if (count + p > info->fix.smem_len) { count = info->fix.smem_len - p; err = -ENOSPC; } if (count) { char *base_addr; base_addr = info->screen_base; count -= copy_from_user16(base_addr + p, buf, count); *ppos += count; err = -EFAULT; } if (count) return count; return err;}/* ------------------------------------------------------------------------- */static struct fb_ops epson1355fb_fbops = { .owner = THIS_MODULE, .fb_setcolreg = epson1355fb_setcolreg, .fb_pan_display = epson1355fb_pan_display, .fb_blank = epson1355fb_blank, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit, .fb_read = epson1355fb_read, .fb_write = epson1355fb_write,};/* ------------------------------------------------------------------------- */static __init unsigned int get_fb_size(struct fb_info *info){ unsigned int size = 2 * 1024 * 1024; char *p = info->screen_base; /* the 512k framebuffer is aliased at start + 0x80000 * n */ fb_writeb(1, p); fb_writeb(0, p + 0x80000); if (!fb_readb(p)) size = 512 * 1024; fb_writeb(0, p); return size;}static int epson1355_width_tab[2][4] __initdata = { {4, 8, 16, -1}, {9, 12, 16, -1} };static int epson1355_bpp_tab[8] __initdata = { 1, 2, 4, 8, 15, 16 };static void __init fetch_hw_state(struct fb_info *info, struct epson1355_par *par){ struct fb_var_screeninfo *var = &info->var; struct fb_fix_screeninfo *fix = &info->fix; u8 panel, display; u16 offset; u32 xres, yres; u32 xres_virtual, yres_virtual; int bpp, lcd_bpp; int is_color, is_dual, is_tft; int lcd_enabled, crt_enabled; fix->type = FB_TYPE_PACKED_PIXELS; display = epson1355_read_reg(par, REG_DISPLAY_MODE); bpp = epson1355_bpp_tab[(display >> 2) & 7]; switch (bpp) { case 8: fix->visual = FB_VISUAL_PSEUDOCOLOR; var->bits_per_pixel = 8; var->red.offset = var->green.offset = var->blue.offset = 0; var->red.length = var->green.length = var->blue.length = 8; break; case 16: /* 5-6-5 RGB */ fix->visual = FB_VISUAL_TRUECOLOR; var->bits_per_pixel = 16; var->red.offset = 11; var->red.length = 5; var->green.offset = 5; var->green.length = 6; var->blue.offset = 0; var->blue.length = 5; break; default: BUG(); } fb_alloc_cmap(&(info->cmap), 256, 0); panel = epson1355_read_reg(par, REG_PANEL_TYPE); is_color = (panel & 0x04) != 0; is_dual = (panel & 0x02) != 0; is_tft = (panel & 0x01) != 0; crt_enabled = (display & 0x02) != 0; lcd_enabled = (display & 0x01) != 0; lcd_bpp = epson1355_width_tab[is_tft][(panel >> 4) & 3]; xres = (epson1355_read_reg(par, REG_HORZ_DISP_WIDTH) + 1) * 8; yres = (epson1355_read_reg16(par, REG_VERT_DISP_HEIGHT0) + 1) * ((is_dual && !crt_enabled) ? 2 : 1); offset = epson1355_read_reg16(par, REG_MEM_ADDR_OFFSET0) & 0x7ff; xres_virtual = offset * 16 / bpp; yres_virtual = fix->smem_len / (offset * 2); var->xres = xres; var->yres = yres; var->xres_virtual = xres_virtual; var->yres_virtual = yres_virtual; var->xoffset = var->yoffset = 0; fix->line_length = offset * 2; fix->xpanstep = 0; /* no pan yet */ fix->ypanstep = 1; fix->ywrapstep = 0; fix->accel = FB_ACCEL_NONE; var->grayscale = !is_color;#ifdef DEBUG printk(KERN_INFO "epson1355fb: xres=%d, yres=%d, " "is_color=%d, is_dual=%d, is_tft=%d\n", xres, yres, is_color, is_dual, is_tft); printk(KERN_INFO "epson1355fb: bpp=%d, lcd_bpp=%d, " "crt_enabled=%d, lcd_enabled=%d\n", bpp, lcd_bpp, crt_enabled, lcd_enabled);#endif}static void clearfb16(struct fb_info *info){ u16 *dst = (u16 *) info->screen_base; unsigned long n = info->fix.smem_len; while (n > 1) { fb_writew(0, dst); dst++, n -= 2; } if (n) fb_writeb(0, dst);}static void epson1355fb_platform_release(struct device *device){}static int epson1355fb_remove(struct platform_device *dev){ struct fb_info *info = platform_get_drvdata(dev); struct epson1355_par *par = info->par; backlight_enable(0); if (par) { lcd_enable(par, 0); if (par && par->reg_addr) iounmap((void *) par->reg_addr); } if (info) { fb_dealloc_cmap(&info->cmap); if (info->screen_base) iounmap(info->screen_base); framebuffer_release(info); } release_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN); release_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN); return 0;}int __init epson1355fb_probe(struct platform_device *dev){ struct epson1355_par *default_par; struct fb_info *info; u8 revision; int rc = 0; if (!request_mem_region(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN, "S1D13505 registers")) { printk(KERN_ERR "epson1355fb: unable to reserve " "registers at 0x%0x\n", EPSON1355FB_REGS_PHYS); rc = -EBUSY; goto bail; } if (!request_mem_region(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN, "S1D13505 framebuffer")) { printk(KERN_ERR "epson1355fb: unable to reserve " "framebuffer at 0x%0x\n", EPSON1355FB_FB_PHYS); rc = -EBUSY; goto bail; } info = framebuffer_alloc(sizeof(struct epson1355_par) + sizeof(u32) * 256, &dev->dev); if (!info) rc = -ENOMEM; goto bail; default_par = info->par; default_par->reg_addr = (unsigned long) ioremap(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN); if (!default_par->reg_addr) { printk(KERN_ERR "epson1355fb: unable to map registers\n"); rc = -ENOMEM; goto bail; } info->pseudo_palette = (void *)(default_par + 1); info->screen_base = ioremap(EPSON1355FB_FB_PHYS, EPSON1355FB_FB_LEN); if (!info->screen_base) { printk(KERN_ERR "epson1355fb: unable to map framebuffer\n"); rc = -ENOMEM; goto bail; } revision = epson1355_read_reg(default_par, REG_REVISION_CODE); if ((revision >> 2) != 3) { printk(KERN_INFO "epson1355fb: epson1355 not found\n"); rc = -ENODEV; goto bail; } info->fix.mmio_start = EPSON1355FB_REGS_PHYS; info->fix.mmio_len = EPSON1355FB_REGS_LEN; info->fix.smem_start = EPSON1355FB_FB_PHYS; info->fix.smem_len = get_fb_size(info); printk(KERN_INFO "epson1355fb: regs mapped at 0x%lx, fb %d KiB mapped at 0x%p\n", default_par->reg_addr, info->fix.smem_len / 1024, info->screen_base); strcpy(info->fix.id, "S1D13505"); info->par = default_par; info->fbops = &epson1355fb_fbops; info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; /* we expect the boot loader to have initialized the chip with appropriate parameters from which we can determinte the flavor of lcd panel attached */ fetch_hw_state(info, default_par); /* turn this puppy on ... */ clearfb16(info); backlight_enable(1); lcd_enable(default_par, 1); if (register_framebuffer(info) < 0) { rc = -EINVAL; goto bail; } /* * Our driver data. */ platform_set_drvdata(dev, info); printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node, info->fix.id); return 0; bail: epson1355fb_remove(dev); return rc;}static struct platform_driver epson1355fb_driver = { .probe = epson1355fb_probe, .remove = epson1355fb_remove, .driver = { .name = "epson1355fb", },};static struct platform_device epson1355fb_device = { .name = "epson1355fb", .id = 0, .dev = { .release = epson1355fb_platform_release, }};int __init epson1355fb_init(void){ int ret = 0; if (fb_get_options("epson1355fb", NULL)) return -ENODEV; ret = platform_driver_register(&epson1355fb_driver); if (!ret) { ret = platform_device_register(&epson1355fb_device); if (ret) platform_driver_unregister(&epson1355fb_driver); } return ret;}module_init(epson1355fb_init); #ifdef MODULEstatic void __exit epson1355fb_exit(void){ platform_device_unregister(&epson1355fb_device); platform_driver_unregister(&epson1355fb_driver);}/* ------------------------------------------------------------------------- */module_exit(epson1355fb_exit);#endifMODULE_AUTHOR("Christopher Hoover <ch@hpl.hp.com>");MODULE_DESCRIPTION("Framebuffer driver for Epson S1D13505");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -