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

📄 pd6700.c

📁 周立功magic2410实验箱源码 第6章Linux高级实验(part1) 6.1 Linux内核编译实验 6.2 Linux根文件系统实验 6.3 CAT1025读/写实验. 6.4 ZL
💻 C
📖 第 1 页 / 共 5 页
字号:
********************************************************************************************************/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);				// 写入寄存器}/*======================================================================    Code to save and restore global state information for Cirrus    PD67xx controllers, and to set and report global configuration    options.    The VIA controllers also use these routines, as they are mostly    Cirrus lookalikes, without the timing registers.    ======================================================================*/#define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b))))/*********************************************************************************************************** Function name: cirrus_get_state** Descriptions: 获取当将PD6710配置状态,仅在get_bridge_state()函数中使用** Input: s,接口索引** Output :无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void cirrus_get_state(u_short s)	// 获取PD67XX状态{    int i;    cirrus_state_t *p = &socket[s].state.cirrus;    p->misc1 = pd67_get(s, PD67_MISC_CTL_1);								    p->misc1 &= (PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA);    p->misc2 = pd67_get(s, PD67_MISC_CTL_2);    for (i = 0; i < 6; i++)				p->timer[i] = pd67_get(s, PD67_TIME_SETUP(0)+i);	// 读取当前建立/命令/保持时间参数}/*********************************************************************************************************** Function name: cirrus_set_state** Descriptions: 设置PD6710芯片的工作状态** Input:s,接口索引** Output :无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void cirrus_set_state(u_short s)	// 设置PD67XX状态{    int i;    u_char misc;    cirrus_state_t *p = &socket[s].state.cirrus;    misc = pd67_get(s, PD67_MISC_CTL_2);									// 先读出原来的Ctrl2的值    pd67_set(s, PD67_MISC_CTL_2, p->misc2);								// 设置Ctrl2寄存器的值    // 判断之前芯片是否在挂起状态,如果是,需要等延时    if (misc & PD67_MC2_SUSPEND) mdelay(50);							// 如果之前为挂起状态,等待唤醒    misc = pd67_get(s, PD67_MISC_CTL_1);									// 获取Ctrl1的值    misc &= ~(PD67_MC1_MEDIA_ENA | PD67_MC1_INPACK_ENA);	//     pd67_set(s, PD67_MISC_CTL_1, misc | p->misc1);				// 设置 MISC CONTROL2    for (i = 0; i < 6; i++)				pd67_set(s, PD67_TIME_SETUP(0)+i, p->timer[i]);		// 设置建立时间}/*********************************************************************************************************** Function name: cirrus_set_opts** Descriptions: ** Input: S,**			  *buf,缓冲区指针** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static u_int __init cirrus_set_opts(u_short s, char *buf){    socket_info_t *t = &socket[s];    cirrus_state_t *p = &socket[s].state.cirrus;    u_int mask = 0xffff;    if (has_ring == -1) has_ring = 1;    flip(p->misc2, PD67_MC2_IRQ15_RI, has_ring);//#define flip(v,b,f) (v = ((f)<0) ? v : ((f) ? ((v)|(b)) : ((v)&(~b))))    flip(p->misc2, PD67_MC2_DYNAMIC_MODE, dynamic_mode);        if (p->misc2 & PD67_MC2_IRQ15_RI)				strcat(buf, " [ring]");    if (p->misc2 & PD67_MC2_DYNAMIC_MODE)				strcat(buf, " [dyn mode]");    if (p->misc1 & PD67_MC1_INPACK_ENA)				strcat(buf, " [inpack]");	    return mask;}/*======================================================================    Generic routines to get and set controller options    ======================================================================*//*********************************************************************************************************** Function name: get_bridge_state** Descriptions: 获取PCMCIA桥状态,仅在set_bridge_opts()函数中使用,添加不同的桥芯片可以在下面添加** Input:	s,接口序号** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void get_bridge_state(u_short s){    socket_info_t *t = &socket[s];    if (t->flags & IS_CIRRUS)					//  是否使用IS_CIRRUS芯片			cirrus_get_state(s);}/*********************************************************************************************************** Function name: set_bridge_state** Descriptions: 设置PCMCIA桥状态(模式)** Input:s,接口索引** Output :无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void set_bridge_state(u_short s){    socket_info_t *t = &socket[s];    if (t->flags & IS_CIRRUS)			cirrus_set_state(s);							// 设置PD6710工作状态(模式)    pd67_bflip(s, PD67_INTCTL, PD67_INTR_ENA, t->intr);	// 根据t->intr确定关中断或是开中断}/*********************************************************************************************************** Function name: set_bridge_opts** Descriptions: 设置IAS-PCMCIA桥选项,仅在add_pcmcia_bridge()函数中使用** Input: s,接口序号**				ns,接口数** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static u_int __init set_bridge_opts(u_short s, u_short ns){    u_short i;    u_int m = 0xffff;    char buf[128];    for (i = s; i < s+ns; i++) {				buf[0] = '\0';				get_bridge_state(i);									// 获取PCMCIA桥状态				if (socket[i].flags & IS_CIRRUS)				    m = cirrus_set_opts(i, buf);			// 				set_bridge_state(i);									// 设置PCMCIA桥状态				printk(KERN_INFO "    host opts [%d]:%s\n", i,				       (*buf) ? buf : " none");    }    return m;}/*======================================================================    Interrupt testing code, for ISA and PCI interrupts    ======================================================================*//*====================================================================*//* Time conversion functions */static int to_cycles(int ns){    return ns/cycle_time;}static int to_ns(int cycles){    return cycle_time*cycles;}/*====================================================================*//*********************************************************************************************************** Function name: identify** Descriptions: 识别接口芯片** Input:port, 总线端口地址**			 sock, 接口号** Output :IS_I82365A,芯片为PD6710。见typedef enum pcic_id枚举** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static int __init identify(u_short port, u_short sock){    u_char val;    int type = -1;    /* Use the next free entry in the socket table */    socket[sockets].ioaddr = port;    socket[sockets].psock = sock;        /* Wake up a sleepy Cirrus controller */    if (wakeup) {	// 如果PD6700持起				pd67_bclr(sockets, PD67_MISC_CTL_2, PD67_MC2_SUSPEND);			// 唤配PD6700				/* Pause at least 50 ms */				mdelay(50);    }    if ((val = pd67_get(sockets, PD67_IDENT)) & 0x70) {			// 辩认PCMCIA控制器ID				return -1;    }    /* Check for Cirrus CL-PD67xx chips */    pd67_set(sockets, PD67_CHIP_INFO, 0);    val = pd67_get(sockets, PD67_CHIP_INFO);			// PD6710 == 0xc4/ PD6720 == 0xe5    if ((val & PD67_INFO_CHIP_ID) == PD67_INFO_CHIP_ID)     {		val = pd67_get(sockets, PD67_CHIP_INFO);				if ((val & PD67_INFO_CHIP_ID) == 0) {			//PD67_INFO_CHIP_ID==0xc0				    type = (val & PD67_INFO_SLOTS) ? IS_PD6722 : IS_PD6710;			// 检测设备为PD672X(有两个接口)还是PD6710(只有一个接口)				}    }    return type;} /* identify *//*======================================================================    See if a card is present, powered up, in IO mode, and already    bound to a (non PC Card) Linux driver.  We leave these alone.    We make an exception for cards that seem to be serial devices.    ======================================================================*//*********************************************************************************************************** Function name: is_alive** Descriptions: 查询当前接口是否活动的只在add_socket()函数中使用.** Input: sock,系统中的接口号** Output : 接口有效返回1,无效返回0** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static int __init is_alive(u_short sock){    u_char stat;    u_short start, stop;        stat = pd67_get(sock, PD67_STATUS);												// 读取状态寄存器值    start = pd67_get_pair(sock, PD67_IO(0)+PD67_W_START);			// PD67_IO(map)==	(0x08+((map)<<2))    stop = pd67_get_pair(sock, PD67_IO(0)+PD67_W_STOP);				//     if ((stat & PD67_CS_DETECT) && (stat & PD67_CS_POWERON) &&// 		(pd67_get(sock, PD67_INTCTL) & PD67_PC_IOCARD) &&						// 		(pd67_get(sock, PD67_MAP_ENA) & PD67_ENA_IO(0)) &&					// IO是否使能 		(check_region(start, stop-start+1) != 0) &&									// 检查所需要的端口,是否可用		((start & 0xfeef) != 0x02e8))																// ???				return 1;    else				return 0;}/*====================================================================*//*********************************************************************************************************** Function name: add_socket** Descriptions: 向系统添加多一个PCMCIA桥接口芯片** Input:port, 基本接口地址**       psock, 接口偏移**       type, 接口类型(控制器芯片),PD6710为8** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void __init add_socket(u_short port, int psock, int type)

⌨️ 快捷键说明

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