int nvec_close(struct inode *inode, struct file *file) { NvRtClientHandle client = (NvRtClientHandle)file->private_data; if (NvRtUnregisterClient(s_RtHandle, client)) { NvDispatchCtx dctx; dctx.Rt = s_RtHandle; dctx.Client = client; dctx.PackageIdx = 0; // TODO: Enable this code for freeing up leaked handles #if 0 for (;;) { void* ptr = NvRtFreeObjRef(&dctx, NvRtObjType_NvEc_NvEcHandle, NULL); if (!ptr) break; NVRT_LEAK("NvEc", "NvEcHandle", ptr); NvEcClose(ptr); } #endif NvRtUnregisterClient(s_RtHandle, client); } return 0; }
static void __exit nvec_exit(void) { NvEcClose(s_NvEcHandle); s_NvEcHandle = NULL; misc_deregister( &nvec_dev ); NvRtDestroy(s_RtHandle); s_RtHandle = NULL; bus_unregister(&nvec_bus_type); device_unregister(&nvec_bus_dev); }
static int __init nvec_init(void) { int err = 0; NvError status = NvSuccess; NvU32 NumTypes = 1; // TODO: must have NvRtObjType_NvEc_Num instead; err = device_register(&nvec_bus_dev); if (err) return err; err = bus_register(&nvec_bus_type); if (err){ device_unregister(&nvec_bus_dev); return err; } NV_ASSERT(s_RtHandle == NULL); if (NvRtCreate(1, &NumTypes, &s_RtHandle) != NvSuccess) { printk("nvec NvRtCreate returned error\n"); bus_unregister(&nvec_bus_type); device_unregister(&nvec_bus_dev); return -ENOMEM; } status = NvEcOpen(&s_NvEcHandle, 0); if (status != NvError_Success) { printk("nvec NvEcOpen returned 0x%x\n", status); NvRtDestroy(s_RtHandle); s_RtHandle = NULL; bus_unregister(&nvec_bus_type); device_unregister(&nvec_bus_dev); return -EINVAL; } err = misc_register(&nvec_dev); if (err < 0) { if (s_RtHandle) { NvEcClose(s_NvEcHandle); s_NvEcHandle = NULL; NvRtDestroy(s_RtHandle); s_RtHandle = NULL; bus_unregister(&nvec_bus_type); device_unregister(&nvec_bus_dev); } printk("nvec failed to open\n"); } return err; }
void NvOdmCirDeInit(void) { (void)NvEcUnregisterForEvents(s_hEcEventRegistration); s_hEcEventRegistration = NULL; s_CirDeinit = NV_TRUE; NvOdmOsSemaphoreSignal(s_hCirKeyScanRecvSema); NvOdmOsSemaphoreDestroy(s_hCirKeyScanRecvSema); s_hCirKeyScanRecvSema = NULL; NvEcClose(s_NvEcHandle); s_NvEcHandle = NULL; }
NvBool NvOdmCirInit(void) /*jolen 0701*/ { NvError NvStatus = NvError_Success; /* get nvec handle */ NvStatus = NvEcOpen(&s_NvEcHandle, 0 /* instance */); if (NvStatus != NvError_Success) { goto fail; } /* create semaphore which can be used to send scan codes to the clients */ s_hCirKeyScanRecvSema = NvOdmOsSemaphoreCreate(0); if (!s_hCirKeyScanRecvSema) { goto cleanup; } /* register for CIR events */ NvStatus = NvEcRegisterForEvents( s_NvEcHandle, // nvec handle &s_hEcEventRegistration, (NvOsSemaphoreHandle)s_hCirKeyScanRecvSema, sizeof(EventTypes)/sizeof(NvEcEventType), EventTypes, // receive Ir remote scan codes 1, // currently buffer only 1 packet from ECI at a time sizeof(NvEcEvent)); if (NvStatus != NvError_Success) { goto cleanup; } /* success */ return NV_TRUE; cleanup: (void)NvEcUnregisterForEvents(s_hEcEventRegistration); s_hEcEventRegistration = NULL; NvOdmOsSemaphoreDestroy(s_hCirKeyScanRecvSema); s_hCirKeyScanRecvSema = NULL; NvEcClose(s_NvEcHandle); fail: s_NvEcHandle = NULL; return NV_FALSE; }
void NvOdmMouseDeviceClose( NvOdmMouseDeviceHandle hDevice) { if (hDevice) { // close channel to the EC NvEcClose(hDevice->hEc); hDevice->hEc = NULL; // Free the request/response structure objects NvOdmOsFree(hDevice->pRequest); hDevice->pRequest = NULL; NvOdmOsFree(hDevice->pResponse); hDevice->pResponse = NULL; NvOdmOsFree(hDevice->pEvent); hDevice->pEvent = NULL; NvOdmOsFree(hDevice); hDevice = NULL; } }
static void nvec_led_shutdown(struct platform_device *pdev) { int i; struct gpio_led_platform_data *pdata = pdev->dev.platform_data; struct nvec_led_data *leds_data; //printk("led======================>nvec_led_shutdown\n"); leds_data = platform_get_drvdata(pdev); for (i = 0; i < pdata->num_leds; i++) { nvec_blink_mode_set(&leds_data[i].cdev,BLINK_MODE_OFF); led_classdev_unregister(&leds_data[i].cdev); } kfree(leds_data); if( ghEc ) NvEcClose( ghEc ); return 0; }
static int __devexit nvec_led_remove(struct platform_device *pdev) { int i; struct gpio_led_platform_data *pdata = pdev->dev.platform_data; struct nvec_led_data *leds_data; //printk("led======================>nvec_led_remove\n"); leds_data = platform_get_drvdata(pdev); for (i = 0; i < pdata->num_leds; i++) { led_classdev_unregister(&leds_data[i].cdev); //cancel_work_sync(&leds_data[i].work); } kfree(leds_data); if( ghEc ) NvEcClose( ghEc ); return 0; }
void NvOdmKeyboardDeInit(void) { #if WAKE_FROM_KEYBOARD NvRmGpioInterruptUnregister(s_hGpioGlobal, s_hRmGlobal, hOdm->GpioIntrHandle); hOdm->GpioIntrHandle = NULL; NvRmGpioReleasePinHandles(s_hGpioGlobal, &hOdm->hPin, hOdm->PinCount); hOdm->PinCount = 0; NvOdmOsFree(hOdm); hOdm = NULL; #endif (void)NvEcUnregisterForEvents(s_hEcEventRegistration); s_hEcEventRegistration = NULL; s_KeyboardDeinit = NV_TRUE; NvOdmOsSemaphoreSignal(s_hKbcKeyScanRecvSema); NvOdmOsSemaphoreDestroy(s_hKbcKeyScanRecvSema); s_hKbcKeyScanRecvSema = NULL; NvEcClose(s_NvEcHandle); s_NvEcHandle = NULL; }
NvBool NvOdmKeyboardInit(void) { NvError NvStatus = NvError_Success; NvEcRequest Request = {0}; NvEcResponse Response = {0}; /* get nvec handle */ NvStatus = NvEcOpen(&s_NvEcHandle, 0 /* instance */); if (NvStatus != NvError_Success) { goto fail; } /* reset the EC to start the keyboard scanning */ Request.PacketType = NvEcPacketType_Request; Request.RequestType = NvEcRequestResponseType_Keyboard; Request.RequestSubtype = (NvEcRequestResponseSubtype) NvEcKeyboardSubtype_Enable; Request.NumPayloadBytes = 0; NvStatus = NvEcSendRequest(s_NvEcHandle, &Request, &Response, sizeof(Request), sizeof(Response)); if (NvStatus != NvError_Success) { goto cleanup; } /* check if command passed */ if (Response.Status != NvEcStatus_Success) { goto cleanup; } #if WAKE_FROM_KEYBOARD hOdm = NvOdmOsAlloc(sizeof(NvOdmKbdContext)); if (!hOdm) { goto cleanup; } /* Check the supported GPIOs */ hOdm->GpioPinInfo = NvOdmQueryGpioPinMap(NvOdmGpioPinGroup_EmbeddedController, 0, &hOdm->PinCount); NvRmGpioAcquirePinHandle(s_hGpioGlobal, hOdm->GpioPinInfo->Port, hOdm->GpioPinInfo->Pin, &hOdm->hPin); if (!hOdm->hPin) { goto cleanup; } /* register to receive GPIO events */ NvStatus = NvRmGpioInterruptRegister(s_hGpioGlobal, s_hRmGlobal, hOdm->hPin, (NvOsInterruptHandler)GpioInterruptHandler, NvRmGpioPinMode_InputData, hOdm, &hOdm->GpioIntrHandle, DEBOUNCE_TIME_MS); if (NvStatus != NvError_Success) { goto cleanup; } NvStatus = NvRmGpioInterruptEnable(hOdm->GpioIntrHandle); if (NvStatus != NvError_Success) { goto cleanup; } /* enable keyboard as wake up source */ Request.PacketType = NvEcPacketType_Request; Request.RequestType = NvEcRequestResponseType_Keyboard; Request.RequestSubtype = (NvEcRequestResponseSubtype) NvEcKeyboardSubtype_ConfigureWake; Request.NumPayloadBytes = 2; Request.Payload[0] = NVEC_KEYBOARD_WAKE_ENABLE_0_ACTION_ENABLE; Request.Payload[1] = NVEC_KEYBOARD_EVENT_TYPE_0_ANY_KEY_PRESS_ENABLE; NvStatus = NvEcSendRequest(s_NvEcHandle, &Request, &Response, sizeof(Request), sizeof(Response)); if (NvStatus != NvError_Success) { goto cleanup; } if (Response.Status != NvEcStatus_Success) { goto cleanup; } /* enable key reporting on wake up */ Request.PacketType = NvEcPacketType_Request; Request.RequestType = NvEcRequestResponseType_Keyboard; Request.RequestSubtype = (NvEcRequestResponseSubtype) NvEcKeyboardSubtype_ConfigureWakeKeyReport; Request.NumPayloadBytes = 1; Request.Payload[0] = NVEC_KEYBOARD_REPORT_WAKE_KEY_0_ACTION_ENABLE; NvStatus = NvEcSendRequest(s_NvEcHandle, &Request, &Response, sizeof(Request), sizeof(Response)); if (NvStatus != NvError_Success) { goto cleanup; } if (Response.Status != NvEcStatus_Success) { goto cleanup; } #endif /* create semaphore which can be used to send scan codes to the clients */ s_hKbcKeyScanRecvSema = NvOdmOsSemaphoreCreate(0); if (!s_hKbcKeyScanRecvSema) { goto cleanup; } /* register for keyboard events */ NvStatus = NvEcRegisterForEvents( s_NvEcHandle, // nvec handle &s_hEcEventRegistration, (NvOsSemaphoreHandle)s_hKbcKeyScanRecvSema, sizeof(EventTypes)/sizeof(NvEcEventType), EventTypes, // receive keyboard scan codes 1, // currently buffer only 1 packet from ECI at a time sizeof(NvEcEvent)); if (NvStatus != NvError_Success) { goto cleanup; } /* success */ return NV_TRUE; cleanup: #if WAKE_FROM_KEYBOARD NvRmGpioInterruptUnregister(s_hGpioGlobal, s_hRmGlobal, hOdm->GpioIntrHandle); hOdm->GpioIntrHandle = NULL; NvRmGpioReleasePinHandles(s_hGpioGlobal, &hOdm->hPin, hOdm->PinCount); NvOdmOsFree(hOdm); hOdm = NULL; #endif (void)NvEcUnregisterForEvents(s_hEcEventRegistration); s_hEcEventRegistration = NULL; NvOdmOsSemaphoreDestroy(s_hKbcKeyScanRecvSema); s_hKbcKeyScanRecvSema = NULL; NvEcClose(s_NvEcHandle); fail: s_NvEcHandle = NULL; return NV_FALSE; }