📄 arkfb.c
字号:
case 0: case 4: if (regno >= 16) return -EINVAL; if ((fb->var.bits_per_pixel == 4) && (fb->var.nonstd == 0)) { outb(0xF0, VGA_PEL_MSK); outb(regno*16, VGA_PEL_IW); } else { outb(0x0F, VGA_PEL_MSK); outb(regno, VGA_PEL_IW); } outb(red >> 10, VGA_PEL_D); outb(green >> 10, VGA_PEL_D); outb(blue >> 10, VGA_PEL_D); break; case 8: if (regno >= 256) return -EINVAL; outb(0xFF, VGA_PEL_MSK); outb(regno, VGA_PEL_IW); outb(red >> 10, VGA_PEL_D); outb(green >> 10, VGA_PEL_D); outb(blue >> 10, VGA_PEL_D); break; case 16: if (regno >= 16) return 0; if (fb->var.green.length == 5) ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) | ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11); else if (fb->var.green.length == 6) ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) | ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11); else return -EINVAL; break; case 24: case 32: if (regno >= 16) return 0; ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) | (green & 0xFF00) | ((blue & 0xFF00) >> 8); break; default: return -EINVAL; } return 0;}/* Set the display blanking state */static int arkfb_blank(int blank_mode, struct fb_info *info){ switch (blank_mode) { case FB_BLANK_UNBLANK: pr_debug("fb%d: unblank\n", info->node); svga_wseq_mask(0x01, 0x00, 0x20); svga_wcrt_mask(0x17, 0x80, 0x80); break; case FB_BLANK_NORMAL: pr_debug("fb%d: blank\n", info->node); svga_wseq_mask(0x01, 0x20, 0x20); svga_wcrt_mask(0x17, 0x80, 0x80); break; case FB_BLANK_POWERDOWN: case FB_BLANK_HSYNC_SUSPEND: case FB_BLANK_VSYNC_SUSPEND: pr_debug("fb%d: sync down\n", info->node); svga_wseq_mask(0x01, 0x20, 0x20); svga_wcrt_mask(0x17, 0x00, 0x80); break; } return 0;}/* Pan the display */static int arkfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info){ unsigned int offset; /* Calculate the offset */ if (var->bits_per_pixel == 0) { offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2); offset = offset >> 2; } else { offset = (var->yoffset * info->fix.line_length) + (var->xoffset * var->bits_per_pixel / 8); offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 3); } /* Set the offset */ svga_wcrt_multi(ark_start_address_regs, offset); return 0;}/* ------------------------------------------------------------------------- *//* Frame buffer operations */static struct fb_ops arkfb_ops = { .owner = THIS_MODULE, .fb_open = arkfb_open, .fb_release = arkfb_release, .fb_check_var = arkfb_check_var, .fb_set_par = arkfb_set_par, .fb_setcolreg = arkfb_setcolreg, .fb_blank = arkfb_blank, .fb_pan_display = arkfb_pan_display, .fb_fillrect = arkfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = arkfb_imageblit, .fb_get_caps = svga_get_caps,};/* ------------------------------------------------------------------------- *//* PCI probe */static int __devinit ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id){ struct fb_info *info; struct arkfb_info *par; int rc; u8 regval; /* Ignore secondary VGA device because there is no VGA arbitration */ if (! svga_primary_device(dev)) { dev_info(&(dev->dev), "ignoring secondary device\n"); return -ENODEV; } /* Allocate and fill driver data structure */ info = framebuffer_alloc(sizeof(struct arkfb_info), &(dev->dev)); if (! info) { dev_err(&(dev->dev), "cannot allocate memory\n"); return -ENOMEM; } par = info->par; mutex_init(&par->open_lock); info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN; info->fbops = &arkfb_ops; /* Prepare PCI device */ rc = pci_enable_device(dev); if (rc < 0) { dev_err(info->device, "cannot enable PCI device\n"); goto err_enable_device; } rc = pci_request_regions(dev, "arkfb"); if (rc < 0) { dev_err(info->device, "cannot reserve framebuffer region\n"); goto err_request_regions; } par->dac = ics5342_init(ark_dac_read_regs, ark_dac_write_regs, info); if (! par->dac) { rc = -ENOMEM; dev_err(info->device, "RAMDAC initialization failed\n"); goto err_dac; } info->fix.smem_start = pci_resource_start(dev, 0); info->fix.smem_len = pci_resource_len(dev, 0); /* Map physical IO memory address into kernel space */ info->screen_base = pci_iomap(dev, 0, 0); if (! info->screen_base) { rc = -ENOMEM; dev_err(info->device, "iomap for framebuffer failed\n"); goto err_iomap; } /* FIXME get memsize */ regval = vga_rseq(NULL, 0x10); info->screen_size = (1 << (regval >> 6)) << 20; info->fix.smem_len = info->screen_size; strcpy(info->fix.id, "ARK 2000PV"); info->fix.mmio_start = 0; info->fix.mmio_len = 0; info->fix.type = FB_TYPE_PACKED_PIXELS; info->fix.visual = FB_VISUAL_PSEUDOCOLOR; info->fix.ypanstep = 0; info->fix.accel = FB_ACCEL_NONE; info->pseudo_palette = (void*) (par->pseudo_palette); /* Prepare startup mode */ rc = fb_find_mode(&(info->var), info, mode_option, NULL, 0, NULL, 8); if (! ((rc == 1) || (rc == 2))) { rc = -EINVAL; dev_err(info->device, "mode %s not found\n", mode_option); goto err_find_mode; } rc = fb_alloc_cmap(&info->cmap, 256, 0); if (rc < 0) { dev_err(info->device, "cannot allocate colormap\n"); goto err_alloc_cmap; } rc = register_framebuffer(info); if (rc < 0) { dev_err(info->device, "cannot register framebugger\n"); goto err_reg_fb; } printk(KERN_INFO "fb%d: %s on %s, %d MB RAM\n", info->node, info->fix.id, pci_name(dev), info->fix.smem_len >> 20); /* Record a reference to the driver data */ pci_set_drvdata(dev, info);#ifdef CONFIG_MTRR if (mtrr) { par->mtrr_reg = -1; par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1); }#endif return 0; /* Error handling */err_reg_fb: fb_dealloc_cmap(&info->cmap);err_alloc_cmap:err_find_mode: pci_iounmap(dev, info->screen_base);err_iomap: dac_release(par->dac);err_dac: pci_release_regions(dev);err_request_regions:/* pci_disable_device(dev); */err_enable_device: framebuffer_release(info); return rc;}/* PCI remove */static void __devexit ark_pci_remove(struct pci_dev *dev){ struct fb_info *info = pci_get_drvdata(dev); if (info) { struct arkfb_info *par = info->par;#ifdef CONFIG_MTRR if (par->mtrr_reg >= 0) { mtrr_del(par->mtrr_reg, 0, 0); par->mtrr_reg = -1; }#endif dac_release(par->dac); unregister_framebuffer(info); fb_dealloc_cmap(&info->cmap); pci_iounmap(dev, info->screen_base); pci_release_regions(dev);/* pci_disable_device(dev); */ pci_set_drvdata(dev, NULL); framebuffer_release(info); }}#ifdef CONFIG_PM/* PCI suspend */static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state){ struct fb_info *info = pci_get_drvdata(dev); struct arkfb_info *par = info->par; dev_info(info->device, "suspend\n"); acquire_console_sem(); mutex_lock(&(par->open_lock)); if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) { mutex_unlock(&(par->open_lock)); release_console_sem(); return 0; } fb_set_suspend(info, 1); pci_save_state(dev); pci_disable_device(dev); pci_set_power_state(dev, pci_choose_state(dev, state)); mutex_unlock(&(par->open_lock)); release_console_sem(); return 0;}/* PCI resume */static int ark_pci_resume (struct pci_dev* dev){ struct fb_info *info = pci_get_drvdata(dev); struct arkfb_info *par = info->par; dev_info(info->device, "resume\n"); acquire_console_sem(); mutex_lock(&(par->open_lock)); if (par->ref_count == 0) goto fail; pci_set_power_state(dev, PCI_D0); pci_restore_state(dev); if (pci_enable_device(dev)) goto fail; pci_set_master(dev); arkfb_set_par(info); fb_set_suspend(info, 0);fail: mutex_unlock(&(par->open_lock)); release_console_sem(); return 0;}#else#define ark_pci_suspend NULL#define ark_pci_resume NULL#endif /* CONFIG_PM *//* List of boards that we are trying to support */static struct pci_device_id ark_devices[] __devinitdata = { {PCI_DEVICE(0xEDD8, 0xA099)}, {0, 0, 0, 0, 0, 0, 0}};MODULE_DEVICE_TABLE(pci, ark_devices);static struct pci_driver arkfb_pci_driver = { .name = "arkfb", .id_table = ark_devices, .probe = ark_pci_probe, .remove = __devexit_p(ark_pci_remove), .suspend = ark_pci_suspend, .resume = ark_pci_resume,};/* Cleanup */static void __exit arkfb_cleanup(void){ pr_debug("arkfb: cleaning up\n"); pci_unregister_driver(&arkfb_pci_driver);}/* Driver Initialisation */static int __init arkfb_init(void){#ifndef MODULE char *option = NULL; if (fb_get_options("arkfb", &option)) return -ENODEV; if (option && *option) mode_option = option;#endif pr_debug("arkfb: initializing\n"); return pci_register_driver(&arkfb_pci_driver);}module_init(arkfb_init);module_exit(arkfb_cleanup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -