intel_ddi.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322
  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. enum port intel_ddi_get_encoder_port(struct intel_encoder *encoder)
  331. {
  332. switch (encoder->type) {
  333. case INTEL_OUTPUT_DP_MST:
  334. return enc_to_mst(&encoder->base)->primary->port;
  335. case INTEL_OUTPUT_DP:
  336. case INTEL_OUTPUT_EDP:
  337. case INTEL_OUTPUT_HDMI:
  338. case INTEL_OUTPUT_UNKNOWN:
  339. return enc_to_dig_port(&encoder->base)->port;
  340. case INTEL_OUTPUT_ANALOG:
  341. return PORT_E;
  342. default:
  343. MISSING_CASE(encoder->type);
  344. return PORT_A;
  345. }
  346. }
  347. static const struct ddi_buf_trans *
  348. bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
  349. {
  350. if (dev_priv->vbt.edp.low_vswing) {
  351. *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
  352. return bdw_ddi_translations_edp;
  353. } else {
  354. *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  355. return bdw_ddi_translations_dp;
  356. }
  357. }
  358. static const struct ddi_buf_trans *
  359. skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
  360. {
  361. if (IS_SKL_ULX(dev_priv)) {
  362. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
  363. return skl_y_ddi_translations_dp;
  364. } else if (IS_SKL_ULT(dev_priv)) {
  365. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
  366. return skl_u_ddi_translations_dp;
  367. } else {
  368. *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
  369. return skl_ddi_translations_dp;
  370. }
  371. }
  372. static const struct ddi_buf_trans *
  373. kbl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
  374. {
  375. if (IS_KBL_ULX(dev_priv)) {
  376. *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp);
  377. return kbl_y_ddi_translations_dp;
  378. } else if (IS_KBL_ULT(dev_priv)) {
  379. *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
  380. return kbl_u_ddi_translations_dp;
  381. } else {
  382. *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
  383. return kbl_ddi_translations_dp;
  384. }
  385. }
  386. static const struct ddi_buf_trans *
  387. skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
  388. {
  389. if (dev_priv->vbt.edp.low_vswing) {
  390. if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
  391. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
  392. return skl_y_ddi_translations_edp;
  393. } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) {
  394. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
  395. return skl_u_ddi_translations_edp;
  396. } else {
  397. *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
  398. return skl_ddi_translations_edp;
  399. }
  400. }
  401. if (IS_KABYLAKE(dev_priv))
  402. return kbl_get_buf_trans_dp(dev_priv, n_entries);
  403. else
  404. return skl_get_buf_trans_dp(dev_priv, n_entries);
  405. }
  406. static const struct ddi_buf_trans *
  407. skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
  408. {
  409. if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
  410. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
  411. return skl_y_ddi_translations_hdmi;
  412. } else {
  413. *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
  414. return skl_ddi_translations_hdmi;
  415. }
  416. }
  417. static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
  418. {
  419. int n_hdmi_entries;
  420. int hdmi_level;
  421. int hdmi_default_entry;
  422. hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
  423. if (IS_GEN9_LP(dev_priv))
  424. return hdmi_level;
  425. if (IS_GEN9_BC(dev_priv)) {
  426. skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
  427. hdmi_default_entry = 8;
  428. } else if (IS_BROADWELL(dev_priv)) {
  429. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  430. hdmi_default_entry = 7;
  431. } else if (IS_HASWELL(dev_priv)) {
  432. n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
  433. hdmi_default_entry = 6;
  434. } else {
  435. WARN(1, "ddi translation table missing\n");
  436. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  437. hdmi_default_entry = 7;
  438. }
  439. /* Choose a good default if VBT is badly populated */
  440. if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
  441. hdmi_level >= n_hdmi_entries)
  442. hdmi_level = hdmi_default_entry;
  443. return hdmi_level;
  444. }
  445. static const struct ddi_buf_trans *
  446. intel_ddi_get_buf_trans_dp(struct drm_i915_private *dev_priv,
  447. int *n_entries)
  448. {
  449. if (IS_KABYLAKE(dev_priv)) {
  450. return kbl_get_buf_trans_dp(dev_priv, n_entries);
  451. } else if (IS_SKYLAKE(dev_priv)) {
  452. return skl_get_buf_trans_dp(dev_priv, n_entries);
  453. } else if (IS_BROADWELL(dev_priv)) {
  454. *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  455. return bdw_ddi_translations_dp;
  456. } else if (IS_HASWELL(dev_priv)) {
  457. *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
  458. return hsw_ddi_translations_dp;
  459. }
  460. *n_entries = 0;
  461. return NULL;
  462. }
  463. static const struct ddi_buf_trans *
  464. intel_ddi_get_buf_trans_edp(struct drm_i915_private *dev_priv,
  465. int *n_entries)
  466. {
  467. if (IS_KABYLAKE(dev_priv) || IS_SKYLAKE(dev_priv)) {
  468. return skl_get_buf_trans_edp(dev_priv, n_entries);
  469. } else if (IS_BROADWELL(dev_priv)) {
  470. return bdw_get_buf_trans_edp(dev_priv, n_entries);
  471. } else if (IS_HASWELL(dev_priv)) {
  472. *n_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
  473. return hsw_ddi_translations_dp;
  474. }
  475. *n_entries = 0;
  476. return NULL;
  477. }
  478. static const struct ddi_buf_trans *
  479. intel_ddi_get_buf_trans_fdi(struct drm_i915_private *dev_priv,
  480. int *n_entries)
  481. {
  482. if (IS_BROADWELL(dev_priv)) {
  483. *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
  484. return hsw_ddi_translations_fdi;
  485. } else if (IS_HASWELL(dev_priv)) {
  486. *n_entries = ARRAY_SIZE(hsw_ddi_translations_fdi);
  487. return hsw_ddi_translations_fdi;
  488. }
  489. *n_entries = 0;
  490. return NULL;
  491. }
  492. /*
  493. * Starting with Haswell, DDI port buffers must be programmed with correct
  494. * values in advance. This function programs the correct values for
  495. * DP/eDP/FDI use cases.
  496. */
  497. void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder)
  498. {
  499. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  500. u32 iboost_bit = 0;
  501. int i, n_entries;
  502. enum port port = intel_ddi_get_encoder_port(encoder);
  503. const struct ddi_buf_trans *ddi_translations;
  504. if (IS_GEN9_LP(dev_priv))
  505. return;
  506. switch (encoder->type) {
  507. case INTEL_OUTPUT_EDP:
  508. ddi_translations = intel_ddi_get_buf_trans_edp(dev_priv,
  509. &n_entries);
  510. break;
  511. case INTEL_OUTPUT_DP:
  512. ddi_translations = intel_ddi_get_buf_trans_dp(dev_priv,
  513. &n_entries);
  514. break;
  515. case INTEL_OUTPUT_ANALOG:
  516. ddi_translations = intel_ddi_get_buf_trans_fdi(dev_priv,
  517. &n_entries);
  518. break;
  519. default:
  520. MISSING_CASE(encoder->type);
  521. return;
  522. }
  523. if (IS_GEN9_BC(dev_priv)) {
  524. /* If we're boosting the current, set bit 31 of trans1 */
  525. if (dev_priv->vbt.ddi_port_info[port].dp_boost_level)
  526. iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
  527. if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
  528. port != PORT_A && port != PORT_E &&
  529. n_entries > 9))
  530. n_entries = 9;
  531. }
  532. for (i = 0; i < n_entries; i++) {
  533. I915_WRITE(DDI_BUF_TRANS_LO(port, i),
  534. ddi_translations[i].trans1 | iboost_bit);
  535. I915_WRITE(DDI_BUF_TRANS_HI(port, i),
  536. ddi_translations[i].trans2);
  537. }
  538. }
  539. /*
  540. * Starting with Haswell, DDI port buffers must be programmed with correct
  541. * values in advance. This function programs the correct values for
  542. * HDMI/DVI use cases.
  543. */
  544. static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder)
  545. {
  546. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  547. u32 iboost_bit = 0;
  548. int n_hdmi_entries, hdmi_level;
  549. enum port port = intel_ddi_get_encoder_port(encoder);
  550. const struct ddi_buf_trans *ddi_translations_hdmi;
  551. if (IS_GEN9_LP(dev_priv))
  552. return;
  553. hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
  554. if (IS_GEN9_BC(dev_priv)) {
  555. ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
  556. /* If we're boosting the current, set bit 31 of trans1 */
  557. if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
  558. iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
  559. } else if (IS_BROADWELL(dev_priv)) {
  560. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  561. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  562. } else if (IS_HASWELL(dev_priv)) {
  563. ddi_translations_hdmi = hsw_ddi_translations_hdmi;
  564. n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
  565. } else {
  566. WARN(1, "ddi translation table missing\n");
  567. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  568. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  569. }
  570. /* Entry 9 is for HDMI: */
  571. I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
  572. ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
  573. I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
  574. ddi_translations_hdmi[hdmi_level].trans2);
  575. }
  576. static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
  577. enum port port)
  578. {
  579. i915_reg_t reg = DDI_BUF_CTL(port);
  580. int i;
  581. for (i = 0; i < 16; i++) {
  582. udelay(1);
  583. if (I915_READ(reg) & DDI_BUF_IS_IDLE)
  584. return;
  585. }
  586. DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
  587. }
  588. static uint32_t hsw_pll_to_ddi_pll_sel(struct intel_shared_dpll *pll)
  589. {
  590. switch (pll->id) {
  591. case DPLL_ID_WRPLL1:
  592. return PORT_CLK_SEL_WRPLL1;
  593. case DPLL_ID_WRPLL2:
  594. return PORT_CLK_SEL_WRPLL2;
  595. case DPLL_ID_SPLL:
  596. return PORT_CLK_SEL_SPLL;
  597. case DPLL_ID_LCPLL_810:
  598. return PORT_CLK_SEL_LCPLL_810;
  599. case DPLL_ID_LCPLL_1350:
  600. return PORT_CLK_SEL_LCPLL_1350;
  601. case DPLL_ID_LCPLL_2700:
  602. return PORT_CLK_SEL_LCPLL_2700;
  603. default:
  604. MISSING_CASE(pll->id);
  605. return PORT_CLK_SEL_NONE;
  606. }
  607. }
  608. /* Starting with Haswell, different DDI ports can work in FDI mode for
  609. * connection to the PCH-located connectors. For this, it is necessary to train
  610. * both the DDI port and PCH receiver for the desired DDI buffer settings.
  611. *
  612. * The recommended port to work in FDI mode is DDI E, which we use here. Also,
  613. * please note that when FDI mode is active on DDI E, it shares 2 lines with
  614. * DDI A (which is used for eDP)
  615. */
  616. void hsw_fdi_link_train(struct intel_crtc *crtc,
  617. const struct intel_crtc_state *crtc_state)
  618. {
  619. struct drm_device *dev = crtc->base.dev;
  620. struct drm_i915_private *dev_priv = to_i915(dev);
  621. struct intel_encoder *encoder;
  622. u32 temp, i, rx_ctl_val, ddi_pll_sel;
  623. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  624. WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
  625. intel_prepare_dp_ddi_buffers(encoder);
  626. }
  627. /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
  628. * mode set "sequence for CRT port" document:
  629. * - TP1 to TP2 time with the default value
  630. * - FDI delay to 90h
  631. *
  632. * WaFDIAutoLinkSetTimingOverrride:hsw
  633. */
  634. I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
  635. FDI_RX_PWRDN_LANE0_VAL(2) |
  636. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  637. /* Enable the PCH Receiver FDI PLL */
  638. rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
  639. FDI_RX_PLL_ENABLE |
  640. FDI_DP_PORT_WIDTH(crtc_state->fdi_lanes);
  641. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  642. POSTING_READ(FDI_RX_CTL(PIPE_A));
  643. udelay(220);
  644. /* Switch from Rawclk to PCDclk */
  645. rx_ctl_val |= FDI_PCDCLK;
  646. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  647. /* Configure Port Clock Select */
  648. ddi_pll_sel = hsw_pll_to_ddi_pll_sel(crtc_state->shared_dpll);
  649. I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
  650. WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
  651. /* Start the training iterating through available voltages and emphasis,
  652. * testing each value twice. */
  653. for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
  654. /* Configure DP_TP_CTL with auto-training */
  655. I915_WRITE(DP_TP_CTL(PORT_E),
  656. DP_TP_CTL_FDI_AUTOTRAIN |
  657. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  658. DP_TP_CTL_LINK_TRAIN_PAT1 |
  659. DP_TP_CTL_ENABLE);
  660. /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
  661. * DDI E does not support port reversal, the functionality is
  662. * achieved on the PCH side in FDI_RX_CTL, so no need to set the
  663. * port reversal bit */
  664. I915_WRITE(DDI_BUF_CTL(PORT_E),
  665. DDI_BUF_CTL_ENABLE |
  666. ((crtc_state->fdi_lanes - 1) << 1) |
  667. DDI_BUF_TRANS_SELECT(i / 2));
  668. POSTING_READ(DDI_BUF_CTL(PORT_E));
  669. udelay(600);
  670. /* Program PCH FDI Receiver TU */
  671. I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
  672. /* Enable PCH FDI Receiver with auto-training */
  673. rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
  674. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  675. POSTING_READ(FDI_RX_CTL(PIPE_A));
  676. /* Wait for FDI receiver lane calibration */
  677. udelay(30);
  678. /* Unset FDI_RX_MISC pwrdn lanes */
  679. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  680. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  681. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  682. POSTING_READ(FDI_RX_MISC(PIPE_A));
  683. /* Wait for FDI auto training time */
  684. udelay(5);
  685. temp = I915_READ(DP_TP_STATUS(PORT_E));
  686. if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
  687. DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
  688. break;
  689. }
  690. /*
  691. * Leave things enabled even if we failed to train FDI.
  692. * Results in less fireworks from the state checker.
  693. */
  694. if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
  695. DRM_ERROR("FDI link training failed!\n");
  696. break;
  697. }
  698. rx_ctl_val &= ~FDI_RX_ENABLE;
  699. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  700. POSTING_READ(FDI_RX_CTL(PIPE_A));
  701. temp = I915_READ(DDI_BUF_CTL(PORT_E));
  702. temp &= ~DDI_BUF_CTL_ENABLE;
  703. I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
  704. POSTING_READ(DDI_BUF_CTL(PORT_E));
  705. /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
  706. temp = I915_READ(DP_TP_CTL(PORT_E));
  707. temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  708. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  709. I915_WRITE(DP_TP_CTL(PORT_E), temp);
  710. POSTING_READ(DP_TP_CTL(PORT_E));
  711. intel_wait_ddi_buf_idle(dev_priv, PORT_E);
  712. /* Reset FDI_RX_MISC pwrdn lanes */
  713. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  714. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  715. temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  716. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  717. POSTING_READ(FDI_RX_MISC(PIPE_A));
  718. }
  719. /* Enable normal pixel sending for FDI */
  720. I915_WRITE(DP_TP_CTL(PORT_E),
  721. DP_TP_CTL_FDI_AUTOTRAIN |
  722. DP_TP_CTL_LINK_TRAIN_NORMAL |
  723. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  724. DP_TP_CTL_ENABLE);
  725. }
  726. void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
  727. {
  728. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  729. struct intel_digital_port *intel_dig_port =
  730. enc_to_dig_port(&encoder->base);
  731. intel_dp->DP = intel_dig_port->saved_port_bits |
  732. DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
  733. intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
  734. }
  735. static struct intel_encoder *
  736. intel_ddi_get_crtc_encoder(struct intel_crtc *crtc)
  737. {
  738. struct drm_device *dev = crtc->base.dev;
  739. struct intel_encoder *encoder, *ret = NULL;
  740. int num_encoders = 0;
  741. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  742. ret = encoder;
  743. num_encoders++;
  744. }
  745. if (num_encoders != 1)
  746. WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
  747. pipe_name(crtc->pipe));
  748. BUG_ON(ret == NULL);
  749. return ret;
  750. }
  751. static struct intel_encoder *
  752. intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
  753. {
  754. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  755. struct intel_encoder *ret = NULL;
  756. struct drm_atomic_state *state;
  757. struct drm_connector *connector;
  758. struct drm_connector_state *connector_state;
  759. int num_encoders = 0;
  760. int i;
  761. state = crtc_state->base.state;
  762. for_each_new_connector_in_state(state, connector, connector_state, i) {
  763. if (connector_state->crtc != crtc_state->base.crtc)
  764. continue;
  765. ret = to_intel_encoder(connector_state->best_encoder);
  766. num_encoders++;
  767. }
  768. WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
  769. pipe_name(crtc->pipe));
  770. BUG_ON(ret == NULL);
  771. return ret;
  772. }
  773. #define LC_FREQ 2700
  774. static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
  775. i915_reg_t reg)
  776. {
  777. int refclk = LC_FREQ;
  778. int n, p, r;
  779. u32 wrpll;
  780. wrpll = I915_READ(reg);
  781. switch (wrpll & WRPLL_PLL_REF_MASK) {
  782. case WRPLL_PLL_SSC:
  783. case WRPLL_PLL_NON_SSC:
  784. /*
  785. * We could calculate spread here, but our checking
  786. * code only cares about 5% accuracy, and spread is a max of
  787. * 0.5% downspread.
  788. */
  789. refclk = 135;
  790. break;
  791. case WRPLL_PLL_LCPLL:
  792. refclk = LC_FREQ;
  793. break;
  794. default:
  795. WARN(1, "bad wrpll refclk\n");
  796. return 0;
  797. }
  798. r = wrpll & WRPLL_DIVIDER_REF_MASK;
  799. p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
  800. n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
  801. /* Convert to KHz, p & r have a fixed point portion */
  802. return (refclk * n * 100) / (p * r);
  803. }
  804. static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
  805. uint32_t dpll)
  806. {
  807. i915_reg_t cfgcr1_reg, cfgcr2_reg;
  808. uint32_t cfgcr1_val, cfgcr2_val;
  809. uint32_t p0, p1, p2, dco_freq;
  810. cfgcr1_reg = DPLL_CFGCR1(dpll);
  811. cfgcr2_reg = DPLL_CFGCR2(dpll);
  812. cfgcr1_val = I915_READ(cfgcr1_reg);
  813. cfgcr2_val = I915_READ(cfgcr2_reg);
  814. p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
  815. p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
  816. if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
  817. p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
  818. else
  819. p1 = 1;
  820. switch (p0) {
  821. case DPLL_CFGCR2_PDIV_1:
  822. p0 = 1;
  823. break;
  824. case DPLL_CFGCR2_PDIV_2:
  825. p0 = 2;
  826. break;
  827. case DPLL_CFGCR2_PDIV_3:
  828. p0 = 3;
  829. break;
  830. case DPLL_CFGCR2_PDIV_7:
  831. p0 = 7;
  832. break;
  833. }
  834. switch (p2) {
  835. case DPLL_CFGCR2_KDIV_5:
  836. p2 = 5;
  837. break;
  838. case DPLL_CFGCR2_KDIV_2:
  839. p2 = 2;
  840. break;
  841. case DPLL_CFGCR2_KDIV_3:
  842. p2 = 3;
  843. break;
  844. case DPLL_CFGCR2_KDIV_1:
  845. p2 = 1;
  846. break;
  847. }
  848. dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
  849. dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
  850. 1000) / 0x8000;
  851. return dco_freq / (p0 * p1 * p2 * 5);
  852. }
  853. static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
  854. {
  855. int dotclock;
  856. if (pipe_config->has_pch_encoder)
  857. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  858. &pipe_config->fdi_m_n);
  859. else if (intel_crtc_has_dp_encoder(pipe_config))
  860. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  861. &pipe_config->dp_m_n);
  862. else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
  863. dotclock = pipe_config->port_clock * 2 / 3;
  864. else
  865. dotclock = pipe_config->port_clock;
  866. if (pipe_config->pixel_multiplier)
  867. dotclock /= pipe_config->pixel_multiplier;
  868. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  869. }
  870. static void skl_ddi_clock_get(struct intel_encoder *encoder,
  871. struct intel_crtc_state *pipe_config)
  872. {
  873. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  874. int link_clock = 0;
  875. uint32_t dpll_ctl1, dpll;
  876. dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
  877. dpll_ctl1 = I915_READ(DPLL_CTRL1);
  878. if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
  879. link_clock = skl_calc_wrpll_link(dev_priv, dpll);
  880. } else {
  881. link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
  882. link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
  883. switch (link_clock) {
  884. case DPLL_CTRL1_LINK_RATE_810:
  885. link_clock = 81000;
  886. break;
  887. case DPLL_CTRL1_LINK_RATE_1080:
  888. link_clock = 108000;
  889. break;
  890. case DPLL_CTRL1_LINK_RATE_1350:
  891. link_clock = 135000;
  892. break;
  893. case DPLL_CTRL1_LINK_RATE_1620:
  894. link_clock = 162000;
  895. break;
  896. case DPLL_CTRL1_LINK_RATE_2160:
  897. link_clock = 216000;
  898. break;
  899. case DPLL_CTRL1_LINK_RATE_2700:
  900. link_clock = 270000;
  901. break;
  902. default:
  903. WARN(1, "Unsupported link rate\n");
  904. break;
  905. }
  906. link_clock *= 2;
  907. }
  908. pipe_config->port_clock = link_clock;
  909. ddi_dotclock_get(pipe_config);
  910. }
  911. static void hsw_ddi_clock_get(struct intel_encoder *encoder,
  912. struct intel_crtc_state *pipe_config)
  913. {
  914. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  915. int link_clock = 0;
  916. u32 val, pll;
  917. val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
  918. switch (val & PORT_CLK_SEL_MASK) {
  919. case PORT_CLK_SEL_LCPLL_810:
  920. link_clock = 81000;
  921. break;
  922. case PORT_CLK_SEL_LCPLL_1350:
  923. link_clock = 135000;
  924. break;
  925. case PORT_CLK_SEL_LCPLL_2700:
  926. link_clock = 270000;
  927. break;
  928. case PORT_CLK_SEL_WRPLL1:
  929. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
  930. break;
  931. case PORT_CLK_SEL_WRPLL2:
  932. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
  933. break;
  934. case PORT_CLK_SEL_SPLL:
  935. pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
  936. if (pll == SPLL_PLL_FREQ_810MHz)
  937. link_clock = 81000;
  938. else if (pll == SPLL_PLL_FREQ_1350MHz)
  939. link_clock = 135000;
  940. else if (pll == SPLL_PLL_FREQ_2700MHz)
  941. link_clock = 270000;
  942. else {
  943. WARN(1, "bad spll freq\n");
  944. return;
  945. }
  946. break;
  947. default:
  948. WARN(1, "bad port clock sel\n");
  949. return;
  950. }
  951. pipe_config->port_clock = link_clock * 2;
  952. ddi_dotclock_get(pipe_config);
  953. }
  954. static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
  955. enum intel_dpll_id dpll)
  956. {
  957. struct intel_shared_dpll *pll;
  958. struct intel_dpll_hw_state *state;
  959. struct dpll clock;
  960. /* For DDI ports we always use a shared PLL. */
  961. if (WARN_ON(dpll == DPLL_ID_PRIVATE))
  962. return 0;
  963. pll = &dev_priv->shared_dplls[dpll];
  964. state = &pll->state.hw_state;
  965. clock.m1 = 2;
  966. clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
  967. if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
  968. clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
  969. clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
  970. clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
  971. clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
  972. return chv_calc_dpll_params(100000, &clock);
  973. }
  974. static void bxt_ddi_clock_get(struct intel_encoder *encoder,
  975. struct intel_crtc_state *pipe_config)
  976. {
  977. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  978. enum port port = intel_ddi_get_encoder_port(encoder);
  979. uint32_t dpll = port;
  980. pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
  981. ddi_dotclock_get(pipe_config);
  982. }
  983. void intel_ddi_clock_get(struct intel_encoder *encoder,
  984. struct intel_crtc_state *pipe_config)
  985. {
  986. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  987. if (INTEL_GEN(dev_priv) <= 8)
  988. hsw_ddi_clock_get(encoder, pipe_config);
  989. else if (IS_GEN9_BC(dev_priv))
  990. skl_ddi_clock_get(encoder, pipe_config);
  991. else if (IS_GEN9_LP(dev_priv))
  992. bxt_ddi_clock_get(encoder, pipe_config);
  993. }
  994. static bool
  995. hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
  996. struct intel_crtc_state *crtc_state,
  997. struct intel_encoder *encoder)
  998. {
  999. struct intel_shared_dpll *pll;
  1000. pll = intel_get_shared_dpll(intel_crtc, crtc_state,
  1001. encoder);
  1002. if (!pll)
  1003. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  1004. pipe_name(intel_crtc->pipe));
  1005. return pll;
  1006. }
  1007. static bool
  1008. skl_ddi_pll_select(struct intel_crtc *intel_crtc,
  1009. struct intel_crtc_state *crtc_state,
  1010. struct intel_encoder *encoder)
  1011. {
  1012. struct intel_shared_dpll *pll;
  1013. pll = intel_get_shared_dpll(intel_crtc, crtc_state, encoder);
  1014. if (pll == NULL) {
  1015. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  1016. pipe_name(intel_crtc->pipe));
  1017. return false;
  1018. }
  1019. return true;
  1020. }
  1021. static bool
  1022. bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
  1023. struct intel_crtc_state *crtc_state,
  1024. struct intel_encoder *encoder)
  1025. {
  1026. return !!intel_get_shared_dpll(intel_crtc, crtc_state, encoder);
  1027. }
  1028. /*
  1029. * Tries to find a *shared* PLL for the CRTC and store it in
  1030. * intel_crtc->ddi_pll_sel.
  1031. *
  1032. * For private DPLLs, compute_config() should do the selection for us. This
  1033. * function should be folded into compute_config() eventually.
  1034. */
  1035. bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
  1036. struct intel_crtc_state *crtc_state)
  1037. {
  1038. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  1039. struct intel_encoder *encoder =
  1040. intel_ddi_get_crtc_new_encoder(crtc_state);
  1041. if (IS_GEN9_BC(dev_priv))
  1042. return skl_ddi_pll_select(intel_crtc, crtc_state,
  1043. encoder);
  1044. else if (IS_GEN9_LP(dev_priv))
  1045. return bxt_ddi_pll_select(intel_crtc, crtc_state,
  1046. encoder);
  1047. else
  1048. return hsw_ddi_pll_select(intel_crtc, crtc_state,
  1049. encoder);
  1050. }
  1051. void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
  1052. {
  1053. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1054. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1055. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1056. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1057. int type = encoder->type;
  1058. uint32_t temp;
  1059. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
  1060. WARN_ON(transcoder_is_dsi(cpu_transcoder));
  1061. temp = TRANS_MSA_SYNC_CLK;
  1062. switch (crtc_state->pipe_bpp) {
  1063. case 18:
  1064. temp |= TRANS_MSA_6_BPC;
  1065. break;
  1066. case 24:
  1067. temp |= TRANS_MSA_8_BPC;
  1068. break;
  1069. case 30:
  1070. temp |= TRANS_MSA_10_BPC;
  1071. break;
  1072. case 36:
  1073. temp |= TRANS_MSA_12_BPC;
  1074. break;
  1075. default:
  1076. BUG();
  1077. }
  1078. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  1079. }
  1080. }
  1081. void intel_ddi_set_vc_payload_alloc(const struct intel_crtc_state *crtc_state,
  1082. bool state)
  1083. {
  1084. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1085. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1086. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1087. uint32_t temp;
  1088. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1089. if (state == true)
  1090. temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1091. else
  1092. temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1093. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1094. }
  1095. void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state)
  1096. {
  1097. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1098. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1099. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1100. enum pipe pipe = crtc->pipe;
  1101. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1102. enum port port = intel_ddi_get_encoder_port(encoder);
  1103. int type = encoder->type;
  1104. uint32_t temp;
  1105. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  1106. temp = TRANS_DDI_FUNC_ENABLE;
  1107. temp |= TRANS_DDI_SELECT_PORT(port);
  1108. switch (crtc_state->pipe_bpp) {
  1109. case 18:
  1110. temp |= TRANS_DDI_BPC_6;
  1111. break;
  1112. case 24:
  1113. temp |= TRANS_DDI_BPC_8;
  1114. break;
  1115. case 30:
  1116. temp |= TRANS_DDI_BPC_10;
  1117. break;
  1118. case 36:
  1119. temp |= TRANS_DDI_BPC_12;
  1120. break;
  1121. default:
  1122. BUG();
  1123. }
  1124. if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
  1125. temp |= TRANS_DDI_PVSYNC;
  1126. if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
  1127. temp |= TRANS_DDI_PHSYNC;
  1128. if (cpu_transcoder == TRANSCODER_EDP) {
  1129. switch (pipe) {
  1130. case PIPE_A:
  1131. /* On Haswell, can only use the always-on power well for
  1132. * eDP when not using the panel fitter, and when not
  1133. * using motion blur mitigation (which we don't
  1134. * support). */
  1135. if (IS_HASWELL(dev_priv) &&
  1136. (crtc_state->pch_pfit.enabled ||
  1137. crtc_state->pch_pfit.force_thru))
  1138. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  1139. else
  1140. temp |= TRANS_DDI_EDP_INPUT_A_ON;
  1141. break;
  1142. case PIPE_B:
  1143. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  1144. break;
  1145. case PIPE_C:
  1146. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  1147. break;
  1148. default:
  1149. BUG();
  1150. break;
  1151. }
  1152. }
  1153. if (type == INTEL_OUTPUT_HDMI) {
  1154. if (crtc_state->has_hdmi_sink)
  1155. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  1156. else
  1157. temp |= TRANS_DDI_MODE_SELECT_DVI;
  1158. } else if (type == INTEL_OUTPUT_ANALOG) {
  1159. temp |= TRANS_DDI_MODE_SELECT_FDI;
  1160. temp |= (crtc_state->fdi_lanes - 1) << 1;
  1161. } else if (type == INTEL_OUTPUT_DP ||
  1162. type == INTEL_OUTPUT_EDP) {
  1163. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  1164. temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
  1165. } else if (type == INTEL_OUTPUT_DP_MST) {
  1166. temp |= TRANS_DDI_MODE_SELECT_DP_MST;
  1167. temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
  1168. } else {
  1169. WARN(1, "Invalid encoder type %d for pipe %c\n",
  1170. encoder->type, pipe_name(pipe));
  1171. }
  1172. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1173. }
  1174. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  1175. enum transcoder cpu_transcoder)
  1176. {
  1177. i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1178. uint32_t val = I915_READ(reg);
  1179. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
  1180. val |= TRANS_DDI_PORT_NONE;
  1181. I915_WRITE(reg, val);
  1182. }
  1183. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  1184. {
  1185. struct drm_device *dev = intel_connector->base.dev;
  1186. struct drm_i915_private *dev_priv = to_i915(dev);
  1187. struct intel_encoder *encoder = intel_connector->encoder;
  1188. int type = intel_connector->base.connector_type;
  1189. enum port port = intel_ddi_get_encoder_port(encoder);
  1190. enum pipe pipe = 0;
  1191. enum transcoder cpu_transcoder;
  1192. uint32_t tmp;
  1193. bool ret;
  1194. if (!intel_display_power_get_if_enabled(dev_priv,
  1195. encoder->power_domain))
  1196. return false;
  1197. if (!encoder->get_hw_state(encoder, &pipe)) {
  1198. ret = false;
  1199. goto out;
  1200. }
  1201. if (port == PORT_A)
  1202. cpu_transcoder = TRANSCODER_EDP;
  1203. else
  1204. cpu_transcoder = (enum transcoder) pipe;
  1205. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1206. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  1207. case TRANS_DDI_MODE_SELECT_HDMI:
  1208. case TRANS_DDI_MODE_SELECT_DVI:
  1209. ret = type == DRM_MODE_CONNECTOR_HDMIA;
  1210. break;
  1211. case TRANS_DDI_MODE_SELECT_DP_SST:
  1212. ret = type == DRM_MODE_CONNECTOR_eDP ||
  1213. type == DRM_MODE_CONNECTOR_DisplayPort;
  1214. break;
  1215. case TRANS_DDI_MODE_SELECT_DP_MST:
  1216. /* if the transcoder is in MST state then
  1217. * connector isn't connected */
  1218. ret = false;
  1219. break;
  1220. case TRANS_DDI_MODE_SELECT_FDI:
  1221. ret = type == DRM_MODE_CONNECTOR_VGA;
  1222. break;
  1223. default:
  1224. ret = false;
  1225. break;
  1226. }
  1227. out:
  1228. intel_display_power_put(dev_priv, encoder->power_domain);
  1229. return ret;
  1230. }
  1231. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  1232. enum pipe *pipe)
  1233. {
  1234. struct drm_device *dev = encoder->base.dev;
  1235. struct drm_i915_private *dev_priv = to_i915(dev);
  1236. enum port port = intel_ddi_get_encoder_port(encoder);
  1237. u32 tmp;
  1238. int i;
  1239. bool ret;
  1240. if (!intel_display_power_get_if_enabled(dev_priv,
  1241. encoder->power_domain))
  1242. return false;
  1243. ret = false;
  1244. tmp = I915_READ(DDI_BUF_CTL(port));
  1245. if (!(tmp & DDI_BUF_CTL_ENABLE))
  1246. goto out;
  1247. if (port == PORT_A) {
  1248. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  1249. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  1250. case TRANS_DDI_EDP_INPUT_A_ON:
  1251. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  1252. *pipe = PIPE_A;
  1253. break;
  1254. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  1255. *pipe = PIPE_B;
  1256. break;
  1257. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  1258. *pipe = PIPE_C;
  1259. break;
  1260. }
  1261. ret = true;
  1262. goto out;
  1263. }
  1264. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  1265. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  1266. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
  1267. if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
  1268. TRANS_DDI_MODE_SELECT_DP_MST)
  1269. goto out;
  1270. *pipe = i;
  1271. ret = true;
  1272. goto out;
  1273. }
  1274. }
  1275. DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
  1276. out:
  1277. if (ret && IS_GEN9_LP(dev_priv)) {
  1278. tmp = I915_READ(BXT_PHY_CTL(port));
  1279. if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK |
  1280. BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
  1281. DRM_ERROR("Port %c enabled but PHY powered down? "
  1282. "(PHY_CTL %08x)\n", port_name(port), tmp);
  1283. }
  1284. intel_display_power_put(dev_priv, encoder->power_domain);
  1285. return ret;
  1286. }
  1287. static u64 intel_ddi_get_power_domains(struct intel_encoder *encoder)
  1288. {
  1289. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1290. enum pipe pipe;
  1291. if (intel_ddi_get_hw_state(encoder, &pipe))
  1292. return BIT_ULL(dig_port->ddi_io_power_domain);
  1293. return 0;
  1294. }
  1295. void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state)
  1296. {
  1297. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1298. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1299. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1300. enum port port = intel_ddi_get_encoder_port(encoder);
  1301. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1302. if (cpu_transcoder != TRANSCODER_EDP)
  1303. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1304. TRANS_CLK_SEL_PORT(port));
  1305. }
  1306. void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
  1307. {
  1308. struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
  1309. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1310. if (cpu_transcoder != TRANSCODER_EDP)
  1311. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1312. TRANS_CLK_SEL_DISABLED);
  1313. }
  1314. static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
  1315. enum port port, uint8_t iboost)
  1316. {
  1317. u32 tmp;
  1318. tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
  1319. tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
  1320. if (iboost)
  1321. tmp |= iboost << BALANCE_LEG_SHIFT(port);
  1322. else
  1323. tmp |= BALANCE_LEG_DISABLE(port);
  1324. I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
  1325. }
  1326. static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
  1327. {
  1328. struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
  1329. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  1330. enum port port = intel_dig_port->port;
  1331. int type = encoder->type;
  1332. const struct ddi_buf_trans *ddi_translations;
  1333. uint8_t iboost;
  1334. uint8_t dp_iboost, hdmi_iboost;
  1335. int n_entries;
  1336. /* VBT may override standard boost values */
  1337. dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
  1338. hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
  1339. if (type == INTEL_OUTPUT_DP) {
  1340. if (dp_iboost) {
  1341. iboost = dp_iboost;
  1342. } else {
  1343. if (IS_KABYLAKE(dev_priv))
  1344. ddi_translations = kbl_get_buf_trans_dp(dev_priv,
  1345. &n_entries);
  1346. else
  1347. ddi_translations = skl_get_buf_trans_dp(dev_priv,
  1348. &n_entries);
  1349. iboost = ddi_translations[level].i_boost;
  1350. }
  1351. } else if (type == INTEL_OUTPUT_EDP) {
  1352. if (dp_iboost) {
  1353. iboost = dp_iboost;
  1354. } else {
  1355. ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
  1356. if (WARN_ON(port != PORT_A &&
  1357. port != PORT_E && n_entries > 9))
  1358. n_entries = 9;
  1359. iboost = ddi_translations[level].i_boost;
  1360. }
  1361. } else if (type == INTEL_OUTPUT_HDMI) {
  1362. if (hdmi_iboost) {
  1363. iboost = hdmi_iboost;
  1364. } else {
  1365. ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
  1366. iboost = ddi_translations[level].i_boost;
  1367. }
  1368. } else {
  1369. return;
  1370. }
  1371. /* Make sure that the requested I_boost is valid */
  1372. if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
  1373. DRM_ERROR("Invalid I_boost value %u\n", iboost);
  1374. return;
  1375. }
  1376. _skl_ddi_set_iboost(dev_priv, port, iboost);
  1377. if (port == PORT_A && intel_dig_port->max_lanes == 4)
  1378. _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
  1379. }
  1380. static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
  1381. u32 level, enum port port, int type)
  1382. {
  1383. const struct bxt_ddi_buf_trans *ddi_translations;
  1384. u32 n_entries, i;
  1385. if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
  1386. n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
  1387. ddi_translations = bxt_ddi_translations_edp;
  1388. } else if (type == INTEL_OUTPUT_DP
  1389. || type == INTEL_OUTPUT_EDP) {
  1390. n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
  1391. ddi_translations = bxt_ddi_translations_dp;
  1392. } else if (type == INTEL_OUTPUT_HDMI) {
  1393. n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
  1394. ddi_translations = bxt_ddi_translations_hdmi;
  1395. } else {
  1396. DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
  1397. type);
  1398. return;
  1399. }
  1400. /* Check if default value has to be used */
  1401. if (level >= n_entries ||
  1402. (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
  1403. for (i = 0; i < n_entries; i++) {
  1404. if (ddi_translations[i].default_index) {
  1405. level = i;
  1406. break;
  1407. }
  1408. }
  1409. }
  1410. bxt_ddi_phy_set_signal_level(dev_priv, port,
  1411. ddi_translations[level].margin,
  1412. ddi_translations[level].scale,
  1413. ddi_translations[level].enable,
  1414. ddi_translations[level].deemphasis);
  1415. }
  1416. u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder)
  1417. {
  1418. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1419. int n_entries;
  1420. if (encoder->type == INTEL_OUTPUT_EDP)
  1421. intel_ddi_get_buf_trans_edp(dev_priv, &n_entries);
  1422. else
  1423. intel_ddi_get_buf_trans_dp(dev_priv, &n_entries);
  1424. if (WARN_ON(n_entries < 1))
  1425. n_entries = 1;
  1426. if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
  1427. n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
  1428. return index_to_dp_signal_levels[n_entries - 1] &
  1429. DP_TRAIN_VOLTAGE_SWING_MASK;
  1430. }
  1431. static uint32_t translate_signal_level(int signal_levels)
  1432. {
  1433. int i;
  1434. for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
  1435. if (index_to_dp_signal_levels[i] == signal_levels)
  1436. return i;
  1437. }
  1438. WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
  1439. signal_levels);
  1440. return 0;
  1441. }
  1442. uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
  1443. {
  1444. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1445. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  1446. struct intel_encoder *encoder = &dport->base;
  1447. uint8_t train_set = intel_dp->train_set[0];
  1448. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1449. DP_TRAIN_PRE_EMPHASIS_MASK);
  1450. enum port port = dport->port;
  1451. uint32_t level;
  1452. level = translate_signal_level(signal_levels);
  1453. if (IS_GEN9_BC(dev_priv))
  1454. skl_ddi_set_iboost(encoder, level);
  1455. else if (IS_GEN9_LP(dev_priv))
  1456. bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
  1457. return DDI_BUF_TRANS_SELECT(level);
  1458. }
  1459. void intel_ddi_clk_select(struct intel_encoder *encoder,
  1460. struct intel_shared_dpll *pll)
  1461. {
  1462. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1463. enum port port = intel_ddi_get_encoder_port(encoder);
  1464. if (WARN_ON(!pll))
  1465. return;
  1466. if (IS_GEN9_BC(dev_priv)) {
  1467. uint32_t val;
  1468. /* DDI -> PLL mapping */
  1469. val = I915_READ(DPLL_CTRL2);
  1470. val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
  1471. DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
  1472. val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
  1473. DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
  1474. I915_WRITE(DPLL_CTRL2, val);
  1475. } else if (INTEL_INFO(dev_priv)->gen < 9) {
  1476. I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
  1477. }
  1478. }
  1479. static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
  1480. int link_rate, uint32_t lane_count,
  1481. struct intel_shared_dpll *pll,
  1482. bool link_mst)
  1483. {
  1484. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1485. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1486. enum port port = intel_ddi_get_encoder_port(encoder);
  1487. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1488. WARN_ON(link_mst && (port == PORT_A || port == PORT_E));
  1489. intel_dp_set_link_params(intel_dp, link_rate, lane_count,
  1490. link_mst);
  1491. if (encoder->type == INTEL_OUTPUT_EDP)
  1492. intel_edp_panel_on(intel_dp);
  1493. intel_ddi_clk_select(encoder, pll);
  1494. intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
  1495. intel_prepare_dp_ddi_buffers(encoder);
  1496. intel_ddi_init_dp_buf_reg(encoder);
  1497. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1498. intel_dp_start_link_train(intel_dp);
  1499. if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
  1500. intel_dp_stop_link_train(intel_dp);
  1501. }
  1502. static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
  1503. bool has_hdmi_sink,
  1504. const struct intel_crtc_state *crtc_state,
  1505. const struct drm_connector_state *conn_state,
  1506. struct intel_shared_dpll *pll)
  1507. {
  1508. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1509. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1510. struct drm_encoder *drm_encoder = &encoder->base;
  1511. enum port port = intel_ddi_get_encoder_port(encoder);
  1512. int level = intel_ddi_hdmi_level(dev_priv, port);
  1513. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1514. intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
  1515. intel_ddi_clk_select(encoder, pll);
  1516. intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
  1517. intel_prepare_hdmi_ddi_buffers(encoder);
  1518. if (IS_GEN9_BC(dev_priv))
  1519. skl_ddi_set_iboost(encoder, level);
  1520. else if (IS_GEN9_LP(dev_priv))
  1521. bxt_ddi_vswing_sequence(dev_priv, level, port,
  1522. INTEL_OUTPUT_HDMI);
  1523. intel_hdmi->set_infoframes(drm_encoder,
  1524. has_hdmi_sink,
  1525. crtc_state, conn_state);
  1526. }
  1527. static void intel_ddi_pre_enable(struct intel_encoder *encoder,
  1528. struct intel_crtc_state *pipe_config,
  1529. struct drm_connector_state *conn_state)
  1530. {
  1531. int type = encoder->type;
  1532. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1533. intel_ddi_pre_enable_dp(encoder,
  1534. pipe_config->port_clock,
  1535. pipe_config->lane_count,
  1536. pipe_config->shared_dpll,
  1537. intel_crtc_has_type(pipe_config,
  1538. INTEL_OUTPUT_DP_MST));
  1539. }
  1540. if (type == INTEL_OUTPUT_HDMI) {
  1541. intel_ddi_pre_enable_hdmi(encoder,
  1542. pipe_config->has_hdmi_sink,
  1543. pipe_config, conn_state,
  1544. pipe_config->shared_dpll);
  1545. }
  1546. }
  1547. static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
  1548. struct intel_crtc_state *old_crtc_state,
  1549. struct drm_connector_state *old_conn_state)
  1550. {
  1551. struct drm_encoder *encoder = &intel_encoder->base;
  1552. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  1553. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1554. struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
  1555. int type = intel_encoder->type;
  1556. uint32_t val;
  1557. bool wait = false;
  1558. /* old_crtc_state and old_conn_state are NULL when called from DP_MST */
  1559. val = I915_READ(DDI_BUF_CTL(port));
  1560. if (val & DDI_BUF_CTL_ENABLE) {
  1561. val &= ~DDI_BUF_CTL_ENABLE;
  1562. I915_WRITE(DDI_BUF_CTL(port), val);
  1563. wait = true;
  1564. }
  1565. val = I915_READ(DP_TP_CTL(port));
  1566. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1567. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1568. I915_WRITE(DP_TP_CTL(port), val);
  1569. if (wait)
  1570. intel_wait_ddi_buf_idle(dev_priv, port);
  1571. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1572. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1573. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1574. intel_edp_panel_vdd_on(intel_dp);
  1575. intel_edp_panel_off(intel_dp);
  1576. }
  1577. if (dig_port)
  1578. intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
  1579. if (IS_GEN9_BC(dev_priv))
  1580. I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
  1581. DPLL_CTRL2_DDI_CLK_OFF(port)));
  1582. else if (INTEL_GEN(dev_priv) < 9)
  1583. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1584. if (type == INTEL_OUTPUT_HDMI) {
  1585. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  1586. intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
  1587. }
  1588. }
  1589. void intel_ddi_fdi_post_disable(struct intel_encoder *encoder,
  1590. struct intel_crtc_state *old_crtc_state,
  1591. struct drm_connector_state *old_conn_state)
  1592. {
  1593. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1594. uint32_t val;
  1595. /*
  1596. * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
  1597. * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
  1598. * step 13 is the correct place for it. Step 18 is where it was
  1599. * originally before the BUN.
  1600. */
  1601. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1602. val &= ~FDI_RX_ENABLE;
  1603. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1604. intel_ddi_post_disable(encoder, old_crtc_state, old_conn_state);
  1605. val = I915_READ(FDI_RX_MISC(PIPE_A));
  1606. val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  1607. val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  1608. I915_WRITE(FDI_RX_MISC(PIPE_A), val);
  1609. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1610. val &= ~FDI_PCDCLK;
  1611. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1612. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1613. val &= ~FDI_RX_PLL_ENABLE;
  1614. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1615. }
  1616. static void intel_enable_ddi(struct intel_encoder *intel_encoder,
  1617. struct intel_crtc_state *pipe_config,
  1618. struct drm_connector_state *conn_state)
  1619. {
  1620. struct drm_encoder *encoder = &intel_encoder->base;
  1621. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  1622. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1623. int type = intel_encoder->type;
  1624. if (type == INTEL_OUTPUT_HDMI) {
  1625. struct intel_digital_port *intel_dig_port =
  1626. enc_to_dig_port(encoder);
  1627. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  1628. * are ignored so nothing special needs to be done besides
  1629. * enabling the port.
  1630. */
  1631. I915_WRITE(DDI_BUF_CTL(port),
  1632. intel_dig_port->saved_port_bits |
  1633. DDI_BUF_CTL_ENABLE);
  1634. } else if (type == INTEL_OUTPUT_EDP) {
  1635. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1636. if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
  1637. intel_dp_stop_link_train(intel_dp);
  1638. intel_edp_backlight_on(intel_dp);
  1639. intel_psr_enable(intel_dp);
  1640. intel_edp_drrs_enable(intel_dp, pipe_config);
  1641. }
  1642. if (pipe_config->has_audio)
  1643. intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
  1644. }
  1645. static void intel_disable_ddi(struct intel_encoder *intel_encoder,
  1646. struct intel_crtc_state *old_crtc_state,
  1647. struct drm_connector_state *old_conn_state)
  1648. {
  1649. struct drm_encoder *encoder = &intel_encoder->base;
  1650. int type = intel_encoder->type;
  1651. if (old_crtc_state->has_audio)
  1652. intel_audio_codec_disable(intel_encoder);
  1653. if (type == INTEL_OUTPUT_EDP) {
  1654. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1655. intel_edp_drrs_disable(intel_dp, old_crtc_state);
  1656. intel_psr_disable(intel_dp);
  1657. intel_edp_backlight_off(intel_dp);
  1658. }
  1659. }
  1660. static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
  1661. struct intel_crtc_state *pipe_config,
  1662. struct drm_connector_state *conn_state)
  1663. {
  1664. uint8_t mask = pipe_config->lane_lat_optim_mask;
  1665. bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
  1666. }
  1667. void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
  1668. {
  1669. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1670. struct drm_i915_private *dev_priv =
  1671. to_i915(intel_dig_port->base.base.dev);
  1672. enum port port = intel_dig_port->port;
  1673. uint32_t val;
  1674. bool wait = false;
  1675. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  1676. val = I915_READ(DDI_BUF_CTL(port));
  1677. if (val & DDI_BUF_CTL_ENABLE) {
  1678. val &= ~DDI_BUF_CTL_ENABLE;
  1679. I915_WRITE(DDI_BUF_CTL(port), val);
  1680. wait = true;
  1681. }
  1682. val = I915_READ(DP_TP_CTL(port));
  1683. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1684. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1685. I915_WRITE(DP_TP_CTL(port), val);
  1686. POSTING_READ(DP_TP_CTL(port));
  1687. if (wait)
  1688. intel_wait_ddi_buf_idle(dev_priv, port);
  1689. }
  1690. val = DP_TP_CTL_ENABLE |
  1691. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  1692. if (intel_dp->link_mst)
  1693. val |= DP_TP_CTL_MODE_MST;
  1694. else {
  1695. val |= DP_TP_CTL_MODE_SST;
  1696. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1697. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  1698. }
  1699. I915_WRITE(DP_TP_CTL(port), val);
  1700. POSTING_READ(DP_TP_CTL(port));
  1701. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  1702. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  1703. POSTING_READ(DDI_BUF_CTL(port));
  1704. udelay(600);
  1705. }
  1706. bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
  1707. struct intel_crtc *intel_crtc)
  1708. {
  1709. u32 temp;
  1710. if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
  1711. temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1712. if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
  1713. return true;
  1714. }
  1715. return false;
  1716. }
  1717. void intel_ddi_get_config(struct intel_encoder *encoder,
  1718. struct intel_crtc_state *pipe_config)
  1719. {
  1720. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1721. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1722. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  1723. struct intel_hdmi *intel_hdmi;
  1724. u32 temp, flags = 0;
  1725. /* XXX: DSI transcoder paranoia */
  1726. if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
  1727. return;
  1728. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1729. if (temp & TRANS_DDI_PHSYNC)
  1730. flags |= DRM_MODE_FLAG_PHSYNC;
  1731. else
  1732. flags |= DRM_MODE_FLAG_NHSYNC;
  1733. if (temp & TRANS_DDI_PVSYNC)
  1734. flags |= DRM_MODE_FLAG_PVSYNC;
  1735. else
  1736. flags |= DRM_MODE_FLAG_NVSYNC;
  1737. pipe_config->base.adjusted_mode.flags |= flags;
  1738. switch (temp & TRANS_DDI_BPC_MASK) {
  1739. case TRANS_DDI_BPC_6:
  1740. pipe_config->pipe_bpp = 18;
  1741. break;
  1742. case TRANS_DDI_BPC_8:
  1743. pipe_config->pipe_bpp = 24;
  1744. break;
  1745. case TRANS_DDI_BPC_10:
  1746. pipe_config->pipe_bpp = 30;
  1747. break;
  1748. case TRANS_DDI_BPC_12:
  1749. pipe_config->pipe_bpp = 36;
  1750. break;
  1751. default:
  1752. break;
  1753. }
  1754. switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
  1755. case TRANS_DDI_MODE_SELECT_HDMI:
  1756. pipe_config->has_hdmi_sink = true;
  1757. intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1758. if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
  1759. pipe_config->has_infoframe = true;
  1760. /* fall through */
  1761. case TRANS_DDI_MODE_SELECT_DVI:
  1762. pipe_config->lane_count = 4;
  1763. break;
  1764. case TRANS_DDI_MODE_SELECT_FDI:
  1765. break;
  1766. case TRANS_DDI_MODE_SELECT_DP_SST:
  1767. case TRANS_DDI_MODE_SELECT_DP_MST:
  1768. pipe_config->lane_count =
  1769. ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
  1770. intel_dp_get_m_n(intel_crtc, pipe_config);
  1771. break;
  1772. default:
  1773. break;
  1774. }
  1775. pipe_config->has_audio =
  1776. intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
  1777. if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
  1778. pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
  1779. /*
  1780. * This is a big fat ugly hack.
  1781. *
  1782. * Some machines in UEFI boot mode provide us a VBT that has 18
  1783. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1784. * unknown we fail to light up. Yet the same BIOS boots up with
  1785. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1786. * max, not what it tells us to use.
  1787. *
  1788. * Note: This will still be broken if the eDP panel is not lit
  1789. * up by the BIOS, and thus we can't get the mode at module
  1790. * load.
  1791. */
  1792. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1793. pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
  1794. dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
  1795. }
  1796. intel_ddi_clock_get(encoder, pipe_config);
  1797. if (IS_GEN9_LP(dev_priv))
  1798. pipe_config->lane_lat_optim_mask =
  1799. bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
  1800. }
  1801. static bool intel_ddi_compute_config(struct intel_encoder *encoder,
  1802. struct intel_crtc_state *pipe_config,
  1803. struct drm_connector_state *conn_state)
  1804. {
  1805. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1806. int type = encoder->type;
  1807. int port = intel_ddi_get_encoder_port(encoder);
  1808. int ret;
  1809. WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
  1810. if (port == PORT_A)
  1811. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  1812. if (type == INTEL_OUTPUT_HDMI)
  1813. ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
  1814. else
  1815. ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
  1816. if (IS_GEN9_LP(dev_priv) && ret)
  1817. pipe_config->lane_lat_optim_mask =
  1818. bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
  1819. pipe_config->lane_count);
  1820. return ret;
  1821. }
  1822. static const struct drm_encoder_funcs intel_ddi_funcs = {
  1823. .reset = intel_dp_encoder_reset,
  1824. .destroy = intel_dp_encoder_destroy,
  1825. };
  1826. static struct intel_connector *
  1827. intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
  1828. {
  1829. struct intel_connector *connector;
  1830. enum port port = intel_dig_port->port;
  1831. connector = intel_connector_alloc();
  1832. if (!connector)
  1833. return NULL;
  1834. intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
  1835. if (!intel_dp_init_connector(intel_dig_port, connector)) {
  1836. kfree(connector);
  1837. return NULL;
  1838. }
  1839. return connector;
  1840. }
  1841. static struct intel_connector *
  1842. intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
  1843. {
  1844. struct intel_connector *connector;
  1845. enum port port = intel_dig_port->port;
  1846. connector = intel_connector_alloc();
  1847. if (!connector)
  1848. return NULL;
  1849. intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
  1850. intel_hdmi_init_connector(intel_dig_port, connector);
  1851. return connector;
  1852. }
  1853. void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
  1854. {
  1855. struct intel_digital_port *intel_dig_port;
  1856. struct intel_encoder *intel_encoder;
  1857. struct drm_encoder *encoder;
  1858. bool init_hdmi, init_dp, init_lspcon = false;
  1859. int max_lanes;
  1860. if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
  1861. switch (port) {
  1862. case PORT_A:
  1863. max_lanes = 4;
  1864. break;
  1865. case PORT_E:
  1866. max_lanes = 0;
  1867. break;
  1868. default:
  1869. max_lanes = 4;
  1870. break;
  1871. }
  1872. } else {
  1873. switch (port) {
  1874. case PORT_A:
  1875. max_lanes = 2;
  1876. break;
  1877. case PORT_E:
  1878. max_lanes = 2;
  1879. break;
  1880. default:
  1881. max_lanes = 4;
  1882. break;
  1883. }
  1884. }
  1885. init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
  1886. dev_priv->vbt.ddi_port_info[port].supports_hdmi);
  1887. init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
  1888. if (intel_bios_is_lspcon_present(dev_priv, port)) {
  1889. /*
  1890. * Lspcon device needs to be driven with DP connector
  1891. * with special detection sequence. So make sure DP
  1892. * is initialized before lspcon.
  1893. */
  1894. init_dp = true;
  1895. init_lspcon = true;
  1896. init_hdmi = false;
  1897. DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
  1898. }
  1899. if (!init_dp && !init_hdmi) {
  1900. DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
  1901. port_name(port));
  1902. return;
  1903. }
  1904. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  1905. if (!intel_dig_port)
  1906. return;
  1907. intel_encoder = &intel_dig_port->base;
  1908. encoder = &intel_encoder->base;
  1909. drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
  1910. DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
  1911. intel_encoder->compute_config = intel_ddi_compute_config;
  1912. intel_encoder->enable = intel_enable_ddi;
  1913. if (IS_GEN9_LP(dev_priv))
  1914. intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
  1915. intel_encoder->pre_enable = intel_ddi_pre_enable;
  1916. intel_encoder->disable = intel_disable_ddi;
  1917. intel_encoder->post_disable = intel_ddi_post_disable;
  1918. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  1919. intel_encoder->get_config = intel_ddi_get_config;
  1920. intel_encoder->suspend = intel_dp_encoder_suspend;
  1921. intel_encoder->get_power_domains = intel_ddi_get_power_domains;
  1922. intel_dig_port->port = port;
  1923. intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
  1924. (DDI_BUF_PORT_REVERSAL |
  1925. DDI_A_4_LANES);
  1926. switch (port) {
  1927. case PORT_A:
  1928. intel_dig_port->ddi_io_power_domain =
  1929. POWER_DOMAIN_PORT_DDI_A_IO;
  1930. break;
  1931. case PORT_B:
  1932. intel_dig_port->ddi_io_power_domain =
  1933. POWER_DOMAIN_PORT_DDI_B_IO;
  1934. break;
  1935. case PORT_C:
  1936. intel_dig_port->ddi_io_power_domain =
  1937. POWER_DOMAIN_PORT_DDI_C_IO;
  1938. break;
  1939. case PORT_D:
  1940. intel_dig_port->ddi_io_power_domain =
  1941. POWER_DOMAIN_PORT_DDI_D_IO;
  1942. break;
  1943. case PORT_E:
  1944. intel_dig_port->ddi_io_power_domain =
  1945. POWER_DOMAIN_PORT_DDI_E_IO;
  1946. break;
  1947. default:
  1948. MISSING_CASE(port);
  1949. }
  1950. /*
  1951. * Bspec says that DDI_A_4_LANES is the only supported configuration
  1952. * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
  1953. * wasn't lit up at boot. Force this bit on in our internal
  1954. * configuration so that we use the proper lane count for our
  1955. * calculations.
  1956. */
  1957. if (IS_GEN9_LP(dev_priv) && port == PORT_A) {
  1958. if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
  1959. DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
  1960. intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
  1961. max_lanes = 4;
  1962. }
  1963. }
  1964. intel_dig_port->max_lanes = max_lanes;
  1965. intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
  1966. intel_encoder->power_domain = intel_port_to_power_domain(port);
  1967. intel_encoder->port = port;
  1968. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1969. intel_encoder->cloneable = 0;
  1970. if (init_dp) {
  1971. if (!intel_ddi_init_dp_connector(intel_dig_port))
  1972. goto err;
  1973. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  1974. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  1975. }
  1976. /* In theory we don't need the encoder->type check, but leave it just in
  1977. * case we have some really bad VBTs... */
  1978. if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
  1979. if (!intel_ddi_init_hdmi_connector(intel_dig_port))
  1980. goto err;
  1981. }
  1982. if (init_lspcon) {
  1983. if (lspcon_init(intel_dig_port))
  1984. /* TODO: handle hdmi info frame part */
  1985. DRM_DEBUG_KMS("LSPCON init success on port %c\n",
  1986. port_name(port));
  1987. else
  1988. /*
  1989. * LSPCON init faied, but DP init was success, so
  1990. * lets try to drive as DP++ port.
  1991. */
  1992. DRM_ERROR("LSPCON init failed on port %c\n",
  1993. port_name(port));
  1994. }
  1995. return;
  1996. err:
  1997. drm_encoder_cleanup(encoder);
  1998. kfree(intel_dig_port);
  1999. }