BOOL CSDHCBase::Init( LPCTSTR pszActiveKey ) { BOOL fRet = FALSE; SD_API_STATUS status; HKEY hkDevice = NULL; hkDevice = OpenDeviceKey(pszActiveKey); if (!hkDevice || !m_regDevice.Open(hkDevice, _T(""))) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC: Failed to open device key\n"))); goto EXIT; } // Get a handle to our parent bus. m_hBusAccess = CreateBusAccessHandle(pszActiveKey); if (m_hBusAccess == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC: Could not get handle to parent\n"))); goto EXIT; } m_cSlots = DetermineSlotCount(); if (m_cSlots == 0) { goto EXIT; } ValidateSlotCount(); RETAILMSG(0,(TEXT("CSDHCBase::Init m_cSlots=%d\n"),m_cSlots)); // jylee m_pSlotInfos = (PSDHC_SLOT_INFO) LocalAlloc(LPTR, sizeof(SDHC_SLOT_INFO) * m_cSlots); if (m_pSlotInfos == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to allocate slot info objects\n"))); goto EXIT; } status = SDHCDAllocateContext(m_cSlots, &m_pHCDContext); if (!SD_API_SUCCESS(status)) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to allocate context : 0x%08X \n"), status)); goto EXIT; } // Set our extension m_pHCDContext->pHCSpecificContext = this; if (!InitializeHardware()) { goto EXIT; } RETAILMSG(0,(TEXT("AllocateSlotObjects\n"))); // Allocate slot objects m_pSlots = AllocateSlotObjects(m_cSlots); if (m_pSlots == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to allocate slot objects\n"))); goto EXIT; } // Initialize the slots for (DWORD dwSlot = 0; dwSlot < m_cSlots; ++dwSlot) { PSDHC_SLOT_INFO pSlotInfo = &m_pSlotInfos[dwSlot]; PCSDHCSlotBase pSlot = GetSlot(dwSlot); RETAILMSG(0,(TEXT("pSlot->Init\n"))); RETAILMSG(0,(TEXT("pSlotInfo->pucRegisters : 0x%x\r\n"),pSlotInfo->pucRegisters)); if (!pSlot->Init(dwSlot, pSlotInfo->pucRegisters, m_pHCDContext, m_dwSysIntr, m_hBusAccess, m_interfaceType, m_dwBusNumber, &m_regDevice)) { goto EXIT; } } // set the host controller name SDHCDSetHCName(m_pHCDContext, TEXT("HSMMC")); // set init handler SDHCDSetControllerInitHandler(m_pHCDContext, CSDHCBase::SDHCInitialize); // set deinit handler SDHCDSetControllerDeinitHandler(m_pHCDContext, CSDHCBase::SDHCDeinitialize); // set the Send packet handler SDHCDSetBusRequestHandler(m_pHCDContext, CSDHCBase::SDHCBusRequestHandler); // set the cancel I/O handler SDHCDSetCancelIOHandler(m_pHCDContext, CSDHCBase::SDHCCancelIoHandler); // set the slot option handler SDHCDSetSlotOptionHandler(m_pHCDContext, CSDHCBase::SDHCSlotOptionHandler); // These values must be set before calling SDHCDRegisterHostController() // because they are used during that call. m_dwPriority = m_regDevice.ValueDW(SDHC_PRIORITY_KEY, SDHC_CARD_CONTROLLER_PRIORITY); RETAILMSG(0,(TEXT("SDHCDRegisterHostController\n"))); // jylee // now register the host controller status = SDHCDRegisterHostController(m_pHCDContext); if (!SD_API_SUCCESS(status)) { DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHC Failed to register host controller: %0x08X \n"), status)); goto EXIT; } m_fRegisteredWithBusDriver = TRUE; fRet = TRUE; RETAILMSG(0,(TEXT("CSDHCBase::Init Finished.\n"))); // jylee EXIT: if (hkDevice) RegCloseKey(hkDevice); return fRet; }
/////////////////////////////////////////////////////////////////////////////// // SDH_Init - the init entry point // Input: dwContext - the context for this init // Output: // Return: returns instance context // Notes: /////////////////////////////////////////////////////////////////////////////// DWORD SDH_Init(DWORD dwContext) { PSDCARD_HC_CONTEXT pHostContext; // new HC context SD_API_STATUS status; // SD status PSDH_HARDWARE_CONTEXT pController; // new instance HKEY hKeyDevice; LPCTSTR pszActiveKey; DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: +SDH_Init\n"))); DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: Active RegPath: %s \n"), (PTSTR)dwContext)); pController = NULL; // allocate the context status = SDHCDAllocateContext(SDH_SLOTS, &pHostContext); if (!SD_API_SUCCESS(status)) { DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed to allocate context : 0x%08X \n"), status)); return 0; } // create our extension pController = (PSDH_HARDWARE_CONTEXT)malloc( sizeof(SDH_HARDWARE_CONTEXT) ); if( pController == NULL ) { DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed to allocate extension\n"))); return 0; } memset( pController, 0, sizeof(SDH_HARDWARE_CONTEXT) ); // Set our extension pHostContext->pHCSpecificContext = pController; pController = GetExtensionFromHCDContext(PSDH_HARDWARE_CONTEXT, pHostContext); pszActiveKey = (LPCTSTR) dwContext; pController->pszActiveKey = pszActiveKey; pController->hBusAccessHandle = CreateBusAccessHandle( pszActiveKey ); hKeyDevice = OpenDeviceKey(pszActiveKey); if (!hKeyDevice || !LoadRegistrySettings(hKeyDevice, pController) ) { DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed load the registry settings\n"))); return 0; } RegCloseKey( hKeyDevice ); DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: Real RegPath: %s \n"),pController->RegPath)); // save off the host context pController->pHCContext = pHostContext; // set the name SDHCDSetHCName(pHostContext, TEXT("Lubbock")); // set init handler SDHCDSetControllerInitHandler(pHostContext,SDInitialize); // set deinit handler SDHCDSetControllerDeinitHandler(pHostContext, SDDeinitialize); // set the bus request handler SDHCDSetBusRequestHandler(pHostContext,SDHBusRequestHandler); // set the cancel I/O handler SDHCDSetCancelIOHandler(pHostContext, SDHCancelIoHandler); // set the slot option handler SDHCDSetSlotOptionHandler(pHostContext, SDHSlotOptionHandler); // now register the host controller status = SDHCDRegisterHostController(pHostContext); if (!SD_API_SUCCESS(status)) { if( pController ) { free( pController ); } SDHCDDeleteContext(pHostContext); DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDH: Failed to register host controller: %0x08X \n"),status)); return 0; } DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDH: -SDH_Init\n"))); // return the Host Controller context return (DWORD)pHostContext; }