📄 cyber2000fb.c
字号:
int old; old = cyber2000_grphr(EXT_FUNC_CTL, cfb); old |= EXT_FUNC_CTL_EXTREGENBL; cyber2000_grphw(EXT_FUNC_CTL, old, cfb); }}/* * Disable access to the extended registers */void cyber2000fb_disable_extregs(struct cfb_info *cfb){ if (cfb->func_use_count == 1) { int old; old = cyber2000_grphr(EXT_FUNC_CTL, cfb); old &= ~EXT_FUNC_CTL_EXTREGENBL; cyber2000_grphw(EXT_FUNC_CTL, old, cfb); } if (cfb->func_use_count == 0) printk(KERN_ERR "disable_extregs: count = 0\n"); else cfb->func_use_count -= 1;}void cyber2000fb_get_fb_var(struct cfb_info *cfb, struct fb_var_screeninfo *var){ memcpy(var, &cfb->display->var, sizeof(struct fb_var_screeninfo));}/* * Attach a capture/tv driver to the core CyberX0X0 driver. */int cyber2000fb_attach(struct cyberpro_info *info, int idx){ if (int_cfb_info != NULL) { info->dev = int_cfb_info->dev; info->regs = int_cfb_info->regs; info->fb = int_cfb_info->fb.screen_base; info->fb_size = int_cfb_info->fb.fix.smem_len; info->enable_extregs = cyber2000fb_enable_extregs; info->disable_extregs = cyber2000fb_disable_extregs; info->info = int_cfb_info; strncpy(info->dev_name, int_cfb_info->fb.fix.id, sizeof(info->dev_name)); MOD_INC_USE_COUNT; } return int_cfb_info != NULL;}/* * Detach a capture/tv driver from the core CyberX0X0 driver. */void cyber2000fb_detach(int idx){ MOD_DEC_USE_COUNT;}EXPORT_SYMBOL(cyber2000fb_attach);EXPORT_SYMBOL(cyber2000fb_detach);EXPORT_SYMBOL(cyber2000fb_enable_extregs);EXPORT_SYMBOL(cyber2000fb_disable_extregs);EXPORT_SYMBOL(cyber2000fb_get_fb_var);/* * These parameters give * 640x480, hsync 31.5kHz, vsync 60Hz */static struct fb_videomode __devinitdata cyber2000fb_default_mode = { refresh: 60, xres: 640, yres: 480, pixclock: 39722, left_margin: 56, right_margin: 16, upper_margin: 34, lower_margin: 9, hsync_len: 88, vsync_len: 2, sync: FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, vmode: FB_VMODE_NONINTERLACED};static char igs_regs[] __devinitdata = { EXT_CRT_IRQ, 0, EXT_CRT_TEST, 0, EXT_SYNC_CTL, 0, EXT_SEG_WRITE_PTR, 0, EXT_SEG_READ_PTR, 0, EXT_BIU_MISC, EXT_BIU_MISC_LIN_ENABLE | EXT_BIU_MISC_COP_ENABLE | EXT_BIU_MISC_COP_BFC, EXT_FUNC_CTL, 0, CURS_H_START, 0, CURS_H_START + 1, 0, CURS_H_PRESET, 0, CURS_V_START, 0, CURS_V_START + 1, 0, CURS_V_PRESET, 0, CURS_CTL, 0, EXT_ATTRIB_CTL, EXT_ATTRIB_CTL_EXT, EXT_OVERSCAN_RED, 0, EXT_OVERSCAN_GREEN, 0, EXT_OVERSCAN_BLUE, 0, /* some of these are questionable when we have a BIOS */ EXT_MEM_CTL0, EXT_MEM_CTL0_7CLK | EXT_MEM_CTL0_RAS_1 | EXT_MEM_CTL0_MULTCAS, EXT_HIDDEN_CTL1, 0x30, EXT_FIFO_CTL, 0x0b, EXT_FIFO_CTL + 1, 0x17, 0x76, 0x00, EXT_HIDDEN_CTL4, 0xc8};/* * Initialise the CyberPro hardware. On the CyberPro5XXXX, * ensure that we're using the correct PLL (5XXX's may be * programmed to use an additional set of PLLs.) */static void cyberpro_init_hw(struct cfb_info *cfb){ int i; for (i = 0; i < sizeof(igs_regs); i += 2) cyber2000_grphw(igs_regs[i], igs_regs[i+1], cfb); if (cfb->fb.fix.accel == FB_ACCEL_IGS_CYBER5000) { unsigned char val; cyber2000fb_writeb(0xba, 0x3ce, cfb); val = cyber2000fb_readb(0x3cf, cfb) & 0x80; cyber2000fb_writeb(val, 0x3cf, cfb); }}static struct cfb_info * __devinitcyberpro_alloc_fb_info(unsigned int id, char *name){ struct cfb_info *cfb; cfb = kmalloc(sizeof(struct cfb_info) + sizeof(struct display) + sizeof(u32) * 16, GFP_KERNEL); if (!cfb) return NULL; memset(cfb, 0, sizeof(struct cfb_info) + sizeof(struct display)); if (id == ID_CYBERPRO_5000) cfb->ref_ps = 40690; // 24.576 MHz else cfb->ref_ps = 69842; // 14.31818 MHz (69841?) cfb->divisors[0] = 1; cfb->divisors[1] = 2; cfb->divisors[2] = 4; if (id == ID_CYBERPRO_2000) cfb->divisors[3] = 8; else cfb->divisors[3] = 6; strcpy(cfb->fb.fix.id, name); cfb->fb.fix.type = FB_TYPE_PACKED_PIXELS; cfb->fb.fix.type_aux = 0; cfb->fb.fix.xpanstep = 0; cfb->fb.fix.ypanstep = 1; cfb->fb.fix.ywrapstep = 0; switch (id) { case ID_IGA_1682: cfb->fb.fix.accel = 0; break; case ID_CYBERPRO_2000: cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2000; break; case ID_CYBERPRO_2010: cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER2010; break; case ID_CYBERPRO_5000: cfb->fb.fix.accel = FB_ACCEL_IGS_CYBER5000; break; } cfb->fb.var.nonstd = 0; cfb->fb.var.activate = FB_ACTIVATE_NOW; cfb->fb.var.height = -1; cfb->fb.var.width = -1; cfb->fb.var.accel_flags = FB_ACCELF_TEXT; strcpy(cfb->fb.modename, cfb->fb.fix.id); strcpy(cfb->fb.fontname, default_font); cfb->fb.fbops = &cyber2000fb_ops; cfb->fb.changevar = NULL; cfb->fb.switch_con = cyber2000fb_switch; cfb->fb.updatevar = cyber2000fb_updatevar; cfb->fb.blank = cyber2000fb_blank; cfb->fb.flags = FBINFO_FLAG_DEFAULT; cfb->fb.disp = (struct display *)(cfb + 1); cfb->fb.pseudo_palette = (void *)(cfb->fb.disp + 1); fb_alloc_cmap(&cfb->fb.cmap, NR_PALETTE, 0); return cfb;}static void __devinitcyberpro_free_fb_info(struct cfb_info *cfb){ if (cfb) { /* * Free the colourmap */ fb_alloc_cmap(&cfb->fb.cmap, 0, 0); kfree(cfb); }}/* * Parse Cyber2000fb options. Usage: * video=cyber2000:font:fontname */intcyber2000fb_setup(char *options){ char *opt; if (!options || !*options) return 0; while ((opt = strsep(&options, ",")) != NULL) { if (!*opt) continue; if (strncmp(opt, "font:", 5) == 0) { strncpy(default_font_storage, opt + 5, sizeof(default_font_storage)); default_font = default_font_storage; continue; } printk(KERN_ERR "CyberPro20x0: unknown parameter: %s\n", opt); } return 0;}/* * The CyberPro chips can be placed on many different bus types. * This probe function is common to all bus types. The bus-specific * probe function is expected to have: * - enabled access to the linear memory region * - memory mapped access to the registers * - initialised mem_ctl1 and mem_ctl2 appropriately. */static int __devinit cyberpro_common_probe(struct cfb_info *cfb){ u_long smem_size; u_int h_sync, v_sync; int err; /* * Get the video RAM size and width from the VGA register. * This should have been already initialised by the BIOS, * but if it's garbage, claim default 1MB VRAM (woody) */ cfb->mem_ctl1 = cyber2000_grphr(EXT_MEM_CTL1, cfb); cfb->mem_ctl2 = cyber2000_grphr(EXT_MEM_CTL2, cfb); /* * Determine the size of the memory. */ switch (cfb->mem_ctl2 & MEM_CTL2_SIZE_MASK) { case MEM_CTL2_SIZE_4MB: smem_size = 0x00400000; break; case MEM_CTL2_SIZE_2MB: smem_size = 0x00200000; break; case MEM_CTL2_SIZE_1MB: smem_size = 0x00100000; break; default: smem_size = 0x00100000; break; } cfb->fb.fix.smem_len = smem_size; cfb->fb.fix.mmio_len = MMIO_SIZE; cfb->fb.screen_base = cfb->region; err = -EINVAL; if (!fb_find_mode(&cfb->fb.var, &cfb->fb, NULL, NULL, 0, &cyber2000fb_default_mode, 8)) { printk("%s: no valid mode found\n", cfb->fb.fix.id); goto failed; } cfb->fb.var.yres_virtual = cfb->fb.fix.smem_len * 8 / (cfb->fb.var.bits_per_pixel * cfb->fb.var.xres_virtual); if (cfb->fb.var.yres_virtual < cfb->fb.var.yres) cfb->fb.var.yres_virtual = cfb->fb.var.yres; cyber2000fb_set_var(&cfb->fb.var, -1, &cfb->fb); /* * Calculate the hsync and vsync frequencies. Note that * we split the 1e12 constant up so that we can preserve * the precision and fit the results into 32-bit registers. * (1953125000 * 512 = 1e12) */ h_sync = 1953125000 / cfb->fb.var.pixclock; h_sync = h_sync * 512 / (cfb->fb.var.xres + cfb->fb.var.left_margin + cfb->fb.var.right_margin + cfb->fb.var.hsync_len); v_sync = h_sync / (cfb->fb.var.yres + cfb->fb.var.upper_margin + cfb->fb.var.lower_margin + cfb->fb.var.vsync_len); printk(KERN_INFO "%s: %dKiB VRAM, using %dx%d, %d.%03dkHz, %dHz\n", cfb->fb.fix.id, cfb->fb.fix.smem_len >> 10, cfb->fb.var.xres, cfb->fb.var.yres, h_sync / 1000, h_sync % 1000, v_sync); err = register_framebuffer(&cfb->fb);failed: return err;}static void cyberpro_common_resume(struct cfb_info *cfb){ cyberpro_init_hw(cfb); /* * Reprogram the MEM_CTL1 and MEM_CTL2 registers */ cyber2000_grphw(EXT_MEM_CTL1, cfb->mem_ctl1, cfb); cyber2000_grphw(EXT_MEM_CTL2, cfb->mem_ctl2, cfb); /* * Restore the old video mode and the palette. * We also need to tell fbcon to redraw the console. */ cfb->fb.var.activate = FB_ACTIVATE_NOW; cyber2000fb_set_var(&cfb->fb.var, -1, &cfb->fb);}/* * PCI specific support. *//* * We need to wake up the CyberPro, and make sure its in linear memory * mode. Unfortunately, this is specific to the platform and card that * we are running on. * * On x86 and ARM, should we be initialising the CyberPro first via the * IO registers, and then the MMIO registers to catch all cases? Can we * end up in the situation where the chip is in MMIO mode, but not awake * on an x86 system? */static int cyberpro_pci_enable_mmio(struct cfb_info *cfb){#if defined(__sparc_v9__)#error "You loose, consult DaveM."#elif defined(__sparc__) /* * SPARC does not have an "outb" instruction, so we generate * I/O cycles storing into a reserved memory space at * physical address 0x3000000 */ unsigned char *iop; iop = ioremap(0x3000000, 0x5000); if (iop == NULL) { prom_printf("iga5000: cannot map I/O\n"); return -ENOMEM; } writeb(0x18, iop + 0x46e8); writeb(0x01, iop + 0x102); writeb(0x08, iop + 0x46e8); writeb(EXT_BIU_MISC, iop + 0x3ce); writeb(EXT_BIU_MISC_LIN_ENABLE, iop + 0x3cf); iounmap((void *)iop);#elif defined(CONFIG_ARCH_SHARK) /* * Shark probably needs to do it this way rather than use the * IO method below. Since the CyberPro on the Shark isn't a * PCI device, we probably want to move this to a bus-specific * probe function. Do we even need to do this? */ cyber2000fb_writeb(0x18, 0x46e8, cfb); cyber2000fb_writeb(0x01, 0x102, cfb); cyber2000fb_writeb(0x08, 0x46e8, cfb); cyber2000fb_writeb(EXT_BIU_MISC, 0x3ce, cfb); cyber2000fb_writeb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf, cfb);#else /* * Most other machine types are "normal", so * we use the standard IO-based wakeup. */ outb(0x18, 0x46e8); outb(0x01, 0x102); outb(0x08, 0x46e8); outb(EXT_BIU_MISC, 0x3ce); outb(EXT_BIU_MISC_LIN_ENABLE, 0x3cf);#endif return 0;}static int __devinitcyberpro_pci_probe(struct pci_dev *dev, const struct pci_device_id *id){ struct cfb_info *cfb; char name[16]; int err; sprintf(name, "CyberPro%4X", id->device); err = pci_enable_device(dev); if (err) return err; err = pci_request_regions(dev, name); if (err) return err; err = -ENOMEM; cfb = cyberpro_alloc_fb_info(id->driver_data, name); if (!cfb) goto failed_release; cfb->dev = dev; cfb->region = ioremap(pci_resource_start(dev, 0), pci_resource_len(dev, 0)); if (!cfb->region) goto failed_ioremap; cfb->regs = cfb->region + MMIO_OFFSET; cfb->fb.fix.mmio_start = pci_resource_start(dev, 0) + MMIO_OFFSET; cfb->fb.fix.smem_start = pci_resource_start(dev, 0); /* * Bring up the hardware. This is expected to enable access * to the linear memory region, and allow access to the memory * mapped registers. Also, mem_ctl1 and mem_ctl2 must be * initialised. */ err = cyberpro_pci_enable_mmio(cfb); if (err) goto failed; /* * Use MCLK from BIOS. FIXME: what about hotplug? */#ifndef __arm__ cfb->mclk_mult = cyber2000_grphr(MCLK_MULT, cfb); cfb->mclk_div = cyber2000_grphr(MCLK_DIV, cfb);#else /* * MCLK on the NetWinder and the Shark is fixed at 75MHz */ cfb->mclk_mult = 0xdb; cfb->mclk_div = 0x54;#endif cyberpro_init_hw(cfb); err = cyberpro_common_probe(cfb); if (err) goto failed; /* * Our driver data */ pci_set_drvdata(dev, cfb); if (int_cfb_info == NULL) int_cfb_info = cfb; return 0;failed: iounmap(cfb->region);failed_ioremap: cyberpro_free_fb_info(cfb);failed_release: pci_release_regions(dev); return err;}static void __devexit cyberpro_pci_remove(struct pci_dev *dev){ struct cfb_info *cfb = pci_get_drvdata(dev); if (cfb) { /* * If unregister_framebuffer fails, then * we will be leaving hooks that could cause * oopsen laying around. */ if (unregister_framebuffer(&cfb->fb)) printk(KERN_WARNING "%s: danger Will Robinson, " "danger danger! Oopsen imminent!\n", cfb->fb.fix.id); iounmap(cfb->region); cyberpro_free_fb_info(cfb); /* * Ensure that the driver data is no longer * valid. */ pci_set_drvdata(dev, NULL); if (cfb == int_cfb_info) int_cfb_info = NULL; pci_release_regions(dev); }}static int cyberpro_pci_suspend(struct pci_dev *dev, u32 state){ return 0;}/* * Re-initialise the CyberPro hardware */static int cyberpro_pci_resume(struct pci_dev *dev){ struct cfb_info *cfb = pci_get_drvdata(dev); if (cfb) { cyberpro_pci_enable_mmio(cfb); cyberpro_common_resume(cfb); } return 0;}static struct pci_device_id cyberpro_pci_table[] __devinitdata = { { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_IGA_1682 }, { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2000 }, { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_2010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_2010 }, { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_5000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ID_CYBERPRO_5000 }, { 0, }};MODULE_DEVICE_TABLE(pci,cyberpro_pci_table);#ifndef __devexit_p#define __devexit_p(x) (x)#endifstatic struct pci_driver cyberpro_driver = { name: "CyberPro", probe: cyberpro_pci_probe, remove: __devexit_p(cyberpro_pci_remove), suspend: cyberpro_pci_suspend, resume: cyberpro_pci_resume, id_table: cyberpro_pci_table};/* * I don't think we can use the "module_init" stuff here because * the fbcon stuff may not be initialised yet. Hence the #ifdef * around module_init. */int __init cyber2000fb_init(void){ return pci_module_init(&cyberpro_driver);}static void __exit cyberpro_exit(void){ pci_unregister_driver(&cyberpro_driver);}#ifdef MODULEmodule_init(cyber2000fb_init);#endifmodule_exit(cyberpro_exit);MODULE_AUTHOR("Russell King");MODULE_DESCRIPTION("CyberPro 2000, 2010 and 5000 framebuffer driver");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -