1 //-----------------------------------------------------------------------------
2 #include <linux/uaccess.h>
3 #include <linux/module.h>
4 #include <linux/types.h>
5 #include <linux/device.h>
6 #include <linux/cdev.h>
7 #include <linux/platform_device.h>
8 #include <linux/slab.h> //kmalloc/kfree in kernel 3.10
9 #include <linux/spinlock.h>
10 #include <linux/sched.h>
13 #include <linux/proc_fs.h>
14 #include <linux/xlog.h>
16 #include <mach/camera_pipe_mgr.h>
17 #include <mach/camera_pipe_mgr_imp.h>
18 //-----------------------------------------------------------------------------
19 static CAM_PIPE_MGR_STRUCT CamPipeMgr
;
20 //------------------------------------------------------------------------------
21 static void CamPipeMgr_GetTime(MUINT32
* pSec
, MUINT32
* pUSec
)
26 Time
= ktime_get();//ns
28 do_div( TimeSec
, 1000 );
29 *pUSec
= do_div( TimeSec
, 1000000);
31 *pSec
= (MUINT64
)TimeSec
;
33 //-----------------------------------------------------------------------------
34 static inline void CamPipeMgr_SpinLock(void)
37 spin_lock(&(CamPipeMgr
.SpinLock
));
39 //-----------------------------------------------------------------------------
40 static inline void CamPipeMgr_SpinUnlock(void)
43 spin_unlock(&(CamPipeMgr
.SpinLock
));
45 //-----------------------------------------------------------------------------
46 static unsigned long CamPipeMgr_MsToJiffies(MUINT32 Ms
)
48 return ((Ms
*HZ
+ 512) >> 10);
50 //-----------------------------------------------------------------------------
51 static void CamPipeMgr_DumpPipeInfo(void)
56 for(i
=0;i
<CAM_PIPE_MGR_PIPE_AMOUNT
;i
++)
58 if( CamPipeMgr
.PipeInfo
[i
].Pid
!= 0 &&
59 CamPipeMgr
.PipeInfo
[i
].Tgid
!= 0)
61 LOG_MSG("Pipe(%ld,%s),Proc:Name(%s),Pid(%d),Tgid(%d),Time(%ld.%06ld)",
63 CamPipeMgr
.PipeName
[i
],
64 CamPipeMgr
.PipeInfo
[i
].ProcName
,
65 CamPipeMgr
.PipeInfo
[i
].Pid
,
66 CamPipeMgr
.PipeInfo
[i
].Tgid
,
67 CamPipeMgr
.PipeInfo
[i
].TimeS
,
68 CamPipeMgr
.PipeInfo
[i
].TimeUS
);
73 //----------------------------------------------------------------------------
74 static MUINT32
CamPipeMgr_GtePipeLockTable(
75 CAM_PIPE_MGR_SCEN_SW_ENUM ScenSw
,
76 CAM_PIPE_MGR_SCEN_HW_ENUM ScenHw
)
78 MUINT32 PipeLockTable
= 0;
82 case CAM_PIPE_MGR_SCEN_HW_NONE
:
84 if(ScenSw
== CAM_PIPE_MGR_SCEN_SW_NONE
)
86 PipeLockTable
= CAM_PIPE_MGR_LOCK_TABLE_NONE
;
90 case CAM_PIPE_MGR_SCEN_HW_IC
:
92 PipeLockTable
= CAM_PIPE_MGR_LOCK_TABLE_IC
;
95 case CAM_PIPE_MGR_SCEN_HW_VR
:
97 PipeLockTable
= CAM_PIPE_MGR_LOCK_TABLE_VR
;
100 case CAM_PIPE_MGR_SCEN_HW_ZSD
:
102 PipeLockTable
= CAM_PIPE_MGR_LOCK_TABLE_ZSD
;
105 case CAM_PIPE_MGR_SCEN_HW_IP
:
107 PipeLockTable
= CAM_PIPE_MGR_LOCK_TABLE_IP
;
110 case CAM_PIPE_MGR_SCEN_HW_N3D
:
112 PipeLockTable
= CAM_PIPE_MGR_LOCK_TABLE_N3D
;
115 case CAM_PIPE_MGR_SCEN_HW_VSS
:
117 PipeLockTable
= CAM_PIPE_MGR_LOCK_TABLE_VSS
;
122 LOG_ERR("Unknown ScenHw(%d)",ScenHw
);
129 case CAM_PIPE_MGR_SCEN_SW_CAM_PRV
:
130 case CAM_PIPE_MGR_SCEN_SW_VIDEO_PRV
:
132 if(ScenHw
== CAM_PIPE_MGR_SCEN_HW_VSS
)
138 case CAM_PIPE_MGR_SCEN_SW_ZSD
:
140 if(ScenHw
== CAM_PIPE_MGR_SCEN_HW_ZSD
)
147 case CAM_PIPE_MGR_SCEN_SW_NONE
:
148 case CAM_PIPE_MGR_SCEN_SW_CAM_IDLE
:
149 case CAM_PIPE_MGR_SCEN_SW_CAM_CAP
:
150 case CAM_PIPE_MGR_SCEN_SW_VIDEO_REC
:
151 case CAM_PIPE_MGR_SCEN_SW_VIDEO_VSS
:
152 case CAM_PIPE_MGR_SCEN_SW_N3D
:
159 LOG_ERR("Unknown ScenSw(%d)",ScenSw
);
164 return PipeLockTable
;
166 //----------------------------------------------------------------------------
167 static void CamPipeMgr_UpdatePipeLockTable(CAM_PIPE_MGR_SCEN_SW_ENUM ScenSw
)
171 for(i
=0;i
<CAM_PIPE_MGR_SCEN_HW_AMOUNT
;i
++)
173 CamPipeMgr
.PipeLockTable
[i
] = CamPipeMgr_GtePipeLockTable(ScenSw
,i
);
176 //----------------------------------------------------------------------------
177 static void CamPipeMgr_StorePipeInfo(MUINT32 PipeMask
)
181 //LOG_MSG("PipeMask(0x%08X)",PipeMask);
183 CamPipeMgr
.PipeMask
|= PipeMask
;
185 for(i
=0;i
<CAM_PIPE_MGR_PIPE_AMOUNT
;i
++)
187 if((1<<i
) & PipeMask
)
189 if( CamPipeMgr
.PipeInfo
[i
].Pid
== 0 &&
190 CamPipeMgr
.PipeInfo
[i
].Tgid
== 0)
192 CamPipeMgr
.PipeInfo
[i
].Pid
= current
->pid
;
193 CamPipeMgr
.PipeInfo
[i
].Tgid
= current
->tgid
;
194 strcpy(CamPipeMgr
.PipeInfo
[i
].ProcName
,current
->comm
);
195 CamPipeMgr_GetTime(&(CamPipeMgr
.PipeInfo
[i
].TimeS
), &(CamPipeMgr
.PipeInfo
[i
].TimeUS
));
199 LOG_ERR("PipeMask(0x%lX),Pipe(%ld,%s),Pid(%d),Tgid(%d),Time(%ld.%06ld)",
202 CamPipeMgr
.PipeInfo
[i
].ProcName
,
203 CamPipeMgr
.PipeInfo
[i
].Pid
,
204 CamPipeMgr
.PipeInfo
[i
].Tgid
,
205 CamPipeMgr
.PipeInfo
[i
].TimeS
,
206 CamPipeMgr
.PipeInfo
[i
].TimeUS
);
211 //-----------------------------------------------------------------------------
212 static void CamPipeMgr_RemovePipeInfo(MUINT32 PipeMask
)
216 //LOG_MSG("PipeMask(0x%08X)",PipeMask);
218 CamPipeMgr
.PipeMask
&= (~PipeMask
);
220 for(i
=0;i
<CAM_PIPE_MGR_PIPE_AMOUNT
;i
++)
222 if((1<<i
) & PipeMask
)
224 if( CamPipeMgr
.PipeInfo
[i
].Pid
!= 0 &&
225 CamPipeMgr
.PipeInfo
[i
].Tgid
!= 0)
227 CamPipeMgr
.PipeInfo
[i
].Pid
= 0;
228 CamPipeMgr
.PipeInfo
[i
].Tgid
= 0;
229 strcpy(CamPipeMgr
.PipeInfo
[i
].ProcName
,CAM_PIPE_MGR_PROC_NAME
);
233 LOG_WRN("PipeMask(0x%lX),Pipe(%ld,%s),Pid(%d),Tgid(%d),Time(%ld.%06ld)",
236 CamPipeMgr
.PipeInfo
[i
].ProcName
,
237 CamPipeMgr
.PipeInfo
[i
].Pid
,
238 CamPipeMgr
.PipeInfo
[i
].Tgid
,
239 CamPipeMgr
.PipeInfo
[i
].TimeS
,
240 CamPipeMgr
.PipeInfo
[i
].TimeUS
);
245 //-----------------------------------------------------------------------------
246 static CAM_PIPE_MGR_STATUS_ENUM
CamPipeMgr_LockPipe(CAM_PIPE_MGR_LOCK_STRUCT
* pLock
)
249 CAM_PIPE_MGR_STATUS_ENUM Result
= CAM_PIPE_MGR_STATUS_OK
;
251 if((CamPipeMgr
.PipeMask
& pLock
->PipeMask
) == 0)
253 if((pLock
->PipeMask
& CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
]) != pLock
->PipeMask
)
255 Result
= CAM_PIPE_MGR_STATUS_TIMEOUT
;
259 CamPipeMgr_StorePipeInfo(pLock
->PipeMask
);
260 Result
= CAM_PIPE_MGR_STATUS_OK
;
265 CamPipeMgr_SpinUnlock();
266 if(pLock
->Timeout
> CAM_PIPE_MGR_TIMEOUT_MAX
)
268 pLock
->Timeout
= CAM_PIPE_MGR_TIMEOUT_MAX
;
270 Timeout
= wait_event_interruptible_timeout(
271 CamPipeMgr
.WaitQueueHead
,
272 (CamPipeMgr
.PipeMask
& pLock
->PipeMask
) == 0,
273 CamPipeMgr_MsToJiffies(pLock
->Timeout
));
274 CamPipeMgr_SpinLock();
275 if((CamPipeMgr
.PipeMask
& pLock
->PipeMask
) == 0)
277 if((pLock
->PipeMask
& CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
]) != pLock
->PipeMask
)
279 Result
= CAM_PIPE_MGR_STATUS_TIMEOUT
;
283 CamPipeMgr_StorePipeInfo(pLock
->PipeMask
);
284 Result
= CAM_PIPE_MGR_STATUS_OK
;
289 (CamPipeMgr
.PipeMask
& pLock
->PipeMask
) != 0)
291 Result
= CAM_PIPE_MGR_STATUS_TIMEOUT
;
295 Result
= CAM_PIPE_MGR_STATUS_UNKNOW
;
301 //-----------------------------------------------------------------------------
302 static void CamPipeMgr_UnlockPipe(CAM_PIPE_MGR_UNLOCK_STRUCT
* pUnlock
)
304 CamPipeMgr_RemovePipeInfo(pUnlock
->PipeMask
);
305 wake_up_interruptible(&(CamPipeMgr
.WaitQueueHead
));
307 //-----------------------------------------------------------------------------
308 static int CamPipeMgr_Open(
309 struct inode
* pInode
,
313 MUINT32 Sec
= 0,USec
= 0;
314 CAM_PIPE_MGR_PROC_STRUCT
* pProc
;
316 CamPipeMgr_GetTime(&Sec
, &USec
);
318 LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
325 CamPipeMgr_SpinLock();
327 pFile
->private_data
= NULL
;
328 pFile
->private_data
= kmalloc(sizeof(CAM_PIPE_MGR_PROC_STRUCT
),GFP_ATOMIC
);
329 if(pFile
->private_data
== NULL
)
335 pProc
= (CAM_PIPE_MGR_PROC_STRUCT
*)pFile
->private_data
;
338 strcpy(pProc
->ProcName
,CAM_PIPE_MGR_PROC_NAME
);
341 pProc
->TimeUS
= USec
;
344 CamPipeMgr_SpinUnlock();
348 LOG_ERR("No enough memory");
350 LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
362 //-----------------------------------------------------------------------------
363 static int CamPipeMgr_Release(
364 struct inode
* pInode
,
367 MUINT32 Sec
= 0,USec
= 0;
368 CAM_PIPE_MGR_PROC_STRUCT
* pProc
;
369 CAM_PIPE_MGR_UNLOCK_STRUCT Unlock
;
371 CamPipeMgr_GetTime(&Sec
, &USec
);
373 LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
380 if(pFile
->private_data
!= NULL
)
382 pProc
= (CAM_PIPE_MGR_PROC_STRUCT
*)pFile
->private_data
;
384 if( pProc
->Pid
!= 0 ||
386 pProc
->PipeMask
!= 0)
389 LOG_WRN("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX),Time(%ld.%06ld)",
399 LOG_WRN("Force to unlock pipe");
401 LOG_WRN("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%08lX),Time(%ld.%06ld)",
409 CamPipeMgr_SpinLock();
410 Unlock
.PipeMask
= pProc
->PipeMask
;
411 CamPipeMgr_UnlockPipe(&Unlock
);
412 CamPipeMgr_SpinUnlock();
416 kfree(pFile
->private_data
);
417 pFile
->private_data
= NULL
;
421 LOG_WRN("private_data is NULL");
423 LOG_WRN("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
435 //-----------------------------------------------------------------------------
436 static int CamPipeMgr_Flush(
440 MUINT32 Sec
= 0,USec
= 0;
441 CAM_PIPE_MGR_PROC_STRUCT
* pProc
;
442 CAM_PIPE_MGR_UNLOCK_STRUCT Unlock
;
444 CamPipeMgr_GetTime(&Sec
, &USec
);
446 LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
453 if(pFile
->private_data
!= NULL
)
455 pProc
= (CAM_PIPE_MGR_PROC_STRUCT
*)pFile
->private_data
;
457 if( pProc
->Pid
!= 0 ||
459 pProc
->PipeMask
!= 0)
462 LOG_WRN("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX),Time(%ld.%06ld)",
470 if( pProc
->Tgid
== 0 &&
471 pProc
->PipeMask
!= 0)
473 LOG_ERR("No Tgid info");
475 LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
481 LOG_ERR("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%08lX),Time(%ld.%06ld)",
491 if( (pProc
->Tgid
== current
->tgid
) ||
492 ((pProc
->Tgid
!= current
->tgid
) && (strcmp(current
->comm
, "binder") == 0)))
496 LOG_WRN("Force to unlock pipe");
498 LOG_WRN("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%08lX),Time(%ld.%06ld)",
506 CamPipeMgr_SpinLock();
507 Unlock
.PipeMask
= pProc
->PipeMask
;
508 CamPipeMgr_UnlockPipe(&Unlock
);
510 CamPipeMgr_SpinUnlock();
517 LOG_WRN("private_data is NULL");
519 LOG_WRN("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
531 //-----------------------------------------------------------------------------
532 static long CamPipeMgr_Ioctl(
538 MUINT32 Sec
= 0,USec
= 0;
541 char ProcName
[TASK_COMM_LEN
];
542 CAM_PIPE_MGR_LOCK_STRUCT Lock
;
543 CAM_PIPE_MGR_UNLOCK_STRUCT Unlock
;
544 CAM_PIPE_MGR_MODE_STRUCT Mode
;
545 CAM_PIPE_MGR_ENABLE_STRUCT Enable
;
546 CAM_PIPE_MGR_DISABLE_STRUCT Disable
;
547 CAM_PIPE_MGR_PROC_STRUCT
* pProc
= (CAM_PIPE_MGR_PROC_STRUCT
*)pFile
->private_data
;
548 CAM_PIPE_MGR_STATUS_ENUM Status
;
550 CamPipeMgr_GetTime(&Sec
, &USec
);
552 LOG_MSG("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
559 if(pFile
->private_data
== NULL
)
561 LOG_ERR("private_data is NULL");
568 case CAM_PIPE_MGR_LOCK
:
570 if(copy_from_user(&Lock
, (void*)Param
, sizeof(CAM_PIPE_MGR_LOCK_STRUCT
)) == 0)
572 if((Lock
.PipeMask
& CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
]) != Lock
.PipeMask
)
574 LOG_ERR("LOCK:Sw(%d),Hw(%d),LPM(0x%lX),PLT(0x%lX) fail",
575 CamPipeMgr
.Mode
.ScenSw
,
576 CamPipeMgr
.Mode
.ScenHw
,
578 CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
]);
583 CamPipeMgr_SpinLock();
584 Status
= CamPipeMgr_LockPipe(&Lock
);
585 if(Status
== CAM_PIPE_MGR_STATUS_OK
)
587 pProc
->PipeMask
|= Lock
.PipeMask
;
590 pProc
->Pid
= current
->pid
;
591 pProc
->Tgid
= current
->tgid
;
592 strcpy(pProc
->ProcName
,current
->comm
);
593 CamPipeMgr_SpinUnlock();
594 if(CamPipeMgr
.LogMask
& Lock
.PipeMask
)
596 LOG_MSG("LOCK:Sw(%d),Hw(%d),LPM(0x%lX),PLT(0x%lX) OK",
597 CamPipeMgr
.Mode
.ScenSw
,
598 CamPipeMgr
.Mode
.ScenHw
,
600 CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
]);
601 LOG_MSG("LOCK:Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX)",
610 CamPipeMgr_SpinUnlock();
611 if(pProc
->Tgid
!= current
->tgid
)
613 LOG_ERR("LOCK:Tgid is inconsistent");
620 CamPipeMgr_SpinUnlock();
621 if( (CamPipeMgr
.LogMask
& Lock
.PipeMask
) ||
622 (CamPipeMgr
.Mode
.ScenSw
== CAM_PIPE_MGR_SCEN_SW_NONE
))
624 LOG_ERR("LOCK:Sw(%d),Hw(%d),LPM(0x%lX),PLT(0x%lX) fail,Status(%d)",
625 CamPipeMgr
.Mode
.ScenSw
,
626 CamPipeMgr
.Mode
.ScenHw
,
628 CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
],
637 LOG_ERR("LOCK:copy_from_user fail");
643 case CAM_PIPE_MGR_UNLOCK
:
645 if(copy_from_user(&Unlock
, (void*)Param
, sizeof(CAM_PIPE_MGR_UNLOCK_STRUCT
)) == 0)
647 CamPipeMgr_SpinLock();
648 if(pProc
->PipeMask
& Unlock
.PipeMask
)
650 CamPipeMgr_UnlockPipe(&Unlock
);
651 //Store info before clear.
654 strcpy(ProcName
,pProc
->ProcName
);
656 pProc
->PipeMask
&= (~Unlock
.PipeMask
);
657 if(pProc
->PipeMask
== 0)
661 strcpy(pProc
->ProcName
,CAM_PIPE_MGR_PROC_NAME
);
663 CamPipeMgr_SpinUnlock();
664 if(CamPipeMgr
.LogMask
& Unlock
.PipeMask
)
666 LOG_MSG("UNLOCK:Sw(%d),Hw(%d),UPM(0x%lX),PLT(0x%lX) OK",
667 CamPipeMgr
.Mode
.ScenSw
,
668 CamPipeMgr
.Mode
.ScenHw
,
670 CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
]);
671 LOG_MSG("UNLOCK:Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX)",
680 CamPipeMgr_SpinUnlock();
681 if( (CamPipeMgr
.LogMask
& Unlock
.PipeMask
) ||
682 (CamPipeMgr
.Mode
.ScenSw
== CAM_PIPE_MGR_SCEN_SW_NONE
))
684 LOG_ERR("UNLOCK:Sw(%d),Hw(%d),UPM(0x%lX),PLT(0x%lX) fail, it was not locked before",
685 CamPipeMgr
.Mode
.ScenSw
,
686 CamPipeMgr
.Mode
.ScenHw
,
688 CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
]);
695 LOG_ERR("UNLOCK:copy_from_user fail");
701 case CAM_PIPE_MGR_DUMP
:
703 CamPipeMgr_DumpPipeInfo();
707 case CAM_PIPE_MGR_SET_MODE
:
709 if(copy_from_user(&Mode
, (void*)Param
, sizeof(CAM_PIPE_MGR_MODE_STRUCT
)) == 0)
711 if((Mode
.ScenHw
> CAM_PIPE_MGR_SCEN_HW_VSS
) || (Mode
.ScenHw
<0))
713 LOG_ERR("ScenHw(%d) > max(%d)",Mode
.ScenHw
,CAM_PIPE_MGR_SCEN_HW_VSS
);
717 if((Mode
.ScenSw
> CAM_PIPE_MGR_SCEN_SW_N3D
) || (Mode
.ScenSw
<0))
719 LOG_ERR("ScenSw(%d) > max(%d)",Mode
.ScenSw
,CAM_PIPE_MGR_SCEN_SW_N3D
);
723 if((Mode
.Dev
> CAM_PIPE_MGR_DEV_VT
) || (Mode
.Dev
<0))
725 LOG_ERR("Dev(%d) > max(%d)",Mode
.Dev
,CAM_PIPE_MGR_DEV_VT
);
730 LOG_MSG("SET_MODE:Sw(%d),Hw(%d)",Mode
.ScenSw
,Mode
.ScenHw
);
731 if((CamPipeMgr
.PipeMask
| CamPipeMgr
.PipeLockTable
[Mode
.ScenHw
]) ^ CamPipeMgr
.PipeLockTable
[Mode
.ScenHw
])
733 LOG_ERR("SET_MODE:PM(0x%lX),PLT(0x%lX), some pipe should be unlock",
735 CamPipeMgr
.PipeLockTable
[Mode
.ScenHw
]);
739 CamPipeMgr_SpinLock();
743 sizeof(CAM_PIPE_MGR_MODE_STRUCT
));
744 CamPipeMgr_UpdatePipeLockTable(CamPipeMgr
.Mode
.ScenSw
);
745 CamPipeMgr_SpinUnlock();
746 LOG_MSG("SET_MODE:done");
751 LOG_ERR("SET_MODE:copy_from_user fail");
757 case CAM_PIPE_MGR_GET_MODE
:
759 if((CamPipeMgr
.Mode
.ScenHw
> CAM_PIPE_MGR_SCEN_HW_VSS
) ||(CamPipeMgr
.Mode
.ScenHw
<0))
761 LOG_ERR("ScenHw(%d) > max(%d)",CamPipeMgr
.Mode
.ScenHw
,CAM_PIPE_MGR_SCEN_HW_VSS
);
765 if((CamPipeMgr
.Mode
.ScenSw
> CAM_PIPE_MGR_SCEN_SW_N3D
) || (CamPipeMgr
.Mode
.ScenSw
<0))
767 LOG_ERR("ScenSw(%d) > max(%d)",CamPipeMgr
.Mode
.ScenSw
,CAM_PIPE_MGR_SCEN_SW_N3D
);
771 if((CamPipeMgr
.Mode
.Dev
> CAM_PIPE_MGR_DEV_VT
) || (CamPipeMgr
.Mode
.Dev
<0))
773 LOG_ERR("Dev(%d) > max(%d)",CamPipeMgr
.Mode
.Dev
,CAM_PIPE_MGR_DEV_VT
);
778 if(copy_to_user((void*)Param
, &(CamPipeMgr
.Mode
), sizeof(CAM_PIPE_MGR_MODE_STRUCT
)) == 0)
784 LOG_ERR("GET_MODE:copy_to_user fail");
790 case CAM_PIPE_MGR_ENABLE_PIPE
:
792 if(copy_from_user(&Enable
, (void*)Param
, sizeof(CAM_PIPE_MGR_ENABLE_STRUCT
)) == 0)
794 LOG_MSG("ENABLE_PIPE:Sw(%d),Hw(%d):EPM(0x%lX),PLT(0x%lX)",
795 CamPipeMgr
.Mode
.ScenSw
,
796 CamPipeMgr
.Mode
.ScenHw
,
798 CamPipeMgr_GtePipeLockTable(CamPipeMgr
.Mode
.ScenSw
,CamPipeMgr
.Mode
.ScenHw
));
799 if((Enable
.PipeMask
& CamPipeMgr_GtePipeLockTable(CamPipeMgr
.Mode
.ScenSw
,CamPipeMgr
.Mode
.ScenHw
)) != Enable
.PipeMask
)
801 LOG_ERR("ENABLE_PIPE:Some pipe are not available");
806 CamPipeMgr_SpinLock();
807 CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
] |= Enable
.PipeMask
;
808 CamPipeMgr_SpinUnlock();
813 LOG_ERR("ENABLE_PIPE:copy_from_user fail");
819 case CAM_PIPE_MGR_DISABLE_PIPE
:
821 if(copy_from_user(&Disable
, (void*)Param
, sizeof(CAM_PIPE_MGR_DISABLE_STRUCT
)) == 0)
823 LOG_MSG("DISABLE_PIPE:Sw(%d),Hw(%d):DPM(0x%lX),PLT(0x%lX)",
824 CamPipeMgr
.Mode
.ScenSw
,
825 CamPipeMgr
.Mode
.ScenHw
,
827 CamPipeMgr_GtePipeLockTable(CamPipeMgr
.Mode
.ScenSw
,CamPipeMgr
.Mode
.ScenHw
));
828 if((Disable
.PipeMask
& CamPipeMgr_GtePipeLockTable(CamPipeMgr
.Mode
.ScenSw
,CamPipeMgr
.Mode
.ScenHw
)) != Disable
.PipeMask
)
830 LOG_ERR("DISABLE_PIPE:Some pipe are not available");
835 CamPipeMgr_SpinLock();
836 CamPipeMgr
.PipeLockTable
[CamPipeMgr
.Mode
.ScenHw
] &= (~Disable
.PipeMask
);
837 CamPipeMgr_SpinUnlock();
842 LOG_ERR("DISABLE_PIPE:copy_from_user fail");
850 LOG_ERR("Unknown cmd");
859 if( (CamPipeMgr
.LogMask
& Lock
.PipeMask
) ||
860 (CamPipeMgr
.Mode
.ScenSw
== CAM_PIPE_MGR_SCEN_SW_NONE
))
863 LOG_ERR("Cur:Name(%s),pid(%d),tgid(%d),Time(%ld.%06ld)",
869 if(pFile
->private_data
!= NULL
)
871 LOG_ERR("Proc:Name(%s),Pid(%d),Tgid(%d),PipeMask(0x%lX),Time(%ld.%06ld)",
879 CamPipeMgr_DumpPipeInfo();
884 //-----------------------------------------------------------------------------
885 static const struct file_operations CamPipeMgr_FileOper
=
887 .owner
= THIS_MODULE
,
888 .open
= CamPipeMgr_Open
,
889 .release
= CamPipeMgr_Release
,
890 .flush
= CamPipeMgr_Flush
,
891 .unlocked_ioctl
= CamPipeMgr_Ioctl
893 //-----------------------------------------------------------------------------
894 static int CamPipeMgr_RegCharDev(void)
900 CamPipeMgr
.DevNo
= 0;
901 Ret
= alloc_chrdev_region(
903 CAM_PIPE_MGR_DEV_NO_MINOR
,
904 CAM_PIPE_MGR_DEV_NUM
,
905 CAM_PIPE_MGR_DEV_NAME
);
908 LOG_ERR("alloc_chrdev_region fail:Ret(%ld)",Ret
);
911 //Allocate memory for driver
912 CamPipeMgr
.pCharDrv
= cdev_alloc();
913 if(CamPipeMgr
.pCharDrv
== NULL
)
915 unregister_chrdev_region(
917 CAM_PIPE_MGR_DEV_NUM
);
918 LOG_ERR("Allocate mem for kobject failed");
921 //Attatch file operation.
924 &CamPipeMgr_FileOper
);
925 CamPipeMgr
.pCharDrv
->owner
= THIS_MODULE
;
927 if(cdev_add(CamPipeMgr
.pCharDrv
, CamPipeMgr
.DevNo
, CAM_PIPE_MGR_DEV_MINOR_NUM
))
929 LOG_ERR("Attatch file operation failed");
930 unregister_chrdev_region(
932 CAM_PIPE_MGR_DEV_NUM
);
939 //-----------------------------------------------------------------------------
940 static inline void CamPipeMgr_UnregCharDev(void)
943 //Release char driver
944 cdev_del(CamPipeMgr
.pCharDrv
);
945 unregister_chrdev_region(
947 CAM_PIPE_MGR_DEV_NUM
);
951 //-----------------------------------------------------------------------------
952 static int CamPipeMgr_Probe(struct platform_device
*pDev
)
956 struct device
* pDevice
= NULL
;
960 Ret
= CamPipeMgr_RegCharDev();
963 LOG_ERR("RegCharDev fail:Ret(%ld)",Ret
);
967 CamPipeMgr
.pClass
= class_create(
969 CAM_PIPE_MGR_DEV_NAME
);
970 if(IS_ERR(CamPipeMgr
.pClass
))
972 Ret
= PTR_ERR(CamPipeMgr
.pClass
);
973 LOG_ERR("class_create fail:Ret(%ld)",Ret
);
976 pDevice
= device_create(
981 CAM_PIPE_MGR_DEV_NAME
);
984 LOG_ERR("device_create fail");
988 spin_lock_init(&(CamPipeMgr
.SpinLock
));
989 init_waitqueue_head(&(CamPipeMgr
.WaitQueueHead
));
990 CamPipeMgr
.Mode
.ScenSw
= CAM_PIPE_MGR_SCEN_SW_NONE
;
991 CamPipeMgr
.Mode
.ScenHw
= CAM_PIPE_MGR_SCEN_HW_NONE
;
993 for(i
=0;i
<CAM_PIPE_MGR_PIPE_AMOUNT
;i
++)
995 CamPipeMgr
.PipeInfo
[i
].Pid
= 0;
996 CamPipeMgr
.PipeInfo
[i
].Tgid
= 0;
997 strcpy(CamPipeMgr
.PipeInfo
[i
].ProcName
,CAM_PIPE_MGR_PROC_NAME
);
998 CamPipeMgr
.PipeInfo
[i
].TimeS
= 0;
999 CamPipeMgr
.PipeInfo
[i
].TimeUS
= 0;
1003 CamPipeMgr
.PipeName
[CAM_PIPE_MGR_PIPE_CAM_IO
],
1004 CAM_PIPE_MGR_PIPE_NAME_CAM_IO
);
1006 CamPipeMgr
.PipeName
[CAM_PIPE_MGR_PIPE_POST_PROC
],
1007 CAM_PIPE_MGR_PIPE_NAME_POST_PROC
);
1009 CamPipeMgr
.PipeName
[CAM_PIPE_MGR_PIPE_XDP_CAM
],
1010 CAM_PIPE_MGR_PIPE_NAME_XDP_CAM
);
1012 CamPipeMgr_UpdatePipeLockTable(CamPipeMgr
.Mode
.ScenSw
);
1013 CamPipeMgr
.LogMask
= ( CAM_PIPE_MGR_PIPE_MASK_CAM_IO
|
1014 CAM_PIPE_MGR_PIPE_MASK_POST_PROC
|
1015 CAM_PIPE_MGR_PIPE_MASK_XDP_CAM
);
1020 //-----------------------------------------------------------------------------
1021 static int CamPipeMgr_Remove(struct platform_device
*pdev
)
1024 //unregister char driver.
1025 CamPipeMgr_UnregCharDev();
1030 class_destroy(CamPipeMgr
.pClass
);
1035 //-----------------------------------------------------------------------------
1036 static int CamPipeMgr_Suspend(
1037 struct platform_device
* pDev
,
1043 //-----------------------------------------------------------------------------
1044 static int CamPipeMgr_Resume(struct platform_device
*pDev
)
1049 //-----------------------------------------------------------------------------
1050 static struct platform_driver CamPipeMgr_PlatformDriver
=
1052 .probe
= CamPipeMgr_Probe
,
1053 .remove
= CamPipeMgr_Remove
,
1054 .suspend
= CamPipeMgr_Suspend
,
1055 .resume
= CamPipeMgr_Resume
,
1058 .name
= CAM_PIPE_MGR_DEV_NAME
,
1059 .owner
= THIS_MODULE
,
1062 //-----------------------------------------------------------------------------
1063 static int __init
CamPipeMgr_Init(void)
1069 Ret
= platform_driver_register(&CamPipeMgr_PlatformDriver
);
1072 LOG_ERR("Failed to register driver:Ret(%ld)",Ret
);
1079 //-----------------------------------------------------------------------------
1080 static void __exit
CamPipeMgr_Exit(void)
1083 platform_driver_unregister(&CamPipeMgr_PlatformDriver
);
1086 //-----------------------------------------------------------------------------
1087 module_init(CamPipeMgr_Init
);
1088 module_exit(CamPipeMgr_Exit
);
1089 MODULE_DESCRIPTION("Camera Pipe Manager Driver");
1090 MODULE_AUTHOR("Marx <Marx.Chiu@Mediatek.com>");
1091 MODULE_LICENSE("GPL");
1092 //-----------------------------------------------------------------------------