📄 gspx_bus.c
字号:
#ifdef SC2442_SPI
#include <Windows.h>
#include <Pkfuncs.h>
//#include "igxBug.h"
#include "dbg.h"
#include "gspx_bus.h"
#include "s3c2440a.h"
#include "nkintr.h"
#include "JaguarGSPX.h"
static ISR_CB wlan_isr_callback;
#define GSPI_ISR(pDriver) do { \
if (wlan_isr_callback) \
wlan_isr_callback(pDriver->CbData); \
}while (0);
static DWORD WINAPI GspiBusIST(PVOID pContext);
static CRITICAL_SECTION ioLock;
//static GSPI_GRV_DATA GspiDriverData;
//pGSPI_GRV_DATA g_pDrvData = &GspiDriverData;
// Board dependent APIs
int GspiBusHwInit();
unsigned long GspiBusGetBSPIntID();
void gspi_set_read_delay(int reg,int io);
int gspi_read_data(UINT16 *data, UINT16 size);
int gspi_bus_write_data(UINT16 *data, UINT16 size);
int gspi_read_data_direct(UCHAR *data, UINT16 reg, UINT16 size);
int gspi_bus_write_data_direct(UCHAR *data, UINT16 reg, UINT16 size);
int gspi_read_data_nodma(UINT16 *data, UINT16 size);
int gspi_write_data_nodma(UINT16 *data, UINT16 size);
int gspi_read_data_direct_nodma(UCHAR *data, UINT16 reg, UINT16 size);
int gspi_write_data_direct_nodma(UCHAR *data, UINT16 reg, UINT16 size);
// Local function declaration
int GspiBusInit(PVOID pHC);
extern int GspiCardInit(void);
int GspiBusIntrInit(IN PGSPI_GRV_DATA pDriver);
//int GspiBusIntrInit(PVOID adapter_p, pGSPI_GRV_DATA pDriver);
int GspiBusDeinit(PVOID pHC);
extern int GspiBusIntrDeinit(IN PGSPI_GRV_DATA pDriver);
extern int GspiBusHwDeinit();
extern int GspiBusIntGPIOInit();
extern void GspiBusRaiseBusClock(void);
extern void GspiBusLowerBusClock(void);
#if 1
//__inline
void GspiBusReleaseIO()
{
LeaveCriticalSection(&ioLock);
}
//__inline
int GspiBusAcquireIO()
{
EnterCriticalSection(&ioLock);
return 1;
}
#endif
int GspiBusInit(PVOID pHC)
{
//NdisZeroMemory(g_pDrvData, sizeof(*g_pDrvData));
//memset(g_pDrvData, 0, sizeof(*g_pDrvData));
// Initialize locks
InitializeCriticalSection(&ioLock);
EnterCriticalSection(&ioLock);//gli++
if(GspiBusHwInit() != GSPI_OK )
return !GSPI_OK;
GspiBusIntGPIOInit();
((PGSPI_GRV_DATA)pHC)->dwBusClkRt = GSPI_LOW_CLK_RATE;
if (GspiBusIntrInit(pHC) != GSPI_OK)
return !GSPI_OK;
LeaveCriticalSection(&ioLock);//gli++
return GSPI_OK;
}
int GspiBusDeinit(PVOID pHC)
{
gspx_power_down(pHC); // ksorada : fixed CR#798
if (GspiBusIntrDeinit(pHC) != GSPI_OK)
return !GSPI_OK;
if(GspiBusHwDeinit() != GSPI_OK)
return !GSPI_OK;
// Release locks
//DeleteCriticalSection(&ioLock);//gli++
return GSPI_OK;
}
BOOL InterruptInitialize(
DWORD idInt,
HANDLE hEvent,
LPVOID pvData,
DWORD cbData
);
VOID InterruptDone(
DWORD idInt
);
VOID InterruptDisable(
DWORD idInt
);
// Intr_Init: Called when the driver is initialized.
int GspiBusIntrInit(PGSPI_GRV_DATA pDriver)
{
DWORD irq= IRQ_EINT11; //39;
pDriver->IstPriority = ISTPRIORITY;
// Create the event flag for the IST.
pDriver->hGspiIntrEvent = CreateEvent(
NULL, //Ignored. Must be NULL.
FALSE, //FALSE, the system automatically resets
FALSE, //it is nonsignaled.
NULL); //NULL, the event object is created without a name.
// Hook the interrupt and start the associated thread.
// Initialize the interrupt to be associated with the hSerialEvent event.
pDriver->dwIntID = SYSINTR_UNDEFINED;
if( 0== KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &irq, sizeof(DWORD), &pDriver->dwIntID, sizeof(DWORD), NULL))
{
GSPIMSG(1,(TEXT("IOCTL_HAL_REQUEST_SYSINTR failed\n")));
return (!GSPI_OK);
};
GSPIMSG(1,(TEXT("irq = %d sysint= %d\n"),irq, pDriver->dwIntID));
//DBGPRINT(DBG_LOAD,("sysint= %d\n",pDriver->dwIntID));
if(0 == InterruptInitialize(
pDriver->dwIntID, // Logical ID = SYSINTR_FIRMWARE (16)+Irq
pDriver->hGspiIntrEvent, // Event used by OS to trigger thread
NULL, // Ptr passed to OEMInterruptEnable
0))
{
GSPIMSG(1,(TEXT("InterruptInitialize failed\n")));
return (!GSPI_OK);
};
// Create and start the IST thread
pDriver->hIstThread = CreateThread(
NULL, // no security attributes
0, // use default stack size
GspiBusIST, // thread function
pDriver, // argument to thread function
0, // use default creation flags
NULL); // returns the thread identifier
return (GSPI_OK);
}
// IST: The actual Interrupt Service Thread.
static DWORD WINAPI GspiBusIST(PVOID pContext)
{
DWORD dwExitCode;
PGSPI_GRV_DATA pDrv = (PGSPI_GRV_DATA)pContext;
CeSetThreadPriority(GetCurrentThread(), pDrv->IstPriority);
while (1)
{
// GSPIMSG(1,(TEXT("IST is running.\n")));
// Wait for the kernel to set the event flag.
WaitForSingleObject(pDrv->hGspiIntrEvent, INFINITE);
if (pDrv->gspi_exit)
{
GSPIMSG(1,(TEXT("IST shutting down!\n")));
break;
}
// Call an internal function to process the interrupt
// GSPIMSG(1,("GSPIDrvHandler is called!\n"));
GSPI_ISR(pDrv);
// Signal the end of interrupt processing
InterruptDone(pDrv->dwIntID);
}
//following are resource clean up
//InterruptDisable( pDrv->dwIntID ); //disable the hardware interrupt and to deregister the event registered.
//CloseHandle(pDrv->hGspiIntrEvent); //close event
GetExitCodeThread (pDrv->hIstThread, &dwExitCode);
ExitThread(dwExitCode); //gracefully exit thread
//CloseHandle(pDrv->hIstThread); //close thread handle
return (0);
}
// Code adapted from \Public\Common\Oak\Drivers\Serial\MDD.c
// Intr_Init: Called when the driver is initialized.
int GspiBusIntrDeinit(IN PGSPI_GRV_DATA pDriver)
{
// unregister the interrupt event
InterruptDisable(pDriver->dwIntID);
GSPIMSG(1,(TEXT("dwIntID = %d\n"),pDriver->dwIntID));;
if(!KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &(pDriver->dwIntID), sizeof(DWORD), NULL, 0, NULL))
GSPIMSG(1,(TEXT("IOCTL_HAL_RELEASE_SYSINTR failed!\n")));
//JKU: NdisMSleep(1);
Sleep(0);
// to stop IST thread
pDriver->gspi_exit = 1;
SetEvent(pDriver->hGspiIntrEvent);
//NdisMSleep(1);
//YYU: wait for the IST
WaitForSingleObject(pDriver->hIstThread, INFINITE);
GSPIMSG(1,(TEXT("IST ended\n")));
// To release the event object
CloseHandle(pDriver->hGspiIntrEvent);
CloseHandle(pDriver->hIstThread); //close thread handle
return (GSPI_OK);
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DEBUGREGISTER(hModule);
DEBUG_INIT();
DEBUGMSG(ZONE_INIT, (TEXT("DllMain: DLL_PROCESS_ATTACH\n")));
DEBUGMSG(ZONE_INIT, (TEXT("Build date: ")TEXT(__DATE__)TEXT(" ")TEXT(__TIME__)TEXT("\n")));
DisableThreadLibraryCalls((HMODULE) hModule);
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
DEBUGMSG(ZONE_INIT, (TEXT("DllMain: DLL_PROCESS_DETACH\n")));
DEBUG_HALT();
break;
}
return TRUE;
}
/*******************************************************************************
Customer Section:
gspx_ section: user customizes following functions
fucntions are used by outside the controller
*******************************************************************************/
///////////////////////////////////////////////////////////////////////////////
// Function: gspx_init
// Description:
// Initializes a GSPI host controller so that the other required API
// functions can be implemented. The initialization typically includes
// memory mapping, interrupt, GPIO pin initialization, etc
// Parameters:
// None
// Return:
// Pointer to the OEM defined GSPI host device context on success, and
// NULL on failure. The returned device context is passed back to the DLL
// in subsequent calls to the DLL.
///////////////////////////////////////////////////////////////////////////////
PVOID gspx_init(VOID)
{
USHORT chip_rev;
USHORT chip_id;
USHORT host_int_mask;
UINT delay_read_reg;
PGSPI_GRV_DATA pHC;
GSPIMSG(1,(TEXT("+gspx_init(): SC2442\n")));
pHC = LocalAlloc(LPTR, sizeof(GSPI_GRV_DATA));
if (pHC == NULL) {
GSPIMSG(1, (TEXT("Allocate SSP_HARDWARE_CONTEXT FAILED")));
return NULL;
}
if (GSPI_OK == GspiBusInit(pHC))
{
GSPIMSG(1,(TEXT("<== gspx_init: GSPI bus initialized successfully\n")));
}
else
{
GSPIMSG(1,(TEXT("<== gspx_init: Initialize GSPI bus failed!!\n")));
return NULL;
}
//JKU: NdisMSleep(10000);
Sleep(10);
GspiCardInit();
gspx_read_reg32(pHC, 0x6c, &delay_read_reg);
GSPIMSG(1, (TEXT("DRR is 0x%x\n"), delay_read_reg));
gspx_read_reg16(pHC, 0x0 +2, &chip_id);
GSPIMSG(1, (TEXT("Chip_id is 0x%x\n"), chip_id));
gspx_read_reg16(pHC, 0x0 , &chip_rev);
GSPIMSG(1, (TEXT("Chiprev is 0x%x\n"), chip_rev));
//RETAILMSG(1, (TEXT("Chiprev is 0x%x\n"), chip_rev));
/* Read the HOST_INT_STATUS_REG for ACK the first interrrupt got
* from the bootloader. If we don't do this we get a interrupt
* as soon as we register the irq. */
//gspi_read_reg(HOST_INT_STATUS_REG, &host_int_mask);
gspx_read_reg16(pHC, 0x5c, &host_int_mask);
GSPIMSG(1, (TEXT("host int status is 0x%x\n"), host_int_mask));
// RETAILMSG(1, (TEXT("host int status is 0x%x\n"), host_int_mask));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -