intel_ddi.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329
  1. /*
  2. * Copyright © 2012 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eugeni Dodonov <eugeni.dodonov@intel.com>
  25. *
  26. */
  27. #include "i915_drv.h"
  28. #include "intel_drv.h"
  29. struct ddi_buf_trans {
  30. u32 trans1; /* balance leg enable, de-emph level */
  31. u32 trans2; /* vref sel, vswing */
  32. u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */
  33. };
  34. /* HDMI/DVI modes ignore everything but the last 2 items. So we share
  35. * them for both DP and FDI transports, allowing those ports to
  36. * automatically adapt to HDMI connections as well
  37. */
  38. static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
  39. { 0x00FFFFFF, 0x0006000E, 0x0 },
  40. { 0x00D75FFF, 0x0005000A, 0x0 },
  41. { 0x00C30FFF, 0x00040006, 0x0 },
  42. { 0x80AAAFFF, 0x000B0000, 0x0 },
  43. { 0x00FFFFFF, 0x0005000A, 0x0 },
  44. { 0x00D75FFF, 0x000C0004, 0x0 },
  45. { 0x80C30FFF, 0x000B0000, 0x0 },
  46. { 0x00FFFFFF, 0x00040006, 0x0 },
  47. { 0x80D75FFF, 0x000B0000, 0x0 },
  48. };
  49. static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
  50. { 0x00FFFFFF, 0x0007000E, 0x0 },
  51. { 0x00D75FFF, 0x000F000A, 0x0 },
  52. { 0x00C30FFF, 0x00060006, 0x0 },
  53. { 0x00AAAFFF, 0x001E0000, 0x0 },
  54. { 0x00FFFFFF, 0x000F000A, 0x0 },
  55. { 0x00D75FFF, 0x00160004, 0x0 },
  56. { 0x00C30FFF, 0x001E0000, 0x0 },
  57. { 0x00FFFFFF, 0x00060006, 0x0 },
  58. { 0x00D75FFF, 0x001E0000, 0x0 },
  59. };
  60. static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
  61. /* Idx NT mV d T mV d db */
  62. { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */
  63. { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */
  64. { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */
  65. { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */
  66. { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */
  67. { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */
  68. { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */
  69. { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */
  70. { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */
  71. { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */
  72. { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */
  73. { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */
  74. };
  75. static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
  76. { 0x00FFFFFF, 0x00000012, 0x0 },
  77. { 0x00EBAFFF, 0x00020011, 0x0 },
  78. { 0x00C71FFF, 0x0006000F, 0x0 },
  79. { 0x00AAAFFF, 0x000E000A, 0x0 },
  80. { 0x00FFFFFF, 0x00020011, 0x0 },
  81. { 0x00DB6FFF, 0x0005000F, 0x0 },
  82. { 0x00BEEFFF, 0x000A000C, 0x0 },
  83. { 0x00FFFFFF, 0x0005000F, 0x0 },
  84. { 0x00DB6FFF, 0x000A000C, 0x0 },
  85. };
  86. static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
  87. { 0x00FFFFFF, 0x0007000E, 0x0 },
  88. { 0x00D75FFF, 0x000E000A, 0x0 },
  89. { 0x00BEFFFF, 0x00140006, 0x0 },
  90. { 0x80B2CFFF, 0x001B0002, 0x0 },
  91. { 0x00FFFFFF, 0x000E000A, 0x0 },
  92. { 0x00DB6FFF, 0x00160005, 0x0 },
  93. { 0x80C71FFF, 0x001A0002, 0x0 },
  94. { 0x00F7DFFF, 0x00180004, 0x0 },
  95. { 0x80D75FFF, 0x001B0002, 0x0 },
  96. };
  97. static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
  98. { 0x00FFFFFF, 0x0001000E, 0x0 },
  99. { 0x00D75FFF, 0x0004000A, 0x0 },
  100. { 0x00C30FFF, 0x00070006, 0x0 },
  101. { 0x00AAAFFF, 0x000C0000, 0x0 },
  102. { 0x00FFFFFF, 0x0004000A, 0x0 },
  103. { 0x00D75FFF, 0x00090004, 0x0 },
  104. { 0x00C30FFF, 0x000C0000, 0x0 },
  105. { 0x00FFFFFF, 0x00070006, 0x0 },
  106. { 0x00D75FFF, 0x000C0000, 0x0 },
  107. };
  108. static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
  109. /* Idx NT mV d T mV df db */
  110. { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */
  111. { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */
  112. { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */
  113. { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */
  114. { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */
  115. { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */
  116. { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */
  117. { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */
  118. { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */
  119. { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */
  120. };
  121. /* Skylake H and S */
  122. static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
  123. { 0x00002016, 0x000000A0, 0x0 },
  124. { 0x00005012, 0x0000009B, 0x0 },
  125. { 0x00007011, 0x00000088, 0x0 },
  126. { 0x00009010, 0x000000C7, 0x0 },
  127. { 0x00002016, 0x0000009B, 0x0 },
  128. { 0x00005012, 0x00000088, 0x0 },
  129. { 0x00007011, 0x000000C7, 0x0 },
  130. { 0x00002016, 0x000000DF, 0x0 },
  131. { 0x00005012, 0x000000C7, 0x0 },
  132. };
  133. /* Skylake U */
  134. static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
  135. { 0x0000201B, 0x000000A2, 0x0 },
  136. { 0x00005012, 0x00000088, 0x0 },
  137. { 0x00007011, 0x00000087, 0x0 },
  138. { 0x80009010, 0x000000C7, 0x1 }, /* Uses I_boost level 0x1 */
  139. { 0x0000201B, 0x0000009D, 0x0 },
  140. { 0x00005012, 0x000000C7, 0x0 },
  141. { 0x00007011, 0x000000C7, 0x0 },
  142. { 0x00002016, 0x00000088, 0x0 },
  143. { 0x00005012, 0x000000C7, 0x0 },
  144. };
  145. /* Skylake Y */
  146. static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
  147. { 0x00000018, 0x000000A2, 0x0 },
  148. { 0x00005012, 0x00000088, 0x0 },
  149. { 0x00007011, 0x00000087, 0x0 },
  150. { 0x80009010, 0x000000C7, 0x3 }, /* Uses I_boost level 0x3 */
  151. { 0x00000018, 0x0000009D, 0x0 },
  152. { 0x00005012, 0x000000C7, 0x0 },
  153. { 0x00007011, 0x000000C7, 0x0 },
  154. { 0x00000018, 0x00000088, 0x0 },
  155. { 0x00005012, 0x000000C7, 0x0 },
  156. };
  157. /*
  158. * Skylake H and S
  159. * eDP 1.4 low vswing translation parameters
  160. */
  161. static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
  162. { 0x00000018, 0x000000A8, 0x0 },
  163. { 0x00004013, 0x000000A9, 0x0 },
  164. { 0x00007011, 0x000000A2, 0x0 },
  165. { 0x00009010, 0x0000009C, 0x0 },
  166. { 0x00000018, 0x000000A9, 0x0 },
  167. { 0x00006013, 0x000000A2, 0x0 },
  168. { 0x00007011, 0x000000A6, 0x0 },
  169. { 0x00000018, 0x000000AB, 0x0 },
  170. { 0x00007013, 0x0000009F, 0x0 },
  171. { 0x00000018, 0x000000DF, 0x0 },
  172. };
  173. /*
  174. * Skylake U
  175. * eDP 1.4 low vswing translation parameters
  176. */
  177. static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
  178. { 0x00000018, 0x000000A8, 0x0 },
  179. { 0x00004013, 0x000000A9, 0x0 },
  180. { 0x00007011, 0x000000A2, 0x0 },
  181. { 0x00009010, 0x0000009C, 0x0 },
  182. { 0x00000018, 0x000000A9, 0x0 },
  183. { 0x00006013, 0x000000A2, 0x0 },
  184. { 0x00007011, 0x000000A6, 0x0 },
  185. { 0x00002016, 0x000000AB, 0x0 },
  186. { 0x00005013, 0x0000009F, 0x0 },
  187. { 0x00000018, 0x000000DF, 0x0 },
  188. };
  189. /*
  190. * Skylake Y
  191. * eDP 1.4 low vswing translation parameters
  192. */
  193. static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
  194. { 0x00000018, 0x000000A8, 0x0 },
  195. { 0x00004013, 0x000000AB, 0x0 },
  196. { 0x00007011, 0x000000A4, 0x0 },
  197. { 0x00009010, 0x000000DF, 0x0 },
  198. { 0x00000018, 0x000000AA, 0x0 },
  199. { 0x00006013, 0x000000A4, 0x0 },
  200. { 0x00007011, 0x0000009D, 0x0 },
  201. { 0x00000018, 0x000000A0, 0x0 },
  202. { 0x00006012, 0x000000DF, 0x0 },
  203. { 0x00000018, 0x0000008A, 0x0 },
  204. };
  205. /* Skylake U, H and S */
  206. static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
  207. { 0x00000018, 0x000000AC, 0x0 },
  208. { 0x00005012, 0x0000009D, 0x0 },
  209. { 0x00007011, 0x00000088, 0x0 },
  210. { 0x00000018, 0x000000A1, 0x0 },
  211. { 0x00000018, 0x00000098, 0x0 },
  212. { 0x00004013, 0x00000088, 0x0 },
  213. { 0x00006012, 0x00000087, 0x0 },
  214. { 0x00000018, 0x000000DF, 0x0 },
  215. { 0x00003015, 0x00000087, 0x0 }, /* Default */
  216. { 0x00003015, 0x000000C7, 0x0 },
  217. { 0x00000018, 0x000000C7, 0x0 },
  218. };
  219. /* Skylake Y */
  220. static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
  221. { 0x00000018, 0x000000A1, 0x0 },
  222. { 0x00005012, 0x000000DF, 0x0 },
  223. { 0x00007011, 0x00000084, 0x0 },
  224. { 0x00000018, 0x000000A4, 0x0 },
  225. { 0x00000018, 0x0000009D, 0x0 },
  226. { 0x00004013, 0x00000080, 0x0 },
  227. { 0x00006013, 0x000000C7, 0x0 },
  228. { 0x00000018, 0x0000008A, 0x0 },
  229. { 0x00003015, 0x000000C7, 0x0 }, /* Default */
  230. { 0x80003015, 0x000000C7, 0x7 }, /* Uses I_boost level 0x7 */
  231. { 0x00000018, 0x000000C7, 0x0 },
  232. };
  233. struct bxt_ddi_buf_trans {
  234. u32 margin; /* swing value */
  235. u32 scale; /* scale value */
  236. u32 enable; /* scale enable */
  237. u32 deemphasis;
  238. bool default_index; /* true if the entry represents default value */
  239. };
  240. static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
  241. /* Idx NT mV diff db */
  242. { 52, 0x9A, 0, 128, true }, /* 0: 400 0 */
  243. { 78, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
  244. { 104, 0x9A, 0, 64, false }, /* 2: 400 6 */
  245. { 154, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
  246. { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
  247. { 116, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
  248. { 154, 0x9A, 0, 64, false }, /* 6: 600 6 */
  249. { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
  250. { 154, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
  251. { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
  252. };
  253. static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
  254. /* Idx NT mV diff db */
  255. { 26, 0, 0, 128, false }, /* 0: 200 0 */
  256. { 38, 0, 0, 112, false }, /* 1: 200 1.5 */
  257. { 48, 0, 0, 96, false }, /* 2: 200 4 */
  258. { 54, 0, 0, 69, false }, /* 3: 200 6 */
  259. { 32, 0, 0, 128, false }, /* 4: 250 0 */
  260. { 48, 0, 0, 104, false }, /* 5: 250 1.5 */
  261. { 54, 0, 0, 85, false }, /* 6: 250 4 */
  262. { 43, 0, 0, 128, false }, /* 7: 300 0 */
  263. { 54, 0, 0, 101, false }, /* 8: 300 1.5 */
  264. { 48, 0, 0, 128, false }, /* 9: 300 0 */
  265. };
  266. /* BSpec has 2 recommended values - entries 0 and 8.
  267. * Using the entry with higher vswing.
  268. */
  269. static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
  270. /* Idx NT mV diff db */
  271. { 52, 0x9A, 0, 128, false }, /* 0: 400 0 */
  272. { 52, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
  273. { 52, 0x9A, 0, 64, false }, /* 2: 400 6 */
  274. { 42, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
  275. { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
  276. { 77, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
  277. { 77, 0x9A, 0, 64, false }, /* 6: 600 6 */
  278. { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
  279. { 102, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
  280. { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
  281. };
  282. static void bxt_ddi_vswing_sequence(struct drm_device *dev, u32 level,
  283. enum port port, int type);
  284. static void ddi_get_encoder_port(struct intel_encoder *intel_encoder,
  285. struct intel_digital_port **dig_port,
  286. enum port *port)
  287. {
  288. struct drm_encoder *encoder = &intel_encoder->base;
  289. switch (intel_encoder->type) {
  290. case INTEL_OUTPUT_DP_MST:
  291. *dig_port = enc_to_mst(encoder)->primary;
  292. *port = (*dig_port)->port;
  293. break;
  294. case INTEL_OUTPUT_DISPLAYPORT:
  295. case INTEL_OUTPUT_EDP:
  296. case INTEL_OUTPUT_HDMI:
  297. case INTEL_OUTPUT_UNKNOWN:
  298. *dig_port = enc_to_dig_port(encoder);
  299. *port = (*dig_port)->port;
  300. break;
  301. case INTEL_OUTPUT_ANALOG:
  302. *dig_port = NULL;
  303. *port = PORT_E;
  304. break;
  305. default:
  306. WARN(1, "Invalid DDI encoder type %d\n", intel_encoder->type);
  307. break;
  308. }
  309. }
  310. enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
  311. {
  312. struct intel_digital_port *dig_port;
  313. enum port port;
  314. ddi_get_encoder_port(intel_encoder, &dig_port, &port);
  315. return port;
  316. }
  317. static bool
  318. intel_dig_port_supports_hdmi(const struct intel_digital_port *intel_dig_port)
  319. {
  320. return intel_dig_port->hdmi.hdmi_reg;
  321. }
  322. static const struct ddi_buf_trans *skl_get_buf_trans_dp(struct drm_device *dev,
  323. int *n_entries)
  324. {
  325. const struct ddi_buf_trans *ddi_translations;
  326. if (IS_SKL_ULX(dev)) {
  327. ddi_translations = skl_y_ddi_translations_dp;
  328. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
  329. } else if (IS_SKL_ULT(dev)) {
  330. ddi_translations = skl_u_ddi_translations_dp;
  331. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
  332. } else {
  333. ddi_translations = skl_ddi_translations_dp;
  334. *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
  335. }
  336. return ddi_translations;
  337. }
  338. static const struct ddi_buf_trans *skl_get_buf_trans_edp(struct drm_device *dev,
  339. int *n_entries)
  340. {
  341. struct drm_i915_private *dev_priv = dev->dev_private;
  342. const struct ddi_buf_trans *ddi_translations;
  343. if (IS_SKL_ULX(dev)) {
  344. if (dev_priv->edp_low_vswing) {
  345. ddi_translations = skl_y_ddi_translations_edp;
  346. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
  347. } else {
  348. ddi_translations = skl_y_ddi_translations_dp;
  349. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
  350. }
  351. } else if (IS_SKL_ULT(dev)) {
  352. if (dev_priv->edp_low_vswing) {
  353. ddi_translations = skl_u_ddi_translations_edp;
  354. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
  355. } else {
  356. ddi_translations = skl_u_ddi_translations_dp;
  357. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
  358. }
  359. } else {
  360. if (dev_priv->edp_low_vswing) {
  361. ddi_translations = skl_ddi_translations_edp;
  362. *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
  363. } else {
  364. ddi_translations = skl_ddi_translations_dp;
  365. *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
  366. }
  367. }
  368. return ddi_translations;
  369. }
  370. static const struct ddi_buf_trans *
  371. skl_get_buf_trans_hdmi(struct drm_device *dev,
  372. int *n_entries)
  373. {
  374. const struct ddi_buf_trans *ddi_translations;
  375. if (IS_SKL_ULX(dev)) {
  376. ddi_translations = skl_y_ddi_translations_hdmi;
  377. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
  378. } else {
  379. ddi_translations = skl_ddi_translations_hdmi;
  380. *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
  381. }
  382. return ddi_translations;
  383. }
  384. /*
  385. * Starting with Haswell, DDI port buffers must be programmed with correct
  386. * values in advance. The buffer values are different for FDI and DP modes,
  387. * but the HDMI/DVI fields are shared among those. So we program the DDI
  388. * in either FDI or DP modes only, as HDMI connections will work with both
  389. * of those
  390. */
  391. static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port,
  392. bool supports_hdmi)
  393. {
  394. struct drm_i915_private *dev_priv = dev->dev_private;
  395. u32 iboost_bit = 0;
  396. int i, n_hdmi_entries, n_dp_entries, n_edp_entries, hdmi_default_entry,
  397. size;
  398. int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
  399. const struct ddi_buf_trans *ddi_translations_fdi;
  400. const struct ddi_buf_trans *ddi_translations_dp;
  401. const struct ddi_buf_trans *ddi_translations_edp;
  402. const struct ddi_buf_trans *ddi_translations_hdmi;
  403. const struct ddi_buf_trans *ddi_translations;
  404. if (IS_BROXTON(dev)) {
  405. if (!supports_hdmi)
  406. return;
  407. /* Vswing programming for HDMI */
  408. bxt_ddi_vswing_sequence(dev, hdmi_level, port,
  409. INTEL_OUTPUT_HDMI);
  410. return;
  411. } else if (IS_SKYLAKE(dev)) {
  412. ddi_translations_fdi = NULL;
  413. ddi_translations_dp =
  414. skl_get_buf_trans_dp(dev, &n_dp_entries);
  415. ddi_translations_edp =
  416. skl_get_buf_trans_edp(dev, &n_edp_entries);
  417. ddi_translations_hdmi =
  418. skl_get_buf_trans_hdmi(dev, &n_hdmi_entries);
  419. hdmi_default_entry = 8;
  420. /* If we're boosting the current, set bit 31 of trans1 */
  421. if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level ||
  422. dev_priv->vbt.ddi_port_info[port].dp_boost_level)
  423. iboost_bit = 1<<31;
  424. } else if (IS_BROADWELL(dev)) {
  425. ddi_translations_fdi = bdw_ddi_translations_fdi;
  426. ddi_translations_dp = bdw_ddi_translations_dp;
  427. if (dev_priv->edp_low_vswing) {
  428. ddi_translations_edp = bdw_ddi_translations_edp;
  429. n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
  430. } else {
  431. ddi_translations_edp = bdw_ddi_translations_dp;
  432. n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  433. }
  434. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  435. n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  436. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  437. hdmi_default_entry = 7;
  438. } else if (IS_HASWELL(dev)) {
  439. ddi_translations_fdi = hsw_ddi_translations_fdi;
  440. ddi_translations_dp = hsw_ddi_translations_dp;
  441. ddi_translations_edp = hsw_ddi_translations_dp;
  442. ddi_translations_hdmi = hsw_ddi_translations_hdmi;
  443. n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
  444. n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
  445. hdmi_default_entry = 6;
  446. } else {
  447. WARN(1, "ddi translation table missing\n");
  448. ddi_translations_edp = bdw_ddi_translations_dp;
  449. ddi_translations_fdi = bdw_ddi_translations_fdi;
  450. ddi_translations_dp = bdw_ddi_translations_dp;
  451. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  452. n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
  453. n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  454. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  455. hdmi_default_entry = 7;
  456. }
  457. switch (port) {
  458. case PORT_A:
  459. ddi_translations = ddi_translations_edp;
  460. size = n_edp_entries;
  461. break;
  462. case PORT_B:
  463. case PORT_C:
  464. ddi_translations = ddi_translations_dp;
  465. size = n_dp_entries;
  466. break;
  467. case PORT_D:
  468. if (intel_dp_is_edp(dev, PORT_D)) {
  469. ddi_translations = ddi_translations_edp;
  470. size = n_edp_entries;
  471. } else {
  472. ddi_translations = ddi_translations_dp;
  473. size = n_dp_entries;
  474. }
  475. break;
  476. case PORT_E:
  477. if (ddi_translations_fdi)
  478. ddi_translations = ddi_translations_fdi;
  479. else
  480. ddi_translations = ddi_translations_dp;
  481. size = n_dp_entries;
  482. break;
  483. default:
  484. BUG();
  485. }
  486. for (i = 0; i < size; i++) {
  487. I915_WRITE(DDI_BUF_TRANS_LO(port, i),
  488. ddi_translations[i].trans1 | iboost_bit);
  489. I915_WRITE(DDI_BUF_TRANS_HI(port, i),
  490. ddi_translations[i].trans2);
  491. }
  492. if (!supports_hdmi)
  493. return;
  494. /* Choose a good default if VBT is badly populated */
  495. if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
  496. hdmi_level >= n_hdmi_entries)
  497. hdmi_level = hdmi_default_entry;
  498. /* Entry 9 is for HDMI: */
  499. I915_WRITE(DDI_BUF_TRANS_LO(port, i),
  500. ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
  501. I915_WRITE(DDI_BUF_TRANS_HI(port, i),
  502. ddi_translations_hdmi[hdmi_level].trans2);
  503. }
  504. /* Program DDI buffers translations for DP. By default, program ports A-D in DP
  505. * mode and port E for FDI.
  506. */
  507. void intel_prepare_ddi(struct drm_device *dev)
  508. {
  509. struct intel_encoder *intel_encoder;
  510. bool visited[I915_MAX_PORTS] = { 0, };
  511. if (!HAS_DDI(dev))
  512. return;
  513. for_each_intel_encoder(dev, intel_encoder) {
  514. struct intel_digital_port *intel_dig_port;
  515. enum port port;
  516. bool supports_hdmi;
  517. if (intel_encoder->type == INTEL_OUTPUT_DSI)
  518. continue;
  519. ddi_get_encoder_port(intel_encoder, &intel_dig_port, &port);
  520. if (visited[port])
  521. continue;
  522. supports_hdmi = intel_dig_port &&
  523. intel_dig_port_supports_hdmi(intel_dig_port);
  524. intel_prepare_ddi_buffers(dev, port, supports_hdmi);
  525. visited[port] = true;
  526. }
  527. }
  528. static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
  529. enum port port)
  530. {
  531. uint32_t reg = DDI_BUF_CTL(port);
  532. int i;
  533. for (i = 0; i < 16; i++) {
  534. udelay(1);
  535. if (I915_READ(reg) & DDI_BUF_IS_IDLE)
  536. return;
  537. }
  538. DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
  539. }
  540. /* Starting with Haswell, different DDI ports can work in FDI mode for
  541. * connection to the PCH-located connectors. For this, it is necessary to train
  542. * both the DDI port and PCH receiver for the desired DDI buffer settings.
  543. *
  544. * The recommended port to work in FDI mode is DDI E, which we use here. Also,
  545. * please note that when FDI mode is active on DDI E, it shares 2 lines with
  546. * DDI A (which is used for eDP)
  547. */
  548. void hsw_fdi_link_train(struct drm_crtc *crtc)
  549. {
  550. struct drm_device *dev = crtc->dev;
  551. struct drm_i915_private *dev_priv = dev->dev_private;
  552. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  553. u32 temp, i, rx_ctl_val;
  554. /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
  555. * mode set "sequence for CRT port" document:
  556. * - TP1 to TP2 time with the default value
  557. * - FDI delay to 90h
  558. *
  559. * WaFDIAutoLinkSetTimingOverrride:hsw
  560. */
  561. I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
  562. FDI_RX_PWRDN_LANE0_VAL(2) |
  563. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  564. /* Enable the PCH Receiver FDI PLL */
  565. rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
  566. FDI_RX_PLL_ENABLE |
  567. FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
  568. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  569. POSTING_READ(FDI_RX_CTL(PIPE_A));
  570. udelay(220);
  571. /* Switch from Rawclk to PCDclk */
  572. rx_ctl_val |= FDI_PCDCLK;
  573. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  574. /* Configure Port Clock Select */
  575. I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->config->ddi_pll_sel);
  576. WARN_ON(intel_crtc->config->ddi_pll_sel != PORT_CLK_SEL_SPLL);
  577. /* Start the training iterating through available voltages and emphasis,
  578. * testing each value twice. */
  579. for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
  580. /* Configure DP_TP_CTL with auto-training */
  581. I915_WRITE(DP_TP_CTL(PORT_E),
  582. DP_TP_CTL_FDI_AUTOTRAIN |
  583. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  584. DP_TP_CTL_LINK_TRAIN_PAT1 |
  585. DP_TP_CTL_ENABLE);
  586. /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
  587. * DDI E does not support port reversal, the functionality is
  588. * achieved on the PCH side in FDI_RX_CTL, so no need to set the
  589. * port reversal bit */
  590. I915_WRITE(DDI_BUF_CTL(PORT_E),
  591. DDI_BUF_CTL_ENABLE |
  592. ((intel_crtc->config->fdi_lanes - 1) << 1) |
  593. DDI_BUF_TRANS_SELECT(i / 2));
  594. POSTING_READ(DDI_BUF_CTL(PORT_E));
  595. udelay(600);
  596. /* Program PCH FDI Receiver TU */
  597. I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
  598. /* Enable PCH FDI Receiver with auto-training */
  599. rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
  600. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  601. POSTING_READ(FDI_RX_CTL(PIPE_A));
  602. /* Wait for FDI receiver lane calibration */
  603. udelay(30);
  604. /* Unset FDI_RX_MISC pwrdn lanes */
  605. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  606. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  607. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  608. POSTING_READ(FDI_RX_MISC(PIPE_A));
  609. /* Wait for FDI auto training time */
  610. udelay(5);
  611. temp = I915_READ(DP_TP_STATUS(PORT_E));
  612. if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
  613. DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
  614. /* Enable normal pixel sending for FDI */
  615. I915_WRITE(DP_TP_CTL(PORT_E),
  616. DP_TP_CTL_FDI_AUTOTRAIN |
  617. DP_TP_CTL_LINK_TRAIN_NORMAL |
  618. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  619. DP_TP_CTL_ENABLE);
  620. return;
  621. }
  622. temp = I915_READ(DDI_BUF_CTL(PORT_E));
  623. temp &= ~DDI_BUF_CTL_ENABLE;
  624. I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
  625. POSTING_READ(DDI_BUF_CTL(PORT_E));
  626. /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
  627. temp = I915_READ(DP_TP_CTL(PORT_E));
  628. temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  629. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  630. I915_WRITE(DP_TP_CTL(PORT_E), temp);
  631. POSTING_READ(DP_TP_CTL(PORT_E));
  632. intel_wait_ddi_buf_idle(dev_priv, PORT_E);
  633. rx_ctl_val &= ~FDI_RX_ENABLE;
  634. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  635. POSTING_READ(FDI_RX_CTL(PIPE_A));
  636. /* Reset FDI_RX_MISC pwrdn lanes */
  637. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  638. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  639. temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  640. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  641. POSTING_READ(FDI_RX_MISC(PIPE_A));
  642. }
  643. DRM_ERROR("FDI link training failed!\n");
  644. }
  645. void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
  646. {
  647. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  648. struct intel_digital_port *intel_dig_port =
  649. enc_to_dig_port(&encoder->base);
  650. intel_dp->DP = intel_dig_port->saved_port_bits |
  651. DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
  652. intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
  653. }
  654. static struct intel_encoder *
  655. intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
  656. {
  657. struct drm_device *dev = crtc->dev;
  658. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  659. struct intel_encoder *intel_encoder, *ret = NULL;
  660. int num_encoders = 0;
  661. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  662. ret = intel_encoder;
  663. num_encoders++;
  664. }
  665. if (num_encoders != 1)
  666. WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
  667. pipe_name(intel_crtc->pipe));
  668. BUG_ON(ret == NULL);
  669. return ret;
  670. }
  671. struct intel_encoder *
  672. intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
  673. {
  674. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  675. struct intel_encoder *ret = NULL;
  676. struct drm_atomic_state *state;
  677. struct drm_connector *connector;
  678. struct drm_connector_state *connector_state;
  679. int num_encoders = 0;
  680. int i;
  681. state = crtc_state->base.state;
  682. for_each_connector_in_state(state, connector, connector_state, i) {
  683. if (connector_state->crtc != crtc_state->base.crtc)
  684. continue;
  685. ret = to_intel_encoder(connector_state->best_encoder);
  686. num_encoders++;
  687. }
  688. WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
  689. pipe_name(crtc->pipe));
  690. BUG_ON(ret == NULL);
  691. return ret;
  692. }
  693. #define LC_FREQ 2700
  694. #define LC_FREQ_2K U64_C(LC_FREQ * 2000)
  695. #define P_MIN 2
  696. #define P_MAX 64
  697. #define P_INC 2
  698. /* Constraints for PLL good behavior */
  699. #define REF_MIN 48
  700. #define REF_MAX 400
  701. #define VCO_MIN 2400
  702. #define VCO_MAX 4800
  703. #define abs_diff(a, b) ({ \
  704. typeof(a) __a = (a); \
  705. typeof(b) __b = (b); \
  706. (void) (&__a == &__b); \
  707. __a > __b ? (__a - __b) : (__b - __a); })
  708. struct hsw_wrpll_rnp {
  709. unsigned p, n2, r2;
  710. };
  711. static unsigned hsw_wrpll_get_budget_for_freq(int clock)
  712. {
  713. unsigned budget;
  714. switch (clock) {
  715. case 25175000:
  716. case 25200000:
  717. case 27000000:
  718. case 27027000:
  719. case 37762500:
  720. case 37800000:
  721. case 40500000:
  722. case 40541000:
  723. case 54000000:
  724. case 54054000:
  725. case 59341000:
  726. case 59400000:
  727. case 72000000:
  728. case 74176000:
  729. case 74250000:
  730. case 81000000:
  731. case 81081000:
  732. case 89012000:
  733. case 89100000:
  734. case 108000000:
  735. case 108108000:
  736. case 111264000:
  737. case 111375000:
  738. case 148352000:
  739. case 148500000:
  740. case 162000000:
  741. case 162162000:
  742. case 222525000:
  743. case 222750000:
  744. case 296703000:
  745. case 297000000:
  746. budget = 0;
  747. break;
  748. case 233500000:
  749. case 245250000:
  750. case 247750000:
  751. case 253250000:
  752. case 298000000:
  753. budget = 1500;
  754. break;
  755. case 169128000:
  756. case 169500000:
  757. case 179500000:
  758. case 202000000:
  759. budget = 2000;
  760. break;
  761. case 256250000:
  762. case 262500000:
  763. case 270000000:
  764. case 272500000:
  765. case 273750000:
  766. case 280750000:
  767. case 281250000:
  768. case 286000000:
  769. case 291750000:
  770. budget = 4000;
  771. break;
  772. case 267250000:
  773. case 268500000:
  774. budget = 5000;
  775. break;
  776. default:
  777. budget = 1000;
  778. break;
  779. }
  780. return budget;
  781. }
  782. static void hsw_wrpll_update_rnp(uint64_t freq2k, unsigned budget,
  783. unsigned r2, unsigned n2, unsigned p,
  784. struct hsw_wrpll_rnp *best)
  785. {
  786. uint64_t a, b, c, d, diff, diff_best;
  787. /* No best (r,n,p) yet */
  788. if (best->p == 0) {
  789. best->p = p;
  790. best->n2 = n2;
  791. best->r2 = r2;
  792. return;
  793. }
  794. /*
  795. * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
  796. * freq2k.
  797. *
  798. * delta = 1e6 *
  799. * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
  800. * freq2k;
  801. *
  802. * and we would like delta <= budget.
  803. *
  804. * If the discrepancy is above the PPM-based budget, always prefer to
  805. * improve upon the previous solution. However, if you're within the
  806. * budget, try to maximize Ref * VCO, that is N / (P * R^2).
  807. */
  808. a = freq2k * budget * p * r2;
  809. b = freq2k * budget * best->p * best->r2;
  810. diff = abs_diff(freq2k * p * r2, LC_FREQ_2K * n2);
  811. diff_best = abs_diff(freq2k * best->p * best->r2,
  812. LC_FREQ_2K * best->n2);
  813. c = 1000000 * diff;
  814. d = 1000000 * diff_best;
  815. if (a < c && b < d) {
  816. /* If both are above the budget, pick the closer */
  817. if (best->p * best->r2 * diff < p * r2 * diff_best) {
  818. best->p = p;
  819. best->n2 = n2;
  820. best->r2 = r2;
  821. }
  822. } else if (a >= c && b < d) {
  823. /* If A is below the threshold but B is above it? Update. */
  824. best->p = p;
  825. best->n2 = n2;
  826. best->r2 = r2;
  827. } else if (a >= c && b >= d) {
  828. /* Both are below the limit, so pick the higher n2/(r2*r2) */
  829. if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
  830. best->p = p;
  831. best->n2 = n2;
  832. best->r2 = r2;
  833. }
  834. }
  835. /* Otherwise a < c && b >= d, do nothing */
  836. }
  837. static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv, int reg)
  838. {
  839. int refclk = LC_FREQ;
  840. int n, p, r;
  841. u32 wrpll;
  842. wrpll = I915_READ(reg);
  843. switch (wrpll & WRPLL_PLL_REF_MASK) {
  844. case WRPLL_PLL_SSC:
  845. case WRPLL_PLL_NON_SSC:
  846. /*
  847. * We could calculate spread here, but our checking
  848. * code only cares about 5% accuracy, and spread is a max of
  849. * 0.5% downspread.
  850. */
  851. refclk = 135;
  852. break;
  853. case WRPLL_PLL_LCPLL:
  854. refclk = LC_FREQ;
  855. break;
  856. default:
  857. WARN(1, "bad wrpll refclk\n");
  858. return 0;
  859. }
  860. r = wrpll & WRPLL_DIVIDER_REF_MASK;
  861. p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
  862. n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
  863. /* Convert to KHz, p & r have a fixed point portion */
  864. return (refclk * n * 100) / (p * r);
  865. }
  866. static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
  867. uint32_t dpll)
  868. {
  869. uint32_t cfgcr1_reg, cfgcr2_reg;
  870. uint32_t cfgcr1_val, cfgcr2_val;
  871. uint32_t p0, p1, p2, dco_freq;
  872. cfgcr1_reg = DPLL_CFGCR1(dpll);
  873. cfgcr2_reg = DPLL_CFGCR2(dpll);
  874. cfgcr1_val = I915_READ(cfgcr1_reg);
  875. cfgcr2_val = I915_READ(cfgcr2_reg);
  876. p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
  877. p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
  878. if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
  879. p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
  880. else
  881. p1 = 1;
  882. switch (p0) {
  883. case DPLL_CFGCR2_PDIV_1:
  884. p0 = 1;
  885. break;
  886. case DPLL_CFGCR2_PDIV_2:
  887. p0 = 2;
  888. break;
  889. case DPLL_CFGCR2_PDIV_3:
  890. p0 = 3;
  891. break;
  892. case DPLL_CFGCR2_PDIV_7:
  893. p0 = 7;
  894. break;
  895. }
  896. switch (p2) {
  897. case DPLL_CFGCR2_KDIV_5:
  898. p2 = 5;
  899. break;
  900. case DPLL_CFGCR2_KDIV_2:
  901. p2 = 2;
  902. break;
  903. case DPLL_CFGCR2_KDIV_3:
  904. p2 = 3;
  905. break;
  906. case DPLL_CFGCR2_KDIV_1:
  907. p2 = 1;
  908. break;
  909. }
  910. dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
  911. dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
  912. 1000) / 0x8000;
  913. return dco_freq / (p0 * p1 * p2 * 5);
  914. }
  915. static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
  916. {
  917. int dotclock;
  918. if (pipe_config->has_pch_encoder)
  919. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  920. &pipe_config->fdi_m_n);
  921. else if (pipe_config->has_dp_encoder)
  922. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  923. &pipe_config->dp_m_n);
  924. else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
  925. dotclock = pipe_config->port_clock * 2 / 3;
  926. else
  927. dotclock = pipe_config->port_clock;
  928. if (pipe_config->pixel_multiplier)
  929. dotclock /= pipe_config->pixel_multiplier;
  930. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  931. }
  932. static void skl_ddi_clock_get(struct intel_encoder *encoder,
  933. struct intel_crtc_state *pipe_config)
  934. {
  935. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  936. int link_clock = 0;
  937. uint32_t dpll_ctl1, dpll;
  938. dpll = pipe_config->ddi_pll_sel;
  939. dpll_ctl1 = I915_READ(DPLL_CTRL1);
  940. if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
  941. link_clock = skl_calc_wrpll_link(dev_priv, dpll);
  942. } else {
  943. link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
  944. link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
  945. switch (link_clock) {
  946. case DPLL_CTRL1_LINK_RATE_810:
  947. link_clock = 81000;
  948. break;
  949. case DPLL_CTRL1_LINK_RATE_1080:
  950. link_clock = 108000;
  951. break;
  952. case DPLL_CTRL1_LINK_RATE_1350:
  953. link_clock = 135000;
  954. break;
  955. case DPLL_CTRL1_LINK_RATE_1620:
  956. link_clock = 162000;
  957. break;
  958. case DPLL_CTRL1_LINK_RATE_2160:
  959. link_clock = 216000;
  960. break;
  961. case DPLL_CTRL1_LINK_RATE_2700:
  962. link_clock = 270000;
  963. break;
  964. default:
  965. WARN(1, "Unsupported link rate\n");
  966. break;
  967. }
  968. link_clock *= 2;
  969. }
  970. pipe_config->port_clock = link_clock;
  971. ddi_dotclock_get(pipe_config);
  972. }
  973. static void hsw_ddi_clock_get(struct intel_encoder *encoder,
  974. struct intel_crtc_state *pipe_config)
  975. {
  976. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  977. int link_clock = 0;
  978. u32 val, pll;
  979. val = pipe_config->ddi_pll_sel;
  980. switch (val & PORT_CLK_SEL_MASK) {
  981. case PORT_CLK_SEL_LCPLL_810:
  982. link_clock = 81000;
  983. break;
  984. case PORT_CLK_SEL_LCPLL_1350:
  985. link_clock = 135000;
  986. break;
  987. case PORT_CLK_SEL_LCPLL_2700:
  988. link_clock = 270000;
  989. break;
  990. case PORT_CLK_SEL_WRPLL1:
  991. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
  992. break;
  993. case PORT_CLK_SEL_WRPLL2:
  994. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
  995. break;
  996. case PORT_CLK_SEL_SPLL:
  997. pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
  998. if (pll == SPLL_PLL_FREQ_810MHz)
  999. link_clock = 81000;
  1000. else if (pll == SPLL_PLL_FREQ_1350MHz)
  1001. link_clock = 135000;
  1002. else if (pll == SPLL_PLL_FREQ_2700MHz)
  1003. link_clock = 270000;
  1004. else {
  1005. WARN(1, "bad spll freq\n");
  1006. return;
  1007. }
  1008. break;
  1009. default:
  1010. WARN(1, "bad port clock sel\n");
  1011. return;
  1012. }
  1013. pipe_config->port_clock = link_clock * 2;
  1014. ddi_dotclock_get(pipe_config);
  1015. }
  1016. static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
  1017. enum intel_dpll_id dpll)
  1018. {
  1019. struct intel_shared_dpll *pll;
  1020. struct intel_dpll_hw_state *state;
  1021. intel_clock_t clock;
  1022. /* For DDI ports we always use a shared PLL. */
  1023. if (WARN_ON(dpll == DPLL_ID_PRIVATE))
  1024. return 0;
  1025. pll = &dev_priv->shared_dplls[dpll];
  1026. state = &pll->config.hw_state;
  1027. clock.m1 = 2;
  1028. clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
  1029. if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
  1030. clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
  1031. clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
  1032. clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
  1033. clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
  1034. return chv_calc_dpll_params(100000, &clock);
  1035. }
  1036. static void bxt_ddi_clock_get(struct intel_encoder *encoder,
  1037. struct intel_crtc_state *pipe_config)
  1038. {
  1039. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  1040. enum port port = intel_ddi_get_encoder_port(encoder);
  1041. uint32_t dpll = port;
  1042. pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
  1043. ddi_dotclock_get(pipe_config);
  1044. }
  1045. void intel_ddi_clock_get(struct intel_encoder *encoder,
  1046. struct intel_crtc_state *pipe_config)
  1047. {
  1048. struct drm_device *dev = encoder->base.dev;
  1049. if (INTEL_INFO(dev)->gen <= 8)
  1050. hsw_ddi_clock_get(encoder, pipe_config);
  1051. else if (IS_SKYLAKE(dev))
  1052. skl_ddi_clock_get(encoder, pipe_config);
  1053. else if (IS_BROXTON(dev))
  1054. bxt_ddi_clock_get(encoder, pipe_config);
  1055. }
  1056. static void
  1057. hsw_ddi_calculate_wrpll(int clock /* in Hz */,
  1058. unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
  1059. {
  1060. uint64_t freq2k;
  1061. unsigned p, n2, r2;
  1062. struct hsw_wrpll_rnp best = { 0, 0, 0 };
  1063. unsigned budget;
  1064. freq2k = clock / 100;
  1065. budget = hsw_wrpll_get_budget_for_freq(clock);
  1066. /* Special case handling for 540 pixel clock: bypass WR PLL entirely
  1067. * and directly pass the LC PLL to it. */
  1068. if (freq2k == 5400000) {
  1069. *n2_out = 2;
  1070. *p_out = 1;
  1071. *r2_out = 2;
  1072. return;
  1073. }
  1074. /*
  1075. * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
  1076. * the WR PLL.
  1077. *
  1078. * We want R so that REF_MIN <= Ref <= REF_MAX.
  1079. * Injecting R2 = 2 * R gives:
  1080. * REF_MAX * r2 > LC_FREQ * 2 and
  1081. * REF_MIN * r2 < LC_FREQ * 2
  1082. *
  1083. * Which means the desired boundaries for r2 are:
  1084. * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
  1085. *
  1086. */
  1087. for (r2 = LC_FREQ * 2 / REF_MAX + 1;
  1088. r2 <= LC_FREQ * 2 / REF_MIN;
  1089. r2++) {
  1090. /*
  1091. * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
  1092. *
  1093. * Once again we want VCO_MIN <= VCO <= VCO_MAX.
  1094. * Injecting R2 = 2 * R and N2 = 2 * N, we get:
  1095. * VCO_MAX * r2 > n2 * LC_FREQ and
  1096. * VCO_MIN * r2 < n2 * LC_FREQ)
  1097. *
  1098. * Which means the desired boundaries for n2 are:
  1099. * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
  1100. */
  1101. for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
  1102. n2 <= VCO_MAX * r2 / LC_FREQ;
  1103. n2++) {
  1104. for (p = P_MIN; p <= P_MAX; p += P_INC)
  1105. hsw_wrpll_update_rnp(freq2k, budget,
  1106. r2, n2, p, &best);
  1107. }
  1108. }
  1109. *n2_out = best.n2;
  1110. *p_out = best.p;
  1111. *r2_out = best.r2;
  1112. }
  1113. static bool
  1114. hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
  1115. struct intel_crtc_state *crtc_state,
  1116. struct intel_encoder *intel_encoder)
  1117. {
  1118. int clock = crtc_state->port_clock;
  1119. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  1120. struct intel_shared_dpll *pll;
  1121. uint32_t val;
  1122. unsigned p, n2, r2;
  1123. hsw_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
  1124. val = WRPLL_PLL_ENABLE | WRPLL_PLL_LCPLL |
  1125. WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
  1126. WRPLL_DIVIDER_POST(p);
  1127. memset(&crtc_state->dpll_hw_state, 0,
  1128. sizeof(crtc_state->dpll_hw_state));
  1129. crtc_state->dpll_hw_state.wrpll = val;
  1130. pll = intel_get_shared_dpll(intel_crtc, crtc_state);
  1131. if (pll == NULL) {
  1132. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  1133. pipe_name(intel_crtc->pipe));
  1134. return false;
  1135. }
  1136. crtc_state->ddi_pll_sel = PORT_CLK_SEL_WRPLL(pll->id);
  1137. } else if (crtc_state->ddi_pll_sel == PORT_CLK_SEL_SPLL) {
  1138. struct drm_atomic_state *state = crtc_state->base.state;
  1139. struct intel_shared_dpll_config *spll =
  1140. &intel_atomic_get_shared_dpll_state(state)[DPLL_ID_SPLL];
  1141. if (spll->crtc_mask &&
  1142. WARN_ON(spll->hw_state.spll != crtc_state->dpll_hw_state.spll))
  1143. return false;
  1144. crtc_state->shared_dpll = DPLL_ID_SPLL;
  1145. spll->hw_state.spll = crtc_state->dpll_hw_state.spll;
  1146. spll->crtc_mask |= 1 << intel_crtc->pipe;
  1147. }
  1148. return true;
  1149. }
  1150. struct skl_wrpll_context {
  1151. uint64_t min_deviation; /* current minimal deviation */
  1152. uint64_t central_freq; /* chosen central freq */
  1153. uint64_t dco_freq; /* chosen dco freq */
  1154. unsigned int p; /* chosen divider */
  1155. };
  1156. static void skl_wrpll_context_init(struct skl_wrpll_context *ctx)
  1157. {
  1158. memset(ctx, 0, sizeof(*ctx));
  1159. ctx->min_deviation = U64_MAX;
  1160. }
  1161. /* DCO freq must be within +1%/-6% of the DCO central freq */
  1162. #define SKL_DCO_MAX_PDEVIATION 100
  1163. #define SKL_DCO_MAX_NDEVIATION 600
  1164. static void skl_wrpll_try_divider(struct skl_wrpll_context *ctx,
  1165. uint64_t central_freq,
  1166. uint64_t dco_freq,
  1167. unsigned int divider)
  1168. {
  1169. uint64_t deviation;
  1170. deviation = div64_u64(10000 * abs_diff(dco_freq, central_freq),
  1171. central_freq);
  1172. /* positive deviation */
  1173. if (dco_freq >= central_freq) {
  1174. if (deviation < SKL_DCO_MAX_PDEVIATION &&
  1175. deviation < ctx->min_deviation) {
  1176. ctx->min_deviation = deviation;
  1177. ctx->central_freq = central_freq;
  1178. ctx->dco_freq = dco_freq;
  1179. ctx->p = divider;
  1180. }
  1181. /* negative deviation */
  1182. } else if (deviation < SKL_DCO_MAX_NDEVIATION &&
  1183. deviation < ctx->min_deviation) {
  1184. ctx->min_deviation = deviation;
  1185. ctx->central_freq = central_freq;
  1186. ctx->dco_freq = dco_freq;
  1187. ctx->p = divider;
  1188. }
  1189. }
  1190. static void skl_wrpll_get_multipliers(unsigned int p,
  1191. unsigned int *p0 /* out */,
  1192. unsigned int *p1 /* out */,
  1193. unsigned int *p2 /* out */)
  1194. {
  1195. /* even dividers */
  1196. if (p % 2 == 0) {
  1197. unsigned int half = p / 2;
  1198. if (half == 1 || half == 2 || half == 3 || half == 5) {
  1199. *p0 = 2;
  1200. *p1 = 1;
  1201. *p2 = half;
  1202. } else if (half % 2 == 0) {
  1203. *p0 = 2;
  1204. *p1 = half / 2;
  1205. *p2 = 2;
  1206. } else if (half % 3 == 0) {
  1207. *p0 = 3;
  1208. *p1 = half / 3;
  1209. *p2 = 2;
  1210. } else if (half % 7 == 0) {
  1211. *p0 = 7;
  1212. *p1 = half / 7;
  1213. *p2 = 2;
  1214. }
  1215. } else if (p == 3 || p == 9) { /* 3, 5, 7, 9, 15, 21, 35 */
  1216. *p0 = 3;
  1217. *p1 = 1;
  1218. *p2 = p / 3;
  1219. } else if (p == 5 || p == 7) {
  1220. *p0 = p;
  1221. *p1 = 1;
  1222. *p2 = 1;
  1223. } else if (p == 15) {
  1224. *p0 = 3;
  1225. *p1 = 1;
  1226. *p2 = 5;
  1227. } else if (p == 21) {
  1228. *p0 = 7;
  1229. *p1 = 1;
  1230. *p2 = 3;
  1231. } else if (p == 35) {
  1232. *p0 = 7;
  1233. *p1 = 1;
  1234. *p2 = 5;
  1235. }
  1236. }
  1237. struct skl_wrpll_params {
  1238. uint32_t dco_fraction;
  1239. uint32_t dco_integer;
  1240. uint32_t qdiv_ratio;
  1241. uint32_t qdiv_mode;
  1242. uint32_t kdiv;
  1243. uint32_t pdiv;
  1244. uint32_t central_freq;
  1245. };
  1246. static void skl_wrpll_params_populate(struct skl_wrpll_params *params,
  1247. uint64_t afe_clock,
  1248. uint64_t central_freq,
  1249. uint32_t p0, uint32_t p1, uint32_t p2)
  1250. {
  1251. uint64_t dco_freq;
  1252. switch (central_freq) {
  1253. case 9600000000ULL:
  1254. params->central_freq = 0;
  1255. break;
  1256. case 9000000000ULL:
  1257. params->central_freq = 1;
  1258. break;
  1259. case 8400000000ULL:
  1260. params->central_freq = 3;
  1261. }
  1262. switch (p0) {
  1263. case 1:
  1264. params->pdiv = 0;
  1265. break;
  1266. case 2:
  1267. params->pdiv = 1;
  1268. break;
  1269. case 3:
  1270. params->pdiv = 2;
  1271. break;
  1272. case 7:
  1273. params->pdiv = 4;
  1274. break;
  1275. default:
  1276. WARN(1, "Incorrect PDiv\n");
  1277. }
  1278. switch (p2) {
  1279. case 5:
  1280. params->kdiv = 0;
  1281. break;
  1282. case 2:
  1283. params->kdiv = 1;
  1284. break;
  1285. case 3:
  1286. params->kdiv = 2;
  1287. break;
  1288. case 1:
  1289. params->kdiv = 3;
  1290. break;
  1291. default:
  1292. WARN(1, "Incorrect KDiv\n");
  1293. }
  1294. params->qdiv_ratio = p1;
  1295. params->qdiv_mode = (params->qdiv_ratio == 1) ? 0 : 1;
  1296. dco_freq = p0 * p1 * p2 * afe_clock;
  1297. /*
  1298. * Intermediate values are in Hz.
  1299. * Divide by MHz to match bsepc
  1300. */
  1301. params->dco_integer = div_u64(dco_freq, 24 * MHz(1));
  1302. params->dco_fraction =
  1303. div_u64((div_u64(dco_freq, 24) -
  1304. params->dco_integer * MHz(1)) * 0x8000, MHz(1));
  1305. }
  1306. static bool
  1307. skl_ddi_calculate_wrpll(int clock /* in Hz */,
  1308. struct skl_wrpll_params *wrpll_params)
  1309. {
  1310. uint64_t afe_clock = clock * 5; /* AFE Clock is 5x Pixel clock */
  1311. uint64_t dco_central_freq[3] = {8400000000ULL,
  1312. 9000000000ULL,
  1313. 9600000000ULL};
  1314. static const int even_dividers[] = { 4, 6, 8, 10, 12, 14, 16, 18, 20,
  1315. 24, 28, 30, 32, 36, 40, 42, 44,
  1316. 48, 52, 54, 56, 60, 64, 66, 68,
  1317. 70, 72, 76, 78, 80, 84, 88, 90,
  1318. 92, 96, 98 };
  1319. static const int odd_dividers[] = { 3, 5, 7, 9, 15, 21, 35 };
  1320. static const struct {
  1321. const int *list;
  1322. int n_dividers;
  1323. } dividers[] = {
  1324. { even_dividers, ARRAY_SIZE(even_dividers) },
  1325. { odd_dividers, ARRAY_SIZE(odd_dividers) },
  1326. };
  1327. struct skl_wrpll_context ctx;
  1328. unsigned int dco, d, i;
  1329. unsigned int p0, p1, p2;
  1330. skl_wrpll_context_init(&ctx);
  1331. for (d = 0; d < ARRAY_SIZE(dividers); d++) {
  1332. for (dco = 0; dco < ARRAY_SIZE(dco_central_freq); dco++) {
  1333. for (i = 0; i < dividers[d].n_dividers; i++) {
  1334. unsigned int p = dividers[d].list[i];
  1335. uint64_t dco_freq = p * afe_clock;
  1336. skl_wrpll_try_divider(&ctx,
  1337. dco_central_freq[dco],
  1338. dco_freq,
  1339. p);
  1340. /*
  1341. * Skip the remaining dividers if we're sure to
  1342. * have found the definitive divider, we can't
  1343. * improve a 0 deviation.
  1344. */
  1345. if (ctx.min_deviation == 0)
  1346. goto skip_remaining_dividers;
  1347. }
  1348. }
  1349. skip_remaining_dividers:
  1350. /*
  1351. * If a solution is found with an even divider, prefer
  1352. * this one.
  1353. */
  1354. if (d == 0 && ctx.p)
  1355. break;
  1356. }
  1357. if (!ctx.p) {
  1358. DRM_DEBUG_DRIVER("No valid divider found for %dHz\n", clock);
  1359. return false;
  1360. }
  1361. /*
  1362. * gcc incorrectly analyses that these can be used without being
  1363. * initialized. To be fair, it's hard to guess.
  1364. */
  1365. p0 = p1 = p2 = 0;
  1366. skl_wrpll_get_multipliers(ctx.p, &p0, &p1, &p2);
  1367. skl_wrpll_params_populate(wrpll_params, afe_clock, ctx.central_freq,
  1368. p0, p1, p2);
  1369. return true;
  1370. }
  1371. static bool
  1372. skl_ddi_pll_select(struct intel_crtc *intel_crtc,
  1373. struct intel_crtc_state *crtc_state,
  1374. struct intel_encoder *intel_encoder)
  1375. {
  1376. struct intel_shared_dpll *pll;
  1377. uint32_t ctrl1, cfgcr1, cfgcr2;
  1378. int clock = crtc_state->port_clock;
  1379. /*
  1380. * See comment in intel_dpll_hw_state to understand why we always use 0
  1381. * as the DPLL id in this function.
  1382. */
  1383. ctrl1 = DPLL_CTRL1_OVERRIDE(0);
  1384. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  1385. struct skl_wrpll_params wrpll_params = { 0, };
  1386. ctrl1 |= DPLL_CTRL1_HDMI_MODE(0);
  1387. if (!skl_ddi_calculate_wrpll(clock * 1000, &wrpll_params))
  1388. return false;
  1389. cfgcr1 = DPLL_CFGCR1_FREQ_ENABLE |
  1390. DPLL_CFGCR1_DCO_FRACTION(wrpll_params.dco_fraction) |
  1391. wrpll_params.dco_integer;
  1392. cfgcr2 = DPLL_CFGCR2_QDIV_RATIO(wrpll_params.qdiv_ratio) |
  1393. DPLL_CFGCR2_QDIV_MODE(wrpll_params.qdiv_mode) |
  1394. DPLL_CFGCR2_KDIV(wrpll_params.kdiv) |
  1395. DPLL_CFGCR2_PDIV(wrpll_params.pdiv) |
  1396. wrpll_params.central_freq;
  1397. } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
  1398. intel_encoder->type == INTEL_OUTPUT_DP_MST) {
  1399. switch (crtc_state->port_clock / 2) {
  1400. case 81000:
  1401. ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_810, 0);
  1402. break;
  1403. case 135000:
  1404. ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1350, 0);
  1405. break;
  1406. case 270000:
  1407. ctrl1 |= DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_2700, 0);
  1408. break;
  1409. }
  1410. cfgcr1 = cfgcr2 = 0;
  1411. } else /* eDP */
  1412. return true;
  1413. memset(&crtc_state->dpll_hw_state, 0,
  1414. sizeof(crtc_state->dpll_hw_state));
  1415. crtc_state->dpll_hw_state.ctrl1 = ctrl1;
  1416. crtc_state->dpll_hw_state.cfgcr1 = cfgcr1;
  1417. crtc_state->dpll_hw_state.cfgcr2 = cfgcr2;
  1418. pll = intel_get_shared_dpll(intel_crtc, crtc_state);
  1419. if (pll == NULL) {
  1420. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  1421. pipe_name(intel_crtc->pipe));
  1422. return false;
  1423. }
  1424. /* shared DPLL id 0 is DPLL 1 */
  1425. crtc_state->ddi_pll_sel = pll->id + 1;
  1426. return true;
  1427. }
  1428. /* bxt clock parameters */
  1429. struct bxt_clk_div {
  1430. int clock;
  1431. uint32_t p1;
  1432. uint32_t p2;
  1433. uint32_t m2_int;
  1434. uint32_t m2_frac;
  1435. bool m2_frac_en;
  1436. uint32_t n;
  1437. };
  1438. /* pre-calculated values for DP linkrates */
  1439. static const struct bxt_clk_div bxt_dp_clk_val[] = {
  1440. {162000, 4, 2, 32, 1677722, 1, 1},
  1441. {270000, 4, 1, 27, 0, 0, 1},
  1442. {540000, 2, 1, 27, 0, 0, 1},
  1443. {216000, 3, 2, 32, 1677722, 1, 1},
  1444. {243000, 4, 1, 24, 1258291, 1, 1},
  1445. {324000, 4, 1, 32, 1677722, 1, 1},
  1446. {432000, 3, 1, 32, 1677722, 1, 1}
  1447. };
  1448. static bool
  1449. bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
  1450. struct intel_crtc_state *crtc_state,
  1451. struct intel_encoder *intel_encoder)
  1452. {
  1453. struct intel_shared_dpll *pll;
  1454. struct bxt_clk_div clk_div = {0};
  1455. int vco = 0;
  1456. uint32_t prop_coef, int_coef, gain_ctl, targ_cnt;
  1457. uint32_t lanestagger;
  1458. int clock = crtc_state->port_clock;
  1459. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  1460. intel_clock_t best_clock;
  1461. /* Calculate HDMI div */
  1462. /*
  1463. * FIXME: tie the following calculation into
  1464. * i9xx_crtc_compute_clock
  1465. */
  1466. if (!bxt_find_best_dpll(crtc_state, clock, &best_clock)) {
  1467. DRM_DEBUG_DRIVER("no PLL dividers found for clock %d pipe %c\n",
  1468. clock, pipe_name(intel_crtc->pipe));
  1469. return false;
  1470. }
  1471. clk_div.p1 = best_clock.p1;
  1472. clk_div.p2 = best_clock.p2;
  1473. WARN_ON(best_clock.m1 != 2);
  1474. clk_div.n = best_clock.n;
  1475. clk_div.m2_int = best_clock.m2 >> 22;
  1476. clk_div.m2_frac = best_clock.m2 & ((1 << 22) - 1);
  1477. clk_div.m2_frac_en = clk_div.m2_frac != 0;
  1478. vco = best_clock.vco;
  1479. } else if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT ||
  1480. intel_encoder->type == INTEL_OUTPUT_EDP) {
  1481. int i;
  1482. clk_div = bxt_dp_clk_val[0];
  1483. for (i = 0; i < ARRAY_SIZE(bxt_dp_clk_val); ++i) {
  1484. if (bxt_dp_clk_val[i].clock == clock) {
  1485. clk_div = bxt_dp_clk_val[i];
  1486. break;
  1487. }
  1488. }
  1489. vco = clock * 10 / 2 * clk_div.p1 * clk_div.p2;
  1490. }
  1491. if (vco >= 6200000 && vco <= 6700000) {
  1492. prop_coef = 4;
  1493. int_coef = 9;
  1494. gain_ctl = 3;
  1495. targ_cnt = 8;
  1496. } else if ((vco > 5400000 && vco < 6200000) ||
  1497. (vco >= 4800000 && vco < 5400000)) {
  1498. prop_coef = 5;
  1499. int_coef = 11;
  1500. gain_ctl = 3;
  1501. targ_cnt = 9;
  1502. } else if (vco == 5400000) {
  1503. prop_coef = 3;
  1504. int_coef = 8;
  1505. gain_ctl = 1;
  1506. targ_cnt = 9;
  1507. } else {
  1508. DRM_ERROR("Invalid VCO\n");
  1509. return false;
  1510. }
  1511. memset(&crtc_state->dpll_hw_state, 0,
  1512. sizeof(crtc_state->dpll_hw_state));
  1513. if (clock > 270000)
  1514. lanestagger = 0x18;
  1515. else if (clock > 135000)
  1516. lanestagger = 0x0d;
  1517. else if (clock > 67000)
  1518. lanestagger = 0x07;
  1519. else if (clock > 33000)
  1520. lanestagger = 0x04;
  1521. else
  1522. lanestagger = 0x02;
  1523. crtc_state->dpll_hw_state.ebb0 =
  1524. PORT_PLL_P1(clk_div.p1) | PORT_PLL_P2(clk_div.p2);
  1525. crtc_state->dpll_hw_state.pll0 = clk_div.m2_int;
  1526. crtc_state->dpll_hw_state.pll1 = PORT_PLL_N(clk_div.n);
  1527. crtc_state->dpll_hw_state.pll2 = clk_div.m2_frac;
  1528. if (clk_div.m2_frac_en)
  1529. crtc_state->dpll_hw_state.pll3 =
  1530. PORT_PLL_M2_FRAC_ENABLE;
  1531. crtc_state->dpll_hw_state.pll6 =
  1532. prop_coef | PORT_PLL_INT_COEFF(int_coef);
  1533. crtc_state->dpll_hw_state.pll6 |=
  1534. PORT_PLL_GAIN_CTL(gain_ctl);
  1535. crtc_state->dpll_hw_state.pll8 = targ_cnt;
  1536. crtc_state->dpll_hw_state.pll9 = 5 << PORT_PLL_LOCK_THRESHOLD_SHIFT;
  1537. crtc_state->dpll_hw_state.pll10 =
  1538. PORT_PLL_DCO_AMP(PORT_PLL_DCO_AMP_DEFAULT)
  1539. | PORT_PLL_DCO_AMP_OVR_EN_H;
  1540. crtc_state->dpll_hw_state.ebb4 = PORT_PLL_10BIT_CLK_ENABLE;
  1541. crtc_state->dpll_hw_state.pcsdw12 =
  1542. LANESTAGGER_STRAP_OVRD | lanestagger;
  1543. pll = intel_get_shared_dpll(intel_crtc, crtc_state);
  1544. if (pll == NULL) {
  1545. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  1546. pipe_name(intel_crtc->pipe));
  1547. return false;
  1548. }
  1549. /* shared DPLL id 0 is DPLL A */
  1550. crtc_state->ddi_pll_sel = pll->id;
  1551. return true;
  1552. }
  1553. /*
  1554. * Tries to find a *shared* PLL for the CRTC and store it in
  1555. * intel_crtc->ddi_pll_sel.
  1556. *
  1557. * For private DPLLs, compute_config() should do the selection for us. This
  1558. * function should be folded into compute_config() eventually.
  1559. */
  1560. bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
  1561. struct intel_crtc_state *crtc_state)
  1562. {
  1563. struct drm_device *dev = intel_crtc->base.dev;
  1564. struct intel_encoder *intel_encoder =
  1565. intel_ddi_get_crtc_new_encoder(crtc_state);
  1566. if (IS_SKYLAKE(dev))
  1567. return skl_ddi_pll_select(intel_crtc, crtc_state,
  1568. intel_encoder);
  1569. else if (IS_BROXTON(dev))
  1570. return bxt_ddi_pll_select(intel_crtc, crtc_state,
  1571. intel_encoder);
  1572. else
  1573. return hsw_ddi_pll_select(intel_crtc, crtc_state,
  1574. intel_encoder);
  1575. }
  1576. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
  1577. {
  1578. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1579. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1580. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1581. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1582. int type = intel_encoder->type;
  1583. uint32_t temp;
  1584. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
  1585. temp = TRANS_MSA_SYNC_CLK;
  1586. switch (intel_crtc->config->pipe_bpp) {
  1587. case 18:
  1588. temp |= TRANS_MSA_6_BPC;
  1589. break;
  1590. case 24:
  1591. temp |= TRANS_MSA_8_BPC;
  1592. break;
  1593. case 30:
  1594. temp |= TRANS_MSA_10_BPC;
  1595. break;
  1596. case 36:
  1597. temp |= TRANS_MSA_12_BPC;
  1598. break;
  1599. default:
  1600. BUG();
  1601. }
  1602. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  1603. }
  1604. }
  1605. void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
  1606. {
  1607. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1608. struct drm_device *dev = crtc->dev;
  1609. struct drm_i915_private *dev_priv = dev->dev_private;
  1610. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1611. uint32_t temp;
  1612. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1613. if (state == true)
  1614. temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1615. else
  1616. temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1617. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1618. }
  1619. void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
  1620. {
  1621. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1622. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1623. struct drm_encoder *encoder = &intel_encoder->base;
  1624. struct drm_device *dev = crtc->dev;
  1625. struct drm_i915_private *dev_priv = dev->dev_private;
  1626. enum pipe pipe = intel_crtc->pipe;
  1627. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1628. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1629. int type = intel_encoder->type;
  1630. uint32_t temp;
  1631. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  1632. temp = TRANS_DDI_FUNC_ENABLE;
  1633. temp |= TRANS_DDI_SELECT_PORT(port);
  1634. switch (intel_crtc->config->pipe_bpp) {
  1635. case 18:
  1636. temp |= TRANS_DDI_BPC_6;
  1637. break;
  1638. case 24:
  1639. temp |= TRANS_DDI_BPC_8;
  1640. break;
  1641. case 30:
  1642. temp |= TRANS_DDI_BPC_10;
  1643. break;
  1644. case 36:
  1645. temp |= TRANS_DDI_BPC_12;
  1646. break;
  1647. default:
  1648. BUG();
  1649. }
  1650. if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
  1651. temp |= TRANS_DDI_PVSYNC;
  1652. if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
  1653. temp |= TRANS_DDI_PHSYNC;
  1654. if (cpu_transcoder == TRANSCODER_EDP) {
  1655. switch (pipe) {
  1656. case PIPE_A:
  1657. /* On Haswell, can only use the always-on power well for
  1658. * eDP when not using the panel fitter, and when not
  1659. * using motion blur mitigation (which we don't
  1660. * support). */
  1661. if (IS_HASWELL(dev) &&
  1662. (intel_crtc->config->pch_pfit.enabled ||
  1663. intel_crtc->config->pch_pfit.force_thru))
  1664. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  1665. else
  1666. temp |= TRANS_DDI_EDP_INPUT_A_ON;
  1667. break;
  1668. case PIPE_B:
  1669. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  1670. break;
  1671. case PIPE_C:
  1672. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  1673. break;
  1674. default:
  1675. BUG();
  1676. break;
  1677. }
  1678. }
  1679. if (type == INTEL_OUTPUT_HDMI) {
  1680. if (intel_crtc->config->has_hdmi_sink)
  1681. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  1682. else
  1683. temp |= TRANS_DDI_MODE_SELECT_DVI;
  1684. } else if (type == INTEL_OUTPUT_ANALOG) {
  1685. temp |= TRANS_DDI_MODE_SELECT_FDI;
  1686. temp |= (intel_crtc->config->fdi_lanes - 1) << 1;
  1687. } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
  1688. type == INTEL_OUTPUT_EDP) {
  1689. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1690. if (intel_dp->is_mst) {
  1691. temp |= TRANS_DDI_MODE_SELECT_DP_MST;
  1692. } else
  1693. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  1694. temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
  1695. } else if (type == INTEL_OUTPUT_DP_MST) {
  1696. struct intel_dp *intel_dp = &enc_to_mst(encoder)->primary->dp;
  1697. if (intel_dp->is_mst) {
  1698. temp |= TRANS_DDI_MODE_SELECT_DP_MST;
  1699. } else
  1700. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  1701. temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
  1702. } else {
  1703. WARN(1, "Invalid encoder type %d for pipe %c\n",
  1704. intel_encoder->type, pipe_name(pipe));
  1705. }
  1706. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1707. }
  1708. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  1709. enum transcoder cpu_transcoder)
  1710. {
  1711. uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1712. uint32_t val = I915_READ(reg);
  1713. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
  1714. val |= TRANS_DDI_PORT_NONE;
  1715. I915_WRITE(reg, val);
  1716. }
  1717. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  1718. {
  1719. struct drm_device *dev = intel_connector->base.dev;
  1720. struct drm_i915_private *dev_priv = dev->dev_private;
  1721. struct intel_encoder *intel_encoder = intel_connector->encoder;
  1722. int type = intel_connector->base.connector_type;
  1723. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1724. enum pipe pipe = 0;
  1725. enum transcoder cpu_transcoder;
  1726. enum intel_display_power_domain power_domain;
  1727. uint32_t tmp;
  1728. power_domain = intel_display_port_power_domain(intel_encoder);
  1729. if (!intel_display_power_is_enabled(dev_priv, power_domain))
  1730. return false;
  1731. if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
  1732. return false;
  1733. if (port == PORT_A)
  1734. cpu_transcoder = TRANSCODER_EDP;
  1735. else
  1736. cpu_transcoder = (enum transcoder) pipe;
  1737. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1738. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  1739. case TRANS_DDI_MODE_SELECT_HDMI:
  1740. case TRANS_DDI_MODE_SELECT_DVI:
  1741. return (type == DRM_MODE_CONNECTOR_HDMIA);
  1742. case TRANS_DDI_MODE_SELECT_DP_SST:
  1743. if (type == DRM_MODE_CONNECTOR_eDP)
  1744. return true;
  1745. return (type == DRM_MODE_CONNECTOR_DisplayPort);
  1746. case TRANS_DDI_MODE_SELECT_DP_MST:
  1747. /* if the transcoder is in MST state then
  1748. * connector isn't connected */
  1749. return false;
  1750. case TRANS_DDI_MODE_SELECT_FDI:
  1751. return (type == DRM_MODE_CONNECTOR_VGA);
  1752. default:
  1753. return false;
  1754. }
  1755. }
  1756. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  1757. enum pipe *pipe)
  1758. {
  1759. struct drm_device *dev = encoder->base.dev;
  1760. struct drm_i915_private *dev_priv = dev->dev_private;
  1761. enum port port = intel_ddi_get_encoder_port(encoder);
  1762. enum intel_display_power_domain power_domain;
  1763. u32 tmp;
  1764. int i;
  1765. power_domain = intel_display_port_power_domain(encoder);
  1766. if (!intel_display_power_is_enabled(dev_priv, power_domain))
  1767. return false;
  1768. tmp = I915_READ(DDI_BUF_CTL(port));
  1769. if (!(tmp & DDI_BUF_CTL_ENABLE))
  1770. return false;
  1771. if (port == PORT_A) {
  1772. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  1773. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  1774. case TRANS_DDI_EDP_INPUT_A_ON:
  1775. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  1776. *pipe = PIPE_A;
  1777. break;
  1778. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  1779. *pipe = PIPE_B;
  1780. break;
  1781. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  1782. *pipe = PIPE_C;
  1783. break;
  1784. }
  1785. return true;
  1786. } else {
  1787. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  1788. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  1789. if ((tmp & TRANS_DDI_PORT_MASK)
  1790. == TRANS_DDI_SELECT_PORT(port)) {
  1791. if ((tmp & TRANS_DDI_MODE_SELECT_MASK) == TRANS_DDI_MODE_SELECT_DP_MST)
  1792. return false;
  1793. *pipe = i;
  1794. return true;
  1795. }
  1796. }
  1797. }
  1798. DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
  1799. return false;
  1800. }
  1801. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
  1802. {
  1803. struct drm_crtc *crtc = &intel_crtc->base;
  1804. struct drm_device *dev = crtc->dev;
  1805. struct drm_i915_private *dev_priv = dev->dev_private;
  1806. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1807. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1808. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1809. if (cpu_transcoder != TRANSCODER_EDP)
  1810. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1811. TRANS_CLK_SEL_PORT(port));
  1812. }
  1813. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
  1814. {
  1815. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1816. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1817. if (cpu_transcoder != TRANSCODER_EDP)
  1818. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1819. TRANS_CLK_SEL_DISABLED);
  1820. }
  1821. static void skl_ddi_set_iboost(struct drm_device *dev, u32 level,
  1822. enum port port, int type)
  1823. {
  1824. struct drm_i915_private *dev_priv = dev->dev_private;
  1825. const struct ddi_buf_trans *ddi_translations;
  1826. uint8_t iboost;
  1827. uint8_t dp_iboost, hdmi_iboost;
  1828. int n_entries;
  1829. u32 reg;
  1830. /* VBT may override standard boost values */
  1831. dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
  1832. hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
  1833. if (type == INTEL_OUTPUT_DISPLAYPORT) {
  1834. if (dp_iboost) {
  1835. iboost = dp_iboost;
  1836. } else {
  1837. ddi_translations = skl_get_buf_trans_dp(dev, &n_entries);
  1838. iboost = ddi_translations[port].i_boost;
  1839. }
  1840. } else if (type == INTEL_OUTPUT_EDP) {
  1841. if (dp_iboost) {
  1842. iboost = dp_iboost;
  1843. } else {
  1844. ddi_translations = skl_get_buf_trans_edp(dev, &n_entries);
  1845. iboost = ddi_translations[port].i_boost;
  1846. }
  1847. } else if (type == INTEL_OUTPUT_HDMI) {
  1848. if (hdmi_iboost) {
  1849. iboost = hdmi_iboost;
  1850. } else {
  1851. ddi_translations = skl_get_buf_trans_hdmi(dev, &n_entries);
  1852. iboost = ddi_translations[port].i_boost;
  1853. }
  1854. } else {
  1855. return;
  1856. }
  1857. /* Make sure that the requested I_boost is valid */
  1858. if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
  1859. DRM_ERROR("Invalid I_boost value %u\n", iboost);
  1860. return;
  1861. }
  1862. reg = I915_READ(DISPIO_CR_TX_BMU_CR0);
  1863. reg &= ~BALANCE_LEG_MASK(port);
  1864. reg &= ~(1 << (BALANCE_LEG_DISABLE_SHIFT + port));
  1865. if (iboost)
  1866. reg |= iboost << BALANCE_LEG_SHIFT(port);
  1867. else
  1868. reg |= 1 << (BALANCE_LEG_DISABLE_SHIFT + port);
  1869. I915_WRITE(DISPIO_CR_TX_BMU_CR0, reg);
  1870. }
  1871. static void bxt_ddi_vswing_sequence(struct drm_device *dev, u32 level,
  1872. enum port port, int type)
  1873. {
  1874. struct drm_i915_private *dev_priv = dev->dev_private;
  1875. const struct bxt_ddi_buf_trans *ddi_translations;
  1876. u32 n_entries, i;
  1877. uint32_t val;
  1878. if (type == INTEL_OUTPUT_EDP && dev_priv->edp_low_vswing) {
  1879. n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
  1880. ddi_translations = bxt_ddi_translations_edp;
  1881. } else if (type == INTEL_OUTPUT_DISPLAYPORT
  1882. || type == INTEL_OUTPUT_EDP) {
  1883. n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
  1884. ddi_translations = bxt_ddi_translations_dp;
  1885. } else if (type == INTEL_OUTPUT_HDMI) {
  1886. n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
  1887. ddi_translations = bxt_ddi_translations_hdmi;
  1888. } else {
  1889. DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
  1890. type);
  1891. return;
  1892. }
  1893. /* Check if default value has to be used */
  1894. if (level >= n_entries ||
  1895. (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
  1896. for (i = 0; i < n_entries; i++) {
  1897. if (ddi_translations[i].default_index) {
  1898. level = i;
  1899. break;
  1900. }
  1901. }
  1902. }
  1903. /*
  1904. * While we write to the group register to program all lanes at once we
  1905. * can read only lane registers and we pick lanes 0/1 for that.
  1906. */
  1907. val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
  1908. val &= ~(TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT);
  1909. I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
  1910. val = I915_READ(BXT_PORT_TX_DW2_LN0(port));
  1911. val &= ~(MARGIN_000 | UNIQ_TRANS_SCALE);
  1912. val |= ddi_translations[level].margin << MARGIN_000_SHIFT |
  1913. ddi_translations[level].scale << UNIQ_TRANS_SCALE_SHIFT;
  1914. I915_WRITE(BXT_PORT_TX_DW2_GRP(port), val);
  1915. val = I915_READ(BXT_PORT_TX_DW3_LN0(port));
  1916. val &= ~SCALE_DCOMP_METHOD;
  1917. if (ddi_translations[level].enable)
  1918. val |= SCALE_DCOMP_METHOD;
  1919. if ((val & UNIQUE_TRANGE_EN_METHOD) && !(val & SCALE_DCOMP_METHOD))
  1920. DRM_ERROR("Disabled scaling while ouniqetrangenmethod was set");
  1921. I915_WRITE(BXT_PORT_TX_DW3_GRP(port), val);
  1922. val = I915_READ(BXT_PORT_TX_DW4_LN0(port));
  1923. val &= ~DE_EMPHASIS;
  1924. val |= ddi_translations[level].deemphasis << DEEMPH_SHIFT;
  1925. I915_WRITE(BXT_PORT_TX_DW4_GRP(port), val);
  1926. val = I915_READ(BXT_PORT_PCS_DW10_LN01(port));
  1927. val |= TX2_SWING_CALC_INIT | TX1_SWING_CALC_INIT;
  1928. I915_WRITE(BXT_PORT_PCS_DW10_GRP(port), val);
  1929. }
  1930. static uint32_t translate_signal_level(int signal_levels)
  1931. {
  1932. uint32_t level;
  1933. switch (signal_levels) {
  1934. default:
  1935. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level: 0x%x\n",
  1936. signal_levels);
  1937. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1938. level = 0;
  1939. break;
  1940. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  1941. level = 1;
  1942. break;
  1943. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  1944. level = 2;
  1945. break;
  1946. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3:
  1947. level = 3;
  1948. break;
  1949. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1950. level = 4;
  1951. break;
  1952. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  1953. level = 5;
  1954. break;
  1955. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  1956. level = 6;
  1957. break;
  1958. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1959. level = 7;
  1960. break;
  1961. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  1962. level = 8;
  1963. break;
  1964. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1965. level = 9;
  1966. break;
  1967. }
  1968. return level;
  1969. }
  1970. uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
  1971. {
  1972. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1973. struct drm_device *dev = dport->base.base.dev;
  1974. struct intel_encoder *encoder = &dport->base;
  1975. uint8_t train_set = intel_dp->train_set[0];
  1976. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1977. DP_TRAIN_PRE_EMPHASIS_MASK);
  1978. enum port port = dport->port;
  1979. uint32_t level;
  1980. level = translate_signal_level(signal_levels);
  1981. if (IS_SKYLAKE(dev))
  1982. skl_ddi_set_iboost(dev, level, port, encoder->type);
  1983. else if (IS_BROXTON(dev))
  1984. bxt_ddi_vswing_sequence(dev, level, port, encoder->type);
  1985. return DDI_BUF_TRANS_SELECT(level);
  1986. }
  1987. static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
  1988. {
  1989. struct drm_encoder *encoder = &intel_encoder->base;
  1990. struct drm_device *dev = encoder->dev;
  1991. struct drm_i915_private *dev_priv = dev->dev_private;
  1992. struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
  1993. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1994. int type = intel_encoder->type;
  1995. int hdmi_level;
  1996. if (type == INTEL_OUTPUT_EDP) {
  1997. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1998. intel_edp_panel_on(intel_dp);
  1999. }
  2000. if (IS_SKYLAKE(dev)) {
  2001. uint32_t dpll = crtc->config->ddi_pll_sel;
  2002. uint32_t val;
  2003. /*
  2004. * DPLL0 is used for eDP and is the only "private" DPLL (as
  2005. * opposed to shared) on SKL
  2006. */
  2007. if (type == INTEL_OUTPUT_EDP) {
  2008. WARN_ON(dpll != SKL_DPLL0);
  2009. val = I915_READ(DPLL_CTRL1);
  2010. val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) |
  2011. DPLL_CTRL1_SSC(dpll) |
  2012. DPLL_CTRL1_LINK_RATE_MASK(dpll));
  2013. val |= crtc->config->dpll_hw_state.ctrl1 << (dpll * 6);
  2014. I915_WRITE(DPLL_CTRL1, val);
  2015. POSTING_READ(DPLL_CTRL1);
  2016. }
  2017. /* DDI -> PLL mapping */
  2018. val = I915_READ(DPLL_CTRL2);
  2019. val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
  2020. DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
  2021. val |= (DPLL_CTRL2_DDI_CLK_SEL(dpll, port) |
  2022. DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
  2023. I915_WRITE(DPLL_CTRL2, val);
  2024. } else if (INTEL_INFO(dev)->gen < 9) {
  2025. WARN_ON(crtc->config->ddi_pll_sel == PORT_CLK_SEL_NONE);
  2026. I915_WRITE(PORT_CLK_SEL(port), crtc->config->ddi_pll_sel);
  2027. }
  2028. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  2029. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2030. intel_dp_set_link_params(intel_dp, crtc->config);
  2031. intel_ddi_init_dp_buf_reg(intel_encoder);
  2032. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  2033. intel_dp_start_link_train(intel_dp);
  2034. if (port != PORT_A || INTEL_INFO(dev)->gen >= 9)
  2035. intel_dp_stop_link_train(intel_dp);
  2036. } else if (type == INTEL_OUTPUT_HDMI) {
  2037. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  2038. if (IS_BROXTON(dev)) {
  2039. hdmi_level = dev_priv->vbt.
  2040. ddi_port_info[port].hdmi_level_shift;
  2041. bxt_ddi_vswing_sequence(dev, hdmi_level, port,
  2042. INTEL_OUTPUT_HDMI);
  2043. }
  2044. intel_hdmi->set_infoframes(encoder,
  2045. crtc->config->has_hdmi_sink,
  2046. &crtc->config->base.adjusted_mode);
  2047. }
  2048. }
  2049. static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
  2050. {
  2051. struct drm_encoder *encoder = &intel_encoder->base;
  2052. struct drm_device *dev = encoder->dev;
  2053. struct drm_i915_private *dev_priv = dev->dev_private;
  2054. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  2055. int type = intel_encoder->type;
  2056. uint32_t val;
  2057. bool wait = false;
  2058. val = I915_READ(DDI_BUF_CTL(port));
  2059. if (val & DDI_BUF_CTL_ENABLE) {
  2060. val &= ~DDI_BUF_CTL_ENABLE;
  2061. I915_WRITE(DDI_BUF_CTL(port), val);
  2062. wait = true;
  2063. }
  2064. val = I915_READ(DP_TP_CTL(port));
  2065. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  2066. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2067. I915_WRITE(DP_TP_CTL(port), val);
  2068. if (wait)
  2069. intel_wait_ddi_buf_idle(dev_priv, port);
  2070. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  2071. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2072. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  2073. intel_edp_panel_vdd_on(intel_dp);
  2074. intel_edp_panel_off(intel_dp);
  2075. }
  2076. if (IS_SKYLAKE(dev))
  2077. I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
  2078. DPLL_CTRL2_DDI_CLK_OFF(port)));
  2079. else if (INTEL_INFO(dev)->gen < 9)
  2080. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  2081. }
  2082. static void intel_enable_ddi(struct intel_encoder *intel_encoder)
  2083. {
  2084. struct drm_encoder *encoder = &intel_encoder->base;
  2085. struct drm_crtc *crtc = encoder->crtc;
  2086. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2087. struct drm_device *dev = encoder->dev;
  2088. struct drm_i915_private *dev_priv = dev->dev_private;
  2089. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  2090. int type = intel_encoder->type;
  2091. if (type == INTEL_OUTPUT_HDMI) {
  2092. struct intel_digital_port *intel_dig_port =
  2093. enc_to_dig_port(encoder);
  2094. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  2095. * are ignored so nothing special needs to be done besides
  2096. * enabling the port.
  2097. */
  2098. I915_WRITE(DDI_BUF_CTL(port),
  2099. intel_dig_port->saved_port_bits |
  2100. DDI_BUF_CTL_ENABLE);
  2101. } else if (type == INTEL_OUTPUT_EDP) {
  2102. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2103. if (port == PORT_A && INTEL_INFO(dev)->gen < 9)
  2104. intel_dp_stop_link_train(intel_dp);
  2105. intel_edp_backlight_on(intel_dp);
  2106. intel_psr_enable(intel_dp);
  2107. intel_edp_drrs_enable(intel_dp);
  2108. }
  2109. if (intel_crtc->config->has_audio) {
  2110. intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
  2111. intel_audio_codec_enable(intel_encoder);
  2112. }
  2113. }
  2114. static void intel_disable_ddi(struct intel_encoder *intel_encoder)
  2115. {
  2116. struct drm_encoder *encoder = &intel_encoder->base;
  2117. struct drm_crtc *crtc = encoder->crtc;
  2118. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2119. int type = intel_encoder->type;
  2120. struct drm_device *dev = encoder->dev;
  2121. struct drm_i915_private *dev_priv = dev->dev_private;
  2122. if (intel_crtc->config->has_audio) {
  2123. intel_audio_codec_disable(intel_encoder);
  2124. intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
  2125. }
  2126. if (type == INTEL_OUTPUT_EDP) {
  2127. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2128. intel_edp_drrs_disable(intel_dp);
  2129. intel_psr_disable(intel_dp);
  2130. intel_edp_backlight_off(intel_dp);
  2131. }
  2132. }
  2133. static void hsw_ddi_wrpll_enable(struct drm_i915_private *dev_priv,
  2134. struct intel_shared_dpll *pll)
  2135. {
  2136. I915_WRITE(WRPLL_CTL(pll->id), pll->config.hw_state.wrpll);
  2137. POSTING_READ(WRPLL_CTL(pll->id));
  2138. udelay(20);
  2139. }
  2140. static void hsw_ddi_spll_enable(struct drm_i915_private *dev_priv,
  2141. struct intel_shared_dpll *pll)
  2142. {
  2143. I915_WRITE(SPLL_CTL, pll->config.hw_state.spll);
  2144. POSTING_READ(SPLL_CTL);
  2145. udelay(20);
  2146. }
  2147. static void hsw_ddi_wrpll_disable(struct drm_i915_private *dev_priv,
  2148. struct intel_shared_dpll *pll)
  2149. {
  2150. uint32_t val;
  2151. val = I915_READ(WRPLL_CTL(pll->id));
  2152. I915_WRITE(WRPLL_CTL(pll->id), val & ~WRPLL_PLL_ENABLE);
  2153. POSTING_READ(WRPLL_CTL(pll->id));
  2154. }
  2155. static void hsw_ddi_spll_disable(struct drm_i915_private *dev_priv,
  2156. struct intel_shared_dpll *pll)
  2157. {
  2158. uint32_t val;
  2159. val = I915_READ(SPLL_CTL);
  2160. I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
  2161. POSTING_READ(SPLL_CTL);
  2162. }
  2163. static bool hsw_ddi_wrpll_get_hw_state(struct drm_i915_private *dev_priv,
  2164. struct intel_shared_dpll *pll,
  2165. struct intel_dpll_hw_state *hw_state)
  2166. {
  2167. uint32_t val;
  2168. if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
  2169. return false;
  2170. val = I915_READ(WRPLL_CTL(pll->id));
  2171. hw_state->wrpll = val;
  2172. return val & WRPLL_PLL_ENABLE;
  2173. }
  2174. static bool hsw_ddi_spll_get_hw_state(struct drm_i915_private *dev_priv,
  2175. struct intel_shared_dpll *pll,
  2176. struct intel_dpll_hw_state *hw_state)
  2177. {
  2178. uint32_t val;
  2179. if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
  2180. return false;
  2181. val = I915_READ(SPLL_CTL);
  2182. hw_state->spll = val;
  2183. return val & SPLL_PLL_ENABLE;
  2184. }
  2185. static const char * const hsw_ddi_pll_names[] = {
  2186. "WRPLL 1",
  2187. "WRPLL 2",
  2188. "SPLL"
  2189. };
  2190. static void hsw_shared_dplls_init(struct drm_i915_private *dev_priv)
  2191. {
  2192. int i;
  2193. dev_priv->num_shared_dpll = 3;
  2194. for (i = 0; i < 2; i++) {
  2195. dev_priv->shared_dplls[i].id = i;
  2196. dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
  2197. dev_priv->shared_dplls[i].disable = hsw_ddi_wrpll_disable;
  2198. dev_priv->shared_dplls[i].enable = hsw_ddi_wrpll_enable;
  2199. dev_priv->shared_dplls[i].get_hw_state =
  2200. hsw_ddi_wrpll_get_hw_state;
  2201. }
  2202. /* SPLL is special, but needs to be initialized anyway.. */
  2203. dev_priv->shared_dplls[i].id = i;
  2204. dev_priv->shared_dplls[i].name = hsw_ddi_pll_names[i];
  2205. dev_priv->shared_dplls[i].disable = hsw_ddi_spll_disable;
  2206. dev_priv->shared_dplls[i].enable = hsw_ddi_spll_enable;
  2207. dev_priv->shared_dplls[i].get_hw_state = hsw_ddi_spll_get_hw_state;
  2208. }
  2209. static const char * const skl_ddi_pll_names[] = {
  2210. "DPLL 1",
  2211. "DPLL 2",
  2212. "DPLL 3",
  2213. };
  2214. struct skl_dpll_regs {
  2215. u32 ctl, cfgcr1, cfgcr2;
  2216. };
  2217. /* this array is indexed by the *shared* pll id */
  2218. static const struct skl_dpll_regs skl_dpll_regs[3] = {
  2219. {
  2220. /* DPLL 1 */
  2221. .ctl = LCPLL2_CTL,
  2222. .cfgcr1 = DPLL_CFGCR1(SKL_DPLL1),
  2223. .cfgcr2 = DPLL_CFGCR2(SKL_DPLL1),
  2224. },
  2225. {
  2226. /* DPLL 2 */
  2227. .ctl = WRPLL_CTL1,
  2228. .cfgcr1 = DPLL_CFGCR1(SKL_DPLL2),
  2229. .cfgcr2 = DPLL_CFGCR2(SKL_DPLL2),
  2230. },
  2231. {
  2232. /* DPLL 3 */
  2233. .ctl = WRPLL_CTL2,
  2234. .cfgcr1 = DPLL_CFGCR1(SKL_DPLL3),
  2235. .cfgcr2 = DPLL_CFGCR2(SKL_DPLL3),
  2236. },
  2237. };
  2238. static void skl_ddi_pll_enable(struct drm_i915_private *dev_priv,
  2239. struct intel_shared_dpll *pll)
  2240. {
  2241. uint32_t val;
  2242. unsigned int dpll;
  2243. const struct skl_dpll_regs *regs = skl_dpll_regs;
  2244. /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */
  2245. dpll = pll->id + 1;
  2246. val = I915_READ(DPLL_CTRL1);
  2247. val &= ~(DPLL_CTRL1_HDMI_MODE(dpll) | DPLL_CTRL1_SSC(dpll) |
  2248. DPLL_CTRL1_LINK_RATE_MASK(dpll));
  2249. val |= pll->config.hw_state.ctrl1 << (dpll * 6);
  2250. I915_WRITE(DPLL_CTRL1, val);
  2251. POSTING_READ(DPLL_CTRL1);
  2252. I915_WRITE(regs[pll->id].cfgcr1, pll->config.hw_state.cfgcr1);
  2253. I915_WRITE(regs[pll->id].cfgcr2, pll->config.hw_state.cfgcr2);
  2254. POSTING_READ(regs[pll->id].cfgcr1);
  2255. POSTING_READ(regs[pll->id].cfgcr2);
  2256. /* the enable bit is always bit 31 */
  2257. I915_WRITE(regs[pll->id].ctl,
  2258. I915_READ(regs[pll->id].ctl) | LCPLL_PLL_ENABLE);
  2259. if (wait_for(I915_READ(DPLL_STATUS) & DPLL_LOCK(dpll), 5))
  2260. DRM_ERROR("DPLL %d not locked\n", dpll);
  2261. }
  2262. static void skl_ddi_pll_disable(struct drm_i915_private *dev_priv,
  2263. struct intel_shared_dpll *pll)
  2264. {
  2265. const struct skl_dpll_regs *regs = skl_dpll_regs;
  2266. /* the enable bit is always bit 31 */
  2267. I915_WRITE(regs[pll->id].ctl,
  2268. I915_READ(regs[pll->id].ctl) & ~LCPLL_PLL_ENABLE);
  2269. POSTING_READ(regs[pll->id].ctl);
  2270. }
  2271. static bool skl_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
  2272. struct intel_shared_dpll *pll,
  2273. struct intel_dpll_hw_state *hw_state)
  2274. {
  2275. uint32_t val;
  2276. unsigned int dpll;
  2277. const struct skl_dpll_regs *regs = skl_dpll_regs;
  2278. if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
  2279. return false;
  2280. /* DPLL0 is not part of the shared DPLLs, so pll->id is 0 for DPLL1 */
  2281. dpll = pll->id + 1;
  2282. val = I915_READ(regs[pll->id].ctl);
  2283. if (!(val & LCPLL_PLL_ENABLE))
  2284. return false;
  2285. val = I915_READ(DPLL_CTRL1);
  2286. hw_state->ctrl1 = (val >> (dpll * 6)) & 0x3f;
  2287. /* avoid reading back stale values if HDMI mode is not enabled */
  2288. if (val & DPLL_CTRL1_HDMI_MODE(dpll)) {
  2289. hw_state->cfgcr1 = I915_READ(regs[pll->id].cfgcr1);
  2290. hw_state->cfgcr2 = I915_READ(regs[pll->id].cfgcr2);
  2291. }
  2292. return true;
  2293. }
  2294. static void skl_shared_dplls_init(struct drm_i915_private *dev_priv)
  2295. {
  2296. int i;
  2297. dev_priv->num_shared_dpll = 3;
  2298. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  2299. dev_priv->shared_dplls[i].id = i;
  2300. dev_priv->shared_dplls[i].name = skl_ddi_pll_names[i];
  2301. dev_priv->shared_dplls[i].disable = skl_ddi_pll_disable;
  2302. dev_priv->shared_dplls[i].enable = skl_ddi_pll_enable;
  2303. dev_priv->shared_dplls[i].get_hw_state =
  2304. skl_ddi_pll_get_hw_state;
  2305. }
  2306. }
  2307. static void broxton_phy_init(struct drm_i915_private *dev_priv,
  2308. enum dpio_phy phy)
  2309. {
  2310. enum port port;
  2311. uint32_t val;
  2312. val = I915_READ(BXT_P_CR_GT_DISP_PWRON);
  2313. val |= GT_DISPLAY_POWER_ON(phy);
  2314. I915_WRITE(BXT_P_CR_GT_DISP_PWRON, val);
  2315. /* Considering 10ms timeout until BSpec is updated */
  2316. if (wait_for(I915_READ(BXT_PORT_CL1CM_DW0(phy)) & PHY_POWER_GOOD, 10))
  2317. DRM_ERROR("timeout during PHY%d power on\n", phy);
  2318. for (port = (phy == DPIO_PHY0 ? PORT_B : PORT_A);
  2319. port <= (phy == DPIO_PHY0 ? PORT_C : PORT_A); port++) {
  2320. int lane;
  2321. for (lane = 0; lane < 4; lane++) {
  2322. val = I915_READ(BXT_PORT_TX_DW14_LN(port, lane));
  2323. /*
  2324. * Note that on CHV this flag is called UPAR, but has
  2325. * the same function.
  2326. */
  2327. val &= ~LATENCY_OPTIM;
  2328. if (lane != 1)
  2329. val |= LATENCY_OPTIM;
  2330. I915_WRITE(BXT_PORT_TX_DW14_LN(port, lane), val);
  2331. }
  2332. }
  2333. /* Program PLL Rcomp code offset */
  2334. val = I915_READ(BXT_PORT_CL1CM_DW9(phy));
  2335. val &= ~IREF0RC_OFFSET_MASK;
  2336. val |= 0xE4 << IREF0RC_OFFSET_SHIFT;
  2337. I915_WRITE(BXT_PORT_CL1CM_DW9(phy), val);
  2338. val = I915_READ(BXT_PORT_CL1CM_DW10(phy));
  2339. val &= ~IREF1RC_OFFSET_MASK;
  2340. val |= 0xE4 << IREF1RC_OFFSET_SHIFT;
  2341. I915_WRITE(BXT_PORT_CL1CM_DW10(phy), val);
  2342. /* Program power gating */
  2343. val = I915_READ(BXT_PORT_CL1CM_DW28(phy));
  2344. val |= OCL1_POWER_DOWN_EN | DW28_OLDO_DYN_PWR_DOWN_EN |
  2345. SUS_CLK_CONFIG;
  2346. I915_WRITE(BXT_PORT_CL1CM_DW28(phy), val);
  2347. if (phy == DPIO_PHY0) {
  2348. val = I915_READ(BXT_PORT_CL2CM_DW6_BC);
  2349. val |= DW6_OLDO_DYN_PWR_DOWN_EN;
  2350. I915_WRITE(BXT_PORT_CL2CM_DW6_BC, val);
  2351. }
  2352. val = I915_READ(BXT_PORT_CL1CM_DW30(phy));
  2353. val &= ~OCL2_LDOFUSE_PWR_DIS;
  2354. /*
  2355. * On PHY1 disable power on the second channel, since no port is
  2356. * connected there. On PHY0 both channels have a port, so leave it
  2357. * enabled.
  2358. * TODO: port C is only connected on BXT-P, so on BXT0/1 we should
  2359. * power down the second channel on PHY0 as well.
  2360. */
  2361. if (phy == DPIO_PHY1)
  2362. val |= OCL2_LDOFUSE_PWR_DIS;
  2363. I915_WRITE(BXT_PORT_CL1CM_DW30(phy), val);
  2364. if (phy == DPIO_PHY0) {
  2365. uint32_t grc_code;
  2366. /*
  2367. * PHY0 isn't connected to an RCOMP resistor so copy over
  2368. * the corresponding calibrated value from PHY1, and disable
  2369. * the automatic calibration on PHY0.
  2370. */
  2371. if (wait_for(I915_READ(BXT_PORT_REF_DW3(DPIO_PHY1)) & GRC_DONE,
  2372. 10))
  2373. DRM_ERROR("timeout waiting for PHY1 GRC\n");
  2374. val = I915_READ(BXT_PORT_REF_DW6(DPIO_PHY1));
  2375. val = (val & GRC_CODE_MASK) >> GRC_CODE_SHIFT;
  2376. grc_code = val << GRC_CODE_FAST_SHIFT |
  2377. val << GRC_CODE_SLOW_SHIFT |
  2378. val;
  2379. I915_WRITE(BXT_PORT_REF_DW6(DPIO_PHY0), grc_code);
  2380. val = I915_READ(BXT_PORT_REF_DW8(DPIO_PHY0));
  2381. val |= GRC_DIS | GRC_RDY_OVRD;
  2382. I915_WRITE(BXT_PORT_REF_DW8(DPIO_PHY0), val);
  2383. }
  2384. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  2385. val |= COMMON_RESET_DIS;
  2386. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  2387. }
  2388. void broxton_ddi_phy_init(struct drm_device *dev)
  2389. {
  2390. /* Enable PHY1 first since it provides Rcomp for PHY0 */
  2391. broxton_phy_init(dev->dev_private, DPIO_PHY1);
  2392. broxton_phy_init(dev->dev_private, DPIO_PHY0);
  2393. }
  2394. static void broxton_phy_uninit(struct drm_i915_private *dev_priv,
  2395. enum dpio_phy phy)
  2396. {
  2397. uint32_t val;
  2398. val = I915_READ(BXT_PHY_CTL_FAMILY(phy));
  2399. val &= ~COMMON_RESET_DIS;
  2400. I915_WRITE(BXT_PHY_CTL_FAMILY(phy), val);
  2401. }
  2402. void broxton_ddi_phy_uninit(struct drm_device *dev)
  2403. {
  2404. struct drm_i915_private *dev_priv = dev->dev_private;
  2405. broxton_phy_uninit(dev_priv, DPIO_PHY1);
  2406. broxton_phy_uninit(dev_priv, DPIO_PHY0);
  2407. /* FIXME: do this in broxton_phy_uninit per phy */
  2408. I915_WRITE(BXT_P_CR_GT_DISP_PWRON, 0);
  2409. }
  2410. static const char * const bxt_ddi_pll_names[] = {
  2411. "PORT PLL A",
  2412. "PORT PLL B",
  2413. "PORT PLL C",
  2414. };
  2415. static void bxt_ddi_pll_enable(struct drm_i915_private *dev_priv,
  2416. struct intel_shared_dpll *pll)
  2417. {
  2418. uint32_t temp;
  2419. enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
  2420. temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
  2421. temp &= ~PORT_PLL_REF_SEL;
  2422. /* Non-SSC reference */
  2423. I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
  2424. /* Disable 10 bit clock */
  2425. temp = I915_READ(BXT_PORT_PLL_EBB_4(port));
  2426. temp &= ~PORT_PLL_10BIT_CLK_ENABLE;
  2427. I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
  2428. /* Write P1 & P2 */
  2429. temp = I915_READ(BXT_PORT_PLL_EBB_0(port));
  2430. temp &= ~(PORT_PLL_P1_MASK | PORT_PLL_P2_MASK);
  2431. temp |= pll->config.hw_state.ebb0;
  2432. I915_WRITE(BXT_PORT_PLL_EBB_0(port), temp);
  2433. /* Write M2 integer */
  2434. temp = I915_READ(BXT_PORT_PLL(port, 0));
  2435. temp &= ~PORT_PLL_M2_MASK;
  2436. temp |= pll->config.hw_state.pll0;
  2437. I915_WRITE(BXT_PORT_PLL(port, 0), temp);
  2438. /* Write N */
  2439. temp = I915_READ(BXT_PORT_PLL(port, 1));
  2440. temp &= ~PORT_PLL_N_MASK;
  2441. temp |= pll->config.hw_state.pll1;
  2442. I915_WRITE(BXT_PORT_PLL(port, 1), temp);
  2443. /* Write M2 fraction */
  2444. temp = I915_READ(BXT_PORT_PLL(port, 2));
  2445. temp &= ~PORT_PLL_M2_FRAC_MASK;
  2446. temp |= pll->config.hw_state.pll2;
  2447. I915_WRITE(BXT_PORT_PLL(port, 2), temp);
  2448. /* Write M2 fraction enable */
  2449. temp = I915_READ(BXT_PORT_PLL(port, 3));
  2450. temp &= ~PORT_PLL_M2_FRAC_ENABLE;
  2451. temp |= pll->config.hw_state.pll3;
  2452. I915_WRITE(BXT_PORT_PLL(port, 3), temp);
  2453. /* Write coeff */
  2454. temp = I915_READ(BXT_PORT_PLL(port, 6));
  2455. temp &= ~PORT_PLL_PROP_COEFF_MASK;
  2456. temp &= ~PORT_PLL_INT_COEFF_MASK;
  2457. temp &= ~PORT_PLL_GAIN_CTL_MASK;
  2458. temp |= pll->config.hw_state.pll6;
  2459. I915_WRITE(BXT_PORT_PLL(port, 6), temp);
  2460. /* Write calibration val */
  2461. temp = I915_READ(BXT_PORT_PLL(port, 8));
  2462. temp &= ~PORT_PLL_TARGET_CNT_MASK;
  2463. temp |= pll->config.hw_state.pll8;
  2464. I915_WRITE(BXT_PORT_PLL(port, 8), temp);
  2465. temp = I915_READ(BXT_PORT_PLL(port, 9));
  2466. temp &= ~PORT_PLL_LOCK_THRESHOLD_MASK;
  2467. temp |= pll->config.hw_state.pll9;
  2468. I915_WRITE(BXT_PORT_PLL(port, 9), temp);
  2469. temp = I915_READ(BXT_PORT_PLL(port, 10));
  2470. temp &= ~PORT_PLL_DCO_AMP_OVR_EN_H;
  2471. temp &= ~PORT_PLL_DCO_AMP_MASK;
  2472. temp |= pll->config.hw_state.pll10;
  2473. I915_WRITE(BXT_PORT_PLL(port, 10), temp);
  2474. /* Recalibrate with new settings */
  2475. temp = I915_READ(BXT_PORT_PLL_EBB_4(port));
  2476. temp |= PORT_PLL_RECALIBRATE;
  2477. I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
  2478. temp &= ~PORT_PLL_10BIT_CLK_ENABLE;
  2479. temp |= pll->config.hw_state.ebb4;
  2480. I915_WRITE(BXT_PORT_PLL_EBB_4(port), temp);
  2481. /* Enable PLL */
  2482. temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
  2483. temp |= PORT_PLL_ENABLE;
  2484. I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
  2485. POSTING_READ(BXT_PORT_PLL_ENABLE(port));
  2486. if (wait_for_atomic_us((I915_READ(BXT_PORT_PLL_ENABLE(port)) &
  2487. PORT_PLL_LOCK), 200))
  2488. DRM_ERROR("PLL %d not locked\n", port);
  2489. /*
  2490. * While we write to the group register to program all lanes at once we
  2491. * can read only lane registers and we pick lanes 0/1 for that.
  2492. */
  2493. temp = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
  2494. temp &= ~LANE_STAGGER_MASK;
  2495. temp &= ~LANESTAGGER_STRAP_OVRD;
  2496. temp |= pll->config.hw_state.pcsdw12;
  2497. I915_WRITE(BXT_PORT_PCS_DW12_GRP(port), temp);
  2498. }
  2499. static void bxt_ddi_pll_disable(struct drm_i915_private *dev_priv,
  2500. struct intel_shared_dpll *pll)
  2501. {
  2502. enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
  2503. uint32_t temp;
  2504. temp = I915_READ(BXT_PORT_PLL_ENABLE(port));
  2505. temp &= ~PORT_PLL_ENABLE;
  2506. I915_WRITE(BXT_PORT_PLL_ENABLE(port), temp);
  2507. POSTING_READ(BXT_PORT_PLL_ENABLE(port));
  2508. }
  2509. static bool bxt_ddi_pll_get_hw_state(struct drm_i915_private *dev_priv,
  2510. struct intel_shared_dpll *pll,
  2511. struct intel_dpll_hw_state *hw_state)
  2512. {
  2513. enum port port = (enum port)pll->id; /* 1:1 port->PLL mapping */
  2514. uint32_t val;
  2515. if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS))
  2516. return false;
  2517. val = I915_READ(BXT_PORT_PLL_ENABLE(port));
  2518. if (!(val & PORT_PLL_ENABLE))
  2519. return false;
  2520. hw_state->ebb0 = I915_READ(BXT_PORT_PLL_EBB_0(port));
  2521. hw_state->ebb0 &= PORT_PLL_P1_MASK | PORT_PLL_P2_MASK;
  2522. hw_state->ebb4 = I915_READ(BXT_PORT_PLL_EBB_4(port));
  2523. hw_state->ebb4 &= PORT_PLL_10BIT_CLK_ENABLE;
  2524. hw_state->pll0 = I915_READ(BXT_PORT_PLL(port, 0));
  2525. hw_state->pll0 &= PORT_PLL_M2_MASK;
  2526. hw_state->pll1 = I915_READ(BXT_PORT_PLL(port, 1));
  2527. hw_state->pll1 &= PORT_PLL_N_MASK;
  2528. hw_state->pll2 = I915_READ(BXT_PORT_PLL(port, 2));
  2529. hw_state->pll2 &= PORT_PLL_M2_FRAC_MASK;
  2530. hw_state->pll3 = I915_READ(BXT_PORT_PLL(port, 3));
  2531. hw_state->pll3 &= PORT_PLL_M2_FRAC_ENABLE;
  2532. hw_state->pll6 = I915_READ(BXT_PORT_PLL(port, 6));
  2533. hw_state->pll6 &= PORT_PLL_PROP_COEFF_MASK |
  2534. PORT_PLL_INT_COEFF_MASK |
  2535. PORT_PLL_GAIN_CTL_MASK;
  2536. hw_state->pll8 = I915_READ(BXT_PORT_PLL(port, 8));
  2537. hw_state->pll8 &= PORT_PLL_TARGET_CNT_MASK;
  2538. hw_state->pll9 = I915_READ(BXT_PORT_PLL(port, 9));
  2539. hw_state->pll9 &= PORT_PLL_LOCK_THRESHOLD_MASK;
  2540. hw_state->pll10 = I915_READ(BXT_PORT_PLL(port, 10));
  2541. hw_state->pll10 &= PORT_PLL_DCO_AMP_OVR_EN_H |
  2542. PORT_PLL_DCO_AMP_MASK;
  2543. /*
  2544. * While we write to the group register to program all lanes at once we
  2545. * can read only lane registers. We configure all lanes the same way, so
  2546. * here just read out lanes 0/1 and output a note if lanes 2/3 differ.
  2547. */
  2548. hw_state->pcsdw12 = I915_READ(BXT_PORT_PCS_DW12_LN01(port));
  2549. if (I915_READ(BXT_PORT_PCS_DW12_LN23(port)) != hw_state->pcsdw12)
  2550. DRM_DEBUG_DRIVER("lane stagger config different for lane 01 (%08x) and 23 (%08x)\n",
  2551. hw_state->pcsdw12,
  2552. I915_READ(BXT_PORT_PCS_DW12_LN23(port)));
  2553. hw_state->pcsdw12 &= LANE_STAGGER_MASK | LANESTAGGER_STRAP_OVRD;
  2554. return true;
  2555. }
  2556. static void bxt_shared_dplls_init(struct drm_i915_private *dev_priv)
  2557. {
  2558. int i;
  2559. dev_priv->num_shared_dpll = 3;
  2560. for (i = 0; i < dev_priv->num_shared_dpll; i++) {
  2561. dev_priv->shared_dplls[i].id = i;
  2562. dev_priv->shared_dplls[i].name = bxt_ddi_pll_names[i];
  2563. dev_priv->shared_dplls[i].disable = bxt_ddi_pll_disable;
  2564. dev_priv->shared_dplls[i].enable = bxt_ddi_pll_enable;
  2565. dev_priv->shared_dplls[i].get_hw_state =
  2566. bxt_ddi_pll_get_hw_state;
  2567. }
  2568. }
  2569. void intel_ddi_pll_init(struct drm_device *dev)
  2570. {
  2571. struct drm_i915_private *dev_priv = dev->dev_private;
  2572. uint32_t val = I915_READ(LCPLL_CTL);
  2573. if (IS_SKYLAKE(dev))
  2574. skl_shared_dplls_init(dev_priv);
  2575. else if (IS_BROXTON(dev))
  2576. bxt_shared_dplls_init(dev_priv);
  2577. else
  2578. hsw_shared_dplls_init(dev_priv);
  2579. if (IS_SKYLAKE(dev)) {
  2580. int cdclk_freq;
  2581. cdclk_freq = dev_priv->display.get_display_clock_speed(dev);
  2582. dev_priv->skl_boot_cdclk = cdclk_freq;
  2583. if (!(I915_READ(LCPLL1_CTL) & LCPLL_PLL_ENABLE))
  2584. DRM_ERROR("LCPLL1 is disabled\n");
  2585. else
  2586. intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS);
  2587. } else if (IS_BROXTON(dev)) {
  2588. broxton_init_cdclk(dev);
  2589. broxton_ddi_phy_init(dev);
  2590. } else {
  2591. /*
  2592. * The LCPLL register should be turned on by the BIOS. For now
  2593. * let's just check its state and print errors in case
  2594. * something is wrong. Don't even try to turn it on.
  2595. */
  2596. if (val & LCPLL_CD_SOURCE_FCLK)
  2597. DRM_ERROR("CDCLK source is not LCPLL\n");
  2598. if (val & LCPLL_PLL_DISABLE)
  2599. DRM_ERROR("LCPLL is disabled\n");
  2600. }
  2601. }
  2602. void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
  2603. {
  2604. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  2605. struct intel_dp *intel_dp = &intel_dig_port->dp;
  2606. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  2607. enum port port = intel_dig_port->port;
  2608. uint32_t val;
  2609. bool wait = false;
  2610. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  2611. val = I915_READ(DDI_BUF_CTL(port));
  2612. if (val & DDI_BUF_CTL_ENABLE) {
  2613. val &= ~DDI_BUF_CTL_ENABLE;
  2614. I915_WRITE(DDI_BUF_CTL(port), val);
  2615. wait = true;
  2616. }
  2617. val = I915_READ(DP_TP_CTL(port));
  2618. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  2619. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2620. I915_WRITE(DP_TP_CTL(port), val);
  2621. POSTING_READ(DP_TP_CTL(port));
  2622. if (wait)
  2623. intel_wait_ddi_buf_idle(dev_priv, port);
  2624. }
  2625. val = DP_TP_CTL_ENABLE |
  2626. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  2627. if (intel_dp->is_mst)
  2628. val |= DP_TP_CTL_MODE_MST;
  2629. else {
  2630. val |= DP_TP_CTL_MODE_SST;
  2631. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  2632. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  2633. }
  2634. I915_WRITE(DP_TP_CTL(port), val);
  2635. POSTING_READ(DP_TP_CTL(port));
  2636. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  2637. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  2638. POSTING_READ(DDI_BUF_CTL(port));
  2639. udelay(600);
  2640. }
  2641. void intel_ddi_fdi_disable(struct drm_crtc *crtc)
  2642. {
  2643. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  2644. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  2645. uint32_t val;
  2646. intel_ddi_post_disable(intel_encoder);
  2647. val = I915_READ(FDI_RX_CTL(PIPE_A));
  2648. val &= ~FDI_RX_ENABLE;
  2649. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  2650. val = I915_READ(FDI_RX_MISC(PIPE_A));
  2651. val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  2652. val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  2653. I915_WRITE(FDI_RX_MISC(PIPE_A), val);
  2654. val = I915_READ(FDI_RX_CTL(PIPE_A));
  2655. val &= ~FDI_PCDCLK;
  2656. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  2657. val = I915_READ(FDI_RX_CTL(PIPE_A));
  2658. val &= ~FDI_RX_PLL_ENABLE;
  2659. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  2660. }
  2661. void intel_ddi_get_config(struct intel_encoder *encoder,
  2662. struct intel_crtc_state *pipe_config)
  2663. {
  2664. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  2665. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  2666. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  2667. struct intel_hdmi *intel_hdmi;
  2668. u32 temp, flags = 0;
  2669. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  2670. if (temp & TRANS_DDI_PHSYNC)
  2671. flags |= DRM_MODE_FLAG_PHSYNC;
  2672. else
  2673. flags |= DRM_MODE_FLAG_NHSYNC;
  2674. if (temp & TRANS_DDI_PVSYNC)
  2675. flags |= DRM_MODE_FLAG_PVSYNC;
  2676. else
  2677. flags |= DRM_MODE_FLAG_NVSYNC;
  2678. pipe_config->base.adjusted_mode.flags |= flags;
  2679. switch (temp & TRANS_DDI_BPC_MASK) {
  2680. case TRANS_DDI_BPC_6:
  2681. pipe_config->pipe_bpp = 18;
  2682. break;
  2683. case TRANS_DDI_BPC_8:
  2684. pipe_config->pipe_bpp = 24;
  2685. break;
  2686. case TRANS_DDI_BPC_10:
  2687. pipe_config->pipe_bpp = 30;
  2688. break;
  2689. case TRANS_DDI_BPC_12:
  2690. pipe_config->pipe_bpp = 36;
  2691. break;
  2692. default:
  2693. break;
  2694. }
  2695. switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
  2696. case TRANS_DDI_MODE_SELECT_HDMI:
  2697. pipe_config->has_hdmi_sink = true;
  2698. intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  2699. if (intel_hdmi->infoframe_enabled(&encoder->base))
  2700. pipe_config->has_infoframe = true;
  2701. break;
  2702. case TRANS_DDI_MODE_SELECT_DVI:
  2703. case TRANS_DDI_MODE_SELECT_FDI:
  2704. break;
  2705. case TRANS_DDI_MODE_SELECT_DP_SST:
  2706. case TRANS_DDI_MODE_SELECT_DP_MST:
  2707. pipe_config->has_dp_encoder = true;
  2708. pipe_config->lane_count =
  2709. ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
  2710. intel_dp_get_m_n(intel_crtc, pipe_config);
  2711. break;
  2712. default:
  2713. break;
  2714. }
  2715. if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
  2716. temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  2717. if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
  2718. pipe_config->has_audio = true;
  2719. }
  2720. if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
  2721. pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
  2722. /*
  2723. * This is a big fat ugly hack.
  2724. *
  2725. * Some machines in UEFI boot mode provide us a VBT that has 18
  2726. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  2727. * unknown we fail to light up. Yet the same BIOS boots up with
  2728. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  2729. * max, not what it tells us to use.
  2730. *
  2731. * Note: This will still be broken if the eDP panel is not lit
  2732. * up by the BIOS, and thus we can't get the mode at module
  2733. * load.
  2734. */
  2735. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  2736. pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
  2737. dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
  2738. }
  2739. intel_ddi_clock_get(encoder, pipe_config);
  2740. }
  2741. static bool intel_ddi_compute_config(struct intel_encoder *encoder,
  2742. struct intel_crtc_state *pipe_config)
  2743. {
  2744. int type = encoder->type;
  2745. int port = intel_ddi_get_encoder_port(encoder);
  2746. WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
  2747. if (port == PORT_A)
  2748. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  2749. if (type == INTEL_OUTPUT_HDMI)
  2750. return intel_hdmi_compute_config(encoder, pipe_config);
  2751. else
  2752. return intel_dp_compute_config(encoder, pipe_config);
  2753. }
  2754. static const struct drm_encoder_funcs intel_ddi_funcs = {
  2755. .reset = intel_dp_encoder_reset,
  2756. .destroy = intel_dp_encoder_destroy,
  2757. };
  2758. static struct intel_connector *
  2759. intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
  2760. {
  2761. struct intel_connector *connector;
  2762. enum port port = intel_dig_port->port;
  2763. connector = intel_connector_alloc();
  2764. if (!connector)
  2765. return NULL;
  2766. intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
  2767. if (!intel_dp_init_connector(intel_dig_port, connector)) {
  2768. kfree(connector);
  2769. return NULL;
  2770. }
  2771. return connector;
  2772. }
  2773. static struct intel_connector *
  2774. intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
  2775. {
  2776. struct intel_connector *connector;
  2777. enum port port = intel_dig_port->port;
  2778. connector = intel_connector_alloc();
  2779. if (!connector)
  2780. return NULL;
  2781. intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
  2782. intel_hdmi_init_connector(intel_dig_port, connector);
  2783. return connector;
  2784. }
  2785. void intel_ddi_init(struct drm_device *dev, enum port port)
  2786. {
  2787. struct drm_i915_private *dev_priv = dev->dev_private;
  2788. struct intel_digital_port *intel_dig_port;
  2789. struct intel_encoder *intel_encoder;
  2790. struct drm_encoder *encoder;
  2791. bool init_hdmi, init_dp;
  2792. init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
  2793. dev_priv->vbt.ddi_port_info[port].supports_hdmi);
  2794. init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
  2795. if (!init_dp && !init_hdmi) {
  2796. DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
  2797. port_name(port));
  2798. return;
  2799. }
  2800. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  2801. if (!intel_dig_port)
  2802. return;
  2803. intel_encoder = &intel_dig_port->base;
  2804. encoder = &intel_encoder->base;
  2805. drm_encoder_init(dev, encoder, &intel_ddi_funcs,
  2806. DRM_MODE_ENCODER_TMDS);
  2807. intel_encoder->compute_config = intel_ddi_compute_config;
  2808. intel_encoder->enable = intel_enable_ddi;
  2809. intel_encoder->pre_enable = intel_ddi_pre_enable;
  2810. intel_encoder->disable = intel_disable_ddi;
  2811. intel_encoder->post_disable = intel_ddi_post_disable;
  2812. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  2813. intel_encoder->get_config = intel_ddi_get_config;
  2814. intel_encoder->suspend = intel_dp_encoder_suspend;
  2815. intel_dig_port->port = port;
  2816. intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
  2817. (DDI_BUF_PORT_REVERSAL |
  2818. DDI_A_4_LANES);
  2819. intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
  2820. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  2821. intel_encoder->cloneable = 0;
  2822. if (init_dp) {
  2823. if (!intel_ddi_init_dp_connector(intel_dig_port))
  2824. goto err;
  2825. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  2826. /*
  2827. * On BXT A0/A1, sw needs to activate DDIA HPD logic and
  2828. * interrupts to check the external panel connection.
  2829. */
  2830. if (IS_BROXTON(dev_priv) && (INTEL_REVID(dev) < BXT_REVID_B0)
  2831. && port == PORT_B)
  2832. dev_priv->hotplug.irq_port[PORT_A] = intel_dig_port;
  2833. else
  2834. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  2835. }
  2836. /* In theory we don't need the encoder->type check, but leave it just in
  2837. * case we have some really bad VBTs... */
  2838. if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
  2839. if (!intel_ddi_init_hdmi_connector(intel_dig_port))
  2840. goto err;
  2841. }
  2842. return;
  2843. err:
  2844. drm_encoder_cleanup(encoder);
  2845. kfree(intel_dig_port);
  2846. }