📄 igafb.c
字号:
pci_outb(par, red, DAC_DATA); pci_outb(par, green, DAC_DATA); pci_outb(par, blue, DAC_DATA); if (regno < 16) { switch (info->var.bits_per_pixel) { case 16: ((u16*)(info->pseudo_palette))[regno] = (regno << 10) | (regno << 5) | regno; break; case 24: ((u32*)(info->pseudo_palette))[regno] = (regno << 16) | (regno << 8) | regno; break; case 32: { int i; i = (regno << 8) | regno; ((u32*)(info->pseudo_palette))[regno] = (i << 16) | i; } break; } } return 0;}/* * Framebuffer option structure */static struct fb_ops igafb_ops = { .owner = THIS_MODULE, .fb_setcolreg = igafb_setcolreg, .fb_fillrect = cfb_fillrect, .fb_copyarea = cfb_copyarea, .fb_imageblit = cfb_imageblit,#ifdef CONFIG_SPARC .fb_mmap = igafb_mmap,#endif};static int __init iga_init(struct fb_info *info, struct iga_par *par){ char vramsz = iga_inb(par, IGA_EXT_CNTRL, IGA_IDX_EXT_BUS_CNTL) & MEM_SIZE_ALIAS; int video_cmap_len; switch (vramsz) { case MEM_SIZE_1M: info->fix.smem_len = 0x100000; break; case MEM_SIZE_2M: info->fix.smem_len = 0x200000; break; case MEM_SIZE_4M: case MEM_SIZE_RESERVED: info->fix.smem_len = 0x400000; break; } if (info->var.bits_per_pixel > 8) video_cmap_len = 16; else video_cmap_len = 256; info->fbops = &igafb_ops; info->flags = FBINFO_DEFAULT; fb_alloc_cmap(&info->cmap, video_cmap_len, 0); if (register_framebuffer(info) < 0) return 0; printk("fb%d: %s frame buffer device at 0x%08lx [%dMB VRAM]\n", info->node, info->fix.id, par->frame_buffer_phys, info->fix.smem_len >> 20); iga_blank_border(par); return 1;}int __init igafb_init(void){ struct fb_info *info; struct pci_dev *pdev; struct iga_par *par; unsigned long addr; int size, iga2000 = 0; if (fb_get_options("igafb", NULL)) return -ENODEV; pdev = pci_get_device(PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682, 0); if (pdev == NULL) { /* * XXX We tried to use cyber2000fb.c for IGS 2000. * But it does not initialize the chip in JavaStation-E, alas. */ pdev = pci_get_device(PCI_VENDOR_ID_INTERG, 0x2000, 0); if(pdev == NULL) { return -ENXIO; } iga2000 = 1; } /* We leak a reference here but as it cannot be unloaded this is fine. If you write unload code remember to free it in unload */ size = sizeof(struct fb_info) + sizeof(struct iga_par) + sizeof(u32)*16; info = kzalloc(size, GFP_ATOMIC); if (!info) { printk("igafb_init: can't alloc fb_info\n"); pci_dev_put(pdev); return -ENOMEM; } par = (struct iga_par *) (info + 1); if ((addr = pdev->resource[0].start) == 0) { printk("igafb_init: no memory start\n"); kfree(info); pci_dev_put(pdev); return -ENXIO; } if ((info->screen_base = ioremap(addr, 1024*1024*2)) == 0) { printk("igafb_init: can't remap %lx[2M]\n", addr); kfree(info); pci_dev_put(pdev); return -ENXIO; } par->frame_buffer_phys = addr & PCI_BASE_ADDRESS_MEM_MASK;#ifdef CONFIG_SPARC /* * The following is sparc specific and this is why: * * IGS2000 has its I/O memory mapped and we want * to generate memory cycles on PCI, e.g. do ioremap(), * then readb/writeb() as in Documentation/IO-mapping.txt. * * IGS1682 is more traditional, it responds to PCI I/O * cycles, so we want to access it with inb()/outb(). * * On sparc, PCIC converts CPU memory access within * phys window 0x3000xxxx into PCI I/O cycles. Therefore * we may use readb/writeb to access them with IGS1682. * * We do not take io_base_phys from resource[n].start * on IGS1682 because that chip is BROKEN. It does not * have a base register for I/O. We just "know" what its * I/O addresses are. */ if (iga2000) { igafb_fix.mmio_start = par->frame_buffer_phys | 0x00800000; } else { igafb_fix.mmio_start = 0x30000000; /* XXX */ } if ((par->io_base = (int) ioremap(igafb_fix.mmio_start, igafb_fix.smem_len)) == 0) { printk("igafb_init: can't remap %lx[4K]\n", igafb_fix.mmio_start); iounmap((void *)info->screen_base); kfree(info); pci_dev_put(pdev); return -ENXIO; } /* * Figure mmap addresses from PCI config space. * We need two regions: for video memory and for I/O ports. * Later one can add region for video coprocessor registers. * However, mmap routine loops until size != 0, so we put * one additional region with size == 0. */ par->mmap_map = kzalloc(4 * sizeof(*par->mmap_map), GFP_ATOMIC); if (!par->mmap_map) { printk("igafb_init: can't alloc mmap_map\n"); iounmap((void *)par->io_base); iounmap(info->screen_base); kfree(info); pci_dev_put(pdev); return -ENOMEM; } /* * Set default vmode and cmode from PROM properties. */ { struct device_node *dp = pci_device_to_OF_node(pdev); int node = dp->node; int width = prom_getintdefault(node, "width", 1024); int height = prom_getintdefault(node, "height", 768); int depth = prom_getintdefault(node, "depth", 8); switch (width) { case 1024: if (height == 768) default_var = default_var_1024x768; break; case 1152: if (height == 900) default_var = default_var_1152x900; break; case 1280: if (height == 1024) default_var = default_var_1280x1024; break; default: break; } switch (depth) { case 8: default_var.bits_per_pixel = 8; break; case 16: default_var.bits_per_pixel = 16; break; case 24: default_var.bits_per_pixel = 24; break; case 32: default_var.bits_per_pixel = 32; break; default: break; } }#endif igafb_fix.smem_start = (unsigned long) info->screen_base; igafb_fix.line_length = default_var.xres*(default_var.bits_per_pixel/8); igafb_fix.visual = default_var.bits_per_pixel <= 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_DIRECTCOLOR; info->var = default_var; info->fix = igafb_fix; info->pseudo_palette = (void *)(par + 1); info->device = &pdev->dev; if (!iga_init(info, par)) { iounmap((void *)par->io_base); iounmap(info->screen_base); kfree(par->mmap_map); kfree(info); }#ifdef CONFIG_SPARC /* * Add /dev/fb mmap values. */ /* First region is for video memory */ par->mmap_map[0].voff = 0x0; par->mmap_map[0].poff = par->frame_buffer_phys & PAGE_MASK; par->mmap_map[0].size = info->fix.smem_len & PAGE_MASK; par->mmap_map[0].prot_mask = SRMMU_CACHE; par->mmap_map[0].prot_flag = SRMMU_WRITE; /* Second region is for I/O ports */ par->mmap_map[1].voff = par->frame_buffer_phys & PAGE_MASK; par->mmap_map[1].poff = info->fix.smem_start & PAGE_MASK; par->mmap_map[1].size = PAGE_SIZE * 2; /* X wants 2 pages */ par->mmap_map[1].prot_mask = SRMMU_CACHE; par->mmap_map[1].prot_flag = SRMMU_WRITE;#endif /* CONFIG_SPARC */ return 0;}int __init igafb_setup(char *options){ char *this_opt; if (!options || !*options) return 0; while ((this_opt = strsep(&options, ",")) != NULL) { } return 0;}module_init(igafb_init);MODULE_LICENSE("GPL");static struct pci_device_id igafb_pci_tbl[] __devinitdata = { { PCI_VENDOR_ID_INTERG, PCI_DEVICE_ID_INTERG_1682, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, { }};MODULE_DEVICE_TABLE(pci, igafb_pci_tbl);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -