hdmirx_hw.c 172 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324
  1. /*
  2. * Amlogic M2
  3. * HDMI RX
  4. * Copyright (C) 2010 Amlogic, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the named License,
  9. * or any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/version.h>
  18. #include <linux/module.h>
  19. #include <linux/types.h>
  20. #include <linux/kernel.h>
  21. #include <linux/kthread.h>
  22. #include <linux/delay.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/fs.h>
  25. #include <linux/init.h>
  26. #include <linux/device.h>
  27. #include <linux/mm.h>
  28. #include <linux/major.h>
  29. #include <linux/platform_device.h>
  30. #include <linux/mutex.h>
  31. #include <linux/cdev.h>
  32. //#include <linux/amports/canvas.h>
  33. #include <asm/uaccess.h>
  34. #include <asm/delay.h>
  35. #include <mach/am_regs.h>
  36. #include <mach/power_gate.h>
  37. #include <linux/tvin/tvin.h>
  38. /* Local include */
  39. #include "hdmirx.h"
  40. #include "hdmi_regs.h"
  41. #include "hdmirx_cec.h"
  42. //#define FIFO_ENABLE_AFTER_RESET
  43. #undef FIFO_ENABLE_AFTER_RESET
  44. #undef FIFO_BYPASS
  45. #undef HDMIRX_WITH_IRQ
  46. #define RESET_AFTER_CLK_STABLE
  47. #ifdef RESET_AFTER_CLK_STABLE
  48. static unsigned char reset_flag = 0;
  49. static unsigned char reset_mode = 0;
  50. #endif
  51. #define FOR_LS_DIG2090__DVP_5986K
  52. #undef HPD_AUTO_MODE
  53. #define HW_MONITOR_TIME_UNIT (1000/HDMI_STATE_CHECK_FREQ)
  54. /* parameters begin*/
  55. int hdmirx_log_flag = 0x1;
  56. static int sm_pause = 0;
  57. static int force_vic = 0;
  58. static int audio_enable = 1;
  59. static int eq_enable = 1;
  60. static int eq_config = 0x7;
  61. static int signal_check_mode = 0xb; /*new config 0xb, check if have_avi_info; old config 7, check vic=0 */;
  62. static int signal_recover_mode = 1; /*0x1, reset for all case ; 0x31, not reset for case of "VIC=0" */
  63. static int switch_mode = 0;
  64. static int edid_mode = 0; /*for internal edid, 0, 8 bit mode; 1, deep color mode */
  65. static int dvi_mode = 0;
  66. static int color_format_mode = 0; /* output color format: 0=RGB444; 1=YCbCr444; 2=Rsrv; 3=YCbCr422; other same as input color format */
  67. static int check_color_depth_mode = 0;
  68. /*ms*/
  69. static int delay1 = 20; //100;
  70. static int delay2 = 20; //100;
  71. static int delay3 = 200; //500;
  72. static int delay4 = 500; //1000;
  73. static int hpd_ready_time = 200;
  74. static int hpd_start_time = 0;
  75. static int audio_stable_time = 1000;
  76. static int vendor_specific_info_check_period = 500;
  77. /**/
  78. static int clk_stable_threshold = 20;
  79. static int clk_unstable_threshold = 3;
  80. static int reset_threshold = HDMI_STATE_CHECK_FREQ;
  81. static int audio_sample_rate_stable_count_th = 15; //4;
  82. static int audio_channel_status_stable_th = 4;
  83. static int dvi_detect_wait_avi_th = 3*HDMI_STATE_CHECK_FREQ;
  84. static int general_detect_wait_avi_th = 8*HDMI_STATE_CHECK_FREQ;
  85. static int audio_check_period = 200; //ms
  86. static int aud_channel_status_modify_th = 5;
  87. static int aud_channel_status_all_0_th = 0; //set it to 0 to disable it, as if it is 5 , for some normal case, this condition will also be triggered //5;
  88. static int sample_rate_change_th = 100;
  89. static int powerdown_enable = 0;
  90. static int skip_unstable_frame = 0;
  91. static int eq_mode = 0;
  92. static int eq_mode_max = 4;
  93. /*
  94. internal_mode:
  95. bit [15:0] reserved for internal flag
  96. bit[0]: 1, support full format; 0, support basic format
  97. bit[1]: 1, disable active_lines check
  98. bit[2]: 0, use audio_recover_clock as sample_rate; 1, use sample_rate from "audio info frame" or "channel status bits"
  99. bit [30:16] check value, should be 0x3456
  100. bit [31] not used
  101. */
  102. #define INT_MODE_FULL_FORMAT 0x1
  103. #define INT_MODE_DISABLE_LINES_CHECK 0x2
  104. #define INT_MODE_USE_AUD_INFO_FRAME 0x4
  105. static int internal_mode = 0;
  106. /* bit 0~3, for port 0; bit 4~7 for port 1, bit 8~11 for port 2: 0xf=disable; 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 31 */
  107. unsigned prbs_port_mode = 0xffffffff;
  108. int prbs_check_count = 0;
  109. int prbs_ch1_err_num = 0;
  110. int prbs_ch2_err_num = 0;
  111. int prbs_ch3_err_num = 0;
  112. /*parameters end*/
  113. static int test_flag = 0;
  114. static int msr_par1=23, msr_par2=50; //hdmi_pixel_clk
  115. #define OTHER_CLK_INDEX 12
  116. static unsigned long clk_util_clk_msr( unsigned long clk_mux, unsigned long uS_gate_time );
  117. static int eq_mode_monitor(void);
  118. static int internal_mode_monitor(void);
  119. static unsigned char internal_mode_valid(void);
  120. #define TMDS_CLK_FACTOR 91541
  121. #define TMDS_CLK(measure_value) (measure_value*TMDS_CLK_FACTOR/1000000)
  122. #define PIXEL_CLK ((int)clk_util_clk_msr(msr_par1,msr_par2))
  123. /****************
  124. * register write/read
  125. *
  126. ***************/
  127. #define Wr(reg,val) WRITE_MPEG_REG(reg,val)
  128. #define Rd(reg) READ_MPEG_REG(reg)
  129. #define Wr_reg_bits(reg, val, start, len) \
  130. Wr(reg, (Rd(reg) & ~(((1L<<(len))-1)<<(start)))|((unsigned int)(val) << (start)))
  131. static void hdmi_wr_reg(unsigned long addr, unsigned long data);
  132. static void hdmi_wr_only_reg(unsigned long addr, unsigned long data);
  133. static unsigned int hdmi_rd_reg(unsigned long addr);
  134. #if 1
  135. #define HDMIRX_HW_LOG hdmirx_print
  136. #else
  137. int HDMIRX_HW_LOG(const char *fmt, ...)
  138. {
  139. va_list args;
  140. if(hdmirx_log_flag&1){
  141. va_start(args, fmt);
  142. vprintk(fmt, args);
  143. va_end(args);
  144. }
  145. return 0;
  146. }
  147. #endif
  148. static unsigned int hdmi_rd_reg(unsigned long addr)
  149. {
  150. unsigned long data;
  151. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  152. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  153. data = READ_APB_REG(HDMI_DATA_PORT);
  154. return (data);
  155. }
  156. static void hdmi_wr_only_reg(unsigned long addr, unsigned long data)
  157. {
  158. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  159. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  160. WRITE_APB_REG(HDMI_DATA_PORT, data);
  161. }
  162. static void hdmi_wr_reg(unsigned long addr, unsigned long data)
  163. {
  164. unsigned long rd_data;
  165. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  166. WRITE_APB_REG(HDMI_ADDR_PORT, addr);
  167. WRITE_APB_REG(HDMI_DATA_PORT, data);
  168. rd_data = hdmi_rd_reg (addr);
  169. if (rd_data != data)
  170. {
  171. //while(1){};
  172. }
  173. }
  174. static unsigned int hdmi_wr_only_reg_bits(unsigned long addr, unsigned long val, unsigned int start, unsigned int len)
  175. {
  176. unsigned int data;
  177. data = hdmi_rd_reg(addr);
  178. data &= (~(((1<<len)-1)<<start));
  179. data |= ((val & ((1<<len)-1)) << start);
  180. hdmi_wr_reg(addr, data);
  181. return (data);
  182. }
  183. static void hdmi_wr_reg_bits(unsigned long addr, unsigned long val, unsigned int start, unsigned int len)
  184. {
  185. unsigned long exp_data, act_data;
  186. exp_data = hdmi_wr_only_reg_bits(addr, val, start, len);
  187. act_data = hdmi_rd_reg (addr);
  188. if (exp_data != act_data)
  189. {
  190. printk("Error: (addr) ");
  191. }
  192. }
  193. /*
  194. static void hdmi_rd_check_reg(unsigned long addr, unsigned long exp_data, unsigned long mask)
  195. {
  196. unsigned long rd_data;
  197. rd_data = hdmi_rd_reg(addr);
  198. if ((rd_data | mask) != (exp_data | mask))
  199. {
  200. printk("Error: addr %x, rd_data %x, exp_data %x, mask %x\n", addr, rd_data, exp_data, mask);
  201. }
  202. }*/
  203. /****************
  204. * init function
  205. *
  206. ***************/
  207. //static DEFINE_SPINLOCK(hdmi_print_lock);
  208. //#define RX_INPUT_COLOR_DEPTH 1 // Pixel bit width: 0=24-bit; 1=30-bit; 2=36-bit; 3=48-bit.
  209. #define RX_INPUT_COLOR_DEPTH 0 // Pixel bit width: 0=24-bit; 1=30-bit; 2=36-bit; 3=48-bit.
  210. //#define RX_OUTPUT_COLOR_DEPTH 1 // Pixel bit width: 0=24-bit; 1=30-bit; 2=36-bit; 3=48-bit.
  211. #define RX_OUTPUT_COLOR_DEPTH 0 // Pixel bit width: 0=24-bit; 1=30-bit; 2=36-bit; 3=48-bit.
  212. #define RX_INPUT_COLOR_FORMAT 0 // Pixel format: 0=RGB444; 1=YCbCr444; 2=Rsrv; 3=YCbCr422.
  213. //#define RX_OUTPUT_COLOR_FORMAT 1 // Pixel format: 0=RGB444; 1=YCbCr444; 2=Rsrv; 3=YCbCr422.
  214. #define RX_OUTPUT_COLOR_FORMAT 0 // Pixel format: 0=RGB444; 1=YCbCr444; 2=Rsrv; 3=YCbCr422.
  215. #define RX_INPUT_COLOR_RANGE 0 // Pixel range: 0=16-235/240; 1=16-240; 2=1-254; 3=0-255.
  216. #define RX_OUTPUT_COLOR_RANGE 0 // Pixel range: 0=16-235/240; 1=16-240; 2=1-254; 3=0-255.
  217. #define RX_I2S_SPDIF 1 // 0=SPDIF; 1=I2S.
  218. #define RX_I2S_8_CHANNEL 0 // 0=I2S 2-channel; 1=I2S 4 x 2-channel.
  219. // For Audio Clock Recovery
  220. #define ACR_CONTROL_EXT 1 // Select which ACR scheme:
  221. // 0=Old ACR that is partly inside hdmi_rx_core, and partly outside;
  222. // 1=New ACR that is entirely outside hdmi_rx_core, under hdmi_rx_top.
  223. #define ACR_MODE 3 // Select input clock for either old or new ACR module:
  224. // 0=idle; 1=external oscillator;
  225. // 2=internal oscillator, fast; 3=internal oscillator, slow.
  226. #define AUDIN_FIFO_DIN_SOURCE 1 // Select whose decoded data are to be the input of AUDIN FIFO:
  227. // 0=Use the original SPDIF decoder;
  228. // 1=Use the original I2S decoder;
  229. // 2=Use the new audio decoder which can decode either SPDIF or I2S.
  230. // E.g. If RX_I2S_SPDIF=0, use either 0 or 2; If RX_I2S_SPDIF=1, use either 1 or 2.
  231. // HDCP keys from Efuse are encrypted by default, in this test HDCP keys are written by CPU with encryption manually added
  232. #define ENCRYPT_KEY 0xbe
  233. //#define ENCRYPT_KEY 0
  234. static void hdmi_init(void);
  235. static void hdmirx_phy_init(void);
  236. static void set_eq_27M(int idx1, int idx2);
  237. static void set_eq_27M_2(void);
  238. static void restore_eq_gen(void);
  239. static void hdmirx_reset_clock(void);
  240. static void hdmirx_audio_recover_reset(void);
  241. static void hdmirx_reset_digital(void);
  242. static void hdmirx_reset_pixel_clock(void);
  243. static void hdmirx_unpack_recover(void);
  244. static void hdmirx_release_audio_reset(void);
  245. static unsigned char have_avi_info(void);
  246. void task_rx_edid_setting(void);
  247. //static void hdmi_tx_hpd_detect(void);
  248. //static void hdmirx_monitor_reg_init(void);
  249. static void set_hdmi_audio_source_gate(unsigned char);
  250. //static void hdmirx_monitor_clock(void);
  251. //static void hdimrx_monitor_register(void);
  252. void task_rx_key_setting(void);
  253. static unsigned char is_frame_packing(void);
  254. #define DUMP_FLAG_VIDEO_TIMING 0x1
  255. #define DUMP_FLAG_AVI_INFO 0x2
  256. #define DUMP_FLAG_VENDOR_SPEC_INFO 0x4
  257. #define DUMP_FLAG_AUDIO_INFO 0x8
  258. #define DUMP_FLAG_CLOCK_INFO 0x10
  259. #define DUMP_FLAG_ECC_STATUS 0x20
  260. static void dump_state(unsigned int dump_flag);
  261. #define CC_ITU601 1
  262. #define CC_ITU709 2
  263. // -----------------------------------------------
  264. // Global variables
  265. // -----------------------------------------------
  266. //static int monitor_register(void *data);
  267. // Convertion: RGB_YUV mapping is different from HDMI spec's AVI infoFrame mapping
  268. #define conv_color_format_to_spec_value(a) (((a)==0)? 0 : (((a)==1)? 2 : (((a)==2)? 3 : 1)))
  269. #define conv_color_format_to_rtl_value(a) (((a)==0)? 0 : (((a)==1)? 3 : (((a)==2)? 1 : 2)))
  270. #define HDMIRX_HWSTATE_5V_LOW 0
  271. #define HDMIRX_HWSTATE_5V_HIGH 1
  272. #define HDMIRX_HWSTATE_HPD_READY 2
  273. #define HDMIRX_HWSTATE_SIG_UNSTABLE 3
  274. #define HDMIRX_HWSTATE_SIG_STABLE 4
  275. #define HDMIRX_HWSTATE_INIT 5
  276. struct video_status_s{
  277. unsigned int active_pixels;
  278. unsigned int front_pixels;
  279. unsigned int hsync_pixels;
  280. unsigned int back_pixels;
  281. unsigned int active_lines;
  282. unsigned int eof_lines;
  283. unsigned int vsync_lines;
  284. unsigned int sof_lines;
  285. unsigned char video_scan; /* 0, progressive; 1, interlaced */
  286. unsigned char video_field; /* progressive:0; interlace: 0, 1st; 1, 2nd */
  287. /**/
  288. unsigned char scan_stable; /* 0, not stable; 1, stable */
  289. unsigned char lines_stable;
  290. unsigned char vsync_stable;
  291. unsigned char pixels_stable;
  292. unsigned char hsync_stable;
  293. /**/
  294. unsigned char default_phase;
  295. unsigned char pixel_phase;
  296. unsigned char pixel_phase_ok;
  297. unsigned char gc_error; /* 0, no error; 1, error in packet data */
  298. unsigned char color_depth; /* 0, 24bit; 1, 30bit; 2, 36 bit; 3, 48 bit */
  299. };
  300. struct avi_info_s{
  301. unsigned int vic;
  302. unsigned int pixel_repeat;
  303. unsigned int color_format;
  304. unsigned int color_range;
  305. unsigned int cc;
  306. };
  307. #define CHANNEL_STATUS_SIZE 24
  308. struct aud_info_s{
  309. /* info frame*/
  310. unsigned char cc;
  311. unsigned char ct;
  312. unsigned char ss;
  313. unsigned char sf;
  314. /* channel status */
  315. unsigned char channel_status[CHANNEL_STATUS_SIZE];
  316. unsigned char channel_status_bak[CHANNEL_STATUS_SIZE];
  317. /**/
  318. unsigned int cts;
  319. unsigned int n;
  320. unsigned int audio_recovery_clock;
  321. /**/
  322. int channel_num;
  323. int sample_rate;
  324. int sample_size;
  325. int real_sample_rate;
  326. };
  327. struct vendor_specific_info_s{
  328. unsigned identifier;
  329. unsigned char hdmi_video_format;
  330. unsigned char _3d_structure;
  331. unsigned char _3d_ext_data;
  332. };
  333. #define TMDS_CLK_HIS_SIZE 32
  334. typedef struct hdmirx_hw_stru_{
  335. unsigned int vendor_specific_info_check_time;
  336. unsigned int clock_monitor_time;
  337. int hpd_wait_time;
  338. int audio_wait_time;
  339. int audio_sample_rate_stable_count;
  340. unsigned int audio_reset_release_flag;
  341. unsigned int phy_init_flag;
  342. unsigned int state;
  343. unsigned int clk_stable_count;
  344. /**/
  345. unsigned int port; /*1, 2, 4 */
  346. unsigned int cur_pixel_repeat;
  347. unsigned int cur_vic;
  348. unsigned int guess_vic;
  349. unsigned int cur_color_format; /* ouput color format*/
  350. unsigned int cur_color_depth;
  351. unsigned int tmds_clk[TMDS_CLK_HIS_SIZE];
  352. unsigned int pixel_clock;
  353. unsigned int unstable_irq_count;
  354. struct video_status_s video_status;
  355. struct video_status_s video_status_pre;
  356. struct avi_info_s avi_info;
  357. struct avi_info_s avi_info_pre;
  358. struct aud_info_s aud_info;
  359. #ifdef FOR_LS_DIG2090__DVP_5986K
  360. int audio_check_time;
  361. int aud_channel_status_modify_count;
  362. int aud_channel_status_unmodify_count;
  363. int aud_channel_status_all_0_count;
  364. int aud_buf_ptr_change_count;
  365. int aud_ok_flag;
  366. #endif
  367. struct vendor_specific_info_s vendor_specific_info;
  368. struct vendor_specific_info_s vendor_specific_info_pre;
  369. unsigned int avi_info_change_flag;
  370. unsigned char cur_eq_mode;
  371. unsigned int cur_internal_mode;
  372. /**/
  373. int prbs_check_wait_time;
  374. unsigned char prbs_enable;
  375. unsigned char prbs_mode;
  376. }hdmirx_hw_stru_t;
  377. static hdmirx_hw_stru_t hdmirx_hw_stru;
  378. unsigned int hdmirx_get_cur_vic(void)
  379. {
  380. if(force_vic){
  381. return force_vic;
  382. }
  383. else if(hdmirx_hw_stru.cur_vic == 0){
  384. return hdmirx_hw_stru.guess_vic;
  385. }
  386. return hdmirx_hw_stru.cur_vic;
  387. }
  388. #ifdef HDMIRX_WITH_IRQ
  389. static irqreturn_t intr_handler(int irq, void *dev_instance)
  390. {
  391. unsigned int data32;
  392. data32 = hdmi_rd_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT);
  393. //printk("[HDMIRX Irq] Interrupt status %x\n", data32);
  394. if (data32 & (1<< 8)) {
  395. if(hdmirx_log_flag&0x10000)
  396. HDMIRX_HW_LOG("[HDMIRX Irq] HDMI VIC Change Interrupt Process_Irq\n");
  397. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 1 << 8);
  398. }
  399. if (data32 & (1 << 9)) { // COLOR_DEPTH
  400. if(hdmirx_log_flag&0x10000)
  401. HDMIRX_HW_LOG("[HDMIRX Irq] HDMI RX COLOR_DEPTH Interrupt Process_Irq\n");
  402. //clear COLOR_DEPTH interrupt in hdmi rx
  403. hdmi_wr_only_reg_bits(RX_VIC_COLOR_DEPTH, 1, 5, 1);
  404. hdmi_wr_only_reg_bits(RX_VIC_COLOR_DEPTH, 0, 5, 1);
  405. //clear COLOR_DEPTH interrupt in hdmi top module
  406. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 1 << 9);
  407. } /* COLOR_DEPTH */
  408. if (data32 & (1 << 10)) { // TMDS_CLK_UNSTABLE
  409. //printk("[HDMIRX Irq] Error: HDMI TMDS_CLK_UNSTABLE Interrupt Process_Irq\n");
  410. //clear TMDS_CLK_UNSTABLE interrupt in hdmi top module
  411. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 1 << 10);
  412. hdmirx_hw_stru.unstable_irq_count++;
  413. } /* TMDS_CLK_UNSTABLE */
  414. if (data32 & (1 << 11)) { // EDID_ADDR
  415. if(hdmirx_log_flag&0x10000)
  416. HDMIRX_HW_LOG("[HDMIRX Irq] HDMI EDID_ADDR Interrupt Process_Irq\n");
  417. //clear EDID_ADDR interrupt in hdmi rx
  418. hdmi_wr_only_reg_bits(RX_HDCP_EDID_CONFIG, 1, 1, 1);
  419. hdmi_wr_only_reg_bits(RX_HDCP_EDID_CONFIG, 0, 1, 1);
  420. //clear EDID_ADDR interrupt in hdmi top module
  421. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 1 << 11);
  422. } /* EDID_ADDR */
  423. if (data32 & (1 << 12)) { // AVMUTE_UPDATE
  424. if(hdmirx_log_flag&0x10000)
  425. HDMIRX_HW_LOG("[HDMIRX Irq] HDMI AVMUTE_UPDATE Interrupt Process_Irq\n");
  426. //clear AVMUTE_UPDATE interrupt in hdmi rx
  427. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_PACKET_INTR_CLR, 1 << 0);
  428. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_PACKET_INTR_CLR, 0);
  429. //clear AVMUTE_UPDATE interrupt in hdmi top module
  430. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 1 << 12);
  431. } /* AVMUTE_UPDATE */
  432. if (data32 & (1 << 13)) { // AVI_UPDATE
  433. if(hdmirx_log_flag&0x10000)
  434. HDMIRX_HW_LOG("[HDMIRX Irq] HDMI AVI_UPDATE Interrupt Process_Irq\n");
  435. //clear AVI_UPDATE interrupt in hdmi rx
  436. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_PACKET_INTR_CLR, 1 << 1);
  437. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_PACKET_INTR_CLR, 0);
  438. //clear AVI_UPDATE interrupt in hdmi top module
  439. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 1 << 13);
  440. } /* AVI_UPDATE */
  441. if (data32 & (1 << 14)) { // AUDIO_INFO_UPDATE
  442. if(hdmirx_log_flag&0x10000)
  443. HDMIRX_HW_LOG("[HDMIRX Irq] HDMI AUDIO_INFO_UPDATE Interrupt Process_Irq\n");
  444. //clear AUDIO_INFO_UPDATE interrupt in hdmi rx
  445. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_PACKET_INTR_CLR, 1 << 2);
  446. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_PACKET_INTR_CLR, 0);
  447. //clear AUDIO_INFO_UPDATE interrupt in hdmi top module
  448. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 1 << 14);
  449. } /* AUDIO_INFO_UPDATE */
  450. if (data32 & (7 << 15)) { // RX_5V_RISE
  451. if(hdmirx_log_flag&0x10000)
  452. HDMIRX_HW_LOG("[HDMIRX Irq] HDMI RX_5V_RISE Interrupt Process_Irq\n");
  453. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 7 << 15); //clear RX_5V_RISE interrupt in hdmi top module
  454. } /* RX_5V_RISE */
  455. if (data32 & (7 << 18)) { // RX_5V_FALL
  456. if(hdmirx_log_flag&0x10000)
  457. HDMIRX_HW_LOG("[HDMIRX Irq] Error: HDMI RX_5V_FALL Interrupt Process_Irq\n");
  458. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, 7 << 18); //clear RX_5V_FALL interrupt in hdmi top module
  459. } /* RX_5V_FALL */
  460. if (data32 & ~(0x1fff00)) {
  461. if(hdmirx_log_flag&0x10000)
  462. HDMIRX_HW_LOG("[HDMIRX Irq] Error: Unkown HDMI RX Interrupt source Process_Irq\n");
  463. hdmi_wr_only_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_STAT_CLR, data32); //clear unkown interrupt in hdmi top module
  464. }
  465. Wr(A9_0_IRQ_IN1_INTR_STAT_CLR, 1 << 24); //clear hdmi_rx interrupt
  466. return IRQ_HANDLED;
  467. }
  468. static void hdmirx_setupirq(void)
  469. {
  470. int r;
  471. r = request_irq(INT_HDMI_RX, &intr_handler,
  472. IRQF_SHARED, "amhdmirx",
  473. (void *)"amhdmirx");
  474. Rd(A9_0_IRQ_IN1_INTR_STAT_CLR);
  475. Wr(A9_0_IRQ_IN1_INTR_MASK, Rd(A9_0_IRQ_IN1_INTR_MASK)|(1 << 24));
  476. }
  477. #endif
  478. static void hdmi_rx_prbs_init(unsigned int prbs_mode)
  479. {
  480. unsigned int tmp_add_data;
  481. // PRBS control
  482. tmp_add_data = 0;
  483. tmp_add_data |= prbs_mode << 6; // [7:6] hdmi_prbs_ana_i0.prbs_mode[1:0]. 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 32.
  484. tmp_add_data |= 3 << 4; // [5:4] hdmi_prbs_ana_i0.mode[1:0]
  485. tmp_add_data |= 0 << 3; // [3] hdmi_prbs_ana_i0.clr_ber_meter
  486. tmp_add_data |= 0 << 2; // [2] hdmi_prbs_ana_i0.freeze_ber
  487. tmp_add_data |= 0 << 1; // [1] hdmi_prbs_ana_i0.inverse_in
  488. tmp_add_data |= 0 << 0; // [0] hdmi_prbs_ana_i0.Rsrv
  489. hdmi_wr_reg(RX_SYS2_PRBS0_CNTRL, tmp_add_data);
  490. tmp_add_data = 0;
  491. tmp_add_data |= prbs_mode << 6; // [7:6] hdmi_prbs_ana_i1.prbs_mode[1:0]. 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 32.
  492. tmp_add_data |= 3 << 4; // [5:4] hdmi_prbs_ana_i1.mode[1:0]
  493. tmp_add_data |= 0 << 3; // [3] hdmi_prbs_ana_i1.clr_ber_meter
  494. tmp_add_data |= 0 << 2; // [2] hdmi_prbs_ana_i1.freeze_ber
  495. tmp_add_data |= 1 << 1; // [1] hdmi_prbs_ana_i1.inverse_in
  496. tmp_add_data |= 0 << 0; // [0] hdmi_prbs_ana_i1.Rsrv
  497. hdmi_wr_reg(RX_SYS2_PRBS1_CNTRL, tmp_add_data);
  498. tmp_add_data = 0;
  499. tmp_add_data |= prbs_mode << 6; // [7:6] hdmi_prbs_ana_i2.prbs_mode[1:0]. 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 32.
  500. tmp_add_data |= 3 << 4; // [5:4] hdmi_prbs_ana_i2.mode[1:0]
  501. tmp_add_data |= 0 << 3; // [3] hdmi_prbs_ana_i2.clr_ber_meter
  502. tmp_add_data |= 0 << 2; // [2] hdmi_prbs_ana_i2.freeze_ber
  503. tmp_add_data |= 1 << 1; // [1] hdmi_prbs_ana_i2.inverse_in
  504. tmp_add_data |= 0 << 0; // [0] hdmi_prbs_ana_i2.Rsrv
  505. hdmi_wr_reg(RX_SYS2_PRBS2_CNTRL, tmp_add_data);
  506. tmp_add_data = 0;
  507. tmp_add_data |= prbs_mode << 6; // [7:6] hdmi_prbs_ana_i3.prbs_mode[1:0]. 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 32.
  508. tmp_add_data |= 3 << 4; // [5:4] hdmi_prbs_ana_i3.mode[1:0]
  509. tmp_add_data |= 0 << 3; // [3] hdmi_prbs_ana_i3.clr_ber_meter
  510. tmp_add_data |= 0 << 2; // [2] hdmi_prbs_ana_i3.freeze_ber
  511. tmp_add_data |= 1 << 1; // [1] hdmi_prbs_ana_i3.inverse_in
  512. tmp_add_data |= 0 << 0; // [0] hdmi_prbs_ana_i3.Rsrv
  513. hdmi_wr_reg(RX_SYS2_PRBS3_CNTRL, tmp_add_data);
  514. hdmi_wr_reg(RX_SYS2_PRBS_ERR_THR, 0x00); // prbs_err_thr[7:0]
  515. hdmi_wr_reg(RX_SYS2_PRBS_TIME_WINDOW0, 0xff); // prbs_time_window[7:0]
  516. } /* hdmi_rx_prbs_init */
  517. static void turn_on_prbs_mode(int prbs_mode)
  518. {
  519. hdmirx_hw_stru.prbs_mode = prbs_mode;
  520. /* reset tmds_config */
  521. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(1<<6));
  522. mdelay(10);
  523. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(1<<6)));
  524. /**/
  525. hdmi_rx_prbs_init(hdmirx_hw_stru.prbs_mode);
  526. mdelay(10);
  527. prbs_ch1_err_num = 0;
  528. prbs_ch2_err_num = 0;
  529. prbs_ch3_err_num = 0;
  530. prbs_check_count = 0;
  531. hdmirx_hw_stru.prbs_enable = 1;
  532. printk("enable prbs mode %d\n", hdmirx_hw_stru.prbs_mode);
  533. }
  534. static void hdmi_rx_prbs_detect(unsigned int prbs_mode)
  535. {
  536. int j;
  537. unsigned int tmp_add_data;
  538. unsigned int rd_data;
  539. unsigned char prbs_ber_ok[4];
  540. // --------------------------------------------------------
  541. // Check channel 0-3 BER result
  542. // --------------------------------------------------------
  543. for (j = 0; j <= 3; j ++) {
  544. //stimulus_print("[TEST.C] Check channel PRBS results\n");
  545. prbs_ber_ok[j] = 0;
  546. // Select to view channel 0's BER result
  547. tmp_add_data = 0;
  548. tmp_add_data |= 0 << 8; // [7:6] Rsrv
  549. tmp_add_data |= j << 4; // [5:4] prbs_status_select[1:0]
  550. tmp_add_data |= 0 << 0; // [3:0] prbs_time_window[11:8]
  551. hdmi_wr_reg(RX_SYS2_PRBS_TIME_WINDOW1, tmp_add_data);
  552. // Freeze BER result
  553. tmp_add_data = 0;
  554. tmp_add_data |= prbs_mode << 6; // [7:6] hdmi_prbs_ana_i(0-3).prbs_mode[1:0]. 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 32.
  555. tmp_add_data |= 3 << 4; // [5:4] hdmi_prbs_ana_i(0-3).mode[1:0]
  556. tmp_add_data |= 0 << 3; // [3] hdmi_prbs_ana_i(0-3).clr_ber_meter
  557. tmp_add_data |= 1 << 2; // [2] hdmi_prbs_ana_i(0-3).freeze_ber
  558. tmp_add_data |= ((j == 0)? 0 : 1) << 1; // [1] hdmi_prbs_ana_i(0-3).inverse_in
  559. tmp_add_data |= 0 << 0; // [0] hdmi_prbs_ana_i(0-3).Rsrv
  560. hdmi_wr_reg(RX_SYS2_PRBS0_CNTRL+j, tmp_add_data);
  561. //if(hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_0) != 0x00){
  562. printk("CH%d:RX_SYSST_EXT_PRBS_BER_METER_0 = %x\n", j, hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_0));
  563. //}
  564. //if(hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_1) != 0x00){
  565. printk("CH%d:RX_SYSST_EXT_PRBS_BER_METER_1 = %x\n", j, hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_1));
  566. //}
  567. //if(hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_2) != 0x00){
  568. printk("CH%d:RX_SYSST_EXT_PRBS_BER_METER_2 = %x\n", j, hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_2));
  569. //}
  570. if((hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_0)==0)&&
  571. (hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_1)==0)&&
  572. (hdmi_rd_reg(RX_SYSST_EXT_PRBS_BER_METER_2)==0)){
  573. prbs_ber_ok[j] = 1;
  574. }
  575. // Un-freeze BER result
  576. tmp_add_data = 0;
  577. tmp_add_data |= prbs_mode << 6; // [7:6] hdmi_prbs_ana_i(0-3).prbs_mode[1:0]. 0=PRBS 11; 1=PRBS 15; 2=PRBS 7; 3=PRBS 32.
  578. tmp_add_data |= 3 << 4; // [5:4] hdmi_prbs_ana_i(0-3).mode[1:0]
  579. tmp_add_data |= 1 << 3; // [3] hdmi_prbs_ana_i(0-3).clr_ber_meter
  580. tmp_add_data |= 0 << 2; // [2] hdmi_prbs_ana_i(0-3).freeze_ber
  581. tmp_add_data |= ((j == 0)? 0 : 1) << 1; // [1] hdmi_prbs_ana_i(0-3).inverse_in
  582. tmp_add_data |= 0 << 0; // [0] hdmi_prbs_ana_i(0-3).Rsrv
  583. hdmi_wr_reg(RX_SYS2_PRBS0_CNTRL+j, tmp_add_data);
  584. hdmi_wr_reg(RX_SYS2_PRBS0_CNTRL+j, hdmi_rd_reg(RX_SYS2_PRBS0_CNTRL+j)&(~(1<<3))); //clear clr_ber_meter
  585. }
  586. // --------------------------------------------------------
  587. // Check all channels' PRBS status
  588. // --------------------------------------------------------
  589. //stimulus_print("[TEST.C] Check all channels' PRBS status\n");
  590. tmp_add_data = 0;
  591. tmp_add_data |= 0 << 7; // [7] hdmi_prbs_ana_i3.prbs_pattern_not_ok
  592. tmp_add_data |= 1 << 6; // [6] hdmi_prbs_ana_i3.prbs_lock
  593. tmp_add_data |= 0 << 5; // [5] hdmi_prbs_ana_i2.prbs_pattern_not_ok
  594. tmp_add_data |= 1 << 4; // [4] hdmi_prbs_ana_i2.prbs_lock
  595. tmp_add_data |= 0 << 3; // [3] hdmi_prbs_ana_i1.prbs_pattern_not_ok
  596. tmp_add_data |= 1 << 2; // [2] hdmi_prbs_ana_i1.prbs_lock
  597. tmp_add_data |= 1 << 1; // [1] hdmi_prbs_ana_i0.prbs_pattern_not_ok
  598. tmp_add_data |= 0 << 0; // [0] hdmi_prbs_ana_i0.prbs_lock
  599. rd_data = hdmi_rd_reg(RX_SYSST_EXT_PRBS_STATUS);
  600. //if(rd_data!=tmp_add_data){
  601. printk("RX_SYSST_EXT_PRBS_STATUS = %x, CH1 %s, CH2 %s, CH3 %s\n", rd_data,
  602. (((rd_data>>2)&3)==0x1)?"ok ":"err",
  603. (((rd_data>>4)&3)==0x1)?"ok ":"err",
  604. (((rd_data>>6)&3)==0x1)?"ok ":"err"
  605. );
  606. if((((rd_data>>2)&3)!=0x1)||
  607. (prbs_ber_ok[1]==0))
  608. prbs_ch1_err_num++;
  609. if((((rd_data>>4)&3)!=0x1)||
  610. (prbs_ber_ok[2]==0))
  611. prbs_ch2_err_num++;
  612. if((((rd_data>>6)&3)!=0x1)||
  613. (prbs_ber_ok[3]==0))
  614. prbs_ch3_err_num++;
  615. prbs_check_count++;
  616. //}
  617. } /* hdmi_rx_prbs_detect */
  618. void hdmirx_hw_init(tvin_port_t port)
  619. {
  620. //unsigned long flags;
  621. //hdmi_sys_clk = clk_util_clk_msr( OTHER_CLK_INDEX, 50 )/((Rd(HHI_HDMI_CLK_CNTL)&0x7f)+1);
  622. cec_set_pending(TV_CEC_PENDING_ON);
  623. HDMIRX_HW_LOG("[HDMIRX] hdmirx_hw_init(%d)\n", port);
  624. memset(&hdmirx_hw_stru, 0, sizeof(hdmirx_hw_stru));
  625. internal_mode_monitor();
  626. switch (port)
  627. {
  628. case TVIN_PORT_HDMI1:
  629. hdmirx_hw_stru.port = 0x2;
  630. break;
  631. case TVIN_PORT_HDMI2:
  632. hdmirx_hw_stru.port = 0x4;
  633. break;
  634. default:
  635. hdmirx_hw_stru.port = 0x1;
  636. break;
  637. }
  638. #if 1
  639. /* reset the whole hdmi module */
  640. Wr(RESET2_REGISTER, Rd(RESET2_REGISTER)|(1<<15));
  641. mdelay(10);
  642. Wr(RESET2_REGISTER, Rd(RESET2_REGISTER)&(~(1<<15)));
  643. #endif
  644. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(3<<6));
  645. hdmi_init();
  646. /*cec config*/
  647. cec_init();
  648. cec_set_pending(TV_CEC_PENDING_OFF);
  649. //hdmirx_monitor_reg_init();
  650. #ifdef HDMIRX_WITH_IRQ
  651. hdmirx_setupirq();
  652. #endif
  653. return;
  654. }
  655. static void hdmirx_config_color_depth(unsigned int color_depth)
  656. {
  657. if(color_depth!=hdmirx_hw_stru.cur_color_depth){
  658. hdmi_wr_only_reg(RX_BASE_ADDR+0x865,(hdmi_rd_reg(RX_BASE_ADDR+0x865)&(~0x3))|color_depth );
  659. hdmi_wr_only_reg(RX_BASE_ADDR+0x86D,(hdmi_rd_reg(RX_BASE_ADDR+0x86D)&(~0x3))|color_depth );
  660. hdmi_wr_only_reg(RX_BASE_ADDR+0x875,(hdmi_rd_reg(RX_BASE_ADDR+0x875)&(~0x3))|color_depth );
  661. hdmi_wr_only_reg(RX_BASE_ADDR+0x87D,(hdmi_rd_reg(RX_BASE_ADDR+0x87D)&(~0x3))|color_depth );
  662. hdmi_wr_reg(RX_VIDEO_DTV_MODE, (hdmi_rd_reg(RX_VIDEO_DTV_MODE)&(~0x3))|color_depth);
  663. hdmi_wr_reg(RX_VIDEO_DTV_OPTION_L, (hdmi_rd_reg(RX_VIDEO_DTV_OPTION_L)&(~0x3))|color_depth);
  664. HDMIRX_HW_LOG("[HDMIRX] config color depth %d\n", color_depth);
  665. hdmirx_hw_stru.cur_color_depth = color_depth;
  666. }
  667. }
  668. static void hdmirx_config_color(void)
  669. {
  670. if(hdmirx_hw_stru.avi_info.cc == CC_ITU709){
  671. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_B0, 0x7b);
  672. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_B1, 0x12);
  673. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_R0, 0x6c);
  674. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_R1, 0x36);
  675. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CB0, 0xf2);
  676. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CB1, 0x2f);
  677. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CR0, 0xd4);
  678. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CR1, 0x77);
  679. }
  680. else{
  681. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_B0, 0x2f);
  682. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_B1, 0x1d);
  683. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_R0, 0x8b);
  684. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_R1, 0x4c);
  685. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CB0, 0x18);
  686. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CB1, 0x58);
  687. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CR0, 0xd0);
  688. hdmi_wr_reg(RX_VIDEO_CSC_COEFF_CR1, 0xb6);
  689. }
  690. hdmi_wr_reg(RX_VIDEO_DTV_OPTION_L, (hdmi_rd_reg(RX_VIDEO_DTV_OPTION_L)&(~(3<<4)))|(conv_color_format_to_rtl_value(hdmirx_hw_stru.avi_info.color_format)<<4)); //input color format
  691. hdmi_wr_reg(RX_VIDEO_DTV_OPTION_L, (hdmi_rd_reg(RX_VIDEO_DTV_OPTION_L)&(~(3<<6)))|(conv_color_format_to_rtl_value(hdmirx_hw_stru.cur_color_format)<<6)); //output color format
  692. hdmi_wr_reg_bits(RX_VIDEO_DTV_OPTION_H, (hdmirx_hw_stru.avi_info.color_range==2)?3:0, 0, 2); // [1:0] input_color_range: 0=16-235/240; 1=16-240; 2=1-254; 3=0-255.
  693. hdmi_wr_reg(RX_VIDEO_PROC_CONFIG0,(hdmi_rd_reg(RX_VIDEO_PROC_CONFIG0)&(~(0xf<<4)))|( hdmirx_hw_stru.avi_info.pixel_repeat << 4));
  694. }
  695. typedef struct{
  696. unsigned int vic;
  697. #ifdef GET_COLOR_DEPTH_WORK_AROUND
  698. unsigned char frame_packing_flag;
  699. #endif
  700. unsigned char vesa_format;
  701. unsigned int ref_freq; /* 8 bit tmds clock */
  702. unsigned int active_pixels;
  703. unsigned int active_lines;
  704. unsigned int active_lines_fp;
  705. }freq_ref_t;
  706. /*
  707. format_en0[bit 0] is for vic1, bit1 is for vic2, ...
  708. format_en1[bit 0] is for vic33, bit2 is for vic34, ...
  709. format_en2[bit 0] is for vic65, bit2 is for vic66, ...
  710. */
  711. static int format_en0_default = 0xc03f807f;
  712. static int format_en1_default = 0x00000003;
  713. static int format_en2_default = 0x00000447;
  714. static int format_en3_default = 0x00000000;
  715. static int format_en0 = 0xc03f807f;
  716. static int format_en1 = 0x00000003;
  717. static int format_en2 = 0x00000447;
  718. static int format_en3 = 0x00000000;
  719. static freq_ref_t freq_ref[]=
  720. {
  721. /* basic format*/
  722. {HDMI_640x480p60, 0, 25000, 640, 480, 480},
  723. {HDMI_480p60, 0, 27000, 720, 480, 1005},
  724. {HDMI_480p60_16x9, 0, 27000, 720, 480, 1005},
  725. {HDMI_480i60, 0, 27000, 1440, 240, 240},
  726. {HDMI_480i60_16x9, 0, 27000, 1440, 240, 240},
  727. {HDMI_576p50, 0, 27000, 720, 576, 1201},
  728. {HDMI_576p50_16x9, 0, 27000, 720, 576, 1201},
  729. {HDMI_576i50, 0, 27000, 1440, 288, 288},
  730. {HDMI_576i50_16x9, 0, 27000, 1440, 288, 288},
  731. {HDMI_720p60, 0, 74250, 1280, 720, 1470},
  732. {HDMI_720p50, 0, 74250, 1280, 720, 1470},
  733. {HDMI_1080i60, 0, 74250, 1920, 540, 2228},
  734. {HDMI_1080i50, 0, 74250, 1920, 540, 2228},
  735. {HDMI_1080p24, 0, 74250, 1920, 1080, 2205},
  736. {HDMI_1080p30, 0, 74250, 1920, 1080, 2205},
  737. {HDMI_1080p60, 0, 148500, 1920, 1080, 1080},
  738. {HDMI_1080p50, 0, 148500, 1920, 1080, 1080},
  739. /* extend format */
  740. {HDMI_1440x240p60, 0, 27000, 1440, 240, 240}, //vic 8
  741. {HDMI_1440x240p60_16x9, 0, 27000, 1440, 240, 240}, //vic 9
  742. {HDMI_2880x480i60, 0, 54000, 2880, 240, 240}, //vic 10
  743. {HDMI_2880x480i60_16x9, 0, 54000, 2880, 240, 240}, //vic 11
  744. {HDMI_2880x240p60, 0, 54000, 2880, 240, 240}, //vic 12
  745. {HDMI_2880x240p60_16x9, 0, 54000, 2880, 240, 240}, //vic 13
  746. {HDMI_1440x480p60, 0, 54000, 1440, 480, 480}, //vic 14
  747. {HDMI_1440x480p60_16x9, 0, 54000, 1440, 480, 480}, //vic 15
  748. {HDMI_1440x288p50, 0, 27000, 1440, 288, 288}, //vic 23
  749. {HDMI_1440x288p50_16x9, 0, 27000, 1440, 288, 288}, //vic 24
  750. {HDMI_2880x576i50, 0, 54000, 2880, 288, 288}, //vic 25
  751. {HDMI_2880x576i50_16x9, 0, 54000, 2880, 288, 288}, //vic 26
  752. {HDMI_2880x288p50, 0, 54000, 2880, 288, 288}, //vic 27
  753. {HDMI_2880x288p50_16x9, 0, 54000, 2880, 288, 288}, //vic 28
  754. {HDMI_1440x576p50, 0, 54000, 1440, 576, 576}, //vic 29
  755. {HDMI_1440x576p50_16x9, 0, 54000, 1440, 576, 576}, //vic 30
  756. {HDMI_2880x480p60, 0, 108000, 2880, 480, 480}, //vic 35
  757. {HDMI_2880x480p60_16x9, 0, 108000, 2880, 480, 480}, //vic 36
  758. {HDMI_2880x576p50, 0, 108000, 2880, 576, 576}, //vic 37
  759. {HDMI_2880x576p50_16x9, 0, 108000, 2880, 576, 576}, //vic 38
  760. {HDMI_1080i50_1250, 0, 72000, 1920, 540, 540}, //vic 39
  761. /* vesa format*/
  762. {HDMI_800_600, 1, 0, 800, 600, 600},
  763. {HDMI_1024_768, 1, 0, 1024, 768, 768},
  764. {HDMI_720_400, 1, 0, 720, 400, 400},
  765. {HDMI_1280_768, 1, 0, 1280, 768, 768},
  766. {HDMI_1280_800, 1, 0, 1280, 800, 800},
  767. {HDMI_1280_960, 1, 0, 1280, 960, 960},
  768. {HDMI_1280_1024, 1, 0, 1280, 1024, 1024},
  769. {HDMI_1360_768, 1, 0, 1360, 768, 768},
  770. {HDMI_1366_768, 1, 0, 1366, 768, 768},
  771. {HDMI_1600_1200, 1, 0, 1600, 1200, 1200},
  772. {HDMI_1920_1200, 1, 0, 1920, 1200, 1200},
  773. /* for AG-506 */
  774. {HDMI_480p60, 0, 27000, 720, 483, 483},
  775. {0, 0, 0}
  776. };
  777. static unsigned int get_vic_from_timing(void)
  778. {
  779. int i;
  780. for(i = 0; freq_ref[i].vic; i++){
  781. if((hdmirx_hw_stru.video_status.active_pixels == freq_ref[i].active_pixels)&&
  782. ((hdmirx_hw_stru.video_status.active_lines == freq_ref[i].active_lines)||
  783. (hdmirx_hw_stru.video_status.active_lines == freq_ref[i].active_lines_fp))){
  784. break;
  785. }
  786. }
  787. return freq_ref[i].vic;
  788. }
  789. static unsigned int get_freq(void)
  790. {
  791. int i;
  792. #if 1
  793. return PIXEL_CLK;
  794. #else
  795. if(hdmirx_hw_stru.avi_info.vic){
  796. for(i = 0; freq_ref[i].vic; i++){
  797. if((hdmirx_hw_stru.avi_info.vic == freq_ref[i].vic)){
  798. break;
  799. }
  800. }
  801. return freq_ref[i].ref_freq*1000;
  802. }
  803. #endif
  804. return 0;
  805. }
  806. static unsigned char is_vesa_format(void)
  807. {
  808. int i;
  809. unsigned char ret = 0;
  810. for(i = 0; freq_ref[i].vic; i++){
  811. if((hdmirx_hw_stru.video_status.active_pixels == freq_ref[i].active_pixels)&&
  812. (hdmirx_hw_stru.video_status.active_lines == freq_ref[i].active_lines)&&
  813. (freq_ref[i].vesa_format!=0)
  814. ){
  815. break;
  816. }
  817. }
  818. if(freq_ref[i].vic!=0){
  819. ret = 1;
  820. }
  821. return ret;
  822. }
  823. static unsigned char is_tmds_clock_stable(int diff_threshold, int count_threshold)
  824. {
  825. int i;
  826. unsigned char ret = 1;
  827. for(i = 1; i<count_threshold; i++){
  828. if(hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1] > hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1-i]){
  829. if((hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1]-hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1-i])>diff_threshold){
  830. ret = 0;
  831. break;
  832. }
  833. }
  834. else{
  835. if((hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1-i]-hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1])>diff_threshold){
  836. ret = 0;
  837. break;
  838. }
  839. }
  840. }
  841. return ret;
  842. }
  843. static unsigned char is_tmds_clock_unstable(int diff_threshold, int count_threshold)
  844. {
  845. int i;
  846. unsigned char ret = 1;
  847. for(i = 0; i<(count_threshold-1); i++){
  848. if(hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-count_threshold] > hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1-i]){
  849. if((hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-count_threshold]-hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1-i])<diff_threshold){
  850. ret = 0;
  851. break;
  852. }
  853. }
  854. else{
  855. if((hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1-i]-hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-count_threshold])<diff_threshold){
  856. ret = 0;
  857. break;
  858. }
  859. }
  860. }
  861. return ret;
  862. }
  863. static unsigned char signal_not_ok(void)
  864. {
  865. int i;
  866. int ret = 0;
  867. if((have_avi_info()==0)&&
  868. (signal_check_mode&8)){
  869. ret |= 0x8;
  870. }
  871. if(dvi_mode&1){
  872. if((hdmi_rd_reg(RX_BASE_ADDR+RX_TMDSST_HDMI_STATUS)&0x60)==0x20){
  873. HDMIRX_HW_LOG("[HDMIRX] DVI mode is detected\n\n");
  874. printk("DDDDDDDDDDDDDDDDDDDDDD\n");
  875. printk("VVVVVVVVVVVVVVVVVVVVVV\n");
  876. printk("IIIIIIIIIIIIIIIIIIIIII\n");
  877. ret &= (~0x8);
  878. }
  879. }
  880. if(dvi_detect_wait_avi_th){
  881. if(hdmirx_hw_stru.clk_stable_count > dvi_detect_wait_avi_th){
  882. if(is_vesa_format()){
  883. ret &= (~0x8);
  884. }
  885. }
  886. }
  887. if(general_detect_wait_avi_th){
  888. if(hdmirx_hw_stru.clk_stable_count > general_detect_wait_avi_th){
  889. if(get_vic_from_timing() != 0){
  890. ret &= (~0x8);
  891. }
  892. }
  893. }
  894. if((hdmirx_hw_stru.avi_info.vic == 0)&&
  895. (signal_check_mode&4)){
  896. ret |= 0x4;
  897. }
  898. if(signal_check_mode&2){
  899. if(signal_check_mode&4){
  900. for(i = 0; freq_ref[i].vic; i++){
  901. if(freq_ref[i].vic == hdmirx_hw_stru.avi_info.vic){
  902. if(hdmirx_hw_stru.video_status.active_pixels != freq_ref[i].active_pixels){
  903. ret |= 0x2;
  904. }
  905. if((hdmirx_hw_stru.video_status.active_lines != freq_ref[i].active_lines)&&
  906. (hdmirx_hw_stru.video_status.active_lines != freq_ref[i].active_lines_fp)){
  907. ret |= 0x2;
  908. }
  909. if(internal_mode_valid()&&(internal_mode&INT_MODE_DISABLE_LINES_CHECK)
  910. &&(hdmirx_hw_stru.video_status.active_pixels == freq_ref[i].active_pixels)){
  911. ret &= (~0x2);
  912. }
  913. break;
  914. }
  915. }
  916. }
  917. else{
  918. /* if we do not check vic=0, it is possible vic is 0 */
  919. if(get_vic_from_timing() == 0){
  920. ret |= 0x2;
  921. }
  922. }
  923. }
  924. if(signal_check_mode&1){
  925. if(hdmirx_hw_stru.video_status.pixel_phase_ok == 0){
  926. ret |= 0x1;
  927. }
  928. }
  929. return ret;
  930. }
  931. static unsigned char wait_signal_ok(void)
  932. {
  933. static int count=0;
  934. unsigned char ret = signal_not_ok();
  935. unsigned char signal_recover_type = signal_recover_mode&0xf;
  936. unsigned char signal_recover_mask = (signal_recover_mode>>4)&0xf;
  937. if(ret){
  938. count++;
  939. if(((count>reset_threshold)&&(hdmirx_hw_stru.clk_stable_count < (10*HDMI_STATE_CHECK_FREQ)))||
  940. (count>(reset_threshold*3))) // reset period is 3 seconds after 10 seconds
  941. {
  942. HDMIRX_HW_LOG("[HDMIRX]============signal not ok %d\n", ret);
  943. dump_state(DUMP_FLAG_VIDEO_TIMING|DUMP_FLAG_AVI_INFO|DUMP_FLAG_VENDOR_SPEC_INFO|DUMP_FLAG_CLOCK_INFO);
  944. if((signal_recover_mask==0)||(ret&signal_recover_mask)){
  945. if((eq_config&0x200)==0){
  946. if(PIXEL_CLK<28000000){
  947. set_eq_27M_2();
  948. }
  949. else{
  950. restore_eq_gen();
  951. }
  952. }
  953. if(signal_recover_type == 1){
  954. hdmirx_reset_clock();
  955. HDMIRX_HW_LOG("[HDMIRX]============hdmirx_reset_clock\n\n");
  956. }
  957. else if(signal_recover_type == 2){
  958. hdmirx_reset();
  959. HDMIRX_HW_LOG("[HDMIRX]============hdmirx_reset\n\n");
  960. }
  961. else if(signal_recover_type == 3){
  962. hdmirx_phy_init();
  963. HDMIRX_HW_LOG("[HDMIRX]============hdmirx_phy_init\n\n");
  964. }
  965. else if(signal_recover_type == 4){
  966. hdmirx_reset_pixel_clock();
  967. HDMIRX_HW_LOG("[HDMIRX]============hdmirx_reset_pixel_clock\n\n");
  968. }
  969. else if(signal_recover_type == 5){
  970. hdmirx_unpack_recover();
  971. HDMIRX_HW_LOG("[HDMIRX]============hdmirx_unpack_recover\n\n");
  972. }
  973. else{
  974. HDMIRX_HW_LOG("[HDMIRX]============\n\n");
  975. }
  976. }
  977. else{
  978. HDMIRX_HW_LOG("[HDMIRX]============\n\n");
  979. }
  980. count = 0;
  981. }
  982. }
  983. else{
  984. count=0;
  985. }
  986. return ret;
  987. }
  988. #ifdef GET_COLOR_DEPTH_WORK_AROUND
  989. static unsigned char is_frame_packing_fmt(int vic);
  990. static unsigned int check_color_depth(void)
  991. {
  992. int i;
  993. unsigned int ret_color_depth = hdmirx_hw_stru.video_status.color_depth;
  994. unsigned int ref_freq_8, ref_freq_10, ref_freq_12, cur_freq;
  995. for(i = 0; freq_ref[i].vic; i++){
  996. if((freq_ref[i].vic == hdmirx_hw_stru.avi_info.vic)
  997. &&(is_frame_packing_fmt(hdmirx_hw_stru.avi_info.vic) == freq_ref[i].frame_packing_flag)){
  998. ref_freq_8 = freq_ref[i].ref_freq;
  999. ref_freq_10 = ref_freq_8*10/8;
  1000. ref_freq_12 = ref_freq_8*12/8;
  1001. cur_freq = TMDS_CLK(hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1]);
  1002. if( cur_freq > ref_freq_12){
  1003. ret_color_depth = 2;
  1004. }
  1005. else if(cur_freq > ref_freq_10){
  1006. if((ref_freq_12-cur_freq)<(cur_freq-ref_freq_10))
  1007. ret_color_depth = 2;
  1008. else
  1009. ret_color_depth = 1;
  1010. }
  1011. else if(cur_freq > ref_freq_8){
  1012. if((ref_freq_10-cur_freq)<(cur_freq-ref_freq_8))
  1013. ret_color_depth = 1;
  1014. else
  1015. ret_color_depth = 0;
  1016. }
  1017. else{
  1018. ret_color_depth = 0;
  1019. }
  1020. if(ret_color_depth!=(hdmi_rd_reg(RX_VIDEO_DTV_MODE)&0x3)){
  1021. printk("index %d, cur_freq %d,ref_freq_12 %d, ref_freq_10 %d, ref_freq_8 %d, ret_color_depth %d\n",
  1022. i, cur_freq, ref_freq_12, ref_freq_10, ref_freq_8, ret_color_depth);
  1023. }
  1024. break;
  1025. }
  1026. }
  1027. return ret_color_depth;
  1028. }
  1029. static unsigned int check_color_depth_b(void)
  1030. {
  1031. if( hdmirx_hw_stru.video_status.gc_error||
  1032. hdmirx_hw_stru.video_status.color_depth == 0 ){
  1033. return 0;
  1034. }
  1035. else{
  1036. return hdmirx_hw_stru.video_status.color_depth;
  1037. }
  1038. }
  1039. #endif
  1040. static int get_color_depth(void)
  1041. {
  1042. int color_depth = hdmirx_hw_stru.video_status.color_depth;
  1043. #ifdef GET_COLOR_DEPTH_WORK_AROUND
  1044. if(check_color_depth_mode == 1){
  1045. color_depth = check_color_depth_b();
  1046. }
  1047. else if(check_color_depth_mode == 2){
  1048. color_depth = check_color_depth(); //work around code: detect wrong color depth
  1049. }
  1050. else if(check_color_depth_mode == 3){
  1051. if(hdmirx_hw_stru.video_status.gc_error){
  1052. color_depth = check_color_depth(); //work around code: detect wrong color depth
  1053. }
  1054. else{
  1055. color_depth = check_color_depth_b();
  1056. }
  1057. }
  1058. #endif
  1059. return color_depth;
  1060. }
  1061. static void hdmirx_hw_enable_clock(void )
  1062. {
  1063. // -----------------------------------------
  1064. // HDMI (90Mhz)
  1065. // -----------------------------------------
  1066. // .clk_div ( hi_hdmi_clk_cntl[6:0] ),
  1067. // .clk_en ( hi_hdmi_clk_cntl[8] ),
  1068. // .clk_sel ( hi_hdmi_clk_cntl[11:9]),
  1069. #ifdef _SUPPORT_CEC_TV_MASTER_
  1070. Wr( HHI_HDMI_CLK_CNTL, ((1 << 9) | // select "other" PLL
  1071. (1 << 8) | // Enable gated clock
  1072. (0x1D << 0)) ); // Divide the "other" PLL output by 30
  1073. #else
  1074. Wr( HHI_HDMI_CLK_CNTL, ((1 << 9) | // select "other" PLL
  1075. (1 << 8) | // Enable gated clock
  1076. (3 << 0)) ); // Divide the "other" PLL output by 4
  1077. #endif
  1078. }
  1079. static void hdmirx_hw_disable_clock(void)
  1080. {
  1081. //Wr(HHI_HDMI_CLK_CNTL, Rd(HHI_HDMI_CLK_CNTL)&(~(1<<8)));
  1082. }
  1083. void hdmirx_hw_enable(void)
  1084. {
  1085. HDMIRX_HW_LOG("[HDMIRX] hdmirx_hw_enable()\n");
  1086. // --------------------------------------------------------
  1087. // Set Clocks
  1088. // --------------------------------------------------------
  1089. // --------------------------------------------------------
  1090. // Program core_pin_mux to enable HDMI pins
  1091. // --------------------------------------------------------
  1092. Wr(PERIPHS_PIN_MUX_3, Rd(PERIPHS_PIN_MUX_3) | ((1 << 31) | // pm_gpioX_5_hdmi_pwr0
  1093. (1 << 30) | // pm_gpioX_6_hdmi_hpd0
  1094. (1 << 29) | // pm_gpioX_7_hdmi_pwr1
  1095. (1 << 28) | // pm_gpioX_8_hdmi_hpd1
  1096. (1 << 27) | // pm_gpioX_9_hdmi_pwr2
  1097. (1 << 26))); // pm_gpioX_10_hdmi_hpd2
  1098. Wr(PERIPHS_PIN_MUX_6, Rd(PERIPHS_PIN_MUX_6) | ((1 << 22) | // pm_gpioD_0_hdmi_cec
  1099. (1 << 21) | // pm_gpioD_1_hdmi_sda0
  1100. (1 << 20) | // pm_gpioD_2_hdmi_scl0
  1101. (1 << 19) | // pm_gpioD_3_hdmi_sda1
  1102. (1 << 18) | // pm_gpioD_4_hdmi_scl1
  1103. (1 << 17) | // pm_gpioD_5_hdmi_sda2
  1104. (1 << 16))); // pm_gpioD_6_hdmi_scl2
  1105. hdmirx_hw_enable_clock();
  1106. }
  1107. static void phy_powerdown(unsigned char flag)
  1108. {
  1109. #if 1
  1110. if((powerdown_enable==0)&&(flag==0)){
  1111. return;
  1112. }
  1113. hdmi_wr_reg(RX_BASE_ADDR+0x864, hdmi_rd_reg(RX_BASE_ADDR+0x864) | (1<<7)); // rx0_eq_pd = 1
  1114. hdmi_wr_reg(RX_BASE_ADDR+0x86C, hdmi_rd_reg(RX_BASE_ADDR+0x86C) | (1<<7)); // rx1_eq_pd = 1
  1115. hdmi_wr_reg(RX_BASE_ADDR+0x874, hdmi_rd_reg(RX_BASE_ADDR+0x874) | (1<<7)); // rx2_eq_pd = 1
  1116. hdmi_wr_reg(RX_BASE_ADDR+0x87C, hdmi_rd_reg(RX_BASE_ADDR+0x87C) | (1<<7)); // rx3_eq_pd = 1
  1117. pr_info("hdmirx_hw: rx3_eq_pd\n");
  1118. hdmi_wr_reg(RX_BASE_ADDR+0x866, hdmi_rd_reg(RX_BASE_ADDR+0x866) | (1<<6)); // cdr0_pd = 1
  1119. hdmi_wr_reg(RX_BASE_ADDR+0x86E, hdmi_rd_reg(RX_BASE_ADDR+0x86E) | (1<<6)); // cdr1_pd = 1
  1120. hdmi_wr_reg(RX_BASE_ADDR+0x876, hdmi_rd_reg(RX_BASE_ADDR+0x876) | (1<<6)); // cdr2_pd = 1
  1121. hdmi_wr_reg(RX_BASE_ADDR+0x87E, hdmi_rd_reg(RX_BASE_ADDR+0x87E) | (1<<6)); // cdr3_pd = 1
  1122. pr_info("hdmirx_hw: cdr3_pd\n");
  1123. hdmi_wr_reg(RX_BASE_ADDR+0x005, 0<<0); // [2:0] port_en = 0
  1124. hdmi_wr_reg(RX_BASE_ADDR+0x097, hdmi_rd_reg(RX_BASE_ADDR+0x097)|
  1125. (1<<7)| // rxref_pd = 1
  1126. (1<<6)| // rxref_pd_vgap = 1
  1127. (1<<5));// rxref_pd_op2 = 1
  1128. #else
  1129. /* it will block at hdmi_wr_reg(RX_BASE_ADDR+0x864, ...) for some board when unplug */
  1130. printk("1\n");
  1131. hdmi_wr_reg(RX_BASE_ADDR+0x097, hdmi_rd_reg(RX_BASE_ADDR+0x097)|
  1132. (1<<7)| // rxref_pd = 1
  1133. (1<<6)| // rxref_pd_vgap = 1
  1134. (1<<5));// rxref_pd_op2 = 1
  1135. printk("2\n");
  1136. hdmi_wr_reg(RX_BASE_ADDR+0x864, hdmi_rd_reg(RX_BASE_ADDR+0x864) | (1<<7)); // rx0_eq_pd = 1
  1137. printk("2.1\n");
  1138. hdmi_wr_reg(RX_BASE_ADDR+0x86C, hdmi_rd_reg(RX_BASE_ADDR+0x86C) | (1<<7)); // rx1_eq_pd = 1
  1139. printk("2.2\n");
  1140. hdmi_wr_reg(RX_BASE_ADDR+0x874, hdmi_rd_reg(RX_BASE_ADDR+0x874) | (1<<7)); // rx2_eq_pd = 1
  1141. printk("2.3\n");
  1142. hdmi_wr_reg(RX_BASE_ADDR+0x87C, hdmi_rd_reg(RX_BASE_ADDR+0x87C) | (1<<7)); // rx3_eq_pd = 1
  1143. printk("3\n");
  1144. hdmi_wr_reg(RX_BASE_ADDR+0x866, hdmi_rd_reg(RX_BASE_ADDR+0x866) | (1<<6)); // cdr0_pd = 1
  1145. printk("3.1\n");
  1146. hdmi_wr_reg(RX_BASE_ADDR+0x86E, hdmi_rd_reg(RX_BASE_ADDR+0x86E) | (1<<6)); // cdr1_pd = 1
  1147. printk("3.2\n");
  1148. hdmi_wr_reg(RX_BASE_ADDR+0x876, hdmi_rd_reg(RX_BASE_ADDR+0x876) | (1<<6)); // cdr2_pd = 1
  1149. printk("3.3\n");
  1150. hdmi_wr_reg(RX_BASE_ADDR+0x87E, hdmi_rd_reg(RX_BASE_ADDR+0x87E) | (1<<6)); // cdr3_pd = 1
  1151. printk("4\n");
  1152. hdmi_wr_reg(RX_BASE_ADDR+0x005, 0<<0); // [2:0] port_en = 0
  1153. printk("5\n");
  1154. #endif
  1155. }
  1156. static void phy_poweron(void)
  1157. {
  1158. hdmi_wr_reg(RX_BASE_ADDR+0x097, hdmi_rd_reg(RX_BASE_ADDR+0x097)&
  1159. (~((1<<7)|
  1160. (1<<6)|
  1161. (1<<5))));
  1162. hdmi_wr_reg(RX_BASE_ADDR+0x864, hdmi_rd_reg(RX_BASE_ADDR+0x864) & (~(1<<7)));
  1163. hdmi_wr_reg(RX_BASE_ADDR+0x86C, hdmi_rd_reg(RX_BASE_ADDR+0x86C) & (~(1<<7)));
  1164. hdmi_wr_reg(RX_BASE_ADDR+0x874, hdmi_rd_reg(RX_BASE_ADDR+0x874) & (~(1<<7)));
  1165. hdmi_wr_reg(RX_BASE_ADDR+0x87C, hdmi_rd_reg(RX_BASE_ADDR+0x87C) & (~(1<<7)));
  1166. hdmi_wr_reg(RX_BASE_ADDR+0x866, hdmi_rd_reg(RX_BASE_ADDR+0x866) & (~(1<<6)));
  1167. hdmi_wr_reg(RX_BASE_ADDR+0x86E, hdmi_rd_reg(RX_BASE_ADDR+0x86E) & (~(1<<6)));
  1168. hdmi_wr_reg(RX_BASE_ADDR+0x876, hdmi_rd_reg(RX_BASE_ADDR+0x876) & (~(1<<6)));
  1169. hdmi_wr_reg(RX_BASE_ADDR+0x87E, hdmi_rd_reg(RX_BASE_ADDR+0x87E) & (~(1<<6)));
  1170. //hdmi_wr_reg(RX_BASE_ADDR+0x005, 0<<0); // [2:0] port_en = 0
  1171. hdmi_wr_reg(RX_BASE_ADDR+0x005, hdmirx_hw_stru.port); // 0x04
  1172. }
  1173. void hdmirx_hw_disable(unsigned char flag)
  1174. {
  1175. HDMIRX_HW_LOG("[HDMIRX] hdmirx_hw_disable()\n");
  1176. set_hdmi_audio_source_gate(0);
  1177. phy_powerdown(flag);
  1178. pr_info("hdmirx_hw: phy_powerdown\n");
  1179. hdmirx_hw_disable_clock();
  1180. return;
  1181. }
  1182. void hdmirx_hw_uninit(void)
  1183. {
  1184. #ifdef HDMIRX_WITH_IRQ
  1185. Rd(A9_0_IRQ_IN1_INTR_STAT_CLR);
  1186. Wr(A9_0_IRQ_IN1_INTR_MASK, Rd(A9_0_IRQ_IN1_INTR_MASK)&(~(1 << 24)));
  1187. free_irq(INT_HDMI_RX, (void *)"amhdmirx");
  1188. #endif
  1189. }
  1190. static void hdmi_init(void)
  1191. {
  1192. unsigned int tmp_add_data;
  1193. // Enable APB3 fail on error
  1194. //*((volatile unsigned long *) HDMI_CTRL_PORT) |= (1 << 15); //APB3 err_en
  1195. WRITE_APB_REG(HDMI_CTRL_PORT, READ_APB_REG(HDMI_CTRL_PORT)|(1<<15)); //APB3 err_en
  1196. // Mask AVI InfoFrame: only to interrupt on VIC, color format, pixel repetition
  1197. hdmi_wr_reg(OTHER_BASE_ADDR + HDMI_OTHER_AVI_INTR_MASKN0, 0x7f0c0060);
  1198. hdmi_wr_reg(OTHER_BASE_ADDR + HDMI_OTHER_AVI_INTR_MASKN1, 0x0000000f);
  1199. // Mask Audio InfoFrame: only to interrupt on channel count, sample frequency
  1200. hdmi_wr_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_AINFO_INTR_MASKN0, 0x00001c07);
  1201. hdmi_wr_reg(OTHER_BASE_ADDR + HDMI_OTHER_RX_AINFO_INTR_MASKN1, 0x00000000);
  1202. // Enable HDMI RX interrupts on:
  1203. // [9] COLOR_DEPTH, [10] TMDS_CLK_UNSTABLE, [11] EDID_ADDR, [12] AVMUTE_UPDATE,
  1204. // [13] AVI_UPDATE, [14] AUDIO_INFO_UPDATE, [17:15] RX_5V_RISE, [20:18] RX_5V_FALL
  1205. //hdmi_wr_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_MASKN, 0x1ffe00);
  1206. // Enable RX interrupts:
  1207. hdmi_wr_reg(OTHER_BASE_ADDR + HDMI_OTHER_INTR_MASKN, 0x1fff00);
  1208. // SOFT_RESET [23:16]
  1209. tmp_add_data = 0;
  1210. tmp_add_data |= 0 << 7; // [7] ~rx_i2s_config_rstn
  1211. tmp_add_data |= 0 << 6; // [6] rsvd
  1212. tmp_add_data |= 3 << 4; // [5:4] rx_acr_rst_config[1:0]
  1213. tmp_add_data |= 0 << 3; // [3] ~rx_config_eye_rstn_ch3
  1214. tmp_add_data |= 0 << 2; // [2] ~rx_config_eye_rstn_ch2
  1215. tmp_add_data |= 0 << 1; // [1] ~rx_config_eye_rstn_ch1
  1216. tmp_add_data |= 0 << 0; // [0] ~rx_config_eye_rstn_ch0
  1217. hdmi_wr_reg(RX_BASE_ADDR+0xe4, tmp_add_data); // 0x30
  1218. // Program hdmi_rx_osc_ext_clk if it is selected to be the ACR input clock
  1219. if (ACR_MODE == 1) {
  1220. // Configure clk_rst_tst.cts_hdmi_rx_osc_ext_clk
  1221. tmp_add_data = 0;
  1222. tmp_add_data |= 0 << 3; // [7:3] Rsrv
  1223. tmp_add_data |= 1 << 0; // [2:0] clk_sel
  1224. hdmi_wr_reg(RX_SYS4_OSC_EXT_CLK_CNTL_1, tmp_add_data);
  1225. tmp_add_data = 0;
  1226. tmp_add_data |= 1 << 7; // [7] clk_en
  1227. tmp_add_data |= 1 << 0; // [6:0] clk_div
  1228. hdmi_wr_reg(RX_SYS4_OSC_EXT_CLK_CNTL_0, tmp_add_data);
  1229. }
  1230. // Div Pre
  1231. tmp_add_data = 0xff; // div_pre[7:0]
  1232. hdmi_wr_reg(RX_SYS3_RX_ACR_0, tmp_add_data);
  1233. tmp_add_data = 0;
  1234. tmp_add_data |= ACR_MODE<< 6; // [7:6] acr_mode[1:0]
  1235. tmp_add_data |= 1 << 5; // [5] ~force div_main
  1236. tmp_add_data |= 1 << 4; // [4] ~force div_pre
  1237. tmp_add_data |= 0xb << 0; // [3:0] div_pre[11:8]
  1238. hdmi_wr_reg(RX_SYS3_RX_ACR_1, tmp_add_data); // 0xfb
  1239. // SOFT_RESET [23:16]: need it to kick start ACR clocks
  1240. tmp_add_data = 0;
  1241. tmp_add_data |= 0 << 7; // [7] ~rx_i2s_config_rstn
  1242. tmp_add_data |= 0 << 6; // [6] Rsvd
  1243. tmp_add_data |= 1 << 4; // [5:4] rx_acr_rst_config[1:0]
  1244. tmp_add_data |= 0 << 3; // [3] ~rx_config_eye_rstn_ch3
  1245. tmp_add_data |= 0 << 2; // [2] ~rx_config_eye_rstn_ch2
  1246. tmp_add_data |= 0 << 1; // [1] ~rx_config_eye_rstn_ch1
  1247. tmp_add_data |= 0 << 0; // [0] ~rx_config_eye_rstn_ch0
  1248. hdmi_wr_reg(RX_BASE_ADDR+0xe4, tmp_add_data); // 0x10
  1249. // SOFT_RESET [23:16]
  1250. tmp_add_data = 0;
  1251. tmp_add_data |= 0 << 7; // [7] ~rx_i2s_config_rstn
  1252. tmp_add_data |= 0 << 6; // [6] Rsvd
  1253. tmp_add_data |= 0 << 4; // [5:4] rx_acr_rst_config[1:0]
  1254. tmp_add_data |= 0 << 3; // [3] ~rx_config_eye_rstn_ch3
  1255. tmp_add_data |= 0 << 2; // [2] ~rx_config_eye_rstn_ch2
  1256. tmp_add_data |= 0 << 1; // [1] ~rx_config_eye_rstn_ch1
  1257. tmp_add_data |= 0 << 0; // [0] ~rx_config_eye_rstn_ch0
  1258. hdmi_wr_reg(RX_BASE_ADDR+0xe4, tmp_add_data); // 0x00
  1259. //task_rx_key_setting();
  1260. HDMIRX_HW_LOG("[HDMIRX Init] Setting HDMI RX EDID\n");
  1261. task_rx_edid_setting();
  1262. //printk("[HDMIRX Init] HDMI RX EDID Setting is done\n");
  1263. // Set RX video/pixel/audio/packet source to DATA_PATH
  1264. hdmi_wr_reg(RX_CORE_DATA_CAPTURE_2, 0x0000 );
  1265. // Port Enable
  1266. tmp_add_data = 0;
  1267. tmp_add_data |= 0 << 7; // [7] cdr3_force_datafd_data
  1268. tmp_add_data |= 0 << 6; // [6] cdr2_force_datafd_data
  1269. tmp_add_data |= 0 << 5; // [5] cdr1_force_datafd_data
  1270. tmp_add_data |= 0 << 4; // [4] cdr0_force_datafd_data
  1271. tmp_add_data |= 0 << 3; // [3] rsvd
  1272. tmp_add_data |= hdmirx_hw_stru.port << 0; // [2:0] port_en [2:0]
  1273. if(switch_mode&0x10){
  1274. hdmi_wr_reg(RX_BASE_ADDR+0x005, tmp_add_data); // 0x04
  1275. }
  1276. // Set CDR ch0 pixel_clk / tmds_clk ratio
  1277. tmp_add_data = 0;
  1278. tmp_add_data |= 0 << 5; // [7:5] hogg_adj ??
  1279. tmp_add_data |= 0 << 2; // [4:2] dp_div_cfg
  1280. tmp_add_data |= RX_INPUT_COLOR_DEPTH << 0; // [1:0] hdmi_div_cfg: pixel_clk/tmds_clk
  1281. //hdmi_wr_reg(RX_BASE_ADDR+0x865, tmp_add_data); // 0x01 //analog module init, removed
  1282. // Enable CDR ch0
  1283. tmp_add_data = 0;
  1284. tmp_add_data |= 1 << 5; // [5] cdr0_en_clk_ch
  1285. //hdmi_wr_reg(RX_BASE_ADDR+0x866, tmp_add_data); // 0x20 //analog module init, removed
  1286. // Set CDR ch1 pixel_clk / tmds_clk ratio
  1287. tmp_add_data = 0;
  1288. tmp_add_data |= 0 << 5; // [7:5] hogg_adj ??
  1289. tmp_add_data |= 0 << 2; // [4:2] dp_div_cfg
  1290. tmp_add_data |= RX_INPUT_COLOR_DEPTH << 0; // [1:0] hdmi_div_cfg: pixel_clk/tmds_clk
  1291. //hdmi_wr_reg(RX_BASE_ADDR+0x86D, tmp_add_data); // 0x01 //analog module init, removed
  1292. // Enable CDR ch1
  1293. tmp_add_data = 0;
  1294. tmp_add_data |= 0 << 5; // [5] cdr1_en_clk_ch
  1295. //hdmi_wr_reg(RX_BASE_ADDR+0x86E, tmp_add_data); // 0x00 //analog module init, removed
  1296. // Set CDR ch2 pixel_clk / tmds_clk ratio
  1297. tmp_add_data = 0;
  1298. tmp_add_data |= 0 << 5; // [7:5] hogg_adj ??
  1299. tmp_add_data |= 0 << 2; // [4:2] dp_div_cfg
  1300. tmp_add_data |= RX_INPUT_COLOR_DEPTH << 0; // [1:0] hdmi_div_cfg: pixel_clk/tmds_clk
  1301. //hdmi_wr_reg(RX_BASE_ADDR+0x875, tmp_add_data); // 0x01 //analog module init, removed
  1302. // Enable CDR ch2
  1303. tmp_add_data = 0;
  1304. tmp_add_data |= 0 << 5; // [5] cdr2_en_clk_ch
  1305. //hdmi_wr_reg(RX_BASE_ADDR+0x876, tmp_add_data); // 0x00 //analog module init, removed
  1306. // Set CDR ch3 pixel_clk / tmds_clk ratio
  1307. tmp_add_data = 0;
  1308. tmp_add_data |= 0 << 5; // [7:5] hogg_adj ??
  1309. tmp_add_data |= 0 << 2; // [4:2] dp_div_cfg
  1310. tmp_add_data |= RX_INPUT_COLOR_DEPTH << 0; // [1:0] hdmi_div_cfg: pixel_clk/tmds_clk
  1311. //hdmi_wr_reg(RX_BASE_ADDR+0x87D, tmp_add_data); // 0x01 //analog module init, removed
  1312. // Enable CDR ch3
  1313. tmp_add_data = 0;
  1314. tmp_add_data |= 0 << 5; // [5] cdr3_en_clk_ch
  1315. //hdmi_wr_reg(RX_BASE_ADDR+0x87E, tmp_add_data); // 0x00 //analog module init, removed
  1316. // Enable AFE FIFO
  1317. tmp_add_data = 0;
  1318. tmp_add_data |= 0xf << 0; // [3:0] hdmidp_rx_afe_connect.fifo_enable
  1319. #ifdef FIFO_BYPASS
  1320. hdmi_wr_reg(RX_BASE_ADDR+0xA1, 0xf0);
  1321. #elif (!(defined FIFO_ENABLE_AFTER_RESET))
  1322. hdmi_wr_reg(RX_BASE_ADDR+0xA1, tmp_add_data); // 0x0f
  1323. #endif
  1324. // CHANNEL_SWITCH A4
  1325. tmp_add_data = 0;
  1326. tmp_add_data |= 0 << 0; // [0] polarity_0
  1327. tmp_add_data |= 0 << 1; // [1] polarity_1
  1328. tmp_add_data |= 0 << 2; // [2] polarity_2
  1329. tmp_add_data |= 0 << 3; // [3] polarity_3
  1330. tmp_add_data |= 0 << 4; // [4] bitswap_0
  1331. tmp_add_data |= 0 << 5; // [5] bitswap_1
  1332. tmp_add_data |= 0 << 6; // [6] bitswap_2
  1333. tmp_add_data |= 0 << 7; // [7] bitswap_3
  1334. hdmi_wr_reg(RX_BASE_ADDR+0x0A4, tmp_add_data); // 0x00
  1335. // CHANNEL_SWITCH A5
  1336. tmp_add_data = 0;
  1337. tmp_add_data |= 0 << 0; // [1:0] source_0
  1338. tmp_add_data |= 1 << 2; // [3:2] source_1
  1339. tmp_add_data |= 2 << 4; // [5:4] source_2
  1340. tmp_add_data |= 3 << 6; // [7:6] source_3
  1341. hdmi_wr_reg(RX_BASE_ADDR+0x0A5, tmp_add_data); // 0xe4
  1342. // CHANNEL_SWITCH A6
  1343. tmp_add_data = 0;
  1344. tmp_add_data |= 0 << 0; // [2:0] skew_0
  1345. tmp_add_data |= 0 << 3; // [3] enable_0
  1346. tmp_add_data |= 0 << 4; // [6:4] skew_1
  1347. tmp_add_data |= 1 << 7; // [7] enable_1
  1348. // hdmi_wr_reg(RX_BASE_ADDR+0x0A6, tmp_add_data); // 0x80
  1349. hdmi_wr_reg(RX_BASE_ADDR+0x0A6, 0x88); // annie
  1350. // CHANNEL_SWITCH A7
  1351. tmp_add_data = 0;
  1352. tmp_add_data |= 0 << 0; // [2:0] skew_2
  1353. tmp_add_data |= 1 << 3; // [3] enable_2
  1354. tmp_add_data |= 0 << 4; // [6:4] skew_3
  1355. tmp_add_data |= 1 << 7; // [7] enable_3
  1356. hdmi_wr_reg(RX_BASE_ADDR+0x0A7, tmp_add_data); // 0x88
  1357. tmp_add_data = 0;
  1358. tmp_add_data |= 0 << 7; // [7] Force DTV timing
  1359. tmp_add_data |= 0 << 6; // [6] Force Video Scan
  1360. tmp_add_data |= 0 << 5; // [5] Force Video field
  1361. tmp_add_data |= 0 << 0; // [4:0] Rsrv
  1362. hdmi_wr_reg(RX_VIDEO_DTV_TIMING, tmp_add_data); // 0x00
  1363. tmp_add_data = 0;
  1364. tmp_add_data |= 0 << 7; // [7] forced_default_phase
  1365. tmp_add_data |= 1 << 3; // [3] forced_color_depth
  1366. tmp_add_data |= RX_INPUT_COLOR_DEPTH << 0; // [1:0] color_depth_config
  1367. hdmi_wr_reg(RX_VIDEO_DTV_MODE, tmp_add_data); // 0x09
  1368. tmp_add_data = 0;
  1369. tmp_add_data |= RX_OUTPUT_COLOR_FORMAT << 6; // [7:6] output_color_format: 0=RGB444; 1=YCbCr444; 2=Rsrv; 3=YCbCr422.
  1370. tmp_add_data |= RX_INPUT_COLOR_FORMAT << 4; // [5:4] input_color_format: 0=RGB444; 1=YCbCr444; 2=Rsrv; 3=YCbCr422.
  1371. tmp_add_data |= RX_OUTPUT_COLOR_DEPTH << 2; // [3:2] output_color_depth: 0=24-b; 1=30-b; 2=36-b; 3=48-b.
  1372. tmp_add_data |= RX_INPUT_COLOR_DEPTH << 0; // [1:0] input_color_depth: 0=24-b; 1=30-b; 2=36-b; 3=48-b.
  1373. hdmi_wr_reg(RX_VIDEO_DTV_OPTION_L, tmp_add_data); // 0x55
  1374. tmp_add_data = 0;
  1375. tmp_add_data |= 0 << 4; // [7:4] Rsrv
  1376. tmp_add_data |= RX_OUTPUT_COLOR_RANGE << 2; // [3:2] output_color_range: 0=16-235/240; 1=16-240; 2=1-254; 3=0-255.
  1377. tmp_add_data |= RX_INPUT_COLOR_RANGE << 0; // [1:0] input_color_range: 0=16-235/240; 1=16-240; 2=1-254; 3=0-255.
  1378. hdmi_wr_reg(RX_VIDEO_DTV_OPTION_H, tmp_add_data); // 0x00
  1379. tmp_add_data = 0;
  1380. tmp_add_data |= 0 << 6; // [7:6] hdcp_source_select[1:0]
  1381. tmp_add_data |= 0 << 4; // [5:4] tmds_decode_source_select[1:0]
  1382. tmp_add_data |= 0 << 2; // [3:2] tmds_align_source_select[1:0]
  1383. tmp_add_data |= 0 << 0; // [1:0] tmds_channel_source_select[1:0]
  1384. hdmi_wr_reg(RX_CORE_DATA_CAPTURE_1, tmp_add_data); // 0x00
  1385. tmp_add_data = 0;
  1386. tmp_add_data |= 0 << 7; // [7] forced_hdmi
  1387. tmp_add_data |= 0 << 6; // [6] hdmi_config
  1388. tmp_add_data |= 0 << 5; // [5] hdmi_reset_enable
  1389. tmp_add_data |= 0 << 4; // [4] 1 rsvd
  1390. tmp_add_data |= 0 << 3; // [3] bit_swap
  1391. tmp_add_data |= 0 << 0; // [2:0] channel_swap[2:0]
  1392. hdmi_wr_reg(RX_TMDS_MODE, tmp_add_data); // 0x00
  1393. tmp_add_data = 0;
  1394. tmp_add_data |= 0 << 3; // [7:3] Rsrv
  1395. tmp_add_data |= 1 << 2; // [2] acr_div_adjust.adjust_enable
  1396. tmp_add_data |= 0 << 1; // [1] clock_adjust_fsm.glitch_filter_enable
  1397. tmp_add_data |= 0 << 0; // [2] clock_adjust_fsm.fsm_select
  1398. hdmi_wr_reg(RX_AUDIO_RSV2, tmp_add_data); // 0x04
  1399. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_K1_IN_4, 0x10);
  1400. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_K1_IN_6, 0x50); // [7:4] k0_in
  1401. // Configure Audio Clock Recovery scheme
  1402. tmp_add_data = 0;
  1403. tmp_add_data |= ACR_CONTROL_EXT << 7; // [7] clock_control_ext:
  1404. // 0=audio clocks are generated from the old clock_control module inside hdmi_rx_core;
  1405. // 1=audio clocks are generated from the new acr module outside hdmi_rx_core.
  1406. tmp_add_data |= 0 << 4; // [6:4] clock_control_config -- manual audio_fifo_status_source
  1407. tmp_add_data |= 0 << 3; // [3] clock_control_source: 0=from received info; 1=from registers.
  1408. tmp_add_data |= 0 << 2; // [2] audio_fifo_status_source: 0=from audio fifo status; 1=from bit[6:4].
  1409. tmp_add_data |= 0 << 1; // [1] Manual new_m_n
  1410. tmp_add_data |= 0 << 0; // [0] 1=force idle on internal clock_control module.
  1411. // Note: internal clock_control is automatically idle if ACR_CONTROL_EXT=1
  1412. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_FSM, tmp_add_data); // 0x80
  1413. // RX_SYS1_CLOCK_CONTROL_TIMER_0/1 mean differently depending on which ACR is used
  1414. if (ACR_CONTROL_EXT) {
  1415. tmp_add_data = (RX_I2S_8_CHANNEL? 16-1 : 64-1); // [7:0] acr_sample_clk_div[7:0]
  1416. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_TIMER_0, tmp_add_data); // 0x3f
  1417. tmp_add_data = 0;
  1418. tmp_add_data |= ((ACR_MODE==1)? 0 : ACR_MODE) << 6; // [7:6] acr_ref_clk_sel:
  1419. // 0=osc_ext_clk; 1=acr_pre_clk; 2=osc_int_clk/2; 3=osc_int_clk/4
  1420. tmp_add_data |= 0 << 4; // [5:4] Rsrv
  1421. tmp_add_data |= 0 << 0; // [3:0] acr_sample_clk_div[11:8]
  1422. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_TIMER_1, tmp_add_data); // 0xc0
  1423. } else {
  1424. tmp_add_data = 0;
  1425. tmp_add_data |= 3 << 4; // [7:4] clock_control.cycles_per_iter[3:0]
  1426. tmp_add_data |= 9 << 0; // [3:0] clock_control.meas_tolerance[3:0]
  1427. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_TIMER_0, tmp_add_data);
  1428. tmp_add_data = 51; // CLK_CNTRL_UPDATE_TIMER
  1429. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_TIMER_1, tmp_add_data);
  1430. }
  1431. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_N_EXP_0, 186);
  1432. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_N_EXP_1, 104);
  1433. hdmi_wr_reg(RX_SYS1_CLOCK_CONTROL_M_EXP_1, 16);
  1434. // div_main[7:0]. Set it to close to actual result to speed up audio clock recovery.
  1435. hdmi_wr_reg(RX_BASE_ADDR+0x9E, 0x01);
  1436. tmp_add_data = 0;
  1437. tmp_add_data |= (RX_I2S_8_CHANNEL? 0 : 2) << 6; // rx_audio_master_div_sel[3:2]: audio_sample_clk ratio; 0=master/16 for 8-ch I2S, 1=master/32, 2=master/64 for 2-ch I2S, 3=master/128
  1438. tmp_add_data |= 0 << 4; // rx_audio_master_div_sel[1:0]: i2s_clk ratio; 0=master/2, 1=master/4, 2=master/8, 3=master/16
  1439. tmp_add_data |= 0 << 0; // div_main[11:8]
  1440. hdmi_wr_reg(RX_BASE_ADDR+0x9F, tmp_add_data); // 0x00
  1441. tmp_add_data = 0;
  1442. tmp_add_data |= 3 << 4; // [7:4] depth[3:0]
  1443. tmp_add_data |= 3 << 2; // [3:2] crit_threshold[1:0]
  1444. tmp_add_data |= 1 << 0; // [1:0] nom_threshold[1:0]
  1445. hdmi_wr_reg(RX_AUDIO_FIFO, tmp_add_data); // 0x3d
  1446. hdmi_wr_reg(RX_AUDIO_RSV1, 16); // RX_CLOCK_ADJUST[7:0]
  1447. tmp_add_data = RX_I2S_8_CHANNEL ? 0xff : 0x03; // RX_AUDIO_CHANNEL_ALLOC[7:0]
  1448. hdmi_wr_reg(RX_AUDIO_SAMPLE, tmp_add_data);
  1449. tmp_add_data = 0;
  1450. tmp_add_data |= 0 << 7; // [7] forced_audio_fifo_clear
  1451. tmp_add_data |= 1 << 6; // [6] auto_audio_fifo_clear
  1452. tmp_add_data |= 0 << 0; // [5:0] Rsrv
  1453. hdmi_wr_reg(RX_AUDIO_CONTROL, tmp_add_data); // 0x40
  1454. tmp_add_data = 0;
  1455. tmp_add_data |= RX_I2S_SPDIF << 7; // I2S | SPDIF
  1456. tmp_add_data |= RX_I2S_8_CHANNEL<< 6; // 8 channel | 2 channel
  1457. tmp_add_data |= 2 << 4; // serial format[1:0]
  1458. tmp_add_data |= 3 << 2; // bit width[1:0]
  1459. tmp_add_data |= 0 << 1; // WS polarity: 0=WS low is left; 1=WS high is left
  1460. tmp_add_data |= 1 << 0; // channel status manual | auto
  1461. hdmi_wr_reg(RX_AUDIO_FORMAT, tmp_add_data); // 0xed
  1462. /*
  1463. if(RX_I2S_SPDIF) {
  1464. tmp_add_data = 1;
  1465. hdmi_wr_reg(RX_AUDIO_I2S, tmp_add_data);
  1466. } else {
  1467. tmp_add_data = 1;
  1468. hdmi_wr_reg(RX_AUDIO_SPDIF, tmp_add_data);
  1469. }
  1470. */
  1471. hdmi_wr_reg(RX_AUDIO_I2S, 0x0);
  1472. hdmi_wr_reg(RX_AUDIO_SPDIF, 0x0);
  1473. tmp_add_data = 0x00; // tmds_clock_meter.ref_cycles[7:0]
  1474. hdmi_wr_reg(RX_BASE_ADDR+0x64, tmp_add_data);
  1475. tmp_add_data = 0x10; // tmds_clock_meter.ref_cycles[15:8]
  1476. hdmi_wr_reg(RX_BASE_ADDR+0x65, tmp_add_data);
  1477. tmp_add_data = 0; // tmds_clock_meter.ref_cycles[23:16]
  1478. hdmi_wr_reg(RX_BASE_ADDR+0x66, tmp_add_data);
  1479. tmp_add_data = 0;
  1480. tmp_add_data |= 0 << 7; // [7] forced_tmds_clock_int
  1481. tmp_add_data |= 0 << 6; // [6] tmds_clock_int_config
  1482. tmp_add_data |= 0 << 5; // [5] tmds_clock_int_forced_clear
  1483. tmp_add_data |= 1 << 4; // [4] tmds_clock_int_auto_clear
  1484. tmp_add_data |= 0x9 << 0; // [3:0] tmds_clock_meter.meas_tolerance[3:0]
  1485. hdmi_wr_reg(RX_BASE_ADDR+0x67, tmp_add_data); // 0x19
  1486. //tmp_add_data = 9; // time_divider[7:0] for DDC I2C bus clock
  1487. tmp_add_data = 1; // time_divider[7:0] for DDC I2C bus clock
  1488. hdmi_wr_reg(RX_HDCP_CONFIG3, tmp_add_data);
  1489. tmp_add_data = 0;
  1490. tmp_add_data |= 0 << 6; // [7:6] feed_through_mode
  1491. tmp_add_data |= 0 << 5; // [5] gated_hpd
  1492. #ifdef HPD_AUTO_MODE
  1493. tmp_add_data |= 0 << 4; // [4] forced_hpd
  1494. #else
  1495. tmp_add_data |= 1 << 4; // [4] forced_hpd
  1496. #endif
  1497. //if(switch_mode&0x20){
  1498. // tmp_add_data |= 1<<3;
  1499. // }
  1500. //else{
  1501. tmp_add_data |= 0<< 3; // [3] hpd_config
  1502. //}
  1503. tmp_add_data |= 1 << 2; // [2] forced_ksv:0=automatic read after hpd; 1=manually triggered read
  1504. tmp_add_data |= 1 << 1; // [1] ksv_config:0=disable; 1=enable
  1505. tmp_add_data |= 0 << 0; // [0] read_km
  1506. hdmi_wr_reg(RX_HDCP_CONFIG0, tmp_add_data); // 0x06
  1507. }
  1508. static void set_hdmi_audio_source_gate(unsigned char enable)
  1509. {
  1510. if(enable){
  1511. if(RX_I2S_SPDIF) {
  1512. hdmi_wr_reg(RX_AUDIO_I2S, 0x1);
  1513. } else {
  1514. hdmi_wr_reg(RX_AUDIO_SPDIF, 0x1);
  1515. }
  1516. }
  1517. else{
  1518. hdmi_wr_reg(RX_AUDIO_I2S, 0x0);
  1519. hdmi_wr_reg(RX_AUDIO_SPDIF, 0x0);
  1520. }
  1521. }
  1522. static unsigned char is_aud_buf_ptr_change(void)
  1523. {
  1524. unsigned char ret = 0;
  1525. static unsigned audin_fifo_ptr_pre = 0;
  1526. if((hdmi_rd_reg(RX_AUDIO_I2S)==1)||
  1527. (hdmi_rd_reg(RX_AUDIO_SPDIF)==1)){
  1528. if(audin_fifo_ptr_pre!=Rd(AUDIN_FIFO0_PTR)){
  1529. ret = 1;
  1530. }
  1531. }
  1532. audin_fifo_ptr_pre=Rd(AUDIN_FIFO0_PTR);
  1533. return ret;
  1534. }
  1535. /*
  1536. static unsigned char is_no_error(void)
  1537. {
  1538. if((hdmi_rd_reg(RX_BASE_ADDR+0x170)==0)
  1539. &&(hdmi_rd_reg(RX_BASE_ADDR+0x171)==0)
  1540. &&(hdmi_rd_reg(RX_BASE_ADDR+0x172)==0)
  1541. &&(hdmi_rd_reg(RX_BASE_ADDR+0x173)==0)
  1542. &&(hdmi_rd_reg(RX_BASE_ADDR+0x174)==0)
  1543. ){
  1544. return 1;
  1545. }
  1546. return 0;
  1547. }
  1548. */
  1549. /*
  1550. hdmirx interface function
  1551. */
  1552. #ifdef GET_COLOR_DEPTH_WORK_AROUND
  1553. static unsigned char is_frame_packing_fmt(int vic)
  1554. {
  1555. unsigned char ret = 0;
  1556. if(is_frame_packing()){
  1557. if((vic == HDMI_720p60)||(vic == HDMI_1080i60)
  1558. ||(vic == HDMI_1080p24) || (vic == HDMI_720p50)
  1559. ||(vic == HDMI_1080i50)){
  1560. ret = 1;
  1561. }
  1562. }
  1563. return ret;
  1564. }
  1565. #endif
  1566. enum tvin_sig_fmt_e hdmirx_hw_get_fmt(void)
  1567. {
  1568. /* to do:
  1569. TVIN_SIG_FMT_HDMI_1280x720P_24Hz_FRAME_PACKING,
  1570. TVIN_SIG_FMT_HDMI_1280x720P_30Hz_FRAME_PACKING,
  1571. TVIN_SIG_FMT_HDMI_1920x1080P_24Hz_FRAME_PACKING,
  1572. TVIN_SIG_FMT_HDMI_1920x1080P_30Hz_FRAME_PACKING, // 150
  1573. */
  1574. unsigned char support_flag = 0;
  1575. enum tvin_sig_fmt_e fmt = TVIN_SIG_FMT_NULL;
  1576. unsigned int vic = hdmirx_hw_stru.cur_vic;
  1577. if(force_vic){
  1578. vic = force_vic;
  1579. }
  1580. else if(hdmirx_hw_stru.cur_vic == 0){
  1581. vic = hdmirx_hw_stru.guess_vic;
  1582. }
  1583. /* check format is in enable list */
  1584. if(vic>96){
  1585. if((format_en3>>(vic-96-1))&0x1){
  1586. support_flag = 1;
  1587. }
  1588. }
  1589. else if(vic>64){
  1590. if((format_en2>>(vic-64-1))&0x1){
  1591. support_flag = 1;
  1592. }
  1593. }
  1594. else if(vic>32){
  1595. if((format_en1>>(vic-32-1))&0x1){
  1596. support_flag = 1;
  1597. }
  1598. }
  1599. else{
  1600. if((format_en0>>(vic-1))&0x1){
  1601. support_flag = 1;
  1602. }
  1603. }
  1604. if(support_flag==0){
  1605. return TVIN_SIG_FMT_NULL;
  1606. }
  1607. /**/
  1608. switch(vic){
  1609. /* basic format */
  1610. case HDMI_640x480p60:
  1611. fmt = TVIN_SIG_FMT_HDMI_640x480P_60Hz;
  1612. break;
  1613. case HDMI_480p60: /*2*/
  1614. case HDMI_480p60_16x9: /*3*/
  1615. if(is_frame_packing()){
  1616. fmt = TVIN_SIG_FMT_HDMI_720x480P_60Hz_FRAME_PACKING;
  1617. }
  1618. else{
  1619. fmt = TVIN_SIG_FMT_HDMI_720x480P_60Hz;
  1620. }
  1621. break;
  1622. case HDMI_720p60: /*4*/
  1623. if(is_frame_packing()){
  1624. fmt = TVIN_SIG_FMT_HDMI_1280x720P_60Hz_FRAME_PACKING;
  1625. }
  1626. else{
  1627. fmt = TVIN_SIG_FMT_HDMI_1280x720P_60Hz;
  1628. }
  1629. break;
  1630. case HDMI_1080i60: /*5*/
  1631. if(is_frame_packing()){
  1632. fmt = TVIN_SIG_FMT_HDMI_1920x1080I_60Hz_FRAME_PACKING;
  1633. }
  1634. else{
  1635. fmt = TVIN_SIG_FMT_HDMI_1920x1080I_60Hz;
  1636. }
  1637. break;
  1638. case HDMI_480i60: /*6*/
  1639. case HDMI_480i60_16x9: /*7*/
  1640. fmt = TVIN_SIG_FMT_HDMI_1440x480I_60Hz;
  1641. break;
  1642. case HDMI_1080p60: /*16*/
  1643. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_60Hz;
  1644. break;
  1645. case HDMI_1080p24: /*32 */
  1646. if(is_frame_packing()){
  1647. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_24Hz_FRAME_PACKING;
  1648. }
  1649. else{
  1650. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_24Hz;
  1651. }
  1652. break;
  1653. case HDMI_576p50: /*17*/
  1654. case HDMI_576p50_16x9: /*18*/
  1655. if(is_frame_packing()){
  1656. fmt = TVIN_SIG_FMT_HDMI_720x576P_50Hz_FRAME_PACKING;
  1657. }
  1658. else{
  1659. fmt = TVIN_SIG_FMT_HDMI_720x576P_50Hz;
  1660. }
  1661. break;
  1662. case HDMI_720p50: /*19*/
  1663. if(is_frame_packing()){
  1664. fmt = TVIN_SIG_FMT_HDMI_1280x720P_50Hz_FRAME_PACKING;
  1665. }
  1666. else{
  1667. fmt = TVIN_SIG_FMT_HDMI_1280x720P_50Hz;
  1668. }
  1669. break;
  1670. case HDMI_1080i50: /*20*/
  1671. if(is_frame_packing()){
  1672. fmt = TVIN_SIG_FMT_HDMI_1920x1080I_50Hz_FRAME_PACKING;
  1673. }
  1674. else{
  1675. fmt = TVIN_SIG_FMT_HDMI_1920x1080I_50Hz_A;
  1676. }
  1677. break;
  1678. case HDMI_576i50: /*21*/
  1679. case HDMI_576i50_16x9: /*22*/
  1680. fmt = TVIN_SIG_FMT_HDMI_1440x576I_50Hz;
  1681. break;
  1682. case HDMI_1080p50: /*31*/
  1683. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_50Hz;
  1684. break;
  1685. case HDMI_1080p25: /*33*/
  1686. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_25Hz;
  1687. break;
  1688. case HDMI_1080p30: /*34*/
  1689. if(is_frame_packing()){
  1690. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_30Hz_FRAME_PACKING;
  1691. }
  1692. else{
  1693. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_30Hz;
  1694. }
  1695. break;
  1696. /* extend format */
  1697. case HDMI_1440x240p60:
  1698. case HDMI_1440x240p60_16x9:
  1699. fmt = TVIN_SIG_FMT_HDMI_1440x240P_60Hz;
  1700. break;
  1701. case HDMI_2880x480i60:
  1702. case HDMI_2880x480i60_16x9:
  1703. fmt = TVIN_SIG_FMT_HDMI_2880x480I_60Hz;
  1704. break;
  1705. case HDMI_2880x240p60:
  1706. case HDMI_2880x240p60_16x9:
  1707. fmt = TVIN_SIG_FMT_HDMI_2880x240P_60Hz;
  1708. break;
  1709. case HDMI_1440x480p60:
  1710. case HDMI_1440x480p60_16x9:
  1711. fmt = TVIN_SIG_FMT_HDMI_1440x480P_60Hz;
  1712. break;
  1713. case HDMI_1440x288p50:
  1714. case HDMI_1440x288p50_16x9:
  1715. fmt = TVIN_SIG_FMT_HDMI_1440x288P_50Hz;
  1716. break;
  1717. case HDMI_2880x576i50:
  1718. case HDMI_2880x576i50_16x9:
  1719. fmt = TVIN_SIG_FMT_HDMI_2880x576I_50Hz;
  1720. break;
  1721. case HDMI_2880x288p50:
  1722. case HDMI_2880x288p50_16x9:
  1723. fmt = TVIN_SIG_FMT_HDMI_2880x288P_50Hz;
  1724. break;
  1725. case HDMI_1440x576p50:
  1726. case HDMI_1440x576p50_16x9:
  1727. fmt = TVIN_SIG_FMT_HDMI_1440x576P_50Hz;
  1728. break;
  1729. case HDMI_2880x480p60:
  1730. case HDMI_2880x480p60_16x9:
  1731. fmt = TVIN_SIG_FMT_HDMI_2880x480P_60Hz;
  1732. break;
  1733. case HDMI_2880x576p50:
  1734. case HDMI_2880x576p50_16x9:
  1735. fmt = TVIN_SIG_FMT_HDMI_2880x576P_60Hz; //????, should be TVIN_SIG_FMT_HDMI_2880x576P_50Hz
  1736. break;
  1737. case HDMI_1080i50_1250:
  1738. fmt = TVIN_SIG_FMT_HDMI_1920x1080I_50Hz_B;
  1739. break;
  1740. case HDMI_1080I120: /*46*/
  1741. fmt = TVIN_SIG_FMT_HDMI_1920x1080I_120Hz;
  1742. break;
  1743. case HDMI_720p120: /*47*/
  1744. fmt = TVIN_SIG_FMT_HDMI_1280x720P_120Hz;
  1745. break;
  1746. case HDMI_1080p120: /*63*/
  1747. fmt = TVIN_SIG_FMT_HDMI_1920x1080P_120Hz;
  1748. break;
  1749. /* vesa format*/
  1750. case HDMI_800_600: /*65*/
  1751. fmt = TVIN_SIG_FMT_HDMI_800x600;
  1752. break;
  1753. case HDMI_1024_768: /*66*/
  1754. fmt = TVIN_SIG_FMT_HDMI_1024x768;
  1755. break;
  1756. case HDMI_720_400:
  1757. fmt = TVIN_SIG_FMT_HDMI_720_400;
  1758. break;
  1759. case HDMI_1280_768:
  1760. fmt = TVIN_SIG_FMT_HDMI_1280_768;
  1761. break;
  1762. case HDMI_1280_800:
  1763. fmt = TVIN_SIG_FMT_HDMI_1280_800;
  1764. break;
  1765. case HDMI_1280_960:
  1766. fmt = TVIN_SIG_FMT_HDMI_1280_960;
  1767. break;
  1768. case HDMI_1280_1024:
  1769. fmt = TVIN_SIG_FMT_HDMI_1280_1024;
  1770. break;
  1771. case HDMI_1360_768:
  1772. fmt = TVIN_SIG_FMT_HDMI_1360_768;
  1773. break;
  1774. case HDMI_1366_768:
  1775. fmt = TVIN_SIG_FMT_HDMI_1366_768;
  1776. break;
  1777. case HDMI_1600_1200:
  1778. fmt = TVIN_SIG_FMT_HDMI_1600_1200;
  1779. break;
  1780. case HDMI_1920_1200:
  1781. fmt = TVIN_SIG_FMT_HDMI_1920_1200;
  1782. break;
  1783. default:
  1784. break;
  1785. }
  1786. return fmt;
  1787. }
  1788. int hdmirx_hw_get_color_fmt(void)
  1789. {
  1790. /*let vdin use rx "output color format" instead of "input color format" */
  1791. return hdmirx_hw_stru.cur_color_format;
  1792. }
  1793. int hdmirx_hw_get_3d_structure(unsigned char* _3d_structure, unsigned char* _3d_ext_data)
  1794. {
  1795. if((hdmirx_hw_stru.vendor_specific_info.identifier == 0x000c03)&&
  1796. (hdmirx_hw_stru.vendor_specific_info.hdmi_video_format == 0x2)){
  1797. *_3d_structure = hdmirx_hw_stru.vendor_specific_info._3d_structure;
  1798. *_3d_ext_data = hdmirx_hw_stru.vendor_specific_info._3d_ext_data;
  1799. return 0;
  1800. }
  1801. return -1;
  1802. }
  1803. static unsigned char dump_flag = 0;
  1804. static unsigned char is_frame_packing(void)
  1805. {
  1806. if((hdmirx_hw_stru.vendor_specific_info.identifier == 0x000c03)&&
  1807. (hdmirx_hw_stru.vendor_specific_info.hdmi_video_format == 0x2)&&
  1808. (hdmirx_hw_stru.vendor_specific_info._3d_structure == 0x0)){
  1809. return 1;
  1810. }
  1811. return 0;
  1812. }
  1813. int hdmirx_hw_get_pixel_repeat(void)
  1814. {
  1815. return hdmirx_hw_stru.cur_pixel_repeat+1;
  1816. }
  1817. static void read_video_timing(void)
  1818. {
  1819. hdmirx_hw_stru.video_status.active_pixels = hdmi_rd_reg(RX_VIDEO_ST_ACTIVE_PIXELS_1)|
  1820. ((hdmi_rd_reg(RX_VIDEO_ST_ACTIVE_PIXELS_2)&0xf)<<8);
  1821. hdmirx_hw_stru.video_status.front_pixels = hdmi_rd_reg(RX_VIDEO_ST_FRONT_PIXELS)|
  1822. (((hdmi_rd_reg(RX_VIDEO_ST_ACTIVE_PIXELS_2)>>4)&0xf)<<8);
  1823. hdmirx_hw_stru.video_status.hsync_pixels = hdmi_rd_reg(RX_VIDEO_ST_HSYNC_PIXELS)|
  1824. (((hdmi_rd_reg(RX_VIDEO_ST_VSYNC_LINES)>>6)&0x3)<<8);
  1825. hdmirx_hw_stru.video_status.back_pixels = hdmi_rd_reg(RX_VIDEO_ST_BACK_PIXELS)|
  1826. (((hdmi_rd_reg(RX_VIDEO_ST_SOF_LINES)>>6)&0x3)<<8);
  1827. hdmirx_hw_stru.video_status.active_lines = hdmi_rd_reg(RX_VIDEO_ST_ACTIVE_LINES_1)|
  1828. ((hdmi_rd_reg(RX_VIDEO_ST_ACTIVE_LINES_2)&0xf)<<8);;
  1829. hdmirx_hw_stru.video_status.eof_lines = hdmi_rd_reg(RX_VIDEO_ST_EOF_LINES)&0x3f;
  1830. hdmirx_hw_stru.video_status.vsync_lines = hdmi_rd_reg(RX_VIDEO_ST_VSYNC_LINES)&0x3f;
  1831. hdmirx_hw_stru.video_status.sof_lines = hdmi_rd_reg(RX_VIDEO_ST_SOF_LINES)&0x3f;
  1832. hdmirx_hw_stru.video_status.video_scan = (hdmi_rd_reg(RX_VIDEO_ST_DTV_TIMING)>>6)&0x1; /* 0, progressive; 1, interlaced */
  1833. hdmirx_hw_stru.video_status.video_field = (hdmi_rd_reg(RX_VIDEO_ST_DTV_TIMING)>>5)&0x1; /* progressive:0; interlace: 0, 1st; 1, 2nd */
  1834. hdmirx_hw_stru.video_status.scan_stable = (hdmi_rd_reg(RX_VIDEO_ST_DTV_TIMING)>>4)&0x1; /* 0, not stable; 1, stable */
  1835. hdmirx_hw_stru.video_status.lines_stable = (hdmi_rd_reg(RX_VIDEO_ST_DTV_TIMING)>>3)&0x1;
  1836. hdmirx_hw_stru.video_status.vsync_stable = (hdmi_rd_reg(RX_VIDEO_ST_DTV_TIMING)>>2)&0x1;
  1837. hdmirx_hw_stru.video_status.pixels_stable = (hdmi_rd_reg(RX_VIDEO_ST_DTV_TIMING)>>1)&0x1;
  1838. hdmirx_hw_stru.video_status.hsync_stable = (hdmi_rd_reg(RX_VIDEO_ST_DTV_TIMING)>>0)&0x1;
  1839. hdmirx_hw_stru.video_status.default_phase = (hdmi_rd_reg(RX_VIDEO_ST_DTV_MODE)>>7)&0x1;
  1840. hdmirx_hw_stru.video_status.pixel_phase = (hdmi_rd_reg(RX_VIDEO_ST_DTV_MODE)>>4)&0x7;
  1841. hdmirx_hw_stru.video_status.pixel_phase_ok = (hdmi_rd_reg(RX_VIDEO_ST_DTV_MODE)>>3)&0x1;
  1842. hdmirx_hw_stru.video_status.gc_error = (hdmi_rd_reg(RX_VIDEO_ST_DTV_MODE)>>2)&0x1; /* 0, no error; 1, error in packet data */
  1843. hdmirx_hw_stru.video_status.color_depth = (hdmi_rd_reg(RX_VIDEO_ST_DTV_MODE)>>0)&0x3; /* 0, 24bit; 1, 30bit; 2, 36 bit; 3, 48 bit */
  1844. if(memcmp(&hdmirx_hw_stru.video_status, &hdmirx_hw_stru.video_status_pre, sizeof(struct video_status_s))){
  1845. //dump_flag = 1;
  1846. }
  1847. memcpy(&hdmirx_hw_stru.video_status_pre, &hdmirx_hw_stru.video_status, sizeof(struct video_status_s));
  1848. }
  1849. static void dump_video_timing(void)
  1850. {
  1851. HDMIRX_HW_LOG("[HDMIRX Vidoe Timing]:\n");
  1852. HDMIRX_HW_LOG("[HDMIRX]active pixels %d, active lines %d\n",
  1853. hdmirx_hw_stru.video_status.active_pixels,
  1854. hdmirx_hw_stru.video_status.active_lines
  1855. );
  1856. HDMIRX_HW_LOG("[HDMIRX]front pixels %d, hsync pixels %d, back pixels %d, eof lines %d, vsync lines %d, sof lines %d\n",
  1857. hdmirx_hw_stru.video_status.front_pixels,
  1858. hdmirx_hw_stru.video_status.hsync_pixels,
  1859. hdmirx_hw_stru.video_status.back_pixels,
  1860. hdmirx_hw_stru.video_status.eof_lines,
  1861. hdmirx_hw_stru.video_status.vsync_lines,
  1862. hdmirx_hw_stru.video_status.sof_lines
  1863. );
  1864. HDMIRX_HW_LOG("[HDMIRX]scan %d, field %d\n",
  1865. hdmirx_hw_stru.video_status.video_scan,
  1866. hdmirx_hw_stru.video_status.video_field
  1867. );
  1868. HDMIRX_HW_LOG("[HDMIRX]scan stable %d, lines stable %d, vsync stable %d, pixels stable %d, hsync stable %d\n",
  1869. hdmirx_hw_stru.video_status.scan_stable,
  1870. hdmirx_hw_stru.video_status.lines_stable,
  1871. hdmirx_hw_stru.video_status.vsync_stable,
  1872. hdmirx_hw_stru.video_status.pixels_stable,
  1873. hdmirx_hw_stru.video_status.hsync_stable
  1874. );
  1875. HDMIRX_HW_LOG("[HDMIRX]default phase %d, pixel phase %d, pixel phase ok %d, gc error %d, color_depth %d\n",
  1876. hdmirx_hw_stru.video_status.default_phase,
  1877. hdmirx_hw_stru.video_status.pixel_phase,
  1878. hdmirx_hw_stru.video_status.pixel_phase_ok,
  1879. hdmirx_hw_stru.video_status.gc_error,
  1880. hdmirx_hw_stru.video_status.color_depth);
  1881. }
  1882. static void read_tmds_clk(void)
  1883. {
  1884. int i;
  1885. unsigned int tmds_clock=0;
  1886. hdmi_wr_reg(RX_BASE_ADDR+0x64, 0x00);
  1887. hdmi_wr_reg(RX_BASE_ADDR+0x65, 0x08);
  1888. hdmi_wr_reg(RX_BASE_ADDR+0x66, 0x00);
  1889. hdmi_wr_reg(RX_BASE_ADDR+0x67, 0x10|0x4);
  1890. tmds_clock |= hdmi_rd_reg(RX_BASE_ADDR+0x1f4);
  1891. tmds_clock |= (hdmi_rd_reg(RX_BASE_ADDR+0x1f5)<<8);
  1892. tmds_clock |= (hdmi_rd_reg(RX_BASE_ADDR+0x1f6)<<16);
  1893. for(i = 0; i<(TMDS_CLK_HIS_SIZE-1); i++){
  1894. hdmirx_hw_stru.tmds_clk[i] = hdmirx_hw_stru.tmds_clk[i+1];
  1895. }
  1896. hdmirx_hw_stru.tmds_clk[i] = tmds_clock;
  1897. if(((hdmirx_log_flag&0x10)&&(hdmirx_hw_stru.state!=HDMIRX_HWSTATE_SIG_STABLE))
  1898. ||(hdmirx_log_flag&0x20)){
  1899. HDMIRX_HW_LOG("[HDMIRX tmds clock] %d\n", tmds_clock);
  1900. }
  1901. }
  1902. static unsigned char have_audio_info(void)
  1903. {
  1904. unsigned char ret = 0;
  1905. if(hdmi_rd_reg(RX_COREST_INTERRUPT_STATUS_0)&0x10){
  1906. ret = 1;
  1907. }
  1908. else{
  1909. ret = 0;
  1910. }
  1911. hdmi_wr_reg(RX_CORE_INTERRUPT_CLEAR_0, hdmi_rd_reg(RX_CORE_INTERRUPT_CLEAR_0)|0x10);
  1912. hdmi_wr_reg(RX_CORE_INTERRUPT_CLEAR_0, hdmi_rd_reg(RX_CORE_INTERRUPT_CLEAR_0)&(~0x10));
  1913. return ret;
  1914. }
  1915. static unsigned char is_audio_channel_status_valid(void)
  1916. {
  1917. if(have_audio_info()){
  1918. if((hdmirx_hw_stru.aud_info.cc == 0)
  1919. ||(hdmirx_hw_stru.aud_info.ss == 0)
  1920. // ||(hdmirx_hw_stru.aud_info.sf == 0)
  1921. ){
  1922. return 1;
  1923. }
  1924. }
  1925. return 0;
  1926. }
  1927. #ifdef FOR_LS_DIG2090__DVP_5986K
  1928. static void check_audio(void)
  1929. {
  1930. int i;
  1931. unsigned char channel_status_change;
  1932. unsigned char channel_status_all_0;
  1933. unsigned char channel_status_tmp;
  1934. channel_status_change = 0;
  1935. channel_status_all_0 = 1;
  1936. for(i=0; i<CHANNEL_STATUS_SIZE; i++){
  1937. if(hdmirx_hw_stru.aud_info.channel_status[i]!=0){
  1938. channel_status_all_0 = 0;
  1939. }
  1940. }
  1941. if(channel_status_all_0 == 0){
  1942. for(i=0; i<CHANNEL_STATUS_SIZE; i++){
  1943. if(hdmirx_hw_stru.aud_info.channel_status[i]!=hdmirx_hw_stru.aud_info.channel_status_bak[i]){
  1944. channel_status_change = 1;
  1945. }
  1946. hdmirx_hw_stru.aud_info.channel_status_bak[i]=hdmirx_hw_stru.aud_info.channel_status[i];
  1947. }
  1948. }
  1949. if(channel_status_change){
  1950. hdmirx_hw_stru.aud_channel_status_modify_count++;
  1951. hdmirx_hw_stru.aud_channel_status_unmodify_count = 0;
  1952. }
  1953. else if(hdmirx_hw_stru.aud_channel_status_unmodify_count > 0){
  1954. hdmirx_hw_stru.aud_channel_status_modify_count = 0;
  1955. }
  1956. else{
  1957. hdmirx_hw_stru.aud_channel_status_unmodify_count++;
  1958. }
  1959. if((channel_status_all_0)
  1960. &&(is_audio_channel_status_valid())
  1961. ){
  1962. hdmirx_hw_stru.aud_channel_status_all_0_count++;
  1963. if(is_aud_buf_ptr_change()){
  1964. hdmirx_hw_stru.aud_buf_ptr_change_count++;
  1965. }
  1966. }
  1967. else{
  1968. hdmirx_hw_stru.aud_channel_status_all_0_count=0;
  1969. hdmirx_hw_stru.aud_buf_ptr_change_count = 0;
  1970. }
  1971. }
  1972. #endif
  1973. typedef struct{
  1974. unsigned int sample_rate;
  1975. unsigned char aud_info_sf;
  1976. unsigned char channel_status_id;
  1977. }sample_rate_info_t;
  1978. sample_rate_info_t sample_rate_info[]=
  1979. {
  1980. {32000, 0x1, 0x3},
  1981. {44100, 0x2, 0x0},
  1982. {48000, 0x3, 0x2},
  1983. {88200, 0x4, 0x8},
  1984. {96000, 0x5, 0xa},
  1985. {176400, 0x6, 0xc},
  1986. {192000, 0x7, 0xe},
  1987. //{768000, 0, 0x9},
  1988. {0, 0, 0}
  1989. };
  1990. static unsigned is_use_audio_recover_clock(void)
  1991. {
  1992. if(internal_mode_valid()&&(internal_mode&INT_MODE_USE_AUD_INFO_FRAME))
  1993. return 0;
  1994. else
  1995. return 1;
  1996. }
  1997. static void read_audio_info(void)
  1998. {
  1999. int i;
  2000. /* get audio recovery clock */
  2001. hdmirx_hw_stru.aud_info.cts = ((hdmi_rd_reg(RX_SYSST0_NCTS_STATUS)&0xf)<<16)|
  2002. (hdmi_rd_reg(RX_SYSST0_CTS_STATUS_H)<<8)|
  2003. (hdmi_rd_reg(RX_SYSST0_CTS_STATUS_L));
  2004. hdmirx_hw_stru.aud_info.n = (hdmi_rd_reg(RX_SYSST0_N_STATUS_H)<<12)|
  2005. (hdmi_rd_reg(RX_SYSST0_N_STATUS_L)<<4)|
  2006. ((hdmi_rd_reg(RX_SYSST0_NCTS_STATUS)>>4)&0xf);
  2007. if(hdmirx_hw_stru.aud_info.cts!=0){
  2008. hdmirx_hw_stru.aud_info.audio_recovery_clock = (get_freq()/hdmirx_hw_stru.aud_info.cts)
  2009. *hdmirx_hw_stru.aud_info.n/128;
  2010. }
  2011. else{
  2012. hdmirx_hw_stru.aud_info.audio_recovery_clock = 0;
  2013. }
  2014. /* audio info frame */
  2015. hdmirx_hw_stru.aud_info.cc = hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR + 1)&0x7;
  2016. hdmirx_hw_stru.aud_info.ct = (hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR + 1)>>4)&0xf;
  2017. hdmirx_hw_stru.aud_info.ss = hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR + 2)&0x3;
  2018. hdmirx_hw_stru.aud_info.sf = (hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR + 2)>>2)&0x7;
  2019. /* channel status */
  2020. for(i=0; i<CHANNEL_STATUS_SIZE; i++){
  2021. hdmirx_hw_stru.aud_info.channel_status[i] = hdmi_rd_reg(RX_IEC60958_ST_SUB1_OFFSET + i);
  2022. }
  2023. /*parse audio info*/
  2024. if(hdmirx_hw_stru.aud_info.cc == 0){
  2025. hdmirx_hw_stru.aud_info.channel_num = hdmirx_hw_stru.aud_info.channel_status[2]&0xf;
  2026. }
  2027. else{
  2028. hdmirx_hw_stru.aud_info.channel_num = hdmirx_hw_stru.aud_info.cc + 1;
  2029. }
  2030. if(hdmirx_hw_stru.aud_info.ct == 0){
  2031. }
  2032. else{
  2033. if(hdmirx_hw_stru.aud_info.ct == 1){ //pcm
  2034. }
  2035. else{
  2036. HDMIRX_HW_LOG("[HDMIRX] Audio ct of %x , not support\n", hdmirx_hw_stru.aud_info.ct);
  2037. }
  2038. }
  2039. if(hdmirx_hw_stru.aud_info.ss == 0){
  2040. switch(hdmirx_hw_stru.aud_info.channel_status[4]&0xf){
  2041. case 0x2:
  2042. hdmirx_hw_stru.aud_info.sample_size = 16;
  2043. break;
  2044. case 0x3:
  2045. hdmirx_hw_stru.aud_info.sample_size = 20;
  2046. break;
  2047. case 0xb:
  2048. hdmirx_hw_stru.aud_info.sample_size = 24;
  2049. break;
  2050. }
  2051. }
  2052. else{
  2053. hdmirx_hw_stru.aud_info.sample_size = 12 + (hdmirx_hw_stru.aud_info.ss*4);
  2054. }
  2055. if(hdmirx_hw_stru.aud_info.sf == 0){
  2056. for(i=0; sample_rate_info[i].sample_rate; i++){
  2057. if((hdmirx_hw_stru.aud_info.channel_status[3]&0xf) ==
  2058. sample_rate_info[i].channel_status_id){
  2059. hdmirx_hw_stru.aud_info.sample_rate = sample_rate_info[i].sample_rate;
  2060. break;
  2061. }
  2062. }
  2063. }
  2064. else{
  2065. for(i=0; sample_rate_info[i].sample_rate; i++){
  2066. if(hdmirx_hw_stru.aud_info.sf ==
  2067. sample_rate_info[i].aud_info_sf){
  2068. hdmirx_hw_stru.aud_info.sample_rate = sample_rate_info[i].sample_rate;
  2069. break;
  2070. }
  2071. }
  2072. }
  2073. if((hdmirx_hw_stru.aud_info.audio_recovery_clock!=0)&&
  2074. is_use_audio_recover_clock()){
  2075. hdmirx_hw_stru.aud_info.real_sample_rate = hdmirx_hw_stru.aud_info.audio_recovery_clock;
  2076. for(i=0; sample_rate_info[i].sample_rate; i++){
  2077. if(hdmirx_hw_stru.aud_info.audio_recovery_clock > sample_rate_info[i].sample_rate){
  2078. if((hdmirx_hw_stru.aud_info.audio_recovery_clock-sample_rate_info[i].sample_rate)<sample_rate_change_th){
  2079. hdmirx_hw_stru.aud_info.real_sample_rate = sample_rate_info[i].sample_rate;
  2080. break;
  2081. }
  2082. }
  2083. else{
  2084. if((sample_rate_info[i].sample_rate - hdmirx_hw_stru.aud_info.audio_recovery_clock)<sample_rate_change_th){
  2085. hdmirx_hw_stru.aud_info.real_sample_rate = sample_rate_info[i].sample_rate;
  2086. break;
  2087. }
  2088. }
  2089. }
  2090. }
  2091. else{
  2092. hdmirx_hw_stru.aud_info.real_sample_rate = hdmirx_hw_stru.aud_info.sample_rate;
  2093. }
  2094. }
  2095. static unsigned char is_sample_rate_change(int sample_rate_pre, int sample_rate_cur)
  2096. {
  2097. unsigned char ret = 0;
  2098. if((sample_rate_cur!=0)&&
  2099. (sample_rate_cur>31000)&&(sample_rate_cur<193000)){
  2100. if(sample_rate_pre > sample_rate_cur){
  2101. if((sample_rate_pre - sample_rate_cur)> sample_rate_change_th){
  2102. ret = 1;
  2103. }
  2104. }
  2105. else{
  2106. if((sample_rate_cur - sample_rate_pre)> sample_rate_change_th){
  2107. ret = 1;
  2108. }
  2109. }
  2110. }
  2111. return ret;
  2112. }
  2113. static void dump_audio_info(void)
  2114. {
  2115. //int audio_master_clock = clk_util_clk_msr(24,50);
  2116. HDMIRX_HW_LOG("[HDMIRX AUD Info] cc %x, ct %x, ss %x, sf %x\n",
  2117. hdmirx_hw_stru.aud_info.cc, hdmirx_hw_stru.aud_info.ct, hdmirx_hw_stru.aud_info.ss, hdmirx_hw_stru.aud_info.sf);
  2118. HDMIRX_HW_LOG("[HDMIRX] channel status[0,1,2,3,4,5]%02x %02x %02x %02x %02x %02x\n",
  2119. hdmirx_hw_stru.aud_info.channel_status[0], hdmirx_hw_stru.aud_info.channel_status[1], hdmirx_hw_stru.aud_info.channel_status[2],
  2120. hdmirx_hw_stru.aud_info.channel_status[3], hdmirx_hw_stru.aud_info.channel_status[4], hdmirx_hw_stru.aud_info.channel_status[5]);
  2121. HDMIRX_HW_LOG("[HDMIRX] channel num %d, sample rate %d, sample size %d\n",
  2122. hdmirx_hw_stru.aud_info.channel_num, hdmirx_hw_stru.aud_info.sample_rate, hdmirx_hw_stru.aud_info.sample_size);
  2123. HDMIRX_HW_LOG("[HDMIRX] audio infoframe raw %s: %02x %02x %02x %02x %02x %02x %02x %02x\n",
  2124. have_audio_info()?"":"(not come)",
  2125. hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR), hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR+1),
  2126. hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR+2), hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR+3),
  2127. hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR+4), hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR+5),
  2128. hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR+6), hdmi_rd_reg(RX_PKT_REG_AUDIO_INFO_BASE_ADDR+7));
  2129. HDMIRX_HW_LOG("[HDMIRX]CTS %d N %d, audio recovery clock %d\n", hdmirx_hw_stru.aud_info.cts,
  2130. hdmirx_hw_stru.aud_info.n, hdmirx_hw_stru.aud_info.audio_recovery_clock);
  2131. HDMIRX_HW_LOG("[HDMIRX] real_sample_rate is %d\n", hdmirx_hw_stru.aud_info.real_sample_rate);
  2132. //HDMIRX_HW_LOG("[HDMIRX] audio master clock (%d/128)=%d\n", audio_master_clock, audio_master_clock/128);
  2133. }
  2134. static unsigned char have_avi_info(void)
  2135. {
  2136. unsigned char ret = 0;
  2137. if(hdmi_rd_reg(RX_COREST_INTERRUPT_STATUS_0)&0x8){
  2138. ret = 1;
  2139. }
  2140. else{
  2141. ret = 0;
  2142. }
  2143. hdmi_wr_reg(RX_CORE_INTERRUPT_CLEAR_0, hdmi_rd_reg(RX_CORE_INTERRUPT_CLEAR_0)|0x8);
  2144. hdmi_wr_reg(RX_CORE_INTERRUPT_CLEAR_0, hdmi_rd_reg(RX_CORE_INTERRUPT_CLEAR_0)&(~0x8));
  2145. return ret;
  2146. }
  2147. static void read_avi_info(void)
  2148. {
  2149. hdmirx_hw_stru.avi_info.color_format = (hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+1) & 0x60) >> 5;
  2150. hdmirx_hw_stru.avi_info.cc = (hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+2) & 0xc0) >> 6;
  2151. hdmirx_hw_stru.avi_info.color_range = (hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+3) & 0x0c) >> 2;
  2152. hdmirx_hw_stru.avi_info.vic = hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+4) & 0x7f;
  2153. hdmirx_hw_stru.avi_info.pixel_repeat = hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+5) & 0x0f;
  2154. // Patch for 1080P25Hz vic error issue
  2155. if(hdmirx_hw_stru.avi_info.vic == 32){
  2156. unsigned int sig_h_total = hdmirx_hw_stru.video_status.front_pixels +
  2157. hdmirx_hw_stru.video_status.hsync_pixels +
  2158. hdmirx_hw_stru.video_status.active_pixels +
  2159. hdmirx_hw_stru.video_status.back_pixels;
  2160. unsigned int sig_v_total = hdmirx_hw_stru.video_status.sof_lines +
  2161. hdmirx_hw_stru.video_status.vsync_lines +
  2162. hdmirx_hw_stru.video_status.active_lines +
  2163. hdmirx_hw_stru.video_status.eof_lines;
  2164. if ((ABS((signed int)sig_h_total- (signed int)tvin_fmt_tbl[TVIN_SIG_FMT_HDMI_1920x1080P_25Hz].h_total) <= 15) &&
  2165. (ABS((signed int)sig_v_total- (signed int)tvin_fmt_tbl[TVIN_SIG_FMT_HDMI_1920x1080P_25Hz].v_total) <= 15)){
  2166. hdmirx_hw_stru.avi_info.vic = 33;
  2167. //printk("change vic\n");
  2168. }
  2169. }
  2170. // Patch end
  2171. if((color_format_mode>=0) && (color_format_mode<=3)){
  2172. hdmirx_hw_stru.cur_color_format = color_format_mode;
  2173. }
  2174. else{
  2175. hdmirx_hw_stru.cur_color_format = hdmirx_hw_stru.avi_info.color_format;
  2176. }
  2177. if(memcmp(&hdmirx_hw_stru.avi_info, &hdmirx_hw_stru.avi_info_pre, sizeof(struct avi_info_s))){
  2178. dump_flag = 1;
  2179. hdmirx_hw_stru.avi_info_change_flag = 1;
  2180. }
  2181. memcpy(&hdmirx_hw_stru.avi_info_pre, &hdmirx_hw_stru.avi_info, sizeof(struct avi_info_s));
  2182. }
  2183. static void dump_avi_info(void)
  2184. {
  2185. HDMIRX_HW_LOG("[HDMIRX AVI Info %s] vic %d, repeat %d, color format %d, color range %d, cc %d\n\[HDMIRX]AVI raw:[%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x][%02x]\n",
  2186. have_avi_info()?"":"(not received)",
  2187. hdmirx_hw_stru.avi_info.vic, hdmirx_hw_stru.avi_info.pixel_repeat,
  2188. hdmirx_hw_stru.avi_info.color_format, hdmirx_hw_stru.avi_info.color_range, hdmirx_hw_stru.avi_info.cc,
  2189. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+1),
  2190. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+2),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+3),
  2191. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+4),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+5),
  2192. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+6),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+7),
  2193. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+8),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+9),
  2194. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+10),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+11),
  2195. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+12),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+13),
  2196. hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+14),hdmi_rd_reg(RX_PKT_REG_AVI_INFO_BASE_ADDR+15)
  2197. );
  2198. }
  2199. static unsigned char have_vendor_specific_info(void)
  2200. {
  2201. unsigned char ret = 0;
  2202. if(hdmi_rd_reg(RX_COREST_INTERRUPT_STATUS_0)&2){
  2203. ret = 1;
  2204. }
  2205. else{
  2206. ret = 0;
  2207. }
  2208. hdmi_wr_reg(RX_CORE_INTERRUPT_CLEAR_0, hdmi_rd_reg(RX_CORE_INTERRUPT_CLEAR_0)|0x2);
  2209. hdmi_wr_reg(RX_CORE_INTERRUPT_CLEAR_0, hdmi_rd_reg(RX_CORE_INTERRUPT_CLEAR_0)&(~0x2));
  2210. return ret;
  2211. }
  2212. static void read_vendor_specific_info_frame(void)
  2213. {
  2214. if(have_vendor_specific_info()){
  2215. hdmirx_hw_stru.vendor_specific_info.identifier = (hdmi_rd_reg(RX_PKT_REG_VEND_INFO_BASE_ADDR+3)<<16)|
  2216. (hdmi_rd_reg(RX_PKT_REG_VEND_INFO_BASE_ADDR+2)<<8)|
  2217. hdmi_rd_reg(RX_PKT_REG_VEND_INFO_BASE_ADDR+1);
  2218. hdmirx_hw_stru.vendor_specific_info.hdmi_video_format = (hdmi_rd_reg(RX_PKT_REG_VEND_INFO_BASE_ADDR+4) & 0xe0) >> 5;
  2219. hdmirx_hw_stru.vendor_specific_info._3d_structure = (hdmi_rd_reg(RX_PKT_REG_VEND_INFO_BASE_ADDR+5) & 0xf0) >> 4;
  2220. hdmirx_hw_stru.vendor_specific_info._3d_ext_data = (hdmi_rd_reg(RX_PKT_REG_VEND_INFO_BASE_ADDR+6) & 0xf0) >> 4;
  2221. }
  2222. else{
  2223. hdmirx_hw_stru.vendor_specific_info.identifier = 0;
  2224. hdmirx_hw_stru.vendor_specific_info.hdmi_video_format = 0;
  2225. hdmirx_hw_stru.vendor_specific_info._3d_structure = 0;
  2226. hdmirx_hw_stru.vendor_specific_info._3d_ext_data = 0;
  2227. }
  2228. if(memcmp(&hdmirx_hw_stru.vendor_specific_info, &hdmirx_hw_stru.vendor_specific_info_pre, sizeof(struct vendor_specific_info_s))){
  2229. dump_flag = 1;
  2230. }
  2231. memcpy(&hdmirx_hw_stru.vendor_specific_info_pre, &hdmirx_hw_stru.vendor_specific_info, sizeof(struct vendor_specific_info_s));
  2232. }
  2233. static void dump_vendor_specific_info_frame(void)
  2234. {
  2235. HDMIRX_HW_LOG("[HDMIRX Vendor Specific Info] identifier %x, video_format %x, 3d_structure %x, ext_data %x\n",
  2236. hdmirx_hw_stru.vendor_specific_info.identifier,
  2237. hdmirx_hw_stru.vendor_specific_info.hdmi_video_format,
  2238. hdmirx_hw_stru.vendor_specific_info._3d_structure,
  2239. hdmirx_hw_stru.vendor_specific_info._3d_ext_data );
  2240. }
  2241. static unsigned char dump_temp_buffer[128];
  2242. static void dump_tmds_clk(void)
  2243. {
  2244. int i;
  2245. int tmplen = 0;
  2246. HDMIRX_HW_LOG("[HDMIRX Tmds Clk]:\n");
  2247. for(i=0; i<TMDS_CLK_HIS_SIZE; i++){
  2248. tmplen += sprintf(dump_temp_buffer+tmplen, "%d ", hdmirx_hw_stru.tmds_clk[i]);
  2249. if(((i+1)&0xf)==0){
  2250. HDMIRX_HW_LOG("[HDMIRX]%s\n", dump_temp_buffer);
  2251. tmplen = 0;
  2252. }
  2253. }
  2254. }
  2255. static void dump_ecc_status(void)
  2256. {
  2257. HDMIRX_HW_LOG("[HDMIRX ECC Status] %02x %02x %02x %02x %02x\n",
  2258. hdmi_rd_reg(RX_BASE_ADDR+0x170),
  2259. hdmi_rd_reg(RX_BASE_ADDR+0x171),
  2260. hdmi_rd_reg(RX_BASE_ADDR+0x172),
  2261. hdmi_rd_reg(RX_BASE_ADDR+0x173),
  2262. hdmi_rd_reg(RX_BASE_ADDR+0x174));
  2263. }
  2264. static void dump_state(unsigned int flag)
  2265. {
  2266. #ifdef FIFO_BYPASS
  2267. HDMIRX_HW_LOG("[HDMIRX] fifo_bypass ver %s, [0xa1]=%x\n", HDMIRX_VER, hdmi_rd_reg(RX_BASE_ADDR+0xA1));
  2268. #elif (defined FIFO_ENABLE_AFTER_RESET)
  2269. HDMIRX_HW_LOG("[HDMIRX] fifo_enable_after_reset ver %s, [0xa1]=%x\n", HDMIRX_VER, hdmi_rd_reg(RX_BASE_ADDR+0xA1));
  2270. #else
  2271. HDMIRX_HW_LOG("[HDMIRX] ver %s, eq_mode=%d, internal_mode=%x, eq_confit=%x, [0xa1]=%x\n", HDMIRX_VER,
  2272. eq_mode, internal_mode, eq_config,
  2273. hdmi_rd_reg(RX_BASE_ADDR+0xA1));
  2274. #endif
  2275. if(flag&DUMP_FLAG_VIDEO_TIMING){
  2276. read_video_timing();
  2277. dump_video_timing();
  2278. }
  2279. if(flag&DUMP_FLAG_AVI_INFO){
  2280. read_avi_info();
  2281. dump_avi_info();
  2282. }
  2283. if(flag&DUMP_FLAG_VENDOR_SPEC_INFO){
  2284. read_vendor_specific_info_frame();
  2285. dump_vendor_specific_info_frame();
  2286. }
  2287. if(flag&DUMP_FLAG_AUDIO_INFO){
  2288. read_audio_info();
  2289. dump_audio_info();
  2290. }
  2291. if(flag&DUMP_FLAG_CLOCK_INFO){
  2292. HDMIRX_HW_LOG("[HDMIRX] tmds clock %d (%d), pixel clock %d, active pixels %d, active lines %d, [ALIGN_STATUS]=%x [AUTH_STATUS]=%x\n",
  2293. TMDS_CLK(hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1]),
  2294. hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1],
  2295. PIXEL_CLK,
  2296. hdmirx_hw_stru.video_status.active_pixels,
  2297. hdmirx_hw_stru.video_status.active_lines,
  2298. hdmi_rd_reg(RX_BASE_ADDR+0x1fb),
  2299. hdmi_rd_reg(RX_HDCP_ST_STATUS_3)
  2300. );
  2301. }
  2302. if(flag&DUMP_FLAG_ECC_STATUS){
  2303. dump_ecc_status();
  2304. }
  2305. }
  2306. #ifdef CONFIG_AML_AUDIO_DSP
  2307. #define M2B_IRQ0_DSP_AUDIO_EFFECT (7)
  2308. #define DSP_CMD_SET_HDMI_SR (6)
  2309. extern int mailbox_send_audiodsp(int overwrite,int num,int cmd,const char *data,int len);
  2310. #endif
  2311. #ifndef HPD_AUTO_MODE
  2312. #define DEASERT_HPD() hdmi_wr_reg(RX_HDCP_CONFIG0, hdmi_rd_reg(RX_HDCP_CONFIG0)&(~(1<<3)))
  2313. #else
  2314. #define DEASERT_HPD()
  2315. #endif
  2316. void hdmirx_hw_monitor(void)
  2317. {
  2318. unsigned int tx_5v_status;
  2319. int pre_sample_rate;
  2320. if(sm_pause){
  2321. return;
  2322. }
  2323. else if(hdmirx_hw_stru.prbs_enable){
  2324. hdmirx_hw_stru.prbs_check_wait_time -= HW_MONITOR_TIME_UNIT;
  2325. if(hdmirx_hw_stru.prbs_check_wait_time<=0){
  2326. hdmirx_hw_stru.prbs_check_wait_time = 1000;
  2327. hdmi_rx_prbs_detect(hdmirx_hw_stru.prbs_mode);
  2328. }
  2329. return;
  2330. }
  2331. else{
  2332. int prbs_mode_tmp = 0xf;
  2333. switch(hdmirx_hw_stru.port){
  2334. case 0x1:
  2335. prbs_mode_tmp = prbs_port_mode&0xf;
  2336. break;
  2337. case 0x2:
  2338. prbs_mode_tmp = (prbs_port_mode>>4)&0xf;
  2339. break;
  2340. case 0x4:
  2341. prbs_mode_tmp = (prbs_port_mode>>8)&0xf;
  2342. break;
  2343. }
  2344. if(prbs_mode_tmp != 0xf){
  2345. turn_on_prbs_mode(prbs_mode_tmp);
  2346. return;
  2347. }
  2348. }
  2349. tx_5v_status = hdmi_rd_reg(OTHER_BASE_ADDR + HDMI_OTHER_STATUS0)&hdmirx_hw_stru.port;
  2350. switch(hdmirx_hw_stru.state){
  2351. case HDMIRX_HWSTATE_INIT:
  2352. {
  2353. Wr(RESET2_REGISTER, Rd(RESET2_REGISTER)|(1<<15));
  2354. mdelay(10);
  2355. Wr(RESET2_REGISTER, Rd(RESET2_REGISTER)&(~(1<<15)));
  2356. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(3<<6));
  2357. hdmi_init();
  2358. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2359. HDMIRX_HW_LOG("[HDMIRX State] init->5v low\n");
  2360. }
  2361. break;
  2362. case HDMIRX_HWSTATE_5V_LOW:
  2363. if(tx_5v_status!=0){
  2364. hdmirx_audio_recover_reset(); //make unplug can recover audio problem of LS_DIG2090__DVP_5986K
  2365. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_HIGH;
  2366. HDMIRX_HW_LOG("[HDMIRX State] 5v low->5v high\n");
  2367. }
  2368. break;
  2369. case HDMIRX_HWSTATE_5V_HIGH:
  2370. if(tx_5v_status==0){
  2371. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2372. DEASERT_HPD();
  2373. phy_powerdown(0);
  2374. HDMIRX_HW_LOG("[HDMIRX State] 5v high->5v low\n");
  2375. }
  2376. else{
  2377. #if 1
  2378. if(hpd_start_time)
  2379. mdelay(hpd_start_time);
  2380. #endif
  2381. #ifndef HPD_AUTO_MODE
  2382. hdmi_wr_reg(RX_HDCP_CONFIG0, hdmi_rd_reg(RX_HDCP_CONFIG0)|(1<<3));
  2383. phy_poweron();
  2384. if((hdmi_rd_reg(RX_HDCP_ST_STATUS_0)&0x2)==0)
  2385. break;
  2386. #endif
  2387. hdmirx_hw_stru.state = HDMIRX_HWSTATE_HPD_READY;
  2388. HDMIRX_HW_LOG("[HDMIRX State] 5v high->hpd ready\n");
  2389. hdmirx_hw_stru.hpd_wait_time = hpd_ready_time;
  2390. }
  2391. break;
  2392. case HDMIRX_HWSTATE_HPD_READY:
  2393. if(tx_5v_status==0){
  2394. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2395. DEASERT_HPD();
  2396. phy_powerdown(0);
  2397. HDMIRX_HW_LOG("[HDMIRX State] hpd ready ->5v low\n");
  2398. }
  2399. else{
  2400. hdmirx_hw_stru.hpd_wait_time -= HW_MONITOR_TIME_UNIT;
  2401. if(hdmirx_hw_stru.hpd_wait_time < 0){
  2402. hdmirx_hw_stru.state = HDMIRX_HWSTATE_SIG_UNSTABLE;
  2403. hdmirx_hw_stru.cur_color_depth = 0xff;
  2404. hdmirx_hw_stru.guess_vic = 0;
  2405. hdmirx_hw_stru.clk_stable_count = 0;
  2406. HDMIRX_HW_LOG("[HDMIRX State] hpd ready->unstable\n");
  2407. eq_mode_monitor(); //call it before hdmirx_phy_init(), which will set eq register
  2408. hdmirx_phy_init();
  2409. #ifdef RESET_AFTER_CLK_STABLE
  2410. reset_flag = 0;
  2411. #endif
  2412. }
  2413. }
  2414. break;
  2415. case HDMIRX_HWSTATE_SIG_UNSTABLE:
  2416. if(tx_5v_status==0){
  2417. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2418. DEASERT_HPD();
  2419. phy_powerdown(0);
  2420. HDMIRX_HW_LOG("[HDMIRX State] unstable->5v low\n");
  2421. }
  2422. else{
  2423. read_tmds_clk();
  2424. if(is_tmds_clock_stable(16, clk_stable_threshold)){
  2425. hdmirx_hw_stru.clk_stable_count++;
  2426. #ifdef RESET_AFTER_CLK_STABLE
  2427. if(reset_flag == 0){
  2428. if(reset_mode==1){
  2429. hdmirx_reset_clock();
  2430. }
  2431. else if(reset_mode==2){
  2432. hdmirx_reset();
  2433. }
  2434. else if(reset_mode==3){
  2435. hdmirx_phy_init();
  2436. }
  2437. else if(reset_mode==4){
  2438. hdmi_init();
  2439. hdmirx_phy_init();
  2440. }
  2441. else if(reset_mode==5){
  2442. hdmirx_reset_digital();
  2443. }
  2444. if(reset_mode){
  2445. HDMIRX_HW_LOG("[HDMIRX] reset%d after clk stable\n",reset_mode);
  2446. }
  2447. reset_flag = 1;
  2448. }
  2449. #endif
  2450. read_video_timing();
  2451. read_avi_info();
  2452. hdmirx_config_color_depth(get_color_depth());
  2453. if(wait_signal_ok()==0){
  2454. hdmirx_config_color();
  2455. if(hdmirx_hw_stru.avi_info.vic == 0){
  2456. hdmirx_hw_stru.guess_vic = get_vic_from_timing();
  2457. HDMIRX_HW_LOG("[HDMIRX] guess vic %d\n", hdmirx_hw_stru.guess_vic);
  2458. }
  2459. hdmirx_hw_stru.avi_info_change_flag = 0;
  2460. hdmirx_hw_stru.unstable_irq_count = 0;
  2461. hdmirx_hw_stru.aud_info.real_sample_rate = 0;
  2462. hdmirx_hw_stru.audio_sample_rate_stable_count = audio_sample_rate_stable_count_th;
  2463. hdmirx_hw_stru.audio_wait_time = 0;
  2464. hdmirx_hw_stru.audio_reset_release_flag = 0;
  2465. #ifdef FOR_LS_DIG2090__DVP_5986K
  2466. hdmirx_hw_stru.aud_channel_status_modify_count = 0;
  2467. hdmirx_hw_stru.aud_channel_status_unmodify_count = 0;
  2468. hdmirx_hw_stru.aud_channel_status_all_0_count = 0;
  2469. hdmirx_hw_stru.aud_buf_ptr_change_count = 0;
  2470. hdmirx_hw_stru.aud_ok_flag = 0;
  2471. #endif
  2472. hdmirx_hw_stru.state = HDMIRX_HWSTATE_SIG_STABLE;
  2473. HDMIRX_HW_LOG("[HDMIRX State] unstable->stable\n");
  2474. dump_state(DUMP_FLAG_VIDEO_TIMING|DUMP_FLAG_AVI_INFO|DUMP_FLAG_VENDOR_SPEC_INFO|DUMP_FLAG_CLOCK_INFO|DUMP_FLAG_ECC_STATUS);
  2475. pr_info("[HDMIRX] tmds clock %d (%d), pixel clock %d, active pixels %d, active lines %d\n",
  2476. TMDS_CLK(hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1]),
  2477. hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1],
  2478. PIXEL_CLK,
  2479. hdmirx_hw_stru.video_status.active_pixels,
  2480. hdmirx_hw_stru.video_status.active_lines
  2481. );
  2482. }
  2483. }
  2484. else{
  2485. hdmirx_hw_stru.clk_stable_count = 0;
  2486. }
  2487. if(eq_mode_monitor()>0){
  2488. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x5, 0);
  2489. DEASERT_HPD();
  2490. mdelay(100);
  2491. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x5,hdmirx_hw_stru.port);
  2492. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2493. HDMIRX_HW_LOG("[HDMIRX] eq change to %d\n", eq_mode);
  2494. HDMIRX_HW_LOG("[HDMIRX State] unstable->5v low\n");
  2495. }
  2496. }
  2497. break;
  2498. case HDMIRX_HWSTATE_SIG_STABLE:
  2499. if(tx_5v_status==0){
  2500. set_hdmi_audio_source_gate(0);
  2501. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2502. DEASERT_HPD();
  2503. phy_powerdown(0);
  2504. HDMIRX_HW_LOG("[HDMIRX State] stable->5v low\n");
  2505. }
  2506. else if(is_tmds_clock_unstable(64, clk_unstable_threshold)
  2507. ||(test_flag==2)){
  2508. test_flag = 0;
  2509. dump_tmds_clk();
  2510. hdmirx_hw_stru.state = HDMIRX_HWSTATE_SIG_UNSTABLE;
  2511. hdmirx_hw_stru.cur_color_depth = 0xff;
  2512. hdmirx_hw_stru.guess_vic = 0;
  2513. hdmirx_hw_stru.clk_stable_count = 0;
  2514. HDMIRX_HW_LOG("[HDMIRX State] stable->unstable: unstable_irq_count %d\n",
  2515. hdmirx_hw_stru.unstable_irq_count);
  2516. set_hdmi_audio_source_gate(0);
  2517. if((switch_mode&0xf) == 0){
  2518. hdmirx_reset();
  2519. }
  2520. else if((switch_mode&0xf) == 1){
  2521. hdmirx_phy_init();
  2522. }
  2523. #ifdef RESET_AFTER_CLK_STABLE
  2524. reset_flag = 0;
  2525. #endif
  2526. }
  2527. else{
  2528. read_tmds_clk();
  2529. read_video_timing();
  2530. read_avi_info();
  2531. if(hdmirx_hw_stru.avi_info_change_flag){
  2532. hdmirx_config_color_depth(get_color_depth());
  2533. hdmirx_config_color();
  2534. hdmirx_hw_stru.avi_info_change_flag = 0;
  2535. }
  2536. hdmirx_hw_stru.vendor_specific_info_check_time += HW_MONITOR_TIME_UNIT;
  2537. if(hdmirx_hw_stru.vendor_specific_info_check_time > vendor_specific_info_check_period){
  2538. read_vendor_specific_info_frame();
  2539. hdmirx_hw_stru.vendor_specific_info_check_time = 0;
  2540. }
  2541. if(is_tmds_clock_unstable(16, 2)){
  2542. dump_tmds_clk();
  2543. }
  2544. #if 0
  2545. if(dump_flag){
  2546. dump_avi_info();
  2547. dump_video_timing();
  2548. dump_vendor_specific_info_frame();
  2549. pr_info("[HDMIRX] tmds clock %d (%d), pixel clock %d, active pixels %d, active lines %d\n",
  2550. TMDS_CLK(hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1]),
  2551. hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1],
  2552. PIXEL_CLK,
  2553. hdmirx_hw_stru.video_status.active_pixels,
  2554. hdmirx_hw_stru.video_status.active_lines
  2555. );
  2556. dump_flag = 0;
  2557. }
  2558. #endif
  2559. if(audio_enable){
  2560. if(hdmirx_hw_stru.audio_reset_release_flag==0){
  2561. if(have_audio_info()||
  2562. is_use_audio_recover_clock()){
  2563. hdmirx_hw_stru.audio_reset_release_flag = audio_channel_status_stable_th;
  2564. set_hdmi_audio_source_gate(0);
  2565. hdmirx_release_audio_reset();
  2566. }
  2567. }
  2568. else if(hdmirx_hw_stru.audio_reset_release_flag>1){
  2569. hdmirx_hw_stru.audio_reset_release_flag--;
  2570. }
  2571. else{
  2572. pre_sample_rate = hdmirx_hw_stru.aud_info.real_sample_rate;
  2573. read_audio_info();
  2574. #ifdef FOR_LS_DIG2090__DVP_5986K
  2575. hdmirx_hw_stru.audio_check_time += HW_MONITOR_TIME_UNIT;
  2576. if(hdmirx_hw_stru.audio_check_time >= audio_check_period){
  2577. hdmirx_hw_stru.audio_check_time = 0;
  2578. check_audio();
  2579. if(((aud_channel_status_modify_th!=0)&&(hdmirx_hw_stru.aud_channel_status_modify_count>aud_channel_status_modify_th))
  2580. ||((aud_channel_status_all_0_th!=0)&&(hdmirx_hw_stru.aud_buf_ptr_change_count>0)&&(hdmirx_hw_stru.aud_channel_status_all_0_count>aud_channel_status_all_0_th))
  2581. ){
  2582. hdmirx_audio_recover_reset();
  2583. HDMIRX_HW_LOG("[HDMIRX]aud_channel_status_modify_count %d aud_channel_status_all_0_count %d aud_buf_ptr_change_count %d\n",
  2584. hdmirx_hw_stru.aud_channel_status_modify_count,
  2585. hdmirx_hw_stru.aud_channel_status_all_0_count,
  2586. hdmirx_hw_stru.aud_buf_ptr_change_count);
  2587. HDMIRX_HW_LOG("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  2588. HDMIRX_HW_LOG("[HDMIRX] reset HDMI_OTHER_CTRL0 bit 0\n");
  2589. HDMIRX_HW_LOG("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  2590. hdmirx_hw_stru.aud_channel_status_modify_count = 0;
  2591. hdmirx_hw_stru.aud_channel_status_unmodify_count = 0;
  2592. hdmirx_hw_stru.aud_channel_status_all_0_count = 0;
  2593. hdmirx_hw_stru.aud_buf_ptr_change_count = 0;
  2594. break;
  2595. }
  2596. }
  2597. //if(hdmirx_hw_stru.aud_ok_flag == 0){
  2598. if(hdmi_rd_reg(RX_AUDIOST_AUDIO_STATUS)&0x2){
  2599. int rrr=0;
  2600. for(rrr=0; rrr<10; rrr++){
  2601. if((hdmi_rd_reg(RX_AUDIOST_AUDIO_STATUS)&0x2)==0){
  2602. break;
  2603. }
  2604. mdelay(20);
  2605. }
  2606. if(rrr==10){
  2607. HDMIRX_HW_LOG("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  2608. HDMIRX_HW_LOG("[HDMIRX]RX_AUDIOST_AUDIO_STATUS is %x, reset HDMI_OTHER_CTRL0 bit 0\n",
  2609. hdmi_rd_reg(RX_AUDIOST_AUDIO_STATUS));
  2610. HDMIRX_HW_LOG("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  2611. hdmirx_audio_recover_reset();
  2612. }
  2613. }
  2614. /*
  2615. else{
  2616. int rrr=0;
  2617. for(rrr=0; rrr<5; rrr++){
  2618. if(hdmi_rd_reg(RX_AUDIOST_AUDIO_STATUS)&0x2){
  2619. break;
  2620. }
  2621. mdelay(20);
  2622. }
  2623. if(rrr==5){
  2624. hdmirx_hw_stru.aud_ok_flag = 1;
  2625. }
  2626. }*/
  2627. //}
  2628. #endif
  2629. if(test_flag==1){
  2630. test_flag = 0;
  2631. set_hdmi_audio_source_gate(0);
  2632. DEASERT_HPD();
  2633. phy_powerdown(0);
  2634. HDMIRX_HW_LOG("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  2635. HDMIRX_HW_LOG("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  2636. HDMIRX_HW_LOG("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n");
  2637. hdmirx_hw_stru.state = HDMIRX_HWSTATE_INIT;
  2638. HDMIRX_HW_LOG("[HDMIRX State] stable->init\n");
  2639. break;
  2640. }
  2641. if(is_sample_rate_change(pre_sample_rate, hdmirx_hw_stru.aud_info.real_sample_rate)){
  2642. set_hdmi_audio_source_gate(0);
  2643. dump_audio_info();
  2644. hdmirx_hw_stru.audio_sample_rate_stable_count = 0;
  2645. }
  2646. else{
  2647. if(hdmirx_hw_stru.audio_sample_rate_stable_count<audio_sample_rate_stable_count_th){
  2648. hdmirx_hw_stru.audio_sample_rate_stable_count++;
  2649. if(hdmirx_hw_stru.audio_sample_rate_stable_count==audio_sample_rate_stable_count_th){
  2650. #ifdef CONFIG_AML_AUDIO_DSP
  2651. mailbox_send_audiodsp(1, M2B_IRQ0_DSP_AUDIO_EFFECT, DSP_CMD_SET_HDMI_SR, (char *)&hdmirx_hw_stru.aud_info.real_sample_rate,sizeof(hdmirx_hw_stru.aud_info.real_sample_rate));
  2652. #endif
  2653. hdmirx_hw_stru.audio_wait_time = audio_stable_time;
  2654. }
  2655. }
  2656. }
  2657. if(hdmirx_hw_stru.audio_wait_time > 0 ){
  2658. hdmirx_hw_stru.audio_wait_time -= HW_MONITOR_TIME_UNIT;
  2659. if(hdmirx_hw_stru.audio_wait_time <= 0){
  2660. set_hdmi_audio_source_gate(1);
  2661. }
  2662. }
  2663. }
  2664. }
  2665. hdmirx_hw_stru.cur_vic = hdmirx_hw_stru.avi_info.vic;
  2666. hdmirx_hw_stru.cur_pixel_repeat = hdmirx_hw_stru.avi_info.pixel_repeat;
  2667. if(eq_mode_monitor()>0){
  2668. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x5, 0);
  2669. DEASERT_HPD();
  2670. mdelay(100);
  2671. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x5,hdmirx_hw_stru.port);
  2672. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2673. HDMIRX_HW_LOG("[HDMIRX] eq change to %d\n", eq_mode);
  2674. HDMIRX_HW_LOG("[HDMIRX State] stable->5v low\n");
  2675. }
  2676. }
  2677. break;
  2678. default:
  2679. if(tx_5v_status==0){
  2680. hdmirx_hw_stru.state = HDMIRX_HWSTATE_5V_LOW;
  2681. DEASERT_HPD();
  2682. phy_powerdown(0);
  2683. }
  2684. break;
  2685. }
  2686. }
  2687. bool hdmirx_hw_check_frame_skip(void)
  2688. {
  2689. if(skip_unstable_frame){
  2690. if(hdmirx_hw_stru.state == HDMIRX_HWSTATE_SIG_STABLE)
  2691. return false;
  2692. else
  2693. return true;
  2694. }
  2695. return false;
  2696. }
  2697. bool hdmirx_hw_is_nosig(void)
  2698. {
  2699. return ((hdmirx_hw_stru.state == HDMIRX_HWSTATE_5V_LOW) ||
  2700. ((hdmirx_hw_stru.state == HDMIRX_HWSTATE_SIG_UNSTABLE) &&
  2701. ((hdmirx_hw_stru.video_status.active_pixels == 0) ||
  2702. (hdmirx_hw_stru.video_status.active_lines == 0) ||
  2703. (hdmirx_hw_stru.clk_stable_count == 0))));
  2704. }
  2705. bool hdmirx_hw_pll_lock(void)
  2706. {
  2707. return (hdmirx_hw_stru.state==HDMIRX_HWSTATE_SIG_STABLE);
  2708. }
  2709. void hdmirx_reset(void)
  2710. {
  2711. #ifndef FIFO_BYPASS
  2712. #ifdef FIFO_ENABLE_AFTER_RESET
  2713. hdmi_wr_reg(RX_BASE_ADDR+0xA1, 0); // 0x0f
  2714. mdelay(10);
  2715. #endif
  2716. #endif
  2717. //reset tmds, pixel clock , bit 6,7
  2718. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(3<<6));
  2719. mdelay(10);
  2720. hdmi_wr_only_reg( RX_BASE_ADDR+0x866, hdmi_rd_reg(RX_BASE_ADDR+0x866)|0x80);
  2721. hdmi_wr_only_reg( RX_BASE_ADDR+0x86e, hdmi_rd_reg(RX_BASE_ADDR+0x86e)|0x80);
  2722. hdmi_wr_only_reg( RX_BASE_ADDR+0x876, hdmi_rd_reg(RX_BASE_ADDR+0x876)|0x80);
  2723. hdmi_wr_only_reg( RX_BASE_ADDR+0x87e, hdmi_rd_reg(RX_BASE_ADDR+0x87e)|0x80);
  2724. mdelay(10);
  2725. hdmi_wr_only_reg( RX_BASE_ADDR+0x866, hdmi_rd_reg(RX_BASE_ADDR+0x866)&(~0x80));
  2726. hdmi_wr_only_reg( RX_BASE_ADDR+0x86e, hdmi_rd_reg(RX_BASE_ADDR+0x86e)&(~0x80));
  2727. hdmi_wr_only_reg( RX_BASE_ADDR+0x876, hdmi_rd_reg(RX_BASE_ADDR+0x876)&(~0x80));
  2728. hdmi_wr_only_reg( RX_BASE_ADDR+0x87e, hdmi_rd_reg(RX_BASE_ADDR+0x87e)&(~0x80));
  2729. mdelay(10);
  2730. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(1<<5)); //Write RX_AUDIO_MASTER_CONFIG_RSTN = 1
  2731. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(1<<4)); //Write RX_AUDIO_SAMPLE_CONFIG_RSTN = 1
  2732. hdmi_wr_reg(RX_BASE_ADDR+0xe4, hdmi_rd_reg(RX_BASE_ADDR+0xe4)|(1<<7)); //reset i2s config
  2733. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|0xf); //reset config ch0~3
  2734. mdelay(10);
  2735. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~0xf)); //release config ch0~3
  2736. mdelay(10);
  2737. //release tmds, pixel clock
  2738. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(3<<6)));
  2739. #ifndef FIFO_BYPASS
  2740. #ifdef FIFO_ENABLE_AFTER_RESET
  2741. mdelay(10);
  2742. hdmi_wr_reg(RX_BASE_ADDR+0xA1, 0xf); // 0x0f
  2743. #endif
  2744. #endif
  2745. }
  2746. static void hdmirx_release_audio_reset(void)
  2747. {
  2748. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(1<<5)));
  2749. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(1<<4)));
  2750. hdmi_wr_reg(RX_BASE_ADDR+0xe4, hdmi_rd_reg(RX_BASE_ADDR+0xe4)& (~(1<<7))); //release i2s config
  2751. }
  2752. static void hdmirx_reset_clock(void)
  2753. {
  2754. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(3<<6));
  2755. mdelay(10);
  2756. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(3<<6)));
  2757. }
  2758. static void hdmirx_reset_digital(void)
  2759. {
  2760. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(3<<6));
  2761. mdelay(10);
  2762. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|0xf); //reset config ch0~3
  2763. mdelay(10);
  2764. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~0xf)); //release config ch0~3
  2765. mdelay(10);
  2766. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(3<<6)));
  2767. }
  2768. static void hdmirx_reset_pixel_clock(void)
  2769. {
  2770. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(1<<7));
  2771. mdelay(10);
  2772. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(1<<7)));
  2773. }
  2774. static void hdmirx_audio_recover_reset(void)
  2775. {
  2776. WRITE_APB_REG(HDMI_CTRL_PORT, READ_APB_REG(HDMI_CTRL_PORT)|(1<<16));
  2777. hdmi_wr_reg(OTHER_BASE_ADDR+HDMI_OTHER_CTRL0, 0x1);
  2778. mdelay(10);
  2779. hdmi_wr_reg(OTHER_BASE_ADDR+HDMI_OTHER_CTRL0, 0x0);
  2780. WRITE_APB_REG(HDMI_CTRL_PORT, READ_APB_REG(HDMI_CTRL_PORT)&(~(1<<16)));
  2781. }
  2782. static void hdmirx_unpack_recover(void)
  2783. {
  2784. int timeout = 0;
  2785. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(3<<6));
  2786. mdelay(10);
  2787. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(1<<6))); //release tmds clock
  2788. /*check tmds clock stable*/
  2789. timeout = 0;
  2790. while((hdmi_rd_reg(RX_BASE_ADDR+0x160)&0x80)!=0x80){
  2791. mdelay(10);
  2792. timeout++;
  2793. if(timeout>1000){
  2794. printk("+++++++++++++++++check tmds clock timeout\n");
  2795. goto exit;
  2796. }
  2797. }
  2798. timeout = 0;
  2799. while((hdmi_rd_reg(RX_BASE_ADDR+0x161)&0x90)!=0x90){
  2800. mdelay(10);
  2801. timeout++;
  2802. if(timeout>1000){
  2803. printk("+++++++++++++++++check tmds clock timeout\n");
  2804. goto exit;
  2805. }
  2806. }
  2807. timeout = 0;
  2808. while((hdmi_rd_reg(RX_BASE_ADDR+0x162)&0x80)!=0x80){
  2809. mdelay(10);
  2810. timeout++;
  2811. if(timeout>1000){
  2812. printk("+++++++++++++++++check tmds clock timeout\n");
  2813. goto exit;
  2814. }
  2815. }
  2816. timeout = 0;
  2817. while((hdmi_rd_reg(RX_BASE_ADDR+0x163)&0x90)!=0x90){
  2818. mdelay(10);
  2819. timeout++;
  2820. if(timeout>1000){
  2821. printk("+++++++++++++++++check tmds clock timeout\n");
  2822. goto exit;
  2823. }
  2824. }
  2825. timeout = 0;
  2826. while((hdmi_rd_reg(RX_BASE_ADDR+0x164)&0x80)!=0x80){
  2827. mdelay(10);
  2828. timeout++;
  2829. if(timeout>1000){
  2830. printk("+++++++++++++++++check tmds clock timeout\n");
  2831. goto exit;
  2832. }
  2833. }
  2834. timeout = 0;
  2835. while((hdmi_rd_reg(RX_BASE_ADDR+0x165)&0x90)!=0x90){
  2836. mdelay(10);
  2837. timeout++;
  2838. if(timeout>1000){
  2839. printk("+++++++++++++++++check tmds clock timeout\n");
  2840. goto exit;
  2841. }
  2842. }
  2843. timeout = 0;
  2844. while((hdmi_rd_reg(RX_BASE_ADDR+0x166)&0x80)!=0x80){
  2845. mdelay(10);
  2846. timeout++;
  2847. if(timeout>1000){
  2848. printk("+++++++++++++++++check tmds clock timeout\n");
  2849. goto exit;
  2850. }
  2851. }
  2852. timeout = 0;
  2853. while((hdmi_rd_reg(RX_BASE_ADDR+0x167)&0x90)!=0x90){
  2854. mdelay(10);
  2855. timeout++;
  2856. if(timeout>1000){
  2857. printk("+++++++++++++++++check tmds clock timeout\n");
  2858. goto exit;
  2859. }
  2860. }
  2861. timeout = 0;
  2862. while((hdmi_rd_reg(RX_BASE_ADDR+0x1fb)&0x3f)!=0x3f){
  2863. mdelay(10);
  2864. timeout++;
  2865. if(timeout>1000){
  2866. printk("+++++++++++++++++check tmds clock timeout\n");
  2867. goto exit;
  2868. }
  2869. }
  2870. exit:
  2871. if(timeout>1000){
  2872. printk("[1fb] %x [160]~[167]:%x %x %x %x %x %x %x %x\n", hdmi_rd_reg(RX_BASE_ADDR+0x1fb),
  2873. hdmi_rd_reg(RX_BASE_ADDR+0x160),
  2874. hdmi_rd_reg(RX_BASE_ADDR+0x161),
  2875. hdmi_rd_reg(RX_BASE_ADDR+0x162),
  2876. hdmi_rd_reg(RX_BASE_ADDR+0x163),
  2877. hdmi_rd_reg(RX_BASE_ADDR+0x164),
  2878. hdmi_rd_reg(RX_BASE_ADDR+0x165),
  2879. hdmi_rd_reg(RX_BASE_ADDR+0x166),
  2880. hdmi_rd_reg(RX_BASE_ADDR+0x167)
  2881. );
  2882. }
  2883. /**/
  2884. mdelay(250);//wait at least two vsync
  2885. hdmirx_config_color_depth(get_color_depth());
  2886. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(1<<7))); //release pixel clock
  2887. }
  2888. /****************
  2889. * phy init sequence
  2890. * Amlogic_Init_sequence_Address_data.txt
  2891. *
  2892. ***************/
  2893. static unsigned char use_general_eq = 1;
  2894. static void hdmirx_phy_init(void)
  2895. {
  2896. use_general_eq = 1;
  2897. #ifndef FIFO_BYPASS
  2898. #ifdef FIFO_ENABLE_AFTER_RESET
  2899. hdmi_wr_reg(RX_BASE_ADDR+0xA1, 0); // 0x0f
  2900. mdelay(10);
  2901. #endif
  2902. #endif
  2903. { //reset tmds, pixel clock , bit 6,7
  2904. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(3<<6));
  2905. }
  2906. HDMIRX_HW_LOG("[HDMIRX] Phy Init For M2B\n");
  2907. hdmi_wr_only_reg( RX_BASE_ADDR+0x5,hdmirx_hw_stru.port );
  2908. hdmi_wr_only_reg( RX_BASE_ADDR+0x866, hdmi_rd_reg(RX_BASE_ADDR+0x866)|0x80);
  2909. hdmi_wr_only_reg( RX_BASE_ADDR+0x86e, hdmi_rd_reg(RX_BASE_ADDR+0x86e)|0x80);
  2910. hdmi_wr_only_reg( RX_BASE_ADDR+0x876, hdmi_rd_reg(RX_BASE_ADDR+0x876)|0x80);
  2911. hdmi_wr_only_reg( RX_BASE_ADDR+0x87e, hdmi_rd_reg(RX_BASE_ADDR+0x87e)|0x80);
  2912. mdelay(delay1);//delay_us(1000000/10);
  2913. hdmi_wr_only_reg( RX_BASE_ADDR+0x866, hdmi_rd_reg(RX_BASE_ADDR+0x866)&(~0x80));
  2914. hdmi_wr_only_reg( RX_BASE_ADDR+0x86e, hdmi_rd_reg(RX_BASE_ADDR+0x86e)&(~0x80));
  2915. hdmi_wr_only_reg( RX_BASE_ADDR+0x876, hdmi_rd_reg(RX_BASE_ADDR+0x876)&(~0x80));
  2916. hdmi_wr_only_reg( RX_BASE_ADDR+0x87e, hdmi_rd_reg(RX_BASE_ADDR+0x87e)&(~0x80));
  2917. mdelay(delay2); //delay_us(1000000/10);
  2918. //MonsoonHDMI_set_Amlogic ## Register Name
  2919. if(eq_enable){
  2920. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xAC,0xC );// #RX_LS_CLK_SEL,3
  2921. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x8,0xFF );// #RX_EQ_EN_CH0_0_7,255
  2922. if(eq_config&0x100){
  2923. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x9, 0xff );// #RX_EQ_EN_CH0_8_13,63
  2924. }
  2925. else{
  2926. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x9,/*0xff*/0x3F );// #RX_EQ_EN_CH0_8_13,63
  2927. }
  2928. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA,0xFF );// #RX_EQ_EN_CH1_0_7,255
  2929. if(eq_config&0x100){
  2930. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xB, 0xff );// #RX_EQ_EN_CH1_8_13,63
  2931. }
  2932. else{
  2933. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xB,/*0xff*/0x3F );// #RX_EQ_EN_CH1_8_13,63
  2934. }
  2935. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xC,0xFF );// #RX_EQ_EN_CH2_0_7,255
  2936. if(eq_config&0x100){
  2937. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xD, 0xff );// #RX_EQ_EN_CH2_8_13,63
  2938. }
  2939. else{
  2940. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xD,/*0xff*/0x3F );// #RX_EQ_EN_CH2_8_13,63
  2941. }
  2942. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xE,0xFF );// #RX_EQ_EN_CH3_0_7,255
  2943. if(eq_config&0x100){
  2944. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xF, 0xff );// #RX_EQ_EN_CH3_8_13,63
  2945. }
  2946. else{
  2947. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xF,/*0xff*/0x3F );// #RX_EQ_EN_CH3_8_13,63
  2948. }
  2949. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x57,0x8 );// #RX_EQ_MAP_SEL,1
  2950. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xFE,0x80 );// #RX_EQ_FORCED,1
  2951. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x863,(0x38&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx0_eq_biastrimeq,7
  2952. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x86B,(0x38&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx1_eq_biastrimeq,7
  2953. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x873,(0x38&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx2_eq_biastrimeq,7
  2954. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x87B,(0x38&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx3_eq_biastrimeq,7
  2955. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x863,(0x3F&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx0_eq_biastrimsf,7
  2956. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x86B,(0x3F&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx1_eq_biastrimsf,7
  2957. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x873,(0x3F&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx2_eq_biastrimsf,7
  2958. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x87B,(0x3F&(~(7<<3)))|((eq_config&0xf)<<3) );// #rx_rx3_eq_biastrimsf,7
  2959. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x860,0x5 );// #rx_rx0_eq_eqcap1_trim,5
  2960. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x868,0x5 );// #rx_rx1_eq_eqcap1_trim,5
  2961. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x870,0x5 );// #rx_rx2_eq_eqcap1_trim,5
  2962. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x878,0x5 );// #rx_rx3_eq_eqcap1_trim,5
  2963. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x861,0x5 );// #rx_rx0_eq_eqcap2_trim,5
  2964. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x869,0x5 );// #rx_rx1_eq_eqcap2_trim,5
  2965. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x871,0x5 );// #rx_rx2_eq_eqcap2_trim,5
  2966. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x879,0x5 );// #rx_rx3_eq_eqcap2_trim,5
  2967. }
  2968. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x5,hdmirx_hw_stru.port ); // rx_port_en" , 4
  2969. if((eq_config&0x10)==0){
  2970. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x863,0x20 ); // rx_rx0_eq_biastrimeq",4
  2971. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x86B,0x20 ); // rx_rx1_eq_biastrimeq",4
  2972. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x873,0x20 ); // rx_rx2_eq_biastrimeq",4
  2973. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x87B,0x20 ); // rx_rx3_eq_biastrimeq",4
  2974. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x863,0x22 ); // rx_rx0_eq_biastrimsf",2
  2975. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x86B,0x23 ); // rx_rx1_eq_biastrimsf",3
  2976. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x873,0x23 ); // rx_rx2_eq_biastrimsf",3
  2977. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x87B,0x23 ); // rx_rx3_eq_biastrimsf",3
  2978. }
  2979. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x864,0x10 ); // rx_rx0_dp_pixel_clk_pd",1
  2980. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x86C,0x10 ); // rx_rx1_dp_pixel_clk_pd",1
  2981. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x874,0x10 ); // rx_rx2_dp_pixel_clk_pd",1
  2982. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x87C,0x10 ); // rx_rx3_dp_pixel_clk_pd",1
  2983. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x865,0x80 ); // rx_cdr0_hogg_adj",4
  2984. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x86D,0x80 ); // rx_cdr1_hogg_adj",4
  2985. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x875,0x80 ); // rx_cdr2_hogg_adj",4
  2986. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x87D,0x80 ); // rx_cdr3_hogg_adj",4
  2987. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x865,0x90 ); // rx_cdr0_dp_div_cfg",4
  2988. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x86D,0x9C ); // rx_cdr1_dp_div_cfg",7
  2989. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x875,0x90 ); // rx_cdr2_dp_div_cfg",4
  2990. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x87D,0x90 ); // rx_cdr3_dp_div_cfg",4
  2991. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x83,0x0 ); // Was 1 Not needed ## rx_cdr1_en_clkfd",0
  2992. //Monsoon_set_ana_RX
  2993. //AnalogReceiver(hdrx)
  2994. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x99,0x7 ); // rx_ra,7
  2995. //'AUX(hdaux)
  2996. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x90,0x1 ); // rx_rxaux_slope_cntrl",1
  2997. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x90,0x9 ); // rx_rxaux_leak_cur_en",1
  2998. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x90,0x49 ); // rx_rxaux_mvedge",1
  2999. //''Reference(hdref)
  3000. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x95,0x2 ); // rx_rxref_cur_tun1",1
  3001. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x96,0x4 ); // rx_rxref_test_vgapa",4
  3002. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x96,0x14 ); // rx_rxref_test_vgapb",2
  3003. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x93,0x4 ); // rx_rxg_ch_vsh",1
  3004. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x93,0x6 ); // rx_rxg_aux_vsh",2
  3005. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x93,0x46 ); // rx_rxg_shield_en",1
  3006. //'CDR
  3007. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x857,0x80 ); // moved from 0x81,0x80 ); // "rx_cdr0_en_clkfd_loop",1
  3008. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x859,0x80 ); // moved from 0x83,0x80 ); // "rx_cdr1_en_clkfd_loop",1
  3009. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85B,0x80 ); // moved from 0x85,0x80 ); // "rx_cdr2_en_clkfd_loop",1
  3010. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85D,0x80 ); // moved from 0x87,0x80 ); // "rx_cdr3_en_clkfd_loop",1
  3011. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x857,0xC0 ); // moved from 0x81,0xC0 ## "rx_cdr0_en_datafd_loop",1
  3012. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x859,0xC0 ); // moved from 0x83,0xC0 ## "rx_cdr1_en_datafd_loop",1
  3013. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85B,0xC0 ); // moved from 0x85,0xC0 ## "rx_cdr2_en_datafd_loop",1
  3014. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85D,0xC0 ); // moved from 0x87,0xC0 ## "rx_cdr3_en_datafd_loop",1
  3015. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x857,0xE0 ); // moved from 0x81,0xE0 ## "rx_cdr0_pd_loop",1
  3016. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x859,0xE0 ); // moved from 0x83,0xE0 ## "rx_cdr1_pd_loop",1
  3017. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85B,0xE0 ); // moved from 0x85,0xE0 ## "rx_cdr2_pd_loop",1
  3018. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85D,0xE0 ); // moved from 0x87,0xE0 ## "rx_cdr3_pd_loop",1
  3019. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x857,0xF0 ); // moved from 0x81,0xF0 ## "rx_cdr0_datfd_timer",1
  3020. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x859,0xF0 ); // moved from 0x83,0xF0 ## "rx_cdr1_datafd_timer",1
  3021. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85B,0xF0 ); // moved from 0x85,0xF0 ## "rx_cdr2_datafd_timer",1
  3022. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x85D,0xF0 ); // moved from 0x87,0xF0 ## "rx_cdr3_datafd_timer",1
  3023. //'rx_lab_default
  3024. //'Rescalibration
  3025. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA0,0x0 ); // "RX_HDMIDP_AFE_CONN_RCALIB_MODE" , 0
  3026. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x98,0x1 ); // "rx_rcalib_mask" , 1
  3027. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x98,0x9 ); // "rx_rcalib_trigger" , 2
  3028. //sleep 0.5 ##
  3029. mdelay(delay3); //delay_us(500000);
  3030. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x98,0x1 ); // "rx_rcalib_trigger" , 0
  3031. //'RX_DIG_Clockssetting ); //
  3032. #ifdef FIFO_BYPASS
  3033. hdmi_wr_reg(RX_BASE_ADDR+0xA1, 0xf0);
  3034. #elif (!(defined FIFO_ENABLE_AFTER_RESET))
  3035. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA1,0xF ); // "RX_HDMIDP_AFE_CONN_FIFO_EN" , 15
  3036. #endif
  3037. //'Sleep1
  3038. mdelay(delay4); //delay_us(1000000);
  3039. //MonsoonHDMI_set_ana_RX
  3040. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x866,0x20 ); // Stay at the same place ); // "RX_CDR0_EN_CLK_CH" , 1
  3041. //Nochannelswapping:
  3042. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA4,0x0 ); // "RX_HDMIDP_AFE_CONN_CH_SW_0_7", 0
  3043. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA5,0xE4 ); // "RX_HDMIDP_AFE_CONN_CH_SW_8_15", 228
  3044. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA6,0x88 ); // "RX_HDMIDP_AFE_CONN_CH_SW_16_23", 136
  3045. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA7,0x88 ); // "RX_HDMIDP_AFE_CONN_CH_SW_24_31", 136
  3046. //Monson_digitalx3
  3047. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x5,hdmirx_hw_stru.port ); // "rx_port_en" , 4
  3048. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA0,0x70 );
  3049. {
  3050. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(1<<5)); //Write RX_AUDIO_MASTER_CONFIG_RSTN = 1
  3051. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(1<<4)); //Write RX_AUDIO_SAMPLE_CONFIG_RSTN = 1
  3052. hdmi_wr_reg(RX_BASE_ADDR+0xe4, hdmi_rd_reg(RX_BASE_ADDR+0xe4)|(1<<7)); //reset i2s config
  3053. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|0xf); //reset config ch0~3
  3054. mdelay(10);
  3055. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~0xf)); //release config ch0~3
  3056. mdelay(10);
  3057. //release tmds, pixel clock
  3058. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(3<<6)));
  3059. }
  3060. #ifndef FIFO_BYPASS
  3061. #ifdef FIFO_ENABLE_AFTER_RESET
  3062. mdelay(10);
  3063. hdmi_wr_reg(RX_BASE_ADDR+0xA1, 0xf); // 0x0f
  3064. #endif
  3065. #endif
  3066. }
  3067. static void set_eq_27M(int idx1, int idx2)
  3068. { /* idx1 from 0 to 7, idx2 from 0 to 31 */
  3069. HDMIRX_HW_LOG("[HDMIRX] PIXEL_CLK is %d, call %s\n",PIXEL_CLK, __FUNCTION__);
  3070. //Enable EQ
  3071. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x8,0xFF );// #RX_EQ_EN_CH0_0_7,255
  3072. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x9,/*0xff*/0x3F );// #RX_EQ_EN_CH0_8_13,63
  3073. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xA,0xFF );// #RX_EQ_EN_CH1_0_7,255
  3074. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xB,/*0xff*/0x3F );// #RX_EQ_EN_CH1_8_13,63
  3075. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xC,0xFF );// #RX_EQ_EN_CH2_0_7,255
  3076. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xD,/*0xff*/0x3F );// #RX_EQ_EN_CH2_8_13,63
  3077. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xE,0xFF );// #RX_EQ_EN_CH3_0_7,255
  3078. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xF,/*0xff*/0x3F );// #RX_EQ_EN_CH3_8_13,63
  3079. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x57,0x8 );// #RX_EQ_MAP_SEL,1
  3080. hdmi_wr_only_reg( RX_BASE_ADDR+ 0xFE,0x80 );// #RX_EQ_FORCED,1
  3081. // Set EQRS + rx(x)_Spare bit 0
  3082. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x62,0x10|(((idx1>>2)&0x1)<<2)|(((idx1>>1)&0x1)<<0));
  3083. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x64,0x10|(((idx1>>0)&0x1)<<0));
  3084. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x6A,0x10|(((idx1>>2)&0x1)<<2)|(((idx1>>1)&0x1)<<0) );
  3085. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x6C,0x10|(((idx1>>0)&0x1)<<0) );
  3086. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x72,0x10|(((idx1>>2)&0x1)<<2)|(((idx1>>1)&0x1)<<0) );
  3087. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x74,0x10|(((idx1>>0)&0x1)<<0) );
  3088. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x7A,0x10|(((idx1>>2)&0x1)<<2)|(((idx1>>1)&0x1)<<0) );
  3089. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x7C,0x10|(((idx1>>0)&0x1)<<0) );
  3090. //Set equalizers Option 1:
  3091. // Set Eq to diffrent num eq_cp_trim = 1
  3092. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x60,(((idx2>>5)&0x1)<<2)|(((idx2>>4)&0x1)<<1) );
  3093. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x61,(((idx2>>3)&0x1)<<4)|(((idx2>>2)&0x1)<<3)|(((idx2>>1)&0x1)<<1)|(((idx2>>0)&0x1)<<0));
  3094. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x68,(((idx2>>5)&0x1)<<2)|(((idx2>>4)&0x1)<<1) );
  3095. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x69,(((idx2>>3)&0x1)<<4)|(((idx2>>2)&0x1)<<3)|(((idx2>>1)&0x1)<<1)|(((idx2>>0)&0x1)<<0) );
  3096. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x70,(((idx2>>5)&0x1)<<2)|(((idx2>>4)&0x1)<<1) );
  3097. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x71,(((idx2>>3)&0x1)<<4)|(((idx2>>2)&0x1)<<3)|(((idx2>>1)&0x1)<<1)|(((idx2>>0)&0x1)<<0) );
  3098. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x78,(((idx2>>5)&0x1)<<2)|(((idx2>>4)&0x1)<<1) );
  3099. hdmi_wr_only_reg( RX_BASE_ADDR+ 0x79,(((idx2>>3)&0x1)<<4)|(((idx2>>2)&0x1)<<3)|(((idx2>>1)&0x1)<<1)|(((idx2>>0)&0x1)<<0) );
  3100. }
  3101. typedef struct {
  3102. unsigned int adr;
  3103. unsigned int val;
  3104. unsigned int val_bak;
  3105. }eq_setting_t;
  3106. static eq_setting_t eq_27M[]=
  3107. {
  3108. // bypass_hf bit[5] and dig_hf bit[3] (bypass_hf=1 and dig_hf=1)
  3109. { RX_BASE_ADDR+ 0x856, 0x28, 0 },
  3110. { RX_BASE_ADDR+ 0x858, 0x28, 0 },
  3111. { RX_BASE_ADDR+ 0x85A, 0x28, 0 },
  3112. { RX_BASE_ADDR+ 0x85C, 0x28, 0 },
  3113. // biastrimsf bits [2:0] + biastrim_eq bits [5:3] (eq_biastrimsf = 3¡¯b001 and Biastrim_eq=3¡¯b111)
  3114. { RX_BASE_ADDR+ 0x863, 0x39, 0 },
  3115. { RX_BASE_ADDR+ 0x86B, 0x39, 0 },
  3116. { RX_BASE_ADDR+ 0x873, 0x39, 0 },
  3117. { RX_BASE_ADDR+ 0x87B, 0x39, 0 },
  3118. // EQ_EQRS [5:2] + [1:0] = 6¡¯b11_1111
  3119. { RX_BASE_ADDR+ 0x862, 0x3C, 0 },
  3120. { RX_BASE_ADDR+ 0x86A, 0x3C, 0 },
  3121. { RX_BASE_ADDR+ 0x872, 0x3C, 0 },
  3122. { RX_BASE_ADDR+ 0x87A, 0x3C, 0 },
  3123. { RX_BASE_ADDR+ 0x864, 0x13, 0 },
  3124. { RX_BASE_ADDR+ 0x86C, 0x13, 0 },
  3125. { RX_BASE_ADDR+ 0x874, 0x13, 0 },
  3126. { RX_BASE_ADDR+ 0x87C, 0x13, 0 },
  3127. // EQ_VCNTR_TRIM + EQ_CAP_TRIM (eq_vcntr_trim=3¡¯b111 eq_cap_trim=6¡¯b11_1111)
  3128. { RX_BASE_ADDR+ 0x860, 0xFF, 0 },
  3129. { RX_BASE_ADDR+ 0x861, 0x3 , 0 },
  3130. { RX_BASE_ADDR+ 0x868, 0xFF, 0 },
  3131. { RX_BASE_ADDR+ 0x869, 0x3 , 0 },
  3132. { RX_BASE_ADDR+ 0x870, 0xFF, 0 },
  3133. { RX_BASE_ADDR+ 0x871, 0x3 , 0 },
  3134. { RX_BASE_ADDR+ 0x878, 0xFF, 0 },
  3135. { RX_BASE_ADDR+ 0x879, 0x3 , 0 },
  3136. {0, 0, 0}
  3137. };
  3138. static void set_eq_27M_2(void)
  3139. {
  3140. int i;
  3141. HDMIRX_HW_LOG("[HDMIRX] call %s()\n",__func__);
  3142. if(use_general_eq == 1){
  3143. for( i=0; eq_27M[i].adr; i++){
  3144. eq_27M[i].val_bak = hdmi_rd_reg(eq_27M[i].adr);
  3145. }
  3146. }
  3147. for( i=0; eq_27M[i].adr; i++){
  3148. hdmi_wr_only_reg(eq_27M[i].adr, eq_27M[i].val);
  3149. }
  3150. use_general_eq = 0;
  3151. }
  3152. static void restore_eq_gen(void)
  3153. {
  3154. int i;
  3155. if(use_general_eq == 0){
  3156. HDMIRX_HW_LOG("[HDMIRX] call %s()\n",__func__);
  3157. for( i=0; eq_27M[i].adr; i++){
  3158. hdmi_wr_only_reg(eq_27M[i].adr, eq_27M[i].val_bak);
  3159. }
  3160. use_general_eq = 1;
  3161. }
  3162. }
  3163. /****************
  3164. * debug function
  3165. *
  3166. ***************/
  3167. static unsigned long clk_util_clk_msr( unsigned long clk_mux, unsigned long uS_gate_time )
  3168. {
  3169. unsigned long dummy_rd;
  3170. unsigned long measured_val;
  3171. unsigned long timeout = 0;
  3172. // Set the measurement gate to 100uS
  3173. Wr(MSR_CLK_REG0, (Rd(MSR_CLK_REG0) & ~(0xFFFF << 0)) | ((uS_gate_time-1) << 0) );
  3174. // Disable continuous measurement
  3175. // disable interrupts
  3176. Wr(MSR_CLK_REG0, (Rd(MSR_CLK_REG0) & ~((1 << 18) | (1 << 17))) );
  3177. Wr(MSR_CLK_REG0, (Rd(MSR_CLK_REG0) & ~(0xf << 20)) | ((clk_mux << 20) | // Select MUX
  3178. (1 << 19) | // enable the clock
  3179. (1 << 16)) ); // enable measuring
  3180. dummy_rd = Rd(MSR_CLK_REG0);
  3181. // Wait for the measurement to be done
  3182. while( (Rd(MSR_CLK_REG0) & (1 << 31)) ) {
  3183. mdelay(10);
  3184. timeout++;
  3185. if(timeout>10){
  3186. return 0;
  3187. }
  3188. }
  3189. // disable measuring
  3190. Wr(MSR_CLK_REG0, (Rd(MSR_CLK_REG0) & ~(1 << 16)) | (0 << 16) );
  3191. measured_val = Rd(MSR_CLK_REG2);
  3192. if( measured_val == 65535 ) {
  3193. return(0);
  3194. } else {
  3195. // Return value in Hz
  3196. return(measured_val*(1000000/uS_gate_time));
  3197. }
  3198. }
  3199. //int msr_par1=11,msr_par2=50; //ddr_pll_clk
  3200. #if 0
  3201. static unsigned monitor_register_adr[]=
  3202. {
  3203. RX_BASE_ADDR+0x160,
  3204. RX_BASE_ADDR+0x161,
  3205. RX_BASE_ADDR+0x162,
  3206. RX_BASE_ADDR+0x163,
  3207. RX_BASE_ADDR+0x164,
  3208. RX_BASE_ADDR+0x165,
  3209. RX_BASE_ADDR+0x166,
  3210. RX_BASE_ADDR+0x167,
  3211. RX_BASE_ADDR+0x856,
  3212. RX_BASE_ADDR+0x857,
  3213. RX_BASE_ADDR+0x858,
  3214. RX_BASE_ADDR+0x859,
  3215. RX_BASE_ADDR+0x85a,
  3216. RX_BASE_ADDR+0x85b,
  3217. RX_BASE_ADDR+0x85c,
  3218. RX_BASE_ADDR+0x85d,
  3219. RX_BASE_ADDR+0x1fb,
  3220. RX_BASE_ADDR+0x1a0,
  3221. RX_BASE_ADDR+0x1a1,
  3222. RX_BASE_ADDR+0x1a2,
  3223. RX_BASE_ADDR+0x1a3,
  3224. RX_BASE_ADDR+0x1a4,
  3225. RX_BASE_ADDR+0x1a5,
  3226. RX_BASE_ADDR+0x1a6,
  3227. RX_BASE_ADDR+0x1a7,
  3228. RX_BASE_ADDR+0x1a8,
  3229. RX_BASE_ADDR+0x1a9,
  3230. };
  3231. static unsigned monitor_register_val[128];
  3232. static void hdmirx_monitor_reg_init(void)
  3233. {
  3234. int i;
  3235. int n=sizeof(monitor_register_adr)/sizeof(unsigned);
  3236. for(i=0;i<n;i++){
  3237. monitor_register_val[i]=0xffffffff;
  3238. }
  3239. }
  3240. /*
  3241. static void hdmirx_monitor_clock(void)
  3242. {
  3243. int clktmp;
  3244. clktmp=clk_util_clk_msr(msr_par1,msr_par2);
  3245. HDMIRX_HW_LOG("[clk_util_clk_msr(%d,%d)]=%d, unstable count=%d\n[msr_tmds]=%d, [0x1f7]=%x\n",
  3246. msr_par1,msr_par2, clktmp, hdmirx_hw_stru.unstable_irq_count,
  3247. hdmirx_hw_stru.tmds_clk[TMDS_CLK_HIS_SIZE-1], hdmi_rd_reg(RX_BASE_ADDR+0x1f7));
  3248. }
  3249. */
  3250. static void hdimrx_monitor_register(void)
  3251. {
  3252. unsigned char print_buf[128];
  3253. int n=sizeof(monitor_register_adr)/sizeof(unsigned);
  3254. unsigned tmp;
  3255. int i;
  3256. unsigned long flags;
  3257. spin_lock_irqsave(&hdmi_print_lock, flags);
  3258. for(i=0;i<n;i++){
  3259. tmp=hdmi_rd_reg(monitor_register_adr[i]);
  3260. if(tmp!=monitor_register_val[i]){
  3261. sprintf(print_buf,"[%x(%x)]=%x\n", monitor_register_adr[i], monitor_register_val[i], tmp);
  3262. HDMIRX_HW_LOG(print_buf);
  3263. monitor_register_val[i]=tmp;
  3264. }
  3265. }
  3266. spin_unlock_irqrestore(&hdmi_print_lock, flags);
  3267. }
  3268. #endif
  3269. /*
  3270. * Debug
  3271. */
  3272. static void dump_reg(void)
  3273. {
  3274. int i;
  3275. for(i=0; i<0x900; i+=16){
  3276. printk("[HDMIRX]%03x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  3277. i,hdmi_rd_reg(RX_BASE_ADDR+i), hdmi_rd_reg(RX_BASE_ADDR+i+1), hdmi_rd_reg(RX_BASE_ADDR+i+2),hdmi_rd_reg(RX_BASE_ADDR+i+3),
  3278. hdmi_rd_reg(RX_BASE_ADDR+i+4), hdmi_rd_reg(RX_BASE_ADDR+i+5), hdmi_rd_reg(RX_BASE_ADDR+i+6),hdmi_rd_reg(RX_BASE_ADDR+i+7),
  3279. hdmi_rd_reg(RX_BASE_ADDR+i+8), hdmi_rd_reg(RX_BASE_ADDR+i+9), hdmi_rd_reg(RX_BASE_ADDR+i+10),hdmi_rd_reg(RX_BASE_ADDR+i+11),
  3280. hdmi_rd_reg(RX_BASE_ADDR+i+12), hdmi_rd_reg(RX_BASE_ADDR+i+13), hdmi_rd_reg(RX_BASE_ADDR+i+14),hdmi_rd_reg(RX_BASE_ADDR+i+15));
  3281. }
  3282. printk("[HDMIRX OTHER_BASE_ADDR] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  3283. hdmi_rd_reg(OTHER_BASE_ADDR), hdmi_rd_reg(OTHER_BASE_ADDR+1), hdmi_rd_reg(OTHER_BASE_ADDR+2),hdmi_rd_reg(OTHER_BASE_ADDR+3),
  3284. hdmi_rd_reg(OTHER_BASE_ADDR+4), hdmi_rd_reg(OTHER_BASE_ADDR+5), hdmi_rd_reg(OTHER_BASE_ADDR+6),hdmi_rd_reg(OTHER_BASE_ADDR+7),
  3285. hdmi_rd_reg(OTHER_BASE_ADDR+8), hdmi_rd_reg(OTHER_BASE_ADDR+9), hdmi_rd_reg(OTHER_BASE_ADDR+10),hdmi_rd_reg(OTHER_BASE_ADDR+11));
  3286. i = 0;
  3287. printk("[CECCFG]%03x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  3288. i,hdmi_rd_reg(CEC0_BASE_ADDR+i),hdmi_rd_reg(CEC0_BASE_ADDR+i+1),hdmi_rd_reg(CEC0_BASE_ADDR+i+2),hdmi_rd_reg(CEC0_BASE_ADDR+i+3),
  3289. hdmi_rd_reg(CEC0_BASE_ADDR+i+4),hdmi_rd_reg(CEC0_BASE_ADDR+i+5),hdmi_rd_reg(CEC0_BASE_ADDR+i+6),hdmi_rd_reg(CEC0_BASE_ADDR+i+7),
  3290. hdmi_rd_reg(CEC0_BASE_ADDR+i+8),hdmi_rd_reg(CEC0_BASE_ADDR+i+9),hdmi_rd_reg(CEC0_BASE_ADDR+i+10),hdmi_rd_reg(CEC0_BASE_ADDR+i+11),
  3291. hdmi_rd_reg(CEC0_BASE_ADDR+i+12),hdmi_rd_reg(CEC0_BASE_ADDR+i+13),hdmi_rd_reg(CEC0_BASE_ADDR+i+14),hdmi_rd_reg(CEC0_BASE_ADDR+i+15));
  3292. i = 16;
  3293. printk("[CECCFG]%03x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  3294. i,hdmi_rd_reg(CEC0_BASE_ADDR+i),hdmi_rd_reg(CEC0_BASE_ADDR+i+1),hdmi_rd_reg(CEC0_BASE_ADDR+i+2),hdmi_rd_reg(CEC0_BASE_ADDR+i+3),
  3295. hdmi_rd_reg(CEC0_BASE_ADDR+i+4),hdmi_rd_reg(CEC0_BASE_ADDR+i+5),hdmi_rd_reg(CEC0_BASE_ADDR+i+6),hdmi_rd_reg(CEC0_BASE_ADDR+i+7),
  3296. hdmi_rd_reg(CEC0_BASE_ADDR+i+8),hdmi_rd_reg(CEC0_BASE_ADDR+i+9),hdmi_rd_reg(CEC0_BASE_ADDR+i+10),hdmi_rd_reg(CEC0_BASE_ADDR+i+11),
  3297. hdmi_rd_reg(CEC0_BASE_ADDR+i+12));
  3298. i = 0;
  3299. printk("[CECSTU]%03x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
  3300. i,hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+1),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+2),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+3),
  3301. hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+4),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+5),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+6),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+7),
  3302. hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+8),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+9),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+10),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+11),
  3303. hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+12),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+13),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+14),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+15));
  3304. i = 16;
  3305. printk("[CECSTU]%03x %02x %02x %02x %02x %02x\n",
  3306. i,hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+1),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+2),hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+3),
  3307. hdmi_rd_reg(CEC0_BASE_ADDR+CEC_RX_MSG_0_HEADER+i+4));
  3308. }
  3309. static int sample_rate_temp;
  3310. static unsigned char eq_27M_index=0;
  3311. int hdmirx_debug(const char* buf, int size)
  3312. {
  3313. char tmpbuf[128];
  3314. int i=0;
  3315. unsigned int adr;
  3316. unsigned int value=0;
  3317. while((buf[i])&&(buf[i]!=',')&&(buf[i]!=' ')){
  3318. tmpbuf[i]=buf[i];
  3319. i++;
  3320. }
  3321. tmpbuf[i]=0;
  3322. if(strncmp(tmpbuf, "set_color_depth", 15) == 0){
  3323. hdmirx_config_color_depth(tmpbuf[15]-'0');
  3324. printk("set color depth %c\n", tmpbuf[15]);
  3325. }
  3326. #ifdef RESET_AFTER_CLK_STABLE
  3327. else if(strncmp(tmpbuf, "reset_mode", 10)==0){
  3328. reset_mode = simple_strtoul(tmpbuf+10, NULL, 10);
  3329. printk("set reset_mode %d\n", reset_mode);
  3330. }
  3331. #endif
  3332. else if(strncmp(tmpbuf, "reset", 5)==0){
  3333. if(tmpbuf[5]=='0'){
  3334. hdmirx_reset_clock();
  3335. }
  3336. else if(tmpbuf[5]=='1'){
  3337. hdmirx_reset();
  3338. }
  3339. else if(tmpbuf[5]=='2'){
  3340. hdmirx_phy_init();
  3341. }
  3342. else if(tmpbuf[5]=='3'){
  3343. hdmi_init();
  3344. hdmirx_phy_init();
  3345. }
  3346. else if(tmpbuf[5]=='4'){
  3347. int ch_num = tmpbuf[6]-'0';
  3348. if((ch_num < 0)||(ch_num > 3)){
  3349. ch_num = 0;
  3350. }
  3351. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)|(1<<ch_num)); //reset config ch0~3
  3352. mdelay(10);
  3353. hdmi_wr_reg(RX_BASE_ADDR+0xe2, hdmi_rd_reg(RX_BASE_ADDR+0xe2)& (~(1<<ch_num))); //release config ch0~3
  3354. }
  3355. else if(tmpbuf[5]=='5'){
  3356. hdmirx_reset_digital();
  3357. }
  3358. else if(tmpbuf[5]=='6'){
  3359. hdmirx_audio_recover_reset();
  3360. }
  3361. }
  3362. else if(strncmp(tmpbuf, "set_state", 9)==0){
  3363. hdmirx_hw_stru.state = simple_strtoul(tmpbuf+9, NULL, 10);
  3364. printk("set state %d\n", hdmirx_hw_stru.state);
  3365. }
  3366. else if(strncmp(tmpbuf, "test", 4)==0){
  3367. test_flag = simple_strtoul(tmpbuf+4, NULL, 10);;
  3368. printk("test %d\n", test_flag);
  3369. }
  3370. else if(strncmp(tmpbuf, "state", 5)==0){
  3371. dump_state(0xff);
  3372. }
  3373. else if(strncmp(tmpbuf, "pause", 5)==0){
  3374. sm_pause = simple_strtoul(tmpbuf+5, NULL, 10);
  3375. printk("%s the state machine\n", sm_pause?"pause":"enable");
  3376. }
  3377. else if(strncmp(tmpbuf, "reg", 3)==0){
  3378. dump_reg();
  3379. }
  3380. else if(strncmp(tmpbuf, "set_eq_27M", 10)==0){
  3381. int tmp = simple_strtoul(tmpbuf+10, NULL, 10);
  3382. if(tmp<0x100){
  3383. eq_27M_index = tmp;
  3384. }
  3385. else{
  3386. eq_27M_index++;
  3387. }
  3388. set_eq_27M(eq_27M_index&0x7, (eq_27M_index>>3)&0x1f);
  3389. printk("eq_27M_index=%d, et set_eq_27M(%d,%d)\n",eq_27M_index, eq_27M_index&0x7, (eq_27M_index>>3)&0x1f);
  3390. }
  3391. else if(strncmp(tmpbuf, "log", 3)==0){
  3392. hdmirx_log_flag = simple_strtoul(tmpbuf+3, NULL, 10);
  3393. printk("set hdmirx_log_flag as %d\n", hdmirx_log_flag);
  3394. }
  3395. else if(strncmp(tmpbuf, "sample_rate", 11)==0){
  3396. sample_rate_temp = simple_strtoul(tmpbuf+11, NULL, 10);
  3397. #ifdef CONFIG_AML_AUDIO_DSP
  3398. mailbox_send_audiodsp(1, M2B_IRQ0_DSP_AUDIO_EFFECT, DSP_CMD_SET_HDMI_SR, (char *)&sample_rate_temp,sizeof(sample_rate_temp));
  3399. #endif
  3400. printk("force audio sample rate as %d\n", sample_rate_temp);
  3401. }
  3402. else if(strncmp(tmpbuf, "eq_mode", 7)==0){
  3403. if((eq_mode>=0)&&(eq_mode<=eq_mode_max)){
  3404. eq_mode = simple_strtoul(tmpbuf+7, NULL, 10);
  3405. printk("set eq_mode as %d\n", eq_mode);
  3406. }
  3407. else{
  3408. printk("set eq_mode (%d) fail\n", eq_mode);
  3409. }
  3410. }
  3411. else if(strncmp(tmpbuf, "internal_mode", 13)==0){
  3412. internal_mode = simple_strtoul(tmpbuf+13, NULL, 10);
  3413. printk("set internal_mode as %d\n", internal_mode);
  3414. }
  3415. else if(strncmp(tmpbuf, "prbs", 4)==0){
  3416. turn_on_prbs_mode(simple_strtoul(tmpbuf+4, NULL, 10));
  3417. }
  3418. else if(tmpbuf[0]=='w'){
  3419. adr=simple_strtoul(tmpbuf+2, NULL, 16);
  3420. value=simple_strtoul(buf+i+1, NULL, 16);
  3421. if(buf[1]=='h'){
  3422. hdmirx_hw_enable_clock();
  3423. hdmi_wr_reg(adr, value);
  3424. }
  3425. else if(buf[1]=='c'){
  3426. WRITE_MPEG_REG(adr, value);
  3427. pr_info("write %x to CBUS reg[%x]\n",value,adr);
  3428. }
  3429. else if(buf[1]=='p'){
  3430. WRITE_APB_REG(adr, value);
  3431. pr_info("write %x to APB reg[%x]\n",value,adr);
  3432. }
  3433. else if(buf[1]=='l'){
  3434. WRITE_MPEG_REG(MDB_CTRL, 2);
  3435. WRITE_MPEG_REG(MDB_ADDR_REG, adr);
  3436. WRITE_MPEG_REG(MDB_DATA_REG, value);
  3437. pr_info("write %x to LMEM[%x]\n",value,adr);
  3438. }
  3439. else if(buf[1]=='r'){
  3440. WRITE_MPEG_REG(MDB_CTRL, 1);
  3441. WRITE_MPEG_REG(MDB_ADDR_REG, adr);
  3442. WRITE_MPEG_REG(MDB_DATA_REG, value);
  3443. pr_info("write %x to amrisc reg [%x]\n",value,adr);
  3444. }
  3445. }
  3446. else if(tmpbuf[0]=='r'){
  3447. adr=simple_strtoul(tmpbuf+2, NULL, 16);
  3448. if(buf[1]=='h'){
  3449. hdmirx_hw_enable_clock();
  3450. value = hdmi_rd_reg(adr);
  3451. pr_info("HDMI reg[%x]=%x\n", adr, value);
  3452. }
  3453. else if(buf[1]=='c'){
  3454. value = READ_MPEG_REG(adr);
  3455. pr_info("CBUS reg[%x]=%x\n", adr, value);
  3456. }
  3457. else if(buf[1]=='p'){
  3458. value = READ_APB_REG(adr);
  3459. pr_info("APB reg[%x]=%x\n", adr, value);
  3460. }
  3461. else if(buf[1]=='l'){
  3462. WRITE_MPEG_REG(MDB_CTRL, 2);
  3463. WRITE_MPEG_REG(MDB_ADDR_REG, adr);
  3464. value = READ_MPEG_REG(MDB_DATA_REG);
  3465. pr_info("LMEM[%x]=%x\n", adr, value);
  3466. }
  3467. else if(buf[1]=='r'){
  3468. WRITE_MPEG_REG(MDB_CTRL, 1);
  3469. WRITE_MPEG_REG(MDB_ADDR_REG, adr);
  3470. value = READ_MPEG_REG(MDB_DATA_REG);
  3471. pr_info("amrisc reg[%x]=%x\n", adr, value);
  3472. }
  3473. }
  3474. else if(tmpbuf[0]=='v'){
  3475. printk("------------------\nHdmirx driver version: %s\n", HDMIRX_VER);
  3476. printk("------------------\n");
  3477. }
  3478. else if(strncmp(tmpbuf, "cec", 3)==0){
  3479. int j = 0;
  3480. int i_pre = 0;
  3481. char buf_tmp[128];
  3482. char tmp[128];
  3483. if (size > 30) return;
  3484. memcpy(buf_tmp, buf, size);
  3485. buf_tmp[size] = ' ';
  3486. for(i = 0; ; i++){
  3487. if (i > size)
  3488. break;
  3489. if (buf[i] == ' '){
  3490. if (i_pre != 0){
  3491. tmp[j] = simple_strtoul(&buf[i_pre+1], NULL, 10);
  3492. j++;
  3493. }
  3494. i_pre = i;
  3495. }
  3496. }
  3497. cec_test_function(tmp, j);
  3498. }
  3499. return 0;
  3500. }
  3501. int hdmirx_hw_dump_reg(unsigned char* buf, int size)
  3502. {
  3503. int i, j;
  3504. for(i = 0; i<0x900; i++){
  3505. buf[i] = hdmi_rd_reg(RX_BASE_ADDR + i);
  3506. }
  3507. for(j = 0; j<=0xc; j++){
  3508. buf[j] = hdmi_rd_reg(OTHER_BASE_ADDR + j);
  3509. }
  3510. return (i+j);
  3511. }
  3512. /*
  3513. * EDID
  3514. */
  3515. #define MAX_EDID_BUF_SIZE 1024
  3516. static char edid_buf[MAX_EDID_BUF_SIZE];
  3517. static int edid_size = 0;
  3518. int hdmirx_read_edid_buf(char* buf, int max_size)
  3519. {
  3520. if(edid_size > max_size){
  3521. pr_err("Error: %s, edid size %d is larger than the buf size of %d\n", __func__, edid_size, max_size);
  3522. return 0;
  3523. }
  3524. memcpy(buf, edid_buf, edid_size);
  3525. pr_info("HDMIRX: read edid buf\n");
  3526. return edid_size;
  3527. }
  3528. void hdmirx_fill_edid_buf(const char* buf, int size)
  3529. {
  3530. if(size > MAX_EDID_BUF_SIZE){
  3531. pr_err("Error: %s, edid size %d is larger than the max size of %d\n", __func__, size, MAX_EDID_BUF_SIZE);
  3532. return;
  3533. }
  3534. memcpy(edid_buf, buf, size);
  3535. edid_size = size;
  3536. pr_info("HDMIRX: fill edid buf, size %d\n", size);
  3537. }
  3538. //#define EDID_SW
  3539. #define EDID_3D_12BIT
  3540. //#define EDID_3D
  3541. static unsigned char hdmirx_8bit_3d_edid_port1[] =
  3542. {
  3543. //8 bit only with 3D
  3544. 0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x4d ,0x77 ,0x02 ,0x2c ,0x01 ,0x01 ,0x01 ,0x01,
  3545. 0x01 ,0x15 ,0x01 ,0x03 ,0x80 ,0x85 ,0x4b ,0x78 ,0x0a ,0x0d ,0xc9 ,0xa0 ,0x57 ,0x47 ,0x98 ,0x27,
  3546. 0x12 ,0x48 ,0x4c ,0x21 ,0x08 ,0x00 ,0x81 ,0x80 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01,
  3547. 0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x02 ,0x3a ,0x80 ,0x18 ,0x71 ,0x38 ,0x2d ,0x40 ,0x58 ,0x2c,
  3548. 0x45 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00 ,0x72 ,0x51 ,0xd0 ,0x1e ,0x20,
  3549. 0x6e ,0x28 ,0x55 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x00 ,0x00 ,0x00 ,0xfc ,0x00 ,0x53,
  3550. 0x6b ,0x79 ,0x77 ,0x6f ,0x72 ,0x74 ,0x68 ,0x20 ,0x54 ,0x56 ,0x0a ,0x20 ,0x00 ,0x00 ,0x00 ,0xfd,
  3551. 0x00 ,0x30 ,0x3e ,0x0e ,0x46 ,0x0f ,0x00 ,0x0a ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x01 ,0xdc,
  3552. 0x02 ,0x03 ,0x3b ,0xf0 ,0x53 ,0x1f ,0x10 ,0x14 ,0x05 ,0x13 ,0x04 ,0x20 ,0x22 ,0x3c ,0x3e ,0x12,
  3553. 0x16 ,0x03 ,0x07 ,0x11 ,0x15 ,0x02 ,0x06 ,0x01 ,0x23 ,0x09 ,0x07 ,0x01 ,0x83 ,0x01 ,0x00 ,0x00,
  3554. 0x74 ,0x03 ,0x0c ,0x00 ,0x10 ,0x00 ,0x88 ,0x2d ,0x2f ,0xd0 ,0x0a ,0x01 ,0x40 ,0x00 ,0x7f ,0x20,
  3555. 0x30 ,0x70 ,0x80 ,0x90 ,0x76 ,0xe2 ,0x00 ,0xfb ,0x02 ,0x3a ,0x80 ,0xd0 ,0x72 ,0x38 ,0x2d ,0x40,
  3556. 0x10 ,0x2c ,0x45 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00 ,0xbc ,0x52 ,0xd0,
  3557. 0x1e ,0x20 ,0xb8 ,0x28 ,0x55 ,0x40 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x80 ,0xd0,
  3558. 0x72 ,0x1c ,0x16 ,0x20 ,0x10 ,0x2c ,0x25 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x9e ,0x00 ,0x00,
  3559. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x8e
  3560. };
  3561. static unsigned char hdmirx_8bit_3d_edid_port2[] =
  3562. {
  3563. //8 bit only with 3D
  3564. 0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x4d ,0x77 ,0x02 ,0x2c ,0x01 ,0x01 ,0x01 ,0x01,
  3565. 0x01 ,0x15 ,0x01 ,0x03 ,0x80 ,0x85 ,0x4b ,0x78 ,0x0a ,0x0d ,0xc9 ,0xa0 ,0x57 ,0x47 ,0x98 ,0x27,
  3566. 0x12 ,0x48 ,0x4c ,0x21 ,0x08 ,0x00 ,0x81 ,0x80 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01,
  3567. 0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x02 ,0x3a ,0x80 ,0x18 ,0x71 ,0x38 ,0x2d ,0x40 ,0x58 ,0x2c,
  3568. 0x45 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00 ,0x72 ,0x51 ,0xd0 ,0x1e ,0x20,
  3569. 0x6e ,0x28 ,0x55 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x00 ,0x00 ,0x00 ,0xfc ,0x00 ,0x53,
  3570. 0x6b ,0x79 ,0x77 ,0x6f ,0x72 ,0x74 ,0x68 ,0x20 ,0x54 ,0x56 ,0x0a ,0x20 ,0x00 ,0x00 ,0x00 ,0xfd,
  3571. 0x00 ,0x30 ,0x3e ,0x0e ,0x46 ,0x0f ,0x00 ,0x0a ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x01 ,0xdc,
  3572. 0x02 ,0x03 ,0x3b ,0xf0 ,0x53 ,0x1f ,0x10 ,0x14 ,0x05 ,0x13 ,0x04 ,0x20 ,0x22 ,0x3c ,0x3e ,0x12,
  3573. 0x16 ,0x03 ,0x07 ,0x11 ,0x15 ,0x02 ,0x06 ,0x01 ,0x23 ,0x09 ,0x07 ,0x01 ,0x83 ,0x01 ,0x00 ,0x00,
  3574. 0x74 ,0x03 ,0x0c ,0x00 ,0x20 ,0x00 ,0x88 ,0x2d ,0x2f ,0xd0 ,0x0a ,0x01 ,0x40 ,0x00 ,0x7f ,0x20,
  3575. 0x30 ,0x70 ,0x80 ,0x90 ,0x76 ,0xe2 ,0x00 ,0xfb ,0x02 ,0x3a ,0x80 ,0xd0 ,0x72 ,0x38 ,0x2d ,0x40,
  3576. 0x10 ,0x2c ,0x45 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00 ,0xbc ,0x52 ,0xd0,
  3577. 0x1e ,0x20 ,0xb8 ,0x28 ,0x55 ,0x40 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x80 ,0xd0,
  3578. 0x72 ,0x1c ,0x16 ,0x20 ,0x10 ,0x2c ,0x25 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x9e ,0x00 ,0x00,
  3579. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x7e
  3580. };
  3581. static unsigned char hdmirx_8bit_3d_edid_port3[] =
  3582. {
  3583. //8 bit only with 3D
  3584. 0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x4d ,0x77 ,0x02 ,0x2c ,0x01 ,0x01 ,0x01 ,0x01,
  3585. 0x01 ,0x15 ,0x01 ,0x03 ,0x80 ,0x85 ,0x4b ,0x78 ,0x0a ,0x0d ,0xc9 ,0xa0 ,0x57 ,0x47 ,0x98 ,0x27,
  3586. 0x12 ,0x48 ,0x4c ,0x21 ,0x08 ,0x00 ,0x81 ,0x80 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01,
  3587. 0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x02 ,0x3a ,0x80 ,0x18 ,0x71 ,0x38 ,0x2d ,0x40 ,0x58 ,0x2c,
  3588. 0x45 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00 ,0x72 ,0x51 ,0xd0 ,0x1e ,0x20,
  3589. 0x6e ,0x28 ,0x55 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x00 ,0x00 ,0x00 ,0xfc ,0x00 ,0x53,
  3590. 0x6b ,0x79 ,0x77 ,0x6f ,0x72 ,0x74 ,0x68 ,0x20 ,0x54 ,0x56 ,0x0a ,0x20 ,0x00 ,0x00 ,0x00 ,0xfd,
  3591. 0x00 ,0x30 ,0x3e ,0x0e ,0x46 ,0x0f ,0x00 ,0x0a ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x01 ,0xdc,
  3592. 0x02 ,0x03 ,0x3b ,0xf0 ,0x53 ,0x1f ,0x10 ,0x14 ,0x05 ,0x13 ,0x04 ,0x20 ,0x22 ,0x3c ,0x3e ,0x12,
  3593. 0x16 ,0x03 ,0x07 ,0x11 ,0x15 ,0x02 ,0x06 ,0x01 ,0x23 ,0x09 ,0x07 ,0x01 ,0x83 ,0x01 ,0x00 ,0x00,
  3594. 0x74 ,0x03 ,0x0c ,0x00 ,0x30 ,0x00 ,0x88 ,0x2d ,0x2f ,0xd0 ,0x0a ,0x01 ,0x40 ,0x00 ,0x7f ,0x20,
  3595. 0x30 ,0x70 ,0x80 ,0x90 ,0x76 ,0xe2 ,0x00 ,0xfb ,0x02 ,0x3a ,0x80 ,0xd0 ,0x72 ,0x38 ,0x2d ,0x40,
  3596. 0x10 ,0x2c ,0x45 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00 ,0xbc ,0x52 ,0xd0,
  3597. 0x1e ,0x20 ,0xb8 ,0x28 ,0x55 ,0x40 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x80 ,0xd0,
  3598. 0x72 ,0x1c ,0x16 ,0x20 ,0x10 ,0x2c ,0x25 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x9e ,0x00 ,0x00,
  3599. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x6e
  3600. };
  3601. static unsigned char hdmirx_default_edid [] =
  3602. {
  3603. #if (defined EDID_SW)
  3604. 0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x4d ,0x77 ,0x01 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
  3605. 0x01 ,0x0f ,0x01 ,0x03 ,0x80 ,0x3c ,0x22 ,0x78 ,0x0a ,0x0d ,0xc9 ,0xa0 ,0x57 ,0x47 ,0x98 ,0x27,
  3606. 0x12 ,0x48 ,0x4c ,0xbf ,0xee ,0x00 ,0x81 ,0x80 ,0x8b ,0x00 ,0x81 ,0xc0 ,0x61 ,0x40 ,0x45 ,0x40,
  3607. 0x8b ,0xc0 ,0x01 ,0x01 ,0x01 ,0x01 ,0x8c ,0x0a ,0xd0 ,0x8a ,0x20 ,0xe0 ,0x2d ,0x10 ,0x10 ,0x3e,
  3608. 0x96 ,0x00 ,0x13 ,0x8e ,0x21 ,0x00 ,0x00 ,0x18 ,0x01 ,0x1d ,0x80 ,0x18 ,0x71 ,0x1c ,0x16 ,0x20,
  3609. 0x58 ,0x2c ,0x25 ,0x00 ,0xc4 ,0x8e ,0x21 ,0x00 ,0x00 ,0x9e ,0x00 ,0x00 ,0x00 ,0xfc ,0x00 ,0x53,
  3610. 0x6b ,0x79 ,0x77 ,0x6f ,0x72 ,0x74 ,0x68 ,0x20 ,0x4c ,0x43 ,0x44 ,0x0a ,0x00 ,0x00 ,0x00 ,0xfd,
  3611. 0x00 ,0x31 ,0x4c ,0x0f ,0x60 ,0x0e ,0x00 ,0x0a ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x01 ,0x21,
  3612. 0x02 ,0x03 ,0x26 ,0x74 ,0x4b ,0x84 ,0x10 ,0x1f ,0x05 ,0x13 ,0x14 ,0x01 ,0x02 ,0x11 ,0x06 ,0x15,
  3613. 0x26 ,0x09 ,0x7f ,0x03 ,0x11 ,0x7f ,0x18 ,0x83 ,0x01 ,0x00 ,0x00 ,0x6a ,0x03 ,0x0c ,0x00 ,0x10,
  3614. 0x00 ,0xb8 ,0x2d ,0x2f ,0x80 ,0x00 ,0x01 ,0x1d ,0x00 ,0xbc ,0x52 ,0xd0 ,0x1e ,0x20 ,0xb8 ,0x28,
  3615. 0x55 ,0x40 ,0xc4 ,0x8e ,0x21 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x80 ,0xd0 ,0x72 ,0x1c ,0x16 ,0x20,
  3616. 0x10 ,0x2c ,0x25 ,0x80 ,0xc4 ,0x8e ,0x21 ,0x00 ,0x00 ,0x9e ,0x8c ,0x0a ,0xd0 ,0x8a ,0x20 ,0xe0,
  3617. 0x2d ,0x10 ,0x10 ,0x3e ,0x96 ,0x00 ,0x13 ,0x8e ,0x21 ,0x00 ,0x00 ,0x18 ,0x8c ,0x0a ,0xd0 ,0x90,
  3618. 0x20 ,0x40 ,0x31 ,0x20 ,0x0c ,0x40 ,0x55 ,0x00 ,0x13 ,0x8e ,0x21 ,0x00 ,0x00 ,0x18 ,0x00 ,0x00,
  3619. 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x9d,
  3620. #elif (defined EDID_3D_12BIT)
  3621. 0x00 ,0xff ,0xff ,0xff ,0xff ,0xff ,0xff ,0x00 ,0x4d ,0xd9 ,0x02 ,0x2c ,0x01 ,0x01 ,0x01 ,0x01,
  3622. 0x01 ,0x15 ,0x01 ,0x03 ,0x80 ,0x85 ,0x4b ,0x78 ,0x0a ,0x0d ,0xc9 ,0xa0 ,0x57 ,0x47 ,0x98 ,0x27,
  3623. 0x12 ,0x48 ,0x4c ,0x21 ,0x08 ,0x00 ,0x81 ,0x80 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01,
  3624. 0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x01 ,0x02 ,0x3a ,0x80 ,0x18 ,0x71 ,0x38 ,0x2d ,0x40 ,0x58 ,0x2c,
  3625. 0x45 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00 ,0x72 ,0x51 ,0xd0 ,0x1e ,0x20,
  3626. 0x6e ,0x28 ,0x55 ,0x00 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x00 ,0x00 ,0x00 ,0xfc ,0x00 ,0x53,
  3627. 0x4f ,0x4e ,0x59 ,0x20 ,0x54 ,0x56 ,0x0a ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x00 ,0x00 ,0x00 ,0xfd,
  3628. 0x00 ,0x30 ,0x3e ,0x0e ,0x46 ,0x0f ,0x00 ,0x0a ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x01 ,0x1c,
  3629. 0x02 ,0x03 ,0x3b ,0xf0 ,0x53 ,0x1f ,0x10 ,0x14 ,0x05 ,0x13 ,0x04 ,0x20 ,0x22 ,0x3c ,0x3e ,0x12,
  3630. 0x16 ,0x03 ,0x07 ,0x11 ,0x15 ,0x02 ,0x06 ,0x01 ,0x26 ,0x09 ,0x07 ,0x07 ,0x15 ,0x07 ,0x50 ,0x83,
  3631. 0x01 ,0x00 ,0x00 ,0x74 ,0x03 ,0x0c ,0x00 ,0x20 ,0x00 ,0xb8 ,0x2d ,0x2f ,0xd0 ,0x0a ,0x01 ,0x40,
  3632. 0x00 ,0x7f ,0x20 ,0x30 ,0x70 ,0x80 ,0x90 ,0x76 ,0xe2 ,0x00 ,0xfb ,0x02 ,0x3a ,0x80 ,0xd0 ,0x72,
  3633. 0x38 ,0x2d ,0x40 ,0x10 ,0x2c ,0x45 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01 ,0x1d ,0x00,
  3634. 0xbc ,0x52 ,0xd0 ,0x1e ,0x20 ,0xb8 ,0x28 ,0x55 ,0x40 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00 ,0x1e ,0x01,
  3635. 0x1d ,0x80 ,0xd0 ,0x72 ,0x1c ,0x16 ,0x20 ,0x10 ,0x2c ,0x25 ,0x80 ,0x30 ,0xeb ,0x52 ,0x00 ,0x00,
  3636. 0x9e ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0xd9,
  3637. #elif (defined EDID_3D)
  3638. 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x4c, 0x2d, 0x9b, 0x06, 0x01, 0x00, 0x00, 0x00,
  3639. 0x33, 0x13, 0x01, 0x03, 0x80, 0x66, 0x39, 0x78, 0x0a, 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26,
  3640. 0x0f, 0x50, 0x54, 0xbd, 0xef, 0x80, 0x71, 0x4f, 0x81, 0x00, 0x81, 0x40, 0x81, 0x80, 0x95, 0x00,
  3641. 0x95, 0x0f, 0xb3, 0x00, 0xa9, 0x40, 0x02, 0x3a, 0x80, 0x18, 0x71, 0x38, 0x2d, 0x40, 0x58, 0x2c,
  3642. 0x45, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x66, 0x21, 0x50, 0xb0, 0x51, 0x00, 0x1b, 0x30,
  3643. 0x40, 0x70, 0x36, 0x00, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18,
  3644. 0x4b, 0x1a, 0x51, 0x17, 0x00, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xfc,
  3645. 0x00, 0x53, 0x41, 0x4d, 0x53, 0x55, 0x4e, 0x47, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x6b,
  3646. 0x02, 0x03, 0x3e, 0xf1, 0x4b, 0x90, 0x1f, 0x04, 0x13, 0x05, 0x14, 0x03, 0x12, 0x20, 0x21, 0x22,
  3647. 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0xe2, 0x00, 0x0f, 0xe3, 0x05, 0x03, 0x01, 0x7e,
  3648. 0x03, 0x0c, 0x00, 0x40, 0x00, 0xb8, 0x2d, 0x20, 0xc0, 0x14, 0x00, 0x01, 0x01, 0x0c, 0x08, 0x20,
  3649. 0x18, 0x20, 0x28, 0x20, 0x38, 0x20, 0x48, 0x20, 0x58, 0x20, 0x88, 0x20, 0xa8, 0x20, 0x02, 0x3a,
  3650. 0x80, 0xd0, 0x72, 0x38, 0x2d, 0x40, 0x10, 0x2c, 0x45, 0x80, 0xa0, 0x5a, 0x00, 0x00, 0x00, 0x1e,
  3651. 0x01, 0x1d, 0x00, 0xbc, 0x52, 0xd0, 0x1e, 0x20, 0xb8, 0x28, 0x55, 0x40, 0xa0, 0x5a, 0x00, 0x00,
  3652. 0x00, 0x1e, 0x01, 0x1d, 0x80, 0xd0, 0x72, 0x1c, 0x16, 0x20, 0x10, 0x2c, 0x25, 0x80, 0xa0, 0x5a,
  3653. 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5d
  3654. #else
  3655. 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x4D,0x77,0x00,0x32,0x00,0x00,0x00,0x00,
  3656. 0x1B,0x12,0x01,0x03,0x80,0x46,0x28,0x78,0xCA,0x0D,0xC9,0xA0,0x57,0x47,0x98,0x27,
  3657. 0x12,0x48,0x4C,0xBF,0xCF,0x00,0x61,0x00,0x61,0x40,0x61,0x80,0x61,0xC0,0x81,0x00,
  3658. 0x81,0x40,0x81,0x80,0x81,0xC0,0x01,0x1D,0x00,0x72,0x51,0xD0,0x1E,0x20,0x6E,0x28,
  3659. 0x55,0x00,0xC4,0x8E,0x21,0x00,0x00,0x1E,0x00,0x00,0x00,0xFD,0x00,0x2F,0x50,0x1E,
  3660. 0x50,0x0F,0x00,0x0A,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0xFC,0x00,0x73,
  3661. 0x6B,0x79,0x77,0x6F,0x72,0x74,0x68,0x2D,0x6C,0x63,0x64,0x0A,0x00,0x00,0x00,0x10,
  3662. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0xF0,
  3663. 0x02,0x03,0x21,0x71,0x4B,0x84,0x03,0x05,0x0A,0x12,0x13,0x14,0x15,0x10,0x1F,0x06,
  3664. 0x23,0x0F,0x07,0x07,0x83,0x4F,0x00,0x00,0x68,0x03,0x0C,0x00,0x10,0x00,0x38,0x2D,
  3665. 0x00,0x01,0x1D,0x00,0x72,0x51,0xD0,0x1E,0x20,0x6E,0x28,0x55,0x00,0xE8,0x12,0x11,
  3666. 0x00,0x00,0x1E,0x8C,0x0A,0xD0,0x90,0x20,0x40,0x31,0x20,0x0C,0x40,0x55,0x00,0xE8,
  3667. 0x12,0x11,0x00,0x00,0x18,0x8C,0x0A,0xD0,0x8A,0x20,0xE0,0x2D,0x10,0x10,0x3E,0x96,
  3668. 0x00,0xE8,0x12,0x11,0x00,0x00,0x18,0x01,0x1D,0x80,0x18,0x71,0x1C,0x16,0x20,0x58,
  3669. 0x2C,0x25,0x00,0xC4,0x8E,0x21,0x00,0x00,0x9E,0x01,0x1D,0x80,0xD0,0x72,0x1C,0x16,
  3670. 0x20,0x10,0x2C,0x25,0x80,0xC4,0x8E,0x21,0x00,0x00,0x9E,0x00,0x00,0x00,0x00,0x0E
  3671. #endif
  3672. };
  3673. void task_rx_edid_setting(void)
  3674. {
  3675. int i, ram_addr, byte_num;
  3676. unsigned int value;
  3677. //printk("HDMI_OTHER_CTRL2=%x\n", hdmi_rd_reg(OTHER_BASE_ADDR+HDMI_OTHER_CTRL2));
  3678. if(edid_mode == 0x100){ //at least one block
  3679. pr_info("edid: use custom edid\n");
  3680. for (i = 0; i < edid_size; i++)
  3681. {
  3682. value = edid_buf[i];
  3683. ram_addr = RX_EDID_OFFSET+i;
  3684. hdmi_wr_reg(ram_addr, value ^ ENCRYPT_KEY);
  3685. }
  3686. }
  3687. else{
  3688. if(edid_mode == 0){
  3689. unsigned char * p_edid_array;
  3690. if (hdmirx_hw_stru.port == 0x4) {
  3691. byte_num = sizeof(hdmirx_8bit_3d_edid_port3)/sizeof(unsigned char);
  3692. p_edid_array = hdmirx_8bit_3d_edid_port3;
  3693. }
  3694. else if (hdmirx_hw_stru.port == 0x2) {
  3695. byte_num = sizeof(hdmirx_8bit_3d_edid_port2)/sizeof(unsigned char);
  3696. p_edid_array = hdmirx_8bit_3d_edid_port2;
  3697. }
  3698. else {
  3699. byte_num = sizeof(hdmirx_8bit_3d_edid_port1)/sizeof(unsigned char);
  3700. p_edid_array = hdmirx_8bit_3d_edid_port1;
  3701. }
  3702. for (i = 0; i < byte_num; i++)
  3703. {
  3704. value = p_edid_array[i];
  3705. ram_addr = RX_EDID_OFFSET+i;
  3706. hdmi_wr_reg(ram_addr, value ^ ENCRYPT_KEY);
  3707. }
  3708. }
  3709. else if(edid_mode == 1){
  3710. byte_num = sizeof(hdmirx_default_edid)/sizeof(unsigned char);
  3711. for (i = 0; i < byte_num; i++)
  3712. {
  3713. value = hdmirx_default_edid[i];
  3714. ram_addr = RX_EDID_OFFSET+i;
  3715. hdmi_wr_reg(ram_addr, value ^ ENCRYPT_KEY);
  3716. }
  3717. }
  3718. }
  3719. }
  3720. static unsigned char internal_mode_valid(void)
  3721. {
  3722. if(((internal_mode>>16)&0xffff)==0x3456){
  3723. return 1;
  3724. }
  3725. else{
  3726. return 0;
  3727. }
  3728. }
  3729. static int eq_mode_monitor(void)
  3730. {
  3731. int ret = 0;
  3732. if(internal_mode_valid()){
  3733. if(eq_mode != hdmirx_hw_stru.cur_eq_mode){
  3734. hdmirx_hw_stru.cur_eq_mode = eq_mode&0xff;
  3735. switch(hdmirx_hw_stru.cur_eq_mode){
  3736. case 0:
  3737. case 0xff:
  3738. eq_config = 0x7; //default value
  3739. break;
  3740. case 1:
  3741. eq_config = 0x15;
  3742. break;
  3743. case 2:
  3744. eq_config = 0x13;
  3745. break;
  3746. case 3:
  3747. eq_config = 0x11;
  3748. break;
  3749. case 4:
  3750. eq_config = 0x207;
  3751. break;
  3752. default:
  3753. eq_config = 0x7;
  3754. break;
  3755. }
  3756. ret = 1;
  3757. }
  3758. }
  3759. else{
  3760. /* (((internal_mode>>16)&0xffff)==0x3455): for changging eq_config by uart console */
  3761. if(((internal_mode>>16)&0xffff)!=0x3455){
  3762. eq_config = 0x7;
  3763. }
  3764. }
  3765. return ret;
  3766. }
  3767. static int internal_mode_monitor(void)
  3768. {
  3769. int ret = 0;
  3770. if(internal_mode_valid()){
  3771. if(internal_mode&INT_MODE_FULL_FORMAT){
  3772. format_en0 = 0xffffffff;
  3773. format_en1 = 0xffffffff;
  3774. format_en2 = 0xffffffff;
  3775. format_en3 = 0xffffffff;
  3776. }
  3777. else{
  3778. format_en0 = format_en0_default;
  3779. format_en1 = format_en1_default;
  3780. format_en2 = format_en2_default;
  3781. format_en3 = format_en3_default;
  3782. }
  3783. }
  3784. else{
  3785. format_en0 = format_en0_default;
  3786. format_en1 = format_en1_default;
  3787. format_en2 = format_en2_default;
  3788. format_en3 = format_en3_default;
  3789. }
  3790. return ret;
  3791. }
  3792. MODULE_PARM_DESC(hdmirx_log_flag, "\n hdmirx_log_flag \n");
  3793. module_param(hdmirx_log_flag, int, 0664);
  3794. MODULE_PARM_DESC(sm_pause, "\n sm_pause \n");
  3795. module_param(sm_pause, int, 0664);
  3796. MODULE_PARM_DESC(force_vic, "\n force_vic \n");
  3797. module_param(force_vic, int, 0664);
  3798. MODULE_PARM_DESC(audio_enable, "\n audio_enable \n");
  3799. module_param(audio_enable, int, 0664);
  3800. MODULE_PARM_DESC(eq_enable, "\n eq_enable \n");
  3801. module_param(eq_enable, int, 0664);
  3802. MODULE_PARM_DESC(eq_config, "\n eq_config \n");
  3803. module_param(eq_config, int, 0664);
  3804. MODULE_PARM_DESC(eq_mode, "\n eq_mode \n");
  3805. module_param(eq_mode, int, 0664);
  3806. MODULE_PARM_DESC(eq_mode_max, "\n eq_mode_max \n");
  3807. module_param(eq_mode_max, int, 0664);
  3808. MODULE_PARM_DESC(internal_mode, "\n internal_mode \n");
  3809. module_param(internal_mode, int, 0664);
  3810. MODULE_PARM_DESC(signal_check_mode, "\n signal_check_mode \n");
  3811. module_param(signal_check_mode, int, 0664);
  3812. MODULE_PARM_DESC(signal_recover_mode, "\n signal_recover_mode \n");
  3813. module_param(signal_recover_mode, int, 0664);
  3814. MODULE_PARM_DESC(switch_mode, "\n switch_mode \n");
  3815. module_param(switch_mode, int, 0664);
  3816. MODULE_PARM_DESC(edid_mode, "\n edid_mode \n");
  3817. module_param(edid_mode, int, 0664);
  3818. MODULE_PARM_DESC(dvi_mode, "\n dvi_mode \n");
  3819. module_param(dvi_mode, int, 0664);
  3820. MODULE_PARM_DESC(color_format_mode, "\n color_format_mode \n");
  3821. module_param(color_format_mode, int, 0664);
  3822. MODULE_PARM_DESC(check_color_depth_mode, "\n check_color_depth_mode \n");
  3823. module_param(check_color_depth_mode, int, 0664);
  3824. MODULE_PARM_DESC(reset_threshold, "\n reset_threshold \n");
  3825. module_param(reset_threshold, int, 0664);
  3826. MODULE_PARM_DESC(delay1, "\n delay1 \n");
  3827. module_param(delay1, int, 0664);
  3828. MODULE_PARM_DESC(delay2, "\n delay2 \n");
  3829. module_param(delay2, int, 0664);
  3830. MODULE_PARM_DESC(delay3, "\n delay3 \n");
  3831. module_param(delay3, int, 0664);
  3832. MODULE_PARM_DESC(delay4, "\n delay4 \n");
  3833. module_param(delay4, int, 0664);
  3834. MODULE_PARM_DESC(hpd_ready_time, "\n hpd_ready_time \n");
  3835. module_param(hpd_ready_time, int, 0664);
  3836. MODULE_PARM_DESC(hpd_start_time, "\n hpd_start_time \n");
  3837. module_param(hpd_start_time, int, 0664);
  3838. MODULE_PARM_DESC(audio_stable_time, "\n audio_stable_time \n");
  3839. module_param(audio_stable_time, int, 0664);
  3840. MODULE_PARM_DESC(vendor_specific_info_check_period, "\n vendor_specific_info_check_period \n");
  3841. module_param(vendor_specific_info_check_period, int, 0664);
  3842. MODULE_PARM_DESC(clk_stable_threshold, "\n clk_stable_threshold \n");
  3843. module_param(clk_stable_threshold, int, 0664);
  3844. MODULE_PARM_DESC(clk_unstable_threshold, "\n clk_unstable_threshold \n");
  3845. module_param(clk_unstable_threshold, int, 0664);
  3846. MODULE_PARM_DESC(dvi_detect_wait_avi_th, "\n dvi_detect_wait_avi_th \n");
  3847. module_param(dvi_detect_wait_avi_th, int, 0664);
  3848. MODULE_PARM_DESC(general_detect_wait_avi_th, "\n general_detect_wait_avi_th \n");
  3849. module_param(general_detect_wait_avi_th, int, 0664);
  3850. MODULE_PARM_DESC(aud_channel_status_modify_th, "\n aud_channel_status_modify_th \n");
  3851. module_param(aud_channel_status_modify_th, int, 0664);
  3852. MODULE_PARM_DESC(aud_channel_status_all_0_th, "\n aud_channel_status_all_0_th \n");
  3853. module_param(aud_channel_status_all_0_th, int, 0664);
  3854. MODULE_PARM_DESC(sample_rate_change_th, "\n sample_rate_change_th \n");
  3855. module_param(sample_rate_change_th, int, 0664);
  3856. MODULE_PARM_DESC(format_en0, "\n format_en0 \n");
  3857. module_param(format_en0, int, 0664);
  3858. MODULE_PARM_DESC(format_en1, "\n format_en1 \n");
  3859. module_param(format_en1, int, 0664);
  3860. MODULE_PARM_DESC(format_en2, "\n format_en2 \n");
  3861. module_param(format_en2, int, 0664);
  3862. MODULE_PARM_DESC(format_en3, "\n format_en3 \n");
  3863. module_param(format_en3, int, 0664);
  3864. MODULE_PARM_DESC(powerdown_enable, "\n powerdown_enable \n");
  3865. module_param(powerdown_enable, int, 0664);
  3866. MODULE_PARM_DESC(skip_unstable_frame, "\n skip_unstable_frame \n");
  3867. module_param(skip_unstable_frame, int, 0664);
  3868. MODULE_PARM_DESC(prbs_ch1_err_num, "\n prbs_ch1_err_num \n");
  3869. module_param(prbs_ch1_err_num, int, 0664);
  3870. MODULE_PARM_DESC(prbs_ch2_err_num, "\n prbs_ch2_err_num \n");
  3871. module_param(prbs_ch2_err_num, int, 0664);
  3872. MODULE_PARM_DESC(prbs_ch3_err_num, "\n prbs_ch3_err_num \n");
  3873. module_param(prbs_ch3_err_num, int, 0664);
  3874. MODULE_PARM_DESC(prbs_check_count, "\n prbs_check_count \n");
  3875. module_param(prbs_check_count, int, 0664);
  3876. MODULE_PARM_DESC(prbs_port_mode, "\n prbs_port_mode \n");
  3877. module_param(prbs_port_mode, int, 0664);
  3878. /*
  3879. for pioneer DV-400V 1080P, only below config make signal good
  3880. echo 0x11 > /sys/module/tvin_hdmirx/parameters/eq_config
  3881. cat /sys/module/tvin_hdmirx/parameters/eq_config
  3882. echo 0x10 > /sys/module/tvin_hdmirx/parameters/eq_config
  3883. cat /sys/module/tvin_hdmirx/parameters/eq_config
  3884. echo 0x110 > /sys/module/tvin_hdmirx/parameters/eq_config
  3885. cat /sys/module/tvin_hdmirx/parameters/eq_config
  3886. echo 0x111 > /sys/module/tvin_hdmirx/parameters/eq_config
  3887. cat /sys/module/tvin_hdmirx/parameters/eq_config
  3888. */