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

📄 pd6700_ide.c

📁 周立功magic2410实验箱源码 第6章Linux高级实验(part2) 6.9 IDE硬盘实验. 6.10 USB主机驱动编译与加载实验 6.11 U盘驱动程序编译与使用实验 6.12
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************Copyright (c)****************************************************                               Guangzhou ZHIYUAN electronics Co.,LTD.**                                     **                                 http://www.zyinside.com****--------------File Info-------------------------------------------------------------------------------** File Name: pd6700_id.c** Last modified Date: 2006-01-14 ** Last Version: v1.0** Description: Linxu系统下PD6710的ATA模式驱动应用程序。** Note: **------------------------------------------------------------------------------------------------------** Created By: 周立山** Created date: 2006-01-01 ** Version: v1.0** Descriptions:****------------------------------------------------------------------------------------------------------** Modified by:** Modified date:** Version:** Description:**********************************************************************************************************/#ifndef __KERNEL__    #define __KERNEL__#endif#ifndef MODULE    #define MODULE#endif#include <linux/module.h>#include <linux/sched.h>#include <linux/kernel.h>       /* printk() */#include <linux/init.h>#include <linux/config.h>#include <linux/types.h>#include <linux/fcntl.h>#include <linux/string.h>#include <linux/errno.h>#include <linux/timer.h>#include <linux/slab.h>#include <linux/ioport.h>#include <linux/delay.h>#include <linux/proc_fs.h>#include <linux/ptrace.h>#include <linux/hdreg.h>#include <linux/major.h>#include <asm/irq.h>#include <asm/io.h>#include <asm/bitops.h>#include <asm/segment.h>#include <asm/system.h>#include "pd6700.h"#include <asm/hardware.h>#define io_base(port)	(*(volatile u_char *)(vCF_IO_BASE + port))//===========================================================================#define PCMCIA_DEBUG 5									// 是否打印调试信息//===========================================================================#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;MODULE_PARM(pc_debug, "i");#define DEBUG(n, args...) if (n <=  pc_debug) {printk(KERN_INFO args);}static const char *version ="pd6700.c 1.265 2005/12/08 zhoulishan";#else#define DEBUG(n, args...)#endifstruct ide_info_t {    int	ndev;    int	hd;}ide_info_t;// PCMCIA卡接口信息typedef struct socket_info_t {   int				ioaddr;							// IO 接口地址    u_short		psock;								// 接口号    u_char		cs_irq; 							// PD6710芯片中断    u_char		intr;									// 中断号		u_char		time0_setup;					// 状态		u_char		time0_command;		u_char		time0_recovery;		u_char		time1_setup;					// 状态		u_char		time1_command;		u_char		time1_recovery;		int				io_base;		u_char		io_len;		int 			ctl_base;		u_char		ctl_len;		u_char		ata_irq;		struct ide_info_t ide;} socket_info_t;static socket_info_t socket[1]={	{		ioaddr:					0x3e0 ,		//		psock:  				0,											//			cs_irq: 				3,											// 卡检测中断		intr:						3,											// IRQ	// 总线时序参数			time0_setup:		0,											// 40ns =  40*0 + 40		time0_command:	3,											// 160ns =(40*3 + 40		time0_recovery:	0,											// 40ns =  40*0 + 40		time1_setup:		0,		time1_command:	3,		time1_recovery:	0,		io_base:				vCF_IO_BASE + 0x1f0 ,		// IDE地址设置		io_len:					8,			ctl_base:				vCF_IO_BASE + 0x3f6 ,		ctl_len:				2,		ata_irq:				IRQ_CF_RDY							// IDE使用的中断  }};/********************************************************************************************************/static spinlock_t bus_lock = SPIN_LOCK_UNLOCKED;/*********************************************************************************************************** Function name: pd67_get** Descriptions: 获取接口寄存器的值** Input:sock,接口号**  			reg,寄存器索引** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static u_char pd67_get(u_short sock, u_short reg){   unsigned long flags;    spin_lock_irqsave(&bus_lock,flags);				// 关中断    {		int port = socket[sock].ioaddr;				// IO地址				u_char val;				reg = PD67_REG(socket[sock].psock, reg);		// 获取寄存器索引				io_base(port) = (u_char) reg;							// 写寄存器地址				val = io_base(port+1);										// 读寄存器值				spin_unlock_irqrestore(&bus_lock,flags);		// 开中断			printk(KERN_ERR "reg = 0x%x ,port = 0x%x , val = 0x%x \n", reg, port ,val);				return val;    }}/*********************************************************************************************************** Function name: pd67_set** Descriptions: 写入指定寄存器的值** Input:** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void pd67_set(u_short sock, u_short reg, u_char data){   unsigned long flags;    spin_lock_irqsave(&bus_lock,flags);    {		int port = socket[sock].ioaddr;				u_char val = PD67_REG(socket[sock].psock, reg);				io_base(port) = (u_char)val;				io_base(port+1) = (u_char)data;				spin_unlock_irqrestore(&bus_lock,flags);    }}/*********************************************************************************************************** Function name: pd67_bset** Descriptions: 设置寄存器标记位.先读出寄存器的值,再将该值与mask求或,最后写入到寄存器** Input:sock, 接口索引号** 			 reg,寄存器索引号**			 mask,屏蔽位** Output : 无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void pd67_bset(u_short sock, u_short reg, u_char mask){    u_char d = pd67_get(sock, reg);    d |= mask;    pd67_set(sock, reg, d);}/*********************************************************************************************************** Function name: pd67_bclr** Descriptions: 清零标志位,将寄存器中mask相应的位清零** Input:sock, 接口索引号** 			 reg,寄存器索引号**			 mask,屏蔽位** Output :** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void pd67_bclr(u_short sock, u_short reg, u_char mask){    u_char d = pd67_get(sock, reg);    d &= ~mask;    pd67_set(sock, reg, d);}/*********************************************************************************************************** Function name: pd67_bflip** Descriptions: 该函数集成了pd67_bset和pd67_bclr的功能,通过b的值选择相关的操作,b为0清标志位,反之置标志位** Input:sock,接口索引**			 reg, 寄存器索引**			 mask, 屏蔽位**			 b, 操作标志位** Output : 无** Created by:** Created Date: **-------------------------------------------------------------------------------------------------------** Modified by:** Modified Date: **------------------------------------------------------------------------------------------------------********************************************************************************************************/static void pd67_bflip(u_short sock, u_short reg, u_char mask, int b){    u_char d = pd67_get(sock, reg);					// 读出寄存器原值    if (b)	d |= mask;    else		d &= ~mask;    pd67_set(sock, reg, d);								// 写入寄存器}/*********************************************************************************************************** Function name: pd67_get_pair** Descriptions: 获取寄存器连续两个值,将寄存器reg和reg+1(高8位)组成一个16位的值,** Input:sock , 接口号**			 reg , 寄存器索引** Output : 返回16位的值** Created by:

⌨️ 快捷键说明

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