intel_ddi.c 82 KB

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