intel_ddi.c 66 KB

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