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

📄 1553_junk_bm-5_bu69080s1.c

📁 BU-65550M2-605 PCMCIA card (1553) 的驱动程序源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
1                                                      /**************************************************************************
*  File Name : bu69080s1.c
*
*  Project:  Ace BU6555xM2-300 PCMCIA interface driver for Linux 2.2.16-22
*
*
*  Comments:
*            Make within the Linux Card Services package
*            usr/src/linux/pcmcia-cs-x.y.z/clients
*            Ignore warining for .modinfo (not implemented)
*            See readme.txt
*
*  Revision History
*     Date         Name         Version         Description
*--------------------------------------------------------------------------
*  18-Apr-2001    1.0         Original
*  08-Feb-2002    1.1         Updated to suppot Kernel 2.4.X
*                                               -wait_queue structure changed and added 
*                                               initialiser
*                                               -vm_operations_struct removed vm_unmap
*                                               -mmap changed vma->vmoffset to vma->pgOff
*                                               -malloc.h depreciated, changed to slab.h
*
***************************************************************************/
#include <pcmcia/config.h>
#include <pcmcia/k_compat.h>

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/ptrace.h>
#include <linux/malloc.h>
#include <linux/string.h>



#include <linux/timer.h>
#include <linux/ioport.h>
#include <asm/io.h>
#include <asm/system.h>

#include <pcmcia/version.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/ds.h>
#include <pcmcia/bus_ops.h>

#include "bu69080s1.h"

// Driver declarations -----------------------------------------------

/* List of known cards to bind*/
char m_cszArrKnownCards[MAX_NUM_KNOWN_CARDS][20];

/* Holds the MAJOR number of the ace53 driver */
__s32 m_dwMajorNumber = 0;

/* Holds the total number of 65549 cards in the system */
__u8  m_bNumberOfCards = 0;

/* The card list. */
ACE53_CARD  m_aCards[MAX_NUM_CARDS];

/* Card device ID's used by ISR to determine which card issued an interrupt. */
__u8	m_Dev_id[8] = { 0, 1, 2, 3, 4, 5, 6, 7 };

/* String used as a reference for interrupt usage (/proc/interrupts).
 * THIS STRING BEING DECLARED AND INITIALIZED CANNOT BE LOCATED IN THE 'ioctl'
 * METHOD BECAUSE IT WOULD NEED A 'memset' SYMBOL TO BE AVAILABLE, BUT I DON'T
 * THINK ONE EXISTS AT THE KERNEL LEVEL.  IT WOULD COMPILE, BUT GIVES AN ERROR
 * WHEN THE MODULE IS LOADED. */
// sDevName gets updated by the
ioctl function so don't use it to reference the module name in other functions, use MODULE_NAME
__s8	m_sDevName[DEV_NAME_LEN] = { MODULE_NAME };

/* Wait queues used for blocking. */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)//jmf Wait_queue structure changed in kernel 2.4.X
    struct	wait_queue	*m_apWaitQue[MAX_NUM_CARDS*MAX_NUM_CHANS];
#else
    wait_queue_head_t m_apWaitQue[MAX_NUM_CARDS*MAX_NUM_CHANS];
#endif

// End of Driver declarations ----------------------------------------

/*
   All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If
   you do not define PCMCIA_DEBUG at all, all the debug code will be
   left out.  If you compile with PCMCIA_DEBUG=0, the debug code will
   be present but disabled -- but it can then be enabled for specific
   modules at load time with a 'pc_debug=#' option to insmod.
*/

#define PCMCIA_DEBUG 99

#ifdef PCMCIA_DEBUG
static int pc_debug = PCMCIA_DEBUG;
MODULE_PARM(pc_debug, "i");
#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
static char *version =
"bu69080s1 V1.1.1 18";
#else
#define DEBUG(n, args...)
#endif

/*====================================================================*/

/* Parameters that can be set with 'insmod' */

/* The old way: bit map of interrupts to choose from */
/* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
//static u_int irq_mask = 0xdeb8;
/* Newer, simpler way of listing specific interrupts */
//static int irq_list[4] = { -1 };

/*====================================================================*/

