static void nvec_battery_remove(struct nvec_device *pdev) { unsigned int i = 0; if (batt_dev) { batt_dev->exitThread = NV_TRUE; if (batt_dev->hOdmSemaphore) { NvOsSemaphoreSignal(batt_dev->hOdmSemaphore); NvOsSemaphoreDestroy(batt_dev->hOdmSemaphore); batt_dev->hOdmSemaphore = NULL; } if (batt_dev->hBattEventThread) { NvOsThreadJoin(batt_dev->hBattEventThread); } if (batt_dev->hOdmBattDev) { device_remove_file(&pdev->dev, &tegra_battery_attr); device_remove_file(&pdev->dev, &tegra_battery_version); //Daniel 20100823, put ec version to fs del_timer_sync(&(batt_dev->battery_poll_timer)); NvOdmBatteryDeviceClose(batt_dev->hOdmBattDev); batt_dev->hOdmBattDev = NULL; for (i = 0; i < ARRAY_SIZE(tegra_power_supplies); i++) { power_supply_unregister(&tegra_power_supplies[i]); } } kfree(batt_dev); batt_dev = NULL; } }
static int tegra_battery_remove(struct platform_device *pdev) { int i; for (i = 0; i < ARRAY_SIZE(tegra_supplies); i++) { power_supply_unregister(&tegra_supplies[i]); } if (batt_dev) { device_remove_file(&pdev->dev, &tegra_battery_attr); del_timer_sync(&(batt_dev->battery_poll_timer)); // this is froyo 10.7.2 source but build ERROR [START] #if 0 if (batt_dev->hOdmBattDev) { NvOdmBatteryDeviceClose(batt_dev->hOdmBattDev); batt_dev->hOdmBattDev = NULL; } #endif // this is froyo 10.7.2 source but build ERROR [END] kfree(batt_dev); batt_dev = NULL; } return 0; }
NvBool NvOdmBatteryDeviceOpen(NvOdmBatteryDeviceHandle *hDevice, NvOdmOsSemaphoreHandle *hOdmSemaphore) { NvOdmBatteryDevice *pBattContext = NULL; NvU32 i; NvError NvStatus = NvError_Success; NvU32 PinState; pBattContext = NvOdmOsAlloc(sizeof(NvOdmBatteryDevice)); if (!pBattContext) { NvOsDebugPrintf(("NvOdmOsAlloc failed to allocate pBattContext.")); return NV_FALSE; } NvOdmOsMemset(pBattContext, 0, sizeof(NvOdmBatteryDevice)); NvStatus = NvRmOpen(&pBattContext->hRm, 0); if (NvStatus != NvError_Success) goto Cleanup; NvStatus = NvRmGpioOpen(pBattContext->hRm, &pBattContext->hGpio); if (NvStatus != NvError_Success) goto Cleanup; pBattContext->pGpioPinInfo = NvOdmQueryGpioPinMap( NvOdmGpioPinGroup_Battery, 0, &pBattContext->PinCount); if (pBattContext->pGpioPinInfo == NULL) { goto Cleanup; } for (i = 0; i < pBattContext->PinCount; i++ ) { /*Need the pin 1 to be set to Output for charging of the battery. */ if (i == 1) { NvRmGpioAcquirePinHandle( pBattContext->hGpio, pBattContext->pGpioPinInfo[i].Port, pBattContext->pGpioPinInfo[i].Pin, &pBattContext->hPin); if (!pBattContext->hPin) { goto Cleanup; } NvRmGpioConfigPins(pBattContext->hGpio, &pBattContext->hPin, 1, NvRmGpioPinMode_Output); PinState = NvRmGpioPinState_Low; NvRmGpioWritePins(pBattContext->hGpio, &pBattContext->hPin, &PinState,1); } } *hDevice = pBattContext; return NV_TRUE; Cleanup: NvOdmBatteryDeviceClose(pBattContext); return NV_FALSE; }
static int tegra_battery_remove(struct platform_device *pdev) { int i; for (i = 0; i < ARRAY_SIZE(tegra_supplies); i++) { power_supply_unregister(&tegra_supplies[i]); } if (batt_dev) { device_remove_file(&pdev->dev, &tegra_battery_attr); del_timer_sync(&(batt_dev->battery_poll_timer)); if (batt_dev->hOdmBattDev) { NvOdmBatteryDeviceClose(batt_dev->hOdmBattDev); batt_dev->hOdmBattDev = NULL; } kfree(batt_dev); batt_dev = NULL; } return 0; }
static void nvec_battery_remove(struct nvec_device *pdev) { unsigned int i = 0; if (batt_dev) { batt_dev->exitThread = NV_TRUE; if (batt_dev->hOdmSemaphore) { NvOsSemaphoreSignal(batt_dev->hOdmSemaphore); NvOsSemaphoreDestroy(batt_dev->hOdmSemaphore); batt_dev->hOdmSemaphore = NULL; } if (batt_dev->hBattEventThread) { NvOsThreadJoin(batt_dev->hBattEventThread); } if (batt_dev->hBattEventMutex) { NvOsMutexDestroy(batt_dev->hBattEventMutex); batt_dev->hBattEventMutex = NULL; } if (batt_dev->hOdmBattDev) { device_remove_file(&pdev->dev, &tegra_battery_attr); NvOdmBatteryDeviceClose(batt_dev->hOdmBattDev); batt_dev->hOdmBattDev = NULL; for (i = 0; i < ARRAY_SIZE(tegra_power_supplies); i++) { power_supply_unregister(&tegra_power_supplies[i]); } } kfree(batt_dev); batt_dev = NULL; } }
static int nvec_battery_probe(struct nvec_device *pdev) { int i, rc; NvError ErrorStatus = NvSuccess; NvBool result = NV_FALSE; batt_dev = kzalloc(sizeof(struct tegra_battery_dev), GFP_KERNEL); if (!batt_dev) { pr_err("nvec_battery_probe:NOMEM\n"); return -ENOMEM; } ErrorStatus = NvOsMutexCreate(&batt_dev->hBattEventMutex); if (NvSuccess != ErrorStatus) { pr_err("NvOsMutexCreate Failed!\n"); goto Cleanup; } ErrorStatus = NvOsSemaphoreCreate(&batt_dev->hOdmSemaphore, 0); if (NvSuccess != ErrorStatus) { pr_err("NvOsSemaphoreCreate Failed!\n"); goto Cleanup; } /*Henry++ adjust thread to be createn at last batt_dev->exitThread = NV_FALSE; batt_dev->inSuspend = NV_FALSE; ErrorStatus = NvOsThreadCreate(NvBatteryEventHandlerThread, batt_dev, &(batt_dev->hBattEventThread)); if (NvSuccess != ErrorStatus) { pr_err("NvOsThreadCreate FAILED\n"); goto Cleanup; } */ //Henry add retry when fail **** for(i=0;i<BATTERY_RETRY_TIMES;i++){ result = NvOdmBatteryDeviceOpen(&(batt_dev->hOdmBattDev), (NvOdmOsSemaphoreHandle *)&batt_dev->hOdmSemaphore); if (!result || !batt_dev->hOdmBattDev) { pr_err("NvOdmBatteryDeviceOpen FAILED,retry i=%i\n",i); NvOsWaitUS(10000); continue; } else{ break; } } if(i==BATTERY_RETRY_TIMES){ pr_err("NvOdmBatteryDeviceOpen FAILED\n"); goto Cleanup; } //****************************** for (i = 0; i < ARRAY_SIZE(tegra_power_supplies); i++) { if (power_supply_register(&pdev->dev, &tegra_power_supplies[i])) pr_err("Failed to register power supply\n"); } batt_dev->batt_status_poll_period = NVBATTERY_POLLING_INTERVAL; rc = device_create_file(&pdev->dev, &tegra_battery_attr); if (rc) { for (i = 0; i < ARRAY_SIZE(tegra_power_supplies); i++) { power_supply_unregister(&tegra_power_supplies[i]); } pr_err("nvec_battery_probe:device_create_file FAILED"); goto Cleanup; } //Henry++ adjust thread to be createn at last batt_dev->exitThread = NV_FALSE; batt_dev->inSuspend = NV_FALSE; ErrorStatus = NvOsThreadCreate(NvBatteryEventHandlerThread, batt_dev, &(batt_dev->hBattEventThread)); if (NvSuccess != ErrorStatus) { pr_err("NvOsThreadCreate FAILED\n"); goto Cleanup; } return 0; Cleanup: batt_dev->exitThread = NV_TRUE; if (batt_dev->hOdmSemaphore) { NvOsSemaphoreSignal(batt_dev->hOdmSemaphore); NvOsSemaphoreDestroy(batt_dev->hOdmSemaphore); batt_dev->hOdmSemaphore = NULL; } if (batt_dev->hBattEventThread) { NvOsThreadJoin(batt_dev->hBattEventThread); } if (batt_dev->hBattEventMutex) { NvOsMutexDestroy(batt_dev->hBattEventMutex); batt_dev->hBattEventMutex = NULL; } if (batt_dev->hOdmBattDev) { NvOdmBatteryDeviceClose(batt_dev->hOdmBattDev); batt_dev->hOdmBattDev = NULL; } kfree(batt_dev); batt_dev = NULL; //return -1; return 0; //henry++ workaround system can't enter suspend }
static int nvec_battery_probe(struct nvec_device *pdev) { int i, rc; NvError ErrorStatus = NvSuccess; NvBool result = NV_FALSE; batt_dev = kzalloc(sizeof(struct tegra_battery_dev), GFP_KERNEL); if (!batt_dev) { pr_err("nvec_battery_probe:NOMEM\n"); return -ENOMEM; } ErrorStatus = NvOsSemaphoreCreate(&batt_dev->hOdmSemaphore, 0); if (NvSuccess != ErrorStatus) { pr_err("NvOsSemaphoreCreate Failed!\n"); goto Cleanup; } batt_dev->exitThread = NV_FALSE; ErrorStatus = NvOsThreadCreate(NvBatteryEventHandlerThread, batt_dev, &(batt_dev->hBattEventThread)); if (NvSuccess != ErrorStatus) { pr_err("NvOsThreadCreate FAILED\n"); goto Cleanup; } result = NvOdmBatteryDeviceOpen(&(batt_dev->hOdmBattDev), (NvOdmOsSemaphoreHandle *)&batt_dev->hOdmSemaphore, &(batt_dev->ec_version)); //Daniel 20100823, put ec version to fs. if (!result || !batt_dev->hOdmBattDev) { pr_err("NvOdmBatteryDeviceOpen FAILED\n"); goto Cleanup; } for (i = 0; i < ARRAY_SIZE(tegra_power_supplies); i++) { if (power_supply_register(&pdev->dev, &tegra_power_supplies[i])) pr_err("Failed to register power supply\n"); } batt_dev->batt_status_poll_period = NVBATTERY_POLLING_INTERVAL_MILLISECS; setup_timer(&(batt_dev->battery_poll_timer), tegra_battery_poll_timer_func, 0); mod_timer(&(batt_dev->battery_poll_timer), jiffies + msecs_to_jiffies(batt_dev->batt_status_poll_period)); rc = device_create_file(&pdev->dev, &tegra_battery_attr); rc = device_create_file(&pdev->dev, &tegra_battery_version); //Daniel 20100823, put ec version to fs if (rc) { for (i = 0; i < ARRAY_SIZE(tegra_power_supplies); i++) { power_supply_unregister(&tegra_power_supplies[i]); } del_timer_sync(&(batt_dev->battery_poll_timer)); pr_err("nvec_battery_probe:device_create_file FAILED"); goto Cleanup; } return 0; Cleanup: batt_dev->exitThread = NV_TRUE; if (batt_dev->hOdmSemaphore) { NvOsSemaphoreSignal(batt_dev->hOdmSemaphore); NvOsSemaphoreDestroy(batt_dev->hOdmSemaphore); batt_dev->hOdmSemaphore = NULL; } if (batt_dev->hBattEventThread) { NvOsThreadJoin(batt_dev->hBattEventThread); } if (batt_dev->hOdmBattDev) { NvOdmBatteryDeviceClose(batt_dev->hOdmBattDev); batt_dev->hOdmBattDev = NULL; } kfree(batt_dev); batt_dev = NULL; return -1; }