ddp_disp_bdg.c 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2021. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. */
  31. #include <string.h>
  32. #include <platform/ddp_disp_bdg.h>
  33. #include <platform/ddp_reg_disp_bdg.h>
  34. #include <platform/disp_drv_log.h>
  35. #include <platform/ddp_reg.h>
  36. #include <platform/mt6382.h>
  37. #include "lcm_drv.h"
  38. #define SPI_EN
  39. struct BDG_SYSREG_CTRL_REGS *SYS_REG; /* 0x00000000 */
  40. struct BDG_TOPCKGEN_REGS *TOPCKGEN; /* 0x00003000 */
  41. struct BDG_APMIXEDSYS_REGS *APMIXEDSYS; /* 0x00004000 */
  42. struct BDG_GPIO_REGS *GPIO; /* 0x00007000 */
  43. struct BDG_EFUSE_REGS *EFUSE; /* 0x00009000 */
  44. struct BDG_MIPIDSI2_REGS *DSI2_REG; /* 0x0000d000 */
  45. struct BDG_GCE_REGS *GCE_REG; /* 0x00010000 */
  46. struct BDG_OCLA_REGS *OCLA_REG; /* 0x00014000 */
  47. struct BDG_DISP_DSC_REGS *DSC_REG; /* 0x00020000 */
  48. struct BDG_TX_REGS *TX_REG[HW_NUM]; /* 0x00021000 */
  49. struct DSI_TX_CMDQ_REGS *TX_CMDQ_REG[HW_NUM]; /* 0x00021d00 */
  50. struct BDG_MIPI_TX_REGS *MIPI_TX_REG; /* 0x00022000 */
  51. struct BDG_DISPSYS_CONFIG_REGS *DISPSYS_REG; /* 0x00023000 */
  52. struct BDG_RDMA0_REGS *RDMA_REG; /* 0x00024000 */
  53. struct BDG_MUTEX_REGS *MUTEX_REG; /* 0x00025000 */
  54. struct DSI_TX_PHY_TIMCON0_REG timcon0;
  55. struct DSI_TX_PHY_TIMCON1_REG timcon1;
  56. struct DSI_TX_PHY_TIMCON2_REG timcon2;
  57. struct DSI_TX_PHY_TIMCON3_REG timcon3;
  58. unsigned int bg_tx_data_phy_cycle;
  59. unsigned int tx_data_rate, ap_tx_data_rate;
  60. unsigned int hsa_byte, hbp_byte, hfp_byte;
  61. unsigned int bllp_byte, bg_tx_line_cycle;
  62. unsigned int dsc_en;
  63. unsigned int mt6382_init;
  64. int mt6382_connected;
  65. unsigned int bdg_tx_mode;
  66. #define T_DCO 5 /* nominal: 200MHz */
  67. int hsrx_clk_div;
  68. int hs_thssettle, fjump_deskew_reg, eye_open_deskew_reg;
  69. int cdr_coarse_trgt_reg, en_dly_deass_thresh_reg;
  70. int max_phase, dll_fbk, coarse_bank, sel_fast;
  71. int post_rcvd_rst_val, post_det_dly_thresh_val;
  72. unsigned int post_rcvd_rst_reg, post_det_dly_thresh_reg;
  73. unsigned int ddl_cntr_ref_reg;
  74. #define REGFLAG_DELAY 0xFFFC
  75. #define REGFLAG_UDELAY 0xFFFB
  76. #define REGFLAG_END_OF_TABLE 0xFFFD
  77. #define REGFLAG_RESET_LOW 0xFFFE
  78. #define REGFLAG_RESET_HIGH 0xFFFF
  79. struct lcm_setting_table {
  80. unsigned int cmd;
  81. unsigned char count;
  82. unsigned char para_list[64];
  83. };
  84. #define MM_CLK 270
  85. #define NS_TO_CYCLE(n, c) ((n) / (c) + (((n) % (c)) ? 1 : 0))
  86. #define DSI_MODULE_to_ID(x) \
  87. (x == DISP_BDG_DSI0 ? 0 : 1)
  88. #define DSI_MODULE_BEGIN(x) (\
  89. x == DISP_BDG_DSIDUAL ? \
  90. 0 : DSI_MODULE_to_ID(x))
  91. #define DSI_MODULE_END(x) \
  92. (x == DISP_BDG_DSIDUAL ? \
  93. 1 : DSI_MODULE_to_ID(x))
  94. /* #define SW_EARLY_PORTING */
  95. unsigned int mtk_spi_read(u32 addr)
  96. {
  97. unsigned int value = 0;
  98. #ifdef SW_EARLY_PORTING
  99. #else
  100. spislv_read(addr, &value, 4);
  101. #endif
  102. /*
  103. * DISPMSG("%s, addr=0x%08x, value=0x%08x\n", __func__, addr, value);
  104. */
  105. return value;
  106. }
  107. int mtk_spi_write(u32 addr, unsigned int regval)
  108. {
  109. unsigned int value = regval;
  110. int ret = 0;
  111. /*
  112. * DISPMSG("mt6382, %s, addr=0x%08x, value=0x%x\n",
  113. * __func__, addr, value);
  114. */
  115. #ifdef SW_EARLY_PORTING
  116. #else
  117. ret = spislv_write(addr, &value, 4);
  118. #endif
  119. return ret;
  120. }
  121. int mtk_spi_mask_write_1(u32 addr, u32 msk, u32 value)
  122. {
  123. /*
  124. * DISPMSG("mt6382, %s, addr=0x%08x, msk=0x%08x, value=0x%x\n",
  125. * __func__, addr, msk, value);
  126. */
  127. #ifdef SW_EARLY_PORTING
  128. return 0;
  129. #else
  130. spislv_write_register_mask(addr, value, msk);
  131. return 1;
  132. #endif
  133. }
  134. int mtk_spi_mask_write(u32 addr, u32 msk, u32 value)
  135. {
  136. unsigned int i = 0;
  137. unsigned int temp;
  138. for (i = 0; i < 32; i++) {
  139. temp = 1 << i;
  140. if ((msk & temp) == temp)
  141. break;
  142. }
  143. value = value << i;
  144. /*
  145. * DISPMSG("mt6382, %s, i=%02d, temp=0x%08x, addr=0x%08x,
  146. * msk=0x%08x, value=0x%x\n",
  147. * __func__, i, temp, addr, msk, value);
  148. */
  149. #ifdef SW_EARLY_PORTING
  150. return 0;
  151. #else
  152. spislv_write_register_mask(addr, value, msk);
  153. return 1;
  154. #endif
  155. }
  156. int mtk_spi_mask_field_write(u32 addr, u32 msk, u32 value)
  157. {
  158. unsigned int i = 0;
  159. unsigned int temp;
  160. for (i = 0; i < 32; i++) {
  161. temp = 1 << i;
  162. if ((msk & temp) == temp)
  163. break;
  164. }
  165. value = value << i;
  166. /*
  167. * DISPMSG("mt6382, %s, i=%02d, temp=0x%08x, addr=0x%08x,
  168. * msk=0x%08x, value=0x%x\n",
  169. * __func__, i, temp, addr, msk, value);
  170. */
  171. #ifdef SW_EARLY_PORTING
  172. return 0;
  173. #else
  174. spislv_write_register_mask(addr, value, msk);
  175. return 0;
  176. #endif
  177. }
  178. #ifdef SPI_EN
  179. #define DSI_OUTREG32(cmdq, addr, val) \
  180. mtk_spi_write((unsigned long)(&addr), val)
  181. #define DSI_MASKREG32(cmdq, addr, mask, val) \
  182. mtk_spi_mask_write((unsigned long)(addr), mask, val)
  183. #else
  184. #define DSI_OUTREG32(spi_en, cmdq, addr, val) \
  185. { \
  186. if (spi_en) { \
  187. mtk_spi_write((unsigned long)(&addr), val); \
  188. } \
  189. else { \
  190. DISP_REG_SET(cmdq, addr, val); \
  191. } \
  192. }
  193. #define DSI_MASKREG32(spi_en, cmdq, addr, mask, val) \
  194. { \
  195. if (spi_en) { \
  196. mtk_spi_mask_write((unsigned long)(addr), mask, val); \
  197. } \
  198. else { \
  199. DISP_REG_SET(cmdq, addr, val); \
  200. } \
  201. }
  202. #endif
  203. bool bdg_is_bdg_connected(void)
  204. {
  205. DISPFUNCSTART();
  206. if (mt6382_connected == 0) {
  207. unsigned long CHIP_ID_REG = 0x0;
  208. unsigned int ret = 0;
  209. #ifdef CONFIG_MTK_MT6382_BDG
  210. spislv_init();
  211. spislv_switch_speed_hz(SPI_TX_LOW_SPEED_HZ,
  212. SPI_RX_LOW_SPEED_HZ);
  213. ret = mtk_spi_read(0x0);
  214. #endif
  215. if (ret == 0)
  216. mt6382_connected = -1;
  217. else
  218. mt6382_connected = 1;
  219. }
  220. if (mt6382_connected > 0)
  221. return true;
  222. else
  223. return false;
  224. }
  225. static void bdg_get_chip_id(void)
  226. {
  227. }
  228. void bdg_test_write_spi(void)
  229. {
  230. int i = 0;
  231. for (i = 0; i < 1000; i++)
  232. DSI_OUTREG32(NULL, TX_REG[0]->DSI_TX_SELF_PAT_CON0, 0x11);
  233. }
  234. void bdg_tx_pull_lcm_reset_pin(void)
  235. {
  236. bdg_tx_set_lcm_reset_pin(1);
  237. mdelay(10);
  238. bdg_tx_set_lcm_reset_pin(0);
  239. mdelay(10);
  240. bdg_tx_set_lcm_reset_pin(1);
  241. mdelay(10);
  242. }
  243. void bdg_tx_set_lcm_reset_pin(unsigned int value)
  244. {
  245. int rst_pin;
  246. rst_pin = lcm_util_get_pin("mtkfb_pins_lcm_rst_out0_gpio");
  247. if (rst_pin < 0) {
  248. OUTREG32(MMSYS_CONFIG_BASE+0x150, value);
  249. dprintf(0, "reg set lcm rst pin\n");
  250. } else {
  251. dprintf(0, "gpio set lcm rst pin\n");
  252. mt_set_gpio_mode(rst_pin, GPIO_MODE_00);
  253. mt_set_gpio_dir(rst_pin, GPIO_DIR_OUT);
  254. if (value)
  255. mt_set_gpio_out(rst_pin, GPIO_OUT_ONE);
  256. else
  257. mt_set_gpio_out(rst_pin, GPIO_OUT_ZERO);
  258. }
  259. }
  260. void bdg_tx_pull_6382_reset_pin(void)
  261. {
  262. bdg_tx_set_6382_reset_pin(1);
  263. mdelay(10);
  264. bdg_tx_set_6382_reset_pin(0);
  265. mdelay(10);
  266. bdg_tx_set_6382_reset_pin(1);
  267. mdelay(10);
  268. }
  269. void bdg_tx_set_6382_reset_pin(unsigned int value)
  270. {
  271. int rst_pin;
  272. rst_pin = lcm_util_get_pin("6382_rst_out0_gpio");
  273. if (rst_pin < 0) {
  274. OUTREG32(MMSYS_CONFIG_BASE+0x150, value);
  275. dprintf(0, "reg set lcm rst pin\n");
  276. } else {
  277. dprintf(0, "gpio set lcm rst pin\n");
  278. mt_set_gpio_mode(rst_pin, GPIO_MODE_00);
  279. mt_set_gpio_dir(rst_pin, GPIO_DIR_OUT);
  280. if (value)
  281. mt_set_gpio_out(rst_pin, GPIO_OUT_ONE);
  282. else
  283. mt_set_gpio_out(rst_pin, GPIO_OUT_ZERO);
  284. }
  285. }
  286. void bdg_tx_set_test_pattern(void)
  287. {
  288. DSI_OUTREG32(NULL, TX_REG[0]->DSI_TX_SELF_PAT_CON0, 0x11);
  289. DSI_OUTREG32(NULL, TX_REG[0]->DSI_TX_INTSTA, 0x0);
  290. }
  291. struct lcm_setting_table nt36672c_60hz[] = {
  292. {0xFF, 1, {0x10} },
  293. {0xFB, 1, {0x01} },
  294. /* DSC on */
  295. {0xC0, 1, {0x03} },
  296. {0xC1, 16, {0x89, 0x28, 0x00, 0x08, 0x00, 0xAA,
  297. 0x02, 0x0E, 0x00, 0x2B, 0x00, 0x07, 0x0D,
  298. 0xB7, 0x0C, 0xB7} },
  299. {0xC2, 2, {0x1B, 0xA0} },
  300. {0xFF, 1, {0x20} },
  301. {0xFB, 1, {0x01} },
  302. {0x01, 1, {0x66} },
  303. {0x32, 1, {0x4D} },
  304. {0x69, 1, {0xD1} },
  305. {0xF2, 1, {0x64} },
  306. {0xF4, 1, {0x64} },
  307. {0xF6, 1, {0x64} },
  308. {0xF9, 1, {0x64} },
  309. {0xFF, 1, {0x26} },
  310. {0xFB, 1, {0x01} },
  311. {0x81, 1, {0x0E} },
  312. {0x84, 1, {0x03} },
  313. {0x86, 1, {0x03} },
  314. {0x88, 1, {0x07} },
  315. {0xFF, 1, {0x27} },
  316. {0xFB, 1, {0x01} },
  317. {0xE3, 1, {0x01} },
  318. {0xE4, 1, {0xEC} },
  319. {0xE5, 1, {0x02} },
  320. {0xE6, 1, {0xE3} },
  321. {0xE7, 1, {0x01} },
  322. {0xE8, 1, {0xEC} },
  323. {0xE9, 1, {0x02} },
  324. {0xEA, 1, {0x22} },
  325. {0xEB, 1, {0x03} },
  326. {0xEC, 1, {0x32} },
  327. {0xED, 1, {0x02} },
  328. {0xEE, 1, {0x22} },
  329. {0xFF, 1, {0x2A} },
  330. {0xFB, 1, {0x01} },
  331. {0x0C, 1, {0x04} },
  332. {0x0F, 1, {0x01} },
  333. {0x11, 1, {0xE0} },
  334. {0x15, 1, {0x0E} },
  335. {0x16, 1, {0x78} },
  336. {0x19, 1, {0x0D} },
  337. {0x1A, 1, {0xF4} },
  338. {0x37, 1, {0X6E} },
  339. {0x88, 1, {0X76} },
  340. {0xFF, 1, {0x2C} },
  341. {0xFB, 1, {0x01} },
  342. {0x4D, 1, {0x1E} },
  343. {0x4E, 1, {0x04} },
  344. {0x4F, 1, {0X00} },
  345. {0x9D, 1, {0X1E} },
  346. {0x9E, 1, {0X04} },
  347. {0xFF, 1, {0xF0} },
  348. {0xFB, 1, {0x01} },
  349. {0x5A, 1, {0x00} },
  350. {0xFF, 1, {0xE0} },
  351. {0xFB, 1, {0x01} },
  352. {0x25, 1, {0x02} },
  353. {0x4E, 1, {0x02} },
  354. {0x85, 1, {0x02} },
  355. {0xFF, 1, {0XD0} },
  356. {0xFB, 1, {0x01} },
  357. {0X09, 1, {0XAD} },
  358. {0xFF, 1, {0X20} },
  359. {0xFB, 1, {0x01} },
  360. {0XF8, 1, {0X64} },
  361. {0xFF, 1, {0X2A} },
  362. {0xFB, 1, {0x01} },
  363. {0X1A, 1, {0XF0} },
  364. {0x30, 1, {0x5E} },
  365. {0x31, 1, {0xCA} },
  366. {0x34, 1, {0xFE} },
  367. {0x35, 1, {0x35} },
  368. {0x36, 1, {0xA2} },
  369. {0x37, 1, {0xF8} },
  370. {0x38, 1, {0x37} },
  371. {0x39, 1, {0xA0} },
  372. {0x3A, 1, {0x5E} },
  373. {0x53, 1, {0xD7} },
  374. {0x88, 1, {0x72} },
  375. {0x88, 1, {0x72} },
  376. {0xFF, 1, {0x24} },
  377. {0xFB, 1, {0x01} },
  378. {0xC6, 1, {0xC0} },
  379. {0xFF, 1, {0xE0} },
  380. {0xFB, 1, {0x01} },
  381. {0x25, 1, {0x00} },
  382. {0x4E, 1, {0x02} },
  383. {0x35, 1, {0x82} },
  384. {0xFF, 1, {0xC0} },
  385. {0xFB, 1, {0x01} },
  386. {0x9C, 1, {0x11} },
  387. {0x9D, 1, {0x11} },
  388. /* 60HZ VESA DSC */
  389. {0xFF, 1, {0x25} },
  390. {0xFB, 1, {0x01} },
  391. {0x18, 1, {0x22} },
  392. /* CCMRUN */
  393. {0xFF, 1, {0x10} },
  394. {0xFB, 1, {0x01} },
  395. {0xC0, 1, {0x03} },
  396. {0x51, 1, {0x00} },
  397. {0x35, 1, {0x00} },
  398. {0x53, 1, {0x24} },
  399. {0x55, 1, {0x00} },
  400. {0xFF, 1, {0x10} },
  401. {0x11, 0, {} },
  402. {REGFLAG_DELAY, 120, {} },
  403. /* Display On */
  404. {0x29, 0, {} },
  405. };
  406. struct lcm_setting_table nt36672c_90hz[] = {
  407. {0xFF, 1, {0x10} },
  408. {0xFB, 1, {0x01} },
  409. /* DSC on */
  410. {0xC0, 1, {0x03} },
  411. {0xC1, 16, {0x89, 0x28, 0x00, 0x08, 0x00, 0xAA,
  412. 0x02, 0x0E, 0x00, 0x2B, 0x00, 0x07, 0x0D,
  413. 0xB7, 0x0C, 0xB7} },
  414. {0xC2, 2, {0x1B, 0xA0} },
  415. {0xFF, 1, {0x20} },
  416. {0xFB, 1, {0x01} },
  417. {0x01, 1, {0x66} },
  418. {0x32, 1, {0x4D} },
  419. {0x69, 1, {0xD1} },
  420. {0xF2, 1, {0x64} },
  421. {0xF4, 1, {0x64} },
  422. {0xF6, 1, {0x64} },
  423. {0xF9, 1, {0x64} },
  424. {0xFF, 1, {0x26} },
  425. {0xFB, 1, {0x01} },
  426. {0x81, 1, {0x0E} },
  427. {0x84, 1, {0x03} },
  428. {0x86, 1, {0x03} },
  429. {0x88, 1, {0x07} },
  430. {0xFF, 1, {0x27} },
  431. {0xFB, 1, {0x01} },
  432. {0xE3, 1, {0x01} },
  433. {0xE4, 1, {0xEC} },
  434. {0xE5, 1, {0x02} },
  435. {0xE6, 1, {0xE3} },
  436. {0xE7, 1, {0x01} },
  437. {0xE8, 1, {0xEC} },
  438. {0xE9, 1, {0x02} },
  439. {0xEA, 1, {0x22} },
  440. {0xEB, 1, {0x03} },
  441. {0xEC, 1, {0x32} },
  442. {0xED, 1, {0x02} },
  443. {0xEE, 1, {0x22} },
  444. {0xFF, 1, {0x2A} },
  445. {0xFB, 1, {0x01} },
  446. {0x0C, 1, {0x04} },
  447. {0x0F, 1, {0x01} },
  448. {0x11, 1, {0xE0} },
  449. {0x15, 1, {0x0E} },
  450. {0x16, 1, {0x78} },
  451. {0x19, 1, {0x0D} },
  452. {0x1A, 1, {0xF4} },
  453. {0x37, 1, {0X6E} },
  454. {0x88, 1, {0X76} },
  455. {0xFF, 1, {0x2C} },
  456. {0xFB, 1, {0x01} },
  457. {0x4D, 1, {0x1E} },
  458. {0x4E, 1, {0x04} },
  459. {0x4F, 1, {0X00} },
  460. {0x9D, 1, {0X1E} },
  461. {0x9E, 1, {0X04} },
  462. {0xFF, 1, {0xF0} },
  463. {0xFB, 1, {0x01} },
  464. {0x5A, 1, {0x00} },
  465. {0xFF, 1, {0xE0} },
  466. {0xFB, 1, {0x01} },
  467. {0x25, 1, {0x02} },
  468. {0x4E, 1, {0x02} },
  469. {0x85, 1, {0x02} },
  470. {0xFF, 1, {0XD0} },
  471. {0xFB, 1, {0x01} },
  472. {0X09, 1, {0XAD} },
  473. {0xFF, 1, {0X20} },
  474. {0xFB, 1, {0x01} },
  475. {0XF8, 1, {0X64} },
  476. {0xFF, 1, {0X2A} },
  477. {0xFB, 1, {0x01} },
  478. {0X1A, 1, {0XF0} },
  479. {0x30, 1, {0x5E} },
  480. {0x31, 1, {0xCA} },
  481. {0x34, 1, {0xFE} },
  482. {0x35, 1, {0x35} },
  483. {0x36, 1, {0xA2} },
  484. {0x37, 1, {0xF8} },
  485. {0x38, 1, {0x37} },
  486. {0x39, 1, {0xA0} },
  487. {0x3A, 1, {0x5E} },
  488. {0x53, 1, {0xD7} },
  489. {0x88, 1, {0x72} },
  490. {0x88, 1, {0x72} },
  491. {0xFF, 1, {0x24} },
  492. {0xFB, 1, {0x01} },
  493. {0xC6, 1, {0xC0} },
  494. {0xFF, 1, {0xE0} },
  495. {0xFB, 1, {0x01} },
  496. {0x25, 1, {0x00} },
  497. {0x4E, 1, {0x02} },
  498. {0x35, 1, {0x82} },
  499. {0xFF, 1, {0xC0} },
  500. {0xFB, 1, {0x01} },
  501. {0x9C, 1, {0x11} },
  502. {0x9D, 1, {0x11} },
  503. /* 90HZ VESA DSC */
  504. {0xFF, 1, {0x25} },
  505. {0xFB, 1, {0x01} },
  506. {0x18, 1, {0x21} },
  507. /* CCMRUN */
  508. {0xFF, 1, {0x10} },
  509. {0xFB, 1, {0x01} },
  510. {0xC0, 1, {0x03} },
  511. {0x51, 1, {0x00} },
  512. {0x35, 1, {0x00} },
  513. {0x53, 1, {0x24} },
  514. {0x55, 1, {0x00} },
  515. {0xFF, 1, {0x10} },
  516. {0x11, 0, {} },
  517. {REGFLAG_DELAY, 120, {} },
  518. /* Display On*/
  519. {0x29, 0, {} },
  520. };
  521. struct lcm_setting_table nt36672c_120hz[] = {
  522. {0xFF, 1, {0x10} },
  523. {0xFB, 1, {0x01} },
  524. /*DSC on*/
  525. {0xC0, 1, {0x03} },
  526. {0xC1, 16, {0x89, 0x28, 0x00, 0x08, 0x00,
  527. 0xAA, 0x02, 0x0E, 0x00, 0x2B, 0x00,
  528. 0x07, 0x0D, 0xB7, 0x0C, 0xB7} },
  529. {0xC2, 2, {0x1B, 0xA0} },
  530. {0xFF, 1, {0x20} },
  531. {0xFB, 1, {0x01} },
  532. {0x01, 1, {0x66} },
  533. {0x32, 1, {0x4D} },
  534. {0x69, 1, {0xD1} },
  535. {0xF2, 1, {0x64} },
  536. {0xF4, 1, {0x64} },
  537. {0xF6, 1, {0x64} },
  538. {0xF9, 1, {0x64} },
  539. {0xFF, 1, {0x26} },
  540. {0xFB, 1, {0x01} },
  541. {0x81, 1, {0x0E} },
  542. {0x84, 1, {0x03} },
  543. {0x86, 1, {0x03} },
  544. {0x88, 1, {0x07} },
  545. {0xFF, 1, {0x27} },
  546. {0xFB, 1, {0x01} },
  547. {0xE3, 1, {0x01} },
  548. {0xE4, 1, {0xEC} },
  549. {0xE5, 1, {0x02} },
  550. {0xE6, 1, {0xE3} },
  551. {0xE7, 1, {0x01} },
  552. {0xE8, 1, {0xEC} },
  553. {0xE9, 1, {0x02} },
  554. {0xEA, 1, {0x22} },
  555. {0xEB, 1, {0x03} },
  556. {0xEC, 1, {0x32} },
  557. {0xED, 1, {0x02} },
  558. {0xEE, 1, {0x22} },
  559. {0xFF, 1, {0x2A} },
  560. {0xFB, 1, {0x01} },
  561. {0x0C, 1, {0x04} },
  562. {0x0F, 1, {0x01} },
  563. {0x11, 1, {0xE0} },
  564. {0x15, 1, {0x0E} },
  565. {0x16, 1, {0x78} },
  566. {0x19, 1, {0x0D} },
  567. {0x1A, 1, {0xF4} },
  568. {0x37, 1, {0X6E} },
  569. {0x88, 1, {0X76} },
  570. {0xFF, 1, {0x2C} },
  571. {0xFB, 1, {0x01} },
  572. {0x4D, 1, {0x1E} },
  573. {0x4E, 1, {0x04} },
  574. {0x4F, 1, {0X00} },
  575. {0x9D, 1, {0X1E} },
  576. {0x9E, 1, {0X04} },
  577. {0xFF, 1, {0xF0} },
  578. {0xFB, 1, {0x01} },
  579. {0x5A, 1, {0x00} },
  580. {0xFF, 1, {0xE0} },
  581. {0xFB, 1, {0x01} },
  582. {0x25, 1, {0x02} },
  583. {0x4E, 1, {0x02} },
  584. {0x85, 1, {0x02} },
  585. {0xFF, 1, {0XD0} },
  586. {0xFB, 1, {0x01} },
  587. {0X09, 1, {0XAD} },
  588. {0xFF, 1, {0X20} },
  589. {0xFB, 1, {0x01} },
  590. {0XF8, 1, {0X64} },
  591. {0xFF, 1, {0X2A} },
  592. {0xFB, 1, {0x01} },
  593. {0X1A, 1, {0XF0} },
  594. {0x30, 1, {0x5E} },
  595. {0x31, 1, {0xCA} },
  596. {0x34, 1, {0xFE} },
  597. {0x35, 1, {0x35} },
  598. {0x36, 1, {0xA2} },
  599. {0x37, 1, {0xF8} },
  600. {0x38, 1, {0x37} },
  601. {0x39, 1, {0xA0} },
  602. {0x3A, 1, {0x5E} },
  603. {0x53, 1, {0xD7} },
  604. {0x88, 1, {0x72} },
  605. {0x88, 1, {0x72} },
  606. {0xFF, 1, {0x24} },
  607. {0xFB, 1, {0x01} },
  608. {0xC6, 1, {0xC0} },
  609. {0xFF, 1, {0xE0} },
  610. {0xFB, 1, {0x01} },
  611. {0x25, 1, {0x00} },
  612. {0x4E, 1, {0x02} },
  613. {0x35, 1, {0x82} },
  614. {0xFF, 1, {0xC0} },
  615. {0xFB, 1, {0x01} },
  616. {0x9C, 1, {0x11} },
  617. {0x9D, 1, {0x11} },
  618. /* 120HZ VESA DSC */
  619. {0xFF, 1, {0x25} },
  620. {0xFB, 1, {0x01} },
  621. {0x18, 1, {0x20} },
  622. /* CCMRUN */
  623. {0xFF, 1, {0x10} },
  624. {0xFB, 1, {0x01} },
  625. {0xC0, 1, {0x03} },
  626. {0x51, 1, {0x00} },
  627. {0x35, 1, {0x00} },
  628. {0x53, 1, {0x24} },
  629. {0x55, 1, {0x00} },
  630. {0xFF, 1, {0x10} },
  631. {0x11, 0, {} },
  632. {REGFLAG_DELAY, 120, {} },
  633. /* Display On*/
  634. {0x29, 0, {} },
  635. };
  636. struct lcm_setting_table nt36672c_wo_dsc[] = {
  637. {0xC0, 1, {0x00} },
  638. };
  639. void set_LDO_on(void *cmdq)
  640. {
  641. unsigned int reg1, reg2, reg3;
  642. unsigned int timeout = 100;
  643. while (timeout) {
  644. reg1 = (mtk_spi_read((unsigned long)
  645. (&SYS_REG->LDO_STATUS)) & 0x300);
  646. DISPMSG("mt6382, %s, LDO_STATUS=0x%x\n", __func__, reg1);
  647. if (reg1 == 0x300)
  648. break;
  649. udelay(10);
  650. timeout--;
  651. }
  652. if (timeout == 0)
  653. return;
  654. reg1 = (mtk_spi_read((unsigned long)
  655. (&EFUSE->STATUS)) & 0x7fffff);
  656. DISPMSG("mt6382, %s, EFUSE_STATUS=0x%x\n", __func__, reg1);
  657. if (reg1 != 0) {
  658. reg1 = (mtk_spi_read((unsigned long)(&EFUSE->TRIM1)) & 0x3f);
  659. reg2 = (mtk_spi_read((unsigned long)(&EFUSE->TRIM2)) & 0xf);
  660. reg3 = (mtk_spi_read((unsigned long)(&EFUSE->TRIM3)) & 0xf);
  661. DISPMSG("mt6382, %s, TRIM1=0x%x, TRIM2=0x%x, TRIM3=0x%x\n",
  662. __func__, reg1, reg2, reg3);
  663. if ((reg1 != 0) || (reg2 != 0) || (reg2 != 0)) {
  664. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  665. REG_SYSREG_LDO_CTRL0),
  666. SYSREG_LDO_CTRL0_FLD_RG_PHYLDO_MASKB, 1);
  667. }
  668. }
  669. }
  670. void set_LDO_off(void *cmdq)
  671. {
  672. DISPFUNCSTART();
  673. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  674. REG_SYSREG_LDO_CTRL1),
  675. SYSREG_LDO_CTRL1_FLD_RG_PHYLDO2_EN, 0);
  676. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  677. REG_SYSREG_LDO_CTRL1),
  678. SYSREG_LDO_CTRL1_FLD_RG_PHYLDO1_LP_EN, 1);
  679. DISPFUNCEND();
  680. }
  681. void set_mtcmos_on(void *cmdq)
  682. {
  683. unsigned int reg = 0;
  684. DISPFUNCSTART();
  685. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  686. REG_SYSREG_PWR_CTRL),
  687. SYSREG_PWR_CTRL_FLD_REG_PWR_ON, 1);
  688. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  689. REG_SYSREG_PWR_CTRL),
  690. SYSREG_PWR_CTRL_FLD_REG_PWR_ON_2ND, 1);
  691. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  692. REG_SYSREG_RST_CTRL),
  693. SYSREG_RST_CTRL_FLD_REG_SW_RST_EN_DISP_PWR_WRAP, 0);
  694. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  695. REG_SYSREG_PWR_CTRL),
  696. SYSREG_PWR_CTRL_FLD_REG_PISO_EN, 0);
  697. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  698. REG_SYSREG_PWR_CTRL),
  699. SYSREG_PWR_CTRL_FLD_REG_DISP_PWR_CLK_DIS, 0);
  700. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  701. REG_SYSREG_PWR_CTRL),
  702. SYSREG_PWR_CTRL_FLD_REG_SYSBUF_SRAM_SLEEP_B, 1);
  703. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  704. REG_SYSREG_PWR_CTRL),
  705. SYSREG_PWR_CTRL_FLD_REG_GCE_SRAM_SLEEP_B, 1);
  706. reg = mtk_spi_read((unsigned long)(&SYS_REG->SYSREG_PWR_CTRL));
  707. reg = reg | 0x00880000;
  708. reg = reg & 0xffbbefff;
  709. DSI_OUTREG32(cmdq, SYS_REG->SYSREG_PWR_CTRL, reg);
  710. DISPFUNCEND();
  711. }
  712. void set_mtcmos_off(void *cmdq)
  713. {
  714. unsigned int reg = 0;
  715. DISPFUNCSTART();
  716. reg = mtk_spi_read((unsigned long)(&SYS_REG->SYSREG_PWR_CTRL));
  717. reg = reg & 0x00000fff;
  718. reg = reg | 0x00661000;
  719. DSI_OUTREG32(cmdq, SYS_REG->SYSREG_PWR_CTRL, reg);
  720. reg = mtk_spi_read((unsigned long)(&SYS_REG->SYSREG_PWR_CTRL));
  721. reg = reg & 0xffddffff;
  722. DSI_OUTREG32(cmdq, SYS_REG->SYSREG_PWR_CTRL, reg);
  723. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  724. REG_SYSREG_PWR_CTRL),
  725. SYSREG_PWR_CTRL_FLD_REG_DISP_PWR_CLK_DIS, 1);
  726. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  727. REG_SYSREG_PWR_CTRL),
  728. SYSREG_PWR_CTRL_FLD_REG_PISO_EN, 1);
  729. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  730. REG_SYSREG_RST_CTRL),
  731. SYSREG_RST_CTRL_FLD_REG_SW_RST_EN_DISP_PWR_WRAP, 1);
  732. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  733. REG_SYSREG_PWR_CTRL),
  734. SYSREG_PWR_CTRL_FLD_REG_PWR_ON_2ND, 0);
  735. mtk_spi_mask_write((u32)(DISPSYS_BDG_SYSREG_CTRL_BASE +
  736. REG_SYSREG_PWR_CTRL),
  737. SYSREG_PWR_CTRL_FLD_REG_PWR_ON, 0);
  738. DISPFUNCEND();
  739. }
  740. void set_pll_on(void *cmdq)
  741. {
  742. DISPFUNCSTART();
  743. }
  744. void set_pll_off(void *cmdq)
  745. {
  746. DISPFUNCSTART();
  747. }
  748. void ana_macro_on(void *cmdq)
  749. {
  750. unsigned int reg = 0;
  751. DISPFUNCSTART();
  752. /*select pll power on `MAINPLL_CON3*/
  753. DSI_OUTREG32(cmdq, APMIXEDSYS->MAINPLL_CON3, 3);
  754. udelay(1);
  755. DSI_OUTREG32(cmdq, APMIXEDSYS->MAINPLL_CON3, 1);
  756. DSI_OUTREG32(cmdq, APMIXEDSYS->MAINPLL_CON0, 0xff000000);
  757. DSI_OUTREG32(cmdq, APMIXEDSYS->MAINPLL_CON1, 0x000fc000);
  758. udelay(2);
  759. DSI_OUTREG32(cmdq, APMIXEDSYS->MAINPLL_CON0, 0xff000001);
  760. udelay(25);
  761. DSI_OUTREG32(cmdq, APMIXEDSYS->MAINPLL_CON0, 0xff800001);
  762. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0_CLR, 0xffffffff);
  763. /* set clock source
  764. * bit 16-17 is display mm clk 1(270m)/2(405m)/3(540m)
  765. * dsc_on:vact * hact * vrefresh * (vtotal / vact) * bubble_ratio
  766. */
  767. switch (MM_CLK) {
  768. case 546:
  769. DISPMSG("%s, 6382 mmclk 546M\n", __func__);
  770. reg = (3 << 24) | (3 << 16) | (1 << 8) | (1 << 0); //540M
  771. break;
  772. case 405:
  773. DISPMSG("%s, 6382 mmclk 405M\n", __func__);
  774. reg = (3 << 24) | (2 << 16) | (1 << 8) | (1 << 0); //405M for 120Hz
  775. break;
  776. case 270:
  777. DISPMSG("%s, 6382 mmclk 270M\n", __func__);
  778. reg = (3 << 24) | (1 << 16) | (1 << 8) | (1 << 0); //270M for 90Hz
  779. break;
  780. default:
  781. DISPMSG("%s, 6382 mmclk default 546M\n", __func__);
  782. reg = (3 << 24) | (3 << 16) | (1 << 8) | (1 << 0); //540M
  783. break;
  784. }
  785. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0_SET, reg);
  786. /*config update*/
  787. reg = (1 << 4) | (1 << 3) | (1 << 1) | (1 << 0);
  788. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_UPDATE, reg);
  789. udelay(6);
  790. DISPFUNCEND();
  791. }
  792. void ana_macro_off(void *cmdq)
  793. {
  794. unsigned int reg = 0;
  795. DISPFUNCSTART();
  796. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_SHUTDOWNZ_OS, 0);
  797. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_RSTZ_OS, 0);
  798. /*config update*/
  799. reg = (3 << 24) | (3 << 16) | (1 << 8) | (3 << 0);
  800. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0_CLR, reg);
  801. reg = (1 << 4) | (1 << 3) | (1 << 1) | (1 << 0);
  802. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_UPDATE, reg);
  803. /*#5000ns wait clk mux stable*/
  804. udelay(6);
  805. set_pll_off(cmdq);
  806. }
  807. void set_topck_on(void *cmdq)
  808. {
  809. unsigned int reg = 0;
  810. DISPFUNCSTART();
  811. reg = mtk_spi_read((unsigned long)(&TOPCKGEN->CLK_MODE));
  812. reg = reg & 0xfffffffd;
  813. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_MODE, reg);
  814. reg = mtk_spi_read((unsigned long)(&TOPCKGEN->CLK_CFG_0));
  815. reg = reg & 0xdf7f7f7f;
  816. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0, reg);
  817. DISPFUNCEND();
  818. }
  819. void set_topck_off(void *cmdq)
  820. {
  821. unsigned int reg = 0;
  822. DISPFUNCSTART();
  823. /*select clock source*/
  824. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0_CLR, 0x03030103);
  825. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0_SET, 0);
  826. /*config update*/
  827. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_UPDATE, 0x0000001b);
  828. /*#5000ns wait clk mux stable*/
  829. udelay(6);
  830. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0_CLR, 0x00808080);
  831. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_0_SET, 0x00808080);
  832. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_CFG_UPDATE, 0x0000001b);
  833. reg = mtk_spi_read((unsigned long)(&TOPCKGEN->CLK_MODE));
  834. reg = reg | 0x00000001;
  835. DSI_OUTREG32(cmdq, TOPCKGEN->CLK_MODE, reg);
  836. }
  837. void set_subsys_on(void *cmdq)
  838. {
  839. unsigned int reg = 0;
  840. DISPFUNCSTART();
  841. reg = mtk_spi_read((unsigned long)(&GCE_REG->GCE_CTL_INT0));
  842. reg = reg & 0x0000ffff;
  843. DSI_OUTREG32(cmdq, GCE_REG->GCE_CTL_INT0, reg);
  844. /*Clear CG*/
  845. DSI_OUTREG32(cmdq, DISPSYS_REG->MMSYS_CG_CON0, 0);
  846. /*Turn off all DCM, Clock on*/
  847. reg = mtk_spi_read((unsigned long)(&EFUSE->DCM_ON));
  848. reg = reg & 0xfffffff8;
  849. DSI_OUTREG32(cmdq, EFUSE->DCM_ON, reg);
  850. reg = mtk_spi_read((unsigned long)(&GCE_REG->GCE_CTL_INT0));
  851. reg = reg | 0x0000ffff;
  852. DSI_OUTREG32(cmdq, GCE_REG->GCE_CTL_INT0, reg);
  853. DSI_OUTREG32(cmdq, DISPSYS_REG->MMSYS_HW_DCM_1ST_DIS0, 0xffffffff);
  854. DSI_OUTREG32(cmdq, DISPSYS_REG->MMSYS_HW_DCM_2ND_DIS0, 0xffffffff);
  855. /*enable 26m clock*/
  856. DSI_OUTREG32(cmdq, SYS_REG->DISP_MISC1, 1);
  857. DISPFUNCEND();
  858. }
  859. void set_subsys_off(void *cmdq)
  860. {
  861. unsigned int reg = 0;
  862. DISPFUNCSTART();
  863. reg = mtk_spi_read((unsigned long)(&GCE_REG->GCE_CTL_INT0));
  864. reg = reg | 0x00010000;
  865. DSI_OUTREG32(cmdq, GCE_REG->GCE_CTL_INT0, reg);
  866. reg = mtk_spi_read((unsigned long)(&GCE_REG->GCE_CTL_INT0));
  867. reg = reg & 0x0001ffff;
  868. DSI_OUTREG32(cmdq, GCE_REG->GCE_CTL_INT0, reg);
  869. /*Set CG*/
  870. DSI_OUTREG32(cmdq, DISPSYS_REG->MMSYS_CG_CON0, 0xffffffff);
  871. /*Turn on all DCM, Clock off*/
  872. reg = mtk_spi_read((unsigned long)(&EFUSE->DCM_ON));
  873. reg = reg | 0x00000007;
  874. DSI_OUTREG32(cmdq, EFUSE->DCM_ON, reg);
  875. reg = mtk_spi_read((unsigned long)(&GCE_REG->GCE_CTL_INT0));
  876. reg = reg | 0x0000ffff;
  877. DSI_OUTREG32(cmdq, GCE_REG->GCE_CTL_INT0, reg);
  878. DSI_OUTREG32(cmdq, DISPSYS_REG->MMSYS_HW_DCM_1ST_DIS0, 0);
  879. DSI_OUTREG32(cmdq, DISPSYS_REG->MMSYS_HW_DCM_2ND_DIS0, 0);
  880. }
  881. int dsi_get_pcw(int data_rate, int pcw_ratio)
  882. {
  883. int pcw, tmp, pcw_floor;
  884. /**
  885. * PCW bit 24~30 = floor(pcw)
  886. * PCW bit 16~23 = (pcw - floor(pcw))*256
  887. * PCW bit 8~15 = (pcw*256 - floor(pcw)*256)*256
  888. * PCW bit 0~7 = (pcw*256*256 - floor(pcw)*256*256)*256
  889. */
  890. pcw = data_rate * pcw_ratio / 26;
  891. pcw_floor = data_rate * pcw_ratio % 26;
  892. tmp = ((pcw & 0xFF) << 24) |
  893. (((256 * pcw_floor / 26) & 0xFF) << 16) |
  894. (((256 * (256 * pcw_floor % 26) / 26) & 0xFF) << 8) |
  895. ((256 * (256 * (256 * pcw_floor % 26) % 26) / 26) & 0xFF);
  896. return tmp;
  897. }
  898. int bdg_mipi_tx_dphy_clk_setting(enum DISP_BDG_ENUM module,
  899. void *cmdq, LCM_DSI_PARAMS *dsi_params)
  900. {
  901. int i = 0;
  902. unsigned int j = 0;
  903. unsigned int data_Rate;
  904. unsigned int pcw_ratio = 0;
  905. unsigned int posdiv = 0;
  906. unsigned int prediv = 0;
  907. /* Delta1 is SSC range, default is 0%~-5% */
  908. unsigned int delta1 = 2;
  909. unsigned int pdelta1 = 0;
  910. MIPITX_PHY_LANE_SWAP *swap_base;
  911. enum MIPI_TX_PAD_VALUE pad_mapping[MIPITX_PHY_LANE_NUM] = {
  912. PAD_D0P, PAD_D1P, PAD_D2P,
  913. PAD_D3P, PAD_CKP, PAD_CKP};
  914. DISPFUNCSTART();
  915. if (dsi_params->data_rate != 0) {
  916. data_Rate = dsi_params->data_rate;
  917. } else if (dsi_params->PLL_CLOCK) {
  918. data_Rate = dsi_params->PLL_CLOCK * 2;
  919. } else {
  920. DISPMSG("PLL clock should not be 0!!!\n");
  921. ASSERT(0);
  922. return -1;
  923. }
  924. DISPMSG("%s, data_Rate=%d\n", __func__, data_Rate);
  925. /* DPHY SETTING */
  926. /* MIPITX lane swap setting */
  927. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  928. /* step 0 MIPITX lane swap setting */
  929. swap_base = dsi_params->lane_swap[i];
  930. DISPMSG(
  931. "MIPITX Lane Swap mapping: 0=%d|1=%d|2=%d|3=%d|CK=%d|RX=%d\n",
  932. swap_base[MIPITX_PHY_LANE_0],
  933. swap_base[MIPITX_PHY_LANE_1],
  934. swap_base[MIPITX_PHY_LANE_2],
  935. swap_base[MIPITX_PHY_LANE_3],
  936. swap_base[MIPITX_PHY_LANE_CK],
  937. swap_base[MIPITX_PHY_LANE_RX]);
  938. if (unlikely(dsi_params->lane_swap_en)) {
  939. DISPMSG("MIPITX Lane Swap Enabled for DSI Port %d\n",
  940. i);
  941. DISPMSG(
  942. "MIPITX Lane Swap mapping: %d|%d|%d|%d|%d|%d\n",
  943. swap_base[MIPITX_PHY_LANE_0],
  944. swap_base[MIPITX_PHY_LANE_1],
  945. swap_base[MIPITX_PHY_LANE_2],
  946. swap_base[MIPITX_PHY_LANE_3],
  947. swap_base[MIPITX_PHY_LANE_CK],
  948. swap_base[MIPITX_PHY_LANE_RX]);
  949. /* CKMODE_EN */
  950. for (j = MIPITX_PHY_LANE_0; j < MIPITX_PHY_LANE_CK;
  951. j++) {
  952. if (dsi_params->lane_swap[i][j] ==
  953. MIPITX_PHY_LANE_CK)
  954. break;
  955. }
  956. switch (j) {
  957. case MIPITX_PHY_LANE_0:
  958. mtk_spi_mask_write(
  959. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  960. REG_MIPI_TX_D0_CKMODE_EN),
  961. MIPI_TX_DX_FLD_DSI_CKMODE_EN, 1);
  962. break;
  963. case MIPITX_PHY_LANE_1:
  964. mtk_spi_mask_write(
  965. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  966. REG_MIPI_TX_D1_CKMODE_EN),
  967. MIPI_TX_DX_FLD_DSI_CKMODE_EN, 1);
  968. break;
  969. case MIPITX_PHY_LANE_2:
  970. mtk_spi_mask_write(
  971. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  972. REG_MIPI_TX_D2_CKMODE_EN),
  973. MIPI_TX_DX_FLD_DSI_CKMODE_EN, 1);
  974. break;
  975. case MIPITX_PHY_LANE_3:
  976. mtk_spi_mask_write(
  977. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  978. REG_MIPI_TX_D3_CKMODE_EN),
  979. MIPI_TX_DX_FLD_DSI_CKMODE_EN, 1);
  980. break;
  981. case MIPITX_PHY_LANE_CK:
  982. mtk_spi_mask_write(
  983. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  984. REG_MIPI_TX_CK_CKMODE_EN),
  985. MIPI_TX_DX_FLD_DSI_CKMODE_EN, 1);
  986. break;
  987. default:
  988. break;
  989. }
  990. /* LANE_0 */
  991. mtk_spi_mask_write(
  992. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  993. REG_MIPI_TX_PHY_SEL0),
  994. MIPI_TX_PHY_SEL0_FLD_MIPI_TX_PHY0_SEL,
  995. pad_mapping[swap_base[MIPITX_PHY_LANE_0]]);
  996. mtk_spi_mask_write(
  997. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  998. REG_MIPI_TX_PHY_SEL0),
  999. MIPI_TX_PHY_SEL0_FLD_MIPI_TX_PHY1AB_SEL,
  1000. pad_mapping[swap_base[MIPITX_PHY_LANE_0]] + 1);
  1001. /* LANE_1 */
  1002. mtk_spi_mask_write(
  1003. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1004. REG_MIPI_TX_PHY_SEL0),
  1005. MIPI_TX_PHY_SEL0_FLD_MIPI_TX_PHY1_SEL,
  1006. pad_mapping[swap_base[MIPITX_PHY_LANE_1]]);
  1007. mtk_spi_mask_write(
  1008. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1009. REG_MIPI_TX_PHY_SEL1),
  1010. MIPI_TX_PHY_SEL1_FLD_MIPI_TX_PHY2BC_SEL,
  1011. pad_mapping[swap_base[MIPITX_PHY_LANE_1]] + 1);
  1012. /* LANE_2 */
  1013. mtk_spi_mask_write(
  1014. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1015. REG_MIPI_TX_PHY_SEL0),
  1016. MIPI_TX_PHY_SEL0_FLD_MIPI_TX_PHY2_SEL,
  1017. pad_mapping[swap_base[MIPITX_PHY_LANE_2]]);
  1018. mtk_spi_mask_write(
  1019. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1020. REG_MIPI_TX_PHY_SEL0),
  1021. MIPI_TX_PHY_SEL0_FLD_MIPI_TX_CPHY0BC_SEL,
  1022. pad_mapping[swap_base[MIPITX_PHY_LANE_2]] + 1);
  1023. /* LANE_3 */
  1024. mtk_spi_mask_write(
  1025. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1026. REG_MIPI_TX_PHY_SEL1),
  1027. MIPI_TX_PHY_SEL1_FLD_MIPI_TX_PHY3_SEL,
  1028. pad_mapping[swap_base[MIPITX_PHY_LANE_3]]);
  1029. mtk_spi_mask_write(
  1030. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1031. REG_MIPI_TX_PHY_SEL1),
  1032. MIPI_TX_PHY_SEL1_FLD_MIPI_TX_CPHYXXX_SEL,
  1033. pad_mapping[swap_base[MIPITX_PHY_LANE_3]] + 1);
  1034. /* CK LANE */
  1035. mtk_spi_mask_write(
  1036. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1037. REG_MIPI_TX_PHY_SEL0),
  1038. MIPI_TX_PHY_SEL0_FLD_MIPI_TX_PHYC_SEL,
  1039. pad_mapping[swap_base[MIPITX_PHY_LANE_CK]]);
  1040. mtk_spi_mask_write(
  1041. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1042. REG_MIPI_TX_PHY_SEL0),
  1043. MIPI_TX_PHY_SEL0_FLD_MIPI_TX_CPHY1CA_SEL,
  1044. pad_mapping[swap_base[MIPITX_PHY_LANE_CK]] + 1);
  1045. mtk_spi_mask_write(
  1046. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1047. REG_MIPI_TX_PHY_SEL1),
  1048. MIPI_TX_PHY_SEL1_FLD_MIPI_TX_LPRX0AB_SEL,
  1049. pad_mapping[swap_base[MIPITX_PHY_LANE_RX]]);
  1050. mtk_spi_mask_write(
  1051. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1052. REG_MIPI_TX_PHY_SEL1),
  1053. MIPI_TX_PHY_SEL1_FLD_MIPI_TX_LPRX0BC_SEL,
  1054. pad_mapping[swap_base[MIPITX_PHY_LANE_RX]] + 1);
  1055. /* LPRX SETTING */
  1056. /* HS_DATA SETTING */
  1057. mtk_spi_mask_write(
  1058. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1059. REG_MIPI_TX_PHY_SEL2),
  1060. MIPI_TX_PHY_SEL2_FLD_MIPI_TX_PHY2_HSDATA_SEL,
  1061. pad_mapping[swap_base[MIPITX_PHY_LANE_2]]);
  1062. mtk_spi_mask_write(
  1063. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1064. REG_MIPI_TX_PHY_SEL2),
  1065. MIPI_TX_PHY_SEL2_FLD_MIPI_TX_PHY0_HSDATA_SEL,
  1066. pad_mapping[swap_base[MIPITX_PHY_LANE_0]]);
  1067. mtk_spi_mask_write(
  1068. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1069. REG_MIPI_TX_PHY_SEL2),
  1070. MIPI_TX_PHY_SEL2_FLD_MIPI_TX_PHYC_HSDATA_SEL,
  1071. pad_mapping[swap_base[MIPITX_PHY_LANE_CK]]);
  1072. mtk_spi_mask_write(
  1073. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1074. REG_MIPI_TX_PHY_SEL2),
  1075. MIPI_TX_PHY_SEL2_FLD_MIPI_TX_PHY1_HSDATA_SEL,
  1076. pad_mapping[swap_base[MIPITX_PHY_LANE_1]]);
  1077. mtk_spi_mask_write(
  1078. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1079. REG_MIPI_TX_PHY_SEL3),
  1080. MIPI_TX_PHY_SEL3_FLD_MIPI_TX_PHY3_HSDATA_SEL,
  1081. pad_mapping[swap_base[MIPITX_PHY_LANE_3]]);
  1082. } else {
  1083. mtk_spi_mask_write(
  1084. (u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1085. REG_MIPI_TX_CK_CKMODE_EN),
  1086. MIPI_TX_DX_FLD_DSI_CKMODE_EN, 1);
  1087. }
  1088. }
  1089. /* MIPI INIT */
  1090. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1091. unsigned int tmp = 0;
  1092. /* step 0: RG_DSI0_PLL_IBIAS = 0*/
  1093. DSI_OUTREG32(cmdq, MIPI_TX_REG->MIPI_TX_PLL_CON4, 0x00FF12E0);
  1094. /* BG_LPF_EN / BG_CORE_EN */
  1095. DSI_OUTREG32(cmdq, MIPI_TX_REG->MIPI_TX_LANE_CON, 0x3FFF0180);
  1096. udelay(2);
  1097. /* BG_LPF_EN=1,TIEL_SEL=0 */
  1098. DSI_OUTREG32(cmdq, MIPI_TX_REG->MIPI_TX_LANE_CON, 0x3FFF0080);
  1099. /* Switch OFF each Lane */
  1100. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1101. REG_MIPI_TX_D0_SW_CTL_EN),
  1102. MIPI_TX_DX_FLD_DSI_SW_CTL_EN, 0);
  1103. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1104. REG_MIPI_TX_D1_SW_CTL_EN),
  1105. MIPI_TX_DX_FLD_DSI_SW_CTL_EN, 0);
  1106. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1107. REG_MIPI_TX_D2_SW_CTL_EN),
  1108. MIPI_TX_DX_FLD_DSI_SW_CTL_EN, 0);
  1109. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1110. REG_MIPI_TX_D3_SW_CTL_EN),
  1111. MIPI_TX_DX_FLD_DSI_SW_CTL_EN, 0);
  1112. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1113. REG_MIPI_TX_CK_SW_CTL_EN),
  1114. MIPI_TX_DX_FLD_DSI_SW_CTL_EN, 0);
  1115. /* step 1: SDM_RWR_ON / SDM_ISO_EN */
  1116. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1117. REG_MIPI_TX_PLL_PWR),
  1118. MIPI_TX_PLL_PWR_FLD_AD_DSI_PLL_SDM_PWR_ON, 1);
  1119. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1120. REG_MIPI_TX_PLL_PWR),
  1121. MIPI_TX_PLL_PWR_FLD_AD_DSI_PLL_SDM_ISO_EN, 0);
  1122. if (data_Rate > 2500) {
  1123. DISPERR("mipitx Data Rate exceed limitation(%d)\n",
  1124. data_Rate);
  1125. ASSERT(0);
  1126. return -2;
  1127. } else if (data_Rate >= 2000) { /* 2G ~ 2.5G */
  1128. pcw_ratio = 1;
  1129. posdiv = 0;
  1130. prediv = 0;
  1131. } else if (data_Rate >= 1000) { /* 1G ~ 2G */
  1132. pcw_ratio = 2;
  1133. posdiv = 1;
  1134. prediv = 0;
  1135. } else if (data_Rate >= 500) { /* 500M ~ 1G */
  1136. pcw_ratio = 4;
  1137. posdiv = 2;
  1138. prediv = 0;
  1139. } else if (data_Rate > 250) { /* 250M ~ 500M */
  1140. pcw_ratio = 8;
  1141. posdiv = 3;
  1142. prediv = 0;
  1143. } else if (data_Rate >= 125) { /* 125M ~ 250M */
  1144. pcw_ratio = 16;
  1145. posdiv = 4;
  1146. prediv = 0;
  1147. } else {
  1148. DISPERR("dataRate is too low(%d)\n", data_Rate);
  1149. ASSERT(0);
  1150. return -3;
  1151. }
  1152. /* step 3 */
  1153. /* PLL PCW config */
  1154. tmp = dsi_get_pcw(data_Rate, pcw_ratio);
  1155. DSI_OUTREG32(cmdq, MIPI_TX_REG->MIPI_TX_PLL_CON0, tmp);
  1156. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1157. REG_MIPI_TX_PLL_CON1),
  1158. MIPI_TX_PLL_CON1_FLD_RG_DSI_PLL_POSDIV, posdiv);
  1159. /* SSC config */
  1160. if (dsi_params->ssc_disable != 1) {
  1161. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1162. REG_MIPI_TX_PLL_CON2),
  1163. MIPI_TX_PLL_CON2_FLD_RG_DSI_PLL_SDM_SSC_PH_INIT,
  1164. 1);
  1165. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1166. REG_MIPI_TX_PLL_CON2),
  1167. MIPI_TX_PLL_CON2_FLD_RG_DSI_PLL_SDM_SSC_PRD,
  1168. 0x1B1);
  1169. delta1 = (dsi_params->ssc_range == 0) ?
  1170. delta1 : dsi_params->ssc_range;
  1171. ASSERT(delta1 <= 8);
  1172. pdelta1 = (delta1 * (data_Rate / 2) * pcw_ratio *
  1173. 262144 + 281664) / 563329;
  1174. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1175. REG_MIPI_TX_PLL_CON3),
  1176. MIPI_TX_PLL_CON2_FLD_RG_DSI_PLL_SDM_SSC_DELTA,
  1177. pdelta1);
  1178. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1179. REG_MIPI_TX_PLL_CON3),
  1180. MIPI_TX_PLL_CON2_FLD_RG_DSI_PLL_SDM_SSC_DELTA1,
  1181. pdelta1);
  1182. DISPMSG("%s, PLL config:data_rate=%d, pcw_ratio=%d, delta1=%d,pdelta1=0x%x\n",
  1183. __func__, data_Rate, pcw_ratio,
  1184. delta1, pdelta1);
  1185. }
  1186. }
  1187. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1188. if (data_Rate && (dsi_params->ssc_disable != 1))
  1189. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1190. REG_MIPI_TX_PLL_CON2),
  1191. MIPI_TX_PLL_CON2_FLD_RG_DSI_PLL_SDM_SSC_EN, 1);
  1192. else
  1193. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1194. REG_MIPI_TX_PLL_CON2),
  1195. MIPI_TX_PLL_CON2_FLD_RG_DSI_PLL_SDM_SSC_EN, 0);
  1196. }
  1197. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1198. /* PLL EN */
  1199. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1200. REG_MIPI_TX_PLL_CON1),
  1201. MIPI_TX_PLL_CON1_FLD_RG_DSI_PLL_EN, 1);
  1202. udelay(50);
  1203. mtk_spi_mask_write((u32)(DISPSYS_BDG_MIPI_TX_BASE +
  1204. REG_MIPI_TX_SW_CTRL_CON4),
  1205. MIPI_TX_SW_CTRL_CON4_FLD_MIPI_TX_SW_ANA_CK_EN, 1);
  1206. }
  1207. DISPFUNCEND();
  1208. return 0;
  1209. }
  1210. int bdg_tx_phy_config(enum DISP_BDG_ENUM module,
  1211. void *cmdq, LCM_DSI_PARAMS *tx_params)
  1212. {
  1213. int i;
  1214. u32 ui, cycle_time;
  1215. unsigned int hs_trail;
  1216. DISPFUNCSTART();
  1217. if (tx_params->data_rate != 0) {
  1218. ui = 1000 / tx_params->data_rate;
  1219. cycle_time = 8000 / tx_params->data_rate;
  1220. tx_data_rate = tx_params->data_rate;
  1221. } else if (tx_params->PLL_CLOCK) {
  1222. ui = 1000 / (tx_params->PLL_CLOCK * 2);
  1223. cycle_time = 8000 / (tx_params->PLL_CLOCK * 2);
  1224. tx_data_rate = tx_params->PLL_CLOCK * 2;
  1225. } else {
  1226. DISPMSG("PLL clock should not be 0!!!\n");
  1227. ASSERT(0);
  1228. }
  1229. DISPMSG(
  1230. "%s, tx_data_rate=%d, cycle_time=%d, ui=%d\n",
  1231. __func__, tx_data_rate, cycle_time, ui);
  1232. #if 1
  1233. /* lpx >= 50ns (spec) */
  1234. /* lpx = 60ns */
  1235. timcon0.LPX = NS_TO_CYCLE(60, cycle_time);
  1236. if (timcon0.LPX < 2)
  1237. timcon0.LPX = 2;
  1238. /* hs_prep = 40ns+4*UI ~ 85ns+6*UI (spec) */
  1239. /* hs_prep = 64ns+5*UI */
  1240. timcon0.HS_PRPR = NS_TO_CYCLE((64 + 5 * ui), cycle_time) + 1;
  1241. /* hs_zero = (200+10*UI) - hs_prep */
  1242. timcon0.HS_ZERO = NS_TO_CYCLE((200 + 10 * ui), cycle_time);
  1243. timcon0.HS_ZERO = timcon0.HS_ZERO > timcon0.HS_PRPR ?
  1244. timcon0.HS_ZERO - timcon0.HS_PRPR : timcon0.HS_ZERO;
  1245. if (timcon0.HS_ZERO < 1)
  1246. timcon0.HS_ZERO = 1;
  1247. /* hs_trail > max(8*UI, 60ns+4*UI) (spec) */
  1248. /* hs_trail = 80ns+4*UI */
  1249. hs_trail = 80 + 4 * ui;
  1250. timcon0.HS_TRAIL = (hs_trail > cycle_time) ?
  1251. NS_TO_CYCLE(hs_trail, cycle_time) + 1 : 2;
  1252. /* hs_exit > 100ns (spec) */
  1253. /* hs_exit = 120ns */
  1254. /* timcon1.DA_HS_EXIT = NS_TO_CYCLE(120, cycle_time); */
  1255. /* hs_exit = 2*lpx */
  1256. timcon1.DA_HS_EXIT = 2 * timcon0.LPX;
  1257. /* ta_go = 4*lpx (spec) */
  1258. timcon1.TA_GO = 4 * timcon0.LPX;
  1259. /* ta_get = 5*lpx (spec) */
  1260. timcon1.TA_GET = 5 * timcon0.LPX;
  1261. /* ta_sure = lpx ~ 2*lpx (spec) */
  1262. timcon1.TA_SURE = 3 * timcon0.LPX / 2;
  1263. /* clk_hs_prep = 38ns ~ 95ns (spec) */
  1264. /* clk_hs_prep = 80ns */
  1265. timcon3.CLK_HS_PRPR = NS_TO_CYCLE(80, cycle_time);
  1266. /* clk_zero + clk_hs_prep > 300ns (spec) */
  1267. /* clk_zero = 400ns - clk_hs_prep */
  1268. timcon2.CLK_ZERO = NS_TO_CYCLE(400, cycle_time) -
  1269. timcon3.CLK_HS_PRPR;
  1270. if (timcon2.CLK_ZERO < 1)
  1271. timcon2.CLK_ZERO = 1;
  1272. /* clk_trail > 60ns (spec) */
  1273. /* clk_trail = 100ns */
  1274. timcon2.CLK_TRAIL = NS_TO_CYCLE(100, cycle_time) + 1;
  1275. if (timcon2.CLK_TRAIL < 2)
  1276. timcon2.CLK_TRAIL = 2;
  1277. /* clk_exit > 100ns (spec) */
  1278. /* clk_exit = 200ns */
  1279. /* timcon3.CLK_EXIT = NS_TO_CYCLE(200, cycle_time); */
  1280. /* clk_exit = 2*lpx */
  1281. timcon3.CLK_HS_EXIT = 2 * timcon0.LPX;
  1282. /* clk_post > 60ns+52*UI (spec) */
  1283. /* clk_post = 96ns+52*UI */
  1284. timcon3.CLK_HS_POST = NS_TO_CYCLE((96 + 52 * ui), cycle_time);
  1285. #else
  1286. hs_trail = (tx_params->HS_TRAIL == 0) ?
  1287. (NS_TO_CYCLE(((1 * 4 * ui) + 80)
  1288. * tx_params->PLL_CLOCK * 2, 8000) + 1) :
  1289. tx_params->HS_TRAIL;
  1290. /* +3 is recommended from designer becauase of HW latency */
  1291. timcon0.HS_TRAIL = (1 > hs_trail) ? 1 : hs_trail;
  1292. timcon0.HS_PRPR = (tx_params->HS_PRPR == 0) ?
  1293. (NS_TO_CYCLE((64 + 5 * ui), cycle_time) + 1) :
  1294. tx_params->HS_PRPR;
  1295. /* HS_PRPR can't be 1. */
  1296. if (timcon0.HS_PRPR < 1)
  1297. timcon0.HS_PRPR = 1;
  1298. timcon0.HS_ZERO = (tx_params->HS_ZERO == 0) ?
  1299. NS_TO_CYCLE((200 + 10 * ui), cycle_time) :
  1300. tx_params->HS_ZERO;
  1301. timcon_temp = timcon0.HS_PRPR;
  1302. if (timcon_temp < timcon0.HS_ZERO)
  1303. timcon0.HS_ZERO -= timcon0.HS_PRPR;
  1304. timcon0.LPX = (tx_params->LPX == 0) ?
  1305. (NS_TO_CYCLE(tx_params->PLL_CLOCK * 2 * 75, 8000) + 1) :
  1306. tx_params->LPX;
  1307. if (timcon0.LPX < 1)
  1308. timcon0.LPX = 1;
  1309. timcon1.TA_GET = (tx_params->TA_GET == 0) ? (5 * timcon0.LPX) :
  1310. tx_params->TA_GET;
  1311. timcon1.TA_SURE = (tx_params->TA_SURE == 0) ?
  1312. (3 * timcon0.LPX / 2) : tx_params->TA_SURE;
  1313. timcon1.TA_GO = (tx_params->TA_GO == 0) ? (4 * timcon0.LPX) :
  1314. tx_params->TA_GO;
  1315. /* --------------------------------------------------------------
  1316. * NT35510 need fine tune timing
  1317. * Data_hs_exit = 60 ns + 128UI
  1318. * Clk_post = 60 ns + 128 UI.
  1319. * --------------------------------------------------------------
  1320. */
  1321. timcon1.DA_HS_EXIT = (tx_params->DA_HS_EXIT == 0) ?
  1322. (2 * timcon0.LPX) : tx_params->DA_HS_EXIT;
  1323. timcon2.CLK_TRAIL = ((tx_params->CLK_TRAIL == 0) ?
  1324. NS_TO_CYCLE(100 * tx_params->PLL_CLOCK * 2,
  1325. 8000) : tx_params->CLK_TRAIL) + 1;
  1326. /* CLK_TRAIL can't be 1. */
  1327. if (timcon2.CLK_TRAIL < 2)
  1328. timcon2.CLK_TRAIL = 2;
  1329. timcon2.CLK_ZERO = (tx_params->CLK_ZERO == 0) ?
  1330. NS_TO_CYCLE(400, cycle_time) :
  1331. tx_params->CLK_ZERO;
  1332. timcon3.CLK_HS_PRPR = (tx_params->CLK_HS_PRPR == 0) ?
  1333. NS_TO_CYCLE(80 * tx_params->PLL_CLOCK * 2,
  1334. 8000) : tx_params->CLK_HS_PRPR;
  1335. if (timcon3.CLK_HS_PRPR < 1)
  1336. timcon3.CLK_HS_PRPR = 1;
  1337. timcon3.CLK_HS_EXIT = (tx_params->CLK_HS_EXIT == 0) ?
  1338. (2 * timcon0.LPX) : tx_params->CLK_HS_EXIT;
  1339. timcon3.CLK_HS_POST = (tx_params->CLK_HS_POST == 0) ?
  1340. NS_TO_CYCLE((96 + 52 * ui), cycle_time) :
  1341. tx_params->CLK_HS_POST;
  1342. #endif
  1343. bg_tx_data_phy_cycle = (timcon1.DA_HS_EXIT + 1) + timcon0.LPX +
  1344. timcon0.HS_PRPR + timcon0.HS_ZERO + 1;
  1345. DISPMSG(
  1346. "%s, bg_tx_data_phy_cycle=%d, LPX=%d, HS_PRPR=%d, HS_ZERO=%d, HS_TRAIL=%d, DA_HS_EXIT=%d\n",
  1347. __func__, bg_tx_data_phy_cycle, timcon0.LPX,
  1348. timcon0.HS_PRPR, timcon0.HS_ZERO, timcon0.HS_TRAIL,
  1349. timcon1.DA_HS_EXIT);
  1350. DISPMSG(
  1351. "%s, TA_GO=%d, TA_GET=%d, TA_SURE=%d, CLK_HS_PRPR=%d, CLK_ZERO=%d, CLK_TRAIL=%d, CLK_HS_EXIT=%d, CLK_HS_POST=%d\n",
  1352. __func__, timcon1.TA_GO, timcon1.TA_GET, timcon1.TA_SURE,
  1353. timcon3.CLK_HS_PRPR, timcon2.CLK_ZERO, timcon2.CLK_TRAIL,
  1354. timcon3.CLK_HS_EXIT, timcon3.CLK_HS_POST);
  1355. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1356. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1357. + REG_DSI_TX_PHY_TIMCON0),
  1358. DSI_TX_PHY_TIMCON0_FLD_LPX, timcon0.LPX);
  1359. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1360. + REG_DSI_TX_PHY_TIMCON0),
  1361. DSI_TX_PHY_TIMCON0_FLD_HS_PRPR, timcon0.HS_PRPR);
  1362. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1363. + REG_DSI_TX_PHY_TIMCON0),
  1364. DSI_TX_PHY_TIMCON0_FLD_HS_ZERO, timcon0.HS_ZERO);
  1365. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1366. + REG_DSI_TX_PHY_TIMCON0),
  1367. DSI_TX_PHY_TIMCON0_FLD_HS_TRAIL, timcon0.HS_TRAIL);
  1368. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1369. + REG_DSI_TX_PHY_TIMCON1),
  1370. DSI_TX_PHY_TIMCON1_FLD_TA_GO, timcon1.TA_GO);
  1371. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1372. + REG_DSI_TX_PHY_TIMCON1),
  1373. DSI_TX_PHY_TIMCON1_FLD_TA_SURE, timcon1.TA_SURE);
  1374. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1375. + REG_DSI_TX_PHY_TIMCON1),
  1376. DSI_TX_PHY_TIMCON1_FLD_TA_GET, timcon1.TA_GET);
  1377. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1378. + REG_DSI_TX_PHY_TIMCON1),
  1379. DSI_TX_PHY_TIMCON1_FLD_DA_HS_EXIT,
  1380. timcon1.DA_HS_EXIT);
  1381. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1382. + REG_DSI_TX_PHY_TIMCON2),
  1383. DSI_TX_PHY_TIMCON2_FLD_CLK_ZERO,
  1384. timcon2.CLK_ZERO);
  1385. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1386. + REG_DSI_TX_PHY_TIMCON2),
  1387. DSI_TX_PHY_TIMCON2_FLD_CLK_TRAIL,
  1388. timcon2.CLK_TRAIL);
  1389. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1390. + REG_DSI_TX_PHY_TIMCON3),
  1391. DSI_TX_PHY_TIMCON3_FLD_DCLK_HS_PRPR,
  1392. timcon3.CLK_HS_PRPR);
  1393. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1394. + REG_DSI_TX_PHY_TIMCON3),
  1395. DSI_TX_PHY_TIMCON3_FLD_CCLK_HS_POST,
  1396. timcon3.CLK_HS_POST);
  1397. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1398. + REG_DSI_TX_PHY_TIMCON3),
  1399. DSI_TX_PHY_TIMCON3_FLD_CCLK_HS_EXIT,
  1400. timcon3.CLK_HS_EXIT);
  1401. DISPMSG("%s, PHY_TIMECON0=0x%08x,PHY_TIMECON1=0x%08x,PHY_TIMECON2=0x%08x,PHY_TIMECON3=0x%08x\n",
  1402. __func__,
  1403. mtk_spi_read((unsigned long)
  1404. (&TX_REG[i]->DSI_TX_PHY_TIMECON0)),
  1405. mtk_spi_read((unsigned long)
  1406. (&TX_REG[i]->DSI_TX_PHY_TIMECON1)),
  1407. mtk_spi_read((unsigned long)
  1408. (&TX_REG[i]->DSI_TX_PHY_TIMECON2)),
  1409. mtk_spi_read((unsigned long)
  1410. (&TX_REG[i]->DSI_TX_PHY_TIMECON3)));
  1411. }
  1412. return 0;
  1413. }
  1414. int bdg_tx_txrx_ctrl(enum DISP_BDG_ENUM module,
  1415. void *cmdq, LCM_DSI_PARAMS *tx_params)
  1416. {
  1417. int i;
  1418. int lane_num = tx_params->LANE_NUM;
  1419. bool hstx_cklp_en = tx_params->cont_clock ? FALSE : TRUE;
  1420. bool dis_eotp_en = tx_params->IsCphy ? TRUE : FALSE;
  1421. bool ext_te_en = tx_params->mode ? FALSE : TRUE;
  1422. DISPFUNCSTART();
  1423. switch (lane_num) {
  1424. case ONE_LANE:
  1425. lane_num = 0x1;
  1426. break;
  1427. case TWO_LANE:
  1428. lane_num = 0x3;
  1429. break;
  1430. case THREE_LANE:
  1431. lane_num = 0x7;
  1432. break;
  1433. case FOUR_LANE:
  1434. default:
  1435. lane_num = 0xF;
  1436. break;
  1437. }
  1438. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1439. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1440. + REG_DSI_TX_TXRX_CON),
  1441. DSI_TX_TXRX_CON_FLD_LANE_NUM, lane_num);
  1442. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1443. + REG_DSI_TX_TXRX_CON),
  1444. DSI_TX_TXRX_CON_FLD_HSTX_CKLP_EN, hstx_cklp_en);
  1445. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1446. + REG_DSI_TX_TXRX_CON),
  1447. DSI_TX_TXRX_CON_FLD_DIS_EOT, dis_eotp_en);
  1448. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1449. + REG_DSI_TX_TXRX_CON),
  1450. DSI_TX_TXRX_CON_FLD_EXT_TE_EN, ext_te_en);
  1451. }
  1452. return 0;
  1453. }
  1454. int bdg_tx_ps_ctrl(enum DISP_BDG_ENUM module,
  1455. void *cmdq, LCM_DSI_PARAMS *tx_params)
  1456. {
  1457. int i;
  1458. unsigned int ps_wc, width, bpp, ps_sel;
  1459. DISPFUNCSTART();
  1460. width = tx_params->horizontal_active_pixel / 1;
  1461. switch (tx_params->data_format.format) {
  1462. case LCM_DSI_FORMAT_RGB565:
  1463. ps_sel = PACKED_PS_16BIT_RGB565;
  1464. bpp = 16;
  1465. break;
  1466. case LCM_DSI_FORMAT_RGB666_LOOSELY:
  1467. ps_sel = LOOSELY_PS_24BIT_RGB666;
  1468. bpp = 24;
  1469. break;
  1470. case LCM_DSI_FORMAT_RGB666:
  1471. ps_sel = PACKED_PS_18BIT_RGB666;
  1472. bpp = 18;
  1473. break;
  1474. case LCM_DSI_FORMAT_RGB888:
  1475. ps_sel = PACKED_PS_24BIT_RGB888;
  1476. bpp = 24;
  1477. break;
  1478. case LCM_DSI_FORMAT_RGB101010:
  1479. ps_sel = PACKED_PS_30BIT_RGB101010;
  1480. bpp = 30;
  1481. break;
  1482. default:
  1483. DISPMSG("format not support!!!\n");
  1484. return -1;
  1485. }
  1486. if (dsc_en) {
  1487. ps_sel = PACKED_COMPRESSION;
  1488. width = (width + 2) / 3;
  1489. }
  1490. ps_wc = (width * bpp) / 8;
  1491. DISPMSG(
  1492. "%s, DSI_WIDTH=%d, DSI_HEIGHT=%d, ps_sel=%d, ps_wc=%d\n",
  1493. __func__, width, tx_params->vertical_active_line,
  1494. ps_sel, ps_wc);
  1495. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1496. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1497. + REG_DSI_TX_VACT_NL),
  1498. DSI_TX_VACT_NL_FLD_DSI_TX_VACT_NL,
  1499. tx_params->vertical_active_line);
  1500. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1501. + REG_DSI_TX_PSCON),
  1502. DSI_TX_FLD_CUSTOM_HEADER, 0);
  1503. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1504. + REG_DSI_TX_PSCON),
  1505. DSI_TX_FLD_DSI_PS_WC, ps_wc);
  1506. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1507. + REG_DSI_TX_PSCON),
  1508. DSI_TX_FLD_DSI_PS_SEL, ps_sel);
  1509. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1510. + REG_DSI_TX_SIZE_CON),
  1511. DSI_TX_SIZE_FLD_DSI_WIDTH, width);
  1512. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1513. + REG_DSI_TX_SIZE_CON),
  1514. DSI_TX_SIZE_FLD_DSI_HEIGHT,
  1515. tx_params->vertical_active_line);
  1516. }
  1517. return 0;
  1518. }
  1519. int bdg_tx_vdo_timing_set(enum DISP_BDG_ENUM module,
  1520. void *cmdq, LCM_DSI_PARAMS *tx_params)
  1521. {
  1522. int i;
  1523. u32 dsi_buf_bpp, data_init_byte;
  1524. DISPFUNCSTART();
  1525. switch (tx_params->data_format.format) {
  1526. case LCM_DSI_FORMAT_RGB565:
  1527. dsi_buf_bpp = 16;
  1528. break;
  1529. case LCM_DSI_FORMAT_RGB666:
  1530. dsi_buf_bpp = 18;
  1531. break;
  1532. case LCM_DSI_FORMAT_RGB666_LOOSELY:
  1533. case LCM_DSI_FORMAT_RGB888:
  1534. dsi_buf_bpp = 24;
  1535. break;
  1536. case LCM_DSI_FORMAT_RGB101010:
  1537. dsi_buf_bpp = 30;
  1538. break;
  1539. default:
  1540. DISPMSG("format not support!!!\n");
  1541. return -1;
  1542. }
  1543. if (tx_params->IsCphy) {
  1544. DISPMSG("C-PHY mode, need check!!!\n");
  1545. } else {
  1546. data_init_byte = bg_tx_data_phy_cycle * tx_params->LANE_NUM;
  1547. switch (tx_params->mode) {
  1548. case DSI_CMD_MODE:
  1549. break;
  1550. case DSI_SYNC_PULSE_VDO_MODE:
  1551. hsa_byte =
  1552. (((tx_params->horizontal_sync_active *
  1553. dsi_buf_bpp) / 8) - 10);
  1554. hbp_byte =
  1555. (((tx_params->horizontal_backporch *
  1556. dsi_buf_bpp) / 8) - 10);
  1557. hfp_byte =
  1558. (((tx_params->horizontal_frontporch *
  1559. dsi_buf_bpp) / 8) - 12);
  1560. break;
  1561. case DSI_SYNC_EVENT_VDO_MODE:
  1562. hsa_byte = 0; /* don't care */
  1563. hbp_byte =
  1564. (((tx_params->horizontal_backporch +
  1565. tx_params->horizontal_sync_active) *
  1566. dsi_buf_bpp) / 8) - 10;
  1567. hfp_byte =
  1568. (((tx_params->horizontal_frontporch *
  1569. dsi_buf_bpp) / 8) - 12);
  1570. break;
  1571. case DSI_BURST_VDO_MODE:
  1572. hsa_byte = 0; /* don't care */
  1573. hbp_byte =
  1574. (((tx_params->horizontal_backporch +
  1575. tx_params->horizontal_sync_active) *
  1576. dsi_buf_bpp) / 8) - 10;
  1577. hfp_byte =
  1578. (((tx_params->horizontal_frontporch *
  1579. dsi_buf_bpp) / 8) - 12 - 6);
  1580. break;
  1581. }
  1582. bllp_byte = 16 * tx_params->LANE_NUM;
  1583. }
  1584. if (hsa_byte < 0) {
  1585. DISPMSG("error!hsa = %d < 0!\n", hsa_byte);
  1586. hsa_byte = 0;
  1587. return -1;
  1588. }
  1589. if (hfp_byte > data_init_byte) {
  1590. hfp_byte -= data_init_byte;
  1591. } else {
  1592. hfp_byte = 4;
  1593. DISPMSG("hfp is too short!\n");
  1594. return -2;
  1595. }
  1596. DISPMSG(
  1597. "%s, mode=0x%x, t_vsa=%d, t_vbp=%d, t_vfp=%d, hsa_byte=%d, hbp_byte=%d, hfp_byte=%d, bllp_byte=%d\n",
  1598. __func__, tx_params->mode, tx_params->vertical_sync_active,
  1599. tx_params->vertical_backporch, tx_params->vertical_frontporch,
  1600. hsa_byte, hbp_byte, hfp_byte, bllp_byte);
  1601. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1602. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_VSA_NL,
  1603. tx_params->vertical_sync_active);
  1604. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_VBP_NL,
  1605. (tx_params->vertical_backporch));
  1606. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_VFP_NL,
  1607. (tx_params->vertical_frontporch));
  1608. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_HSA_WC, hsa_byte);
  1609. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_HBP_WC, hbp_byte);
  1610. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_HFP_WC, hfp_byte);
  1611. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_BLLP_WC, bllp_byte);
  1612. }
  1613. return 0;
  1614. }
  1615. int bdg_tx_buf_rw_set(enum DISP_BDG_ENUM module,
  1616. void *cmdq, LCM_DSI_PARAMS *tx_params)
  1617. {
  1618. int i;
  1619. unsigned int width, height, rw_times, tmp;
  1620. DISPFUNCSTART();
  1621. tmp = (mtk_spi_read((unsigned long)
  1622. (&TX_REG[0]->DSI_TX_COM_CON)) & 0x01000000) >> 24;
  1623. width = tx_params->horizontal_active_pixel / 1;
  1624. height = tx_params->vertical_active_line;
  1625. if (dsc_en)
  1626. width = (width + 2) / 3;
  1627. if (tmp == 1 && tx_params->mode == 0) {
  1628. if ((width * 3 % 9) == 0)
  1629. rw_times = (width * 3 / 9) * height;
  1630. else
  1631. rw_times = (width * 3 / 9 + 1) * height;
  1632. } else {
  1633. if ((width * height * 3 % 9) == 0)
  1634. rw_times = width * height * 3 / 9;
  1635. else
  1636. rw_times = width * height * 3 / 9 + 1;
  1637. }
  1638. DISPMSG(
  1639. "%s, mode=0x%x, tmp=%d, width=%d, height=%d, rw_times=%d\n",
  1640. __func__, tx_params->mode, tmp, width, height, rw_times);
  1641. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1642. DSI_OUTREG32(cmdq, TX_REG[i]->DSI_TX_BUF_RW_TIMES, rw_times);
  1643. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1644. + REG_DSI_TX_BUF_CON0),
  1645. DSI_TX_SIZE_FLD_ANTI_LATENCY_BUF_EN, 1);
  1646. }
  1647. return 0;
  1648. }
  1649. int bdg_tx_enable_hs_clk(enum DISP_BDG_ENUM module,
  1650. void *cmdq, bool enable)
  1651. {
  1652. int i;
  1653. DISPFUNCSTART();
  1654. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1655. if (enable) {
  1656. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1657. + REG_DSI_TX_PHY_LCCON),
  1658. DSI_TX_SIZE_FLD_LC_HS_TX_EN, 1);
  1659. } else {
  1660. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1661. + REG_DSI_TX_BUF_CON0),
  1662. DSI_TX_SIZE_FLD_LC_HS_TX_EN, 0);
  1663. }
  1664. }
  1665. return 0;
  1666. }
  1667. int bdg_tx_set_mode(enum DISP_BDG_ENUM module,
  1668. void *cmdq, unsigned int mode)
  1669. {
  1670. int i = 0;
  1671. DISPMSG("%s, mode=%d\n", __func__, mode);
  1672. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1673. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1674. + REG_DSI_TX_MODE_CON),
  1675. DSI_TX_MODE_CON_FLD_MODE, mode);
  1676. }
  1677. if (mode == CMD_MODE)
  1678. mtk_spi_mask_write((u32)(DISPSYS_BDG_MMSYS_CONFIG_BASE
  1679. + REG_MIPI_RX_POST_CTRL),
  1680. MIPI_RX_POST_CTRL_FLD_MIPI_RX_MODE_SEL, 0);
  1681. else
  1682. mtk_spi_mask_write((u32)(DISPSYS_BDG_MMSYS_CONFIG_BASE
  1683. + REG_MIPI_RX_POST_CTRL),
  1684. MIPI_RX_POST_CTRL_FLD_MIPI_RX_MODE_SEL, 1);
  1685. return 0;
  1686. }
  1687. int bdg_tx_bist_pattern(enum DISP_BDG_ENUM module,
  1688. void *cmdq, bool enable, unsigned int sel,
  1689. unsigned int red, unsigned int green,
  1690. unsigned int blue)
  1691. {
  1692. int i;
  1693. DISPFUNCSTART();
  1694. return 0;
  1695. }
  1696. int bdg_tx_start(enum DISP_BDG_ENUM module, void *cmdq)
  1697. {
  1698. int i;
  1699. DISPFUNCSTART();
  1700. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1701. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1702. + REG_DSI_TX_START),
  1703. DSI_TX_START_FLD_DSI_TX_START, 0);
  1704. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1705. + REG_DSI_TX_START),
  1706. DSI_TX_START_FLD_DSI_TX_START, 1);
  1707. }
  1708. return 0;
  1709. }
  1710. int bdg_set_dcs_read_cmd(bool enable, void *cmdq)
  1711. {
  1712. DISPFUNCSTART();
  1713. if (enable) {
  1714. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1715. + REG_DSI_TX_RACK),
  1716. REG_DSI_TX_RACK_FLD_DSI_TX_RACK_BYPASS, 1);
  1717. mtk_spi_mask_write((u32)(DISPSYS_BDG_MMSYS_CONFIG_BASE
  1718. + REG_MIPI_RX_POST_CTRL),
  1719. MIPI_RX_POST_CTRL_FLD_MIPI_RX_MODE_SEL, 0);
  1720. } else {
  1721. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1722. + REG_DSI_TX_RACK),
  1723. REG_DSI_TX_RACK_FLD_DSI_TX_RACK_BYPASS, 0);
  1724. mtk_spi_mask_write((u32)(DISPSYS_BDG_MMSYS_CONFIG_BASE
  1725. + REG_MIPI_RX_POST_CTRL),
  1726. MIPI_RX_POST_CTRL_FLD_MIPI_RX_MODE_SEL, 1);
  1727. }
  1728. return 0;
  1729. }
  1730. int bdg_tx_stop(enum DISP_BDG_ENUM module, void *cmdq)
  1731. {
  1732. int i;
  1733. DISPFUNCSTART();
  1734. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++)
  1735. mtk_spi_mask_write(
  1736. (u32)(DISPSYS_BDG_TX_DSI0_BASE + REG_DSI_TX_START),
  1737. DSI_TX_START_FLD_DSI_TX_START, 0);
  1738. return 0;
  1739. }
  1740. int bdg_tx_reset(enum DISP_BDG_ENUM module, void *cmdq)
  1741. {
  1742. int i;
  1743. DISPFUNCSTART();
  1744. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1745. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1746. + REG_DSI_TX_COM_CON),
  1747. DSI_TX_COM_CON_FLD_DSI_RESET, 1);
  1748. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  1749. + REG_DSI_TX_COM_CON),
  1750. DSI_TX_COM_CON_FLD_DSI_RESET, 0);
  1751. }
  1752. return 0;
  1753. }
  1754. int bdg_vm_mode_set(enum DISP_BDG_ENUM module, bool enable,
  1755. unsigned int long_pkt, void *cmdq)
  1756. {
  1757. int i = 0;
  1758. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1759. if (enable) {
  1760. DSI_OUTREG32(cmdq,
  1761. TX_REG[i]->DSI_VM_CMD_CON1, 0x10);
  1762. DSI_OUTREG32(cmdq,
  1763. DISPSYS_REG->DDI_POST_CTRL, 0x00001110);
  1764. if (long_pkt > 1)
  1765. DSI_OUTREG32(cmdq,
  1766. TX_REG[i]->DSI_VM_CMD_CON0, 0x37);
  1767. else
  1768. DSI_OUTREG32(cmdq,
  1769. TX_REG[i]->DSI_VM_CMD_CON0, 0x35);
  1770. } else {
  1771. DSI_OUTREG32(cmdq,
  1772. TX_REG[i]->DSI_VM_CMD_CON0, 0);
  1773. DSI_OUTREG32(cmdq,
  1774. DISPSYS_REG->DDI_POST_CTRL, 0x00001100);
  1775. }
  1776. }
  1777. return 0;
  1778. }
  1779. int bdg_tx_cmd_mode(enum DISP_BDG_ENUM module, void *cmdq)
  1780. {
  1781. int i;
  1782. DISPFUNCSTART();
  1783. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1784. DSI_OUTREG32(cmdq,
  1785. TX_REG[i]->DSI_TX_MEM_CONTI, 0x3c);
  1786. DSI_OUTREG32(cmdq,
  1787. TX_REG[i]->DSI_TX_CMDQ, 0x2c3909);
  1788. DSI_OUTREG32(cmdq,
  1789. TX_REG[i]->DSI_TX_CMDQ_CON, 1);
  1790. }
  1791. udelay(10);
  1792. return 0;
  1793. }
  1794. int bdg_mutex_trigger(enum DISP_BDG_ENUM module, void *cmdq)
  1795. {
  1796. DISPFUNCSTART();
  1797. mtk_spi_mask_write((u32)(DISPSYS_BDG_MUTEX_REGS_BASE
  1798. + REG_BDG_TX_DISP_MUTEX0_EN),
  1799. BDG_TX_DISP_MUTEX0_EN_FLD_MUTEX0_EN, 0);
  1800. mtk_spi_mask_write((u32)(DISPSYS_BDG_MUTEX_REGS_BASE
  1801. + REG_BDG_TX_DISP_MUTEX0_EN),
  1802. BDG_TX_DISP_MUTEX0_EN_FLD_MUTEX0_EN, 1);
  1803. return 0;
  1804. }
  1805. int bdg_dsi_dump_reg(enum DISP_BDG_ENUM module)
  1806. {
  1807. unsigned int i, k;
  1808. DISPFUNCSTART();
  1809. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  1810. unsigned long dsc_base_addr = (unsigned long)DSC_REG;
  1811. unsigned long dsi_base_addr = (unsigned long)TX_REG[i];
  1812. unsigned long mipi_base_addr = (unsigned long)MIPI_TX_REG;
  1813. DISPMSG("0x%08x: 0x%08x\n", 0x0000d00c,
  1814. mtk_spi_read(0x0000d00c));
  1815. DISPMSG("0x%08x: 0x%08x\n", 0x0000d2d0,
  1816. mtk_spi_read(0x0000d2d0));
  1817. DISPMSG("0x%08x: 0x%08x\n", 0x0000d2b0,
  1818. mtk_spi_read(0x0000d2b0));
  1819. DISPMSG("0x%08x: 0x%08x\n", 0x0000d270,
  1820. mtk_spi_read(0x0000d270));
  1821. DISPMSG("0x%08x: 0x%08x\n", 0x0000d250,
  1822. mtk_spi_read(0x0000d250));
  1823. DISPMSG("0x%08x: 0x%08x\n", 0x0000d230,
  1824. mtk_spi_read(0x0000d230));
  1825. DISPMSG("0x%08x: 0x%08x\n", 0x0000d210,
  1826. mtk_spi_read(0x0000d210));
  1827. DISPMSG("0x%08x: 0x%08x\n", 0x0000d280,
  1828. mtk_spi_read(0x0000d280));
  1829. DISPMSG("0x%08x: 0x%08x\n", 0x0000d260,
  1830. mtk_spi_read(0x0000d260));
  1831. DISPMSG("0x%08x: 0x%08x\n", 0x0000d240,
  1832. mtk_spi_read(0x0000d240));
  1833. DISPMSG("0x%08x: 0x%08x\n", 0x0000d220,
  1834. mtk_spi_read(0x0000d220));
  1835. DISPMSG("0x%08x: 0x%08x\n", 0x0000d200,
  1836. mtk_spi_read(0x0000d200));
  1837. DISPMSG("========================== mt6382 DSI%d REGS ==\n", i);
  1838. for (k = 0; k < 0x210; k += 16) {
  1839. DISPMSG("0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n", k,
  1840. mtk_spi_read(dsi_base_addr + k),
  1841. mtk_spi_read(dsi_base_addr + k + 0x4),
  1842. mtk_spi_read(dsi_base_addr + k + 0x8),
  1843. mtk_spi_read(dsi_base_addr + k + 0xc));
  1844. }
  1845. DISPMSG("========================== mt6382 DSI%d CMD REGS ==\n",
  1846. i);
  1847. /* only dump first 32 bytes cmd */
  1848. for (k = 0; k < 32; k += 16) {
  1849. DISPMSG("0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n", k,
  1850. mtk_spi_read((dsi_base_addr + 0x200 + k)),
  1851. mtk_spi_read((dsi_base_addr + 0x200 + k + 0x4)),
  1852. mtk_spi_read((dsi_base_addr + 0x200 + k + 0x8)),
  1853. mtk_spi_read((
  1854. dsi_base_addr + 0x200 + k + 0xc)));
  1855. }
  1856. DISPMSG("===================== MIPI%d REGS ==\n", i);
  1857. for (k = 0; k < 0x200; k += 16) {
  1858. DISPMSG("0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n", k,
  1859. mtk_spi_read(mipi_base_addr + k),
  1860. mtk_spi_read(mipi_base_addr + k + 0x4),
  1861. mtk_spi_read(mipi_base_addr + k + 0x8),
  1862. mtk_spi_read(mipi_base_addr + k + 0xc));
  1863. }
  1864. if (dsc_en) {
  1865. DISPMSG("================ mt6382 DSC%d REGS ==\n", i);
  1866. for (k = 0; k < sizeof(struct BDG_DISP_DSC_REGS);
  1867. k += 16) {
  1868. DISPMSG("0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
  1869. k,
  1870. mtk_spi_read(dsc_base_addr + k),
  1871. mtk_spi_read(dsc_base_addr + k + 0x4),
  1872. mtk_spi_read(dsc_base_addr + k + 0x8),
  1873. mtk_spi_read(dsc_base_addr + k + 0xc));
  1874. }
  1875. }
  1876. }
  1877. return 0;
  1878. }
  1879. int bdg_tx_wait_for_idle(enum DISP_BDG_ENUM module)
  1880. {
  1881. int i;
  1882. unsigned int timeout = 5000; /* unit: usec */
  1883. unsigned int status;
  1884. for (i = DSI_MODULE_BEGIN(module);
  1885. i <= DSI_MODULE_END(module); i++) {
  1886. while (timeout) {
  1887. udelay(1);
  1888. status = mtk_spi_read(
  1889. (unsigned long)(&TX_REG[i]->DSI_TX_INTSTA));
  1890. if (!(status & 0x80000000))
  1891. break;
  1892. timeout--;
  1893. }
  1894. }
  1895. if (timeout == 0) {
  1896. DISPMSG("%s, wait timeout!\n", __func__);
  1897. return -1;
  1898. }
  1899. return 0;
  1900. }
  1901. int ap_tx_phy_config(enum DISP_BDG_ENUM module,
  1902. void *cmdq, LCM_DSI_PARAMS *tx_params)
  1903. {
  1904. return 0;
  1905. }
  1906. int bdg_dsi_line_timing_dphy_setting(enum DISP_BDG_ENUM module,
  1907. void *cmdq, LCM_DSI_PARAMS *tx_params)
  1908. {
  1909. unsigned int width, height, lanes, ps_wc, new_hfp_byte;
  1910. unsigned int bg_tx_total_word_cnt = 0;
  1911. unsigned int bg_tx_line_time = 0, disp_pipe_line_time = 0;
  1912. unsigned int rxtx_ratio = 0;
  1913. DISPFUNCSTART();
  1914. width = tx_params->horizontal_active_pixel;
  1915. height = tx_params->vertical_active_line;
  1916. lanes = tx_params->LANE_NUM;
  1917. /* Step 1. Show Bridge DSI TX Setting. */
  1918. /* get bdg-tx hsa_byte, hbp_byte, new_hfp_byte and bllp_byte */
  1919. if (dsc_en) {
  1920. /* for 8bpp, 1/3 compression */
  1921. ps_wc = width * 24 / 8 / 3;
  1922. rxtx_ratio = RXTX_RATIO;
  1923. } else {
  1924. /* for 8bpp, 1/3 compression */
  1925. ps_wc = width * 24 / 8;
  1926. rxtx_ratio = 100;
  1927. }
  1928. new_hfp_byte = hfp_byte;
  1929. DISPMSG("%s, dsc_en=%d, hsa_byte=%d, hbp_byte=%d, new_hfp_byte=%d, bllp_byte=%d, ps_wc=%d\n",
  1930. __func__, dsc_en, hsa_byte, hbp_byte,
  1931. new_hfp_byte, bllp_byte, ps_wc);
  1932. /* get lpx, hs_prep, hs_zero,... refer to bdg_tx_phy_config()*/
  1933. /* Step 2. Bridge DSI TX Cycle Count. */
  1934. /* get bg_tx_line_cycle, bg_tx_total_word_cnt */
  1935. /* D-PHY, DSI TX (Bridge IC) back to LP mode during V-Active */
  1936. switch (tx_params->mode) {
  1937. case CMD_MODE:
  1938. bg_tx_total_word_cnt = 0;
  1939. break;
  1940. case SYNC_PULSE_VDO_MODE:
  1941. bg_tx_total_word_cnt = 4 + /* hss packet */
  1942. (4 + hsa_byte + 2) + /* hsa packet */
  1943. 4 + /* hse packet */
  1944. (4 + hbp_byte + 2) + /* hbp packet */
  1945. (4 + ps_wc + 2) + /* rgb packet */
  1946. (4 + new_hfp_byte + 2) +/* hfp packet */
  1947. bg_tx_data_phy_cycle * lanes;
  1948. break;
  1949. case SYNC_EVENT_VDO_MODE:
  1950. bg_tx_total_word_cnt = 4 + /* hss packet */
  1951. (4 + hbp_byte + 2) + /* hbp packet */
  1952. (4 + ps_wc + 2) + /* rgb packet */
  1953. (4 + new_hfp_byte + 2) +/* hfp packet */
  1954. bg_tx_data_phy_cycle * lanes;
  1955. break;
  1956. case BURST_VDO_MODE:
  1957. bg_tx_total_word_cnt = 4 + /* hss packet */
  1958. (4 + hbp_byte + 2) + /* hbp packet */
  1959. (4 + ps_wc + 2) + /* rgb packet */
  1960. (4 + bllp_byte + 2) + /* bllp packet */
  1961. (4 + new_hfp_byte + 2) +/* hfp packet */
  1962. bg_tx_data_phy_cycle * lanes;
  1963. break;
  1964. }
  1965. bg_tx_line_cycle = (bg_tx_total_word_cnt + (lanes - 1)) / lanes;
  1966. bg_tx_line_time = bg_tx_line_cycle * 8000 / tx_data_rate;
  1967. disp_pipe_line_time = width * 1000 / MM_CLK;
  1968. DISPMSG("bg_tx_total_word_cnt=%d, bg_tx_line_cycle=%d\n",
  1969. bg_tx_total_word_cnt, bg_tx_line_cycle);
  1970. DISPMSG("disp_pipe_line_time=%d, bg_tx_line_time=%d\n",
  1971. disp_pipe_line_time, bg_tx_line_time);
  1972. if ((tx_params->mode != CMD_MODE) &&
  1973. (disp_pipe_line_time > bg_tx_line_time)) {
  1974. DISPMSG("error!! disp_pipe_line_time(%d) > bg_tx_line_time(%d)\n",
  1975. disp_pipe_line_time, bg_tx_line_time);
  1976. return -1;
  1977. }
  1978. /* Step 3. Decide AP DSI TX Data Rate and PHY Timing */
  1979. /* get ap_tx_data_rate and set back to ap */
  1980. /* get lpx, hs_prep, hs_zero,... refer to DSI_DPHY_TIMCONFIG()*/
  1981. ap_tx_data_rate = tx_data_rate * rxtx_ratio / 100;
  1982. /* Step 4. Decide AP DSI TX Blanking */
  1983. /* get ap-tx hsa_byte, hbp_byte, new_hfp_byte and bllp_byte */
  1984. /* refer to DSI_DPHY_Calc_VDO_Timing() */
  1985. /* Step 5. fine-tune data rate */
  1986. #if 0
  1987. if (dsc_en) {
  1988. ap_tx_hsa_wc = 4;
  1989. ap_tx_hbp_wc = 4;
  1990. } else {
  1991. ap_tx_hsa_wc = hsa_byte;
  1992. ap_tx_hbp_wc = hbp_byte;
  1993. ap_tx_data_phy_cycle = bg_tx_data_phy_cycle;
  1994. }
  1995. ap_tx_bllp_wc = bllp_byte;
  1996. ap_tx_total_word_cnt = bg_tx_line_cycle *
  1997. lanes * rxtx_ratio / 100;
  1998. switch (tx_params->mode) {
  1999. case CMD_MODE:
  2000. ap_tx_total_word_cnt_no_hfp_wc = 0;
  2001. break;
  2002. case SYNC_PULSE_VDO_MODE:
  2003. ap_tx_total_word_cnt_no_hfp_wc = 4 + /* hss packet */
  2004. (4 + ap_tx_hsa_wc + 2) + /* hsa packet */
  2005. 4 + /* hse packet */
  2006. (4 + ap_tx_hbp_wc + 2) + /* hbp packet */
  2007. (4 + ps_wc + 2) + /* rgb packet */
  2008. (4 + 2) + /* hfp packet */
  2009. ap_tx_data_phy_cycle * lanes;
  2010. break;
  2011. case SYNC_EVENT_VDO_MODE:
  2012. ap_tx_total_word_cnt_no_hfp_wc = 4 + /* hss packet */
  2013. (4 + ap_tx_hbp_wc + 2) + /* hbp packet */
  2014. (4 + ps_wc + 2) + /* rgb packet */
  2015. (4 + 2) + /* hfp packet */
  2016. ap_tx_data_phy_cycle * lanes;
  2017. break;
  2018. case BURST_VDO_MODE:
  2019. ap_tx_total_word_cnt_no_hfp_wc = 4 + /* hss packet */
  2020. (4 + ap_tx_hbp_wc + 2) + /* hbp packet */
  2021. (4 + ps_wc + 2) + /* rgb packet */
  2022. (4 + ap_tx_bllp_wc + 2) + /* bllp packet */
  2023. (4 + 2) + /* hfp packet */
  2024. ap_tx_data_phy_cycle * lanes;
  2025. break;
  2026. }
  2027. ap_tx_hfp_wc = ap_tx_total_word_cnt - ap_tx_total_word_cnt_no_hfp_wc;
  2028. DISPMSG("%s, ap_tx_hsa_wc=%d, ap_tx_hbp_wc=%d, ap_tx_bllp_wc=%d, ap_tx_data_phy_cycle=%d\n",
  2029. __func__, ap_tx_hsa_wc, ap_tx_hbp_wc,
  2030. ap_tx_bllp_wc, ap_tx_data_phy_cycle);
  2031. DISPMSG("%s, ap_tx_hfp_wc=%d, ap_tx_total_word_cnt=%d, ap_tx_total_word_cnt_no_hfp_wc=%d\n",
  2032. __func__, ap_tx_hfp_wc, ap_tx_total_word_cnt,
  2033. ap_tx_total_word_cnt_no_hfp_wc);
  2034. #endif
  2035. return 0;
  2036. }
  2037. unsigned int get_ap_data_rate(void)
  2038. {
  2039. DISPMSG("%s, ap_tx_data_rate=%d\n", __func__, ap_tx_data_rate);
  2040. return ap_tx_data_rate;
  2041. }
  2042. unsigned int get_bdg_data_rate(void)
  2043. {
  2044. DISPMSG("%s, tx_data_rate=%d\n", __func__, tx_data_rate);
  2045. return tx_data_rate;
  2046. }
  2047. int set_bdg_data_rate(unsigned int data_rate)
  2048. {
  2049. if (data_rate > 2500 || data_rate < 100) {
  2050. DISPMSG("error, please check data rate=%d MHz\n", data_rate);
  2051. return -1;
  2052. }
  2053. tx_data_rate = data_rate;
  2054. return 0;
  2055. }
  2056. unsigned int get_bdg_line_cycle(void)
  2057. {
  2058. DISPMSG("%s, bg_tx_line_cycle=%d\n", __func__, bg_tx_line_cycle);
  2059. return bg_tx_line_cycle;
  2060. }
  2061. unsigned int get_dsc_state(void)
  2062. {
  2063. DISPMSG("%s, dsc_en=%d\n", __func__, dsc_en);
  2064. return dsc_en;
  2065. }
  2066. unsigned int get_mt6382_init(void)
  2067. {
  2068. DISPMSG("%s, mt6382_init=%d\n", __func__, mt6382_init);
  2069. return mt6382_init;
  2070. }
  2071. unsigned int get_bdg_tx_mode(void)
  2072. {
  2073. DISPMSG("%s, bdg_tx_mode=%d\n", __func__, bdg_tx_mode);
  2074. return bdg_tx_mode;
  2075. }
  2076. void dsi_set_cmdq_v2(enum DISP_BDG_ENUM module, void *cmdq,
  2077. unsigned int cmd, unsigned char count,
  2078. unsigned char *para_list, unsigned char force_update)
  2079. {
  2080. UINT32 i = 0;
  2081. unsigned long goto_addr, mask_para, set_para;
  2082. struct DSI_TX_T0_INS t0;
  2083. struct DSI_TX_T2_INS t2;
  2084. struct DSI_TX_CMDQ *tx_cmdq;
  2085. memset(&t0, 0, sizeof(struct DSI_TX_T0_INS));
  2086. memset(&t2, 0, sizeof(struct DSI_TX_T2_INS));
  2087. tx_cmdq = TX_CMDQ_REG[0]->data;
  2088. bdg_tx_wait_for_idle(module);
  2089. if (count > 1) {
  2090. t2.CONFG = 2;
  2091. if (cmd < 0xB0)
  2092. t2.Data_ID = TX_DCS_LONG_PACKET_ID;
  2093. else
  2094. t2.Data_ID = TX_GERNERIC_LONG_PACKET_ID;
  2095. t2.WC16 = count + 1;
  2096. DSI_OUTREG32(cmdq, tx_cmdq[0], AS_UINT32(&t2));
  2097. goto_addr = (unsigned long)(&tx_cmdq[1].byte0);
  2098. mask_para = (0xFFu << ((goto_addr & 0x3u) * 8));
  2099. set_para = cmd;
  2100. goto_addr = (goto_addr & (~0x3UL));
  2101. DSI_MASKREG32(cmdq, goto_addr, mask_para, set_para);
  2102. for (i = 0; i < count; i++) {
  2103. goto_addr = (unsigned long)(&tx_cmdq[1].byte1) + i;
  2104. mask_para = (0xFFu << ((goto_addr & 0x3u) * 8));
  2105. set_para = (unsigned long)para_list[i];
  2106. goto_addr = (goto_addr & (~0x3UL));
  2107. DSI_MASKREG32(cmdq, goto_addr, mask_para, set_para);
  2108. }
  2109. DSI_OUTREG32(cmdq, TX_REG[0]->DSI_TX_CMDQ_CON,
  2110. (1 << 15) | (2 + (count) / 4));
  2111. } else {
  2112. t0.CONFG = 0;
  2113. t0.Data0 = cmd;
  2114. if (count) {
  2115. if (cmd < 0xB0)
  2116. t0.Data_ID = TX_DCS_SHORT_PACKET_ID_1;
  2117. else
  2118. t0.Data_ID = TX_GERNERIC_SHORT_PACKET_ID_2;
  2119. t0.Data1 = para_list[0];
  2120. } else {
  2121. if (cmd < 0xB0)
  2122. t0.Data_ID = TX_DCS_SHORT_PACKET_ID_0;
  2123. else
  2124. t0.Data_ID = TX_GERNERIC_SHORT_PACKET_ID_1;
  2125. t0.Data1 = 0;
  2126. }
  2127. DSI_OUTREG32(cmdq, tx_cmdq[0], AS_UINT32(&t0));
  2128. DSI_OUTREG32(cmdq, TX_REG[0]->DSI_TX_CMDQ_CON, 1);
  2129. }
  2130. if (force_update) {
  2131. bdg_tx_start(module, cmdq);
  2132. bdg_tx_wait_for_idle(module);
  2133. }
  2134. }
  2135. void push_table(struct lcm_setting_table *table, unsigned int count,
  2136. unsigned char force_update)
  2137. {
  2138. unsigned int i, cmd;
  2139. for (i = 0; i < count; i++) {
  2140. cmd = table[i].cmd;
  2141. switch (cmd) {
  2142. case REGFLAG_DELAY:
  2143. if (table[i].count <= 10)
  2144. mdelay(table[i].count);
  2145. else
  2146. mdelay(table[i].count);
  2147. break;
  2148. case REGFLAG_UDELAY:
  2149. udelay(table[i].count);
  2150. break;
  2151. case REGFLAG_END_OF_TABLE:
  2152. break;
  2153. default:
  2154. dsi_set_cmdq_v2(DISP_BDG_DSI0, NULL, cmd,
  2155. table[i].count, table[i].para_list,
  2156. force_update);
  2157. if (table[i].count > 1)
  2158. UDELAY(100);
  2159. break;
  2160. }
  2161. }
  2162. }
  2163. int lcm_init(enum DISP_BDG_ENUM module)
  2164. {
  2165. DISPFUNCSTART();
  2166. DISPFUNCEND();
  2167. return 0;
  2168. }
  2169. int bdg_tx_init(enum DISP_BDG_ENUM module,
  2170. disp_ddp_path_config *config, void *cmdq)
  2171. {
  2172. int ret = 0;
  2173. LCM_DSI_PARAMS *tx_params;
  2174. DISPFUNCSTART();
  2175. tx_params = &(config->dsi_config);
  2176. if (tx_params->PLL_CLOCK) {
  2177. tx_data_rate = tx_params->PLL_CLOCK * 2;
  2178. } else {
  2179. DISPMSG("PLL clock should not be 0!!!\n");
  2180. return -1;
  2181. }
  2182. dsc_en = tx_params->bdg_dsc_enable;
  2183. bdg_tx_mode = tx_params->mode;
  2184. DISPMSG("%s, tx_data_rate=%d, bdg_ssc_disable=%d, ssc_disable=%d, dsc_enable=%d, bdg_tx_mode=%d\n",
  2185. __func__, tx_data_rate, tx_params->ssc_disable,
  2186. tx_params->ssc_disable, dsc_en, bdg_tx_mode);
  2187. ret |= bdg_mipi_tx_dphy_clk_setting(module, cmdq, tx_params);
  2188. udelay(20);
  2189. ret |= bdg_tx_phy_config(module, cmdq, tx_params);
  2190. ret |= bdg_tx_txrx_ctrl(module, cmdq, tx_params);
  2191. ret |= bdg_tx_ps_ctrl(module, cmdq, tx_params);
  2192. ret |= bdg_tx_vdo_timing_set(module, cmdq, tx_params);
  2193. ret |= bdg_tx_buf_rw_set(module, cmdq, tx_params);
  2194. ret |= bdg_tx_enable_hs_clk(module, cmdq, TRUE);
  2195. ret |= bdg_tx_set_mode(module, cmdq, CMD_MODE);
  2196. ret |= bdg_dsi_line_timing_dphy_setting(module, cmdq, tx_params);
  2197. /* panel init*/
  2198. DISPFUNCEND();
  2199. return ret;
  2200. }
  2201. int bdg_tx_deinit(enum DISP_BDG_ENUM module, void *cmdq)
  2202. {
  2203. int i;
  2204. DISPFUNCSTART();
  2205. bdg_tx_enable_hs_clk(module, cmdq, FALSE);
  2206. bdg_tx_set_mode(module, cmdq, CMD_MODE);
  2207. bdg_tx_reset(module, cmdq);
  2208. for (i = DSI_MODULE_BEGIN(module); i <= DSI_MODULE_END(module); i++) {
  2209. mtk_spi_mask_write((u32)(DISPSYS_BDG_TX_DSI0_BASE
  2210. + REG_DSI_TX_TXRX_CON),
  2211. DSI_TX_TXRX_CON_FLD_LANE_NUM, 0);
  2212. }
  2213. DISPFUNCEND();
  2214. return 0;
  2215. }
  2216. void calculate_datarate_cfgs_rx(unsigned int data_rate)
  2217. {
  2218. unsigned int timebase = 1000, itminrx = 4;
  2219. unsigned int des_div_en_dly_deass_th = 1;
  2220. unsigned int hs_clk_freq = data_rate * 1000 / 2;
  2221. DISPFUNCSTART();
  2222. ddl_cntr_ref_reg = 5 * hs_clk_freq / 1000 / 2 / 16;
  2223. if (data_rate >= 4500) {
  2224. sel_fast = 1;
  2225. max_phase = 63;
  2226. dll_fbk = 7;
  2227. coarse_bank = 0;
  2228. } else if (data_rate >= 4000) {
  2229. sel_fast = 1;
  2230. max_phase = 71;
  2231. dll_fbk = 8;
  2232. coarse_bank = 1;
  2233. } else if (data_rate >= 3600) {
  2234. sel_fast = 1;
  2235. max_phase = 79;
  2236. dll_fbk = 9;
  2237. coarse_bank = 1;
  2238. } else if (data_rate >= 3230) {
  2239. sel_fast = 1;
  2240. max_phase = 87;
  2241. dll_fbk = 10;
  2242. coarse_bank = 1;
  2243. } else if (data_rate >= 3000) {
  2244. sel_fast = 0;
  2245. max_phase = 71;
  2246. dll_fbk = 8;
  2247. coarse_bank = 0;
  2248. } else if (data_rate >= 2700) {
  2249. sel_fast = 0;
  2250. max_phase = 79;
  2251. dll_fbk = 9;
  2252. coarse_bank = 1;
  2253. } else if (data_rate >= 2455) {
  2254. sel_fast = 0;
  2255. max_phase = 87;
  2256. dll_fbk = 10;
  2257. coarse_bank = 1;
  2258. } else if (data_rate >= 2250) {
  2259. sel_fast = 0;
  2260. max_phase = 95;
  2261. dll_fbk = 11;
  2262. coarse_bank = 1;
  2263. } else if (data_rate >= 2077) {
  2264. sel_fast = 0;
  2265. max_phase = 103;
  2266. dll_fbk = 12;
  2267. coarse_bank = 1;
  2268. } else if (data_rate >= 1929) {
  2269. sel_fast = 0;
  2270. max_phase = 111;
  2271. dll_fbk = 13;
  2272. coarse_bank = 2;
  2273. } else if (data_rate >= 1800) {
  2274. sel_fast = 0;
  2275. max_phase = 119;
  2276. dll_fbk = 14;
  2277. coarse_bank = 2;
  2278. } else if (data_rate >= 1688) {
  2279. sel_fast = 0;
  2280. max_phase = 127;
  2281. dll_fbk = 15;
  2282. coarse_bank = 2;
  2283. } else if (data_rate >= 1588) {
  2284. sel_fast = 0;
  2285. max_phase = 135;
  2286. dll_fbk = 16;
  2287. coarse_bank = 2;
  2288. } else if (data_rate >= 1500) {
  2289. sel_fast = 0;
  2290. max_phase = 143;
  2291. dll_fbk = 17;
  2292. coarse_bank = 3;
  2293. } else {
  2294. sel_fast = 0;
  2295. max_phase = 0;
  2296. dll_fbk = 0;
  2297. coarse_bank = 0;
  2298. }
  2299. if (hs_clk_freq * 2 < 160000)
  2300. hsrx_clk_div = 1;
  2301. else if (hs_clk_freq * 2 < 320000)
  2302. hsrx_clk_div = 2;
  2303. else if (hs_clk_freq * 2 < 640000)
  2304. hsrx_clk_div = 3;
  2305. else if (hs_clk_freq * 2 < 1280000)
  2306. hsrx_clk_div = 4;
  2307. else if (hs_clk_freq * 2 < 2560000)
  2308. hsrx_clk_div = 5;
  2309. else
  2310. hsrx_clk_div = 6;
  2311. hs_thssettle = 115 + 1000 * 6 / data_rate;
  2312. hs_thssettle = (hs_thssettle - T_DCO - (itminrx + 3) *
  2313. T_DCO - 2 * T_DCO) / T_DCO - 1;
  2314. fjump_deskew_reg = max_phase / 10 / 4;
  2315. eye_open_deskew_reg = max_phase * 4 / 10 / 2;
  2316. DISPMSG("data_rate=%d, ddl_cntr_ref_reg=%d, hs_thssettle=%d, fjump_deskew_reg=%d\n",
  2317. data_rate, ddl_cntr_ref_reg, hs_thssettle, fjump_deskew_reg);
  2318. if (hs_clk_freq * 2 >= 900000)
  2319. cdr_coarse_trgt_reg = timebase * hs_clk_freq * 2 * 2 /
  2320. 32 / 1000000 - 1;
  2321. else
  2322. cdr_coarse_trgt_reg = timebase * 900000 * 2 / 32 / 1000000 - 1;
  2323. en_dly_deass_thresh_reg = 1000000 * 7 * 6 / hs_clk_freq / 2 /
  2324. T_DCO + des_div_en_dly_deass_th;
  2325. post_rcvd_rst_val = 2 * T_DCO * hs_clk_freq * 2 / 7 / 1000000 - 1;
  2326. post_rcvd_rst_reg = (post_rcvd_rst_val > 0) ? post_rcvd_rst_val : 1;
  2327. post_det_dly_thresh_val = ((189 * 1000000 / hs_clk_freq / 2) -
  2328. (9 * 7 * 1000000 / hs_clk_freq / 2)) / T_DCO - 7;
  2329. post_det_dly_thresh_reg = (post_det_dly_thresh_val > 0) ?
  2330. post_det_dly_thresh_val : 1;
  2331. DISPMSG("cdr_coarse_trgt_reg=%d, post_rcvd_rst_val=%d, fjump_deskew_reg=%d\n",
  2332. cdr_coarse_trgt_reg, post_rcvd_rst_val, post_rcvd_rst_reg);
  2333. DISPMSG("en_dly_deass_thresh_reg=%d, post_det_dly_thresh_val=%d, post_det_dly_thresh_reg=%d\n",
  2334. en_dly_deass_thresh_reg, post_det_dly_thresh_val,
  2335. post_det_dly_thresh_reg);
  2336. }
  2337. void mipi_rx_enable(void *cmdq)
  2338. {
  2339. DSI_OUTREG32(cmdq, OCLA_REG->OCLA_LANEC_CON, 0);
  2340. DSI_OUTREG32(cmdq, OCLA_REG->OCLA_LANE0_CON, 0);
  2341. DSI_OUTREG32(cmdq, OCLA_REG->OCLA_LANE1_CON, 0);
  2342. DSI_OUTREG32(cmdq, OCLA_REG->OCLA_LANE2_CON, 0);
  2343. DSI_OUTREG32(cmdq, OCLA_REG->OCLA_LANE3_CON, 0);
  2344. }
  2345. void mipi_rx_unset_forcerxmode(void *cmdq)
  2346. {
  2347. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2348. + REG_OCLA_LANEC_CON),
  2349. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 0);
  2350. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2351. + REG_OCLA_LANE0_CON),
  2352. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 0);
  2353. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2354. + REG_OCLA_LANE1_CON),
  2355. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 0);
  2356. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2357. + REG_OCLA_LANE2_CON),
  2358. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 0);
  2359. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2360. + REG_OCLA_LANE3_CON),
  2361. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 0);
  2362. }
  2363. void mipi_rx_set_forcerxmode(void *cmdq)
  2364. {
  2365. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2366. + REG_OCLA_LANEC_CON),
  2367. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 1);
  2368. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2369. + REG_OCLA_LANE0_CON),
  2370. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 1);
  2371. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2372. + REG_OCLA_LANE1_CON),
  2373. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 1);
  2374. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2375. + REG_OCLA_LANE2_CON),
  2376. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 1);
  2377. mtk_spi_mask_write((u32)(DISPSYS_BDG_OCLA_BASE
  2378. + REG_OCLA_LANE3_CON),
  2379. OCLA_LANE_CON_FLD_FORCE_RX_MODE, 1);
  2380. }
  2381. void startup_seq_common(void *cmdq)
  2382. {
  2383. DISPFUNCSTART();
  2384. DSI_OUTREG32(cmdq, OCLA_REG->OCLA_LANE_SWAP, 0x30213102);
  2385. mipi_rx_enable(cmdq);
  2386. mipi_rx_set_forcerxmode(cmdq);
  2387. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2388. + CORE_DIG_ANACTRL_RW_COMMON_ANACTRL_0 * 4,
  2389. CORE_DIG_ANACTRL_RW_COMMON_ANACTRL_0_CB_LP_DCO_EN_DLY_MASK,
  2390. 63);
  2391. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2392. + PPI_STARTUP_RW_COMMON_STARTUP_1_1 * 4,
  2393. PPI_STARTUP_RW_COMMON_STARTUP_1_1_PHY_READY_DLY_MASK, 563);
  2394. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2395. + PPI_STARTUP_RW_COMMON_DPHY_6 * 4,
  2396. PPI_STARTUP_RW_COMMON_DPHY_6_LP_DCO_CAL_addr_MASK, 39);
  2397. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2398. + PPI_CALIBCTRL_RW_COMMON_BG_0 * 4,
  2399. PPI_CALIBCTRL_RW_COMMON_BG_0_BG_MAX_COUNTER_MASK, 500);
  2400. /* cfg_clk = 26 MHz */
  2401. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2402. + PPI_RW_TERMCAL_CFG_0 * 4,
  2403. PPI_RW_TERMCAL_CFG_0_TERMCAL_TIMER_MASK, 25);
  2404. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2405. + PPI_RW_OFFSETCAL_CFG_0 * 4,
  2406. PPI_RW_OFFSETCAL_CFG_0_OFFSETCAL_WAIT_THRESH_MASK, 5);
  2407. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2408. + PPI_RW_LPDCOCAL_TIMEBASE * 4,
  2409. PPI_RW_LPDCOCAL_TIMEBASE_LPCDCOCAL_TIMEBASE_MASK, 103);
  2410. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2411. + PPI_RW_LPDCOCAL_NREF * 4,
  2412. PPI_RW_LPDCOCAL_NREF_LPDCOCAL_NREF_MASK, 800);
  2413. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2414. + PPI_RW_LPDCOCAL_NREF_RANGE * 4,
  2415. PPI_RW_LPDCOCAL_NREF_RANGE_LPDCOCAL_NREF_RANGE_MASK, 15);
  2416. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2417. + PPI_RW_LPDCOCAL_TWAIT_CONFIG * 4,
  2418. PPI_RW_LPDCOCAL_TWAIT_CONFIG_LPDCOCAL_TWAIT_PON_MASK, 127);
  2419. /* cfg_clk = 26 MHz */
  2420. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2421. + PPI_RW_LPDCOCAL_TWAIT_CONFIG * 4,
  2422. PPI_RW_LPDCOCAL_TWAIT_CONFIG_LPDCOCAL_TWAIT_COARSE_MASK, 32);
  2423. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2424. + PPI_RW_LPDCOCAL_VT_CONFIG * 4,
  2425. PPI_RW_LPDCOCAL_VT_CONFIG_LPDCOCAL_TWAIT_FINE_MASK, 32);
  2426. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2427. + PPI_RW_LPDCOCAL_VT_CONFIG * 4,
  2428. PPI_RW_LPDCOCAL_VT_CONFIG_LPCDCOCAL_VT_NREF_RANGE_MASK, 15);
  2429. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2430. + PPI_RW_LPDCOCAL_VT_CONFIG * 4,
  2431. PPI_RW_LPDCOCAL_VT_CONFIG_LPCDCOCAL_USE_IDEAL_NREF_MASK, 0);
  2432. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2433. + PPI_RW_LPDCOCAL_VT_CONFIG * 4,
  2434. PPI_RW_LPDCOCAL_VT_CONFIG_LPCDCOCAL_VT_TRACKING_EN_MASK, 0);
  2435. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2436. + PPI_RW_LPDCOCAL_COARSE_CFG * 4,
  2437. PPI_RW_LPDCOCAL_COARSE_CFG_NCOARSE_START_MASK, 1);
  2438. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2439. + CORE_DIG_IOCTRL_RW_AFE_CB_CTRL_2_6 * 4,
  2440. CORE_DIG_IOCTRL_RW_AFE_CB_CTRL_2_6_OA_CB_HSTXLB_DCO_PON_OVR_EN_MASK,
  2441. 1);
  2442. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2443. + PPI_RW_COMMON_CFG * 4,
  2444. PPI_RW_COMMON_CFG_CFG_CLK_DIV_FACTOR_MASK, 3);
  2445. DISPFUNCEND();
  2446. }
  2447. int check_stopstate(void *cmdq)
  2448. {
  2449. unsigned int timeout = 50000;
  2450. unsigned int stop_state = 0, count = 0;
  2451. DISPFUNCSTART();
  2452. while (timeout) {
  2453. stop_state = mtk_spi_read(
  2454. (unsigned long)(&OCLA_REG->OCLA_LANE0_STOPSTATE));
  2455. DISPMSG("stop_state=0x%x, timeout=%d\n", stop_state, timeout);
  2456. if ((stop_state & 0x1) == 0x1)
  2457. count++;
  2458. if (count > 5)
  2459. break;
  2460. udelay(1);
  2461. timeout--;
  2462. }
  2463. if (timeout == 0) {
  2464. DISPMSG("%s, wait timeout!\n", __func__);
  2465. return -1;
  2466. }
  2467. mipi_rx_unset_forcerxmode(cmdq);
  2468. mt6382_init = 1;
  2469. DISPFUNCEND();
  2470. return 0;
  2471. }
  2472. #if 0
  2473. int polling_status(void)
  2474. {
  2475. unsigned int timeout = 5000;
  2476. unsigned int status = 0;
  2477. DISPFUNCSTART();
  2478. while (timeout) {
  2479. status = mtk_spi_read((
  2480. unsigned long)(&TX_REG[0]->DSI_TX_STATE_DBG7));
  2481. DISPMSG("status=0x%x, timeout=%d\n", status, timeout);
  2482. if ((status & 0x800) == 0x800)
  2483. break;
  2484. udelay(1);
  2485. timeout--;
  2486. }
  2487. if (timeout == 0) {
  2488. DISPMSG("%s, wait timeout!\n", __func__);
  2489. return -1;
  2490. }
  2491. DISPFUNCEND();
  2492. return 0;
  2493. }
  2494. void disp_init_bdg_gce_obj(void)
  2495. {
  2496. struct device *dev;
  2497. int index;
  2498. dev = disp_get_device();
  2499. if (dev == NULL) {
  2500. DISPERR("get device fail\n");
  2501. return;
  2502. }
  2503. index = of_property_match_string(dev->of_node,
  2504. "gce-client-names", "BDG_CLIENT_CFG0");
  2505. if (index < 0) {
  2506. DISPERR("%s map client fail\n", __func__);
  2507. return;
  2508. }
  2509. disp_bdg_gce_client = cmdq_mbox_create(dev, index);
  2510. if (disp_bdg_gce_client == NULL) {
  2511. DISPERR("%s create client fail\n", __func__);
  2512. return;
  2513. }
  2514. disp_bdg_gce_base = cmdq_register_device(dev);
  2515. if (disp_bdg_gce_base == NULL)
  2516. DISPERR("%s register client fail\n", __func__);
  2517. bdg_dsi0_eof_gce_event = cmdq_dev_get_event(dev, "bdg_dsi0_eof");
  2518. if (bdg_dsi0_eof_gce_event == 0)
  2519. DISPERR("%s register EOF GCE event %d\n", __func__,
  2520. bdg_dsi0_eof_gce_event);
  2521. bdg_dsi0_sof_gce_event = cmdq_dev_get_event(dev, "bdg_dsi0_sof");
  2522. if (bdg_dsi0_sof_gce_event)
  2523. DISPERR("%s register SOF GCE event %d\n", __func__,
  2524. bdg_dsi0_sof_gce_event);
  2525. bdg_dsi0_te_gce_event = cmdq_dev_get_event(dev, "bdg_dsi0_te");
  2526. if (bdg_dsi0_te_gce_event)
  2527. DISPERR("%s register TE GCE event %d\n", __func__,
  2528. bdg_dsi0_te_gce_event);
  2529. bdg_dsi0_done_gce_event = cmdq_dev_get_event(dev, "bdg_dsi0_done");
  2530. if (bdg_dsi0_done_gce_event)
  2531. DISPERR("%s register DONE GCE event %d\n", __func__,
  2532. bdg_dsi0_done_gce_event);
  2533. bdg_dsi0_target_gce_event =
  2534. cmdq_dev_get_event(dev, "bdg_dsi0_target_line");
  2535. if (bdg_dsi0_target_gce_event)
  2536. DISPERR("%s register TARGET GCE event %d\n", __func__,
  2537. bdg_dsi0_target_gce_event);
  2538. bdg_rdma0_sof_gce_event = cmdq_dev_get_event(dev, "bdg_rdma0_sof");
  2539. if (bdg_rdma0_sof_gce_event)
  2540. DISPERR("%s register TARGET GCE event %d\n", __func__,
  2541. bdg_rdma0_sof_gce_event);
  2542. bdg_rdma0_eof_gce_event = cmdq_dev_get_event(dev, "bdg_rdma0_eof");
  2543. if (bdg_rdma0_eof_gce_event)
  2544. DISPERR("%s register TARGET GCE event %d\n", __func__,
  2545. bdg_rdma0_eof_gce_event);
  2546. }
  2547. static void bdg_cmdq_cb(struct cmdq_cb_data data)
  2548. {
  2549. struct cmdq_pkt *cmdq_handle = data.data;
  2550. cmdq_pkt_destroy(cmdq_handle);
  2551. }
  2552. void bdg_dsi_vfp_gce(unsigned int vfp)
  2553. {
  2554. struct cmdq_pkt *cmdq_handle;
  2555. int ret;
  2556. if (!disp_bdg_gce_client) {
  2557. DISPERR("%s not valid gce client\n", __func__);
  2558. return;
  2559. }
  2560. cmdq_handle = cmdq_pkt_create(disp_bdg_gce_client);
  2561. cmdq_pkt_clear_event(cmdq_handle, bdg_dsi0_target_gce_event);
  2562. cmdq_pkt_clear_event(cmdq_handle, bdg_rdma0_sof_gce_event);
  2563. /* set DSI TARGET_LINE unmask */
  2564. /* TODO: remove fixed TARGET_NL count */
  2565. /* TODO: not to usd fixed address */
  2566. cmdq_pkt_write(cmdq_handle, disp_bdg_gce_base,
  2567. 0x00021300, 0x107d0, ~0);
  2568. cmdq_pkt_wait_no_clear(cmdq_handle, bdg_dsi0_target_gce_event);
  2569. cmdq_pkt_wait_no_clear(cmdq_handle, bdg_rdma0_sof_gce_event);
  2570. /* set BDG VFP to vfp - 1 */
  2571. cmdq_pkt_write(cmdq_handle, disp_bdg_gce_base, 0x00021028, vfp - 1, ~0);
  2572. /* set DSI TARGET_LINE mask */
  2573. cmdq_pkt_write(cmdq_handle, disp_bdg_gce_base, 0x00021300, 0x7d0, ~0);
  2574. /* TODO: use cmdq async flush */
  2575. if (0)
  2576. cmdq_pkt_flush_threaded(cmdq_handle, bdg_cmdq_cb, cmdq_handle);
  2577. else {
  2578. ret = cmdq_pkt_flush(cmdq_handle);
  2579. if (ret)
  2580. DISPERR("%s cmdq_timeout\n", __func__);
  2581. }
  2582. cmdq_pkt_destroy(cmdq_handle);
  2583. }
  2584. #endif
  2585. #define _n36672c_
  2586. int bdg_dsc_init(enum DISP_BDG_ENUM module,
  2587. void *cmdq, LCM_DSI_PARAMS *tx_params)
  2588. {
  2589. unsigned long width = tx_params->horizontal_active_pixel / 1;
  2590. unsigned long height = tx_params->vertical_active_line;
  2591. unsigned int init_delay_limit, init_delay_height;
  2592. unsigned int pic_group_width_m1;
  2593. unsigned int pic_height_m1, pic_height_ext_m1, pic_height_ext_num;
  2594. unsigned int slice_group_width_m1;
  2595. unsigned int pad_num;
  2596. unsigned int val;
  2597. LCM_DSC_CONFIG_PARAMS *params = &tx_params->dsc_params;
  2598. if (!dsc_en) {
  2599. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PIC_H, height - 1);
  2600. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PIC_W, width);
  2601. return 0;
  2602. }
  2603. if (params->pic_width != width || params->pic_height != height) {
  2604. DISPERR("%s size mismatch...", __func__);
  2605. return 1;
  2606. }
  2607. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  2608. REG_DISP_DSC_CON),
  2609. DISP_DSC_CON_FLD_DSC_UFOE_SEL, 1);
  2610. /* DSC Empty flag always high */
  2611. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  2612. REG_DISP_DSC_CON),
  2613. DISP_DSC_CON_FLD_DSC_EMPTY_FLAG_SEL, 1);
  2614. /* DSC output buffer as FHD(plus) */
  2615. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_OBUF, 0x800002C2);
  2616. init_delay_limit =
  2617. ((128 + (params->xmit_delay + 2) / 3) * 3 +
  2618. params->slice_width - 1) / params->slice_width;
  2619. init_delay_height =
  2620. (init_delay_limit > 15) ? 15 : init_delay_limit;
  2621. val = params->slice_mode + (init_delay_height << 8) + (1 << 16);
  2622. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_MODE, val);
  2623. pic_group_width_m1 = (width + 2) / 3 - 1;
  2624. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PIC_W,
  2625. (pic_group_width_m1 << 16) + width);
  2626. pic_height_m1 = height - 1;
  2627. pic_height_ext_num = (height + params->slice_height - 1) /
  2628. params->slice_height;
  2629. pic_height_ext_m1 = pic_height_ext_num * params->slice_height - 1;
  2630. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PIC_H,
  2631. (pic_height_ext_m1 << 16) + pic_height_m1);
  2632. slice_group_width_m1 = (params->slice_width + 2) / 3 - 1;
  2633. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_SLICE_W,
  2634. (slice_group_width_m1 << 16) + params->slice_width);
  2635. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_SLICE_H,
  2636. ((params->slice_width % 3) << 30) +
  2637. ((pic_height_ext_num - 1) << 16) + params->slice_height - 1);
  2638. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_CHUNK_SIZE,
  2639. params->chunk_size);
  2640. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_BUF_SIZE,
  2641. params->chunk_size * params->slice_height);
  2642. pad_num = (params->chunk_size + 2) / 3 * 3 - params->chunk_size;
  2643. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PAD, pad_num);
  2644. if (params->dsc_cfg)
  2645. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_CFG, params->dsc_cfg);
  2646. else
  2647. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_CFG, 0x22);
  2648. if ((params->ver & 0xf) == 2)
  2649. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  2650. REG_DISP_DSC_SHADOW),
  2651. DISP_DSC_VERSION_MINOR, 0x2); /* DSC V1.2 */
  2652. else
  2653. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  2654. REG_DISP_DSC_SHADOW),
  2655. DISP_DSC_VERSION_MINOR, 0x1); /* DSC V1.1 */
  2656. /* set PPS */
  2657. val = params->dsc_line_buf_depth + (params->bit_per_channel << 4) +
  2658. (params->bit_per_pixel << 8) + (params->rct_on << 18) +
  2659. (params->bp_enable << 19);
  2660. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[0], val);
  2661. val = (params->xmit_delay) + (params->dec_delay << 16);
  2662. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[1], val);
  2663. val = (params->scale_value) + (params->increment_interval << 16);
  2664. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[2], val);
  2665. val = (params->decrement_interval) + (params->line_bpg_offset << 16);
  2666. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[3], val);
  2667. val = (params->nfl_bpg_offset) + (params->slice_bpg_offset << 16);
  2668. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[4], val);
  2669. val = (params->initial_offset) + (params->final_offset << 16);
  2670. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[5], val);
  2671. val = (params->flatness_minqp) + (params->flatness_maxqp << 8) +
  2672. (params->rc_model_size << 16);
  2673. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[6], val);
  2674. val = (params->rc_edge_factor) + (params->rc_quant_incr_limit0 << 8) +
  2675. (params->rc_quant_incr_limit1 << 16) +
  2676. (params->rc_tgt_offset_hi << 24) +
  2677. (params->rc_tgt_offset_lo << 28);
  2678. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[7], val);
  2679. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[8], 0x382a1c0e);
  2680. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[9], 0x69625446);
  2681. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[10], 0x7b797770);
  2682. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[11], 0x7e7d);
  2683. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[12], 0x800880);
  2684. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[13], 0xf8c100a1);
  2685. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[14], 0xe8e3f0e3);
  2686. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[15], 0xe103e0e3);
  2687. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[16], 0xd943e123);
  2688. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[17], 0xd185d965);
  2689. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[18], 0xd1a7d1a5);
  2690. DSI_OUTREG32(cmdq, DSC_REG->DISP_DSC_PPS[19], 0xd1ed);
  2691. return 0;
  2692. }
  2693. int mipi_dsi_rx_mac_init(enum DISP_BDG_ENUM module,
  2694. disp_ddp_path_config *config, void *cmdq)
  2695. {
  2696. int ret = 0;
  2697. unsigned int lanes = 0, ipi_mode_qst, out_type;
  2698. unsigned int temp, frame_width;
  2699. unsigned int ipi_tx_delay_qst, t_ipi_tx_delay;
  2700. unsigned int t_ppi_clk, t_ipi_clk, t_hact_ppi, t_hact_ipi;
  2701. /*
  2702. * bit0: LPRX EoTp enable
  2703. * bit1: LPTX EoTp enable
  2704. * bit2: HSRX EoTp enable
  2705. */
  2706. unsigned int eotp_cfg = 4;
  2707. unsigned int timeout = 5000;
  2708. unsigned int phy_ready = 0, count = 0;
  2709. LCM_DSI_PARAMS *tx_params;
  2710. DISPFUNCSTART();
  2711. tx_params = &(config->dsi_config);
  2712. lanes = tx_params->LANE_NUM > 0 ? tx_params->LANE_NUM - 1 : 0;
  2713. ipi_mode_qst = tx_params->mode == SYNC_PULSE_VDO_MODE ? 0 : 1;
  2714. out_type = tx_params->mode == CMD_MODE ? 1 : 0;
  2715. frame_width = tx_params->horizontal_active_pixel;
  2716. DSI_OUTREG32(cmdq, SYS_REG->DISP_MISC0, 1);
  2717. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_N_LANES_OS, 3);
  2718. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_SHUTDOWNZ_OS, 1);
  2719. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_RSTZ_OS, 1);
  2720. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_SOFT_RSTN_OS, 0);
  2721. udelay(1);
  2722. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_SOFT_RSTN_OS, 1);
  2723. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_VERSION_OS, 0);
  2724. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_N_LANES_OS, lanes);
  2725. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_MAIN_OS, 0);
  2726. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_EOTP_CFG_OS, eotp_cfg);
  2727. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_CTRL_CFG_OS, 0);
  2728. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_FIFO_STATUS_OS, 0);
  2729. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_MODE_OS,
  2730. tx_params->IsCphy);
  2731. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_TEST_CTRL0_OS, 0);
  2732. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_TEST_CTRL1_OS, 0);
  2733. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_PHY_DATA_STATUS_OS, 0);
  2734. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_LPTXRDY_TO_CNT_OS, 0);
  2735. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_LPTX_TO_CNT_OS, 0);
  2736. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_HSRX_TO_CNT_OS, 0);
  2737. /* Interrupt Registers */
  2738. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_PHY_FATAL_OS, 0);
  2739. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_PHY_FATAL_OS,
  2740. 0xffffffff);
  2741. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_PHY_FATAL_OS, 0);
  2742. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_PHY_OS, 0);
  2743. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_PHY_OS,
  2744. 0xffffffff);
  2745. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_PHY_OS, 0);
  2746. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_DSI_FATAL_OS, 0);
  2747. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_DSI_FATAL_OS,
  2748. 0xffffffff);
  2749. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_DSI_FATAL_OS, 0);
  2750. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_DSI_OS, 0);
  2751. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_DSI_OS,
  2752. 0xffffffff);
  2753. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_DSI_OS, 0);
  2754. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_DDI_FATAL_OS, 0);
  2755. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_DDI_FATAL_OS,
  2756. 0xffffffff);
  2757. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_DDI_FATAL_OS, 0);
  2758. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_DDI_OS, 0);
  2759. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_DDI_OS,
  2760. 0xffffffff);
  2761. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_DDI_OS, 0);
  2762. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_IPI_FATAL_OS, 0);
  2763. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_IPI_FATAL_OS,
  2764. 0xffffffff);
  2765. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_IPI_FATAL_OS, 0);
  2766. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_FIFO_FATAL_OS, 0);
  2767. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_FIFO_FATAL_OS,
  2768. 0xffffffff);
  2769. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_FIFO_FATAL_OS, 0);
  2770. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_ERR_RPT_OS, 0);
  2771. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_ERR_RPT_OS,
  2772. 0xffffffff);
  2773. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_ERR_RPT_OS, 0);
  2774. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_ST_RX_TRIGGERS_OS, 0);
  2775. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_MASK_N_RX_TRIGGERS_OS,
  2776. 0xffffffff);
  2777. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_INT_FORCE_RX_TRIGGERS_OS, 0);
  2778. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_DDI_RDY_TO_CNT_OS, 0);
  2779. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_DDI_RESP_TO_CNT_OS, 0);
  2780. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_DDI_VALID_VC_CFG_OS, 0xf);
  2781. /* set 0x1b for MMCLK 270M set 0x37 for MMCLK 405M */
  2782. if (MM_CLK == 270)
  2783. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_DDI_CLK_MGR_CFG_OS, 0x1b);
  2784. else
  2785. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_DDI_CLK_MGR_CFG_OS, 0x37);
  2786. /* video mode/ipi */
  2787. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_IPI_MODE_CFG_OS, 0);
  2788. if (ipi_mode_qst)
  2789. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_IPI_MODE_CFG_OS, 1);
  2790. t_ipi_clk = 1000 / MM_CLK;
  2791. t_hact_ipi = frame_width * 1000 / MM_CLK;
  2792. if (tx_params->IsCphy) {
  2793. temp = 7000;
  2794. t_ppi_clk = temp / ap_tx_data_rate;
  2795. t_hact_ppi = ((6 + frame_width * 3) * temp /
  2796. ap_tx_data_rate / (lanes + 1) / 2);
  2797. } else {
  2798. temp = 8000;
  2799. t_ppi_clk = temp / ap_tx_data_rate;
  2800. t_hact_ppi = ((6 + frame_width * 3) * temp /
  2801. ap_tx_data_rate / (lanes + 1));
  2802. }
  2803. if (t_hact_ppi > t_hact_ipi)
  2804. ipi_tx_delay_qst = ((t_hact_ppi - t_hact_ipi) *
  2805. MM_CLK + 20 * temp * MM_CLK / ap_tx_data_rate)
  2806. / 1000 + 4;
  2807. else
  2808. ipi_tx_delay_qst = 20 * temp * MM_CLK /
  2809. ap_tx_data_rate / 1000 + 4;
  2810. DISPMSG("ap_tx_data_rate=%d, temp=%d, t_ppi_clk=%d, t_ipi_clk=%d\n",
  2811. ap_tx_data_rate, temp, t_ppi_clk, t_ipi_clk);
  2812. DISPMSG("t_hact_ppi=%d, t_hact_ipi=%d\n", t_hact_ppi, t_hact_ipi);
  2813. t_ipi_tx_delay = ipi_tx_delay_qst * 1000 / MM_CLK;
  2814. DISPMSG("ipi_tx_delay_qst=%d, t_ipi_tx_delay=%d\n",
  2815. ipi_tx_delay_qst, t_ipi_tx_delay);
  2816. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_IPI_VALID_VC_CFG_OS, 0);
  2817. DSI_OUTREG32(cmdq, DSI2_REG->DSI2_DEVICE_IPI_TX_DELAY_OS,
  2818. ipi_tx_delay_qst);
  2819. while (timeout) {
  2820. phy_ready = mtk_spi_read(
  2821. (unsigned long)(&OCLA_REG->OCLA_PHY_READY));
  2822. if ((phy_ready & 0x1) == 0x1)
  2823. count++;
  2824. if (count > 5)
  2825. break;
  2826. udelay(1);
  2827. timeout--;
  2828. }
  2829. if (timeout == 0) {
  2830. ret = -1;
  2831. DISPMSG("%s, wait timeout!\n", __func__);
  2832. }
  2833. DISPFUNCEND();
  2834. return ret;
  2835. }
  2836. void startup_seq_dphy_specific(unsigned int data_rate)
  2837. {
  2838. DISPMSG("%s, data_rate=%d\n", __func__, data_rate);
  2839. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  2840. CORE_DIG_RW_COMMON_7 * 4,
  2841. CORE_DIG_RW_COMMON_7_LANE0_HSRX_WORD_CLK_SEL_GATING_REG_MASK,
  2842. 0);
  2843. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  2844. CORE_DIG_RW_COMMON_7 * 4,
  2845. CORE_DIG_RW_COMMON_7_LANE1_HSRX_WORD_CLK_SEL_GATING_REG_MASK,
  2846. 0);
  2847. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  2848. CORE_DIG_RW_COMMON_7 * 4,
  2849. CORE_DIG_RW_COMMON_7_LANE2_HSRX_WORD_CLK_SEL_GATING_REG_MASK,
  2850. 0);
  2851. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  2852. CORE_DIG_RW_COMMON_7 * 4,
  2853. CORE_DIG_RW_COMMON_7_LANE3_HSRX_WORD_CLK_SEL_GATING_REG_MASK,
  2854. 0);
  2855. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  2856. CORE_DIG_RW_COMMON_7 * 4,
  2857. CORE_DIG_RW_COMMON_7_LANE4_HSRX_WORD_CLK_SEL_GATING_REG_MASK,
  2858. 0);
  2859. if (data_rate > RX_V12)
  2860. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2861. + PPI_STARTUP_RW_COMMON_DPHY_7 * 4,
  2862. PPI_STARTUP_RW_COMMON_DPHY_7_DPHY_DDL_CAL_addr_MASK, 40);
  2863. else
  2864. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2865. + PPI_STARTUP_RW_COMMON_DPHY_7 * 4,
  2866. PPI_STARTUP_RW_COMMON_DPHY_7_DPHY_DDL_CAL_addr_MASK, 104);
  2867. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2868. + PPI_STARTUP_RW_COMMON_DPHY_8 * 4,
  2869. PPI_STARTUP_RW_COMMON_DPHY_8_CPHY_DDL_CAL_addr_MASK, 80);
  2870. /* cfg_clk = 26 MHz */
  2871. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2872. + PPI_RW_DDLCAL_CFG_0 * 4,
  2873. PPI_RW_DDLCAL_CFG_0_DDLCAL_TIMEBASE_TARGET_MASK, 125);
  2874. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2875. + PPI_RW_DDLCAL_CFG_7 * 4,
  2876. PPI_RW_DDLCAL_CFG_7_DDLCAL_DECR_WAIT_MASK, 34);
  2877. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2878. + PPI_RW_DDLCAL_CFG_1 * 4,
  2879. PPI_RW_DDLCAL_CFG_1_DDLCAL_DISABLE_TIME_MASK, 25);
  2880. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2881. + PPI_RW_DDLCAL_CFG_2 * 4,
  2882. PPI_RW_DDLCAL_CFG_2_DDLCAL_WAIT_MASK, 4);
  2883. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2884. + PPI_RW_DDLCAL_CFG_2 * 4,
  2885. PPI_RW_DDLCAL_CFG_2_DDLCAL_TUNE_MODE_MASK, 2);
  2886. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2887. + PPI_RW_DDLCAL_CFG_2 * 4,
  2888. PPI_RW_DDLCAL_CFG_2_DDLCAL_DDL_DLL_MASK, 1);
  2889. /* cfg_clk = 26 MHz */
  2890. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2891. + PPI_RW_DDLCAL_CFG_2 * 4,
  2892. PPI_RW_DDLCAL_CFG_2_DDLCAL_ENABLE_WAIT_MASK, 25);
  2893. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2894. + PPI_RW_DDLCAL_CFG_2 * 4,
  2895. PPI_RW_DDLCAL_CFG_2_DDLCAL_UPDATE_SETTINGS_MASK, 1);
  2896. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2897. + PPI_RW_DDLCAL_CFG_4 * 4,
  2898. PPI_RW_DDLCAL_CFG_4_DDLCAL_STUCK_THRESH_MASK, 10);
  2899. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2900. + PPI_RW_DDLCAL_CFG_6 * 4,
  2901. PPI_RW_DDLCAL_CFG_6_DDLCAL_MAX_DIFF_MASK, 10);
  2902. /* cfg_clk = 26 MHz */
  2903. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2904. + PPI_RW_DDLCAL_CFG_7 * 4,
  2905. PPI_RW_DDLCAL_CFG_7_DDLCAL_START_DELAY_MASK, 12);
  2906. if (data_rate > 1500) {
  2907. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2908. + PPI_RW_DDLCAL_CFG_3 * 4,
  2909. PPI_RW_DDLCAL_CFG_3_DDLCAL_COUNTER_REF_MASK,
  2910. ddl_cntr_ref_reg);
  2911. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2912. + PPI_RW_DDLCAL_CFG_1 * 4,
  2913. PPI_RW_DDLCAL_CFG_1_DDLCAL_MAX_PHASE_MASK,
  2914. max_phase);
  2915. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2916. + PPI_RW_DDLCAL_CFG_5 * 4,
  2917. PPI_RW_DDLCAL_CFG_5_DDLCAL_DLL_FBK_MASK,
  2918. dll_fbk);
  2919. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2920. + PPI_RW_DDLCAL_CFG_5 * 4,
  2921. PPI_RW_DDLCAL_CFG_5_DDLCAL_DDL_COARSE_BANK_MASK,
  2922. coarse_bank);
  2923. }
  2924. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2925. + CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_8 * 4,
  2926. CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_8_OA_LANE0_HSRX_CDPHY_SEL_FAST_MASK,
  2927. sel_fast);
  2928. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2929. + CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_8 * 4,
  2930. CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_8_OA_LANE1_HSRX_CDPHY_SEL_FAST_MASK,
  2931. sel_fast);
  2932. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2933. + CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_8 * 4,
  2934. CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_8_OA_LANE2_HSRX_CDPHY_SEL_FAST_MASK,
  2935. sel_fast);
  2936. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2937. + CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_8 * 4,
  2938. CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_8_OA_LANE3_HSRX_CDPHY_SEL_FAST_MASK,
  2939. sel_fast);
  2940. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2941. + CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_8 * 4,
  2942. CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_8_OA_LANE4_HSRX_CDPHY_SEL_FAST_MASK,
  2943. sel_fast);
  2944. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2945. + CORE_DIG_DLANE_0_RW_LP_0 * 4,
  2946. CORE_DIG_DLANE_0_RW_LP_0_LP_0_TTAGO_REG_MASK, 6);
  2947. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2948. + CORE_DIG_DLANE_1_RW_LP_0 * 4,
  2949. CORE_DIG_DLANE_1_RW_LP_0_LP_0_TTAGO_REG_MASK, 6);
  2950. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2951. + CORE_DIG_DLANE_2_RW_LP_0 * 4,
  2952. CORE_DIG_DLANE_2_RW_LP_0_LP_0_TTAGO_REG_MASK, 6);
  2953. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2954. + CORE_DIG_DLANE_3_RW_LP_0 * 4,
  2955. CORE_DIG_DLANE_3_RW_LP_0_LP_0_TTAGO_REG_MASK, 6);
  2956. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2957. + CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_2 * 4,
  2958. CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_2_OA_LANE0_SEL_LANE_CFG_MASK, 0);
  2959. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2960. + CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_2 * 4,
  2961. CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_2_OA_LANE1_SEL_LANE_CFG_MASK, 0);
  2962. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2963. + CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_2 * 4,
  2964. CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_2_OA_LANE2_SEL_LANE_CFG_MASK, 1);
  2965. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2966. + CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_2 * 4,
  2967. CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_2_OA_LANE3_SEL_LANE_CFG_MASK, 0);
  2968. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2969. + CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_2 * 4,
  2970. CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_2_OA_LANE4_SEL_LANE_CFG_MASK, 0);
  2971. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2972. + CORE_DIG_RW_COMMON_6 * 4,
  2973. CORE_DIG_RW_COMMON_6_DESERIALIZER_EN_DEASS_COUNT_THRESH_D_MASK, 1);
  2974. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2975. + CORE_DIG_RW_COMMON_6 * 4,
  2976. CORE_DIG_RW_COMMON_6_DESERIALIZER_DIV_EN_DELAY_THRESH_D_MASK, 1);
  2977. if (data_rate > RX_V12) {
  2978. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2979. + CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_12 * 4,
  2980. CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_12_OA_LANE0_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 0);
  2981. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2982. + CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_12 * 4,
  2983. CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_12_OA_LANE1_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 0);
  2984. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2985. + CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_12 * 4,
  2986. CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_12_OA_LANE2_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 0);
  2987. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2988. + CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_12 * 4,
  2989. CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_12_OA_LANE3_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 0);
  2990. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2991. + CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_12 * 4,
  2992. CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_12_OA_LANE4_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 0);
  2993. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2994. + CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_13 * 4,
  2995. CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_13_OA_LANE0_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 0);
  2996. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  2997. + CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_13 * 4,
  2998. CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_13_OA_LANE1_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 0);
  2999. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3000. + CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_13 * 4,
  3001. CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_13_OA_LANE2_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 0);
  3002. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3003. + CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_13 * 4,
  3004. CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_13_OA_LANE3_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 0);
  3005. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3006. + CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_13 * 4,
  3007. CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_13_OA_LANE4_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 0);
  3008. } else {
  3009. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3010. + CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_12 * 4,
  3011. CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_12_OA_LANE0_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 1);
  3012. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3013. + CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_12 * 4,
  3014. CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_12_OA_LANE1_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 1);
  3015. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3016. + CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_12 * 4,
  3017. CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_12_OA_LANE2_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 1);
  3018. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3019. + CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_12 * 4,
  3020. CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_12_OA_LANE3_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 1);
  3021. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3022. + CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_12 * 4,
  3023. CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_12_OA_LANE4_HSRX_DPHY_DDL_BYPASS_EN_OVR_VAL_MASK, 1);
  3024. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3025. + CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_13 * 4,
  3026. CORE_DIG_IOCTRL_RW_AFE_LANE0_CTRL_2_13_OA_LANE0_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 1);
  3027. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3028. + CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_13 * 4,
  3029. CORE_DIG_IOCTRL_RW_AFE_LANE1_CTRL_2_13_OA_LANE1_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 1);
  3030. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3031. + CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_13 * 4,
  3032. CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_13_OA_LANE2_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 1);
  3033. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3034. + CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_13 * 4,
  3035. CORE_DIG_IOCTRL_RW_AFE_LANE3_CTRL_2_13_OA_LANE3_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 1);
  3036. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3037. + CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_13 * 4,
  3038. CORE_DIG_IOCTRL_RW_AFE_LANE4_CTRL_2_13_OA_LANE4_HSRX_DPHY_DDL_BYPASS_EN_OVR_EN_MASK, 1);
  3039. }
  3040. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3041. + CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_9 * 4,
  3042. CORE_DIG_IOCTRL_RW_AFE_LANE2_CTRL_2_9_OA_LANE2_HSRX_HS_CLK_DIV_MASK,
  3043. hsrx_clk_div);
  3044. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3045. + CORE_DIG_DLANE_CLK_RW_HS_RX_0 * 4,
  3046. CORE_DIG_DLANE_CLK_RW_HS_RX_0_HS_RX_0_TCLKSETTLE_REG_MASK, 28);
  3047. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3048. + CORE_DIG_DLANE_CLK_RW_HS_RX_7 * 4,
  3049. CORE_DIG_DLANE_CLK_RW_HS_RX_7_HS_RX_7_TCLKMISS_REG_MASK, 6);
  3050. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3051. + CORE_DIG_DLANE_0_RW_HS_RX_0 * 4,
  3052. CORE_DIG_DLANE_0_RW_HS_RX_0_HS_RX_0_THSSETTLE_REG_MASK,
  3053. hs_thssettle);
  3054. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3055. + CORE_DIG_DLANE_1_RW_HS_RX_0 * 4,
  3056. CORE_DIG_DLANE_1_RW_HS_RX_0_HS_RX_0_THSSETTLE_REG_MASK,
  3057. hs_thssettle);
  3058. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3059. + CORE_DIG_DLANE_2_RW_HS_RX_0 * 4,
  3060. CORE_DIG_DLANE_2_RW_HS_RX_0_HS_RX_0_THSSETTLE_REG_MASK,
  3061. hs_thssettle);
  3062. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3063. + CORE_DIG_DLANE_3_RW_HS_RX_0 * 4,
  3064. CORE_DIG_DLANE_3_RW_HS_RX_0_HS_RX_0_THSSETTLE_REG_MASK,
  3065. hs_thssettle);
  3066. if (data_rate > RX_V12) {
  3067. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3068. + CORE_DIG_DLANE_0_RW_CFG_1 * 4,
  3069. CORE_DIG_DLANE_0_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3070. 1);
  3071. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3072. + CORE_DIG_DLANE_1_RW_CFG_1 * 4,
  3073. CORE_DIG_DLANE_1_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3074. 1);
  3075. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3076. + CORE_DIG_DLANE_2_RW_CFG_1 * 4,
  3077. CORE_DIG_DLANE_2_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3078. 1);
  3079. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3080. + CORE_DIG_DLANE_3_RW_CFG_1 * 4,
  3081. CORE_DIG_DLANE_3_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3082. 1);
  3083. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3084. + CORE_DIG_DLANE_0_RW_CFG_1 * 4,
  3085. CORE_DIG_DLANE_0_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3086. 0);
  3087. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3088. + CORE_DIG_DLANE_1_RW_CFG_1 * 4,
  3089. CORE_DIG_DLANE_1_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3090. 0);
  3091. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3092. + CORE_DIG_DLANE_2_RW_CFG_1 * 4,
  3093. CORE_DIG_DLANE_2_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3094. 0);
  3095. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3096. + CORE_DIG_DLANE_3_RW_CFG_1 * 4,
  3097. CORE_DIG_DLANE_3_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3098. 0);
  3099. } else {
  3100. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3101. + CORE_DIG_DLANE_0_RW_CFG_1 * 4,
  3102. CORE_DIG_DLANE_0_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3103. 0);
  3104. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3105. + CORE_DIG_DLANE_1_RW_CFG_1 * 4,
  3106. CORE_DIG_DLANE_1_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3107. 0);
  3108. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3109. + CORE_DIG_DLANE_2_RW_CFG_1 * 4,
  3110. CORE_DIG_DLANE_2_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3111. 0);
  3112. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3113. + CORE_DIG_DLANE_3_RW_CFG_1 * 4,
  3114. CORE_DIG_DLANE_3_RW_CFG_1_CFG_1_DESKEW_SUPPORTED_REG_MASK,
  3115. 0);
  3116. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3117. + CORE_DIG_DLANE_0_RW_CFG_1 * 4,
  3118. CORE_DIG_DLANE_0_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3119. 1);
  3120. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3121. + CORE_DIG_DLANE_1_RW_CFG_1 * 4,
  3122. CORE_DIG_DLANE_1_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3123. 1);
  3124. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3125. + CORE_DIG_DLANE_2_RW_CFG_1 * 4,
  3126. CORE_DIG_DLANE_2_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3127. 1);
  3128. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3129. + CORE_DIG_DLANE_3_RW_CFG_1 * 4,
  3130. CORE_DIG_DLANE_3_RW_CFG_1_CFG_1_SOT_DETECTION_REG_MASK,
  3131. 1);
  3132. }
  3133. if (data_rate > 2500) {
  3134. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3135. + CORE_DIG_DLANE_0_RW_HS_RX_2 * 4,
  3136. CORE_DIG_DLANE_0_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3137. 0);
  3138. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3139. + CORE_DIG_DLANE_1_RW_HS_RX_2 * 4,
  3140. CORE_DIG_DLANE_1_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3141. 0);
  3142. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3143. + CORE_DIG_DLANE_2_RW_HS_RX_2 * 4,
  3144. CORE_DIG_DLANE_2_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3145. 0);
  3146. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3147. + CORE_DIG_DLANE_3_RW_HS_RX_2 * 4,
  3148. CORE_DIG_DLANE_3_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3149. 0);
  3150. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3151. + CORE_DIG_DLANE_CLK_RW_HS_RX_2 * 4,
  3152. CORE_DIG_DLANE_CLK_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3153. 0);
  3154. } else {
  3155. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3156. + CORE_DIG_DLANE_0_RW_HS_RX_2 * 4,
  3157. CORE_DIG_DLANE_0_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3158. 1);
  3159. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3160. + CORE_DIG_DLANE_1_RW_HS_RX_2 * 4,
  3161. CORE_DIG_DLANE_1_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3162. 1);
  3163. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3164. + CORE_DIG_DLANE_2_RW_HS_RX_2 * 4,
  3165. CORE_DIG_DLANE_2_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3166. 1);
  3167. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3168. + CORE_DIG_DLANE_3_RW_HS_RX_2 * 4,
  3169. CORE_DIG_DLANE_3_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3170. 1);
  3171. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3172. + CORE_DIG_DLANE_CLK_RW_HS_RX_2 * 4,
  3173. CORE_DIG_DLANE_CLK_RW_HS_RX_2_HS_RX_2_IGNORE_ALTERNCAL_REG_MASK,
  3174. 1);
  3175. }
  3176. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3177. + CORE_DIG_DLANE_0_RW_HS_RX_2 * 4,
  3178. CORE_DIG_DLANE_0_RW_HS_RX_2_HS_RX_2_UPDATE_SETTINGS_DESKEW_REG_MASK,
  3179. 1);
  3180. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3181. + CORE_DIG_DLANE_1_RW_HS_RX_2 * 4,
  3182. CORE_DIG_DLANE_1_RW_HS_RX_2_HS_RX_2_UPDATE_SETTINGS_DESKEW_REG_MASK,
  3183. 1);
  3184. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3185. + CORE_DIG_DLANE_2_RW_HS_RX_2 * 4,
  3186. CORE_DIG_DLANE_2_RW_HS_RX_2_HS_RX_2_UPDATE_SETTINGS_DESKEW_REG_MASK,
  3187. 1);
  3188. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3189. + CORE_DIG_DLANE_3_RW_HS_RX_2 * 4,
  3190. CORE_DIG_DLANE_3_RW_HS_RX_2_HS_RX_2_UPDATE_SETTINGS_DESKEW_REG_MASK,
  3191. 1);
  3192. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3193. + CORE_DIG_DLANE_CLK_RW_HS_RX_2 * 4,
  3194. CORE_DIG_DLANE_CLK_RW_HS_RX_2_HS_RX_2_UPDATE_SETTINGS_DESKEW_REG_MASK,
  3195. 1);
  3196. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3197. + CORE_DIG_DLANE_0_RW_HS_RX_1 * 4,
  3198. CORE_DIG_DLANE_0_RW_HS_RX_1_HS_RX_1_FILTER_SIZE_DESKEW_REG_MASK,
  3199. 16);
  3200. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3201. + CORE_DIG_DLANE_1_RW_HS_RX_1 * 4,
  3202. CORE_DIG_DLANE_1_RW_HS_RX_1_HS_RX_1_FILTER_SIZE_DESKEW_REG_MASK,
  3203. 16);
  3204. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE
  3205. + CORE_DIG_DLANE_2_RW_HS_RX_1 * 4,
  3206. CORE_DIG_DLANE_2_RW_HS_RX_1_HS_RX_1_FILTER_SIZE_DESKEW_REG_MASK,
  3207. 16);
  3208. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3209. CORE_DIG_DLANE_3_RW_HS_RX_1 * 4,
  3210. CORE_DIG_DLANE_3_RW_HS_RX_1_HS_RX_1_FILTER_SIZE_DESKEW_REG_MASK,
  3211. 16);
  3212. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3213. CORE_DIG_DLANE_0_RW_HS_RX_2 * 4,
  3214. CORE_DIG_DLANE_0_RW_HS_RX_2_HS_RX_2_WINDOW_SIZE_DESKEW_REG_MASK,
  3215. 3);
  3216. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3217. CORE_DIG_DLANE_1_RW_HS_RX_2 * 4,
  3218. CORE_DIG_DLANE_1_RW_HS_RX_2_HS_RX_2_WINDOW_SIZE_DESKEW_REG_MASK,
  3219. 3);
  3220. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3221. CORE_DIG_DLANE_2_RW_HS_RX_2 * 4,
  3222. CORE_DIG_DLANE_2_RW_HS_RX_2_HS_RX_2_WINDOW_SIZE_DESKEW_REG_MASK,
  3223. 3);
  3224. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3225. CORE_DIG_DLANE_3_RW_HS_RX_2 * 4,
  3226. CORE_DIG_DLANE_3_RW_HS_RX_2_HS_RX_2_WINDOW_SIZE_DESKEW_REG_MASK,
  3227. 3);
  3228. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3229. CORE_DIG_DLANE_CLK_RW_HS_RX_2 * 4,
  3230. CORE_DIG_DLANE_CLK_RW_HS_RX_2_HS_RX_2_WINDOW_SIZE_DESKEW_REG_MASK,
  3231. 3);
  3232. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3233. CORE_DIG_DLANE_0_RW_HS_RX_3 * 4,
  3234. CORE_DIG_DLANE_0_RW_HS_RX_3_HS_RX_3_STEP_SIZE_DESKEW_REG_MASK,
  3235. 1);
  3236. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3237. CORE_DIG_DLANE_1_RW_HS_RX_3 * 4,
  3238. CORE_DIG_DLANE_1_RW_HS_RX_3_HS_RX_3_STEP_SIZE_DESKEW_REG_MASK,
  3239. 1);
  3240. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3241. CORE_DIG_DLANE_2_RW_HS_RX_3 * 4,
  3242. CORE_DIG_DLANE_2_RW_HS_RX_3_HS_RX_3_STEP_SIZE_DESKEW_REG_MASK,
  3243. 1);
  3244. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3245. CORE_DIG_DLANE_3_RW_HS_RX_3 * 4,
  3246. CORE_DIG_DLANE_3_RW_HS_RX_3_HS_RX_3_STEP_SIZE_DESKEW_REG_MASK,
  3247. 1);
  3248. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3249. CORE_DIG_DLANE_0_RW_HS_RX_4 * 4,
  3250. CORE_DIG_DLANE_0_RW_HS_RX_4_HS_RX_4_MAX_ITERATIONS_DESKEW_REG_MASK,
  3251. 150);
  3252. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3253. CORE_DIG_DLANE_1_RW_HS_RX_4 * 4,
  3254. CORE_DIG_DLANE_1_RW_HS_RX_4_HS_RX_4_MAX_ITERATIONS_DESKEW_REG_MASK,
  3255. 150);
  3256. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3257. CORE_DIG_DLANE_2_RW_HS_RX_4 * 4,
  3258. CORE_DIG_DLANE_2_RW_HS_RX_4_HS_RX_4_MAX_ITERATIONS_DESKEW_REG_MASK,
  3259. 150);
  3260. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3261. CORE_DIG_DLANE_3_RW_HS_RX_4 * 4,
  3262. CORE_DIG_DLANE_3_RW_HS_RX_4_HS_RX_4_MAX_ITERATIONS_DESKEW_REG_MASK,
  3263. 150);
  3264. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3265. CORE_DIG_DLANE_0_RW_HS_RX_5 * 4,
  3266. CORE_DIG_DLANE_0_RW_HS_RX_5_HS_RX_5_DDL_LEFT_INIT_REG_MASK,
  3267. 0);
  3268. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3269. CORE_DIG_DLANE_1_RW_HS_RX_5 * 4,
  3270. CORE_DIG_DLANE_1_RW_HS_RX_5_HS_RX_5_DDL_LEFT_INIT_REG_MASK,
  3271. 0);
  3272. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3273. CORE_DIG_DLANE_2_RW_HS_RX_5 * 4,
  3274. CORE_DIG_DLANE_2_RW_HS_RX_5_HS_RX_5_DDL_LEFT_INIT_REG_MASK,
  3275. 0);
  3276. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3277. CORE_DIG_DLANE_3_RW_HS_RX_5 * 4,
  3278. CORE_DIG_DLANE_3_RW_HS_RX_5_HS_RX_5_DDL_LEFT_INIT_REG_MASK,
  3279. 0);
  3280. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3281. CORE_DIG_DLANE_0_RW_HS_RX_5 * 4,
  3282. CORE_DIG_DLANE_0_RW_HS_RX_5_HS_RX_5_DDL_MID_INIT_REG_MASK,
  3283. 1);
  3284. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3285. CORE_DIG_DLANE_1_RW_HS_RX_5 * 4,
  3286. CORE_DIG_DLANE_1_RW_HS_RX_5_HS_RX_5_DDL_MID_INIT_REG_MASK,
  3287. 1);
  3288. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3289. CORE_DIG_DLANE_2_RW_HS_RX_5 * 4,
  3290. CORE_DIG_DLANE_2_RW_HS_RX_5_HS_RX_5_DDL_MID_INIT_REG_MASK,
  3291. 1);
  3292. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3293. CORE_DIG_DLANE_3_RW_HS_RX_5 * 4,
  3294. CORE_DIG_DLANE_3_RW_HS_RX_5_HS_RX_5_DDL_MID_INIT_REG_MASK,
  3295. 1);
  3296. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3297. CORE_DIG_DLANE_0_RW_HS_RX_6 * 4,
  3298. CORE_DIG_DLANE_0_RW_HS_RX_6_HS_RX_6_DDL_RIGHT_INIT_REG_MASK,
  3299. 2);
  3300. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3301. CORE_DIG_DLANE_1_RW_HS_RX_6 * 4,
  3302. CORE_DIG_DLANE_1_RW_HS_RX_6_HS_RX_6_DDL_RIGHT_INIT_REG_MASK,
  3303. 2);
  3304. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3305. CORE_DIG_DLANE_2_RW_HS_RX_6 * 4,
  3306. CORE_DIG_DLANE_2_RW_HS_RX_6_HS_RX_6_DDL_RIGHT_INIT_REG_MASK,
  3307. 2);
  3308. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3309. CORE_DIG_DLANE_3_RW_HS_RX_6 * 4,
  3310. CORE_DIG_DLANE_3_RW_HS_RX_6_HS_RX_6_DDL_RIGHT_INIT_REG_MASK,
  3311. 2);
  3312. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3313. CORE_DIG_DLANE_0_RW_HS_RX_7 * 4,
  3314. CORE_DIG_DLANE_0_RW_HS_RX_7_HS_RX_7_DESKEW_AUTO_ALGO_SEL_REG_MASK,
  3315. 1);
  3316. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3317. CORE_DIG_DLANE_1_RW_HS_RX_7 * 4,
  3318. CORE_DIG_DLANE_1_RW_HS_RX_7_HS_RX_7_DESKEW_AUTO_ALGO_SEL_REG_MASK,
  3319. 1);
  3320. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3321. CORE_DIG_DLANE_2_RW_HS_RX_7 * 4,
  3322. CORE_DIG_DLANE_2_RW_HS_RX_7_HS_RX_7_DESKEW_AUTO_ALGO_SEL_REG_MASK,
  3323. 1);
  3324. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3325. CORE_DIG_DLANE_3_RW_HS_RX_7 * 4,
  3326. CORE_DIG_DLANE_3_RW_HS_RX_7_HS_RX_7_DESKEW_AUTO_ALGO_SEL_REG_MASK,
  3327. 1);
  3328. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3329. CORE_DIG_DLANE_0_RW_HS_RX_3 * 4,
  3330. CORE_DIG_DLANE_0_RW_HS_RX_3_HS_RX_3_FJUMP_DESKEW_REG_MASK,
  3331. fjump_deskew_reg);
  3332. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3333. CORE_DIG_DLANE_1_RW_HS_RX_3 * 4,
  3334. CORE_DIG_DLANE_1_RW_HS_RX_3_HS_RX_3_FJUMP_DESKEW_REG_MASK,
  3335. fjump_deskew_reg);
  3336. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3337. CORE_DIG_DLANE_2_RW_HS_RX_3 * 4,
  3338. CORE_DIG_DLANE_2_RW_HS_RX_3_HS_RX_3_FJUMP_DESKEW_REG_MASK,
  3339. fjump_deskew_reg);
  3340. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3341. CORE_DIG_DLANE_3_RW_HS_RX_3 * 4,
  3342. CORE_DIG_DLANE_3_RW_HS_RX_3_HS_RX_3_FJUMP_DESKEW_REG_MASK,
  3343. fjump_deskew_reg);
  3344. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3345. CORE_DIG_DLANE_0_RW_HS_RX_6 * 4,
  3346. CORE_DIG_DLANE_0_RW_HS_RX_6_HS_RX_6_MIN_EYE_OPENING_DESKEW_REG_MASK,
  3347. eye_open_deskew_reg);
  3348. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3349. CORE_DIG_DLANE_1_RW_HS_RX_6 * 4,
  3350. CORE_DIG_DLANE_1_RW_HS_RX_6_HS_RX_6_MIN_EYE_OPENING_DESKEW_REG_MASK,
  3351. eye_open_deskew_reg);
  3352. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3353. CORE_DIG_DLANE_2_RW_HS_RX_6 * 4,
  3354. CORE_DIG_DLANE_2_RW_HS_RX_6_HS_RX_6_MIN_EYE_OPENING_DESKEW_REG_MASK,
  3355. eye_open_deskew_reg);
  3356. mtk_spi_mask_field_write(MIPI_RX_PHY_BASE +
  3357. CORE_DIG_DLANE_3_RW_HS_RX_6 * 4,
  3358. CORE_DIG_DLANE_3_RW_HS_RX_6_HS_RX_6_MIN_EYE_OPENING_DESKEW_REG_MASK,
  3359. eye_open_deskew_reg);
  3360. mtk_spi_write(MIPI_RX_PHY_BASE +
  3361. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4,
  3362. 0x0404);
  3363. mtk_spi_write(MIPI_RX_PHY_BASE +
  3364. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4,
  3365. 0x040C);
  3366. mtk_spi_write(MIPI_RX_PHY_BASE +
  3367. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0414);
  3368. mtk_spi_write(MIPI_RX_PHY_BASE +
  3369. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x041C);
  3370. mtk_spi_write(MIPI_RX_PHY_BASE +
  3371. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0423);
  3372. mtk_spi_write(MIPI_RX_PHY_BASE +
  3373. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0429);
  3374. mtk_spi_write(MIPI_RX_PHY_BASE +
  3375. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0430);
  3376. mtk_spi_write(MIPI_RX_PHY_BASE +
  3377. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x043A);
  3378. mtk_spi_write(MIPI_RX_PHY_BASE +
  3379. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0445);
  3380. mtk_spi_write(MIPI_RX_PHY_BASE +
  3381. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x044A);
  3382. mtk_spi_write(MIPI_RX_PHY_BASE +
  3383. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0450);
  3384. mtk_spi_write(MIPI_RX_PHY_BASE +
  3385. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x045A);
  3386. mtk_spi_write(MIPI_RX_PHY_BASE +
  3387. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0465);
  3388. mtk_spi_write(MIPI_RX_PHY_BASE +
  3389. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0469);
  3390. mtk_spi_write(MIPI_RX_PHY_BASE +
  3391. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0472);
  3392. mtk_spi_write(MIPI_RX_PHY_BASE +
  3393. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x047A);
  3394. mtk_spi_write(MIPI_RX_PHY_BASE +
  3395. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0485);
  3396. mtk_spi_write(MIPI_RX_PHY_BASE +
  3397. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0489);
  3398. mtk_spi_write(MIPI_RX_PHY_BASE +
  3399. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0490);
  3400. mtk_spi_write(MIPI_RX_PHY_BASE +
  3401. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x049A);
  3402. mtk_spi_write(MIPI_RX_PHY_BASE +
  3403. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04A4);
  3404. mtk_spi_write(MIPI_RX_PHY_BASE +
  3405. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04AC);
  3406. mtk_spi_write(MIPI_RX_PHY_BASE +
  3407. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04B4);
  3408. mtk_spi_write(MIPI_RX_PHY_BASE +
  3409. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04BC);
  3410. mtk_spi_write(MIPI_RX_PHY_BASE +
  3411. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04C4);
  3412. mtk_spi_write(MIPI_RX_PHY_BASE +
  3413. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04CC);
  3414. mtk_spi_write(MIPI_RX_PHY_BASE +
  3415. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04D4);
  3416. mtk_spi_write(MIPI_RX_PHY_BASE +
  3417. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04DC);
  3418. mtk_spi_write(MIPI_RX_PHY_BASE +
  3419. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04E4);
  3420. mtk_spi_write(MIPI_RX_PHY_BASE +
  3421. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04EC);
  3422. mtk_spi_write(MIPI_RX_PHY_BASE +
  3423. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04F4);
  3424. mtk_spi_write(MIPI_RX_PHY_BASE +
  3425. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x04FC);
  3426. mtk_spi_write(MIPI_RX_PHY_BASE +
  3427. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0504);
  3428. mtk_spi_write(MIPI_RX_PHY_BASE +
  3429. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x050C);
  3430. mtk_spi_write(MIPI_RX_PHY_BASE +
  3431. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0514);
  3432. mtk_spi_write(MIPI_RX_PHY_BASE +
  3433. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x051C);
  3434. mtk_spi_write(MIPI_RX_PHY_BASE +
  3435. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0523);
  3436. mtk_spi_write(MIPI_RX_PHY_BASE +
  3437. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0529);
  3438. mtk_spi_write(MIPI_RX_PHY_BASE +
  3439. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0530);
  3440. mtk_spi_write(MIPI_RX_PHY_BASE +
  3441. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x053A);
  3442. mtk_spi_write(MIPI_RX_PHY_BASE +
  3443. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0545);
  3444. mtk_spi_write(MIPI_RX_PHY_BASE +
  3445. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x054A);
  3446. mtk_spi_write(MIPI_RX_PHY_BASE +
  3447. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0550);
  3448. mtk_spi_write(MIPI_RX_PHY_BASE +
  3449. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x055A);
  3450. mtk_spi_write(MIPI_RX_PHY_BASE +
  3451. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0565);
  3452. mtk_spi_write(MIPI_RX_PHY_BASE +
  3453. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0569);
  3454. mtk_spi_write(MIPI_RX_PHY_BASE +
  3455. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0572);
  3456. mtk_spi_write(MIPI_RX_PHY_BASE +
  3457. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x057A);
  3458. mtk_spi_write(MIPI_RX_PHY_BASE +
  3459. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0585);
  3460. mtk_spi_write(MIPI_RX_PHY_BASE +
  3461. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0589);
  3462. mtk_spi_write(MIPI_RX_PHY_BASE +
  3463. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0590);
  3464. mtk_spi_write(MIPI_RX_PHY_BASE +
  3465. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x059A);
  3466. mtk_spi_write(MIPI_RX_PHY_BASE +
  3467. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05A4);
  3468. mtk_spi_write(MIPI_RX_PHY_BASE +
  3469. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05AC);
  3470. mtk_spi_write(MIPI_RX_PHY_BASE +
  3471. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05B4);
  3472. mtk_spi_write(MIPI_RX_PHY_BASE +
  3473. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05BC);
  3474. mtk_spi_write(MIPI_RX_PHY_BASE +
  3475. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05C4);
  3476. mtk_spi_write(MIPI_RX_PHY_BASE +
  3477. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05CC);
  3478. mtk_spi_write(MIPI_RX_PHY_BASE +
  3479. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05D4);
  3480. mtk_spi_write(MIPI_RX_PHY_BASE +
  3481. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05DC);
  3482. mtk_spi_write(MIPI_RX_PHY_BASE +
  3483. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05E4);
  3484. mtk_spi_write(MIPI_RX_PHY_BASE +
  3485. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05EC);
  3486. mtk_spi_write(MIPI_RX_PHY_BASE +
  3487. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05F4);
  3488. mtk_spi_write(MIPI_RX_PHY_BASE +
  3489. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x05FC);
  3490. mtk_spi_write(MIPI_RX_PHY_BASE +
  3491. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0604);
  3492. mtk_spi_write(MIPI_RX_PHY_BASE +
  3493. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x060C);
  3494. mtk_spi_write(MIPI_RX_PHY_BASE +
  3495. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0614);
  3496. mtk_spi_write(MIPI_RX_PHY_BASE +
  3497. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x061C);
  3498. mtk_spi_write(MIPI_RX_PHY_BASE +
  3499. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0623);
  3500. mtk_spi_write(MIPI_RX_PHY_BASE +
  3501. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0629);
  3502. mtk_spi_write(MIPI_RX_PHY_BASE +
  3503. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0632);
  3504. mtk_spi_write(MIPI_RX_PHY_BASE +
  3505. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x063A);
  3506. mtk_spi_write(MIPI_RX_PHY_BASE +
  3507. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0645);
  3508. mtk_spi_write(MIPI_RX_PHY_BASE +
  3509. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x064A);
  3510. mtk_spi_write(MIPI_RX_PHY_BASE +
  3511. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0650);
  3512. mtk_spi_write(MIPI_RX_PHY_BASE +
  3513. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x065A);
  3514. mtk_spi_write(MIPI_RX_PHY_BASE +
  3515. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0665);
  3516. mtk_spi_write(MIPI_RX_PHY_BASE +
  3517. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0669);
  3518. mtk_spi_write(MIPI_RX_PHY_BASE +
  3519. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0672);
  3520. mtk_spi_write(MIPI_RX_PHY_BASE +
  3521. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x067A);
  3522. mtk_spi_write(MIPI_RX_PHY_BASE +
  3523. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0685);
  3524. mtk_spi_write(MIPI_RX_PHY_BASE +
  3525. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0689);
  3526. mtk_spi_write(MIPI_RX_PHY_BASE +
  3527. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0690);
  3528. mtk_spi_write(MIPI_RX_PHY_BASE +
  3529. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x069A);
  3530. mtk_spi_write(MIPI_RX_PHY_BASE +
  3531. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06A4);
  3532. mtk_spi_write(MIPI_RX_PHY_BASE +
  3533. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06AC);
  3534. mtk_spi_write(MIPI_RX_PHY_BASE +
  3535. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06B4);
  3536. mtk_spi_write(MIPI_RX_PHY_BASE +
  3537. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06BC);
  3538. mtk_spi_write(MIPI_RX_PHY_BASE +
  3539. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06C4);
  3540. mtk_spi_write(MIPI_RX_PHY_BASE +
  3541. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06CC);
  3542. mtk_spi_write(MIPI_RX_PHY_BASE +
  3543. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06D4);
  3544. mtk_spi_write(MIPI_RX_PHY_BASE +
  3545. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06DC);
  3546. mtk_spi_write(MIPI_RX_PHY_BASE +
  3547. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06E4);
  3548. mtk_spi_write(MIPI_RX_PHY_BASE +
  3549. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06EC);
  3550. mtk_spi_write(MIPI_RX_PHY_BASE +
  3551. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06F4);
  3552. mtk_spi_write(MIPI_RX_PHY_BASE +
  3553. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x06FC);
  3554. mtk_spi_write(MIPI_RX_PHY_BASE +
  3555. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0704);
  3556. mtk_spi_write(MIPI_RX_PHY_BASE +
  3557. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x070C);
  3558. mtk_spi_write(MIPI_RX_PHY_BASE +
  3559. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0714);
  3560. mtk_spi_write(MIPI_RX_PHY_BASE +
  3561. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x071C);
  3562. mtk_spi_write(MIPI_RX_PHY_BASE +
  3563. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0723);
  3564. mtk_spi_write(MIPI_RX_PHY_BASE +
  3565. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x072A);
  3566. mtk_spi_write(MIPI_RX_PHY_BASE +
  3567. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0730);
  3568. mtk_spi_write(MIPI_RX_PHY_BASE +
  3569. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x073A);
  3570. mtk_spi_write(MIPI_RX_PHY_BASE +
  3571. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0745);
  3572. mtk_spi_write(MIPI_RX_PHY_BASE +
  3573. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x074A);
  3574. mtk_spi_write(MIPI_RX_PHY_BASE +
  3575. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0750);
  3576. mtk_spi_write(MIPI_RX_PHY_BASE +
  3577. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x075A);
  3578. mtk_spi_write(MIPI_RX_PHY_BASE +
  3579. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0765);
  3580. mtk_spi_write(MIPI_RX_PHY_BASE +
  3581. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0769);
  3582. mtk_spi_write(MIPI_RX_PHY_BASE +
  3583. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0772);
  3584. mtk_spi_write(MIPI_RX_PHY_BASE +
  3585. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x077A);
  3586. mtk_spi_write(MIPI_RX_PHY_BASE +
  3587. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0785);
  3588. mtk_spi_write(MIPI_RX_PHY_BASE +
  3589. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0789);
  3590. mtk_spi_write(MIPI_RX_PHY_BASE +
  3591. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x0790);
  3592. mtk_spi_write(MIPI_RX_PHY_BASE +
  3593. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x079A);
  3594. mtk_spi_write(MIPI_RX_PHY_BASE +
  3595. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07A4);
  3596. mtk_spi_write(MIPI_RX_PHY_BASE +
  3597. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07AC);
  3598. mtk_spi_write(MIPI_RX_PHY_BASE +
  3599. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07B4);
  3600. mtk_spi_write(MIPI_RX_PHY_BASE +
  3601. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07BC);
  3602. mtk_spi_write(MIPI_RX_PHY_BASE +
  3603. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07C4);
  3604. mtk_spi_write(MIPI_RX_PHY_BASE +
  3605. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07CC);
  3606. mtk_spi_write(MIPI_RX_PHY_BASE +
  3607. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07D4);
  3608. mtk_spi_write(MIPI_RX_PHY_BASE +
  3609. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07DC);
  3610. mtk_spi_write(MIPI_RX_PHY_BASE +
  3611. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07E4);
  3612. mtk_spi_write(MIPI_RX_PHY_BASE +
  3613. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07EC);
  3614. mtk_spi_write(MIPI_RX_PHY_BASE +
  3615. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07F4);
  3616. mtk_spi_write(MIPI_RX_PHY_BASE +
  3617. CORE_DIG_COMMON_RW_DESKEW_FINE_MEM * 4, 0x07FC);
  3618. DISPFUNCEND();
  3619. }
  3620. /* for debug use */
  3621. void output_debug_signal(void)
  3622. {
  3623. #if 0
  3624. /* Mutex thread 0 remove mod_sof[1] */
  3625. mtk_spi_write(0x00025030, 0x0000001D);
  3626. /* Mutex thread 1 use IPI_VSYNC falling and mod_sof[1] */
  3627. mtk_spi_write(0x00025050, 0x00000002);
  3628. mtk_spi_write(0x0002504C, 0x0000004a);
  3629. mtk_spi_write(0x00025040, 0x00000001);
  3630. /* DSI DBG Setting */
  3631. mtk_spi_write(0x00021170, 0x00001001);
  3632. /* MM DBG Setting */
  3633. mtk_spi_write(0x00023300, 0x00000003);
  3634. mtk_spi_write(0x000231a8, 0x00000021);
  3635. /* DBGSYS Setting */
  3636. mtk_spi_write(0x000076d0, 0x00000001);
  3637. /* GPIO Mode */
  3638. mtk_spi_write(0x00007300, 0x77701111);
  3639. #endif
  3640. mtk_spi_write(0x00007310, 0x31111111);
  3641. }
  3642. int bdg_common_init(enum DISP_BDG_ENUM module,
  3643. disp_ddp_path_config *config, void *cmdq)
  3644. {
  3645. int ret = 0;
  3646. LCM_DSI_PARAMS *tx_params;
  3647. DISPSYS_REG = (struct BDG_DISPSYS_CONFIG_REGS *)
  3648. DISPSYS_BDG_MMSYS_CONFIG_BASE;
  3649. DSI2_REG = (struct BDG_MIPIDSI2_REGS *)
  3650. DISPSYS_BDG_MIPIDSI2_DEVICE_BASE;
  3651. SYS_REG = (struct BDG_SYSREG_CTRL_REGS *)
  3652. DISPSYS_BDG_SYSREG_CTRL_BASE;
  3653. RDMA_REG = (struct BDG_RDMA0_REGS *)
  3654. DISPSYS_BDG_RDMA0_REGS_BASE;
  3655. MUTEX_REG = (struct BDG_MUTEX_REGS *)
  3656. DISPSYS_BDG_MUTEX_REGS_BASE;
  3657. OCLA_REG = (struct BDG_OCLA_REGS *)
  3658. DISPSYS_BDG_OCLA_BASE;
  3659. TX_REG[0] = (struct BDG_TX_REGS *)
  3660. DISPSYS_BDG_TX_DSI0_BASE;
  3661. MIPI_TX_REG = (struct BDG_MIPI_TX_REGS *)
  3662. DISPSYS_BDG_MIPI_TX_BASE;
  3663. DSC_REG = (struct BDG_DISP_DSC_REGS *)
  3664. DISPSYS_BDG_DISP_DSC_BASE;
  3665. APMIXEDSYS = (struct BDG_APMIXEDSYS_REGS *)DISPSYS_BDG_APMIXEDSYS_BASE;
  3666. TOPCKGEN = (struct BDG_TOPCKGEN_REGS *)DISPSYS_BDG_TOPCKGEN_BASE;
  3667. GCE_REG = (struct BDG_GCE_REGS *)DISPSYS_BDG_GCE_BASE;
  3668. EFUSE = (struct BDG_EFUSE_REGS *)DISPSYS_BDG_EFUSE_BASE;
  3669. GPIO = (struct BDG_GPIO_REGS *)DISPSYS_BDG_GPIO_BASE;
  3670. TX_CMDQ_REG[0] =
  3671. (struct DSI_TX_CMDQ_REGS *)(DISPSYS_BDG_TX_DSI0_BASE + 0xd00);
  3672. DISPFUNCSTART();
  3673. bdg_tx_pull_6382_reset_pin();
  3674. bdg_is_bdg_connected();
  3675. spislv_init();
  3676. spislv_switch_speed_hz(SPI_TX_LOW_SPEED_HZ,
  3677. SPI_RX_LOW_SPEED_HZ);
  3678. set_LDO_on(cmdq);
  3679. set_mtcmos_on(cmdq);
  3680. ana_macro_on(cmdq);
  3681. set_subsys_on(cmdq);
  3682. spislv_switch_speed_hz(SPI_TX_MAX_SPEED_HZ, SPI_RX_MAX_SPEED_HZ);
  3683. /* Disable reset sequential de-glitch circuit */
  3684. DSI_OUTREG32(cmdq, SYS_REG->RST_DG_CTRL, 0);
  3685. /* Set GPIO to active IRQ */
  3686. mtk_spi_mask_write((u32)(DISPSYS_BDG_GPIO_BASE +
  3687. REG_GPIO_MODE1),
  3688. GPIO_MODE1_FLD_GPIO12, 1);
  3689. tx_params = &(config->dsi_config);
  3690. /* clear CG */
  3691. DSI_OUTREG32(cmdq, DISPSYS_REG->MMSYS_CG_CON0, 0);
  3692. /* for release rx mac reset */
  3693. DSI_OUTREG32(cmdq, SYS_REG->DISP_MISC0, 1);
  3694. DSI_OUTREG32(cmdq, SYS_REG->DISP_MISC0, 0);
  3695. /* switch DDI(cmd mode) or IPI(vdo mode) path */
  3696. DSI_OUTREG32(cmdq, DISPSYS_REG->MIPI_RX_POST_CTRL, 0x00001100);
  3697. if (tx_params->mode == CMD_MODE) {
  3698. mtk_spi_mask_write(
  3699. (u32)(DISPSYS_BDG_GPIO_BASE + REG_GPIO_MODE1),
  3700. REG_GPIO_MODE1_FIELD_RSV_24, 0x31);
  3701. mtk_spi_mask_write((u32)(DISPSYS_BDG_MMSYS_CONFIG_BASE +
  3702. REG_MIPI_RX_POST_CTRL),
  3703. MIPI_RX_POST_CTRL_FLD_MIPI_RX_MODE_SEL, 0);
  3704. }
  3705. else
  3706. mtk_spi_mask_write((u32)(DISPSYS_BDG_MMSYS_CONFIG_BASE +
  3707. REG_MIPI_RX_POST_CTRL),
  3708. MIPI_RX_POST_CTRL_FLD_MIPI_RX_MODE_SEL, 1);
  3709. /* RDMA setting */
  3710. DSI_OUTREG32(cmdq, RDMA_REG->DISP_RDMA_SIZE_CON_0,
  3711. tx_params->horizontal_active_pixel);
  3712. DSI_OUTREG32(cmdq, RDMA_REG->DISP_RDMA_SIZE_CON_1,
  3713. tx_params->vertical_active_line);
  3714. DSI_OUTREG32(cmdq, RDMA_REG->DISP_RDMA_FIFO_CON, 0xf30 << 16);
  3715. DSI_OUTREG32(cmdq, RDMA_REG->DISP_RDMA_STALL_CG_CON, 0);
  3716. mtk_spi_mask_write((u32)(DISPSYS_BDG_RDMA0_REGS_BASE +
  3717. REG_DISP_RDMA_SRAM_SEL),
  3718. DISP_RDMA_SRAM_SEL_FLD_RDMA_SRAM_SEL, 0);
  3719. mtk_spi_mask_write((u32)(DISPSYS_BDG_RDMA0_REGS_BASE +
  3720. REG_DISP_RDMA_GLOBAL_CON),
  3721. DISP_RDMA_GLOBAL_CON_FLD_ENGINE_EN, 1);
  3722. /* MUTEX setting */
  3723. DSI_OUTREG32(cmdq, MUTEX_REG->BDG_TX_DISP_MUTEX_INTEN, 0x1 << 16);
  3724. DSI_OUTREG32(cmdq, MUTEX_REG->BDG_TX_DISP_MUTEX0_MOD0, 0x1f);
  3725. if (tx_params->mode == CMD_MODE)
  3726. DSI_OUTREG32(cmdq, MUTEX_REG->BDG_TX_DISP_MUTEX0_CTL, 0);
  3727. else {
  3728. DSI_OUTREG32(cmdq, MUTEX_REG->BDG_TX_DISP_MUTEX0_CTL,
  3729. 0x1 << 0 | 0x0 << 3 | 0x1 << 6 | 0x0 << 9);
  3730. mtk_spi_mask_write((u32)(DISPSYS_BDG_MUTEX_REGS_BASE +
  3731. REG_BDG_TX_DISP_MUTEX0_EN),
  3732. BDG_TX_DISP_MUTEX0_EN_FLD_MUTEX0_EN, 1);
  3733. }
  3734. /* DSI-TX setting */
  3735. bdg_tx_init(module, config, NULL);
  3736. DSI_OUTREG32(cmdq, TX_REG[0]->DSI_RESYNC_CON, 0x50007);
  3737. /* DSC setting */
  3738. if (dsc_en) {
  3739. bdg_dsc_init(module, cmdq, tx_params);
  3740. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  3741. REG_DISP_DSC_CON),
  3742. DISP_DSC_CON_FLD_DSC_PT_MEM_EN, 1);
  3743. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  3744. REG_DISP_DSC_CON),
  3745. DISP_DSC_CON_FLD_DSC_EN, 1);
  3746. } else {
  3747. #ifdef DSC_RELAY_MODE_EN
  3748. bdg_dsc_init(module, cmdq, tx_params);
  3749. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  3750. REG_DISP_DSC_CON),
  3751. DISP_DSC_CON_FLD_DSC_PT_MEM_EN, 1);
  3752. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  3753. REG_DISP_DSC_CON),
  3754. DISP_DSC_CON_FLD_DSC_RELAY, 1);
  3755. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  3756. REG_DISP_DSC_CON),
  3757. DISP_DSC_CON_FLD_DSC_EN, 1);
  3758. #else
  3759. mtk_spi_mask_write((u32)(DISPSYS_BDG_DISP_DSC_BASE +
  3760. REG_DISP_DSC_CON),
  3761. DISP_DSC_CON_FLD_DSC_ALL_BYPASS, 1);
  3762. #endif
  3763. }
  3764. calculate_datarate_cfgs_rx(ap_tx_data_rate);
  3765. startup_seq_common(cmdq);
  3766. startup_seq_dphy_specific(ap_tx_data_rate);
  3767. output_debug_signal();
  3768. /*TODO: Fix TARGET line*/
  3769. DSI_OUTREG32(cmdq, TX_REG[0]->DSI_TARGET_NL, 0x7d0);
  3770. DSI_OUTREG32(cmdq, DISPSYS_REG->TE_OUT_CON, 0x2e);
  3771. DISPFUNCEND();
  3772. return ret;
  3773. }
  3774. int bdg_common_deinit(enum DISP_BDG_ENUM module, void *cmdq)
  3775. {
  3776. int ret = 0;
  3777. DISPFUNCSTART();
  3778. spislv_switch_speed_hz(SPI_TX_LOW_SPEED_HZ, SPI_RX_LOW_SPEED_HZ);
  3779. set_ana_mipi_dsi_off(cmdq);
  3780. ana_macro_off(cmdq);
  3781. set_mtcmos_off(cmdq);
  3782. set_LDO_off(cmdq);
  3783. clk_buf_disp_ctrl(false);
  3784. mt6382_init = 0;
  3785. DISPFUNCEND();
  3786. return ret;
  3787. }