intel_ddi.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  1. /*
  2. * Copyright © 2012 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eugeni Dodonov <eugeni.dodonov@intel.com>
  25. *
  26. */
  27. #include "i915_drv.h"
  28. #include "intel_drv.h"
  29. struct ddi_buf_trans {
  30. u32 trans1; /* balance leg enable, de-emph level */
  31. u32 trans2; /* vref sel, vswing */
  32. u8 i_boost; /* SKL: I_boost; valid: 0x0, 0x1, 0x3, 0x7 */
  33. };
  34. /* HDMI/DVI modes ignore everything but the last 2 items. So we share
  35. * them for both DP and FDI transports, allowing those ports to
  36. * automatically adapt to HDMI connections as well
  37. */
  38. static const struct ddi_buf_trans hsw_ddi_translations_dp[] = {
  39. { 0x00FFFFFF, 0x0006000E, 0x0 },
  40. { 0x00D75FFF, 0x0005000A, 0x0 },
  41. { 0x00C30FFF, 0x00040006, 0x0 },
  42. { 0x80AAAFFF, 0x000B0000, 0x0 },
  43. { 0x00FFFFFF, 0x0005000A, 0x0 },
  44. { 0x00D75FFF, 0x000C0004, 0x0 },
  45. { 0x80C30FFF, 0x000B0000, 0x0 },
  46. { 0x00FFFFFF, 0x00040006, 0x0 },
  47. { 0x80D75FFF, 0x000B0000, 0x0 },
  48. };
  49. static const struct ddi_buf_trans hsw_ddi_translations_fdi[] = {
  50. { 0x00FFFFFF, 0x0007000E, 0x0 },
  51. { 0x00D75FFF, 0x000F000A, 0x0 },
  52. { 0x00C30FFF, 0x00060006, 0x0 },
  53. { 0x00AAAFFF, 0x001E0000, 0x0 },
  54. { 0x00FFFFFF, 0x000F000A, 0x0 },
  55. { 0x00D75FFF, 0x00160004, 0x0 },
  56. { 0x00C30FFF, 0x001E0000, 0x0 },
  57. { 0x00FFFFFF, 0x00060006, 0x0 },
  58. { 0x00D75FFF, 0x001E0000, 0x0 },
  59. };
  60. static const struct ddi_buf_trans hsw_ddi_translations_hdmi[] = {
  61. /* Idx NT mV d T mV d db */
  62. { 0x00FFFFFF, 0x0006000E, 0x0 },/* 0: 400 400 0 */
  63. { 0x00E79FFF, 0x000E000C, 0x0 },/* 1: 400 500 2 */
  64. { 0x00D75FFF, 0x0005000A, 0x0 },/* 2: 400 600 3.5 */
  65. { 0x00FFFFFF, 0x0005000A, 0x0 },/* 3: 600 600 0 */
  66. { 0x00E79FFF, 0x001D0007, 0x0 },/* 4: 600 750 2 */
  67. { 0x00D75FFF, 0x000C0004, 0x0 },/* 5: 600 900 3.5 */
  68. { 0x00FFFFFF, 0x00040006, 0x0 },/* 6: 800 800 0 */
  69. { 0x80E79FFF, 0x00030002, 0x0 },/* 7: 800 1000 2 */
  70. { 0x00FFFFFF, 0x00140005, 0x0 },/* 8: 850 850 0 */
  71. { 0x00FFFFFF, 0x000C0004, 0x0 },/* 9: 900 900 0 */
  72. { 0x00FFFFFF, 0x001C0003, 0x0 },/* 10: 950 950 0 */
  73. { 0x80FFFFFF, 0x00030002, 0x0 },/* 11: 1000 1000 0 */
  74. };
  75. static const struct ddi_buf_trans bdw_ddi_translations_edp[] = {
  76. { 0x00FFFFFF, 0x00000012, 0x0 },
  77. { 0x00EBAFFF, 0x00020011, 0x0 },
  78. { 0x00C71FFF, 0x0006000F, 0x0 },
  79. { 0x00AAAFFF, 0x000E000A, 0x0 },
  80. { 0x00FFFFFF, 0x00020011, 0x0 },
  81. { 0x00DB6FFF, 0x0005000F, 0x0 },
  82. { 0x00BEEFFF, 0x000A000C, 0x0 },
  83. { 0x00FFFFFF, 0x0005000F, 0x0 },
  84. { 0x00DB6FFF, 0x000A000C, 0x0 },
  85. };
  86. static const struct ddi_buf_trans bdw_ddi_translations_dp[] = {
  87. { 0x00FFFFFF, 0x0007000E, 0x0 },
  88. { 0x00D75FFF, 0x000E000A, 0x0 },
  89. { 0x00BEFFFF, 0x00140006, 0x0 },
  90. { 0x80B2CFFF, 0x001B0002, 0x0 },
  91. { 0x00FFFFFF, 0x000E000A, 0x0 },
  92. { 0x00DB6FFF, 0x00160005, 0x0 },
  93. { 0x80C71FFF, 0x001A0002, 0x0 },
  94. { 0x00F7DFFF, 0x00180004, 0x0 },
  95. { 0x80D75FFF, 0x001B0002, 0x0 },
  96. };
  97. static const struct ddi_buf_trans bdw_ddi_translations_fdi[] = {
  98. { 0x00FFFFFF, 0x0001000E, 0x0 },
  99. { 0x00D75FFF, 0x0004000A, 0x0 },
  100. { 0x00C30FFF, 0x00070006, 0x0 },
  101. { 0x00AAAFFF, 0x000C0000, 0x0 },
  102. { 0x00FFFFFF, 0x0004000A, 0x0 },
  103. { 0x00D75FFF, 0x00090004, 0x0 },
  104. { 0x00C30FFF, 0x000C0000, 0x0 },
  105. { 0x00FFFFFF, 0x00070006, 0x0 },
  106. { 0x00D75FFF, 0x000C0000, 0x0 },
  107. };
  108. static const struct ddi_buf_trans bdw_ddi_translations_hdmi[] = {
  109. /* Idx NT mV d T mV df db */
  110. { 0x00FFFFFF, 0x0007000E, 0x0 },/* 0: 400 400 0 */
  111. { 0x00D75FFF, 0x000E000A, 0x0 },/* 1: 400 600 3.5 */
  112. { 0x00BEFFFF, 0x00140006, 0x0 },/* 2: 400 800 6 */
  113. { 0x00FFFFFF, 0x0009000D, 0x0 },/* 3: 450 450 0 */
  114. { 0x00FFFFFF, 0x000E000A, 0x0 },/* 4: 600 600 0 */
  115. { 0x00D7FFFF, 0x00140006, 0x0 },/* 5: 600 800 2.5 */
  116. { 0x80CB2FFF, 0x001B0002, 0x0 },/* 6: 600 1000 4.5 */
  117. { 0x00FFFFFF, 0x00140006, 0x0 },/* 7: 800 800 0 */
  118. { 0x80E79FFF, 0x001B0002, 0x0 },/* 8: 800 1000 2 */
  119. { 0x80FFFFFF, 0x001B0002, 0x0 },/* 9: 1000 1000 0 */
  120. };
  121. /* Skylake H and S */
  122. static const struct ddi_buf_trans skl_ddi_translations_dp[] = {
  123. { 0x00002016, 0x000000A0, 0x0 },
  124. { 0x00005012, 0x0000009B, 0x0 },
  125. { 0x00007011, 0x00000088, 0x0 },
  126. { 0x80009010, 0x000000C0, 0x1 },
  127. { 0x00002016, 0x0000009B, 0x0 },
  128. { 0x00005012, 0x00000088, 0x0 },
  129. { 0x80007011, 0x000000C0, 0x1 },
  130. { 0x00002016, 0x000000DF, 0x0 },
  131. { 0x80005012, 0x000000C0, 0x1 },
  132. };
  133. /* Skylake U */
  134. static const struct ddi_buf_trans skl_u_ddi_translations_dp[] = {
  135. { 0x0000201B, 0x000000A2, 0x0 },
  136. { 0x00005012, 0x00000088, 0x0 },
  137. { 0x80007011, 0x000000CD, 0x1 },
  138. { 0x80009010, 0x000000C0, 0x1 },
  139. { 0x0000201B, 0x0000009D, 0x0 },
  140. { 0x80005012, 0x000000C0, 0x1 },
  141. { 0x80007011, 0x000000C0, 0x1 },
  142. { 0x00002016, 0x00000088, 0x0 },
  143. { 0x80005012, 0x000000C0, 0x1 },
  144. };
  145. /* Skylake Y */
  146. static const struct ddi_buf_trans skl_y_ddi_translations_dp[] = {
  147. { 0x00000018, 0x000000A2, 0x0 },
  148. { 0x00005012, 0x00000088, 0x0 },
  149. { 0x80007011, 0x000000CD, 0x3 },
  150. { 0x80009010, 0x000000C0, 0x3 },
  151. { 0x00000018, 0x0000009D, 0x0 },
  152. { 0x80005012, 0x000000C0, 0x3 },
  153. { 0x80007011, 0x000000C0, 0x3 },
  154. { 0x00000018, 0x00000088, 0x0 },
  155. { 0x80005012, 0x000000C0, 0x3 },
  156. };
  157. /* Kabylake H and S */
  158. static const struct ddi_buf_trans kbl_ddi_translations_dp[] = {
  159. { 0x00002016, 0x000000A0, 0x0 },
  160. { 0x00005012, 0x0000009B, 0x0 },
  161. { 0x00007011, 0x00000088, 0x0 },
  162. { 0x80009010, 0x000000C0, 0x1 },
  163. { 0x00002016, 0x0000009B, 0x0 },
  164. { 0x00005012, 0x00000088, 0x0 },
  165. { 0x80007011, 0x000000C0, 0x1 },
  166. { 0x00002016, 0x00000097, 0x0 },
  167. { 0x80005012, 0x000000C0, 0x1 },
  168. };
  169. /* Kabylake U */
  170. static const struct ddi_buf_trans kbl_u_ddi_translations_dp[] = {
  171. { 0x0000201B, 0x000000A1, 0x0 },
  172. { 0x00005012, 0x00000088, 0x0 },
  173. { 0x80007011, 0x000000CD, 0x3 },
  174. { 0x80009010, 0x000000C0, 0x3 },
  175. { 0x0000201B, 0x0000009D, 0x0 },
  176. { 0x80005012, 0x000000C0, 0x3 },
  177. { 0x80007011, 0x000000C0, 0x3 },
  178. { 0x00002016, 0x0000004F, 0x0 },
  179. { 0x80005012, 0x000000C0, 0x3 },
  180. };
  181. /* Kabylake Y */
  182. static const struct ddi_buf_trans kbl_y_ddi_translations_dp[] = {
  183. { 0x00001017, 0x000000A1, 0x0 },
  184. { 0x00005012, 0x00000088, 0x0 },
  185. { 0x80007011, 0x000000CD, 0x3 },
  186. { 0x8000800F, 0x000000C0, 0x3 },
  187. { 0x00001017, 0x0000009D, 0x0 },
  188. { 0x80005012, 0x000000C0, 0x3 },
  189. { 0x80007011, 0x000000C0, 0x3 },
  190. { 0x00001017, 0x0000004C, 0x0 },
  191. { 0x80005012, 0x000000C0, 0x3 },
  192. };
  193. /*
  194. * Skylake/Kabylake H and S
  195. * eDP 1.4 low vswing translation parameters
  196. */
  197. static const struct ddi_buf_trans skl_ddi_translations_edp[] = {
  198. { 0x00000018, 0x000000A8, 0x0 },
  199. { 0x00004013, 0x000000A9, 0x0 },
  200. { 0x00007011, 0x000000A2, 0x0 },
  201. { 0x00009010, 0x0000009C, 0x0 },
  202. { 0x00000018, 0x000000A9, 0x0 },
  203. { 0x00006013, 0x000000A2, 0x0 },
  204. { 0x00007011, 0x000000A6, 0x0 },
  205. { 0x00000018, 0x000000AB, 0x0 },
  206. { 0x00007013, 0x0000009F, 0x0 },
  207. { 0x00000018, 0x000000DF, 0x0 },
  208. };
  209. /*
  210. * Skylake/Kabylake U
  211. * eDP 1.4 low vswing translation parameters
  212. */
  213. static const struct ddi_buf_trans skl_u_ddi_translations_edp[] = {
  214. { 0x00000018, 0x000000A8, 0x0 },
  215. { 0x00004013, 0x000000A9, 0x0 },
  216. { 0x00007011, 0x000000A2, 0x0 },
  217. { 0x00009010, 0x0000009C, 0x0 },
  218. { 0x00000018, 0x000000A9, 0x0 },
  219. { 0x00006013, 0x000000A2, 0x0 },
  220. { 0x00007011, 0x000000A6, 0x0 },
  221. { 0x00002016, 0x000000AB, 0x0 },
  222. { 0x00005013, 0x0000009F, 0x0 },
  223. { 0x00000018, 0x000000DF, 0x0 },
  224. };
  225. /*
  226. * Skylake/Kabylake Y
  227. * eDP 1.4 low vswing translation parameters
  228. */
  229. static const struct ddi_buf_trans skl_y_ddi_translations_edp[] = {
  230. { 0x00000018, 0x000000A8, 0x0 },
  231. { 0x00004013, 0x000000AB, 0x0 },
  232. { 0x00007011, 0x000000A4, 0x0 },
  233. { 0x00009010, 0x000000DF, 0x0 },
  234. { 0x00000018, 0x000000AA, 0x0 },
  235. { 0x00006013, 0x000000A4, 0x0 },
  236. { 0x00007011, 0x0000009D, 0x0 },
  237. { 0x00000018, 0x000000A0, 0x0 },
  238. { 0x00006012, 0x000000DF, 0x0 },
  239. { 0x00000018, 0x0000008A, 0x0 },
  240. };
  241. /* Skylake/Kabylake U, H and S */
  242. static const struct ddi_buf_trans skl_ddi_translations_hdmi[] = {
  243. { 0x00000018, 0x000000AC, 0x0 },
  244. { 0x00005012, 0x0000009D, 0x0 },
  245. { 0x00007011, 0x00000088, 0x0 },
  246. { 0x00000018, 0x000000A1, 0x0 },
  247. { 0x00000018, 0x00000098, 0x0 },
  248. { 0x00004013, 0x00000088, 0x0 },
  249. { 0x80006012, 0x000000CD, 0x1 },
  250. { 0x00000018, 0x000000DF, 0x0 },
  251. { 0x80003015, 0x000000CD, 0x1 }, /* Default */
  252. { 0x80003015, 0x000000C0, 0x1 },
  253. { 0x80000018, 0x000000C0, 0x1 },
  254. };
  255. /* Skylake/Kabylake Y */
  256. static const struct ddi_buf_trans skl_y_ddi_translations_hdmi[] = {
  257. { 0x00000018, 0x000000A1, 0x0 },
  258. { 0x00005012, 0x000000DF, 0x0 },
  259. { 0x80007011, 0x000000CB, 0x3 },
  260. { 0x00000018, 0x000000A4, 0x0 },
  261. { 0x00000018, 0x0000009D, 0x0 },
  262. { 0x00004013, 0x00000080, 0x0 },
  263. { 0x80006013, 0x000000C0, 0x3 },
  264. { 0x00000018, 0x0000008A, 0x0 },
  265. { 0x80003015, 0x000000C0, 0x3 }, /* Default */
  266. { 0x80003015, 0x000000C0, 0x3 },
  267. { 0x80000018, 0x000000C0, 0x3 },
  268. };
  269. struct bxt_ddi_buf_trans {
  270. u32 margin; /* swing value */
  271. u32 scale; /* scale value */
  272. u32 enable; /* scale enable */
  273. u32 deemphasis;
  274. bool default_index; /* true if the entry represents default value */
  275. };
  276. static const struct bxt_ddi_buf_trans bxt_ddi_translations_dp[] = {
  277. /* Idx NT mV diff db */
  278. { 52, 0x9A, 0, 128, true }, /* 0: 400 0 */
  279. { 78, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
  280. { 104, 0x9A, 0, 64, false }, /* 2: 400 6 */
  281. { 154, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
  282. { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
  283. { 116, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
  284. { 154, 0x9A, 0, 64, false }, /* 6: 600 6 */
  285. { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
  286. { 154, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
  287. { 154, 0x9A, 1, 128, false }, /* 9: 1200 0 */
  288. };
  289. static const struct bxt_ddi_buf_trans bxt_ddi_translations_edp[] = {
  290. /* Idx NT mV diff db */
  291. { 26, 0, 0, 128, false }, /* 0: 200 0 */
  292. { 38, 0, 0, 112, false }, /* 1: 200 1.5 */
  293. { 48, 0, 0, 96, false }, /* 2: 200 4 */
  294. { 54, 0, 0, 69, false }, /* 3: 200 6 */
  295. { 32, 0, 0, 128, false }, /* 4: 250 0 */
  296. { 48, 0, 0, 104, false }, /* 5: 250 1.5 */
  297. { 54, 0, 0, 85, false }, /* 6: 250 4 */
  298. { 43, 0, 0, 128, false }, /* 7: 300 0 */
  299. { 54, 0, 0, 101, false }, /* 8: 300 1.5 */
  300. { 48, 0, 0, 128, false }, /* 9: 300 0 */
  301. };
  302. /* BSpec has 2 recommended values - entries 0 and 8.
  303. * Using the entry with higher vswing.
  304. */
  305. static const struct bxt_ddi_buf_trans bxt_ddi_translations_hdmi[] = {
  306. /* Idx NT mV diff db */
  307. { 52, 0x9A, 0, 128, false }, /* 0: 400 0 */
  308. { 52, 0x9A, 0, 85, false }, /* 1: 400 3.5 */
  309. { 52, 0x9A, 0, 64, false }, /* 2: 400 6 */
  310. { 42, 0x9A, 0, 43, false }, /* 3: 400 9.5 */
  311. { 77, 0x9A, 0, 128, false }, /* 4: 600 0 */
  312. { 77, 0x9A, 0, 85, false }, /* 5: 600 3.5 */
  313. { 77, 0x9A, 0, 64, false }, /* 6: 600 6 */
  314. { 102, 0x9A, 0, 128, false }, /* 7: 800 0 */
  315. { 102, 0x9A, 0, 85, false }, /* 8: 800 3.5 */
  316. { 154, 0x9A, 1, 128, true }, /* 9: 1200 0 */
  317. };
  318. enum port intel_ddi_get_encoder_port(struct intel_encoder *encoder)
  319. {
  320. switch (encoder->type) {
  321. case INTEL_OUTPUT_DP_MST:
  322. return enc_to_mst(&encoder->base)->primary->port;
  323. case INTEL_OUTPUT_DP:
  324. case INTEL_OUTPUT_EDP:
  325. case INTEL_OUTPUT_HDMI:
  326. case INTEL_OUTPUT_UNKNOWN:
  327. return enc_to_dig_port(&encoder->base)->port;
  328. case INTEL_OUTPUT_ANALOG:
  329. return PORT_E;
  330. default:
  331. MISSING_CASE(encoder->type);
  332. return PORT_A;
  333. }
  334. }
  335. static const struct ddi_buf_trans *
  336. bdw_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
  337. {
  338. if (dev_priv->vbt.edp.low_vswing) {
  339. *n_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
  340. return bdw_ddi_translations_edp;
  341. } else {
  342. *n_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  343. return bdw_ddi_translations_dp;
  344. }
  345. }
  346. static const struct ddi_buf_trans *
  347. skl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
  348. {
  349. if (IS_SKL_ULX(dev_priv)) {
  350. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_dp);
  351. return skl_y_ddi_translations_dp;
  352. } else if (IS_SKL_ULT(dev_priv)) {
  353. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_dp);
  354. return skl_u_ddi_translations_dp;
  355. } else {
  356. *n_entries = ARRAY_SIZE(skl_ddi_translations_dp);
  357. return skl_ddi_translations_dp;
  358. }
  359. }
  360. static const struct ddi_buf_trans *
  361. kbl_get_buf_trans_dp(struct drm_i915_private *dev_priv, int *n_entries)
  362. {
  363. if (IS_KBL_ULX(dev_priv)) {
  364. *n_entries = ARRAY_SIZE(kbl_y_ddi_translations_dp);
  365. return kbl_y_ddi_translations_dp;
  366. } else if (IS_KBL_ULT(dev_priv)) {
  367. *n_entries = ARRAY_SIZE(kbl_u_ddi_translations_dp);
  368. return kbl_u_ddi_translations_dp;
  369. } else {
  370. *n_entries = ARRAY_SIZE(kbl_ddi_translations_dp);
  371. return kbl_ddi_translations_dp;
  372. }
  373. }
  374. static const struct ddi_buf_trans *
  375. skl_get_buf_trans_edp(struct drm_i915_private *dev_priv, int *n_entries)
  376. {
  377. if (dev_priv->vbt.edp.low_vswing) {
  378. if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
  379. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_edp);
  380. return skl_y_ddi_translations_edp;
  381. } else if (IS_SKL_ULT(dev_priv) || IS_KBL_ULT(dev_priv)) {
  382. *n_entries = ARRAY_SIZE(skl_u_ddi_translations_edp);
  383. return skl_u_ddi_translations_edp;
  384. } else {
  385. *n_entries = ARRAY_SIZE(skl_ddi_translations_edp);
  386. return skl_ddi_translations_edp;
  387. }
  388. }
  389. if (IS_KABYLAKE(dev_priv))
  390. return kbl_get_buf_trans_dp(dev_priv, n_entries);
  391. else
  392. return skl_get_buf_trans_dp(dev_priv, n_entries);
  393. }
  394. static const struct ddi_buf_trans *
  395. skl_get_buf_trans_hdmi(struct drm_i915_private *dev_priv, int *n_entries)
  396. {
  397. if (IS_SKL_ULX(dev_priv) || IS_KBL_ULX(dev_priv)) {
  398. *n_entries = ARRAY_SIZE(skl_y_ddi_translations_hdmi);
  399. return skl_y_ddi_translations_hdmi;
  400. } else {
  401. *n_entries = ARRAY_SIZE(skl_ddi_translations_hdmi);
  402. return skl_ddi_translations_hdmi;
  403. }
  404. }
  405. static int intel_ddi_hdmi_level(struct drm_i915_private *dev_priv, enum port port)
  406. {
  407. int n_hdmi_entries;
  408. int hdmi_level;
  409. int hdmi_default_entry;
  410. hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
  411. if (IS_GEN9_LP(dev_priv))
  412. return hdmi_level;
  413. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  414. skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
  415. hdmi_default_entry = 8;
  416. } else if (IS_BROADWELL(dev_priv)) {
  417. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  418. hdmi_default_entry = 7;
  419. } else if (IS_HASWELL(dev_priv)) {
  420. n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
  421. hdmi_default_entry = 6;
  422. } else {
  423. WARN(1, "ddi translation table missing\n");
  424. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  425. hdmi_default_entry = 7;
  426. }
  427. /* Choose a good default if VBT is badly populated */
  428. if (hdmi_level == HDMI_LEVEL_SHIFT_UNKNOWN ||
  429. hdmi_level >= n_hdmi_entries)
  430. hdmi_level = hdmi_default_entry;
  431. return hdmi_level;
  432. }
  433. /*
  434. * Starting with Haswell, DDI port buffers must be programmed with correct
  435. * values in advance. This function programs the correct values for
  436. * DP/eDP/FDI use cases.
  437. */
  438. void intel_prepare_dp_ddi_buffers(struct intel_encoder *encoder)
  439. {
  440. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  441. u32 iboost_bit = 0;
  442. int i, n_dp_entries, n_edp_entries, size;
  443. enum port port = intel_ddi_get_encoder_port(encoder);
  444. const struct ddi_buf_trans *ddi_translations_fdi;
  445. const struct ddi_buf_trans *ddi_translations_dp;
  446. const struct ddi_buf_trans *ddi_translations_edp;
  447. const struct ddi_buf_trans *ddi_translations;
  448. if (IS_GEN9_LP(dev_priv))
  449. return;
  450. if (IS_KABYLAKE(dev_priv)) {
  451. ddi_translations_fdi = NULL;
  452. ddi_translations_dp =
  453. kbl_get_buf_trans_dp(dev_priv, &n_dp_entries);
  454. ddi_translations_edp =
  455. skl_get_buf_trans_edp(dev_priv, &n_edp_entries);
  456. } else if (IS_SKYLAKE(dev_priv)) {
  457. ddi_translations_fdi = NULL;
  458. ddi_translations_dp =
  459. skl_get_buf_trans_dp(dev_priv, &n_dp_entries);
  460. ddi_translations_edp =
  461. skl_get_buf_trans_edp(dev_priv, &n_edp_entries);
  462. } else if (IS_BROADWELL(dev_priv)) {
  463. ddi_translations_fdi = bdw_ddi_translations_fdi;
  464. ddi_translations_dp = bdw_ddi_translations_dp;
  465. ddi_translations_edp = bdw_get_buf_trans_edp(dev_priv, &n_edp_entries);
  466. n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  467. } else if (IS_HASWELL(dev_priv)) {
  468. ddi_translations_fdi = hsw_ddi_translations_fdi;
  469. ddi_translations_dp = hsw_ddi_translations_dp;
  470. ddi_translations_edp = hsw_ddi_translations_dp;
  471. n_dp_entries = n_edp_entries = ARRAY_SIZE(hsw_ddi_translations_dp);
  472. } else {
  473. WARN(1, "ddi translation table missing\n");
  474. ddi_translations_edp = bdw_ddi_translations_dp;
  475. ddi_translations_fdi = bdw_ddi_translations_fdi;
  476. ddi_translations_dp = bdw_ddi_translations_dp;
  477. n_edp_entries = ARRAY_SIZE(bdw_ddi_translations_edp);
  478. n_dp_entries = ARRAY_SIZE(bdw_ddi_translations_dp);
  479. }
  480. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  481. /* If we're boosting the current, set bit 31 of trans1 */
  482. if (dev_priv->vbt.ddi_port_info[port].dp_boost_level)
  483. iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
  484. if (WARN_ON(encoder->type == INTEL_OUTPUT_EDP &&
  485. port != PORT_A && port != PORT_E &&
  486. n_edp_entries > 9))
  487. n_edp_entries = 9;
  488. }
  489. switch (encoder->type) {
  490. case INTEL_OUTPUT_EDP:
  491. ddi_translations = ddi_translations_edp;
  492. size = n_edp_entries;
  493. break;
  494. case INTEL_OUTPUT_DP:
  495. ddi_translations = ddi_translations_dp;
  496. size = n_dp_entries;
  497. break;
  498. case INTEL_OUTPUT_ANALOG:
  499. ddi_translations = ddi_translations_fdi;
  500. size = n_dp_entries;
  501. break;
  502. default:
  503. BUG();
  504. }
  505. for (i = 0; i < size; i++) {
  506. I915_WRITE(DDI_BUF_TRANS_LO(port, i),
  507. ddi_translations[i].trans1 | iboost_bit);
  508. I915_WRITE(DDI_BUF_TRANS_HI(port, i),
  509. ddi_translations[i].trans2);
  510. }
  511. }
  512. /*
  513. * Starting with Haswell, DDI port buffers must be programmed with correct
  514. * values in advance. This function programs the correct values for
  515. * HDMI/DVI use cases.
  516. */
  517. static void intel_prepare_hdmi_ddi_buffers(struct intel_encoder *encoder)
  518. {
  519. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  520. u32 iboost_bit = 0;
  521. int n_hdmi_entries, hdmi_level;
  522. enum port port = intel_ddi_get_encoder_port(encoder);
  523. const struct ddi_buf_trans *ddi_translations_hdmi;
  524. if (IS_GEN9_LP(dev_priv))
  525. return;
  526. hdmi_level = intel_ddi_hdmi_level(dev_priv, port);
  527. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  528. ddi_translations_hdmi = skl_get_buf_trans_hdmi(dev_priv, &n_hdmi_entries);
  529. /* If we're boosting the current, set bit 31 of trans1 */
  530. if (dev_priv->vbt.ddi_port_info[port].hdmi_boost_level)
  531. iboost_bit = DDI_BUF_BALANCE_LEG_ENABLE;
  532. } else if (IS_BROADWELL(dev_priv)) {
  533. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  534. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  535. } else if (IS_HASWELL(dev_priv)) {
  536. ddi_translations_hdmi = hsw_ddi_translations_hdmi;
  537. n_hdmi_entries = ARRAY_SIZE(hsw_ddi_translations_hdmi);
  538. } else {
  539. WARN(1, "ddi translation table missing\n");
  540. ddi_translations_hdmi = bdw_ddi_translations_hdmi;
  541. n_hdmi_entries = ARRAY_SIZE(bdw_ddi_translations_hdmi);
  542. }
  543. /* Entry 9 is for HDMI: */
  544. I915_WRITE(DDI_BUF_TRANS_LO(port, 9),
  545. ddi_translations_hdmi[hdmi_level].trans1 | iboost_bit);
  546. I915_WRITE(DDI_BUF_TRANS_HI(port, 9),
  547. ddi_translations_hdmi[hdmi_level].trans2);
  548. }
  549. static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
  550. enum port port)
  551. {
  552. i915_reg_t reg = DDI_BUF_CTL(port);
  553. int i;
  554. for (i = 0; i < 16; i++) {
  555. udelay(1);
  556. if (I915_READ(reg) & DDI_BUF_IS_IDLE)
  557. return;
  558. }
  559. DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
  560. }
  561. static uint32_t hsw_pll_to_ddi_pll_sel(struct intel_shared_dpll *pll)
  562. {
  563. switch (pll->id) {
  564. case DPLL_ID_WRPLL1:
  565. return PORT_CLK_SEL_WRPLL1;
  566. case DPLL_ID_WRPLL2:
  567. return PORT_CLK_SEL_WRPLL2;
  568. case DPLL_ID_SPLL:
  569. return PORT_CLK_SEL_SPLL;
  570. case DPLL_ID_LCPLL_810:
  571. return PORT_CLK_SEL_LCPLL_810;
  572. case DPLL_ID_LCPLL_1350:
  573. return PORT_CLK_SEL_LCPLL_1350;
  574. case DPLL_ID_LCPLL_2700:
  575. return PORT_CLK_SEL_LCPLL_2700;
  576. default:
  577. MISSING_CASE(pll->id);
  578. return PORT_CLK_SEL_NONE;
  579. }
  580. }
  581. /* Starting with Haswell, different DDI ports can work in FDI mode for
  582. * connection to the PCH-located connectors. For this, it is necessary to train
  583. * both the DDI port and PCH receiver for the desired DDI buffer settings.
  584. *
  585. * The recommended port to work in FDI mode is DDI E, which we use here. Also,
  586. * please note that when FDI mode is active on DDI E, it shares 2 lines with
  587. * DDI A (which is used for eDP)
  588. */
  589. void hsw_fdi_link_train(struct drm_crtc *crtc)
  590. {
  591. struct drm_device *dev = crtc->dev;
  592. struct drm_i915_private *dev_priv = to_i915(dev);
  593. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  594. struct intel_encoder *encoder;
  595. u32 temp, i, rx_ctl_val, ddi_pll_sel;
  596. for_each_encoder_on_crtc(dev, crtc, encoder) {
  597. WARN_ON(encoder->type != INTEL_OUTPUT_ANALOG);
  598. intel_prepare_dp_ddi_buffers(encoder);
  599. }
  600. /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
  601. * mode set "sequence for CRT port" document:
  602. * - TP1 to TP2 time with the default value
  603. * - FDI delay to 90h
  604. *
  605. * WaFDIAutoLinkSetTimingOverrride:hsw
  606. */
  607. I915_WRITE(FDI_RX_MISC(PIPE_A), FDI_RX_PWRDN_LANE1_VAL(2) |
  608. FDI_RX_PWRDN_LANE0_VAL(2) |
  609. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  610. /* Enable the PCH Receiver FDI PLL */
  611. rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
  612. FDI_RX_PLL_ENABLE |
  613. FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes);
  614. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  615. POSTING_READ(FDI_RX_CTL(PIPE_A));
  616. udelay(220);
  617. /* Switch from Rawclk to PCDclk */
  618. rx_ctl_val |= FDI_PCDCLK;
  619. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  620. /* Configure Port Clock Select */
  621. ddi_pll_sel = hsw_pll_to_ddi_pll_sel(intel_crtc->config->shared_dpll);
  622. I915_WRITE(PORT_CLK_SEL(PORT_E), ddi_pll_sel);
  623. WARN_ON(ddi_pll_sel != PORT_CLK_SEL_SPLL);
  624. /* Start the training iterating through available voltages and emphasis,
  625. * testing each value twice. */
  626. for (i = 0; i < ARRAY_SIZE(hsw_ddi_translations_fdi) * 2; i++) {
  627. /* Configure DP_TP_CTL with auto-training */
  628. I915_WRITE(DP_TP_CTL(PORT_E),
  629. DP_TP_CTL_FDI_AUTOTRAIN |
  630. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  631. DP_TP_CTL_LINK_TRAIN_PAT1 |
  632. DP_TP_CTL_ENABLE);
  633. /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
  634. * DDI E does not support port reversal, the functionality is
  635. * achieved on the PCH side in FDI_RX_CTL, so no need to set the
  636. * port reversal bit */
  637. I915_WRITE(DDI_BUF_CTL(PORT_E),
  638. DDI_BUF_CTL_ENABLE |
  639. ((intel_crtc->config->fdi_lanes - 1) << 1) |
  640. DDI_BUF_TRANS_SELECT(i / 2));
  641. POSTING_READ(DDI_BUF_CTL(PORT_E));
  642. udelay(600);
  643. /* Program PCH FDI Receiver TU */
  644. I915_WRITE(FDI_RX_TUSIZE1(PIPE_A), TU_SIZE(64));
  645. /* Enable PCH FDI Receiver with auto-training */
  646. rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
  647. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  648. POSTING_READ(FDI_RX_CTL(PIPE_A));
  649. /* Wait for FDI receiver lane calibration */
  650. udelay(30);
  651. /* Unset FDI_RX_MISC pwrdn lanes */
  652. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  653. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  654. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  655. POSTING_READ(FDI_RX_MISC(PIPE_A));
  656. /* Wait for FDI auto training time */
  657. udelay(5);
  658. temp = I915_READ(DP_TP_STATUS(PORT_E));
  659. if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
  660. DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
  661. break;
  662. }
  663. /*
  664. * Leave things enabled even if we failed to train FDI.
  665. * Results in less fireworks from the state checker.
  666. */
  667. if (i == ARRAY_SIZE(hsw_ddi_translations_fdi) * 2 - 1) {
  668. DRM_ERROR("FDI link training failed!\n");
  669. break;
  670. }
  671. rx_ctl_val &= ~FDI_RX_ENABLE;
  672. I915_WRITE(FDI_RX_CTL(PIPE_A), rx_ctl_val);
  673. POSTING_READ(FDI_RX_CTL(PIPE_A));
  674. temp = I915_READ(DDI_BUF_CTL(PORT_E));
  675. temp &= ~DDI_BUF_CTL_ENABLE;
  676. I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
  677. POSTING_READ(DDI_BUF_CTL(PORT_E));
  678. /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
  679. temp = I915_READ(DP_TP_CTL(PORT_E));
  680. temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  681. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  682. I915_WRITE(DP_TP_CTL(PORT_E), temp);
  683. POSTING_READ(DP_TP_CTL(PORT_E));
  684. intel_wait_ddi_buf_idle(dev_priv, PORT_E);
  685. /* Reset FDI_RX_MISC pwrdn lanes */
  686. temp = I915_READ(FDI_RX_MISC(PIPE_A));
  687. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  688. temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  689. I915_WRITE(FDI_RX_MISC(PIPE_A), temp);
  690. POSTING_READ(FDI_RX_MISC(PIPE_A));
  691. }
  692. /* Enable normal pixel sending for FDI */
  693. I915_WRITE(DP_TP_CTL(PORT_E),
  694. DP_TP_CTL_FDI_AUTOTRAIN |
  695. DP_TP_CTL_LINK_TRAIN_NORMAL |
  696. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  697. DP_TP_CTL_ENABLE);
  698. }
  699. void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder)
  700. {
  701. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  702. struct intel_digital_port *intel_dig_port =
  703. enc_to_dig_port(&encoder->base);
  704. intel_dp->DP = intel_dig_port->saved_port_bits |
  705. DDI_BUF_CTL_ENABLE | DDI_BUF_TRANS_SELECT(0);
  706. intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
  707. }
  708. static struct intel_encoder *
  709. intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
  710. {
  711. struct drm_device *dev = crtc->dev;
  712. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  713. struct intel_encoder *intel_encoder, *ret = NULL;
  714. int num_encoders = 0;
  715. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  716. ret = intel_encoder;
  717. num_encoders++;
  718. }
  719. if (num_encoders != 1)
  720. WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
  721. pipe_name(intel_crtc->pipe));
  722. BUG_ON(ret == NULL);
  723. return ret;
  724. }
  725. struct intel_encoder *
  726. intel_ddi_get_crtc_new_encoder(struct intel_crtc_state *crtc_state)
  727. {
  728. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  729. struct intel_encoder *ret = NULL;
  730. struct drm_atomic_state *state;
  731. struct drm_connector *connector;
  732. struct drm_connector_state *connector_state;
  733. int num_encoders = 0;
  734. int i;
  735. state = crtc_state->base.state;
  736. for_each_connector_in_state(state, connector, connector_state, i) {
  737. if (connector_state->crtc != crtc_state->base.crtc)
  738. continue;
  739. ret = to_intel_encoder(connector_state->best_encoder);
  740. num_encoders++;
  741. }
  742. WARN(num_encoders != 1, "%d encoders on crtc for pipe %c\n", num_encoders,
  743. pipe_name(crtc->pipe));
  744. BUG_ON(ret == NULL);
  745. return ret;
  746. }
  747. #define LC_FREQ 2700
  748. static int hsw_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
  749. i915_reg_t reg)
  750. {
  751. int refclk = LC_FREQ;
  752. int n, p, r;
  753. u32 wrpll;
  754. wrpll = I915_READ(reg);
  755. switch (wrpll & WRPLL_PLL_REF_MASK) {
  756. case WRPLL_PLL_SSC:
  757. case WRPLL_PLL_NON_SSC:
  758. /*
  759. * We could calculate spread here, but our checking
  760. * code only cares about 5% accuracy, and spread is a max of
  761. * 0.5% downspread.
  762. */
  763. refclk = 135;
  764. break;
  765. case WRPLL_PLL_LCPLL:
  766. refclk = LC_FREQ;
  767. break;
  768. default:
  769. WARN(1, "bad wrpll refclk\n");
  770. return 0;
  771. }
  772. r = wrpll & WRPLL_DIVIDER_REF_MASK;
  773. p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
  774. n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
  775. /* Convert to KHz, p & r have a fixed point portion */
  776. return (refclk * n * 100) / (p * r);
  777. }
  778. static int skl_calc_wrpll_link(struct drm_i915_private *dev_priv,
  779. uint32_t dpll)
  780. {
  781. i915_reg_t cfgcr1_reg, cfgcr2_reg;
  782. uint32_t cfgcr1_val, cfgcr2_val;
  783. uint32_t p0, p1, p2, dco_freq;
  784. cfgcr1_reg = DPLL_CFGCR1(dpll);
  785. cfgcr2_reg = DPLL_CFGCR2(dpll);
  786. cfgcr1_val = I915_READ(cfgcr1_reg);
  787. cfgcr2_val = I915_READ(cfgcr2_reg);
  788. p0 = cfgcr2_val & DPLL_CFGCR2_PDIV_MASK;
  789. p2 = cfgcr2_val & DPLL_CFGCR2_KDIV_MASK;
  790. if (cfgcr2_val & DPLL_CFGCR2_QDIV_MODE(1))
  791. p1 = (cfgcr2_val & DPLL_CFGCR2_QDIV_RATIO_MASK) >> 8;
  792. else
  793. p1 = 1;
  794. switch (p0) {
  795. case DPLL_CFGCR2_PDIV_1:
  796. p0 = 1;
  797. break;
  798. case DPLL_CFGCR2_PDIV_2:
  799. p0 = 2;
  800. break;
  801. case DPLL_CFGCR2_PDIV_3:
  802. p0 = 3;
  803. break;
  804. case DPLL_CFGCR2_PDIV_7:
  805. p0 = 7;
  806. break;
  807. }
  808. switch (p2) {
  809. case DPLL_CFGCR2_KDIV_5:
  810. p2 = 5;
  811. break;
  812. case DPLL_CFGCR2_KDIV_2:
  813. p2 = 2;
  814. break;
  815. case DPLL_CFGCR2_KDIV_3:
  816. p2 = 3;
  817. break;
  818. case DPLL_CFGCR2_KDIV_1:
  819. p2 = 1;
  820. break;
  821. }
  822. dco_freq = (cfgcr1_val & DPLL_CFGCR1_DCO_INTEGER_MASK) * 24 * 1000;
  823. dco_freq += (((cfgcr1_val & DPLL_CFGCR1_DCO_FRACTION_MASK) >> 9) * 24 *
  824. 1000) / 0x8000;
  825. return dco_freq / (p0 * p1 * p2 * 5);
  826. }
  827. static void ddi_dotclock_get(struct intel_crtc_state *pipe_config)
  828. {
  829. int dotclock;
  830. if (pipe_config->has_pch_encoder)
  831. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  832. &pipe_config->fdi_m_n);
  833. else if (intel_crtc_has_dp_encoder(pipe_config))
  834. dotclock = intel_dotclock_calculate(pipe_config->port_clock,
  835. &pipe_config->dp_m_n);
  836. else if (pipe_config->has_hdmi_sink && pipe_config->pipe_bpp == 36)
  837. dotclock = pipe_config->port_clock * 2 / 3;
  838. else
  839. dotclock = pipe_config->port_clock;
  840. if (pipe_config->pixel_multiplier)
  841. dotclock /= pipe_config->pixel_multiplier;
  842. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  843. }
  844. static void skl_ddi_clock_get(struct intel_encoder *encoder,
  845. struct intel_crtc_state *pipe_config)
  846. {
  847. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  848. int link_clock = 0;
  849. uint32_t dpll_ctl1, dpll;
  850. dpll = intel_get_shared_dpll_id(dev_priv, pipe_config->shared_dpll);
  851. dpll_ctl1 = I915_READ(DPLL_CTRL1);
  852. if (dpll_ctl1 & DPLL_CTRL1_HDMI_MODE(dpll)) {
  853. link_clock = skl_calc_wrpll_link(dev_priv, dpll);
  854. } else {
  855. link_clock = dpll_ctl1 & DPLL_CTRL1_LINK_RATE_MASK(dpll);
  856. link_clock >>= DPLL_CTRL1_LINK_RATE_SHIFT(dpll);
  857. switch (link_clock) {
  858. case DPLL_CTRL1_LINK_RATE_810:
  859. link_clock = 81000;
  860. break;
  861. case DPLL_CTRL1_LINK_RATE_1080:
  862. link_clock = 108000;
  863. break;
  864. case DPLL_CTRL1_LINK_RATE_1350:
  865. link_clock = 135000;
  866. break;
  867. case DPLL_CTRL1_LINK_RATE_1620:
  868. link_clock = 162000;
  869. break;
  870. case DPLL_CTRL1_LINK_RATE_2160:
  871. link_clock = 216000;
  872. break;
  873. case DPLL_CTRL1_LINK_RATE_2700:
  874. link_clock = 270000;
  875. break;
  876. default:
  877. WARN(1, "Unsupported link rate\n");
  878. break;
  879. }
  880. link_clock *= 2;
  881. }
  882. pipe_config->port_clock = link_clock;
  883. ddi_dotclock_get(pipe_config);
  884. }
  885. static void hsw_ddi_clock_get(struct intel_encoder *encoder,
  886. struct intel_crtc_state *pipe_config)
  887. {
  888. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  889. int link_clock = 0;
  890. u32 val, pll;
  891. val = hsw_pll_to_ddi_pll_sel(pipe_config->shared_dpll);
  892. switch (val & PORT_CLK_SEL_MASK) {
  893. case PORT_CLK_SEL_LCPLL_810:
  894. link_clock = 81000;
  895. break;
  896. case PORT_CLK_SEL_LCPLL_1350:
  897. link_clock = 135000;
  898. break;
  899. case PORT_CLK_SEL_LCPLL_2700:
  900. link_clock = 270000;
  901. break;
  902. case PORT_CLK_SEL_WRPLL1:
  903. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(0));
  904. break;
  905. case PORT_CLK_SEL_WRPLL2:
  906. link_clock = hsw_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL(1));
  907. break;
  908. case PORT_CLK_SEL_SPLL:
  909. pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
  910. if (pll == SPLL_PLL_FREQ_810MHz)
  911. link_clock = 81000;
  912. else if (pll == SPLL_PLL_FREQ_1350MHz)
  913. link_clock = 135000;
  914. else if (pll == SPLL_PLL_FREQ_2700MHz)
  915. link_clock = 270000;
  916. else {
  917. WARN(1, "bad spll freq\n");
  918. return;
  919. }
  920. break;
  921. default:
  922. WARN(1, "bad port clock sel\n");
  923. return;
  924. }
  925. pipe_config->port_clock = link_clock * 2;
  926. ddi_dotclock_get(pipe_config);
  927. }
  928. static int bxt_calc_pll_link(struct drm_i915_private *dev_priv,
  929. enum intel_dpll_id dpll)
  930. {
  931. struct intel_shared_dpll *pll;
  932. struct intel_dpll_hw_state *state;
  933. struct dpll clock;
  934. /* For DDI ports we always use a shared PLL. */
  935. if (WARN_ON(dpll == DPLL_ID_PRIVATE))
  936. return 0;
  937. pll = &dev_priv->shared_dplls[dpll];
  938. state = &pll->state.hw_state;
  939. clock.m1 = 2;
  940. clock.m2 = (state->pll0 & PORT_PLL_M2_MASK) << 22;
  941. if (state->pll3 & PORT_PLL_M2_FRAC_ENABLE)
  942. clock.m2 |= state->pll2 & PORT_PLL_M2_FRAC_MASK;
  943. clock.n = (state->pll1 & PORT_PLL_N_MASK) >> PORT_PLL_N_SHIFT;
  944. clock.p1 = (state->ebb0 & PORT_PLL_P1_MASK) >> PORT_PLL_P1_SHIFT;
  945. clock.p2 = (state->ebb0 & PORT_PLL_P2_MASK) >> PORT_PLL_P2_SHIFT;
  946. return chv_calc_dpll_params(100000, &clock);
  947. }
  948. static void bxt_ddi_clock_get(struct intel_encoder *encoder,
  949. struct intel_crtc_state *pipe_config)
  950. {
  951. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  952. enum port port = intel_ddi_get_encoder_port(encoder);
  953. uint32_t dpll = port;
  954. pipe_config->port_clock = bxt_calc_pll_link(dev_priv, dpll);
  955. ddi_dotclock_get(pipe_config);
  956. }
  957. void intel_ddi_clock_get(struct intel_encoder *encoder,
  958. struct intel_crtc_state *pipe_config)
  959. {
  960. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  961. if (INTEL_GEN(dev_priv) <= 8)
  962. hsw_ddi_clock_get(encoder, pipe_config);
  963. else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  964. skl_ddi_clock_get(encoder, pipe_config);
  965. else if (IS_GEN9_LP(dev_priv))
  966. bxt_ddi_clock_get(encoder, pipe_config);
  967. }
  968. static bool
  969. hsw_ddi_pll_select(struct intel_crtc *intel_crtc,
  970. struct intel_crtc_state *crtc_state,
  971. struct intel_encoder *intel_encoder)
  972. {
  973. struct intel_shared_dpll *pll;
  974. pll = intel_get_shared_dpll(intel_crtc, crtc_state,
  975. intel_encoder);
  976. if (!pll)
  977. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  978. pipe_name(intel_crtc->pipe));
  979. return pll;
  980. }
  981. static bool
  982. skl_ddi_pll_select(struct intel_crtc *intel_crtc,
  983. struct intel_crtc_state *crtc_state,
  984. struct intel_encoder *intel_encoder)
  985. {
  986. struct intel_shared_dpll *pll;
  987. pll = intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder);
  988. if (pll == NULL) {
  989. DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n",
  990. pipe_name(intel_crtc->pipe));
  991. return false;
  992. }
  993. return true;
  994. }
  995. static bool
  996. bxt_ddi_pll_select(struct intel_crtc *intel_crtc,
  997. struct intel_crtc_state *crtc_state,
  998. struct intel_encoder *intel_encoder)
  999. {
  1000. return !!intel_get_shared_dpll(intel_crtc, crtc_state, intel_encoder);
  1001. }
  1002. /*
  1003. * Tries to find a *shared* PLL for the CRTC and store it in
  1004. * intel_crtc->ddi_pll_sel.
  1005. *
  1006. * For private DPLLs, compute_config() should do the selection for us. This
  1007. * function should be folded into compute_config() eventually.
  1008. */
  1009. bool intel_ddi_pll_select(struct intel_crtc *intel_crtc,
  1010. struct intel_crtc_state *crtc_state)
  1011. {
  1012. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  1013. struct intel_encoder *intel_encoder =
  1014. intel_ddi_get_crtc_new_encoder(crtc_state);
  1015. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  1016. return skl_ddi_pll_select(intel_crtc, crtc_state,
  1017. intel_encoder);
  1018. else if (IS_GEN9_LP(dev_priv))
  1019. return bxt_ddi_pll_select(intel_crtc, crtc_state,
  1020. intel_encoder);
  1021. else
  1022. return hsw_ddi_pll_select(intel_crtc, crtc_state,
  1023. intel_encoder);
  1024. }
  1025. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
  1026. {
  1027. struct drm_i915_private *dev_priv = to_i915(crtc->dev);
  1028. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1029. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1030. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1031. int type = intel_encoder->type;
  1032. uint32_t temp;
  1033. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP || type == INTEL_OUTPUT_DP_MST) {
  1034. WARN_ON(transcoder_is_dsi(cpu_transcoder));
  1035. temp = TRANS_MSA_SYNC_CLK;
  1036. switch (intel_crtc->config->pipe_bpp) {
  1037. case 18:
  1038. temp |= TRANS_MSA_6_BPC;
  1039. break;
  1040. case 24:
  1041. temp |= TRANS_MSA_8_BPC;
  1042. break;
  1043. case 30:
  1044. temp |= TRANS_MSA_10_BPC;
  1045. break;
  1046. case 36:
  1047. temp |= TRANS_MSA_12_BPC;
  1048. break;
  1049. default:
  1050. BUG();
  1051. }
  1052. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  1053. }
  1054. }
  1055. void intel_ddi_set_vc_payload_alloc(struct drm_crtc *crtc, bool state)
  1056. {
  1057. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1058. struct drm_device *dev = crtc->dev;
  1059. struct drm_i915_private *dev_priv = to_i915(dev);
  1060. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1061. uint32_t temp;
  1062. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1063. if (state == true)
  1064. temp |= TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1065. else
  1066. temp &= ~TRANS_DDI_DP_VC_PAYLOAD_ALLOC;
  1067. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1068. }
  1069. void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
  1070. {
  1071. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1072. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1073. struct drm_device *dev = crtc->dev;
  1074. struct drm_i915_private *dev_priv = to_i915(dev);
  1075. enum pipe pipe = intel_crtc->pipe;
  1076. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1077. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1078. int type = intel_encoder->type;
  1079. uint32_t temp;
  1080. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  1081. temp = TRANS_DDI_FUNC_ENABLE;
  1082. temp |= TRANS_DDI_SELECT_PORT(port);
  1083. switch (intel_crtc->config->pipe_bpp) {
  1084. case 18:
  1085. temp |= TRANS_DDI_BPC_6;
  1086. break;
  1087. case 24:
  1088. temp |= TRANS_DDI_BPC_8;
  1089. break;
  1090. case 30:
  1091. temp |= TRANS_DDI_BPC_10;
  1092. break;
  1093. case 36:
  1094. temp |= TRANS_DDI_BPC_12;
  1095. break;
  1096. default:
  1097. BUG();
  1098. }
  1099. if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
  1100. temp |= TRANS_DDI_PVSYNC;
  1101. if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
  1102. temp |= TRANS_DDI_PHSYNC;
  1103. if (cpu_transcoder == TRANSCODER_EDP) {
  1104. switch (pipe) {
  1105. case PIPE_A:
  1106. /* On Haswell, can only use the always-on power well for
  1107. * eDP when not using the panel fitter, and when not
  1108. * using motion blur mitigation (which we don't
  1109. * support). */
  1110. if (IS_HASWELL(dev_priv) &&
  1111. (intel_crtc->config->pch_pfit.enabled ||
  1112. intel_crtc->config->pch_pfit.force_thru))
  1113. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  1114. else
  1115. temp |= TRANS_DDI_EDP_INPUT_A_ON;
  1116. break;
  1117. case PIPE_B:
  1118. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  1119. break;
  1120. case PIPE_C:
  1121. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  1122. break;
  1123. default:
  1124. BUG();
  1125. break;
  1126. }
  1127. }
  1128. if (type == INTEL_OUTPUT_HDMI) {
  1129. if (intel_crtc->config->has_hdmi_sink)
  1130. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  1131. else
  1132. temp |= TRANS_DDI_MODE_SELECT_DVI;
  1133. } else if (type == INTEL_OUTPUT_ANALOG) {
  1134. temp |= TRANS_DDI_MODE_SELECT_FDI;
  1135. temp |= (intel_crtc->config->fdi_lanes - 1) << 1;
  1136. } else if (type == INTEL_OUTPUT_DP ||
  1137. type == INTEL_OUTPUT_EDP) {
  1138. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  1139. temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
  1140. } else if (type == INTEL_OUTPUT_DP_MST) {
  1141. temp |= TRANS_DDI_MODE_SELECT_DP_MST;
  1142. temp |= DDI_PORT_WIDTH(intel_crtc->config->lane_count);
  1143. } else {
  1144. WARN(1, "Invalid encoder type %d for pipe %c\n",
  1145. intel_encoder->type, pipe_name(pipe));
  1146. }
  1147. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  1148. }
  1149. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  1150. enum transcoder cpu_transcoder)
  1151. {
  1152. i915_reg_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1153. uint32_t val = I915_READ(reg);
  1154. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK | TRANS_DDI_DP_VC_PAYLOAD_ALLOC);
  1155. val |= TRANS_DDI_PORT_NONE;
  1156. I915_WRITE(reg, val);
  1157. }
  1158. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  1159. {
  1160. struct drm_device *dev = intel_connector->base.dev;
  1161. struct drm_i915_private *dev_priv = to_i915(dev);
  1162. struct intel_encoder *intel_encoder = intel_connector->encoder;
  1163. int type = intel_connector->base.connector_type;
  1164. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1165. enum pipe pipe = 0;
  1166. enum transcoder cpu_transcoder;
  1167. enum intel_display_power_domain power_domain;
  1168. uint32_t tmp;
  1169. bool ret;
  1170. power_domain = intel_display_port_power_domain(intel_encoder);
  1171. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  1172. return false;
  1173. if (!intel_encoder->get_hw_state(intel_encoder, &pipe)) {
  1174. ret = false;
  1175. goto out;
  1176. }
  1177. if (port == PORT_A)
  1178. cpu_transcoder = TRANSCODER_EDP;
  1179. else
  1180. cpu_transcoder = (enum transcoder) pipe;
  1181. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1182. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  1183. case TRANS_DDI_MODE_SELECT_HDMI:
  1184. case TRANS_DDI_MODE_SELECT_DVI:
  1185. ret = type == DRM_MODE_CONNECTOR_HDMIA;
  1186. break;
  1187. case TRANS_DDI_MODE_SELECT_DP_SST:
  1188. ret = type == DRM_MODE_CONNECTOR_eDP ||
  1189. type == DRM_MODE_CONNECTOR_DisplayPort;
  1190. break;
  1191. case TRANS_DDI_MODE_SELECT_DP_MST:
  1192. /* if the transcoder is in MST state then
  1193. * connector isn't connected */
  1194. ret = false;
  1195. break;
  1196. case TRANS_DDI_MODE_SELECT_FDI:
  1197. ret = type == DRM_MODE_CONNECTOR_VGA;
  1198. break;
  1199. default:
  1200. ret = false;
  1201. break;
  1202. }
  1203. out:
  1204. intel_display_power_put(dev_priv, power_domain);
  1205. return ret;
  1206. }
  1207. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  1208. enum pipe *pipe)
  1209. {
  1210. struct drm_device *dev = encoder->base.dev;
  1211. struct drm_i915_private *dev_priv = to_i915(dev);
  1212. enum port port = intel_ddi_get_encoder_port(encoder);
  1213. enum intel_display_power_domain power_domain;
  1214. u32 tmp;
  1215. int i;
  1216. bool ret;
  1217. power_domain = intel_display_port_power_domain(encoder);
  1218. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  1219. return false;
  1220. ret = false;
  1221. tmp = I915_READ(DDI_BUF_CTL(port));
  1222. if (!(tmp & DDI_BUF_CTL_ENABLE))
  1223. goto out;
  1224. if (port == PORT_A) {
  1225. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  1226. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  1227. case TRANS_DDI_EDP_INPUT_A_ON:
  1228. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  1229. *pipe = PIPE_A;
  1230. break;
  1231. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  1232. *pipe = PIPE_B;
  1233. break;
  1234. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  1235. *pipe = PIPE_C;
  1236. break;
  1237. }
  1238. ret = true;
  1239. goto out;
  1240. }
  1241. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  1242. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  1243. if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(port)) {
  1244. if ((tmp & TRANS_DDI_MODE_SELECT_MASK) ==
  1245. TRANS_DDI_MODE_SELECT_DP_MST)
  1246. goto out;
  1247. *pipe = i;
  1248. ret = true;
  1249. goto out;
  1250. }
  1251. }
  1252. DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
  1253. out:
  1254. if (ret && IS_GEN9_LP(dev_priv)) {
  1255. tmp = I915_READ(BXT_PHY_CTL(port));
  1256. if ((tmp & (BXT_PHY_LANE_POWERDOWN_ACK |
  1257. BXT_PHY_LANE_ENABLED)) != BXT_PHY_LANE_ENABLED)
  1258. DRM_ERROR("Port %c enabled but PHY powered down? "
  1259. "(PHY_CTL %08x)\n", port_name(port), tmp);
  1260. }
  1261. intel_display_power_put(dev_priv, power_domain);
  1262. return ret;
  1263. }
  1264. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
  1265. {
  1266. struct drm_crtc *crtc = &intel_crtc->base;
  1267. struct drm_device *dev = crtc->dev;
  1268. struct drm_i915_private *dev_priv = to_i915(dev);
  1269. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1270. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1271. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1272. if (cpu_transcoder != TRANSCODER_EDP)
  1273. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1274. TRANS_CLK_SEL_PORT(port));
  1275. }
  1276. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
  1277. {
  1278. struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev);
  1279. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  1280. if (cpu_transcoder != TRANSCODER_EDP)
  1281. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1282. TRANS_CLK_SEL_DISABLED);
  1283. }
  1284. static void _skl_ddi_set_iboost(struct drm_i915_private *dev_priv,
  1285. enum port port, uint8_t iboost)
  1286. {
  1287. u32 tmp;
  1288. tmp = I915_READ(DISPIO_CR_TX_BMU_CR0);
  1289. tmp &= ~(BALANCE_LEG_MASK(port) | BALANCE_LEG_DISABLE(port));
  1290. if (iboost)
  1291. tmp |= iboost << BALANCE_LEG_SHIFT(port);
  1292. else
  1293. tmp |= BALANCE_LEG_DISABLE(port);
  1294. I915_WRITE(DISPIO_CR_TX_BMU_CR0, tmp);
  1295. }
  1296. static void skl_ddi_set_iboost(struct intel_encoder *encoder, u32 level)
  1297. {
  1298. struct intel_digital_port *intel_dig_port = enc_to_dig_port(&encoder->base);
  1299. struct drm_i915_private *dev_priv = to_i915(intel_dig_port->base.base.dev);
  1300. enum port port = intel_dig_port->port;
  1301. int type = encoder->type;
  1302. const struct ddi_buf_trans *ddi_translations;
  1303. uint8_t iboost;
  1304. uint8_t dp_iboost, hdmi_iboost;
  1305. int n_entries;
  1306. /* VBT may override standard boost values */
  1307. dp_iboost = dev_priv->vbt.ddi_port_info[port].dp_boost_level;
  1308. hdmi_iboost = dev_priv->vbt.ddi_port_info[port].hdmi_boost_level;
  1309. if (type == INTEL_OUTPUT_DP) {
  1310. if (dp_iboost) {
  1311. iboost = dp_iboost;
  1312. } else {
  1313. if (IS_KABYLAKE(dev_priv))
  1314. ddi_translations = kbl_get_buf_trans_dp(dev_priv,
  1315. &n_entries);
  1316. else
  1317. ddi_translations = skl_get_buf_trans_dp(dev_priv,
  1318. &n_entries);
  1319. iboost = ddi_translations[level].i_boost;
  1320. }
  1321. } else if (type == INTEL_OUTPUT_EDP) {
  1322. if (dp_iboost) {
  1323. iboost = dp_iboost;
  1324. } else {
  1325. ddi_translations = skl_get_buf_trans_edp(dev_priv, &n_entries);
  1326. if (WARN_ON(port != PORT_A &&
  1327. port != PORT_E && n_entries > 9))
  1328. n_entries = 9;
  1329. iboost = ddi_translations[level].i_boost;
  1330. }
  1331. } else if (type == INTEL_OUTPUT_HDMI) {
  1332. if (hdmi_iboost) {
  1333. iboost = hdmi_iboost;
  1334. } else {
  1335. ddi_translations = skl_get_buf_trans_hdmi(dev_priv, &n_entries);
  1336. iboost = ddi_translations[level].i_boost;
  1337. }
  1338. } else {
  1339. return;
  1340. }
  1341. /* Make sure that the requested I_boost is valid */
  1342. if (iboost && iboost != 0x1 && iboost != 0x3 && iboost != 0x7) {
  1343. DRM_ERROR("Invalid I_boost value %u\n", iboost);
  1344. return;
  1345. }
  1346. _skl_ddi_set_iboost(dev_priv, port, iboost);
  1347. if (port == PORT_A && intel_dig_port->max_lanes == 4)
  1348. _skl_ddi_set_iboost(dev_priv, PORT_E, iboost);
  1349. }
  1350. static void bxt_ddi_vswing_sequence(struct drm_i915_private *dev_priv,
  1351. u32 level, enum port port, int type)
  1352. {
  1353. const struct bxt_ddi_buf_trans *ddi_translations;
  1354. u32 n_entries, i;
  1355. if (type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.low_vswing) {
  1356. n_entries = ARRAY_SIZE(bxt_ddi_translations_edp);
  1357. ddi_translations = bxt_ddi_translations_edp;
  1358. } else if (type == INTEL_OUTPUT_DP
  1359. || type == INTEL_OUTPUT_EDP) {
  1360. n_entries = ARRAY_SIZE(bxt_ddi_translations_dp);
  1361. ddi_translations = bxt_ddi_translations_dp;
  1362. } else if (type == INTEL_OUTPUT_HDMI) {
  1363. n_entries = ARRAY_SIZE(bxt_ddi_translations_hdmi);
  1364. ddi_translations = bxt_ddi_translations_hdmi;
  1365. } else {
  1366. DRM_DEBUG_KMS("Vswing programming not done for encoder %d\n",
  1367. type);
  1368. return;
  1369. }
  1370. /* Check if default value has to be used */
  1371. if (level >= n_entries ||
  1372. (type == INTEL_OUTPUT_HDMI && level == HDMI_LEVEL_SHIFT_UNKNOWN)) {
  1373. for (i = 0; i < n_entries; i++) {
  1374. if (ddi_translations[i].default_index) {
  1375. level = i;
  1376. break;
  1377. }
  1378. }
  1379. }
  1380. bxt_ddi_phy_set_signal_level(dev_priv, port,
  1381. ddi_translations[level].margin,
  1382. ddi_translations[level].scale,
  1383. ddi_translations[level].enable,
  1384. ddi_translations[level].deemphasis);
  1385. }
  1386. static uint32_t translate_signal_level(int signal_levels)
  1387. {
  1388. uint32_t level;
  1389. switch (signal_levels) {
  1390. default:
  1391. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level: 0x%x\n",
  1392. signal_levels);
  1393. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1394. level = 0;
  1395. break;
  1396. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  1397. level = 1;
  1398. break;
  1399. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  1400. level = 2;
  1401. break;
  1402. case DP_TRAIN_VOLTAGE_SWING_LEVEL_0 | DP_TRAIN_PRE_EMPH_LEVEL_3:
  1403. level = 3;
  1404. break;
  1405. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1406. level = 4;
  1407. break;
  1408. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  1409. level = 5;
  1410. break;
  1411. case DP_TRAIN_VOLTAGE_SWING_LEVEL_1 | DP_TRAIN_PRE_EMPH_LEVEL_2:
  1412. level = 6;
  1413. break;
  1414. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1415. level = 7;
  1416. break;
  1417. case DP_TRAIN_VOLTAGE_SWING_LEVEL_2 | DP_TRAIN_PRE_EMPH_LEVEL_1:
  1418. level = 8;
  1419. break;
  1420. case DP_TRAIN_VOLTAGE_SWING_LEVEL_3 | DP_TRAIN_PRE_EMPH_LEVEL_0:
  1421. level = 9;
  1422. break;
  1423. }
  1424. return level;
  1425. }
  1426. uint32_t ddi_signal_levels(struct intel_dp *intel_dp)
  1427. {
  1428. struct intel_digital_port *dport = dp_to_dig_port(intel_dp);
  1429. struct drm_i915_private *dev_priv = to_i915(dport->base.base.dev);
  1430. struct intel_encoder *encoder = &dport->base;
  1431. uint8_t train_set = intel_dp->train_set[0];
  1432. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1433. DP_TRAIN_PRE_EMPHASIS_MASK);
  1434. enum port port = dport->port;
  1435. uint32_t level;
  1436. level = translate_signal_level(signal_levels);
  1437. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  1438. skl_ddi_set_iboost(encoder, level);
  1439. else if (IS_GEN9_LP(dev_priv))
  1440. bxt_ddi_vswing_sequence(dev_priv, level, port, encoder->type);
  1441. return DDI_BUF_TRANS_SELECT(level);
  1442. }
  1443. void intel_ddi_clk_select(struct intel_encoder *encoder,
  1444. struct intel_shared_dpll *pll)
  1445. {
  1446. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1447. enum port port = intel_ddi_get_encoder_port(encoder);
  1448. if (WARN_ON(!pll))
  1449. return;
  1450. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  1451. uint32_t val;
  1452. /* DDI -> PLL mapping */
  1453. val = I915_READ(DPLL_CTRL2);
  1454. val &= ~(DPLL_CTRL2_DDI_CLK_OFF(port) |
  1455. DPLL_CTRL2_DDI_CLK_SEL_MASK(port));
  1456. val |= (DPLL_CTRL2_DDI_CLK_SEL(pll->id, port) |
  1457. DPLL_CTRL2_DDI_SEL_OVERRIDE(port));
  1458. I915_WRITE(DPLL_CTRL2, val);
  1459. } else if (INTEL_INFO(dev_priv)->gen < 9) {
  1460. I915_WRITE(PORT_CLK_SEL(port), hsw_pll_to_ddi_pll_sel(pll));
  1461. }
  1462. }
  1463. static void intel_ddi_pre_enable_dp(struct intel_encoder *encoder,
  1464. int link_rate, uint32_t lane_count,
  1465. struct intel_shared_dpll *pll,
  1466. bool link_mst)
  1467. {
  1468. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1469. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1470. enum port port = intel_ddi_get_encoder_port(encoder);
  1471. intel_dp_set_link_params(intel_dp, link_rate, lane_count,
  1472. link_mst);
  1473. if (encoder->type == INTEL_OUTPUT_EDP)
  1474. intel_edp_panel_on(intel_dp);
  1475. intel_ddi_clk_select(encoder, pll);
  1476. intel_prepare_dp_ddi_buffers(encoder);
  1477. intel_ddi_init_dp_buf_reg(encoder);
  1478. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1479. intel_dp_start_link_train(intel_dp);
  1480. if (port != PORT_A || INTEL_GEN(dev_priv) >= 9)
  1481. intel_dp_stop_link_train(intel_dp);
  1482. }
  1483. static void intel_ddi_pre_enable_hdmi(struct intel_encoder *encoder,
  1484. bool has_hdmi_sink,
  1485. const struct intel_crtc_state *crtc_state,
  1486. const struct drm_connector_state *conn_state,
  1487. struct intel_shared_dpll *pll)
  1488. {
  1489. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1490. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1491. struct drm_encoder *drm_encoder = &encoder->base;
  1492. enum port port = intel_ddi_get_encoder_port(encoder);
  1493. int level = intel_ddi_hdmi_level(dev_priv, port);
  1494. intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
  1495. intel_ddi_clk_select(encoder, pll);
  1496. intel_prepare_hdmi_ddi_buffers(encoder);
  1497. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  1498. skl_ddi_set_iboost(encoder, level);
  1499. else if (IS_GEN9_LP(dev_priv))
  1500. bxt_ddi_vswing_sequence(dev_priv, level, port,
  1501. INTEL_OUTPUT_HDMI);
  1502. intel_hdmi->set_infoframes(drm_encoder,
  1503. has_hdmi_sink,
  1504. crtc_state, conn_state);
  1505. }
  1506. static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder,
  1507. struct intel_crtc_state *pipe_config,
  1508. struct drm_connector_state *conn_state)
  1509. {
  1510. struct drm_encoder *encoder = &intel_encoder->base;
  1511. struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
  1512. int type = intel_encoder->type;
  1513. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1514. intel_ddi_pre_enable_dp(intel_encoder,
  1515. crtc->config->port_clock,
  1516. crtc->config->lane_count,
  1517. crtc->config->shared_dpll,
  1518. intel_crtc_has_type(crtc->config,
  1519. INTEL_OUTPUT_DP_MST));
  1520. }
  1521. if (type == INTEL_OUTPUT_HDMI) {
  1522. intel_ddi_pre_enable_hdmi(intel_encoder,
  1523. pipe_config->has_hdmi_sink,
  1524. pipe_config, conn_state,
  1525. crtc->config->shared_dpll);
  1526. }
  1527. }
  1528. static void intel_ddi_post_disable(struct intel_encoder *intel_encoder,
  1529. struct intel_crtc_state *old_crtc_state,
  1530. struct drm_connector_state *old_conn_state)
  1531. {
  1532. struct drm_encoder *encoder = &intel_encoder->base;
  1533. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  1534. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1535. int type = intel_encoder->type;
  1536. uint32_t val;
  1537. bool wait = false;
  1538. /* old_crtc_state and old_conn_state are NULL when called from DP_MST */
  1539. val = I915_READ(DDI_BUF_CTL(port));
  1540. if (val & DDI_BUF_CTL_ENABLE) {
  1541. val &= ~DDI_BUF_CTL_ENABLE;
  1542. I915_WRITE(DDI_BUF_CTL(port), val);
  1543. wait = true;
  1544. }
  1545. val = I915_READ(DP_TP_CTL(port));
  1546. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1547. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1548. I915_WRITE(DP_TP_CTL(port), val);
  1549. if (wait)
  1550. intel_wait_ddi_buf_idle(dev_priv, port);
  1551. if (type == INTEL_OUTPUT_DP || type == INTEL_OUTPUT_EDP) {
  1552. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1553. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1554. intel_edp_panel_vdd_on(intel_dp);
  1555. intel_edp_panel_off(intel_dp);
  1556. }
  1557. if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))
  1558. I915_WRITE(DPLL_CTRL2, (I915_READ(DPLL_CTRL2) |
  1559. DPLL_CTRL2_DDI_CLK_OFF(port)));
  1560. else if (INTEL_GEN(dev_priv) < 9)
  1561. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1562. if (type == INTEL_OUTPUT_HDMI) {
  1563. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  1564. intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
  1565. }
  1566. }
  1567. void intel_ddi_fdi_post_disable(struct intel_encoder *intel_encoder,
  1568. struct intel_crtc_state *old_crtc_state,
  1569. struct drm_connector_state *old_conn_state)
  1570. {
  1571. struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev);
  1572. uint32_t val;
  1573. /*
  1574. * Bspec lists this as both step 13 (before DDI_BUF_CTL disable)
  1575. * and step 18 (after clearing PORT_CLK_SEL). Based on a BUN,
  1576. * step 13 is the correct place for it. Step 18 is where it was
  1577. * originally before the BUN.
  1578. */
  1579. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1580. val &= ~FDI_RX_ENABLE;
  1581. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1582. intel_ddi_post_disable(intel_encoder, old_crtc_state, old_conn_state);
  1583. val = I915_READ(FDI_RX_MISC(PIPE_A));
  1584. val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  1585. val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  1586. I915_WRITE(FDI_RX_MISC(PIPE_A), val);
  1587. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1588. val &= ~FDI_PCDCLK;
  1589. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1590. val = I915_READ(FDI_RX_CTL(PIPE_A));
  1591. val &= ~FDI_RX_PLL_ENABLE;
  1592. I915_WRITE(FDI_RX_CTL(PIPE_A), val);
  1593. }
  1594. static void intel_enable_ddi(struct intel_encoder *intel_encoder,
  1595. struct intel_crtc_state *pipe_config,
  1596. struct drm_connector_state *conn_state)
  1597. {
  1598. struct drm_encoder *encoder = &intel_encoder->base;
  1599. struct drm_crtc *crtc = encoder->crtc;
  1600. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1601. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  1602. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1603. int type = intel_encoder->type;
  1604. if (type == INTEL_OUTPUT_HDMI) {
  1605. struct intel_digital_port *intel_dig_port =
  1606. enc_to_dig_port(encoder);
  1607. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  1608. * are ignored so nothing special needs to be done besides
  1609. * enabling the port.
  1610. */
  1611. I915_WRITE(DDI_BUF_CTL(port),
  1612. intel_dig_port->saved_port_bits |
  1613. DDI_BUF_CTL_ENABLE);
  1614. } else if (type == INTEL_OUTPUT_EDP) {
  1615. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1616. if (port == PORT_A && INTEL_GEN(dev_priv) < 9)
  1617. intel_dp_stop_link_train(intel_dp);
  1618. intel_edp_backlight_on(intel_dp);
  1619. intel_psr_enable(intel_dp);
  1620. intel_edp_drrs_enable(intel_dp, pipe_config);
  1621. }
  1622. if (intel_crtc->config->has_audio) {
  1623. intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
  1624. intel_audio_codec_enable(intel_encoder, pipe_config, conn_state);
  1625. }
  1626. }
  1627. static void intel_disable_ddi(struct intel_encoder *intel_encoder,
  1628. struct intel_crtc_state *old_crtc_state,
  1629. struct drm_connector_state *old_conn_state)
  1630. {
  1631. struct drm_encoder *encoder = &intel_encoder->base;
  1632. struct drm_crtc *crtc = encoder->crtc;
  1633. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1634. int type = intel_encoder->type;
  1635. struct drm_device *dev = encoder->dev;
  1636. struct drm_i915_private *dev_priv = to_i915(dev);
  1637. if (intel_crtc->config->has_audio) {
  1638. intel_audio_codec_disable(intel_encoder);
  1639. intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
  1640. }
  1641. if (type == INTEL_OUTPUT_EDP) {
  1642. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1643. intel_edp_drrs_disable(intel_dp, old_crtc_state);
  1644. intel_psr_disable(intel_dp);
  1645. intel_edp_backlight_off(intel_dp);
  1646. }
  1647. }
  1648. static void bxt_ddi_pre_pll_enable(struct intel_encoder *encoder,
  1649. struct intel_crtc_state *pipe_config,
  1650. struct drm_connector_state *conn_state)
  1651. {
  1652. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1653. uint8_t mask = intel_crtc->config->lane_lat_optim_mask;
  1654. bxt_ddi_phy_set_lane_optim_mask(encoder, mask);
  1655. }
  1656. void intel_ddi_prepare_link_retrain(struct intel_dp *intel_dp)
  1657. {
  1658. struct intel_digital_port *intel_dig_port = dp_to_dig_port(intel_dp);
  1659. struct drm_i915_private *dev_priv =
  1660. to_i915(intel_dig_port->base.base.dev);
  1661. enum port port = intel_dig_port->port;
  1662. uint32_t val;
  1663. bool wait = false;
  1664. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  1665. val = I915_READ(DDI_BUF_CTL(port));
  1666. if (val & DDI_BUF_CTL_ENABLE) {
  1667. val &= ~DDI_BUF_CTL_ENABLE;
  1668. I915_WRITE(DDI_BUF_CTL(port), val);
  1669. wait = true;
  1670. }
  1671. val = I915_READ(DP_TP_CTL(port));
  1672. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1673. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1674. I915_WRITE(DP_TP_CTL(port), val);
  1675. POSTING_READ(DP_TP_CTL(port));
  1676. if (wait)
  1677. intel_wait_ddi_buf_idle(dev_priv, port);
  1678. }
  1679. val = DP_TP_CTL_ENABLE |
  1680. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  1681. if (intel_dp->link_mst)
  1682. val |= DP_TP_CTL_MODE_MST;
  1683. else {
  1684. val |= DP_TP_CTL_MODE_SST;
  1685. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1686. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  1687. }
  1688. I915_WRITE(DP_TP_CTL(port), val);
  1689. POSTING_READ(DP_TP_CTL(port));
  1690. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  1691. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  1692. POSTING_READ(DDI_BUF_CTL(port));
  1693. udelay(600);
  1694. }
  1695. bool intel_ddi_is_audio_enabled(struct drm_i915_private *dev_priv,
  1696. struct intel_crtc *intel_crtc)
  1697. {
  1698. u32 temp;
  1699. if (intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
  1700. temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1701. if (temp & AUDIO_OUTPUT_ENABLE(intel_crtc->pipe))
  1702. return true;
  1703. }
  1704. return false;
  1705. }
  1706. void intel_ddi_get_config(struct intel_encoder *encoder,
  1707. struct intel_crtc_state *pipe_config)
  1708. {
  1709. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1710. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1711. enum transcoder cpu_transcoder = pipe_config->cpu_transcoder;
  1712. struct intel_hdmi *intel_hdmi;
  1713. u32 temp, flags = 0;
  1714. /* XXX: DSI transcoder paranoia */
  1715. if (WARN_ON(transcoder_is_dsi(cpu_transcoder)))
  1716. return;
  1717. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1718. if (temp & TRANS_DDI_PHSYNC)
  1719. flags |= DRM_MODE_FLAG_PHSYNC;
  1720. else
  1721. flags |= DRM_MODE_FLAG_NHSYNC;
  1722. if (temp & TRANS_DDI_PVSYNC)
  1723. flags |= DRM_MODE_FLAG_PVSYNC;
  1724. else
  1725. flags |= DRM_MODE_FLAG_NVSYNC;
  1726. pipe_config->base.adjusted_mode.flags |= flags;
  1727. switch (temp & TRANS_DDI_BPC_MASK) {
  1728. case TRANS_DDI_BPC_6:
  1729. pipe_config->pipe_bpp = 18;
  1730. break;
  1731. case TRANS_DDI_BPC_8:
  1732. pipe_config->pipe_bpp = 24;
  1733. break;
  1734. case TRANS_DDI_BPC_10:
  1735. pipe_config->pipe_bpp = 30;
  1736. break;
  1737. case TRANS_DDI_BPC_12:
  1738. pipe_config->pipe_bpp = 36;
  1739. break;
  1740. default:
  1741. break;
  1742. }
  1743. switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
  1744. case TRANS_DDI_MODE_SELECT_HDMI:
  1745. pipe_config->has_hdmi_sink = true;
  1746. intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1747. if (intel_hdmi->infoframe_enabled(&encoder->base, pipe_config))
  1748. pipe_config->has_infoframe = true;
  1749. /* fall through */
  1750. case TRANS_DDI_MODE_SELECT_DVI:
  1751. pipe_config->lane_count = 4;
  1752. break;
  1753. case TRANS_DDI_MODE_SELECT_FDI:
  1754. break;
  1755. case TRANS_DDI_MODE_SELECT_DP_SST:
  1756. case TRANS_DDI_MODE_SELECT_DP_MST:
  1757. pipe_config->lane_count =
  1758. ((temp & DDI_PORT_WIDTH_MASK) >> DDI_PORT_WIDTH_SHIFT) + 1;
  1759. intel_dp_get_m_n(intel_crtc, pipe_config);
  1760. break;
  1761. default:
  1762. break;
  1763. }
  1764. pipe_config->has_audio =
  1765. intel_ddi_is_audio_enabled(dev_priv, intel_crtc);
  1766. if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp.bpp &&
  1767. pipe_config->pipe_bpp > dev_priv->vbt.edp.bpp) {
  1768. /*
  1769. * This is a big fat ugly hack.
  1770. *
  1771. * Some machines in UEFI boot mode provide us a VBT that has 18
  1772. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1773. * unknown we fail to light up. Yet the same BIOS boots up with
  1774. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1775. * max, not what it tells us to use.
  1776. *
  1777. * Note: This will still be broken if the eDP panel is not lit
  1778. * up by the BIOS, and thus we can't get the mode at module
  1779. * load.
  1780. */
  1781. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1782. pipe_config->pipe_bpp, dev_priv->vbt.edp.bpp);
  1783. dev_priv->vbt.edp.bpp = pipe_config->pipe_bpp;
  1784. }
  1785. intel_ddi_clock_get(encoder, pipe_config);
  1786. if (IS_GEN9_LP(dev_priv))
  1787. pipe_config->lane_lat_optim_mask =
  1788. bxt_ddi_phy_get_lane_lat_optim_mask(encoder);
  1789. }
  1790. static bool intel_ddi_compute_config(struct intel_encoder *encoder,
  1791. struct intel_crtc_state *pipe_config,
  1792. struct drm_connector_state *conn_state)
  1793. {
  1794. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1795. int type = encoder->type;
  1796. int port = intel_ddi_get_encoder_port(encoder);
  1797. int ret;
  1798. WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
  1799. if (port == PORT_A)
  1800. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  1801. if (type == INTEL_OUTPUT_HDMI)
  1802. ret = intel_hdmi_compute_config(encoder, pipe_config, conn_state);
  1803. else
  1804. ret = intel_dp_compute_config(encoder, pipe_config, conn_state);
  1805. if (IS_GEN9_LP(dev_priv) && ret)
  1806. pipe_config->lane_lat_optim_mask =
  1807. bxt_ddi_phy_calc_lane_lat_optim_mask(encoder,
  1808. pipe_config->lane_count);
  1809. return ret;
  1810. }
  1811. static const struct drm_encoder_funcs intel_ddi_funcs = {
  1812. .reset = intel_dp_encoder_reset,
  1813. .destroy = intel_dp_encoder_destroy,
  1814. };
  1815. static struct intel_connector *
  1816. intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
  1817. {
  1818. struct intel_connector *connector;
  1819. enum port port = intel_dig_port->port;
  1820. connector = intel_connector_alloc();
  1821. if (!connector)
  1822. return NULL;
  1823. intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
  1824. if (!intel_dp_init_connector(intel_dig_port, connector)) {
  1825. kfree(connector);
  1826. return NULL;
  1827. }
  1828. return connector;
  1829. }
  1830. static struct intel_connector *
  1831. intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
  1832. {
  1833. struct intel_connector *connector;
  1834. enum port port = intel_dig_port->port;
  1835. connector = intel_connector_alloc();
  1836. if (!connector)
  1837. return NULL;
  1838. intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
  1839. intel_hdmi_init_connector(intel_dig_port, connector);
  1840. return connector;
  1841. }
  1842. struct intel_shared_dpll *
  1843. intel_ddi_get_link_dpll(struct intel_dp *intel_dp, int clock)
  1844. {
  1845. struct intel_connector *connector = intel_dp->attached_connector;
  1846. struct intel_encoder *encoder = connector->encoder;
  1847. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1848. struct intel_digital_port *dig_port = dp_to_dig_port(intel_dp);
  1849. struct intel_shared_dpll *pll = NULL;
  1850. struct intel_shared_dpll_state tmp_pll_state;
  1851. enum intel_dpll_id dpll_id;
  1852. if (IS_GEN9_LP(dev_priv)) {
  1853. dpll_id = (enum intel_dpll_id)dig_port->port;
  1854. /*
  1855. * Select the required PLL. This works for platforms where
  1856. * there is no shared DPLL.
  1857. */
  1858. pll = &dev_priv->shared_dplls[dpll_id];
  1859. if (WARN_ON(pll->active_mask)) {
  1860. DRM_ERROR("Shared DPLL in use. active_mask:%x\n",
  1861. pll->active_mask);
  1862. return NULL;
  1863. }
  1864. tmp_pll_state = pll->state;
  1865. if (!bxt_ddi_dp_set_dpll_hw_state(clock,
  1866. &pll->state.hw_state)) {
  1867. DRM_ERROR("Could not setup DPLL\n");
  1868. pll->state = tmp_pll_state;
  1869. return NULL;
  1870. }
  1871. } else if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  1872. pll = skl_find_link_pll(dev_priv, clock);
  1873. } else if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) {
  1874. pll = hsw_ddi_dp_get_dpll(encoder, clock);
  1875. }
  1876. return pll;
  1877. }
  1878. void intel_ddi_init(struct drm_i915_private *dev_priv, enum port port)
  1879. {
  1880. struct intel_digital_port *intel_dig_port;
  1881. struct intel_encoder *intel_encoder;
  1882. struct drm_encoder *encoder;
  1883. bool init_hdmi, init_dp, init_lspcon = false;
  1884. int max_lanes;
  1885. if (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES) {
  1886. switch (port) {
  1887. case PORT_A:
  1888. max_lanes = 4;
  1889. break;
  1890. case PORT_E:
  1891. max_lanes = 0;
  1892. break;
  1893. default:
  1894. max_lanes = 4;
  1895. break;
  1896. }
  1897. } else {
  1898. switch (port) {
  1899. case PORT_A:
  1900. max_lanes = 2;
  1901. break;
  1902. case PORT_E:
  1903. max_lanes = 2;
  1904. break;
  1905. default:
  1906. max_lanes = 4;
  1907. break;
  1908. }
  1909. }
  1910. init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
  1911. dev_priv->vbt.ddi_port_info[port].supports_hdmi);
  1912. init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
  1913. if (intel_bios_is_lspcon_present(dev_priv, port)) {
  1914. /*
  1915. * Lspcon device needs to be driven with DP connector
  1916. * with special detection sequence. So make sure DP
  1917. * is initialized before lspcon.
  1918. */
  1919. init_dp = true;
  1920. init_lspcon = true;
  1921. init_hdmi = false;
  1922. DRM_DEBUG_KMS("VBT says port %c has lspcon\n", port_name(port));
  1923. }
  1924. if (!init_dp && !init_hdmi) {
  1925. DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible, respect it\n",
  1926. port_name(port));
  1927. return;
  1928. }
  1929. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  1930. if (!intel_dig_port)
  1931. return;
  1932. intel_encoder = &intel_dig_port->base;
  1933. encoder = &intel_encoder->base;
  1934. drm_encoder_init(&dev_priv->drm, encoder, &intel_ddi_funcs,
  1935. DRM_MODE_ENCODER_TMDS, "DDI %c", port_name(port));
  1936. intel_encoder->compute_config = intel_ddi_compute_config;
  1937. intel_encoder->enable = intel_enable_ddi;
  1938. if (IS_GEN9_LP(dev_priv))
  1939. intel_encoder->pre_pll_enable = bxt_ddi_pre_pll_enable;
  1940. intel_encoder->pre_enable = intel_ddi_pre_enable;
  1941. intel_encoder->disable = intel_disable_ddi;
  1942. intel_encoder->post_disable = intel_ddi_post_disable;
  1943. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  1944. intel_encoder->get_config = intel_ddi_get_config;
  1945. intel_encoder->suspend = intel_dp_encoder_suspend;
  1946. intel_dig_port->port = port;
  1947. intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
  1948. (DDI_BUF_PORT_REVERSAL |
  1949. DDI_A_4_LANES);
  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->port = port;
  1967. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1968. intel_encoder->cloneable = 0;
  1969. if (init_dp) {
  1970. if (!intel_ddi_init_dp_connector(intel_dig_port))
  1971. goto err;
  1972. intel_dig_port->hpd_pulse = intel_dp_hpd_pulse;
  1973. /*
  1974. * On BXT A0/A1, sw needs to activate DDIA HPD logic and
  1975. * interrupts to check the external panel connection.
  1976. */
  1977. if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_A1) && port == PORT_B)
  1978. dev_priv->hotplug.irq_port[PORT_A] = intel_dig_port;
  1979. else
  1980. dev_priv->hotplug.irq_port[port] = intel_dig_port;
  1981. }
  1982. /* In theory we don't need the encoder->type check, but leave it just in
  1983. * case we have some really bad VBTs... */
  1984. if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi) {
  1985. if (!intel_ddi_init_hdmi_connector(intel_dig_port))
  1986. goto err;
  1987. }
  1988. if (init_lspcon) {
  1989. if (lspcon_init(intel_dig_port))
  1990. /* TODO: handle hdmi info frame part */
  1991. DRM_DEBUG_KMS("LSPCON init success on port %c\n",
  1992. port_name(port));
  1993. else
  1994. /*
  1995. * LSPCON init faied, but DP init was success, so
  1996. * lets try to drive as DP++ port.
  1997. */
  1998. DRM_ERROR("LSPCON init failed on port %c\n",
  1999. port_name(port));
  2000. }
  2001. return;
  2002. err:
  2003. drm_encoder_cleanup(encoder);
  2004. kfree(intel_dig_port);
  2005. }