mtk_dp_hal.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470
  1. /*
  2. * Copyright (c) 2020 MediaTek Inc.
  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 version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include "mtk_dp_hal.h"
  14. #include <linux/io.h>
  15. #include <linux/of.h>
  16. #include <linux/of_platform.h>
  17. #include <linux/sched/clock.h>
  18. #include <linux/arm-smccc.h>
  19. #include <linux/soc/mediatek/mtk_sip_svc.h>
  20. #include "mtk_dp_reg.h"
  21. #include "mtk_devinfo.h"
  22. u32 mtk_dp_read(struct mtk_dp *mtk_dp, u32 offset)
  23. {
  24. u32 read_val = 0;
  25. if (offset > 0x8000) {
  26. DPTXERR("dptx %s, error reg 0x%p, offset 0x%x\n",
  27. __func__, mtk_dp->regs, offset);
  28. return 0;
  29. }
  30. read_val = readl(mtk_dp->regs + offset - (offset%4))
  31. >> ((offset % 4) * 8);
  32. return read_val;
  33. }
  34. void mtk_dp_write(struct mtk_dp *mtk_dp, u32 offset, u32 val)
  35. {
  36. if ((offset % 4 != 0) || (offset > 0x8000)) {
  37. DPTXERR("dptx %s, error reg 0x%p, offset 0x%x, value 0x%x\n",
  38. __func__, mtk_dp->regs, offset, val);
  39. return;
  40. }
  41. writel(val, mtk_dp->regs + offset);
  42. }
  43. void mtk_dp_mask(struct mtk_dp *mtk_dp, u32 offset, u32 val, u32 mask)
  44. {
  45. void __iomem *reg = mtk_dp->regs + offset;
  46. u32 tmp;
  47. if ((offset % 4 != 0) || (offset > 0x8000)) {
  48. DPTXERR("dptx %s, error reg 0x%p, offset 0x%x, value 0x%x\n",
  49. __func__, mtk_dp->regs, offset, val);
  50. return;
  51. }
  52. tmp = readl(reg);
  53. tmp = (tmp & ~mask) | (val & mask);
  54. writel(tmp, reg);
  55. }
  56. void mtk_dp_write_byte(struct mtk_dp *mtk_dp,
  57. u32 addr, u8 val, u32 mask)
  58. {
  59. if (addr % 2) {
  60. mtk_dp_write(mtk_dp, DP_TX_TOP_APB_WSTRB, 0x12);
  61. mtk_dp_mask(mtk_dp, addr - 1, (u32)(val << 8), (mask << 8));
  62. } else {
  63. mtk_dp_write(mtk_dp, DP_TX_TOP_APB_WSTRB, 0x11);
  64. mtk_dp_mask(mtk_dp, addr, (u32)val, mask);
  65. }
  66. mtk_dp_write(mtk_dp, DP_TX_TOP_APB_WSTRB, 0x00);
  67. }
  68. unsigned long mtk_dp_atf_call(unsigned int cmd, unsigned int para)
  69. {
  70. #ifndef CONFIG_FPGA_EARLY_PORTING
  71. struct arm_smccc_res res;
  72. arm_smccc_smc(MTK_SIP_DP_CONTROL, cmd, para,
  73. 0, 0, 0, 0, 0, &res);
  74. DPTXDBG("%s cmd 0x%x, p1 0x%x, ret 0x%x-0x%x",
  75. __func__, cmd, para, res.a0, res.a1);
  76. return res.a1;
  77. #else
  78. return 0;
  79. #endif
  80. }
  81. void mhal_dump_reg(struct mtk_dp *mtk_dp)
  82. {
  83. u32 i, val[4], reg;
  84. for (i = 0x0; i < 0x600; i += 16) {
  85. reg = 0x3000 + i;
  86. val[0] = msRead4Byte(mtk_dp, reg);
  87. val[1] = msRead4Byte(mtk_dp, reg + 4);
  88. val[2] = msRead4Byte(mtk_dp, reg + 8);
  89. val[3] = msRead4Byte(mtk_dp, reg + 12);
  90. DPTXMSG("aux reg[0x%x] = 0x%x 0x%x 0x%x 0x%x",
  91. reg, val[0], val[1], val[2], val[3]);
  92. }
  93. }
  94. void mhal_DPTx_Verify_Clock(struct mtk_dp *mtk_dp)
  95. {
  96. u32 m, n, Ls_clk, pix_clk;
  97. m = msRead4Byte(mtk_dp, REG_33C8_DP_ENCODER1_P0);
  98. n = 0x8000;
  99. Ls_clk = mtk_dp->training_info.ubLinkRate;
  100. Ls_clk *= 27;
  101. pix_clk = m * Ls_clk / n;
  102. DPTXMSG("DPTX calc pixel clock = %d MHz, dp_intf clock = %dMHz\n",
  103. pix_clk, pix_clk/4);
  104. }
  105. void mhal_DPTx_InitialSetting(struct mtk_dp *mtk_dp)
  106. {
  107. msWriteByte(mtk_dp, REG_342C_DP_TRANS_P0, 0x69);
  108. msWrite4ByteMask(mtk_dp, REG_3540_DP_TRANS_P0, BIT3, BIT3);
  109. msWrite4ByteMask(mtk_dp, REG_31EC_DP_ENCODER0_P0, BIT4, BIT4);
  110. msWrite4ByteMask(mtk_dp, REG_304C_DP_ENCODER0_P0, 0, BIT8);
  111. msWrite4ByteMask(mtk_dp, DP_TX_TOP_IRQ_MASK, BIT2, BIT2);
  112. }
  113. void mhal_DPTx_DataLanePNSwap(struct mtk_dp *mtk_dp, bool bENABLE)
  114. {
  115. if (bENABLE) {
  116. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0,
  117. POST_MISC_PN_SWAP_EN_LANE0_DP_TRANS_P0_FLDMASK_POS,
  118. POST_MISC_PN_SWAP_EN_LANE0_DP_TRANS_P0_FLDMASK);
  119. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0,
  120. POST_MISC_PN_SWAP_EN_LANE1_DP_TRANS_P0_FLDMASK_POS,
  121. POST_MISC_PN_SWAP_EN_LANE1_DP_TRANS_P0_FLDMASK);
  122. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0,
  123. POST_MISC_PN_SWAP_EN_LANE2_DP_TRANS_P0_FLDMASK_POS,
  124. POST_MISC_PN_SWAP_EN_LANE2_DP_TRANS_P0_FLDMASK);
  125. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0,
  126. POST_MISC_PN_SWAP_EN_LANE3_DP_TRANS_P0_FLDMASK_POS,
  127. POST_MISC_PN_SWAP_EN_LANE3_DP_TRANS_P0_FLDMASK);
  128. } else {
  129. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0, 0,
  130. POST_MISC_PN_SWAP_EN_LANE0_DP_TRANS_P0_FLDMASK);
  131. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0, 0,
  132. POST_MISC_PN_SWAP_EN_LANE1_DP_TRANS_P0_FLDMASK);
  133. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0, 0,
  134. POST_MISC_PN_SWAP_EN_LANE2_DP_TRANS_P0_FLDMASK);
  135. msWriteByteMask(mtk_dp, REG_3428_DP_TRANS_P0, 0,
  136. POST_MISC_PN_SWAP_EN_LANE3_DP_TRANS_P0_FLDMASK);
  137. }
  138. }
  139. void mhal_DPTx_Set_Efuse_Value(struct mtk_dp *mtk_dp)
  140. {
  141. u32 efuse = get_devinfo_with_index(114);
  142. DPTXMSG("DPTX Efuse(0x11C101B8) = 0x%x\n", efuse);
  143. if (efuse) {
  144. msWrite4ByteMask(mtk_dp, 0x0008, efuse >> 1, BITMASK(23 : 20));
  145. msWrite4ByteMask(mtk_dp, 0x0000, efuse, BITMASK(20 : 16));
  146. msWrite4ByteMask(mtk_dp, 0x0104, efuse, BITMASK(15 : 12));
  147. msWrite4ByteMask(mtk_dp, 0x0104, efuse << 8, BITMASK(19 : 16));
  148. msWrite4ByteMask(mtk_dp, 0x0204, efuse << 8, BITMASK(15 : 12));
  149. msWrite4ByteMask(mtk_dp, 0x0204, efuse << 16, BITMASK(19 : 16));
  150. }
  151. }
  152. void mhal_DPTx_Set_VideoInterlance(struct mtk_dp *mtk_dp, bool bENABLE)
  153. {
  154. if (bENABLE) {
  155. msWriteByteMask(mtk_dp, REG_3030_DP_ENCODER0_P0 + 1,
  156. BIT6|BIT5, BIT6|BIT5);
  157. msWriteByteMask(mtk_dp, REG_3368_DP_ENCODER1_P0 + 1,
  158. 0, BIT5|BIT4);
  159. DPTXMSG("DPTX imode force-ov\n");
  160. } else {
  161. msWriteByteMask(mtk_dp, REG_3030_DP_ENCODER0_P0 + 1,
  162. BIT6, BIT6|BIT5);
  163. msWriteByteMask(mtk_dp, REG_3368_DP_ENCODER1_P0 + 1,
  164. BIT4, BIT5|BIT4);
  165. DPTXMSG("DPTX pmode force-ov\n");
  166. }
  167. }
  168. void mhal_DPTx_EnableBypassMSA(struct mtk_dp *mtk_dp, bool bENABLE)
  169. {
  170. if (bENABLE)
  171. msWrite2ByteMask(mtk_dp, REG_3030_DP_ENCODER0_P0,
  172. 0, 0x03FF);
  173. else
  174. msWrite2ByteMask(mtk_dp, REG_3030_DP_ENCODER0_P0,
  175. 0x03FF, 0x03FF);
  176. }
  177. void mhal_DPTx_SetMSA(struct mtk_dp *mtk_dp)
  178. {
  179. struct DPTX_TIMING_PARAMETER *DPTX_TBL = &mtk_dp->info.DPTX_OUTBL;
  180. msWrite2Byte(mtk_dp, REG_3010_DP_ENCODER0_P0, DPTX_TBL->Htt);
  181. msWrite2Byte(mtk_dp, REG_3018_DP_ENCODER0_P0,
  182. DPTX_TBL->Hsw + DPTX_TBL->Hbp);
  183. msWrite2ByteMask(mtk_dp, REG_3028_DP_ENCODER0_P0,
  184. DPTX_TBL->Hsw << HSW_SW_DP_ENCODER0_P0_FLDMASK_POS,
  185. HSW_SW_DP_ENCODER0_P0_FLDMASK);
  186. msWrite2ByteMask(mtk_dp, REG_3028_DP_ENCODER0_P0,
  187. DPTX_TBL->bHsp << HSP_SW_DP_ENCODER0_P0_FLDMASK_POS,
  188. HSP_SW_DP_ENCODER0_P0_FLDMASK);
  189. msWrite2Byte(mtk_dp, REG_3020_DP_ENCODER0_P0, DPTX_TBL->Hde);
  190. msWrite2Byte(mtk_dp, REG_3014_DP_ENCODER0_P0, DPTX_TBL->Vtt);
  191. msWrite2Byte(mtk_dp, REG_301C_DP_ENCODER0_P0,
  192. DPTX_TBL->Vsw + DPTX_TBL->Vbp);
  193. msWrite2ByteMask(mtk_dp, REG_302C_DP_ENCODER0_P0,
  194. DPTX_TBL->Vsw << VSW_SW_DP_ENCODER0_P0_FLDMASK_POS,
  195. VSW_SW_DP_ENCODER0_P0_FLDMASK);
  196. msWrite2ByteMask(mtk_dp, REG_302C_DP_ENCODER0_P0,
  197. DPTX_TBL->bVsp << VSP_SW_DP_ENCODER0_P0_FLDMASK_POS,
  198. VSP_SW_DP_ENCODER0_P0_FLDMASK);
  199. msWrite2Byte(mtk_dp, REG_3024_DP_ENCODER0_P0, DPTX_TBL->Vde);
  200. msWrite2Byte(mtk_dp, REG_3064_DP_ENCODER0_P0, DPTX_TBL->Hde);
  201. msWrite2Byte(mtk_dp, REG_3154_DP_ENCODER0_P0, (DPTX_TBL->Htt));
  202. msWrite2Byte(mtk_dp, REG_3158_DP_ENCODER0_P0, (DPTX_TBL->Hfp));
  203. msWrite2Byte(mtk_dp, REG_315C_DP_ENCODER0_P0, (DPTX_TBL->Hsw));
  204. msWrite2Byte(mtk_dp, REG_3160_DP_ENCODER0_P0,
  205. DPTX_TBL->Hbp + DPTX_TBL->Hsw);
  206. msWrite2Byte(mtk_dp, REG_3164_DP_ENCODER0_P0, (DPTX_TBL->Hde));
  207. msWrite2Byte(mtk_dp, REG_3168_DP_ENCODER0_P0, DPTX_TBL->Vtt);
  208. msWrite2Byte(mtk_dp, REG_316C_DP_ENCODER0_P0, DPTX_TBL->Vfp);
  209. msWrite2Byte(mtk_dp, REG_3170_DP_ENCODER0_P0, DPTX_TBL->Vsw);
  210. msWrite2Byte(mtk_dp, REG_3174_DP_ENCODER0_P0,
  211. DPTX_TBL->Vbp + DPTX_TBL->Vsw);
  212. msWrite2Byte(mtk_dp, REG_3178_DP_ENCODER0_P0, DPTX_TBL->Vde);
  213. DPTXMSG("MSA:Htt=%d Vtt=%d Hact=%d Vact=%d, fps=%d\n",
  214. DPTX_TBL->Htt, DPTX_TBL->Vtt,
  215. DPTX_TBL->Hde, DPTX_TBL->Vde, DPTX_TBL->FrameRate);
  216. }
  217. void mhal_DPTx_SetColorFormat(struct mtk_dp *mtk_dp, BYTE enOutColorFormat)
  218. {
  219. msWriteByteMask(mtk_dp, REG_3034_DP_ENCODER0_P0,
  220. (enOutColorFormat << 0x1), MASKBIT(2 : 1)); //MISC0
  221. if ((enOutColorFormat == DP_COLOR_FORMAT_RGB_444)
  222. || (enOutColorFormat == DP_COLOR_FORMAT_YUV_444))
  223. msWriteByteMask(mtk_dp, REG_303C_DP_ENCODER0_P0 + 1,
  224. (0), MASKBIT(6 : 4));
  225. else if (enOutColorFormat == DP_COLOR_FORMAT_YUV_422)
  226. msWriteByteMask(mtk_dp, REG_303C_DP_ENCODER0_P0 + 1,
  227. (BIT4), MASKBIT(6 : 4));
  228. else if (enOutColorFormat == DP_COLOR_FORMAT_YUV_420)
  229. msWriteByteMask(mtk_dp, REG_303C_DP_ENCODER0_P0 + 1, (BIT5),
  230. MASKBIT(6 : 4));
  231. }
  232. void mhal_DPTx_SetColorDepth(struct mtk_dp *mtk_dp, BYTE coloer_depth)
  233. {
  234. msWriteByteMask(mtk_dp, REG_3034_DP_ENCODER0_P0,
  235. (coloer_depth << 0x5), 0xE0);
  236. switch (coloer_depth) {
  237. case DP_COLOR_DEPTH_6BIT:
  238. msWriteByteMask(mtk_dp,
  239. REG_303C_DP_ENCODER0_P0 + 1,
  240. 4,
  241. 0x07);
  242. break;
  243. case DP_COLOR_DEPTH_8BIT:
  244. msWriteByteMask(mtk_dp,
  245. REG_303C_DP_ENCODER0_P0 + 1,
  246. 3,
  247. 0x07);
  248. break;
  249. case DP_COLOR_DEPTH_10BIT:
  250. msWriteByteMask(mtk_dp,
  251. REG_303C_DP_ENCODER0_P0 + 1,
  252. 2,
  253. 0x07);
  254. break;
  255. case DP_COLOR_DEPTH_12BIT:
  256. msWriteByteMask(mtk_dp,
  257. REG_303C_DP_ENCODER0_P0 + 1,
  258. 1,
  259. 0x07);
  260. break;
  261. case DP_COLOR_DEPTH_16BIT:
  262. msWriteByteMask(mtk_dp,
  263. REG_303C_DP_ENCODER0_P0 + 1,
  264. 0,
  265. 0x07);
  266. break;
  267. default:
  268. break;
  269. }
  270. }
  271. void mhal_DPTx_SetMISC(struct mtk_dp *mtk_dp, BYTE ucMISC[2])
  272. {
  273. msWriteByteMask(mtk_dp, REG_3034_DP_ENCODER0_P0,
  274. ucMISC[0], 0xFE);
  275. msWriteByteMask(mtk_dp, REG_3034_DP_ENCODER0_P0 + 1,
  276. ucMISC[1], 0xFF);
  277. }
  278. void mhal_DPTx_Set_MVIDx2(struct mtk_dp *mtk_dp, bool bEnable)
  279. {
  280. if (bEnable)
  281. msWriteByteMask(mtk_dp, REG_300C_DP_ENCODER0_P0 + 1,
  282. BIT4, BIT6|BIT5|BIT4);
  283. else
  284. msWriteByteMask(mtk_dp, REG_300C_DP_ENCODER0_P0 + 1,
  285. 0, BIT6|BIT5|BIT4);
  286. }
  287. bool mhal_DPTx_OverWrite_MN(struct mtk_dp *mtk_dp,
  288. bool bEnable, DWORD ulVideo_M, DWORD ulVideo_N)
  289. {
  290. if (bEnable) {
  291. //Turn-on overwrite MN
  292. msWrite2Byte(mtk_dp,
  293. REG_3008_DP_ENCODER0_P0,
  294. ulVideo_M & 0xFFFF);
  295. msWriteByte(mtk_dp,
  296. REG_300C_DP_ENCODER0_P0,
  297. ((ulVideo_M >> 16) & 0xFF));
  298. msWrite2Byte(mtk_dp,
  299. REG_3044_DP_ENCODER0_P0,
  300. ulVideo_N & 0xFFFF);
  301. msWriteByte(mtk_dp,
  302. REG_3048_DP_ENCODER0_P0,
  303. (ulVideo_N >> 16) & 0xFF);
  304. msWrite2Byte(mtk_dp,
  305. REG_3050_DP_ENCODER0_P0,
  306. ulVideo_N & 0xFFFF);
  307. // legerII add
  308. msWriteByte(mtk_dp,
  309. REG_3054_DP_ENCODER0_P0,
  310. (ulVideo_N >> 16) & 0xFF);
  311. //LegerII add
  312. msWriteByteMask(mtk_dp,
  313. REG_3004_DP_ENCODER0_P0 + 1,
  314. BIT0,
  315. BIT0);
  316. } else {
  317. //Turn-off overwrite MN
  318. msWriteByteMask(mtk_dp,
  319. REG_3004_DP_ENCODER0_P0 + 1,
  320. 0,
  321. BIT0);
  322. }
  323. return true;
  324. }
  325. BYTE mhal_DPTx_GetColorBpp(struct mtk_dp *mtk_dp)
  326. {
  327. BYTE ColorBpp;
  328. BYTE ubDPTXColorDepth = mtk_dp->info.depth;
  329. BYTE ubDPTXColorFormat = mtk_dp->info.format;
  330. switch (ubDPTXColorDepth) {
  331. case DP_COLOR_DEPTH_6BIT:
  332. if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_422)
  333. ColorBpp = 16;
  334. else if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_420)
  335. ColorBpp = 12;
  336. else
  337. ColorBpp = 18;
  338. break;
  339. case DP_COLOR_DEPTH_8BIT:
  340. if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_422)
  341. ColorBpp = 16;
  342. else if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_420)
  343. ColorBpp = 12;
  344. else
  345. ColorBpp = 24;
  346. break;
  347. case DP_COLOR_DEPTH_10BIT:
  348. if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_422)
  349. ColorBpp = 20;
  350. else if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_420)
  351. ColorBpp = 15;
  352. else
  353. ColorBpp = 30;
  354. break;
  355. case DP_COLOR_DEPTH_12BIT:
  356. if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_422)
  357. ColorBpp = 24;
  358. else if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_420)
  359. ColorBpp = 18;
  360. else
  361. ColorBpp = 36;
  362. break;
  363. case DP_COLOR_DEPTH_16BIT:
  364. if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_422)
  365. ColorBpp = 32;
  366. else if (ubDPTXColorFormat == DP_COLOR_FORMAT_YUV_420)
  367. ColorBpp = 24;
  368. else
  369. ColorBpp = 48;
  370. break;
  371. default:
  372. ColorBpp = 24;
  373. DPTXMSG("Set Wrong Bpp = %d\n", ColorBpp);
  374. break;
  375. }
  376. return ColorBpp;
  377. }
  378. void mhal_DPTx_SetTU_SramRdStart(struct mtk_dp *mtk_dp, WORD uwValue)
  379. {
  380. //[5:0]video sram start address=>modify in 480P case only, default=0x1F
  381. msWriteByteMask(mtk_dp, REG_303C_DP_ENCODER0_P0, uwValue, 0x3F);
  382. }
  383. void mhal_DPTx_SetSDP_DownCntinitInHblanking(struct mtk_dp *mtk_dp,
  384. WORD uwValue)
  385. {
  386. //[11 : 0]mtk_dp, REG_sdp_down_cnt_init_in_hblank
  387. msWrite2ByteMask(mtk_dp, REG_3364_DP_ENCODER1_P0, uwValue, 0x0FFF);
  388. }
  389. void mhal_DPTx_SetSDP_DownCntinit(struct mtk_dp *mtk_dp, WORD uwValue)
  390. {
  391. //[11 : 0]mtk_dp, REG_sdp_down_cnt_init
  392. msWrite2ByteMask(mtk_dp, REG_3040_DP_ENCODER0_P0, uwValue, 0x0FFF);
  393. }
  394. void mhal_DPTx_SetTU_SetEncoder(struct mtk_dp *mtk_dp)
  395. {
  396. msWriteByteMask(mtk_dp, REG_303C_DP_ENCODER0_P0 + 1, BIT7, BIT7);
  397. msWrite2Byte(mtk_dp, REG_3040_DP_ENCODER0_P0, 0x2020);
  398. msWrite2ByteMask(mtk_dp, REG_3364_DP_ENCODER1_P0, 0x2020, 0x0FFF);
  399. msWriteByteMask(mtk_dp, REG_3300_DP_ENCODER1_P0 + 1, 0x02, BIT1|BIT0);
  400. msWriteByteMask(mtk_dp, REG_3364_DP_ENCODER1_P0 + 1, 0x40, 0x70);
  401. msWrite2Byte(mtk_dp, REG_3368_DP_ENCODER1_P0, 0x1111);
  402. }
  403. void mhal_DPTx_PGEnable(struct mtk_dp *mtk_dp, bool bENABLE)
  404. {
  405. if (bENABLE)
  406. msWriteByteMask(mtk_dp,
  407. REG_3038_DP_ENCODER0_P0 + 1,
  408. BIT3,
  409. BIT3);
  410. else
  411. msWriteByteMask(mtk_dp,
  412. REG_3038_DP_ENCODER0_P0 + 1,
  413. 0,
  414. BIT3);
  415. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT6, BIT6);
  416. }
  417. void mhal_DPTx_PG_Pure_Color(struct mtk_dp *mtk_dp, BYTE BGR, DWORD ColorDepth)
  418. {
  419. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  420. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, 0, MASKBIT(6:4));
  421. switch (BGR) {
  422. case DPTX_PG_PURECOLOR_BLUE:
  423. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  424. 0, MASKBIT(11:0));
  425. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  426. 0, MASKBIT(11:0));
  427. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  428. ColorDepth, MASKBIT(11:0));
  429. break;
  430. case DPTX_PG_PURECOLOR_GREEN:
  431. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  432. 0, MASKBIT(11:0));
  433. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  434. ColorDepth, MASKBIT(11:0));
  435. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  436. 0, MASKBIT(11:0));
  437. break;
  438. case DPTX_PG_PURECOLOR_RED:
  439. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  440. ColorDepth, MASKBIT(11:0));
  441. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  442. 0, MASKBIT(11:0));
  443. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  444. 0, MASKBIT(11:0));
  445. break;
  446. default:
  447. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  448. ColorDepth, MASKBIT(11:0));
  449. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  450. 0, MASKBIT(11:0));
  451. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  452. 0, MASKBIT(11:0));
  453. break;
  454. }
  455. }
  456. void mhal_DPTx_PG_VerticalRamping(struct mtk_dp *mtk_dp, BYTE BGR,
  457. DWORD ColorDepth, BYTE Location)
  458. {
  459. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  460. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT4, MASKBIT(6:4));
  461. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT7, BIT7);
  462. switch (Location) {
  463. case DPTX_PG_LOCATION_ALL:
  464. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  465. 0, MASKBIT(11:0));
  466. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  467. 0, MASKBIT(11:0));
  468. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  469. ColorDepth, MASKBIT(11:0));
  470. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  471. BGR, MASKBIT(2:0));
  472. msWrite2Byte(mtk_dp, REG_31A0_DP_ENCODER0_P0, 0x3FFF);
  473. break;
  474. case DPTX_PG_LOCATION_TOP:
  475. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  476. 0, MASKBIT(11:0));
  477. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  478. ColorDepth, MASKBIT(11:0));
  479. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  480. 0, MASKBIT(11:0));
  481. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  482. BGR, MASKBIT(2:0));
  483. msWrite2Byte(mtk_dp, REG_31A0_DP_ENCODER0_P0, 0x40);
  484. break;
  485. case DPTX_PG_LOCATION_BOTTOM:
  486. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  487. ColorDepth, MASKBIT(11:0));
  488. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  489. 0, MASKBIT(11:0));
  490. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  491. 0, MASKBIT(11:0));
  492. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  493. BGR, MASKBIT(2:0));
  494. msWrite2Byte(mtk_dp, REG_31A0_DP_ENCODER0_P0, 0x2FFF);
  495. break;
  496. default:
  497. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  498. 0, MASKBIT(11:0));
  499. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  500. 0, MASKBIT(11:0));
  501. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  502. ColorDepth, MASKBIT(11:0));
  503. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  504. BGR, MASKBIT(2:0));
  505. msWrite2Byte(mtk_dp, REG_31A0_DP_ENCODER0_P0, 0x3FFF);
  506. break;
  507. }
  508. }
  509. void mhal_DPTx_PG_HorizontalRamping(struct mtk_dp *mtk_dp, BYTE BGR,
  510. DWORD ColorDepth, BYTE Location)
  511. {
  512. DWORD Ramp = 0x3FFF;
  513. ColorDepth = 0x0000;
  514. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  515. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT5, MASKBIT(6:4));
  516. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT7, BIT7);
  517. msWrite2Byte(mtk_dp, REG_31A0_DP_ENCODER0_P0, Ramp);
  518. switch (Location) {
  519. case DPTX_PG_LOCATION_ALL:
  520. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  521. 0, MASKBIT(11:0));
  522. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  523. 0, MASKBIT(11:0));
  524. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  525. 0, MASKBIT(11:0));
  526. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  527. BGR, MASKBIT(2:0));
  528. break;
  529. case DPTX_PG_LOCATION_LEFT_OF_TOP:
  530. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  531. 0, MASKBIT(11:0));
  532. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  533. 0, MASKBIT(11:0));
  534. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  535. 0, MASKBIT(11:0));
  536. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  537. BGR, MASKBIT(2:0));
  538. msWrite2Byte(mtk_dp, REG_31A0_DP_ENCODER0_P0, 0x3FFF);
  539. break;
  540. case DPTX_PG_LOCATION_LEFT_OF_BOTTOM:
  541. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  542. 0, MASKBIT(11:0));
  543. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  544. 0, MASKBIT(11:0));
  545. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  546. 0, MASKBIT(11:0));
  547. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  548. BGR, MASKBIT(2:0));
  549. msWrite2Byte(mtk_dp, REG_31A0_DP_ENCODER0_P0, 0x3FFF);
  550. break;
  551. default:
  552. break;
  553. }
  554. }
  555. void mhal_DPTx_PG_VerticalColorBar(struct mtk_dp *mtk_dp, BYTE Location)
  556. {
  557. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  558. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  559. BIT5|BIT4, MASKBIT(6:4));
  560. switch (Location) {
  561. case DPTX_PG_LOCATION_ALL:
  562. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  563. 0, MASKBIT(5:4));
  564. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  565. 0, MASKBIT(2:0));
  566. break;
  567. case DPTX_PG_LOCATION_LEFT:
  568. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  569. BIT4, MASKBIT(5:4));
  570. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  571. 0, MASKBIT(2:0));
  572. break;
  573. case DPTX_PG_LOCATION_RIGHT:
  574. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  575. BIT4, MASKBIT(5:4));
  576. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  577. BIT2, MASKBIT(2:0));
  578. break;
  579. case DPTX_PG_LOCATION_LEFT_OF_LEFT:
  580. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  581. BIT5|BIT4, MASKBIT(5:4));
  582. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  583. 0, MASKBIT(2:0));
  584. break;
  585. case DPTX_PG_LOCATION_RIGHT_OF_LEFT:
  586. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  587. BIT5|BIT4, MASKBIT(5:4));
  588. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  589. BIT1, MASKBIT(2:0));
  590. break;
  591. case DPTX_PG_LOCATION_LEFT_OF_RIGHT:
  592. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  593. BIT5|BIT4, MASKBIT(5:4));
  594. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  595. BIT2, MASKBIT(2:0));
  596. break;
  597. case DPTX_PG_LOCATION_RIGHT_OF_RIGHT:
  598. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  599. BIT5|BIT4, MASKBIT(5:4));
  600. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  601. BIT2|BIT1, MASKBIT(2:0));
  602. break;
  603. default:
  604. break;
  605. }
  606. }
  607. void mhal_DPTx_PG_HorizontalColorBar(struct mtk_dp *mtk_dp, BYTE Location)
  608. {
  609. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  610. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT6, MASKBIT(6:4));
  611. switch (Location) {
  612. case DPTX_PG_LOCATION_ALL:
  613. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  614. 0, MASKBIT(5:4));
  615. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  616. 0, MASKBIT(2:0));
  617. break;
  618. case DPTX_PG_LOCATION_TOP:
  619. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  620. BIT4, MASKBIT(5:4));
  621. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  622. 0, MASKBIT(2:0));
  623. break;
  624. case DPTX_PG_LOCATION_BOTTOM:
  625. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  626. BIT4, MASKBIT(5:4));
  627. msWriteByteMask(mtk_dp, REG_3190_DP_ENCODER0_P0,
  628. BIT2, MASKBIT(2:0));
  629. break;
  630. default:
  631. break;
  632. }
  633. }
  634. void mhal_DPTx_PG_Chessboard(struct mtk_dp *mtk_dp, BYTE Location,
  635. WORD Hde, WORD Vde)
  636. {
  637. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  638. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT6|BIT4,
  639. MASKBIT(6:4));
  640. switch (Location) {
  641. case DPTX_PG_LOCATION_ALL:
  642. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  643. 0xFFF, MASKBIT(11:0));
  644. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  645. 0xFFF, MASKBIT(11:0));
  646. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  647. 0xFFF, MASKBIT(11:0));
  648. msWrite2ByteMask(mtk_dp, REG_3194_DP_ENCODER0_P0,
  649. 0, MASKBIT(11:0));
  650. msWrite2ByteMask(mtk_dp, REG_3198_DP_ENCODER0_P0,
  651. 0, MASKBIT(11:0));
  652. msWrite2ByteMask(mtk_dp, REG_319C_DP_ENCODER0_P0,
  653. 0, MASKBIT(11:0));
  654. msWrite2ByteMask(mtk_dp, REG_31A8_DP_ENCODER0_P0,
  655. (Hde/8), MASKBIT(13:0));
  656. msWrite2ByteMask(mtk_dp, REG_31AC_DP_ENCODER0_P0,
  657. (Vde/8), MASKBIT(13:0));
  658. break;
  659. default:
  660. break;
  661. }
  662. }
  663. void mhal_DPTx_PG_SubPixel(struct mtk_dp *mtk_dp, BYTE Location)
  664. {
  665. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  666. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0,
  667. BIT6|BIT5, MASKBIT(6:4));
  668. switch (Location) {
  669. case DPTX_PG_PIXEL_ODD_MASK:
  670. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0 + 1, 0, BIT5);
  671. break;
  672. case DPTX_PG_PIXEL_EVEN_MASK:
  673. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0 + 1,
  674. BIT5, BIT5);
  675. break;
  676. default:
  677. break;
  678. }
  679. }
  680. void mhal_DPTx_PG_Frame(struct mtk_dp *mtk_dp, BYTE Location,
  681. WORD Hde, WORD Vde)
  682. {
  683. msWriteByteMask(mtk_dp, REG_3038_DP_ENCODER0_P0 + 1, BIT3, BIT3);
  684. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0, BIT6|BIT5|BIT4,
  685. MASKBIT(6:4));
  686. switch (Location) {
  687. case DPTX_PG_PIXEL_ODD_MASK:
  688. msWriteByteMask(mtk_dp, REG_31B0_DP_ENCODER0_P0 + 1,
  689. 0, BIT5);
  690. msWrite2ByteMask(mtk_dp, REG_317C_DP_ENCODER0_P0,
  691. 0xFFF, MASKBIT(11:0));
  692. msWrite2ByteMask(mtk_dp, REG_3180_DP_ENCODER0_P0,
  693. 0xFFF, MASKBIT(11:0));
  694. msWrite2ByteMask(mtk_dp, REG_3184_DP_ENCODER0_P0,
  695. 0xFFF, MASKBIT(11:0));
  696. msWrite2ByteMask(mtk_dp, REG_3194_DP_ENCODER0_P0,
  697. 0xFFF, MASKBIT(11:0));
  698. msWrite2ByteMask(mtk_dp, REG_3198_DP_ENCODER0_P0,
  699. 0xFFF, MASKBIT(11:0));
  700. msWrite2ByteMask(mtk_dp, REG_319C_DP_ENCODER0_P0,
  701. 0, MASKBIT(11:0));
  702. msWrite2ByteMask(mtk_dp, REG_31A8_DP_ENCODER0_P0,
  703. ((Hde/8)-12), MASKBIT(13:0));
  704. msWrite2ByteMask(mtk_dp, REG_31AC_DP_ENCODER0_P0,
  705. ((Vde/8)-12), MASKBIT(13:0));
  706. msWriteByteMask(mtk_dp, REG_31B4_DP_ENCODER0_P0,
  707. 0x0B, MASKBIT(3:0));
  708. break;
  709. default:
  710. break;
  711. }
  712. }
  713. void mhal_DPTx_Audio_Setting(struct mtk_dp *mtk_dp, BYTE Channel, BYTE bEnable)
  714. {
  715. if (bEnable) {
  716. msWrite4Byte(mtk_dp, 0x112101FC, 0x110E10E4);
  717. if (Channel == 2)//audio dptx config [1] : 0=2ch, 1=8ch
  718. msWrite4Byte(mtk_dp, 0x11210558, 0x0000FF01);
  719. else
  720. msWrite4Byte(mtk_dp, 0x11210558, 0x0000FF03);
  721. //channel status setting [13:12]:0=16bck, 1=24bck, 2=32bck
  722. //[11:10]:0=2ch, 1=4ch, 2=8ch
  723. //[9:8]:0=8bit, 1=16bit, 2=32bit [0]:enable
  724. if (Channel == 2)
  725. msWrite4Byte(mtk_dp, 0x11210548, 0x00002201);
  726. else
  727. msWrite4Byte(mtk_dp, 0x11210548, 0x00002A01);
  728. msWrite4Byte(mtk_dp, 0x11210000, 0x60004000); //turn on clock
  729. msWrite4Byte(mtk_dp, 0x11210010, 0x00000003); //turn on afe
  730. } else {
  731. msWrite4Byte(mtk_dp, 0x11210000, 0x00000000); //turn off clock
  732. msWrite4Byte(mtk_dp, 0x11210010, 0x00000000); //turn off afe
  733. }
  734. }
  735. void mhal_DPTx_Audio_PG_EN(struct mtk_dp *mtk_dp, BYTE Channel,
  736. BYTE Fs, BYTE bEnable)
  737. {
  738. if (bEnable) {
  739. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  740. AU_GEN_EN_DP_ENCODER0_P0_FLDMASK,
  741. AU_GEN_EN_DP_ENCODER0_P0_FLDMASK);
  742. //[9 : 8] set 0x3 : PG mtk_dp
  743. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  744. AUDIO_SOURCE_MUX_DP_ENCODER1_P0_FLDMASK,
  745. AUDIO_SOURCE_MUX_DP_ENCODER1_P0_FLDMASK);
  746. } else {
  747. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  748. 0, AU_GEN_EN_DP_ENCODER0_P0_FLDMASK);
  749. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  750. 0, AUDIO_SOURCE_MUX_DP_ENCODER1_P0_FLDMASK);
  751. }
  752. DPTXMSG("fs = %d, ch = %d\n", Fs, Channel);
  753. //audio channel count change reset
  754. msWriteByteMask(mtk_dp, REG_33F4_DP_ENCODER1_P0 + 1, BIT1, BIT1);
  755. msWrite2ByteMask(mtk_dp, REG_3304_DP_ENCODER1_P0,
  756. AU_PRTY_REGEN_DP_ENCODER1_P0_FLDMASK,
  757. AU_PRTY_REGEN_DP_ENCODER1_P0_FLDMASK);
  758. msWrite2ByteMask(mtk_dp, REG_3304_DP_ENCODER1_P0,
  759. AU_CH_STS_REGEN_DP_ENCODER1_P0_FLDMASK,
  760. AU_CH_STS_REGEN_DP_ENCODER1_P0_FLDMASK);
  761. msWrite2ByteMask(mtk_dp, REG_3304_DP_ENCODER1_P0,
  762. AUDIO_SAMPLE_PRSENT_REGEN_DP_ENCODER1_P0_FLDMASK,
  763. AUDIO_SAMPLE_PRSENT_REGEN_DP_ENCODER1_P0_FLDMASK);
  764. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  765. AUDIO_2CH_SEL_DP_ENCODER0_P0_FLDMASK,
  766. AUDIO_2CH_SEL_DP_ENCODER0_P0_FLDMASK); //[15]
  767. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  768. AUDIO_MN_GEN_EN_DP_ENCODER0_P0_FLDMASK,
  769. AUDIO_MN_GEN_EN_DP_ENCODER0_P0_FLDMASK); // [12]
  770. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  771. AUDIO_8CH_SEL_DP_ENCODER0_P0_FLDMASK,
  772. AUDIO_8CH_SEL_DP_ENCODER0_P0_FLDMASK); //[8]
  773. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  774. AU_EN_DP_ENCODER0_P0_FLDMASK,
  775. AU_EN_DP_ENCODER0_P0_FLDMASK); //[6]
  776. switch (Fs) {
  777. case FS_44K:
  778. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  779. 0x0 << AUDIO_PATGEN_FS_SEL_DP_ENCODER1_P0_FLDMASK_POS,
  780. AUDIO_PATTERN_GEN_FS_SEL_DP_ENCODER1_P0_FLDMASK);
  781. break;
  782. case FS_48K:
  783. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  784. 0x1 << AUDIO_PATGEN_FS_SEL_DP_ENCODER1_P0_FLDMASK_POS,
  785. AUDIO_PATTERN_GEN_FS_SEL_DP_ENCODER1_P0_FLDMASK);
  786. break;
  787. case FS_192K:
  788. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  789. 0x2 << AUDIO_PATGEN_FS_SEL_DP_ENCODER1_P0_FLDMASK_POS,
  790. AUDIO_PATTERN_GEN_FS_SEL_DP_ENCODER1_P0_FLDMASK);
  791. break;
  792. default:
  793. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  794. 0x0 << AUDIO_PATGEN_FS_SEL_DP_ENCODER1_P0_FLDMASK_POS,
  795. AUDIO_PATTERN_GEN_FS_SEL_DP_ENCODER1_P0_FLDMASK);
  796. break;
  797. }
  798. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  799. 0, AUDIO_2CH_EN_DP_ENCODER0_P0_FLDMASK);
  800. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  801. 0, AUDIO_8CH_EN_DP_ENCODER0_P0_FLDMASK);
  802. switch (Channel) {
  803. case 2:
  804. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  805. 0x0 << AUDIO_PATGEN_CH_NUM_DP_ENCODER1_P0_FLDMASK_POS,
  806. AUDIO_PATTERN_GEN_CH_NUM_DP_ENCODER1_P0_FLDMASK);
  807. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  808. AUDIO_2CH_EN_DP_ENCODER0_P0_FLDMASK,
  809. AUDIO_2CH_EN_DP_ENCODER0_P0_FLDMASK);
  810. break;
  811. case 8:
  812. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  813. 0x1 << AUDIO_PATGEN_CH_NUM_DP_ENCODER1_P0_FLDMASK_POS,
  814. AUDIO_PATTERN_GEN_CH_NUM_DP_ENCODER1_P0_FLDMASK);
  815. msWrite2ByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  816. AUDIO_8CH_EN_DP_ENCODER0_P0_FLDMASK,
  817. AUDIO_8CH_EN_DP_ENCODER0_P0_FLDMASK);
  818. break;
  819. case 16:
  820. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  821. 0x2 << AUDIO_PATGEN_CH_NUM_DP_ENCODER1_P0_FLDMASK_POS,
  822. AUDIO_PATTERN_GEN_CH_NUM_DP_ENCODER1_P0_FLDMASK);
  823. break;
  824. case 32:
  825. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  826. 0x3 << AUDIO_PATGEN_CH_NUM_DP_ENCODER1_P0_FLDMASK_POS,
  827. AUDIO_PATTERN_GEN_CH_NUM_DP_ENCODER1_P0_FLDMASK);
  828. break;
  829. default:
  830. msWrite2ByteMask(mtk_dp, REG_3324_DP_ENCODER1_P0,
  831. 0x0 << AUDIO_PATGEN_CH_NUM_DP_ENCODER1_P0_FLDMASK_POS,
  832. AUDIO_PATTERN_GEN_CH_NUM_DP_ENCODER1_P0_FLDMASK);
  833. break;
  834. }
  835. //audio channel count change reset
  836. msWriteByteMask(mtk_dp, REG_33F4_DP_ENCODER1_P0 + 1, 0, BIT1);
  837. //enable audio reset
  838. msWriteByteMask(mtk_dp, REG_33F4_DP_ENCODER1_P0, BIT(0), BIT(0));
  839. }
  840. #if (DPTX_AutoTest_ENABLE == 0x1) && (DPTX_PHY_TEST_PATTERN_EN == 0x1)
  841. void mhal_DPTx_AudioClock(struct mtk_dp *mtk_dp, BYTE Channel, BYTE Fs)
  842. {
  843. int bck, mck;
  844. int div4, divb;
  845. int clk_source = 196608000, clk_value; //KHZ
  846. switch (Fs) {
  847. case FS_44K:
  848. clk_value = 44100;
  849. break;
  850. case FS_48K:
  851. clk_value = 48000;
  852. break;
  853. case FS_96K:
  854. clk_value = 96000;
  855. break;
  856. case FS_192K:
  857. clk_value = 192000;
  858. break;
  859. default:
  860. clk_value = 44100;
  861. break;
  862. }
  863. bck = clk_value * Channel * 32;
  864. mck = clk_value * 256;
  865. div4 = mck / bck - 1;
  866. divb = clk_source / mck - 1;
  867. DPTXMSG("bck = %d, mck = %d, div4 = %d, divb=%d\n",
  868. bck, mck, div4, divb);
  869. msWrite4Byte(mtk_dp, 0x1000c320, 0x6F28BD4C);
  870. msWrite4Byte(mtk_dp, 0x1000c040, 0x6F28BD4D);
  871. msWrite4Byte(mtk_dp, 0x1000c328, 0x00000001);
  872. msWrite4Byte(mtk_dp, 0x1000c318, 0x000003e1);
  873. msWrite4Byte(mtk_dp, 0x1000c31c, 0x84000000);
  874. msWrite4Byte(mtk_dp, 0x1000c334, 0x78FD5264);
  875. msWrite4Byte(mtk_dp, 0x1000c044, 0x78FD5265);
  876. msWrite4Byte(mtk_dp, 0x1000c33C, 0x00000001);
  877. msWrite4Byte(mtk_dp, 0x1000c32C, 0x000003E1);
  878. msWrite4Byte(mtk_dp, 0x1000c330, 0x84000000);
  879. msWrite4Byte(mtk_dp, 0x1000c00c, 0x0000003F);
  880. msWrite4Byte(mtk_dp, 0x100000d4, 0x01000000);
  881. msWrite4Byte(mtk_dp, 0x100000e4, 0x00000001);
  882. msWrite4Byte(mtk_dp, 0x10000008, 0x00300000);
  883. msWrite4Byte(mtk_dp, 0x10000328, div4 << 8 | divb);
  884. msWrite4Byte(mtk_dp, 0x10000320, 0x00001000);
  885. }
  886. #endif
  887. void mhal_DPTx_Audio_Ch_Status_Set(struct mtk_dp *mtk_dp, BYTE Channel,
  888. BYTE Fs, BYTE Wordlength)
  889. {
  890. union DPRX_AUDIO_CHSTS AudChSts;
  891. memset(&AudChSts, 0, sizeof(AudChSts));
  892. switch (Fs) {
  893. case FS_32K:
  894. AudChSts.iec_ch_sts.SamplingFreq = 3;
  895. break;
  896. case FS_44K:
  897. AudChSts.iec_ch_sts.SamplingFreq = 0;
  898. break;
  899. case FS_48K:
  900. AudChSts.iec_ch_sts.SamplingFreq = 2;
  901. break;
  902. case FS_88K:
  903. AudChSts.iec_ch_sts.SamplingFreq = 8;
  904. break;
  905. case FS_96K:
  906. AudChSts.iec_ch_sts.SamplingFreq = 0xA;
  907. break;
  908. case FS_192K:
  909. AudChSts.iec_ch_sts.SamplingFreq = 0xE;
  910. break;
  911. default:
  912. AudChSts.iec_ch_sts.SamplingFreq = 0x1;
  913. break;
  914. }
  915. switch (Wordlength) {
  916. case WL_16bit:
  917. AudChSts.iec_ch_sts.WordLen = 0x02;
  918. break;
  919. case WL_20bit:
  920. AudChSts.iec_ch_sts.WordLen = 0x03;
  921. break;
  922. case WL_24bit:
  923. AudChSts.iec_ch_sts.WordLen = 0x0B;
  924. break;
  925. }
  926. msWrite2Byte(mtk_dp, REG_308C_DP_ENCODER0_P0,
  927. AudChSts.AUD_CH_STS[1] << 8 | AudChSts.AUD_CH_STS[0]);
  928. msWrite2Byte(mtk_dp, REG_3090_DP_ENCODER0_P0,
  929. AudChSts.AUD_CH_STS[3] << 8 | AudChSts.AUD_CH_STS[2]);
  930. msWriteByte(mtk_dp, REG_3094_DP_ENCODER0_P0,
  931. AudChSts.AUD_CH_STS[4]);
  932. }
  933. void mhal_DPTx_Audio_SDP_Setting(struct mtk_dp *mtk_dp, BYTE Channel)
  934. {
  935. msWriteByteMask(mtk_dp, REG_312C_DP_ENCODER0_P0,
  936. 0x00, 0xFF); //[7 : 0] //HB2
  937. if (Channel == 8)
  938. msWrite2ByteMask(mtk_dp, REG_312C_DP_ENCODER0_P0,
  939. 0x0700, 0xFF00);//[15 : 8]channel-1
  940. else
  941. msWrite2ByteMask(mtk_dp, REG_312C_DP_ENCODER0_P0,
  942. 0x0100, 0xFF00);
  943. }
  944. void mhal_DPTx_Audio_M_Divider_Setting(struct mtk_dp *mtk_dp, BYTE Div)
  945. {
  946. msWrite2ByteMask(mtk_dp, REG_30BC_DP_ENCODER0_P0,
  947. Div << AUDIO_M_CODE_MULT_DIV_SEL_DP_ENCODER0_P0_FLDMASK_POS,
  948. AUDIO_M_CODE_MULT_DIV_SEL_DP_ENCODER0_P0_FLDMASK);
  949. }
  950. bool mhal_DPTx_GetHPDPinLevel(struct mtk_dp *mtk_dp)
  951. {
  952. bool ret = (msReadByte(mtk_dp, REG_3414_DP_TRANS_P0) & BIT2) ? 1 : 0;
  953. return ret | mtk_dp->bPowerOn;
  954. }
  955. void mhal_DPTx_SPKG_SDP(struct mtk_dp *mtk_dp, bool bEnable, BYTE ucSDPType,
  956. BYTE *pHB, BYTE *pDB)
  957. {
  958. BYTE ucDBOffset;
  959. WORD ucSTOffset;
  960. BYTE ucpHBOffset;
  961. BYTE bRegIndex;
  962. if (bEnable) {
  963. for (ucDBOffset = 0; ucDBOffset < 0x10; ucDBOffset++)
  964. for (bRegIndex = 0; bRegIndex < 2; bRegIndex++) {
  965. u32 addr = REG_3200_DP_ENCODER1_P0
  966. + ucDBOffset * 4 + bRegIndex;
  967. msWriteByte(mtk_dp, addr,
  968. pDB[ucDBOffset * 2 + bRegIndex]);
  969. }
  970. if (ucSDPType == DPTx_SDPTYP_DRM)
  971. for (ucpHBOffset = 0; ucpHBOffset < 4/2; ucpHBOffset++)
  972. for (bRegIndex = 0;
  973. bRegIndex < 2; bRegIndex++) {
  974. u32 addr = REG_3138_DP_ENCODER0_P0
  975. + ucpHBOffset * 4 + bRegIndex;
  976. BYTE pOffset = ucpHBOffset * 2
  977. + bRegIndex;
  978. msWriteByte(mtk_dp, addr, pHB[pOffset]);
  979. DPTXMSG("W Reg addr: %x, index %d\n",
  980. addr, pOffset);
  981. }
  982. else if (ucSDPType >= DPTx_SDPTYP_PPS0
  983. && ucSDPType <= DPTx_SDPTYP_PPS3) {
  984. for (ucpHBOffset = 0; ucpHBOffset < (4/2);
  985. ucpHBOffset++)
  986. for (bRegIndex = 0; bRegIndex < 2;
  987. bRegIndex++) {
  988. u32 addr = REG_3130_DP_ENCODER0_P0
  989. + ucpHBOffset * 4 + bRegIndex;
  990. BYTE pOffset = ucpHBOffset * 2
  991. + bRegIndex;
  992. msWriteByte(mtk_dp, addr, pHB[pOffset]);
  993. DPTXMSG("W H1 Reg addr:%x,index:%d\n",
  994. addr, pOffset);
  995. }
  996. } else {
  997. ucSTOffset = (ucSDPType - DPTx_SDPTYP_ACM) * 8;
  998. for (ucpHBOffset = 0; ucpHBOffset < 4/2; ucpHBOffset++)
  999. for (bRegIndex = 0; bRegIndex < 2;
  1000. bRegIndex++) {
  1001. u32 addr = REG_30D8_DP_ENCODER0_P0
  1002. + ucSTOffset
  1003. + ucpHBOffset * 4 + bRegIndex;
  1004. BYTE pOffset = ucpHBOffset * 2
  1005. + bRegIndex;
  1006. msWriteByte(mtk_dp, addr, pHB[pOffset]);
  1007. DPTXMSG("W H2 Reg addr: %x,index %d\n",
  1008. addr, pOffset);
  1009. }
  1010. }
  1011. }
  1012. switch (ucSDPType) {
  1013. case DPTx_SDPTYP_NONE:
  1014. break;
  1015. case DPTx_SDPTYP_ACM:
  1016. msWriteByte(mtk_dp, REG_30B4_DP_ENCODER0_P0, 0x00);
  1017. if (bEnable) {
  1018. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1019. DPTx_SDPTYP_ACM, BIT4|BIT3|BIT2|BIT1|BIT0);
  1020. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1021. BIT5, BIT5);
  1022. msWriteByte(mtk_dp, REG_30B4_DP_ENCODER0_P0, 0x05);
  1023. DPTXMSG("SENT SDP TYPE ACM\n");
  1024. }
  1025. break;
  1026. case DPTx_SDPTYP_ISRC:
  1027. msWriteByte(mtk_dp, REG_30B4_DP_ENCODER0_P0 + 1, 0x00);
  1028. if (bEnable) {
  1029. msWriteByte(mtk_dp, REG_31EC_DP_ENCODER0_P0 + 1, 0x1C);
  1030. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1031. DPTx_SDPTYP_ISRC, BIT4|BIT3|BIT2|BIT1|BIT0);
  1032. if (pHB[3] & BIT2)
  1033. msWriteByteMask(mtk_dp, REG_30BC_DP_ENCODER0_P0,
  1034. BIT0, BIT0);
  1035. else
  1036. msWriteByteMask(mtk_dp, REG_30BC_DP_ENCODER0_P0,
  1037. 0, BIT0);
  1038. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1039. BIT5, BIT5);
  1040. msWriteByte(mtk_dp, REG_30B4_DP_ENCODER0_P0 + 1, 0x05);
  1041. DPTXMSG("SENT SDP TYPE ISRC\n");
  1042. }
  1043. break;
  1044. case DPTx_SDPTYP_AVI:
  1045. msWriteByte(mtk_dp, REG_30A4_DP_ENCODER0_P0 + 1, 0x00);
  1046. if (bEnable) {
  1047. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1048. DPTx_SDPTYP_AVI, BIT4|BIT3|BIT2|BIT1|BIT0);
  1049. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1050. BIT5, BIT5);
  1051. msWriteByte(mtk_dp, REG_30A4_DP_ENCODER0_P0 + 1, 0x05);
  1052. DPTXMSG("SENT SDP TYPE AVI\n");
  1053. }
  1054. break;
  1055. case DPTx_SDPTYP_AUI:
  1056. msWriteByte(mtk_dp, REG_30A8_DP_ENCODER0_P0, 0x00);
  1057. if (bEnable) {
  1058. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1059. DPTx_SDPTYP_AUI, BIT4|BIT3|BIT2|BIT1|BIT0);
  1060. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1061. BIT5, BIT5);
  1062. msWriteByte(mtk_dp, REG_30A8_DP_ENCODER0_P0, 0x05);
  1063. DPTXMSG("SENT SDP TYPE AUI\n");
  1064. }
  1065. break;
  1066. case DPTx_SDPTYP_SPD:
  1067. msWriteByte(mtk_dp, REG_30A8_DP_ENCODER0_P0 + 1, 0x00);
  1068. if (bEnable) {
  1069. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1070. DPTx_SDPTYP_SPD, BIT4|BIT3|BIT2|BIT1|BIT0);
  1071. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1072. BIT5, BIT5);
  1073. msWriteByte(mtk_dp, REG_30A8_DP_ENCODER0_P0 + 1, 0x05);
  1074. DPTXMSG("SENT SDP TYPE SPD\n");
  1075. }
  1076. break;
  1077. case DPTx_SDPTYP_MPEG:
  1078. msWriteByte(mtk_dp, REG_30AC_DP_ENCODER0_P0, 0x00);
  1079. if (bEnable) {
  1080. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1081. DPTx_SDPTYP_MPEG, BIT4|BIT3|BIT2|BIT1|BIT0);
  1082. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1083. BIT5, BIT5);
  1084. msWriteByte(mtk_dp, REG_30AC_DP_ENCODER0_P0, 0x05);
  1085. DPTXMSG("SENT SDP TYPE MPEG\n");
  1086. }
  1087. break;
  1088. case DPTx_SDPTYP_NTSC:
  1089. msWriteByte(mtk_dp, REG_30AC_DP_ENCODER0_P0 + 1, 0x00);
  1090. if (bEnable) {
  1091. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1092. DPTx_SDPTYP_NTSC, BIT4|BIT3|BIT2|BIT1|BIT0);
  1093. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1094. BIT5, BIT5);
  1095. msWriteByte(mtk_dp, REG_30AC_DP_ENCODER0_P0 + 1, 0x05);
  1096. DPTXMSG("SENT SDP TYPE NTSC\n");
  1097. }
  1098. break;
  1099. case DPTx_SDPTYP_VSP:
  1100. msWriteByte(mtk_dp, REG_30B0_DP_ENCODER0_P0, 0x00);
  1101. if (bEnable) {
  1102. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1103. DPTx_SDPTYP_VSP, BIT4|BIT3|BIT2|BIT1|BIT0);
  1104. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1105. BIT5, BIT5);
  1106. msWriteByte(mtk_dp, REG_30B0_DP_ENCODER0_P0, 0x05);
  1107. DPTXMSG("SENT SDP TYPE VSP\n");
  1108. }
  1109. break;
  1110. case DPTx_SDPTYP_VSC:
  1111. msWriteByte(mtk_dp, REG_30B8_DP_ENCODER0_P0, 0x00);
  1112. if (bEnable) {
  1113. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1114. DPTx_SDPTYP_VSC, BIT4|BIT3|BIT2|BIT1|BIT0);
  1115. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1116. BIT5, BIT5);
  1117. msWriteByte(mtk_dp, REG_30B8_DP_ENCODER0_P0, 0x05);
  1118. DPTXMSG("SENT SDP TYPE VSC\n");
  1119. }
  1120. break;
  1121. case DPTx_SDPTYP_EXT:
  1122. msWriteByte(mtk_dp, REG_30B0_DP_ENCODER0_P0 + 1, 0x00);
  1123. if (bEnable) {
  1124. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1125. DPTx_SDPTYP_EXT, BIT4|BIT3|BIT2|BIT1|BIT0);
  1126. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1127. BIT5, BIT5);
  1128. msWriteByte(mtk_dp, REG_30B0_DP_ENCODER0_P0 + 1, 0x05);
  1129. DPTXMSG("SENT SDP TYPE EXT\n");
  1130. }
  1131. break;
  1132. case DPTx_SDPTYP_PPS0:
  1133. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x00);
  1134. if (bEnable) {
  1135. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1136. DPTx_SDPTYP_PPS0, BIT4|BIT3|BIT2|BIT1|BIT0);
  1137. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1138. BIT5, BIT5);
  1139. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x05);
  1140. DPTXMSG("SENT SDP TYPE PPS0\n");
  1141. }
  1142. break;
  1143. case DPTx_SDPTYP_PPS1:
  1144. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x00);
  1145. if (bEnable) {
  1146. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1147. DPTx_SDPTYP_PPS1, BIT4|BIT3|BIT2|BIT1|BIT0);
  1148. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1149. BIT5, BIT5);
  1150. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x05);
  1151. DPTXMSG("SENT SDP TYPE PPS1\n");
  1152. }
  1153. break;
  1154. case DPTx_SDPTYP_PPS2:
  1155. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x00);
  1156. if (bEnable) {
  1157. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1158. DPTx_SDPTYP_PPS2, BIT4|BIT3|BIT2|BIT1|BIT0);
  1159. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1160. BIT5, BIT5);
  1161. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x05);
  1162. DPTXMSG("SENT SDP TYPE PPS2\n");
  1163. }
  1164. break;
  1165. case DPTx_SDPTYP_PPS3:
  1166. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x00);
  1167. if (bEnable) {
  1168. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1169. DPTx_SDPTYP_PPS3, BIT4|BIT3|BIT2|BIT1|BIT0);
  1170. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1171. BIT5, BIT5);
  1172. msWriteByte(mtk_dp, REG_31E8_DP_ENCODER0_P0, 0x05);
  1173. DPTXMSG("SENT SDP TYPE PPS3\n");
  1174. }
  1175. break;
  1176. case DPTx_SDPTYP_DRM:
  1177. msWriteByte(mtk_dp, REG_31DC_DP_ENCODER0_P0, 0x00);
  1178. if (bEnable) {
  1179. msWriteByte(mtk_dp, REG_3138_DP_ENCODER0_P0, pHB[0]);
  1180. msWriteByte(mtk_dp, REG_3138_DP_ENCODER0_P0 + 1,
  1181. pHB[1]);
  1182. msWriteByte(mtk_dp, REG_313C_DP_ENCODER0_P0, pHB[2]);
  1183. msWriteByte(mtk_dp, REG_313C_DP_ENCODER0_P0 + 1,
  1184. pHB[3]);
  1185. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1186. DPTx_SDPTYP_DRM, BIT4|BIT3|BIT2|BIT1|BIT0);
  1187. msWriteByteMask(mtk_dp, REG_3280_DP_ENCODER1_P0,
  1188. BIT5, BIT5);
  1189. msWriteByte(mtk_dp, REG_31DC_DP_ENCODER0_P0, 0x05);
  1190. DPTXMSG("SENT SDP TYPE DRM\n");
  1191. }
  1192. break;
  1193. default:
  1194. break;
  1195. }
  1196. }
  1197. void mhal_DPTx_SPKG_VSC_EXT_VESA(struct mtk_dp *mtk_dp, bool bEnable,
  1198. BYTE ucHDR_NUM, BYTE *pDB)
  1199. {
  1200. BYTE VSC_HB1 = 0x20; // VESA : 0x20; CEA : 0x21
  1201. BYTE VSC_HB2;
  1202. BYTE ucPkgCnt;
  1203. WORD ucDBOffset;
  1204. BYTE ucDPloop;
  1205. BYTE ucpDBOffset;
  1206. BYTE bRegIndex;
  1207. if (!bEnable) {
  1208. msWriteByteMask(mtk_dp, REG_30A0_DP_ENCODER0_P0 + 1, 0, BIT0);
  1209. msWriteByteMask(mtk_dp, REG_328C_DP_ENCODER1_P0, 0, BIT7);
  1210. return;
  1211. }
  1212. VSC_HB2 = (ucHDR_NUM > 0) ? BIT6 : 0x00;
  1213. msWriteByte(mtk_dp, REG_31C8_DP_ENCODER0_P0, 0x00);
  1214. msWriteByte(mtk_dp, REG_31C8_DP_ENCODER0_P0 + 1, VSC_HB1);
  1215. msWriteByte(mtk_dp, REG_31CC_DP_ENCODER0_P0, VSC_HB2);
  1216. msWriteByte(mtk_dp, REG_31CC_DP_ENCODER0_P0 + 1, 0x00);
  1217. msWriteByte(mtk_dp, REG_31D8_DP_ENCODER0_P0, ucHDR_NUM);
  1218. msWriteByteMask(mtk_dp, REG_328C_DP_ENCODER1_P0, BIT0, BIT0);
  1219. msWriteByteMask(mtk_dp, REG_328C_DP_ENCODER1_P0, BIT2, BIT2);
  1220. udelay(50);
  1221. msWriteByteMask(mtk_dp, REG_328C_DP_ENCODER1_P0, 0, BIT2);
  1222. udelay(50);
  1223. for (ucPkgCnt = 0; ucPkgCnt < (ucHDR_NUM+1); ucPkgCnt++) {
  1224. ucDBOffset = 0;
  1225. for (ucDPloop = 0; ucDPloop < 4; ucDPloop++) {
  1226. for (ucpDBOffset = 0; ucpDBOffset < 8/2; ucpDBOffset++)
  1227. for (bRegIndex = 0; bRegIndex < 2;
  1228. bRegIndex++) {
  1229. u32 addr = REG_3290_DP_ENCODER1_P0
  1230. + ucpDBOffset * 4 + bRegIndex;
  1231. BYTE pOffset = ucDBOffset
  1232. + ucpDBOffset * 2 + bRegIndex;
  1233. msWriteByte(mtk_dp,
  1234. addr,
  1235. pDB[pOffset]);
  1236. }
  1237. msWriteByteMask(mtk_dp, REG_328C_DP_ENCODER1_P0,
  1238. BIT6, BIT6);
  1239. ucDBOffset += 8;
  1240. }
  1241. }
  1242. msWriteByteMask(mtk_dp, REG_30A0_DP_ENCODER0_P0 + 1, BIT0, BIT0);
  1243. msWriteByteMask(mtk_dp, REG_328C_DP_ENCODER1_P0, BIT7, BIT7);
  1244. }
  1245. void mhal_DPTx_SPKG_VSC_EXT_CEA(struct mtk_dp *mtk_dp, bool bEnable,
  1246. BYTE ucHDR_NUM, BYTE *pDB)
  1247. {
  1248. BYTE VSC_HB1 = 0x21;
  1249. BYTE VSC_HB2;
  1250. BYTE ucPkgCnt;
  1251. WORD ucDBOffset;
  1252. BYTE ucDPloop;
  1253. BYTE ucpDBOffset;
  1254. BYTE bRegIndex;
  1255. if (!bEnable) {
  1256. msWriteByteMask(mtk_dp, REG_30A0_DP_ENCODER0_P0 + 1, 0, BIT4);
  1257. msWriteByteMask(mtk_dp, REG_32A0_DP_ENCODER1_P0, 0, BIT7);
  1258. return;
  1259. }
  1260. VSC_HB2 = (ucHDR_NUM > 0) ? 0x40 : 0x00;
  1261. msWriteByte(mtk_dp, REG_31D0_DP_ENCODER0_P0, 0x00);
  1262. msWriteByte(mtk_dp, REG_31D0_DP_ENCODER0_P0 + 1, VSC_HB1);
  1263. msWriteByte(mtk_dp, REG_31D4_DP_ENCODER0_P0, VSC_HB2);
  1264. msWriteByte(mtk_dp, REG_31D4_DP_ENCODER0_P0 + 1, 0x00);
  1265. msWriteByte(mtk_dp, REG_31D8_DP_ENCODER0_P0 + 1, ucHDR_NUM);
  1266. msWriteByteMask(mtk_dp, REG_32A0_DP_ENCODER1_P0, BIT0, BIT0);
  1267. msWriteByteMask(mtk_dp, REG_32A0_DP_ENCODER1_P0, BIT2, BIT2);
  1268. udelay(50);
  1269. msWriteByteMask(mtk_dp, REG_32A0_DP_ENCODER1_P0, 0, BIT2);
  1270. for (ucPkgCnt = 0; ucPkgCnt < (ucHDR_NUM+1); ucPkgCnt++) {
  1271. ucDBOffset = 0;
  1272. for (ucDPloop = 0; ucDPloop < 4; ucDPloop++) {
  1273. for (ucpDBOffset = 0; ucpDBOffset < 8/2; ucpDBOffset++)
  1274. for (bRegIndex = 0; bRegIndex < 2;
  1275. bRegIndex++) {
  1276. u32 addr = REG_32A4_DP_ENCODER1_P0
  1277. + ucpDBOffset * 4 + bRegIndex;
  1278. BYTE pOffset = ucDBOffset
  1279. + ucpDBOffset * 2 + bRegIndex;
  1280. msWriteByte(mtk_dp,
  1281. addr,
  1282. pDB[pOffset]);
  1283. }
  1284. msWriteByteMask(mtk_dp, REG_32A0_DP_ENCODER1_P0,
  1285. BIT6, BIT6);
  1286. ucDBOffset += 8;
  1287. }
  1288. }
  1289. msWriteByteMask(mtk_dp, REG_30A0_DP_ENCODER0_P0 + 1, BIT4, BIT4);
  1290. msWriteByteMask(mtk_dp, REG_32A0_DP_ENCODER1_P0, BIT7, BIT7);
  1291. }
  1292. bool mhal_DPTx_AuxRead_Bytes(struct mtk_dp *mtk_dp, BYTE ubCmd,
  1293. DWORD usDPCDADDR, size_t ubLength, BYTE *pRxBuf)
  1294. {
  1295. bool bVaildCmd = false;
  1296. BYTE ubReplyCmd = 0xFF;
  1297. BYTE ubRdCount = 0x0;
  1298. BYTE uAuxIrqStatus = 0;
  1299. unsigned int WaitReplyCount = AuxWaitReplyLpCntNum;
  1300. msWriteByte(mtk_dp, REG_3640_AUX_TX_P0, 0x7F);
  1301. udelay(AUX_WRITE_READ_WAIT_TIME);
  1302. if ((ubLength > 16) ||
  1303. ((ubCmd == AUX_CMD_NATIVE_R) && (ubLength == 0x0)))
  1304. return bVaildCmd;
  1305. msWriteByte(mtk_dp, REG_3650_AUX_TX_P0 + 1, 0x01);
  1306. msWriteByte(mtk_dp, REG_3644_AUX_TX_P0, ubCmd);
  1307. msWrite2Byte(mtk_dp, REG_3648_AUX_TX_P0, usDPCDADDR&0x0000FFFF);
  1308. msWriteByte(mtk_dp, REG_364C_AUX_TX_P0, (usDPCDADDR>>16)&0x0000000F);
  1309. if (ubLength > 0) {
  1310. msWrite2ByteMask(mtk_dp, REG_3650_AUX_TX_P0,
  1311. (ubLength-1) << MCU_REQ_DATA_NUM_AUX_TX_P0_FLDMASK_POS,
  1312. MCU_REQUEST_DATA_NUM_AUX_TX_P0_FLDMASK);
  1313. msWriteByte(mtk_dp, REG_362C_AUX_TX_P0, 0x00);
  1314. }
  1315. if ((ubCmd == AUX_CMD_I2C_R) || (ubCmd == AUX_CMD_I2C_R_MOT0))
  1316. if (ubLength == 0x0)
  1317. msWrite2ByteMask(mtk_dp, REG_362C_AUX_TX_P0,
  1318. 0x01 << AUX_NO_LENGTH_AUX_TX_P0_FLDMASK_POS,
  1319. AUX_NO_LENGTH_AUX_TX_P0_FLDMASK);
  1320. msWrite2ByteMask(mtk_dp, REG_3630_AUX_TX_P0,
  1321. 0x01 << AUX_TX_REQUEST_READY_AUX_TX_P0_FLDMASK_POS,
  1322. AUX_TX_REQUEST_READY_AUX_TX_P0_FLDMASK);
  1323. while (--WaitReplyCount) {
  1324. if ((msReadByte(mtk_dp, REG_3618_AUX_TX_P0)
  1325. & AUX_RX_FIFO_WRITE_POINTER_AUX_TX_P0_FLDMASK)) {
  1326. bVaildCmd = true;
  1327. break;
  1328. }
  1329. if ((msRead2Byte(mtk_dp, REG_3618_AUX_TX_P0)
  1330. & AUX_RX_FIFO_FULL_AUX_TX_P0_FLDMASK)) {
  1331. bVaildCmd = true;
  1332. break;
  1333. }
  1334. uAuxIrqStatus = msReadByte(mtk_dp, REG_3640_AUX_TX_P0) & 0xFF;
  1335. if (uAuxIrqStatus & AUX_RX_RECV_COMPLETE_IRQ_TX_P0_FLDMASK) {
  1336. bVaildCmd = true;
  1337. break;
  1338. }
  1339. if (uAuxIrqStatus & AUX_400US_TIMEOUT_IRQ_AUX_TX_P0_FLDMASK) {
  1340. DPTXMSG("(AUX Read)HW Timeout 400us irq");
  1341. break;
  1342. }
  1343. }
  1344. ubReplyCmd = msReadByte(mtk_dp, REG_3624_AUX_TX_P0) & 0x0F;
  1345. if (ubReplyCmd)
  1346. DPTXMSG("ubReplyCmd =%x NACK or Defer\n", ubReplyCmd);
  1347. if ((WaitReplyCount == 0x0) || ubReplyCmd) {
  1348. BYTE phyStatus = 0x00;
  1349. phyStatus = msReadByte(mtk_dp, REG_3628_AUX_TX_P0);
  1350. if (phyStatus != 0x01)
  1351. DPTXERR("Aux R:Aux hang,need SW reset\n");
  1352. msWrite2ByteMask(mtk_dp, REG_3650_AUX_TX_P0,
  1353. 0x01 << MCU_ACK_TRAN_COMPLETE_AUX_TX_P0_FLDMASK_POS,
  1354. MCU_ACK_TRANSACTION_COMPLETE_AUX_TX_P0_FLDMASK);
  1355. msWriteByte(mtk_dp, REG_3640_AUX_TX_P0, 0x7F);
  1356. udelay(AUX_WRITE_READ_WAIT_TIME);
  1357. DPTXMSG("WaitReplyCount =%x TimeOut", WaitReplyCount);
  1358. return false;
  1359. }
  1360. if (ubLength == 0) {
  1361. msWriteByte(mtk_dp, REG_362C_AUX_TX_P0, 0x00);
  1362. } else {
  1363. if (bVaildCmd) {
  1364. msWrite2ByteMask(mtk_dp, REG_3620_AUX_TX_P0,
  1365. 0x0 << AUX_RD_MODE_AUX_TX_P0_FLDMASK_POS,
  1366. AUX_RD_MODE_AUX_TX_P0_FLDMASK);
  1367. for (ubRdCount = 0x0; ubRdCount < ubLength;
  1368. ubRdCount++) {
  1369. msWrite2ByteMask(mtk_dp, REG_3620_AUX_TX_P0,
  1370. 0x01 << AUX_RX_FIFO_R_PULSE_TX_P0_FLDMASK_POS,
  1371. AUX_RX_FIFO_READ_PULSE_TX_P0_FLDMASK);
  1372. if ((ubCmd == (DP_AUX_I2C_READ
  1373. | DP_AUX_I2C_MOT))
  1374. || (ubCmd == DP_AUX_I2C_READ))
  1375. udelay(500);
  1376. else
  1377. udelay(AUX_WRITE_READ_WAIT_TIME*5);
  1378. *(pRxBuf + ubRdCount)
  1379. = msReadByte(mtk_dp,
  1380. REG_3620_AUX_TX_P0);
  1381. }
  1382. } else
  1383. DPTXMSG("Read TimeOut 0x%x\n", usDPCDADDR);
  1384. }
  1385. msWrite2ByteMask(mtk_dp, REG_3650_AUX_TX_P0,
  1386. 0x01 << MCU_ACK_TRAN_COMPLETE_AUX_TX_P0_FLDMASK_POS,
  1387. MCU_ACK_TRANSACTION_COMPLETE_AUX_TX_P0_FLDMASK);
  1388. msWriteByte(mtk_dp, REG_3640_AUX_TX_P0, 0x7F);
  1389. udelay(AUX_WRITE_READ_WAIT_TIME);
  1390. return bVaildCmd;
  1391. }
  1392. bool mhal_DPTx_AuxWrite_Bytes(struct mtk_dp *mtk_dp,
  1393. BYTE ubCmd, DWORD usDPCDADDR, size_t ubLength, BYTE *pData)
  1394. {
  1395. bool bVaildCmd = false;
  1396. BYTE ubReplyCmd = 0x0;
  1397. BYTE i;
  1398. WORD WaitReplyCount = AuxWaitReplyLpCntNum;
  1399. BYTE bRegIndex;
  1400. msWriteByteMask(mtk_dp, REG_3704_AUX_TX_P0,
  1401. 1 << AUX_TX_FIFO_NEW_MODE_EN_AUX_TX_P0_FLDMASK_POS,
  1402. AUX_TX_FIFO_NEW_MODE_EN_AUX_TX_P0_FLDMASK);
  1403. msWriteByte(mtk_dp, REG_3650_AUX_TX_P0 + 1, 0x01);
  1404. msWriteByte(mtk_dp, REG_3640_AUX_TX_P0, 0x7F);
  1405. udelay(AUX_WRITE_READ_WAIT_TIME);
  1406. msWriteByte(mtk_dp, REG_3650_AUX_TX_P0 + 1, 0x01);
  1407. msWriteByte(mtk_dp, REG_3644_AUX_TX_P0, ubCmd);
  1408. msWriteByte(mtk_dp, REG_3648_AUX_TX_P0, usDPCDADDR & 0x00FF);
  1409. msWriteByte(mtk_dp, REG_3648_AUX_TX_P0 + 1, (usDPCDADDR >> 8) & 0x00FF);
  1410. msWriteByte(mtk_dp, REG_364C_AUX_TX_P0, (usDPCDADDR >> 16) & 0x000F);
  1411. if (ubLength > 0) {
  1412. msWriteByte(mtk_dp, REG_362C_AUX_TX_P0, 0x00);
  1413. for (i = 0x0; i < (ubLength+1)/2; i++)
  1414. for (bRegIndex = 0; bRegIndex < 2; bRegIndex++)
  1415. if ((i * 2 + bRegIndex) < ubLength)
  1416. msWriteByte(mtk_dp,
  1417. REG_3708_AUX_TX_P0 + i * 4 + bRegIndex,
  1418. pData[i * 2 + bRegIndex]);
  1419. msWriteByte(mtk_dp, REG_3650_AUX_TX_P0 + 1,
  1420. ((ubLength - 1) & 0x0F) << 4);
  1421. } else
  1422. msWriteByte(mtk_dp, REG_362C_AUX_TX_P0, 0x01);
  1423. msWriteByteMask(mtk_dp, REG_3704_AUX_TX_P0,
  1424. AUX_TX_FIFO_WRITE_DATA_NEW_MODE_TOGGLE_AUX_TX_P0_FLDMASK,
  1425. AUX_TX_FIFO_WRITE_DATA_NEW_MODE_TOGGLE_AUX_TX_P0_FLDMASK);
  1426. msWriteByte(mtk_dp, REG_3630_AUX_TX_P0, 0x08);
  1427. while (--WaitReplyCount) {
  1428. BYTE uAuxIrqStatus;
  1429. uAuxIrqStatus = msReadByte(mtk_dp, REG_3640_AUX_TX_P0) & 0xFF;
  1430. udelay(1);
  1431. if (uAuxIrqStatus & AUX_RX_RECV_COMPLETE_IRQ_TX_P0_FLDMASK) {
  1432. bVaildCmd = true;
  1433. break;
  1434. }
  1435. if (uAuxIrqStatus & AUX_400US_TIMEOUT_IRQ_AUX_TX_P0_FLDMASK) {
  1436. DPTXMSG("(AUX write)HW Timeout 400us irq");
  1437. break;
  1438. }
  1439. }
  1440. ubReplyCmd = msReadByte(mtk_dp, REG_3624_AUX_TX_P0) & 0x0F;
  1441. if (ubReplyCmd)
  1442. DPTXMSG("ubReplyCmd =%x NACK or Defer\n", ubReplyCmd);
  1443. if ((WaitReplyCount == 0x0) || ubReplyCmd) {
  1444. BYTE phyStatus = 0x00;
  1445. phyStatus = msReadByte(mtk_dp, REG_3628_AUX_TX_P0);
  1446. if (phyStatus != 0x01)
  1447. DPTXERR("Aux Write: Aux hang, need SW reset!\n");
  1448. msWriteByte(mtk_dp, REG_3650_AUX_TX_P0 + 1, 0x01);
  1449. msWriteByte(mtk_dp, REG_3640_AUX_TX_P0, 0x7F);
  1450. udelay(AUX_WRITE_READ_WAIT_TIME);
  1451. DPTXMSG("ubReplyCmd = 0x%x WaitReplyCount = %d\n",
  1452. ubReplyCmd, WaitReplyCount);
  1453. return false;
  1454. }
  1455. msWriteByte(mtk_dp, REG_3650_AUX_TX_P0 + 1, 0x01);
  1456. if (ubLength == 0)
  1457. msWriteByte(mtk_dp, REG_362C_AUX_TX_P0, 0x00);
  1458. msWriteByte(mtk_dp, REG_3640_AUX_TX_P0, 0x7F);
  1459. udelay(AUX_WRITE_READ_WAIT_TIME);
  1460. return bVaildCmd;
  1461. }
  1462. bool mhal_DPTx_SetSwingtPreEmphasis(struct mtk_dp *mtk_dp, int lane_num,
  1463. int swingValue, int preEmphasis)
  1464. {
  1465. DPTXMSG("lane%d, set Swing = %x, Emp =%x\n", lane_num,
  1466. swingValue, preEmphasis);
  1467. switch (lane_num) {
  1468. case DPTx_LANE0:
  1469. msWrite4ByteMask(mtk_dp,
  1470. DP_TX_TOP_SWING_EMP,
  1471. swingValue << DP_TX0_VOLT_SWING_FLDMASK_POS,
  1472. DP_TX0_VOLT_SWING_FLDMASK);
  1473. msWrite4ByteMask(mtk_dp,
  1474. DP_TX_TOP_SWING_EMP,
  1475. preEmphasis << DP_TX0_PRE_EMPH_FLDMASK_POS,
  1476. DP_TX0_PRE_EMPH_FLDMASK);
  1477. break;
  1478. case DPTx_LANE1:
  1479. msWrite4ByteMask(mtk_dp,
  1480. DP_TX_TOP_SWING_EMP,
  1481. swingValue << DP_TX1_VOLT_SWING_FLDMASK_POS,
  1482. DP_TX1_VOLT_SWING_FLDMASK);
  1483. msWrite4ByteMask(mtk_dp,
  1484. DP_TX_TOP_SWING_EMP,
  1485. preEmphasis << DP_TX1_PRE_EMPH_FLDMASK_POS,
  1486. DP_TX1_PRE_EMPH_FLDMASK);
  1487. break;
  1488. case DPTx_LANE2:
  1489. msWrite4ByteMask(mtk_dp,
  1490. DP_TX_TOP_SWING_EMP,
  1491. swingValue << DP_TX2_VOLT_SWING_FLDMASK_POS,
  1492. DP_TX2_VOLT_SWING_FLDMASK);
  1493. msWrite4ByteMask(mtk_dp,
  1494. DP_TX_TOP_SWING_EMP,
  1495. preEmphasis << DP_TX2_PRE_EMPH_FLDMASK_POS,
  1496. DP_TX2_PRE_EMPH_FLDMASK);
  1497. break;
  1498. case DPTx_LANE3:
  1499. msWrite4ByteMask(mtk_dp,
  1500. DP_TX_TOP_SWING_EMP,
  1501. swingValue << DP_TX3_VOLT_SWING_FLDMASK_POS,
  1502. DP_TX3_VOLT_SWING_FLDMASK);
  1503. msWrite4ByteMask(mtk_dp,
  1504. DP_TX_TOP_SWING_EMP,
  1505. preEmphasis << DP_TX3_PRE_EMPH_FLDMASK_POS,
  1506. DP_TX3_PRE_EMPH_FLDMASK);
  1507. break;
  1508. default:
  1509. DPTXERR("lane number is error\n");
  1510. return false;
  1511. }
  1512. return true;
  1513. }
  1514. bool mhal_DPTx_ResetSwingtPreEmphasis(struct mtk_dp *mtk_dp)
  1515. {
  1516. msWrite4ByteMask(mtk_dp,
  1517. DP_TX_TOP_SWING_EMP, 0, DP_TX0_VOLT_SWING_FLDMASK);
  1518. msWrite4ByteMask(mtk_dp,
  1519. DP_TX_TOP_SWING_EMP, 0, DP_TX1_VOLT_SWING_FLDMASK);
  1520. msWrite4ByteMask(mtk_dp,
  1521. DP_TX_TOP_SWING_EMP, 0, DP_TX2_VOLT_SWING_FLDMASK);
  1522. msWrite4ByteMask(mtk_dp,
  1523. DP_TX_TOP_SWING_EMP, 0, DP_TX3_VOLT_SWING_FLDMASK);
  1524. msWrite4ByteMask(mtk_dp,
  1525. DP_TX_TOP_SWING_EMP, 0, DP_TX0_PRE_EMPH_FLDMASK);
  1526. msWrite4ByteMask(mtk_dp,
  1527. DP_TX_TOP_SWING_EMP, 0, DP_TX1_PRE_EMPH_FLDMASK);
  1528. msWrite4ByteMask(mtk_dp,
  1529. DP_TX_TOP_SWING_EMP, 0, DP_TX2_PRE_EMPH_FLDMASK);
  1530. msWrite4ByteMask(mtk_dp,
  1531. DP_TX_TOP_SWING_EMP, 0, DP_TX3_PRE_EMPH_FLDMASK);
  1532. return true;
  1533. }
  1534. void mhal_DPTx_ISR(struct mtk_dp *mtk_dp)
  1535. {
  1536. static DWORD AuxIrqCnt;
  1537. static DWORD TransIrqCnt;
  1538. static DWORD EncIrqCnt;
  1539. uint32_t int_status;
  1540. int_status = msRead4Byte(mtk_dp, DP_TX_TOP_IRQ_STATUS);
  1541. DPTXDBG("int_status = 0x%x\n", int_status);
  1542. if (int_status & BIT2)
  1543. AuxIrqCnt++;
  1544. if (int_status & BIT1) {
  1545. mdrv_DPTx_HPD_ISREvent(mtk_dp);
  1546. TransIrqCnt++;
  1547. }
  1548. if (int_status & BIT0)
  1549. EncIrqCnt++;
  1550. DPTXDBG("AuxIrqCnt:%d, TransIrqCnt:%d, EncIrqCnt:%d\n",
  1551. AuxIrqCnt, TransIrqCnt, EncIrqCnt);
  1552. }
  1553. void mhal_DPTx_EnableFEC(struct mtk_dp *mtk_dp, bool bENABLE)
  1554. {
  1555. DPTXFUNC("Fec enable=%d\n", bENABLE);
  1556. if (bENABLE)
  1557. msWriteByteMask(mtk_dp, REG_3540_DP_TRANS_P0, BIT0, BIT0);
  1558. else
  1559. msWriteByteMask(mtk_dp, REG_3540_DP_TRANS_P0, 0, BIT0);
  1560. }
  1561. void mhal_DPTx_EnableDSC(struct mtk_dp *mtk_dp, bool bENABLE)
  1562. {
  1563. DPTXFUNC("DSC enable=%d\n", bENABLE);
  1564. if (bENABLE) {
  1565. msWriteByteMask(mtk_dp,
  1566. REG_336C_DP_ENCODER1_P0,
  1567. BIT0,
  1568. BIT0); // [0] : DSC Enable
  1569. msWriteByteMask(mtk_dp,
  1570. REG_300C_DP_ENCODER0_P0 + 1,
  1571. BIT1,
  1572. BIT1); //300C [9] : VB-ID[6] DSC enable
  1573. msWriteByteMask(mtk_dp,
  1574. REG_303C_DP_ENCODER0_P0 + 1,
  1575. 0x7,
  1576. MASKBIT(2 : 0)); //303C[10 : 8] : DSC color depth
  1577. msWriteByteMask(mtk_dp,
  1578. REG_303C_DP_ENCODER0_P0 + 1,
  1579. 0x7 << 4,
  1580. MASKBIT(6 : 4)); //303C[14 : 12] : DSC color format
  1581. msWriteByteMask(mtk_dp,
  1582. REG_31FC_DP_ENCODER0_P0 + 1,
  1583. BIT4,
  1584. BIT4); //31FC[12] : HDE last num control
  1585. } else {
  1586. msWriteByteMask(mtk_dp,
  1587. REG_336C_DP_ENCODER1_P0,
  1588. 0,
  1589. BIT0); // DSC Disable
  1590. msWriteByteMask(mtk_dp,
  1591. REG_300C_DP_ENCODER0_P0 + 1,
  1592. 0,
  1593. BIT1);
  1594. msWriteByteMask(mtk_dp,
  1595. REG_303C_DP_ENCODER0_P0 + 1,
  1596. 0x3,
  1597. MASKBIT(2 : 0)); //default 8bit
  1598. msWriteByteMask(mtk_dp,
  1599. REG_303C_DP_ENCODER0_P0 + 1,
  1600. 0x0,
  1601. MASKBIT(6 : 4)); //default RGB
  1602. msWriteByteMask(mtk_dp,
  1603. REG_31FC_DP_ENCODER0_P0 + 1,
  1604. 0x0,
  1605. BIT4);
  1606. }
  1607. }
  1608. void mhal_DPTx_SetChunkSize(struct mtk_dp *mtk_dp,
  1609. BYTE slice_num, WORD chunk_num, BYTE remainder,
  1610. BYTE lane_count, BYTE hde_last_num, BYTE hde_num_even)
  1611. {
  1612. msWriteByteMask(mtk_dp,
  1613. REG_336C_DP_ENCODER1_P0,
  1614. slice_num << 4,
  1615. MASKBIT(7 : 4));
  1616. msWriteByteMask(mtk_dp,
  1617. REG_336C_DP_ENCODER1_P0 + 1,
  1618. remainder,
  1619. MASKBIT(3 : 0));
  1620. msWrite2Byte(mtk_dp,
  1621. REG_3370_DP_ENCODER1_P0,
  1622. chunk_num); //set chunk_num
  1623. if (lane_count == 1) {
  1624. msWriteByteMask(mtk_dp,
  1625. REG_31FC_DP_ENCODER0_P0,
  1626. hde_last_num,
  1627. MASKBIT(1 : 0)); //last data catch on lane 0
  1628. msWriteByteMask(mtk_dp,
  1629. REG_31FC_DP_ENCODER0_P0 + 1,
  1630. hde_num_even,
  1631. BIT0); //sram last data catch on lane 0
  1632. } else {
  1633. msWriteByteMask(mtk_dp,
  1634. REG_31FC_DP_ENCODER0_P0,
  1635. hde_last_num,
  1636. MASKBIT(1 : 0));
  1637. msWriteByteMask(mtk_dp,
  1638. REG_31FC_DP_ENCODER0_P0,
  1639. hde_last_num << 2,
  1640. MASKBIT(3 : 2));
  1641. msWriteByteMask(mtk_dp,
  1642. REG_31FC_DP_ENCODER0_P0 + 1,
  1643. hde_num_even,
  1644. BIT0);
  1645. msWriteByteMask(mtk_dp,
  1646. REG_31FC_DP_ENCODER0_P0 + 1,
  1647. hde_num_even << 1,
  1648. BIT1);
  1649. }
  1650. }
  1651. void mhal_DPTx_Fake_Plugin(struct mtk_dp *mtk_dp, bool conn)
  1652. {
  1653. if (conn) {
  1654. msWriteByteMask(mtk_dp, REG_3414_DP_TRANS_P0, 0,
  1655. HPD_OVR_EN_DP_TRANS_P0_FLDMASK);
  1656. msWriteByteMask(mtk_dp, REG_3414_DP_TRANS_P0, 0,
  1657. HPD_SET_DP_TRANS_P0_FLDMASK);
  1658. } else {
  1659. msWriteByteMask(mtk_dp, REG_3414_DP_TRANS_P0,
  1660. HPD_OVR_EN_DP_TRANS_P0_FLDMASK,
  1661. HPD_OVR_EN_DP_TRANS_P0_FLDMASK);
  1662. msWriteByteMask(mtk_dp, REG_3414_DP_TRANS_P0, 0,
  1663. HPD_SET_DP_TRANS_P0_FLDMASK);
  1664. }
  1665. }
  1666. void mhal_DPTx_USBC_HPD(struct mtk_dp *mtk_dp, bool conn)
  1667. {
  1668. msWriteByteMask(mtk_dp,
  1669. REG_3414_DP_TRANS_P0,
  1670. HPD_OVR_EN_DP_TRANS_P0_FLDMASK,
  1671. HPD_OVR_EN_DP_TRANS_P0_FLDMASK);
  1672. if (conn)
  1673. msWriteByteMask(mtk_dp,
  1674. REG_3414_DP_TRANS_P0,
  1675. HPD_SET_DP_TRANS_P0_FLDMASK,
  1676. HPD_SET_DP_TRANS_P0_FLDMASK);
  1677. else
  1678. msWriteByteMask(mtk_dp,
  1679. REG_3414_DP_TRANS_P0,
  1680. 0,
  1681. HPD_SET_DP_TRANS_P0_FLDMASK);
  1682. DPTXFUNC("REG3414 = 0x%x\n", msReadByte(mtk_dp, REG_3414_DP_TRANS_P0));
  1683. }
  1684. WORD mhal_DPTx_GetSWIRQStatus(struct mtk_dp *mtk_dp)
  1685. {
  1686. return msRead2Byte(mtk_dp, REG_35D0_DP_TRANS_P0);
  1687. }
  1688. void mhal_DPTx_SWInterruptSet(struct mtk_dp *mtk_dp, WORD bstatus)
  1689. {
  1690. msWrite2Byte(mtk_dp, REG_35C0_DP_TRANS_P0, bstatus);
  1691. }
  1692. void mhal_DPTx_SWInterruptClr(struct mtk_dp *mtk_dp, WORD bstatus)
  1693. {
  1694. msWrite2Byte(mtk_dp, REG_35C8_DP_TRANS_P0, bstatus);
  1695. msWrite2Byte(mtk_dp, REG_35C8_DP_TRANS_P0, 0);
  1696. }
  1697. void mhal_DPTx_SWInterruptEnable(struct mtk_dp *mtk_dp, bool enable)
  1698. {
  1699. if (enable)
  1700. msWrite2Byte(mtk_dp, REG_35C4_DP_TRANS_P0, 0);
  1701. else
  1702. msWrite2Byte(mtk_dp, REG_35C4_DP_TRANS_P0, 0xFFFF);
  1703. }
  1704. BYTE mhal_DPTx_GetHPDIRQStatus(struct mtk_dp *mtk_dp)
  1705. {
  1706. return (msReadByte(mtk_dp, REG_3418_DP_TRANS_P0 + 1) & 0xE0) >> 4;
  1707. }
  1708. void mhal_DPTx_HPDInterruptClr(struct mtk_dp *mtk_dp, BYTE bstatus)
  1709. {
  1710. DPTXFUNC();
  1711. msWriteByteMask(mtk_dp,
  1712. REG_3418_DP_TRANS_P0,
  1713. bstatus,
  1714. BIT3|BIT2|BIT1);
  1715. msWriteByteMask(mtk_dp,
  1716. REG_3418_DP_TRANS_P0,
  1717. 0,
  1718. BIT3|BIT2|BIT1);
  1719. }
  1720. void mhal_DPTx_HPDInterruptEnable(struct mtk_dp *mtk_dp, bool enable)
  1721. {
  1722. DPTXFUNC();
  1723. // [7]:int[6]:Con[5]DisCon[4]No-Use:UnMASK HPD Port
  1724. if (enable)
  1725. msWriteByteMask(mtk_dp,
  1726. REG_3418_DP_TRANS_P0,
  1727. 0,
  1728. BIT7|BIT6|BIT5);
  1729. else
  1730. msWriteByteMask(mtk_dp,
  1731. REG_3418_DP_TRANS_P0,
  1732. BIT7|BIT6|BIT5,
  1733. BIT7|BIT6|BIT5);
  1734. }
  1735. void mhal_DPTx_HPDDetectSetting(struct mtk_dp *mtk_dp)
  1736. {
  1737. msWriteByteMask(mtk_dp,
  1738. REG_3410_DP_TRANS_P0,
  1739. 0x8,
  1740. MASKBIT(3 : 0));
  1741. msWriteByteMask(mtk_dp,
  1742. REG_3410_DP_TRANS_P0,
  1743. (0x0A << 4),
  1744. MASKBIT(7 : 4));
  1745. // [7 : 4] Con Thd = 1.5ms+Vx0.1ms[3 : 0] : DisCon Thd = 1.5ms+Vx0.1ms
  1746. msWriteByte(mtk_dp,
  1747. REG_3410_DP_TRANS_P0 + 1,
  1748. 0x55);
  1749. msWriteByte(mtk_dp,
  1750. REG_3430_DP_TRANS_P0,
  1751. 0x02); //1113 MK
  1752. }
  1753. void mhal_DPTx_PHYSetting(struct mtk_dp *mtk_dp)
  1754. {
  1755. uint32_t value = 0;
  1756. uint8_t mask = 0x3F;
  1757. msWrite4ByteMask(mtk_dp,
  1758. DP_TX_TOP_PWR_STATE,
  1759. 0x3 << DP_PWR_STATE_FLDMASK_POS, DP_PWR_STATE_FLDMASK);
  1760. msWrite4Byte(mtk_dp, 0x2000, 0x00000001);
  1761. msWrite4Byte(mtk_dp, 0x103C, 0x00000000);
  1762. msWrite4Byte(mtk_dp, 0x2000, 0x00000003);
  1763. value = (mtk_dp->phy_params[0].C0 & mask)
  1764. | ((mtk_dp->phy_params[1].C0 & mask) << 8)
  1765. | ((mtk_dp->phy_params[2].C0 & mask) << 16)
  1766. | ((mtk_dp->phy_params[3].C0 & mask) << 24);
  1767. msWrite4Byte(mtk_dp, 0x1138, value);//0x20181410
  1768. msWrite4Byte(mtk_dp, 0x1238, value);
  1769. DPTXDBG("0x38:%#010x, 0x38:%#010x", value, msRead4Byte(mtk_dp, 0x1138));
  1770. value = (mtk_dp->phy_params[4].C0 & mask)
  1771. | ((mtk_dp->phy_params[5].C0 & mask) << 8)
  1772. | ((mtk_dp->phy_params[6].C0 & mask) << 16)
  1773. | ((mtk_dp->phy_params[7].C0 & mask) << 24);
  1774. msWrite4Byte(mtk_dp, 0x113C, value);//0x20241e18
  1775. msWrite4Byte(mtk_dp, 0x123C, value);
  1776. DPTXDBG("0x3C:%#010x, 0x3C:%#010x", value, msRead4Byte(mtk_dp, 0x113C));
  1777. value = (mtk_dp->phy_params[8].C0 & mask)
  1778. | ((mtk_dp->phy_params[9].C0 & mask) << 8);
  1779. msWrite4Byte(mtk_dp, 0x1140, value);//0x00003028
  1780. msWrite4Byte(mtk_dp, 0x1240, value);
  1781. DPTXDBG("0x40:%#010x, 0x40:%#010x", value, msRead4Byte(mtk_dp, 0x1140));
  1782. value = (mtk_dp->phy_params[0].CP1 & mask)
  1783. | ((mtk_dp->phy_params[1].CP1 & mask) << 8)
  1784. | ((mtk_dp->phy_params[2].CP1 & mask) << 16)
  1785. | ((mtk_dp->phy_params[3].CP1 & mask) << 24);
  1786. msWrite4Byte(mtk_dp, 0x1144, 0x10080400);//0x10080400
  1787. msWrite4Byte(mtk_dp, 0x1244, 0x10080400);
  1788. DPTXDBG("0x44:%#010x, 0x44:%#010x", value, msRead4Byte(mtk_dp, 0x1144));
  1789. value = (mtk_dp->phy_params[4].CP1 & mask)
  1790. | ((mtk_dp->phy_params[5].CP1 & mask) << 8)
  1791. | ((mtk_dp->phy_params[6].CP1 & mask) << 16)
  1792. | ((mtk_dp->phy_params[7].CP1 & mask) << 24);
  1793. msWrite4Byte(mtk_dp, 0x1148, value);//0x000c0600
  1794. msWrite4Byte(mtk_dp, 0x1248, value);
  1795. DPTXDBG("0x48:%#010x, 0x48:%#010x", value, msRead4Byte(mtk_dp, 0x1148));
  1796. value = (mtk_dp->phy_params[8].CP1 & mask)
  1797. | ((mtk_dp->phy_params[9].CP1 & mask) << 8);
  1798. msWrite4Byte(mtk_dp, 0x114C, value);//0x00000008
  1799. msWrite4Byte(mtk_dp, 0x124C, value);
  1800. DPTXDBG("0x4C:%#010x, 0x4C:%#010x", value, msRead4Byte(mtk_dp, 0x114C));
  1801. msWrite4ByteMask(mtk_dp, 0x3690, BIT8, BIT8);
  1802. }
  1803. void mhal_DPTx_SSCOnOffSetting(struct mtk_dp *mtk_dp, bool bENABLE)
  1804. {
  1805. DPTXMSG("SSC enable = %d\n", bENABLE);
  1806. msWrite4ByteMask(mtk_dp, 0x2000, BIT(0), BITMASK(0:1));
  1807. if (bENABLE)
  1808. msWrite4ByteMask(mtk_dp, 0x1014, BIT(3), BIT(3));
  1809. else
  1810. msWrite4ByteMask(mtk_dp, 0x1014, 0x0, BIT(3));
  1811. msWrite4ByteMask(mtk_dp, 0x2000, BIT(0)|BIT(1), BITMASK(0:1));
  1812. udelay(50);
  1813. }
  1814. void mhal_DPTx_AuxSetting(struct mtk_dp *mtk_dp)
  1815. {
  1816. // modify timeout threshold = 1595 [12 : 8]
  1817. msWrite2ByteMask(mtk_dp,
  1818. REG_360C_AUX_TX_P0,
  1819. 0x1595,
  1820. AUX_TIMEOUT_THR_AUX_TX_P0_FLDMASK);
  1821. msWriteByteMask(mtk_dp,
  1822. REG_3658_AUX_TX_P0,
  1823. 0,
  1824. BIT0); //[0]mtk_dp, REG_aux_tx_ov_en
  1825. msWriteByte(mtk_dp,
  1826. REG_3634_AUX_TX_P0 + 1,
  1827. 0x19); // 25 for 26M
  1828. msWriteByteMask(mtk_dp,
  1829. REG_3614_AUX_TX_P0,
  1830. 0x0D,
  1831. MASKBIT(6 : 0)); // Modify, 13 for 26M
  1832. msWrite4ByteMask(mtk_dp,
  1833. REG_37C8_AUX_TX_P0,
  1834. 0x01 << MTK_ATOP_EN_AUX_TX_P0_FLDMASK_POS,
  1835. MTK_ATOP_EN_AUX_TX_P0_FLDMASK);
  1836. }
  1837. void mhal_DPTx_DigitalSetting(struct mtk_dp *mtk_dp)
  1838. {
  1839. DPTXFUNC();
  1840. msWriteByteMask(mtk_dp,
  1841. REG_304C_DP_ENCODER0_P0,
  1842. 0,
  1843. VBID_VIDEO_MUTE_DP_ENCODER0_P0_FLDMASK);
  1844. mhal_DPTx_SetColorFormat(mtk_dp, DP_COLOR_FORMAT_RGB);//MISC0
  1845. // [13 : 12] : = 2b'01 VDE check BS2BS & set min value
  1846. mhal_DPTx_SetColorDepth(mtk_dp, DP_COLOR_DEPTH_8BIT);
  1847. msWriteByteMask(mtk_dp,
  1848. REG_3368_DP_ENCODER1_P0 + 1,
  1849. BIT4,
  1850. MASKBIT(5 : 4));
  1851. msWriteByteMask(mtk_dp,
  1852. REG_3004_DP_ENCODER0_P0 + 1,
  1853. BIT1,
  1854. BIT1);// dp tx encoder reset all sw
  1855. //DELAY_NOP(10);
  1856. mdelay(1);
  1857. // dp tx encoder reset all sw
  1858. msWriteByteMask(mtk_dp, REG_3004_DP_ENCODER0_P0 + 1, 0, BIT1);
  1859. }
  1860. void mhal_DPTx_DigitalSwReset(struct mtk_dp *mtk_dp)
  1861. {
  1862. DPTXFUNC();
  1863. msWriteByteMask(mtk_dp, REG_340C_DP_TRANS_P0 + 1, BIT5, BIT5);
  1864. mdelay(1);
  1865. msWriteByteMask(mtk_dp, REG_340C_DP_TRANS_P0 + 1, 0, BIT5);
  1866. }
  1867. void mhal_DPTx_SetTxLaneToLane(struct mtk_dp *mtk_dp, BYTE ucLaneNum,
  1868. BYTE ucSetLaneNum)
  1869. {
  1870. msWriteByteMask(mtk_dp,
  1871. REG_3408_DP_TRANS_P0 + 1,
  1872. (ucSetLaneNum << (ucLaneNum*2)),
  1873. (BIT1|BIT0) << (ucLaneNum*2)); // swap Lane A to Lane B
  1874. }
  1875. void mhal_DPTx_PHYD_Reset(struct mtk_dp *mtk_dp)
  1876. {
  1877. msWriteByteMask(mtk_dp, 0x1038, 0, BIT(0));
  1878. udelay(50);
  1879. msWriteByteMask(mtk_dp, 0x1038, BIT(0), BIT(0));
  1880. }
  1881. void mhal_DPTx_SetTxLane(struct mtk_dp *mtk_dp, int Value)
  1882. {
  1883. DPTXFUNC();
  1884. if (Value == 0)
  1885. msWriteByteMask(mtk_dp,
  1886. REG_35F0_DP_TRANS_P0,
  1887. 0,
  1888. BIT3|BIT2);
  1889. else
  1890. msWriteByteMask(mtk_dp,
  1891. REG_35F0_DP_TRANS_P0,
  1892. BIT3,
  1893. BIT3|BIT2);
  1894. msWriteByteMask(mtk_dp,
  1895. REG_3000_DP_ENCODER0_P0,
  1896. Value,
  1897. BIT1|BIT0);
  1898. msWriteByteMask(mtk_dp,
  1899. REG_34A4_DP_TRANS_P0,
  1900. (Value << 2),
  1901. BIT3|BIT2);
  1902. }
  1903. void mhal_DPTx_SetTxRate(struct mtk_dp *mtk_dp, int Value)
  1904. {
  1905. DPTXFUNC();
  1906. msWrite4Byte(mtk_dp, 0x2000, 0x00000001); // power off TPLL and Lane;
  1907. /// Set gear : 0x0 : RBR, 0x1 : HBR, 0x2 : HBR2, 0x3 : HBR3
  1908. switch (Value) {
  1909. case 0x06:
  1910. msWrite4Byte(mtk_dp,
  1911. 0x103C,
  1912. 0x00000000);
  1913. break;
  1914. case 0x0A:
  1915. msWrite4Byte(mtk_dp,
  1916. 0x103C,
  1917. 0x00000001);
  1918. break;
  1919. case 0x14:
  1920. msWrite4Byte(mtk_dp,
  1921. 0x103C,
  1922. 0x00000002);
  1923. break;
  1924. case 0x1E:
  1925. msWrite4Byte(mtk_dp,
  1926. 0x103C,
  1927. 0x00000003);
  1928. break;
  1929. default:
  1930. break;
  1931. }
  1932. msWrite4Byte(mtk_dp,
  1933. 0x2000,
  1934. 0x00000003); // power on BandGap, TPLL and Lane;
  1935. }
  1936. void mhal_DPTx_SetTxTrainingPattern(struct mtk_dp *mtk_dp, int Value)
  1937. {
  1938. DPTXMSG("Set Train Pattern =0x%x\n ", Value);
  1939. if (Value == BIT4) // if Set TPS1
  1940. mhal_DPTx_PHY_SetIdlePattern(mtk_dp, false);
  1941. msWriteByteMask(mtk_dp,
  1942. REG_3400_DP_TRANS_P0 + 1,
  1943. Value,
  1944. MASKBIT(7 : 4));
  1945. }
  1946. void mhal_DPTx_PHY_SetIdlePattern(struct mtk_dp *mtk_dp, bool bENABLE)
  1947. {
  1948. DPTXDBG("Idle pattern enable(%d)\n", bENABLE);
  1949. if (bENABLE)
  1950. msWriteByteMask(mtk_dp,
  1951. REG_3580_DP_TRANS_P0 + 1,
  1952. 0x0F,
  1953. 0x0F);
  1954. else
  1955. msWriteByteMask(mtk_dp,
  1956. REG_3580_DP_TRANS_P0 + 1,
  1957. 0x0,
  1958. 0x0F);
  1959. }
  1960. void mhal_DPTx_SetFreeSync(struct mtk_dp *mtk_dp, bool bENABLE)
  1961. {
  1962. DPTXFUNC();
  1963. if (bENABLE)//mtk_dp, REG_bs2bs_mode, [13 : 12] = 11 freesync on
  1964. msWriteByteMask(mtk_dp,
  1965. REG_3368_DP_ENCODER1_P0 + 1,
  1966. BIT5|BIT4,
  1967. BIT5|BIT4);
  1968. else//mtk_dp, REG_bs2bs_mode, [13 : 12] = 01 freesync off
  1969. msWriteByteMask(mtk_dp,
  1970. REG_3368_DP_ENCODER1_P0 + 1,
  1971. BIT4,
  1972. BIT5|BIT4);
  1973. }
  1974. void mhal_DPTx_SetEF_Mode(struct mtk_dp *mtk_dp, bool bENABLE)
  1975. {
  1976. if (bENABLE)//[4] REG_enhanced_frame_mode [1 : 0]mtk_dp, REG_lane_num
  1977. msWriteByteMask(mtk_dp,
  1978. REG_3000_DP_ENCODER0_P0,
  1979. BIT4,
  1980. BIT4);
  1981. else //[4]mtk_dp, REG_enhanced_frame_mode [1 : 0]mtk_dp, REG_lane_num
  1982. msWriteByteMask(mtk_dp,
  1983. REG_3000_DP_ENCODER0_P0,
  1984. 0,
  1985. BIT4);
  1986. }
  1987. void mhal_DPTx_SetScramble(struct mtk_dp *mtk_dp, bool bENABLE)
  1988. {
  1989. if (bENABLE)
  1990. msWriteByteMask(mtk_dp,
  1991. REG_3404_DP_TRANS_P0,
  1992. BIT0,
  1993. BIT0); //[0]dp tx transmitter scramble enable
  1994. else
  1995. msWriteByteMask(mtk_dp,
  1996. REG_3404_DP_TRANS_P0,
  1997. 0,
  1998. BIT0); //[0]dp tx transmitter scramble enable
  1999. }
  2000. void mhal_DPTx_SetScramble_Type(struct mtk_dp *mtk_dp, bool bSelType)
  2001. {
  2002. //[1]scrambler reset data,0:DP 16'ffff, 1:eDP 16'fffe
  2003. if (bSelType)//eDP
  2004. msWriteByteMask(mtk_dp,
  2005. REG_3404_DP_TRANS_P0,
  2006. BIT1,
  2007. BIT1);
  2008. else // DP
  2009. msWriteByteMask(mtk_dp,
  2010. REG_3404_DP_TRANS_P0,
  2011. 0,
  2012. BIT1);
  2013. }
  2014. void mhal_DPTx_VideoMute(struct mtk_dp *mtk_dp, bool bENABLE)
  2015. {
  2016. DPTXFUNC("enable = %d\n", bENABLE);
  2017. if (bENABLE) {
  2018. msWriteByteMask(mtk_dp,
  2019. REG_3000_DP_ENCODER0_P0,
  2020. BIT3|BIT2,
  2021. BIT3|BIT2); //Video mute enable
  2022. mtk_dp_atf_call(DP_ATF_VIDEO_UNMUTE, 1);
  2023. } else {
  2024. msWriteByteMask(mtk_dp,
  2025. REG_3000_DP_ENCODER0_P0,
  2026. BIT3,
  2027. BIT3|BIT2);// [3] Sw ov Mode [2] mute value
  2028. mtk_dp_atf_call(DP_ATF_VIDEO_UNMUTE, 0);
  2029. }
  2030. }
  2031. void mhal_DPTx_VideoMuteSW(struct mtk_dp *mtk_dp, bool bENABLE)
  2032. {
  2033. DPTXFUNC("enable = %d\n", bENABLE);
  2034. if (bENABLE)
  2035. msWriteByteMask(mtk_dp,
  2036. REG_304C_DP_ENCODER0_P0,
  2037. BIT2,
  2038. BIT2); //Video mute enable
  2039. else
  2040. msWriteByteMask(mtk_dp,
  2041. REG_304C_DP_ENCODER0_P0,
  2042. 0,
  2043. BIT2); // [3] Sw ov Mode [2] mute value
  2044. }
  2045. void mhal_DPTx_AudioMute(struct mtk_dp *mtk_dp, bool bENABLE)
  2046. {
  2047. DPTXFUNC();
  2048. if (bENABLE) {
  2049. msWrite2ByteMask(mtk_dp,
  2050. REG_3030_DP_ENCODER0_P0,
  2051. 0x01 << VBID_AUDIO_MUTE_SW_DP_ENCODER0_P0_FLDMASK_POS,
  2052. VBID_AUDIO_MUTE_FLAG_SW_DP_ENCODER0_P0_FLDMASK);
  2053. msWrite2ByteMask(mtk_dp,
  2054. REG_3030_DP_ENCODER0_P0,
  2055. 0x01 << VBID_AUDIO_MUTE_SEL_DP_ENCODER0_P0_FLDMASK_POS,
  2056. VBID_AUDIO_MUTE_FLAG_SEL_DP_ENCODER0_P0_FLDMASK);
  2057. msWriteByteMask(mtk_dp,
  2058. REG_3088_DP_ENCODER0_P0,
  2059. 0x0 << AU_EN_DP_ENCODER0_P0_FLDMASK_POS,
  2060. AU_EN_DP_ENCODER0_P0_FLDMASK);
  2061. msWriteByte(mtk_dp,
  2062. REG_30A4_DP_ENCODER0_P0,
  2063. 0x00);
  2064. } else {
  2065. msWrite2ByteMask(mtk_dp,
  2066. REG_3030_DP_ENCODER0_P0,
  2067. 0x00 << VBID_AUDIO_MUTE_SEL_DP_ENCODER0_P0_FLDMASK_POS,
  2068. VBID_AUDIO_MUTE_FLAG_SEL_DP_ENCODER0_P0_FLDMASK);
  2069. msWriteByteMask(mtk_dp, REG_3088_DP_ENCODER0_P0,
  2070. 0x1 << AU_EN_DP_ENCODER0_P0_FLDMASK_POS,
  2071. AU_EN_DP_ENCODER0_P0_FLDMASK);
  2072. msWriteByte(mtk_dp,
  2073. REG_30A4_DP_ENCODER0_P0,
  2074. 0x0F);
  2075. }
  2076. }
  2077. #if (DPTX_AutoTest_ENABLE == 0x1) && (DPTX_PHY_TEST_PATTERN_EN == 0x1)
  2078. void mhal_DPTx_PHY_ResetPattern(struct mtk_dp *mtk_dp)
  2079. {
  2080. DPTXFUNC();
  2081. //reset pattern
  2082. mhal_DPTx_SetTxLane(mtk_dp, DPTx_LANE_4);
  2083. mhal_DPTx_ProgramPatternEnable(mtk_dp, false);
  2084. mhal_DPTx_PatternSelect(mtk_dp, 0x00);
  2085. mhal_DPTx_PRBSEnable(mtk_dp, false);
  2086. mhal_DPTx_ComplianceEyeEnSetting(mtk_dp, false);
  2087. }
  2088. void mhal_DPTx_PRBSEnable(struct mtk_dp *mtk_dp, bool bENABLE)
  2089. {
  2090. DPTXFUNC();
  2091. if (bENABLE)
  2092. msWriteByteMask(mtk_dp, REG_3444_DP_TRANS_P0, (BIT3), BIT3);
  2093. else
  2094. msWriteByteMask(mtk_dp, REG_3444_DP_TRANS_P0, (0), BIT3);
  2095. }
  2096. void mhal_DPTx_ProgramPatternEnable(struct mtk_dp *mtk_dp, bool bENABLE)
  2097. {
  2098. DPTXFUNC();
  2099. if (bENABLE)
  2100. msWriteByteMask(mtk_dp,
  2101. REG_3440_DP_TRANS_P0,
  2102. 0x0F,
  2103. MASKBIT(3 : 0));
  2104. else
  2105. msWriteByteMask(mtk_dp,
  2106. REG_3440_DP_TRANS_P0,
  2107. 0,
  2108. MASKBIT(3 : 0));
  2109. }
  2110. void mhal_DPTx_PatternSelect(struct mtk_dp *mtk_dp, int Value)
  2111. {
  2112. DPTXFUNC();
  2113. msWriteByteMask(mtk_dp,
  2114. REG_3440_DP_TRANS_P0, (Value << 4), MASKBIT(6 : 4));
  2115. msWriteByteMask(mtk_dp,
  2116. REG_3440_DP_TRANS_P0 + 1, (Value), MASKBIT(2 : 0));
  2117. msWriteByteMask(mtk_dp,
  2118. REG_3440_DP_TRANS_P0 + 1, (Value << 4), MASKBIT(6 : 4));
  2119. msWriteByteMask(mtk_dp,
  2120. REG_3444_DP_TRANS_P0, (Value), MASKBIT(2 : 0));
  2121. }
  2122. void mhal_DPTx_SetProgramPattern(struct mtk_dp *mtk_dp,
  2123. BYTE Value, BYTE *usData)
  2124. {
  2125. DPTXFUNC();
  2126. //16bit RG need *2
  2127. msWriteByte(mtk_dp, REG_3448_DP_TRANS_P0 + Value*6*2, usData[0]);
  2128. msWriteByte(mtk_dp, REG_3448_DP_TRANS_P0 + 1 + Value*6*2, usData[1]);
  2129. msWriteByte(mtk_dp, REG_344C_DP_TRANS_P0 + Value*6*2, usData[2]);
  2130. msWriteByte(mtk_dp, REG_344C_DP_TRANS_P0 + 1 + Value*6*2, usData[3]);
  2131. msWriteByte(mtk_dp, REG_3450_DP_TRANS_P0 + Value*6*2, usData[4]);
  2132. msWriteByte(mtk_dp, REG_3450_DP_TRANS_P0 + 1 + Value*6*2, 0x00);
  2133. }
  2134. void mhal_DPTx_ComplianceEyeEnSetting(struct mtk_dp *mtk_dp, bool bENABLE)
  2135. {
  2136. DPTXFUNC();
  2137. if (bENABLE)
  2138. msWriteByteMask(mtk_dp, REG_3478_DP_TRANS_P0, (BIT0), BIT0);
  2139. else
  2140. msWriteByteMask(mtk_dp, REG_3478_DP_TRANS_P0, (0), BIT0);
  2141. }
  2142. #endif
  2143. void mhal_DPTx_ShutDownDPTxPort(struct mtk_dp *mtk_dp)
  2144. {
  2145. DPTXFUNC();
  2146. //Power Down Tx Aux
  2147. msWriteByteMask(mtk_dp, REG_367C_AUX_TX_P0 + 1, 0, BIT4);
  2148. msWriteByteMask(mtk_dp, REG_3670_AUX_TX_P0 + 1, BIT2, BIT2);
  2149. }
  2150. void mhal_DPTx_AnalogPowerOnOff(struct mtk_dp *mtk_dp, bool enable)
  2151. {
  2152. if (enable) {
  2153. msWriteByteMask(mtk_dp, DP_TX_TOP_RESET_AND_PROBE, 0, BIT4);
  2154. udelay(10);
  2155. msWriteByteMask(mtk_dp, DP_TX_TOP_RESET_AND_PROBE, BIT4, BIT4);
  2156. } else {
  2157. msWrite2Byte(mtk_dp, TOP_OFFSET, 0x0);
  2158. udelay(10);
  2159. msWrite2Byte(mtk_dp, 0x0034, 0x4AA);
  2160. msWrite2Byte(mtk_dp, 0x1040, 0x0);
  2161. msWrite2Byte(mtk_dp, 0x0038, 0x555);
  2162. }
  2163. }