//------------------------------------------------------------------------------ // // Function: KPD_Init // // Called by device manager to initialize device. // DWORD KPD_Init(LPCTSTR szContext, LPCVOID pBusContext) { DWORD rc = (DWORD)NULL; KPD_DEVICE *pDevice = NULL; PHYSICAL_ADDRESS pa; DEBUGMSG(ZONE_FUNCTION, ( L"+KPD_Init(%s, 0x%08x)\r\n", szContext, pBusContext )); // Create device structure pDevice = (KPD_DEVICE *)LocalAlloc(LPTR, sizeof(KPD_DEVICE)); if (pDevice == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed allocate KDP driver structure\r\n" )); goto cleanUp; } // Set cookie & initialize critical section pDevice->cookie = KPD_DEVICE_COOKIE; InitializeCriticalSection(&pDevice->cs); // Read device parameters if (GetDeviceRegistryParams( szContext, pDevice, dimof(g_deviceRegParams), g_deviceRegParams ) != ERROR_SUCCESS) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed read KPD driver registry parameters\r\n" )); pDevice->irqs[0]= -1; pDevice->irqs[1]= 2; pDevice->irqs[2]=(DWORD)NULL; pDevice->irqs[3]=(DWORD)NULL; pDevice->irqs[4]=(DWORD)NULL; pDevice->irqs[5]=(DWORD)NULL; pDevice->irqs[6]=(DWORD)NULL; pDevice->priority256=100; pDevice->samplePeriod=40; pDevice->debounceTime=0x50; pDevice->firstRepeat=500; pDevice->nextRepeat=125; // goto cleanUp; } // map gpio memory space pa.QuadPart = OMAP2420_GPIO1_REGS_PA; pDevice->pGPIO1Regs = (OMAP2420_GPIO_REGS *) MmMapIoSpace(pa, sizeof(OMAP2420_GPIO_REGS), FALSE); if (pDevice->pGPIO1Regs == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: Failed to map GPIO1 registers\r\n")); goto cleanUp; } pa.QuadPart = OMAP2420_GPIO2_REGS_PA; pDevice->pGPIO2Regs = (OMAP2420_GPIO_REGS *) MmMapIoSpace(pa, sizeof(OMAP2420_GPIO_REGS), FALSE); if (pDevice->pGPIO2Regs == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: Failed to map GPIO2 registers\r\n")); goto cleanUp; } pa.QuadPart = OMAP2420_GPIO3_REGS_PA; pDevice->pGPIO3Regs = (OMAP2420_GPIO_REGS *) MmMapIoSpace(pa, sizeof(OMAP2420_GPIO_REGS), FALSE); if (pDevice->pGPIO3Regs == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: Failed to map GPIO3 registers\r\n")); goto cleanUp; } pa.QuadPart = OMAP2420_GPIO4_REGS_PA; pDevice->pGPIO4Regs = (OMAP2420_GPIO_REGS *) MmMapIoSpace(pa, sizeof(OMAP2420_GPIO_REGS), FALSE); if (pDevice->pGPIO4Regs == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: Failed to map GPIO4 registers\r\n")); goto cleanUp; } // Need to configure the row GPIO's as interrupt sources pDevice->irqs[0] = -1; pDevice->irqs[1] = 2; //pDevice->irqs[2] = IRQ_GPIO_0+88; // row 0 = GPIO88 //pDevice->irqs[3] = IRQ_GPIO_0+89; // row 1 = GPIO89 //pDevice->irqs[4] = IRQ_GPIO_0+124; // row 2 = GPIO124 //pDevice->irqs[5] = IRQ_GPIO_0+11; // row 3 = GPIO11 //pDevice->irqs[6] = IRQ_GPIO_0+6; // row 4 = GPIO6 // Map interrupts if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, pDevice->irqs, sizeof(pDevice->irqs), &pDevice->sysIntr, sizeof(pDevice->sysIntr), NULL )) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed map Keyboard Interrupt\r\n" )); goto cleanUp; } else DEBUGMSG(ZONE_INIT, (L"KPD_Init: sysintr = %d",pDevice->sysIntr)); // Enable wakeup from keyboard if required if (pDevice->enableWake != 0) { DEBUGMSG(ZONE_ERROR, (L"Enable keyboard as wakeup source\r\n")); if (!KernelIoControl( IOCTL_HAL_ENABLE_WAKE, &pDevice->sysIntr, sizeof(pDevice->sysIntr), NULL, 0, NULL )) { DEBUGMSG(ZONE_WARN, (L"WARN: KPD_Init: " L"Failed enable keyboard as wakeup source\r\n" )); } } // Create interrupt event pDevice->hIntrEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if (pDevice->hIntrEvent == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed create interrupt event\r\n" )); goto cleanUp; } // Initialize interrupt if (!InterruptInitialize(pDevice->sysIntr, pDevice->hIntrEvent, NULL, 0)) { DEBUGMSG (ZONE_ERROR, (L"ERROR: KPD_Init: " L"InterruptInitialize failed\r\n" )); goto cleanUp; } // Start interrupt service thread if ((pDevice->hIntrThread = CreateThread( NULL, 0, KPD_IntrThread, pDevice, 0,NULL )) == NULL) { DEBUGMSG (ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed create interrupt thread\r\n" )); goto cleanUp; } // Set thread priority CeSetThreadPriority(pDevice->hIntrThread, pDevice->priority256); // Return non-null value rc = (DWORD)pDevice; cleanUp: if (rc == 0) KPD_Deinit((DWORD)pDevice); DEBUGMSG(ZONE_FUNCTION, (L"-KPD_Init(rc = %d\r\n", rc)); return rc; }
//------------------------------------------------------------------------------ // // Function: KPD_Init // // Called by device manager to initialize device. // DWORD KPD_Init(LPCTSTR szContext, LPCVOID pBusContext) { DWORD rc = (DWORD)NULL; KeypadDevice_t *pDevice = NULL; UINT8 regval; UNREFERENCED_PARAMETER(pBusContext); DEBUGMSG(ZONE_FUNCTION, ( L"+KPD_Init(%s, 0x%08x)\r\n", szContext, pBusContext )); // Create device structure pDevice = (KeypadDevice_t *)LocalAlloc(LPTR, sizeof(KeypadDevice_t)); if (pDevice == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed allocate KDP driver structure\r\n" )); goto cleanUp; } memset(pDevice, 0, sizeof(KeypadDevice_t)); // Set cookie & initialize critical section pDevice->cookie = KPD_DEVICE_COOKIE; // Read device parameters if (GetDeviceRegistryParams( szContext, pDevice, dimof(s_deviceRegParams), s_deviceRegParams) != ERROR_SUCCESS) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed read KPD driver registry parameters\r\n" )); goto cleanUp; } // Open parent bus pDevice->hTWL = TWLOpen(); if (pDevice->hTWL == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed open TWL bus driver\r\n" )); goto cleanUp; } // Set debounce delay and enable hardware mode regval = TWL_KBD_CTRL_KBD_ON | TWL_KBD_CTRL_NRESET | TWL_KBD_CTRL_NSOFT_MODE; TWLWriteRegs(pDevice->hTWL, TWL_KEYP_CTRL_REG, ®val, sizeof(regval)); regval = 0x07 << 5; TWLWriteRegs(pDevice->hTWL, TWL_LK_PTV_REG, ®val, sizeof(regval)); regval = (UINT8)pDevice->debounceCount & 0x3F; TWLWriteRegs(pDevice->hTWL, TWL_KEY_DEB_REG, ®val, sizeof(regval)); // Create interrupt event pDevice->hIntrEventKeypad = CreateEvent(NULL, FALSE, FALSE, NULL); if (pDevice->hIntrEventKeypad == NULL) { DEBUGMSG(ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed create keypad interrupt event\r\n" )); goto cleanUp; } // Associate event with TWL KP interrupt if (!TWLInterruptInitialize(pDevice->hTWL, TWL_INTR_ITKPI, pDevice->hIntrEventKeypad)) { DEBUGMSG (ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed associate event with TWL KBD interrupt\r\n" )); goto cleanUp; } // Enable KP event if (!TWLInterruptMask(pDevice->hTWL, TWL_INTR_ITKPI, FALSE)) { DEBUGMSG (ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed associate event with TWL KBD interrupt\r\n" )); } // register to be wake-up enabled if (pDevice->enableWake != 0) { TWLWakeEnable(pDevice->hTWL, TWL_INTR_ITKPI, TRUE); } // Start keypad interrupt service thread pDevice->hIntrThreadKeypad = CreateThread( NULL, 0, KPD_IntrThread, pDevice, 0,NULL ); if (!pDevice->hIntrThreadKeypad) { DEBUGMSG (ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed create keypad interrupt thread\r\n" )); goto cleanUp; } if( pDevice->KpLedNum != -1) { // Create keypress notification event pDevice->hKeypressEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if ( pDevice->hKeypressEvent == NULL ) { DEBUGMSG (ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed to create keypress event\r\n" )); goto cleanUp; } // Start interrupt service thread pDevice->hLightThread = CreateThread( NULL, 0, KPD_LightThread, pDevice, 0,NULL ); if (!pDevice->hLightThread) { DEBUGMSG (ZONE_ERROR, (L"ERROR: KPD_Init: " L"Failed to create keypad light thread\r\n" )); goto cleanUp; } } // Return non-null value rc = (DWORD)pDevice; cleanUp: if (rc == 0) { KPD_Deinit((DWORD)pDevice); } DEBUGMSG(ZONE_FUNCTION, (L"-KPD_Init(rc = %d\r\n", rc)); return rc; }