📄 1553_junk_bm-5_bu69080s1.c
字号:
m_aCards[u8CardNumber].Channel[u8ChannelNumber].dwRegWndUsrAddr = vma->vm_start;
break;
case ACE_CHAN_MEM_LENGTH:
if( !(m_aCards[u8CardNumber].Channel[u8ChannelNumber].bMmapWinNum == 1) )
{
printk("%s: bu69080s1_fops_mmap(): Size#:%04x returned sequence error\n", MODULE_NAME, dwPcmciaWinSize);
return STATUS_ACE53_MMAP_SEQUENCE_ERROR;
}
dwPcmciaWinBaseAddr = (m_aCards[u8CardNumber].dwMemWndPcmciaAddr)+(u8ChannelNumber*0x20000);
DEBUG(1, "%s: bu69080s1_fops_mmap(): CHANNEL = %02x\n", MODULE_NAME,u8ChannelNumber);
DEBUG(1, "%s: bu69080s1_fops_mmap(): PCI Mem Addr BEFORE = %08lx\n", MODULE_NAME,m_aCards[u8CardNumber].dwMemWndPcmciaAddr);
DEBUG(1, "%s: bu69080s1_fops_mmap(): PCI Mem Addr AFTER = %08x\n", MODULE_NAME,dwPcmciaWinBaseAddr);
m_aCards[u8CardNumber].Channel[u8ChannelNumber].dwMemWndUsrAddr = vma->vm_start;
break;
default:
printk("%s: bu69080s1_fops_mmap(): Size#:%04x returned invalid window size\n", MODULE_NAME,dwPcmciaWinSize);
return STATUS_ACE53_MMAP_INVALID_WINDOW_SIZE;
}
/* Size must be a multiple of PAGE_SIZE. */
if( dwPcmciaWinSize % PAGE_SIZE )
{
mmap_error_cleanup(dwPcmciaWinSize, u8SystemNumber);
printk("%s: bu69080s1_fops_mmap(): Size#:%04x returned invalid page size\n", MODULE_NAME,dwPcmciaWinSize);
return STATUS_ACE53_MMAP_INVALID_PAGE_SIZE;
}
/* Physical window must be page aligned. */
if( dwVMOffset & (PAGE_SIZE - 1) )
{
mmap_error_cleanup(dwPcmciaWinSize, u8SystemNumber);
printk("%s: bu69080s1_fops_mmap(): Size#:%x returned Bad Alignment\n", MODULE_NAME, dwPcmciaWinSize);
return STATUS_ACE53_MMAP_BAD_ALIGNMENT;
}
DEBUG(1, "%s: bu69080s1_fops_mmap(): vma-vm_start %08x\n", MODULE_NAME,(unsigned int)vma->vm_start);
DEBUG(1, "%s: bu69080s1_fops_mmap(): dwPcmciaWinBaseAddr %08x\n", MODULE_NAME,(unsigned int)dwPcmciaWinBaseAddr);
DEBUG(1, "%s: bu69080s1_fops_mmap(): dwPcmciaWinSize %08x\n", MODULE_NAME,(unsigned int)dwPcmciaWinSize);
// Gary Davies: Maybe the previous developer wanted to print a field within the structure vma->vm_page_prot?
//DEBUG(1, "%s: bu69080s1_fops_mmap(): %d\n", MODULE_NAME,vma->vm_page_prot);
/* Remap the PCI window to user space. */
if( remap_page_range( vma->vm_start,
dwPcmciaWinBaseAddr,
dwPcmciaWinSize,
vma->vm_page_prot) )
{
mmap_error_cleanup(dwPcmciaWinSize, u8SystemNumber);
printk("%s: bu69080s1_fops_mmap(): Size#:%04x returned remap fail\n", MODULE_NAME,dwPcmciaWinSize);
return STATUS_ACE53_MMAP_REMAP_FAIL;
}
/* Increment 'mmap' count. */
m_aCards[u8CardNumber].Channel[u8ChannelNumber].bMmapWinNum++;
DEBUG(1, "%s: bu69080s1_fops_mmap(): Size#:%08x returned OK\n", MODULE_NAME,dwPcmciaWinSize);
/* Return success. */
return STATUS_ACE53_SUCCESS;
}
/* Jump table used to invoke driver functions */
struct file_operations m_foFileOps = {
ioctl: bu69080s1_fops_ioctl,
mmap: bu69080s1_fops_mmap,
open: bu69080s1_fops_open,
release: bu69080s1_fops_release
};
/***************
* init_module *
*******************************************************************
** Function ** Register Module and Initialize it. *
*******************************************************************
** Parameters ** None *
*******************************************************************/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*----------------------------END OF CHAR DRIVER FUNCTIONS-----------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------START OF CARD SERVICES FUNCTIONS----------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------------*/
/*====================================================================*/
static void cs_error(client_handle_t handle, int func, int ret)
{
error_info_t err = { func, ret };
CardServices(ReportError, handle, &err);
}
/*======================================================================
bu65553x_attach() creates an "instance" of the driver, allocating
local data structures for one device. The device is registered
with Card Services.
The dev_link structure is initialized, but we don't actually
configure the card at this point -- we wait until we receive a
card insertion event.
======================================================================*/
static dev_link_t *bu69080s1_cs_attach(void)
{
local_info_t *local;
dev_link_t *link;
client_reg_t client_reg;
int ret;
cs_status_t status;
//config_info_t conf;
/* Allocate space for private device-specific data */
local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
if (!local)
{
printk("%s: bu69080s1_cs_attach(): kmalloc() failed\n", MODULE_NAME);
return NULL;
}
memset(local, 0, sizeof(local_info_t));
link = &local->link; link->priv = local;
/* Initialize the dev_link_t structure */
link->release.function = &bu69080s1_cs_release;
link->release.data = (u_long)link;
/*
link->io.BasePort1 = 0x000; // Start the search at 0x000
link->io.NumPorts1 = 1;
link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
link->io.BasePort2 = 0;
link->io.NumPorts2 = 0;
link->io.Attributes2 = IO_DATA_PATH_WIDTH_AUTO;
link->io.IOAddrLines = 0;
*/
/*
General socket configuration defaults can go here. In this
client, we assume very little, and rely on the CIS for almost
everything. In most clients, many details (i.e., number, sizes,
and attributes of IO windows) are fixed by the nature of the
device, and can be hard-wired here.
*/
link->conf.Attributes = CONF_ENABLE_IRQ;
link->conf.Attributes |= CONF_ENABLE_DMA;
link->conf.Vcc = 50;
link->conf.Vpp1 = 50;
link->conf.Vpp2 = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
link->conf.ConfigBase = 0x200;
/* Register with Card Services */
link->next = dev_list;
dev_list = link;
client_reg.dev_info = &dev_info;
client_reg.Attributes = INFO_IO_CLIENT | INFO_MEM_CLIENT | INFO_CARD_SHARE;
client_reg.EventMask =
CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
client_reg.event_handler = &bu69080s1_cs_event;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
ret = CardServices(RegisterClient, &link->handle, &client_reg);
if (ret != CS_SUCCESS) {
printk("%s: bu69080s1_cs_attach(): Attach failed\n", MODULE_NAME);
cs_error(link->handle, RegisterClient, ret);
bu69080s1_cs_detach(link);
return NULL;
}
status.Function = 0;
ret = CardServices(GetStatus, link->handle, &status);
return link;
} /* bu65553x_attach */
/*======================================================================
This deletes a driver "instance". The device is de-registered
with Card Services. If it has been released, all local data
structures are freed. Otherwise, the structures will be freed
when the device is released.
======================================================================*/
static void bu69080s1_cs_detach(dev_link_t *link)
{
dev_link_t **linkp;
int nStatus;
/* Locate device structure */
for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
if (*linkp == link) break;
if (*linkp == NULL)
{
printk("%s: bu69080s1_cs_detach(): *** ERROR *** Could not locate device in card services linked list\n", MODULE_NAME);
return;
}
/*
If the device is currently configured and active, we won't
actually delete it yet. Instead, it is marked so that when
the release() function is called, that will trigger a proper
detach().
*/
if (link->state & DEV_CONFIG) {
DEBUG(50, "%s: bu69080s1_cs_detach(): detach postponed, '%s' still locked\n", MODULE_NAME, link->dev->dev_name);
link->state |= DEV_STALE_LINK;
return;
}
/* Break the link with Card Services */
if (link->handle)
{
nStatus = CardServices(DeregisterClient, link->handle);
}
/* Unlink device structure, and free it */
*linkp = link->next;
/* This points to the parent local_info_t struct */
kfree(link->priv);
} /* bu65553x_detach */
/*======================================================================
bu65553x_config() is scheduled to run after a CARD_INSERTION event
is received, to configure the PCMCIA socket, and to make the
device available to the system.
======================================================================*/
//RAYL DEBUG #define CS_CHECK(fn, args...)
//RAYL DEBUG while ((last_ret=CardServices(last_fn=(fn),args))!=0) goto cs_failed
//RAYL DEBUG #define CFG_CHECK(fn, args...)
//RAYL DEBUG if (CardServices(fn, args) != 0) goto next_entry
/*******************************************************************
* Function: bu69080s1_cs_GetTuple *
* *
* Description: Gets a Tuple from the PCMCIA card (use appropriate *
* part of the cisparse struct requested) *
* *
* Parameters: nTupleType - Pass a value of GetFirstTuple or *
* GetNextTuple; see cs.h *
* *
* handle - Pass a valid client handle; aquired from *
* link->handle *
* *
* nDesriedTuple - Pass a valid tuple type as *
* defined in cistpl.h eg. *
* CISTPL_CONFIG *
* *
* pcisparse - Pass a cisparse struct to Contain *
* the CIS data requested *
* *
* return 0 - Success; *
* !0 - Failure; error codes are defined by Card *
* Services functions *
*******************************************************************/
int bu69080s1_cs_GetTuple( int nTupleType,
//client_handle_t handle,
int nDesiredTuple,
cisparse_t *pcisparse)
{
client_handle_t handle;
tuple_t tuple;
u_char buf[TUPLE_BUFFER_SIZE];
int nStatus = 1;
if(m_aCards[m_bNumberOfCards].plink != NULL)
{
if(m_aCards[m_bNumberOfCards].plink->handle != NULL)
{
handle = m_aCards[m_bNumberOfCards].plink->handle;
tuple.Attributes = 0;
tuple.TupleData = buf;
tuple.TupleDataMax = (cisdata_t)sizeof(buf);
tuple.TupleOffset = 0;
tuple.DesiredTuple = nDesiredTuple;
if((nStatus = CardServices(nTupleType, handle, &tuple)) == 0)
{
if((nStatus = CardServices(GetTupleData, handle, &tuple)) == 0)
{
nStatus = CardServices(ParseTuple, handle, &tuple, pcisparse);
}
}
}
}
return nStatus;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -