/**************************************************************************************
*
* Project Name : IIC Driver
*
* Copyright 2007 by Samsung Electronics, Inc.
* All rights reserved.
*
* Project Description :
* This software is MDD layer for IIC Samsung driver.
*
*--------------------------------------------------------------------------------------
*
* File Name : iic_mdd.cpp
*
* File Description : This file implements MDD layer functions which is stream driver.
*
**************************************************************************************/
#include <windows.h>
#include <types.h>
#include <linklist.h>
#include <nkintr.h>
#include <devload.h>
#include <pm.h>
#include <pmplatform.h>
#include <iic_mdd.h>
#include <iic_pdd.h>
#define DEFAULT_CE_THREAD_PRIORITY 103
CEDEVICE_POWER_STATE g_Dx;
// Define some internally used functions
BOOL IIC_Close(PHW_OPEN_INFO pOpenContext);
BOOL IIC_Deinit(PHW_INIT_INFO pInitContext);
void IIC_PowerUp(PHW_INIT_INFO pInitContext);
void IIC_PowerDown(PHW_INIT_INFO pInitContext);
#if DEBUG
#define ZONE_ERROR DEBUGZONE(0)
#define ZONE_WARN DEBUGZONE(1)
#define ZONE_FUNCTION DEBUGZONE(2)
#define ZONE_INIT DEBUGZONE(3)
#define ZONE_INFO DEBUGZONE(4)
#define ZONE_IST DEBUGZONE(5)
DBGPARAM dpCurSettings =
{
TEXT("IIC"),
{
TEXT("Errors"),TEXT("Warnings"),TEXT("Function"),TEXT("Init"),
TEXT("Info"),TEXT("Ist"),TEXT("Undefined"),TEXT("Undefined"),
TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),
TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined"),TEXT("Undefined")
},
(1 << 0) // Errors
| (1 << 1) // Warnings
};
#endif
static const POWER_CAPABILITIES g_PowerCaps =
{
// DeviceDx: Supported power states
DX_MASK(D0 ) | DX_MASK(D4),
0, // WakeFromDx:
0, // InrushDx: No inrush of power
{ // Power: Maximum milliwatts in each state
0x00000001, // D0 = 0
0x00000001, // D1 = 0
0x00000001, // D2 = 0
0x00000001, // D3 = 0
0x00000001 // D4 = 0 (off)
},
{ // Latency
0x00000000, // D0 = 0
0x00000000, // D1 = 0
0x00000000, // D2 = 0
0x00000000, // D3 = 0
0x00000000 // D4 = 0
},
POWER_CAP_PREFIX_MICRO | POWER_CAP_UNIT_AMPS, // Flags
};
//////////
// Function Name : DllEntry
// Function Description : Process attach/detach api.
// Input : HINSTANCE hinstDll, DWORD dwReason, LPVOID lpReserved
// Output : The return is a BOOL, representing success (TRUE) or failure (FALSE).
// Version : v1.0
BOOL
DllEntry(
HINSTANCE hinstDll, /*Instance pointer. */
DWORD dwReason, /*Reason routine is called. */
LPVOID lpReserved /*system parameter. */
)
{
if ( dwReason == DLL_PROCESS_ATTACH ) {
DEBUGREGISTER(hinstDll);
DEBUGMSG (ZONE_INIT, (TEXT("process attach\r\n")));
DisableThreadLibraryCalls((HMODULE) hinstDll);
}
if ( dwReason == DLL_PROCESS_DETACH ) {
DEBUGMSG (ZONE_INIT, (TEXT("process detach called\r\n")));
}
return(TRUE);
}
//////////
// Function Name : IIC_Init
// Function Description : IIC device initialization.
// Input : LPCTSTR pContext
// Output : Returns a pointer to the head which is passed into
// the IIC_OPEN and IIC_DEINIT entry points as a device handle.
// Version : v0.5
HANDLE
IIC_Init(
LPCTSTR pContext /* Pointer to a string containing the registry path.*/
)
{
PHW_INIT_INFO pInitContext = NULL;
HKEY hKey;
ULONG datasize = sizeof(ULONG);
ULONG kvaluetype;
DEBUGCHK(pContext != NULL);
DEBUGMSG(ZONE_FUNCTION,(TEXT("+IIC_Init\r\n")));
// Allocate our control structure.
pInitContext = (PHW_INIT_INFO)LocalAlloc(LPTR, sizeof(HW_INIT_INFO));
// Check that LocalAlloc did stuff ok too.
if ( !pInitContext ) {
DEBUGMSG(ZONE_ERROR,
(TEXT("Error allocating memory for pInitContext, IIC_Init failed\n\r")));
return(NULL);
}
// Initially, open list is empty.
InitializeListHead( &pInitContext->OpenList );
InitializeCriticalSection(&(pInitContext->OpenCS));
/* Initialize the critical sections that will guard the parts of
* the receive and transmit action.
*/
InitializeCriticalSection(&(pInitContext->CritSec));
pInitContext->pAccessOwner = NULL;
/* Want to use the Identifier to do RegOpenKey and RegQueryValue (?)
* to get the index to be passed to GetHWObj.
* The HWObj will also have a flag denoting whether to start the
* listening thread or provide the callback.
*/
DEBUGMSG(ZONE_INFO, (TEXT("Try to open %s\r\n"), pContext));
hKey = OpenDeviceKey(pContext);
if ( !hKey ) {
DEBUGMSG (ZONE_ERROR,
(TEXT("Failed to open devkeypath, IIC_Init failed\r\n")));
IIC_Deinit(pInitContext);
return(NULL);
}
datasize = sizeof(DWORD);
if ( RegQueryValueEx(hKey, L"Priority256", NULL, &kvaluetype,
(LPBYTE)&pInitContext->Priority256, &datasize) ) {
pInitContext->Priority256 = DEFAULT_CE_THREAD_PRIORITY;
DEBUGMSG (ZONE_WARN,
(TEXT("Failed to get Priority256 value, defaulting to %d\r\n"), pInitContext->Priority256));
}
if ( RegQueryValueEx(hKey, L"SlaveAddress", NULL, &kvaluetype,
(LPBYTE)&pInitContext->PDDCommonVal.SlaveAddress, &datasize) ) {
pInitContext->PDDCommonVal.SlaveAddress = DEFAULT_SLAVE_ADDRESS;
DEBUGMSG (ZONE_WARN,
(TEXT("Failed to get SlaveAddress value, defaulting to %d\r\n"), pInitContext->PDDCommonVal.SlaveAddress));
}
if ( RegQueryValueEx(hKey, L"Mode", NULL, &kvaluetype,
(LPBYTE)&pInitContext->PDDCommonVal.InterruptEnable, &datasize) ) {
pInitContext->PDDCommonVal.InterruptEnable = DEFAULT_INTERRUPT_ENABLE;
DEBUGMSG (ZONE_WARN,
(TEXT("Failed to get InterruptEnable value, defaulting to %d\r\n"), pInitContext->PDDCommonVal.InterruptEnable));
}
RegCloseKey (hKey);
pInitContext->State = IIC_RUN;
/* Check that HW_Init did stuff ok. From here on out, call Deinit function
* when things fail.
*/
if ( !HW_Init(pInitContext) ) {
DEBUGMSG (ZONE_ERROR,
(TEXT("Hardware doesn't init correctly, IIC_Init failed\r\n")));
IIC_Deinit(pInitContext);
return(NULL);
}
g_Dx = D0;
DEBUGMSG(ZONE_FUNCTION, (TEXT("-IIC_Init\r\n")));
return(pInitContext);
}
//////////
// Function Name : IIC_Deinit
// Function Description : IIC device De-initialization.
// Input : PHW_INIT_INFO pInitContext
// Output : The return is a BOOL, representing success (TRUE) or failure (FALSE).
// Version : v0.5
BOOL
IIC_Deinit(
PHW_INIT_INFO pInitContext /* Context pointer returned from IIC_Init*/
)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("+IIC_Deinit\r\n")));
if ( !pInitContext ) {
/* Can't do much without this */
DEBUGMSG (ZONE_ERROR,
(TEXT("IIC_Deinit can't find pInitContext\r\n")));
SetLastError(ERROR_INVALID_HANDLE);
return(FALSE);
}
/*
** Call close, if we have a user. Note that t
评论1