vh264mvc.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. /*
  2. * AMLOGIC Audio/Video streaming port driver.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the named License,
  7. * or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
  17. *
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/errno.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/timer.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/amports/amstream.h>
  26. #include <linux/amports/ptsserv.h>
  27. #include <linux/amports/canvas.h>
  28. #include <linux/amports/vframe.h>
  29. #include <linux/amports/vframe_provider.h>
  30. #include <linux/amports/vframe_receiver.h>
  31. #include <linux/workqueue.h>
  32. #include <linux/dma-mapping.h>
  33. #include <asm/atomic.h>
  34. #include <mach/am_regs.h>
  35. #include "vdec_reg.h"
  36. #include "amvdec.h"
  37. #include "vh264mvc_mc.h"
  38. #define DRIVER_NAME "amvdec_h264mvc"
  39. #define MODULE_NAME "amvdec_h264mvc"
  40. #define HANDLE_h264mvc_IRQ
  41. #define DEBUG_PTS
  42. #define DEBUG_SKIP
  43. #define PUT_INTERVAL (HZ/100)
  44. #define STAT_TIMER_INIT 0x01
  45. #define STAT_MC_LOAD 0x02
  46. #define STAT_ISR_REG 0x04
  47. #define STAT_VF_HOOK 0x08
  48. #define STAT_TIMER_ARM 0x10
  49. #define STAT_VDEC_RUN 0x20
  50. #define DROPPING_THREAD_HOLD 4
  51. #define DROPPING_FIRST_WAIT 6
  52. static vframe_t *vh264mvc_vf_peek(void*);
  53. static vframe_t *vh264mvc_vf_get(void*);
  54. static void vh264mvc_vf_put(vframe_t *, void*);
  55. static int vh264mvc_event_cb(int type, void *data, void *private_data);
  56. static void vh264mvc_prot_init(void);
  57. static void vh264mvc_local_init(void);
  58. static void vh264mvc_put_timer_func(unsigned long arg);
  59. static const char vh264mvc_dec_id[] = "vh264mvc-dev";
  60. #define PROVIDER_NAME "decoder.h264mvc"
  61. static const struct vframe_operations_s vh264mvc_vf_provider = {
  62. .peek = vh264mvc_vf_peek,
  63. .get = vh264mvc_vf_get,
  64. .put = vh264mvc_vf_put,
  65. .event_cb = vh264mvc_event_cb,
  66. .vf_states=NULL,
  67. };
  68. static struct vframe_provider_s vh264mvc_vf_prov;
  69. static u32 frame_width, frame_height, frame_dur;
  70. static struct timer_list recycle_timer;
  71. static u32 stat;
  72. static u32 pts_outside = 0;
  73. static u32 sync_outside = 0;
  74. static u32 vh264mvc_ratio;
  75. static u32 h264mvc_ar;
  76. static u32 no_dropping_cnt;
  77. #ifdef DEBUG_SKIP
  78. static unsigned long view_total, view_dropped;
  79. #endif
  80. #ifdef DEBUG_PTS
  81. static unsigned long pts_missed, pts_hit;
  82. #endif
  83. static atomic_t vh264mvc_active = ATOMIC_INIT(0);
  84. static struct work_struct error_wd_work;
  85. static struct dec_sysinfo vh264mvc_amstream_dec_info;
  86. extern u32 trickmode_i;
  87. static DEFINE_SPINLOCK(lock);
  88. static int vh264mvc_stop(void);
  89. static s32 vh264mvc_init(void);
  90. /***************************
  91. * new
  92. ***************************/
  93. // bit[3:0] command :
  94. // 0 - command finished
  95. // (DATA0 - {level_idc_mmco, max_reference_frame_num, width, height}
  96. // 1 - alloc view_0 display_buffer and reference_data_area
  97. // 2 - alloc view_1 display_buffer and reference_data_area
  98. #define MAILBOX_COMMAND AV_SCRATCH_0
  99. #define MAILBOX_DATA_0 AV_SCRATCH_1
  100. #define MAILBOX_DATA_1 AV_SCRATCH_2
  101. #define MAILBOX_DATA_2 AV_SCRATCH_3
  102. #define CANVAS_START AV_SCRATCH_6
  103. #define BUFFER_RECYCLE AV_SCRATCH_7
  104. #define DROP_CONTROL AV_SCRATCH_8
  105. #define PICTURE_COUNT AV_SCRATCH_9
  106. #define DECODE_STATUS AV_SCRATCH_A
  107. #define SPS_STATUS AV_SCRATCH_B
  108. #define PPS_STATUS AV_SCRATCH_C
  109. #define SIM_RESERV_D AV_SCRATCH_D
  110. #define WORKSPACE_START AV_SCRATCH_E
  111. #define SIM_RESERV_F AV_SCRATCH_F
  112. #define DECODE_ERROR_CNT AV_SCRATCH_G
  113. #define CURRENT_UCODE AV_SCRATCH_H
  114. #define CURRENT_SPS_PPS AV_SCRATCH_I // bit[15:9]-SPS, bit[8:0]-PPS
  115. #define DECODE_SKIP_PICTURE AV_SCRATCH_J
  116. #define SIM_RESERV_K AV_SCRATCH_K
  117. #define SIM_RESERV_L AV_SCRATCH_L
  118. #define REF_START_VIEW_0 AV_SCRATCH_M
  119. #define REF_START_VIEW_1 AV_SCRATCH_N
  120. /********************************************
  121. * Mailbox command
  122. ********************************************/
  123. #define CMD_FINISHED 0
  124. #define CMD_ALLOC_VIEW_0 1
  125. #define CMD_ALLOC_VIEW_1 2
  126. #define CMD_FRAME_DISPLAY 3
  127. #define CANVAS_INDEX_START 106
  128. unsigned DECODE_BUFFER_START=0x00200000;
  129. unsigned DECODE_BUFFER_END=0x05000000;
  130. #define DECODE_BUFFER_NUM_MAX 16
  131. #define DISPLAY_BUFFER_NUM 4
  132. static unsigned int ANC_CANVAS_ADDR;
  133. static unsigned int index;
  134. static unsigned int dpb_start_addr[3];
  135. static unsigned int ref_start_addr[2];
  136. static unsigned int max_dec_frame_buffering[2];
  137. static unsigned int total_dec_frame_buffering[2];
  138. static unsigned int level_idc, max_reference_frame_num, mb_width, mb_height;
  139. static unsigned int dpb_size, ref_size;
  140. static int display_buff_id;
  141. static int display_view_id;
  142. static int display_POC;
  143. static int stream_offset;
  144. #define video_domain_addr(adr) (adr&0x7fffffff)
  145. static unsigned work_space_adr;
  146. static unsigned work_space_size = 0xa0000;
  147. typedef struct {
  148. unsigned int y_addr;
  149. unsigned int u_addr;
  150. unsigned int v_addr;
  151. int y_canvas_index;
  152. int u_canvas_index;
  153. int v_canvas_index;
  154. } buffer_spec_t;
  155. static buffer_spec_t buffer_spec0[DECODE_BUFFER_NUM_MAX+DISPLAY_BUFFER_NUM];
  156. static buffer_spec_t buffer_spec1[DECODE_BUFFER_NUM_MAX+DISPLAY_BUFFER_NUM];
  157. /*
  158. dbg_mode:
  159. bit 0: 1, print debug information
  160. bit 4: 1, recycle buffer without displaying;
  161. bit 5: 1, buffer single frame step , set dbg_cmd to 1 to step
  162. */
  163. static int dbg_mode = 0;
  164. static int dbg_cmd = 0;
  165. static int view_mode = 3; /* 0, left; 1 ,right ; 2, left<->right 3, right<->left */
  166. static int drop_rate = 2;
  167. /**/
  168. #define MVC_BUF_NUM (DECODE_BUFFER_NUM_MAX+DISPLAY_BUFFER_NUM)
  169. static struct list_head free_list_head = LIST_HEAD_INIT(free_list_head);
  170. static struct list_head ready_list_head = LIST_HEAD_INIT(ready_list_head);
  171. static struct list_head recycle_list_head = LIST_HEAD_INIT(recycle_list_head);
  172. typedef struct mvc_buf_s{
  173. struct list_head list;
  174. vframe_t vframe;
  175. int display_POC;
  176. int view0_buff_id;
  177. int view1_buff_id;
  178. int view0_drop;
  179. int view1_drop;
  180. int stream_offset;
  181. unsigned pts;
  182. }mvc_buf_t;
  183. static mvc_buf_t mvc_buf_local[MVC_BUF_NUM];
  184. #define spec2canvas(x) \
  185. (((x)->v_canvas_index << 16) | \
  186. ((x)->u_canvas_index << 8) | \
  187. ((x)->y_canvas_index << 0))
  188. #define to_mvcbuf(vf) \
  189. container_of(vf, struct mvc_buf_s, vframe)
  190. static int vf_buf_init_flag = 0;
  191. static void recycle_vframe(void);
  192. static void init_vf_buf(void)
  193. {
  194. int i;
  195. mvc_buf_t* mvc_buf;
  196. for(i = 0; i< MVC_BUF_NUM; i++){
  197. mvc_buf = &mvc_buf_local[i];
  198. memset(mvc_buf, 0, sizeof(mvc_buf_t));
  199. mvc_buf->view0_buff_id = -1;
  200. mvc_buf->view1_buff_id = -1;
  201. mvc_buf->display_POC = -1;
  202. list_add_tail(&(mvc_buf->list), &free_list_head);
  203. }
  204. vf_buf_init_flag = 1;
  205. }
  206. static void uninit_vf_buf(void)
  207. {
  208. mvc_buf_t *p = NULL, *ptmp;
  209. vf_buf_init_flag = 0;
  210. list_for_each_entry_safe(p, ptmp, &free_list_head, list) {
  211. list_del(&p->list);
  212. }
  213. list_for_each_entry_safe(p, ptmp, &ready_list_head, list) {
  214. list_del(&p->list);
  215. }
  216. list_for_each_entry_safe(p, ptmp, &recycle_list_head, list) {
  217. list_del(&p->list);
  218. }
  219. }
  220. static void set_frame_info(vframe_t *vf)
  221. {
  222. unsigned int ar = 0;
  223. vf->width = frame_width;
  224. vf->height = frame_height;
  225. vf->duration = frame_dur;
  226. vf->duration_pulldown = 0;
  227. if (vh264mvc_ratio == 0) {
  228. vf->ratio_control |= (0x90 << DISP_RATIO_ASPECT_RATIO_BIT); // always stretch to 16:9
  229. } else {
  230. //h264mvc_ar = ((float)frame_height/frame_width)*customer_ratio;
  231. ar = min(h264mvc_ar, (u32)DISP_RATIO_ASPECT_RATIO_MAX);
  232. vf->ratio_control = (ar << DISP_RATIO_ASPECT_RATIO_BIT);
  233. }
  234. return;
  235. }
  236. static vframe_t *vh264mvc_vf_peek(void* op_arg)
  237. {
  238. int ready_cnt = 0;
  239. vframe_t *vf, *vf_next;
  240. mvc_buf_t *p = NULL, *ptmp;
  241. if(vf_buf_init_flag == 0)
  242. return NULL;
  243. if((dbg_mode&0x30)==0x20){
  244. if(dbg_cmd!=1){
  245. return NULL;
  246. }
  247. }
  248. ready_cnt = 0;
  249. list_for_each_entry_safe(p, ptmp, &ready_list_head, list) {
  250. if((p->view0_buff_id >= 0 && p->view1_buff_id >= 0) &&
  251. ((p->view0_drop == 0) && (p->view1_drop) == 0))
  252. ready_cnt++;
  253. }
  254. if((no_dropping_cnt >= DROPPING_FIRST_WAIT) && (ready_cnt < DROPPING_THREAD_HOLD)) {
  255. WRITE_VREG(DROP_CONTROL, (1 << 31) | (drop_rate));
  256. } else {
  257. WRITE_VREG(DROP_CONTROL, 0);
  258. }
  259. if (ready_cnt == 0)
  260. return NULL;
  261. /* consolidate ready queue for dropped frames */
  262. list_for_each_entry_safe(p, ptmp, &ready_list_head, list) {
  263. if((p->view0_buff_id >= 0 && p->view1_buff_id >= 0)){
  264. if (((p->view0_drop) || (p->view1_drop)) &&
  265. (&ptmp->list != &ready_list_head)) {
  266. vf = &(p->vframe);
  267. vf_next = &(ptmp->vframe);
  268. if (vf_next->pts == 0) {
  269. if (p->vframe.pts == 0) {
  270. vf_next->duration += frame_dur;
  271. } else {
  272. vf_next->pts = p->vframe.pts + p->vframe.duration;
  273. }
  274. }
  275. list_move_tail(&p->list, &recycle_list_head);
  276. }
  277. }
  278. }
  279. vf = NULL;
  280. list_for_each_entry_safe(p, ptmp, &ready_list_head, list) {
  281. if((p->view0_buff_id >= 0 && p->view1_buff_id >= 0)){
  282. /* if there is only a single dropped frame in the ready queue, return NULL */
  283. if ((p->view0_drop) || (p->view1_drop))
  284. break;
  285. vf = &(p->vframe);
  286. if(view_mode==0 || view_mode==1){
  287. vf->type = VIDTYPE_PROGRESSIVE | VIDTYPE_VIU_FIELD;
  288. vf->canvas0Addr = vf->canvas1Addr = (view_mode==0)?spec2canvas(&buffer_spec0[p->view0_buff_id]):
  289. spec2canvas(&buffer_spec1[p->view1_buff_id]);
  290. }
  291. else{
  292. vf->type = VIDTYPE_PROGRESSIVE | VIDTYPE_MVC;
  293. if(view_mode==2){
  294. vf->canvas0Addr = spec2canvas(&buffer_spec1[p->view1_buff_id]);
  295. vf->canvas1Addr = spec2canvas(&buffer_spec0[p->view0_buff_id]);
  296. }
  297. else{
  298. vf->canvas0Addr = spec2canvas(&buffer_spec0[p->view0_buff_id]);
  299. vf->canvas1Addr = spec2canvas(&buffer_spec1[p->view1_buff_id]);
  300. }
  301. }
  302. break;
  303. }
  304. }
  305. if(vf){
  306. if(frame_width==0){
  307. frame_width = vh264mvc_amstream_dec_info.width;
  308. }
  309. if(frame_height==0){
  310. frame_height = vh264mvc_amstream_dec_info.height;
  311. }
  312. vf->width = frame_width;
  313. vf->height = frame_height;
  314. }
  315. return vf;
  316. }
  317. static vframe_t *vh264mvc_vf_get(void* op_arg)
  318. {
  319. mvc_buf_t * mvc_buf;
  320. vframe_t* vf = vh264mvc_vf_peek(op_arg);
  321. if(vf){
  322. mvc_buf = to_mvcbuf(vf);
  323. list_del(&(mvc_buf->list));
  324. /* use newest frame_width, frame_height */
  325. if((dbg_mode&0x30)==0x20){
  326. if(dbg_cmd==1){
  327. dbg_cmd = 0;
  328. }
  329. }
  330. if(dbg_mode&0x1)
  331. printk("vh264mvc_vf_get %d %d %d poc %d view0_buf %d view1_buf %d\n",
  332. vf->width, vf->height, vf->duration, mvc_buf->display_POC, mvc_buf->view0_buff_id, mvc_buf->view1_buff_id);
  333. if (vf->pts)
  334. pts_hit++;
  335. else
  336. pts_missed++;
  337. if (no_dropping_cnt < DROPPING_FIRST_WAIT)
  338. no_dropping_cnt++;
  339. }
  340. return vf;
  341. }
  342. static void vh264mvc_vf_put(vframe_t *vf, void* op_arg)
  343. {
  344. mvc_buf_t * mvc_buf;
  345. if(vf_buf_init_flag == 0){
  346. return;
  347. }
  348. mvc_buf = to_mvcbuf(vf);
  349. list_add_tail(&mvc_buf->list, &recycle_list_head);
  350. recycle_vframe();
  351. }
  352. static int vh264mvc_event_cb(int type, void *data, void *private_data)
  353. {
  354. if(type & VFRAME_EVENT_RECEIVER_RESET){
  355. unsigned long flags;
  356. amvdec_stop();
  357. #ifndef CONFIG_POST_PROCESS_MANAGER
  358. vf_light_unreg_provider(&vh264mvc_vf_prov);
  359. #endif
  360. spin_lock_irqsave(&lock, flags);
  361. vh264mvc_local_init();
  362. vh264mvc_prot_init();
  363. spin_unlock_irqrestore(&lock, flags);
  364. #ifndef CONFIG_POST_PROCESS_MANAGER
  365. vf_reg_provider(&vh264mvc_vf_prov);
  366. #endif
  367. amvdec_start();
  368. }
  369. return 0;
  370. }
  371. /**/
  372. long init_canvas( int start_addr, long dpb_size, int dpb_number, int mb_width, int mb_height, buffer_spec_t* buffer_spec) {
  373. int dpb_addr, addr;
  374. int i;
  375. int mb_total;
  376. //cav_con canvas;
  377. dpb_addr = start_addr;
  378. mb_total = mb_width * mb_height;
  379. for ( i = 0 ; i < dpb_number ; i++ )
  380. {
  381. WRITE_VREG(ANC_CANVAS_ADDR, index | ((index+1)<<8) | ((index+2)<<16));
  382. ANC_CANVAS_ADDR++;
  383. addr = dpb_addr;
  384. buffer_spec[i].y_addr = addr;
  385. buffer_spec[i].y_canvas_index = index;
  386. canvas_config(index,
  387. addr,
  388. mb_width << 4,
  389. mb_height << 4,
  390. CANVAS_ADDR_NOWRAP,
  391. CANVAS_BLKMODE_32X32);
  392. addr += mb_total << 8;
  393. index++;
  394. buffer_spec[i].u_addr = addr;
  395. buffer_spec[i].u_canvas_index = index;
  396. canvas_config(index,
  397. addr,
  398. mb_width << 3,
  399. mb_height << 3,
  400. CANVAS_ADDR_NOWRAP,
  401. CANVAS_BLKMODE_32X32);
  402. addr += mb_total << 6;
  403. index++;
  404. buffer_spec[i].v_addr = addr;
  405. buffer_spec[i].v_canvas_index = index;
  406. canvas_config(index,
  407. addr,
  408. mb_width << 3,
  409. mb_height << 3,
  410. CANVAS_ADDR_NOWRAP,
  411. CANVAS_BLKMODE_32X32);
  412. addr += mb_total << 6;
  413. index++;
  414. dpb_addr = dpb_addr + dpb_size;
  415. if(dpb_addr >= DECODE_BUFFER_END) return -1;
  416. }
  417. return dpb_addr;
  418. }
  419. static int get_max_dec_frame_buf_size(int level_idc, int max_reference_frame_num, int mb_width, int mb_height)
  420. {
  421. int pic_size = mb_width * mb_height * 384;
  422. int size = 0;
  423. switch (level_idc)
  424. {
  425. case 9:
  426. size = 152064;
  427. break;
  428. case 10:
  429. size = 152064;
  430. break;
  431. case 11:
  432. size = 345600;
  433. break;
  434. case 12:
  435. size = 912384;
  436. break;
  437. case 13:
  438. size = 912384;
  439. break;
  440. case 20:
  441. size = 912384;
  442. break;
  443. case 21:
  444. size = 1824768;
  445. break;
  446. case 22:
  447. size = 3110400;
  448. break;
  449. case 30:
  450. size = 3110400;
  451. break;
  452. case 31:
  453. size = 6912000;
  454. break;
  455. case 32:
  456. size = 7864320;
  457. break;
  458. case 40:
  459. size = 12582912;
  460. break;
  461. case 41:
  462. size = 12582912;
  463. break;
  464. case 42:
  465. size = 13369344;
  466. break;
  467. case 50:
  468. size = 42393600;
  469. break;
  470. case 51:
  471. size = 70778880;
  472. break;
  473. default:
  474. break;
  475. }
  476. size /= pic_size;
  477. size = size + 1; // For MVC need onr more buffer
  478. if(max_reference_frame_num > size) size = max_reference_frame_num;
  479. if(size > DECODE_BUFFER_NUM_MAX) size = DECODE_BUFFER_NUM_MAX;
  480. return size;
  481. }
  482. #ifdef DEBUG_PTS
  483. static void dump_ready_list(void)
  484. {
  485. mvc_buf_t *p = NULL, *ptmp;
  486. list_for_each_entry_safe(p, ptmp, &ready_list_head, list) {
  487. printk("view0_buff_id = %d, view1_buff_id = %d, stream_offset = %d, POC = %d\n",
  488. p->view0_buff_id,
  489. p->view1_buff_id,
  490. p->stream_offset,
  491. p->display_POC);
  492. }
  493. }
  494. #endif
  495. #ifdef HANDLE_h264mvc_IRQ
  496. static irqreturn_t vh264mvc_isr(int irq, void *dev_id)
  497. #else
  498. static void vh264mvc_isr(void)
  499. #endif
  500. {
  501. int drop_status;
  502. int ret = READ_VREG(MAILBOX_COMMAND);
  503. //printk("vh264mvc_isr, cmd =%x\n", ret);
  504. switch(ret & 0xff) {
  505. case CMD_ALLOC_VIEW_0:
  506. if(dbg_mode&0x1)
  507. printk("Start H264 display buffer allocation for view 0\n");
  508. if((dpb_start_addr[0] != -1) | (dpb_start_addr[1] != -1)){
  509. dpb_start_addr[0] = -1;
  510. dpb_start_addr[1] = -1;
  511. }
  512. dpb_start_addr[0] = DECODE_BUFFER_START;
  513. ret = READ_VREG(MAILBOX_DATA_0);
  514. level_idc = (ret >> 24) & 0xff;
  515. max_reference_frame_num = (ret >> 16) & 0xff;
  516. mb_width = (ret >> 8) & 0xff;
  517. mb_height = (ret >> 0) & 0xff;
  518. max_dec_frame_buffering[0] = get_max_dec_frame_buf_size(level_idc, max_reference_frame_num, mb_width, mb_height);
  519. total_dec_frame_buffering[0] = max_dec_frame_buffering[0] + DISPLAY_BUFFER_NUM;
  520. mb_width = (mb_width+3) & 0xfffffffc;
  521. mb_height = (mb_height+3) & 0xfffffffc;
  522. dpb_size = mb_width * mb_height * 384;
  523. ref_size = mb_width * mb_height * 96;
  524. if(dbg_mode&0x1){
  525. printk("dpb_size: 0x%x\n", dpb_size);
  526. printk("ref_size: 0x%x\n", ref_size);
  527. printk("total_dec_frame_buffering[0] : 0x%x\n", total_dec_frame_buffering[0]);
  528. printk("max_reference_frame_num: 0x%x\n", max_reference_frame_num);
  529. }
  530. ref_start_addr[0] = dpb_start_addr[0] +
  531. (dpb_size * total_dec_frame_buffering[0]);
  532. dpb_start_addr[1] = ref_start_addr[0] +
  533. (ref_size * (max_reference_frame_num+1));
  534. if(dbg_mode&0x1){
  535. printk("dpb_start_addr[0]: 0x%x\n", dpb_start_addr[0]);
  536. printk("ref_start_addr[0]: 0x%x\n", ref_start_addr[0]);
  537. printk("dpb_start_addr[1]: 0x%x\n", dpb_start_addr[1]);
  538. }
  539. if(dpb_start_addr[1] >= DECODE_BUFFER_END)
  540. {
  541. printk(" No enough memory for alloc view 0\n");
  542. goto exit;
  543. }
  544. index = CANVAS_INDEX_START;
  545. ANC_CANVAS_ADDR = ANC0_CANVAS_ADDR;
  546. ret = init_canvas(dpb_start_addr[0], dpb_size, total_dec_frame_buffering[0], mb_width, mb_height, buffer_spec0);
  547. if(ret == -1) {
  548. printk(" Un-expected memory alloc problem\n");
  549. goto exit;
  550. }
  551. WRITE_VREG(REF_START_VIEW_0, video_domain_addr(ref_start_addr[0]));
  552. WRITE_VREG(MAILBOX_DATA_0,
  553. (max_dec_frame_buffering[0] << 8) |
  554. (total_dec_frame_buffering[0] << 0)
  555. );
  556. WRITE_VREG(MAILBOX_DATA_1, ref_size);
  557. WRITE_VREG(MAILBOX_COMMAND, CMD_FINISHED);
  558. if(dbg_mode&0x1){
  559. printk("End H264 display buffer allocation for view 0\n");
  560. }
  561. if(frame_width == 0){
  562. frame_width = mb_width<<4;
  563. }
  564. if(frame_height == 0){
  565. frame_height = mb_height<<4;
  566. if(frame_height == 1088) frame_height = 1080;
  567. }
  568. break;
  569. case CMD_ALLOC_VIEW_1:
  570. if(dbg_mode&0x1){
  571. printk("Start H264 display buffer allocation for view 1\n");
  572. }
  573. if((dpb_start_addr[0] == -1) | (dpb_start_addr[1] == -1)){
  574. printk("Error : allocation view 1 before view 0 !!!\n");
  575. break;
  576. }
  577. ret = READ_VREG(MAILBOX_DATA_0);
  578. level_idc = (ret >> 24) & 0xff;
  579. max_reference_frame_num = (ret >> 16) & 0xff;
  580. mb_width = (ret >> 8) & 0xff;
  581. mb_height = (ret >> 0) & 0xff;
  582. max_dec_frame_buffering[1] = get_max_dec_frame_buf_size(level_idc, max_reference_frame_num, mb_width, mb_height);
  583. if(max_dec_frame_buffering[1] != max_dec_frame_buffering[0]){
  584. printk(" Warning : view0/1 max_dec_frame_buffering different : 0x%x/0x%x, Use View0\n",
  585. max_dec_frame_buffering[0], max_dec_frame_buffering[1]);
  586. max_dec_frame_buffering[1] = max_dec_frame_buffering[0];
  587. }
  588. total_dec_frame_buffering[1] = max_dec_frame_buffering[1] + DISPLAY_BUFFER_NUM;
  589. mb_width = (mb_width+3) & 0xfffffffc;
  590. mb_height = (mb_height+3) & 0xfffffffc;
  591. dpb_size = mb_width * mb_height * 384;
  592. ref_size = mb_width * mb_height * 96;
  593. if(dbg_mode&0x1){
  594. printk("dpb_size: 0x%x\n", dpb_size);
  595. printk("ref_size: 0x%x\n", ref_size);
  596. printk("total_dec_frame_buffering[1] : 0x%x\n", total_dec_frame_buffering[1]);
  597. printk("max_reference_frame_num: 0x%x\n", max_reference_frame_num);
  598. }
  599. ref_start_addr[1] = dpb_start_addr[1] +
  600. (dpb_size * total_dec_frame_buffering[1]);
  601. dpb_start_addr[2] = ref_start_addr[1] +
  602. (ref_size * (max_reference_frame_num+1));
  603. if(dbg_mode&0x1){
  604. printk("dpb_start_addr[1]: 0x%x\n", dpb_start_addr[1]);
  605. printk("ref_start_addr[1]: 0x%x\n", ref_start_addr[1]);
  606. printk("dpb_start_addr[2]: 0x%x\n", dpb_start_addr[2]);
  607. }
  608. if(dpb_start_addr[2] >= DECODE_BUFFER_END)
  609. {
  610. printk(" No enough memory for alloc view 1\n");
  611. goto exit;
  612. }
  613. index = CANVAS_INDEX_START + total_dec_frame_buffering[0] * 3;
  614. ANC_CANVAS_ADDR = ANC0_CANVAS_ADDR + total_dec_frame_buffering[0];
  615. ret = init_canvas(dpb_start_addr[1], dpb_size, total_dec_frame_buffering[1], mb_width, mb_height, buffer_spec1);
  616. if(ret == -1) {
  617. printk(" Un-expected memory alloc problem\n");
  618. goto exit;
  619. }
  620. WRITE_VREG(REF_START_VIEW_1, video_domain_addr(ref_start_addr[1]));
  621. WRITE_VREG(MAILBOX_DATA_0,
  622. (max_dec_frame_buffering[1] << 8) |
  623. (total_dec_frame_buffering[1] << 0)
  624. );
  625. WRITE_VREG(MAILBOX_DATA_1, ref_size);
  626. WRITE_VREG(MAILBOX_COMMAND, CMD_FINISHED);
  627. if(dbg_mode&0x1){
  628. printk("End H264 display buffer allocation for view 1\n");
  629. }
  630. if(frame_width == 0){
  631. frame_width = mb_width<<4;
  632. }
  633. if(frame_height == 0){
  634. frame_height = mb_height<<4;
  635. if(frame_height == 1088) frame_height = 1080;
  636. }
  637. break;
  638. case CMD_FRAME_DISPLAY:
  639. ret = READ_VREG(MAILBOX_DATA_0);
  640. display_buff_id = (ret >> 0) & 0x3f;
  641. display_view_id = (ret >> 6) & 0x3;
  642. drop_status = (ret >> 8) & 0x1;
  643. display_POC = READ_VREG(MAILBOX_DATA_1);
  644. stream_offset = READ_VREG(MAILBOX_DATA_2);
  645. //if (display_view_id == 0)
  646. //printk("view_id=%d,buff_id=%d,offset=%d, display_POC = %d,ret=0x%x\n", display_view_id, display_buff_id, stream_offset, display_POC, ret);
  647. WRITE_VREG(MAILBOX_COMMAND, CMD_FINISHED);
  648. #ifdef DEBUG_SKIP
  649. view_total++;
  650. if (drop_status)
  651. view_dropped++;
  652. #endif
  653. if(dbg_mode&0x1){
  654. printk(" H264 display frame ready -------------- View : %x, Buffer : %x\n", display_view_id, display_buff_id);
  655. printk(" H264 display frame POC -------------- Buffer : %x, POC : %x\n", display_buff_id, display_POC);
  656. printk("H264 display frame ready\n");
  657. }
  658. if(dbg_mode&0x10){
  659. if((dbg_mode&0x20)==0){
  660. while(READ_VREG(BUFFER_RECYCLE) !=0) {}
  661. WRITE_VREG(BUFFER_RECYCLE, (display_view_id<<8)|(display_buff_id+1));
  662. display_buff_id = -1;
  663. display_view_id = -1;
  664. display_POC = -1;
  665. }
  666. }
  667. else{
  668. mvc_buf_t *p = NULL, *ptmp;
  669. unsigned char in_list_flag = 0;
  670. ulong fiq_flag;
  671. raw_local_save_flags(fiq_flag);
  672. local_fiq_disable();
  673. list_for_each_entry_safe(p, ptmp, &ready_list_head, list) {
  674. if(p->display_POC == display_POC){
  675. if(display_view_id == 0){
  676. if(p->view0_buff_id>=0){
  677. #ifdef DEBUG_PTS
  678. dump_ready_list();
  679. #endif
  680. printk("H264MVC Warning, view0_buff_id is %d, not -1\n", p->view0_buff_id);
  681. }
  682. p->view0_buff_id = display_buff_id;
  683. p->view0_drop = drop_status;
  684. p->stream_offset = stream_offset;
  685. }
  686. else{
  687. if(p->view1_buff_id>=0){
  688. #ifdef DEBUG_PTS
  689. dump_ready_list();
  690. #endif
  691. printk("H264MVC Warning, view1_buff_id is %d, not -1\n", p->view1_buff_id);
  692. }
  693. p->view1_drop = drop_status;
  694. p->view1_buff_id = display_buff_id;
  695. }
  696. in_list_flag = 1;
  697. break;
  698. }
  699. }
  700. if(in_list_flag == 0){
  701. if(list_empty(&free_list_head)){
  702. printk("H264MVC Error, free_list empty\n");
  703. }
  704. else{
  705. p = list_first_entry(&free_list_head, struct mvc_buf_s, list);
  706. p->display_POC = display_POC;
  707. if(display_view_id == 0){
  708. p->view0_buff_id = display_buff_id;
  709. p->view0_drop = drop_status;
  710. p->stream_offset = stream_offset;
  711. }
  712. else{
  713. p->view1_buff_id = display_buff_id;
  714. p->view1_drop = drop_status;
  715. }
  716. #if 1
  717. if (pts_lookup_offset(PTS_TYPE_VIDEO, p->stream_offset, &p->vframe.pts, 0) != 0) {
  718. p->vframe.pts = 0;
  719. }
  720. #else
  721. p->vframe.pts = 0;
  722. #endif
  723. set_frame_info(&p->vframe);
  724. in_list_flag = 1;
  725. list_del(&(p->list));
  726. list_add_tail(&(p->list), &ready_list_head);
  727. vf_notify_receiver(PROVIDER_NAME,VFRAME_EVENT_PROVIDER_VFRAME_READY,NULL);
  728. }
  729. }
  730. raw_local_irq_restore(fiq_flag);
  731. if(in_list_flag){
  732. display_buff_id = -1;
  733. display_view_id = -1;
  734. display_POC = -1;
  735. stream_offset = -1;
  736. }
  737. }
  738. break;
  739. default : break;
  740. }
  741. exit:
  742. #ifdef HANDLE_h264mvc_IRQ
  743. return IRQ_HANDLED;
  744. #else
  745. return;
  746. #endif
  747. }
  748. static void recycle_vframe(void)
  749. {
  750. int cnt = 0;
  751. mvc_buf_t *p = NULL, *ptmp;
  752. list_for_each_entry_safe(p, ptmp, &recycle_list_head, list) {
  753. cnt++;
  754. }
  755. if((!list_empty(&recycle_list_head))&&
  756. (READ_VREG(BUFFER_RECYCLE) ==0)){
  757. mvc_buf_t* mvc_buf;
  758. ulong fiq_flag;
  759. raw_local_save_flags(fiq_flag);
  760. local_fiq_disable();
  761. mvc_buf = list_first_entry(&recycle_list_head, struct mvc_buf_s, list);
  762. if(mvc_buf->view0_buff_id >= 0){
  763. WRITE_VREG(BUFFER_RECYCLE, (0<<8)|(mvc_buf->view0_buff_id+1));
  764. mvc_buf->view0_buff_id = -1;
  765. }
  766. else if(mvc_buf->view1_buff_id >= 0){
  767. WRITE_VREG(BUFFER_RECYCLE, (1<<8)|(mvc_buf->view1_buff_id+1));
  768. mvc_buf->view1_buff_id = -1;
  769. }
  770. if((mvc_buf->view0_buff_id < 0)&&
  771. (mvc_buf->view1_buff_id < 0)){
  772. mvc_buf->display_POC = -1;
  773. mvc_buf->view0_drop = 0;
  774. mvc_buf->view1_drop = 0;
  775. list_del(&mvc_buf->list);
  776. list_add_tail(&mvc_buf->list, &free_list_head);
  777. }
  778. raw_local_irq_restore(fiq_flag);
  779. }
  780. }
  781. static void vh264mvc_put_timer_func(unsigned long arg)
  782. {
  783. struct timer_list *timer = (struct timer_list *)arg;
  784. if((dbg_mode&0x30)==0x30){
  785. if(display_buff_id >=0 ){
  786. if(dbg_cmd==1){
  787. while(READ_VREG(BUFFER_RECYCLE) !=0) {}
  788. WRITE_VREG(BUFFER_RECYCLE, (display_view_id<<8)|(display_buff_id+1));
  789. display_buff_id = -1;
  790. display_view_id = -1;
  791. display_POC = -1;
  792. dbg_cmd = 0;
  793. }
  794. }
  795. }
  796. recycle_vframe();
  797. #ifndef HANDLE_h264mvc_IRQ
  798. if(display_buff_id<0){
  799. vh264mvc_isr();
  800. }
  801. #endif
  802. timer->expires = jiffies + PUT_INTERVAL;
  803. add_timer(timer);
  804. }
  805. int vh264mvc_dec_status(struct vdec_status *vstatus)
  806. {
  807. vstatus->width = frame_width;
  808. vstatus->height = frame_height;
  809. if (frame_dur != 0) {
  810. vstatus->fps = 96000 / frame_dur;
  811. } else {
  812. vstatus->fps = -1;
  813. }
  814. vstatus->error_count = READ_VREG(AV_SCRATCH_D);
  815. vstatus->status = stat;
  816. return 0;
  817. }
  818. int vh264mvc_set_trickmode(unsigned long trickmode)
  819. {
  820. if (trickmode == TRICKMODE_I) {
  821. WRITE_VREG(AV_SCRATCH_F, (READ_VREG(AV_SCRATCH_F) & 0xfffffffc) | 2);
  822. trickmode_i = 1;
  823. } else if (trickmode == TRICKMODE_NONE) {
  824. WRITE_VREG(AV_SCRATCH_F, READ_VREG(AV_SCRATCH_F) & 0xfffffffc);
  825. trickmode_i = 0;
  826. }
  827. return 0;
  828. }
  829. static void H264_DECODE_INIT(void)
  830. {
  831. int i;
  832. i = READ_VREG(DECODE_SKIP_PICTURE);
  833. #ifdef CONFIG_ARCH_MESON6
  834. WRITE_MPEG_REG(DOS_SW_RESET0, (1<<7) | (1<<6) | (7<<3));
  835. WRITE_MPEG_REG(DOS_SW_RESET0, 0);
  836. READ_MPEG_REG(RESET0_REGISTER);
  837. READ_MPEG_REG(RESET0_REGISTER);
  838. READ_MPEG_REG(RESET0_REGISTER);
  839. WRITE_MPEG_REG(DOS_SW_RESET0, (1<<7) | (1<<6) | (7<<3));
  840. WRITE_MPEG_REG(DOS_SW_RESET0, 0);
  841. WRITE_MPEG_REG(DOS_SW_RESET0, (1<<9) | (1<<8));
  842. WRITE_MPEG_REG(DOS_SW_RESET0, 0);
  843. READ_MPEG_REG(RESET0_REGISTER);
  844. READ_MPEG_REG(RESET0_REGISTER);
  845. READ_MPEG_REG(RESET0_REGISTER);
  846. #else
  847. WRITE_MPEG_REG(RESET0_REGISTER, RESET_IQIDCT | RESET_MC | RESET_VLD_PART);
  848. READ_MPEG_REG(RESET0_REGISTER);
  849. WRITE_MPEG_REG(RESET0_REGISTER, RESET_IQIDCT | RESET_MC | RESET_VLD_PART);
  850. WRITE_MPEG_REG(RESET2_REGISTER, RESET_PIC_DC | RESET_DBLK);
  851. #endif
  852. // Wait for some time for RESET
  853. READ_VREG(DECODE_SKIP_PICTURE);
  854. READ_VREG(DECODE_SKIP_PICTURE);
  855. WRITE_VREG(DECODE_SKIP_PICTURE, i);
  856. // fill_weight_pred
  857. WRITE_VREG(MC_MPORT_CTRL, 0x0300);
  858. for(i=0; i<192; i++) WRITE_VREG(MC_MPORT_DAT, 0x100);
  859. WRITE_VREG(MC_MPORT_CTRL, 0);
  860. WRITE_VREG(MB_WIDTH, 0xff); // invalid mb_width
  861. // set slice start to 0x000000 or 0x000001 for check more_rbsp_data
  862. WRITE_VREG(SLICE_START_BYTE_01, 0x00000000);
  863. WRITE_VREG(SLICE_START_BYTE_23, 0x01010000);
  864. WRITE_VREG(MPEG1_2_REG, 1); // set to mpeg2 to enable mismatch logic
  865. WRITE_VREG(VLD_ERROR_MASK, 0x1011); // disable COEF_GT_64 , error_m4_table and voff_rw_err
  866. // Config MCPU Amrisc interrupt
  867. WRITE_VREG(ASSIST_AMR1_INT0, 0x1 ); // viu_vsync_int
  868. WRITE_VREG(ASSIST_AMR1_INT1, 0x5 ); // mbox_isr
  869. WRITE_VREG(ASSIST_AMR1_INT2, 0x8 ); // vld_isr
  870. WRITE_VREG(ASSIST_AMR1_INT3, 0x15); // vififo_empty
  871. WRITE_VREG(ASSIST_AMR1_INT4, 0xd ); // rv_ai_mb_finished_int
  872. WRITE_VREG(ASSIST_AMR1_INT7, 0x14); // dcac_dma_done
  873. // Config MCPU Amrisc interrupt
  874. WRITE_VREG(ASSIST_AMR1_INT5, 0x9 ); // MCPU interrupt
  875. WRITE_VREG(ASSIST_AMR1_INT6, 0x17); // CCPU interrupt
  876. WRITE_VREG(CPC_P, 0xc00); // CCPU Code will start from 0xc00
  877. WRITE_VREG(CINT_VEC_BASE, (0xc20>>5));
  878. #if 0
  879. WRITE_VREG(POWER_CTL_VLD, READ_VREG(POWER_CTL_VLD) | (0 << 10) | (1 << 9) | (1 << 6));
  880. #else
  881. WRITE_VREG(
  882. POWER_CTL_VLD,
  883. (
  884. (1<<10) | // disable cabac_step_2
  885. (1<<9) | // viff_drop_flag_en
  886. (1<<6) // h264_000003_en
  887. )
  888. );
  889. #endif
  890. WRITE_VREG(M4_CONTROL_REG, (1<<13)); // H264_DECODE_INFO - h264_en
  891. WRITE_VREG(CANVAS_START , CANVAS_INDEX_START);
  892. #if 1
  893. WRITE_VREG(WORKSPACE_START, video_domain_addr(work_space_adr)); // Start Address of Workspace (UCODE, temp_data...)
  894. #else
  895. WRITE_VREG(WORKSPACE_START, 0x05000000); // Start Address of Workspace (UCODE, temp_data...)
  896. #endif
  897. WRITE_VREG(SPS_STATUS, 0); // Clear all sequence parameter set available
  898. WRITE_VREG(PPS_STATUS, 0); // Clear all picture parameter set available
  899. WRITE_VREG(CURRENT_UCODE, 0xff); // Set current microcode to NULL
  900. WRITE_VREG(CURRENT_SPS_PPS, 0xffff); // Set current SPS/PPS to NULL
  901. WRITE_VREG(DECODE_STATUS, 1); // Set decode status to DECODE_START_HEADER
  902. }
  903. static void vh264mvc_prot_init(void)
  904. {
  905. while (READ_VREG(DCAC_DMA_CTRL) & 0x8000) {
  906. ;
  907. }
  908. while (READ_VREG(LMEM_DMA_CTRL) & 0x8000) {
  909. ; // reg address is 0x350
  910. }
  911. /* clear mailbox interrupt */
  912. WRITE_VREG(ASSIST_MBOX1_CLR_REG, 1);
  913. /* enable mailbox interrupt */
  914. WRITE_VREG(ASSIST_MBOX1_MASK, 1);
  915. /* disable PSCALE for hardware sharing */
  916. WRITE_VREG(PSCALE_CTRL, 0);
  917. H264_DECODE_INIT();
  918. #ifdef CONFIG_ARCH_MESON6
  919. WRITE_MPEG_REG(DOS_SW_RESET0, (1<<11));
  920. WRITE_MPEG_REG(DOS_SW_RESET0, 0);
  921. READ_MPEG_REG(DOS_SW_RESET0);
  922. READ_MPEG_REG(DOS_SW_RESET0);
  923. READ_MPEG_REG(DOS_SW_RESET0);
  924. #else
  925. WRITE_MPEG_REG(RESET0_REGISTER, 0x80); // RESET MCPU
  926. #endif
  927. WRITE_VREG(MAILBOX_COMMAND, 0);
  928. WRITE_VREG(BUFFER_RECYCLE, 0);
  929. WRITE_VREG(DROP_CONTROL, 0);
  930. }
  931. static void vh264mvc_local_init(void)
  932. {
  933. display_buff_id = -1;
  934. display_view_id = -1;
  935. display_POC = -1;
  936. no_dropping_cnt = 0;
  937. #ifdef DEBUG_PTS
  938. pts_missed = 0;
  939. pts_hit = 0;
  940. #endif
  941. #ifdef DEBUG_SKIP
  942. view_total = 0;
  943. view_dropped = 0;
  944. #endif
  945. //vh264mvc_ratio = vh264mvc_amstream_dec_info.ratio;
  946. vh264mvc_ratio = 0x100;
  947. //frame_width = vh264mvc_amstream_dec_info.width;
  948. //frame_height = vh264mvc_amstream_dec_info.height;
  949. frame_dur = vh264mvc_amstream_dec_info.rate;
  950. if(frame_dur == 0){
  951. frame_dur = 96000/24;
  952. }
  953. pts_outside = ((u32)vh264mvc_amstream_dec_info.param) & 0x01;
  954. sync_outside = ((u32)vh264mvc_amstream_dec_info.param & 0x02) >> 1;
  955. /**/
  956. dpb_start_addr[0] = -1;
  957. dpb_start_addr[1] = -1;
  958. max_dec_frame_buffering[0] = -1;
  959. max_dec_frame_buffering[1] = -1;
  960. init_vf_buf();
  961. return;
  962. }
  963. static s32 vh264mvc_init(void)
  964. {
  965. void __iomem *p = ioremap_nocache(work_space_adr, work_space_size);
  966. if (!p) {
  967. printk("\nvh264mvc_init: Cannot remap ucode swapping memory\n");
  968. return -ENOMEM;
  969. }
  970. printk("\nvh264mvc_init\n");
  971. init_timer(&recycle_timer);
  972. stat |= STAT_TIMER_INIT;
  973. vh264mvc_local_init();
  974. amvdec_enable();
  975. if (amvdec_loadmc(vh264mvc_mc) < 0) {
  976. amvdec_disable();
  977. return -EBUSY;
  978. }
  979. memcpy(p,
  980. vh264mvc_header_mc, sizeof(vh264mvc_header_mc));
  981. memcpy((void *)((ulong)p + 0x1000),
  982. vh264mvc_mmco_mc, sizeof(vh264mvc_mmco_mc));
  983. memcpy((void *)((ulong)p + 0x3000),
  984. vh264mvc_slice_mc, sizeof(vh264mvc_slice_mc));
  985. iounmap(p);
  986. stat |= STAT_MC_LOAD;
  987. /* enable AMRISC side protocol */
  988. vh264mvc_prot_init();
  989. #ifdef HANDLE_h264mvc_IRQ
  990. if (request_irq(INT_MAILBOX_1A, vh264mvc_isr,
  991. IRQF_SHARED, "vh264mvc-irq", (void *)vh264mvc_dec_id)) {
  992. printk("vh264mvc irq register error.\n");
  993. amvdec_disable();
  994. return -ENOENT;
  995. }
  996. #endif
  997. stat |= STAT_ISR_REG;
  998. vf_provider_init(&vh264mvc_vf_prov, PROVIDER_NAME, &vh264mvc_vf_provider, NULL);
  999. vf_reg_provider(&vh264mvc_vf_prov);
  1000. vf_notify_receiver(PROVIDER_NAME,VFRAME_EVENT_PROVIDER_START,NULL);
  1001. stat |= STAT_VF_HOOK;
  1002. recycle_timer.data = (ulong) & recycle_timer;
  1003. recycle_timer.function = vh264mvc_put_timer_func;
  1004. recycle_timer.expires = jiffies + PUT_INTERVAL;
  1005. add_timer(&recycle_timer);
  1006. stat |= STAT_TIMER_ARM;
  1007. amvdec_start();
  1008. stat |= STAT_VDEC_RUN;
  1009. set_vdec_func(&vh264mvc_dec_status);
  1010. //set_trickmode_func(&vh264mvc_set_trickmode);
  1011. return 0;
  1012. }
  1013. static int vh264mvc_stop(void)
  1014. {
  1015. if (stat & STAT_VDEC_RUN) {
  1016. amvdec_stop();
  1017. stat &= ~STAT_VDEC_RUN;
  1018. }
  1019. if (stat & STAT_ISR_REG) {
  1020. WRITE_VREG(ASSIST_MBOX1_MASK, 0);
  1021. #ifdef HANDLE_h264mvc_IRQ
  1022. free_irq(INT_MAILBOX_1A,
  1023. (void *)vh264mvc_dec_id);
  1024. #endif
  1025. stat &= ~STAT_ISR_REG;
  1026. }
  1027. if (stat & STAT_TIMER_ARM) {
  1028. del_timer_sync(&recycle_timer);
  1029. stat &= ~STAT_TIMER_ARM;
  1030. }
  1031. if (stat & STAT_VF_HOOK) {
  1032. ulong flags;
  1033. spin_lock_irqsave(&lock, flags);
  1034. spin_unlock_irqrestore(&lock, flags);
  1035. vf_unreg_provider(&vh264mvc_vf_prov);
  1036. stat &= ~STAT_VF_HOOK;
  1037. }
  1038. amvdec_disable();
  1039. uninit_vf_buf();
  1040. return 0;
  1041. }
  1042. static void error_do_work(struct work_struct *work)
  1043. {
  1044. if (atomic_read(&vh264mvc_active)) {
  1045. vh264mvc_stop();
  1046. vh264mvc_init();
  1047. }
  1048. }
  1049. static int amvdec_h264mvc_probe(struct platform_device *pdev)
  1050. {
  1051. struct resource *mem;
  1052. int buf_size;
  1053. printk("amvdec_h264mvc probe start.\n");
  1054. if (!(mem = platform_get_resource(pdev, IORESOURCE_MEM, 0))) {
  1055. printk("\namvdec_h264mvc memory resource undefined.\n");
  1056. return -EFAULT;
  1057. }
  1058. buf_size = mem->end - mem->start + 1;
  1059. //buf_offset = mem->start - DEF_BUF_START_ADDR;
  1060. work_space_adr = mem->start;
  1061. DECODE_BUFFER_START = work_space_adr + work_space_size;
  1062. DECODE_BUFFER_END = mem->start + buf_size;
  1063. printk("work_space_adr %x, DECODE_BUFFER_START %x, DECODE_BUFFER_END %x\n", work_space_adr, DECODE_BUFFER_START, DECODE_BUFFER_END);
  1064. memcpy(&vh264mvc_amstream_dec_info, (void *)mem[1].start, sizeof(vh264mvc_amstream_dec_info));
  1065. if (vh264mvc_init() < 0) {
  1066. printk("\namvdec_h264mvc init failed.\n");
  1067. return -ENODEV;
  1068. }
  1069. INIT_WORK(&error_wd_work, error_do_work);
  1070. atomic_set(&vh264mvc_active, 1);
  1071. printk("amvdec_h264mvc probe end.\n");
  1072. return 0;
  1073. }
  1074. static int amvdec_h264mvc_remove(struct platform_device *pdev)
  1075. {
  1076. printk("amvdec_h264mvc_remove\n");
  1077. vh264mvc_stop();
  1078. atomic_set(&vh264mvc_active, 0);
  1079. #ifdef DEBUG_PTS
  1080. printk("pts missed %ld, pts hit %ld, pts_outside %d, duration %d, sync_outside %d\n",
  1081. pts_missed, pts_hit, pts_outside, frame_dur, sync_outside);
  1082. #endif
  1083. #ifdef DEBUG_SKIP
  1084. printk("view_total = %ld, dropped %ld\n", view_total, view_dropped);
  1085. #endif
  1086. return 0;
  1087. }
  1088. /****************************************/
  1089. static struct platform_driver amvdec_h264mvc_driver = {
  1090. .probe = amvdec_h264mvc_probe,
  1091. .remove = amvdec_h264mvc_remove,
  1092. #ifdef CONFIG_PM
  1093. .suspend = amvdec_suspend,
  1094. .resume = amvdec_resume,
  1095. #endif
  1096. .driver = {
  1097. .name = DRIVER_NAME,
  1098. }
  1099. };
  1100. static int __init amvdec_h264mvc_driver_init_module(void)
  1101. {
  1102. printk("amvdec_h264mvc module init\n");
  1103. if (platform_driver_register(&amvdec_h264mvc_driver)) {
  1104. printk("failed to register amvdec_h264mvc driver\n");
  1105. return -ENODEV;
  1106. }
  1107. return 0;
  1108. }
  1109. static void __exit amvdec_h264mvc_driver_remove_module(void)
  1110. {
  1111. printk("amvdec_h264mvc module remove.\n");
  1112. platform_driver_unregister(&amvdec_h264mvc_driver);
  1113. }
  1114. /****************************************/
  1115. module_param(stat, uint, 0664);
  1116. MODULE_PARM_DESC(stat, "\n amvdec_h264mvc stat \n");
  1117. module_param(dbg_mode, uint, 0664);
  1118. MODULE_PARM_DESC(dbg_mode, "\n amvdec_h264mvc dbg mode \n");
  1119. module_param(view_mode, uint, 0664);
  1120. MODULE_PARM_DESC(view_mode, "\n amvdec_h264mvc view mode \n");
  1121. module_param(dbg_cmd, uint, 0664);
  1122. MODULE_PARM_DESC(dbg_mode, "\n amvdec_h264mvc cmd mode \n");
  1123. module_param(drop_rate, uint, 0664);
  1124. MODULE_PARM_DESC(dbg_mode, "\n amvdec_h264mvc drop rate \n");
  1125. module_init(amvdec_h264mvc_driver_init_module);
  1126. module_exit(amvdec_h264mvc_driver_remove_module);
  1127. MODULE_DESCRIPTION("AMLOGIC h264mvc Video Decoder Driver");
  1128. MODULE_LICENSE("GPL");
  1129. MODULE_AUTHOR("Chen Zhang <chen.zhang@amlogic.com>");