/* ** Function Name : MFC_Open ** ** Function Description : This function open MFC instace and return instance handle. */ DWORD MFC_Open( DWORD InitHandle, DWORD dwAccess, DWORD dwShareMode ) { MFC_HANDLE *handle; // Mutex Lock MFC_Mutex_Lock(); // Allocate & Clear MFC Handle handle = (MFC_HANDLE *) malloc(sizeof(MFC_HANDLE)); if (!handle) { RETAILMSG(1, (L"\n[MFC_Open Error] Momory Allocation Fail.\n")); MFC_Mutex_Release(); return 0; } memset(handle, 0, sizeof(MFC_HANDLE)); // Increment OpenHandle Count InterlockedIncrement(&_openhandle_count); // if (_openhandle_count == 1) // Handle for Power Control { // Save Specific Handle for Power Control gMfcHandlePower = handle; RETAILMSG(1, (L"\n[MFC_Open] Power Manager Handle Opened...\n")); } else if (_openhandle_count >= 2) // Handle for User Application { // Create MFC Instance handle->mfc_inst = MFCInst_Create(); if (!handle->mfc_inst) { RETAILMSG(1, (L"\n[MFC_Open Error] MFC Instance Creattion Fail.\n")); InterlockedDecrement(&_openhandle_count); free(handle); MFC_Mutex_Release(); return 0; } if (_openhandle_count == 2) // First Handle for User Application { // MFC HW Init Mfc_Pwr_On(); Mfc_Clk_On(); if (MFC_HW_Init() == FALSE) { Mfc_Clk_Off(); Mfc_Pwr_Off(); MFCInst_Delete(handle->mfc_inst); InterlockedDecrement(&_openhandle_count); MFC_Mutex_Release(); return 0; } Mfc_Clk_Off(); } } // Mutex Release MFC_Mutex_Release(); return (DWORD) handle; }
static int s3c_mfc_open(struct inode *inode, struct file *file) { MFC_HANDLE *handle; int ret; ////////////////// // Mutex Lock // ////////////////// MFC_Mutex_Lock(); #ifdef USE_MFC_DOMAIN_GATING if(_openhandle_count == 0) { DOMAIN_POWER_ON; } #endif /* USE_MFC_DOMAIN_GATING */ _openhandle_count++; #ifdef USE_MFC_DOMAIN_GATING CLOCK_ENABLE; #endif /* USE_MFC_DOMAIN_GATING */ if(_openhandle_count == 1) { #if defined(CONFIG_S3C6400_KDPMD) || defined(CONFIG_S3C6400_KDPMD_MODULE) kdpmd_set_event(mfc_pmdev.devid, KDPMD_DRVOPEN); kdpmd_wakeup(); kdpmd_wait(mfc_pmdev.devid); mfc_pmdev.state = DEV_RUNNING; printk("mfc_open woke up\n"); #endif ////////////////////////////////////// // 3. MFC Hardware Initialization // ////////////////////////////////////// if (MFC_HW_Init() == FALSE) { ret = -ENODEV; goto err_MFC_HW_Init; } } handle = (MFC_HANDLE *)kzalloc(sizeof(MFC_HANDLE), GFP_KERNEL); if(!handle) { LOG_MSG(LOG_ERROR, "s3c_mfc_open", "MFC open error\n"); ret = -1; goto err_kzmalloc; } ////////////////////////////// // MFC Instance creation // ////////////////////////////// handle->mfc_inst = MFCInst_Create(); if (handle->mfc_inst == NULL) { LOG_MSG(LOG_ERROR, "s3c_mfc_open", "MFC Instance allocation was failed!\r\n"); ret = -1; goto err_MFCInst_Create; } /* * MFC supports multi-instance. so each instance have own data structure * It saves file->private_data */ file->private_data = (MFC_HANDLE *)handle; #ifdef CONFIG_CPU_FREQ set_dvfs_level(0); #endif /* CONFIG_CPU_FREQ */ LOG_MSG(LOG_TRACE, "mfc_open", "MFC open success! \r\n"); ret = 0; goto no_err; err_MFCInst_Create: kfree (handle); err_kzmalloc: err_MFC_HW_Init: #ifdef USE_MFC_DOMAIN_GATING CLOCK_DISABLE; #endif /* USE_MFC_DOMAIN_GATING */ _openhandle_count --; #ifdef USE_MFC_DOMAIN_GATING if(_openhandle_count == 0) DOMAIN_POWER_OFF; #endif /* USE_MFC_DOMAIN_GATING */ no_err: MFC_Mutex_Release(); return ret; }