hdmi_processing.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. #include "drv_types.h"
  2. #include <linux/module.h>
  3. #include "hdmi_dbg.h"
  4. #include "hdmi_cfg.h"
  5. #include "hdmi_hw.h"
  6. #include "hdmi_notice.h"
  7. #include "hdmi_processing.h"
  8. #include "hdmi_video.h"
  9. #include "hdmi_hpd.h"
  10. #include "cec.h"
  11. #include "drv_hdmi_internal.h"
  12. #include "hdmi.h"
  13. #include "sysreg.h"
  14. #include "hdmi_time.h"
  15. #include "../../module_include/drv_gpio.h"
  16. #ifdef CONFIG_HDMI_SUPPORT_MHL
  17. #include "cbus_drv.h"
  18. #include "cbus_mid.h"
  19. #endif
  20. static UINT32 local_signal_status;
  21. static BOOL bHdmiMode = false;
  22. static VIP_InterfaceKIC stKic;
  23. static INT32 active_run = 0;
  24. static struct timer_list active_timer;
  25. static struct timer_list nosignal_timer;
  26. static struct timer_list turn_off_sw_5V_timer;
  27. static struct timer_list signal_monitor_timer;
  28. static struct work_struct wq_active;
  29. static struct work_struct wq_nosignal;
  30. static struct work_struct wq_avi_change;
  31. static struct work_struct wq_turn_off_sw_5V;
  32. static void WQ_ACTIVE(void *dummy);
  33. static UINT8 WQ_NOSIGNAL_CNT=0;
  34. static UINT8 VBUS_TOGGLE_CNT=0;
  35. static void WQ_NOSIGNAL(void *dummy);
  36. static void WQ_AVI_CHANGE(void *dummy);
  37. static void NOSIGNAL_TIMER(void *dummy);
  38. static void nosignal_timer_schedule(UINT32 delay_ms);
  39. static void nosignal_timer_remove(void);
  40. static void ACTIVE_TIMER(void* dummy);
  41. BOOL DRV_HDMI_IsHDMIMode(void)
  42. {
  43. return bHdmiMode;
  44. }
  45. void hdmi_flag_set(SIGNAL_T s)
  46. {
  47. local_signal_status |= (1 << s);
  48. }
  49. void hdmi_flag_clear(SIGNAL_T s)
  50. {
  51. local_signal_status = local_signal_status & (~(1 << s));
  52. }
  53. BOOL hdmi_flag_check(SIGNAL_T s)
  54. {
  55. return (local_signal_status & (1 << s)) == 0?FALSE:TRUE;
  56. }
  57. void hdmi_flag_reset(void)
  58. {
  59. local_signal_status = 0;
  60. }
  61. //==========================================
  62. // Work Queue Function
  63. //==========================================
  64. static void WQ_ACTIVE(void *dummy)
  65. {
  66. UINT8 bSignalStatus;
  67. WQ_NOSIGNAL_CNT =0;
  68. VBUS_TOGGLE_CNT=0;
  69. HDMI_RegisterWrite(HDMIRX_R_VIDEO_MUTE, 0);
  70. bSignalStatus = HDMI_GetInputInformation(&stKic);
  71. signal_monitor_timer_schedule(10);
  72. switch (bSignalStatus)
  73. {
  74. default:
  75. case 0: /* Not Support */
  76. HDMI_NoticeHandler(HDMINOTICE_NOTSUPPORT, "WQ_ACTIVE");
  77. break;
  78. case 1: /* Support */
  79. #ifdef SUPPORT_XVYCC
  80. if(HDMI_RegisterRead(HDMIRX_R_GBD_exist) == 1) //if Gamut Boundary Description exist, handle xvycc
  81. {
  82. hdmi_handler_xvycc();
  83. }
  84. #endif
  85. HDMI_NoticeHandler(HDMINOTICE_HAVESIGNAL, "WQ_ACTIVE");
  86. VIP_SendInformation(&stKic);
  87. /* Indicate flow control that hdmi/dvi mode */
  88. if (HDMI_RegisterRead(HDMIRX_R_HDMI_en) == 1)
  89. {
  90. HDMI_NoticeAudioMode(HDMI_MODE);
  91. bHdmiMode = true;
  92. }
  93. else
  94. {
  95. HDMI_NoticeAudioMode(DVI_MODE);
  96. bHdmiMode = false;
  97. }
  98. #ifdef HDMI_DDC5V_WORKAROUND
  99. HDMI_TurnOff_SW_5V_schedule(2000, hdmi_get_cur_port()); //restart HW DDC 5V detection after signal is stable
  100. #endif
  101. break;
  102. case 2: /* No Signal */
  103. HDMI_NoticeHandler(HDMINOTICE_NOSIGNAL, "WQ_ACTIVE");
  104. break;
  105. }
  106. }
  107. extern BOOL MHL_CABLE_IN;
  108. static void WQ_NOSIGNAL(void *dummy)
  109. {
  110. BOOL bNotSupport;
  111. if (HDMI_RegisterRead(HDMIRX_R_HDMI_en)) //HDMI mode
  112. {
  113. bNotSupport = ((HDMI_RegisterRead(HDMIRX_ref_freq_cnt) * 26672410/1000000) > 0xa00); //246.7MHz
  114. }
  115. else //DVI mode
  116. {
  117. bNotSupport = ((HDMI_RegisterRead(HDMIRX_ref_freq_cnt) * 26672410/1000000) > 0x6b0); //165MHz
  118. }
  119. #ifdef CONFIG_HDMI_SUPPORT_MHL
  120. #ifdef CONFIG_HDMI_MHL_PORT
  121. if((HDMI_RegisterRead(HDMIRX_IN_RANGE)==0)&&(DrvHDMIPortSelectBitsGet()==CONFIG_HDMI_MHL_PORT))
  122. {
  123. if(( MHL_ADOPTER_ID_Check()== FALSE)&&(VBUS_TOGGLE_CNT==0)&&(GPIOGetValueByPinFunc(GPIO_PIN_MHL_CD_SENSE_DETECT)==1))
  124. {
  125. #if 0
  126. printk("MHL TOGGLE Vbus1!!!!!! \n");
  127. sysset_VbusEnable(0);
  128. HDMI_DelayMs(100);
  129. sysset_VbusEnable(1);
  130. VBUS_TOGGLE_CNT ++;
  131. #endif
  132. }
  133. }
  134. #endif
  135. #endif
  136. #if 1
  137. if(HDMI_RegisterRead(HDMIRX_PHYPLLLOCK))
  138. {
  139. if(WQ_NOSIGNAL_CNT<3)
  140. {
  141. printk("HDMIRX_PHYPLLLOCK!!!!!! \n");
  142. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 0);
  143. HDMI_DelayMs(2);
  144. /* Power On PHY */
  145. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 1);
  146. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 1);
  147. HDMI_RegisterWrite(HDMIRX_R_rst_n, 0);
  148. HDMI_SetPLL_ByFreq();
  149. HDMI_DelayMs(2);
  150. HDMI_RegisterWrite(HDMIRX_R_rst_n, 1);
  151. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 0);
  152. #ifdef CONFIG_HDMI_MHL_PORT
  153. if((MHL_CABLE_IN == TRUE)&&(DrvHDMIPortSelectBitsGet()==CONFIG_HDMI_MHL_PORT))
  154. {
  155. printk("MHL reset cbus!!!!!! \n");
  156. //reset cbus
  157. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_cbus_reset, 1);
  158. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_debounce_reset, 1);
  159. HDMI_DelayMs(150);
  160. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_debounce_reset, 0);
  161. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_cbus_reset, 0);
  162. }
  163. #endif
  164. hdmi_signal_lock_check_start();
  165. WQ_NOSIGNAL_CNT++;
  166. }
  167. else if(WQ_NOSIGNAL_CNT<10)
  168. {
  169. printk("HDMIRX_PHYPLLLOCK!!!!!! \n");
  170. printk("Reset PLL!!!!!! \n");
  171. //Reset PLL
  172. HDMI_Reset_HDMI_PLL();
  173. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 0);
  174. HDMI_DelayMs(2);
  175. /* Power On PHY */
  176. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 1);
  177. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 1);
  178. HDMI_RegisterWrite(HDMIRX_R_rst_n, 0);
  179. HDMI_DelayMs(2);
  180. HDMI_RegisterWrite(HDMIRX_R_rst_n, 1);
  181. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 0);
  182. #ifdef CONFIG_HDMI_MHL_PORT
  183. if((MHL_CABLE_IN == TRUE)&&(DrvHDMIPortSelectBitsGet()==CONFIG_HDMI_MHL_PORT))
  184. {
  185. printk("MHL reset cbus!!!!!! \n");
  186. //reset cbus
  187. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_cbus_reset, 1);
  188. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_debounce_reset, 1);
  189. HDMI_DelayMs(150);
  190. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_debounce_reset, 0);
  191. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_cbus_reset, 0);
  192. }
  193. #endif
  194. hdmi_signal_lock_check_start();
  195. WQ_NOSIGNAL_CNT++;
  196. }
  197. else
  198. {
  199. /* mantis 27479, chroma 2402 unsupport timing issue*/
  200. #ifdef HDMI_DDC5V_WORKAROUND
  201. HDMI_TurnOff_SW_5V_schedule(0, hdmi_get_cur_port()); //restart HW DDC 5V detection after signal is stable
  202. #endif
  203. WQ_NOSIGNAL_CNT =0;
  204. //HDMI_NoticeHandler(HDMINOTICE_NOTSUPPORT, "NOSIGNAL_TIMER");
  205. HDMI_NoticeHandler(HDMINOTICE_NOSIGNAL, "NOSIGNAL_TIMER");
  206. }
  207. }
  208. #ifdef CONFIG_HDMI_SUPPORT_MHL
  209. #ifdef CONFIG_HDMI_MHL_PORT
  210. else if((CbusMidGetDevCapReadyBit()==FALSE)&&(MHL_CABLE_IN == TRUE)&&(DrvHDMIPortSelectBitsGet()==CONFIG_HDMI_MHL_PORT))
  211. {
  212. if(WQ_NOSIGNAL_CNT<26)
  213. {
  214. if((WQ_NOSIGNAL_CNT==5)||(WQ_NOSIGNAL_CNT==10)||(WQ_NOSIGNAL_CNT==15)||(WQ_NOSIGNAL_CNT==20)||(WQ_NOSIGNAL_CNT==25))
  215. {
  216. printk("MHL reset cbus!!!!!! \n");
  217. //reset cbus
  218. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_cbus_reset, 1);
  219. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_debounce_reset, 1);
  220. HDMI_DelayMs(150);
  221. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_debounce_reset, 0);
  222. HDMI_RegisterWrite(HDMIRX_CBUS_cfg_cbus_reset, 0);
  223. }
  224. #if 0
  225. if(( MHL_ADOPTER_ID_Check()== FALSE)&&((WQ_NOSIGNAL_CNT==10)||(WQ_NOSIGNAL_CNT==20))&&(GPIOGetValueByPinFunc(GPIO_PIN_MHL_CD_SENSE_DETECT)==1))
  226. {
  227. printk("MHL TOGGLE Vbus2!!!!!! \n");
  228. sysset_VbusEnable(0);
  229. HDMI_DelayMs(100);
  230. sysset_VbusEnable(1);
  231. VBUS_TOGGLE_CNT ++;
  232. }
  233. #endif
  234. hdmi_signal_check_start();
  235. WQ_NOSIGNAL_CNT++;
  236. }
  237. else
  238. {
  239. WQ_NOSIGNAL_CNT =0;
  240. VBUS_TOGGLE_CNT =0;
  241. #if 0
  242. if((HDMI_RegisterRead(HDMIRX_IN_RANGE)==0)&&(DrvHDMIPortSelectBitsGet()==CONFIG_HDMI_MHL_PORT))
  243. {
  244. if(( MHL_ADOPTER_ID_Check()== FALSE)&&(VBUS_TOGGLE_CNT==0)&&(GPIOGetValueByPinFunc(GPIO_PIN_MHL_CD_SENSE_DETECT)==1))
  245. {
  246. printk("MHL TOGGLE Vbus3!!!!!! \n");
  247. sysset_VbusEnable(0);
  248. HDMI_DelayMs(100);
  249. sysset_VbusEnable(1);
  250. }
  251. }
  252. #endif
  253. HDMI_NoticeHandler(HDMINOTICE_NOSIGNAL, "NOSIGNAL_TIMER");
  254. }
  255. }
  256. #endif
  257. #endif
  258. else
  259. #endif
  260. {
  261. if(HDMI_RegisterRead(HDMIRX_IN_RANGE))
  262. {
  263. if(WQ_NOSIGNAL_CNT<3)
  264. {
  265. HDMI_RegisterWrite(HDMIRX_PDACJ_CK, 0);//For No siglal issue
  266. HDMI_DelayMs(2);
  267. HDMI_RegisterWrite(HDMIRX_PDACJ_CK, 1);
  268. hdmi_signal_lock_check_start();
  269. WQ_NOSIGNAL_CNT++;
  270. }
  271. else
  272. {
  273. WQ_NOSIGNAL_CNT =0;
  274. VBUS_TOGGLE_CNT =0;
  275. //HDMI_NoticeHandler(HDMINOTICE_NOTSUPPORT, "NOSIGNAL_TIMER");
  276. HDMI_NoticeHandler(HDMINOTICE_NOSIGNAL, "NOSIGNAL_TIMER");
  277. }
  278. }
  279. else
  280. {
  281. WQ_NOSIGNAL_CNT =0;
  282. VBUS_TOGGLE_CNT =0;
  283. if (hdmi_get_hpd_at_cur_src() && bNotSupport)
  284. {
  285. //HDMI_NoticeHandler(HDMINOTICE_NOTSUPPORT, "NOSIGNAL_TIMER");
  286. HDMI_NoticeHandler(HDMINOTICE_NOSIGNAL, "NOSIGNAL_TIMER");
  287. }
  288. else
  289. {
  290. HDMI_NoticeHandler(HDMINOTICE_NOSIGNAL, "NOSIGNAL_TIMER");
  291. }
  292. }
  293. }
  294. }
  295. static void WQ_AVI_CHANGE(void *dummy)
  296. {
  297. if(HDMI_IsAviChanged(&stKic) == true)
  298. {
  299. HDMI_RegisterWrite(HDMIRX_R_VIDEO_MUTE, 1);
  300. VIP_MuteScreen();
  301. VIP_SendInformation(&stKic);
  302. /* Indicate flow control that hdmi/dvi mode */
  303. if(HDMI_RegisterRead(HDMIRX_R_HDMI_en) == 1)
  304. {
  305. HDMI_NoticeAudioMode(HDMI_MODE);
  306. bHdmiMode = true;
  307. }
  308. else
  309. {
  310. HDMI_NoticeAudioMode(DVI_MODE);
  311. bHdmiMode = false;
  312. }
  313. HDMI_RegisterWrite(HDMIRX_R_VIDEO_MUTE, 0);
  314. }
  315. }
  316. static void WQ_TURN_OFF_SW5V(UINT32 data)
  317. {
  318. if((HDMI_PORT_T)data != DRV_Get_GPIO5V_ARCPort()) //do not turn off SW 5V at ARC GPIO 5V port,workaround for SONY BDP-S360
  319. {
  320. sysset_HDMI_SW5V((HDMI_PORT_T)data, FALSE);
  321. }
  322. }
  323. //==========================================
  324. // Timer
  325. //==========================================
  326. /* no signal */
  327. static void NOSIGNAL_TIMER(void *dummy)
  328. {
  329. if (hdmi_flag_check(HAS_ACTIVE_DATA) == FALSE)
  330. {
  331. schedule_work(&wq_nosignal);
  332. }
  333. }
  334. static void nosignal_timer_schedule(UINT32 delay_ms)
  335. {
  336. hdmidbg("%s: check signal after %d ms\n", __FUNCTION__, delay_ms);
  337. del_timer(&nosignal_timer);
  338. nosignal_timer.expires = jiffies + ((HZ / 1000) * delay_ms) + HZ / 1000;
  339. nosignal_timer.data = (UINT32)NULL;
  340. nosignal_timer.function = (void (*)(ULONG))NOSIGNAL_TIMER;
  341. add_timer(&nosignal_timer);
  342. }
  343. static void nosignal_timer_remove(void)
  344. {
  345. del_timer(&nosignal_timer);
  346. }
  347. void hdmi_signal_check_start(void)
  348. {
  349. UINT32 delay_ms;
  350. UINT8 fInRange = HDMI_RegisterRead(HDMIRX_IN_RANGE);
  351. if(fInRange==0)
  352. {
  353. delay_ms = HDMI_INFORM_NOSIGNAL_DELAY_NO_5V;
  354. }
  355. else
  356. {
  357. /* Wait for Long Time if 5V is high, otherwise wait for Short Time */
  358. #ifdef HDMI_DDC5V_WORKAROUND
  359. #ifdef CONFIG_HDMI_SUPPORT_MHL
  360. #ifdef CONFIG_HDMI_MHL_PORT
  361. if((MHL_CABLE_IN == TRUE)&&(DrvHDMIPortSelectBitsGet()==CONFIG_HDMI_MHL_PORT))
  362. {
  363. delay_ms = HDMI_INFORM_NOSIGNAL_DELAY_NO_5V;
  364. }
  365. else
  366. {
  367. delay_ms = (CEC_Get_SW5V(hdmi_get_cur_port()) == DRV_5V_LEVEL_HIGH) ? HDMI_INFORM_NOSIGNAL_DELAY_WITH_5V : HDMI_INFORM_NOSIGNAL_DELAY_NO_5V;
  368. }
  369. #endif
  370. #else
  371. delay_ms = (CEC_Get_SW5V(hdmi_get_cur_port()) == DRV_5V_LEVEL_HIGH) ? HDMI_INFORM_NOSIGNAL_DELAY_WITH_5V : HDMI_INFORM_NOSIGNAL_DELAY_NO_5V;
  372. #endif
  373. #else
  374. #ifdef CONFIG_HDMI_SUPPORT_MHL
  375. #ifdef CONFIG_HDMI_MHL_PORT
  376. if((MHL_CABLE_IN == TRUE)&&(DrvHDMIPortSelectBitsGet()==CONFIG_HDMI_MHL_PORT))
  377. {
  378. delay_ms = HDMI_INFORM_NOSIGNAL_DELAY_NO_5V;
  379. }
  380. else
  381. {
  382. delay_ms = hdmi_get_hpd_at_cur_src() ? HDMI_INFORM_NOSIGNAL_DELAY_WITH_5V : HDMI_INFORM_NOSIGNAL_DELAY_NO_5V;
  383. }
  384. #endif
  385. #else
  386. delay_ms = hdmi_get_hpd_at_cur_src() ? HDMI_INFORM_NOSIGNAL_DELAY_WITH_5V : HDMI_INFORM_NOSIGNAL_DELAY_NO_5V;
  387. #endif
  388. #endif
  389. }
  390. hdmidbg("%s: check signal after %d ms\n", __FUNCTION__, delay_ms);
  391. nosignal_timer_schedule(delay_ms);
  392. }
  393. void hdmi_signal_lock_check_start(void)
  394. {
  395. nosignal_timer_schedule(1000);
  396. }
  397. void hdmi_signal_check_stop(void)
  398. {
  399. hdmidbg("%s: removed\n", __FUNCTION__);
  400. nosignal_timer_remove();
  401. }
  402. /* active */
  403. #ifdef CONFIG_QSD
  404. #define ACTIVE_DEBOUNCE_DELAY (1) //unit:10ms
  405. #else
  406. #define ACTIVE_DEBOUNCE_DELAY (20) //unit:10ms
  407. #endif
  408. #define ACTIVE_DEBOUNCE_TIMES (10)
  409. #define MAX_HDCP_WAIT_TIMES (20)
  410. UINT32 MAX_BCH_ERROR_CNT = 0x20;
  411. #define ACTIVE_SIGNAL_MONITOR_DELAY (20) //unit:10ms
  412. static void ACTIVE_TIMER(void* dummy)
  413. {
  414. BOOL bWait = false;
  415. #ifdef CONFIG_QSD //for module test, reduce debounce time
  416. if(HDMI_GetInputInformation(&stKic) == 1)
  417. {
  418. if((stKic.bDviEnable == 0) && (stKic.uiHactive > 600) && (stKic.uiVactive > 200) &&(stKic.uiVfreq > 20))
  419. {
  420. hdmidbg("%s: Status verified after %d run\n", __FUNCTION__, active_run);
  421. hdmidbg("\t%s Mode\n", HDMI_RegisterRead(HDMIRX_R_HDMI_en) ? "HDMI" : "DVI");
  422. hdmidbg("\t%s AVI InfoFrame\n", hdmi_flag_check(HAS_AVIINFO_PKT) ? "Have" : "No");
  423. hdmidbg("\t%s HDCP HandShake\n", hdmi_flag_check(HAS_HDCP) ? "Have" : "No");
  424. /* Remove nosignal timer */
  425. hdmi_signal_check_stop();
  426. /* Set flag */
  427. hdmi_flag_set(HAS_ACTIVE_DATA);
  428. schedule_work(&wq_active);
  429. signal_monitor_timer_schedule(ACTIVE_SIGNAL_MONITOR_DELAY);
  430. /* Enable audio sample coming isrs */
  431. HDMI_Interrupt_Enable(INTR_audio_sample_coming | INTR_HBR_audio_sample_coming);
  432. return;
  433. }
  434. }
  435. hdmidbg("%s MT_code active round:%d\n", __FUNCTION__, active_run);
  436. active_run++;
  437. active_timer_schedule(ACTIVE_DEBOUNCE_DELAY);
  438. return;
  439. #endif
  440. if (active_run == 0)
  441. {
  442. //HDMI_NoticeHandler(HDMINOTICE_PROCESSING_IN, "ACTIVE_TIMER");
  443. }
  444. hdmidbg("%s[%d] bch_cnt:0x%x\n", __FUNCTION__, active_run, HDMI_RegisterRead(HDMIRX_R_bch_ep_cnt));
  445. if(HDMI_RegisterRead(HDMIRX_R_bch_ep_cnt)>MAX_BCH_ERROR_CNT)
  446. {
  447. HDMI_RegisterWrite(HDMIRX_Clr_bch_epcnt, 1);
  448. if (active_run >= 3)
  449. {
  450. printk("[H] BCH error, Reset HDMI!!! \n");
  451. //Reset PLL
  452. //HDMI_RegisterWrite(HDMIRX_CTL_R_MORECTRLI_15_0_, 0x0020);
  453. //HDMI_DelayMs(2);
  454. //HDMI_RegisterWrite(HDMIRX_CTL_R_MORECTRLI_15_0_, 0x0028);
  455. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 1);
  456. HDMI_RegisterWrite(HDMIRX_R_rst_n, 0);
  457. HDMI_DelayMs(2);
  458. HDMI_RegisterWrite(HDMIRX_R_rst_n, 1);
  459. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 0);
  460. /* Check signal status */
  461. //hdmi_signal_check_start();
  462. active_run = 0;
  463. return;
  464. }
  465. }
  466. #ifdef USE_HW_ADAPTIVE_EQ
  467. #ifdef CONFIG_HDMI_SUPPORT_MHL
  468. if((MHL_CABLE_IN != TRUE)||( DrvHDMIPortSelectBitsGet() != CONFIG_HDMI_MHL_PORT))
  469. #endif
  470. {
  471. if (active_run == 0)
  472. {
  473. printk("(HDMIRX_unstable_align_cnt) Clear \n");
  474. HDMI_RegisterWrite(HDMIRX_unstable_align_cnt, 1);//Write 1 clear
  475. }
  476. #if 0
  477. if(HDMI_RegisterRead(HDMIRX_unstable_align_cnt)>0x20)
  478. {
  479. printk("(HDMIRX_unstable_align_cnt)=%d\n",HDMI_RegisterRead(HDMIRX_unstable_align_cnt));
  480. printk("(HDMIRX_unstable_align_cnt)>0x0 Reset PLL!!!!!! \n");
  481. //Reset PLL
  482. HDMI_Reset_HDMI_PLL();
  483. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 0);
  484. HDMI_DelayMs(2);
  485. /* Power On PHY */
  486. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 1);
  487. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 1);
  488. HDMI_RegisterWrite(HDMIRX_R_rst_n, 0);
  489. HDMI_DelayMs(2);
  490. HDMI_RegisterWrite(HDMIRX_R_rst_n, 1);
  491. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 0);
  492. /* Check signal status */
  493. //hdmi_signal_check_start();
  494. active_run = 0;
  495. return;
  496. }
  497. #else
  498. printk("(HDMIRX_unstable_align_cnt)=%d\n",HDMI_RegisterRead(HDMIRX_unstable_align_cnt));
  499. #endif
  500. }
  501. #endif
  502. if (HDMI_RegisterRead(HDMIRX_R_HDMI_en) &&
  503. hdmi_flag_check(HAS_HDCP) == false &&
  504. active_run < MAX_HDCP_WAIT_TIMES)
  505. {
  506. bWait = true;
  507. }
  508. if (active_run < ACTIVE_DEBOUNCE_TIMES)
  509. {
  510. bWait = true;
  511. }
  512. if(hdmi_flag_check(WAIT_HDCP) == true )
  513. {
  514. if (active_run >= MAX_HDCP_WAIT_TIMES)
  515. {
  516. bWait = false;
  517. }
  518. }
  519. else
  520. {
  521. if (active_run >= ACTIVE_DEBOUNCE_TIMES)
  522. {
  523. bWait = false;
  524. }
  525. }
  526. if (bWait)
  527. {
  528. active_run++;
  529. active_timer_schedule(ACTIVE_DEBOUNCE_DELAY);
  530. return;
  531. }
  532. //HDMI_RegisterWrite(HDMIRX_R_BYTE_ALIGN_CNT2, 4);
  533. hdmidbg("%s: Status verified after %d run\n", __FUNCTION__, active_run);
  534. hdmidbg("\t%s Mode\n", HDMI_RegisterRead(HDMIRX_R_HDMI_en) ? "HDMI" : "DVI");
  535. hdmidbg("\t%s AVI InfoFrame\n", hdmi_flag_check(HAS_AVIINFO_PKT) ? "Have" : "No");
  536. hdmidbg("\t%s HDCP HandShake\n", hdmi_flag_check(HAS_HDCP) ? "Have" : "No");
  537. /* Remove nosignal timer */
  538. hdmi_signal_check_stop();
  539. /* Set flag */
  540. hdmi_flag_set(HAS_ACTIVE_DATA);
  541. schedule_work(&wq_active);
  542. // signal_monitor_timer_schedule(ACTIVE_SIGNAL_MONITOR_DELAY);
  543. /* Enable audio sample coming isrs */
  544. HDMI_Interrupt_Enable(INTR_audio_sample_coming | INTR_HBR_audio_sample_coming);
  545. }
  546. void active_timer_schedule(UINT32 ten_ms)
  547. {
  548. hdmidbg("Active Run #%d, wait for %d ms\n", active_run, ten_ms * 10);
  549. del_timer(&active_timer);
  550. active_timer.expires = jiffies + ((HZ / 100) * ten_ms) + HZ / 100;
  551. active_timer.data = (UINT32)NULL;
  552. active_timer.function = (void (*)(ULONG))ACTIVE_TIMER;
  553. add_timer(&active_timer);
  554. }
  555. void active_timer_remove(void)
  556. {
  557. del_timer(&active_timer);
  558. active_run = 0;
  559. }
  560. extern void HDMI_Toggle_HPD(void);
  561. static void SIGNAL_MONITOR_TIMER(void* dummy)
  562. {
  563. VIP_InterfaceKIC CurKic;
  564. bool fResolution_change = false;
  565. UINT32 Vactive_o, Vactive_e;
  566. if (active_run <= ACTIVE_DEBOUNCE_TIMES*2)
  567. {
  568. active_run++;
  569. }
  570. else
  571. {
  572. if(HDMI_RegisterRead(HDMIRX_R_bch_ep_cnt)>0x1000)
  573. {
  574. printk("%s bch_cnt:0x%x\n", __FUNCTION__,HDMI_RegisterRead(HDMIRX_R_bch_ep_cnt));
  575. HDMI_Toggle_HPD();
  576. }
  577. }
  578. /* Interlace */
  579. CurKic.bInterlace = HDMI_RegisterRead(HDMIRX_R_Interlace);
  580. /* Vertical */
  581. Vactive_o = HDMI_RegisterRead(HDMIRX_top_de_v_width_lock);
  582. Vactive_e = HDMI_RegisterRead(HDMIRX_btn_de_v_width_lock);
  583. if(((INT32)(HDMI_RegisterRead(HDMIRX_R_TOP_VDEE) - HDMI_RegisterRead(HDMIRX_R_TOP_VDES))) < 0)
  584. {
  585. Vactive_o = Vactive_o + 1;
  586. }
  587. if(((INT32)(HDMI_RegisterRead(HDMIRX_R_BTM_VDEE) - HDMI_RegisterRead(HDMIRX_R_BTM_VDES))) < 0)
  588. {
  589. Vactive_e = Vactive_e + 1;
  590. }
  591. if (Vactive_o != 0)
  592. {
  593. CurKic.uiVactive = Vactive_o;
  594. CurKic.uiVtotal = HDMI_RegisterRead(HDMIRX_R_TOP_VT);
  595. CurKic.uiVstart = HDMI_RegisterRead(HDMIRX_R_TOP_VDES);
  596. }
  597. else
  598. {
  599. CurKic.uiVactive = Vactive_e;
  600. CurKic.uiVtotal = HDMI_RegisterRead(HDMIRX_R_BTM_VT);
  601. CurKic.uiVstart = HDMI_RegisterRead(HDMIRX_R_BTM_VDES);
  602. }
  603. if(CurKic.bInterlace == 1)
  604. {
  605. if(Vactive_o == (Vactive_e + 1))
  606. CurKic.uiVactive = Vactive_e;
  607. else
  608. CurKic.uiVactive = Vactive_o;
  609. }
  610. CurKic.uiVend = CurKic.uiVstart + CurKic.uiVactive ;
  611. /* Horizontal */
  612. CurKic.uiHactive = HDMI_RegisterRead(HDMIRX_de_h_width_lock) / (HDMI_RegisterRead(HDMIRX_R_AVI_PR) + 1);
  613. /* Patch: hactive should be a even number in DVI mode */
  614. if (HDMI_RegisterRead(HDMIRX_R_HDMI_en) == 0)
  615. {
  616. CurKic.uiHactive &= 0xfffffffe;
  617. }
  618. CurKic.uiHtotal = HDMI_RegisterRead(HDMIRX_R_HT) + 1;
  619. CurKic.uiHstart = HDMI_RegisterRead(HDMIRX_R_HDES) + 1;
  620. CurKic.uiHend = CurKic.uiHstart + CurKic.uiHactive;
  621. #ifdef CONFIG_SUPPORT_4K_2K_30
  622. if (CurKic.uiHactive == 3840)
  623. {
  624. //hdmidbg("......4K x 2K.....\n");
  625. CurKic.uiHactive = (CurKic.uiHactive)/2;
  626. CurKic.uiHtotal = (CurKic.uiHtotal)/2;
  627. CurKic.uiHstart = (CurKic.uiHstart)/2 ;
  628. CurKic.uiHend = (CurKic.uiHend)/2;
  629. }
  630. #endif
  631. if(abs(CurKic.uiHactive - stKic.uiHactive ) > abs(stKic.uiHactive * HDMI_HVAILD_TOLERANCE_PERMILE / 1000))
  632. {
  633. printk("#UNSTBL_H:HVld=%d(%d)\n", CurKic.uiHactive, stKic.uiHactive);
  634. fResolution_change = true;
  635. }
  636. else if (abs(CurKic.uiVactive - stKic.uiVactive ) > abs(stKic.uiVactive * HDMI_VVAILD_TOLERANCE_PERMILE / 1000))
  637. {
  638. printk("#UNSTBL_H:VVld=%d(%d)\n", CurKic.uiVactive, stKic.uiVactive);
  639. fResolution_change = true;
  640. }
  641. else if (abs(CurKic.uiHtotal - stKic.uiHtotal ) > abs(stKic.uiHtotal * HDMI_HTOTAL_TOLERANCE_PERMILE / 1000))
  642. {
  643. printk("#UNSTBL:HTotal=%d\n", CurKic.uiHtotal);
  644. fResolution_change = true;
  645. }
  646. else if (abs(CurKic.uiVtotal - stKic.uiVtotal) > abs(stKic.uiVtotal* HDMI_VTOTAL_TOLERANCE_PERMILE / 1000))
  647. {
  648. printk("#UNSTBL:VTotal=%d\n", CurKic.uiVtotal);
  649. fResolution_change = true;
  650. }
  651. if(fResolution_change == true)
  652. {
  653. printk("Mode Change!!!!!! \n");
  654. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 0);
  655. HDMI_DelayMs(2);
  656. /* Power On PHY */
  657. HDMI_RegisterWrite(HDMIRX_PHY_DIV_RESETJ, 1);
  658. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 1);
  659. HDMI_RegisterWrite(HDMIRX_R_rst_n, 0);
  660. HDMI_DelayMs(2);
  661. HDMI_RegisterWrite(HDMIRX_R_rst_n, 1);
  662. HDMI_RegisterWrite(HDMIRX_R_DDC5V_reset, 0);
  663. }
  664. else
  665. {
  666. signal_monitor_timer_schedule(ACTIVE_SIGNAL_MONITOR_DELAY);
  667. }
  668. HDMI_RegisterWrite(HDMIRX_Clr_bch_epcnt, 1);
  669. }
  670. void signal_monitor_timer_schedule(UINT32 ten_ms)
  671. {
  672. //hdmidbg("bch_check, wait for %d ms\n",ten_ms * 10);
  673. del_timer(&signal_monitor_timer);
  674. signal_monitor_timer.expires = jiffies + ((HZ / 100) * ten_ms) + HZ / 100;
  675. signal_monitor_timer.data = (UINT32)NULL;
  676. signal_monitor_timer.function = (void (*)(ULONG))SIGNAL_MONITOR_TIMER;
  677. add_timer(&signal_monitor_timer);
  678. }
  679. void signal_monitor_timer_remove(void)
  680. {
  681. del_timer(&signal_monitor_timer);
  682. }
  683. /* avi */
  684. void avi_change_schedule(void)
  685. {
  686. schedule_work(&wq_avi_change);
  687. }
  688. /* turn off software 5V */
  689. void HDMI_TurnOff_SW_5V_schedule(UINT32 delay_ms, HDMI_PORT_T ePort)
  690. {
  691. hdmidbg("%s: Turn off Software 5V after %d ms\n", __FUNCTION__, delay_ms);
  692. del_timer(&turn_off_sw_5V_timer);
  693. turn_off_sw_5V_timer.expires = jiffies + ((HZ / 1000) * delay_ms) + HZ / 1000;
  694. turn_off_sw_5V_timer.data = (UINT32)ePort;
  695. turn_off_sw_5V_timer.function = (void (*)(ULONG))WQ_TURN_OFF_SW5V;
  696. add_timer(&turn_off_sw_5V_timer);
  697. }
  698. //==========================================
  699. // Initial
  700. //==========================================
  701. void hdmi_processing_init(void)
  702. {
  703. init_timer(&nosignal_timer);
  704. init_timer(&active_timer);
  705. init_timer(&signal_monitor_timer);
  706. init_timer(&turn_off_sw_5V_timer);
  707. INIT_WORK(&wq_active, (work_func_t) WQ_ACTIVE);
  708. INIT_WORK(&wq_nosignal, (work_func_t) WQ_NOSIGNAL);
  709. INIT_WORK(&wq_avi_change, (work_func_t) WQ_AVI_CHANGE);
  710. INIT_WORK(&wq_turn_off_sw_5V, (work_func_t) WQ_TURN_OFF_SW5V);
  711. }