/*
   The event() function is this driver's Card Services event handler.
   It will be called by Card Services when an appropriate card status
   event is received.  The config() and release() entry points are
   used to configure or release a socket, in response to card
   insertion and ejection events.  They are invoked from the bu65553x
   event handler. 
*/

static void cs_error(client_handle_t handle, int func, int ret);
static void bu69080s1_cs_config(dev_link_t *link);
static void bu69080s1_cs_release(u_long arg);
static int bu69080s1_cs_event(event_t event, int priority, event_callback_args_t *args);

/*
   The attach() and detach() entry points are used to create and destroy
   "instances" of the driver, where each instance represents everything
   needed to manage one actual PCMCIA card.
*/

static dev_link_t *bu69080s1_cs_attach(void);
static void bu69080s1_cs_detach(dev_link_t *);

/*
   You'll also need to prototype all the functions that will actually
   be used to talk to your device.  See 'memory_cs' for a good example
   of a fully self-sufficient driver; the other drivers rely more or
   less on other parts of the kernel.
*/

/*
   The dev_info variable is the "key" that is used to match up this
   device driver with appropriate cards, through the card configuration
   database.
*/

static dev_info_t dev_info = "bu69080s1";

/*
   A linked list of "instances" of the bu65553x device.  Each actual
   PCMCIA card corresponds to one device instance, and is described
   by one dev_link_t structure (defined in ds.h).

   You may not want to use a linked list for this -- for example, the
   bu65553x card driver uses an array of dev_link_t pointers, where minor
   device numbers are used to derive the corresponding array index.
*/

static dev_link_t *dev_list = NULL;

/*
   A dev_link_t structure has fields for most things that are needed
   to keep track of a socket, but there will usually be some device
   specific information that also needs to be kept track of.  The
   'priv' pointer in a dev_link_t structure can be used to point to
   a device-specific private data structure, like this.

   To simplify the data structure handling, we actually include the
   dev_link_t structure in the device's private data structure.

   A driver needs to provide a dev_node_t structure for each device
   on a card.  In some cases, there is only one device per card (for
   example, ethernet cards, modems).  In other cases, there may be
   many actual or logical devices (SCSI adapters, memory cards with
   multiple partitions).  The dev_node_t structures need to be kept
   in a linked list starting at the 'dev' field of a dev_link_t
   structure.  We allocate them in the card's private data structure,
   because they generally shouldn't be allocated dynamically.

   In this case, we also provide a flag to indicate if a device is
   "stopped" due to a power management event, or card ejection.  The
   device IO routines can use a flag like this to throttle IO to a
   card that is not ready to accept it.

   The bus_operations pointer is used on platforms for which we need
   to use special socket-specific versions of normal IO primitives
   (inb, outb, readb, writeb, etc) for card IO.
*/
   
typedef struct local_info_t {
    dev_link_t		link;
    dev_node_t		node;
    int			stop;
    struct bus_operations *bus;
} local_info_t;

#define __NOTREQUESTED__                          0
#define __REQUESTED__                             1


// Structures used to request card resources; IO ports, IRQ, memory 
typedef struct
{
    win_req_t req;
    memreq_t map;
    window_handle_t winhandle;
    char cArrWindowRequest;
    int* pnDirectPhysicalAddr;
    unsigned long ulWindowSize;
    int* pnDirectKernelAddr;
} Card_Win_t;

typedef struct
{
    char cIORequest;
    char cIRQRequest;
    int nNumWindows;
    Card_Win_t WinArr[MAX_NUM_WINDOWS];
} Card_IO_t;

static Card_IO_t m_CardIO[MAX_NUM_CARDS];

/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*---------------------------START OF CHAR DRIVER FUNCTIONS----------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/




/*******************************************************************
 * Function: bu69080s1_fops_open                                   *
 *                                                                 *
 * Description: Handles opening of a single channel (device)       *
 *                                                                 *
 * Parameters:   inode - used to get the Minor Number		           *
 *               flip  - Not Used				                           *
 *******************************************************************/
int bu69080s1_fops_open(struct inode *inode, struct file *filp)
{
	__u8	bSystemNum      = MINOR(inode->i_rdev);  /* Enumerated device  */
	__u8	bCardNum        = (__u8)bSystemNum / 2;  /* Card number in system (0 - 3) */
	__u8	bChanNum        = bSystemNum % 2;	      /* Channel number on card (0, 1) */
	__u16  wConfigReg      = 0x0000;                /* Ace 0800 Config Register */
	__u8	bOtherChanNum   = (bChanNum+1)%2;	      /* Calculate the index to other chan. */
	__u16  wChanCount      = 0x0000;                /* Number of Channels */
	
	DEBUG(1, "%s: bu69080s1_fops_open(): Sys#:%02d/Card#:%02d/Chan#:%02d\n",MODULE_NAME, bSystemNum,bCardNum,bChanNum);
	/* Check that minor number corresponds to a card in the system. */
	if ( bSystemNum >= m_bNumberOfCards)
	{
	    printk("%s: bu69080s1_fops_open(): STATUS_BU69080S1_CS_DEVICE_NOT_EXIST\n", MODULE_NAME);    
	    return STATUS_ACE53_DEVICE_NOT_EXIST;
	}
	
	/* Check that this device is not already opened. */
	if( m_aCards[bCardNum].Channel[bChanNum].bOpen)
	{
	    printk("%s: bu69080s1_fops_open(): STATUS_ACE53_CARD_ALREADY_OPEN\n", MODULE_NAME);    
	    return STATUS_ACE53_CARD_ALREADY_OPEN;
	}

	/* Check if REGISTER window in User Space was properly closed */
	if( (m_aCards[bCardNum].Channel[bChanNum].dwMemWndUsrAddr) ||
	    (m_aCards[bCardNum].Channel[bChanNum].dwRegWndUsrAddr) )
	{
   		printk("%s: bu69080s1_fops_open(): STATUS_ACE53_CARD_IMPROPERLY_CLOSED\n", MODULE_NAME);
			return STATUS_ACE53_CARD_IMPROPERLY_CLOSED;
	}
	
	/* Set Card Number */
	m_aCards[bCardNum].Channel[bChanNum].bCardNum = bCardNum;

	/* Set Channel Number */
	m_aCards[bCardNum].Channel[bChanNum].bChanNum = bChanNum;
	
	/* Check if the other channel is closed */
	if (m_aCards[bCardNum].Channel[bOtherChanNum].bOpen != 1)
	{
		/* Kernel Memory should be null */
		if(m_aCards[bCardNum].dwRegWndKrnAddr)
		{
			printk("%s: bu69080s1_fops_open(): STATUS_ACE53_CARD_IMPROPERLY_CLOSED\n", MODULE_NAME);
			return STATUS_ACE53_CARD_IMPROPERLY_CLOSED;
		}
		
		/* Map the Register window to kernel space. */
		if(!(m_aCards[bCardNum].dwRegWndKrnAddr = (U32)__ioremap( m_aCards[bCardNum].dwRegWndPcmciaAddr,ACE_CHAN_REG_LENGTH,0)))
		{
		  printk("%s: bu69080s1_fops_open(): STATUS_ACE53_PCMCIACFG_REMAP_FAIL\n", MODULE_NAME);
			return STATUS_ACE53_PCMCIACFG_REMAP_FAIL;
		}

	}
	wConfigReg = readw((void*)(m_aCards[bCardNum].dwRegWndKrnAddr + 0x0800));
	
	DEBUG(1, "%s: bu69080s1_fops_open(): Config Register: %04x\n", MODULE_NAME,wConfigReg);
	
	/* Determine Number of Channels */
	wChanCount = (wConfigReg >> 8) & 0x7;

	/* Set Number of Channels */
	m_aCards[bCardNum].bNumChnls = (U8)wChanCount;
	
	/* Check if requested channel is present */
	if (bChanNum > m_aCards[bCardNum].bNumChnls)
	{
		printk("%s: bu69080s1_fops_open(): STATUS_ACE53_CHANNEL_NOT_AVAILABLE\n", MODULE_NAME);
		return STATUS_ACE53_CHANNEL_NOT_AVAILABLE;      		
	}

⌨️ 快捷键说明

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