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

📄 hpt366.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 4 页
字号:
	pci_write_config_byte(dev, 0x50, 0x37); 	pci_write_config_byte(dev, 0x54, 0x37); 	udelay(100);}static int __devinit init_hpt37x(struct pci_dev *dev){	u8 reg5ah;	pci_read_config_byte(dev, 0x5a, &reg5ah);	/* interrupt force enable */	pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));	return 0;}static int __devinit init_hpt366(struct pci_dev *dev){	u32 reg1	= 0;	u8 drive_fast	= 0;	/*	 * Disable the "fast interrupt" prediction.	 */	pci_read_config_byte(dev, 0x51, &drive_fast);	if (drive_fast & 0x80)		pci_write_config_byte(dev, 0x51, drive_fast & ~0x80);	pci_read_config_dword(dev, 0x40, &reg1);										return 0;}static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name){	int ret = 0;	/*	 * FIXME: Not portable. Also, why do we enable the ROM in the first place?	 * We don't seem to be using it.	 */	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);	pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));	pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);	pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);	pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);	if (hpt_revision(dev) >= 3)		ret = init_hpt37x(dev);	else		ret = init_hpt366(dev);	if (ret)		return ret;	return dev->irq;}static void __devinit init_hwif_hpt366(ide_hwif_t *hwif){	struct pci_dev *dev		= hwif->pci_dev;	struct hpt_info *info		= ide_get_hwifdata(hwif);	u8 ata66 = 0, regmask		= (hwif->channel) ? 0x01 : 0x02;		hwif->tuneproc			= &hpt3xx_tune_drive;	hwif->speedproc			= &hpt3xx_tune_chipset;	hwif->quirkproc			= &hpt3xx_quirkproc;	hwif->intrproc			= &hpt3xx_intrproc;	hwif->maskproc			= &hpt3xx_maskproc;		if(info->flags & IS_372N)		hwif->rw_disk = &hpt372n_rw_disk;	/*	 * The HPT37x uses the CBLID pins as outputs for MA15/MA16	 * address lines to access an external eeprom.  To read valid	 * cable detect state the pins must be enabled as inputs.	 */	if (info->revision >= 8 && (PCI_FUNC(dev->devfn) & 1)) {		/*		 * HPT374 PCI function 1		 * - set bit 15 of reg 0x52 to enable TCBLID as input		 * - set bit 15 of reg 0x56 to enable FCBLID as input		 */		u16 mcr3, mcr6;		pci_read_config_word(dev, 0x52, &mcr3);		pci_read_config_word(dev, 0x56, &mcr6);		pci_write_config_word(dev, 0x52, mcr3 | 0x8000);		pci_write_config_word(dev, 0x56, mcr6 | 0x8000);		/* now read cable id register */		pci_read_config_byte(dev, 0x5a, &ata66);		pci_write_config_word(dev, 0x52, mcr3);		pci_write_config_word(dev, 0x56, mcr6);	} else if (info->revision >= 3) {		/*		 * HPT370/372 and 374 pcifn 0		 * - clear bit 0 of 0x5b to enable P/SCBLID as inputs		 */		u8 scr2;		pci_read_config_byte(dev, 0x5b, &scr2);		pci_write_config_byte(dev, 0x5b, scr2 & ~1);		/* now read cable id register */		pci_read_config_byte(dev, 0x5a, &ata66);		pci_write_config_byte(dev, 0x5b, scr2);	} else {		pci_read_config_byte(dev, 0x5a, &ata66);	}#ifdef DEBUG	printk("HPT366: reg5ah=0x%02x ATA-%s Cable Port%d\n",		ata66, (ata66 & regmask) ? "33" : "66",		PCI_FUNC(hwif->pci_dev->devfn));#endif /* DEBUG */#ifdef HPT_SERIALIZE_IO	/* serialize access to this device */	if (hwif->mate)		hwif->serialized = hwif->mate->serialized = 1;#endif	if (info->revision >= 3) {		u8 reg5ah = 0;			pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);		/*		 * set up ioctl for power status.		 * note: power affects both		 * drives on each channel		 */		hwif->resetproc	= &hpt3xx_reset;		hwif->busproc	= &hpt370_busproc;	} else if (info->revision >= 2) {		hwif->resetproc	= &hpt3xx_reset;		hwif->busproc	= &hpt3xx_tristate;	} else {		hwif->resetproc = &hpt3xx_reset;		hwif->busproc   = &hpt3xx_tristate;	}	if (!hwif->dma_base) {		hwif->drives[0].autotune = 1;		hwif->drives[1].autotune = 1;		return;	}	hwif->ultra_mask = 0x7f;	hwif->mwdma_mask = 0x07;	if (!(hwif->udma_four))		hwif->udma_four = ((ata66 & regmask) ? 0 : 1);	hwif->ide_dma_check = &hpt366_config_drive_xfer_rate;	if (info->revision >= 8) {		hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;		hwif->ide_dma_end = &hpt374_ide_dma_end;	} else if (info->revision >= 5) {		hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;		hwif->ide_dma_end = &hpt374_ide_dma_end;	} else if (info->revision >= 3) {		hwif->dma_start = &hpt370_ide_dma_start;		hwif->ide_dma_end = &hpt370_ide_dma_end;		hwif->ide_dma_timeout = &hpt370_ide_dma_timeout;		hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq;	} else if (info->revision >= 2)		hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;	else		hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;	if (!noautodma)		hwif->autodma = 1;	hwif->drives[0].autodma = hwif->autodma;	hwif->drives[1].autodma = hwif->autodma;}static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase){	struct hpt_info	*info	= ide_get_hwifdata(hwif);	u8 masterdma	= 0, slavedma = 0;	u8 dma_new	= 0, dma_old = 0;	u8 primary	= hwif->channel ? 0x4b : 0x43;	u8 secondary	= hwif->channel ? 0x4f : 0x47;	unsigned long flags;	if (!dmabase)		return;			if(info->speed == NULL) {		printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n");		return;	}	dma_old = hwif->INB(dmabase+2);	local_irq_save(flags);	dma_new = dma_old;	pci_read_config_byte(hwif->pci_dev, primary, &masterdma);	pci_read_config_byte(hwif->pci_dev, secondary, &slavedma);	if (masterdma & 0x30)	dma_new |= 0x20;	if (slavedma & 0x30)	dma_new |= 0x40;	if (dma_new != dma_old)		hwif->OUTB(dma_new, dmabase+2);	local_irq_restore(flags);	ide_setup_dma(hwif, dmabase, 8);}/* *	We "borrow" this hook in order to set the data structures *	up early enough before dma or init_hwif calls are made. */static void __devinit init_iops_hpt366(ide_hwif_t *hwif){	struct hpt_info *info = kzalloc(sizeof(struct hpt_info), GFP_KERNEL);	unsigned long dmabase = pci_resource_start(hwif->pci_dev, 4);	u8 did, rid;	if(info == NULL) {		printk(KERN_WARNING "hpt366: out of memory.\n");		return;	}	ide_set_hwifdata(hwif, info);	if(dmabase) {		did = inb(dmabase + 0x22);		rid = inb(dmabase + 0x28);		if((did == 4 && rid == 6) || (did == 5 && rid > 1))			info->flags |= IS_372N;	}	info->revision = hpt_revision(hwif->pci_dev);	if (info->revision >= 3)		hpt37x_clocking(hwif);	else		hpt366_clocking(hwif);}static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d){	struct pci_dev *findev = NULL;	if (PCI_FUNC(dev->devfn) & 1)		return -ENODEV;	while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {		if ((findev->vendor == dev->vendor) &&		    (findev->device == dev->device) &&		    ((findev->devfn - dev->devfn) == 1) &&		    (PCI_FUNC(findev->devfn) & 1)) {			if (findev->irq != dev->irq) {				/* FIXME: we need a core pci_set_interrupt() */				findev->irq = dev->irq;				printk(KERN_WARNING "%s: pci-config space interrupt "					"fixed.\n", d->name);			}			return ide_setup_pci_devices(dev, findev, d);		}	}	return ide_setup_pci_device(dev, d);}static int __devinit init_setup_hpt37x(struct pci_dev *dev, ide_pci_device_t *d){	return ide_setup_pci_device(dev, d);}static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d){	struct pci_dev *findev = NULL;	u8 pin1 = 0, pin2 = 0;	unsigned int class_rev;	char *chipset_names[] = {"HPT366", "HPT366",  "HPT368",				 "HPT370", "HPT370A", "HPT372",				 "HPT372N" };	if (PCI_FUNC(dev->devfn) & 1)		return -ENODEV;	pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);	class_rev &= 0xff;	if(dev->device == PCI_DEVICE_ID_TTI_HPT372N)		class_rev = 6;			if(class_rev <= 6)		d->name = chipset_names[class_rev];	switch(class_rev) {		case 6:		case 5:		case 4:		case 3:			goto init_single;		default:			break;	}	d->channels = 1;	pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1);	while ((findev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, findev)) != NULL) {		if ((findev->vendor == dev->vendor) &&		    (findev->device == dev->device) &&		    ((findev->devfn - dev->devfn) == 1) &&		    (PCI_FUNC(findev->devfn) & 1)) {			pci_read_config_byte(findev, PCI_INTERRUPT_PIN, &pin2);			if ((pin1 != pin2) && (dev->irq == findev->irq)) {				d->bootable = ON_BOARD;				printk("%s: onboard version of chipset, "					"pin1=%d pin2=%d\n", d->name,					pin1, pin2);			}			return ide_setup_pci_devices(dev, findev, d);		}	}init_single:	return ide_setup_pci_device(dev, d);}static ide_pci_device_t hpt366_chipsets[] __devinitdata = {	{	/* 0 */		.name		= "HPT366",		.init_setup	= init_setup_hpt366,		.init_chipset	= init_chipset_hpt366,		.init_iops	= init_iops_hpt366,		.init_hwif	= init_hwif_hpt366,		.init_dma	= init_dma_hpt366,		.channels	= 2,		.autodma	= AUTODMA,		.bootable	= OFF_BOARD,		.extra		= 240	},{	/* 1 */		.name		= "HPT372A",		.init_setup	= init_setup_hpt37x,		.init_chipset	= init_chipset_hpt366,		.init_iops	= init_iops_hpt366,		.init_hwif	= init_hwif_hpt366,		.init_dma	= init_dma_hpt366,		.channels	= 2,		.autodma	= AUTODMA,		.bootable	= OFF_BOARD,	},{	/* 2 */		.name		= "HPT302",		.init_setup	= init_setup_hpt37x,		.init_chipset	= init_chipset_hpt366,		.init_iops	= init_iops_hpt366,		.init_hwif	= init_hwif_hpt366,		.init_dma	= init_dma_hpt366,		.channels	= 2,		.autodma	= AUTODMA,		.bootable	= OFF_BOARD,	},{	/* 3 */		.name		= "HPT371",		.init_setup	= init_setup_hpt37x,		.init_chipset	= init_chipset_hpt366,		.init_iops	= init_iops_hpt366,		.init_hwif	= init_hwif_hpt366,		.init_dma	= init_dma_hpt366,		.channels	= 2,		.autodma	= AUTODMA,		.bootable	= OFF_BOARD,	},{	/* 4 */		.name		= "HPT374",		.init_setup	= init_setup_hpt374,		.init_chipset	= init_chipset_hpt366,		.init_iops	= init_iops_hpt366,		.init_hwif	= init_hwif_hpt366,		.init_dma	= init_dma_hpt366,		.channels	= 2,	/* 4 */		.autodma	= AUTODMA,		.bootable	= OFF_BOARD,	},{	/* 5 */		.name		= "HPT372N",		.init_setup	= init_setup_hpt37x,		.init_chipset	= init_chipset_hpt366,		.init_iops	= init_iops_hpt366,		.init_hwif	= init_hwif_hpt366,		.init_dma	= init_dma_hpt366,		.channels	= 2,	/* 4 */		.autodma	= AUTODMA,		.bootable	= OFF_BOARD,	}};/** *	hpt366_init_one	-	called when an HPT366 is found *	@dev: the hpt366 device *	@id: the matching pci id * *	Called when the PCI registration layer (or the IDE initialization) *	finds a device matching our IDE device tables. */ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id){	ide_pci_device_t *d = &hpt366_chipsets[id->driver_data];	return d->init_setup(dev, d);}static struct pci_device_id hpt366_pci_tbl[] = {	{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},	{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},	{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},	{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},	{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT374, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},	{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372N, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},	{ 0, },};MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);static struct pci_driver driver = {	.name		= "HPT366_IDE",	.id_table	= hpt366_pci_tbl,	.probe		= hpt366_init_one,};static int hpt366_ide_init(void){	return ide_pci_register_driver(&driver);}module_init(hpt366_ide_init);MODULE_AUTHOR("Andre Hedrick");MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");MODULE_LICENSE("GPL");

⌨️ 快捷键说明

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