📄 pmc551.c
字号:
"pmc551: DRAM_BLK0 Row MUX: %d, Col MUX: %d\n", (((0x1<<1)&dcmd) == 0)?"RW":"RO", (((0x1<<0)&dcmd) == 0)?"Off":"On", PMC551_DRAM_BLK_GET_SIZE(dcmd), ((dcmd>>20)&0x7FF), ((dcmd>>13)&0x7), ((dcmd>>9)&0xF) ); pci_read_config_dword( dev, PMC551_DRAM_BLK1, &dcmd ); printk(KERN_DEBUG "pmc551: DRAM_BLK1 Flags: %s,%s\n" "pmc551: DRAM_BLK1 Size: %d at %d\n" "pmc551: DRAM_BLK1 Row MUX: %d, Col MUX: %d\n", (((0x1<<1)&dcmd) == 0)?"RW":"RO", (((0x1<<0)&dcmd) == 0)?"Off":"On", PMC551_DRAM_BLK_GET_SIZE(dcmd), ((dcmd>>20)&0x7FF), ((dcmd>>13)&0x7), ((dcmd>>9)&0xF) ); pci_read_config_dword( dev, PMC551_DRAM_BLK2, &dcmd ); printk(KERN_DEBUG "pmc551: DRAM_BLK2 Flags: %s,%s\n" "pmc551: DRAM_BLK2 Size: %d at %d\n" "pmc551: DRAM_BLK2 Row MUX: %d, Col MUX: %d\n", (((0x1<<1)&dcmd) == 0)?"RW":"RO", (((0x1<<0)&dcmd) == 0)?"Off":"On", PMC551_DRAM_BLK_GET_SIZE(dcmd), ((dcmd>>20)&0x7FF), ((dcmd>>13)&0x7), ((dcmd>>9)&0xF) ); pci_read_config_dword( dev, PMC551_DRAM_BLK3, &dcmd ); printk(KERN_DEBUG "pmc551: DRAM_BLK3 Flags: %s,%s\n" "pmc551: DRAM_BLK3 Size: %d at %d\n" "pmc551: DRAM_BLK3 Row MUX: %d, Col MUX: %d\n", (((0x1<<1)&dcmd) == 0)?"RW":"RO", (((0x1<<0)&dcmd) == 0)?"Off":"On", PMC551_DRAM_BLK_GET_SIZE(dcmd), ((dcmd>>20)&0x7FF), ((dcmd>>13)&0x7), ((dcmd>>9)&0xF) ); pci_read_config_word( dev, PCI_COMMAND, &cmd ); printk( KERN_DEBUG "pmc551: Memory Access %s\n", (((0x1<<1)&cmd) == 0)?"off":"on" ); printk( KERN_DEBUG "pmc551: I/O Access %s\n", (((0x1<<0)&cmd) == 0)?"off":"on" ); pci_read_config_word( dev, PCI_STATUS, &cmd ); printk( KERN_DEBUG "pmc551: Devsel %s\n", ((PCI_STATUS_DEVSEL_MASK&cmd)==0x000)?"Fast": ((PCI_STATUS_DEVSEL_MASK&cmd)==0x200)?"Medium": ((PCI_STATUS_DEVSEL_MASK&cmd)==0x400)?"Slow":"Invalid" ); printk( KERN_DEBUG "pmc551: %sFast Back-to-Back\n", ((PCI_COMMAND_FAST_BACK&cmd) == 0)?"Not ":"" ); pci_read_config_byte(dev, PMC551_SYS_CTRL_REG, &bcmd ); printk( KERN_DEBUG "pmc551: EEPROM is under %s control\n" "pmc551: System Control Register is %slocked to PCI access\n" "pmc551: System Control Register is %slocked to EEPROM access\n", (bcmd&0x1)?"software":"hardware", (bcmd&0x20)?"":"un", (bcmd&0x40)?"":"un");#endif return size;}/* * Kernel version specific module stuffages */#if LINUX_VERSION_CODE < 0x20211#ifdef MODULE#define init_pmc551 init_module#define cleanup_pmc551 cleanup_module#endif#define __exit#endif#if defined(MODULE)MODULE_AUTHOR("Mark Ferrell <mferrell@mvista.com>");MODULE_DESCRIPTION(PMC551_VERSION);MODULE_PARM(msize, "i");MODULE_PARM_DESC(msize, "memory size, 6=32M, 7=64M, 8=128M, ect.. [32M-1024M]");MODULE_PARM(asize, "i");MODULE_PARM_DESC(asize, "aperture size, must be <= memsize [1M-1024M]");#endif/* * Stuff these outside the ifdef so as to not bust compiled in driver support */static int msize=0;#if defined(CONFIG_MTD_PMC551_APERTURE_SIZE)static int asize=CONFIG_MTD_PMC551_APERTURE_SIZE#elsestatic int asize=0;#endif/* * PMC551 Card Initialization */int __init init_pmc551(void){ struct pci_dev *PCI_Device = NULL; struct mypriv *priv; int count, found=0; struct mtd_info *mtd; u32 length = 0; if(msize) { if (msize < 6 || msize > 11 ) { printk(KERN_NOTICE "pmc551: Invalid memory size\n"); return -ENODEV; } msize = (512*1024)<<msize; } if(asize) { if (asize < 1 || asize > 11 ) { printk(KERN_NOTICE "pmc551: Invalid aperture size\n"); return -ENODEV; } asize = (512*1024)<<asize; } printk(KERN_INFO PMC551_VERSION); if(!pci_present()) { printk(KERN_NOTICE "pmc551: PCI not enabled.\n"); return -ENODEV; } /* * PCU-bus chipset probe. */ for( count = 0; count < MAX_MTD_DEVICES; count++ ) { if ( (PCI_Device = pci_find_device( PCI_VENDOR_ID_V3_SEMI, PCI_DEVICE_ID_V3_SEMI_V370PDC, PCI_Device ) ) == NULL) { break; } printk(KERN_NOTICE "pmc551: Found PCI V370PDC IRQ:%d\n", PCI_Device->irq); /* * The PMC551 device acts VERY wierd if you don't init it * first. i.e. it will not correctly report devsel. If for * some reason the sdram is in a wrote-protected state the * device will DEVSEL when it is written to causing problems * with the oldproc.c driver in * some kernels (2.2.*) */ if((length = fixup_pmc551(PCI_Device)) <= 0) { printk(KERN_NOTICE "pmc551: Cannot init SDRAM\n"); break; } if(msize) { length = msize; printk(KERN_NOTICE "pmc551: Using specified memory size 0x%x\n", length); } mtd = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); if (!mtd) { printk(KERN_NOTICE "pmc551: Cannot allocate new MTD device.\n"); break; } memset(mtd, 0, sizeof(struct mtd_info)); priv = kmalloc (sizeof(struct mypriv), GFP_KERNEL); if (!priv) { printk(KERN_NOTICE "pmc551: Cannot allocate new MTD device.\n"); kfree(mtd); break; } memset(priv, 0, sizeof(*priv)); mtd->priv = priv; priv->dev = PCI_Device; if(asize) { if(asize > length) { asize=length; printk(KERN_NOTICE "pmc551: reducing aperture size to fit memory [0x%x]\n",asize); } else { printk(KERN_NOTICE "pmc551: Using specified aperture size 0x%x\n", asize); } priv->aperture_size = asize; } else { priv->aperture_size = length; } priv->start = ioremap((PCI_BASE_ADDRESS(PCI_Device) & PCI_BASE_ADDRESS_MEM_MASK), priv->aperture_size); /* * Due to the dynamic nature of the code, we need to figure * this out in order to stuff the register to set the proper * aperture size. If you know of an easier way to do this then * PLEASE help yourself. * * Not with bloody floating point, you don't. Consider yourself * duly LARTed. dwmw2. */ { u32 size; u16 bits; size = priv->aperture_size>>20; for(bits=0;!(size&0x01)&&size>0;bits++,size=size>>1); //size=((u32)((log10(priv->aperture_size)/.30103)-19)<<4); priv->mem_map0_base_val = (PMC551_PCI_MEM_MAP_REG_EN | PMC551_PCI_MEM_MAP_ENABLE | size);#ifdef CONFIG_MTD_PMC551_DEBUG printk(KERN_NOTICE "pmc551: aperture set to %d[%d]\n", size, size>>4);#endif } priv->curr_mem_map0_val = priv->mem_map0_base_val; pci_write_config_dword ( priv->dev, PMC551_PCI_MEM_MAP0, priv->curr_mem_map0_val); mtd->size = length; mtd->flags = (MTD_CLEAR_BITS | MTD_SET_BITS | MTD_WRITEB_WRITEABLE | MTD_VOLATILE); mtd->erase = pmc551_erase; mtd->point = NULL; mtd->unpoint = pmc551_unpoint; mtd->read = pmc551_read; mtd->write = pmc551_write; mtd->module = THIS_MODULE; mtd->type = MTD_RAM; mtd->name = "PMC551 RAM board"; mtd->erasesize = 0x10000; if (add_mtd_device(mtd)) { printk(KERN_NOTICE "pmc551: Failed to register new device\n"); kfree(mtd->priv); kfree(mtd); break; } printk(KERN_NOTICE "Registered pmc551 memory device.\n"); printk(KERN_NOTICE "Mapped %dM of memory from 0x%p to 0x%p\n", priv->aperture_size/1024/1024, priv->start, priv->start + priv->aperture_size); printk(KERN_NOTICE "Total memory is %d%c\n", (length<1024)?length: (length<1048576)?length/1024:length/1024/1024, (length<1024)?'B':(length<1048576)?'K':'M'); priv->nextpmc551 = pmc551list; pmc551list = mtd; found++; } if( !pmc551list ) { printk(KERN_NOTICE "pmc551: not detected,\n"); return -ENODEV; } else { printk(KERN_NOTICE "pmc551: %d pmc551 devices loaded\n", found); return 0; }}/* * PMC551 Card Cleanup */static void __exit cleanup_pmc551(void){ int found=0; struct mtd_info *mtd; struct mypriv *priv; while((mtd=pmc551list)) { priv = (struct mypriv *)mtd->priv; pmc551list = priv->nextpmc551; if(priv->start) iounmap(((struct mypriv *)mtd->priv)->start); kfree (mtd->priv); del_mtd_device(mtd); kfree(mtd); found++; } printk(KERN_NOTICE "pmc551: %d pmc551 devices unloaded\n", found);}#if LINUX_VERSION_CODE >= 0x20211module_init(init_pmc551);module_exit(cleanup_pmc551);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -