⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sc1200.c

📁 ep9315平台下硬盘驱动的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
}/* * sc1200_config_dma() handles selection/setting of DMA/UDMA modes * for both the chipset and drive. */static int sc1200_config_dma (ide_drive_t *drive){	return sc1200_config_dma2(drive, sc1200_autoselect_dma_mode(drive));}/*  Replacement for the standard ide_dma_end action in *  dma_proc. * *  returns 1 on error, 0 otherwise */int sc1200_ide_dma_end (ide_drive_t *drive){	ide_hwif_t *hwif = HWIF(drive);	unsigned long dma_base = hwif->dma_base;	byte dma_stat;	dma_stat = inb(dma_base+2);		/* get DMA status */	if (!(dma_stat & 4))		printk(" ide_dma_end dma_stat=%0x err=%x newerr=%x\n",		  dma_stat, ((dma_stat&7)!=4), ((dma_stat&2)==2));	outb(dma_stat|0x1b, dma_base+2);	/* clear the INTR & ERROR bits */	outb(inb(dma_base)&~1, dma_base);	/* !! DO THIS HERE !! stop DMA */	drive->waiting_for_dma = 0;	ide_destroy_dmatable(drive);		/* purge DMA mappings */	return (dma_stat & 7) != 4;		/* verify good DMA status */}/* * sc1200_tuneproc() handles selection/setting of PIO modes * for both the chipset and drive. * * All existing BIOSs for this chipset guarantee that all drives * will have valid default PIO timings set up before we get here. */static void sc1200_tuneproc (ide_drive_t *drive, byte pio)	/* mode=255 means "autotune" */{	ide_hwif_t	*hwif = HWIF(drive);	unsigned int	format;	static byte	modes[5] = {XFER_PIO_0, XFER_PIO_1, XFER_PIO_2, XFER_PIO_3, XFER_PIO_4};	int		mode = -1;	switch (pio) {		case 200: mode = XFER_UDMA_0;	break;		case 201: mode = XFER_UDMA_1;	break;		case 202: mode = XFER_UDMA_2;	break;		case 100: mode = XFER_MW_DMA_0;	break;		case 101: mode = XFER_MW_DMA_1;	break;		case 102: mode = XFER_MW_DMA_2;	break;	}	if (mode != -1) {		printk("SC1200: %s: changing (U)DMA mode\n", drive->name);		(void)sc1200_config_dma2(drive, mode);		return;	}	pio = ide_get_best_pio_mode(drive, pio, 4, NULL);	printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio);	if (!sc1200_set_xfer_mode(drive, modes[pio])) {		unsigned int basereg = hwif->channel ? 0x50 : 0x40;		pci_read_config_dword (hwif->pci_dev, basereg+4, &format);		format = (format >> 31) & 1;		if (format)			format += sc1200_get_pci_clock();		pci_write_config_dword(hwif->pci_dev, basereg + (drive->select.b.unit << 3), sc1200_pio_timings[format][pio]); 	}}static ide_hwif_t *lookup_pci_dev (ide_hwif_t *prev, struct pci_dev *dev){	int	h;	for (h = 0; h < MAX_HWIFS; h++) {		ide_hwif_t *hwif = &ide_hwifs[h];		if (prev) {			if (hwif == prev)				prev = NULL;	// found previous, now look for next match		} else {			if (hwif && hwif->pci_dev == dev)				return hwif;	// found next match		}	}	return NULL;	// not found}typedef struct sc1200_saved_state_s {	__u32		regs[4];} sc1200_saved_state_t;static int sc1200_save_state (struct pci_dev *dev, u32 state){	ide_hwif_t		*hwif = NULL;printk("SC1200: save_state(%u)\n", state);	if (state != 0)		return 0;	// we only save state when going from full power to less	//	// Loop over all interfaces that are part of this PCI device:	//	while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) {		sc1200_saved_state_t	*ss;		unsigned int		basereg, r;		//		// allocate a permanent save area, if not already allocated		//		ss = (sc1200_saved_state_t *)hwif->config_data;		if (ss == NULL) {			ss = kmalloc(sizeof(sc1200_saved_state_t), GFP_KERNEL);			if (ss == NULL)				return -ENOMEM;			(sc1200_saved_state_t *)hwif->config_data = ss;		}		ss = (sc1200_saved_state_t *)hwif->config_data;		//		// Save timing registers:  this may be unnecessary if BIOS also does it		//		basereg = hwif->channel ? 0x50 : 0x40;		for (r = 0; r < 4; ++r) {			pci_read_config_dword (hwif->pci_dev, basereg + (r<<2), &ss->regs[r]);		}	}	return 0;}static int sc1200_suspend (struct pci_dev *dev, u32 state){	printk("SC1200: suspend(%u)\n", state);	/* You don't need to iterate over disks -- sysfs should have done that for you already */ 	pci_disable_device(dev);	pci_set_power_state(dev,state);	dev->current_state = state;	return 0;}static int sc1200_resume (struct pci_dev *dev){	ide_hwif_t	*hwif = NULL;printk("SC1200: resume\n");	pci_set_power_state(dev,0);	// bring chip back from sleep state	dev->current_state = 0;	pci_enable_device(dev);	//	// loop over all interfaces that are part of this pci device:	//	while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) {		unsigned int		basereg, r, d, format;		sc1200_saved_state_t	*ss = (sc1200_saved_state_t *)hwif->config_data;printk("%s: SC1200: resume\n", hwif->name);		//		// Restore timing registers:  this may be unnecessary if BIOS also does it		//		basereg = hwif->channel ? 0x50 : 0x40;		if (ss != NULL) {			for (r = 0; r < 4; ++r) {				pci_write_config_dword(hwif->pci_dev, basereg + (r<<2), ss->regs[r]);			}		}		//		// Re-program drive PIO modes		//		pci_read_config_dword(hwif->pci_dev, basereg+4, &format);		format = (format >> 31) & 1;		if (format)			format += sc1200_get_pci_clock();		for (d = 0; d < 2; ++d) {			ide_drive_t *drive = &(hwif->drives[d]);			if (drive->present) {				unsigned int pio, timings;				pci_read_config_dword(hwif->pci_dev, basereg+(drive->select.b.unit << 3), &timings);				for (pio = 0; pio <= 4; ++pio) {					if (sc1200_pio_timings[format][pio] == timings)						break;				}				if (pio > 4)					pio = 255; /* autotune */				(void)sc1200_tuneproc(drive, pio);			}		}		//		// Re-program drive DMA modes		//		for (d = 0; d < MAX_DRIVES; ++d) {			ide_drive_t *drive = &(hwif->drives[d]);			if (drive->present && !hwif->ide_dma_bad_drive(drive)) {				int was_using_dma = drive->using_dma;				hwif->ide_dma_off_quietly(drive);				sc1200_config_dma(drive);				if (!was_using_dma && drive->using_dma) {					hwif->ide_dma_off_quietly(drive);				}			}		}	}	return 0;}/* * Initialize the sc1200 bridge for reliable IDE DMA operation. */static unsigned int __init init_chipset_sc1200 (struct pci_dev *dev, const char *name){#if defined(DISPLAY_SC1200_TIMINGS) && defined(CONFIG_PROC_FS)	if (!bmide_dev) {		sc1200_proc = 1;		bmide_dev = dev;		ide_pci_register_host_proc(&sc1200_procs[0]);	}#endif /* DISPLAY_SC1200_TIMINGS && CONFIG_PROC_FS */	return 0;}/* * This gets invoked by the IDE driver once for each channel, * and performs channel-specific pre-initialization before drive probing. */static void __init init_hwif_sc1200 (ide_hwif_t *hwif){	if (hwif->mate)		hwif->serialized = hwif->mate->serialized = 1;	hwif->autodma = 0;	if (hwif->dma_base) {		hwif->ide_dma_check = &sc1200_config_dma;		hwif->ide_dma_end   = &sc1200_ide_dma_end;        	if (!noautodma)                	hwif->autodma = 1;		hwif->tuneproc = &sc1200_tuneproc;	}        hwif->atapi_dma = 1;        hwif->ultra_mask = 0x07;        hwif->mwdma_mask = 0x07;        hwif->drives[0].autodma = hwif->autodma;        hwif->drives[1].autodma = hwif->autodma;}static void __init init_dma_sc1200 (ide_hwif_t *hwif, unsigned long dmabase){	ide_setup_dma(hwif, dmabase, 8);}extern void ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);static int __devinit sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id){	ide_pci_device_t *d = &sc1200_chipsets[id->driver_data];	if (dev->device != d->device)		BUG();	ide_setup_pci_device(dev, d);	MOD_INC_USE_COUNT;	return 0;}static struct pci_device_id sc1200_pci_tbl[] __devinitdata = {	{ PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_SCx200_IDE, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},	{ 0, },};static struct pci_driver driver = {	.name		= "SC1200 IDE",	.id_table	= sc1200_pci_tbl,	.probe		= sc1200_init_one,	.save_state	= sc1200_save_state,	.suspend	= sc1200_suspend,	.resume		= sc1200_resume,};static int sc1200_ide_init(void){	return ide_pci_register_driver(&driver);}static void sc1200_ide_exit(void){	ide_pci_unregister_driver(&driver);}module_init(sc1200_ide_init);module_exit(sc1200_ide_exit);MODULE_AUTHOR("Mark Lord");MODULE_DESCRIPTION("PCI driver module for NS SC1200 IDE");MODULE_LICENSE("GPL");EXPORT_NO_SYMBOLS;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -