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

📄 pdc202xx.c

📁 at91rm9200处理器ide接口驱动程序源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
			pci_read_config_dword(dev, drive_pci, &drive_conf);			if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4))				goto chipset_is_set;			pci_read_config_byte(dev, 0x60, &test1);			pci_read_config_byte(dev, (drive_pci), &test2);			if ((test1 & SYNC_ERRDY_EN) && !(test2 & SYNC_ERRDY_EN))				pci_write_config_byte(dev, (drive_pci), test2|SYNC_ERRDY_EN);			break;		case 2:	drive_pci = 0x68;			pci_read_config_dword(dev, drive_pci, &drive_conf);			if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4))				goto chipset_is_set;			pci_read_config_byte(dev, (drive_pci), &test1);			if (!(test1 & SYNC_ERRDY_EN))				pci_write_config_byte(dev, (drive_pci), test1|SYNC_ERRDY_EN);			break;		case 3:	drive_pci = 0x6c;			pci_read_config_dword(dev, drive_pci, &drive_conf);			if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4))				goto chipset_is_set;			pci_read_config_byte(dev, 0x68, &test1);			pci_read_config_byte(dev, (drive_pci), &test2);			if ((test1 & SYNC_ERRDY_EN) && !(test2 & SYNC_ERRDY_EN))				pci_write_config_byte(dev, (drive_pci), test2|SYNC_ERRDY_EN);			break;		default:			return ide_dma_off;	}chipset_is_set:	if (drive->media != ide_disk)		return ide_dma_off_quietly;		if (new_chip) {		if (id->capability & 4) {	/* IORDY_EN & PREFETCH_EN */			OUT_BYTE((iordy + adj), indexreg);			OUT_BYTE((IN_BYTE(datareg)|0x03), datareg);		}	}	else {		pci_read_config_byte(dev, (drive_pci), &AP);		if (id->capability & 4)	/* IORDY_EN */			pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN);		pci_read_config_byte(dev, (drive_pci), &AP);		if (drive->media == ide_disk)	/* PREFETCH_EN */			pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);	}	if ((id->dma_ultra & 0x0040)&&(udma_133))	speed = XFER_UDMA_6;	else if ((id->dma_ultra & 0x0020)&&(udma_100))	speed = XFER_UDMA_5;	else if ((id->dma_ultra & 0x0010)&&(udma_66))	speed = XFER_UDMA_4;	else if ((id->dma_ultra & 0x0008)&&(udma_66))	speed = XFER_UDMA_3;	else if ((id->dma_ultra & 0x0004)&&(udma_33))	speed = XFER_UDMA_2;	else if ((id->dma_ultra & 0x0002)&&(udma_33))	speed = XFER_UDMA_1;	else if ((id->dma_ultra & 0x0001)&&(udma_33))	speed = XFER_UDMA_0;	else if (id->dma_mword & 0x0004)		speed = XFER_MW_DMA_2;	else if (id->dma_mword & 0x0002)		speed = XFER_MW_DMA_1;	else if (id->dma_mword & 0x0001)		speed = XFER_MW_DMA_0;	else if ((id->dma_1word & 0x0004)&&(!new_chip))	speed = XFER_SW_DMA_2;	else if ((id->dma_1word & 0x0002)&&(!new_chip))	speed = XFER_SW_DMA_1;	else if ((id->dma_1word & 0x0001)&&(!new_chip))	speed = XFER_SW_DMA_0;	else {		/* restore original pci-config space */		if (!new_chip)			pci_write_config_dword(dev, drive_pci, drive_conf);		return ide_dma_off_quietly;	}	outb(inb(dma_base+2) & ~(1<<(5+unit)), dma_base+2);	(void) hwif->speedproc(drive, speed);	return ((int)	((id->dma_ultra >> 14) & 3) ? ide_dma_on :			((id->dma_ultra >> 11) & 7) ? ide_dma_on :			((id->dma_ultra >> 8) & 7) ? ide_dma_on :			((id->dma_mword >> 8) & 7) ? ide_dma_on : 			((id->dma_1word >> 8) & 7) ? ide_dma_on :						     ide_dma_off_quietly);}static int config_drive_xfer_rate (ide_drive_t *drive){	struct hd_driveid *id = drive->id;	ide_hwif_t *hwif = HWIF(drive);	ide_dma_action_t dma_func = ide_dma_off_quietly;	if (id && (id->capability & 1) && hwif->autodma) {		/* Consult the list of known "bad" drives */		if (ide_dmaproc(ide_dma_bad_drive, drive)) {			dma_func = ide_dma_off;			goto fast_ata_pio;		}		dma_func = ide_dma_off_quietly;		if (id->field_valid & 4) {			if (id->dma_ultra & 0x007F) {				/* Force if Capable UltraDMA */				dma_func = config_chipset_for_dma(drive, 1);				if ((id->field_valid & 2) &&				    (dma_func != ide_dma_on))					goto try_dma_modes;			}		} else if (id->field_valid & 2) {try_dma_modes:			if ((id->dma_mword & 0x0007) ||			    (id->dma_1word & 0x0007)) {				/* Force if Capable regular DMA modes */				dma_func = config_chipset_for_dma(drive, 0);				if (dma_func != ide_dma_on)					goto no_dma_set;			}		} else if (ide_dmaproc(ide_dma_good_drive, drive)) {			if (id->eide_dma_time > 150) {				goto no_dma_set;			}			/* Consult the list of known "good" drives */			dma_func = config_chipset_for_dma(drive, 0);			if (dma_func != ide_dma_on)				goto no_dma_set;		} else {			goto fast_ata_pio;		}	} else if ((id->capability & 8) || (id->field_valid & 2)) {fast_ata_pio:		dma_func = ide_dma_off_quietly;no_dma_set:		(void) config_chipset_for_pio(drive, 5);	}	return HWIF(drive)->dmaproc(dma_func, drive);}int pdc202xx_quirkproc (ide_drive_t *drive){	return ((int) check_in_drive_lists(drive, pdc_quirk_drives));}/* * pdc202xx_dmaproc() initiates/aborts (U)DMA read/write operations on a drive. */int pdc202xx_dmaproc (ide_dma_action_t func, ide_drive_t *drive){	byte dma_stat		= 0;	byte sc1d		= 0;	byte newchip		= 0;	byte clock		= 0;	byte hardware48fix	= 0;	ide_hwif_t *hwif	= HWIF(drive);	struct pci_dev *dev	= hwif->pci_dev;	unsigned long high_16	= pci_resource_start(dev, 4);	unsigned long dma_base	= hwif->dma_base;	unsigned long atapi_port= hwif->channel ? high_16+0x24 : high_16+0x20;	switch (dev->device) {		case PCI_DEVICE_ID_PROMISE_20276:		case PCI_DEVICE_ID_PROMISE_20275:		case PCI_DEVICE_ID_PROMISE_20269:		case PCI_DEVICE_ID_PROMISE_20268:		case PCI_DEVICE_ID_PROMISE_20270:			newchip = 1;			break;		case PCI_DEVICE_ID_PROMISE_20267:		case PCI_DEVICE_ID_PROMISE_20265:			hardware48fix = 1;			clock = IN_BYTE(high_16 + 0x11);		default:			break;	}	switch (func) {		case ide_dma_check:			return config_drive_xfer_rate(drive);		case ide_dma_begin:			/* Note that this is done *after* the cmd has			 * been issued to the drive, as per the BM-IDE spec.			 * The Promise Ultra33 doesn't work correctly when			 * we do this part before issuing the drive cmd.			 */			/* Enable ATAPI UDMA port for 48bit data on PDC20267 */			if ((drive->addressing) && (hardware48fix)) {				struct request *rq = HWGROUP(drive)->rq;				unsigned long word_count = 0;				unsigned long hankval = 0;				byte	clockreg = high_16 + 0x11;								OUT_BYTE(clock|(hwif->channel ? 0x08:0x02), clockreg);				word_count = (rq->nr_sectors << 8);				hankval = (rq->cmd == READ) ? 0x05<<24 : 0x06<<24;				hankval = hankval | word_count ;				outl(hankval, atapi_port);			}  			break;		case ide_dma_end:			/* Disable ATAPI UDMA port for 48bit data on PDC20267 */			if ((drive->addressing) && (hardware48fix)) {				unsigned long hankval = 0;				byte	clockreg = high_16 + 0x11;							    	outl(hankval, atapi_port);	/* zero out extra */				clock = IN_BYTE(clockreg);				OUT_BYTE(clock & ~(hwif->channel ? 0x08:0x02), clockreg);			}			break;		case ide_dma_test_irq:	/* returns 1 if dma irq issued, 0 otherwise */			dma_stat = IN_BYTE(dma_base+2);			if (newchip)				return (dma_stat & 4) == 4;			sc1d = IN_BYTE(high_16 + 0x001d);			if (HWIF(drive)->channel) {				if ((sc1d & 0x50) == 0x50) goto somebody_else;				else if ((sc1d & 0x40) == 0x40)					return (dma_stat & 4) == 4;			} else {				if ((sc1d & 0x05) == 0x05) goto somebody_else;				else if ((sc1d & 0x04) == 0x04)					return (dma_stat & 4) == 4;			}somebody_else:			return (dma_stat & 4) == 4;	/* return 1 if INTR asserted */		case ide_dma_lostirq:		case ide_dma_timeout:			if (HWIF(drive)->resetproc != NULL)				HWIF(drive)->resetproc(drive);		default:			break;	}	return ide_dmaproc(func, drive);	/* use standard DMA stuff */}#endif /* CONFIG_BLK_DEV_IDEDMA */void pdc202xx_reset (ide_drive_t *drive){	OUT_BYTE(0x04,IDE_CONTROL_REG);	mdelay(1000);	OUT_BYTE(0x00,IDE_CONTROL_REG);	mdelay(1000);	printk("PDC202XX: %s channel reset.\n",		HWIF(drive)->channel ? "Secondary" : "Primary");}/* * Since SUN Cobalt is attempting to do this operation, I should disclose * this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date * HOTSWAP ATA Infrastructure. */static int pdc202xx_tristate (ide_drive_t * drive, int state){#if 0	ide_hwif_t *hwif	= HWIF(drive);	unsigned long high_16	= pci_resource_start(hwif->pci_dev, 4);	byte sc1f		= inb(high_16 + 0x001f);	if (!hwif)		return -EINVAL;//	hwif->bus_state = state;	if (state) {		outb(sc1f | 0x08, high_16 + 0x001f);	} else {		outb(sc1f & ~0x08, high_16 + 0x001f);	}#endif	return 0;}unsigned int __init pci_init_pdc202xx (struct pci_dev *dev, const char *name){	unsigned long high_16	= pci_resource_start(dev, 4);	byte udma_speed_flag	= IN_BYTE(high_16 + 0x001f);	byte primary_mode	= IN_BYTE(high_16 + 0x001a);	byte secondary_mode	= IN_BYTE(high_16 + 0x001b);	OUT_BYTE(udma_speed_flag | 0x10, high_16 + 0x001f);	mdelay(100);	OUT_BYTE(udma_speed_flag & ~0x10, high_16 + 0x001f);	mdelay(2000);	/* 2 seconds ?! */	if (dev->resource[PCI_ROM_RESOURCE].start) {		pci_write_config_dword(dev, PCI_ROM_ADDRESS, dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);		printk("%s: ROM enabled at 0x%08lx\n", name, dev->resource[PCI_ROM_RESOURCE].start);	}		printk("%s: (U)DMA Burst Bit %sABLED " \		"Primary %s Mode " \		"Secondary %s Mode.\n",		name,		(udma_speed_flag & 1) ? "EN" : "DIS",		(primary_mode & 1) ? "MASTER" : "PCI",		(secondary_mode & 1) ? "MASTER" : "PCI" );#ifdef CONFIG_PDC202XX_BURST	if (!(udma_speed_flag & 1)) {		printk("%s: FORCING BURST BIT 0x%02x -> 0x%02x ", name, udma_speed_flag, (udma_speed_flag|1));		OUT_BYTE(udma_speed_flag|1, high_16 + 0x001f);		printk("%sCTIVE\n", (IN_BYTE(high_16 + 0x001f) & 1) ? "A" : "INA");	}#endif /* CONFIG_PDC202XX_BURST */#ifdef CONFIG_PDC202XX_MASTER	if (!(primary_mode & 1)) {		printk("%s: FORCING PRIMARY MODE BIT 0x%02x -> 0x%02x ",			name, primary_mode, (primary_mode|1));		OUT_BYTE(primary_mode|1, high_16 + 0x001a);		printk("%s\n", (IN_BYTE(high_16 + 0x001a) & 1) ? "MASTER" : "PCI");	}	if (!(secondary_mode & 1)) {		printk("%s: FORCING SECONDARY MODE BIT 0x%02x -> 0x%02x ",			name, secondary_mode, (secondary_mode|1));		OUT_BYTE(secondary_mode|1, high_16 + 0x001b);		printk("%s\n", (IN_BYTE(high_16 + 0x001b) & 1) ? "MASTER" : "PCI");	}#endif /* CONFIG_PDC202XX_MASTER */#if defined(DISPLAY_PDC202XX_TIMINGS) && defined(CONFIG_PROC_FS)	if (!pdc202xx_proc) {		pdc202xx_proc = 1;		bmide_dev = dev;		pdc202xx_display_info = &pdc202xx_get_info;	}#endif /* DISPLAY_PDC202XX_TIMINGS && CONFIG_PROC_FS */	return dev->irq;}unsigned int __init ata66_pdc202xx (ide_hwif_t *hwif){	unsigned short mask = (hwif->channel) ? (1<<11) : (1<<10);	unsigned short CIS;        	switch(hwif->pci_dev->device) {		case PCI_DEVICE_ID_PROMISE_20276:		case PCI_DEVICE_ID_PROMISE_20275:		case PCI_DEVICE_ID_PROMISE_20269:		case PCI_DEVICE_ID_PROMISE_20268:		case PCI_DEVICE_ID_PROMISE_20270:			OUT_BYTE(0x0b, (hwif->dma_base + 1));			return (!(IN_BYTE((hwif->dma_base + 3)) & 0x04));			/* check 80pin cable */		default:			pci_read_config_word(hwif->pci_dev, 0x50, &CIS);			return (!(CIS & mask));			/* check 80pin cable */	}}void __init ide_init_pdc202xx (ide_hwif_t *hwif){	hwif->tuneproc  = &pdc202xx_tune_drive;	hwif->quirkproc = &pdc202xx_quirkproc;	hwif->resetproc = &pdc202xx_reset;        switch(hwif->pci_dev->device) {		case PCI_DEVICE_ID_PROMISE_20276:		case PCI_DEVICE_ID_PROMISE_20275:		case PCI_DEVICE_ID_PROMISE_20269:		case PCI_DEVICE_ID_PROMISE_20268:		case PCI_DEVICE_ID_PROMISE_20270:			hwif->speedproc = &pdc202xx_new_tune_chipset;			break;		case PCI_DEVICE_ID_PROMISE_20267:		case PCI_DEVICE_ID_PROMISE_20265:		case PCI_DEVICE_ID_PROMISE_20262:			hwif->busproc   = &pdc202xx_tristate;		case PCI_DEVICE_ID_PROMISE_20246:			hwif->speedproc = &pdc202xx_tune_chipset;		default:			break;	}#undef CONFIG_PDC202XX_32_UNMASK#ifdef CONFIG_PDC202XX_32_UNMASK	hwif->drives[0].io_32bit = 1;	hwif->drives[1].io_32bit = 1;	hwif->drives[0].unmask = 1;	hwif->drives[1].unmask = 1;#endif /* CONFIG_PDC202XX_32_UNMASK */#ifdef CONFIG_BLK_DEV_IDEDMA	if (hwif->dma_base) {		hwif->dmaproc = &pdc202xx_dmaproc;		if (!noautodma)			hwif->autodma = 1;	} else {		hwif->drives[0].autotune = 1;		hwif->drives[1].autotune = 1;		hwif->autodma = 0;	}#else /* !CONFIG_BLK_DEV_IDEDMA */	hwif->drives[0].autotune = 1;	hwif->drives[1].autotune = 1;	hwif->autodma = 0;#endif /* CONFIG_BLK_DEV_IDEDMA */}

⌨️ 快捷键说明

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