intel_ddi.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. 0x00FFFFFF, 0x00040006 /* HDMI parameters */
  44. };
  45. static const u32 hsw_ddi_translations_fdi[] = {
  46. 0x00FFFFFF, 0x0007000E, /* FDI parameters */
  47. 0x00D75FFF, 0x000F000A,
  48. 0x00C30FFF, 0x00060006,
  49. 0x00AAAFFF, 0x001E0000,
  50. 0x00FFFFFF, 0x000F000A,
  51. 0x00D75FFF, 0x00160004,
  52. 0x00C30FFF, 0x001E0000,
  53. 0x00FFFFFF, 0x00060006,
  54. 0x00D75FFF, 0x001E0000,
  55. 0x00FFFFFF, 0x00040006 /* HDMI parameters */
  56. };
  57. static enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder)
  58. {
  59. struct drm_encoder *encoder = &intel_encoder->base;
  60. int type = intel_encoder->type;
  61. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP ||
  62. type == INTEL_OUTPUT_HDMI) {
  63. struct intel_digital_port *intel_dig_port =
  64. enc_to_dig_port(encoder);
  65. return intel_dig_port->port;
  66. } else if (type == INTEL_OUTPUT_ANALOG) {
  67. return PORT_E;
  68. } else {
  69. DRM_ERROR("Invalid DDI encoder type %d\n", type);
  70. BUG();
  71. }
  72. }
  73. /* On Haswell, DDI port buffers must be programmed with correct values
  74. * in advance. The buffer values are different for FDI and DP modes,
  75. * but the HDMI/DVI fields are shared among those. So we program the DDI
  76. * in either FDI or DP modes only, as HDMI connections will work with both
  77. * of those
  78. */
  79. void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port, bool use_fdi_mode)
  80. {
  81. struct drm_i915_private *dev_priv = dev->dev_private;
  82. u32 reg;
  83. int i;
  84. const u32 *ddi_translations = ((use_fdi_mode) ?
  85. hsw_ddi_translations_fdi :
  86. hsw_ddi_translations_dp);
  87. DRM_DEBUG_DRIVER("Initializing DDI buffers for port %c in %s mode\n",
  88. port_name(port),
  89. use_fdi_mode ? "FDI" : "DP");
  90. WARN((use_fdi_mode && (port != PORT_E)),
  91. "Programming port %c in FDI mode, this probably will not work.\n",
  92. port_name(port));
  93. for (i=0, reg=DDI_BUF_TRANS(port); i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
  94. I915_WRITE(reg, ddi_translations[i]);
  95. reg += 4;
  96. }
  97. }
  98. /* Program DDI buffers translations for DP. By default, program ports A-D in DP
  99. * mode and port E for FDI.
  100. */
  101. void intel_prepare_ddi(struct drm_device *dev)
  102. {
  103. int port;
  104. if (IS_HASWELL(dev)) {
  105. for (port = PORT_A; port < PORT_E; port++)
  106. intel_prepare_ddi_buffers(dev, port, false);
  107. /* DDI E is the suggested one to work in FDI mode, so program is as such by
  108. * default. It will have to be re-programmed in case a digital DP output
  109. * will be detected on it
  110. */
  111. intel_prepare_ddi_buffers(dev, PORT_E, true);
  112. }
  113. }
  114. static const long hsw_ddi_buf_ctl_values[] = {
  115. DDI_BUF_EMP_400MV_0DB_HSW,
  116. DDI_BUF_EMP_400MV_3_5DB_HSW,
  117. DDI_BUF_EMP_400MV_6DB_HSW,
  118. DDI_BUF_EMP_400MV_9_5DB_HSW,
  119. DDI_BUF_EMP_600MV_0DB_HSW,
  120. DDI_BUF_EMP_600MV_3_5DB_HSW,
  121. DDI_BUF_EMP_600MV_6DB_HSW,
  122. DDI_BUF_EMP_800MV_0DB_HSW,
  123. DDI_BUF_EMP_800MV_3_5DB_HSW
  124. };
  125. /* Starting with Haswell, different DDI ports can work in FDI mode for
  126. * connection to the PCH-located connectors. For this, it is necessary to train
  127. * both the DDI port and PCH receiver for the desired DDI buffer settings.
  128. *
  129. * The recommended port to work in FDI mode is DDI E, which we use here. Also,
  130. * please note that when FDI mode is active on DDI E, it shares 2 lines with
  131. * DDI A (which is used for eDP)
  132. */
  133. void hsw_fdi_link_train(struct drm_crtc *crtc)
  134. {
  135. struct drm_device *dev = crtc->dev;
  136. struct drm_i915_private *dev_priv = dev->dev_private;
  137. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  138. int pipe = intel_crtc->pipe;
  139. u32 reg, temp, i;
  140. /* Start the training iterating through available voltages and emphasis */
  141. for (i=0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values); i++) {
  142. /* Configure DP_TP_CTL with auto-training */
  143. I915_WRITE(DP_TP_CTL(PORT_E),
  144. DP_TP_CTL_FDI_AUTOTRAIN |
  145. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  146. DP_TP_CTL_LINK_TRAIN_PAT1 |
  147. DP_TP_CTL_ENABLE);
  148. /* Configure and enable DDI_BUF_CTL for DDI E with next voltage */
  149. temp = I915_READ(DDI_BUF_CTL(PORT_E));
  150. temp = (temp & ~DDI_BUF_EMP_MASK);
  151. I915_WRITE(DDI_BUF_CTL(PORT_E),
  152. temp |
  153. DDI_BUF_CTL_ENABLE |
  154. DDI_PORT_WIDTH_X2 |
  155. hsw_ddi_buf_ctl_values[i]);
  156. udelay(600);
  157. /* We need to program FDI_RX_MISC with the default TP1 to TP2
  158. * values before enabling the receiver, and configure the delay
  159. * for the FDI timing generator to 90h. Luckily, all the other
  160. * bits are supposed to be zeroed, so we can write those values
  161. * directly.
  162. */
  163. I915_WRITE(FDI_RX_MISC(pipe), FDI_RX_TP1_TO_TP2_48 |
  164. FDI_RX_FDI_DELAY_90);
  165. /* Enable CPU FDI Receiver with auto-training */
  166. reg = FDI_RX_CTL(pipe);
  167. I915_WRITE(reg,
  168. I915_READ(reg) |
  169. FDI_LINK_TRAIN_AUTO |
  170. FDI_RX_ENABLE |
  171. FDI_LINK_TRAIN_PATTERN_1_CPT |
  172. FDI_RX_ENHANCE_FRAME_ENABLE |
  173. FDI_PORT_WIDTH_2X_LPT |
  174. FDI_RX_PLL_ENABLE);
  175. POSTING_READ(reg);
  176. udelay(100);
  177. temp = I915_READ(DP_TP_STATUS(PORT_E));
  178. if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
  179. DRM_DEBUG_DRIVER("BUF_CTL training done on %d step\n", i);
  180. /* Enable normal pixel sending for FDI */
  181. I915_WRITE(DP_TP_CTL(PORT_E),
  182. DP_TP_CTL_FDI_AUTOTRAIN |
  183. DP_TP_CTL_LINK_TRAIN_NORMAL |
  184. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  185. DP_TP_CTL_ENABLE);
  186. break;
  187. } else {
  188. DRM_ERROR("Error training BUF_CTL %d\n", i);
  189. /* Disable DP_TP_CTL and FDI_RX_CTL) and retry */
  190. I915_WRITE(DP_TP_CTL(PORT_E),
  191. I915_READ(DP_TP_CTL(PORT_E)) &
  192. ~DP_TP_CTL_ENABLE);
  193. I915_WRITE(FDI_RX_CTL(pipe),
  194. I915_READ(FDI_RX_CTL(pipe)) &
  195. ~FDI_RX_PLL_ENABLE);
  196. continue;
  197. }
  198. }
  199. DRM_DEBUG_KMS("FDI train done.\n");
  200. }
  201. /* For DDI connections, it is possible to support different outputs over the
  202. * same DDI port, such as HDMI or DP or even VGA via FDI. So we don't know by
  203. * the time the output is detected what exactly is on the other end of it. This
  204. * function aims at providing support for this detection and proper output
  205. * configuration.
  206. */
  207. void intel_ddi_init(struct drm_device *dev, enum port port)
  208. {
  209. /* For now, we don't do any proper output detection and assume that we
  210. * handle HDMI only */
  211. switch(port){
  212. case PORT_A:
  213. DRM_DEBUG_DRIVER("Found digital output on DDI port A\n");
  214. intel_dp_init(dev, DDI_BUF_CTL_A, PORT_A);
  215. break;
  216. /* Assume that the ports B, C and D are working in HDMI mode for now */
  217. case PORT_B:
  218. case PORT_C:
  219. case PORT_D:
  220. intel_hdmi_init(dev, DDI_BUF_CTL(port), port);
  221. break;
  222. default:
  223. DRM_DEBUG_DRIVER("No handlers defined for port %d, skipping DDI initialization\n",
  224. port);
  225. break;
  226. }
  227. }
  228. /* WRPLL clock dividers */
  229. struct wrpll_tmds_clock {
  230. u32 clock;
  231. u16 p; /* Post divider */
  232. u16 n2; /* Feedback divider */
  233. u16 r2; /* Reference divider */
  234. };
  235. /* Table of matching values for WRPLL clocks programming for each frequency.
  236. * The code assumes this table is sorted. */
  237. static const struct wrpll_tmds_clock wrpll_tmds_clock_table[] = {
  238. {19750, 38, 25, 18},
  239. {20000, 48, 32, 18},
  240. {21000, 36, 21, 15},
  241. {21912, 42, 29, 17},
  242. {22000, 36, 22, 15},
  243. {23000, 36, 23, 15},
  244. {23500, 40, 40, 23},
  245. {23750, 26, 16, 14},
  246. {24000, 36, 24, 15},
  247. {25000, 36, 25, 15},
  248. {25175, 26, 40, 33},
  249. {25200, 30, 21, 15},
  250. {26000, 36, 26, 15},
  251. {27000, 30, 21, 14},
  252. {27027, 18, 100, 111},
  253. {27500, 30, 29, 19},
  254. {28000, 34, 30, 17},
  255. {28320, 26, 30, 22},
  256. {28322, 32, 42, 25},
  257. {28750, 24, 23, 18},
  258. {29000, 30, 29, 18},
  259. {29750, 32, 30, 17},
  260. {30000, 30, 25, 15},
  261. {30750, 30, 41, 24},
  262. {31000, 30, 31, 18},
  263. {31500, 30, 28, 16},
  264. {32000, 30, 32, 18},
  265. {32500, 28, 32, 19},
  266. {33000, 24, 22, 15},
  267. {34000, 28, 30, 17},
  268. {35000, 26, 32, 19},
  269. {35500, 24, 30, 19},
  270. {36000, 26, 26, 15},
  271. {36750, 26, 46, 26},
  272. {37000, 24, 23, 14},
  273. {37762, 22, 40, 26},
  274. {37800, 20, 21, 15},
  275. {38000, 24, 27, 16},
  276. {38250, 24, 34, 20},
  277. {39000, 24, 26, 15},
  278. {40000, 24, 32, 18},
  279. {40500, 20, 21, 14},
  280. {40541, 22, 147, 89},
  281. {40750, 18, 19, 14},
  282. {41000, 16, 17, 14},
  283. {41500, 22, 44, 26},
  284. {41540, 22, 44, 26},
  285. {42000, 18, 21, 15},
  286. {42500, 22, 45, 26},
  287. {43000, 20, 43, 27},
  288. {43163, 20, 24, 15},
  289. {44000, 18, 22, 15},
  290. {44900, 20, 108, 65},
  291. {45000, 20, 25, 15},
  292. {45250, 20, 52, 31},
  293. {46000, 18, 23, 15},
  294. {46750, 20, 45, 26},
  295. {47000, 20, 40, 23},
  296. {48000, 18, 24, 15},
  297. {49000, 18, 49, 30},
  298. {49500, 16, 22, 15},
  299. {50000, 18, 25, 15},
  300. {50500, 18, 32, 19},
  301. {51000, 18, 34, 20},
  302. {52000, 18, 26, 15},
  303. {52406, 14, 34, 25},
  304. {53000, 16, 22, 14},
  305. {54000, 16, 24, 15},
  306. {54054, 16, 173, 108},
  307. {54500, 14, 24, 17},
  308. {55000, 12, 22, 18},
  309. {56000, 14, 45, 31},
  310. {56250, 16, 25, 15},
  311. {56750, 14, 25, 17},
  312. {57000, 16, 27, 16},
  313. {58000, 16, 43, 25},
  314. {58250, 16, 38, 22},
  315. {58750, 16, 40, 23},
  316. {59000, 14, 26, 17},
  317. {59341, 14, 40, 26},
  318. {59400, 16, 44, 25},
  319. {60000, 16, 32, 18},
  320. {60500, 12, 39, 29},
  321. {61000, 14, 49, 31},
  322. {62000, 14, 37, 23},
  323. {62250, 14, 42, 26},
  324. {63000, 12, 21, 15},
  325. {63500, 14, 28, 17},
  326. {64000, 12, 27, 19},
  327. {65000, 14, 32, 19},
  328. {65250, 12, 29, 20},
  329. {65500, 12, 32, 22},
  330. {66000, 12, 22, 15},
  331. {66667, 14, 38, 22},
  332. {66750, 10, 21, 17},
  333. {67000, 14, 33, 19},
  334. {67750, 14, 58, 33},
  335. {68000, 14, 30, 17},
  336. {68179, 14, 46, 26},
  337. {68250, 14, 46, 26},
  338. {69000, 12, 23, 15},
  339. {70000, 12, 28, 18},
  340. {71000, 12, 30, 19},
  341. {72000, 12, 24, 15},
  342. {73000, 10, 23, 17},
  343. {74000, 12, 23, 14},
  344. {74176, 8, 100, 91},
  345. {74250, 10, 22, 16},
  346. {74481, 12, 43, 26},
  347. {74500, 10, 29, 21},
  348. {75000, 12, 25, 15},
  349. {75250, 10, 39, 28},
  350. {76000, 12, 27, 16},
  351. {77000, 12, 53, 31},
  352. {78000, 12, 26, 15},
  353. {78750, 12, 28, 16},
  354. {79000, 10, 38, 26},
  355. {79500, 10, 28, 19},
  356. {80000, 12, 32, 18},
  357. {81000, 10, 21, 14},
  358. {81081, 6, 100, 111},
  359. {81624, 8, 29, 24},
  360. {82000, 8, 17, 14},
  361. {83000, 10, 40, 26},
  362. {83950, 10, 28, 18},
  363. {84000, 10, 28, 18},
  364. {84750, 6, 16, 17},
  365. {85000, 6, 17, 18},
  366. {85250, 10, 30, 19},
  367. {85750, 10, 27, 17},
  368. {86000, 10, 43, 27},
  369. {87000, 10, 29, 18},
  370. {88000, 10, 44, 27},
  371. {88500, 10, 41, 25},
  372. {89000, 10, 28, 17},
  373. {89012, 6, 90, 91},
  374. {89100, 10, 33, 20},
  375. {90000, 10, 25, 15},
  376. {91000, 10, 32, 19},
  377. {92000, 10, 46, 27},
  378. {93000, 10, 31, 18},
  379. {94000, 10, 40, 23},
  380. {94500, 10, 28, 16},
  381. {95000, 10, 44, 25},
  382. {95654, 10, 39, 22},
  383. {95750, 10, 39, 22},
  384. {96000, 10, 32, 18},
  385. {97000, 8, 23, 16},
  386. {97750, 8, 42, 29},
  387. {98000, 8, 45, 31},
  388. {99000, 8, 22, 15},
  389. {99750, 8, 34, 23},
  390. {100000, 6, 20, 18},
  391. {100500, 6, 19, 17},
  392. {101000, 6, 37, 33},
  393. {101250, 8, 21, 14},
  394. {102000, 6, 17, 15},
  395. {102250, 6, 25, 22},
  396. {103000, 8, 29, 19},
  397. {104000, 8, 37, 24},
  398. {105000, 8, 28, 18},
  399. {106000, 8, 22, 14},
  400. {107000, 8, 46, 29},
  401. {107214, 8, 27, 17},
  402. {108000, 8, 24, 15},
  403. {108108, 8, 173, 108},
  404. {109000, 6, 23, 19},
  405. {110000, 6, 22, 18},
  406. {110013, 6, 22, 18},
  407. {110250, 8, 49, 30},
  408. {110500, 8, 36, 22},
  409. {111000, 8, 23, 14},
  410. {111264, 8, 150, 91},
  411. {111375, 8, 33, 20},
  412. {112000, 8, 63, 38},
  413. {112500, 8, 25, 15},
  414. {113100, 8, 57, 34},
  415. {113309, 8, 42, 25},
  416. {114000, 8, 27, 16},
  417. {115000, 6, 23, 18},
  418. {116000, 8, 43, 25},
  419. {117000, 8, 26, 15},
  420. {117500, 8, 40, 23},
  421. {118000, 6, 38, 29},
  422. {119000, 8, 30, 17},
  423. {119500, 8, 46, 26},
  424. {119651, 8, 39, 22},
  425. {120000, 8, 32, 18},
  426. {121000, 6, 39, 29},
  427. {121250, 6, 31, 23},
  428. {121750, 6, 23, 17},
  429. {122000, 6, 42, 31},
  430. {122614, 6, 30, 22},
  431. {123000, 6, 41, 30},
  432. {123379, 6, 37, 27},
  433. {124000, 6, 51, 37},
  434. {125000, 6, 25, 18},
  435. {125250, 4, 13, 14},
  436. {125750, 4, 27, 29},
  437. {126000, 6, 21, 15},
  438. {127000, 6, 24, 17},
  439. {127250, 6, 41, 29},
  440. {128000, 6, 27, 19},
  441. {129000, 6, 43, 30},
  442. {129859, 4, 25, 26},
  443. {130000, 6, 26, 18},
  444. {130250, 6, 42, 29},
  445. {131000, 6, 32, 22},
  446. {131500, 6, 38, 26},
  447. {131850, 6, 41, 28},
  448. {132000, 6, 22, 15},
  449. {132750, 6, 28, 19},
  450. {133000, 6, 34, 23},
  451. {133330, 6, 37, 25},
  452. {134000, 6, 61, 41},
  453. {135000, 6, 21, 14},
  454. {135250, 6, 167, 111},
  455. {136000, 6, 62, 41},
  456. {137000, 6, 35, 23},
  457. {138000, 6, 23, 15},
  458. {138500, 6, 40, 26},
  459. {138750, 6, 37, 24},
  460. {139000, 6, 34, 22},
  461. {139050, 6, 34, 22},
  462. {139054, 6, 34, 22},
  463. {140000, 6, 28, 18},
  464. {141000, 6, 36, 23},
  465. {141500, 6, 22, 14},
  466. {142000, 6, 30, 19},
  467. {143000, 6, 27, 17},
  468. {143472, 4, 17, 16},
  469. {144000, 6, 24, 15},
  470. {145000, 6, 29, 18},
  471. {146000, 6, 47, 29},
  472. {146250, 6, 26, 16},
  473. {147000, 6, 49, 30},
  474. {147891, 6, 23, 14},
  475. {148000, 6, 23, 14},
  476. {148250, 6, 28, 17},
  477. {148352, 4, 100, 91},
  478. {148500, 6, 33, 20},
  479. {149000, 6, 48, 29},
  480. {150000, 6, 25, 15},
  481. {151000, 4, 19, 17},
  482. {152000, 6, 27, 16},
  483. {152280, 6, 44, 26},
  484. {153000, 6, 34, 20},
  485. {154000, 6, 53, 31},
  486. {155000, 6, 31, 18},
  487. {155250, 6, 50, 29},
  488. {155750, 6, 45, 26},
  489. {156000, 6, 26, 15},
  490. {157000, 6, 61, 35},
  491. {157500, 6, 28, 16},
  492. {158000, 6, 65, 37},
  493. {158250, 6, 44, 25},
  494. {159000, 6, 53, 30},
  495. {159500, 6, 39, 22},
  496. {160000, 6, 32, 18},
  497. {161000, 4, 31, 26},
  498. {162000, 4, 18, 15},
  499. {162162, 4, 131, 109},
  500. {162500, 4, 53, 44},
  501. {163000, 4, 29, 24},
  502. {164000, 4, 17, 14},
  503. {165000, 4, 22, 18},
  504. {166000, 4, 32, 26},
  505. {167000, 4, 26, 21},
  506. {168000, 4, 46, 37},
  507. {169000, 4, 104, 83},
  508. {169128, 4, 64, 51},
  509. {169500, 4, 39, 31},
  510. {170000, 4, 34, 27},
  511. {171000, 4, 19, 15},
  512. {172000, 4, 51, 40},
  513. {172750, 4, 32, 25},
  514. {172800, 4, 32, 25},
  515. {173000, 4, 41, 32},
  516. {174000, 4, 49, 38},
  517. {174787, 4, 22, 17},
  518. {175000, 4, 35, 27},
  519. {176000, 4, 30, 23},
  520. {177000, 4, 38, 29},
  521. {178000, 4, 29, 22},
  522. {178500, 4, 37, 28},
  523. {179000, 4, 53, 40},
  524. {179500, 4, 73, 55},
  525. {180000, 4, 20, 15},
  526. {181000, 4, 55, 41},
  527. {182000, 4, 31, 23},
  528. {183000, 4, 42, 31},
  529. {184000, 4, 30, 22},
  530. {184750, 4, 26, 19},
  531. {185000, 4, 37, 27},
  532. {186000, 4, 51, 37},
  533. {187000, 4, 36, 26},
  534. {188000, 4, 32, 23},
  535. {189000, 4, 21, 15},
  536. {190000, 4, 38, 27},
  537. {190960, 4, 41, 29},
  538. {191000, 4, 41, 29},
  539. {192000, 4, 27, 19},
  540. {192250, 4, 37, 26},
  541. {193000, 4, 20, 14},
  542. {193250, 4, 53, 37},
  543. {194000, 4, 23, 16},
  544. {194208, 4, 23, 16},
  545. {195000, 4, 26, 18},
  546. {196000, 4, 45, 31},
  547. {197000, 4, 35, 24},
  548. {197750, 4, 41, 28},
  549. {198000, 4, 22, 15},
  550. {198500, 4, 25, 17},
  551. {199000, 4, 28, 19},
  552. {200000, 4, 37, 25},
  553. {201000, 4, 61, 41},
  554. {202000, 4, 112, 75},
  555. {202500, 4, 21, 14},
  556. {203000, 4, 146, 97},
  557. {204000, 4, 62, 41},
  558. {204750, 4, 44, 29},
  559. {205000, 4, 38, 25},
  560. {206000, 4, 29, 19},
  561. {207000, 4, 23, 15},
  562. {207500, 4, 40, 26},
  563. {208000, 4, 37, 24},
  564. {208900, 4, 48, 31},
  565. {209000, 4, 48, 31},
  566. {209250, 4, 31, 20},
  567. {210000, 4, 28, 18},
  568. {211000, 4, 25, 16},
  569. {212000, 4, 22, 14},
  570. {213000, 4, 30, 19},
  571. {213750, 4, 38, 24},
  572. {214000, 4, 46, 29},
  573. {214750, 4, 35, 22},
  574. {215000, 4, 43, 27},
  575. {216000, 4, 24, 15},
  576. {217000, 4, 37, 23},
  577. {218000, 4, 42, 26},
  578. {218250, 4, 42, 26},
  579. {218750, 4, 34, 21},
  580. {219000, 4, 47, 29},
  581. {220000, 4, 44, 27},
  582. {220640, 4, 49, 30},
  583. {220750, 4, 36, 22},
  584. {221000, 4, 36, 22},
  585. {222000, 4, 23, 14},
  586. {222525, 4, 28, 17},
  587. {222750, 4, 33, 20},
  588. {227000, 4, 37, 22},
  589. {230250, 4, 29, 17},
  590. {233500, 4, 38, 22},
  591. {235000, 4, 40, 23},
  592. {238000, 4, 30, 17},
  593. {241500, 2, 17, 19},
  594. {245250, 2, 20, 22},
  595. {247750, 2, 22, 24},
  596. {253250, 2, 15, 16},
  597. {256250, 2, 18, 19},
  598. {262500, 2, 31, 32},
  599. {267250, 2, 66, 67},
  600. {268500, 2, 94, 95},
  601. {270000, 2, 14, 14},
  602. {272500, 2, 77, 76},
  603. {273750, 2, 57, 56},
  604. {280750, 2, 24, 23},
  605. {281250, 2, 23, 22},
  606. {286000, 2, 17, 16},
  607. {291750, 2, 26, 24},
  608. {296703, 2, 56, 51},
  609. {297000, 2, 22, 20},
  610. {298000, 2, 21, 19},
  611. };
  612. void intel_ddi_mode_set(struct drm_encoder *encoder,
  613. struct drm_display_mode *mode,
  614. struct drm_display_mode *adjusted_mode)
  615. {
  616. struct drm_crtc *crtc = encoder->crtc;
  617. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  618. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  619. int port = intel_ddi_get_encoder_port(intel_encoder);
  620. int pipe = intel_crtc->pipe;
  621. int type = intel_encoder->type;
  622. DRM_DEBUG_KMS("Preparing DDI mode for Haswell on port %c, pipe %c\n",
  623. port_name(port), pipe_name(pipe));
  624. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  625. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  626. intel_dp->DP = DDI_BUF_CTL_ENABLE | DDI_BUF_EMP_400MV_0DB_HSW;
  627. switch (intel_dp->lane_count) {
  628. case 1:
  629. intel_dp->DP |= DDI_PORT_WIDTH_X1;
  630. break;
  631. case 2:
  632. intel_dp->DP |= DDI_PORT_WIDTH_X2;
  633. break;
  634. case 4:
  635. intel_dp->DP |= DDI_PORT_WIDTH_X4;
  636. break;
  637. default:
  638. intel_dp->DP |= DDI_PORT_WIDTH_X4;
  639. WARN(1, "Unexpected DP lane count %d\n",
  640. intel_dp->lane_count);
  641. break;
  642. }
  643. intel_dp_init_link_config(intel_dp);
  644. } else if (type == INTEL_OUTPUT_HDMI) {
  645. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  646. if (intel_hdmi->has_audio) {
  647. /* Proper support for digital audio needs a new logic
  648. * and a new set of registers, so we leave it for future
  649. * patch bombing.
  650. */
  651. DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
  652. pipe_name(intel_crtc->pipe));
  653. /* write eld */
  654. DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
  655. intel_write_eld(encoder, adjusted_mode);
  656. }
  657. intel_hdmi->set_infoframes(encoder, adjusted_mode);
  658. }
  659. }
  660. static struct intel_encoder *
  661. intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
  662. {
  663. struct drm_device *dev = crtc->dev;
  664. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  665. struct intel_encoder *intel_encoder, *ret = NULL;
  666. int num_encoders = 0;
  667. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  668. ret = intel_encoder;
  669. num_encoders++;
  670. }
  671. if (num_encoders != 1)
  672. WARN(1, "%d encoders on crtc for pipe %d\n", num_encoders,
  673. intel_crtc->pipe);
  674. BUG_ON(ret == NULL);
  675. return ret;
  676. }
  677. void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
  678. {
  679. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  680. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  681. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  682. uint32_t val;
  683. switch (intel_crtc->ddi_pll_sel) {
  684. case PORT_CLK_SEL_SPLL:
  685. plls->spll_refcount--;
  686. if (plls->spll_refcount == 0) {
  687. DRM_DEBUG_KMS("Disabling SPLL\n");
  688. val = I915_READ(SPLL_CTL);
  689. WARN_ON(!(val & SPLL_PLL_ENABLE));
  690. I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
  691. POSTING_READ(SPLL_CTL);
  692. }
  693. break;
  694. case PORT_CLK_SEL_WRPLL1:
  695. plls->wrpll1_refcount--;
  696. if (plls->wrpll1_refcount == 0) {
  697. DRM_DEBUG_KMS("Disabling WRPLL 1\n");
  698. val = I915_READ(WRPLL_CTL1);
  699. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  700. I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
  701. POSTING_READ(WRPLL_CTL1);
  702. }
  703. break;
  704. case PORT_CLK_SEL_WRPLL2:
  705. plls->wrpll2_refcount--;
  706. if (plls->wrpll2_refcount == 0) {
  707. DRM_DEBUG_KMS("Disabling WRPLL 2\n");
  708. val = I915_READ(WRPLL_CTL2);
  709. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  710. I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
  711. POSTING_READ(WRPLL_CTL2);
  712. }
  713. break;
  714. }
  715. WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
  716. WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
  717. WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
  718. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
  719. }
  720. static void intel_ddi_calculate_wrpll(int clock, int *p, int *n2, int *r2)
  721. {
  722. u32 i;
  723. for (i = 0; i < ARRAY_SIZE(wrpll_tmds_clock_table); i++)
  724. if (clock <= wrpll_tmds_clock_table[i].clock)
  725. break;
  726. if (i == ARRAY_SIZE(wrpll_tmds_clock_table))
  727. i--;
  728. *p = wrpll_tmds_clock_table[i].p;
  729. *n2 = wrpll_tmds_clock_table[i].n2;
  730. *r2 = wrpll_tmds_clock_table[i].r2;
  731. if (wrpll_tmds_clock_table[i].clock != clock)
  732. DRM_INFO("WRPLL: using settings for %dKHz on %dKHz mode\n",
  733. wrpll_tmds_clock_table[i].clock, clock);
  734. DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
  735. clock, *p, *n2, *r2);
  736. }
  737. bool intel_ddi_pll_mode_set(struct drm_crtc *crtc, int clock)
  738. {
  739. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  740. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  741. struct drm_encoder *encoder = &intel_encoder->base;
  742. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  743. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  744. int type = intel_encoder->type;
  745. enum pipe pipe = intel_crtc->pipe;
  746. uint32_t reg, val;
  747. /* TODO: reuse PLLs when possible (compare values) */
  748. intel_ddi_put_crtc_pll(crtc);
  749. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  750. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  751. switch (intel_dp->link_bw) {
  752. case DP_LINK_BW_1_62:
  753. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
  754. break;
  755. case DP_LINK_BW_2_7:
  756. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
  757. break;
  758. case DP_LINK_BW_5_4:
  759. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
  760. break;
  761. default:
  762. DRM_ERROR("Link bandwidth %d unsupported\n",
  763. intel_dp->link_bw);
  764. return false;
  765. }
  766. /* We don't need to turn any PLL on because we'll use LCPLL. */
  767. return true;
  768. } else if (type == INTEL_OUTPUT_HDMI) {
  769. int p, n2, r2;
  770. if (plls->wrpll1_refcount == 0) {
  771. DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
  772. pipe_name(pipe));
  773. plls->wrpll1_refcount++;
  774. reg = WRPLL_CTL1;
  775. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
  776. } else if (plls->wrpll2_refcount == 0) {
  777. DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
  778. pipe_name(pipe));
  779. plls->wrpll2_refcount++;
  780. reg = WRPLL_CTL2;
  781. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
  782. } else {
  783. DRM_ERROR("No WRPLLs available!\n");
  784. return false;
  785. }
  786. WARN(I915_READ(reg) & WRPLL_PLL_ENABLE,
  787. "WRPLL already enabled\n");
  788. intel_ddi_calculate_wrpll(clock, &p, &n2, &r2);
  789. val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
  790. WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
  791. WRPLL_DIVIDER_POST(p);
  792. } else if (type == INTEL_OUTPUT_ANALOG) {
  793. if (plls->spll_refcount == 0) {
  794. DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
  795. pipe_name(pipe));
  796. plls->spll_refcount++;
  797. reg = SPLL_CTL;
  798. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
  799. }
  800. WARN(I915_READ(reg) & SPLL_PLL_ENABLE,
  801. "SPLL already enabled\n");
  802. val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz | SPLL_PLL_SSC;
  803. } else {
  804. WARN(1, "Invalid DDI encoder type %d\n", type);
  805. return false;
  806. }
  807. I915_WRITE(reg, val);
  808. udelay(20);
  809. return true;
  810. }
  811. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
  812. {
  813. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  814. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  815. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  816. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  817. int type = intel_encoder->type;
  818. uint32_t temp;
  819. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  820. temp = TRANS_MSA_SYNC_CLK;
  821. switch (intel_crtc->bpp) {
  822. case 18:
  823. temp |= TRANS_MSA_6_BPC;
  824. break;
  825. case 24:
  826. temp |= TRANS_MSA_8_BPC;
  827. break;
  828. case 30:
  829. temp |= TRANS_MSA_10_BPC;
  830. break;
  831. case 36:
  832. temp |= TRANS_MSA_12_BPC;
  833. break;
  834. default:
  835. temp |= TRANS_MSA_8_BPC;
  836. WARN(1, "%d bpp unsupported by DDI function\n",
  837. intel_crtc->bpp);
  838. }
  839. I915_WRITE(TRANS_MSA_MISC(cpu_transcoder), temp);
  840. }
  841. }
  842. void intel_ddi_enable_pipe_func(struct drm_crtc *crtc)
  843. {
  844. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  845. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  846. struct drm_encoder *encoder = &intel_encoder->base;
  847. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  848. enum pipe pipe = intel_crtc->pipe;
  849. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  850. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  851. int type = intel_encoder->type;
  852. uint32_t temp;
  853. /* Enable TRANS_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  854. temp = TRANS_DDI_FUNC_ENABLE;
  855. temp |= TRANS_DDI_SELECT_PORT(port);
  856. switch (intel_crtc->bpp) {
  857. case 18:
  858. temp |= TRANS_DDI_BPC_6;
  859. break;
  860. case 24:
  861. temp |= TRANS_DDI_BPC_8;
  862. break;
  863. case 30:
  864. temp |= TRANS_DDI_BPC_10;
  865. break;
  866. case 36:
  867. temp |= TRANS_DDI_BPC_12;
  868. break;
  869. default:
  870. WARN(1, "%d bpp unsupported by transcoder DDI function\n",
  871. intel_crtc->bpp);
  872. }
  873. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  874. temp |= TRANS_DDI_PVSYNC;
  875. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  876. temp |= TRANS_DDI_PHSYNC;
  877. if (cpu_transcoder == TRANSCODER_EDP) {
  878. switch (pipe) {
  879. case PIPE_A:
  880. temp |= TRANS_DDI_EDP_INPUT_A_ONOFF;
  881. break;
  882. case PIPE_B:
  883. temp |= TRANS_DDI_EDP_INPUT_B_ONOFF;
  884. break;
  885. case PIPE_C:
  886. temp |= TRANS_DDI_EDP_INPUT_C_ONOFF;
  887. break;
  888. default:
  889. BUG();
  890. break;
  891. }
  892. }
  893. if (type == INTEL_OUTPUT_HDMI) {
  894. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  895. if (intel_hdmi->has_hdmi_sink)
  896. temp |= TRANS_DDI_MODE_SELECT_HDMI;
  897. else
  898. temp |= TRANS_DDI_MODE_SELECT_DVI;
  899. } else if (type == INTEL_OUTPUT_ANALOG) {
  900. temp |= TRANS_DDI_MODE_SELECT_FDI;
  901. } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
  902. type == INTEL_OUTPUT_EDP) {
  903. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  904. temp |= TRANS_DDI_MODE_SELECT_DP_SST;
  905. switch (intel_dp->lane_count) {
  906. case 1:
  907. temp |= TRANS_DDI_PORT_WIDTH_X1;
  908. break;
  909. case 2:
  910. temp |= TRANS_DDI_PORT_WIDTH_X2;
  911. break;
  912. case 4:
  913. temp |= TRANS_DDI_PORT_WIDTH_X4;
  914. break;
  915. default:
  916. temp |= TRANS_DDI_PORT_WIDTH_X4;
  917. WARN(1, "Unsupported lane count %d\n",
  918. intel_dp->lane_count);
  919. }
  920. } else {
  921. WARN(1, "Invalid encoder type %d for pipe %d\n",
  922. intel_encoder->type, pipe);
  923. }
  924. I915_WRITE(TRANS_DDI_FUNC_CTL(cpu_transcoder), temp);
  925. }
  926. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  927. enum transcoder cpu_transcoder)
  928. {
  929. uint32_t reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  930. uint32_t val = I915_READ(reg);
  931. val &= ~(TRANS_DDI_FUNC_ENABLE | TRANS_DDI_PORT_MASK);
  932. val |= TRANS_DDI_PORT_NONE;
  933. I915_WRITE(reg, val);
  934. }
  935. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector)
  936. {
  937. struct drm_device *dev = intel_connector->base.dev;
  938. struct drm_i915_private *dev_priv = dev->dev_private;
  939. struct intel_encoder *intel_encoder = intel_connector->encoder;
  940. int type = intel_connector->base.connector_type;
  941. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  942. enum pipe pipe = 0;
  943. enum transcoder cpu_transcoder;
  944. uint32_t tmp;
  945. if (!intel_encoder->get_hw_state(intel_encoder, &pipe))
  946. return false;
  947. if (port == PORT_A)
  948. cpu_transcoder = TRANSCODER_EDP;
  949. else
  950. cpu_transcoder = pipe;
  951. tmp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  952. switch (tmp & TRANS_DDI_MODE_SELECT_MASK) {
  953. case TRANS_DDI_MODE_SELECT_HDMI:
  954. case TRANS_DDI_MODE_SELECT_DVI:
  955. return (type == DRM_MODE_CONNECTOR_HDMIA);
  956. case TRANS_DDI_MODE_SELECT_DP_SST:
  957. if (type == DRM_MODE_CONNECTOR_eDP)
  958. return true;
  959. case TRANS_DDI_MODE_SELECT_DP_MST:
  960. return (type == DRM_MODE_CONNECTOR_DisplayPort);
  961. case TRANS_DDI_MODE_SELECT_FDI:
  962. return (type == DRM_MODE_CONNECTOR_VGA);
  963. default:
  964. return false;
  965. }
  966. }
  967. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  968. enum pipe *pipe)
  969. {
  970. struct drm_device *dev = encoder->base.dev;
  971. struct drm_i915_private *dev_priv = dev->dev_private;
  972. enum port port = intel_ddi_get_encoder_port(encoder);
  973. u32 tmp;
  974. int i;
  975. tmp = I915_READ(DDI_BUF_CTL(port));
  976. if (!(tmp & DDI_BUF_CTL_ENABLE))
  977. return false;
  978. if (port == PORT_A) {
  979. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  980. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  981. case TRANS_DDI_EDP_INPUT_A_ON:
  982. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  983. *pipe = PIPE_A;
  984. break;
  985. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  986. *pipe = PIPE_B;
  987. break;
  988. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  989. *pipe = PIPE_C;
  990. break;
  991. }
  992. return true;
  993. } else {
  994. for (i = TRANSCODER_A; i <= TRANSCODER_C; i++) {
  995. tmp = I915_READ(TRANS_DDI_FUNC_CTL(i));
  996. if ((tmp & TRANS_DDI_PORT_MASK)
  997. == TRANS_DDI_SELECT_PORT(port)) {
  998. *pipe = i;
  999. return true;
  1000. }
  1001. }
  1002. }
  1003. DRM_DEBUG_KMS("No pipe for ddi port %i found\n", port);
  1004. return true;
  1005. }
  1006. static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
  1007. enum pipe pipe)
  1008. {
  1009. uint32_t temp, ret;
  1010. enum port port;
  1011. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1012. pipe);
  1013. int i;
  1014. if (cpu_transcoder == TRANSCODER_EDP) {
  1015. port = PORT_A;
  1016. } else {
  1017. temp = I915_READ(TRANS_DDI_FUNC_CTL(cpu_transcoder));
  1018. temp &= TRANS_DDI_PORT_MASK;
  1019. for (i = PORT_B; i <= PORT_E; i++)
  1020. if (temp == TRANS_DDI_SELECT_PORT(i))
  1021. port = i;
  1022. }
  1023. ret = I915_READ(PORT_CLK_SEL(port));
  1024. DRM_DEBUG_KMS("Pipe %c connected to port %c using clock 0x%08x\n",
  1025. pipe_name(pipe), port_name(port), ret);
  1026. return ret;
  1027. }
  1028. void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
  1029. {
  1030. struct drm_i915_private *dev_priv = dev->dev_private;
  1031. enum pipe pipe;
  1032. struct intel_crtc *intel_crtc;
  1033. for_each_pipe(pipe) {
  1034. intel_crtc =
  1035. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  1036. if (!intel_crtc->active)
  1037. continue;
  1038. intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
  1039. pipe);
  1040. switch (intel_crtc->ddi_pll_sel) {
  1041. case PORT_CLK_SEL_SPLL:
  1042. dev_priv->ddi_plls.spll_refcount++;
  1043. break;
  1044. case PORT_CLK_SEL_WRPLL1:
  1045. dev_priv->ddi_plls.wrpll1_refcount++;
  1046. break;
  1047. case PORT_CLK_SEL_WRPLL2:
  1048. dev_priv->ddi_plls.wrpll2_refcount++;
  1049. break;
  1050. }
  1051. }
  1052. }
  1053. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
  1054. {
  1055. struct drm_crtc *crtc = &intel_crtc->base;
  1056. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  1057. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  1058. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1059. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  1060. if (cpu_transcoder != TRANSCODER_EDP)
  1061. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1062. TRANS_CLK_SEL_PORT(port));
  1063. }
  1064. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
  1065. {
  1066. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1067. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  1068. if (cpu_transcoder != TRANSCODER_EDP)
  1069. I915_WRITE(TRANS_CLK_SEL(cpu_transcoder),
  1070. TRANS_CLK_SEL_DISABLED);
  1071. }
  1072. void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
  1073. {
  1074. struct drm_encoder *encoder = &intel_encoder->base;
  1075. struct drm_crtc *crtc = encoder->crtc;
  1076. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1077. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1078. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1079. int type = intel_encoder->type;
  1080. if (type == INTEL_OUTPUT_EDP) {
  1081. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1082. ironlake_edp_panel_vdd_on(intel_dp);
  1083. ironlake_edp_panel_on(intel_dp);
  1084. ironlake_edp_panel_vdd_off(intel_dp, true);
  1085. }
  1086. WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
  1087. I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel);
  1088. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  1089. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1090. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1091. intel_dp_start_link_train(intel_dp);
  1092. intel_dp_complete_link_train(intel_dp);
  1093. }
  1094. }
  1095. static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
  1096. enum port port)
  1097. {
  1098. uint32_t reg = DDI_BUF_CTL(port);
  1099. int i;
  1100. for (i = 0; i < 8; i++) {
  1101. udelay(1);
  1102. if (I915_READ(reg) & DDI_BUF_IS_IDLE)
  1103. return;
  1104. }
  1105. DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
  1106. }
  1107. void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
  1108. {
  1109. struct drm_encoder *encoder = &intel_encoder->base;
  1110. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1111. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1112. int type = intel_encoder->type;
  1113. uint32_t val;
  1114. bool wait = false;
  1115. val = I915_READ(DDI_BUF_CTL(port));
  1116. if (val & DDI_BUF_CTL_ENABLE) {
  1117. val &= ~DDI_BUF_CTL_ENABLE;
  1118. I915_WRITE(DDI_BUF_CTL(port), val);
  1119. wait = true;
  1120. }
  1121. val = I915_READ(DP_TP_CTL(port));
  1122. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1123. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1124. I915_WRITE(DP_TP_CTL(port), val);
  1125. if (wait)
  1126. intel_wait_ddi_buf_idle(dev_priv, port);
  1127. if (type == INTEL_OUTPUT_EDP) {
  1128. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1129. ironlake_edp_panel_vdd_on(intel_dp);
  1130. ironlake_edp_panel_off(intel_dp);
  1131. }
  1132. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1133. }
  1134. void intel_enable_ddi(struct intel_encoder *intel_encoder)
  1135. {
  1136. struct drm_encoder *encoder = &intel_encoder->base;
  1137. struct drm_device *dev = encoder->dev;
  1138. struct drm_i915_private *dev_priv = dev->dev_private;
  1139. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  1140. int type = intel_encoder->type;
  1141. if (type == INTEL_OUTPUT_HDMI) {
  1142. /* In HDMI/DVI mode, the port width, and swing/emphasis values
  1143. * are ignored so nothing special needs to be done besides
  1144. * enabling the port.
  1145. */
  1146. I915_WRITE(DDI_BUF_CTL(port), DDI_BUF_CTL_ENABLE);
  1147. } else if (type == INTEL_OUTPUT_EDP) {
  1148. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1149. ironlake_edp_backlight_on(intel_dp);
  1150. }
  1151. }
  1152. void intel_disable_ddi(struct intel_encoder *intel_encoder)
  1153. {
  1154. struct drm_encoder *encoder = &intel_encoder->base;
  1155. int type = intel_encoder->type;
  1156. if (type == INTEL_OUTPUT_EDP) {
  1157. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1158. ironlake_edp_backlight_off(intel_dp);
  1159. }
  1160. }
  1161. int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
  1162. {
  1163. if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT)
  1164. return 450;
  1165. else if ((I915_READ(LCPLL_CTL) & LCPLL_CLK_FREQ_MASK) ==
  1166. LCPLL_CLK_FREQ_450)
  1167. return 450;
  1168. else
  1169. return 540;
  1170. }
  1171. void intel_ddi_pll_init(struct drm_device *dev)
  1172. {
  1173. struct drm_i915_private *dev_priv = dev->dev_private;
  1174. uint32_t val = I915_READ(LCPLL_CTL);
  1175. /* The LCPLL register should be turned on by the BIOS. For now let's
  1176. * just check its state and print errors in case something is wrong.
  1177. * Don't even try to turn it on.
  1178. */
  1179. DRM_DEBUG_KMS("CDCLK running at %dMHz\n",
  1180. intel_ddi_get_cdclk_freq(dev_priv));
  1181. if (val & LCPLL_CD_SOURCE_FCLK)
  1182. DRM_ERROR("CDCLK source is not LCPLL\n");
  1183. if (val & LCPLL_PLL_DISABLE)
  1184. DRM_ERROR("LCPLL is disabled\n");
  1185. }
  1186. void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder)
  1187. {
  1188. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  1189. struct intel_dp *intel_dp = &intel_dig_port->dp;
  1190. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  1191. enum port port = intel_dig_port->port;
  1192. bool wait;
  1193. uint32_t val;
  1194. if (I915_READ(DP_TP_CTL(port)) & DP_TP_CTL_ENABLE) {
  1195. val = I915_READ(DDI_BUF_CTL(port));
  1196. if (val & DDI_BUF_CTL_ENABLE) {
  1197. val &= ~DDI_BUF_CTL_ENABLE;
  1198. I915_WRITE(DDI_BUF_CTL(port), val);
  1199. wait = true;
  1200. }
  1201. val = I915_READ(DP_TP_CTL(port));
  1202. val &= ~(DP_TP_CTL_ENABLE | DP_TP_CTL_LINK_TRAIN_MASK);
  1203. val |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1204. I915_WRITE(DP_TP_CTL(port), val);
  1205. POSTING_READ(DP_TP_CTL(port));
  1206. if (wait)
  1207. intel_wait_ddi_buf_idle(dev_priv, port);
  1208. }
  1209. val = DP_TP_CTL_ENABLE | DP_TP_CTL_MODE_SST |
  1210. DP_TP_CTL_LINK_TRAIN_PAT1 | DP_TP_CTL_SCRAMBLE_DISABLE;
  1211. if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
  1212. val |= DP_TP_CTL_ENHANCED_FRAME_ENABLE;
  1213. I915_WRITE(DP_TP_CTL(port), val);
  1214. POSTING_READ(DP_TP_CTL(port));
  1215. intel_dp->DP |= DDI_BUF_CTL_ENABLE;
  1216. I915_WRITE(DDI_BUF_CTL(port), intel_dp->DP);
  1217. POSTING_READ(DDI_BUF_CTL(port));
  1218. udelay(600);
  1219. }