hdmi_msm.c 142 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990
  1. /* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. /* #define DEBUG */
  14. #define DEV_DBG_PREFIX "HDMI: "
  15. /* #define REG_DUMP */
  16. #define CEC_MSG_PRINT
  17. #define TOGGLE_CEC_HARDWARE_FSM
  18. #include <linux/types.h>
  19. #include <linux/bitops.h>
  20. #include <linux/clk.h>
  21. #include <linux/mutex.h>
  22. #include <mach/msm_hdmi_audio.h>
  23. #include <mach/clk.h>
  24. #include <mach/msm_iomap.h>
  25. #include <mach/socinfo.h>
  26. #include "msm_fb.h"
  27. #include "hdmi_msm.h"
  28. /* Supported HDMI Audio channels */
  29. #define MSM_HDMI_AUDIO_CHANNEL_2 0
  30. #define MSM_HDMI_AUDIO_CHANNEL_4 1
  31. #define MSM_HDMI_AUDIO_CHANNEL_6 2
  32. #define MSM_HDMI_AUDIO_CHANNEL_8 3
  33. #define MSM_HDMI_AUDIO_CHANNEL_MAX 4
  34. #define MSM_HDMI_AUDIO_CHANNEL_FORCE_32BIT 0x7FFFFFFF
  35. /* Supported HDMI Audio sample rates */
  36. #define MSM_HDMI_SAMPLE_RATE_32KHZ 0
  37. #define MSM_HDMI_SAMPLE_RATE_44_1KHZ 1
  38. #define MSM_HDMI_SAMPLE_RATE_48KHZ 2
  39. #define MSM_HDMI_SAMPLE_RATE_88_2KHZ 3
  40. #define MSM_HDMI_SAMPLE_RATE_96KHZ 4
  41. #define MSM_HDMI_SAMPLE_RATE_176_4KHZ 5
  42. #define MSM_HDMI_SAMPLE_RATE_192KHZ 6
  43. #define MSM_HDMI_SAMPLE_RATE_MAX 7
  44. #define MSM_HDMI_SAMPLE_RATE_FORCE_32BIT 0x7FFFFFFF
  45. static int msm_hdmi_sample_rate = MSM_HDMI_SAMPLE_RATE_48KHZ;
  46. /* HDMI/HDCP Registers */
  47. #define HDCP_DDC_STATUS 0x0128
  48. #define HDCP_DDC_CTRL_0 0x0120
  49. #define HDCP_DDC_CTRL_1 0x0124
  50. #define HDMI_DDC_CTRL 0x020C
  51. #define HPD_EVENT_OFFLINE 0
  52. #define HPD_EVENT_ONLINE 1
  53. #define SWITCH_SET_HDMI_AUDIO(d, force) \
  54. do {\
  55. if (!hdmi_msm_is_dvi_mode() &&\
  56. ((force) ||\
  57. (external_common_state->audio_sdev.state != (d)))) {\
  58. switch_set_state(&external_common_state->audio_sdev,\
  59. (d));\
  60. DEV_INFO("%s: hdmi_audio state switched to %d\n",\
  61. __func__,\
  62. external_common_state->audio_sdev.state);\
  63. } \
  64. } while (0)
  65. struct workqueue_struct *hdmi_work_queue;
  66. struct hdmi_msm_state_type *hdmi_msm_state;
  67. /* Enable HDCP by default */
  68. static bool hdcp_feature_on = true;
  69. DEFINE_MUTEX(hdmi_msm_state_mutex);
  70. EXPORT_SYMBOL(hdmi_msm_state_mutex);
  71. static DEFINE_MUTEX(hdcp_auth_state_mutex);
  72. static void hdmi_msm_dump_regs(const char *prefix);
  73. static void hdmi_msm_hdcp_enable(void);
  74. static void hdmi_msm_turn_on(void);
  75. static int hdmi_msm_audio_off(void);
  76. static int hdmi_msm_read_edid(void);
  77. static void hdmi_msm_hpd_off(void);
  78. static boolean hdmi_msm_is_dvi_mode(void);
  79. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  80. static void hdmi_msm_cec_line_latch_detect(void);
  81. #ifdef TOGGLE_CEC_HARDWARE_FSM
  82. static boolean msg_send_complete = TRUE;
  83. static boolean msg_recv_complete = TRUE;
  84. #endif
  85. #define HDMI_MSM_CEC_REFTIMER_REFTIMER_ENABLE BIT(16)
  86. #define HDMI_MSM_CEC_REFTIMER_REFTIMER(___t) (((___t)&0xFFFF) << 0)
  87. #define HDMI_MSM_CEC_TIME_SIGNAL_FREE_TIME(___t) (((___t)&0x1FF) << 7)
  88. #define HDMI_MSM_CEC_TIME_ENABLE BIT(0)
  89. #define HDMI_MSM_CEC_ADDR_LOGICAL_ADDR(___la) (((___la)&0xFF) << 0)
  90. #define HDMI_MSM_CEC_CTRL_LINE_OE BIT(9)
  91. #define HDMI_MSM_CEC_CTRL_FRAME_SIZE(___sz) (((___sz)&0x1F) << 4)
  92. #define HDMI_MSM_CEC_CTRL_SOFT_RESET BIT(2)
  93. #define HDMI_MSM_CEC_CTRL_SEND_TRIG BIT(1)
  94. #define HDMI_MSM_CEC_CTRL_ENABLE BIT(0)
  95. #define HDMI_MSM_CEC_INT_FRAME_RD_DONE_MASK BIT(7)
  96. #define HDMI_MSM_CEC_INT_FRAME_RD_DONE_ACK BIT(6)
  97. #define HDMI_MSM_CEC_INT_FRAME_RD_DONE_INT BIT(6)
  98. #define HDMI_MSM_CEC_INT_MONITOR_MASK BIT(5)
  99. #define HDMI_MSM_CEC_INT_MONITOR_ACK BIT(4)
  100. #define HDMI_MSM_CEC_INT_MONITOR_INT BIT(4)
  101. #define HDMI_MSM_CEC_INT_FRAME_ERROR_MASK BIT(3)
  102. #define HDMI_MSM_CEC_INT_FRAME_ERROR_ACK BIT(2)
  103. #define HDMI_MSM_CEC_INT_FRAME_ERROR_INT BIT(2)
  104. #define HDMI_MSM_CEC_INT_FRAME_WR_DONE_MASK BIT(1)
  105. #define HDMI_MSM_CEC_INT_FRAME_WR_DONE_ACK BIT(0)
  106. #define HDMI_MSM_CEC_INT_FRAME_WR_DONE_INT BIT(0)
  107. #define HDMI_MSM_CEC_FRAME_WR_SUCCESS(___st) (((___st)&0xB) ==\
  108. (HDMI_MSM_CEC_INT_FRAME_WR_DONE_INT |\
  109. HDMI_MSM_CEC_INT_FRAME_WR_DONE_MASK |\
  110. HDMI_MSM_CEC_INT_FRAME_ERROR_MASK))
  111. #define HDMI_MSM_CEC_RETRANSMIT_NUM(___num) (((___num)&0xF) << 4)
  112. #define HDMI_MSM_CEC_RETRANSMIT_ENABLE BIT(0)
  113. #define HDMI_MSM_CEC_WR_DATA_DATA(___d) (((___d)&0xFF) << 8)
  114. void hdmi_msm_cec_init(void)
  115. {
  116. /* 0x02A8 CEC_REFTIMER */
  117. HDMI_OUTP(0x02A8,
  118. HDMI_MSM_CEC_REFTIMER_REFTIMER_ENABLE
  119. | HDMI_MSM_CEC_REFTIMER_REFTIMER(27 * 50)
  120. );
  121. /*
  122. * 0x02A0 CEC_ADDR
  123. * Starting with a default address of 4
  124. */
  125. HDMI_OUTP(0x02A0, HDMI_MSM_CEC_ADDR_LOGICAL_ADDR(4));
  126. hdmi_msm_state->first_monitor = 0;
  127. hdmi_msm_state->fsm_reset_done = false;
  128. /* 0x029C CEC_INT */
  129. /* Enable CEC interrupts */
  130. HDMI_OUTP(0x029C, \
  131. HDMI_MSM_CEC_INT_FRAME_WR_DONE_MASK \
  132. | HDMI_MSM_CEC_INT_FRAME_ERROR_MASK \
  133. | HDMI_MSM_CEC_INT_MONITOR_MASK \
  134. | HDMI_MSM_CEC_INT_FRAME_RD_DONE_MASK);
  135. HDMI_OUTP(0x02B0, 0x7FF << 4 | 1);
  136. /*
  137. * Slight adjustment to logic 1 low periods on read,
  138. * CEC Test 8.2-3 was failing, 8 for the
  139. * BIT_1_ERR_RANGE_HI = 8 => 750us, the test used 775us,
  140. * so increased this to 9 which => 800us.
  141. */
  142. /*
  143. * CEC latch up issue - To fire monitor interrupt
  144. * for every start of message
  145. */
  146. HDMI_OUTP(0x02E0, 0x880000);
  147. /*
  148. * Slight adjustment to logic 0 low period on write
  149. */
  150. HDMI_OUTP(0x02DC, 0x8888A888);
  151. /*
  152. * Enable Signal Free Time counter and set to 7 bit periods
  153. */
  154. HDMI_OUTP(0x02A4, 0x1 | (7 * 0x30) << 7);
  155. /* 0x028C CEC_CTRL */
  156. HDMI_OUTP(0x028C, HDMI_MSM_CEC_CTRL_ENABLE);
  157. }
  158. void hdmi_msm_cec_write_logical_addr(int addr)
  159. {
  160. /* 0x02A0 CEC_ADDR
  161. * LOGICAL_ADDR 7:0 NUM
  162. */
  163. HDMI_OUTP(0x02A0, addr & 0xFF);
  164. }
  165. void hdmi_msm_dump_cec_msg(struct hdmi_msm_cec_msg *msg)
  166. {
  167. #ifdef CEC_MSG_PRINT
  168. int i;
  169. DEV_DBG("sender_id : %d", msg->sender_id);
  170. DEV_DBG("recvr_id : %d", msg->recvr_id);
  171. if (msg->frame_size < 2) {
  172. DEV_DBG("polling message");
  173. return;
  174. }
  175. DEV_DBG("opcode : %02x", msg->opcode);
  176. for (i = 0; i < msg->frame_size - 2; i++)
  177. DEV_DBG("operand(%2d) : %02x", i + 1, msg->operand[i]);
  178. #endif /* CEC_MSG_PRINT */
  179. }
  180. void hdmi_msm_cec_msg_send(struct hdmi_msm_cec_msg *msg)
  181. {
  182. int i;
  183. uint32 timeout_count = 1;
  184. int retry = 10;
  185. boolean frameType = (msg->recvr_id == 15 ? BIT(0) : 0);
  186. mutex_lock(&hdmi_msm_state_mutex);
  187. hdmi_msm_state->fsm_reset_done = false;
  188. mutex_unlock(&hdmi_msm_state_mutex);
  189. #ifdef TOGGLE_CEC_HARDWARE_FSM
  190. msg_send_complete = FALSE;
  191. #endif
  192. INIT_COMPLETION(hdmi_msm_state->cec_frame_wr_done);
  193. hdmi_msm_state->cec_frame_wr_status = 0;
  194. /* 0x0294 HDMI_MSM_CEC_RETRANSMIT */
  195. HDMI_OUTP(0x0294,
  196. #ifdef DRVR_ONLY_CECT_NO_DAEMON
  197. HDMI_MSM_CEC_RETRANSMIT_NUM(msg->retransmit)
  198. | (msg->retransmit > 0) ? HDMI_MSM_CEC_RETRANSMIT_ENABLE : 0);
  199. #else
  200. HDMI_MSM_CEC_RETRANSMIT_NUM(0) |
  201. HDMI_MSM_CEC_RETRANSMIT_ENABLE);
  202. #endif
  203. /* 0x028C CEC_CTRL */
  204. HDMI_OUTP(0x028C, 0x1 | msg->frame_size << 4);
  205. /* 0x0290 CEC_WR_DATA */
  206. /* header block */
  207. HDMI_OUTP(0x0290,
  208. HDMI_MSM_CEC_WR_DATA_DATA(msg->sender_id << 4 | msg->recvr_id)
  209. | frameType);
  210. /* data block 0 : opcode */
  211. HDMI_OUTP(0x0290,
  212. HDMI_MSM_CEC_WR_DATA_DATA(msg->frame_size < 2 ? 0 : msg->opcode)
  213. | frameType);
  214. /* data block 1-14 : operand 0-13 */
  215. for (i = 0; i < msg->frame_size - 1; i++)
  216. HDMI_OUTP(0x0290,
  217. HDMI_MSM_CEC_WR_DATA_DATA(msg->operand[i])
  218. | (msg->recvr_id == 15 ? BIT(0) : 0));
  219. for (; i < 14; i++)
  220. HDMI_OUTP(0x0290,
  221. HDMI_MSM_CEC_WR_DATA_DATA(0)
  222. | (msg->recvr_id == 15 ? BIT(0) : 0));
  223. while ((HDMI_INP(0x0298) & 1) && retry--) {
  224. DEV_DBG("CEC line is busy(%d)\n", retry);
  225. schedule();
  226. }
  227. /* 0x028C CEC_CTRL */
  228. HDMI_OUTP(0x028C,
  229. HDMI_MSM_CEC_CTRL_LINE_OE
  230. | HDMI_MSM_CEC_CTRL_FRAME_SIZE(msg->frame_size)
  231. | HDMI_MSM_CEC_CTRL_SEND_TRIG
  232. | HDMI_MSM_CEC_CTRL_ENABLE);
  233. timeout_count = wait_for_completion_interruptible_timeout(
  234. &hdmi_msm_state->cec_frame_wr_done, HZ);
  235. if (!timeout_count) {
  236. hdmi_msm_state->cec_frame_wr_status |= CEC_STATUS_WR_TMOUT;
  237. DEV_ERR("%s: timedout", __func__);
  238. hdmi_msm_dump_cec_msg(msg);
  239. } else {
  240. DEV_DBG("CEC write frame done (frame len=%d)",
  241. msg->frame_size);
  242. hdmi_msm_dump_cec_msg(msg);
  243. }
  244. #ifdef TOGGLE_CEC_HARDWARE_FSM
  245. if (!msg_recv_complete) {
  246. /* Toggle CEC hardware FSM */
  247. HDMI_OUTP(0x028C, 0x0);
  248. HDMI_OUTP(0x028C, HDMI_MSM_CEC_CTRL_ENABLE);
  249. msg_recv_complete = TRUE;
  250. }
  251. msg_send_complete = TRUE;
  252. #else
  253. HDMI_OUTP(0x028C, 0x0);
  254. HDMI_OUTP(0x028C, HDMI_MSM_CEC_CTRL_ENABLE);
  255. #endif
  256. }
  257. void hdmi_msm_cec_line_latch_detect(void)
  258. {
  259. /*
  260. * CECT 9-5-1
  261. * The timer period needs to be changed to appropriate value
  262. */
  263. /*
  264. * Timedout without RD_DONE, WR_DONE or ERR_INT
  265. * Toggle CEC hardware FSM
  266. */
  267. mutex_lock(&hdmi_msm_state_mutex);
  268. if (hdmi_msm_state->first_monitor == 1) {
  269. DEV_WARN("CEC line is probably latched up - CECT 9-5-1");
  270. if (!msg_recv_complete)
  271. hdmi_msm_state->fsm_reset_done = true;
  272. HDMI_OUTP(0x028C, 0x0);
  273. HDMI_OUTP(0x028C, HDMI_MSM_CEC_CTRL_ENABLE);
  274. hdmi_msm_state->first_monitor = 0;
  275. }
  276. mutex_unlock(&hdmi_msm_state_mutex);
  277. }
  278. void hdmi_msm_cec_msg_recv(void)
  279. {
  280. uint32 data;
  281. int i;
  282. #ifdef DRVR_ONLY_CECT_NO_DAEMON
  283. struct hdmi_msm_cec_msg temp_msg;
  284. #endif
  285. mutex_lock(&hdmi_msm_state_mutex);
  286. if (hdmi_msm_state->cec_queue_wr == hdmi_msm_state->cec_queue_rd
  287. && hdmi_msm_state->cec_queue_full) {
  288. mutex_unlock(&hdmi_msm_state_mutex);
  289. DEV_ERR("CEC message queue is overflowing\n");
  290. #ifdef DRVR_ONLY_CECT_NO_DAEMON
  291. /*
  292. * Without CEC daemon:
  293. * Compliance tests fail once the queue gets filled up.
  294. * so reset the pointers to the start of the queue.
  295. */
  296. hdmi_msm_state->cec_queue_wr = hdmi_msm_state->cec_queue_start;
  297. hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
  298. hdmi_msm_state->cec_queue_full = false;
  299. #else
  300. return;
  301. #endif
  302. }
  303. if (hdmi_msm_state->cec_queue_wr == NULL) {
  304. DEV_ERR("%s: wp is NULL\n", __func__);
  305. return;
  306. }
  307. mutex_unlock(&hdmi_msm_state_mutex);
  308. /* 0x02AC CEC_RD_DATA */
  309. data = HDMI_INP(0x02AC);
  310. hdmi_msm_state->cec_queue_wr->sender_id = (data & 0xF0) >> 4;
  311. hdmi_msm_state->cec_queue_wr->recvr_id = (data & 0x0F);
  312. hdmi_msm_state->cec_queue_wr->frame_size = (data & 0x1F00) >> 8;
  313. DEV_DBG("Recvd init=[%u] dest=[%u] size=[%u]\n",
  314. hdmi_msm_state->cec_queue_wr->sender_id,
  315. hdmi_msm_state->cec_queue_wr->recvr_id,
  316. hdmi_msm_state->cec_queue_wr->frame_size);
  317. if (hdmi_msm_state->cec_queue_wr->frame_size < 1) {
  318. DEV_ERR("%s: invalid message (frame length = %d)",
  319. __func__, hdmi_msm_state->cec_queue_wr->frame_size);
  320. return;
  321. } else if (hdmi_msm_state->cec_queue_wr->frame_size == 1) {
  322. DEV_DBG("%s: polling message (dest[%x] <- init[%x])",
  323. __func__,
  324. hdmi_msm_state->cec_queue_wr->recvr_id,
  325. hdmi_msm_state->cec_queue_wr->sender_id);
  326. return;
  327. }
  328. /* data block 0 : opcode */
  329. data = HDMI_INP(0x02AC);
  330. hdmi_msm_state->cec_queue_wr->opcode = data & 0xFF;
  331. /* data block 1-14 : operand 0-13 */
  332. for (i = 0; i < hdmi_msm_state->cec_queue_wr->frame_size - 2; i++) {
  333. data = HDMI_INP(0x02AC);
  334. hdmi_msm_state->cec_queue_wr->operand[i] = data & 0xFF;
  335. }
  336. for (; i < 14; i++)
  337. hdmi_msm_state->cec_queue_wr->operand[i] = 0;
  338. DEV_DBG("CEC read frame done\n");
  339. DEV_DBG("=======================================\n");
  340. hdmi_msm_dump_cec_msg(hdmi_msm_state->cec_queue_wr);
  341. DEV_DBG("=======================================\n");
  342. #ifdef DRVR_ONLY_CECT_NO_DAEMON
  343. switch (hdmi_msm_state->cec_queue_wr->opcode) {
  344. case 0x64:
  345. /* Set OSD String */
  346. DEV_INFO("Recvd OSD Str=[%x]\n",\
  347. hdmi_msm_state->cec_queue_wr->operand[3]);
  348. break;
  349. case 0x83:
  350. /* Give Phy Addr */
  351. DEV_INFO("Recvd a Give Phy Addr cmd\n");
  352. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  353. /* Setup a frame for sending out phy addr */
  354. temp_msg.sender_id = 0x4;
  355. /* Broadcast */
  356. temp_msg.recvr_id = 0xf;
  357. temp_msg.opcode = 0x84;
  358. i = 0;
  359. temp_msg.operand[i++] = 0x10;
  360. temp_msg.operand[i++] = 0x00;
  361. temp_msg.operand[i++] = 0x04;
  362. temp_msg.frame_size = i + 2;
  363. hdmi_msm_cec_msg_send(&temp_msg);
  364. break;
  365. case 0xFF:
  366. /* Abort */
  367. DEV_INFO("Recvd an abort cmd 0xFF\n");
  368. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  369. temp_msg.sender_id = 0x4;
  370. temp_msg.recvr_id = hdmi_msm_state->cec_queue_wr->sender_id;
  371. i = 0;
  372. /*feature abort */
  373. temp_msg.opcode = 0x00;
  374. temp_msg.operand[i++] =
  375. hdmi_msm_state->cec_queue_wr->opcode;
  376. /*reason for abort = "Refused" */
  377. temp_msg.operand[i++] = 0x04;
  378. temp_msg.frame_size = i + 2;
  379. hdmi_msm_dump_cec_msg(&temp_msg);
  380. hdmi_msm_cec_msg_send(&temp_msg);
  381. break;
  382. case 0x046:
  383. /* Give OSD name */
  384. DEV_INFO("Recvd cmd 0x046\n");
  385. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  386. temp_msg.sender_id = 0x4;
  387. temp_msg.recvr_id = hdmi_msm_state->cec_queue_wr->sender_id;
  388. i = 0;
  389. /* OSD Name */
  390. temp_msg.opcode = 0x47;
  391. /* Display control byte */
  392. temp_msg.operand[i++] = 0x00;
  393. temp_msg.operand[i++] = 'H';
  394. temp_msg.operand[i++] = 'e';
  395. temp_msg.operand[i++] = 'l';
  396. temp_msg.operand[i++] = 'l';
  397. temp_msg.operand[i++] = 'o';
  398. temp_msg.operand[i++] = ' ';
  399. temp_msg.operand[i++] = 'W';
  400. temp_msg.operand[i++] = 'o';
  401. temp_msg.operand[i++] = 'r';
  402. temp_msg.operand[i++] = 'l';
  403. temp_msg.operand[i++] = 'd';
  404. temp_msg.frame_size = i + 2;
  405. hdmi_msm_cec_msg_send(&temp_msg);
  406. break;
  407. case 0x08F:
  408. /* Give Device Power status */
  409. DEV_INFO("Recvd a Power status message\n");
  410. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  411. temp_msg.sender_id = 0x4;
  412. temp_msg.recvr_id = hdmi_msm_state->cec_queue_wr->sender_id;
  413. i = 0;
  414. /* OSD String */
  415. temp_msg.opcode = 0x90;
  416. temp_msg.operand[i++] = 'H';
  417. temp_msg.operand[i++] = 'e';
  418. temp_msg.operand[i++] = 'l';
  419. temp_msg.operand[i++] = 'l';
  420. temp_msg.operand[i++] = 'o';
  421. temp_msg.operand[i++] = ' ';
  422. temp_msg.operand[i++] = 'W';
  423. temp_msg.operand[i++] = 'o';
  424. temp_msg.operand[i++] = 'r';
  425. temp_msg.operand[i++] = 'l';
  426. temp_msg.operand[i++] = 'd';
  427. temp_msg.frame_size = i + 2;
  428. hdmi_msm_cec_msg_send(&temp_msg);
  429. break;
  430. case 0x080:
  431. /* Routing Change cmd */
  432. case 0x086:
  433. /* Set Stream Path */
  434. DEV_INFO("Recvd Set Stream\n");
  435. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  436. temp_msg.sender_id = 0x4;
  437. /*Broadcast this message*/
  438. temp_msg.recvr_id = 0xf;
  439. i = 0;
  440. temp_msg.opcode = 0x82; /* Active Source */
  441. temp_msg.operand[i++] = 0x10;
  442. temp_msg.operand[i++] = 0x00;
  443. temp_msg.frame_size = i + 2;
  444. hdmi_msm_cec_msg_send(&temp_msg);
  445. /*
  446. * sending <Image View On> message
  447. */
  448. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  449. temp_msg.sender_id = 0x4;
  450. temp_msg.recvr_id = hdmi_msm_state->cec_queue_wr->sender_id;
  451. i = 0;
  452. /* opcode for Image View On */
  453. temp_msg.opcode = 0x04;
  454. temp_msg.frame_size = i + 2;
  455. hdmi_msm_cec_msg_send(&temp_msg);
  456. break;
  457. case 0x44:
  458. /* User Control Pressed */
  459. DEV_INFO("User Control Pressed\n");
  460. break;
  461. case 0x45:
  462. /* User Control Released */
  463. DEV_INFO("User Control Released\n");
  464. break;
  465. default:
  466. DEV_INFO("Recvd an unknown cmd = [%u]\n",
  467. hdmi_msm_state->cec_queue_wr->opcode);
  468. #ifdef __SEND_ABORT__
  469. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  470. temp_msg.sender_id = 0x4;
  471. temp_msg.recvr_id = hdmi_msm_state->cec_queue_wr->sender_id;
  472. i = 0;
  473. /* opcode for feature abort */
  474. temp_msg.opcode = 0x00;
  475. temp_msg.operand[i++] =
  476. hdmi_msm_state->cec_queue_wr->opcode;
  477. /*reason for abort = "Unrecognized opcode" */
  478. temp_msg.operand[i++] = 0x00;
  479. temp_msg.frame_size = i + 2;
  480. hdmi_msm_cec_msg_send(&temp_msg);
  481. break;
  482. #else
  483. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  484. temp_msg.sender_id = 0x4;
  485. temp_msg.recvr_id = hdmi_msm_state->cec_queue_wr->sender_id;
  486. i = 0;
  487. /* OSD String */
  488. temp_msg.opcode = 0x64;
  489. temp_msg.operand[i++] = 0x0;
  490. temp_msg.operand[i++] = 'H';
  491. temp_msg.operand[i++] = 'e';
  492. temp_msg.operand[i++] = 'l';
  493. temp_msg.operand[i++] = 'l';
  494. temp_msg.operand[i++] = 'o';
  495. temp_msg.operand[i++] = ' ';
  496. temp_msg.operand[i++] = 'W';
  497. temp_msg.operand[i++] = 'o';
  498. temp_msg.operand[i++] = 'r';
  499. temp_msg.operand[i++] = 'l';
  500. temp_msg.operand[i++] = 'd';
  501. temp_msg.frame_size = i + 2;
  502. hdmi_msm_cec_msg_send(&temp_msg);
  503. break;
  504. #endif /* __SEND_ABORT__ */
  505. }
  506. #endif /* DRVR_ONLY_CECT_NO_DAEMON */
  507. mutex_lock(&hdmi_msm_state_mutex);
  508. hdmi_msm_state->cec_queue_wr++;
  509. if (hdmi_msm_state->cec_queue_wr == CEC_QUEUE_END)
  510. hdmi_msm_state->cec_queue_wr = hdmi_msm_state->cec_queue_start;
  511. if (hdmi_msm_state->cec_queue_wr == hdmi_msm_state->cec_queue_rd)
  512. hdmi_msm_state->cec_queue_full = true;
  513. mutex_unlock(&hdmi_msm_state_mutex);
  514. DEV_DBG("Exiting %s()\n", __func__);
  515. }
  516. void hdmi_msm_cec_one_touch_play(void)
  517. {
  518. struct hdmi_msm_cec_msg temp_msg;
  519. uint32 i = 0;
  520. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  521. temp_msg.sender_id = 0x4;
  522. /*
  523. * Broadcast this message
  524. */
  525. temp_msg.recvr_id = 0xf;
  526. i = 0;
  527. /* Active Source */
  528. temp_msg.opcode = 0x82;
  529. temp_msg.operand[i++] = 0x10;
  530. temp_msg.operand[i++] = 0x00;
  531. /*temp_msg.operand[i++] = 0x04;*/
  532. temp_msg.frame_size = i + 2;
  533. hdmi_msm_cec_msg_send(&temp_msg);
  534. /*
  535. * sending <Image View On> message
  536. */
  537. memset(&temp_msg, 0x00, sizeof(struct hdmi_msm_cec_msg));
  538. temp_msg.sender_id = 0x4;
  539. temp_msg.recvr_id = hdmi_msm_state->cec_queue_wr->sender_id;
  540. i = 0;
  541. /* Image View On */
  542. temp_msg.opcode = 0x04;
  543. temp_msg.frame_size = i + 2;
  544. hdmi_msm_cec_msg_send(&temp_msg);
  545. }
  546. #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
  547. uint32 hdmi_msm_get_io_base(void)
  548. {
  549. return (uint32)MSM_HDMI_BASE;
  550. }
  551. EXPORT_SYMBOL(hdmi_msm_get_io_base);
  552. /* Table indicating the video format supported by the HDMI TX Core v1.0 */
  553. /* Valid Pixel-Clock rates: 25.2MHz, 27MHz, 27.03MHz, 74.25MHz, 148.5MHz */
  554. static void hdmi_msm_setup_video_mode_lut(void)
  555. {
  556. HDMI_SETUP_LUT(640x480p60_4_3);
  557. HDMI_SETUP_LUT(720x480p60_4_3);
  558. HDMI_SETUP_LUT(720x480p60_16_9);
  559. HDMI_SETUP_LUT(1280x720p60_16_9);
  560. HDMI_SETUP_LUT(1920x1080i60_16_9);
  561. HDMI_SETUP_LUT(1440x480i60_4_3);
  562. HDMI_SETUP_LUT(1440x480i60_16_9);
  563. HDMI_SETUP_LUT(1920x1080p60_16_9);
  564. HDMI_SETUP_LUT(720x576p50_4_3);
  565. HDMI_SETUP_LUT(720x576p50_16_9);
  566. HDMI_SETUP_LUT(1280x720p50_16_9);
  567. HDMI_SETUP_LUT(1440x576i50_4_3);
  568. HDMI_SETUP_LUT(1440x576i50_16_9);
  569. HDMI_SETUP_LUT(1920x1080p50_16_9);
  570. HDMI_SETUP_LUT(1920x1080p24_16_9);
  571. HDMI_SETUP_LUT(1920x1080p25_16_9);
  572. HDMI_SETUP_LUT(1920x1080p30_16_9);
  573. HDMI_SETUP_LUT(1280x1024p60_5_4);
  574. }
  575. #ifdef PORT_DEBUG
  576. const char *hdmi_msm_name(uint32 offset)
  577. {
  578. switch (offset) {
  579. case 0x0000: return "CTRL";
  580. case 0x0020: return "AUDIO_PKT_CTRL1";
  581. case 0x0024: return "ACR_PKT_CTRL";
  582. case 0x0028: return "VBI_PKT_CTRL";
  583. case 0x002C: return "INFOFRAME_CTRL0";
  584. #ifdef CONFIG_FB_MSM_HDMI_3D
  585. case 0x0034: return "GEN_PKT_CTRL";
  586. #endif
  587. case 0x003C: return "ACP";
  588. case 0x0040: return "GC";
  589. case 0x0044: return "AUDIO_PKT_CTRL2";
  590. case 0x0048: return "ISRC1_0";
  591. case 0x004C: return "ISRC1_1";
  592. case 0x0050: return "ISRC1_2";
  593. case 0x0054: return "ISRC1_3";
  594. case 0x0058: return "ISRC1_4";
  595. case 0x005C: return "ISRC2_0";
  596. case 0x0060: return "ISRC2_1";
  597. case 0x0064: return "ISRC2_2";
  598. case 0x0068: return "ISRC2_3";
  599. case 0x006C: return "AVI_INFO0";
  600. case 0x0070: return "AVI_INFO1";
  601. case 0x0074: return "AVI_INFO2";
  602. case 0x0078: return "AVI_INFO3";
  603. #ifdef CONFIG_FB_MSM_HDMI_3D
  604. case 0x0084: return "GENERIC0_HDR";
  605. case 0x0088: return "GENERIC0_0";
  606. case 0x008C: return "GENERIC0_1";
  607. #endif
  608. case 0x00C4: return "ACR_32_0";
  609. case 0x00C8: return "ACR_32_1";
  610. case 0x00CC: return "ACR_44_0";
  611. case 0x00D0: return "ACR_44_1";
  612. case 0x00D4: return "ACR_48_0";
  613. case 0x00D8: return "ACR_48_1";
  614. case 0x00E4: return "AUDIO_INFO0";
  615. case 0x00E8: return "AUDIO_INFO1";
  616. case 0x0110: return "HDCP_CTRL";
  617. case 0x0114: return "HDCP_DEBUG_CTRL";
  618. case 0x0118: return "HDCP_INT_CTRL";
  619. case 0x011C: return "HDCP_LINK0_STATUS";
  620. case 0x012C: return "HDCP_ENTROPY_CTRL0";
  621. case 0x0130: return "HDCP_RESET";
  622. case 0x0134: return "HDCP_RCVPORT_DATA0";
  623. case 0x0138: return "HDCP_RCVPORT_DATA1";
  624. case 0x013C: return "HDCP_RCVPORT_DATA2";
  625. case 0x0144: return "HDCP_RCVPORT_DATA3";
  626. case 0x0148: return "HDCP_RCVPORT_DATA4";
  627. case 0x014C: return "HDCP_RCVPORT_DATA5";
  628. case 0x0150: return "HDCP_RCVPORT_DATA6";
  629. case 0x0168: return "HDCP_RCVPORT_DATA12";
  630. case 0x01D0: return "AUDIO_CFG";
  631. case 0x0208: return "USEC_REFTIMER";
  632. case 0x020C: return "DDC_CTRL";
  633. case 0x0214: return "DDC_INT_CTRL";
  634. case 0x0218: return "DDC_SW_STATUS";
  635. case 0x021C: return "DDC_HW_STATUS";
  636. case 0x0220: return "DDC_SPEED";
  637. case 0x0224: return "DDC_SETUP";
  638. case 0x0228: return "DDC_TRANS0";
  639. case 0x022C: return "DDC_TRANS1";
  640. case 0x0238: return "DDC_DATA";
  641. case 0x0250: return "HPD_INT_STATUS";
  642. case 0x0254: return "HPD_INT_CTRL";
  643. case 0x0258: return "HPD_CTRL";
  644. case 0x025C: return "HDCP_ENTROPY_CTRL1";
  645. case 0x027C: return "DDC_REF";
  646. case 0x0284: return "HDCP_SW_UPPER_AKSV";
  647. case 0x0288: return "HDCP_SW_LOWER_AKSV";
  648. case 0x02B4: return "ACTIVE_H";
  649. case 0x02B8: return "ACTIVE_V";
  650. case 0x02BC: return "ACTIVE_V_F2";
  651. case 0x02C0: return "TOTAL";
  652. case 0x02C4: return "V_TOTAL_F2";
  653. case 0x02C8: return "FRAME_CTRL";
  654. case 0x02CC: return "AUD_INT";
  655. case 0x0300: return "PHY_REG0";
  656. case 0x0304: return "PHY_REG1";
  657. case 0x0308: return "PHY_REG2";
  658. case 0x030C: return "PHY_REG3";
  659. case 0x0310: return "PHY_REG4";
  660. case 0x0314: return "PHY_REG5";
  661. case 0x0318: return "PHY_REG6";
  662. case 0x031C: return "PHY_REG7";
  663. case 0x0320: return "PHY_REG8";
  664. case 0x0324: return "PHY_REG9";
  665. case 0x0328: return "PHY_REG10";
  666. case 0x032C: return "PHY_REG11";
  667. case 0x0330: return "PHY_REG12";
  668. default: return "???";
  669. }
  670. }
  671. void hdmi_outp(uint32 offset, uint32 value)
  672. {
  673. uint32 in_val;
  674. outpdw(MSM_HDMI_BASE+offset, value);
  675. in_val = inpdw(MSM_HDMI_BASE+offset);
  676. DEV_DBG("HDMI[%04x] => %08x [%08x] %s\n",
  677. offset, value, in_val, hdmi_msm_name(offset));
  678. }
  679. uint32 hdmi_inp(uint32 offset)
  680. {
  681. uint32 value = inpdw(MSM_HDMI_BASE+offset);
  682. DEV_DBG("HDMI[%04x] <= %08x %s\n",
  683. offset, value, hdmi_msm_name(offset));
  684. return value;
  685. }
  686. #endif /* DEBUG */
  687. static void hdmi_msm_turn_on(void);
  688. static int hdmi_msm_audio_off(void);
  689. static int hdmi_msm_read_edid(void);
  690. static void hdmi_msm_hpd_off(void);
  691. static bool hdmi_ready(void)
  692. {
  693. return MSM_HDMI_BASE &&
  694. hdmi_msm_state &&
  695. hdmi_msm_state->hdmi_app_clk &&
  696. hdmi_msm_state->hpd_initialized;
  697. }
  698. static void hdmi_msm_send_event(boolean on)
  699. {
  700. char *envp[2];
  701. /* QDSP OFF preceding the HPD event notification */
  702. envp[0] = "HDCP_STATE=FAIL";
  703. envp[1] = NULL;
  704. DEV_ERR("hdmi: HDMI HPD: QDSP OFF\n");
  705. kobject_uevent_env(external_common_state->uevent_kobj,
  706. KOBJ_CHANGE, envp);
  707. if (on) {
  708. /* Build EDID table */
  709. hdmi_msm_read_edid();
  710. switch_set_state(&external_common_state->sdev, 1);
  711. DEV_INFO("%s: hdmi state switched to %d\n", __func__,
  712. external_common_state->sdev.state);
  713. DEV_INFO("HDMI HPD: CONNECTED: send ONLINE\n");
  714. kobject_uevent(external_common_state->uevent_kobj, KOBJ_ONLINE);
  715. if (!hdmi_msm_state->hdcp_enable) {
  716. /* Send Audio for HDMI Compliance Cases*/
  717. envp[0] = "HDCP_STATE=PASS";
  718. envp[1] = NULL;
  719. DEV_INFO("HDMI HPD: sense : send HDCP_PASS\n");
  720. kobject_uevent_env(external_common_state->uevent_kobj,
  721. KOBJ_CHANGE, envp);
  722. }
  723. } else {
  724. switch_set_state(&external_common_state->sdev, 0);
  725. DEV_INFO("%s: hdmi state switch to %d\n", __func__,
  726. external_common_state->sdev.state);
  727. DEV_INFO("hdmi: HDMI HPD: sense DISCONNECTED: send OFFLINE\n");
  728. kobject_uevent(external_common_state->uevent_kobj,
  729. KOBJ_OFFLINE);
  730. }
  731. if (!completion_done(&hdmi_msm_state->hpd_event_processed))
  732. complete(&hdmi_msm_state->hpd_event_processed);
  733. }
  734. static void hdmi_msm_hpd_state_work(struct work_struct *work)
  735. {
  736. if (!hdmi_ready()) {
  737. DEV_ERR("hdmi: %s: ignored, probe failed\n", __func__);
  738. return;
  739. }
  740. hdmi_msm_send_event(external_common_state->hpd_state);
  741. }
  742. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  743. static void hdmi_msm_cec_latch_work(struct work_struct *work)
  744. {
  745. hdmi_msm_cec_line_latch_detect();
  746. }
  747. #endif
  748. static void hdcp_deauthenticate(void);
  749. static void hdmi_msm_hdcp_reauth_work(struct work_struct *work)
  750. {
  751. if (!hdmi_msm_state->hdcp_enable) {
  752. DEV_DBG("%s: HDCP not enabled\n", __func__);
  753. return;
  754. }
  755. /* Don't process recursive actions */
  756. mutex_lock(&hdmi_msm_state_mutex);
  757. if (hdmi_msm_state->hdcp_activating) {
  758. mutex_unlock(&hdmi_msm_state_mutex);
  759. return;
  760. }
  761. mutex_unlock(&hdmi_msm_state_mutex);
  762. /*
  763. * Reauth=>deauth, hdcp_auth
  764. * hdcp_auth=>turn_on() which calls
  765. * HDMI Core reset without informing the Audio QDSP
  766. * this can do bad things to video playback on the HDTV
  767. * Therefore, as surprising as it may sound do reauth
  768. * only if the device is HDCP-capable
  769. */
  770. hdcp_deauthenticate();
  771. mutex_lock(&hdcp_auth_state_mutex);
  772. hdmi_msm_state->reauth = TRUE;
  773. mutex_unlock(&hdcp_auth_state_mutex);
  774. mod_timer(&hdmi_msm_state->hdcp_timer, jiffies + HZ/2);
  775. }
  776. static void hdmi_msm_hdcp_work(struct work_struct *work)
  777. {
  778. if (!hdmi_msm_state->hdcp_enable) {
  779. DEV_DBG("%s: HDCP not enabled\n", __func__);
  780. return;
  781. }
  782. /* Only re-enable if cable still connected */
  783. mutex_lock(&external_common_state_hpd_mutex);
  784. if (external_common_state->hpd_state &&
  785. !(hdmi_msm_state->full_auth_done)) {
  786. mutex_unlock(&external_common_state_hpd_mutex);
  787. if (hdmi_msm_state->reauth == TRUE) {
  788. DEV_DBG("%s: Starting HDCP re-authentication\n",
  789. __func__);
  790. hdmi_msm_turn_on();
  791. } else {
  792. DEV_DBG("%s: Starting HDCP authentication\n", __func__);
  793. hdmi_msm_hdcp_enable();
  794. }
  795. } else {
  796. mutex_unlock(&external_common_state_hpd_mutex);
  797. DEV_DBG("%s: HDMI not connected or HDCP already active\n",
  798. __func__);
  799. hdmi_msm_state->reauth = FALSE;
  800. }
  801. }
  802. int hdmi_msm_process_hdcp_interrupts(void)
  803. {
  804. int rc = -1;
  805. uint32 hdcp_int_val;
  806. char *envp[2];
  807. if (!hdmi_msm_state->hdcp_enable) {
  808. DEV_DBG("%s: HDCP not enabled\n", __func__);
  809. return -EINVAL;
  810. }
  811. /* HDCP_INT_CTRL[0x0118]
  812. * [0] AUTH_SUCCESS_INT [R] HDCP Authentication Success
  813. * interrupt status
  814. * [1] AUTH_SUCCESS_ACK [W] Acknowledge bit for HDCP
  815. * Authentication Success bit - write 1 to clear
  816. * [2] AUTH_SUCCESS_MASK [R/W] Mask bit for HDCP Authentication
  817. * Success interrupt - set to 1 to enable interrupt */
  818. hdcp_int_val = HDMI_INP_ND(0x0118);
  819. if ((hdcp_int_val & (1 << 2)) && (hdcp_int_val & (1 << 0))) {
  820. /* AUTH_SUCCESS_INT */
  821. HDMI_OUTP(0x0118, (hdcp_int_val | (1 << 1)) & ~(1 << 0));
  822. DEV_INFO("HDCP: AUTH_SUCCESS_INT received\n");
  823. complete_all(&hdmi_msm_state->hdcp_success_done);
  824. return 0;
  825. }
  826. /* [4] AUTH_FAIL_INT [R] HDCP Authentication Lost
  827. * interrupt Status
  828. * [5] AUTH_FAIL_ACK [W] Acknowledge bit for HDCP
  829. * Authentication Lost bit - write 1 to clear
  830. * [6] AUTH_FAIL_MASK [R/W] Mask bit fo HDCP Authentication
  831. * Lost interrupt set to 1 to enable interrupt
  832. * [7] AUTH_FAIL_INFO_ACK [W] Acknowledge bit for HDCP
  833. * Authentication Failure Info field - write 1 to clear */
  834. if ((hdcp_int_val & (1 << 6)) && (hdcp_int_val & (1 << 4))) {
  835. /* AUTH_FAIL_INT */
  836. /* Clear and Disable */
  837. uint32 link_status = HDMI_INP_ND(0x011C);
  838. HDMI_OUTP(0x0118, (hdcp_int_val | (1 << 5))
  839. & ~((1 << 6) | (1 << 4)));
  840. DEV_INFO("HDCP: AUTH_FAIL_INT received, LINK0_STATUS=0x%08x\n",
  841. link_status);
  842. if (hdmi_msm_state->full_auth_done) {
  843. SWITCH_SET_HDMI_AUDIO(0, 0);
  844. envp[0] = "HDCP_STATE=FAIL";
  845. envp[1] = NULL;
  846. DEV_INFO("HDMI HPD:QDSP OFF\n");
  847. kobject_uevent_env(external_common_state->uevent_kobj,
  848. KOBJ_CHANGE, envp);
  849. mutex_lock(&hdcp_auth_state_mutex);
  850. hdmi_msm_state->full_auth_done = FALSE;
  851. mutex_unlock(&hdcp_auth_state_mutex);
  852. /* Calling reauth only when authentication
  853. * is sucessful or else we always go into
  854. * the reauth loop. Also, No need to reauthenticate
  855. * if authentication failed because of cable disconnect
  856. */
  857. if (((link_status & 0xF0) >> 4) != 0x7) {
  858. DEV_DBG("Reauthenticate From %s HDCP FAIL INT ",
  859. __func__);
  860. queue_work(hdmi_work_queue,
  861. &hdmi_msm_state->hdcp_reauth_work);
  862. } else {
  863. DEV_INFO("HDCP: HDMI cable disconnected\n");
  864. }
  865. }
  866. /* Clear AUTH_FAIL_INFO as well */
  867. HDMI_OUTP(0x0118, (hdcp_int_val | (1 << 7)));
  868. return 0;
  869. }
  870. /* [8] DDC_XFER_REQ_INT [R] HDCP DDC Transfer Request
  871. * interrupt status
  872. * [9] DDC_XFER_REQ_ACK [W] Acknowledge bit for HDCP DDC
  873. * Transfer Request bit - write 1 to clear
  874. * [10] DDC_XFER_REQ_MASK [R/W] Mask bit for HDCP DDC Transfer
  875. * Request interrupt - set to 1 to enable interrupt */
  876. if ((hdcp_int_val & (1 << 10)) && (hdcp_int_val & (1 << 8))) {
  877. /* DDC_XFER_REQ_INT */
  878. HDMI_OUTP_ND(0x0118, (hdcp_int_val | (1 << 9)) & ~(1 << 8));
  879. if (!(hdcp_int_val & (1 << 12)))
  880. return 0;
  881. }
  882. /* [12] DDC_XFER_DONE_INT [R] HDCP DDC Transfer done interrupt
  883. * status
  884. * [13] DDC_XFER_DONE_ACK [W] Acknowledge bit for HDCP DDC
  885. * Transfer done bit - write 1 to clear
  886. * [14] DDC_XFER_DONE_MASK [R/W] Mask bit for HDCP DDC Transfer
  887. * done interrupt - set to 1 to enable interrupt */
  888. if ((hdcp_int_val & (1 << 14)) && (hdcp_int_val & (1 << 12))) {
  889. /* DDC_XFER_DONE_INT */
  890. HDMI_OUTP_ND(0x0118, (hdcp_int_val | (1 << 13)) & ~(1 << 12));
  891. DEV_INFO("HDCP: DDC_XFER_DONE received\n");
  892. return 0;
  893. }
  894. return rc;
  895. }
  896. static irqreturn_t hdmi_msm_isr(int irq, void *dev_id)
  897. {
  898. uint32 hpd_int_status;
  899. uint32 hpd_int_ctrl;
  900. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  901. uint32 cec_intr_status;
  902. #endif
  903. uint32 ddc_int_ctrl;
  904. uint32 audio_int_val;
  905. static uint32 fifo_urun_int_occurred;
  906. static uint32 sample_drop_int_occurred;
  907. const uint32 occurrence_limit = 5;
  908. if (!hdmi_ready()) {
  909. DEV_DBG("ISR ignored, probe failed\n");
  910. return IRQ_HANDLED;
  911. }
  912. /* Process HPD Interrupt */
  913. /* HDMI_HPD_INT_STATUS[0x0250] */
  914. hpd_int_status = HDMI_INP_ND(0x0250);
  915. /* HDMI_HPD_INT_CTRL[0x0254] */
  916. hpd_int_ctrl = HDMI_INP_ND(0x0254);
  917. if ((hpd_int_ctrl & (1 << 2)) && (hpd_int_status & (1 << 0))) {
  918. /*
  919. * Got HPD interrupt. Ack the interrupt and disable any
  920. * further HPD interrupts until we process this interrupt.
  921. */
  922. HDMI_OUTP(0x0254, ((hpd_int_ctrl | (BIT(0))) & ~BIT(2)));
  923. external_common_state->hpd_state =
  924. (HDMI_INP(0x0250) & BIT(1)) >> 1;
  925. DEV_DBG("%s: Queuing work to handle HPD %s event\n", __func__,
  926. external_common_state->hpd_state ? "connect" :
  927. "disconnect");
  928. queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_state_work);
  929. return IRQ_HANDLED;
  930. }
  931. /* Process DDC Interrupts */
  932. /* HDMI_DDC_INT_CTRL[0x0214] */
  933. ddc_int_ctrl = HDMI_INP_ND(0x0214);
  934. if ((ddc_int_ctrl & (1 << 2)) && (ddc_int_ctrl & (1 << 0))) {
  935. /* SW_DONE INT occured, clr it */
  936. HDMI_OUTP_ND(0x0214, ddc_int_ctrl | (1 << 1));
  937. complete(&hdmi_msm_state->ddc_sw_done);
  938. return IRQ_HANDLED;
  939. }
  940. /* FIFO Underrun Int is enabled */
  941. /* HDMI_AUD_INT[0x02CC]
  942. * [3] AUD_SAM_DROP_MASK [R/W]
  943. * [2] AUD_SAM_DROP_ACK [W], AUD_SAM_DROP_INT [R]
  944. * [1] AUD_FIFO_URUN_MASK [R/W]
  945. * [0] AUD_FIFO_URUN_ACK [W], AUD_FIFO_URUN_INT [R] */
  946. audio_int_val = HDMI_INP_ND(0x02CC);
  947. if ((audio_int_val & (1 << 1)) && (audio_int_val & (1 << 0))) {
  948. /* FIFO Underrun occured, clr it */
  949. HDMI_OUTP(0x02CC, audio_int_val | (1 << 0));
  950. ++fifo_urun_int_occurred;
  951. DEV_INFO("HDMI AUD_FIFO_URUN: %d\n", fifo_urun_int_occurred);
  952. if (fifo_urun_int_occurred >= occurrence_limit) {
  953. HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) & ~(1 << 1));
  954. DEV_INFO("HDMI AUD_FIFO_URUN: INT has been disabled "
  955. "by the ISR after %d occurences...\n",
  956. fifo_urun_int_occurred);
  957. }
  958. return IRQ_HANDLED;
  959. }
  960. /* Audio Sample Drop int is enabled */
  961. if ((audio_int_val & (1 << 3)) && (audio_int_val & (1 << 2))) {
  962. /* Audio Sample Drop occured, clr it */
  963. HDMI_OUTP(0x02CC, audio_int_val | (1 << 2));
  964. DEV_DBG("%s: AUD_SAM_DROP", __func__);
  965. ++sample_drop_int_occurred;
  966. if (sample_drop_int_occurred >= occurrence_limit) {
  967. HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) & ~(1 << 3));
  968. DEV_INFO("HDMI AUD_SAM_DROP: INT has been disabled "
  969. "by the ISR after %d occurences...\n",
  970. sample_drop_int_occurred);
  971. }
  972. return IRQ_HANDLED;
  973. }
  974. if (!hdmi_msm_process_hdcp_interrupts())
  975. return IRQ_HANDLED;
  976. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  977. /* Process CEC Interrupt */
  978. /* HDMI_MSM_CEC_INT[0x029C] */
  979. cec_intr_status = HDMI_INP_ND(0x029C);
  980. DEV_DBG("cec interrupt status is [%u]\n", cec_intr_status);
  981. if (HDMI_MSM_CEC_FRAME_WR_SUCCESS(cec_intr_status)) {
  982. DEV_DBG("CEC_IRQ_FRAME_WR_DONE\n");
  983. HDMI_OUTP(0x029C, cec_intr_status |
  984. HDMI_MSM_CEC_INT_FRAME_WR_DONE_ACK);
  985. mutex_lock(&hdmi_msm_state_mutex);
  986. hdmi_msm_state->cec_frame_wr_status |= CEC_STATUS_WR_DONE;
  987. hdmi_msm_state->first_monitor = 0;
  988. del_timer(&hdmi_msm_state->cec_read_timer);
  989. mutex_unlock(&hdmi_msm_state_mutex);
  990. complete(&hdmi_msm_state->cec_frame_wr_done);
  991. return IRQ_HANDLED;
  992. }
  993. if ((cec_intr_status & (1 << 2)) && (cec_intr_status & (1 << 3))) {
  994. DEV_DBG("CEC_IRQ_FRAME_ERROR\n");
  995. #ifdef TOGGLE_CEC_HARDWARE_FSM
  996. /* Toggle CEC hardware FSM */
  997. HDMI_OUTP(0x028C, 0x0);
  998. HDMI_OUTP(0x028C, HDMI_MSM_CEC_CTRL_ENABLE);
  999. #endif
  1000. HDMI_OUTP(0x029C, cec_intr_status);
  1001. mutex_lock(&hdmi_msm_state_mutex);
  1002. hdmi_msm_state->first_monitor = 0;
  1003. del_timer(&hdmi_msm_state->cec_read_timer);
  1004. hdmi_msm_state->cec_frame_wr_status |= CEC_STATUS_WR_ERROR;
  1005. mutex_unlock(&hdmi_msm_state_mutex);
  1006. complete(&hdmi_msm_state->cec_frame_wr_done);
  1007. return IRQ_HANDLED;
  1008. }
  1009. if ((cec_intr_status & (1 << 4)) && (cec_intr_status & (1 << 5))) {
  1010. DEV_DBG("CEC_IRQ_MONITOR\n");
  1011. HDMI_OUTP(0x029C, cec_intr_status |
  1012. HDMI_MSM_CEC_INT_MONITOR_ACK);
  1013. /*
  1014. * CECT 9-5-1
  1015. * On the first occassion start a timer
  1016. * for few hundred ms, if it expires then
  1017. * reset the CEC block else go on with
  1018. * frame transactions as usual.
  1019. * Below adds hdmi_msm_cec_msg_recv() as an
  1020. * item into the work queue instead of running in
  1021. * interrupt context
  1022. */
  1023. mutex_lock(&hdmi_msm_state_mutex);
  1024. if (hdmi_msm_state->first_monitor == 0) {
  1025. /* This timer might have to be changed
  1026. * worst case theoritical =
  1027. * 16 bytes * 8 * 2.7msec = 346 msec
  1028. */
  1029. mod_timer(&hdmi_msm_state->cec_read_timer,
  1030. jiffies + HZ/2);
  1031. hdmi_msm_state->first_monitor = 1;
  1032. }
  1033. mutex_unlock(&hdmi_msm_state_mutex);
  1034. return IRQ_HANDLED;
  1035. }
  1036. if ((cec_intr_status & (1 << 6)) && (cec_intr_status & (1 << 7))) {
  1037. DEV_DBG("CEC_IRQ_FRAME_RD_DONE\n");
  1038. mutex_lock(&hdmi_msm_state_mutex);
  1039. hdmi_msm_state->first_monitor = 0;
  1040. del_timer(&hdmi_msm_state->cec_read_timer);
  1041. mutex_unlock(&hdmi_msm_state_mutex);
  1042. HDMI_OUTP(0x029C, cec_intr_status |
  1043. HDMI_MSM_CEC_INT_FRAME_RD_DONE_ACK);
  1044. hdmi_msm_cec_msg_recv();
  1045. #ifdef TOGGLE_CEC_HARDWARE_FSM
  1046. if (!msg_send_complete)
  1047. msg_recv_complete = FALSE;
  1048. else {
  1049. /* Toggle CEC hardware FSM */
  1050. HDMI_OUTP(0x028C, 0x0);
  1051. HDMI_OUTP(0x028C, HDMI_MSM_CEC_CTRL_ENABLE);
  1052. }
  1053. #else
  1054. HDMI_OUTP(0x028C, 0x0);
  1055. HDMI_OUTP(0x028C, HDMI_MSM_CEC_CTRL_ENABLE);
  1056. #endif
  1057. return IRQ_HANDLED;
  1058. }
  1059. #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
  1060. DEV_DBG("%s: HPD<Ctrl=%04x, State=%04x>, ddc_int_ctrl=%04x, "
  1061. "aud_int=%04x, cec_intr_status=%04x\n", __func__, hpd_int_ctrl,
  1062. hpd_int_status, ddc_int_ctrl, audio_int_val,
  1063. HDMI_INP_ND(0x029C));
  1064. return IRQ_HANDLED;
  1065. }
  1066. static int check_hdmi_features(void)
  1067. {
  1068. /* RAW_FEAT_CONFIG_ROW0_LSB */
  1069. uint32 val = inpdw(QFPROM_BASE + 0x0238);
  1070. /* HDMI_DISABLE */
  1071. boolean hdmi_disabled = (val & 0x00200000) >> 21;
  1072. /* HDCP_DISABLE */
  1073. boolean hdcp_disabled = (val & 0x00400000) >> 22;
  1074. DEV_DBG("Features <val:0x%08x, HDMI:%s, HDCP:%s>\n", val,
  1075. hdmi_disabled ? "OFF" : "ON", hdcp_disabled ? "OFF" : "ON");
  1076. if (hdmi_disabled) {
  1077. DEV_ERR("ERROR: HDMI disabled\n");
  1078. return -ENODEV;
  1079. }
  1080. if (hdcp_disabled)
  1081. DEV_WARN("WARNING: HDCP disabled\n");
  1082. return 0;
  1083. }
  1084. static boolean hdmi_msm_has_hdcp(void)
  1085. {
  1086. /* RAW_FEAT_CONFIG_ROW0_LSB, HDCP_DISABLE */
  1087. return (inpdw(QFPROM_BASE + 0x0238) & 0x00400000) ? FALSE : TRUE;
  1088. }
  1089. static boolean hdmi_msm_is_power_on(void)
  1090. {
  1091. /* HDMI_CTRL, ENABLE */
  1092. return (HDMI_INP_ND(0x0000) & 0x00000001) ? TRUE : FALSE;
  1093. }
  1094. /* 1.2.1.2.1 DVI Operation
  1095. * HDMI compliance requires the HDMI core to support DVI as well. The
  1096. * HDMI core also supports DVI. In DVI operation there are no preambles
  1097. * and guardbands transmitted. THe TMDS encoding of video data remains
  1098. * the same as HDMI. There are no VBI or audio packets transmitted. In
  1099. * order to enable DVI mode in HDMI core, HDMI_DVI_SEL field of
  1100. * HDMI_CTRL register needs to be programmed to 0. */
  1101. static boolean hdmi_msm_is_dvi_mode(void)
  1102. {
  1103. /* HDMI_CTRL, HDMI_DVI_SEL */
  1104. return (HDMI_INP_ND(0x0000) & 0x00000002) ? FALSE : TRUE;
  1105. }
  1106. void hdmi_msm_set_mode(boolean power_on)
  1107. {
  1108. uint32 reg_val = 0;
  1109. if (power_on) {
  1110. /* ENABLE */
  1111. reg_val |= 0x00000001; /* Enable the block */
  1112. if (external_common_state->hdmi_sink == 0) {
  1113. /* HDMI_DVI_SEL */
  1114. reg_val |= 0x00000002;
  1115. if (hdmi_msm_state->hdcp_enable)
  1116. /* HDMI Encryption */
  1117. reg_val |= 0x00000004;
  1118. /* HDMI_CTRL */
  1119. HDMI_OUTP(0x0000, reg_val);
  1120. /* HDMI_DVI_SEL */
  1121. reg_val &= ~0x00000002;
  1122. } else {
  1123. if (hdmi_msm_state->hdcp_enable)
  1124. /* HDMI_Encryption_ON */
  1125. reg_val |= 0x00000006;
  1126. else
  1127. reg_val |= 0x00000002;
  1128. }
  1129. } else
  1130. reg_val = 0x00000002;
  1131. /* HDMI_CTRL */
  1132. HDMI_OUTP(0x0000, reg_val);
  1133. DEV_DBG("HDMI Core: %s, HDMI_CTRL=0x%08x\n",
  1134. power_on ? "Enable" : "Disable", reg_val);
  1135. }
  1136. static void msm_hdmi_init_ddc(void)
  1137. {
  1138. /* 0x0220 HDMI_DDC_SPEED
  1139. [31:16] PRESCALE prescale = (m * xtal_frequency) /
  1140. (desired_i2c_speed), where m is multiply
  1141. factor, default: m = 1
  1142. [1:0] THRESHOLD Select threshold to use to determine whether value
  1143. sampled on SDA is a 1 or 0. Specified in terms of the ratio
  1144. between the number of sampled ones and the total number of times
  1145. SDA is sampled.
  1146. * 0x0: >0
  1147. * 0x1: 1/4 of total samples
  1148. * 0x2: 1/2 of total samples
  1149. * 0x3: 3/4 of total samples */
  1150. /* Configure the Pre-Scale multiplier
  1151. * Configure the Threshold */
  1152. HDMI_OUTP_ND(0x0220, (10 << 16) | (2 << 0));
  1153. /*
  1154. * 0x0224 HDMI_DDC_SETUP
  1155. * Setting 31:24 bits : Time units to wait before timeout
  1156. * when clock is being stalled by external sink device
  1157. */
  1158. HDMI_OUTP_ND(0x0224, 0xff000000);
  1159. /* 0x027C HDMI_DDC_REF
  1160. [6] REFTIMER_ENABLE Enable the timer
  1161. * 0: Disable
  1162. * 1: Enable
  1163. [15:0] REFTIMER Value to set the register in order to generate
  1164. DDC strobe. This register counts on HDCP application clock */
  1165. /* Enable reference timer
  1166. * 27 micro-seconds */
  1167. HDMI_OUTP_ND(0x027C, (1 << 16) | (27 << 0));
  1168. }
  1169. static int hdmi_msm_ddc_clear_irq(const char *what)
  1170. {
  1171. const uint32 time_out = 0xFFFF;
  1172. uint32 time_out_count, reg_val;
  1173. /* clear pending and enable interrupt */
  1174. time_out_count = time_out;
  1175. do {
  1176. --time_out_count;
  1177. /* HDMI_DDC_INT_CTRL[0x0214]
  1178. [2] SW_DONE_MK Mask bit for SW_DONE_INT. Set to 1 to enable
  1179. interrupt.
  1180. [1] SW_DONE_ACK WRITE ONLY. Acknowledge bit for SW_DONE_INT.
  1181. Write 1 to clear interrupt.
  1182. [0] SW_DONE_INT READ ONLY. SW_DONE interrupt status */
  1183. /* Clear and Enable DDC interrupt */
  1184. /* Write */
  1185. HDMI_OUTP_ND(0x0214, (1 << 2) | (1 << 1));
  1186. /* Read back */
  1187. reg_val = HDMI_INP_ND(0x0214);
  1188. } while ((reg_val & 0x1) && time_out_count);
  1189. if (!time_out_count) {
  1190. DEV_ERR("%s[%s]: timedout\n", __func__, what);
  1191. return -ETIMEDOUT;
  1192. }
  1193. return 0;
  1194. }
  1195. static int hdmi_msm_ddc_write(uint32 dev_addr, uint32 offset,
  1196. const uint8 *data_buf, uint32 data_len, const char *what)
  1197. {
  1198. uint32 reg_val, ndx;
  1199. int status = 0, retry = 10;
  1200. uint32 time_out_count;
  1201. if (NULL == data_buf) {
  1202. status = -EINVAL;
  1203. DEV_ERR("%s[%s]: invalid input paramter\n", __func__, what);
  1204. goto error;
  1205. }
  1206. again:
  1207. status = hdmi_msm_ddc_clear_irq(what);
  1208. if (status)
  1209. goto error;
  1210. /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */
  1211. dev_addr &= 0xFE;
  1212. /* 0x0238 HDMI_DDC_DATA
  1213. [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to
  1214. 1 while writing HDMI_DDC_DATA.
  1215. [23:16] INDEX Use to set index into DDC buffer for next read or
  1216. current write, or to read index of current read or next write.
  1217. Writable only when INDEX_WRITE=1.
  1218. [15:8] DATA Use to fill or read the DDC buffer
  1219. [0] DATA_RW Select whether buffer access will be a read or write.
  1220. For writes, address auto-increments on write to HDMI_DDC_DATA.
  1221. For reads, address autoincrements on reads to HDMI_DDC_DATA.
  1222. * 0: Write
  1223. * 1: Read */
  1224. /* 1. Write to HDMI_I2C_DATA with the following fields set in order to
  1225. * handle portion #1
  1226. * DATA_RW = 0x1 (write)
  1227. * DATA = linkAddress (primary link address and writing)
  1228. * INDEX = 0x0 (initial offset into buffer)
  1229. * INDEX_WRITE = 0x1 (setting initial offset) */
  1230. HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (dev_addr << 8));
  1231. /* 2. Write to HDMI_I2C_DATA with the following fields set in order to
  1232. * handle portion #2
  1233. * DATA_RW = 0x0 (write)
  1234. * DATA = offsetAddress
  1235. * INDEX = 0x0
  1236. * INDEX_WRITE = 0x0 (auto-increment by hardware) */
  1237. HDMI_OUTP_ND(0x0238, offset << 8);
  1238. /* 3. Write to HDMI_I2C_DATA with the following fields set in order to
  1239. * handle portion #3
  1240. * DATA_RW = 0x0 (write)
  1241. * DATA = data_buf[ndx]
  1242. * INDEX = 0x0
  1243. * INDEX_WRITE = 0x0 (auto-increment by hardware) */
  1244. for (ndx = 0; ndx < data_len; ++ndx)
  1245. HDMI_OUTP_ND(0x0238, ((uint32)data_buf[ndx]) << 8);
  1246. /* Data setup is complete, now setup the transaction characteristics */
  1247. /* 0x0228 HDMI_DDC_TRANS0
  1248. [23:16] CNT0 Byte count for first transaction (excluding the first
  1249. byte, which is usually the address).
  1250. [13] STOP0 Determines whether a stop bit will be sent after the first
  1251. transaction
  1252. * 0: NO STOP
  1253. * 1: STOP
  1254. [12] START0 Determines whether a start bit will be sent before the
  1255. first transaction
  1256. * 0: NO START
  1257. * 1: START
  1258. [8] STOP_ON_NACK0 Determines whether the current transfer will stop
  1259. if a NACK is received during the first transaction (current
  1260. transaction always stops).
  1261. * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
  1262. * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
  1263. [0] RW0 Read/write indicator for first transaction - set to 0 for
  1264. write, 1 for read. This bit only controls HDMI_DDC behaviour -
  1265. the R/W bit in the transaction is programmed into the DDC buffer
  1266. as the LSB of the address byte.
  1267. * 0: WRITE
  1268. * 1: READ */
  1269. /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in
  1270. order to handle characteristics of portion #1 and portion #2
  1271. * RW0 = 0x0 (write)
  1272. * START0 = 0x1 (insert START bit)
  1273. * STOP0 = 0x0 (do NOT insert STOP bit)
  1274. * CNT0 = 0x1 (single byte transaction excluding address) */
  1275. HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16));
  1276. /* 0x022C HDMI_DDC_TRANS1
  1277. [23:16] CNT1 Byte count for second transaction (excluding the first
  1278. byte, which is usually the address).
  1279. [13] STOP1 Determines whether a stop bit will be sent after the second
  1280. transaction
  1281. * 0: NO STOP
  1282. * 1: STOP
  1283. [12] START1 Determines whether a start bit will be sent before the
  1284. second transaction
  1285. * 0: NO START
  1286. * 1: START
  1287. [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
  1288. a NACK is received during the second transaction (current
  1289. transaction always stops).
  1290. * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
  1291. * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
  1292. [0] RW1 Read/write indicator for second transaction - set to 0 for
  1293. write, 1 for read. This bit only controls HDMI_DDC behaviour -
  1294. the R/W bit in the transaction is programmed into the DDC buffer
  1295. as the LSB of the address byte.
  1296. * 0: WRITE
  1297. * 1: READ */
  1298. /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
  1299. order to handle characteristics of portion #3
  1300. * RW1 = 0x1 (read)
  1301. * START1 = 0x1 (insert START bit)
  1302. * STOP1 = 0x1 (insert STOP bit)
  1303. * CNT1 = data_len (0xN (write N bytes of data))
  1304. * Byte count for second transition (excluding the first
  1305. * Byte which is usually the address) */
  1306. HDMI_OUTP_ND(0x022C, (1 << 13) | ((data_len-1) << 16));
  1307. /* Trigger the I2C transfer */
  1308. /* 0x020C HDMI_DDC_CTRL
  1309. [21:20] TRANSACTION_CNT
  1310. Number of transactions to be done in current transfer.
  1311. * 0x0: transaction0 only
  1312. * 0x1: transaction0, transaction1
  1313. * 0x2: transaction0, transaction1, transaction2
  1314. * 0x3: transaction0, transaction1, transaction2, transaction3
  1315. [3] SW_STATUS_RESET
  1316. Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE,
  1317. ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW,
  1318. STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3
  1319. [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no
  1320. data) at start of transfer. This sequence is sent after GO is
  1321. written to 1, before the first transaction only.
  1322. [1] SOFT_RESET Write 1 to reset DDC controller
  1323. [0] GO WRITE ONLY. Write 1 to start DDC transfer. */
  1324. /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware.
  1325. * Note that NOTHING has been transmitted on the DDC lines up to this
  1326. * point.
  1327. * TRANSACTION_CNT = 0x1 (execute transaction0 followed by
  1328. * transaction1)
  1329. * GO = 0x1 (kicks off hardware) */
  1330. INIT_COMPLETION(hdmi_msm_state->ddc_sw_done);
  1331. HDMI_OUTP_ND(0x020C, (1 << 0) | (1 << 20));
  1332. time_out_count = wait_for_completion_interruptible_timeout(
  1333. &hdmi_msm_state->ddc_sw_done, HZ/2);
  1334. HDMI_OUTP_ND(0x0214, 0x2);
  1335. if (!time_out_count) {
  1336. if (retry-- > 0) {
  1337. DEV_INFO("%s[%s]: failed timout, retry=%d\n", __func__,
  1338. what, retry);
  1339. goto again;
  1340. }
  1341. status = -ETIMEDOUT;
  1342. DEV_ERR("%s[%s]: timedout, DDC SW Status=%08x, HW "
  1343. "Status=%08x, Int Ctrl=%08x\n", __func__, what,
  1344. HDMI_INP_ND(0x0218), HDMI_INP_ND(0x021C),
  1345. HDMI_INP_ND(0x0214));
  1346. goto error;
  1347. }
  1348. /* Read DDC status */
  1349. reg_val = HDMI_INP_ND(0x0218);
  1350. reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000;
  1351. /* Check if any NACK occurred */
  1352. if (reg_val) {
  1353. if (retry > 1)
  1354. HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */
  1355. else
  1356. HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */
  1357. if (retry-- > 0) {
  1358. DEV_DBG("%s[%s]: failed NACK=%08x, retry=%d\n",
  1359. __func__, what, reg_val, retry);
  1360. msleep(100);
  1361. goto again;
  1362. }
  1363. status = -EIO;
  1364. DEV_ERR("%s[%s]: failed NACK: %08x\n", __func__, what, reg_val);
  1365. goto error;
  1366. }
  1367. DEV_DBG("%s[%s] success\n", __func__, what);
  1368. error:
  1369. return status;
  1370. }
  1371. static int hdmi_msm_ddc_read_retry(uint32 dev_addr, uint32 offset,
  1372. uint8 *data_buf, uint32 data_len, uint32 request_len, int retry,
  1373. const char *what)
  1374. {
  1375. uint32 reg_val, ndx;
  1376. int status = 0;
  1377. uint32 time_out_count;
  1378. int log_retry_fail = retry != 1;
  1379. if (NULL == data_buf) {
  1380. status = -EINVAL;
  1381. DEV_ERR("%s: invalid input paramter\n", __func__);
  1382. goto error;
  1383. }
  1384. again:
  1385. status = hdmi_msm_ddc_clear_irq(what);
  1386. if (status)
  1387. goto error;
  1388. /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */
  1389. dev_addr &= 0xFE;
  1390. /* 0x0238 HDMI_DDC_DATA
  1391. [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to
  1392. 1 while writing HDMI_DDC_DATA.
  1393. [23:16] INDEX Use to set index into DDC buffer for next read or
  1394. current write, or to read index of current read or next write.
  1395. Writable only when INDEX_WRITE=1.
  1396. [15:8] DATA Use to fill or read the DDC buffer
  1397. [0] DATA_RW Select whether buffer access will be a read or write.
  1398. For writes, address auto-increments on write to HDMI_DDC_DATA.
  1399. For reads, address autoincrements on reads to HDMI_DDC_DATA.
  1400. * 0: Write
  1401. * 1: Read */
  1402. /* 1. Write to HDMI_I2C_DATA with the following fields set in order to
  1403. * handle portion #1
  1404. * DATA_RW = 0x0 (write)
  1405. * DATA = linkAddress (primary link address and writing)
  1406. * INDEX = 0x0 (initial offset into buffer)
  1407. * INDEX_WRITE = 0x1 (setting initial offset) */
  1408. HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (dev_addr << 8));
  1409. /* 2. Write to HDMI_I2C_DATA with the following fields set in order to
  1410. * handle portion #2
  1411. * DATA_RW = 0x0 (write)
  1412. * DATA = offsetAddress
  1413. * INDEX = 0x0
  1414. * INDEX_WRITE = 0x0 (auto-increment by hardware) */
  1415. HDMI_OUTP_ND(0x0238, offset << 8);
  1416. /* 3. Write to HDMI_I2C_DATA with the following fields set in order to
  1417. * handle portion #3
  1418. * DATA_RW = 0x0 (write)
  1419. * DATA = linkAddress + 1 (primary link address 0x74 and reading)
  1420. * INDEX = 0x0
  1421. * INDEX_WRITE = 0x0 (auto-increment by hardware) */
  1422. HDMI_OUTP_ND(0x0238, (dev_addr | 1) << 8);
  1423. /* Data setup is complete, now setup the transaction characteristics */
  1424. /* 0x0228 HDMI_DDC_TRANS0
  1425. [23:16] CNT0 Byte count for first transaction (excluding the first
  1426. byte, which is usually the address).
  1427. [13] STOP0 Determines whether a stop bit will be sent after the first
  1428. transaction
  1429. * 0: NO STOP
  1430. * 1: STOP
  1431. [12] START0 Determines whether a start bit will be sent before the
  1432. first transaction
  1433. * 0: NO START
  1434. * 1: START
  1435. [8] STOP_ON_NACK0 Determines whether the current transfer will stop
  1436. if a NACK is received during the first transaction (current
  1437. transaction always stops).
  1438. * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
  1439. * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
  1440. [0] RW0 Read/write indicator for first transaction - set to 0 for
  1441. write, 1 for read. This bit only controls HDMI_DDC behaviour -
  1442. the R/W bit in the transaction is programmed into the DDC buffer
  1443. as the LSB of the address byte.
  1444. * 0: WRITE
  1445. * 1: READ */
  1446. /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in
  1447. order to handle characteristics of portion #1 and portion #2
  1448. * RW0 = 0x0 (write)
  1449. * START0 = 0x1 (insert START bit)
  1450. * STOP0 = 0x0 (do NOT insert STOP bit)
  1451. * CNT0 = 0x1 (single byte transaction excluding address) */
  1452. HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16));
  1453. /* 0x022C HDMI_DDC_TRANS1
  1454. [23:16] CNT1 Byte count for second transaction (excluding the first
  1455. byte, which is usually the address).
  1456. [13] STOP1 Determines whether a stop bit will be sent after the second
  1457. transaction
  1458. * 0: NO STOP
  1459. * 1: STOP
  1460. [12] START1 Determines whether a start bit will be sent before the
  1461. second transaction
  1462. * 0: NO START
  1463. * 1: START
  1464. [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
  1465. a NACK is received during the second transaction (current
  1466. transaction always stops).
  1467. * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
  1468. * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
  1469. [0] RW1 Read/write indicator for second transaction - set to 0 for
  1470. write, 1 for read. This bit only controls HDMI_DDC behaviour -
  1471. the R/W bit in the transaction is programmed into the DDC buffer
  1472. as the LSB of the address byte.
  1473. * 0: WRITE
  1474. * 1: READ */
  1475. /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
  1476. order to handle characteristics of portion #3
  1477. * RW1 = 0x1 (read)
  1478. * START1 = 0x1 (insert START bit)
  1479. * STOP1 = 0x1 (insert STOP bit)
  1480. * CNT1 = data_len (it's 128 (0x80) for a blk read) */
  1481. HDMI_OUTP_ND(0x022C, 1 | (1 << 12) | (1 << 13) | (request_len << 16));
  1482. /* Trigger the I2C transfer */
  1483. /* 0x020C HDMI_DDC_CTRL
  1484. [21:20] TRANSACTION_CNT
  1485. Number of transactions to be done in current transfer.
  1486. * 0x0: transaction0 only
  1487. * 0x1: transaction0, transaction1
  1488. * 0x2: transaction0, transaction1, transaction2
  1489. * 0x3: transaction0, transaction1, transaction2, transaction3
  1490. [3] SW_STATUS_RESET
  1491. Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE,
  1492. ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW,
  1493. STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3
  1494. [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no
  1495. data) at start of transfer. This sequence is sent after GO is
  1496. written to 1, before the first transaction only.
  1497. [1] SOFT_RESET Write 1 to reset DDC controller
  1498. [0] GO WRITE ONLY. Write 1 to start DDC transfer. */
  1499. /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware.
  1500. * Note that NOTHING has been transmitted on the DDC lines up to this
  1501. * point.
  1502. * TRANSACTION_CNT = 0x1 (execute transaction0 followed by
  1503. * transaction1)
  1504. * SEND_RESET = Set to 1 to send reset sequence
  1505. * GO = 0x1 (kicks off hardware) */
  1506. INIT_COMPLETION(hdmi_msm_state->ddc_sw_done);
  1507. HDMI_OUTP_ND(0x020C, (1 << 0) | (1 << 20));
  1508. time_out_count = wait_for_completion_interruptible_timeout(
  1509. &hdmi_msm_state->ddc_sw_done, HZ/2);
  1510. HDMI_OUTP_ND(0x0214, 0x2);
  1511. if (!time_out_count) {
  1512. if (retry-- > 0) {
  1513. DEV_INFO("%s: failed timout, retry=%d\n", __func__,
  1514. retry);
  1515. goto again;
  1516. }
  1517. status = -ETIMEDOUT;
  1518. DEV_ERR("%s: timedout(7), DDC SW Status=%08x, HW "
  1519. "Status=%08x, Int Ctrl=%08x\n", __func__,
  1520. HDMI_INP(0x0218), HDMI_INP(0x021C), HDMI_INP(0x0214));
  1521. goto error;
  1522. }
  1523. /* Read DDC status */
  1524. reg_val = HDMI_INP_ND(0x0218);
  1525. reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000;
  1526. /* Check if any NACK occurred */
  1527. if (reg_val) {
  1528. HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */
  1529. if (retry == 1)
  1530. HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */
  1531. if (retry-- > 0) {
  1532. DEV_DBG("%s(%s): failed NACK=0x%08x, retry=%d, "
  1533. "dev-addr=0x%02x, offset=0x%02x, "
  1534. "length=%d\n", __func__, what,
  1535. reg_val, retry, dev_addr,
  1536. offset, data_len);
  1537. goto again;
  1538. }
  1539. status = -EIO;
  1540. if (log_retry_fail)
  1541. DEV_ERR("%s(%s): failed NACK=0x%08x, dev-addr=0x%02x, "
  1542. "offset=0x%02x, length=%d\n", __func__, what,
  1543. reg_val, dev_addr, offset, data_len);
  1544. goto error;
  1545. }
  1546. /* 0x0238 HDMI_DDC_DATA
  1547. [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to 1
  1548. while writing HDMI_DDC_DATA.
  1549. [23:16] INDEX Use to set index into DDC buffer for next read or
  1550. current write, or to read index of current read or next write.
  1551. Writable only when INDEX_WRITE=1.
  1552. [15:8] DATA Use to fill or read the DDC buffer
  1553. [0] DATA_RW Select whether buffer access will be a read or write.
  1554. For writes, address auto-increments on write to HDMI_DDC_DATA.
  1555. For reads, address autoincrements on reads to HDMI_DDC_DATA.
  1556. * 0: Write
  1557. * 1: Read */
  1558. /* 8. ALL data is now available and waiting in the DDC buffer.
  1559. * Read HDMI_I2C_DATA with the following fields set
  1560. * RW = 0x1 (read)
  1561. * DATA = BCAPS (this is field where data is pulled from)
  1562. * INDEX = 0x3 (where the data has been placed in buffer by hardware)
  1563. * INDEX_WRITE = 0x1 (explicitly define offset) */
  1564. /* Write this data to DDC buffer */
  1565. HDMI_OUTP_ND(0x0238, 0x1 | (3 << 16) | (1 << 31));
  1566. /* Discard first byte */
  1567. HDMI_INP_ND(0x0238);
  1568. for (ndx = 0; ndx < data_len; ++ndx) {
  1569. reg_val = HDMI_INP_ND(0x0238);
  1570. data_buf[ndx] = (uint8) ((reg_val & 0x0000FF00) >> 8);
  1571. }
  1572. DEV_DBG("%s[%s] success\n", __func__, what);
  1573. error:
  1574. return status;
  1575. }
  1576. static int hdmi_msm_ddc_read_edid_seg(uint32 dev_addr, uint32 offset,
  1577. uint8 *data_buf, uint32 data_len, uint32 request_len, int retry,
  1578. const char *what)
  1579. {
  1580. uint32 reg_val, ndx;
  1581. int status = 0;
  1582. uint32 time_out_count;
  1583. int log_retry_fail = retry != 1;
  1584. int seg_addr = 0x60, seg_num = 0x01;
  1585. if (NULL == data_buf) {
  1586. status = -EINVAL;
  1587. DEV_ERR("%s: invalid input paramter\n", __func__);
  1588. goto error;
  1589. }
  1590. again:
  1591. status = hdmi_msm_ddc_clear_irq(what);
  1592. if (status)
  1593. goto error;
  1594. /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */
  1595. dev_addr &= 0xFE;
  1596. /* 0x0238 HDMI_DDC_DATA
  1597. [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to
  1598. 1 while writing HDMI_DDC_DATA.
  1599. [23:16] INDEX Use to set index into DDC buffer for next read or
  1600. current write, or to read index of current read or next write.
  1601. Writable only when INDEX_WRITE=1.
  1602. [15:8] DATA Use to fill or read the DDC buffer
  1603. [0] DATA_RW Select whether buffer access will be a read or write.
  1604. For writes, address auto-increments on write to HDMI_DDC_DATA.
  1605. For reads, address autoincrements on reads to HDMI_DDC_DATA.
  1606. * 0: Write
  1607. * 1: Read */
  1608. /* 1. Write to HDMI_I2C_DATA with the following fields set in order to
  1609. * handle portion #1
  1610. * DATA_RW = 0x0 (write)
  1611. * DATA = linkAddress (primary link address and writing)
  1612. * INDEX = 0x0 (initial offset into buffer)
  1613. * INDEX_WRITE = 0x1 (setting initial offset) */
  1614. HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (seg_addr << 8));
  1615. /* 2. Write to HDMI_I2C_DATA with the following fields set in order to
  1616. * handle portion #2
  1617. * DATA_RW = 0x0 (write)
  1618. * DATA = offsetAddress
  1619. * INDEX = 0x0
  1620. * INDEX_WRITE = 0x0 (auto-increment by hardware) */
  1621. HDMI_OUTP_ND(0x0238, seg_num << 8);
  1622. /* 3. Write to HDMI_I2C_DATA with the following fields set in order to
  1623. * handle portion #3
  1624. * DATA_RW = 0x0 (write)
  1625. * DATA = linkAddress + 1 (primary link address 0x74 and reading)
  1626. * INDEX = 0x0
  1627. * INDEX_WRITE = 0x0 (auto-increment by hardware) */
  1628. HDMI_OUTP_ND(0x0238, dev_addr << 8);
  1629. HDMI_OUTP_ND(0x0238, offset << 8);
  1630. HDMI_OUTP_ND(0x0238, (dev_addr | 1) << 8);
  1631. /* Data setup is complete, now setup the transaction characteristics */
  1632. /* 0x0228 HDMI_DDC_TRANS0
  1633. [23:16] CNT0 Byte count for first transaction (excluding the first
  1634. byte, which is usually the address).
  1635. [13] STOP0 Determines whether a stop bit will be sent after the first
  1636. transaction
  1637. * 0: NO STOP
  1638. * 1: STOP
  1639. [12] START0 Determines whether a start bit will be sent before the
  1640. first transaction
  1641. * 0: NO START
  1642. * 1: START
  1643. [8] STOP_ON_NACK0 Determines whether the current transfer will stop
  1644. if a NACK is received during the first transaction (current
  1645. transaction always stops).
  1646. * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
  1647. * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
  1648. [0] RW0 Read/write indicator for first transaction - set to 0 for
  1649. write, 1 for read. This bit only controls HDMI_DDC behaviour -
  1650. the R/W bit in the transaction is programmed into the DDC buffer
  1651. as the LSB of the address byte.
  1652. * 0: WRITE
  1653. * 1: READ */
  1654. /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in
  1655. order to handle characteristics of portion #1 and portion #2
  1656. * RW0 = 0x0 (write)
  1657. * START0 = 0x1 (insert START bit)
  1658. * STOP0 = 0x0 (do NOT insert STOP bit)
  1659. * CNT0 = 0x1 (single byte transaction excluding address) */
  1660. HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16));
  1661. /* 0x022C HDMI_DDC_TRANS1
  1662. [23:16] CNT1 Byte count for second transaction (excluding the first
  1663. byte, which is usually the address).
  1664. [13] STOP1 Determines whether a stop bit will be sent after the second
  1665. transaction
  1666. * 0: NO STOP
  1667. * 1: STOP
  1668. [12] START1 Determines whether a start bit will be sent before the
  1669. second transaction
  1670. * 0: NO START
  1671. * 1: START
  1672. [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
  1673. a NACK is received during the second transaction (current
  1674. transaction always stops).
  1675. * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
  1676. * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
  1677. [0] RW1 Read/write indicator for second transaction - set to 0 for
  1678. write, 1 for read. This bit only controls HDMI_DDC behaviour -
  1679. the R/W bit in the transaction is programmed into the DDC buffer
  1680. as the LSB of the address byte.
  1681. * 0: WRITE
  1682. * 1: READ */
  1683. /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
  1684. order to handle characteristics of portion #3
  1685. * RW1 = 0x1 (read)
  1686. * START1 = 0x1 (insert START bit)
  1687. * STOP1 = 0x1 (insert STOP bit)
  1688. * CNT1 = data_len (it's 128 (0x80) for a blk read) */
  1689. HDMI_OUTP_ND(0x022C, (1 << 12) | (1 << 16));
  1690. /* 0x022C HDMI_DDC_TRANS2
  1691. [23:16] CNT1 Byte count for second transaction (excluding the first
  1692. byte, which is usually the address).
  1693. [13] STOP1 Determines whether a stop bit will be sent after the second
  1694. transaction
  1695. * 0: NO STOP
  1696. * 1: STOP
  1697. [12] START1 Determines whether a start bit will be sent before the
  1698. second transaction
  1699. * 0: NO START
  1700. * 1: START
  1701. [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
  1702. a NACK is received during the second transaction (current
  1703. transaction always stops).
  1704. * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
  1705. * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
  1706. [0] RW1 Read/write indicator for second transaction - set to 0 for
  1707. write, 1 for read. This bit only controls HDMI_DDC behaviour -
  1708. the R/W bit in the transaction is programmed into the DDC buffer
  1709. as the LSB of the address byte.
  1710. * 0: WRITE
  1711. * 1: READ */
  1712. /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
  1713. order to handle characteristics of portion #3
  1714. * RW1 = 0x1 (read)
  1715. * START1 = 0x1 (insert START bit)
  1716. * STOP1 = 0x1 (insert STOP bit)
  1717. * CNT1 = data_len (it's 128 (0x80) for a blk read) */
  1718. HDMI_OUTP_ND(0x0230, 1 | (1 << 12) | (1 << 13) | (request_len << 16));
  1719. /* Trigger the I2C transfer */
  1720. /* 0x020C HDMI_DDC_CTRL
  1721. [21:20] TRANSACTION_CNT
  1722. Number of transactions to be done in current transfer.
  1723. * 0x0: transaction0 only
  1724. * 0x1: transaction0, transaction1
  1725. * 0x2: transaction0, transaction1, transaction2
  1726. * 0x3: transaction0, transaction1, transaction2, transaction3
  1727. [3] SW_STATUS_RESET
  1728. Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE,
  1729. ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW,
  1730. STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3
  1731. [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no
  1732. data) at start of transfer. This sequence is sent after GO is
  1733. written to 1, before the first transaction only.
  1734. [1] SOFT_RESET Write 1 to reset DDC controller
  1735. [0] GO WRITE ONLY. Write 1 to start DDC transfer. */
  1736. /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware.
  1737. * Note that NOTHING has been transmitted on the DDC lines up to this
  1738. * point.
  1739. * TRANSACTION_CNT = 0x2 (execute transaction0 followed by
  1740. * transaction1)
  1741. * GO = 0x1 (kicks off hardware) */
  1742. INIT_COMPLETION(hdmi_msm_state->ddc_sw_done);
  1743. HDMI_OUTP_ND(0x020C, (1 << 0) | (2 << 20));
  1744. time_out_count = wait_for_completion_interruptible_timeout(
  1745. &hdmi_msm_state->ddc_sw_done, HZ/2);
  1746. HDMI_OUTP_ND(0x0214, 0x2);
  1747. if (!time_out_count) {
  1748. if (retry-- > 0) {
  1749. DEV_INFO("%s: failed timout, retry=%d\n", __func__,
  1750. retry);
  1751. goto again;
  1752. }
  1753. status = -ETIMEDOUT;
  1754. DEV_ERR("%s: timedout(7), DDC SW Status=%08x, HW "
  1755. "Status=%08x, Int Ctrl=%08x\n", __func__,
  1756. HDMI_INP(0x0218), HDMI_INP(0x021C), HDMI_INP(0x0214));
  1757. goto error;
  1758. }
  1759. /* Read DDC status */
  1760. reg_val = HDMI_INP_ND(0x0218);
  1761. reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000;
  1762. /* Check if any NACK occurred */
  1763. if (reg_val) {
  1764. HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */
  1765. if (retry == 1)
  1766. HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */
  1767. if (retry-- > 0) {
  1768. DEV_DBG("%s(%s): failed NACK=0x%08x, retry=%d, "
  1769. "dev-addr=0x%02x, offset=0x%02x, "
  1770. "length=%d\n", __func__, what,
  1771. reg_val, retry, dev_addr,
  1772. offset, data_len);
  1773. goto again;
  1774. }
  1775. status = -EIO;
  1776. if (log_retry_fail)
  1777. DEV_ERR("%s(%s): failed NACK=0x%08x, dev-addr=0x%02x, "
  1778. "offset=0x%02x, length=%d\n", __func__, what,
  1779. reg_val, dev_addr, offset, data_len);
  1780. goto error;
  1781. }
  1782. /* 0x0238 HDMI_DDC_DATA
  1783. [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to 1
  1784. while writing HDMI_DDC_DATA.
  1785. [23:16] INDEX Use to set index into DDC buffer for next read or
  1786. current write, or to read index of current read or next write.
  1787. Writable only when INDEX_WRITE=1.
  1788. [15:8] DATA Use to fill or read the DDC buffer
  1789. [0] DATA_RW Select whether buffer access will be a read or write.
  1790. For writes, address auto-increments on write to HDMI_DDC_DATA.
  1791. For reads, address autoincrements on reads to HDMI_DDC_DATA.
  1792. * 0: Write
  1793. * 1: Read */
  1794. /* 8. ALL data is now available and waiting in the DDC buffer.
  1795. * Read HDMI_I2C_DATA with the following fields set
  1796. * RW = 0x1 (read)
  1797. * DATA = BCAPS (this is field where data is pulled from)
  1798. * INDEX = 0x5 (where the data has been placed in buffer by hardware)
  1799. * INDEX_WRITE = 0x1 (explicitly define offset) */
  1800. /* Write this data to DDC buffer */
  1801. HDMI_OUTP_ND(0x0238, 0x1 | (5 << 16) | (1 << 31));
  1802. /* Discard first byte */
  1803. HDMI_INP_ND(0x0238);
  1804. for (ndx = 0; ndx < data_len; ++ndx) {
  1805. reg_val = HDMI_INP_ND(0x0238);
  1806. data_buf[ndx] = (uint8) ((reg_val & 0x0000FF00) >> 8);
  1807. }
  1808. DEV_DBG("%s[%s] success\n", __func__, what);
  1809. error:
  1810. return status;
  1811. }
  1812. static int hdmi_msm_ddc_read(uint32 dev_addr, uint32 offset, uint8 *data_buf,
  1813. uint32 data_len, int retry, const char *what, boolean no_align)
  1814. {
  1815. int ret = hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf, data_len,
  1816. data_len, retry, what);
  1817. if (!ret)
  1818. return 0;
  1819. if (no_align) {
  1820. return hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf,
  1821. data_len, data_len, retry, what);
  1822. } else {
  1823. return hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf,
  1824. data_len, 32 * ((data_len + 31) / 32), retry, what);
  1825. }
  1826. }
  1827. static int hdmi_msm_read_edid_block(int block, uint8 *edid_buf)
  1828. {
  1829. int i, rc = 0;
  1830. int block_size = 0x80;
  1831. do {
  1832. DEV_DBG("EDID: reading block(%d) with block-size=%d\n",
  1833. block, block_size);
  1834. for (i = 0; i < 0x80; i += block_size) {
  1835. /*Read EDID twice with 32bit alighnment too */
  1836. if (block < 2) {
  1837. rc = hdmi_msm_ddc_read(0xA0, block*0x80 + i,
  1838. edid_buf+i, block_size, 1,
  1839. "EDID", FALSE);
  1840. } else {
  1841. rc = hdmi_msm_ddc_read_edid_seg(0xA0,
  1842. block*0x80 + i, edid_buf+i, block_size,
  1843. block_size, 1, "EDID");
  1844. }
  1845. if (rc)
  1846. break;
  1847. }
  1848. block_size /= 2;
  1849. } while (rc && (block_size >= 16));
  1850. return rc;
  1851. }
  1852. static int hdmi_msm_read_edid(void)
  1853. {
  1854. int status;
  1855. msm_hdmi_init_ddc();
  1856. /* Looks like we need to turn on HDMI engine before any
  1857. * DDC transaction */
  1858. if (!hdmi_msm_is_power_on()) {
  1859. DEV_ERR("%s: failed: HDMI power is off", __func__);
  1860. status = -ENXIO;
  1861. goto error;
  1862. }
  1863. external_common_state->read_edid_block = hdmi_msm_read_edid_block;
  1864. status = hdmi_common_read_edid();
  1865. if (!status)
  1866. DEV_DBG("EDID: successfully read\n");
  1867. error:
  1868. return status;
  1869. }
  1870. static void hdcp_auth_info(uint32 auth_info)
  1871. {
  1872. if (!hdmi_msm_state->hdcp_enable) {
  1873. DEV_DBG("%s: HDCP not enabled\n", __func__);
  1874. return;
  1875. }
  1876. switch (auth_info) {
  1877. case 0:
  1878. DEV_INFO("%s: None", __func__);
  1879. break;
  1880. case 1:
  1881. DEV_INFO("%s: Software Disabled Authentication", __func__);
  1882. break;
  1883. case 2:
  1884. DEV_INFO("%s: An Written", __func__);
  1885. break;
  1886. case 3:
  1887. DEV_INFO("%s: Invalid Aksv", __func__);
  1888. break;
  1889. case 4:
  1890. DEV_INFO("%s: Invalid Bksv", __func__);
  1891. break;
  1892. case 5:
  1893. DEV_INFO("%s: RI Mismatch (including RO)", __func__);
  1894. break;
  1895. case 6:
  1896. DEV_INFO("%s: consecutive Pj Mismatches", __func__);
  1897. break;
  1898. case 7:
  1899. DEV_INFO("%s: HPD Disconnect", __func__);
  1900. break;
  1901. case 8:
  1902. default:
  1903. DEV_INFO("%s: Reserved", __func__);
  1904. break;
  1905. }
  1906. }
  1907. static void hdcp_key_state(uint32 key_state)
  1908. {
  1909. if (!hdmi_msm_state->hdcp_enable) {
  1910. DEV_DBG("%s: HDCP not enabled\n", __func__);
  1911. return;
  1912. }
  1913. switch (key_state) {
  1914. case 0:
  1915. DEV_WARN("%s: No HDCP Keys", __func__);
  1916. break;
  1917. case 1:
  1918. DEV_WARN("%s: Not Checked", __func__);
  1919. break;
  1920. case 2:
  1921. DEV_DBG("%s: Checking", __func__);
  1922. break;
  1923. case 3:
  1924. DEV_DBG("%s: HDCP Keys Valid", __func__);
  1925. break;
  1926. case 4:
  1927. DEV_WARN("%s: AKSV not valid", __func__);
  1928. break;
  1929. case 5:
  1930. DEV_WARN("%s: Checksum Mismatch", __func__);
  1931. break;
  1932. case 6:
  1933. DEV_DBG("%s: Production AKSV"
  1934. "with ENABLE_USER_DEFINED_AN=1", __func__);
  1935. break;
  1936. case 7:
  1937. default:
  1938. DEV_INFO("%s: Reserved", __func__);
  1939. break;
  1940. }
  1941. }
  1942. static int hdmi_msm_count_one(uint8 *array, uint8 len)
  1943. {
  1944. int i, j, count = 0;
  1945. for (i = 0; i < len; i++)
  1946. for (j = 0; j < 8; j++)
  1947. count += (((array[i] >> j) & 0x1) ? 1 : 0);
  1948. return count;
  1949. }
  1950. static void hdcp_deauthenticate(void)
  1951. {
  1952. int hdcp_link_status = HDMI_INP(0x011C);
  1953. if (!hdmi_msm_state->hdcp_enable) {
  1954. DEV_DBG("%s: HDCP not enabled\n", __func__);
  1955. return;
  1956. }
  1957. /* Disable HDCP interrupts */
  1958. HDMI_OUTP(0x0118, 0x0);
  1959. mutex_lock(&hdcp_auth_state_mutex);
  1960. external_common_state->hdcp_active = FALSE;
  1961. mutex_unlock(&hdcp_auth_state_mutex);
  1962. /* 0x0130 HDCP_RESET
  1963. [0] LINK0_DEAUTHENTICATE */
  1964. HDMI_OUTP(0x0130, 0x1);
  1965. /* 0x0110 HDCP_CTRL
  1966. [8] ENCRYPTION_ENABLE
  1967. [0] ENABLE */
  1968. /* encryption_enable = 0 | hdcp block enable = 1 */
  1969. HDMI_OUTP(0x0110, 0x0);
  1970. if (hdcp_link_status & 0x00000004)
  1971. hdcp_auth_info((hdcp_link_status & 0x000000F0) >> 4);
  1972. }
  1973. static void check_and_clear_HDCP_DDC_Failure(void)
  1974. {
  1975. int hdcp_ddc_ctrl1_reg;
  1976. int hdcp_ddc_status;
  1977. int failure;
  1978. int nack0;
  1979. if (!hdmi_msm_state->hdcp_enable) {
  1980. DEV_DBG("%s: HDCP not enabled\n", __func__);
  1981. return;
  1982. }
  1983. /*
  1984. * Check for any DDC transfer failures
  1985. * 0x0128 HDCP_DDC_STATUS
  1986. * [16] FAILED Indicates that the last HDCP HW DDC transer
  1987. * failed. This occurs when a transfer is
  1988. * attempted with HDCP DDC disabled
  1989. * (HDCP_DDC_DISABLE=1) or the number of retries
  1990. * match HDCP_DDC_RETRY_CNT
  1991. *
  1992. * [14] NACK0 Indicates that the last HDCP HW DDC transfer
  1993. * was aborted due to a NACK on the first
  1994. * transaction - cleared by writing 0 to GO bit
  1995. */
  1996. hdcp_ddc_status = HDMI_INP(HDCP_DDC_STATUS);
  1997. failure = (hdcp_ddc_status >> 16) & 0x1;
  1998. nack0 = (hdcp_ddc_status >> 14) & 0x1;
  1999. DEV_DBG("%s: On Entry: HDCP_DDC_STATUS = 0x%x, FAILURE = %d,"
  2000. "NACK0 = %d\n", __func__ , hdcp_ddc_status, failure, nack0);
  2001. if (failure == 0x1) {
  2002. /*
  2003. * Indicates that the last HDCP HW DDC transfer failed.
  2004. * This occurs when a transfer is attempted with HDCP DDC
  2005. * disabled (HDCP_DDC_DISABLE=1) or the number of retries
  2006. * matches HDCP_DDC_RETRY_CNT.
  2007. * Failure occured, let's clear it.
  2008. */
  2009. DEV_INFO("%s: DDC failure detected. HDCP_DDC_STATUS=0x%08x\n",
  2010. __func__, hdcp_ddc_status);
  2011. /*
  2012. * First, Disable DDC
  2013. * 0x0120 HDCP_DDC_CTRL_0
  2014. * [0] DDC_DISABLE Determines whether HDCP Ri and Pj reads
  2015. * are done unassisted by hardware or by
  2016. * software via HDMI_DDC (HDCP provides
  2017. * interrupts to request software
  2018. * transfers)
  2019. * 0 : Use Hardware DDC
  2020. * 1 : Use Software DDC
  2021. */
  2022. HDMI_OUTP(HDCP_DDC_CTRL_0, 0x1);
  2023. /*
  2024. * ACK the Failure to Clear it
  2025. * 0x0124 HDCP_DDC_CTRL_1
  2026. * [0] DDC_FAILED_ACK Write 1 to clear
  2027. * HDCP_STATUS.HDCP_DDC_FAILED
  2028. */
  2029. hdcp_ddc_ctrl1_reg = HDMI_INP(HDCP_DDC_CTRL_1);
  2030. HDMI_OUTP(HDCP_DDC_CTRL_1, hdcp_ddc_ctrl1_reg | 0x1);
  2031. /* Check if the FAILURE got Cleared */
  2032. hdcp_ddc_status = HDMI_INP(HDCP_DDC_STATUS);
  2033. hdcp_ddc_status = (hdcp_ddc_status >> 16) & 0x1;
  2034. if (hdcp_ddc_status == 0x0) {
  2035. DEV_INFO("%s: HDCP DDC Failure has been cleared\n",
  2036. __func__);
  2037. } else {
  2038. DEV_WARN("%s: Error: HDCP DDC Failure DID NOT get"
  2039. "cleared\n", __func__);
  2040. }
  2041. /* Re-Enable HDCP DDC */
  2042. HDMI_OUTP(HDCP_DDC_CTRL_0, 0x0);
  2043. }
  2044. if (nack0 == 0x1) {
  2045. /*
  2046. * 0x020C HDMI_DDC_CTRL
  2047. * [3] SW_STATUS_RESET Write 1 to reset HDMI_DDC_SW_STATUS
  2048. * flags, will reset SW_DONE, ABORTED,
  2049. * TIMEOUT, SW_INTERRUPTED,
  2050. * BUFFER_OVERFLOW, STOPPED_ON_NACK, NACK0,
  2051. * NACK1, NACK2, NACK3
  2052. */
  2053. HDMI_OUTP_ND(HDMI_DDC_CTRL,
  2054. HDMI_INP(HDMI_DDC_CTRL) | (0x1 << 3));
  2055. msleep(20);
  2056. HDMI_OUTP_ND(HDMI_DDC_CTRL,
  2057. HDMI_INP(HDMI_DDC_CTRL) & ~(0x1 << 3));
  2058. }
  2059. hdcp_ddc_status = HDMI_INP(HDCP_DDC_STATUS);
  2060. failure = (hdcp_ddc_status >> 16) & 0x1;
  2061. nack0 = (hdcp_ddc_status >> 14) & 0x1;
  2062. DEV_DBG("%s: On Exit: HDCP_DDC_STATUS = 0x%x, FAILURE = %d,"
  2063. "NACK0 = %d\n", __func__ , hdcp_ddc_status, failure, nack0);
  2064. }
  2065. static int hdcp_authentication_part1(void)
  2066. {
  2067. int ret = 0;
  2068. boolean is_match;
  2069. boolean is_part1_done = FALSE;
  2070. uint32 timeout_count;
  2071. uint8 bcaps;
  2072. uint8 aksv[5];
  2073. uint32 qfprom_aksv_0, qfprom_aksv_1, link0_aksv_0, link0_aksv_1;
  2074. uint8 bksv[5];
  2075. uint32 link0_bksv_0, link0_bksv_1;
  2076. uint8 an[8];
  2077. uint32 link0_an_0, link0_an_1;
  2078. uint32 hpd_int_status, hpd_int_ctrl;
  2079. static uint8 buf[0xFF];
  2080. memset(buf, 0, sizeof(buf));
  2081. if (!hdmi_msm_state->hdcp_enable) {
  2082. DEV_DBG("%s: HDCP not enabled\n", __func__);
  2083. return 0;
  2084. }
  2085. if (!is_part1_done) {
  2086. is_part1_done = TRUE;
  2087. /* Fetch aksv from QFprom, this info should be public. */
  2088. qfprom_aksv_0 = inpdw(QFPROM_BASE + 0x000060D8);
  2089. qfprom_aksv_1 = inpdw(QFPROM_BASE + 0x000060DC);
  2090. /* copy an and aksv to byte arrays for transmission */
  2091. aksv[0] = qfprom_aksv_0 & 0xFF;
  2092. aksv[1] = (qfprom_aksv_0 >> 8) & 0xFF;
  2093. aksv[2] = (qfprom_aksv_0 >> 16) & 0xFF;
  2094. aksv[3] = (qfprom_aksv_0 >> 24) & 0xFF;
  2095. aksv[4] = qfprom_aksv_1 & 0xFF;
  2096. /* check there are 20 ones in AKSV */
  2097. if (hdmi_msm_count_one(aksv, 5) != 20) {
  2098. DEV_ERR("HDCP: AKSV read from QFPROM doesn't have "
  2099. "20 1's and 20 0's, FAIL (AKSV=%02x%08x)\n",
  2100. qfprom_aksv_1, qfprom_aksv_0);
  2101. ret = -EINVAL;
  2102. goto error;
  2103. }
  2104. DEV_DBG("HDCP: AKSV=%02x%08x\n", qfprom_aksv_1, qfprom_aksv_0);
  2105. /* 0x0288 HDCP_SW_LOWER_AKSV
  2106. [31:0] LOWER_AKSV */
  2107. /* 0x0284 HDCP_SW_UPPER_AKSV
  2108. [7:0] UPPER_AKSV */
  2109. /* This is the lower 32 bits of the SW
  2110. * injected AKSV value(AKSV[31:0]) read
  2111. * from the EFUSE. It is needed for HDCP
  2112. * authentication and must be written
  2113. * before enabling HDCP. */
  2114. HDMI_OUTP(0x0288, qfprom_aksv_0);
  2115. HDMI_OUTP(0x0284, qfprom_aksv_1);
  2116. msm_hdmi_init_ddc();
  2117. /* read Bcaps at 0x40 in HDCP Port */
  2118. ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 5, "Bcaps",
  2119. TRUE);
  2120. if (ret) {
  2121. DEV_ERR("%s(%d): Read Bcaps failed", __func__,
  2122. __LINE__);
  2123. goto error;
  2124. }
  2125. DEV_DBG("HDCP: Bcaps=%02x\n", bcaps);
  2126. /* HDCP setup prior to HDCP enabled */
  2127. /* 0x0148 HDCP_RCVPORT_DATA4
  2128. [15:8] LINK0_AINFO
  2129. [7:0] LINK0_AKSV_1 */
  2130. /* LINK0_AINFO = 0x2 FEATURE 1.1 on.
  2131. * = 0x0 FEATURE 1.1 off*/
  2132. HDMI_OUTP(0x0148, 0x0);
  2133. /* 0x012C HDCP_ENTROPY_CTRL0
  2134. [31:0] BITS_OF_INFLUENCE_0 */
  2135. /* 0x025C HDCP_ENTROPY_CTRL1
  2136. [31:0] BITS_OF_INFLUENCE_1 */
  2137. HDMI_OUTP(0x012C, 0xB1FFB0FF);
  2138. HDMI_OUTP(0x025C, 0xF00DFACE);
  2139. /* 0x0114 HDCP_DEBUG_CTRL
  2140. [2] DEBUG_RNG_CIPHER
  2141. else default 0 */
  2142. HDMI_OUTP(0x0114, HDMI_INP(0x0114) & 0xFFFFFFFB);
  2143. /* 0x0110 HDCP_CTRL
  2144. [8] ENCRYPTION_ENABLE
  2145. [0] ENABLE */
  2146. /* Enable HDCP. Encryption should be enabled after reading R0 */
  2147. HDMI_OUTP(0x0110, BIT(0));
  2148. /*
  2149. * Check to see if a HDCP DDC Failure is indicated in
  2150. * HDCP_DDC_STATUS. If yes, clear it.
  2151. */
  2152. check_and_clear_HDCP_DDC_Failure();
  2153. /* 0x0118 HDCP_INT_CTRL
  2154. * [2] AUTH_SUCCESS_MASK [R/W] Mask bit for\
  2155. * HDCP Authentication
  2156. * Success interrupt - set to 1 to enable interrupt
  2157. *
  2158. * [6] AUTH_FAIL_MASK [R/W] Mask bit for HDCP
  2159. * Authentication
  2160. * Lost interrupt set to 1 to enable interrupt
  2161. *
  2162. * [7] AUTH_FAIL_INFO_ACK [W] Acknwledge bit for HDCP
  2163. * Auth Failure Info field - write 1 to clear
  2164. *
  2165. * [10] DDC_XFER_REQ_MASK [R/W] Mask bit for HDCP\
  2166. * DDC Transfer
  2167. * Request interrupt - set to 1 to enable interrupt
  2168. *
  2169. * [14] DDC_XFER_DONE_MASK [R/W] Mask bit for HDCP\
  2170. * DDC Transfer
  2171. * done interrupt - set to 1 to enable interrupt */
  2172. /* enable all HDCP ints */
  2173. HDMI_OUTP(0x0118, (1 << 2) | (1 << 6) | (1 << 7));
  2174. /* 0x011C HDCP_LINK0_STATUS
  2175. [8] AN_0_READY
  2176. [9] AN_1_READY */
  2177. /* wait for an0 and an1 ready bits to be set in LINK0_STATUS */
  2178. mutex_lock(&hdcp_auth_state_mutex);
  2179. timeout_count = 100;
  2180. while (((HDMI_INP_ND(0x011C) & (0x3 << 8)) != (0x3 << 8))
  2181. && timeout_count--)
  2182. msleep(20);
  2183. if (!timeout_count) {
  2184. ret = -ETIMEDOUT;
  2185. DEV_ERR("%s(%d): timedout, An0=%d, An1=%d\n",
  2186. __func__, __LINE__,
  2187. (HDMI_INP_ND(0x011C) & BIT(8)) >> 8,
  2188. (HDMI_INP_ND(0x011C) & BIT(9)) >> 9);
  2189. mutex_unlock(&hdcp_auth_state_mutex);
  2190. goto error;
  2191. }
  2192. /* 0x0168 HDCP_RCVPORT_DATA12
  2193. [23:8] BSTATUS
  2194. [7:0] BCAPS */
  2195. HDMI_OUTP(0x0168, bcaps);
  2196. /* 0x014C HDCP_RCVPORT_DATA5
  2197. [31:0] LINK0_AN_0 */
  2198. /* read an0 calculation */
  2199. link0_an_0 = HDMI_INP(0x014C);
  2200. /* 0x0150 HDCP_RCVPORT_DATA6
  2201. [31:0] LINK0_AN_1 */
  2202. /* read an1 calculation */
  2203. link0_an_1 = HDMI_INP(0x0150);
  2204. mutex_unlock(&hdcp_auth_state_mutex);
  2205. /* three bits 28..30 */
  2206. hdcp_key_state((HDMI_INP(0x011C) >> 28) & 0x7);
  2207. /* 0x0144 HDCP_RCVPORT_DATA3
  2208. [31:0] LINK0_AKSV_0 public key
  2209. 0x0148 HDCP_RCVPORT_DATA4
  2210. [15:8] LINK0_AINFO
  2211. [7:0] LINK0_AKSV_1 public key */
  2212. link0_aksv_0 = HDMI_INP(0x0144);
  2213. link0_aksv_1 = HDMI_INP(0x0148);
  2214. /* copy an and aksv to byte arrays for transmission */
  2215. aksv[0] = link0_aksv_0 & 0xFF;
  2216. aksv[1] = (link0_aksv_0 >> 8) & 0xFF;
  2217. aksv[2] = (link0_aksv_0 >> 16) & 0xFF;
  2218. aksv[3] = (link0_aksv_0 >> 24) & 0xFF;
  2219. aksv[4] = link0_aksv_1 & 0xFF;
  2220. an[0] = link0_an_0 & 0xFF;
  2221. an[1] = (link0_an_0 >> 8) & 0xFF;
  2222. an[2] = (link0_an_0 >> 16) & 0xFF;
  2223. an[3] = (link0_an_0 >> 24) & 0xFF;
  2224. an[4] = link0_an_1 & 0xFF;
  2225. an[5] = (link0_an_1 >> 8) & 0xFF;
  2226. an[6] = (link0_an_1 >> 16) & 0xFF;
  2227. an[7] = (link0_an_1 >> 24) & 0xFF;
  2228. /* Write An 8 bytes to offset 0x18 */
  2229. ret = hdmi_msm_ddc_write(0x74, 0x18, an, 8, "An");
  2230. if (ret) {
  2231. DEV_ERR("%s(%d): Write An failed", __func__, __LINE__);
  2232. goto error;
  2233. }
  2234. /* Write Aksv 5 bytes to offset 0x10 */
  2235. ret = hdmi_msm_ddc_write(0x74, 0x10, aksv, 5, "Aksv");
  2236. if (ret) {
  2237. DEV_ERR("%s(%d): Write Aksv failed", __func__,
  2238. __LINE__);
  2239. goto error;
  2240. }
  2241. DEV_DBG("HDCP: Link0-AKSV=%02x%08x\n",
  2242. link0_aksv_1 & 0xFF, link0_aksv_0);
  2243. /* Read Bksv 5 bytes at 0x00 in HDCP port */
  2244. ret = hdmi_msm_ddc_read(0x74, 0x00, bksv, 5, 5, "Bksv", TRUE);
  2245. if (ret) {
  2246. DEV_ERR("%s(%d): Read BKSV failed", __func__, __LINE__);
  2247. goto error;
  2248. }
  2249. /* check there are 20 ones in BKSV */
  2250. if (hdmi_msm_count_one(bksv, 5) != 20) {
  2251. DEV_ERR("HDCP: BKSV read from Sink doesn't have "
  2252. "20 1's and 20 0's, FAIL (BKSV="
  2253. "%02x%02x%02x%02x%02x)\n",
  2254. bksv[4], bksv[3], bksv[2], bksv[1], bksv[0]);
  2255. ret = -EINVAL;
  2256. goto error;
  2257. }
  2258. link0_bksv_0 = bksv[3];
  2259. link0_bksv_0 = (link0_bksv_0 << 8) | bksv[2];
  2260. link0_bksv_0 = (link0_bksv_0 << 8) | bksv[1];
  2261. link0_bksv_0 = (link0_bksv_0 << 8) | bksv[0];
  2262. link0_bksv_1 = bksv[4];
  2263. DEV_DBG("HDCP: BKSV=%02x%08x\n", link0_bksv_1, link0_bksv_0);
  2264. /* 0x0134 HDCP_RCVPORT_DATA0
  2265. [31:0] LINK0_BKSV_0 */
  2266. HDMI_OUTP(0x0134, link0_bksv_0);
  2267. /* 0x0138 HDCP_RCVPORT_DATA1
  2268. [31:0] LINK0_BKSV_1 */
  2269. HDMI_OUTP(0x0138, link0_bksv_1);
  2270. DEV_DBG("HDCP: Link0-BKSV=%02x%08x\n", link0_bksv_1,
  2271. link0_bksv_0);
  2272. /* HDMI_HPD_INT_STATUS[0x0250] */
  2273. hpd_int_status = HDMI_INP_ND(0x0250);
  2274. /* HDMI_HPD_INT_CTRL[0x0254] */
  2275. hpd_int_ctrl = HDMI_INP_ND(0x0254);
  2276. DEV_DBG("[SR-DEUG]: HPD_INTR_CTRL=[%u] HPD_INTR_STATUS=[%u] "
  2277. "before reading R0'\n", hpd_int_ctrl, hpd_int_status);
  2278. /*
  2279. * HDCP Compliace Test case 1B-01:
  2280. * Wait here until all the ksv bytes have been
  2281. * read from the KSV FIFO register.
  2282. */
  2283. msleep(125);
  2284. /* Reading R0' 2 bytes at offset 0x08 */
  2285. ret = hdmi_msm_ddc_read(0x74, 0x08, buf, 2, 5, "RO'", TRUE);
  2286. if (ret) {
  2287. DEV_ERR("%s(%d): Read RO's failed", __func__,
  2288. __LINE__);
  2289. goto error;
  2290. }
  2291. DEV_DBG("HDCP: R0'=%02x%02x\n", buf[1], buf[0]);
  2292. INIT_COMPLETION(hdmi_msm_state->hdcp_success_done);
  2293. /* 0x013C HDCP_RCVPORT_DATA2_0
  2294. [15:0] LINK0_RI */
  2295. HDMI_OUTP(0x013C, (((uint32)buf[1]) << 8) | buf[0]);
  2296. timeout_count = wait_for_completion_interruptible_timeout(
  2297. &hdmi_msm_state->hdcp_success_done, HZ*2);
  2298. if (!timeout_count) {
  2299. ret = -ETIMEDOUT;
  2300. is_match = HDMI_INP(0x011C) & BIT(12);
  2301. DEV_ERR("%s(%d): timedout, Link0=<%s>\n", __func__,
  2302. __LINE__,
  2303. is_match ? "RI_MATCH" : "No RI Match INTR in time");
  2304. if (!is_match)
  2305. goto error;
  2306. }
  2307. /* 0x011C HDCP_LINK0_STATUS
  2308. [12] RI_MATCHES [0] MISMATCH, [1] MATCH
  2309. [0] AUTH_SUCCESS */
  2310. /* Checking for RI, R0 Match */
  2311. /* RI_MATCHES */
  2312. if ((HDMI_INP(0x011C) & BIT(12)) != BIT(12)) {
  2313. ret = -EINVAL;
  2314. DEV_ERR("%s: HDCP_LINK0_STATUS[RI_MATCHES]: MISMATCH\n",
  2315. __func__);
  2316. goto error;
  2317. }
  2318. /* Enable HDCP Encryption */
  2319. HDMI_OUTP(0x0110, BIT(0) | BIT(8));
  2320. DEV_INFO("HDCP: authentication part I, successful\n");
  2321. is_part1_done = FALSE;
  2322. return 0;
  2323. error:
  2324. DEV_ERR("[%s]: HDCP Reauthentication\n", __func__);
  2325. is_part1_done = FALSE;
  2326. return ret;
  2327. } else {
  2328. return 1;
  2329. }
  2330. }
  2331. static int hdmi_msm_transfer_v_h(void)
  2332. {
  2333. /* Read V'.HO 4 Byte at offset 0x20 */
  2334. char what[20];
  2335. int ret;
  2336. uint8 buf[4];
  2337. if (!hdmi_msm_state->hdcp_enable) {
  2338. DEV_DBG("%s: HDCP not enabled\n", __func__);
  2339. return 0;
  2340. }
  2341. snprintf(what, sizeof(what), "V' H0");
  2342. ret = hdmi_msm_ddc_read(0x74, 0x20, buf, 4, 5, what, TRUE);
  2343. if (ret) {
  2344. DEV_ERR("%s: Read %s failed", __func__, what);
  2345. return ret;
  2346. }
  2347. DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
  2348. buf[0] , buf[1] , buf[2] , buf[3]);
  2349. /* 0x0154 HDCP_RCVPORT_DATA7
  2350. [31:0] V_HO */
  2351. HDMI_OUTP(0x0154 ,
  2352. (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
  2353. snprintf(what, sizeof(what), "V' H1");
  2354. ret = hdmi_msm_ddc_read(0x74, 0x24, buf, 4, 5, what, TRUE);
  2355. if (ret) {
  2356. DEV_ERR("%s: Read %s failed", __func__, what);
  2357. return ret;
  2358. }
  2359. DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
  2360. buf[0] , buf[1] , buf[2] , buf[3]);
  2361. /* 0x0158 HDCP_RCVPORT_ DATA8
  2362. [31:0] V_H1 */
  2363. HDMI_OUTP(0x0158,
  2364. (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
  2365. snprintf(what, sizeof(what), "V' H2");
  2366. ret = hdmi_msm_ddc_read(0x74, 0x28, buf, 4, 5, what, TRUE);
  2367. if (ret) {
  2368. DEV_ERR("%s: Read %s failed", __func__, what);
  2369. return ret;
  2370. }
  2371. DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
  2372. buf[0] , buf[1] , buf[2] , buf[3]);
  2373. /* 0x015c HDCP_RCVPORT_DATA9
  2374. [31:0] V_H2 */
  2375. HDMI_OUTP(0x015c ,
  2376. (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
  2377. snprintf(what, sizeof(what), "V' H3");
  2378. ret = hdmi_msm_ddc_read(0x74, 0x2c, buf, 4, 5, what, TRUE);
  2379. if (ret) {
  2380. DEV_ERR("%s: Read %s failed", __func__, what);
  2381. return ret;
  2382. }
  2383. DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
  2384. buf[0] , buf[1] , buf[2] , buf[3]);
  2385. /* 0x0160 HDCP_RCVPORT_DATA10
  2386. [31:0] V_H3 */
  2387. HDMI_OUTP(0x0160,
  2388. (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
  2389. snprintf(what, sizeof(what), "V' H4");
  2390. ret = hdmi_msm_ddc_read(0x74, 0x30, buf, 4, 5, what, TRUE);
  2391. if (ret) {
  2392. DEV_ERR("%s: Read %s failed", __func__, what);
  2393. return ret;
  2394. }
  2395. DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
  2396. buf[0] , buf[1] , buf[2] , buf[3]);
  2397. /* 0x0164 HDCP_RCVPORT_DATA11
  2398. [31:0] V_H4 */
  2399. HDMI_OUTP(0x0164,
  2400. (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
  2401. return 0;
  2402. }
  2403. static int hdcp_authentication_part2(void)
  2404. {
  2405. int ret = 0;
  2406. uint32 timeout_count;
  2407. int i = 0;
  2408. int cnt = 0;
  2409. uint bstatus;
  2410. uint8 bcaps;
  2411. uint32 down_stream_devices;
  2412. uint32 ksv_bytes;
  2413. static uint8 buf[0xFF];
  2414. static uint8 kvs_fifo[5 * 127];
  2415. boolean max_devs_exceeded = 0;
  2416. boolean max_cascade_exceeded = 0;
  2417. boolean ksv_done = FALSE;
  2418. if (!hdmi_msm_state->hdcp_enable) {
  2419. DEV_DBG("%s: HDCP not enabled\n", __func__);
  2420. return 0;
  2421. }
  2422. memset(buf, 0, sizeof(buf));
  2423. memset(kvs_fifo, 0, sizeof(kvs_fifo));
  2424. /* wait until READY bit is set in bcaps */
  2425. timeout_count = 50;
  2426. do {
  2427. timeout_count--;
  2428. /* read bcaps 1 Byte at offset 0x40 */
  2429. ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 1,
  2430. "Bcaps", FALSE);
  2431. if (ret) {
  2432. DEV_ERR("%s(%d): Read Bcaps failed", __func__,
  2433. __LINE__);
  2434. goto error;
  2435. }
  2436. msleep(100);
  2437. } while ((0 == (bcaps & 0x20)) && timeout_count); /* READY (Bit 5) */
  2438. if (!timeout_count) {
  2439. ret = -ETIMEDOUT;
  2440. DEV_ERR("%s:timedout(1)", __func__);
  2441. goto error;
  2442. }
  2443. /* read bstatus 2 bytes at offset 0x41 */
  2444. ret = hdmi_msm_ddc_read(0x74, 0x41, buf, 2, 5, "Bstatus", FALSE);
  2445. if (ret) {
  2446. DEV_ERR("%s(%d): Read Bstatus failed", __func__, __LINE__);
  2447. goto error;
  2448. }
  2449. bstatus = buf[1];
  2450. bstatus = (bstatus << 8) | buf[0];
  2451. /* 0x0168 DCP_RCVPORT_DATA12
  2452. [7:0] BCAPS
  2453. [23:8 BSTATUS */
  2454. HDMI_OUTP(0x0168, bcaps | (bstatus << 8));
  2455. /* BSTATUS [6:0] DEVICE_COUNT Number of HDMI device attached to repeater
  2456. * - see HDCP spec */
  2457. down_stream_devices = bstatus & 0x7F;
  2458. if (down_stream_devices == 0x0) {
  2459. /* There isn't any devices attaced to the Repeater */
  2460. DEV_ERR("%s: there isn't any devices attached to the "
  2461. "Repeater\n", __func__);
  2462. ret = -EINVAL;
  2463. goto error;
  2464. }
  2465. /*
  2466. * HDCP Compliance 1B-05:
  2467. * Check if no. of devices connected to repeater
  2468. * exceed max_devices_connected from bit 7 of Bstatus.
  2469. */
  2470. max_devs_exceeded = (bstatus & 0x80) >> 7;
  2471. if (max_devs_exceeded == 0x01) {
  2472. DEV_ERR("%s: Number of devs connected to repeater "
  2473. "exceeds max_devs\n", __func__);
  2474. ret = -EINVAL;
  2475. goto hdcp_error;
  2476. }
  2477. /*
  2478. * HDCP Compliance 1B-06:
  2479. * Check if no. of cascade connected to repeater
  2480. * exceed max_cascade_connected from bit 11 of Bstatus.
  2481. */
  2482. max_cascade_exceeded = (bstatus & 0x800) >> 11;
  2483. if (max_cascade_exceeded == 0x01) {
  2484. DEV_ERR("%s: Number of cascade connected to repeater "
  2485. "exceeds max_cascade\n", __func__);
  2486. ret = -EINVAL;
  2487. goto hdcp_error;
  2488. }
  2489. /* Read KSV FIFO over DDC
  2490. * Key Slection vector FIFO
  2491. * Used to pull downstream KSVs from HDCP Repeaters.
  2492. * All bytes (DEVICE_COUNT * 5) must be read in a single,
  2493. * auto incrementing access.
  2494. * All bytes read as 0x00 for HDCP Receivers that are not
  2495. * HDCP Repeaters (REPEATER == 0). */
  2496. ksv_bytes = 5 * down_stream_devices;
  2497. /* Reading KSV FIFO / KSV FIFO */
  2498. ksv_done = FALSE;
  2499. ret = hdmi_msm_ddc_read(0x74, 0x43, kvs_fifo, ksv_bytes, 5,
  2500. "KSV FIFO", TRUE);
  2501. do {
  2502. if (ret) {
  2503. DEV_ERR("%s(%d): Read KSV FIFO failed",
  2504. __func__, __LINE__);
  2505. /*
  2506. * HDCP Compliace Test case 1B-01:
  2507. * Wait here until all the ksv bytes have been
  2508. * read from the KSV FIFO register.
  2509. */
  2510. msleep(25);
  2511. } else {
  2512. ksv_done = TRUE;
  2513. }
  2514. cnt++;
  2515. } while (!ksv_done && cnt != 20);
  2516. if (ksv_done == FALSE)
  2517. goto error;
  2518. ret = hdmi_msm_transfer_v_h();
  2519. if (ret)
  2520. goto error;
  2521. /* Next: Write KSV FIFO to HDCP_SHA_DATA.
  2522. * This is done 1 byte at time starting with the LSB.
  2523. * On the very last byte write,
  2524. * the HDCP_SHA_DATA_DONE bit[0]
  2525. */
  2526. /* 0x023C HDCP_SHA_CTRL
  2527. [0] RESET [0] Enable, [1] Reset
  2528. [4] SELECT [0] DIGA_HDCP, [1] DIGB_HDCP */
  2529. /* reset SHA engine */
  2530. HDMI_OUTP(0x023C, 1);
  2531. /* enable SHA engine, SEL=DIGA_HDCP */
  2532. HDMI_OUTP(0x023C, 0);
  2533. for (i = 0; i < ksv_bytes - 1; i++) {
  2534. /* Write KSV byte and do not set DONE bit[0] */
  2535. HDMI_OUTP_ND(0x0244, kvs_fifo[i] << 16);
  2536. /* Once 64 bytes have been written, we need to poll for
  2537. * HDCP_SHA_BLOCK_DONE before writing any further
  2538. */
  2539. if (i && !((i+1)%64)) {
  2540. timeout_count = 100;
  2541. while (!(HDMI_INP_ND(0x0240) & 0x1)
  2542. && (--timeout_count)) {
  2543. DEV_DBG("HDCP Auth Part II: Waiting for the "
  2544. "computation of the current 64 byte to "
  2545. "complete. HDCP_SHA_STATUS=%08x. "
  2546. "timeout_count=%d\n",
  2547. HDMI_INP_ND(0x0240), timeout_count);
  2548. msleep(20);
  2549. }
  2550. if (!timeout_count) {
  2551. ret = -ETIMEDOUT;
  2552. DEV_ERR("%s(%d): timedout", __func__, __LINE__);
  2553. goto error;
  2554. }
  2555. }
  2556. }
  2557. /* Write l to DONE bit[0] */
  2558. HDMI_OUTP_ND(0x0244, (kvs_fifo[ksv_bytes - 1] << 16) | 0x1);
  2559. /* 0x0240 HDCP_SHA_STATUS
  2560. [4] COMP_DONE */
  2561. /* Now wait for HDCP_SHA_COMP_DONE */
  2562. timeout_count = 100;
  2563. while ((0x10 != (HDMI_INP_ND(0x0240) & 0xFFFFFF10)) && --timeout_count)
  2564. msleep(20);
  2565. if (!timeout_count) {
  2566. ret = -ETIMEDOUT;
  2567. DEV_ERR("%s(%d): timedout", __func__, __LINE__);
  2568. goto error;
  2569. }
  2570. /* 0x011C HDCP_LINK0_STATUS
  2571. [20] V_MATCHES */
  2572. timeout_count = 100;
  2573. while (((HDMI_INP_ND(0x011C) & (1 << 20)) != (1 << 20))
  2574. && --timeout_count) {
  2575. msleep(20);
  2576. }
  2577. if (!timeout_count) {
  2578. ret = -ETIMEDOUT;
  2579. DEV_ERR("%s(%d): timedout", __func__, __LINE__);
  2580. goto error;
  2581. }
  2582. DEV_INFO("HDCP: authentication part II, successful\n");
  2583. hdcp_error:
  2584. error:
  2585. return ret;
  2586. }
  2587. static int hdcp_authentication_part3(uint32 found_repeater)
  2588. {
  2589. int ret = 0;
  2590. int poll = 3000;
  2591. if (!hdmi_msm_state->hdcp_enable) {
  2592. DEV_DBG("%s: HDCP not enabled\n", __func__);
  2593. return 0;
  2594. }
  2595. while (poll) {
  2596. /* 0x011C HDCP_LINK0_STATUS
  2597. [30:28] KEYS_STATE = 3 = "Valid"
  2598. [24] RO_COMPUTATION_DONE [0] Not Done, [1] Done
  2599. [20] V_MATCHES [0] Mismtach, [1] Match
  2600. [12] RI_MATCHES [0] Mismatch, [1] Match
  2601. [0] AUTH_SUCCESS */
  2602. if (HDMI_INP_ND(0x011C) != (0x31001001 |
  2603. (found_repeater << 20))) {
  2604. DEV_ERR("HDCP: autentication part III, FAILED, "
  2605. "Link Status=%08x\n", HDMI_INP(0x011C));
  2606. ret = -EINVAL;
  2607. goto error;
  2608. }
  2609. poll--;
  2610. }
  2611. DEV_INFO("HDCP: authentication part III, successful\n");
  2612. error:
  2613. return ret;
  2614. }
  2615. static void hdmi_msm_hdcp_enable(void)
  2616. {
  2617. int ret = 0;
  2618. uint8 bcaps;
  2619. uint32 found_repeater = 0x0;
  2620. char *envp[2];
  2621. if (!hdmi_msm_state->hdcp_enable) {
  2622. DEV_INFO("%s: HDCP NOT ENABLED\n", __func__);
  2623. return;
  2624. }
  2625. mutex_lock(&hdmi_msm_state_mutex);
  2626. hdmi_msm_state->hdcp_activating = TRUE;
  2627. mutex_unlock(&hdmi_msm_state_mutex);
  2628. mutex_lock(&hdcp_auth_state_mutex);
  2629. /* This flag prevents other threads from re-authenticating
  2630. * after we've just authenticated (i.e., finished part3)
  2631. * We probably need to protect this in a mutex lock */
  2632. hdmi_msm_state->full_auth_done = FALSE;
  2633. mutex_unlock(&hdcp_auth_state_mutex);
  2634. /* Disable HDCP before we start part1 */
  2635. HDMI_OUTP(0x0110, 0x0);
  2636. /* PART I Authentication*/
  2637. ret = hdcp_authentication_part1();
  2638. if (ret)
  2639. goto error;
  2640. /* PART II Authentication*/
  2641. /* read Bcaps at 0x40 in HDCP Port */
  2642. ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 5, "Bcaps", FALSE);
  2643. if (ret) {
  2644. DEV_ERR("%s(%d): Read Bcaps failed\n", __func__, __LINE__);
  2645. goto error;
  2646. }
  2647. DEV_DBG("HDCP: Bcaps=0x%02x (%s)\n", bcaps,
  2648. (bcaps & BIT(6)) ? "repeater" : "no repeater");
  2649. /* if REPEATER (Bit 6), perform Part2 Authentication */
  2650. if (bcaps & BIT(6)) {
  2651. found_repeater = 0x1;
  2652. ret = hdcp_authentication_part2();
  2653. if (ret)
  2654. goto error;
  2655. } else
  2656. DEV_INFO("HDCP: authentication part II skipped, no repeater\n");
  2657. /* PART III Authentication*/
  2658. ret = hdcp_authentication_part3(found_repeater);
  2659. if (ret)
  2660. goto error;
  2661. mutex_lock(&hdmi_msm_state_mutex);
  2662. hdmi_msm_state->hdcp_activating = FALSE;
  2663. mutex_unlock(&hdmi_msm_state_mutex);
  2664. mutex_lock(&hdcp_auth_state_mutex);
  2665. /*
  2666. * This flag prevents other threads from re-authenticating
  2667. * after we've just authenticated (i.e., finished part3)
  2668. */
  2669. hdmi_msm_state->full_auth_done = TRUE;
  2670. external_common_state->hdcp_active = TRUE;
  2671. mutex_unlock(&hdcp_auth_state_mutex);
  2672. if (!hdmi_msm_is_dvi_mode()) {
  2673. DEV_INFO("HDMI HPD: sense : send HDCP_PASS\n");
  2674. envp[0] = "HDCP_STATE=PASS";
  2675. envp[1] = NULL;
  2676. kobject_uevent_env(external_common_state->uevent_kobj,
  2677. KOBJ_CHANGE, envp);
  2678. SWITCH_SET_HDMI_AUDIO(1, 0);
  2679. }
  2680. return;
  2681. error:
  2682. if (hdmi_msm_state->hpd_during_auth) {
  2683. DEV_WARN("Calling Deauthentication: HPD occured during "
  2684. "authentication from [%s]\n", __func__);
  2685. hdcp_deauthenticate();
  2686. mutex_lock(&hdcp_auth_state_mutex);
  2687. hdmi_msm_state->hpd_during_auth = FALSE;
  2688. mutex_unlock(&hdcp_auth_state_mutex);
  2689. } else {
  2690. DEV_WARN("[DEV_DBG]: Calling reauth from [%s]\n", __func__);
  2691. if (hdmi_msm_state->panel_power_on)
  2692. queue_work(hdmi_work_queue,
  2693. &hdmi_msm_state->hdcp_reauth_work);
  2694. }
  2695. mutex_lock(&hdmi_msm_state_mutex);
  2696. hdmi_msm_state->hdcp_activating = FALSE;
  2697. mutex_unlock(&hdmi_msm_state_mutex);
  2698. }
  2699. static void hdmi_msm_video_setup(int video_format)
  2700. {
  2701. uint32 total_v = 0;
  2702. uint32 total_h = 0;
  2703. uint32 start_h = 0;
  2704. uint32 end_h = 0;
  2705. uint32 start_v = 0;
  2706. uint32 end_v = 0;
  2707. const struct hdmi_disp_mode_timing_type *timing =
  2708. hdmi_common_get_supported_mode(video_format);
  2709. /* timing register setup */
  2710. if (timing == NULL) {
  2711. DEV_ERR("video format not supported: %d\n", video_format);
  2712. return;
  2713. }
  2714. /* Hsync Total and Vsync Total */
  2715. total_h = timing->active_h + timing->front_porch_h
  2716. + timing->back_porch_h + timing->pulse_width_h - 1;
  2717. total_v = timing->active_v + timing->front_porch_v
  2718. + timing->back_porch_v + timing->pulse_width_v - 1;
  2719. /* 0x02C0 HDMI_TOTAL
  2720. [27:16] V_TOTAL Vertical Total
  2721. [11:0] H_TOTAL Horizontal Total */
  2722. HDMI_OUTP(0x02C0, ((total_v << 16) & 0x0FFF0000)
  2723. | ((total_h << 0) & 0x00000FFF));
  2724. /* Hsync Start and Hsync End */
  2725. start_h = timing->back_porch_h + timing->pulse_width_h;
  2726. end_h = (total_h + 1) - timing->front_porch_h;
  2727. /* 0x02B4 HDMI_ACTIVE_H
  2728. [27:16] END Horizontal end
  2729. [11:0] START Horizontal start */
  2730. HDMI_OUTP(0x02B4, ((end_h << 16) & 0x0FFF0000)
  2731. | ((start_h << 0) & 0x00000FFF));
  2732. start_v = timing->back_porch_v + timing->pulse_width_v - 1;
  2733. end_v = total_v - timing->front_porch_v;
  2734. /* 0x02B8 HDMI_ACTIVE_V
  2735. [27:16] END Vertical end
  2736. [11:0] START Vertical start */
  2737. HDMI_OUTP(0x02B8, ((end_v << 16) & 0x0FFF0000)
  2738. | ((start_v << 0) & 0x00000FFF));
  2739. if (timing->interlaced) {
  2740. /* 0x02C4 HDMI_V_TOTAL_F2
  2741. [11:0] V_TOTAL_F2 Vertical total for field2 */
  2742. HDMI_OUTP(0x02C4, ((total_v + 1) << 0) & 0x00000FFF);
  2743. /* 0x02BC HDMI_ACTIVE_V_F2
  2744. [27:16] END_F2 Vertical end for field2
  2745. [11:0] START_F2 Vertical start for Field2 */
  2746. HDMI_OUTP(0x02BC,
  2747. (((start_v + 1) << 0) & 0x00000FFF)
  2748. | (((end_v + 1) << 16) & 0x0FFF0000));
  2749. } else {
  2750. /* HDMI_V_TOTAL_F2 */
  2751. HDMI_OUTP(0x02C4, 0);
  2752. /* HDMI_ACTIVE_V_F2 */
  2753. HDMI_OUTP(0x02BC, 0);
  2754. }
  2755. hdmi_frame_ctrl_cfg(timing);
  2756. }
  2757. struct hdmi_msm_audio_acr {
  2758. uint32 n; /* N parameter for clock regeneration */
  2759. uint32 cts; /* CTS parameter for clock regeneration */
  2760. };
  2761. struct hdmi_msm_audio_arcs {
  2762. uint32 pclk;
  2763. struct hdmi_msm_audio_acr lut[MSM_HDMI_SAMPLE_RATE_MAX];
  2764. };
  2765. #define HDMI_MSM_AUDIO_ARCS(pclk, ...) { pclk, __VA_ARGS__ }
  2766. /* Audio constants lookup table for hdmi_msm_audio_acr_setup */
  2767. /* Valid Pixel-Clock rates: 25.2MHz, 27MHz, 27.03MHz, 74.25MHz, 148.5MHz */
  2768. static const struct hdmi_msm_audio_arcs hdmi_msm_audio_acr_lut[] = {
  2769. /* 25.200MHz */
  2770. HDMI_MSM_AUDIO_ARCS(25200, {
  2771. {4096, 25200}, {6272, 28000}, {6144, 25200}, {12544, 28000},
  2772. {12288, 25200}, {25088, 28000}, {24576, 25200} }),
  2773. /* 27.000MHz */
  2774. HDMI_MSM_AUDIO_ARCS(27000, {
  2775. {4096, 27000}, {6272, 30000}, {6144, 27000}, {12544, 30000},
  2776. {12288, 27000}, {25088, 30000}, {24576, 27000} }),
  2777. /* 27.027MHz */
  2778. HDMI_MSM_AUDIO_ARCS(27030, {
  2779. {4096, 27027}, {6272, 30030}, {6144, 27027}, {12544, 30030},
  2780. {12288, 27027}, {25088, 30030}, {24576, 27027} }),
  2781. /* 74.250MHz */
  2782. HDMI_MSM_AUDIO_ARCS(74250, {
  2783. {4096, 74250}, {6272, 82500}, {6144, 74250}, {12544, 82500},
  2784. {12288, 74250}, {25088, 82500}, {24576, 74250} }),
  2785. /* 148.500MHz */
  2786. HDMI_MSM_AUDIO_ARCS(148500, {
  2787. {4096, 148500}, {6272, 165000}, {6144, 148500}, {12544, 165000},
  2788. {12288, 148500}, {25088, 165000}, {24576, 148500} }),
  2789. };
  2790. static void hdmi_msm_audio_acr_setup(boolean enabled, int video_format,
  2791. int audio_sample_rate, int num_of_channels)
  2792. {
  2793. /* Read first before writing */
  2794. /* HDMI_ACR_PKT_CTRL[0x0024] */
  2795. uint32 acr_pck_ctrl_reg = HDMI_INP(0x0024);
  2796. /* Clear N/CTS selection bits */
  2797. acr_pck_ctrl_reg &= ~(3 << 4);
  2798. if (enabled) {
  2799. const struct hdmi_disp_mode_timing_type *timing =
  2800. hdmi_common_get_supported_mode(video_format);
  2801. const struct hdmi_msm_audio_arcs *audio_arc =
  2802. &hdmi_msm_audio_acr_lut[0];
  2803. const int lut_size = sizeof(hdmi_msm_audio_acr_lut)
  2804. /sizeof(*hdmi_msm_audio_acr_lut);
  2805. uint32 i, n, cts, layout, multiplier, aud_pck_ctrl_2_reg;
  2806. if (timing == NULL) {
  2807. DEV_WARN("%s: video format %d not supported\n",
  2808. __func__, video_format);
  2809. return;
  2810. }
  2811. for (i = 0; i < lut_size;
  2812. audio_arc = &hdmi_msm_audio_acr_lut[++i]) {
  2813. if (audio_arc->pclk == timing->pixel_freq)
  2814. break;
  2815. }
  2816. if (i >= lut_size) {
  2817. DEV_WARN("%s: pixel clock %d not supported\n", __func__,
  2818. timing->pixel_freq);
  2819. return;
  2820. }
  2821. n = audio_arc->lut[audio_sample_rate].n;
  2822. cts = audio_arc->lut[audio_sample_rate].cts;
  2823. layout = (MSM_HDMI_AUDIO_CHANNEL_2 == num_of_channels) ? 0 : 1;
  2824. if ((MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate) ||
  2825. (MSM_HDMI_SAMPLE_RATE_176_4KHZ == audio_sample_rate)) {
  2826. multiplier = 4;
  2827. n >>= 2; /* divide N by 4 and use multiplier */
  2828. } else if ((MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) ||
  2829. (MSM_HDMI_SAMPLE_RATE_88_2KHZ == audio_sample_rate)) {
  2830. multiplier = 2;
  2831. n >>= 1; /* divide N by 2 and use multiplier */
  2832. } else {
  2833. multiplier = 1;
  2834. }
  2835. DEV_DBG("%s: n=%u, cts=%u, layout=%u\n", __func__, n, cts,
  2836. layout);
  2837. /* AUDIO_PRIORITY | SOURCE */
  2838. acr_pck_ctrl_reg |= 0x80000100;
  2839. /* N_MULTIPLE(multiplier) */
  2840. acr_pck_ctrl_reg |= (multiplier & 7) << 16;
  2841. if ((MSM_HDMI_SAMPLE_RATE_48KHZ == audio_sample_rate) ||
  2842. (MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) ||
  2843. (MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate)) {
  2844. /* SELECT(3) */
  2845. acr_pck_ctrl_reg |= 3 << 4;
  2846. /* CTS_48 */
  2847. cts <<= 12;
  2848. /* CTS: need to determine how many fractional bits */
  2849. /* HDMI_ACR_48_0 */
  2850. HDMI_OUTP(0x00D4, cts);
  2851. /* N */
  2852. /* HDMI_ACR_48_1 */
  2853. HDMI_OUTP(0x00D8, n);
  2854. } else if ((MSM_HDMI_SAMPLE_RATE_44_1KHZ == audio_sample_rate)
  2855. || (MSM_HDMI_SAMPLE_RATE_88_2KHZ ==
  2856. audio_sample_rate)
  2857. || (MSM_HDMI_SAMPLE_RATE_176_4KHZ ==
  2858. audio_sample_rate)) {
  2859. /* SELECT(2) */
  2860. acr_pck_ctrl_reg |= 2 << 4;
  2861. /* CTS_44 */
  2862. cts <<= 12;
  2863. /* CTS: need to determine how many fractional bits */
  2864. /* HDMI_ACR_44_0 */
  2865. HDMI_OUTP(0x00CC, cts);
  2866. /* N */
  2867. /* HDMI_ACR_44_1 */
  2868. HDMI_OUTP(0x00D0, n);
  2869. } else { /* default to 32k */
  2870. /* SELECT(1) */
  2871. acr_pck_ctrl_reg |= 1 << 4;
  2872. /* CTS_32 */
  2873. cts <<= 12;
  2874. /* CTS: need to determine how many fractional bits */
  2875. /* HDMI_ACR_32_0 */
  2876. HDMI_OUTP(0x00C4, cts);
  2877. /* N */
  2878. /* HDMI_ACR_32_1 */
  2879. HDMI_OUTP(0x00C8, n);
  2880. }
  2881. /* Payload layout depends on number of audio channels */
  2882. /* LAYOUT_SEL(layout) */
  2883. aud_pck_ctrl_2_reg = 1 | (layout << 1);
  2884. /* override | layout */
  2885. /* HDMI_AUDIO_PKT_CTRL2[0x00044] */
  2886. HDMI_OUTP(0x00044, aud_pck_ctrl_2_reg);
  2887. /* SEND | CONT */
  2888. acr_pck_ctrl_reg |= 0x00000003;
  2889. } else {
  2890. /* ~(SEND | CONT) */
  2891. acr_pck_ctrl_reg &= ~0x00000003;
  2892. }
  2893. /* HDMI_ACR_PKT_CTRL[0x0024] */
  2894. HDMI_OUTP(0x0024, acr_pck_ctrl_reg);
  2895. }
  2896. static void hdmi_msm_outpdw_chk(uint32 offset, uint32 data)
  2897. {
  2898. uint32 check, i = 0;
  2899. #ifdef DEBUG
  2900. HDMI_OUTP(offset, data);
  2901. #endif
  2902. do {
  2903. outpdw(MSM_HDMI_BASE+offset, data);
  2904. check = inpdw(MSM_HDMI_BASE+offset);
  2905. } while (check != data && i++ < 10);
  2906. if (check != data)
  2907. DEV_ERR("%s: failed addr=%08x, data=%x, check=%x",
  2908. __func__, offset, data, check);
  2909. }
  2910. static void hdmi_msm_rmw32or(uint32 offset, uint32 data)
  2911. {
  2912. uint32 reg_data;
  2913. reg_data = inpdw(MSM_HDMI_BASE+offset);
  2914. reg_data = inpdw(MSM_HDMI_BASE+offset);
  2915. hdmi_msm_outpdw_chk(offset, reg_data | data);
  2916. }
  2917. #define HDMI_AUDIO_CFG 0x01D0
  2918. #define HDMI_AUDIO_ENGINE_ENABLE 1
  2919. #define HDMI_AUDIO_FIFO_MASK 0x000000F0
  2920. #define HDMI_AUDIO_FIFO_WATERMARK_SHIFT 4
  2921. #define HDMI_AUDIO_FIFO_MAX_WATER_MARK 8
  2922. int hdmi_audio_enable(bool on , u32 fifo_water_mark)
  2923. {
  2924. u32 hdmi_audio_config;
  2925. hdmi_audio_config = HDMI_INP(HDMI_AUDIO_CFG);
  2926. if (on) {
  2927. if (fifo_water_mark > HDMI_AUDIO_FIFO_MAX_WATER_MARK) {
  2928. pr_err("%s : HDMI audio fifo water mark can not be more"
  2929. " than %u\n", __func__,
  2930. HDMI_AUDIO_FIFO_MAX_WATER_MARK);
  2931. return -EINVAL;
  2932. }
  2933. /*
  2934. * Enable HDMI Audio engine.
  2935. * MUST be enabled after Audio DMA is enabled.
  2936. */
  2937. hdmi_audio_config &= ~(HDMI_AUDIO_FIFO_MASK);
  2938. hdmi_audio_config |= (HDMI_AUDIO_ENGINE_ENABLE |
  2939. (fifo_water_mark << HDMI_AUDIO_FIFO_WATERMARK_SHIFT));
  2940. } else
  2941. hdmi_audio_config &= ~(HDMI_AUDIO_ENGINE_ENABLE);
  2942. HDMI_OUTP(HDMI_AUDIO_CFG, hdmi_audio_config);
  2943. mb();
  2944. pr_info("%s :HDMI_AUDIO_CFG 0x%08x\n", __func__,
  2945. HDMI_INP(HDMI_AUDIO_CFG));
  2946. return 0;
  2947. }
  2948. EXPORT_SYMBOL(hdmi_audio_enable);
  2949. #define HDMI_AUDIO_PKT_CTRL 0x0020
  2950. #define HDMI_AUDIO_SAMPLE_SEND_ENABLE 1
  2951. int hdmi_audio_packet_enable(bool on)
  2952. {
  2953. u32 hdmi_audio_pkt_ctrl;
  2954. hdmi_audio_pkt_ctrl = HDMI_INP(HDMI_AUDIO_PKT_CTRL);
  2955. if (on)
  2956. hdmi_audio_pkt_ctrl |= HDMI_AUDIO_SAMPLE_SEND_ENABLE;
  2957. else
  2958. hdmi_audio_pkt_ctrl &= ~(HDMI_AUDIO_SAMPLE_SEND_ENABLE);
  2959. HDMI_OUTP(HDMI_AUDIO_PKT_CTRL, hdmi_audio_pkt_ctrl);
  2960. mb();
  2961. pr_info("%s : HDMI_AUDIO_PKT_CTRL 0x%08x\n", __func__,
  2962. HDMI_INP(HDMI_AUDIO_PKT_CTRL));
  2963. return 0;
  2964. }
  2965. EXPORT_SYMBOL(hdmi_audio_packet_enable);
  2966. /* TO-DO: return -EINVAL when num_of_channels and channel_allocation
  2967. * does not match CEA 861-D spec.
  2968. */
  2969. int hdmi_msm_audio_info_setup(bool enabled, u32 num_of_channels,
  2970. u32 channel_allocation, u32 level_shift, bool down_mix)
  2971. {
  2972. uint32 channel_count = 1; /* Default to 2 channels
  2973. -> See Table 17 in CEA-D spec */
  2974. uint32 check_sum, audio_info_0_reg, audio_info_1_reg;
  2975. uint32 audio_info_ctrl_reg;
  2976. u32 aud_pck_ctrl_2_reg;
  2977. u32 layout;
  2978. layout = (MSM_HDMI_AUDIO_CHANNEL_2 == num_of_channels) ? 0 : 1;
  2979. aud_pck_ctrl_2_reg = 1 | (layout << 1);
  2980. HDMI_OUTP(0x00044, aud_pck_ctrl_2_reg);
  2981. /* Please see table 20 Audio InfoFrame in HDMI spec
  2982. FL = front left
  2983. FC = front Center
  2984. FR = front right
  2985. FLC = front left center
  2986. FRC = front right center
  2987. RL = rear left
  2988. RC = rear center
  2989. RR = rear right
  2990. RLC = rear left center
  2991. RRC = rear right center
  2992. LFE = low frequency effect
  2993. */
  2994. /* Read first then write because it is bundled with other controls */
  2995. /* HDMI_INFOFRAME_CTRL0[0x002C] */
  2996. audio_info_ctrl_reg = HDMI_INP(0x002C);
  2997. if (enabled) {
  2998. switch (num_of_channels) {
  2999. case MSM_HDMI_AUDIO_CHANNEL_2:
  3000. channel_allocation = 0; /* Default to FR,FL */
  3001. break;
  3002. case MSM_HDMI_AUDIO_CHANNEL_4:
  3003. channel_count = 3;
  3004. /* FC,LFE,FR,FL */
  3005. channel_allocation = 0x3;
  3006. break;
  3007. case MSM_HDMI_AUDIO_CHANNEL_6:
  3008. channel_count = 5;
  3009. /* RR,RL,FC,LFE,FR,FL */
  3010. channel_allocation = 0xB;
  3011. break;
  3012. case MSM_HDMI_AUDIO_CHANNEL_8:
  3013. channel_count = 7;
  3014. /* FRC,FLC,RR,RL,FC,LFE,FR,FL */
  3015. channel_allocation = 0x1f;
  3016. break;
  3017. default:
  3018. pr_err("%s(): Unsupported num_of_channels = %u\n",
  3019. __func__, num_of_channels);
  3020. return -EINVAL;
  3021. break;
  3022. }
  3023. /* Program the Channel-Speaker allocation */
  3024. audio_info_1_reg = 0;
  3025. /* CA(channel_allocation) */
  3026. audio_info_1_reg |= channel_allocation & 0xff;
  3027. /* Program the Level shifter */
  3028. /* LSV(level_shift) */
  3029. audio_info_1_reg |= (level_shift << 11) & 0x00007800;
  3030. /* Program the Down-mix Inhibit Flag */
  3031. /* DM_INH(down_mix) */
  3032. audio_info_1_reg |= (down_mix << 15) & 0x00008000;
  3033. /* HDMI_AUDIO_INFO1[0x00E8] */
  3034. HDMI_OUTP(0x00E8, audio_info_1_reg);
  3035. /* Calculate CheckSum
  3036. Sum of all the bytes in the Audio Info Packet bytes
  3037. (See table 8.4 in HDMI spec) */
  3038. check_sum = 0;
  3039. /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_TYPE[0x84] */
  3040. check_sum += 0x84;
  3041. /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_VERSION[0x01] */
  3042. check_sum += 1;
  3043. /* HDMI_AUDIO_INFO_FRAME_PACKET_LENGTH[0x0A] */
  3044. check_sum += 0x0A;
  3045. check_sum += channel_count;
  3046. check_sum += channel_allocation;
  3047. /* See Table 8.5 in HDMI spec */
  3048. check_sum += (level_shift & 0xF) << 3 | (down_mix & 0x1) << 7;
  3049. check_sum &= 0xFF;
  3050. check_sum = (uint8) (256 - check_sum);
  3051. audio_info_0_reg = 0;
  3052. /* CHECKSUM(check_sum) */
  3053. audio_info_0_reg |= check_sum & 0xff;
  3054. /* CC(channel_count) */
  3055. audio_info_0_reg |= (channel_count << 8) & 0x00000700;
  3056. /* HDMI_AUDIO_INFO0[0x00E4] */
  3057. HDMI_OUTP(0x00E4, audio_info_0_reg);
  3058. /* Set these flags */
  3059. /* AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
  3060. | AUDIO_INFO_SEND */
  3061. audio_info_ctrl_reg |= 0x000000F0;
  3062. } else {
  3063. /* Clear these flags */
  3064. /* ~(AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
  3065. | AUDIO_INFO_SEND) */
  3066. audio_info_ctrl_reg &= ~0x000000F0;
  3067. }
  3068. /* HDMI_INFOFRAME_CTRL0[0x002C] */
  3069. HDMI_OUTP(0x002C, audio_info_ctrl_reg);
  3070. hdmi_msm_dump_regs("HDMI-AUDIO-ON: ");
  3071. return 0;
  3072. }
  3073. EXPORT_SYMBOL(hdmi_msm_audio_info_setup);
  3074. static void hdmi_msm_en_gc_packet(boolean av_mute_is_requested)
  3075. {
  3076. /* HDMI_GC[0x0040] */
  3077. HDMI_OUTP(0x0040, av_mute_is_requested ? 1 : 0);
  3078. /* GC packet enable (every frame) */
  3079. /* HDMI_VBI_PKT_CTRL[0x0028] */
  3080. hdmi_msm_rmw32or(0x0028, 3 << 4);
  3081. }
  3082. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
  3083. static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
  3084. {
  3085. static const char isrc_psuedo_data[] =
  3086. "ISRC1:0123456789isrc2=ABCDEFGHIJ";
  3087. const uint32 * isrc_data = (const uint32 *) isrc_psuedo_data;
  3088. /* ISRC_STATUS =0b010 | ISRC_CONTINUE | ISRC_VALID */
  3089. /* HDMI_ISRC1_0[0x00048] */
  3090. HDMI_OUTP(0x00048, 2 | (isrc_is_continued ? 1 : 0) << 6 | 0 << 7);
  3091. /* HDMI_ISRC1_1[0x004C] */
  3092. HDMI_OUTP(0x004C, *isrc_data++);
  3093. /* HDMI_ISRC1_2[0x0050] */
  3094. HDMI_OUTP(0x0050, *isrc_data++);
  3095. /* HDMI_ISRC1_3[0x0054] */
  3096. HDMI_OUTP(0x0054, *isrc_data++);
  3097. /* HDMI_ISRC1_4[0x0058] */
  3098. HDMI_OUTP(0x0058, *isrc_data++);
  3099. /* HDMI_ISRC2_0[0x005C] */
  3100. HDMI_OUTP(0x005C, *isrc_data++);
  3101. /* HDMI_ISRC2_1[0x0060] */
  3102. HDMI_OUTP(0x0060, *isrc_data++);
  3103. /* HDMI_ISRC2_2[0x0064] */
  3104. HDMI_OUTP(0x0064, *isrc_data++);
  3105. /* HDMI_ISRC2_3[0x0068] */
  3106. HDMI_OUTP(0x0068, *isrc_data);
  3107. /* HDMI_VBI_PKT_CTRL[0x0028] */
  3108. /* ISRC Send + Continuous */
  3109. hdmi_msm_rmw32or(0x0028, 3 << 8);
  3110. }
  3111. #else
  3112. static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
  3113. {
  3114. /*
  3115. * Until end-to-end support for various audio packets
  3116. */
  3117. }
  3118. #endif
  3119. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
  3120. static void hdmi_msm_en_acp_packet(uint32 byte1)
  3121. {
  3122. /* HDMI_ACP[0x003C] */
  3123. HDMI_OUTP(0x003C, 2 | 1 << 8 | byte1 << 16);
  3124. /* HDMI_VBI_PKT_CTRL[0x0028] */
  3125. /* ACP send, s/w source */
  3126. hdmi_msm_rmw32or(0x0028, 3 << 12);
  3127. }
  3128. #else
  3129. static void hdmi_msm_en_acp_packet(uint32 byte1)
  3130. {
  3131. /*
  3132. * Until end-to-end support for various audio packets
  3133. */
  3134. }
  3135. #endif
  3136. int hdmi_msm_audio_get_sample_rate(void)
  3137. {
  3138. return msm_hdmi_sample_rate;
  3139. }
  3140. EXPORT_SYMBOL(hdmi_msm_audio_get_sample_rate);
  3141. void hdmi_msm_audio_sample_rate_reset(int rate)
  3142. {
  3143. if (msm_hdmi_sample_rate == rate)
  3144. return;
  3145. msm_hdmi_sample_rate = rate;
  3146. if (hdmi_msm_state->hdcp_enable)
  3147. hdcp_deauthenticate();
  3148. else
  3149. hdmi_msm_turn_on();
  3150. }
  3151. EXPORT_SYMBOL(hdmi_msm_audio_sample_rate_reset);
  3152. static void hdmi_msm_audio_setup(void)
  3153. {
  3154. const int channels = MSM_HDMI_AUDIO_CHANNEL_2;
  3155. /* (0) for clr_avmute, (1) for set_avmute */
  3156. hdmi_msm_en_gc_packet(0);
  3157. /* (0) for isrc1 only, (1) for isrc1 and isrc2 */
  3158. hdmi_msm_en_isrc_packet(1);
  3159. /* arbitrary bit pattern for byte1 */
  3160. hdmi_msm_en_acp_packet(0x5a);
  3161. DEV_DBG("Not setting ACP, ISRC1, ISRC2 packets\n");
  3162. hdmi_msm_audio_acr_setup(TRUE,
  3163. external_common_state->video_resolution,
  3164. msm_hdmi_sample_rate, channels);
  3165. hdmi_msm_audio_info_setup(TRUE, channels, 0, 0, FALSE);
  3166. /* Turn on Audio FIFO and SAM DROP ISR */
  3167. HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) | BIT(1) | BIT(3));
  3168. DEV_INFO("HDMI Audio: Enabled\n");
  3169. }
  3170. static int hdmi_msm_audio_off(void)
  3171. {
  3172. uint32 audio_cfg;
  3173. int i, timeout_val = 50;
  3174. for (i = 0; (i < timeout_val) &&
  3175. ((audio_cfg = HDMI_INP_ND(0x01D0)) & BIT(0)); i++) {
  3176. DEV_DBG("%s: %d times: AUDIO CFG is %08xi\n", __func__,
  3177. i+1, audio_cfg);
  3178. if (!((i+1) % 10)) {
  3179. DEV_ERR("%s: audio still on after %d sec. try again\n",
  3180. __func__, (i+1)/10);
  3181. SWITCH_SET_HDMI_AUDIO(0, 1);
  3182. }
  3183. msleep(100);
  3184. }
  3185. if (i == timeout_val)
  3186. DEV_ERR("%s: Error: cannot turn off audio engine\n", __func__);
  3187. hdmi_msm_audio_info_setup(FALSE, 0, 0, 0, FALSE);
  3188. hdmi_msm_audio_acr_setup(FALSE, 0, 0, 0);
  3189. DEV_INFO("HDMI Audio: Disabled\n");
  3190. return 0;
  3191. }
  3192. static uint8 hdmi_msm_avi_iframe_lut[][17] = {
  3193. /* 480p60 480i60 576p50 576i50 720p60 720p50 1080p60 1080i60 1080p50
  3194. 1080i50 1080p24 1080p30 1080p25 640x480p 480p60_16_9 576p50_4_3 */
  3195. {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  3196. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, /*00*/
  3197. {0x18, 0x18, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
  3198. 0x28, 0x28, 0x28, 0x28, 0x18, 0x28, 0x18, 0x08}, /*01*/
  3199. {0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
  3200. 0x04, 0x04, 0x04, 0x04, 0x88, 0x00, 0x04, 0x04}, /*02*/
  3201. {0x02, 0x06, 0x11, 0x15, 0x04, 0x13, 0x10, 0x05, 0x1F,
  3202. 0x14, 0x20, 0x22, 0x21, 0x01, 0x03, 0x11, 0x00}, /*03*/
  3203. {0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  3204. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*04*/
  3205. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3206. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*05*/
  3207. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3208. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*06*/
  3209. {0xE1, 0xE1, 0x41, 0x41, 0xD1, 0xd1, 0x39, 0x39, 0x39,
  3210. 0x39, 0x39, 0x39, 0x39, 0xe1, 0xE1, 0x41, 0x01}, /*07*/
  3211. {0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04,
  3212. 0x04, 0x04, 0x04, 0x04, 0x01, 0x01, 0x02, 0x04}, /*08*/
  3213. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3214. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*09*/
  3215. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  3216. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*10*/
  3217. {0xD1, 0xD1, 0xD1, 0xD1, 0x01, 0x01, 0x81, 0x81, 0x81,
  3218. 0x81, 0x81, 0x81, 0x81, 0x81, 0xD1, 0xD1, 0x01}, /*11*/
  3219. {0x02, 0x02, 0x02, 0x02, 0x05, 0x05, 0x07, 0x07, 0x07,
  3220. 0x07, 0x07, 0x07, 0x07, 0x02, 0x02, 0x02, 0x05} /*12*/
  3221. };
  3222. static void hdmi_msm_avi_info_frame(void)
  3223. {
  3224. /* two header + length + 13 data */
  3225. uint8 aviInfoFrame[16];
  3226. uint8 checksum;
  3227. uint32 sum;
  3228. uint32 regVal;
  3229. int i;
  3230. int mode = 0;
  3231. boolean use_ce_scan_info = TRUE;
  3232. switch (external_common_state->video_resolution) {
  3233. case HDMI_VFRMT_720x480p60_4_3:
  3234. mode = 0;
  3235. break;
  3236. case HDMI_VFRMT_720x480i60_16_9:
  3237. mode = 1;
  3238. break;
  3239. case HDMI_VFRMT_720x576p50_16_9:
  3240. mode = 2;
  3241. break;
  3242. case HDMI_VFRMT_720x576i50_16_9:
  3243. mode = 3;
  3244. break;
  3245. case HDMI_VFRMT_1280x720p60_16_9:
  3246. mode = 4;
  3247. break;
  3248. case HDMI_VFRMT_1280x720p50_16_9:
  3249. mode = 5;
  3250. break;
  3251. case HDMI_VFRMT_1920x1080p60_16_9:
  3252. mode = 6;
  3253. break;
  3254. case HDMI_VFRMT_1920x1080i60_16_9:
  3255. mode = 7;
  3256. break;
  3257. case HDMI_VFRMT_1920x1080p50_16_9:
  3258. mode = 8;
  3259. break;
  3260. case HDMI_VFRMT_1920x1080i50_16_9:
  3261. mode = 9;
  3262. break;
  3263. case HDMI_VFRMT_1920x1080p24_16_9:
  3264. mode = 10;
  3265. break;
  3266. case HDMI_VFRMT_1920x1080p30_16_9:
  3267. mode = 11;
  3268. break;
  3269. case HDMI_VFRMT_1920x1080p25_16_9:
  3270. mode = 12;
  3271. break;
  3272. case HDMI_VFRMT_640x480p60_4_3:
  3273. mode = 13;
  3274. break;
  3275. case HDMI_VFRMT_720x480p60_16_9:
  3276. mode = 14;
  3277. break;
  3278. case HDMI_VFRMT_720x576p50_4_3:
  3279. mode = 15;
  3280. break;
  3281. case HDMI_VFRMT_1280x1024p60_5_4:
  3282. mode = 16;
  3283. break;
  3284. default:
  3285. DEV_INFO("%s: mode %d not supported\n", __func__,
  3286. external_common_state->video_resolution);
  3287. return;
  3288. }
  3289. /* InfoFrame Type = 82 */
  3290. aviInfoFrame[0] = 0x82;
  3291. /* Version = 2 */
  3292. aviInfoFrame[1] = 2;
  3293. /* Length of AVI InfoFrame = 13 */
  3294. aviInfoFrame[2] = 13;
  3295. /* Data Byte 01: 0 Y1 Y0 A0 B1 B0 S1 S0 */
  3296. aviInfoFrame[3] = hdmi_msm_avi_iframe_lut[0][mode];
  3297. /*
  3298. * If the sink specified support for both underscan/overscan
  3299. * then, by default, set the underscan bit.
  3300. * Only checking underscan support for preferred format and cea formats
  3301. */
  3302. if ((external_common_state->video_resolution ==
  3303. external_common_state->preferred_video_format)) {
  3304. use_ce_scan_info = FALSE;
  3305. switch (external_common_state->pt_scan_info) {
  3306. case 0:
  3307. /*
  3308. * Need to use the info specified for the corresponding
  3309. * IT or CE format
  3310. */
  3311. DEV_DBG("%s: No underscan information specified for the"
  3312. " preferred video format\n", __func__);
  3313. use_ce_scan_info = TRUE;
  3314. break;
  3315. case 3:
  3316. DEV_DBG("%s: Setting underscan bit for the preferred"
  3317. " video format\n", __func__);
  3318. aviInfoFrame[3] |= 0x02;
  3319. break;
  3320. default:
  3321. DEV_DBG("%s: Underscan information not set for the"
  3322. " preferred video format\n", __func__);
  3323. break;
  3324. }
  3325. }
  3326. if (use_ce_scan_info) {
  3327. if (3 == external_common_state->ce_scan_info) {
  3328. DEV_DBG("%s: Setting underscan bit for the CE video"
  3329. " format\n", __func__);
  3330. aviInfoFrame[3] |= 0x02;
  3331. } else {
  3332. DEV_DBG("%s: Not setting underscan bit for the CE video"
  3333. " format\n", __func__);
  3334. }
  3335. }
  3336. /* Data Byte 02: C1 C0 M1 M0 R3 R2 R1 R0 */
  3337. aviInfoFrame[4] = hdmi_msm_avi_iframe_lut[1][mode];
  3338. /* Data Byte 03: ITC EC2 EC1 EC0 Q1 Q0 SC1 SC0 */
  3339. aviInfoFrame[5] = hdmi_msm_avi_iframe_lut[2][mode];
  3340. /* Data Byte 04: 0 VIC6 VIC5 VIC4 VIC3 VIC2 VIC1 VIC0 */
  3341. aviInfoFrame[6] = hdmi_msm_avi_iframe_lut[3][mode];
  3342. /* Data Byte 05: 0 0 0 0 PR3 PR2 PR1 PR0 */
  3343. aviInfoFrame[7] = hdmi_msm_avi_iframe_lut[4][mode];
  3344. /* Data Byte 06: LSB Line No of End of Top Bar */
  3345. aviInfoFrame[8] = hdmi_msm_avi_iframe_lut[5][mode];
  3346. /* Data Byte 07: MSB Line No of End of Top Bar */
  3347. aviInfoFrame[9] = hdmi_msm_avi_iframe_lut[6][mode];
  3348. /* Data Byte 08: LSB Line No of Start of Bottom Bar */
  3349. aviInfoFrame[10] = hdmi_msm_avi_iframe_lut[7][mode];
  3350. /* Data Byte 09: MSB Line No of Start of Bottom Bar */
  3351. aviInfoFrame[11] = hdmi_msm_avi_iframe_lut[8][mode];
  3352. /* Data Byte 10: LSB Pixel Number of End of Left Bar */
  3353. aviInfoFrame[12] = hdmi_msm_avi_iframe_lut[9][mode];
  3354. /* Data Byte 11: MSB Pixel Number of End of Left Bar */
  3355. aviInfoFrame[13] = hdmi_msm_avi_iframe_lut[10][mode];
  3356. /* Data Byte 12: LSB Pixel Number of Start of Right Bar */
  3357. aviInfoFrame[14] = hdmi_msm_avi_iframe_lut[11][mode];
  3358. /* Data Byte 13: MSB Pixel Number of Start of Right Bar */
  3359. aviInfoFrame[15] = hdmi_msm_avi_iframe_lut[12][mode];
  3360. sum = 0;
  3361. for (i = 0; i < 16; i++)
  3362. sum += aviInfoFrame[i];
  3363. sum &= 0xFF;
  3364. sum = 256 - sum;
  3365. checksum = (uint8) sum;
  3366. regVal = aviInfoFrame[5];
  3367. regVal = regVal << 8 | aviInfoFrame[4];
  3368. regVal = regVal << 8 | aviInfoFrame[3];
  3369. regVal = regVal << 8 | checksum;
  3370. HDMI_OUTP(0x006C, regVal);
  3371. regVal = aviInfoFrame[9];
  3372. regVal = regVal << 8 | aviInfoFrame[8];
  3373. regVal = regVal << 8 | aviInfoFrame[7];
  3374. regVal = regVal << 8 | aviInfoFrame[6];
  3375. HDMI_OUTP(0x0070, regVal);
  3376. regVal = aviInfoFrame[13];
  3377. regVal = regVal << 8 | aviInfoFrame[12];
  3378. regVal = regVal << 8 | aviInfoFrame[11];
  3379. regVal = regVal << 8 | aviInfoFrame[10];
  3380. HDMI_OUTP(0x0074, regVal);
  3381. regVal = aviInfoFrame[1];
  3382. regVal = regVal << 16 | aviInfoFrame[15];
  3383. regVal = regVal << 8 | aviInfoFrame[14];
  3384. HDMI_OUTP(0x0078, regVal);
  3385. /* INFOFRAME_CTRL0[0x002C] */
  3386. /* 0x3 for AVI InfFrame enable (every frame) */
  3387. HDMI_OUTP(0x002C, HDMI_INP(0x002C) | 0x00000003L);
  3388. }
  3389. #ifdef CONFIG_FB_MSM_HDMI_3D
  3390. static void hdmi_msm_vendor_infoframe_packetsetup(void)
  3391. {
  3392. uint32 packet_header = 0;
  3393. uint32 check_sum = 0;
  3394. uint32 packet_payload = 0;
  3395. if (!external_common_state->format_3d) {
  3396. HDMI_OUTP(0x0034, 0);
  3397. return;
  3398. }
  3399. /* 0x0084 GENERIC0_HDR
  3400. * HB0 7:0 NUM
  3401. * HB1 15:8 NUM
  3402. * HB2 23:16 NUM */
  3403. /* Setup Packet header and payload */
  3404. /* 0x81 VS_INFO_FRAME_ID
  3405. 0x01 VS_INFO_FRAME_VERSION
  3406. 0x1B VS_INFO_FRAME_PAYLOAD_LENGTH */
  3407. packet_header = 0x81 | (0x01 << 8) | (0x1B << 16);
  3408. HDMI_OUTP(0x0084, packet_header);
  3409. check_sum = packet_header & 0xff;
  3410. check_sum += (packet_header >> 8) & 0xff;
  3411. check_sum += (packet_header >> 16) & 0xff;
  3412. /* 0x008C GENERIC0_1
  3413. * BYTE4 7:0 NUM
  3414. * BYTE5 15:8 NUM
  3415. * BYTE6 23:16 NUM
  3416. * BYTE7 31:24 NUM */
  3417. /* 0x02 VS_INFO_FRAME_3D_PRESENT */
  3418. packet_payload = 0x02 << 5;
  3419. switch (external_common_state->format_3d) {
  3420. case 1:
  3421. /* 0b1000 VIDEO_3D_FORMAT_SIDE_BY_SIDE_HALF */
  3422. packet_payload |= (0x08 << 8) << 4;
  3423. break;
  3424. case 2:
  3425. /* 0b0110 VIDEO_3D_FORMAT_TOP_AND_BOTTOM_HALF */
  3426. packet_payload |= (0x06 << 8) << 4;
  3427. break;
  3428. }
  3429. HDMI_OUTP(0x008C, packet_payload);
  3430. check_sum += packet_payload & 0xff;
  3431. check_sum += (packet_payload >> 8) & 0xff;
  3432. #define IEEE_REGISTRATION_ID 0xC03
  3433. /* Next 3 bytes are IEEE Registration Identifcation */
  3434. /* 0x0088 GENERIC0_0
  3435. * BYTE0 7:0 NUM (checksum)
  3436. * BYTE1 15:8 NUM
  3437. * BYTE2 23:16 NUM
  3438. * BYTE3 31:24 NUM */
  3439. check_sum += IEEE_REGISTRATION_ID & 0xff;
  3440. check_sum += (IEEE_REGISTRATION_ID >> 8) & 0xff;
  3441. check_sum += (IEEE_REGISTRATION_ID >> 16) & 0xff;
  3442. HDMI_OUTP(0x0088, (0x100 - (0xff & check_sum))
  3443. | ((IEEE_REGISTRATION_ID & 0xff) << 8)
  3444. | (((IEEE_REGISTRATION_ID >> 8) & 0xff) << 16)
  3445. | (((IEEE_REGISTRATION_ID >> 16) & 0xff) << 24));
  3446. /* 0x0034 GEN_PKT_CTRL
  3447. * GENERIC0_SEND 0 0 = Disable Generic0 Packet Transmission
  3448. * 1 = Enable Generic0 Packet Transmission
  3449. * GENERIC0_CONT 1 0 = Send Generic0 Packet on next frame only
  3450. * 1 = Send Generic0 Packet on every frame
  3451. * GENERIC0_UPDATE 2 NUM
  3452. * GENERIC1_SEND 4 0 = Disable Generic1 Packet Transmission
  3453. * 1 = Enable Generic1 Packet Transmission
  3454. * GENERIC1_CONT 5 0 = Send Generic1 Packet on next frame only
  3455. * 1 = Send Generic1 Packet on every frame
  3456. * GENERIC0_LINE 21:16 NUM
  3457. * GENERIC1_LINE 29:24 NUM
  3458. */
  3459. /* GENERIC0_LINE | GENERIC0_UPDATE | GENERIC0_CONT | GENERIC0_SEND
  3460. * Setup HDMI TX generic packet control
  3461. * Enable this packet to transmit every frame
  3462. * Enable this packet to transmit every frame
  3463. * Enable HDMI TX engine to transmit Generic packet 0 */
  3464. HDMI_OUTP(0x0034, (1 << 16) | (1 << 2) | BIT(1) | BIT(0));
  3465. }
  3466. static void hdmi_msm_switch_3d(boolean on)
  3467. {
  3468. mutex_lock(&external_common_state_hpd_mutex);
  3469. if (external_common_state->hpd_state)
  3470. hdmi_msm_vendor_infoframe_packetsetup();
  3471. mutex_unlock(&external_common_state_hpd_mutex);
  3472. }
  3473. #endif
  3474. #define IFRAME_CHECKSUM_32(d) \
  3475. ((d & 0xff) + ((d >> 8) & 0xff) + \
  3476. ((d >> 16) & 0xff) + ((d >> 24) & 0xff))
  3477. static void hdmi_msm_spd_infoframe_packetsetup(void)
  3478. {
  3479. uint32 packet_header = 0;
  3480. uint32 check_sum = 0;
  3481. uint32 packet_payload = 0;
  3482. uint32 packet_control = 0;
  3483. uint8 *vendor_name = external_common_state->spd_vendor_name;
  3484. uint8 *product_description =
  3485. external_common_state->spd_product_description;
  3486. /* 0x00A4 GENERIC1_HDR
  3487. * HB0 7:0 NUM
  3488. * HB1 15:8 NUM
  3489. * HB2 23:16 NUM */
  3490. /* Setup Packet header and payload */
  3491. /* 0x83 InfoFrame Type Code
  3492. 0x01 InfoFrame Version Number
  3493. 0x19 Length of Source Product Description InfoFrame
  3494. */
  3495. packet_header = 0x83 | (0x01 << 8) | (0x19 << 16);
  3496. HDMI_OUTP(0x00A4, packet_header);
  3497. check_sum += IFRAME_CHECKSUM_32(packet_header);
  3498. /* 0x00AC GENERIC1_1
  3499. * BYTE4 7:0 VENDOR_NAME[3]
  3500. * BYTE5 15:8 VENDOR_NAME[4]
  3501. * BYTE6 23:16 VENDOR_NAME[5]
  3502. * BYTE7 31:24 VENDOR_NAME[6] */
  3503. packet_payload = (vendor_name[3] & 0x7f)
  3504. | ((vendor_name[4] & 0x7f) << 8)
  3505. | ((vendor_name[5] & 0x7f) << 16)
  3506. | ((vendor_name[6] & 0x7f) << 24);
  3507. HDMI_OUTP(0x00AC, packet_payload);
  3508. check_sum += IFRAME_CHECKSUM_32(packet_payload);
  3509. /* Product Description (7-bit ASCII code) */
  3510. /* 0x00B0 GENERIC1_2
  3511. * BYTE8 7:0 VENDOR_NAME[7]
  3512. * BYTE9 15:8 PRODUCT_NAME[ 0]
  3513. * BYTE10 23:16 PRODUCT_NAME[ 1]
  3514. * BYTE11 31:24 PRODUCT_NAME[ 2] */
  3515. packet_payload = (vendor_name[7] & 0x7f)
  3516. | ((product_description[0] & 0x7f) << 8)
  3517. | ((product_description[1] & 0x7f) << 16)
  3518. | ((product_description[2] & 0x7f) << 24);
  3519. HDMI_OUTP(0x00B0, packet_payload);
  3520. check_sum += IFRAME_CHECKSUM_32(packet_payload);
  3521. /* 0x00B4 GENERIC1_3
  3522. * BYTE12 7:0 PRODUCT_NAME[ 3]
  3523. * BYTE13 15:8 PRODUCT_NAME[ 4]
  3524. * BYTE14 23:16 PRODUCT_NAME[ 5]
  3525. * BYTE15 31:24 PRODUCT_NAME[ 6] */
  3526. packet_payload = (product_description[3] & 0x7f)
  3527. | ((product_description[4] & 0x7f) << 8)
  3528. | ((product_description[5] & 0x7f) << 16)
  3529. | ((product_description[6] & 0x7f) << 24);
  3530. HDMI_OUTP(0x00B4, packet_payload);
  3531. check_sum += IFRAME_CHECKSUM_32(packet_payload);
  3532. /* 0x00B8 GENERIC1_4
  3533. * BYTE16 7:0 PRODUCT_NAME[ 7]
  3534. * BYTE17 15:8 PRODUCT_NAME[ 8]
  3535. * BYTE18 23:16 PRODUCT_NAME[ 9]
  3536. * BYTE19 31:24 PRODUCT_NAME[10] */
  3537. packet_payload = (product_description[7] & 0x7f)
  3538. | ((product_description[8] & 0x7f) << 8)
  3539. | ((product_description[9] & 0x7f) << 16)
  3540. | ((product_description[10] & 0x7f) << 24);
  3541. HDMI_OUTP(0x00B8, packet_payload);
  3542. check_sum += IFRAME_CHECKSUM_32(packet_payload);
  3543. /* 0x00BC GENERIC1_5
  3544. * BYTE20 7:0 PRODUCT_NAME[11]
  3545. * BYTE21 15:8 PRODUCT_NAME[12]
  3546. * BYTE22 23:16 PRODUCT_NAME[13]
  3547. * BYTE23 31:24 PRODUCT_NAME[14] */
  3548. packet_payload = (product_description[11] & 0x7f)
  3549. | ((product_description[12] & 0x7f) << 8)
  3550. | ((product_description[13] & 0x7f) << 16)
  3551. | ((product_description[14] & 0x7f) << 24);
  3552. HDMI_OUTP(0x00BC, packet_payload);
  3553. check_sum += IFRAME_CHECKSUM_32(packet_payload);
  3554. /* 0x00C0 GENERIC1_6
  3555. * BYTE24 7:0 PRODUCT_NAME[15]
  3556. * BYTE25 15:8 Source Device Information
  3557. * BYTE26 23:16 NUM
  3558. * BYTE27 31:24 NUM */
  3559. /* Source Device Information
  3560. * 00h unknown
  3561. * 01h Digital STB
  3562. * 02h DVD
  3563. * 03h D-VHS
  3564. * 04h HDD Video
  3565. * 05h DVC
  3566. * 06h DSC
  3567. * 07h Video CD
  3568. * 08h Game
  3569. * 09h PC general */
  3570. packet_payload = (product_description[15] & 0x7f) | 0x00 << 8;
  3571. HDMI_OUTP(0x00C0, packet_payload);
  3572. check_sum += IFRAME_CHECKSUM_32(packet_payload);
  3573. /* Vendor Name (7bit ASCII code) */
  3574. /* 0x00A8 GENERIC1_0
  3575. * BYTE0 7:0 CheckSum
  3576. * BYTE1 15:8 VENDOR_NAME[0]
  3577. * BYTE2 23:16 VENDOR_NAME[1]
  3578. * BYTE3 31:24 VENDOR_NAME[2] */
  3579. packet_payload = ((vendor_name[0] & 0x7f) << 8)
  3580. | ((vendor_name[1] & 0x7f) << 16)
  3581. | ((vendor_name[2] & 0x7f) << 24);
  3582. check_sum += IFRAME_CHECKSUM_32(packet_payload);
  3583. packet_payload |= ((0x100 - (0xff & check_sum)) & 0xff);
  3584. HDMI_OUTP(0x00A8, packet_payload);
  3585. /* GENERIC1_LINE | GENERIC1_CONT | GENERIC1_SEND
  3586. * Setup HDMI TX generic packet control
  3587. * Enable this packet to transmit every frame
  3588. * Enable HDMI TX engine to transmit Generic packet 1 */
  3589. packet_control = HDMI_INP_ND(0x0034);
  3590. packet_control |= ((0x1 << 24) | (1 << 5) | (1 << 4));
  3591. HDMI_OUTP(0x0034, packet_control);
  3592. }
  3593. int hdmi_msm_clk(int on)
  3594. {
  3595. int rc;
  3596. DEV_DBG("HDMI Clk: %s\n", on ? "Enable" : "Disable");
  3597. if (on) {
  3598. rc = clk_prepare_enable(hdmi_msm_state->hdmi_app_clk);
  3599. if (rc) {
  3600. DEV_ERR("'hdmi_app_clk' clock enable failed, rc=%d\n",
  3601. rc);
  3602. return rc;
  3603. }
  3604. rc = clk_prepare_enable(hdmi_msm_state->hdmi_m_pclk);
  3605. if (rc) {
  3606. DEV_ERR("'hdmi_m_pclk' clock enable failed, rc=%d\n",
  3607. rc);
  3608. return rc;
  3609. }
  3610. rc = clk_prepare_enable(hdmi_msm_state->hdmi_s_pclk);
  3611. if (rc) {
  3612. DEV_ERR("'hdmi_s_pclk' clock enable failed, rc=%d\n",
  3613. rc);
  3614. return rc;
  3615. }
  3616. } else {
  3617. clk_disable_unprepare(hdmi_msm_state->hdmi_app_clk);
  3618. clk_disable_unprepare(hdmi_msm_state->hdmi_m_pclk);
  3619. clk_disable_unprepare(hdmi_msm_state->hdmi_s_pclk);
  3620. }
  3621. return 0;
  3622. }
  3623. static void hdmi_msm_turn_on(void)
  3624. {
  3625. uint32 audio_pkt_ctrl, audio_cfg;
  3626. /*
  3627. * Number of wait iterations for QDSP to disable Audio Engine
  3628. * before resetting HDMI core
  3629. */
  3630. int i = 10;
  3631. audio_pkt_ctrl = HDMI_INP_ND(0x0020);
  3632. audio_cfg = HDMI_INP_ND(0x01D0);
  3633. /*
  3634. * Checking BIT[0] of AUDIO PACKET CONTROL and
  3635. * AUDIO CONFIGURATION register
  3636. */
  3637. while (((audio_pkt_ctrl & 0x00000001) || (audio_cfg & 0x00000001))
  3638. && (i--)) {
  3639. audio_pkt_ctrl = HDMI_INP_ND(0x0020);
  3640. audio_cfg = HDMI_INP_ND(0x01D0);
  3641. DEV_DBG("%d times :: HDMI AUDIO PACKET is %08x and "
  3642. "AUDIO CFG is %08x", i, audio_pkt_ctrl, audio_cfg);
  3643. msleep(20);
  3644. }
  3645. hdmi_msm_set_mode(FALSE);
  3646. mutex_lock(&hdcp_auth_state_mutex);
  3647. hdmi_msm_reset_core();
  3648. mutex_unlock(&hdcp_auth_state_mutex);
  3649. hdmi_msm_init_phy(external_common_state->video_resolution);
  3650. /* HDMI_USEC_REFTIMER[0x0208] */
  3651. HDMI_OUTP(0x0208, 0x0001001B);
  3652. hdmi_msm_set_mode(TRUE);
  3653. hdmi_msm_video_setup(external_common_state->video_resolution);
  3654. if (!hdmi_msm_is_dvi_mode()) {
  3655. hdmi_msm_audio_setup();
  3656. /*
  3657. * Send the audio switch device notification if HDCP is
  3658. * not enabled. Otherwise, the notification would be
  3659. * sent after HDCP authentication is successful.
  3660. */
  3661. if (!hdmi_msm_state->hdcp_enable)
  3662. SWITCH_SET_HDMI_AUDIO(1, 0);
  3663. }
  3664. hdmi_msm_avi_info_frame();
  3665. #ifdef CONFIG_FB_MSM_HDMI_3D
  3666. hdmi_msm_vendor_infoframe_packetsetup();
  3667. #endif
  3668. hdmi_msm_spd_infoframe_packetsetup();
  3669. if (hdmi_msm_state->hdcp_enable && hdmi_msm_state->reauth) {
  3670. hdmi_msm_hdcp_enable();
  3671. hdmi_msm_state->reauth = FALSE ;
  3672. }
  3673. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  3674. /* re-initialize CEC if enabled */
  3675. mutex_lock(&hdmi_msm_state_mutex);
  3676. if (hdmi_msm_state->cec_enabled == true) {
  3677. hdmi_msm_cec_init();
  3678. hdmi_msm_cec_write_logical_addr(
  3679. hdmi_msm_state->cec_logical_addr);
  3680. }
  3681. mutex_unlock(&hdmi_msm_state_mutex);
  3682. #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
  3683. DEV_INFO("HDMI Core: Initialized\n");
  3684. }
  3685. static void hdmi_msm_hdcp_timer(unsigned long data)
  3686. {
  3687. if (!hdmi_msm_state->hdcp_enable) {
  3688. DEV_DBG("%s: HDCP not enabled\n", __func__);
  3689. return;
  3690. }
  3691. queue_work(hdmi_work_queue, &hdmi_msm_state->hdcp_work);
  3692. }
  3693. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  3694. static void hdmi_msm_cec_read_timer_func(unsigned long data)
  3695. {
  3696. queue_work(hdmi_work_queue, &hdmi_msm_state->cec_latch_detect_work);
  3697. }
  3698. #endif
  3699. static void hdmi_msm_hpd_polarity_setup(void)
  3700. {
  3701. u32 cable_sense;
  3702. bool polarity = !external_common_state->hpd_state;
  3703. bool trigger = false;
  3704. if (polarity)
  3705. HDMI_OUTP(0x0254, BIT(2) | BIT(1));
  3706. else
  3707. HDMI_OUTP(0x0254, BIT(2));
  3708. cable_sense = (HDMI_INP(0x0250) & BIT(1)) >> 1;
  3709. if (cable_sense == polarity)
  3710. trigger = true;
  3711. DEV_DBG("%s: listen=%s, sense=%s, trigger=%s\n", __func__,
  3712. polarity ? "connect" : "disconnect",
  3713. cable_sense ? "connect" : "disconnect",
  3714. trigger ? "Yes" : "No");
  3715. if (trigger) {
  3716. u32 reg_val = HDMI_INP(0x0258);
  3717. /* Toggle HPD circuit to trigger HPD sense */
  3718. HDMI_OUTP(0x0258, reg_val & ~BIT(28));
  3719. HDMI_OUTP(0x0258, reg_val | BIT(28));
  3720. }
  3721. }
  3722. static void hdmi_msm_hpd_off(void)
  3723. {
  3724. int rc = 0;
  3725. if (!hdmi_msm_state->hpd_initialized) {
  3726. DEV_DBG("%s: HPD is already OFF, returning\n", __func__);
  3727. return;
  3728. }
  3729. DEV_DBG("%s: (timer, 5V, IRQ off)\n", __func__);
  3730. disable_irq(hdmi_msm_state->irq);
  3731. /* Disable HPD interrupt */
  3732. HDMI_OUTP(0x0254, 0);
  3733. DEV_DBG("%s: Disabling HPD_CTRLd\n", __func__);
  3734. hdmi_msm_set_mode(FALSE);
  3735. hdmi_msm_state->pd->enable_5v(0);
  3736. hdmi_msm_clk(0);
  3737. rc = hdmi_msm_state->pd->gpio_config(0);
  3738. if (rc != 0)
  3739. DEV_INFO("%s: Failed to disable GPIOs. Error=%d\n",
  3740. __func__, rc);
  3741. hdmi_msm_state->hpd_initialized = FALSE;
  3742. }
  3743. static void hdmi_msm_dump_regs(const char *prefix)
  3744. {
  3745. #ifdef REG_DUMP
  3746. print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 32, 4,
  3747. (void *)MSM_HDMI_BASE, 0x0334, false);
  3748. #endif
  3749. }
  3750. static int hdmi_msm_hpd_on(void)
  3751. {
  3752. static int phy_reset_done;
  3753. uint32 hpd_ctrl;
  3754. int rc = 0;
  3755. if (hdmi_msm_state->hpd_initialized) {
  3756. DEV_DBG("%s: HPD is already ON\n", __func__);
  3757. } else {
  3758. rc = hdmi_msm_state->pd->gpio_config(1);
  3759. if (rc) {
  3760. DEV_ERR("%s: Failed to enable GPIOs. Error=%d\n",
  3761. __func__, rc);
  3762. goto error1;
  3763. }
  3764. rc = hdmi_msm_clk(1);
  3765. if (rc) {
  3766. DEV_ERR("%s: Failed to enable clocks. Error=%d\n",
  3767. __func__, rc);
  3768. goto error2;
  3769. }
  3770. rc = hdmi_msm_state->pd->enable_5v(1);
  3771. if (rc) {
  3772. DEV_ERR("%s: Failed to enable 5V regulator. Error=%d\n",
  3773. __func__, rc);
  3774. goto error3;
  3775. }
  3776. hdmi_msm_dump_regs("HDMI-INIT: ");
  3777. hdmi_msm_set_mode(FALSE);
  3778. if (!phy_reset_done) {
  3779. hdmi_phy_reset();
  3780. phy_reset_done = 1;
  3781. }
  3782. hdmi_msm_set_mode(TRUE);
  3783. /* HDMI_USEC_REFTIMER[0x0208] */
  3784. HDMI_OUTP(0x0208, 0x0001001B);
  3785. /* Set up HPD state variables */
  3786. mutex_lock(&external_common_state_hpd_mutex);
  3787. external_common_state->hpd_state = 0;
  3788. mutex_unlock(&external_common_state_hpd_mutex);
  3789. mutex_lock(&hdmi_msm_state_mutex);
  3790. mutex_unlock(&hdmi_msm_state_mutex);
  3791. enable_irq(hdmi_msm_state->irq);
  3792. hdmi_msm_state->hpd_initialized = TRUE;
  3793. /* set timeout to 4.1ms (max) for hardware debounce */
  3794. hpd_ctrl = HDMI_INP(0x0258) | 0x1FFF;
  3795. /* Turn on HPD HW circuit */
  3796. HDMI_OUTP(0x0258, hpd_ctrl | BIT(28));
  3797. /* Set HPD cable sense polarity */
  3798. hdmi_msm_hpd_polarity_setup();
  3799. }
  3800. DEV_DBG("%s: (IRQ, 5V on)\n", __func__);
  3801. return 0;
  3802. error3:
  3803. hdmi_msm_clk(0);
  3804. error2:
  3805. hdmi_msm_state->pd->gpio_config(0);
  3806. error1:
  3807. return rc;
  3808. }
  3809. static int hdmi_msm_power_ctrl(boolean enable)
  3810. {
  3811. int rc = 0;
  3812. int time = 0;
  3813. if (enable) {
  3814. /*
  3815. * Enable HPD only if the UI option is on or if
  3816. * HDMI is configured as the primary display
  3817. */
  3818. if (hdmi_prim_display ||
  3819. external_common_state->hpd_feature_on) {
  3820. DEV_DBG("%s: Turning HPD ciruitry on\n", __func__);
  3821. rc = hdmi_msm_hpd_on();
  3822. if (rc) {
  3823. DEV_ERR("%s: HPD ON FAILED\n", __func__);
  3824. return rc;
  3825. }
  3826. /* Wait for HPD initialization to complete */
  3827. INIT_COMPLETION(hdmi_msm_state->hpd_event_processed);
  3828. time = wait_for_completion_interruptible_timeout(
  3829. &hdmi_msm_state->hpd_event_processed, HZ);
  3830. if (!time && !external_common_state->hpd_state) {
  3831. DEV_DBG("%s: cable not detected\n", __func__);
  3832. queue_work(hdmi_work_queue,
  3833. &hdmi_msm_state->hpd_state_work);
  3834. }
  3835. }
  3836. } else {
  3837. DEV_DBG("%s: Turning HPD ciruitry off\n", __func__);
  3838. hdmi_msm_hpd_off();
  3839. }
  3840. return rc;
  3841. }
  3842. static int hdmi_msm_power_on(struct platform_device *pdev)
  3843. {
  3844. struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
  3845. int ret = 0;
  3846. bool changed;
  3847. if (!hdmi_ready()) {
  3848. DEV_ERR("%s: HDMI/HPD not initialized\n", __func__);
  3849. return ret;
  3850. }
  3851. if (!external_common_state->hpd_state) {
  3852. DEV_DBG("%s:HDMI cable not connected\n", __func__);
  3853. goto error;
  3854. }
  3855. /* Only start transmission with supported resolution */
  3856. changed = hdmi_common_get_video_format_from_drv_data(mfd);
  3857. if (changed || external_common_state->default_res_supported) {
  3858. mutex_lock(&external_common_state_hpd_mutex);
  3859. if (external_common_state->hpd_state &&
  3860. hdmi_msm_is_power_on()) {
  3861. mutex_unlock(&external_common_state_hpd_mutex);
  3862. DEV_INFO("HDMI cable connected %s(%dx%d, %d)\n",
  3863. __func__, mfd->var_xres, mfd->var_yres,
  3864. mfd->var_pixclock);
  3865. hdmi_msm_turn_on();
  3866. hdmi_msm_state->panel_power_on = TRUE;
  3867. if (hdmi_msm_state->hdcp_enable) {
  3868. /* Kick off HDCP Authentication */
  3869. mutex_lock(&hdcp_auth_state_mutex);
  3870. hdmi_msm_state->reauth = FALSE;
  3871. hdmi_msm_state->full_auth_done = FALSE;
  3872. mutex_unlock(&hdcp_auth_state_mutex);
  3873. mod_timer(&hdmi_msm_state->hdcp_timer,
  3874. jiffies + HZ/2);
  3875. }
  3876. } else {
  3877. mutex_unlock(&external_common_state_hpd_mutex);
  3878. }
  3879. hdmi_msm_dump_regs("HDMI-ON: ");
  3880. DEV_INFO("power=%s DVI= %s\n",
  3881. hdmi_msm_is_power_on() ? "ON" : "OFF" ,
  3882. hdmi_msm_is_dvi_mode() ? "ON" : "OFF");
  3883. } else {
  3884. DEV_ERR("%s: Video fmt %d not supp. Returning\n",
  3885. __func__,
  3886. external_common_state->video_resolution);
  3887. }
  3888. error:
  3889. /* Set HPD cable sense polarity */
  3890. hdmi_msm_hpd_polarity_setup();
  3891. return ret;
  3892. }
  3893. void mhl_connect_api(boolean on)
  3894. {
  3895. char *envp[2];
  3896. /* Simulating a HPD event based on MHL event */
  3897. if (on) {
  3898. hdmi_msm_read_edid();
  3899. hdmi_msm_state->reauth = FALSE ;
  3900. /* Build EDID table */
  3901. hdmi_msm_turn_on();
  3902. DEV_INFO("HDMI HPD: CONNECTED: send ONLINE\n");
  3903. kobject_uevent(external_common_state->uevent_kobj,
  3904. KOBJ_ONLINE);
  3905. envp[0] = 0;
  3906. if (!hdmi_msm_state->hdcp_enable) {
  3907. /* Send Audio for HDMI Compliance Cases*/
  3908. envp[0] = "HDCP_STATE=PASS";
  3909. envp[1] = NULL;
  3910. DEV_INFO("HDMI HPD: sense : send HDCP_PASS\n");
  3911. kobject_uevent_env(external_common_state->uevent_kobj,
  3912. KOBJ_CHANGE, envp);
  3913. switch_set_state(&external_common_state->sdev, 1);
  3914. DEV_INFO("%s: hdmi state switched to %d\n",
  3915. __func__, external_common_state->sdev.state);
  3916. } else {
  3917. hdmi_msm_hdcp_enable();
  3918. }
  3919. } else {
  3920. DEV_INFO("HDMI HPD: DISCONNECTED: send OFFLINE\n");
  3921. kobject_uevent(external_common_state->uevent_kobj,
  3922. KOBJ_OFFLINE);
  3923. switch_set_state(&external_common_state->sdev, 0);
  3924. DEV_INFO("%s: hdmi state switched to %d\n", __func__,
  3925. external_common_state->sdev.state);
  3926. }
  3927. }
  3928. EXPORT_SYMBOL(mhl_connect_api);
  3929. /* Note that power-off will also be called when the cable-remove event is
  3930. * processed on the user-space and as a result the framebuffer is powered
  3931. * down. However, we are still required to be able to detect a cable-insert
  3932. * event; so for now leave the HDMI engine running; so that the HPD IRQ is
  3933. * still being processed.
  3934. */
  3935. static int hdmi_msm_power_off(struct platform_device *pdev)
  3936. {
  3937. int ret = 0;
  3938. if (!hdmi_ready()) {
  3939. DEV_ERR("%s: HDMI/HPD not initialized\n", __func__);
  3940. return ret;
  3941. }
  3942. if (!hdmi_msm_state->panel_power_on) {
  3943. DEV_DBG("%s: panel not ON\n", __func__);
  3944. goto error;
  3945. }
  3946. if (hdmi_msm_state->hdcp_enable) {
  3947. if (hdmi_msm_state->hdcp_activating) {
  3948. /*
  3949. * Let the HDCP work know that we got an HPD
  3950. * disconnect so that it can stop the
  3951. * reauthentication loop.
  3952. */
  3953. mutex_lock(&hdcp_auth_state_mutex);
  3954. hdmi_msm_state->hpd_during_auth = TRUE;
  3955. mutex_unlock(&hdcp_auth_state_mutex);
  3956. }
  3957. /*
  3958. * Cancel any pending reauth attempts.
  3959. * If one is ongoing, wait for it to finish
  3960. */
  3961. cancel_work_sync(&hdmi_msm_state->hdcp_reauth_work);
  3962. cancel_work_sync(&hdmi_msm_state->hdcp_work);
  3963. del_timer_sync(&hdmi_msm_state->hdcp_timer);
  3964. hdmi_msm_state->reauth = FALSE;
  3965. hdcp_deauthenticate();
  3966. }
  3967. SWITCH_SET_HDMI_AUDIO(0, 0);
  3968. if (!hdmi_msm_is_dvi_mode())
  3969. hdmi_msm_audio_off();
  3970. hdmi_msm_powerdown_phy();
  3971. hdmi_msm_state->panel_power_on = FALSE;
  3972. DEV_INFO("power: OFF (audio off)\n");
  3973. if (!completion_done(&hdmi_msm_state->hpd_event_processed))
  3974. complete(&hdmi_msm_state->hpd_event_processed);
  3975. error:
  3976. /* Set HPD cable sense polarity */
  3977. hdmi_msm_hpd_polarity_setup();
  3978. return ret;
  3979. }
  3980. bool mhl_is_enabled(void)
  3981. {
  3982. return hdmi_msm_state->is_mhl_enabled;
  3983. }
  3984. void hdmi_msm_config_hdcp_feature(void)
  3985. {
  3986. if (hdcp_feature_on && hdmi_msm_has_hdcp()) {
  3987. init_timer(&hdmi_msm_state->hdcp_timer);
  3988. hdmi_msm_state->hdcp_timer.function = hdmi_msm_hdcp_timer;
  3989. hdmi_msm_state->hdcp_timer.data = (uint32)NULL;
  3990. hdmi_msm_state->hdcp_timer.expires = 0xffffffffL;
  3991. init_completion(&hdmi_msm_state->hdcp_success_done);
  3992. INIT_WORK(&hdmi_msm_state->hdcp_reauth_work,
  3993. hdmi_msm_hdcp_reauth_work);
  3994. INIT_WORK(&hdmi_msm_state->hdcp_work, hdmi_msm_hdcp_work);
  3995. hdmi_msm_state->hdcp_enable = TRUE;
  3996. } else {
  3997. del_timer(&hdmi_msm_state->hdcp_timer);
  3998. hdmi_msm_state->hdcp_enable = FALSE;
  3999. }
  4000. external_common_state->present_hdcp = hdmi_msm_state->hdcp_enable;
  4001. DEV_INFO("%s: HDCP Feature: %s\n", __func__,
  4002. hdmi_msm_state->hdcp_enable ? "Enabled" : "Disabled");
  4003. }
  4004. static void hdmi_msm_update_panel_info(struct msm_fb_data_type *mfd)
  4005. {
  4006. if (!mfd)
  4007. return;
  4008. if (hdmi_common_get_video_format_from_drv_data(mfd))
  4009. hdmi_common_init_panel_info(&mfd->panel_info);
  4010. }
  4011. static bool hdmi_msm_cable_connected(void)
  4012. {
  4013. return hdmi_msm_state->hpd_initialized &&
  4014. external_common_state->hpd_state;
  4015. }
  4016. static int __devinit hdmi_msm_probe(struct platform_device *pdev)
  4017. {
  4018. int rc;
  4019. struct platform_device *fb_dev;
  4020. struct msm_fb_data_type *mfd = NULL;
  4021. if (!hdmi_msm_state) {
  4022. pr_err("%s: hdmi_msm_state is NULL\n", __func__);
  4023. return -ENOMEM;
  4024. }
  4025. external_common_state->dev = &pdev->dev;
  4026. DEV_DBG("probe\n");
  4027. if (pdev->id == 0) {
  4028. struct resource *res;
  4029. #define GET_RES(name, mode) do { \
  4030. res = platform_get_resource_byname(pdev, mode, name); \
  4031. if (!res) { \
  4032. DEV_ERR("'" name "' resource not found\n"); \
  4033. rc = -ENODEV; \
  4034. goto error; \
  4035. } \
  4036. } while (0)
  4037. #define IO_REMAP(var, name) do { \
  4038. GET_RES(name, IORESOURCE_MEM); \
  4039. var = ioremap(res->start, resource_size(res)); \
  4040. if (!var) { \
  4041. DEV_ERR("'" name "' ioremap failed\n"); \
  4042. rc = -ENOMEM; \
  4043. goto error; \
  4044. } \
  4045. } while (0)
  4046. #define GET_IRQ(var, name) do { \
  4047. GET_RES(name, IORESOURCE_IRQ); \
  4048. var = res->start; \
  4049. } while (0)
  4050. IO_REMAP(hdmi_msm_state->qfprom_io, "hdmi_msm_qfprom_addr");
  4051. hdmi_msm_state->hdmi_io = MSM_HDMI_BASE;
  4052. GET_IRQ(hdmi_msm_state->irq, "hdmi_msm_irq");
  4053. hdmi_msm_state->pd = pdev->dev.platform_data;
  4054. #undef GET_RES
  4055. #undef IO_REMAP
  4056. #undef GET_IRQ
  4057. return 0;
  4058. }
  4059. hdmi_msm_state->hdmi_app_clk = clk_get(&pdev->dev, "core_clk");
  4060. if (IS_ERR(hdmi_msm_state->hdmi_app_clk)) {
  4061. DEV_ERR("'core_clk' clk not found\n");
  4062. rc = IS_ERR(hdmi_msm_state->hdmi_app_clk);
  4063. goto error;
  4064. }
  4065. hdmi_msm_state->hdmi_m_pclk = clk_get(&pdev->dev, "master_iface_clk");
  4066. if (IS_ERR(hdmi_msm_state->hdmi_m_pclk)) {
  4067. DEV_ERR("'master_iface_clk' clk not found\n");
  4068. rc = IS_ERR(hdmi_msm_state->hdmi_m_pclk);
  4069. goto error;
  4070. }
  4071. hdmi_msm_state->hdmi_s_pclk = clk_get(&pdev->dev, "slave_iface_clk");
  4072. if (IS_ERR(hdmi_msm_state->hdmi_s_pclk)) {
  4073. DEV_ERR("'slave_iface_clk' clk not found\n");
  4074. rc = IS_ERR(hdmi_msm_state->hdmi_s_pclk);
  4075. goto error;
  4076. }
  4077. hdmi_msm_state->is_mhl_enabled = hdmi_msm_state->pd->is_mhl_enabled;
  4078. rc = check_hdmi_features();
  4079. if (rc) {
  4080. DEV_ERR("Init FAILED: check_hdmi_features rc=%d\n", rc);
  4081. goto error;
  4082. }
  4083. if (!hdmi_msm_state->pd->core_power) {
  4084. DEV_ERR("Init FAILED: core_power function missing\n");
  4085. rc = -ENODEV;
  4086. goto error;
  4087. }
  4088. if (!hdmi_msm_state->pd->enable_5v) {
  4089. DEV_ERR("Init FAILED: enable_5v function missing\n");
  4090. rc = -ENODEV;
  4091. goto error;
  4092. }
  4093. if (!hdmi_msm_state->pd->cec_power) {
  4094. DEV_ERR("Init FAILED: cec_power function missing\n");
  4095. rc = -ENODEV;
  4096. goto error;
  4097. }
  4098. rc = request_threaded_irq(hdmi_msm_state->irq, NULL, &hdmi_msm_isr,
  4099. IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "hdmi_msm_isr", NULL);
  4100. if (rc) {
  4101. DEV_ERR("Init FAILED: IRQ request, rc=%d\n", rc);
  4102. goto error;
  4103. }
  4104. disable_irq(hdmi_msm_state->irq);
  4105. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  4106. init_timer(&hdmi_msm_state->cec_read_timer);
  4107. hdmi_msm_state->cec_read_timer.function =
  4108. hdmi_msm_cec_read_timer_func;
  4109. hdmi_msm_state->cec_read_timer.data = (uint32)NULL;
  4110. hdmi_msm_state->cec_read_timer.expires = 0xffffffffL;
  4111. #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
  4112. fb_dev = msm_fb_add_device(pdev);
  4113. if (fb_dev) {
  4114. rc = external_common_state_create(fb_dev);
  4115. if (rc) {
  4116. DEV_ERR("Init FAILED: hdmi_msm_state_create, rc=%d\n",
  4117. rc);
  4118. goto error;
  4119. }
  4120. } else
  4121. DEV_ERR("Init FAILED: failed to add fb device\n");
  4122. mfd = platform_get_drvdata(fb_dev);
  4123. mfd->update_panel_info = hdmi_msm_update_panel_info;
  4124. mfd->is_panel_ready = hdmi_msm_cable_connected;
  4125. if (hdmi_prim_display) {
  4126. rc = hdmi_msm_hpd_on();
  4127. if (rc)
  4128. goto error;
  4129. }
  4130. hdmi_msm_config_hdcp_feature();
  4131. /* Initialize hdmi node and register with switch driver */
  4132. if (hdmi_prim_display)
  4133. external_common_state->sdev.name = "hdmi_as_primary";
  4134. else
  4135. external_common_state->sdev.name = "hdmi";
  4136. if (switch_dev_register(&external_common_state->sdev) < 0) {
  4137. DEV_ERR("Hdmi switch registration failed\n");
  4138. rc = -ENODEV;
  4139. goto error;
  4140. }
  4141. external_common_state->audio_sdev.name = "hdmi_audio";
  4142. if (switch_dev_register(&external_common_state->audio_sdev) < 0) {
  4143. DEV_ERR("Hdmi audio switch registration failed\n");
  4144. switch_dev_unregister(&external_common_state->sdev);
  4145. rc = -ENODEV;
  4146. goto error;
  4147. }
  4148. /* Set the default video resolution for MHL-enabled display */
  4149. if (hdmi_msm_state->is_mhl_enabled) {
  4150. DEV_DBG("MHL Enabled. Restricting default video resolution\n");
  4151. external_common_state->video_resolution =
  4152. HDMI_VFRMT_1920x1080p30_16_9;
  4153. }
  4154. return 0;
  4155. error:
  4156. if (hdmi_msm_state->qfprom_io)
  4157. iounmap(hdmi_msm_state->qfprom_io);
  4158. hdmi_msm_state->qfprom_io = NULL;
  4159. if (hdmi_msm_state->hdmi_io)
  4160. iounmap(hdmi_msm_state->hdmi_io);
  4161. hdmi_msm_state->hdmi_io = NULL;
  4162. external_common_state_remove();
  4163. if (hdmi_msm_state->hdmi_app_clk)
  4164. clk_put(hdmi_msm_state->hdmi_app_clk);
  4165. if (hdmi_msm_state->hdmi_m_pclk)
  4166. clk_put(hdmi_msm_state->hdmi_m_pclk);
  4167. if (hdmi_msm_state->hdmi_s_pclk)
  4168. clk_put(hdmi_msm_state->hdmi_s_pclk);
  4169. hdmi_msm_state->hdmi_app_clk = NULL;
  4170. hdmi_msm_state->hdmi_m_pclk = NULL;
  4171. hdmi_msm_state->hdmi_s_pclk = NULL;
  4172. return rc;
  4173. }
  4174. static int __devexit hdmi_msm_remove(struct platform_device *pdev)
  4175. {
  4176. DEV_INFO("HDMI device: remove\n");
  4177. DEV_INFO("HDMI HPD: OFF\n");
  4178. /* Unregister hdmi node from switch driver */
  4179. switch_dev_unregister(&external_common_state->sdev);
  4180. switch_dev_unregister(&external_common_state->audio_sdev);
  4181. hdmi_msm_hpd_off();
  4182. free_irq(hdmi_msm_state->irq, NULL);
  4183. if (hdmi_msm_state->qfprom_io)
  4184. iounmap(hdmi_msm_state->qfprom_io);
  4185. hdmi_msm_state->qfprom_io = NULL;
  4186. if (hdmi_msm_state->hdmi_io)
  4187. iounmap(hdmi_msm_state->hdmi_io);
  4188. hdmi_msm_state->hdmi_io = NULL;
  4189. external_common_state_remove();
  4190. if (hdmi_msm_state->hdmi_app_clk)
  4191. clk_put(hdmi_msm_state->hdmi_app_clk);
  4192. if (hdmi_msm_state->hdmi_m_pclk)
  4193. clk_put(hdmi_msm_state->hdmi_m_pclk);
  4194. if (hdmi_msm_state->hdmi_s_pclk)
  4195. clk_put(hdmi_msm_state->hdmi_s_pclk);
  4196. hdmi_msm_state->hdmi_app_clk = NULL;
  4197. hdmi_msm_state->hdmi_m_pclk = NULL;
  4198. hdmi_msm_state->hdmi_s_pclk = NULL;
  4199. kfree(hdmi_msm_state);
  4200. hdmi_msm_state = NULL;
  4201. return 0;
  4202. }
  4203. static int hdmi_msm_hpd_feature(int on)
  4204. {
  4205. int rc = 0;
  4206. DEV_INFO("%s: %d\n", __func__, on);
  4207. if (on) {
  4208. rc = hdmi_msm_hpd_on();
  4209. } else {
  4210. if (external_common_state->hpd_state) {
  4211. external_common_state->hpd_state = 0;
  4212. /* Send offline event to switch OFF HDMI and HAL FD */
  4213. hdmi_msm_send_event(HPD_EVENT_OFFLINE);
  4214. /* Wait for HDMI and FD to close */
  4215. INIT_COMPLETION(hdmi_msm_state->hpd_event_processed);
  4216. wait_for_completion_interruptible_timeout(
  4217. &hdmi_msm_state->hpd_event_processed, HZ);
  4218. }
  4219. hdmi_msm_hpd_off();
  4220. /* Set HDMI switch node to 0 on HPD feature disable */
  4221. switch_set_state(&external_common_state->sdev, 0);
  4222. DEV_INFO("%s: hdmi state switched to %d\n", __func__,
  4223. external_common_state->sdev.state);
  4224. }
  4225. return rc;
  4226. }
  4227. static struct platform_driver this_driver = {
  4228. .probe = hdmi_msm_probe,
  4229. .remove = hdmi_msm_remove,
  4230. .driver.name = "hdmi_msm",
  4231. };
  4232. static struct msm_fb_panel_data hdmi_msm_panel_data = {
  4233. .on = hdmi_msm_power_on,
  4234. .off = hdmi_msm_power_off,
  4235. .power_ctrl = hdmi_msm_power_ctrl,
  4236. };
  4237. static struct platform_device this_device = {
  4238. .name = "hdmi_msm",
  4239. .id = 1,
  4240. .dev.platform_data = &hdmi_msm_panel_data,
  4241. };
  4242. static int __init hdmi_msm_init(void)
  4243. {
  4244. int rc;
  4245. if (msm_fb_detect_client("hdmi_msm"))
  4246. return 0;
  4247. #ifdef CONFIG_FB_MSM_HDMI_AS_PRIMARY
  4248. hdmi_prim_display = 1;
  4249. #endif
  4250. hdmi_msm_setup_video_mode_lut();
  4251. hdmi_msm_state = kzalloc(sizeof(*hdmi_msm_state), GFP_KERNEL);
  4252. if (!hdmi_msm_state) {
  4253. pr_err("hdmi_msm_init FAILED: out of memory\n");
  4254. rc = -ENOMEM;
  4255. goto init_exit;
  4256. }
  4257. external_common_state = &hdmi_msm_state->common;
  4258. if (hdmi_prim_display && hdmi_prim_resolution)
  4259. external_common_state->video_resolution =
  4260. hdmi_prim_resolution - 1;
  4261. else
  4262. external_common_state->video_resolution =
  4263. HDMI_VFRMT_1920x1080p60_16_9;
  4264. #ifdef CONFIG_FB_MSM_HDMI_3D
  4265. external_common_state->switch_3d = hdmi_msm_switch_3d;
  4266. #endif
  4267. memset(external_common_state->spd_vendor_name, 0,
  4268. sizeof(external_common_state->spd_vendor_name));
  4269. memset(external_common_state->spd_product_description, 0,
  4270. sizeof(external_common_state->spd_product_description));
  4271. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  4272. hdmi_msm_state->cec_queue_start =
  4273. kzalloc(sizeof(struct hdmi_msm_cec_msg)*CEC_QUEUE_SIZE,
  4274. GFP_KERNEL);
  4275. if (!hdmi_msm_state->cec_queue_start) {
  4276. pr_err("hdmi_msm_init FAILED: CEC queue out of memory\n");
  4277. rc = -ENOMEM;
  4278. goto init_exit;
  4279. }
  4280. hdmi_msm_state->cec_queue_wr = hdmi_msm_state->cec_queue_start;
  4281. hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
  4282. hdmi_msm_state->cec_queue_full = false;
  4283. #endif
  4284. /*
  4285. * Create your work queue
  4286. * allocs and returns ptr
  4287. */
  4288. hdmi_work_queue = create_workqueue("hdmi_hdcp");
  4289. external_common_state->hpd_feature = hdmi_msm_hpd_feature;
  4290. rc = platform_driver_register(&this_driver);
  4291. if (rc) {
  4292. pr_err("hdmi_msm_init FAILED: platform_driver_register rc=%d\n",
  4293. rc);
  4294. goto init_exit;
  4295. }
  4296. hdmi_common_init_panel_info(&hdmi_msm_panel_data.panel_info);
  4297. init_completion(&hdmi_msm_state->ddc_sw_done);
  4298. init_completion(&hdmi_msm_state->hpd_event_processed);
  4299. INIT_WORK(&hdmi_msm_state->hpd_state_work, hdmi_msm_hpd_state_work);
  4300. #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
  4301. INIT_WORK(&hdmi_msm_state->cec_latch_detect_work,
  4302. hdmi_msm_cec_latch_work);
  4303. init_completion(&hdmi_msm_state->cec_frame_wr_done);
  4304. init_completion(&hdmi_msm_state->cec_line_latch_wait);
  4305. #endif
  4306. rc = platform_device_register(&this_device);
  4307. if (rc) {
  4308. pr_err("hdmi_msm_init FAILED: platform_device_register rc=%d\n",
  4309. rc);
  4310. platform_driver_unregister(&this_driver);
  4311. goto init_exit;
  4312. }
  4313. pr_debug("%s: success:"
  4314. #ifdef DEBUG
  4315. " DEBUG"
  4316. #else
  4317. " RELEASE"
  4318. #endif
  4319. " AUDIO EDID HPD HDCP"
  4320. " DVI"
  4321. #ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT
  4322. ":0"
  4323. #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT */
  4324. "\n", __func__);
  4325. return 0;
  4326. init_exit:
  4327. kfree(hdmi_msm_state);
  4328. hdmi_msm_state = NULL;
  4329. return rc;
  4330. }
  4331. static void __exit hdmi_msm_exit(void)
  4332. {
  4333. platform_device_unregister(&this_device);
  4334. platform_driver_unregister(&this_driver);
  4335. }
  4336. static int set_hdcp_feature_on(const char *val, const struct kernel_param *kp)
  4337. {
  4338. int rv = param_set_bool(val, kp);
  4339. if (rv)
  4340. return rv;
  4341. pr_debug("%s: HDCP feature = %d\n", __func__, hdcp_feature_on);
  4342. if (hdmi_msm_state) {
  4343. if ((HDMI_INP(0x0250) & 0x2)) {
  4344. pr_err("%s: Unable to set HDCP feature", __func__);
  4345. pr_err("%s: HDMI panel is currently turned on",
  4346. __func__);
  4347. } else if (hdcp_feature_on != hdmi_msm_state->hdcp_enable) {
  4348. hdmi_msm_config_hdcp_feature();
  4349. }
  4350. }
  4351. return 0;
  4352. }
  4353. static struct kernel_param_ops hdcp_feature_on_param_ops = {
  4354. .set = set_hdcp_feature_on,
  4355. .get = param_get_bool,
  4356. };
  4357. module_param_cb(hdcp, &hdcp_feature_on_param_ops, &hdcp_feature_on,
  4358. S_IRUGO | S_IWUSR);
  4359. MODULE_PARM_DESC(hdcp, "Enable or Disable HDCP");
  4360. module_init(hdmi_msm_init);
  4361. module_exit(hdmi_msm_exit);
  4362. MODULE_LICENSE("GPL v2");
  4363. MODULE_VERSION("0.3");
  4364. MODULE_AUTHOR("Qualcomm Innovation Center, Inc.");
  4365. MODULE_DESCRIPTION("HDMI MSM TX driver");