intel_ddi.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720
  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. /* HDMI/DVI modes ignore everything but the last 2 items. So we share
  30. * them for both DP and FDI transports, allowing those ports to
  31. * automatically adapt to HDMI connections as well
  32. */
  33. static const u32 hsw_ddi_translations_dp[] = {
  34. 0x00FFFFFF, 0x0006000E, /* DP parameters */
  35. 0x00D75FFF, 0x0005000A,
  36. 0x00C30FFF, 0x00040006,
  37. 0x80AAAFFF, 0x000B0000,
  38. 0x00FFFFFF, 0x0005000A,
  39. 0x00D75FFF, 0x000C0004,
  40. 0x80C30FFF, 0x000B0000,
  41. 0x00FFFFFF, 0x00040006,
  42. 0x80D75FFF, 0x000B0000,
  43. };
  44. static const u32 hsw_ddi_translations_fdi[] = {
  45. 0x00FFFFFF, 0x0007000E, /* FDI parameters */
  46. 0x00D75FFF, 0x000F000A,
  47. 0x00C30FFF, 0x00060006,
  48. 0x00AAAFFF, 0x001E0000,
  49. 0x00FFFFFF, 0x000F000A,
  50. 0x00D75FFF, 0x00160004,
  51. 0x00C30FFF, 0x001E0000,
  52. 0x00FFFFFF, 0x00060006,
  53. 0x00D75FFF, 0x001E0000,
  54. };
  55. static const u32 hsw_ddi_translations_hdmi[] = {
  56. /* Idx NT mV diff T mV diff db */
  57. 0x00FFFFFF, 0x0006000E, /* 0: 400 400 0 */
  58. 0x00E79FFF, 0x000E000C, /* 1: 400 500 2 */
  59. 0x00D75FFF, 0x0005000A, /* 2: 400 600 3.5 */
  60. 0x00FFFFFF, 0x0005000A, /* 3: 600 600 0 */
  61. 0x00E79FFF, 0x001D0007, /* 4: 600 750 2 */
  62. 0x00D75FFF, 0x000C0004, /* 5: 600 900 3.5 */
  63. 0x00FFFFFF, 0x00040006, /* 6: 800 800 0 */
  64. 0x80E79FFF, 0x00030002, /* 7: 800 1000 2 */
  65. 0x00FFFFFF, 0x00140005, /* 8: 850 850 0 */
  66. 0x00FFFFFF, 0x000C0004, /* 9: 900 900 0 */
  67. 0x00FFFFFF, 0x001C0003, /* 10: 950 950 0 */
  68. 0x80FFFFFF, 0x00030002, /* 11: 1000 1000 0 */
  69. };
  70. static const u32 bdw_ddi_translations_edp[] = {
  71. 0x00FFFFFF, 0x00000012, /* eDP parameters */
  72. 0x00EBAFFF, 0x00020011,
  73. 0x00C71FFF, 0x0006000F,
  74. 0x00FFFFFF, 0x00020011,
  75. 0x00DB6FFF, 0x0005000F,
  76. 0x00BEEFFF, 0x000A000C,
  77. 0x00FFFFFF, 0x0005000F,
  78. 0x00DB6FFF, 0x000A000C,
  79. 0x00FFFFFF, 0x000A000C,
  80. 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/
  81. };
  82. static const u32 bdw_ddi_translations_dp[] = {
  83. 0x00FFFFFF, 0x0007000E, /* DP parameters */
  84. 0x00D75FFF, 0x000E000A,
  85. 0x00BEFFFF, 0x00140006,
  86. 0x00FFFFFF, 0x000E000A,
  87. 0x00D75FFF, 0x00180004,
  88. 0x80CB2FFF, 0x001B0002,
  89. 0x00F7DFFF, 0x00180004,
  90. 0x80D75FFF, 0x001B0002,
  91. 0x80FFFFFF, 0x001B0002,
  92. 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/
  93. };
  94. static const u32 bdw_ddi_translations_fdi[] = {
  95. 0x00FFFFFF, 0x0001000E, /* FDI parameters */
  96. 0x00D75FFF, 0x0004000A,
  97. 0x00C30FFF, 0x00070006,
  98. 0x00AAAFFF, 0x000C0000,
  99. 0x00FFFFFF, 0x0004000A,
  100. 0x00D75FFF, 0x00090004,
  101. 0x00C30FFF, 0x000C0000,
  102. 0x00FFFFFF, 0x00070006,
  103. 0x00D75FFF, 0x000C0000,
  104. 0x00FFFFFF, 0x00140006 /* HDMI parameters 800mV 0dB*/
  105. };
  106. enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
  107. {
  108. struct drm_encoder *encoder = &intel_encoder->base;
  109. int type = intel_encoder->type;
  110. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
  111. type == INTEL_OUTPUT_HDMI || type == INTEL_OUTPUT_UNKNOWN) {
  112. struct intel_digital_port *intel_dig_port =
  113. enc_to_dig_port(encoder);
  114. return intel_dig_port->port;
  115. } else if (type == INTEL_OUTPUT_ANALOG) {
  116. return PORT_E;
  117. } else {
  118. DRM_ERROR("Invalid DDI encoder type %d\n", type);
  119. BUG();
  120. }
  121. }
  122. /*
  123. * Starting with Haswell, DDI port buffers must be programmed with correct
  124. * values in advance. The buffer values are different for FDI and DP modes,
  125. * but the HDMI/DVI fields are shared among those. So we program the DDI
  126. * in either FDI or DP modes only, as HDMI connections will work with both
  127. * of those
  128. */
  129. static void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port)
  130. {
  131. struct drm_i915_private *dev_priv = dev->dev_private;
  132. u32 reg;
  133. int i;
  134. int hdmi_level = dev_priv->vbt.ddi_port_info[port].hdmi_level_shift;
  135. const u32 *ddi_translations_fdi;
  136. const u32 *ddi_translations_dp;
  137. const u32 *ddi_translations_edp;
  138. const u32 *ddi_translations;
  139. if (IS_BROADWELL(dev)) {
  140. ddi_translations_fdi = bdw_ddi_translations_fdi;
  141. ddi_translations_dp = bdw_ddi_translations_dp;
  142. ddi_translations_edp = bdw_ddi_translations_edp;
  143. } else if (IS_HASWELL(dev)) {
  144. ddi_translations_fdi = hsw_ddi_translations_fdi;
  145. ddi_translations_dp = hsw_ddi_translations_dp;
  146. ddi_translations_edp = hsw_ddi_translations_dp;
  147. } else {
  148. WARN(1, "ddi translation table missing\n");
  149. ddi_translations_edp = bdw_ddi_translations_dp;
  150. ddi_translations_fdi = bdw_ddi_translations_fdi;
  151. ddi_translations_dp = bdw_ddi_translations_dp;
  152. }
  153. switch (port) {
  154. case PORT_A:
  155. ddi_translations = ddi_translations_edp;
  156. break;
  157. case PORT_B:
  158. case PORT_C:
  159. ddi_translations = ddi_translations_dp;
  160. break;
  161. case PORT_D:
  162. if (intel_dp_is_edp(dev, PORT_D))
  163. ddi_translations = ddi_translations_edp;
  164. else
  165. ddi_translations = ddi_translations_dp;
  166. break;
  167. case PORT_E:
  168. ddi_translations = ddi_translations_fdi;
  169. break;
  170. default:
  171. BUG();
  172. }
  173. for (i = 0, reg = DDI_BUF_TRANS(port);
  174. i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
  175. I915_WRITE(reg, ddi_translations[i]);
  176. reg += 4;
  177. }
  178. /* Entry 9 is for HDMI: */
  179. for (i = 0; i < 2; i++) {
  180. I915_WRITE(reg, hsw_ddi_translations_hdmi[hdmi_level * 2 + i]);
  181. reg += 4;
  182. }
  183. }
  184. /* Program DDI buffers translations for DP. By default, program ports A-D in DP
  185. * mode and port E for FDI.
  186. */
  187. void intel_prepare_ddi(struct drm_device *dev)
  188. {
  189. int port;
  190. if (!HAS_DDI(dev))
  191. return;
  192. for (port = PORT_A; port <= PORT_E; port++)
  193. intel_prepare_ddi_buffers(dev, port);
  194. }
  195. static const long hsw_ddi_buf_ctl_values[] = {
  196. DDI_BUF_EMP_400MV_0DB_HSW,
  197. DDI_BUF_EMP_400MV_3_5DB_HSW,
  198. DDI_BUF_EMP_400MV_6DB_HSW,
  199. DDI_BUF_EMP_400MV_9_5DB_HSW,
  200. DDI_BUF_EMP_600MV_0DB_HSW,
  201. DDI_BUF_EMP_600MV_3_5DB_HSW,
  202. DDI_BUF_EMP_600MV_6DB_HSW,
  203. DDI_BUF_EMP_800MV_0DB_HSW,
  204. DDI_BUF_EMP_800MV_3_5DB_HSW
  205. };
  206. static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
  207. enum port port)
  208. {
  209. uint32_t reg = DDI_BUF_CTL(port);
  210. int i;
  211. for (i = 0; i < 8; i++) {
  212. udelay(1);
  213. if (I915_READ(reg) & DDI_BUF_IS_IDLE)
  214. return;
  215. }
  216. DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
  217. }
  218. /* Starting with Haswell, different DDI ports can work in FDI mode for
  219. * connection to the PCH-located connectors. For this, it is necessary to train
  220. * both the DDI port and PCH receiver for the desired DDI buffer settings.
  221. *
  222. * The recommended port to work in FDI mode is DDI E, which we use here. Also,
  223. * please note that when FDI mode is active on DDI E, it shares 2 lines with
  224. * DDI A (which is used for eDP)
  225. */
  226. void hsw_fdi_link_train(struct drm_crtc *crtc)
  227. {
  228. struct drm_device *dev = crtc->dev;
  229. struct drm_i915_private *dev_priv = dev->dev_private;
  230. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  231. u32 temp, i, rx_ctl_val;
  232. /* Set the FDI_RX_MISC pwrdn lanes and the 2 workarounds listed at the
  233. * mode set "sequence for CRT port" document:
  234. * - TP1 to TP2 time with the default value
  235. * - FDI delay to 90h
  236. *
  237. * WaFDIAutoLinkSetTimingOverrride:hsw
  238. */
  239. I915_WRITE(_FDI_RXA_MISC, FDI_RX_PWRDN_LANE1_VAL(2) |
  240. FDI_RX_PWRDN_LANE0_VAL(2) |
  241. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  242. /* Enable the PCH Receiver FDI PLL */
  243. rx_ctl_val = dev_priv->fdi_rx_config | FDI_RX_ENHANCE_FRAME_ENABLE |
  244. FDI_RX_PLL_ENABLE |
  245. FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes);
  246. I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
  247. POSTING_READ(_FDI_RXA_CTL);
  248. udelay(220);
  249. /* Switch from Rawclk to PCDclk */
  250. rx_ctl_val |= FDI_PCDCLK;
  251. I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
  252. /* Configure Port Clock Select */
  253. I915_WRITE(PORT_CLK_SEL(PORT_E), intel_crtc->ddi_pll_sel);
  254. /* Start the training iterating through available voltages and emphasis,
  255. * testing each value twice. */
  256. for (i = 0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values) * 2; i++) {
  257. /* Configure DP_TP_CTL with auto-training */
  258. I915_WRITE(DP_TP_CTL(PORT_E),
  259. DP_TP_CTL_FDI_AUTOTRAIN |
  260. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  261. DP_TP_CTL_LINK_TRAIN_PAT1 |
  262. DP_TP_CTL_ENABLE);
  263. /* Configure and enable DDI_BUF_CTL for DDI E with next voltage.
  264. * DDI E does not support port reversal, the functionality is
  265. * achieved on the PCH side in FDI_RX_CTL, so no need to set the
  266. * port reversal bit */
  267. I915_WRITE(DDI_BUF_CTL(PORT_E),
  268. DDI_BUF_CTL_ENABLE |
  269. ((intel_crtc->config.fdi_lanes - 1) << 1) |
  270. hsw_ddi_buf_ctl_values[i / 2]);
  271. POSTING_READ(DDI_BUF_CTL(PORT_E));
  272. udelay(600);
  273. /* Program PCH FDI Receiver TU */
  274. I915_WRITE(_FDI_RXA_TUSIZE1, TU_SIZE(64));
  275. /* Enable PCH FDI Receiver with auto-training */
  276. rx_ctl_val |= FDI_RX_ENABLE | FDI_LINK_TRAIN_AUTO;
  277. I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
  278. POSTING_READ(_FDI_RXA_CTL);
  279. /* Wait for FDI receiver lane calibration */
  280. udelay(30);
  281. /* Unset FDI_RX_MISC pwrdn lanes */
  282. temp = I915_READ(_FDI_RXA_MISC);
  283. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  284. I915_WRITE(_FDI_RXA_MISC, temp);
  285. POSTING_READ(_FDI_RXA_MISC);
  286. /* Wait for FDI auto training time */
  287. udelay(5);
  288. temp = I915_READ(DP_TP_STATUS(PORT_E));
  289. if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
  290. DRM_DEBUG_KMS("FDI link training done on step %d\n", i);
  291. /* Enable normal pixel sending for FDI */
  292. I915_WRITE(DP_TP_CTL(PORT_E),
  293. DP_TP_CTL_FDI_AUTOTRAIN |
  294. DP_TP_CTL_LINK_TRAIN_NORMAL |
  295. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  296. DP_TP_CTL_ENABLE);
  297. return;
  298. }
  299. temp = I915_READ(DDI_BUF_CTL(PORT_E));
  300. temp &= ~DDI_BUF_CTL_ENABLE;
  301. I915_WRITE(DDI_BUF_CTL(PORT_E), temp);
  302. POSTING_READ(DDI_BUF_CTL(PORT_E));
  303. /* Disable DP_TP_CTL and FDI_RX_CTL and retry */
  304. temp = I915_READ(DP_TP_CTL(PORT_E));
  305. temp &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  306. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  307. I915_WRITE(DP_TP_CTL(PORT_E), temp);
  308. POSTING_READ(DP_TP_CTL(PORT_E));
  309. intel_wait_ddi_buf_idle(dev_priv, PORT_E);
  310. rx_ctl_val &= ~FDI_RX_ENABLE;
  311. I915_WRITE(_FDI_RXA_CTL, rx_ctl_val);
  312. POSTING_READ(_FDI_RXA_CTL);
  313. /* Reset FDI_RX_MISC pwrdn lanes */
  314. temp = I915_READ(_FDI_RXA_MISC);
  315. temp &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  316. temp |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  317. I915_WRITE(_FDI_RXA_MISC, temp);
  318. POSTING_READ(_FDI_RXA_MISC);
  319. }
  320. DRM_ERROR("FDI link training failed!\n");
  321. }
  322. static struct intel_encoder *
  323. intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
  324. {
  325. struct drm_device *dev = crtc->dev;
  326. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  327. struct intel_encoder *intel_encoder, *ret = NULL;
  328. int num_encoders = 0;
  329. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  330. ret = intel_encoder;
  331. num_encoders++;
  332. }
  333. if (num_encoders != 1)
  334. WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
  335. pipe_name(intel_crtc->pipe));
  336. BUG_ON(ret == NULL);
  337. return ret;
  338. }
  339. void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
  340. {
  341. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  342. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  343. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  344. uint32_t val;
  345. switch (intel_crtc->ddi_pll_sel) {
  346. case PORT_CLK_SEL_SPLL:
  347. plls->spll_refcount--;
  348. if (plls->spll_refcount == 0) {
  349. DRM_DEBUG_KMS("Disabling SPLL\n");
  350. val = I915_READ(SPLL_CTL);
  351. WARN_ON(!(val & SPLL_PLL_ENABLE));
  352. I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
  353. POSTING_READ(SPLL_CTL);
  354. }
  355. break;
  356. case PORT_CLK_SEL_WRPLL1:
  357. plls->wrpll1_refcount--;
  358. if (plls->wrpll1_refcount == 0) {
  359. DRM_DEBUG_KMS("Disabling WRPLL 1\n");
  360. val = I915_READ(WRPLL_CTL1);
  361. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  362. I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
  363. POSTING_READ(WRPLL_CTL1);
  364. }
  365. break;
  366. case PORT_CLK_SEL_WRPLL2:
  367. plls->wrpll2_refcount--;
  368. if (plls->wrpll2_refcount == 0) {
  369. DRM_DEBUG_KMS("Disabling WRPLL 2\n");
  370. val = I915_READ(WRPLL_CTL2);
  371. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  372. I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
  373. POSTING_READ(WRPLL_CTL2);
  374. }
  375. break;
  376. }
  377. WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
  378. WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
  379. WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
  380. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
  381. }
  382. #define LC_FREQ 2700
  383. #define LC_FREQ_2K (LC_FREQ * 2000)
  384. #define P_MIN 2
  385. #define P_MAX 64
  386. #define P_INC 2
  387. /* Constraints for PLL good behavior */
  388. #define REF_MIN 48
  389. #define REF_MAX 400
  390. #define VCO_MIN 2400
  391. #define VCO_MAX 4800
  392. #define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
  393. struct wrpll_rnp {
  394. unsigned p, n2, r2;
  395. };
  396. static unsigned wrpll_get_budget_for_freq(int clock)
  397. {
  398. unsigned budget;
  399. switch (clock) {
  400. case 25175000:
  401. case 25200000:
  402. case 27000000:
  403. case 27027000:
  404. case 37762500:
  405. case 37800000:
  406. case 40500000:
  407. case 40541000:
  408. case 54000000:
  409. case 54054000:
  410. case 59341000:
  411. case 59400000:
  412. case 72000000:
  413. case 74176000:
  414. case 74250000:
  415. case 81000000:
  416. case 81081000:
  417. case 89012000:
  418. case 89100000:
  419. case 108000000:
  420. case 108108000:
  421. case 111264000:
  422. case 111375000:
  423. case 148352000:
  424. case 148500000:
  425. case 162000000:
  426. case 162162000:
  427. case 222525000:
  428. case 222750000:
  429. case 296703000:
  430. case 297000000:
  431. budget = 0;
  432. break;
  433. case 233500000:
  434. case 245250000:
  435. case 247750000:
  436. case 253250000:
  437. case 298000000:
  438. budget = 1500;
  439. break;
  440. case 169128000:
  441. case 169500000:
  442. case 179500000:
  443. case 202000000:
  444. budget = 2000;
  445. break;
  446. case 256250000:
  447. case 262500000:
  448. case 270000000:
  449. case 272500000:
  450. case 273750000:
  451. case 280750000:
  452. case 281250000:
  453. case 286000000:
  454. case 291750000:
  455. budget = 4000;
  456. break;
  457. case 267250000:
  458. case 268500000:
  459. budget = 5000;
  460. break;
  461. default:
  462. budget = 1000;
  463. break;
  464. }
  465. return budget;
  466. }
  467. static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
  468. unsigned r2, unsigned n2, unsigned p,
  469. struct wrpll_rnp *best)
  470. {
  471. uint64_t a, b, c, d, diff, diff_best;
  472. /* No best (r,n,p) yet */
  473. if (best->p == 0) {
  474. best->p = p;
  475. best->n2 = n2;
  476. best->r2 = r2;
  477. return;
  478. }
  479. /*
  480. * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
  481. * freq2k.
  482. *
  483. * delta = 1e6 *
  484. * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
  485. * freq2k;
  486. *
  487. * and we would like delta <= budget.
  488. *
  489. * If the discrepancy is above the PPM-based budget, always prefer to
  490. * improve upon the previous solution. However, if you're within the
  491. * budget, try to maximize Ref * VCO, that is N / (P * R^2).
  492. */
  493. a = freq2k * budget * p * r2;
  494. b = freq2k * budget * best->p * best->r2;
  495. diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
  496. diff_best = ABS_DIFF((freq2k * best->p * best->r2),
  497. (LC_FREQ_2K * best->n2));
  498. c = 1000000 * diff;
  499. d = 1000000 * diff_best;
  500. if (a < c && b < d) {
  501. /* If both are above the budget, pick the closer */
  502. if (best->p * best->r2 * diff < p * r2 * diff_best) {
  503. best->p = p;
  504. best->n2 = n2;
  505. best->r2 = r2;
  506. }
  507. } else if (a >= c && b < d) {
  508. /* If A is below the threshold but B is above it? Update. */
  509. best->p = p;
  510. best->n2 = n2;
  511. best->r2 = r2;
  512. } else if (a >= c && b >= d) {
  513. /* Both are below the limit, so pick the higher n2/(r2*r2) */
  514. if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
  515. best->p = p;
  516. best->n2 = n2;
  517. best->r2 = r2;
  518. }
  519. }
  520. /* Otherwise a < c && b >= d, do nothing */
  521. }
  522. static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
  523. int reg)
  524. {
  525. int refclk = LC_FREQ;
  526. int n, p, r;
  527. u32 wrpll;
  528. wrpll = I915_READ(reg);
  529. switch (wrpll & SPLL_PLL_REF_MASK) {
  530. case SPLL_PLL_SSC:
  531. case SPLL_PLL_NON_SSC:
  532. /*
  533. * We could calculate spread here, but our checking
  534. * code only cares about 5% accuracy, and spread is a max of
  535. * 0.5% downspread.
  536. */
  537. refclk = 135;
  538. break;
  539. case SPLL_PLL_LCPLL:
  540. refclk = LC_FREQ;
  541. break;
  542. default:
  543. WARN(1, "bad wrpll refclk\n");
  544. return 0;
  545. }
  546. r = wrpll & WRPLL_DIVIDER_REF_MASK;
  547. p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
  548. n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
  549. /* Convert to KHz, p & r have a fixed point portion */
  550. return (refclk * n * 100) / (p * r);
  551. }
  552. static void intel_ddi_clock_get(struct intel_encoder *encoder,
  553. struct intel_crtc_config *pipe_config)
  554. {
  555. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  556. enum port port = intel_ddi_get_encoder_port(encoder);
  557. int link_clock = 0;
  558. u32 val, pll;
  559. val = I915_READ(PORT_CLK_SEL(port));
  560. switch (val & PORT_CLK_SEL_MASK) {
  561. case PORT_CLK_SEL_LCPLL_810:
  562. link_clock = 81000;
  563. break;
  564. case PORT_CLK_SEL_LCPLL_1350:
  565. link_clock = 135000;
  566. break;
  567. case PORT_CLK_SEL_LCPLL_2700:
  568. link_clock = 270000;
  569. break;
  570. case PORT_CLK_SEL_WRPLL1:
  571. link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
  572. break;
  573. case PORT_CLK_SEL_WRPLL2:
  574. link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
  575. break;
  576. case PORT_CLK_SEL_SPLL:
  577. pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
  578. if (pll == SPLL_PLL_FREQ_810MHz)
  579. link_clock = 81000;
  580. else if (pll == SPLL_PLL_FREQ_1350MHz)
  581. link_clock = 135000;
  582. else if (pll == SPLL_PLL_FREQ_2700MHz)
  583. link_clock = 270000;
  584. else {
  585. WARN(1, "bad spll freq\n");
  586. return;
  587. }
  588. break;
  589. default:
  590. WARN(1, "bad port clock sel\n");
  591. return;
  592. }
  593. pipe_config->port_clock = link_clock * 2;
  594. if (pipe_config->has_pch_encoder)
  595. pipe_config->adjusted_mode.crtc_clock =
  596. intel_dotclock_calculate(pipe_config->port_clock,
  597. &pipe_config->fdi_m_n);
  598. else if (pipe_config->has_dp_encoder)
  599. pipe_config->adjusted_mode.crtc_clock =
  600. intel_dotclock_calculate(pipe_config->port_clock,
  601. &pipe_config->dp_m_n);
  602. else
  603. pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
  604. }
  605. static void
  606. intel_ddi_calculate_wrpll(int clock /* in Hz */,
  607. unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
  608. {
  609. uint64_t freq2k;
  610. unsigned p, n2, r2;
  611. struct wrpll_rnp best = { 0, 0, 0 };
  612. unsigned budget;
  613. freq2k = clock / 100;
  614. budget = wrpll_get_budget_for_freq(clock);
  615. /* Special case handling for 540 pixel clock: bypass WR PLL entirely
  616. * and directly pass the LC PLL to it. */
  617. if (freq2k == 5400000) {
  618. *n2_out = 2;
  619. *p_out = 1;
  620. *r2_out = 2;
  621. return;
  622. }
  623. /*
  624. * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
  625. * the WR PLL.
  626. *
  627. * We want R so that REF_MIN <= Ref <= REF_MAX.
  628. * Injecting R2 = 2 * R gives:
  629. * REF_MAX * r2 > LC_FREQ * 2 and
  630. * REF_MIN * r2 < LC_FREQ * 2
  631. *
  632. * Which means the desired boundaries for r2 are:
  633. * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
  634. *
  635. */
  636. for (r2 = LC_FREQ * 2 / REF_MAX + 1;
  637. r2 <= LC_FREQ * 2 / REF_MIN;
  638. r2++) {
  639. /*
  640. * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
  641. *
  642. * Once again we want VCO_MIN <= VCO <= VCO_MAX.
  643. * Injecting R2 = 2 * R and N2 = 2 * N, we get:
  644. * VCO_MAX * r2 > n2 * LC_FREQ and
  645. * VCO_MIN * r2 < n2 * LC_FREQ)
  646. *
  647. * Which means the desired boundaries for n2 are:
  648. * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
  649. */
  650. for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
  651. n2 <= VCO_MAX * r2 / LC_FREQ;
  652. n2++) {
  653. for (p = P_MIN; p <= P_MAX; p += P_INC)
  654. wrpll_update_rnp(freq2k, budget,
  655. r2, n2, p, &best);
  656. }
  657. }
  658. *n2_out = best.n2;
  659. *p_out = best.p;
  660. *r2_out = best.r2;
  661. }
  662. /*
  663. * Tries to find a PLL for the CRTC. If it finds, it increases the refcount and
  664. * stores it in intel_crtc->ddi_pll_sel, so other mode sets won't be able to
  665. * steal the selected PLL. You need to call intel_ddi_pll_enable to actually
  666. * enable the PLL.
  667. */
  668. bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
  669. {
  670. struct drm_crtc *crtc = &intel_crtc->base;
  671. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  672. struct drm_encoder *encoder = &intel_encoder->base;
  673. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  674. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  675. int type = intel_encoder->type;
  676. enum pipe pipe = intel_crtc->pipe;
  677. int clock = intel_crtc->config.port_clock;
  678. intel_ddi_put_crtc_pll(crtc);
  679. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  680. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  681. switch (intel_dp->link_bw) {
  682. case DP_LINK_BW_1_62:
  683. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
  684. break;
  685. case DP_LINK_BW_2_7:
  686. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
  687. break;
  688. case DP_LINK_BW_5_4:
  689. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
  690. break;
  691. default:
  692. DRM_ERROR("Link bandwidth %d unsupported\n",
  693. intel_dp->link_bw);
  694. return false;
  695. }
  696. } else if (type == INTEL_OUTPUT_HDMI) {
  697. uint32_t reg, val;
  698. unsigned p, n2, r2;
  699. intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
  700. val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
  701. WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
  702. WRPLL_DIVIDER_POST(p);
  703. if (val == I915_READ(WRPLL_CTL1)) {
  704. DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n",
  705. pipe_name(pipe));
  706. reg = WRPLL_CTL1;
  707. } else if (val == I915_READ(WRPLL_CTL2)) {
  708. DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n",
  709. pipe_name(pipe));
  710. reg = WRPLL_CTL2;
  711. } else if (plls->wrpll1_refcount == 0) {
  712. DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
  713. pipe_name(pipe));
  714. reg = WRPLL_CTL1;
  715. } else if (plls->wrpll2_refcount == 0) {
  716. DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
  717. pipe_name(pipe));
  718. reg = WRPLL_CTL2;
  719. } else {
  720. DRM_ERROR("No WRPLLs available!\n");
  721. return false;
  722. }
  723. DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
  724. clock, p, n2, r2);
  725. if (reg == WRPLL_CTL1) {
  726. plls->wrpll1_refcount++;
  727. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
  728. } else {
  729. plls->wrpll2_refcount++;
  730. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
  731. }
  732. } else if (type == INTEL_OUTPUT_ANALOG) {
  733. if (plls->spll_refcount == 0) {
  734. DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
  735. pipe_name(pipe));
  736. plls->spll_refcount++;
  737. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
  738. } else {
  739. DRM_ERROR("SPLL already in use\n");
  740. return false;
  741. }
  742. } else {
  743. WARN(1, "Invalid DDI encoder type %d\n", type);
  744. return false;
  745. }
  746. return true;
  747. }
  748. /*
  749. * To be called after intel_ddi_pll_select(). That one selects the PLL to be
  750. * used, this one actually enables the PLL.
  751. */
  752. void intel_ddi_pll_enable(struct intel_crtc *crtc)
  753. {
  754. struct drm_device *dev = crtc->base.dev;
  755. struct drm_i915_private *dev_priv = dev->dev_private;
  756. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  757. int clock = crtc->config.port_clock;
  758. uint32_t reg, cur_val, new_val;
  759. int refcount;
  760. const char *pll_name;
  761. uint32_t enable_bit = (1 << 31);
  762. unsigned int p, n2, r2;
  763. BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE);
  764. BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE);
  765. switch (crtc->ddi_pll_sel) {
  766. case PORT_CLK_SEL_LCPLL_2700:
  767. case PORT_CLK_SEL_LCPLL_1350:
  768. case PORT_CLK_SEL_LCPLL_810:
  769. /*
  770. * LCPLL should always be enabled at this point of the mode set
  771. * sequence, so nothing to do.
  772. */
  773. return;
  774. case PORT_CLK_SEL_SPLL:
  775. pll_name = "SPLL";
  776. reg = SPLL_CTL;
  777. refcount = plls->spll_refcount;
  778. new_val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz |
  779. SPLL_PLL_SSC;
  780. break;
  781. case PORT_CLK_SEL_WRPLL1:
  782. case PORT_CLK_SEL_WRPLL2:
  783. if (crtc->ddi_pll_sel == PORT_CLK_SEL_WRPLL1) {
  784. pll_name = "WRPLL1";
  785. reg = WRPLL_CTL1;
  786. refcount = plls->wrpll1_refcount;
  787. } else {
  788. pll_name = "WRPLL2";
  789. reg = WRPLL_CTL2;
  790. refcount = plls->wrpll2_refcount;
  791. }
  792. intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
  793. new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
  794. WRPLL_DIVIDER_REFERENCE(r2) |
  795. WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p);
  796. break;
  797. case PORT_CLK_SEL_NONE:
  798. WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n");
  799. return;
  800. default:
  801. WARN(1, "Bad selected pll: 0x%08x\n", crtc->ddi_pll_sel);
  802. return;
  803. }
  804. cur_val = I915_READ(reg);
  805. WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount);
  806. if (refcount == 1) {
  807. WARN(cur_val & enable_bit, "%s already enabled\n", pll_name);
  808. I915_WRITE(reg, new_val);
  809. POSTING_READ(reg);
  810. udelay(20);
  811. } else {
  812. WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name);
  813. }
  814. }
  815. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
  816. {
  817. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  818. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  819. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  820. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  821. int type = intel_encoder->type;
  822. uint32_t temp;
  823. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  824. temp = TRANS_MSA_SYNC_CLK;
  825. switch (intel_crtc->config.pipe_bpp) {
  826. case 18:
  827. temp |= TRANS_MSA_6_BPC;
  828. break;
  829. case 24:
  830. temp |= TRANS_MSA_8_BPC;
  831. break;
  832. case 30:
  833. temp |= TRANS_MSA_10_BPC;
  834. break;
  835. case 36:
  836. temp |= TRANS_MSA_12_BPC;
  837. break;
  838. default:
  839. BUG();
  840. }
  841. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  842. }
  843. }
  844. void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
  845. {
  846. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  847. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  848. struct drm_encoder *encoder = &intel_encoder->base;
  849. struct drm_device *dev = crtc->dev;
  850. struct drm_i915_private *dev_priv = dev->dev_private;
  851. enum pipe pipe = intel_crtc->pipe;
  852. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  853. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  854. int type = intel_encoder->type;
  855. uint32_t temp;
  856. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  857. temp = TRANS_DDI_FUNC_ENABLE;
  858. temp |= TRANS_DDI_SELECT_PORT(port);
  859. switch (intel_crtc->config.pipe_bpp) {
  860. case 18:
  861. temp |= TRANS_DDI_BPC_6;
  862. break;
  863. case 24:
  864. temp |= TRANS_DDI_BPC_8;
  865. break;
  866. case 30:
  867. temp |= TRANS_DDI_BPC_10;
  868. break;
  869. case 36:
  870. temp |= TRANS_DDI_BPC_12;
  871. break;
  872. default:
  873. BUG();
  874. }
  875. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
  876. temp |= TRANS_DDI_PVSYNC;
  877. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
  878. temp |= TRANS_DDI_PHSYNC;
  879. if (cpu_transcoder == TRANSCODER_EDP) {
  880. switch (pipe) {
  881. case PIPE_A:
  882. /* On Haswell, can only use the always-on power well for
  883. * eDP when not using the panel fitter, and when not
  884. * using motion blur mitigation (which we don't
  885. * support). */
  886. if (IS_HASWELL(dev) && intel_crtc->config.pch_pfit.enabled)
  887. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  888. else
  889. temp |= TRANS_DDI_EDP_INPUT_A_ON;
  890. break;
  891. case PIPE_B:
  892. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  893. break;
  894. case PIPE_C:
  895. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  896. break;
  897. default:
  898. BUG();
  899. break;
  900. }
  901. }
  902. if (type == INTEL_OUTPUT_HDMI) {
  903. if (intel_crtc->config.has_hdmi_sink)
  904. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  905. else
  906. temp |= TRANS_DDI_MODE_SELECT_DVI;
  907. } else if (type == INTEL_OUTPUT_ANALOG) {
  908. temp |= TRANS_DDI_MODE_SELECT_FDI;
  909. temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
  910. } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
  911. type == INTEL_OUTPUT_EDP) {
  912. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  913. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  914. temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
  915. } else {
  916. WARN(1, "Invalid encoder type %d for pipe %c\n",
  917. intel_encoder->type, pipe_name(pipe));
  918. }
  919. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  920. }
  921. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  922. enum transcoder cpu_transcoder)
  923. {
  924. uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  925. uint32_t val = I915_READ(reg);
  926. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
  927. val |= TRANS_DDI_PORT_NONE;
  928. I915_WRITE(reg, val);
  929. }
  930. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  931. {
  932. struct drm_device *dev = intel_connector->base.dev;
  933. struct drm_i915_private *dev_priv = dev->dev_private;
  934. struct intel_encoder *intel_encoder = intel_connector->encoder;
  935. int type = intel_connector->base.connector_type;
  936. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  937. enum pipe pipe = 0;
  938. enum transcoder cpu_transcoder;
  939. enum intel_display_power_domain power_domain;
  940. uint32_t tmp;
  941. power_domain = intel_display_port_power_domain(intel_encoder);
  942. if (!intel_display_power_enabled(dev_priv, power_domain))
  943. return false;
  944. if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
  945. return false;
  946. if (port == PORT_A)
  947. cpu_transcoder = TRANSCODER_EDP;
  948. else
  949. cpu_transcoder = (enum transcoder) pipe;
  950. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  951. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  952. case TRANS_DDI_MODE_SELECT_HDMI:
  953. case TRANS_DDI_MODE_SELECT_DVI:
  954. return (type == DRM_MODE_CONNECTOR_HDMIA);
  955. case TRANS_DDI_MODE_SELECT_DP_SST:
  956. if (type == DRM_MODE_CONNECTOR_eDP)
  957. return true;
  958. case TRANS_DDI_MODE_SELECT_DP_MST:
  959. return (type == DRM_MODE_CONNECTOR_DisplayPort);
  960. case TRANS_DDI_MODE_SELECT_FDI:
  961. return (type == DRM_MODE_CONNECTOR_VGA);
  962. default:
  963. return false;
  964. }
  965. }
  966. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  967. enum pipe *pipe)
  968. {
  969. struct drm_device *dev = encoder->base.dev;
  970. struct drm_i915_private *dev_priv = dev->dev_private;
  971. enum port port = intel_ddi_get_encoder_port(encoder);
  972. enum intel_display_power_domain power_domain;
  973. u32 tmp;
  974. int i;
  975. power_domain = intel_display_port_power_domain(encoder);
  976. if (!intel_display_power_enabled(dev_priv, power_domain))
  977. return false;
  978. tmp = I915_READ(DDI_BUF_CTL(port));
  979. if (!(tmp & DDI_BUF_CTL_ENABLE))
  980. return false;
  981. if (port == PORT_A) {
  982. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  983. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  984. case TRANS_DDI_EDP_INPUT_A_ON:
  985. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  986. *pipe = PIPE_A;
  987. break;
  988. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  989. *pipe = PIPE_B;
  990. break;
  991. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  992. *pipe = PIPE_C;
  993. break;
  994. }
  995. return true;
  996. } else {
  997. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  998. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  999. if ((tmp & TRANS_DDI_PORT_MASK)
  1000. == TRANS_DDI_SELECT_PORT(port)) {
  1001. *pipe = i;
  1002. return true;
  1003. }
  1004. }
  1005. }
  1006. DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
  1007. return false;
  1008. }
  1009. static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
  1010. enum pipe pipe)
  1011. {
  1012. uint32_t temp, ret;
  1013. enum port port = I915_MAX_PORTS;
  1014. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1015. pipe);
  1016. int i;
  1017. if (cpu_transcoder == TRANSCODER_EDP) {
  1018. port = PORT_A;
  1019. } else {
  1020. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1021. temp &= TRANS_DDI_PORT_MASK;
  1022. for (i = PORT_B; i <= PORT_E; i++)
  1023. if (temp == TRANS_DDI_SELECT_PORT(i))
  1024. port = i;
  1025. }
  1026. if (port == I915_MAX_PORTS) {
  1027. WARN(1, "Pipe %c enabled on an unknown port\n",
  1028. pipe_name(pipe));
  1029. ret = PORT_CLK_SEL_NONE;
  1030. } else {
  1031. ret = I915_READ(PORT_CLK_SEL(port));
  1032. DRM_DEBUG_KMS("Pipe %c connected to port %c using clock "
  1033. "0x%08x\n", pipe_name(pipe), port_name(port),
  1034. ret);
  1035. }
  1036. return ret;
  1037. }
  1038. void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
  1039. {
  1040. struct drm_i915_private *dev_priv = dev->dev_private;
  1041. enum pipe pipe;
  1042. struct intel_crtc *intel_crtc;
  1043. dev_priv->ddi_plls.spll_refcount = 0;
  1044. dev_priv->ddi_plls.wrpll1_refcount = 0;
  1045. dev_priv->ddi_plls.wrpll2_refcount = 0;
  1046. for_each_pipe(pipe) {
  1047. intel_crtc =
  1048. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1049. if (!intel_crtc->active) {
  1050. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
  1051. continue;
  1052. }
  1053. intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
  1054. pipe);
  1055. switch (intel_crtc->ddi_pll_sel) {
  1056. case PORT_CLK_SEL_SPLL:
  1057. dev_priv->ddi_plls.spll_refcount++;
  1058. break;
  1059. case PORT_CLK_SEL_WRPLL1:
  1060. dev_priv->ddi_plls.wrpll1_refcount++;
  1061. break;
  1062. case PORT_CLK_SEL_WRPLL2:
  1063. dev_priv->ddi_plls.wrpll2_refcount++;
  1064. break;
  1065. }
  1066. }
  1067. }
  1068. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
  1069. {
  1070. struct drm_crtc *crtc = &intel_crtc->base;
  1071. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1072. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1073. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1074. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  1075. if (cpu_transcoder != TRANSCODER_EDP)
  1076. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1077. TRANS_CLK_SEL_PORT(port));
  1078. }
  1079. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
  1080. {
  1081. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1082. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  1083. if (cpu_transcoder != TRANSCODER_EDP)
  1084. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1085. TRANS_CLK_SEL_DISABLED);
  1086. }
  1087. static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
  1088. {
  1089. struct drm_encoder *encoder = &intel_encoder->base;
  1090. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1091. struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
  1092. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1093. int type = intel_encoder->type;
  1094. if (crtc->config.has_audio) {
  1095. DRM_DEBUG_DRIVER("Audio on pipe %c on DDI\n",
  1096. pipe_name(crtc->pipe));
  1097. /* write eld */
  1098. DRM_DEBUG_DRIVER("DDI audio: write eld information\n");
  1099. intel_write_eld(encoder, &crtc->config.adjusted_mode);
  1100. }
  1101. if (type == INTEL_OUTPUT_EDP) {
  1102. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1103. intel_edp_panel_on(intel_dp);
  1104. }
  1105. WARN_ON(crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
  1106. I915_WRITE(PORT_CLK_SEL(port), crtc->ddi_pll_sel);
  1107. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  1108. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1109. struct intel_digital_port *intel_dig_port =
  1110. enc_to_dig_port(encoder);
  1111. intel_dp->DP = intel_dig_port->saved_port_bits |
  1112. DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
  1113. intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
  1114. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1115. intel_dp_start_link_train(intel_dp);
  1116. intel_dp_complete_link_train(intel_dp);
  1117. if (port != PORT_A)
  1118. intel_dp_stop_link_train(intel_dp);
  1119. } else if (type == INTEL_OUTPUT_HDMI) {
  1120. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  1121. intel_hdmi->set_infoframes(encoder,
  1122. crtc->config.has_hdmi_sink,
  1123. &crtc->config.adjusted_mode);
  1124. }
  1125. }
  1126. static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
  1127. {
  1128. struct drm_encoder *encoder = &intel_encoder->base;
  1129. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1130. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1131. int type = intel_encoder->type;
  1132. uint32_t val;
  1133. bool wait = false;
  1134. val = I915_READ(DDI_BUF_CTL(port));
  1135. if (val & DDI_BUF_CTL_ENABLE) {
  1136. val &= ~DDI_BUF_CTL_ENABLE;
  1137. I915_WRITE(DDI_BUF_CTL(port), val);
  1138. wait = true;
  1139. }
  1140. val = I915_READ(DP_TP_CTL(port));
  1141. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1142. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1143. I915_WRITE(DP_TP_CTL(port), val);
  1144. if (wait)
  1145. intel_wait_ddi_buf_idle(dev_priv, port);
  1146. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  1147. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1148. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1149. intel_edp_panel_vdd_on(intel_dp);
  1150. intel_edp_panel_off(intel_dp);
  1151. }
  1152. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1153. }
  1154. static void intel_enable_ddi(struct intel_encoder *intel_encoder)
  1155. {
  1156. struct drm_encoder *encoder = &intel_encoder->base;
  1157. struct drm_crtc *crtc = encoder->crtc;
  1158. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1159. int pipe = intel_crtc->pipe;
  1160. struct drm_device *dev = encoder->dev;
  1161. struct drm_i915_private *dev_priv = dev->dev_private;
  1162. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1163. int type = intel_encoder->type;
  1164. uint32_t tmp;
  1165. if (type == INTEL_OUTPUT_HDMI) {
  1166. struct intel_digital_port *intel_dig_port =
  1167. enc_to_dig_port(encoder);
  1168. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  1169. * are ignored so nothing special needs to be done besides
  1170. * enabling the port.
  1171. */
  1172. I915_WRITE(DDI_BUF_CTL(port),
  1173. intel_dig_port->saved_port_bits |
  1174. DDI_BUF_CTL_ENABLE);
  1175. } else if (type == INTEL_OUTPUT_EDP) {
  1176. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1177. if (port == PORT_A)
  1178. intel_dp_stop_link_train(intel_dp);
  1179. intel_edp_backlight_on(intel_dp);
  1180. intel_edp_psr_enable(intel_dp);
  1181. }
  1182. if (intel_crtc->config.has_audio) {
  1183. intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO);
  1184. tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1185. tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
  1186. I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
  1187. }
  1188. }
  1189. static void intel_disable_ddi(struct intel_encoder *intel_encoder)
  1190. {
  1191. struct drm_encoder *encoder = &intel_encoder->base;
  1192. struct drm_crtc *crtc = encoder->crtc;
  1193. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1194. int pipe = intel_crtc->pipe;
  1195. int type = intel_encoder->type;
  1196. struct drm_device *dev = encoder->dev;
  1197. struct drm_i915_private *dev_priv = dev->dev_private;
  1198. uint32_t tmp;
  1199. /* We can't touch HSW_AUD_PIN_ELD_CP_VLD uncionditionally because this
  1200. * register is part of the power well on Haswell. */
  1201. if (intel_crtc->config.has_audio) {
  1202. tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1203. tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
  1204. (pipe * 4));
  1205. I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
  1206. intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO);
  1207. }
  1208. if (type == INTEL_OUTPUT_EDP) {
  1209. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1210. intel_edp_psr_disable(intel_dp);
  1211. intel_edp_backlight_off(intel_dp);
  1212. }
  1213. }
  1214. int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
  1215. {
  1216. struct drm_device *dev = dev_priv->dev;
  1217. uint32_t lcpll = I915_READ(LCPLL_CTL);
  1218. uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
  1219. if (lcpll & LCPLL_CD_SOURCE_FCLK) {
  1220. return 800000;
  1221. } else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) {
  1222. return 450000;
  1223. } else if (freq == LCPLL_CLK_FREQ_450) {
  1224. return 450000;
  1225. } else if (IS_HASWELL(dev)) {
  1226. if (IS_ULT(dev))
  1227. return 337500;
  1228. else
  1229. return 540000;
  1230. } else {
  1231. if (freq == LCPLL_CLK_FREQ_54O_BDW)
  1232. return 540000;
  1233. else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
  1234. return 337500;
  1235. else
  1236. return 675000;
  1237. }
  1238. }
  1239. void intel_ddi_pll_init(struct drm_device *dev)
  1240. {
  1241. struct drm_i915_private *dev_priv = dev->dev_private;
  1242. uint32_t val = I915_READ(LCPLL_CTL);
  1243. /* The LCPLL register should be turned on by the BIOS. For now let's
  1244. * just check its state and print errors in case something is wrong.
  1245. * Don't even try to turn it on.
  1246. */
  1247. DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
  1248. intel_ddi_get_cdclk_freq(dev_priv));
  1249. if (val & LCPLL_CD_SOURCE_FCLK)
  1250. DRM_ERROR("CDCLK source is not LCPLL\n");
  1251. if (val & LCPLL_PLL_DISABLE)
  1252. DRM_ERROR("LCPLL is disabled\n");
  1253. }
  1254. void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
  1255. {
  1256. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  1257. struct intel_dp *intel_dp = &intel_dig_port->dp;
  1258. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1259. enum port port = intel_dig_port->port;
  1260. uint32_t val;
  1261. bool wait = false;
  1262. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  1263. val = I915_READ(DDI_BUF_CTL(port));
  1264. if (val & DDI_BUF_CTL_ENABLE) {
  1265. val &= ~DDI_BUF_CTL_ENABLE;
  1266. I915_WRITE(DDI_BUF_CTL(port), val);
  1267. wait = true;
  1268. }
  1269. val = I915_READ(DP_TP_CTL(port));
  1270. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1271. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1272. I915_WRITE(DP_TP_CTL(port), val);
  1273. POSTING_READ(DP_TP_CTL(port));
  1274. if (wait)
  1275. intel_wait_ddi_buf_idle(dev_priv, port);
  1276. }
  1277. val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
  1278. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  1279. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1280. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  1281. I915_WRITE(DP_TP_CTL(port), val);
  1282. POSTING_READ(DP_TP_CTL(port));
  1283. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  1284. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  1285. POSTING_READ(DDI_BUF_CTL(port));
  1286. udelay(600);
  1287. }
  1288. void intel_ddi_fdi_disable(struct drm_crtc *crtc)
  1289. {
  1290. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1291. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1292. uint32_t val;
  1293. intel_ddi_post_disable(intel_encoder);
  1294. val = I915_READ(_FDI_RXA_CTL);
  1295. val &= ~FDI_RX_ENABLE;
  1296. I915_WRITE(_FDI_RXA_CTL, val);
  1297. val = I915_READ(_FDI_RXA_MISC);
  1298. val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  1299. val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  1300. I915_WRITE(_FDI_RXA_MISC, val);
  1301. val = I915_READ(_FDI_RXA_CTL);
  1302. val &= ~FDI_PCDCLK;
  1303. I915_WRITE(_FDI_RXA_CTL, val);
  1304. val = I915_READ(_FDI_RXA_CTL);
  1305. val &= ~FDI_RX_PLL_ENABLE;
  1306. I915_WRITE(_FDI_RXA_CTL, val);
  1307. }
  1308. static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
  1309. {
  1310. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  1311. int type = intel_encoder->type;
  1312. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
  1313. intel_dp_check_link_status(intel_dp);
  1314. }
  1315. void intel_ddi_get_config(struct intel_encoder *encoder,
  1316. struct intel_crtc_config *pipe_config)
  1317. {
  1318. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  1319. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1320. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  1321. u32 temp, flags = 0;
  1322. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1323. if (temp & TRANS_DDI_PHSYNC)
  1324. flags |= DRM_MODE_FLAG_PHSYNC;
  1325. else
  1326. flags |= DRM_MODE_FLAG_NHSYNC;
  1327. if (temp & TRANS_DDI_PVSYNC)
  1328. flags |= DRM_MODE_FLAG_PVSYNC;
  1329. else
  1330. flags |= DRM_MODE_FLAG_NVSYNC;
  1331. pipe_config->adjusted_mode.flags |= flags;
  1332. switch (temp & TRANS_DDI_BPC_MASK) {
  1333. case TRANS_DDI_BPC_6:
  1334. pipe_config->pipe_bpp = 18;
  1335. break;
  1336. case TRANS_DDI_BPC_8:
  1337. pipe_config->pipe_bpp = 24;
  1338. break;
  1339. case TRANS_DDI_BPC_10:
  1340. pipe_config->pipe_bpp = 30;
  1341. break;
  1342. case TRANS_DDI_BPC_12:
  1343. pipe_config->pipe_bpp = 36;
  1344. break;
  1345. default:
  1346. break;
  1347. }
  1348. switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
  1349. case TRANS_DDI_MODE_SELECT_HDMI:
  1350. pipe_config->has_hdmi_sink = true;
  1351. case TRANS_DDI_MODE_SELECT_DVI:
  1352. case TRANS_DDI_MODE_SELECT_FDI:
  1353. break;
  1354. case TRANS_DDI_MODE_SELECT_DP_SST:
  1355. case TRANS_DDI_MODE_SELECT_DP_MST:
  1356. pipe_config->has_dp_encoder = true;
  1357. intel_dp_get_m_n(intel_crtc, pipe_config);
  1358. break;
  1359. default:
  1360. break;
  1361. }
  1362. if (intel_display_power_enabled(dev_priv, POWER_DOMAIN_AUDIO)) {
  1363. temp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1364. if (temp & (AUDIO_OUTPUT_ENABLE_A << (intel_crtc->pipe * 4)))
  1365. pipe_config->has_audio = true;
  1366. }
  1367. if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
  1368. pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
  1369. /*
  1370. * This is a big fat ugly hack.
  1371. *
  1372. * Some machines in UEFI boot mode provide us a VBT that has 18
  1373. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1374. * unknown we fail to light up. Yet the same BIOS boots up with
  1375. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1376. * max, not what it tells us to use.
  1377. *
  1378. * Note: This will still be broken if the eDP panel is not lit
  1379. * up by the BIOS, and thus we can't get the mode at module
  1380. * load.
  1381. */
  1382. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1383. pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
  1384. dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
  1385. }
  1386. intel_ddi_clock_get(encoder, pipe_config);
  1387. }
  1388. static void intel_ddi_destroy(struct drm_encoder *encoder)
  1389. {
  1390. /* HDMI has nothing special to destroy, so we can go with this. */
  1391. intel_dp_encoder_destroy(encoder);
  1392. }
  1393. static bool intel_ddi_compute_config(struct intel_encoder *encoder,
  1394. struct intel_crtc_config *pipe_config)
  1395. {
  1396. int type = encoder->type;
  1397. int port = intel_ddi_get_encoder_port(encoder);
  1398. WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
  1399. if (port == PORT_A)
  1400. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  1401. if (type == INTEL_OUTPUT_HDMI)
  1402. return intel_hdmi_compute_config(encoder, pipe_config);
  1403. else
  1404. return intel_dp_compute_config(encoder, pipe_config);
  1405. }
  1406. static const struct drm_encoder_funcs intel_ddi_funcs = {
  1407. .destroy = intel_ddi_destroy,
  1408. };
  1409. static struct intel_connector *
  1410. intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
  1411. {
  1412. struct intel_connector *connector;
  1413. enum port port = intel_dig_port->port;
  1414. connector = kzalloc(sizeof(*connector), GFP_KERNEL);
  1415. if (!connector)
  1416. return NULL;
  1417. intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
  1418. if (!intel_dp_init_connector(intel_dig_port, connector)) {
  1419. kfree(connector);
  1420. return NULL;
  1421. }
  1422. return connector;
  1423. }
  1424. static struct intel_connector *
  1425. intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
  1426. {
  1427. struct intel_connector *connector;
  1428. enum port port = intel_dig_port->port;
  1429. connector = kzalloc(sizeof(*connector), GFP_KERNEL);
  1430. if (!connector)
  1431. return NULL;
  1432. intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
  1433. intel_hdmi_init_connector(intel_dig_port, connector);
  1434. return connector;
  1435. }
  1436. void intel_ddi_init(struct drm_device *dev, enum port port)
  1437. {
  1438. struct drm_i915_private *dev_priv = dev->dev_private;
  1439. struct intel_digital_port *intel_dig_port;
  1440. struct intel_encoder *intel_encoder;
  1441. struct drm_encoder *encoder;
  1442. struct intel_connector *hdmi_connector = NULL;
  1443. struct intel_connector *dp_connector = NULL;
  1444. bool init_hdmi, init_dp;
  1445. init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
  1446. dev_priv->vbt.ddi_port_info[port].supports_hdmi);
  1447. init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
  1448. if (!init_dp && !init_hdmi) {
  1449. DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n",
  1450. port_name(port));
  1451. init_hdmi = true;
  1452. init_dp = true;
  1453. }
  1454. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  1455. if (!intel_dig_port)
  1456. return;
  1457. intel_encoder = &intel_dig_port->base;
  1458. encoder = &intel_encoder->base;
  1459. drm_encoder_init(dev, encoder, &intel_ddi_funcs,
  1460. DRM_MODE_ENCODER_TMDS);
  1461. intel_encoder->compute_config = intel_ddi_compute_config;
  1462. intel_encoder->enable = intel_enable_ddi;
  1463. intel_encoder->pre_enable = intel_ddi_pre_enable;
  1464. intel_encoder->disable = intel_disable_ddi;
  1465. intel_encoder->post_disable = intel_ddi_post_disable;
  1466. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  1467. intel_encoder->get_config = intel_ddi_get_config;
  1468. intel_dig_port->port = port;
  1469. intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
  1470. (DDI_BUF_PORT_REVERSAL |
  1471. DDI_A_4_LANES);
  1472. intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
  1473. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1474. intel_encoder->cloneable = 0;
  1475. intel_encoder->hot_plug = intel_ddi_hot_plug;
  1476. if (init_dp)
  1477. dp_connector = intel_ddi_init_dp_connector(intel_dig_port);
  1478. /* In theory we don't need the encoder->type check, but leave it just in
  1479. * case we have some really bad VBTs... */
  1480. if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi)
  1481. hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port);
  1482. if (!dp_connector && !hdmi_connector) {
  1483. drm_encoder_cleanup(encoder);
  1484. kfree(intel_dig_port);
  1485. }
  1486. }