intel_ddi.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280
  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. static 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. static 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. /* Finds the only possible encoder associated with the given CRTC. */
  752. struct intel_encoder *
  753. intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
  754. {
  755. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  756. struct intel_encoder *ret = NULL;
  757. struct drm_atomic_state *state;
  758. struct drm_connector *connector;
  759. struct drm_connector_state *connector_state;
  760. int num_encoders = 0;
  761. int i;
  762. state = crtc_state->base.state;
  763. for_each_new_connector_in_state(state, connector, connector_state, i) {
  764. if (connector_state->crtc != crtc_state->base.crtc)
  765. continue;
  766. ret = to_intel_encoder(connector_state->best_encoder);
  767. num_encoders++;
  768. }
  769. WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
  770. pipe_name(crtc->pipe));
  771. BUG_ON(ret == NULL);
  772. return ret;
  773. }
  774. #define LC_FREQ 2700
  775. static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
  776. i915_reg_t reg)
  777. {
  778. int refclk = LC_FREQ;
  779. int n, p, r;
  780. u32 wrpll;
  781. wrpll = I915_READ(reg);
  782. switch (wrpll & WRPLL_PLL_REF_MASK) {
  783. case WRPLL_PLL_SSC:
  784. case WRPLL_PLL_NON_SSC:
  785. /*
  786. * We could calculate spread here, but our checking
  787. * code only cares about 5% accuracy, and spread is a max of
  788. * 0.5% downspread.
  789. */
  790. refclk = 135;
  791. break;
  792. case WRPLL_PLL_LCPLL:
  793. refclk = LC_FREQ;
  794. break;
  795. default:
  796. WARN(1, "bad wrpll refclk\n");
  797. return 0;
  798. }
  799. r = wrpll & WRPLL_DIVIDER_REF_MASK;
  800. p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
  801. n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
  802. /* Convert to KHz, p & r have a fixed point portion */
  803. return (refclk * n * 100) / (p * r);
  804. }
  805. static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
  806. uint32_t dpll)
  807. {
  808. i915_reg_t cfgcr1_reg, cfgcr2_reg;
  809. uint32_t cfgcr1_val, cfgcr2_val;
  810. uint32_t p0, p1, p2, dco_freq;
  811. cfgcr1_reg = DPLL_CFGCR1(dpll);
  812. cfgcr2_reg = DPLL_CFGCR2(dpll);
  813. cfgcr1_val = I915_READ(cfgcr1_reg);
  814. cfgcr2_val = I915_READ(cfgcr2_reg);
  815. p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
  816. p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
  817. if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
  818. p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
  819. else
  820. p1 = 1;
  821. switch (p0) {
  822. case DPLL_CFGCR2_PDIV_1:
  823. p0 = 1;
  824. break;
  825. case DPLL_CFGCR2_PDIV_2:
  826. p0 = 2;
  827. break;
  828. case DPLL_CFGCR2_PDIV_3:
  829. p0 = 3;
  830. break;
  831. case DPLL_CFGCR2_PDIV_7:
  832. p0 = 7;
  833. break;
  834. }
  835. switch (p2) {
  836. case DPLL_CFGCR2_KDIV_5:
  837. p2 = 5;
  838. break;
  839. case DPLL_CFGCR2_KDIV_2:
  840. p2 = 2;
  841. break;
  842. case DPLL_CFGCR2_KDIV_3:
  843. p2 = 3;
  844. break;
  845. case DPLL_CFGCR2_KDIV_1:
  846. p2 = 1;
  847. break;
  848. }
  849. dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
  850. dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
  851. 1000) / 0x8000;
  852. return dco_freq / (p0 * p1 * p2 * 5);
  853. }
  854. static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
  855. {
  856. int dotclock;
  857. if (pipe_config->has_pch_encoder)
  858. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  859. &pipe_config->fdi_m_n);
  860. else if (intel_crtc_has_dp_encoder(pipe_config))
  861. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  862. &pipe_config->dp_m_n);
  863. else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
  864. dotclock = pipe_config->port_clock * 2 / 3;
  865. else
  866. dotclock = pipe_config->port_clock;
  867. if (pipe_config->pixel_multiplier)
  868. dotclock /= pipe_config->pixel_multiplier;
  869. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  870. }
  871. static void skl_ddi_clock_get(struct intel_encoder *encoder,
  872. struct intel_crtc_state *pipe_config)
  873. {
  874. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  875. int link_clock = 0;
  876. uint32_t dpll_ctl1, dpll;
  877. dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
  878. dpll_ctl1 = I915_READ(DPLL_CTRL1);
  879. if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
  880. link_clock = skl_calc_wrpll_link(dev_priv, dpll);
  881. } else {
  882. link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
  883. link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
  884. switch (link_clock) {
  885. case DPLL_CTRL1_LINK_RATE_810:
  886. link_clock = 81000;
  887. break;
  888. case DPLL_CTRL1_LINK_RATE_1080:
  889. link_clock = 108000;
  890. break;
  891. case DPLL_CTRL1_LINK_RATE_1350:
  892. link_clock = 135000;
  893. break;
  894. case DPLL_CTRL1_LINK_RATE_1620:
  895. link_clock = 162000;
  896. break;
  897. case DPLL_CTRL1_LINK_RATE_2160:
  898. link_clock = 216000;
  899. break;
  900. case DPLL_CTRL1_LINK_RATE_2700:
  901. link_clock = 270000;
  902. break;
  903. default:
  904. WARN(1, "Unsupported link rate\n");
  905. break;
  906. }
  907. link_clock *= 2;
  908. }
  909. pipe_config->port_clock = link_clock;
  910. ddi_dotclock_get(pipe_config);
  911. }
  912. static void hsw_ddi_clock_get(struct intel_encoder *encoder,
  913. struct intel_crtc_state *pipe_config)
  914. {
  915. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  916. int link_clock = 0;
  917. u32 val, pll;
  918. val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
  919. switch (val & PORT_CLK_SEL_MASK) {
  920. case PORT_CLK_SEL_LCPLL_810:
  921. link_clock = 81000;
  922. break;
  923. case PORT_CLK_SEL_LCPLL_1350:
  924. link_clock = 135000;
  925. break;
  926. case PORT_CLK_SEL_LCPLL_2700:
  927. link_clock = 270000;
  928. break;
  929. case PORT_CLK_SEL_WRPLL1:
  930. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
  931. break;
  932. case PORT_CLK_SEL_WRPLL2:
  933. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
  934. break;
  935. case PORT_CLK_SEL_SPLL:
  936. pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
  937. if (pll == SPLL_PLL_FREQ_810MHz)
  938. link_clock = 81000;
  939. else if (pll == SPLL_PLL_FREQ_1350MHz)
  940. link_clock = 135000;
  941. else if (pll == SPLL_PLL_FREQ_2700MHz)
  942. link_clock = 270000;
  943. else {
  944. WARN(1, "bad spll freq\n");
  945. return;
  946. }
  947. break;
  948. default:
  949. WARN(1, "bad port clock sel\n");
  950. return;
  951. }
  952. pipe_config->port_clock = link_clock * 2;
  953. ddi_dotclock_get(pipe_config);
  954. }
  955. static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
  956. enum intel_dpll_id dpll)
  957. {
  958. struct intel_shared_dpll *pll;
  959. struct intel_dpll_hw_state *state;
  960. struct dpll clock;
  961. /* For DDI ports we always use a shared PLL. */
  962. if (WARN_ON(dpll == DPLL_ID_PRIVATE))
  963. return 0;
  964. pll = &dev_priv->shared_dplls[dpll];
  965. state = &pll->state.hw_state;
  966. clock.m1 = 2;
  967. clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
  968. if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
  969. clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
  970. clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
  971. clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
  972. clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
  973. return chv_calc_dpll_params(100000, &clock);
  974. }
  975. static void bxt_ddi_clock_get(struct intel_encoder *encoder,
  976. struct intel_crtc_state *pipe_config)
  977. {
  978. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  979. enum port port = intel_ddi_get_encoder_port(encoder);
  980. uint32_t dpll = port;
  981. pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
  982. ddi_dotclock_get(pipe_config);
  983. }
  984. void intel_ddi_clock_get(struct intel_encoder *encoder,
  985. struct intel_crtc_state *pipe_config)
  986. {
  987. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  988. if (INTEL_GEN(dev_priv) <= 8)
  989. hsw_ddi_clock_get(encoder, pipe_config);
  990. else if (IS_GEN9_BC(dev_priv))
  991. skl_ddi_clock_get(encoder, pipe_config);
  992. else if (IS_GEN9_LP(dev_priv))
  993. bxt_ddi_clock_get(encoder, pipe_config);
  994. }
  995. void intel_ddi_set_pipe_settings(const struct intel_crtc_state *crtc_state)
  996. {
  997. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  998. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  999. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1000. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1001. int type = encoder->type;
  1002. uint32_t temp;
  1003. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
  1004. WARN_ON(transcoder_is_dsi(cpu_transcoder));
  1005. temp = TRANS_MSA_SYNC_CLK;
  1006. switch (crtc_state->pipe_bpp) {
  1007. case 18:
  1008. temp |= TRANS_MSA_6_BPC;
  1009. break;
  1010. case 24:
  1011. temp |= TRANS_MSA_8_BPC;
  1012. break;
  1013. case 30:
  1014. temp |= TRANS_MSA_10_BPC;
  1015. break;
  1016. case 36:
  1017. temp |= TRANS_MSA_12_BPC;
  1018. break;
  1019. default:
  1020. BUG();
  1021. }
  1022. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  1023. }
  1024. }
  1025. void intel_ddi_set_vc_payload_alloc(const struct intel_crtc_state *crtc_state,
  1026. bool state)
  1027. {
  1028. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1029. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1030. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1031. uint32_t temp;
  1032. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1033. if (state == true)
  1034. temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1035. else
  1036. temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1037. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1038. }
  1039. void intel_ddi_enable_transcoder_func(const struct intel_crtc_state *crtc_state)
  1040. {
  1041. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1042. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1043. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1044. enum pipe pipe = crtc->pipe;
  1045. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1046. enum port port = intel_ddi_get_encoder_port(encoder);
  1047. int type = encoder->type;
  1048. uint32_t temp;
  1049. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  1050. temp = TRANS_DDI_FUNC_ENABLE;
  1051. temp |= TRANS_DDI_SELECT_PORT(port);
  1052. switch (crtc_state->pipe_bpp) {
  1053. case 18:
  1054. temp |= TRANS_DDI_BPC_6;
  1055. break;
  1056. case 24:
  1057. temp |= TRANS_DDI_BPC_8;
  1058. break;
  1059. case 30:
  1060. temp |= TRANS_DDI_BPC_10;
  1061. break;
  1062. case 36:
  1063. temp |= TRANS_DDI_BPC_12;
  1064. break;
  1065. default:
  1066. BUG();
  1067. }
  1068. if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
  1069. temp |= TRANS_DDI_PVSYNC;
  1070. if (crtc_state->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
  1071. temp |= TRANS_DDI_PHSYNC;
  1072. if (cpu_transcoder == TRANSCODER_EDP) {
  1073. switch (pipe) {
  1074. case PIPE_A:
  1075. /* On Haswell, can only use the always-on power well for
  1076. * eDP when not using the panel fitter, and when not
  1077. * using motion blur mitigation (which we don't
  1078. * support). */
  1079. if (IS_HASWELL(dev_priv) &&
  1080. (crtc_state->pch_pfit.enabled ||
  1081. crtc_state->pch_pfit.force_thru))
  1082. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  1083. else
  1084. temp |= TRANS_DDI_EDP_INPUT_A_ON;
  1085. break;
  1086. case PIPE_B:
  1087. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  1088. break;
  1089. case PIPE_C:
  1090. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  1091. break;
  1092. default:
  1093. BUG();
  1094. break;
  1095. }
  1096. }
  1097. if (type == INTEL_OUTPUT_HDMI) {
  1098. if (crtc_state->has_hdmi_sink)
  1099. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  1100. else
  1101. temp |= TRANS_DDI_MODE_SELECT_DVI;
  1102. if (crtc_state->hdmi_scrambling)
  1103. temp |= TRANS_DDI_HDMI_SCRAMBLING_MASK;
  1104. if (crtc_state->hdmi_high_tmds_clock_ratio)
  1105. temp |= TRANS_DDI_HIGH_TMDS_CHAR_RATE;
  1106. } else if (type == INTEL_OUTPUT_ANALOG) {
  1107. temp |= TRANS_DDI_MODE_SELECT_FDI;
  1108. temp |= (crtc_state->fdi_lanes - 1) << 1;
  1109. } else if (type == INTEL_OUTPUT_DP ||
  1110. type == INTEL_OUTPUT_EDP) {
  1111. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  1112. temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
  1113. } else if (type == INTEL_OUTPUT_DP_MST) {
  1114. temp |= TRANS_DDI_MODE_SELECT_DP_MST;
  1115. temp |= DDI_PORT_WIDTH(crtc_state->lane_count);
  1116. } else {
  1117. WARN(1, "Invalid encoder type %d for pipe %c\n",
  1118. encoder->type, pipe_name(pipe));
  1119. }
  1120. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1121. }
  1122. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  1123. enum transcoder cpu_transcoder)
  1124. {
  1125. i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1126. uint32_t val = I915_READ(reg);
  1127. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
  1128. val |= TRANS_DDI_PORT_NONE;
  1129. I915_WRITE(reg, val);
  1130. }
  1131. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  1132. {
  1133. struct drm_device *dev = intel_connector->base.dev;
  1134. struct drm_i915_private *dev_priv = to_i915(dev);
  1135. struct intel_encoder *encoder = intel_connector->encoder;
  1136. int type = intel_connector->base.connector_type;
  1137. enum port port = intel_ddi_get_encoder_port(encoder);
  1138. enum pipe pipe = 0;
  1139. enum transcoder cpu_transcoder;
  1140. uint32_t tmp;
  1141. bool ret;
  1142. if (!intel_display_power_get_if_enabled(dev_priv,
  1143. encoder->power_domain))
  1144. return false;
  1145. if (!encoder->get_hw_state(encoder, &pipe)) {
  1146. ret = false;
  1147. goto out;
  1148. }
  1149. if (port == PORT_A)
  1150. cpu_transcoder = TRANSCODER_EDP;
  1151. else
  1152. cpu_transcoder = (enum transcoder) pipe;
  1153. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1154. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  1155. case TRANS_DDI_MODE_SELECT_HDMI:
  1156. case TRANS_DDI_MODE_SELECT_DVI:
  1157. ret = type == DRM_MODE_CONNECTOR_HDMIA;
  1158. break;
  1159. case TRANS_DDI_MODE_SELECT_DP_SST:
  1160. ret = type == DRM_MODE_CONNECTOR_eDP ||
  1161. type == DRM_MODE_CONNECTOR_DisplayPort;
  1162. break;
  1163. case TRANS_DDI_MODE_SELECT_DP_MST:
  1164. /* if the transcoder is in MST state then
  1165. * connector isn't connected */
  1166. ret = false;
  1167. break;
  1168. case TRANS_DDI_MODE_SELECT_FDI:
  1169. ret = type == DRM_MODE_CONNECTOR_VGA;
  1170. break;
  1171. default:
  1172. ret = false;
  1173. break;
  1174. }
  1175. out:
  1176. intel_display_power_put(dev_priv, encoder->power_domain);
  1177. return ret;
  1178. }
  1179. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  1180. enum pipe *pipe)
  1181. {
  1182. struct drm_device *dev = encoder->base.dev;
  1183. struct drm_i915_private *dev_priv = to_i915(dev);
  1184. enum port port = intel_ddi_get_encoder_port(encoder);
  1185. u32 tmp;
  1186. int i;
  1187. bool ret;
  1188. if (!intel_display_power_get_if_enabled(dev_priv,
  1189. encoder->power_domain))
  1190. return false;
  1191. ret = false;
  1192. tmp = I915_READ(DDI_BUF_CTL(port));
  1193. if (!(tmp & DDI_BUF_CTL_ENABLE))
  1194. goto out;
  1195. if (port == PORT_A) {
  1196. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  1197. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  1198. case TRANS_DDI_EDP_INPUT_A_ON:
  1199. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  1200. *pipe = PIPE_A;
  1201. break;
  1202. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  1203. *pipe = PIPE_B;
  1204. break;
  1205. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  1206. *pipe = PIPE_C;
  1207. break;
  1208. }
  1209. ret = true;
  1210. goto out;
  1211. }
  1212. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  1213. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  1214. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
  1215. if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
  1216. TRANS_DDI_MODE_SELECT_DP_MST)
  1217. goto out;
  1218. *pipe = i;
  1219. ret = true;
  1220. goto out;
  1221. }
  1222. }
  1223. DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
  1224. out:
  1225. if (ret && IS_GEN9_LP(dev_priv)) {
  1226. tmp = I915_READ(BXT_PHY_CTL(port));
  1227. if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK |
  1228. BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
  1229. DRM_ERROR("Port %c enabled but PHY powered down? "
  1230. "(PHY_CTL %08x)\n", port_name(port), tmp);
  1231. }
  1232. intel_display_power_put(dev_priv, encoder->power_domain);
  1233. return ret;
  1234. }
  1235. static u64 intel_ddi_get_power_domains(struct intel_encoder *encoder)
  1236. {
  1237. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1238. enum pipe pipe;
  1239. if (intel_ddi_get_hw_state(encoder, &pipe))
  1240. return BIT_ULL(dig_port->ddi_io_power_domain);
  1241. return 0;
  1242. }
  1243. void intel_ddi_enable_pipe_clock(const struct intel_crtc_state *crtc_state)
  1244. {
  1245. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  1246. struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
  1247. struct intel_encoder *encoder = intel_ddi_get_crtc_encoder(crtc);
  1248. enum port port = intel_ddi_get_encoder_port(encoder);
  1249. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1250. if (cpu_transcoder != TRANSCODER_EDP)
  1251. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1252. TRANS_CLK_SEL_PORT(port));
  1253. }
  1254. void intel_ddi_disable_pipe_clock(const struct intel_crtc_state *crtc_state)
  1255. {
  1256. struct drm_i915_private *dev_priv = to_i915(crtc_state->base.crtc->dev);
  1257. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  1258. if (cpu_transcoder != TRANSCODER_EDP)
  1259. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1260. TRANS_CLK_SEL_DISABLED);
  1261. }
  1262. static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
  1263. enum port port, uint8_t iboost)
  1264. {
  1265. u32 tmp;
  1266. tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
  1267. tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
  1268. if (iboost)
  1269. tmp |= iboost << BALANCE_LEG_SHIFT(port);
  1270. else
  1271. tmp |= BALANCE_LEG_DISABLE(port);
  1272. I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
  1273. }
  1274. static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
  1275. {
  1276. struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
  1277. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  1278. enum port port = intel_dig_port->port;
  1279. int type = encoder->type;
  1280. const struct ddi_buf_trans *ddi_translations;
  1281. uint8_t iboost;
  1282. uint8_t dp_iboost, hdmi_iboost;
  1283. int n_entries;
  1284. /* VBT may override standard boost values */
  1285. dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
  1286. hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
  1287. if (type == INTEL_OUTPUT_DP) {
  1288. if (dp_iboost) {
  1289. iboost = dp_iboost;
  1290. } else {
  1291. if (IS_KABYLAKE(dev_priv))
  1292. ddi_translations = kbl_get_buf_trans_dp(dev_priv,
  1293. &n_entries);
  1294. else
  1295. ddi_translations = skl_get_buf_trans_dp(dev_priv,
  1296. &n_entries);
  1297. iboost = ddi_translations[level].i_boost;
  1298. }
  1299. } else if (type == INTEL_OUTPUT_EDP) {
  1300. if (dp_iboost) {
  1301. iboost = dp_iboost;
  1302. } else {
  1303. ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
  1304. if (WARN_ON(port != PORT_A &&
  1305. port != PORT_E && n_entries > 9))
  1306. n_entries = 9;
  1307. iboost = ddi_translations[level].i_boost;
  1308. }
  1309. } else if (type == INTEL_OUTPUT_HDMI) {
  1310. if (hdmi_iboost) {
  1311. iboost = hdmi_iboost;
  1312. } else {
  1313. ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
  1314. iboost = ddi_translations[level].i_boost;
  1315. }
  1316. } else {
  1317. return;
  1318. }
  1319. /* Make sure that the requested I_boost is valid */
  1320. if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
  1321. DRM_ERROR("Invalid I_boost value %u\n", iboost);
  1322. return;
  1323. }
  1324. _skl_ddi_set_iboost(dev_priv, port, iboost);
  1325. if (port == PORT_A && intel_dig_port->max_lanes == 4)
  1326. _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
  1327. }
  1328. static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
  1329. u32 level, enum port port, int type)
  1330. {
  1331. const struct bxt_ddi_buf_trans *ddi_translations;
  1332. u32 n_entries, i;
  1333. if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
  1334. n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
  1335. ddi_translations = bxt_ddi_translations_edp;
  1336. } else if (type == INTEL_OUTPUT_DP
  1337. || type == INTEL_OUTPUT_EDP) {
  1338. n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
  1339. ddi_translations = bxt_ddi_translations_dp;
  1340. } else if (type == INTEL_OUTPUT_HDMI) {
  1341. n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
  1342. ddi_translations = bxt_ddi_translations_hdmi;
  1343. } else {
  1344. DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
  1345. type);
  1346. return;
  1347. }
  1348. /* Check if default value has to be used */
  1349. if (level >= n_entries ||
  1350. (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
  1351. for (i = 0; i < n_entries; i++) {
  1352. if (ddi_translations[i].default_index) {
  1353. level = i;
  1354. break;
  1355. }
  1356. }
  1357. }
  1358. bxt_ddi_phy_set_signal_level(dev_priv, port,
  1359. ddi_translations[level].margin,
  1360. ddi_translations[level].scale,
  1361. ddi_translations[level].enable,
  1362. ddi_translations[level].deemphasis);
  1363. }
  1364. u8 intel_ddi_dp_voltage_max(struct intel_encoder *encoder)
  1365. {
  1366. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1367. int n_entries;
  1368. if (encoder->type == INTEL_OUTPUT_EDP)
  1369. intel_ddi_get_buf_trans_edp(dev_priv, &n_entries);
  1370. else
  1371. intel_ddi_get_buf_trans_dp(dev_priv, &n_entries);
  1372. if (WARN_ON(n_entries < 1))
  1373. n_entries = 1;
  1374. if (WARN_ON(n_entries > ARRAY_SIZE(index_to_dp_signal_levels)))
  1375. n_entries = ARRAY_SIZE(index_to_dp_signal_levels);
  1376. return index_to_dp_signal_levels[n_entries - 1] &
  1377. DP_TRAIN_VOLTAGE_SWING_MASK;
  1378. }
  1379. static uint32_t translate_signal_level(int signal_levels)
  1380. {
  1381. int i;
  1382. for (i = 0; i < ARRAY_SIZE(index_to_dp_signal_levels); i++) {
  1383. if (index_to_dp_signal_levels[i] == signal_levels)
  1384. return i;
  1385. }
  1386. WARN(1, "Unsupported voltage swing/pre-emphasis level: 0x%x\n",
  1387. signal_levels);
  1388. return 0;
  1389. }
  1390. uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
  1391. {
  1392. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1393. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  1394. struct intel_encoder *encoder = &dport->base;
  1395. uint8_t train_set = intel_dp->train_set[0];
  1396. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1397. DP_TRAIN_PRE_EMPHASIS_MASK);
  1398. enum port port = dport->port;
  1399. uint32_t level;
  1400. level = translate_signal_level(signal_levels);
  1401. if (IS_GEN9_BC(dev_priv))
  1402. skl_ddi_set_iboost(encoder, level);
  1403. else if (IS_GEN9_LP(dev_priv))
  1404. bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
  1405. return DDI_BUF_TRANS_SELECT(level);
  1406. }
  1407. static void intel_ddi_clk_select(struct intel_encoder *encoder,
  1408. struct intel_shared_dpll *pll)
  1409. {
  1410. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1411. enum port port = intel_ddi_get_encoder_port(encoder);
  1412. if (WARN_ON(!pll))
  1413. return;
  1414. if (IS_GEN9_BC(dev_priv)) {
  1415. uint32_t val;
  1416. /* DDI -> PLL mapping */
  1417. val = I915_READ(DPLL_CTRL2);
  1418. val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
  1419. DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
  1420. val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
  1421. DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
  1422. I915_WRITE(DPLL_CTRL2, val);
  1423. } else if (INTEL_INFO(dev_priv)->gen < 9) {
  1424. I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
  1425. }
  1426. }
  1427. static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
  1428. int link_rate, uint32_t lane_count,
  1429. struct intel_shared_dpll *pll,
  1430. bool link_mst)
  1431. {
  1432. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1433. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1434. enum port port = intel_ddi_get_encoder_port(encoder);
  1435. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1436. WARN_ON(link_mst && (port == PORT_A || port == PORT_E));
  1437. intel_dp_set_link_params(intel_dp, link_rate, lane_count,
  1438. link_mst);
  1439. if (encoder->type == INTEL_OUTPUT_EDP)
  1440. intel_edp_panel_on(intel_dp);
  1441. intel_ddi_clk_select(encoder, pll);
  1442. intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
  1443. intel_prepare_dp_ddi_buffers(encoder);
  1444. intel_ddi_init_dp_buf_reg(encoder);
  1445. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1446. intel_dp_start_link_train(intel_dp);
  1447. if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
  1448. intel_dp_stop_link_train(intel_dp);
  1449. }
  1450. static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
  1451. bool has_hdmi_sink,
  1452. const struct intel_crtc_state *crtc_state,
  1453. const struct drm_connector_state *conn_state,
  1454. struct intel_shared_dpll *pll)
  1455. {
  1456. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1457. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1458. struct drm_encoder *drm_encoder = &encoder->base;
  1459. enum port port = intel_ddi_get_encoder_port(encoder);
  1460. int level = intel_ddi_hdmi_level(dev_priv, port);
  1461. struct intel_digital_port *dig_port = enc_to_dig_port(&encoder->base);
  1462. intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
  1463. intel_ddi_clk_select(encoder, pll);
  1464. intel_display_power_get(dev_priv, dig_port->ddi_io_power_domain);
  1465. intel_prepare_hdmi_ddi_buffers(encoder);
  1466. if (IS_GEN9_BC(dev_priv))
  1467. skl_ddi_set_iboost(encoder, level);
  1468. else if (IS_GEN9_LP(dev_priv))
  1469. bxt_ddi_vswing_sequence(dev_priv, level, port,
  1470. INTEL_OUTPUT_HDMI);
  1471. intel_hdmi->set_infoframes(drm_encoder,
  1472. has_hdmi_sink,
  1473. crtc_state, conn_state);
  1474. }
  1475. static void intel_ddi_pre_enable(struct intel_encoder *encoder,
  1476. struct intel_crtc_state *pipe_config,
  1477. struct drm_connector_state *conn_state)
  1478. {
  1479. int type = encoder->type;
  1480. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1481. intel_ddi_pre_enable_dp(encoder,
  1482. pipe_config->port_clock,
  1483. pipe_config->lane_count,
  1484. pipe_config->shared_dpll,
  1485. intel_crtc_has_type(pipe_config,
  1486. INTEL_OUTPUT_DP_MST));
  1487. }
  1488. if (type == INTEL_OUTPUT_HDMI) {
  1489. intel_ddi_pre_enable_hdmi(encoder,
  1490. pipe_config->has_hdmi_sink,
  1491. pipe_config, conn_state,
  1492. pipe_config->shared_dpll);
  1493. }
  1494. }
  1495. static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
  1496. struct intel_crtc_state *old_crtc_state,
  1497. struct drm_connector_state *old_conn_state)
  1498. {
  1499. struct drm_encoder *encoder = &intel_encoder->base;
  1500. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  1501. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1502. struct intel_digital_port *dig_port = enc_to_dig_port(encoder);
  1503. int type = intel_encoder->type;
  1504. uint32_t val;
  1505. bool wait = false;
  1506. /* old_crtc_state and old_conn_state are NULL when called from DP_MST */
  1507. val = I915_READ(DDI_BUF_CTL(port));
  1508. if (val & DDI_BUF_CTL_ENABLE) {
  1509. val &= ~DDI_BUF_CTL_ENABLE;
  1510. I915_WRITE(DDI_BUF_CTL(port), val);
  1511. wait = true;
  1512. }
  1513. val = I915_READ(DP_TP_CTL(port));
  1514. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1515. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1516. I915_WRITE(DP_TP_CTL(port), val);
  1517. if (wait)
  1518. intel_wait_ddi_buf_idle(dev_priv, port);
  1519. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1520. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1521. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1522. intel_edp_panel_vdd_on(intel_dp);
  1523. intel_edp_panel_off(intel_dp);
  1524. }
  1525. if (dig_port)
  1526. intel_display_power_put(dev_priv, dig_port->ddi_io_power_domain);
  1527. if (IS_GEN9_BC(dev_priv))
  1528. I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
  1529. DPLL_CTRL2_DDI_CLK_OFF(port)));
  1530. else if (INTEL_GEN(dev_priv) < 9)
  1531. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1532. if (type == INTEL_OUTPUT_HDMI) {
  1533. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  1534. intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
  1535. }
  1536. }
  1537. void intel_ddi_fdi_post_disable(struct intel_encoder *encoder,
  1538. struct intel_crtc_state *old_crtc_state,
  1539. struct drm_connector_state *old_conn_state)
  1540. {
  1541. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1542. uint32_t val;
  1543. /*
  1544. * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
  1545. * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
  1546. * step 13 is the correct place for it. Step 18 is where it was
  1547. * originally before the BUN.
  1548. */
  1549. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1550. val &= ~FDI_RX_ENABLE;
  1551. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1552. intel_ddi_post_disable(encoder, old_crtc_state, old_conn_state);
  1553. val = I915_READ(FDI_RX_MISC(PIPE_A));
  1554. val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  1555. val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  1556. I915_WRITE(FDI_RX_MISC(PIPE_A), val);
  1557. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1558. val &= ~FDI_PCDCLK;
  1559. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1560. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1561. val &= ~FDI_RX_PLL_ENABLE;
  1562. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1563. }
  1564. static void intel_enable_ddi(struct intel_encoder *intel_encoder,
  1565. struct intel_crtc_state *pipe_config,
  1566. struct drm_connector_state *conn_state)
  1567. {
  1568. struct drm_encoder *encoder = &intel_encoder->base;
  1569. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  1570. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1571. int type = intel_encoder->type;
  1572. if (type == INTEL_OUTPUT_HDMI) {
  1573. struct intel_digital_port *intel_dig_port =
  1574. enc_to_dig_port(encoder);
  1575. bool clock_ratio = pipe_config->hdmi_high_tmds_clock_ratio;
  1576. bool scrambling = pipe_config->hdmi_scrambling;
  1577. intel_hdmi_handle_sink_scrambling(intel_encoder,
  1578. conn_state->connector,
  1579. clock_ratio, scrambling);
  1580. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  1581. * are ignored so nothing special needs to be done besides
  1582. * enabling the port.
  1583. */
  1584. I915_WRITE(DDI_BUF_CTL(port),
  1585. intel_dig_port->saved_port_bits |
  1586. DDI_BUF_CTL_ENABLE);
  1587. } else if (type == INTEL_OUTPUT_EDP) {
  1588. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1589. if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
  1590. intel_dp_stop_link_train(intel_dp);
  1591. intel_edp_backlight_on(intel_dp);
  1592. intel_psr_enable(intel_dp);
  1593. intel_edp_drrs_enable(intel_dp, pipe_config);
  1594. }
  1595. if (pipe_config->has_audio)
  1596. intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
  1597. }
  1598. static void intel_disable_ddi(struct intel_encoder *intel_encoder,
  1599. struct intel_crtc_state *old_crtc_state,
  1600. struct drm_connector_state *old_conn_state)
  1601. {
  1602. struct drm_encoder *encoder = &intel_encoder->base;
  1603. int type = intel_encoder->type;
  1604. if (old_crtc_state->has_audio)
  1605. intel_audio_codec_disable(intel_encoder);
  1606. if (type == INTEL_OUTPUT_HDMI) {
  1607. intel_hdmi_handle_sink_scrambling(intel_encoder,
  1608. old_conn_state->connector,
  1609. false, false);
  1610. }
  1611. if (type == INTEL_OUTPUT_EDP) {
  1612. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1613. intel_edp_drrs_disable(intel_dp, old_crtc_state);
  1614. intel_psr_disable(intel_dp);
  1615. intel_edp_backlight_off(intel_dp);
  1616. }
  1617. }
  1618. static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
  1619. struct intel_crtc_state *pipe_config,
  1620. struct drm_connector_state *conn_state)
  1621. {
  1622. uint8_t mask = pipe_config->lane_lat_optim_mask;
  1623. bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
  1624. }
  1625. void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
  1626. {
  1627. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1628. struct drm_i915_private *dev_priv =
  1629. to_i915(intel_dig_port->base.base.dev);
  1630. enum port port = intel_dig_port->port;
  1631. uint32_t val;
  1632. bool wait = false;
  1633. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  1634. val = I915_READ(DDI_BUF_CTL(port));
  1635. if (val & DDI_BUF_CTL_ENABLE) {
  1636. val &= ~DDI_BUF_CTL_ENABLE;
  1637. I915_WRITE(DDI_BUF_CTL(port), val);
  1638. wait = true;
  1639. }
  1640. val = I915_READ(DP_TP_CTL(port));
  1641. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1642. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1643. I915_WRITE(DP_TP_CTL(port), val);
  1644. POSTING_READ(DP_TP_CTL(port));
  1645. if (wait)
  1646. intel_wait_ddi_buf_idle(dev_priv, port);
  1647. }
  1648. val = DP_TP_CTL_ENABLE |
  1649. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  1650. if (intel_dp->link_mst)
  1651. val |= DP_TP_CTL_MODE_MST;
  1652. else {
  1653. val |= DP_TP_CTL_MODE_SST;
  1654. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1655. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  1656. }
  1657. I915_WRITE(DP_TP_CTL(port), val);
  1658. POSTING_READ(DP_TP_CTL(port));
  1659. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  1660. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  1661. POSTING_READ(DDI_BUF_CTL(port));
  1662. udelay(600);
  1663. }
  1664. bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
  1665. struct intel_crtc *intel_crtc)
  1666. {
  1667. u32 temp;
  1668. if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
  1669. temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1670. if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
  1671. return true;
  1672. }
  1673. return false;
  1674. }
  1675. void intel_ddi_get_config(struct intel_encoder *encoder,
  1676. struct intel_crtc_state *pipe_config)
  1677. {
  1678. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1679. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1680. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  1681. struct intel_hdmi *intel_hdmi;
  1682. u32 temp, flags = 0;
  1683. /* XXX: DSI transcoder paranoia */
  1684. if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
  1685. return;
  1686. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1687. if (temp & TRANS_DDI_PHSYNC)
  1688. flags |= DRM_MODE_FLAG_PHSYNC;
  1689. else
  1690. flags |= DRM_MODE_FLAG_NHSYNC;
  1691. if (temp & TRANS_DDI_PVSYNC)
  1692. flags |= DRM_MODE_FLAG_PVSYNC;
  1693. else
  1694. flags |= DRM_MODE_FLAG_NVSYNC;
  1695. pipe_config->base.adjusted_mode.flags |= flags;
  1696. switch (temp & TRANS_DDI_BPC_MASK) {
  1697. case TRANS_DDI_BPC_6:
  1698. pipe_config->pipe_bpp = 18;
  1699. break;
  1700. case TRANS_DDI_BPC_8:
  1701. pipe_config->pipe_bpp = 24;
  1702. break;
  1703. case TRANS_DDI_BPC_10:
  1704. pipe_config->pipe_bpp = 30;
  1705. break;
  1706. case TRANS_DDI_BPC_12:
  1707. pipe_config->pipe_bpp = 36;
  1708. break;
  1709. default:
  1710. break;
  1711. }
  1712. switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
  1713. case TRANS_DDI_MODE_SELECT_HDMI:
  1714. pipe_config->has_hdmi_sink = true;
  1715. intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1716. if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
  1717. pipe_config->has_infoframe = true;
  1718. if ((temp & TRANS_DDI_HDMI_SCRAMBLING_MASK) ==
  1719. TRANS_DDI_HDMI_SCRAMBLING_MASK)
  1720. pipe_config->hdmi_scrambling = true;
  1721. if (temp & TRANS_DDI_HIGH_TMDS_CHAR_RATE)
  1722. pipe_config->hdmi_high_tmds_clock_ratio = true;
  1723. /* fall through */
  1724. case TRANS_DDI_MODE_SELECT_DVI:
  1725. pipe_config->lane_count = 4;
  1726. break;
  1727. case TRANS_DDI_MODE_SELECT_FDI:
  1728. break;
  1729. case TRANS_DDI_MODE_SELECT_DP_SST:
  1730. case TRANS_DDI_MODE_SELECT_DP_MST:
  1731. pipe_config->lane_count =
  1732. ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
  1733. intel_dp_get_m_n(intel_crtc, pipe_config);
  1734. break;
  1735. default:
  1736. break;
  1737. }
  1738. pipe_config->has_audio =
  1739. intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
  1740. if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
  1741. pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
  1742. /*
  1743. * This is a big fat ugly hack.
  1744. *
  1745. * Some machines in UEFI boot mode provide us a VBT that has 18
  1746. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1747. * unknown we fail to light up. Yet the same BIOS boots up with
  1748. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1749. * max, not what it tells us to use.
  1750. *
  1751. * Note: This will still be broken if the eDP panel is not lit
  1752. * up by the BIOS, and thus we can't get the mode at module
  1753. * load.
  1754. */
  1755. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1756. pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
  1757. dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
  1758. }
  1759. intel_ddi_clock_get(encoder, pipe_config);
  1760. if (IS_GEN9_LP(dev_priv))
  1761. pipe_config->lane_lat_optim_mask =
  1762. bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
  1763. }
  1764. static bool intel_ddi_compute_config(struct intel_encoder *encoder,
  1765. struct intel_crtc_state *pipe_config,
  1766. struct drm_connector_state *conn_state)
  1767. {
  1768. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1769. int type = encoder->type;
  1770. int port = intel_ddi_get_encoder_port(encoder);
  1771. int ret;
  1772. WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
  1773. if (port == PORT_A)
  1774. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  1775. if (type == INTEL_OUTPUT_HDMI)
  1776. ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
  1777. else
  1778. ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
  1779. if (IS_GEN9_LP(dev_priv) && ret)
  1780. pipe_config->lane_lat_optim_mask =
  1781. bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
  1782. pipe_config->lane_count);
  1783. return ret;
  1784. }
  1785. static const struct drm_encoder_funcs intel_ddi_funcs = {
  1786. .reset = intel_dp_encoder_reset,
  1787. .destroy = intel_dp_encoder_destroy,
  1788. };
  1789. static struct intel_connector *
  1790. intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
  1791. {
  1792. struct intel_connector *connector;
  1793. enum port port = intel_dig_port->port;
  1794. connector = intel_connector_alloc();
  1795. if (!connector)
  1796. return NULL;
  1797. intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
  1798. if (!intel_dp_init_connector(intel_dig_port, connector)) {
  1799. kfree(connector);
  1800. return NULL;
  1801. }
  1802. return connector;
  1803. }
  1804. static struct intel_connector *
  1805. intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
  1806. {
  1807. struct intel_connector *connector;
  1808. enum port port = intel_dig_port->port;
  1809. connector = intel_connector_alloc();
  1810. if (!connector)
  1811. return NULL;
  1812. intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
  1813. intel_hdmi_init_connector(intel_dig_port, connector);
  1814. return connector;
  1815. }
  1816. void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
  1817. {
  1818. struct intel_digital_port *intel_dig_port;
  1819. struct intel_encoder *intel_encoder;
  1820. struct drm_encoder *encoder;
  1821. bool init_hdmi, init_dp, init_lspcon = false;
  1822. int max_lanes;
  1823. if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
  1824. switch (port) {
  1825. case PORT_A:
  1826. max_lanes = 4;
  1827. break;
  1828. case PORT_E:
  1829. max_lanes = 0;
  1830. break;
  1831. default:
  1832. max_lanes = 4;
  1833. break;
  1834. }
  1835. } else {
  1836. switch (port) {
  1837. case PORT_A:
  1838. max_lanes = 2;
  1839. break;
  1840. case PORT_E:
  1841. max_lanes = 2;
  1842. break;
  1843. default:
  1844. max_lanes = 4;
  1845. break;
  1846. }
  1847. }
  1848. init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
  1849. dev_priv->vbt.ddi_port_info[port].supports_hdmi);
  1850. init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
  1851. if (intel_bios_is_lspcon_present(dev_priv, port)) {
  1852. /*
  1853. * Lspcon device needs to be driven with DP connector
  1854. * with special detection sequence. So make sure DP
  1855. * is initialized before lspcon.
  1856. */
  1857. init_dp = true;
  1858. init_lspcon = true;
  1859. init_hdmi = false;
  1860. DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
  1861. }
  1862. if (!init_dp && !init_hdmi) {
  1863. DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
  1864. port_name(port));
  1865. return;
  1866. }
  1867. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  1868. if (!intel_dig_port)
  1869. return;
  1870. intel_encoder = &intel_dig_port->base;
  1871. encoder = &intel_encoder->base;
  1872. drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
  1873. DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
  1874. intel_encoder->compute_config = intel_ddi_compute_config;
  1875. intel_encoder->enable = intel_enable_ddi;
  1876. if (IS_GEN9_LP(dev_priv))
  1877. intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
  1878. intel_encoder->pre_enable = intel_ddi_pre_enable;
  1879. intel_encoder->disable = intel_disable_ddi;
  1880. intel_encoder->post_disable = intel_ddi_post_disable;
  1881. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  1882. intel_encoder->get_config = intel_ddi_get_config;
  1883. intel_encoder->suspend = intel_dp_encoder_suspend;
  1884. intel_encoder->get_power_domains = intel_ddi_get_power_domains;
  1885. intel_dig_port->port = port;
  1886. intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
  1887. (DDI_BUF_PORT_REVERSAL |
  1888. DDI_A_4_LANES);
  1889. switch (port) {
  1890. case PORT_A:
  1891. intel_dig_port->ddi_io_power_domain =
  1892. POWER_DOMAIN_PORT_DDI_A_IO;
  1893. break;
  1894. case PORT_B:
  1895. intel_dig_port->ddi_io_power_domain =
  1896. POWER_DOMAIN_PORT_DDI_B_IO;
  1897. break;
  1898. case PORT_C:
  1899. intel_dig_port->ddi_io_power_domain =
  1900. POWER_DOMAIN_PORT_DDI_C_IO;
  1901. break;
  1902. case PORT_D:
  1903. intel_dig_port->ddi_io_power_domain =
  1904. POWER_DOMAIN_PORT_DDI_D_IO;
  1905. break;
  1906. case PORT_E:
  1907. intel_dig_port->ddi_io_power_domain =
  1908. POWER_DOMAIN_PORT_DDI_E_IO;
  1909. break;
  1910. default:
  1911. MISSING_CASE(port);
  1912. }
  1913. /*
  1914. * Bspec says that DDI_A_4_LANES is the only supported configuration
  1915. * for Broxton. Yet some BIOS fail to set this bit on port A if eDP
  1916. * wasn't lit up at boot. Force this bit on in our internal
  1917. * configuration so that we use the proper lane count for our
  1918. * calculations.
  1919. */
  1920. if (IS_GEN9_LP(dev_priv) && port == PORT_A) {
  1921. if (!(intel_dig_port->saved_port_bits & DDI_A_4_LANES)) {
  1922. DRM_DEBUG_KMS("BXT BIOS forgot to set DDI_A_4_LANES for port A; fixing\n");
  1923. intel_dig_port->saved_port_bits |= DDI_A_4_LANES;
  1924. max_lanes = 4;
  1925. }
  1926. }
  1927. intel_dig_port->max_lanes = max_lanes;
  1928. intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
  1929. intel_encoder->power_domain = intel_port_to_power_domain(port);
  1930. intel_encoder->port = port;
  1931. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1932. intel_encoder->cloneable = 0;
  1933. if (init_dp) {
  1934. if (!intel_ddi_init_dp_connector(intel_dig_port))
  1935. goto err;
  1936. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  1937. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  1938. }
  1939. /* In theory we don't need the encoder->type check, but leave it just in
  1940. * case we have some really bad VBTs... */
  1941. if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
  1942. if (!intel_ddi_init_hdmi_connector(intel_dig_port))
  1943. goto err;
  1944. }
  1945. if (init_lspcon) {
  1946. if (lspcon_init(intel_dig_port))
  1947. /* TODO: handle hdmi info frame part */
  1948. DRM_DEBUG_KMS("LSPCON init success on port %c\n",
  1949. port_name(port));
  1950. else
  1951. /*
  1952. * LSPCON init faied, but DP init was success, so
  1953. * lets try to drive as DP++ port.
  1954. */
  1955. DRM_ERROR("LSPCON init failed on port %c\n",
  1956. port_name(port));
  1957. }
  1958. return;
  1959. err:
  1960. drm_encoder_cleanup(encoder);
  1961. kfree(intel_dig_port);
  1962. }