intel_ddi.c 34 KB

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