intel_ddi.c 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766
  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. static const u8 index_to_dp_signal_levels[] = {
  35. [0] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0,
  36. [1] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1,
  37. [2] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2,
  38. [3] = DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3,
  39. [4] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0,
  40. [5] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1,
  41. [6] = DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2,
  42. [7] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0,
  43. [8] = DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1,
  44. [9] = DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0,
  45. };
  46. /* HDMI/DVI modes ignore everything but the last 2 items. So we share
  47. * them for both DP and FDI transports, allowing those ports to
  48. * automatically adapt to HDMI connections as well
  49. */
  50. static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
  51. { 0x00FFFFFF, 0x0006000E, 0x0 },
  52. { 0x00D75FFF, 0x0005000A, 0x0 },
  53. { 0x00C30FFF, 0x00040006, 0x0 },
  54. { 0x80AAAFFF, 0x000B0000, 0x0 },
  55. { 0x00FFFFFF, 0x0005000A, 0x0 },
  56. { 0x00D75FFF, 0x000C0004, 0x0 },
  57. { 0x80C30FFF, 0x000B0000, 0x0 },
  58. { 0x00FFFFFF, 0x00040006, 0x0 },
  59. { 0x80D75FFF, 0x000B0000, 0x0 },
  60. };
  61. static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
  62. { 0x00FFFFFF, 0x0007000E, 0x0 },
  63. { 0x00D75FFF, 0x000F000A, 0x0 },
  64. { 0x00C30FFF, 0x00060006, 0x0 },
  65. { 0x00AAAFFF, 0x001E0000, 0x0 },
  66. { 0x00FFFFFF, 0x000F000A, 0x0 },
  67. { 0x00D75FFF, 0x00160004, 0x0 },
  68. { 0x00C30FFF, 0x001E0000, 0x0 },
  69. { 0x00FFFFFF, 0x00060006, 0x0 },
  70. { 0x00D75FFF, 0x001E0000, 0x0 },
  71. };
  72. static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
  73. /* Idx NT mV d T mV d db */
  74. { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */
  75. { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */
  76. { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */
  77. { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */
  78. { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */
  79. { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */
  80. { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */
  81. { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */
  82. { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */
  83. { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */
  84. { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */
  85. { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */
  86. };
  87. static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
  88. { 0x00FFFFFF, 0x00000012, 0x0 },
  89. { 0x00EBAFFF, 0x00020011, 0x0 },
  90. { 0x00C71FFF, 0x0006000F, 0x0 },
  91. { 0x00AAAFFF, 0x000E000A, 0x0 },
  92. { 0x00FFFFFF, 0x00020011, 0x0 },
  93. { 0x00DB6FFF, 0x0005000F, 0x0 },
  94. { 0x00BEEFFF, 0x000A000C, 0x0 },
  95. { 0x00FFFFFF, 0x0005000F, 0x0 },
  96. { 0x00DB6FFF, 0x000A000C, 0x0 },
  97. };
  98. static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
  99. { 0x00FFFFFF, 0x0007000E, 0x0 },
  100. { 0x00D75FFF, 0x000E000A, 0x0 },
  101. { 0x00BEFFFF, 0x00140006, 0x0 },
  102. { 0x80B2CFFF, 0x001B0002, 0x0 },
  103. { 0x00FFFFFF, 0x000E000A, 0x0 },
  104. { 0x00DB6FFF, 0x00160005, 0x0 },
  105. { 0x80C71FFF, 0x001A0002, 0x0 },
  106. { 0x00F7DFFF, 0x00180004, 0x0 },
  107. { 0x80D75FFF, 0x001B0002, 0x0 },
  108. };
  109. static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
  110. { 0x00FFFFFF, 0x0001000E, 0x0 },
  111. { 0x00D75FFF, 0x0004000A, 0x0 },
  112. { 0x00C30FFF, 0x00070006, 0x0 },
  113. { 0x00AAAFFF, 0x000C0000, 0x0 },
  114. { 0x00FFFFFF, 0x0004000A, 0x0 },
  115. { 0x00D75FFF, 0x00090004, 0x0 },
  116. { 0x00C30FFF, 0x000C0000, 0x0 },
  117. { 0x00FFFFFF, 0x00070006, 0x0 },
  118. { 0x00D75FFF, 0x000C0000, 0x0 },
  119. };
  120. static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
  121. /* Idx NT mV d T mV df db */
  122. { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */
  123. { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */
  124. { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */
  125. { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */
  126. { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */
  127. { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */
  128. { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */
  129. { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */
  130. { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */
  131. { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */
  132. };
  133. /* Skylake H and S */
  134. static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
  135. { 0x00002016, 0x000000A0, 0x0 },
  136. { 0x00005012, 0x0000009B, 0x0 },
  137. { 0x00007011, 0x00000088, 0x0 },
  138. { 0x80009010, 0x000000C0, 0x1 },
  139. { 0x00002016, 0x0000009B, 0x0 },
  140. { 0x00005012, 0x00000088, 0x0 },
  141. { 0x80007011, 0x000000C0, 0x1 },
  142. { 0x00002016, 0x000000DF, 0x0 },
  143. { 0x80005012, 0x000000C0, 0x1 },
  144. };
  145. /* Skylake U */
  146. static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
  147. { 0x0000201B, 0x000000A2, 0x0 },
  148. { 0x00005012, 0x00000088, 0x0 },
  149. { 0x80007011, 0x000000CD, 0x1 },
  150. { 0x80009010, 0x000000C0, 0x1 },
  151. { 0x0000201B, 0x0000009D, 0x0 },
  152. { 0x80005012, 0x000000C0, 0x1 },
  153. { 0x80007011, 0x000000C0, 0x1 },
  154. { 0x00002016, 0x00000088, 0x0 },
  155. { 0x80005012, 0x000000C0, 0x1 },
  156. };
  157. /* Skylake Y */
  158. static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
  159. { 0x00000018, 0x000000A2, 0x0 },
  160. { 0x00005012, 0x00000088, 0x0 },
  161. { 0x80007011, 0x000000CD, 0x3 },
  162. { 0x80009010, 0x000000C0, 0x3 },
  163. { 0x00000018, 0x0000009D, 0x0 },
  164. { 0x80005012, 0x000000C0, 0x3 },
  165. { 0x80007011, 0x000000C0, 0x3 },
  166. { 0x00000018, 0x00000088, 0x0 },
  167. { 0x80005012, 0x000000C0, 0x3 },
  168. };
  169. /* Kabylake H and S */
  170. static const struct ddi_buf_trans kbl_ddi_translations_dp[] = {
  171. { 0x00002016, 0x000000A0, 0x0 },
  172. { 0x00005012, 0x0000009B, 0x0 },
  173. { 0x00007011, 0x00000088, 0x0 },
  174. { 0x80009010, 0x000000C0, 0x1 },
  175. { 0x00002016, 0x0000009B, 0x0 },
  176. { 0x00005012, 0x00000088, 0x0 },
  177. { 0x80007011, 0x000000C0, 0x1 },
  178. { 0x00002016, 0x00000097, 0x0 },
  179. { 0x80005012, 0x000000C0, 0x1 },
  180. };
  181. /* Kabylake U */
  182. static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = {
  183. { 0x0000201B, 0x000000A1, 0x0 },
  184. { 0x00005012, 0x00000088, 0x0 },
  185. { 0x80007011, 0x000000CD, 0x3 },
  186. { 0x80009010, 0x000000C0, 0x3 },
  187. { 0x0000201B, 0x0000009D, 0x0 },
  188. { 0x80005012, 0x000000C0, 0x3 },
  189. { 0x80007011, 0x000000C0, 0x3 },
  190. { 0x00002016, 0x0000004F, 0x0 },
  191. { 0x80005012, 0x000000C0, 0x3 },
  192. };
  193. /* Kabylake Y */
  194. static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = {
  195. { 0x00001017, 0x000000A1, 0x0 },
  196. { 0x00005012, 0x00000088, 0x0 },
  197. { 0x80007011, 0x000000CD, 0x3 },
  198. { 0x8000800F, 0x000000C0, 0x3 },
  199. { 0x00001017, 0x0000009D, 0x0 },
  200. { 0x80005012, 0x000000C0, 0x3 },
  201. { 0x80007011, 0x000000C0, 0x3 },
  202. { 0x00001017, 0x0000004C, 0x0 },
  203. { 0x80005012, 0x000000C0, 0x3 },
  204. };
  205. /*
  206. * Skylake/Kabylake H and S
  207. * eDP 1.4 low vswing translation parameters
  208. */
  209. static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
  210. { 0x00000018, 0x000000A8, 0x0 },
  211. { 0x00004013, 0x000000A9, 0x0 },
  212. { 0x00007011, 0x000000A2, 0x0 },
  213. { 0x00009010, 0x0000009C, 0x0 },
  214. { 0x00000018, 0x000000A9, 0x0 },
  215. { 0x00006013, 0x000000A2, 0x0 },
  216. { 0x00007011, 0x000000A6, 0x0 },
  217. { 0x00000018, 0x000000AB, 0x0 },
  218. { 0x00007013, 0x0000009F, 0x0 },
  219. { 0x00000018, 0x000000DF, 0x0 },
  220. };
  221. /*
  222. * Skylake/Kabylake U
  223. * eDP 1.4 low vswing translation parameters
  224. */
  225. static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
  226. { 0x00000018, 0x000000A8, 0x0 },
  227. { 0x00004013, 0x000000A9, 0x0 },
  228. { 0x00007011, 0x000000A2, 0x0 },
  229. { 0x00009010, 0x0000009C, 0x0 },
  230. { 0x00000018, 0x000000A9, 0x0 },
  231. { 0x00006013, 0x000000A2, 0x0 },
  232. { 0x00007011, 0x000000A6, 0x0 },
  233. { 0x00002016, 0x000000AB, 0x0 },
  234. { 0x00005013, 0x0000009F, 0x0 },
  235. { 0x00000018, 0x000000DF, 0x0 },
  236. };
  237. /*
  238. * Skylake/Kabylake Y
  239. * eDP 1.4 low vswing translation parameters
  240. */
  241. static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
  242. { 0x00000018, 0x000000A8, 0x0 },
  243. { 0x00004013, 0x000000AB, 0x0 },
  244. { 0x00007011, 0x000000A4, 0x0 },
  245. { 0x00009010, 0x000000DF, 0x0 },
  246. { 0x00000018, 0x000000AA, 0x0 },
  247. { 0x00006013, 0x000000A4, 0x0 },
  248. { 0x00007011, 0x0000009D, 0x0 },
  249. { 0x00000018, 0x000000A0, 0x0 },
  250. { 0x00006012, 0x000000DF, 0x0 },
  251. { 0x00000018, 0x0000008A, 0x0 },
  252. };
  253. /* Skylake/Kabylake U, H and S */
  254. static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
  255. { 0x00000018, 0x000000AC, 0x0 },
  256. { 0x00005012, 0x0000009D, 0x0 },
  257. { 0x00007011, 0x00000088, 0x0 },
  258. { 0x00000018, 0x000000A1, 0x0 },
  259. { 0x00000018, 0x00000098, 0x0 },
  260. { 0x00004013, 0x00000088, 0x0 },
  261. { 0x80006012, 0x000000CD, 0x1 },
  262. { 0x00000018, 0x000000DF, 0x0 },
  263. { 0x80003015, 0x000000CD, 0x1 }, /* Default */
  264. { 0x80003015, 0x000000C0, 0x1 },
  265. { 0x80000018, 0x000000C0, 0x1 },
  266. };
  267. /* Skylake/Kabylake Y */
  268. static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
  269. { 0x00000018, 0x000000A1, 0x0 },
  270. { 0x00005012, 0x000000DF, 0x0 },
  271. { 0x80007011, 0x000000CB, 0x3 },
  272. { 0x00000018, 0x000000A4, 0x0 },
  273. { 0x00000018, 0x0000009D, 0x0 },
  274. { 0x00004013, 0x00000080, 0x0 },
  275. { 0x80006013, 0x000000C0, 0x3 },
  276. { 0x00000018, 0x0000008A, 0x0 },
  277. { 0x80003015, 0x000000C0, 0x3 }, /* Default */
  278. { 0x80003015, 0x000000C0, 0x3 },
  279. { 0x80000018, 0x000000C0, 0x3 },
  280. };
  281. struct bxt_ddi_buf_trans {
  282. u32 margin; /* swing value */
  283. u32 scale; /* scale value */
  284. u32 enable; /* scale enable */
  285. u32 deemphasis;
  286. bool default_index; /* true if the entry represents default value */
  287. };
  288. static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
  289. /* Idx NT mV diff db */
  290. { 52, 0x9A, 0, 128, true }, /* 0: 400 0 */
  291. { 78, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
  292. { 104, 0x9A, 0, 64, false }, /* 2: 400 6 */
  293. { 154, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
  294. { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
  295. { 116, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
  296. { 154, 0x9A, 0, 64, false }, /* 6: 600 6 */
  297. { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
  298. { 154, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
  299. { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
  300. };
  301. static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
  302. /* Idx NT mV diff db */
  303. { 26, 0, 0, 128, false }, /* 0: 200 0 */
  304. { 38, 0, 0, 112, false }, /* 1: 200 1.5 */
  305. { 48, 0, 0, 96, false }, /* 2: 200 4 */
  306. { 54, 0, 0, 69, false }, /* 3: 200 6 */
  307. { 32, 0, 0, 128, false }, /* 4: 250 0 */
  308. { 48, 0, 0, 104, false }, /* 5: 250 1.5 */
  309. { 54, 0, 0, 85, false }, /* 6: 250 4 */
  310. { 43, 0, 0, 128, false }, /* 7: 300 0 */
  311. { 54, 0, 0, 101, false }, /* 8: 300 1.5 */
  312. { 48, 0, 0, 128, false }, /* 9: 300 0 */
  313. };
  314. /* BSpec has 2 recommended values - entries 0 and 8.
  315. * Using the entry with higher vswing.
  316. */
  317. static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
  318. /* Idx NT mV diff db */
  319. { 52, 0x9A, 0, 128, false }, /* 0: 400 0 */
  320. { 52, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
  321. { 52, 0x9A, 0, 64, false }, /* 2: 400 6 */
  322. { 42, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
  323. { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
  324. { 77, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
  325. { 77, 0x9A, 0, 64, false }, /* 6: 600 6 */
  326. { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
  327. { 102, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
  328. { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
  329. };
  330. struct cnl_ddi_buf_trans {
  331. u32 dw2_swing_sel;
  332. u32 dw7_n_scalar;
  333. u32 dw4_cursor_coeff;
  334. u32 dw4_post_cursor_2;
  335. u32 dw4_post_cursor_1;
  336. };
  337. /* Voltage Swing Programming for VccIO 0.85V for DP */
  338. static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_85V[] = {
  339. /* NT mV Trans mV db */
  340. { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
  341. { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
  342. { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
  343. { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
  344. { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
  345. { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
  346. { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
  347. { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
  348. { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
  349. { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
  350. };
  351. /* Voltage Swing Programming for VccIO 0.85V for HDMI */
  352. static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_85V[] = {
  353. /* NT mV Trans mV db */
  354. { 0xA, 0x60, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
  355. { 0xB, 0x73, 0x36, 0x00, 0x09 }, /* 450 650 3.2 */
  356. { 0x6, 0x7F, 0x31, 0x00, 0x0E }, /* 450 850 5.5 */
  357. { 0xB, 0x73, 0x3F, 0x00, 0x00 }, /* 650 650 0.0 */
  358. { 0x6, 0x7F, 0x37, 0x00, 0x08 }, /* 650 850 2.3 */
  359. { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 850 850 0.0 */
  360. { 0x6, 0x7F, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
  361. };
  362. /* Voltage Swing Programming for VccIO 0.85V for eDP */
  363. static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_85V[] = {
  364. /* NT mV Trans mV db */
  365. { 0xA, 0x66, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
  366. { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
  367. { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
  368. { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
  369. { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
  370. { 0xA, 0x66, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
  371. { 0xB, 0x70, 0x3C, 0x00, 0x03 }, /* 460 600 2.3 */
  372. { 0xC, 0x75, 0x3C, 0x00, 0x03 }, /* 537 700 2.3 */
  373. { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
  374. };
  375. /* Voltage Swing Programming for VccIO 0.95V for DP */
  376. static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_0_95V[] = {
  377. /* NT mV Trans mV db */
  378. { 0xA, 0x5D, 0x3F, 0x00, 0x00 }, /* 350 350 0.0 */
  379. { 0xA, 0x6A, 0x38, 0x00, 0x07 }, /* 350 500 3.1 */
  380. { 0xB, 0x7A, 0x32, 0x00, 0x0D }, /* 350 700 6.0 */
  381. { 0x6, 0x7C, 0x2D, 0x00, 0x12 }, /* 350 900 8.2 */
  382. { 0xA, 0x69, 0x3F, 0x00, 0x00 }, /* 500 500 0.0 */
  383. { 0xB, 0x7A, 0x36, 0x00, 0x09 }, /* 500 700 2.9 */
  384. { 0x6, 0x7C, 0x30, 0x00, 0x0F }, /* 500 900 5.1 */
  385. { 0xB, 0x7D, 0x3C, 0x00, 0x03 }, /* 650 725 0.9 */
  386. { 0x6, 0x7C, 0x34, 0x00, 0x0B }, /* 600 900 3.5 */
  387. { 0x6, 0x7B, 0x3F, 0x00, 0x00 }, /* 900 900 0.0 */
  388. };
  389. /* Voltage Swing Programming for VccIO 0.95V for HDMI */
  390. static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_0_95V[] = {
  391. /* NT mV Trans mV db */
  392. { 0xA, 0x5C, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
  393. { 0xB, 0x69, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
  394. { 0x5, 0x76, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
  395. { 0xA, 0x5E, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
  396. { 0xB, 0x69, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
  397. { 0xB, 0x79, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
  398. { 0x6, 0x7D, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
  399. { 0x5, 0x76, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
  400. { 0x6, 0x7D, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
  401. { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
  402. { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
  403. };
  404. /* Voltage Swing Programming for VccIO 0.95V for eDP */
  405. static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_0_95V[] = {
  406. /* NT mV Trans mV db */
  407. { 0xA, 0x61, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
  408. { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
  409. { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
  410. { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
  411. { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
  412. { 0xA, 0x61, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
  413. { 0xB, 0x68, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
  414. { 0xC, 0x6E, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
  415. { 0x4, 0x7F, 0x3A, 0x00, 0x05 }, /* 460 600 2.3 */
  416. { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
  417. };
  418. /* Voltage Swing Programming for VccIO 1.05V for DP */
  419. static const struct cnl_ddi_buf_trans cnl_ddi_translations_dp_1_05V[] = {
  420. /* NT mV Trans mV db */
  421. { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
  422. { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
  423. { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
  424. { 0x6, 0x7F, 0x2C, 0x00, 0x13 }, /* 400 1050 8.4 */
  425. { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
  426. { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
  427. { 0x6, 0x7F, 0x30, 0x00, 0x0F }, /* 550 1050 5.6 */
  428. { 0x5, 0x76, 0x3E, 0x00, 0x01 }, /* 850 900 0.5 */
  429. { 0x6, 0x7F, 0x36, 0x00, 0x09 }, /* 750 1050 2.9 */
  430. { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
  431. };
  432. /* Voltage Swing Programming for VccIO 1.05V for HDMI */
  433. static const struct cnl_ddi_buf_trans cnl_ddi_translations_hdmi_1_05V[] = {
  434. /* NT mV Trans mV db */
  435. { 0xA, 0x58, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
  436. { 0xB, 0x64, 0x37, 0x00, 0x08 }, /* 400 600 3.5 */
  437. { 0x5, 0x70, 0x31, 0x00, 0x0E }, /* 400 800 6.0 */
  438. { 0xA, 0x5B, 0x3F, 0x00, 0x00 }, /* 450 450 0.0 */
  439. { 0xB, 0x64, 0x3F, 0x00, 0x00 }, /* 600 600 0.0 */
  440. { 0x5, 0x73, 0x35, 0x00, 0x0A }, /* 600 850 3.0 */
  441. { 0x6, 0x7C, 0x32, 0x00, 0x0D }, /* 600 1000 4.4 */
  442. { 0x5, 0x70, 0x3F, 0x00, 0x00 }, /* 800 800 0.0 */
  443. { 0x6, 0x7C, 0x39, 0x00, 0x06 }, /* 800 1000 1.9 */
  444. { 0x6, 0x7F, 0x39, 0x00, 0x06 }, /* 850 1050 1.8 */
  445. { 0x6, 0x7F, 0x3F, 0x00, 0x00 }, /* 1050 1050 0.0 */
  446. };
  447. /* Voltage Swing Programming for VccIO 1.05V for eDP */
  448. static const struct cnl_ddi_buf_trans cnl_ddi_translations_edp_1_05V[] = {
  449. /* NT mV Trans mV db */
  450. { 0xA, 0x5E, 0x3A, 0x00, 0x05 }, /* 384 500 2.3 */
  451. { 0x0, 0x7F, 0x38, 0x00, 0x07 }, /* 153 200 2.3 */
  452. { 0x8, 0x7F, 0x38, 0x00, 0x07 }, /* 192 250 2.3 */
  453. { 0x1, 0x7F, 0x38, 0x00, 0x07 }, /* 230 300 2.3 */
  454. { 0x9, 0x7F, 0x38, 0x00, 0x07 }, /* 269 350 2.3 */
  455. { 0xA, 0x5E, 0x3C, 0x00, 0x03 }, /* 446 500 1.0 */
  456. { 0xB, 0x64, 0x39, 0x00, 0x06 }, /* 460 600 2.3 */
  457. { 0xE, 0x6A, 0x39, 0x00, 0x06 }, /* 537 700 2.3 */
  458. { 0x2, 0x7F, 0x3F, 0x00, 0x00 }, /* 400 400 0.0 */
  459. };
  460. enum port intel_ddi_get_encoder_port(struct intel_encoder *encoder)
  461. {
  462. switch (encoder->type) {
  463. case INTEL_OUTPUT_DP_MST:
  464. return enc_to_mst(&encoder->base)->primary->port;
  465. case INTEL_OUTPUT_DP:
  466. case INTEL_OUTPUT_EDP:
  467. case INTEL_OUTPUT_HDMI:
  468. case INTEL_OUTPUT_UNKNOWN:
  469. return enc_to_dig_port(&encoder->base)->port;
  470. case INTEL_OUTPUT_ANALOG:
  471. return PORT_E;
  472. default:
  473. MISSING_CASE(encoder->type);
  474. return PORT_A;
  475. }
  476. }
  477. static const struct ddi_buf_trans *
  478. bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
  479. {
  480. if (dev_priv->vbt.edp.low_vswing) {
  481. *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
  482. return bdw_ddi_translations_edp;
  483. } else {
  484. *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  485. return bdw_ddi_translations_dp;
  486. }
  487. }
  488. static const struct ddi_buf_trans *
  489. skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
  490. {
  491. if (IS_SKL_ULX(dev_priv)) {
  492. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
  493. return skl_y_ddi_translations_dp;
  494. } else if (IS_SKL_ULT(dev_priv)) {
  495. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
  496. return skl_u_ddi_translations_dp;
  497. } else {
  498. *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
  499. return skl_ddi_translations_dp;
  500. }
  501. }
  502. static const struct ddi_buf_trans *
  503. kbl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
  504. {
  505. if (IS_KBL_ULX(dev_priv)) {
  506. *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp);
  507. return kbl_y_ddi_translations_dp;
  508. } else if (IS_KBL_ULT(dev_priv) || IS_CFL_ULT(dev_priv)) {
  509. *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
  510. return kbl_u_ddi_translations_dp;
  511. } else {
  512. *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
  513. return kbl_ddi_translations_dp;
  514. }
  515. }
  516. static const struct ddi_buf_trans *
  517. skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
  518. {
  519. if (dev_priv->vbt.edp.low_vswing) {
  520. if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
  521. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
  522. return skl_y_ddi_translations_edp;
  523. } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv) ||
  524. IS_CFL_ULT(dev_priv)) {
  525. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
  526. return skl_u_ddi_translations_edp;
  527. } else {
  528. *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
  529. return skl_ddi_translations_edp;
  530. }
  531. }
  532. if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
  533. return kbl_get_buf_trans_dp(dev_priv, n_entries);
  534. else
  535. return skl_get_buf_trans_dp(dev_priv, n_entries);
  536. }
  537. static const struct ddi_buf_trans *
  538. skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
  539. {
  540. if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
  541. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
  542. return skl_y_ddi_translations_hdmi;
  543. } else {
  544. *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
  545. return skl_ddi_translations_hdmi;
  546. }
  547. }
  548. static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
  549. {
  550. int n_hdmi_entries;
  551. int hdmi_level;
  552. int hdmi_default_entry;
  553. hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
  554. if (IS_GEN9_LP(dev_priv))
  555. return hdmi_level;
  556. if (IS_GEN9_BC(dev_priv)) {
  557. skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
  558. hdmi_default_entry = 8;
  559. } else if (IS_BROADWELL(dev_priv)) {
  560. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  561. hdmi_default_entry = 7;
  562. } else if (IS_HASWELL(dev_priv)) {
  563. n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
  564. hdmi_default_entry = 6;
  565. } else {
  566. WARN(1, "ddi translation table missing\n");
  567. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  568. hdmi_default_entry = 7;
  569. }
  570. /* Choose a good default if VBT is badly populated */
  571. if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
  572. hdmi_level >= n_hdmi_entries)
  573. hdmi_level = hdmi_default_entry;
  574. return hdmi_level;
  575. }
  576. static const struct ddi_buf_trans *
  577. intel_ddi_get_buf_trans_dp(struct drm_i915_private *dev_priv,
  578. int *n_entries)
  579. {
  580. if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv)) {
  581. return kbl_get_buf_trans_dp(dev_priv, n_entries);
  582. } else if (IS_SKYLAKE(dev_priv)) {
  583. return skl_get_buf_trans_dp(dev_priv, n_entries);
  584. } else if (IS_BROADWELL(dev_priv)) {
  585. *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  586. return bdw_ddi_translations_dp;
  587. } else if (IS_HASWELL(dev_priv)) {
  588. *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
  589. return hsw_ddi_translations_dp;
  590. }
  591. *n_entries = 0;
  592. return NULL;
  593. }
  594. static const struct ddi_buf_trans *
  595. intel_ddi_get_buf_trans_edp(struct drm_i915_private *dev_priv,
  596. int *n_entries)
  597. {
  598. if (IS_GEN9_BC(dev_priv)) {
  599. return skl_get_buf_trans_edp(dev_priv, n_entries);
  600. } else if (IS_BROADWELL(dev_priv)) {
  601. return bdw_get_buf_trans_edp(dev_priv, n_entries);
  602. } else if (IS_HASWELL(dev_priv)) {
  603. *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
  604. return hsw_ddi_translations_dp;
  605. }
  606. *n_entries = 0;
  607. return NULL;
  608. }
  609. static const struct ddi_buf_trans *
  610. intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv,
  611. int *n_entries)
  612. {
  613. if (IS_BROADWELL(dev_priv)) {
  614. *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
  615. return hsw_ddi_translations_fdi;
  616. } else if (IS_HASWELL(dev_priv)) {
  617. *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
  618. return hsw_ddi_translations_fdi;
  619. }
  620. *n_entries = 0;
  621. return NULL;
  622. }
  623. /*
  624. * Starting with Haswell, DDI port buffers must be programmed with correct
  625. * values in advance. This function programs the correct values for
  626. * DP/eDP/FDI use cases.
  627. */
  628. static void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder)
  629. {
  630. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  631. u32 iboost_bit = 0;
  632. int i, n_entries;
  633. enum port port = intel_ddi_get_encoder_port(encoder);
  634. const struct ddi_buf_trans *ddi_translations;
  635. if (IS_GEN9_LP(dev_priv))
  636. return;
  637. switch (encoder->type) {
  638. case INTEL_OUTPUT_EDP:
  639. ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv,
  640. &n_entries);
  641. break;
  642. case INTEL_OUTPUT_DP:
  643. ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv,
  644. &n_entries);
  645. break;
  646. case INTEL_OUTPUT_ANALOG:
  647. ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
  648. &n_entries);
  649. break;
  650. default:
  651. MISSING_CASE(encoder->type);
  652. return;
  653. }
  654. if (IS_GEN9_BC(dev_priv)) {
  655. /* If we're boosting the current, set bit 31 of trans1 */
  656. if (dev_priv->vbt.ddi_port_info[port].dp_boost_level)
  657. iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
  658. if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
  659. port != PORT_A && port != PORT_E &&
  660. n_entries > 9))
  661. n_entries = 9;
  662. }
  663. for (i = 0; i < n_entries; i++) {
  664. I915_WRITE(DDI_BUF_TRANS_LO(port, i),
  665. ddi_translations[i].trans1 | iboost_bit);
  666. I915_WRITE(DDI_BUF_TRANS_HI(port, i),
  667. ddi_translations[i].trans2);
  668. }
  669. }
  670. /*
  671. * Starting with Haswell, DDI port buffers must be programmed with correct
  672. * values in advance. This function programs the correct values for
  673. * HDMI/DVI use cases.
  674. */
  675. static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder)
  676. {
  677. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  678. u32 iboost_bit = 0;
  679. int n_hdmi_entries, hdmi_level;
  680. enum port port = intel_ddi_get_encoder_port(encoder);
  681. const struct ddi_buf_trans *ddi_translations_hdmi;
  682. if (IS_GEN9_LP(dev_priv))
  683. return;
  684. hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
  685. if (IS_GEN9_BC(dev_priv)) {
  686. ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
  687. /* If we're boosting the current, set bit 31 of trans1 */
  688. if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
  689. iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
  690. } else if (IS_BROADWELL(dev_priv)) {
  691. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  692. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  693. } else if (IS_HASWELL(dev_priv)) {
  694. ddi_translations_hdmi = hsw_ddi_translations_hdmi;
  695. n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
  696. } else {
  697. WARN(1, "ddi translation table missing\n");
  698. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  699. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  700. }
  701. /* Entry 9 is for HDMI: */
  702. I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
  703. ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
  704. I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
  705. ddi_translations_hdmi[hdmi_level].trans2);
  706. }
  707. static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
  708. enum port port)
  709. {
  710. i915_reg_t reg = DDI_BUF_CTL(port);
  711. int i;
  712. for (i = 0; i < 16; i++) {
  713. udelay(1);
  714. if (I915_READ(reg) & DDI_BUF_IS_IDLE)
  715. return;
  716. }
  717. DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
  718. }
  719. static uint32_t hsw_pll_to_ddi_pll_sel(struct intel_shared_dpll *pll)
  720. {
  721. switch (pll->id) {
  722. case DPLL_ID_WRPLL1:
  723. return PORT_CLK_SEL_WRPLL1;
  724. case DPLL_ID_WRPLL2:
  725. return PORT_CLK_SEL_WRPLL2;
  726. case DPLL_ID_SPLL:
  727. return PORT_CLK_SEL_SPLL;
  728. case DPLL_ID_LCPLL_810:
  729. return PORT_CLK_SEL_LCPLL_810;
  730. case DPLL_ID_LCPLL_1350:
  731. return PORT_CLK_SEL_LCPLL_1350;
  732. case DPLL_ID_LCPLL_2700:
  733. return PORT_CLK_SEL_LCPLL_2700;
  734. default:
  735. MISSING_CASE(pll->id);
  736. return PORT_CLK_SEL_NONE;
  737. }
  738. }
  739. /* Starting with Haswell, different DDI ports can work in FDI mode for
  740. * connection to the PCH-located connectors. For this, it is necessary to train
  741. * both the DDI port and PCH receiver for the desired DDI buffer settings.
  742. *
  743. * The recommended port to work in FDI mode is DDI E, which we use here. Also,
  744. * please note that when FDI mode is active on DDI E, it shares 2 lines with
  745. * DDI A (which is used for eDP)
  746. */
  747. void hsw_fdi_link_train(struct intel_crtc *crtc,
  748. const struct intel_crtc_state *crtc_state)
  749. {
  750. struct drm_device *dev = crtc->base.dev;
  751. struct drm_i915_private *dev_priv = to_i915(dev);
  752. struct intel_encoder *encoder;
  753. u32 temp, i, rx_ctl_val, ddi_pll_sel;
  754. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  755. WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
  756. intel_prepare_dp_ddi_buffers(encoder);
  757. }
  758. /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
  759. * mode set "sequence for CRT port" document:
  760. * - TP1 to TP2 time with the default value
  761. * - FDI delay to 90h
  762. *
  763. * WaFDIAutoLinkSetTimingOverrride:hsw
  764. */
  765. I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
  766. FDI_RX_PWRDN_LANE0_VAL(2) |
  767. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  768. /* Enable the PCH Receiver FDI PLL */
  769. rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
  770. FDI_RX_PLL_ENABLE |
  771. FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
  772. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  773. POSTING_READ(FDI_RX_CTL(PIPE_A));
  774. udelay(220);
  775. /* Switch from Rawclk to PCDclk */
  776. rx_ctl_val |= FDI_PCDCLK;
  777. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  778. /* Configure Port Clock Select */
  779. ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll);
  780. I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
  781. WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
  782. /* Start the training iterating through available voltages and emphasis,
  783. * testing each value twice. */
  784. for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
  785. /* Configure DP_TP_CTL with auto-training */
  786. I915_WRITE(DP_TP_CTL(PORT_E),
  787. DP_TP_CTL_FDI_AUTOTRAIN |
  788. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  789. DP_TP_CTL_LINK_TRAIN_PAT1 |
  790. DP_TP_CTL_ENABLE);
  791. /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
  792. * DDI E does not support port reversal, the functionality is
  793. * achieved on the PCH side in FDI_RX_CTL, so no need to set the
  794. * port reversal bit */
  795. I915_WRITE(DDI_BUF_CTL(PORT_E),
  796. DDI_BUF_CTL_ENABLE |
  797. ((crtc_state->fdi_lanes - 1) << 1) |
  798. DDI_BUF_TRANS_SELECT(i / 2));
  799. POSTING_READ(DDI_BUF_CTL(PORT_E));
  800. udelay(600);
  801. /* Program PCH FDI Receiver TU */
  802. I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
  803. /* Enable PCH FDI Receiver with auto-training */
  804. rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
  805. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  806. POSTING_READ(FDI_RX_CTL(PIPE_A));
  807. /* Wait for FDI receiver lane calibration */
  808. udelay(30);
  809. /* Unset FDI_RX_MISC pwrdn lanes */
  810. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  811. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  812. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  813. POSTING_READ(FDI_RX_MISC(PIPE_A));
  814. /* Wait for FDI auto training time */
  815. udelay(5);
  816. temp = I915_READ(DP_TP_STATUS(PORT_E));
  817. if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
  818. DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
  819. break;
  820. }
  821. /*
  822. * Leave things enabled even if we failed to train FDI.
  823. * Results in less fireworks from the state checker.
  824. */
  825. if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
  826. DRM_ERROR("FDI link training failed!\n");
  827. break;
  828. }
  829. rx_ctl_val &= ~FDI_RX_ENABLE;
  830. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  831. POSTING_READ(FDI_RX_CTL(PIPE_A));
  832. temp = I915_READ(DDI_BUF_CTL(PORT_E));
  833. temp &= ~DDI_BUF_CTL_ENABLE;
  834. I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
  835. POSTING_READ(DDI_BUF_CTL(PORT_E));
  836. /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
  837. temp = I915_READ(DP_TP_CTL(PORT_E));
  838. temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  839. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  840. I915_WRITE(DP_TP_CTL(PORT_E), temp);
  841. POSTING_READ(DP_TP_CTL(PORT_E));
  842. intel_wait_ddi_buf_idle(dev_priv, PORT_E);
  843. /* Reset FDI_RX_MISC pwrdn lanes */
  844. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  845. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  846. temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  847. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  848. POSTING_READ(FDI_RX_MISC(PIPE_A));
  849. }
  850. /* Enable normal pixel sending for FDI */
  851. I915_WRITE(DP_TP_CTL(PORT_E),
  852. DP_TP_CTL_FDI_AUTOTRAIN |
  853. DP_TP_CTL_LINK_TRAIN_NORMAL |
  854. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  855. DP_TP_CTL_ENABLE);
  856. }
  857. static void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
  858. {
  859. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  860. struct intel_digital_port *intel_dig_port =
  861. enc_to_dig_port(&encoder->base);
  862. intel_dp->DP = intel_dig_port->saved_port_bits |
  863. DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
  864. intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
  865. }
  866. static struct intel_encoder *
  867. intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
  868. {
  869. struct drm_device *dev = crtc->base.dev;
  870. struct intel_encoder *encoder, *ret = NULL;
  871. int num_encoders = 0;
  872. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  873. ret = encoder;
  874. num_encoders++;
  875. }
  876. if (num_encoders != 1)
  877. WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
  878. pipe_name(crtc->pipe));
  879. BUG_ON(ret == NULL);
  880. return ret;
  881. }
  882. /* Finds the only possible encoder associated with the given CRTC. */
  883. struct intel_encoder *
  884. intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
  885. {
  886. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  887. struct intel_encoder *ret = NULL;
  888. struct drm_atomic_state *state;
  889. struct drm_connector *connector;
  890. struct drm_connector_state *connector_state;
  891. int num_encoders = 0;
  892. int i;
  893. state = crtc_state->base.state;
  894. for_each_new_connector_in_state(state, connector, connector_state, i) {
  895. if (connector_state->crtc != crtc_state->base.crtc)
  896. continue;
  897. ret = to_intel_encoder(connector_state->best_encoder);
  898. num_encoders++;
  899. }
  900. WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
  901. pipe_name(crtc->pipe));
  902. BUG_ON(ret == NULL);
  903. return ret;
  904. }
  905. #define LC_FREQ 2700
  906. static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
  907. i915_reg_t reg)
  908. {
  909. int refclk = LC_FREQ;
  910. int n, p, r;
  911. u32 wrpll;
  912. wrpll = I915_READ(reg);
  913. switch (wrpll & WRPLL_PLL_REF_MASK) {
  914. case WRPLL_PLL_SSC:
  915. case WRPLL_PLL_NON_SSC:
  916. /*
  917. * We could calculate spread here, but our checking
  918. * code only cares about 5% accuracy, and spread is a max of
  919. * 0.5% downspread.
  920. */
  921. refclk = 135;
  922. break;
  923. case WRPLL_PLL_LCPLL:
  924. refclk = LC_FREQ;
  925. break;
  926. default:
  927. WARN(1, "bad wrpll refclk\n");
  928. return 0;
  929. }
  930. r = wrpll & WRPLL_DIVIDER_REF_MASK;
  931. p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
  932. n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
  933. /* Convert to KHz, p & r have a fixed point portion */
  934. return (refclk * n * 100) / (p * r);
  935. }
  936. static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
  937. uint32_t dpll)
  938. {
  939. i915_reg_t cfgcr1_reg, cfgcr2_reg;
  940. uint32_t cfgcr1_val, cfgcr2_val;
  941. uint32_t p0, p1, p2, dco_freq;
  942. cfgcr1_reg = DPLL_CFGCR1(dpll);
  943. cfgcr2_reg = DPLL_CFGCR2(dpll);
  944. cfgcr1_val = I915_READ(cfgcr1_reg);
  945. cfgcr2_val = I915_READ(cfgcr2_reg);
  946. p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
  947. p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
  948. if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
  949. p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
  950. else
  951. p1 = 1;
  952. switch (p0) {
  953. case DPLL_CFGCR2_PDIV_1:
  954. p0 = 1;
  955. break;
  956. case DPLL_CFGCR2_PDIV_2:
  957. p0 = 2;
  958. break;
  959. case DPLL_CFGCR2_PDIV_3:
  960. p0 = 3;
  961. break;
  962. case DPLL_CFGCR2_PDIV_7:
  963. p0 = 7;
  964. break;
  965. }
  966. switch (p2) {
  967. case DPLL_CFGCR2_KDIV_5:
  968. p2 = 5;
  969. break;
  970. case DPLL_CFGCR2_KDIV_2:
  971. p2 = 2;
  972. break;
  973. case DPLL_CFGCR2_KDIV_3:
  974. p2 = 3;
  975. break;
  976. case DPLL_CFGCR2_KDIV_1:
  977. p2 = 1;
  978. break;
  979. }
  980. dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
  981. dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
  982. 1000) / 0x8000;
  983. return dco_freq / (p0 * p1 * p2 * 5);
  984. }
  985. static int cnl_calc_wrpll_link(struct drm_i915_private *dev_priv,
  986. uint32_t pll_id)
  987. {
  988. uint32_t cfgcr0, cfgcr1;
  989. uint32_t p0, p1, p2, dco_freq, ref_clock;
  990. cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
  991. cfgcr1 = I915_READ(CNL_DPLL_CFGCR1(pll_id));
  992. p0 = cfgcr1 & DPLL_CFGCR1_PDIV_MASK;
  993. p2 = cfgcr1 & DPLL_CFGCR1_KDIV_MASK;
  994. if (cfgcr1 & DPLL_CFGCR1_QDIV_MODE(1))
  995. p1 = (cfgcr1 & DPLL_CFGCR1_QDIV_RATIO_MASK) >>
  996. DPLL_CFGCR1_QDIV_RATIO_SHIFT;
  997. else
  998. p1 = 1;
  999. switch (p0) {
  1000. case DPLL_CFGCR1_PDIV_2:
  1001. p0 = 2;
  1002. break;
  1003. case DPLL_CFGCR1_PDIV_3:
  1004. p0 = 3;
  1005. break;
  1006. case DPLL_CFGCR1_PDIV_5:
  1007. p0 = 5;
  1008. break;
  1009. case DPLL_CFGCR1_PDIV_7:
  1010. p0 = 7;
  1011. break;
  1012. }
  1013. switch (p2) {
  1014. case DPLL_CFGCR1_KDIV_1:
  1015. p2 = 1;
  1016. break;
  1017. case DPLL_CFGCR1_KDIV_2:
  1018. p2 = 2;
  1019. break;
  1020. case DPLL_CFGCR1_KDIV_4:
  1021. p2 = 4;
  1022. break;
  1023. }
  1024. ref_clock = dev_priv->cdclk.hw.ref;
  1025. dco_freq = (cfgcr0 & DPLL_CFGCR0_DCO_INTEGER_MASK) * ref_clock;
  1026. dco_freq += (((cfgcr0 & DPLL_CFGCR0_DCO_FRACTION_MASK) >>
  1027. DPLL_CFGCR0_DCO_FRAC_SHIFT) * ref_clock) / 0x8000;
  1028. return dco_freq / (p0 * p1 * p2 * 5);
  1029. }
  1030. static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
  1031. {
  1032. int dotclock;
  1033. if (pipe_config->has_pch_encoder)
  1034. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  1035. &pipe_config->fdi_m_n);
  1036. else if (intel_crtc_has_dp_encoder(pipe_config))
  1037. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  1038. &pipe_config->dp_m_n);
  1039. else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
  1040. dotclock = pipe_config->port_clock * 2 / 3;
  1041. else
  1042. dotclock = pipe_config->port_clock;
  1043. if (pipe_config->ycbcr420)
  1044. dotclock *= 2;
  1045. if (pipe_config->pixel_multiplier)
  1046. dotclock /= pipe_config->pixel_multiplier;
  1047. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  1048. }
  1049. static void cnl_ddi_clock_get(struct intel_encoder *encoder,
  1050. struct intel_crtc_state *pipe_config)
  1051. {
  1052. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1053. int link_clock = 0;
  1054. uint32_t cfgcr0, pll_id;
  1055. pll_id = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
  1056. cfgcr0 = I915_READ(CNL_DPLL_CFGCR0(pll_id));
  1057. if (cfgcr0 & DPLL_CFGCR0_HDMI_MODE) {
  1058. link_clock = cnl_calc_wrpll_link(dev_priv, pll_id);
  1059. } else {
  1060. link_clock = cfgcr0 & DPLL_CFGCR0_LINK_RATE_MASK;
  1061. switch (link_clock) {
  1062. case DPLL_CFGCR0_LINK_RATE_810:
  1063. link_clock = 81000;
  1064. break;
  1065. case DPLL_CFGCR0_LINK_RATE_1080:
  1066. link_clock = 108000;
  1067. break;
  1068. case DPLL_CFGCR0_LINK_RATE_1350:
  1069. link_clock = 135000;
  1070. break;
  1071. case DPLL_CFGCR0_LINK_RATE_1620:
  1072. link_clock = 162000;
  1073. break;
  1074. case DPLL_CFGCR0_LINK_RATE_2160:
  1075. link_clock = 216000;
  1076. break;
  1077. case DPLL_CFGCR0_LINK_RATE_2700:
  1078. link_clock = 270000;
  1079. break;
  1080. case DPLL_CFGCR0_LINK_RATE_3240:
  1081. link_clock = 324000;
  1082. break;
  1083. case DPLL_CFGCR0_LINK_RATE_4050:
  1084. link_clock = 405000;
  1085. break;
  1086. default:
  1087. WARN(1, "Unsupported link rate\n");
  1088. break;
  1089. }
  1090. link_clock *= 2;
  1091. }
  1092. pipe_config->port_clock = link_clock;
  1093. ddi_dotclock_get(pipe_config);
  1094. }
  1095. static void skl_ddi_clock_get(struct intel_encoder *encoder,
  1096. struct intel_crtc_state *pipe_config)
  1097. {
  1098. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1099. int link_clock = 0;
  1100. uint32_t dpll_ctl1, dpll;
  1101. dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
  1102. dpll_ctl1 = I915_READ(DPLL_CTRL1);
  1103. if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
  1104. link_clock = skl_calc_wrpll_link(dev_priv, dpll);
  1105. } else {
  1106. link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
  1107. link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
  1108. switch (link_clock) {
  1109. case DPLL_CTRL1_LINK_RATE_810:
  1110. link_clock = 81000;
  1111. break;
  1112. case DPLL_CTRL1_LINK_RATE_1080:
  1113. link_clock = 108000;
  1114. break;
  1115. case DPLL_CTRL1_LINK_RATE_1350:
  1116. link_clock = 135000;
  1117. break;
  1118. case DPLL_CTRL1_LINK_RATE_1620:
  1119. link_clock = 162000;
  1120. break;
  1121. case DPLL_CTRL1_LINK_RATE_2160:
  1122. link_clock = 216000;
  1123. break;
  1124. case DPLL_CTRL1_LINK_RATE_2700:
  1125. link_clock = 270000;
  1126. break;
  1127. default:
  1128. WARN(1, "Unsupported link rate\n");
  1129. break;
  1130. }
  1131. link_clock *= 2;
  1132. }
  1133. pipe_config->port_clock = link_clock;
  1134. ddi_dotclock_get(pipe_config);
  1135. }
  1136. static void hsw_ddi_clock_get(struct intel_encoder *encoder,
  1137. struct intel_crtc_state *pipe_config)
  1138. {
  1139. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1140. int link_clock = 0;
  1141. u32 val, pll;
  1142. val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
  1143. switch (val & PORT_CLK_SEL_MASK) {
  1144. case PORT_CLK_SEL_LCPLL_810:
  1145. link_clock = 81000;
  1146. break;
  1147. case PORT_CLK_SEL_LCPLL_1350:
  1148. link_clock = 135000;
  1149. break;
  1150. case PORT_CLK_SEL_LCPLL_2700:
  1151. link_clock = 270000;
  1152. break;
  1153. case PORT_CLK_SEL_WRPLL1:
  1154. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
  1155. break;
  1156. case PORT_CLK_SEL_WRPLL2:
  1157. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
  1158. break;
  1159. case PORT_CLK_SEL_SPLL:
  1160. pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
  1161. if (pll == SPLL_PLL_FREQ_810MHz)
  1162. link_clock = 81000;
  1163. else if (pll == SPLL_PLL_FREQ_1350MHz)
  1164. link_clock = 135000;
  1165. else if (pll == SPLL_PLL_FREQ_2700MHz)
  1166. link_clock = 270000;
  1167. else {
  1168. WARN(1, "bad spll freq\n");
  1169. return;
  1170. }
  1171. break;
  1172. default:
  1173. WARN(1, "bad port clock sel\n");
  1174. return;
  1175. }
  1176. pipe_config->port_clock = link_clock * 2;
  1177. ddi_dotclock_get(pipe_config);
  1178. }
  1179. static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
  1180. enum intel_dpll_id dpll)
  1181. {
  1182. struct intel_shared_dpll *pll;
  1183. struct intel_dpll_hw_state *state;
  1184. struct dpll clock;
  1185. /* For DDI ports we always use a shared PLL. */
  1186. if (WARN_ON(dpll == DPLL_ID_PRIVATE))
  1187. return 0;
  1188. pll = &dev_priv->shared_dplls[dpll];
  1189. state = &pll->state.hw_state;
  1190. clock.m1 = 2;
  1191. clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
  1192. if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
  1193. clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
  1194. clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
  1195. clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
  1196. clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
  1197. return chv_calc_dpll_params(100000, &clock);
  1198. }
  1199. static void bxt_ddi_clock_get(struct intel_encoder *encoder,
  1200. struct intel_crtc_state *pipe_config)
  1201. {
  1202. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1203. enum port port = intel_ddi_get_encoder_port(encoder);
  1204. uint32_t dpll = port;
  1205. pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
  1206. ddi_dotclock_get(pipe_config);
  1207. }
  1208. void intel_ddi_clock_get(struct intel_encoder *encoder,
  1209. struct intel_crtc_state *pipe_config)
  1210. {
  1211. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1212. if (INTEL_GEN(dev_priv) <= 8)
  1213. hsw_ddi_clock_get(encoder, pipe_config);
  1214. else if (IS_GEN9_BC(dev_priv))
  1215. skl_ddi_clock_get(encoder, pipe_config);
  1216. else if (IS_GEN9_LP(dev_priv))
  1217. bxt_ddi_clock_get(encoder, pipe_config);
  1218. else if (IS_CANNONLAKE(dev_priv))
  1219. cnl_ddi_clock_get(encoder, pipe_config);
  1220. }
  1221. void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
  1222. {
  1223. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1224. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1225. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1226. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1227. int type = encoder->type;
  1228. uint32_t temp;
  1229. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
  1230. WARN_ON(transcoder_is_dsi(cpu_transcoder));
  1231. temp = TRANS_MSA_SYNC_CLK;
  1232. switch (crtc_state->pipe_bpp) {
  1233. case 18:
  1234. temp |= TRANS_MSA_6_BPC;
  1235. break;
  1236. case 24:
  1237. temp |= TRANS_MSA_8_BPC;
  1238. break;
  1239. case 30:
  1240. temp |= TRANS_MSA_10_BPC;
  1241. break;
  1242. case 36:
  1243. temp |= TRANS_MSA_12_BPC;
  1244. break;
  1245. default:
  1246. BUG();
  1247. }
  1248. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  1249. }
  1250. }
  1251. void intel_ddi_set_vc_payload_alloc(const struct intel_crtc_state *crtc_state,
  1252. bool state)
  1253. {
  1254. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1255. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1256. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1257. uint32_t temp;
  1258. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1259. if (state == true)
  1260. temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1261. else
  1262. temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1263. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1264. }
  1265. void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state)
  1266. {
  1267. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1268. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1269. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1270. enum pipe pipe = crtc->pipe;
  1271. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1272. enum port port = intel_ddi_get_encoder_port(encoder);
  1273. int type = encoder->type;
  1274. uint32_t temp;
  1275. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  1276. temp = TRANS_DDI_FUNC_ENABLE;
  1277. temp |= TRANS_DDI_SELECT_PORT(port);
  1278. switch (crtc_state->pipe_bpp) {
  1279. case 18:
  1280. temp |= TRANS_DDI_BPC_6;
  1281. break;
  1282. case 24:
  1283. temp |= TRANS_DDI_BPC_8;
  1284. break;
  1285. case 30:
  1286. temp |= TRANS_DDI_BPC_10;
  1287. break;
  1288. case 36:
  1289. temp |= TRANS_DDI_BPC_12;
  1290. break;
  1291. default:
  1292. BUG();
  1293. }
  1294. if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
  1295. temp |= TRANS_DDI_PVSYNC;
  1296. if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
  1297. temp |= TRANS_DDI_PHSYNC;
  1298. if (cpu_transcoder == TRANSCODER_EDP) {
  1299. switch (pipe) {
  1300. case PIPE_A:
  1301. /* On Haswell, can only use the always-on power well for
  1302. * eDP when not using the panel fitter, and when not
  1303. * using motion blur mitigation (which we don't
  1304. * support). */
  1305. if (IS_HASWELL(dev_priv) &&
  1306. (crtc_state->pch_pfit.enabled ||
  1307. crtc_state->pch_pfit.force_thru))
  1308. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  1309. else
  1310. temp |= TRANS_DDI_EDP_INPUT_A_ON;
  1311. break;
  1312. case PIPE_B:
  1313. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  1314. break;
  1315. case PIPE_C:
  1316. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  1317. break;
  1318. default:
  1319. BUG();
  1320. break;
  1321. }
  1322. }
  1323. if (type == INTEL_OUTPUT_HDMI) {
  1324. if (crtc_state->has_hdmi_sink)
  1325. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  1326. else
  1327. temp |= TRANS_DDI_MODE_SELECT_DVI;
  1328. if (crtc_state->hdmi_scrambling)
  1329. temp |= TRANS_DDI_HDMI_SCRAMBLING_MASK;
  1330. if (crtc_state->hdmi_high_tmds_clock_ratio)
  1331. temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
  1332. } else if (type == INTEL_OUTPUT_ANALOG) {
  1333. temp |= TRANS_DDI_MODE_SELECT_FDI;
  1334. temp |= (crtc_state->fdi_lanes - 1) << 1;
  1335. } else if (type == INTEL_OUTPUT_DP ||
  1336. type == INTEL_OUTPUT_EDP) {
  1337. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  1338. temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
  1339. } else if (type == INTEL_OUTPUT_DP_MST) {
  1340. temp |= TRANS_DDI_MODE_SELECT_DP_MST;
  1341. temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
  1342. } else {
  1343. WARN(1, "Invalid encoder type %d for pipe %c\n",
  1344. encoder->type, pipe_name(pipe));
  1345. }
  1346. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1347. }
  1348. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  1349. enum transcoder cpu_transcoder)
  1350. {
  1351. i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1352. uint32_t val = I915_READ(reg);
  1353. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
  1354. val |= TRANS_DDI_PORT_NONE;
  1355. I915_WRITE(reg, val);
  1356. }
  1357. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  1358. {
  1359. struct drm_device *dev = intel_connector->base.dev;
  1360. struct drm_i915_private *dev_priv = to_i915(dev);
  1361. struct intel_encoder *encoder = intel_connector->encoder;
  1362. int type = intel_connector->base.connector_type;
  1363. enum port port = intel_ddi_get_encoder_port(encoder);
  1364. enum pipe pipe = 0;
  1365. enum transcoder cpu_transcoder;
  1366. uint32_t tmp;
  1367. bool ret;
  1368. if (!intel_display_power_get_if_enabled(dev_priv,
  1369. encoder->power_domain))
  1370. return false;
  1371. if (!encoder->get_hw_state(encoder, &pipe)) {
  1372. ret = false;
  1373. goto out;
  1374. }
  1375. if (port == PORT_A)
  1376. cpu_transcoder = TRANSCODER_EDP;
  1377. else
  1378. cpu_transcoder = (enum transcoder) pipe;
  1379. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1380. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  1381. case TRANS_DDI_MODE_SELECT_HDMI:
  1382. case TRANS_DDI_MODE_SELECT_DVI:
  1383. ret = type == DRM_MODE_CONNECTOR_HDMIA;
  1384. break;
  1385. case TRANS_DDI_MODE_SELECT_DP_SST:
  1386. ret = type == DRM_MODE_CONNECTOR_eDP ||
  1387. type == DRM_MODE_CONNECTOR_DisplayPort;
  1388. break;
  1389. case TRANS_DDI_MODE_SELECT_DP_MST:
  1390. /* if the transcoder is in MST state then
  1391. * connector isn't connected */
  1392. ret = false;
  1393. break;
  1394. case TRANS_DDI_MODE_SELECT_FDI:
  1395. ret = type == DRM_MODE_CONNECTOR_VGA;
  1396. break;
  1397. default:
  1398. ret = false;
  1399. break;
  1400. }
  1401. out:
  1402. intel_display_power_put(dev_priv, encoder->power_domain);
  1403. return ret;
  1404. }
  1405. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  1406. enum pipe *pipe)
  1407. {
  1408. struct drm_device *dev = encoder->base.dev;
  1409. struct drm_i915_private *dev_priv = to_i915(dev);
  1410. enum port port = intel_ddi_get_encoder_port(encoder);
  1411. u32 tmp;
  1412. int i;
  1413. bool ret;
  1414. if (!intel_display_power_get_if_enabled(dev_priv,
  1415. encoder->power_domain))
  1416. return false;
  1417. ret = false;
  1418. tmp = I915_READ(DDI_BUF_CTL(port));
  1419. if (!(tmp & DDI_BUF_CTL_ENABLE))
  1420. goto out;
  1421. if (port == PORT_A) {
  1422. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  1423. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  1424. case TRANS_DDI_EDP_INPUT_A_ON:
  1425. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  1426. *pipe = PIPE_A;
  1427. break;
  1428. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  1429. *pipe = PIPE_B;
  1430. break;
  1431. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  1432. *pipe = PIPE_C;
  1433. break;
  1434. }
  1435. ret = true;
  1436. goto out;
  1437. }
  1438. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  1439. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  1440. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
  1441. if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
  1442. TRANS_DDI_MODE_SELECT_DP_MST)
  1443. goto out;
  1444. *pipe = i;
  1445. ret = true;
  1446. goto out;
  1447. }
  1448. }
  1449. DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
  1450. out:
  1451. if (ret && IS_GEN9_LP(dev_priv)) {
  1452. tmp = I915_READ(BXT_PHY_CTL(port));
  1453. if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK |
  1454. BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
  1455. DRM_ERROR("Port %c enabled but PHY powered down? "
  1456. "(PHY_CTL %08x)\n", port_name(port), tmp);
  1457. }
  1458. intel_display_power_put(dev_priv, encoder->power_domain);
  1459. return ret;
  1460. }
  1461. static u64 intel_ddi_get_power_domains(struct intel_encoder *encoder)
  1462. {
  1463. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1464. enum pipe pipe;
  1465. if (intel_ddi_get_hw_state(encoder, &pipe))
  1466. return BIT_ULL(dig_port->ddi_io_power_domain);
  1467. return 0;
  1468. }
  1469. void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state)
  1470. {
  1471. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1472. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1473. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1474. enum port port = intel_ddi_get_encoder_port(encoder);
  1475. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1476. if (cpu_transcoder != TRANSCODER_EDP)
  1477. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1478. TRANS_CLK_SEL_PORT(port));
  1479. }
  1480. void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
  1481. {
  1482. struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
  1483. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1484. if (cpu_transcoder != TRANSCODER_EDP)
  1485. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1486. TRANS_CLK_SEL_DISABLED);
  1487. }
  1488. static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
  1489. enum port port, uint8_t iboost)
  1490. {
  1491. u32 tmp;
  1492. tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
  1493. tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
  1494. if (iboost)
  1495. tmp |= iboost << BALANCE_LEG_SHIFT(port);
  1496. else
  1497. tmp |= BALANCE_LEG_DISABLE(port);
  1498. I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
  1499. }
  1500. static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
  1501. {
  1502. struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
  1503. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  1504. enum port port = intel_dig_port->port;
  1505. int type = encoder->type;
  1506. const struct ddi_buf_trans *ddi_translations;
  1507. uint8_t iboost;
  1508. uint8_t dp_iboost, hdmi_iboost;
  1509. int n_entries;
  1510. /* VBT may override standard boost values */
  1511. dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
  1512. hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
  1513. if (type == INTEL_OUTPUT_DP) {
  1514. if (dp_iboost) {
  1515. iboost = dp_iboost;
  1516. } else {
  1517. if (IS_KABYLAKE(dev_priv) || IS_COFFEELAKE(dev_priv))
  1518. ddi_translations = kbl_get_buf_trans_dp(dev_priv,
  1519. &n_entries);
  1520. else
  1521. ddi_translations = skl_get_buf_trans_dp(dev_priv,
  1522. &n_entries);
  1523. iboost = ddi_translations[level].i_boost;
  1524. }
  1525. } else if (type == INTEL_OUTPUT_EDP) {
  1526. if (dp_iboost) {
  1527. iboost = dp_iboost;
  1528. } else {
  1529. ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
  1530. if (WARN_ON(port != PORT_A &&
  1531. port != PORT_E && n_entries > 9))
  1532. n_entries = 9;
  1533. iboost = ddi_translations[level].i_boost;
  1534. }
  1535. } else if (type == INTEL_OUTPUT_HDMI) {
  1536. if (hdmi_iboost) {
  1537. iboost = hdmi_iboost;
  1538. } else {
  1539. ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
  1540. iboost = ddi_translations[level].i_boost;
  1541. }
  1542. } else {
  1543. return;
  1544. }
  1545. /* Make sure that the requested I_boost is valid */
  1546. if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
  1547. DRM_ERROR("Invalid I_boost value %u\n", iboost);
  1548. return;
  1549. }
  1550. _skl_ddi_set_iboost(dev_priv, port, iboost);
  1551. if (port == PORT_A && intel_dig_port->max_lanes == 4)
  1552. _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
  1553. }
  1554. static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
  1555. u32 level, enum port port, int type)
  1556. {
  1557. const struct bxt_ddi_buf_trans *ddi_translations;
  1558. u32 n_entries, i;
  1559. if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
  1560. n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
  1561. ddi_translations = bxt_ddi_translations_edp;
  1562. } else if (type == INTEL_OUTPUT_DP
  1563. || type == INTEL_OUTPUT_EDP) {
  1564. n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
  1565. ddi_translations = bxt_ddi_translations_dp;
  1566. } else if (type == INTEL_OUTPUT_HDMI) {
  1567. n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
  1568. ddi_translations = bxt_ddi_translations_hdmi;
  1569. } else {
  1570. DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
  1571. type);
  1572. return;
  1573. }
  1574. /* Check if default value has to be used */
  1575. if (level >= n_entries ||
  1576. (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
  1577. for (i = 0; i < n_entries; i++) {
  1578. if (ddi_translations[i].default_index) {
  1579. level = i;
  1580. break;
  1581. }
  1582. }
  1583. }
  1584. bxt_ddi_phy_set_signal_level(dev_priv, port,
  1585. ddi_translations[level].margin,
  1586. ddi_translations[level].scale,
  1587. ddi_translations[level].enable,
  1588. ddi_translations[level].deemphasis);
  1589. }
  1590. u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder)
  1591. {
  1592. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1593. int n_entries;
  1594. if (encoder->type == INTEL_OUTPUT_EDP)
  1595. intel_ddi_get_buf_trans_edp(dev_priv, &n_entries);
  1596. else
  1597. intel_ddi_get_buf_trans_dp(dev_priv, &n_entries);
  1598. if (WARN_ON(n_entries < 1))
  1599. n_entries = 1;
  1600. if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
  1601. n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
  1602. return index_to_dp_signal_levels[n_entries - 1] &
  1603. DP_TRAIN_VOLTAGE_SWING_MASK;
  1604. }
  1605. static const struct cnl_ddi_buf_trans *
  1606. cnl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv,
  1607. u32 voltage, int *n_entries)
  1608. {
  1609. if (voltage == VOLTAGE_INFO_0_85V) {
  1610. *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_85V);
  1611. return cnl_ddi_translations_hdmi_0_85V;
  1612. } else if (voltage == VOLTAGE_INFO_0_95V) {
  1613. *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_0_95V);
  1614. return cnl_ddi_translations_hdmi_0_95V;
  1615. } else if (voltage == VOLTAGE_INFO_1_05V) {
  1616. *n_entries = ARRAY_SIZE(cnl_ddi_translations_hdmi_1_05V);
  1617. return cnl_ddi_translations_hdmi_1_05V;
  1618. }
  1619. return NULL;
  1620. }
  1621. static const struct cnl_ddi_buf_trans *
  1622. cnl_get_buf_trans_dp(struct drm_i915_private *dev_priv,
  1623. u32 voltage, int *n_entries)
  1624. {
  1625. if (voltage == VOLTAGE_INFO_0_85V) {
  1626. *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_85V);
  1627. return cnl_ddi_translations_dp_0_85V;
  1628. } else if (voltage == VOLTAGE_INFO_0_95V) {
  1629. *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_0_95V);
  1630. return cnl_ddi_translations_dp_0_95V;
  1631. } else if (voltage == VOLTAGE_INFO_1_05V) {
  1632. *n_entries = ARRAY_SIZE(cnl_ddi_translations_dp_1_05V);
  1633. return cnl_ddi_translations_dp_1_05V;
  1634. }
  1635. return NULL;
  1636. }
  1637. static const struct cnl_ddi_buf_trans *
  1638. cnl_get_buf_trans_edp(struct drm_i915_private *dev_priv,
  1639. u32 voltage, int *n_entries)
  1640. {
  1641. if (dev_priv->vbt.edp.low_vswing) {
  1642. if (voltage == VOLTAGE_INFO_0_85V) {
  1643. *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_85V);
  1644. return cnl_ddi_translations_edp_0_85V;
  1645. } else if (voltage == VOLTAGE_INFO_0_95V) {
  1646. *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_0_95V);
  1647. return cnl_ddi_translations_edp_0_95V;
  1648. } else if (voltage == VOLTAGE_INFO_1_05V) {
  1649. *n_entries = ARRAY_SIZE(cnl_ddi_translations_edp_1_05V);
  1650. return cnl_ddi_translations_edp_1_05V;
  1651. }
  1652. return NULL;
  1653. } else {
  1654. return cnl_get_buf_trans_dp(dev_priv, voltage, n_entries);
  1655. }
  1656. }
  1657. static void cnl_ddi_vswing_program(struct drm_i915_private *dev_priv,
  1658. u32 level, enum port port, int type)
  1659. {
  1660. const struct cnl_ddi_buf_trans *ddi_translations = NULL;
  1661. u32 n_entries, val, voltage;
  1662. int ln;
  1663. /*
  1664. * Values for each port type are listed in
  1665. * voltage swing programming tables.
  1666. * Vccio voltage found in PORT_COMP_DW3.
  1667. */
  1668. voltage = I915_READ(CNL_PORT_COMP_DW3) & VOLTAGE_INFO_MASK;
  1669. if (type == INTEL_OUTPUT_HDMI) {
  1670. ddi_translations = cnl_get_buf_trans_hdmi(dev_priv,
  1671. voltage, &n_entries);
  1672. } else if (type == INTEL_OUTPUT_DP) {
  1673. ddi_translations = cnl_get_buf_trans_dp(dev_priv,
  1674. voltage, &n_entries);
  1675. } else if (type == INTEL_OUTPUT_EDP) {
  1676. ddi_translations = cnl_get_buf_trans_edp(dev_priv,
  1677. voltage, &n_entries);
  1678. }
  1679. if (ddi_translations == NULL) {
  1680. MISSING_CASE(voltage);
  1681. return;
  1682. }
  1683. if (level >= n_entries) {
  1684. DRM_DEBUG_KMS("DDI translation not found for level %d. Using %d instead.", level, n_entries - 1);
  1685. level = n_entries - 1;
  1686. }
  1687. /* Set PORT_TX_DW5 Scaling Mode Sel to 010b. */
  1688. val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
  1689. val &= ~SCALING_MODE_SEL_MASK;
  1690. val |= SCALING_MODE_SEL(2);
  1691. I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
  1692. /* Program PORT_TX_DW2 */
  1693. val = I915_READ(CNL_PORT_TX_DW2_LN0(port));
  1694. val &= ~(SWING_SEL_LOWER_MASK | SWING_SEL_UPPER_MASK |
  1695. RCOMP_SCALAR_MASK);
  1696. val |= SWING_SEL_UPPER(ddi_translations[level].dw2_swing_sel);
  1697. val |= SWING_SEL_LOWER(ddi_translations[level].dw2_swing_sel);
  1698. /* Rcomp scalar is fixed as 0x98 for every table entry */
  1699. val |= RCOMP_SCALAR(0x98);
  1700. I915_WRITE(CNL_PORT_TX_DW2_GRP(port), val);
  1701. /* Program PORT_TX_DW4 */
  1702. /* We cannot write to GRP. It would overrite individual loadgen */
  1703. for (ln = 0; ln < 4; ln++) {
  1704. val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
  1705. val &= ~(POST_CURSOR_1_MASK | POST_CURSOR_2_MASK |
  1706. CURSOR_COEFF_MASK);
  1707. val |= POST_CURSOR_1(ddi_translations[level].dw4_post_cursor_1);
  1708. val |= POST_CURSOR_2(ddi_translations[level].dw4_post_cursor_2);
  1709. val |= CURSOR_COEFF(ddi_translations[level].dw4_cursor_coeff);
  1710. I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
  1711. }
  1712. /* Program PORT_TX_DW5 */
  1713. /* All DW5 values are fixed for every table entry */
  1714. val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
  1715. val &= ~RTERM_SELECT_MASK;
  1716. val |= RTERM_SELECT(6);
  1717. val |= TAP3_DISABLE;
  1718. I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
  1719. /* Program PORT_TX_DW7 */
  1720. val = I915_READ(CNL_PORT_TX_DW7_LN0(port));
  1721. val &= ~N_SCALAR_MASK;
  1722. val |= N_SCALAR(ddi_translations[level].dw7_n_scalar);
  1723. I915_WRITE(CNL_PORT_TX_DW7_GRP(port), val);
  1724. }
  1725. static void cnl_ddi_vswing_sequence(struct intel_encoder *encoder, u32 level)
  1726. {
  1727. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1728. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1729. enum port port = intel_ddi_get_encoder_port(encoder);
  1730. int type = encoder->type;
  1731. int width = 0;
  1732. int rate = 0;
  1733. u32 val;
  1734. int ln = 0;
  1735. if ((intel_dp) && (type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP)) {
  1736. width = intel_dp->lane_count;
  1737. rate = intel_dp->link_rate;
  1738. } else if (type == INTEL_OUTPUT_HDMI) {
  1739. width = 4;
  1740. /* Rate is always < than 6GHz for HDMI */
  1741. } else {
  1742. MISSING_CASE(type);
  1743. return;
  1744. }
  1745. /*
  1746. * 1. If port type is eDP or DP,
  1747. * set PORT_PCS_DW1 cmnkeeper_enable to 1b,
  1748. * else clear to 0b.
  1749. */
  1750. val = I915_READ(CNL_PORT_PCS_DW1_LN0(port));
  1751. if (type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP)
  1752. val |= COMMON_KEEPER_EN;
  1753. else
  1754. val &= ~COMMON_KEEPER_EN;
  1755. I915_WRITE(CNL_PORT_PCS_DW1_GRP(port), val);
  1756. /* 2. Program loadgen select */
  1757. /*
  1758. * Program PORT_TX_DW4_LN depending on Bit rate and used lanes
  1759. * <= 6 GHz and 4 lanes (LN0=0, LN1=1, LN2=1, LN3=1)
  1760. * <= 6 GHz and 1,2 lanes (LN0=0, LN1=1, LN2=1, LN3=0)
  1761. * > 6 GHz (LN0=0, LN1=0, LN2=0, LN3=0)
  1762. */
  1763. for (ln = 0; ln <= 3; ln++) {
  1764. val = I915_READ(CNL_PORT_TX_DW4_LN(port, ln));
  1765. val &= ~LOADGEN_SELECT;
  1766. if ((rate <= 600000 && width == 4 && ln >= 1) ||
  1767. (rate <= 600000 && width < 4 && (ln == 1 || ln == 2))) {
  1768. val |= LOADGEN_SELECT;
  1769. }
  1770. I915_WRITE(CNL_PORT_TX_DW4_LN(port, ln), val);
  1771. }
  1772. /* 3. Set PORT_CL_DW5 SUS Clock Config to 11b */
  1773. val = I915_READ(CNL_PORT_CL1CM_DW5);
  1774. val |= SUS_CLOCK_CONFIG;
  1775. I915_WRITE(CNL_PORT_CL1CM_DW5, val);
  1776. /* 4. Clear training enable to change swing values */
  1777. val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
  1778. val &= ~TX_TRAINING_EN;
  1779. I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
  1780. /* 5. Program swing and de-emphasis */
  1781. cnl_ddi_vswing_program(dev_priv, level, port, type);
  1782. /* 6. Set training enable to trigger update */
  1783. val = I915_READ(CNL_PORT_TX_DW5_LN0(port));
  1784. val |= TX_TRAINING_EN;
  1785. I915_WRITE(CNL_PORT_TX_DW5_GRP(port), val);
  1786. }
  1787. static uint32_t translate_signal_level(int signal_levels)
  1788. {
  1789. int i;
  1790. for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
  1791. if (index_to_dp_signal_levels[i] == signal_levels)
  1792. return i;
  1793. }
  1794. WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
  1795. signal_levels);
  1796. return 0;
  1797. }
  1798. uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
  1799. {
  1800. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1801. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  1802. struct intel_encoder *encoder = &dport->base;
  1803. uint8_t train_set = intel_dp->train_set[0];
  1804. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1805. DP_TRAIN_PRE_EMPHASIS_MASK);
  1806. enum port port = dport->port;
  1807. uint32_t level;
  1808. level = translate_signal_level(signal_levels);
  1809. if (IS_GEN9_BC(dev_priv))
  1810. skl_ddi_set_iboost(encoder, level);
  1811. else if (IS_GEN9_LP(dev_priv))
  1812. bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
  1813. else if (IS_CANNONLAKE(dev_priv)) {
  1814. cnl_ddi_vswing_sequence(encoder, level);
  1815. /* DDI_BUF_CTL bits 27:24 are reserved on CNL */
  1816. return 0;
  1817. }
  1818. return DDI_BUF_TRANS_SELECT(level);
  1819. }
  1820. static void intel_ddi_clk_select(struct intel_encoder *encoder,
  1821. struct intel_shared_dpll *pll)
  1822. {
  1823. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1824. enum port port = intel_ddi_get_encoder_port(encoder);
  1825. uint32_t val;
  1826. if (WARN_ON(!pll))
  1827. return;
  1828. if (IS_CANNONLAKE(dev_priv)) {
  1829. /* Configure DPCLKA_CFGCR0 to map the DPLL to the DDI. */
  1830. val = I915_READ(DPCLKA_CFGCR0);
  1831. val |= DPCLKA_CFGCR0_DDI_CLK_SEL(pll->id, port);
  1832. I915_WRITE(DPCLKA_CFGCR0, val);
  1833. /*
  1834. * Configure DPCLKA_CFGCR0 to turn on the clock for the DDI.
  1835. * This step and the step before must be done with separate
  1836. * register writes.
  1837. */
  1838. val = I915_READ(DPCLKA_CFGCR0);
  1839. val &= ~(DPCLKA_CFGCR0_DDI_CLK_OFF(port) |
  1840. DPCLKA_CFGCR0_DDI_CLK_SEL_MASK(port));
  1841. I915_WRITE(DPCLKA_CFGCR0, val);
  1842. } else if (IS_GEN9_BC(dev_priv)) {
  1843. /* DDI -> PLL mapping */
  1844. val = I915_READ(DPLL_CTRL2);
  1845. val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
  1846. DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
  1847. val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
  1848. DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
  1849. I915_WRITE(DPLL_CTRL2, val);
  1850. } else if (INTEL_INFO(dev_priv)->gen < 9) {
  1851. I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
  1852. }
  1853. }
  1854. static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
  1855. int link_rate, uint32_t lane_count,
  1856. struct intel_shared_dpll *pll,
  1857. bool link_mst)
  1858. {
  1859. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1860. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1861. enum port port = intel_ddi_get_encoder_port(encoder);
  1862. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1863. WARN_ON(link_mst && (port == PORT_A || port == PORT_E));
  1864. intel_dp_set_link_params(intel_dp, link_rate, lane_count,
  1865. link_mst);
  1866. if (encoder->type == INTEL_OUTPUT_EDP)
  1867. intel_edp_panel_on(intel_dp);
  1868. intel_ddi_clk_select(encoder, pll);
  1869. intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
  1870. intel_prepare_dp_ddi_buffers(encoder);
  1871. intel_ddi_init_dp_buf_reg(encoder);
  1872. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1873. intel_dp_start_link_train(intel_dp);
  1874. if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
  1875. intel_dp_stop_link_train(intel_dp);
  1876. }
  1877. static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
  1878. bool has_hdmi_sink,
  1879. const struct intel_crtc_state *crtc_state,
  1880. const struct drm_connector_state *conn_state,
  1881. struct intel_shared_dpll *pll)
  1882. {
  1883. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1884. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1885. struct drm_encoder *drm_encoder = &encoder->base;
  1886. enum port port = intel_ddi_get_encoder_port(encoder);
  1887. int level = intel_ddi_hdmi_level(dev_priv, port);
  1888. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1889. intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
  1890. intel_ddi_clk_select(encoder, pll);
  1891. intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
  1892. intel_prepare_hdmi_ddi_buffers(encoder);
  1893. if (IS_GEN9_BC(dev_priv))
  1894. skl_ddi_set_iboost(encoder, level);
  1895. else if (IS_GEN9_LP(dev_priv))
  1896. bxt_ddi_vswing_sequence(dev_priv, level, port,
  1897. INTEL_OUTPUT_HDMI);
  1898. else if (IS_CANNONLAKE(dev_priv))
  1899. cnl_ddi_vswing_sequence(encoder, level);
  1900. intel_hdmi->set_infoframes(drm_encoder,
  1901. has_hdmi_sink,
  1902. crtc_state, conn_state);
  1903. }
  1904. static void intel_ddi_pre_enable(struct intel_encoder *encoder,
  1905. struct intel_crtc_state *pipe_config,
  1906. struct drm_connector_state *conn_state)
  1907. {
  1908. int type = encoder->type;
  1909. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1910. intel_ddi_pre_enable_dp(encoder,
  1911. pipe_config->port_clock,
  1912. pipe_config->lane_count,
  1913. pipe_config->shared_dpll,
  1914. intel_crtc_has_type(pipe_config,
  1915. INTEL_OUTPUT_DP_MST));
  1916. }
  1917. if (type == INTEL_OUTPUT_HDMI) {
  1918. intel_ddi_pre_enable_hdmi(encoder,
  1919. pipe_config->has_hdmi_sink,
  1920. pipe_config, conn_state,
  1921. pipe_config->shared_dpll);
  1922. }
  1923. }
  1924. static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
  1925. struct intel_crtc_state *old_crtc_state,
  1926. struct drm_connector_state *old_conn_state)
  1927. {
  1928. struct drm_encoder *encoder = &intel_encoder->base;
  1929. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  1930. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1931. struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
  1932. struct intel_dp *intel_dp = NULL;
  1933. int type = intel_encoder->type;
  1934. uint32_t val;
  1935. bool wait = false;
  1936. /* old_crtc_state and old_conn_state are NULL when called from DP_MST */
  1937. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1938. intel_dp = enc_to_intel_dp(encoder);
  1939. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1940. }
  1941. val = I915_READ(DDI_BUF_CTL(port));
  1942. if (val & DDI_BUF_CTL_ENABLE) {
  1943. val &= ~DDI_BUF_CTL_ENABLE;
  1944. I915_WRITE(DDI_BUF_CTL(port), val);
  1945. wait = true;
  1946. }
  1947. val = I915_READ(DP_TP_CTL(port));
  1948. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1949. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1950. I915_WRITE(DP_TP_CTL(port), val);
  1951. if (wait)
  1952. intel_wait_ddi_buf_idle(dev_priv, port);
  1953. if (intel_dp) {
  1954. intel_edp_panel_vdd_on(intel_dp);
  1955. intel_edp_panel_off(intel_dp);
  1956. }
  1957. if (dig_port)
  1958. intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
  1959. if (IS_CANNONLAKE(dev_priv))
  1960. I915_WRITE(DPCLKA_CFGCR0, I915_READ(DPCLKA_CFGCR0) |
  1961. DPCLKA_CFGCR0_DDI_CLK_OFF(port));
  1962. else if (IS_GEN9_BC(dev_priv))
  1963. I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
  1964. DPLL_CTRL2_DDI_CLK_OFF(port)));
  1965. else if (INTEL_GEN(dev_priv) < 9)
  1966. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1967. if (type == INTEL_OUTPUT_HDMI) {
  1968. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  1969. intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
  1970. }
  1971. }
  1972. void intel_ddi_fdi_post_disable(struct intel_encoder *encoder,
  1973. struct intel_crtc_state *old_crtc_state,
  1974. struct drm_connector_state *old_conn_state)
  1975. {
  1976. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1977. uint32_t val;
  1978. /*
  1979. * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
  1980. * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
  1981. * step 13 is the correct place for it. Step 18 is where it was
  1982. * originally before the BUN.
  1983. */
  1984. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1985. val &= ~FDI_RX_ENABLE;
  1986. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1987. intel_ddi_post_disable(encoder, old_crtc_state, old_conn_state);
  1988. val = I915_READ(FDI_RX_MISC(PIPE_A));
  1989. val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  1990. val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  1991. I915_WRITE(FDI_RX_MISC(PIPE_A), val);
  1992. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1993. val &= ~FDI_PCDCLK;
  1994. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1995. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1996. val &= ~FDI_RX_PLL_ENABLE;
  1997. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1998. }
  1999. static void intel_enable_ddi(struct intel_encoder *intel_encoder,
  2000. struct intel_crtc_state *pipe_config,
  2001. struct drm_connector_state *conn_state)
  2002. {
  2003. struct drm_encoder *encoder = &intel_encoder->base;
  2004. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  2005. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  2006. int type = intel_encoder->type;
  2007. if (type == INTEL_OUTPUT_HDMI) {
  2008. struct intel_digital_port *intel_dig_port =
  2009. enc_to_dig_port(encoder);
  2010. bool clock_ratio = pipe_config->hdmi_high_tmds_clock_ratio;
  2011. bool scrambling = pipe_config->hdmi_scrambling;
  2012. intel_hdmi_handle_sink_scrambling(intel_encoder,
  2013. conn_state->connector,
  2014. clock_ratio, scrambling);
  2015. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  2016. * are ignored so nothing special needs to be done besides
  2017. * enabling the port.
  2018. */
  2019. I915_WRITE(DDI_BUF_CTL(port),
  2020. intel_dig_port->saved_port_bits |
  2021. DDI_BUF_CTL_ENABLE);
  2022. } else if (type == INTEL_OUTPUT_EDP) {
  2023. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2024. if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
  2025. intel_dp_stop_link_train(intel_dp);
  2026. intel_edp_backlight_on(pipe_config, conn_state);
  2027. intel_psr_enable(intel_dp);
  2028. intel_edp_drrs_enable(intel_dp, pipe_config);
  2029. }
  2030. if (pipe_config->has_audio)
  2031. intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
  2032. }
  2033. static void intel_disable_ddi(struct intel_encoder *intel_encoder,
  2034. struct intel_crtc_state *old_crtc_state,
  2035. struct drm_connector_state *old_conn_state)
  2036. {
  2037. struct drm_encoder *encoder = &intel_encoder->base;
  2038. int type = intel_encoder->type;
  2039. if (old_crtc_state->has_audio)
  2040. intel_audio_codec_disable(intel_encoder);
  2041. if (type == INTEL_OUTPUT_HDMI) {
  2042. intel_hdmi_handle_sink_scrambling(intel_encoder,
  2043. old_conn_state->connector,
  2044. false, false);
  2045. }
  2046. if (type == INTEL_OUTPUT_EDP) {
  2047. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2048. intel_edp_drrs_disable(intel_dp, old_crtc_state);
  2049. intel_psr_disable(intel_dp);
  2050. intel_edp_backlight_off(old_conn_state);
  2051. }
  2052. }
  2053. static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
  2054. struct intel_crtc_state *pipe_config,
  2055. struct drm_connector_state *conn_state)
  2056. {
  2057. uint8_t mask = pipe_config->lane_lat_optim_mask;
  2058. bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
  2059. }
  2060. void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
  2061. {
  2062. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  2063. struct drm_i915_private *dev_priv =
  2064. to_i915(intel_dig_port->base.base.dev);
  2065. enum port port = intel_dig_port->port;
  2066. uint32_t val;
  2067. bool wait = false;
  2068. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  2069. val = I915_READ(DDI_BUF_CTL(port));
  2070. if (val & DDI_BUF_CTL_ENABLE) {
  2071. val &= ~DDI_BUF_CTL_ENABLE;
  2072. I915_WRITE(DDI_BUF_CTL(port), val);
  2073. wait = true;
  2074. }
  2075. val = I915_READ(DP_TP_CTL(port));
  2076. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  2077. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  2078. I915_WRITE(DP_TP_CTL(port), val);
  2079. POSTING_READ(DP_TP_CTL(port));
  2080. if (wait)
  2081. intel_wait_ddi_buf_idle(dev_priv, port);
  2082. }
  2083. val = DP_TP_CTL_ENABLE |
  2084. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  2085. if (intel_dp->link_mst)
  2086. val |= DP_TP_CTL_MODE_MST;
  2087. else {
  2088. val |= DP_TP_CTL_MODE_SST;
  2089. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  2090. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  2091. }
  2092. I915_WRITE(DP_TP_CTL(port), val);
  2093. POSTING_READ(DP_TP_CTL(port));
  2094. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  2095. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  2096. POSTING_READ(DDI_BUF_CTL(port));
  2097. udelay(600);
  2098. }
  2099. bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
  2100. struct intel_crtc *intel_crtc)
  2101. {
  2102. u32 temp;
  2103. if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
  2104. temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  2105. if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
  2106. return true;
  2107. }
  2108. return false;
  2109. }
  2110. void intel_ddi_get_config(struct intel_encoder *encoder,
  2111. struct intel_crtc_state *pipe_config)
  2112. {
  2113. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  2114. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  2115. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  2116. struct intel_hdmi *intel_hdmi;
  2117. u32 temp, flags = 0;
  2118. /* XXX: DSI transcoder paranoia */
  2119. if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
  2120. return;
  2121. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  2122. if (temp & TRANS_DDI_PHSYNC)
  2123. flags |= DRM_MODE_FLAG_PHSYNC;
  2124. else
  2125. flags |= DRM_MODE_FLAG_NHSYNC;
  2126. if (temp & TRANS_DDI_PVSYNC)
  2127. flags |= DRM_MODE_FLAG_PVSYNC;
  2128. else
  2129. flags |= DRM_MODE_FLAG_NVSYNC;
  2130. pipe_config->base.adjusted_mode.flags |= flags;
  2131. switch (temp & TRANS_DDI_BPC_MASK) {
  2132. case TRANS_DDI_BPC_6:
  2133. pipe_config->pipe_bpp = 18;
  2134. break;
  2135. case TRANS_DDI_BPC_8:
  2136. pipe_config->pipe_bpp = 24;
  2137. break;
  2138. case TRANS_DDI_BPC_10:
  2139. pipe_config->pipe_bpp = 30;
  2140. break;
  2141. case TRANS_DDI_BPC_12:
  2142. pipe_config->pipe_bpp = 36;
  2143. break;
  2144. default:
  2145. break;
  2146. }
  2147. switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
  2148. case TRANS_DDI_MODE_SELECT_HDMI:
  2149. pipe_config->has_hdmi_sink = true;
  2150. intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  2151. if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
  2152. pipe_config->has_infoframe = true;
  2153. if ((temp & TRANS_DDI_HDMI_SCRAMBLING_MASK) ==
  2154. TRANS_DDI_HDMI_SCRAMBLING_MASK)
  2155. pipe_config->hdmi_scrambling = true;
  2156. if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
  2157. pipe_config->hdmi_high_tmds_clock_ratio = true;
  2158. /* fall through */
  2159. case TRANS_DDI_MODE_SELECT_DVI:
  2160. pipe_config->lane_count = 4;
  2161. break;
  2162. case TRANS_DDI_MODE_SELECT_FDI:
  2163. break;
  2164. case TRANS_DDI_MODE_SELECT_DP_SST:
  2165. case TRANS_DDI_MODE_SELECT_DP_MST:
  2166. pipe_config->lane_count =
  2167. ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
  2168. intel_dp_get_m_n(intel_crtc, pipe_config);
  2169. break;
  2170. default:
  2171. break;
  2172. }
  2173. pipe_config->has_audio =
  2174. intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
  2175. if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
  2176. pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
  2177. /*
  2178. * This is a big fat ugly hack.
  2179. *
  2180. * Some machines in UEFI boot mode provide us a VBT that has 18
  2181. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  2182. * unknown we fail to light up. Yet the same BIOS boots up with
  2183. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  2184. * max, not what it tells us to use.
  2185. *
  2186. * Note: This will still be broken if the eDP panel is not lit
  2187. * up by the BIOS, and thus we can't get the mode at module
  2188. * load.
  2189. */
  2190. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  2191. pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
  2192. dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
  2193. }
  2194. intel_ddi_clock_get(encoder, pipe_config);
  2195. if (IS_GEN9_LP(dev_priv))
  2196. pipe_config->lane_lat_optim_mask =
  2197. bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
  2198. }
  2199. static bool intel_ddi_compute_config(struct intel_encoder *encoder,
  2200. struct intel_crtc_state *pipe_config,
  2201. struct drm_connector_state *conn_state)
  2202. {
  2203. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  2204. int type = encoder->type;
  2205. int port = intel_ddi_get_encoder_port(encoder);
  2206. int ret;
  2207. WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
  2208. if (port == PORT_A)
  2209. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  2210. if (type == INTEL_OUTPUT_HDMI)
  2211. ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
  2212. else
  2213. ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
  2214. if (IS_GEN9_LP(dev_priv) && ret)
  2215. pipe_config->lane_lat_optim_mask =
  2216. bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
  2217. pipe_config->lane_count);
  2218. return ret;
  2219. }
  2220. static const struct drm_encoder_funcs intel_ddi_funcs = {
  2221. .reset = intel_dp_encoder_reset,
  2222. .destroy = intel_dp_encoder_destroy,
  2223. };
  2224. static struct intel_connector *
  2225. intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
  2226. {
  2227. struct intel_connector *connector;
  2228. enum port port = intel_dig_port->port;
  2229. connector = intel_connector_alloc();
  2230. if (!connector)
  2231. return NULL;
  2232. intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
  2233. if (!intel_dp_init_connector(intel_dig_port, connector)) {
  2234. kfree(connector);
  2235. return NULL;
  2236. }
  2237. return connector;
  2238. }
  2239. static struct intel_connector *
  2240. intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
  2241. {
  2242. struct intel_connector *connector;
  2243. enum port port = intel_dig_port->port;
  2244. connector = intel_connector_alloc();
  2245. if (!connector)
  2246. return NULL;
  2247. intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
  2248. intel_hdmi_init_connector(intel_dig_port, connector);
  2249. return connector;
  2250. }
  2251. void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
  2252. {
  2253. struct intel_digital_port *intel_dig_port;
  2254. struct intel_encoder *intel_encoder;
  2255. struct drm_encoder *encoder;
  2256. bool init_hdmi, init_dp, init_lspcon = false;
  2257. int max_lanes;
  2258. if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
  2259. switch (port) {
  2260. case PORT_A:
  2261. max_lanes = 4;
  2262. break;
  2263. case PORT_E:
  2264. max_lanes = 0;
  2265. break;
  2266. default:
  2267. max_lanes = 4;
  2268. break;
  2269. }
  2270. } else {
  2271. switch (port) {
  2272. case PORT_A:
  2273. max_lanes = 2;
  2274. break;
  2275. case PORT_E:
  2276. max_lanes = 2;
  2277. break;
  2278. default:
  2279. max_lanes = 4;
  2280. break;
  2281. }
  2282. }
  2283. init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
  2284. dev_priv->vbt.ddi_port_info[port].supports_hdmi);
  2285. init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
  2286. if (intel_bios_is_lspcon_present(dev_priv, port)) {
  2287. /*
  2288. * Lspcon device needs to be driven with DP connector
  2289. * with special detection sequence. So make sure DP
  2290. * is initialized before lspcon.
  2291. */
  2292. init_dp = true;
  2293. init_lspcon = true;
  2294. init_hdmi = false;
  2295. DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
  2296. }
  2297. if (!init_dp && !init_hdmi) {
  2298. DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
  2299. port_name(port));
  2300. return;
  2301. }
  2302. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  2303. if (!intel_dig_port)
  2304. return;
  2305. intel_encoder = &intel_dig_port->base;
  2306. encoder = &intel_encoder->base;
  2307. drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
  2308. DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
  2309. intel_encoder->compute_config = intel_ddi_compute_config;
  2310. intel_encoder->enable = intel_enable_ddi;
  2311. if (IS_GEN9_LP(dev_priv))
  2312. intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
  2313. intel_encoder->pre_enable = intel_ddi_pre_enable;
  2314. intel_encoder->disable = intel_disable_ddi;
  2315. intel_encoder->post_disable = intel_ddi_post_disable;
  2316. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  2317. intel_encoder->get_config = intel_ddi_get_config;
  2318. intel_encoder->suspend = intel_dp_encoder_suspend;
  2319. intel_encoder->get_power_domains = intel_ddi_get_power_domains;
  2320. intel_dig_port->port = port;
  2321. intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
  2322. (DDI_BUF_PORT_REVERSAL |
  2323. DDI_A_4_LANES);
  2324. switch (port) {
  2325. case PORT_A:
  2326. intel_dig_port->ddi_io_power_domain =
  2327. POWER_DOMAIN_PORT_DDI_A_IO;
  2328. break;
  2329. case PORT_B:
  2330. intel_dig_port->ddi_io_power_domain =
  2331. POWER_DOMAIN_PORT_DDI_B_IO;
  2332. break;
  2333. case PORT_C:
  2334. intel_dig_port->ddi_io_power_domain =
  2335. POWER_DOMAIN_PORT_DDI_C_IO;
  2336. break;
  2337. case PORT_D:
  2338. intel_dig_port->ddi_io_power_domain =
  2339. POWER_DOMAIN_PORT_DDI_D_IO;
  2340. break;
  2341. case PORT_E:
  2342. intel_dig_port->ddi_io_power_domain =
  2343. POWER_DOMAIN_PORT_DDI_E_IO;
  2344. break;
  2345. default:
  2346. MISSING_CASE(port);
  2347. }
  2348. /*
  2349. * Bspec says that DDI_A_4_LANES is the only supported configuration
  2350. * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
  2351. * wasn't lit up at boot. Force this bit on in our internal
  2352. * configuration so that we use the proper lane count for our
  2353. * calculations.
  2354. */
  2355. if (IS_GEN9_LP(dev_priv) && port == PORT_A) {
  2356. if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
  2357. DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
  2358. intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
  2359. max_lanes = 4;
  2360. }
  2361. }
  2362. intel_dig_port->max_lanes = max_lanes;
  2363. intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
  2364. intel_encoder->power_domain = intel_port_to_power_domain(port);
  2365. intel_encoder->port = port;
  2366. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  2367. intel_encoder->cloneable = 0;
  2368. if (init_dp) {
  2369. if (!intel_ddi_init_dp_connector(intel_dig_port))
  2370. goto err;
  2371. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  2372. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  2373. }
  2374. /* In theory we don't need the encoder->type check, but leave it just in
  2375. * case we have some really bad VBTs... */
  2376. if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
  2377. if (!intel_ddi_init_hdmi_connector(intel_dig_port))
  2378. goto err;
  2379. }
  2380. if (init_lspcon) {
  2381. if (lspcon_init(intel_dig_port))
  2382. /* TODO: handle hdmi info frame part */
  2383. DRM_DEBUG_KMS("LSPCON init success on port %c\n",
  2384. port_name(port));
  2385. else
  2386. /*
  2387. * LSPCON init faied, but DP init was success, so
  2388. * lets try to drive as DP++ port.
  2389. */
  2390. DRM_ERROR("LSPCON init failed on port %c\n",
  2391. port_name(port));
  2392. }
  2393. return;
  2394. err:
  2395. drm_encoder_cleanup(encoder);
  2396. kfree(intel_dig_port);
  2397. }