intel_ddi.c 67 KB

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