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

📄 pd6700_ide.c

📁 周立功magic2410实验箱源码 第6章Linux高级实验(part2) 6.9 IDE硬盘实验. 6.10 USB主机驱动编译与加载实验 6.11 U盘驱动程序编译与使用实验 6.12
💻 C
📖 第 1 页 / 共 2 页
字号:
** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static u_short pd67_get_pair(u_short sock, u_short reg){    u_short a, b;    a = pd67_get(sock, reg);						// 读出寄存器    b = pd67_get(sock, reg+1);					// 读出寄存器+1    return (a + (b<<8));}/*********************************************************************************************************** Function name: pd67_set_pair** Descriptions: 写双寄存器** Input:sock,接口号**			 reg,寄存器索引**			 data, 写入的16位数据值** Output : 无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void pd67_set_pair(u_short sock, u_short reg, u_short data){    pd67_set(sock, reg, data & 0xff);				// 写入寄存器    pd67_set(sock, reg+1, data >> 8);				// 写入寄存器}/*********************************************************************************************************** Function name: pd6710_ata** Descriptions: 初始化PCMCIA卡的ATA模式参数.** Input:sock,接口号** Output : 无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void pd6710_ini_ata(u_short sock){	// This code need to be modified to fit your hardware and software system environment	pd67_set(sock,PD67_POWER,0x00);					// 关闭电源输出		// Disable IRQ lines 	pd67_set(sock,PD67_INTCTL,0);						// 禁止所有中断	// Disable memory and I/O windows		pd67_set(sock,PD67_MAP_ENA,0);					// 禁止所有MAP			// 设置总线时序	pd67_set(sock,PD67_FIFO_CTL,0x80);			//清空FIFO	pd67_set(sock,PD67_SET_TIME0,socket[sock].time0_setup);				// 80ns	pd67_set(sock,PD67_CMD_TIME0,socket[sock].time0_command);					// 320ns	pd67_set(sock,PD67_REC_TIME0,socket[sock].time0_recovery);		// 80ns		// Set ATA mode and enable LED	pd67_set(sock,PD67_ATA_CTL,0x03);	// Reset card,configure for I/O, and set IRQ line to IRQ14	pd67_set(sock,PD67_INTCTL, socket[sock].intr|					// 设置中断\IO卡使能、复位										PD67_PC_RESET|PD67_PC_IOCARD);		// Set I/O windows 0 for 1f0-1f7h	pd67_set_pair(sock,PD67_IO(0),0x01f0);								// IO0 MAP开始地址	pd67_set_pair(sock,PD67_IO(0)+PD67_W_STOP,0x01f7);		// IO0 MAP结束地址	pd67_set_pair(sock,PD67_IO(0)+PD67_W_OFF,0x0000);			// IO0 OFFSET结束地址		// Set I/O windows 1 for 3f6-3f7h	pd67_set_pair(sock,PD67_IO(1),0x03f6);								// IO0 MAP开始地址	pd67_set_pair(sock,PD67_IO(1)+PD67_W_STOP,0x03f7);		// IO0 MAP结束地址	pd67_set_pair(sock,PD67_IO(1)+PD67_W_OFF,0x0000);			// IO0 OFFSET结束地址		// Set I/O width for Auto-Data width	pd67_set(sock,PD67_IOCTL,PD67_IOCTL_IOCS16(0)|PD67_IOCTL_IOCS16(1));		// Enable I/O window 0 and 1	pd67_set(sock,PD67_MAP_ENA,PD67_ENA_IO(0)|PD67_ENA_IO(1));	// 使能IO0和IO1 MAP		// Drive LED and enable three-state bit 7	pd67_set(sock,PD67_MISC_CTL_2,PD67_MC2_LED_ENA|PD67_MC2_3STATE_BIT7);	pd67_set(sock,PD67_MISC_CTL_1,0);													// 输出5V 中断为电平触发		// Apply power and enable outputs	pd67_set(sock,PD67_POWER,0x90);														// 输出电源	// Add some delay. The delay tome depends on the drive specifications.	mdelay(10);	// Activate the reset pin	pd67_bclr(sock,PD67_INTCTL,PD67_PC_RESET);				// ATA复位	// Add some delay. The delay time depends on the drive specifications	mdelay(5);	// Remove the reset signal	pd67_bset(sock,PD67_INTCTL,PD67_PC_RESET);	mdelay(50);	}/*********************************************************************************************************** Function name: ini_pcmcia_bridge** Descriptions: 初始化PCMCIA桥芯片,并分配系统硬件资源,仅在init_pd6700()函数中使用.** Input: 无** Output : 无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static int __init ini_pcmcia_bridge(u_short sock){  	pd67_set(sock,PD67_CHIP_INFO,0);		if((pd67_get(sock,PD67_CHIP_INFO)&0xc0)!=0xc0||(pd67_get(sock,PD67_CHIP_INFO)&0xc0)!=0x00)		{			return -1;		}       if (pd67_get(sock, PD67_IDENT) & 0x70) {			// 辩认PCMCIA控制器ID				return -1;    }		return 0;}/*********************************************************************************************************** Function name: ide_release** Descriptions: ** Input:arg,** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/void ide_release(void){    DEBUG(0, "ide_release()\n");    if (socket[0].ide.ndev) {				ide_unregister(socket[0].ide.hd);					// 注销IDE驱动				MOD_DEC_USE_COUNT;    }    		// Turn off all interrupt sources! 		pd67_set(0, PD67_CSCINT, 0);							// 关闭所有中断输出   	release_region(socket[0].ioaddr, 2);			// 释放IO口资源    socket[0].ide.ndev = 0;} // ide_release /*********************************************************************************************************** Function name: init_pd6710_ata** Descriptions: ** Input:arg,** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/int  init_pd6710_ata(void){ 		int i , hd;				printk(KERN_ERR "test: init OK\n");// 配置S3C2410总线接口与    // nGCS2 = nUB/nLB(nSBHE), nWAIT, 16-bit     BWSCON = (BWSCON & ~(BWSCON_ST2 | BWSCON_WS2 | BWSCON_DW2)) |						 (BWSCON_ST2 | BWSCON_WS2 | BWSCON_DW(2, BWSCON_DW_16));    BANKCON2 = BANKCON_Tacs4 | BANKCON_Tcos4 | BANKCON_Tacc14 |							 BANKCON_Toch1 | BANKCON_Tcah4 | BANKCON_Tacp6 | BANKCON_PMC1;  //  set_external_irq(IRQ_nCF_INS, EXT_FALLING_EDGE, GPIO_PULLUP_EN);			//    set_external_irq(IRQ_CF_RDY, EXT_HIGHLEVEL, GPIO_PULLUP_EN);				// 中断配置    DEBUG(0, "%s\n", version);    printk(KERN_INFO "Cirrus Logic probe: "); 		if(check_region(socket[0].ioaddr, 2 )== 0)		// 申请IO地址 		{	 				request_region (socket[0].ioaddr, 2, "pd6700" ); 			 	if (ini_pcmcia_bridge(0) != 0) // 添加PCMCIA桥接口处理函数,		    {		printk("not found.\n");						goto failed;		    }  	}  	else  	{		printk("port conflict at %#x\n", socket[0].ioaddr);				return -ENODEV;  	}  	pd6710_ini_ata(0);							// 初始化PD6710 ATA 模式相关寄存器//============================================================================		// 查询所需的端口是否可用。		if((check_region(socket[0].io_base, socket[0].io_len)!= 0)||			 (check_region(socket[0].ctl_base, socket[0].ctl_len)!= 0))				goto failed;    // retry registration in case device is still spinning up     for ( i = 0; i < 10; i++) {				hd = ide_register(socket[0].io_base, socket[0].ctl_base, socket[0].ata_irq);			// 注册IDE设备				if (hd >= 0) break;				printk(KERN_NOTICE "TASK_UNINTERRUPTIBLE/n");				__set_current_state(TASK_UNINTERRUPTIBLE);									// 等待状态。不能接受信号				schedule_timeout(HZ/10);																		// 进入延时唤醒状态.延时    }        if (hd < 0) {			printk(KERN_NOTICE "PD6710 IDE: ide_register() at 0x%03x & 0x%03x"	       ", irq %u failed\n", socket[0].io_base, socket[0].ctl_base,	       socket[0].ata_irq);				goto failed;    }		printk(KERN_NOTICE "PD6710 IDE: ide_register() at 0x%03x & 0x%03x"	       ", irq %u \n", socket[0].io_base, socket[0].ctl_base,socket[0].ata_irq);	           MOD_INC_USE_COUNT;			// 模块计数    socket[0].ide.ndev = 1;    socket[0].ide.hd = hd;    return 0;    failed:    ide_release();    return -ENODEV;}void exit_pd6710_ata(void){   printk(KERN_ERR "pd6710_ata: remove OK\n");   ide_release();}module_init(init_pd6710_ata);module_exit(exit_pd6710_ata);/***********************************************************************************************************                            End Of File********************************************************************************************************/

⌨️ 快捷键说明

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