//----------------------------------------------------------------------------
static void CamPipeMgr_UpdatePipeLockTable(CAM_PIPE_MGR_SCEN_SW_ENUM ScenSw)
{
    MUINT32 i;
    //
    for(i=0;i<CAM_PIPE_MGR_SCEN_HW_AMOUNT;i++)
    {
        CamPipeMgr.PipeLockTable[i] = CamPipeMgr_GtePipeLockTable(ScenSw,i);
    }
}
//-----------------------------------------------------------------------------
static long CamPipeMgr_Ioctl(
    struct file*    pFile,
    unsigned int    Cmd,
    unsigned long   Param)
{
    MINT32  Ret = 0;
    MUINT32 Sec = 0,USec = 0;
    pid_t   Pid;
    pid_t   Tgid;
    char    ProcName[TASK_COMM_LEN];
    CAM_PIPE_MGR_LOCK_STRUCT    Lock;
    CAM_PIPE_MGR_UNLOCK_STRUCT  Unlock;
    CAM_PIPE_MGR_MODE_STRUCT    Mode;
    CAM_PIPE_MGR_ENABLE_STRUCT  Enable;
    CAM_PIPE_MGR_DISABLE_STRUCT Disable;
    CAM_PIPE_MGR_PROC_STRUCT*   pProc = (CAM_PIPE_MGR_PROC_STRUCT*)pFile->private_data;
    CAM_PIPE_MGR_STATUS_ENUM    Status;
    //
    CamPipeMgr_GetTime(&Sec, &USec);
    /*
    LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
            current->comm,
            current->pid,
            current->tgid,
            Sec,
            USec);
    */
    if(pFile->private_data == NULL)
    {
        LOG_ERR("private_data is NULL");
        Ret = -EFAULT;
        goto EXIT;
    }
    //
    switch(Cmd)
    {
        case CAM_PIPE_MGR_LOCK:
        {
            if(copy_from_user(&Lock, (void*)Param, sizeof(CAM_PIPE_MGR_LOCK_STRUCT)) == 0)
            {
                if((Lock.PipeMask & CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]) != Lock.PipeMask)
                {
                    if( (Lock.PipeMask & CAM_PIPE_MGR_PIPE_MASK_CDP_CONCUR) ||
                        (Lock.PipeMask & CAM_PIPE_MGR_PIPE_MASK_CDP_LINK))
                    {
                        LOG_WRN("LOCK:Sw(%d),Hw(%d),LPM(0x%08lX),PLT(0x%08lX) fail",
                                CamPipeMgr.Mode.ScenSw,
                                CamPipeMgr.Mode.ScenHw,
                                Lock.PipeMask,
                                CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                    }
                    else
                    {
                        LOG_ERR("LOCK:Sw(%d),Hw(%d),LPM(0x%08lX),PLT(0x%08lX) fail",
                                CamPipeMgr.Mode.ScenSw,
                                CamPipeMgr.Mode.ScenHw,
                                Lock.PipeMask,
                                CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                    }
                    Ret = -EFAULT;
                }
                else
                {
                    CamPipeMgr_SpinLock();
                    Status = CamPipeMgr_LockPipe(&Lock);
                    if(Status == CAM_PIPE_MGR_STATUS_OK)
                    {
                        pProc->PipeMask |= Lock.PipeMask;
                        if(pProc->Tgid == 0)
                        {
                            pProc->Pid = current->pid;
                            pProc->Tgid = current->tgid;
                            strcpy(pProc->ProcName,current->comm);
                            CamPipeMgr_SpinUnlock();
                            if(CamPipeMgr.LogMask & Lock.PipeMask)
                            {
                                LOG_MSG("LOCK:Sw(%d),Hw(%d),LPM(0x%08lX),PLT(0x%08lX) OK",
                                        CamPipeMgr.Mode.ScenSw,
                                        CamPipeMgr.Mode.ScenHw,
                                        Lock.PipeMask,
                                        CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                                LOG_MSG("LOCK:Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%08lX)",
                                        pProc->ProcName,
                                        pProc->Pid,
                                        pProc->Tgid,
                                        pProc->PipeMask);
                            }
                        }
                        else
                        {
                            CamPipeMgr_SpinUnlock();
                            if(pProc->Tgid != current->tgid)
                            {
                                LOG_ERR("LOCK:Tgid is inconsistent");
                                Ret = -EFAULT;
                            }
                        }
                    }
                    else
                    {
                        CamPipeMgr_SpinUnlock();
                        if( (CamPipeMgr.LogMask & Lock.PipeMask) ||
                            (CamPipeMgr.Mode.ScenSw == CAM_PIPE_MGR_SCEN_SW_NONE))
                        {
                            if( (Lock.PipeMask & CAM_PIPE_MGR_PIPE_MASK_CDP_CONCUR) ||
                                (Lock.PipeMask & CAM_PIPE_MGR_PIPE_MASK_CDP_LINK))
                            {
                                LOG_WRN("LOCK:Sw(%d),Hw(%d),LPM(0x%08lX),PLT(0x%08lX) fail,Status(%d)",
                                        CamPipeMgr.Mode.ScenSw,
                                        CamPipeMgr.Mode.ScenHw,
                                        Lock.PipeMask,
                                        CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw],
                                        Status);
                            }
                            else
                            {
                                LOG_ERR("LOCK:Sw(%d),Hw(%d),LPM(0x%08lX),PLT(0x%08lX) fail,Status(%d)",
                                        CamPipeMgr.Mode.ScenSw,
                                        CamPipeMgr.Mode.ScenHw,
                                        Lock.PipeMask,
                                        CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw],
                                        Status);
                            }
                        }
                        Ret = -EFAULT;
                    }
                }
            }
            else
            {
                LOG_ERR("LOCK:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_UNLOCK:
        {
            if(copy_from_user(&Unlock, (void*)Param, sizeof(CAM_PIPE_MGR_UNLOCK_STRUCT)) == 0)
            {
                CamPipeMgr_SpinLock();
                if(pProc->PipeMask & Unlock.PipeMask)
                {
                    CamPipeMgr_UnlockPipe(&Unlock);
                    //Store info before clear.
                    Pid = pProc->Pid;
                    Tgid = pProc->Tgid;
                    strcpy(ProcName,pProc->ProcName);
                    //
                    pProc->PipeMask &= (~Unlock.PipeMask);
                    if(pProc->PipeMask == 0)
                    {
                        pProc->Pid = 0;
                        pProc->Tgid = 0;
                        strcpy(pProc->ProcName,CAM_PIPE_MGR_PROC_NAME);
                    }
                    CamPipeMgr_SpinUnlock();
                    if(CamPipeMgr.LogMask & Unlock.PipeMask)
                    {
                        LOG_MSG("UNLOCK:Sw(%d),Hw(%d),UPM(0x%08lX),PLT(0x%08lX) OK",
                                CamPipeMgr.Mode.ScenSw,
                                CamPipeMgr.Mode.ScenHw,
                                Unlock.PipeMask,
                                CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                        LOG_MSG("UNLOCK:Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%08lX)",
                                ProcName,
                                Pid,
                                Tgid,
                                pProc->PipeMask);
                    }
                }
                else
                {
                    CamPipeMgr_SpinUnlock();
                    if( (CamPipeMgr.LogMask & Unlock.PipeMask) ||
                        (CamPipeMgr.Mode.ScenSw == CAM_PIPE_MGR_SCEN_SW_NONE))
                    {
                        LOG_ERR("UNLOCK:Sw(%d),Hw(%d),UPM(0x%08lX),PLT(0x%08lX) fail, it was not locked before",
                                CamPipeMgr.Mode.ScenSw,
                                CamPipeMgr.Mode.ScenHw,
                                Unlock.PipeMask,
                                CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                    }
                    Ret = -EFAULT;
                }
            }
            else
            {
                LOG_ERR("UNLOCK:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_DUMP:
        {
            CamPipeMgr_DumpPipeInfo();
            break;
        }
        //
        case CAM_PIPE_MGR_SET_MODE:
        {
            if(copy_from_user(&Mode, (void*)Param, sizeof(CAM_PIPE_MGR_MODE_STRUCT)) == 0)
            {
                LOG_MSG("SET_MODE:Sw(%d),Hw(%d)",Mode.ScenSw,Mode.ScenHw);
                if((CamPipeMgr.PipeMask | CamPipeMgr.PipeLockTable[Mode.ScenHw]) ^ CamPipeMgr.PipeLockTable[Mode.ScenHw])
                {
                    LOG_ERR("SET_MODE:PM(0x%08lX),PLT(0x%08lX), some pipe should be unlock",
                            CamPipeMgr.PipeMask,
                            CamPipeMgr.PipeLockTable[Mode.ScenHw]);
                    Ret = -EFAULT;
                }
                //
                CamPipeMgr_SpinLock();
                memcpy(
                    &(CamPipeMgr.Mode),
                    &Mode,
                    sizeof(CAM_PIPE_MGR_MODE_STRUCT));
                CamPipeMgr_UpdatePipeLockTable(CamPipeMgr.Mode.ScenSw);
                CamPipeMgr_SpinUnlock();
                LOG_MSG("SET_MODE:done");

            }
            else
            {
                LOG_ERR("SET_MODE:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_GET_MODE:
        {
            if(copy_to_user((void*)Param, &(CamPipeMgr.Mode),  sizeof(CAM_PIPE_MGR_MODE_STRUCT)) == 0)
            {
                //do nothing.
            }
            else
            {
                LOG_ERR("GET_MODE:copy_to_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_ENABLE_PIPE:
        {
            if(copy_from_user(&Enable, (void*)Param, sizeof(CAM_PIPE_MGR_ENABLE_STRUCT)) == 0)
            {
                LOG_MSG("ENABLE_PIPE:Sw(%d),Hw(%d):EPM(0x%08lX),PLT(0x%08lX)",
                        CamPipeMgr.Mode.ScenSw,
                        CamPipeMgr.Mode.ScenHw,
                        Enable.PipeMask,
                        CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw));
                if((Enable.PipeMask & CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw)) != Enable.PipeMask)
                {
                    LOG_ERR("ENABLE_PIPE:Some pipe are not available");
                    Ret = -EFAULT;
                }
                else
                {
                    CamPipeMgr_SpinLock();
                    CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw] |= Enable.PipeMask;
                    CamPipeMgr_SpinUnlock();
                }
            }
            else
            {
                LOG_ERR("ENABLE_PIPE:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_DISABLE_PIPE:
        {
            if(copy_from_user(&Disable, (void*)Param, sizeof(CAM_PIPE_MGR_DISABLE_STRUCT)) == 0)
            {
                LOG_MSG("DISABLE_PIPE:Sw(%d),Hw(%d):DPM(0x%08lX),PLT(0x%08lX)",
                        CamPipeMgr.Mode.ScenSw,
                        CamPipeMgr.Mode.ScenHw,
                        Disable.PipeMask,
                        CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw));
                if((Disable.PipeMask & CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw)) != Disable.PipeMask)
                {
                    LOG_ERR("DISABLE_PIPE:Some pipe are not available");
                    Ret = -EFAULT;
                }
                else
                {
                    CamPipeMgr_SpinLock();
                    CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw] &= (~Disable.PipeMask);
                    CamPipeMgr_SpinUnlock();
                }
            }
            else
            {
                LOG_ERR("DISABLE_PIPE:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        default:
        {
            LOG_ERR("Unknown cmd");
            Ret = -EFAULT;
            break;
        }
    }
    //
    EXIT:
    if(Ret != 0)
    {
        if( (CamPipeMgr.LogMask & Lock.PipeMask) ||
            (CamPipeMgr.Mode.ScenSw == CAM_PIPE_MGR_SCEN_SW_NONE))
        {
            LOG_ERR("Fail");
            LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
                    current->comm,
                    current->pid,
                    current->tgid,
                    Sec,
                    USec);
            if(pFile->private_data != NULL)
            {
                LOG_ERR("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%08lX),Time(%ld.%06ld)",
                        pProc->ProcName,
                        pProc->Pid,
                        pProc->Tgid,
                        pProc->PipeMask,
                        Sec,
                        USec);
            }
            CamPipeMgr_DumpPipeInfo();
        }
    }
    return Ret;
}
//-----------------------------------------------------------------------------
static long CamPipeMgr_Ioctl(
    struct file*    pFile,
    unsigned int    Cmd,
    unsigned long   Param)
{
    LOG_MSG("+ tt Cmd(0x%x)/(0x%lx)",Cmd,(unsigned long)CAM_PIPE_MGR_VENCPLL_CTRL);
    MINT32  Ret = 0;
    MUINT32 Sec = 0,USec = 0;
    pid_t   Pid;
    pid_t   Tgid;
    char    ProcName[TASK_COMM_LEN];
    CAM_PIPE_MGR_LOCK_STRUCT    Lock;
    CAM_PIPE_MGR_UNLOCK_STRUCT  Unlock;
    CAM_PIPE_MGR_MODE_STRUCT    Mode;
    CAM_PIPE_MGR_ENABLE_STRUCT  Enable;
    CAM_PIPE_MGR_DISABLE_STRUCT Disable;
    CAM_PIPE_MGR_PROC_STRUCT*   pProc = (CAM_PIPE_MGR_PROC_STRUCT*)pFile->private_data;
    CAM_PIPE_MGR_STATUS_ENUM    Status;
    CAM_PIPE_MGR_CMD_VECNPLL_CTRL_ENUM vencpll_ctrlEnum=CAM_PIPE_MGR_CMD_VECNPLL_CTRL_SET_LOW;
    int err=0;
    //
    CamPipeMgr_GetTime(&Sec, &USec);
    /*
    LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
            current->comm,
            current->pid,
            current->tgid,
            Sec,
            USec);
    */
    if(pFile->private_data == NULL)
    {
        LOG_ERR("private_data is NULL");
        Ret = -EFAULT;
        goto EXIT;
    }
    //
    switch(Cmd)
    {
        case CAM_PIPE_MGR_LOCK:
        {
            if(copy_from_user(&Lock, (void*)Param, sizeof(CAM_PIPE_MGR_LOCK_STRUCT)) == 0)
            {
                if((Lock.PipeMask & CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]) != Lock.PipeMask)
                {
                    LOG_ERR("LOCK:Sw(%d),Hw(%d),LPM(0x%X),PLT(0x%lX) fail",
                            CamPipeMgr.Mode.ScenSw,
                            CamPipeMgr.Mode.ScenHw,
                            Lock.PipeMask,
                            (unsigned long)CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                    Ret = -EFAULT;
                }
                else
                {
                    CamPipeMgr_SpinLock();
                    Status = CamPipeMgr_LockPipe(&Lock);
                    if(Status == CAM_PIPE_MGR_STATUS_OK)
                    {
                        pProc->PipeMask |= Lock.PipeMask;
                        if(pProc->Tgid == 0)
                        {
                            pProc->Pid = current->pid;
                            pProc->Tgid = current->tgid;
                            strcpy(pProc->ProcName,current->comm);
                            CamPipeMgr_SpinUnlock();
                            if(CamPipeMgr.LogMask & Lock.PipeMask)
                            {
                                LOG_MSG("LOCK:Sw(%d),Hw(%d),LPM(0x%X),PLT(0x%lX) OK",
                                        CamPipeMgr.Mode.ScenSw,
                                        CamPipeMgr.Mode.ScenHw,
                                        Lock.PipeMask,
                                        (unsigned long)CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                                LOG_MSG("LOCK:Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX)",
                                        pProc->ProcName,
                                        pProc->Pid,
                                        pProc->Tgid,
                                        pProc->PipeMask);
                            }
                        }
                        else
                        {
                            CamPipeMgr_SpinUnlock();
                            if(pProc->Tgid != current->tgid)
                            {
                                LOG_ERR("LOCK:Tgid is inconsistent");
                                Ret = -EFAULT;
                            }
                        }
                    }
                    else
                    {
                        CamPipeMgr_SpinUnlock();
                        if( (CamPipeMgr.LogMask & Lock.PipeMask) ||
                            (CamPipeMgr.Mode.ScenSw == CAM_PIPE_MGR_SCEN_SW_NONE))
                        {
                            LOG_ERR("LOCK:Sw(%d),Hw(%d),LPM(0x%X),PLT(0x%lX) fail,Status(%d)",
                                    CamPipeMgr.Mode.ScenSw,
                                    CamPipeMgr.Mode.ScenHw,
                                    Lock.PipeMask,
                                    (unsigned long)CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw],
                                    Status);
                        }
                        Ret = -EFAULT;
                    }
                }
            }
            else
            {
                LOG_ERR("LOCK:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_UNLOCK:
        {
            if(copy_from_user(&Unlock, (void*)Param, sizeof(CAM_PIPE_MGR_UNLOCK_STRUCT)) == 0)
            {
                CamPipeMgr_SpinLock();
                if(pProc->PipeMask & Unlock.PipeMask)
                {
                    CamPipeMgr_UnlockPipe(&Unlock);
                    //Store info before clear.
                    Pid = pProc->Pid;
                    Tgid = pProc->Tgid;
                    strcpy(ProcName,pProc->ProcName);
                    //
                    pProc->PipeMask &= (~Unlock.PipeMask);
                    if(pProc->PipeMask == 0)
                    {
                        pProc->Pid = 0;
                        pProc->Tgid = 0;
                        strcpy(pProc->ProcName,CAM_PIPE_MGR_PROC_NAME);
                    }
                    CamPipeMgr_SpinUnlock();
                    if(CamPipeMgr.LogMask & Unlock.PipeMask)
                    {
                        LOG_MSG("UNLOCK:Sw(%d),Hw(%d),UPM(0x%X),PLT(0x%lX) OK",
                                CamPipeMgr.Mode.ScenSw,
                                CamPipeMgr.Mode.ScenHw,
                                Unlock.PipeMask,
                                (unsigned long)CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                        LOG_MSG("UNLOCK:Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX)",
                                ProcName,
                                Pid,
                                Tgid,
                                pProc->PipeMask);
                    }
                }
                else
                {
                    CamPipeMgr_SpinUnlock();
                    if( (CamPipeMgr.LogMask & Unlock.PipeMask) ||
                        (CamPipeMgr.Mode.ScenSw == CAM_PIPE_MGR_SCEN_SW_NONE))
                    {
                        LOG_ERR("UNLOCK:Sw(%d),Hw(%d),UPM(0x%X),PLT(0x%lX) fail, it was not locked before",
                                CamPipeMgr.Mode.ScenSw,
                                CamPipeMgr.Mode.ScenHw,
                                Unlock.PipeMask,
                                (unsigned long)CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw]);
                    }
                    Ret = -EFAULT;
                }
            }
            else
            {
                LOG_ERR("UNLOCK:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_DUMP:
        {
            CamPipeMgr_DumpPipeInfo();
            break;
        }
        //
        case CAM_PIPE_MGR_SET_MODE:
        {
            if(copy_from_user(&Mode, (void*)Param, sizeof(CAM_PIPE_MGR_MODE_STRUCT)) == 0)
            {
                if((Mode.ScenHw > CAM_PIPE_MGR_SCEN_HW_VSS) || (Mode.ScenHw<0))
                {
                    LOG_ERR("ScenHw(%d) > max(%d)",Mode.ScenHw,CAM_PIPE_MGR_SCEN_HW_VSS);
                    Ret = -EFAULT;
                    goto EXIT;
                }
                if((Mode.ScenSw > CAM_PIPE_MGR_SCEN_SW_N3D) || (Mode.ScenSw<0))
                {
                    LOG_ERR("ScenSw(%d) > max(%d)",Mode.ScenSw,CAM_PIPE_MGR_SCEN_SW_N3D);
                    Ret = -EFAULT;
                    goto EXIT;
                }
                if((Mode.Dev > CAM_PIPE_MGR_DEV_VT) || (Mode.Dev<0))
                {
                    LOG_ERR("Dev(%d) > max(%d)",Mode.Dev,CAM_PIPE_MGR_DEV_VT);
                    Ret = -EFAULT;
                    goto EXIT;
                }
                //
                LOG_MSG("SET_MODE:Sw(%d),Hw(%d)",Mode.ScenSw,Mode.ScenHw);
                if((CamPipeMgr.PipeMask | CamPipeMgr.PipeLockTable[Mode.ScenHw]) ^ CamPipeMgr.PipeLockTable[Mode.ScenHw])
                {
                    LOG_ERR("SET_MODE:PM(0x%lX),PLT(0x%lX), some pipe should be unlock",
                            CamPipeMgr.PipeMask,
                            CamPipeMgr.PipeLockTable[Mode.ScenHw]);
                    Ret = -EFAULT;
                }
                //
                CamPipeMgr_SpinLock();
                memcpy(
                    &(CamPipeMgr.Mode),
                    &Mode,
                    sizeof(CAM_PIPE_MGR_MODE_STRUCT));
                CamPipeMgr_UpdatePipeLockTable(CamPipeMgr.Mode.ScenSw);
                CamPipeMgr_SpinUnlock();
                LOG_MSG("SET_MODE:done");

            }
            else
            {
                LOG_ERR("SET_MODE:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_GET_MODE:
        {
            if((CamPipeMgr.Mode.ScenHw > CAM_PIPE_MGR_SCEN_HW_VSS) ||(CamPipeMgr.Mode.ScenHw <0))
            {
                LOG_ERR("ScenHw(%d) > max(%d)",CamPipeMgr.Mode.ScenHw,CAM_PIPE_MGR_SCEN_HW_VSS);
                Ret = -EFAULT;
                goto EXIT;
            }
            if((CamPipeMgr.Mode.ScenSw > CAM_PIPE_MGR_SCEN_SW_N3D) || (CamPipeMgr.Mode.ScenSw<0))
            {
                LOG_ERR("ScenSw(%d) > max(%d)",CamPipeMgr.Mode.ScenSw,CAM_PIPE_MGR_SCEN_SW_N3D);
                Ret = -EFAULT;
                goto EXIT;
            }
            if((CamPipeMgr.Mode.Dev > CAM_PIPE_MGR_DEV_VT) || (CamPipeMgr.Mode.Dev<0))
            {
                LOG_ERR("Dev(%d) > max(%d)",CamPipeMgr.Mode.Dev,CAM_PIPE_MGR_DEV_VT);
                Ret = -EFAULT;
                goto EXIT;
            }
            //
            if(copy_to_user((void*)Param, &(CamPipeMgr.Mode),  sizeof(CAM_PIPE_MGR_MODE_STRUCT)) == 0)
            {
                //do nothing.
            }
            else
            {
                LOG_ERR("GET_MODE:copy_to_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_ENABLE_PIPE:
        {
            if(copy_from_user(&Enable, (void*)Param, sizeof(CAM_PIPE_MGR_ENABLE_STRUCT)) == 0)
            {
                LOG_MSG("ENABLE_PIPE:Sw(%d),Hw(%d):EPM(0x%X),PLT(0x%lX)",
                        CamPipeMgr.Mode.ScenSw,
                        CamPipeMgr.Mode.ScenHw,
                        Enable.PipeMask,
                        (unsigned long)CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw));
                if((Enable.PipeMask & CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw)) != Enable.PipeMask)
                {
                    LOG_ERR("ENABLE_PIPE:Some pipe are not available");
                    Ret = -EFAULT;
                }
                else
                {
                    CamPipeMgr_SpinLock();
                    CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw] |= Enable.PipeMask;
                    CamPipeMgr_SpinUnlock();
                }
            }
            else
            {
                LOG_ERR("ENABLE_PIPE:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_DISABLE_PIPE:
        {
            if(copy_from_user(&Disable, (void*)Param, sizeof(CAM_PIPE_MGR_DISABLE_STRUCT)) == 0)
            {
                LOG_MSG("DISABLE_PIPE:Sw(%d),Hw(%d):DPM(0x%X),PLT(0x%lX)",
                        CamPipeMgr.Mode.ScenSw,
                        CamPipeMgr.Mode.ScenHw,
                        Disable.PipeMask,
                        (unsigned long)CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw));
                if((Disable.PipeMask & CamPipeMgr_GtePipeLockTable(CamPipeMgr.Mode.ScenSw,CamPipeMgr.Mode.ScenHw)) != Disable.PipeMask)
                {
                    LOG_ERR("DISABLE_PIPE:Some pipe are not available");
                    Ret = -EFAULT;
                }
                else
                {
                    CamPipeMgr_SpinLock();
                    CamPipeMgr.PipeLockTable[CamPipeMgr.Mode.ScenHw] &= (~Disable.PipeMask);
                    CamPipeMgr_SpinUnlock();
                }
            }
            else
            {
                LOG_ERR("DISABLE_PIPE:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        case CAM_PIPE_MGR_VENCPLL_CTRL:
        {
            if(copy_from_user(&vencpll_ctrlEnum, (void*)Param, sizeof(CAM_PIPE_MGR_CMD_VECNPLL_CTRL_ENUM)) == 0)
            {
                LOG_MSG("VPLL CTRL(%d)",vencpll_ctrlEnum);
                if(vencpll_ctrlEnum==CAM_PIPE_MGR_CMD_VECNPLL_CTRL_SET_HIGH)
                {
                    err = mt_dfs_vencpll(0x1713B1);       /* 300MHz */
                    if (err)
                    {
                        LOG_ERR("DISABLE_PIPE SET HIGH fail");
                        Ret = -EFAULT;
                    }
                }
                else if(vencpll_ctrlEnum==CAM_PIPE_MGR_CMD_VECNPLL_CTRL_SET_LOW)
                {
                    err = mt_dfs_vencpll(0xE0000);       /* 182MHz */
                    if (err)
                    {
                        LOG_ERR("DISABLE_PIPE SET LOW fail");
                        Ret = -EFAULT;
                    }
                }
            }
            else
            {
                LOG_ERR("VENCPLL_CTRL:copy_from_user fail");
                Ret = -EFAULT;
            }
            break;
        }
        //
        default:
        {
            LOG_ERR("Unknown cmd");
            Ret = -EFAULT;
            break;
        }
    }
    //
    EXIT:
    if(Ret != 0)
    {
        if( (CamPipeMgr.LogMask & Lock.PipeMask) ||
            (CamPipeMgr.Mode.ScenSw == CAM_PIPE_MGR_SCEN_SW_NONE))
        {
            LOG_ERR("Fail");
            LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
                    current->comm,
                    current->pid,
                    current->tgid,
                    Sec,
                    USec);
            if(pFile->private_data != NULL)
            {
                LOG_ERR("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX),Time(%ld.%06ld)",
                        pProc->ProcName,
                        pProc->Pid,
                        pProc->Tgid,
                        pProc->PipeMask,
                        Sec,
                        USec);
            }
            CamPipeMgr_DumpPipeInfo();
        }
    }
    return Ret;
}