intel_ddi.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730
  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 void intel_ddi_mode_set(struct intel_encoder *encoder)
  323. {
  324. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  325. int port = intel_ddi_get_encoder_port(encoder);
  326. int pipe = crtc->pipe;
  327. int type = encoder->type;
  328. struct drm_display_mode *adjusted_mode = &crtc->config.adjusted_mode;
  329. DRM_DEBUG_KMS("Preparing DDI mode on port %c, pipe %c\n",
  330. port_name(port), pipe_name(pipe));
  331. crtc->eld_vld = false;
  332. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  333. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  334. struct intel_digital_port *intel_dig_port =
  335. enc_to_dig_port(&encoder->base);
  336. intel_dp->DP = intel_dig_port->saved_port_bits |
  337. DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
  338. intel_dp->DP |= DDI_PORT_WIDTH(intel_dp->lane_count);
  339. if (intel_dp->has_audio) {
  340. DRM_DEBUG_DRIVER("DP audio on pipe %c on DDI\n",
  341. pipe_name(crtc->pipe));
  342. /* write eld */
  343. DRM_DEBUG_DRIVER("DP audio: write eld information\n");
  344. intel_write_eld(&encoder->base, adjusted_mode);
  345. }
  346. } else if (type == INTEL_OUTPUT_HDMI) {
  347. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  348. if (intel_hdmi->has_audio) {
  349. /* Proper support for digital audio needs a new logic
  350. * and a new set of registers, so we leave it for future
  351. * patch bombing.
  352. */
  353. DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
  354. pipe_name(crtc->pipe));
  355. /* write eld */
  356. DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
  357. intel_write_eld(&encoder->base, adjusted_mode);
  358. }
  359. intel_hdmi->set_infoframes(&encoder->base, adjusted_mode);
  360. }
  361. }
  362. static struct intel_encoder *
  363. intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
  364. {
  365. struct drm_device *dev = crtc->dev;
  366. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  367. struct intel_encoder *intel_encoder, *ret = NULL;
  368. int num_encoders = 0;
  369. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  370. ret = intel_encoder;
  371. num_encoders++;
  372. }
  373. if (num_encoders != 1)
  374. WARN(1, "%d encoders on crtc for pipe %c\n", num_encoders,
  375. pipe_name(intel_crtc->pipe));
  376. BUG_ON(ret == NULL);
  377. return ret;
  378. }
  379. void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
  380. {
  381. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  382. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  383. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  384. uint32_t val;
  385. switch (intel_crtc->ddi_pll_sel) {
  386. case PORT_CLK_SEL_SPLL:
  387. plls->spll_refcount--;
  388. if (plls->spll_refcount == 0) {
  389. DRM_DEBUG_KMS("Disabling SPLL\n");
  390. val = I915_READ(SPLL_CTL);
  391. WARN_ON(!(val & SPLL_PLL_ENABLE));
  392. I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
  393. POSTING_READ(SPLL_CTL);
  394. }
  395. break;
  396. case PORT_CLK_SEL_WRPLL1:
  397. plls->wrpll1_refcount--;
  398. if (plls->wrpll1_refcount == 0) {
  399. DRM_DEBUG_KMS("Disabling WRPLL 1\n");
  400. val = I915_READ(WRPLL_CTL1);
  401. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  402. I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
  403. POSTING_READ(WRPLL_CTL1);
  404. }
  405. break;
  406. case PORT_CLK_SEL_WRPLL2:
  407. plls->wrpll2_refcount--;
  408. if (plls->wrpll2_refcount == 0) {
  409. DRM_DEBUG_KMS("Disabling WRPLL 2\n");
  410. val = I915_READ(WRPLL_CTL2);
  411. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  412. I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
  413. POSTING_READ(WRPLL_CTL2);
  414. }
  415. break;
  416. }
  417. WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
  418. WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
  419. WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
  420. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
  421. }
  422. #define LC_FREQ 2700
  423. #define LC_FREQ_2K (LC_FREQ * 2000)
  424. #define P_MIN 2
  425. #define P_MAX 64
  426. #define P_INC 2
  427. /* Constraints for PLL good behavior */
  428. #define REF_MIN 48
  429. #define REF_MAX 400
  430. #define VCO_MIN 2400
  431. #define VCO_MAX 4800
  432. #define ABS_DIFF(a, b) ((a > b) ? (a - b) : (b - a))
  433. struct wrpll_rnp {
  434. unsigned p, n2, r2;
  435. };
  436. static unsigned wrpll_get_budget_for_freq(int clock)
  437. {
  438. unsigned budget;
  439. switch (clock) {
  440. case 25175000:
  441. case 25200000:
  442. case 27000000:
  443. case 27027000:
  444. case 37762500:
  445. case 37800000:
  446. case 40500000:
  447. case 40541000:
  448. case 54000000:
  449. case 54054000:
  450. case 59341000:
  451. case 59400000:
  452. case 72000000:
  453. case 74176000:
  454. case 74250000:
  455. case 81000000:
  456. case 81081000:
  457. case 89012000:
  458. case 89100000:
  459. case 108000000:
  460. case 108108000:
  461. case 111264000:
  462. case 111375000:
  463. case 148352000:
  464. case 148500000:
  465. case 162000000:
  466. case 162162000:
  467. case 222525000:
  468. case 222750000:
  469. case 296703000:
  470. case 297000000:
  471. budget = 0;
  472. break;
  473. case 233500000:
  474. case 245250000:
  475. case 247750000:
  476. case 253250000:
  477. case 298000000:
  478. budget = 1500;
  479. break;
  480. case 169128000:
  481. case 169500000:
  482. case 179500000:
  483. case 202000000:
  484. budget = 2000;
  485. break;
  486. case 256250000:
  487. case 262500000:
  488. case 270000000:
  489. case 272500000:
  490. case 273750000:
  491. case 280750000:
  492. case 281250000:
  493. case 286000000:
  494. case 291750000:
  495. budget = 4000;
  496. break;
  497. case 267250000:
  498. case 268500000:
  499. budget = 5000;
  500. break;
  501. default:
  502. budget = 1000;
  503. break;
  504. }
  505. return budget;
  506. }
  507. static void wrpll_update_rnp(uint64_t freq2k, unsigned budget,
  508. unsigned r2, unsigned n2, unsigned p,
  509. struct wrpll_rnp *best)
  510. {
  511. uint64_t a, b, c, d, diff, diff_best;
  512. /* No best (r,n,p) yet */
  513. if (best->p == 0) {
  514. best->p = p;
  515. best->n2 = n2;
  516. best->r2 = r2;
  517. return;
  518. }
  519. /*
  520. * Output clock is (LC_FREQ_2K / 2000) * N / (P * R), which compares to
  521. * freq2k.
  522. *
  523. * delta = 1e6 *
  524. * abs(freq2k - (LC_FREQ_2K * n2/(p * r2))) /
  525. * freq2k;
  526. *
  527. * and we would like delta <= budget.
  528. *
  529. * If the discrepancy is above the PPM-based budget, always prefer to
  530. * improve upon the previous solution. However, if you're within the
  531. * budget, try to maximize Ref * VCO, that is N / (P * R^2).
  532. */
  533. a = freq2k * budget * p * r2;
  534. b = freq2k * budget * best->p * best->r2;
  535. diff = ABS_DIFF((freq2k * p * r2), (LC_FREQ_2K * n2));
  536. diff_best = ABS_DIFF((freq2k * best->p * best->r2),
  537. (LC_FREQ_2K * best->n2));
  538. c = 1000000 * diff;
  539. d = 1000000 * diff_best;
  540. if (a < c && b < d) {
  541. /* If both are above the budget, pick the closer */
  542. if (best->p * best->r2 * diff < p * r2 * diff_best) {
  543. best->p = p;
  544. best->n2 = n2;
  545. best->r2 = r2;
  546. }
  547. } else if (a >= c && b < d) {
  548. /* If A is below the threshold but B is above it? Update. */
  549. best->p = p;
  550. best->n2 = n2;
  551. best->r2 = r2;
  552. } else if (a >= c && b >= d) {
  553. /* Both are below the limit, so pick the higher n2/(r2*r2) */
  554. if (n2 * best->r2 * best->r2 > best->n2 * r2 * r2) {
  555. best->p = p;
  556. best->n2 = n2;
  557. best->r2 = r2;
  558. }
  559. }
  560. /* Otherwise a < c && b >= d, do nothing */
  561. }
  562. static int intel_ddi_calc_wrpll_link(struct drm_i915_private *dev_priv,
  563. int reg)
  564. {
  565. int refclk = LC_FREQ;
  566. int n, p, r;
  567. u32 wrpll;
  568. wrpll = I915_READ(reg);
  569. switch (wrpll & SPLL_PLL_REF_MASK) {
  570. case SPLL_PLL_SSC:
  571. case SPLL_PLL_NON_SSC:
  572. /*
  573. * We could calculate spread here, but our checking
  574. * code only cares about 5% accuracy, and spread is a max of
  575. * 0.5% downspread.
  576. */
  577. refclk = 135;
  578. break;
  579. case SPLL_PLL_LCPLL:
  580. refclk = LC_FREQ;
  581. break;
  582. default:
  583. WARN(1, "bad wrpll refclk\n");
  584. return 0;
  585. }
  586. r = wrpll & WRPLL_DIVIDER_REF_MASK;
  587. p = (wrpll & WRPLL_DIVIDER_POST_MASK) >> WRPLL_DIVIDER_POST_SHIFT;
  588. n = (wrpll & WRPLL_DIVIDER_FB_MASK) >> WRPLL_DIVIDER_FB_SHIFT;
  589. /* Convert to KHz, p & r have a fixed point portion */
  590. return (refclk * n * 100) / (p * r);
  591. }
  592. static void intel_ddi_clock_get(struct intel_encoder *encoder,
  593. struct intel_crtc_config *pipe_config)
  594. {
  595. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  596. enum port port = intel_ddi_get_encoder_port(encoder);
  597. int link_clock = 0;
  598. u32 val, pll;
  599. val = I915_READ(PORT_CLK_SEL(port));
  600. switch (val & PORT_CLK_SEL_MASK) {
  601. case PORT_CLK_SEL_LCPLL_810:
  602. link_clock = 81000;
  603. break;
  604. case PORT_CLK_SEL_LCPLL_1350:
  605. link_clock = 135000;
  606. break;
  607. case PORT_CLK_SEL_LCPLL_2700:
  608. link_clock = 270000;
  609. break;
  610. case PORT_CLK_SEL_WRPLL1:
  611. link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL1);
  612. break;
  613. case PORT_CLK_SEL_WRPLL2:
  614. link_clock = intel_ddi_calc_wrpll_link(dev_priv, WRPLL_CTL2);
  615. break;
  616. case PORT_CLK_SEL_SPLL:
  617. pll = I915_READ(SPLL_CTL) & SPLL_PLL_FREQ_MASK;
  618. if (pll == SPLL_PLL_FREQ_810MHz)
  619. link_clock = 81000;
  620. else if (pll == SPLL_PLL_FREQ_1350MHz)
  621. link_clock = 135000;
  622. else if (pll == SPLL_PLL_FREQ_2700MHz)
  623. link_clock = 270000;
  624. else {
  625. WARN(1, "bad spll freq\n");
  626. return;
  627. }
  628. break;
  629. default:
  630. WARN(1, "bad port clock sel\n");
  631. return;
  632. }
  633. pipe_config->port_clock = link_clock * 2;
  634. if (pipe_config->has_pch_encoder)
  635. pipe_config->adjusted_mode.crtc_clock =
  636. intel_dotclock_calculate(pipe_config->port_clock,
  637. &pipe_config->fdi_m_n);
  638. else if (pipe_config->has_dp_encoder)
  639. pipe_config->adjusted_mode.crtc_clock =
  640. intel_dotclock_calculate(pipe_config->port_clock,
  641. &pipe_config->dp_m_n);
  642. else
  643. pipe_config->adjusted_mode.crtc_clock = pipe_config->port_clock;
  644. }
  645. static void
  646. intel_ddi_calculate_wrpll(int clock /* in Hz */,
  647. unsigned *r2_out, unsigned *n2_out, unsigned *p_out)
  648. {
  649. uint64_t freq2k;
  650. unsigned p, n2, r2;
  651. struct wrpll_rnp best = { 0, 0, 0 };
  652. unsigned budget;
  653. freq2k = clock / 100;
  654. budget = wrpll_get_budget_for_freq(clock);
  655. /* Special case handling for 540 pixel clock: bypass WR PLL entirely
  656. * and directly pass the LC PLL to it. */
  657. if (freq2k == 5400000) {
  658. *n2_out = 2;
  659. *p_out = 1;
  660. *r2_out = 2;
  661. return;
  662. }
  663. /*
  664. * Ref = LC_FREQ / R, where Ref is the actual reference input seen by
  665. * the WR PLL.
  666. *
  667. * We want R so that REF_MIN <= Ref <= REF_MAX.
  668. * Injecting R2 = 2 * R gives:
  669. * REF_MAX * r2 > LC_FREQ * 2 and
  670. * REF_MIN * r2 < LC_FREQ * 2
  671. *
  672. * Which means the desired boundaries for r2 are:
  673. * LC_FREQ * 2 / REF_MAX < r2 < LC_FREQ * 2 / REF_MIN
  674. *
  675. */
  676. for (r2 = LC_FREQ * 2 / REF_MAX + 1;
  677. r2 <= LC_FREQ * 2 / REF_MIN;
  678. r2++) {
  679. /*
  680. * VCO = N * Ref, that is: VCO = N * LC_FREQ / R
  681. *
  682. * Once again we want VCO_MIN <= VCO <= VCO_MAX.
  683. * Injecting R2 = 2 * R and N2 = 2 * N, we get:
  684. * VCO_MAX * r2 > n2 * LC_FREQ and
  685. * VCO_MIN * r2 < n2 * LC_FREQ)
  686. *
  687. * Which means the desired boundaries for n2 are:
  688. * VCO_MIN * r2 / LC_FREQ < n2 < VCO_MAX * r2 / LC_FREQ
  689. */
  690. for (n2 = VCO_MIN * r2 / LC_FREQ + 1;
  691. n2 <= VCO_MAX * r2 / LC_FREQ;
  692. n2++) {
  693. for (p = P_MIN; p <= P_MAX; p += P_INC)
  694. wrpll_update_rnp(freq2k, budget,
  695. r2, n2, p, &best);
  696. }
  697. }
  698. *n2_out = best.n2;
  699. *p_out = best.p;
  700. *r2_out = best.r2;
  701. }
  702. /*
  703. * Tries to find a PLL for the CRTC. If it finds, it increases the refcount and
  704. * stores it in intel_crtc->ddi_pll_sel, so other mode sets won't be able to
  705. * steal the selected PLL. You need to call intel_ddi_pll_enable to actually
  706. * enable the PLL.
  707. */
  708. bool intel_ddi_pll_select(struct intel_crtc *intel_crtc)
  709. {
  710. struct drm_crtc *crtc = &intel_crtc->base;
  711. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  712. struct drm_encoder *encoder = &intel_encoder->base;
  713. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  714. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  715. int type = intel_encoder->type;
  716. enum pipe pipe = intel_crtc->pipe;
  717. int clock = intel_crtc->config.port_clock;
  718. intel_ddi_put_crtc_pll(crtc);
  719. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  720. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  721. switch (intel_dp->link_bw) {
  722. case DP_LINK_BW_1_62:
  723. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
  724. break;
  725. case DP_LINK_BW_2_7:
  726. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
  727. break;
  728. case DP_LINK_BW_5_4:
  729. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
  730. break;
  731. default:
  732. DRM_ERROR("Link bandwidth %d unsupported\n",
  733. intel_dp->link_bw);
  734. return false;
  735. }
  736. } else if (type == INTEL_OUTPUT_HDMI) {
  737. uint32_t reg, val;
  738. unsigned p, n2, r2;
  739. intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
  740. val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
  741. WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
  742. WRPLL_DIVIDER_POST(p);
  743. if (val == I915_READ(WRPLL_CTL1)) {
  744. DRM_DEBUG_KMS("Reusing WRPLL 1 on pipe %c\n",
  745. pipe_name(pipe));
  746. reg = WRPLL_CTL1;
  747. } else if (val == I915_READ(WRPLL_CTL2)) {
  748. DRM_DEBUG_KMS("Reusing WRPLL 2 on pipe %c\n",
  749. pipe_name(pipe));
  750. reg = WRPLL_CTL2;
  751. } else if (plls->wrpll1_refcount == 0) {
  752. DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
  753. pipe_name(pipe));
  754. reg = WRPLL_CTL1;
  755. } else if (plls->wrpll2_refcount == 0) {
  756. DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
  757. pipe_name(pipe));
  758. reg = WRPLL_CTL2;
  759. } else {
  760. DRM_ERROR("No WRPLLs available!\n");
  761. return false;
  762. }
  763. DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
  764. clock, p, n2, r2);
  765. if (reg == WRPLL_CTL1) {
  766. plls->wrpll1_refcount++;
  767. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
  768. } else {
  769. plls->wrpll2_refcount++;
  770. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
  771. }
  772. } else if (type == INTEL_OUTPUT_ANALOG) {
  773. if (plls->spll_refcount == 0) {
  774. DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
  775. pipe_name(pipe));
  776. plls->spll_refcount++;
  777. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
  778. } else {
  779. DRM_ERROR("SPLL already in use\n");
  780. return false;
  781. }
  782. } else {
  783. WARN(1, "Invalid DDI encoder type %d\n", type);
  784. return false;
  785. }
  786. return true;
  787. }
  788. /*
  789. * To be called after intel_ddi_pll_select(). That one selects the PLL to be
  790. * used, this one actually enables the PLL.
  791. */
  792. void intel_ddi_pll_enable(struct intel_crtc *crtc)
  793. {
  794. struct drm_device *dev = crtc->base.dev;
  795. struct drm_i915_private *dev_priv = dev->dev_private;
  796. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  797. int clock = crtc->config.port_clock;
  798. uint32_t reg, cur_val, new_val;
  799. int refcount;
  800. const char *pll_name;
  801. uint32_t enable_bit = (1 << 31);
  802. unsigned int p, n2, r2;
  803. BUILD_BUG_ON(enable_bit != SPLL_PLL_ENABLE);
  804. BUILD_BUG_ON(enable_bit != WRPLL_PLL_ENABLE);
  805. switch (crtc->ddi_pll_sel) {
  806. case PORT_CLK_SEL_LCPLL_2700:
  807. case PORT_CLK_SEL_LCPLL_1350:
  808. case PORT_CLK_SEL_LCPLL_810:
  809. /*
  810. * LCPLL should always be enabled at this point of the mode set
  811. * sequence, so nothing to do.
  812. */
  813. return;
  814. case PORT_CLK_SEL_SPLL:
  815. pll_name = "SPLL";
  816. reg = SPLL_CTL;
  817. refcount = plls->spll_refcount;
  818. new_val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz |
  819. SPLL_PLL_SSC;
  820. break;
  821. case PORT_CLK_SEL_WRPLL1:
  822. case PORT_CLK_SEL_WRPLL2:
  823. if (crtc->ddi_pll_sel == PORT_CLK_SEL_WRPLL1) {
  824. pll_name = "WRPLL1";
  825. reg = WRPLL_CTL1;
  826. refcount = plls->wrpll1_refcount;
  827. } else {
  828. pll_name = "WRPLL2";
  829. reg = WRPLL_CTL2;
  830. refcount = plls->wrpll2_refcount;
  831. }
  832. intel_ddi_calculate_wrpll(clock * 1000, &r2, &n2, &p);
  833. new_val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
  834. WRPLL_DIVIDER_REFERENCE(r2) |
  835. WRPLL_DIVIDER_FEEDBACK(n2) | WRPLL_DIVIDER_POST(p);
  836. break;
  837. case PORT_CLK_SEL_NONE:
  838. WARN(1, "Bad selected pll: PORT_CLK_SEL_NONE\n");
  839. return;
  840. default:
  841. WARN(1, "Bad selected pll: 0x%08x\n", crtc->ddi_pll_sel);
  842. return;
  843. }
  844. cur_val = I915_READ(reg);
  845. WARN(refcount < 1, "Bad %s refcount: %d\n", pll_name, refcount);
  846. if (refcount == 1) {
  847. WARN(cur_val & enable_bit, "%s already enabled\n", pll_name);
  848. I915_WRITE(reg, new_val);
  849. POSTING_READ(reg);
  850. udelay(20);
  851. } else {
  852. WARN((cur_val & enable_bit) == 0, "%s disabled\n", pll_name);
  853. }
  854. }
  855. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
  856. {
  857. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  858. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  859. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  860. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  861. int type = intel_encoder->type;
  862. uint32_t temp;
  863. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  864. temp = TRANS_MSA_SYNC_CLK;
  865. switch (intel_crtc->config.pipe_bpp) {
  866. case 18:
  867. temp |= TRANS_MSA_6_BPC;
  868. break;
  869. case 24:
  870. temp |= TRANS_MSA_8_BPC;
  871. break;
  872. case 30:
  873. temp |= TRANS_MSA_10_BPC;
  874. break;
  875. case 36:
  876. temp |= TRANS_MSA_12_BPC;
  877. break;
  878. default:
  879. BUG();
  880. }
  881. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  882. }
  883. }
  884. void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc)
  885. {
  886. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  887. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  888. struct drm_encoder *encoder = &intel_encoder->base;
  889. struct drm_device *dev = crtc->dev;
  890. struct drm_i915_private *dev_priv = dev->dev_private;
  891. enum pipe pipe = intel_crtc->pipe;
  892. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  893. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  894. int type = intel_encoder->type;
  895. uint32_t temp;
  896. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  897. temp = TRANS_DDI_FUNC_ENABLE;
  898. temp |= TRANS_DDI_SELECT_PORT(port);
  899. switch (intel_crtc->config.pipe_bpp) {
  900. case 18:
  901. temp |= TRANS_DDI_BPC_6;
  902. break;
  903. case 24:
  904. temp |= TRANS_DDI_BPC_8;
  905. break;
  906. case 30:
  907. temp |= TRANS_DDI_BPC_10;
  908. break;
  909. case 36:
  910. temp |= TRANS_DDI_BPC_12;
  911. break;
  912. default:
  913. BUG();
  914. }
  915. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PVSYNC)
  916. temp |= TRANS_DDI_PVSYNC;
  917. if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_PHSYNC)
  918. temp |= TRANS_DDI_PHSYNC;
  919. if (cpu_transcoder == TRANSCODER_EDP) {
  920. switch (pipe) {
  921. case PIPE_A:
  922. /* On Haswell, can only use the always-on power well for
  923. * eDP when not using the panel fitter, and when not
  924. * using motion blur mitigation (which we don't
  925. * support). */
  926. if (IS_HASWELL(dev) && intel_crtc->config.pch_pfit.enabled)
  927. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  928. else
  929. temp |= TRANS_DDI_EDP_INPUT_A_ON;
  930. break;
  931. case PIPE_B:
  932. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  933. break;
  934. case PIPE_C:
  935. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  936. break;
  937. default:
  938. BUG();
  939. break;
  940. }
  941. }
  942. if (type == INTEL_OUTPUT_HDMI) {
  943. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  944. if (intel_hdmi->has_hdmi_sink)
  945. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  946. else
  947. temp |= TRANS_DDI_MODE_SELECT_DVI;
  948. } else if (type == INTEL_OUTPUT_ANALOG) {
  949. temp |= TRANS_DDI_MODE_SELECT_FDI;
  950. temp |= (intel_crtc->config.fdi_lanes - 1) << 1;
  951. } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
  952. type == INTEL_OUTPUT_EDP) {
  953. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  954. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  955. temp |= DDI_PORT_WIDTH(intel_dp->lane_count);
  956. } else {
  957. WARN(1, "Invalid encoder type %d for pipe %c\n",
  958. intel_encoder->type, pipe_name(pipe));
  959. }
  960. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  961. }
  962. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  963. enum transcoder cpu_transcoder)
  964. {
  965. uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  966. uint32_t val = I915_READ(reg);
  967. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
  968. val |= TRANS_DDI_PORT_NONE;
  969. I915_WRITE(reg, val);
  970. }
  971. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  972. {
  973. struct drm_device *dev = intel_connector->base.dev;
  974. struct drm_i915_private *dev_priv = dev->dev_private;
  975. struct intel_encoder *intel_encoder = intel_connector->encoder;
  976. int type = intel_connector->base.connector_type;
  977. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  978. enum pipe pipe = 0;
  979. enum transcoder cpu_transcoder;
  980. uint32_t tmp;
  981. if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
  982. return false;
  983. if (port == PORT_A)
  984. cpu_transcoder = TRANSCODER_EDP;
  985. else
  986. cpu_transcoder = (enum transcoder) pipe;
  987. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  988. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  989. case TRANS_DDI_MODE_SELECT_HDMI:
  990. case TRANS_DDI_MODE_SELECT_DVI:
  991. return (type == DRM_MODE_CONNECTOR_HDMIA);
  992. case TRANS_DDI_MODE_SELECT_DP_SST:
  993. if (type == DRM_MODE_CONNECTOR_eDP)
  994. return true;
  995. case TRANS_DDI_MODE_SELECT_DP_MST:
  996. return (type == DRM_MODE_CONNECTOR_DisplayPort);
  997. case TRANS_DDI_MODE_SELECT_FDI:
  998. return (type == DRM_MODE_CONNECTOR_VGA);
  999. default:
  1000. return false;
  1001. }
  1002. }
  1003. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  1004. enum pipe *pipe)
  1005. {
  1006. struct drm_device *dev = encoder->base.dev;
  1007. struct drm_i915_private *dev_priv = dev->dev_private;
  1008. enum port port = intel_ddi_get_encoder_port(encoder);
  1009. u32 tmp;
  1010. int i;
  1011. tmp = I915_READ(DDI_BUF_CTL(port));
  1012. if (!(tmp & DDI_BUF_CTL_ENABLE))
  1013. return false;
  1014. if (port == PORT_A) {
  1015. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  1016. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  1017. case TRANS_DDI_EDP_INPUT_A_ON:
  1018. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  1019. *pipe = PIPE_A;
  1020. break;
  1021. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  1022. *pipe = PIPE_B;
  1023. break;
  1024. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  1025. *pipe = PIPE_C;
  1026. break;
  1027. }
  1028. return true;
  1029. } else {
  1030. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  1031. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  1032. if ((tmp & TRANS_DDI_PORT_MASK)
  1033. == TRANS_DDI_SELECT_PORT(port)) {
  1034. *pipe = i;
  1035. return true;
  1036. }
  1037. }
  1038. }
  1039. DRM_DEBUG_KMS("No pipe for ddi port %c found\n", port_name(port));
  1040. return false;
  1041. }
  1042. static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
  1043. enum pipe pipe)
  1044. {
  1045. uint32_t temp, ret;
  1046. enum port port = I915_MAX_PORTS;
  1047. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1048. pipe);
  1049. int i;
  1050. if (cpu_transcoder == TRANSCODER_EDP) {
  1051. port = PORT_A;
  1052. } else {
  1053. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1054. temp &= TRANS_DDI_PORT_MASK;
  1055. for (i = PORT_B; i <= PORT_E; i++)
  1056. if (temp == TRANS_DDI_SELECT_PORT(i))
  1057. port = i;
  1058. }
  1059. if (port == I915_MAX_PORTS) {
  1060. WARN(1, "Pipe %c enabled on an unknown port\n",
  1061. pipe_name(pipe));
  1062. ret = PORT_CLK_SEL_NONE;
  1063. } else {
  1064. ret = I915_READ(PORT_CLK_SEL(port));
  1065. DRM_DEBUG_KMS("Pipe %c connected to port %c using clock "
  1066. "0x%08x\n", pipe_name(pipe), port_name(port),
  1067. ret);
  1068. }
  1069. return ret;
  1070. }
  1071. void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
  1072. {
  1073. struct drm_i915_private *dev_priv = dev->dev_private;
  1074. enum pipe pipe;
  1075. struct intel_crtc *intel_crtc;
  1076. dev_priv->ddi_plls.spll_refcount = 0;
  1077. dev_priv->ddi_plls.wrpll1_refcount = 0;
  1078. dev_priv->ddi_plls.wrpll2_refcount = 0;
  1079. for_each_pipe(pipe) {
  1080. intel_crtc =
  1081. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1082. if (!intel_crtc->active) {
  1083. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
  1084. continue;
  1085. }
  1086. intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
  1087. pipe);
  1088. switch (intel_crtc->ddi_pll_sel) {
  1089. case PORT_CLK_SEL_SPLL:
  1090. dev_priv->ddi_plls.spll_refcount++;
  1091. break;
  1092. case PORT_CLK_SEL_WRPLL1:
  1093. dev_priv->ddi_plls.wrpll1_refcount++;
  1094. break;
  1095. case PORT_CLK_SEL_WRPLL2:
  1096. dev_priv->ddi_plls.wrpll2_refcount++;
  1097. break;
  1098. }
  1099. }
  1100. }
  1101. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
  1102. {
  1103. struct drm_crtc *crtc = &intel_crtc->base;
  1104. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1105. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1106. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1107. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  1108. if (cpu_transcoder != TRANSCODER_EDP)
  1109. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1110. TRANS_CLK_SEL_PORT(port));
  1111. }
  1112. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
  1113. {
  1114. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1115. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  1116. if (cpu_transcoder != TRANSCODER_EDP)
  1117. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1118. TRANS_CLK_SEL_DISABLED);
  1119. }
  1120. static void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
  1121. {
  1122. struct drm_encoder *encoder = &intel_encoder->base;
  1123. struct drm_crtc *crtc = encoder->crtc;
  1124. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1125. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1126. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1127. int type = intel_encoder->type;
  1128. if (type == INTEL_OUTPUT_EDP) {
  1129. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1130. intel_edp_panel_on(intel_dp);
  1131. }
  1132. WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
  1133. I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel);
  1134. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  1135. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1136. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1137. intel_dp_start_link_train(intel_dp);
  1138. intel_dp_complete_link_train(intel_dp);
  1139. if (port != PORT_A)
  1140. intel_dp_stop_link_train(intel_dp);
  1141. }
  1142. }
  1143. static void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
  1144. {
  1145. struct drm_encoder *encoder = &intel_encoder->base;
  1146. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1147. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1148. int type = intel_encoder->type;
  1149. uint32_t val;
  1150. bool wait = false;
  1151. val = I915_READ(DDI_BUF_CTL(port));
  1152. if (val & DDI_BUF_CTL_ENABLE) {
  1153. val &= ~DDI_BUF_CTL_ENABLE;
  1154. I915_WRITE(DDI_BUF_CTL(port), val);
  1155. wait = true;
  1156. }
  1157. val = I915_READ(DP_TP_CTL(port));
  1158. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1159. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1160. I915_WRITE(DP_TP_CTL(port), val);
  1161. if (wait)
  1162. intel_wait_ddi_buf_idle(dev_priv, port);
  1163. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  1164. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1165. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_OFF);
  1166. intel_edp_panel_off(intel_dp);
  1167. }
  1168. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1169. }
  1170. static void intel_enable_ddi(struct intel_encoder *intel_encoder)
  1171. {
  1172. struct drm_encoder *encoder = &intel_encoder->base;
  1173. struct drm_crtc *crtc = encoder->crtc;
  1174. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1175. int pipe = intel_crtc->pipe;
  1176. struct drm_device *dev = encoder->dev;
  1177. struct drm_i915_private *dev_priv = dev->dev_private;
  1178. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1179. int type = intel_encoder->type;
  1180. uint32_t tmp;
  1181. if (type == INTEL_OUTPUT_HDMI) {
  1182. struct intel_digital_port *intel_dig_port =
  1183. enc_to_dig_port(encoder);
  1184. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  1185. * are ignored so nothing special needs to be done besides
  1186. * enabling the port.
  1187. */
  1188. I915_WRITE(DDI_BUF_CTL(port),
  1189. intel_dig_port->saved_port_bits |
  1190. DDI_BUF_CTL_ENABLE);
  1191. } else if (type == INTEL_OUTPUT_EDP) {
  1192. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1193. if (port == PORT_A)
  1194. intel_dp_stop_link_train(intel_dp);
  1195. intel_edp_backlight_on(intel_dp);
  1196. intel_edp_psr_enable(intel_dp);
  1197. }
  1198. if (intel_crtc->eld_vld && type != INTEL_OUTPUT_EDP) {
  1199. tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1200. tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4));
  1201. I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
  1202. }
  1203. }
  1204. static void intel_disable_ddi(struct intel_encoder *intel_encoder)
  1205. {
  1206. struct drm_encoder *encoder = &intel_encoder->base;
  1207. struct drm_crtc *crtc = encoder->crtc;
  1208. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1209. int pipe = intel_crtc->pipe;
  1210. int type = intel_encoder->type;
  1211. struct drm_device *dev = encoder->dev;
  1212. struct drm_i915_private *dev_priv = dev->dev_private;
  1213. uint32_t tmp;
  1214. if (intel_crtc->eld_vld && type != INTEL_OUTPUT_EDP) {
  1215. tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD);
  1216. tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) <<
  1217. (pipe * 4));
  1218. I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp);
  1219. }
  1220. if (type == INTEL_OUTPUT_EDP) {
  1221. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1222. intel_edp_psr_disable(intel_dp);
  1223. intel_edp_backlight_off(intel_dp);
  1224. }
  1225. }
  1226. int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
  1227. {
  1228. struct drm_device *dev = dev_priv->dev;
  1229. uint32_t lcpll = I915_READ(LCPLL_CTL);
  1230. uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK;
  1231. if (lcpll & LCPLL_CD_SOURCE_FCLK) {
  1232. return 800000;
  1233. } else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) {
  1234. return 450000;
  1235. } else if (freq == LCPLL_CLK_FREQ_450) {
  1236. return 450000;
  1237. } else if (IS_HASWELL(dev)) {
  1238. if (IS_ULT(dev))
  1239. return 337500;
  1240. else
  1241. return 540000;
  1242. } else {
  1243. if (freq == LCPLL_CLK_FREQ_54O_BDW)
  1244. return 540000;
  1245. else if (freq == LCPLL_CLK_FREQ_337_5_BDW)
  1246. return 337500;
  1247. else
  1248. return 675000;
  1249. }
  1250. }
  1251. void intel_ddi_pll_init(struct drm_device *dev)
  1252. {
  1253. struct drm_i915_private *dev_priv = dev->dev_private;
  1254. uint32_t val = I915_READ(LCPLL_CTL);
  1255. /* The LCPLL register should be turned on by the BIOS. For now let's
  1256. * just check its state and print errors in case something is wrong.
  1257. * Don't even try to turn it on.
  1258. */
  1259. DRM_DEBUG_KMS("CDCLK running at %dKHz\n",
  1260. intel_ddi_get_cdclk_freq(dev_priv));
  1261. if (val & LCPLL_CD_SOURCE_FCLK)
  1262. DRM_ERROR("CDCLK source is not LCPLL\n");
  1263. if (val & LCPLL_PLL_DISABLE)
  1264. DRM_ERROR("LCPLL is disabled\n");
  1265. }
  1266. void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
  1267. {
  1268. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  1269. struct intel_dp *intel_dp = &intel_dig_port->dp;
  1270. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1271. enum port port = intel_dig_port->port;
  1272. uint32_t val;
  1273. bool wait = false;
  1274. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  1275. val = I915_READ(DDI_BUF_CTL(port));
  1276. if (val & DDI_BUF_CTL_ENABLE) {
  1277. val &= ~DDI_BUF_CTL_ENABLE;
  1278. I915_WRITE(DDI_BUF_CTL(port), val);
  1279. wait = true;
  1280. }
  1281. val = I915_READ(DP_TP_CTL(port));
  1282. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1283. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1284. I915_WRITE(DP_TP_CTL(port), val);
  1285. POSTING_READ(DP_TP_CTL(port));
  1286. if (wait)
  1287. intel_wait_ddi_buf_idle(dev_priv, port);
  1288. }
  1289. val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
  1290. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  1291. if (drm_dp_enhanced_frame_cap(intel_dp->dpcd))
  1292. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  1293. I915_WRITE(DP_TP_CTL(port), val);
  1294. POSTING_READ(DP_TP_CTL(port));
  1295. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  1296. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  1297. POSTING_READ(DDI_BUF_CTL(port));
  1298. udelay(600);
  1299. }
  1300. void intel_ddi_fdi_disable(struct drm_crtc *crtc)
  1301. {
  1302. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1303. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1304. uint32_t val;
  1305. intel_ddi_post_disable(intel_encoder);
  1306. val = I915_READ(_FDI_RXA_CTL);
  1307. val &= ~FDI_RX_ENABLE;
  1308. I915_WRITE(_FDI_RXA_CTL, val);
  1309. val = I915_READ(_FDI_RXA_MISC);
  1310. val &= ~(FDI_RX_PWRDN_LANE1_MASK | FDI_RX_PWRDN_LANE0_MASK);
  1311. val |= FDI_RX_PWRDN_LANE1_VAL(2) | FDI_RX_PWRDN_LANE0_VAL(2);
  1312. I915_WRITE(_FDI_RXA_MISC, val);
  1313. val = I915_READ(_FDI_RXA_CTL);
  1314. val &= ~FDI_PCDCLK;
  1315. I915_WRITE(_FDI_RXA_CTL, val);
  1316. val = I915_READ(_FDI_RXA_CTL);
  1317. val &= ~FDI_RX_PLL_ENABLE;
  1318. I915_WRITE(_FDI_RXA_CTL, val);
  1319. }
  1320. static void intel_ddi_hot_plug(struct intel_encoder *intel_encoder)
  1321. {
  1322. struct intel_dp *intel_dp = enc_to_intel_dp(&intel_encoder->base);
  1323. int type = intel_encoder->type;
  1324. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP)
  1325. intel_dp_check_link_status(intel_dp);
  1326. }
  1327. void intel_ddi_get_config(struct intel_encoder *encoder,
  1328. struct intel_crtc_config *pipe_config)
  1329. {
  1330. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  1331. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1332. enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder;
  1333. u32 temp, flags = 0;
  1334. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1335. if (temp & TRANS_DDI_PHSYNC)
  1336. flags |= DRM_MODE_FLAG_PHSYNC;
  1337. else
  1338. flags |= DRM_MODE_FLAG_NHSYNC;
  1339. if (temp & TRANS_DDI_PVSYNC)
  1340. flags |= DRM_MODE_FLAG_PVSYNC;
  1341. else
  1342. flags |= DRM_MODE_FLAG_NVSYNC;
  1343. pipe_config->adjusted_mode.flags |= flags;
  1344. switch (temp & TRANS_DDI_BPC_MASK) {
  1345. case TRANS_DDI_BPC_6:
  1346. pipe_config->pipe_bpp = 18;
  1347. break;
  1348. case TRANS_DDI_BPC_8:
  1349. pipe_config->pipe_bpp = 24;
  1350. break;
  1351. case TRANS_DDI_BPC_10:
  1352. pipe_config->pipe_bpp = 30;
  1353. break;
  1354. case TRANS_DDI_BPC_12:
  1355. pipe_config->pipe_bpp = 36;
  1356. break;
  1357. default:
  1358. break;
  1359. }
  1360. switch (temp & TRANS_DDI_MODE_SELECT_MASK) {
  1361. case TRANS_DDI_MODE_SELECT_HDMI:
  1362. case TRANS_DDI_MODE_SELECT_DVI:
  1363. case TRANS_DDI_MODE_SELECT_FDI:
  1364. break;
  1365. case TRANS_DDI_MODE_SELECT_DP_SST:
  1366. case TRANS_DDI_MODE_SELECT_DP_MST:
  1367. pipe_config->has_dp_encoder = true;
  1368. intel_dp_get_m_n(intel_crtc, pipe_config);
  1369. break;
  1370. default:
  1371. break;
  1372. }
  1373. if (encoder->type == INTEL_OUTPUT_EDP && dev_priv->vbt.edp_bpp &&
  1374. pipe_config->pipe_bpp > dev_priv->vbt.edp_bpp) {
  1375. /*
  1376. * This is a big fat ugly hack.
  1377. *
  1378. * Some machines in UEFI boot mode provide us a VBT that has 18
  1379. * bpp and 1.62 GHz link bandwidth for eDP, which for reasons
  1380. * unknown we fail to light up. Yet the same BIOS boots up with
  1381. * 24 bpp and 2.7 GHz link. Use the same bpp as the BIOS uses as
  1382. * max, not what it tells us to use.
  1383. *
  1384. * Note: This will still be broken if the eDP panel is not lit
  1385. * up by the BIOS, and thus we can't get the mode at module
  1386. * load.
  1387. */
  1388. DRM_DEBUG_KMS("pipe has %d bpp for eDP panel, overriding BIOS-provided max %d bpp\n",
  1389. pipe_config->pipe_bpp, dev_priv->vbt.edp_bpp);
  1390. dev_priv->vbt.edp_bpp = pipe_config->pipe_bpp;
  1391. }
  1392. intel_ddi_clock_get(encoder, pipe_config);
  1393. }
  1394. static void intel_ddi_destroy(struct drm_encoder *encoder)
  1395. {
  1396. /* HDMI has nothing special to destroy, so we can go with this. */
  1397. intel_dp_encoder_destroy(encoder);
  1398. }
  1399. static bool intel_ddi_compute_config(struct intel_encoder *encoder,
  1400. struct intel_crtc_config *pipe_config)
  1401. {
  1402. int type = encoder->type;
  1403. int port = intel_ddi_get_encoder_port(encoder);
  1404. WARN(type == INTEL_OUTPUT_UNKNOWN, "compute_config() on unknown output!\n");
  1405. if (port == PORT_A)
  1406. pipe_config->cpu_transcoder = TRANSCODER_EDP;
  1407. if (type == INTEL_OUTPUT_HDMI)
  1408. return intel_hdmi_compute_config(encoder, pipe_config);
  1409. else
  1410. return intel_dp_compute_config(encoder, pipe_config);
  1411. }
  1412. static const struct drm_encoder_funcs intel_ddi_funcs = {
  1413. .destroy = intel_ddi_destroy,
  1414. };
  1415. static struct intel_connector *
  1416. intel_ddi_init_dp_connector(struct intel_digital_port *intel_dig_port)
  1417. {
  1418. struct intel_connector *connector;
  1419. enum port port = intel_dig_port->port;
  1420. connector = kzalloc(sizeof(*connector), GFP_KERNEL);
  1421. if (!connector)
  1422. return NULL;
  1423. intel_dig_port->dp.output_reg = DDI_BUF_CTL(port);
  1424. if (!intel_dp_init_connector(intel_dig_port, connector)) {
  1425. kfree(connector);
  1426. return NULL;
  1427. }
  1428. return connector;
  1429. }
  1430. static struct intel_connector *
  1431. intel_ddi_init_hdmi_connector(struct intel_digital_port *intel_dig_port)
  1432. {
  1433. struct intel_connector *connector;
  1434. enum port port = intel_dig_port->port;
  1435. connector = kzalloc(sizeof(*connector), GFP_KERNEL);
  1436. if (!connector)
  1437. return NULL;
  1438. intel_dig_port->hdmi.hdmi_reg = DDI_BUF_CTL(port);
  1439. intel_hdmi_init_connector(intel_dig_port, connector);
  1440. return connector;
  1441. }
  1442. void intel_ddi_init(struct drm_device *dev, enum port port)
  1443. {
  1444. struct drm_i915_private *dev_priv = dev->dev_private;
  1445. struct intel_digital_port *intel_dig_port;
  1446. struct intel_encoder *intel_encoder;
  1447. struct drm_encoder *encoder;
  1448. struct intel_connector *hdmi_connector = NULL;
  1449. struct intel_connector *dp_connector = NULL;
  1450. bool init_hdmi, init_dp;
  1451. init_hdmi = (dev_priv->vbt.ddi_port_info[port].supports_dvi ||
  1452. dev_priv->vbt.ddi_port_info[port].supports_hdmi);
  1453. init_dp = dev_priv->vbt.ddi_port_info[port].supports_dp;
  1454. if (!init_dp && !init_hdmi) {
  1455. DRM_DEBUG_KMS("VBT says port %c is not DVI/HDMI/DP compatible\n",
  1456. port_name(port));
  1457. init_hdmi = true;
  1458. init_dp = true;
  1459. }
  1460. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  1461. if (!intel_dig_port)
  1462. return;
  1463. intel_encoder = &intel_dig_port->base;
  1464. encoder = &intel_encoder->base;
  1465. drm_encoder_init(dev, encoder, &intel_ddi_funcs,
  1466. DRM_MODE_ENCODER_TMDS);
  1467. intel_encoder->compute_config = intel_ddi_compute_config;
  1468. intel_encoder->mode_set = intel_ddi_mode_set;
  1469. intel_encoder->enable = intel_enable_ddi;
  1470. intel_encoder->pre_enable = intel_ddi_pre_enable;
  1471. intel_encoder->disable = intel_disable_ddi;
  1472. intel_encoder->post_disable = intel_ddi_post_disable;
  1473. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  1474. intel_encoder->get_config = intel_ddi_get_config;
  1475. intel_dig_port->port = port;
  1476. intel_dig_port->saved_port_bits = I915_READ(DDI_BUF_CTL(port)) &
  1477. (DDI_BUF_PORT_REVERSAL |
  1478. DDI_A_4_LANES);
  1479. intel_encoder->type = INTEL_OUTPUT_UNKNOWN;
  1480. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1481. intel_encoder->cloneable = false;
  1482. intel_encoder->hot_plug = intel_ddi_hot_plug;
  1483. if (init_dp)
  1484. dp_connector = intel_ddi_init_dp_connector(intel_dig_port);
  1485. /* In theory we don't need the encoder->type check, but leave it just in
  1486. * case we have some really bad VBTs... */
  1487. if (intel_encoder->type != INTEL_OUTPUT_EDP && init_hdmi)
  1488. hdmi_connector = intel_ddi_init_hdmi_connector(intel_dig_port);
  1489. if (!dp_connector && !hdmi_connector) {
  1490. drm_encoder_cleanup(encoder);
  1491. kfree(intel_dig_port);
  1492. }
  1493. }