intel_ddi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  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. /* On Haswell, DDI port buffers must be programmed with correct values
  58. * in advance. The buffer values are different for FDI and DP modes,
  59. * but the HDMI/DVI fields are shared among those. So we program the DDI
  60. * in either FDI or DP modes only, as HDMI connections will work with both
  61. * of those
  62. */
  63. void intel_prepare_ddi_buffers(struct drm_device *dev, enum port port, bool use_fdi_mode)
  64. {
  65. struct drm_i915_private *dev_priv = dev->dev_private;
  66. u32 reg;
  67. int i;
  68. const u32 *ddi_translations = ((use_fdi_mode) ?
  69. hsw_ddi_translations_fdi :
  70. hsw_ddi_translations_dp);
  71. DRM_DEBUG_DRIVER("Initializing DDI buffers for port %c in %s mode\n",
  72. port_name(port),
  73. use_fdi_mode ? "FDI" : "DP");
  74. WARN((use_fdi_mode && (port != PORT_E)),
  75. "Programming port %c in FDI mode, this probably will not work.\n",
  76. port_name(port));
  77. for (i=0, reg=DDI_BUF_TRANS(port); i < ARRAY_SIZE(hsw_ddi_translations_fdi); i++) {
  78. I915_WRITE(reg, ddi_translations[i]);
  79. reg += 4;
  80. }
  81. }
  82. /* Program DDI buffers translations for DP. By default, program ports A-D in DP
  83. * mode and port E for FDI.
  84. */
  85. void intel_prepare_ddi(struct drm_device *dev)
  86. {
  87. int port;
  88. if (IS_HASWELL(dev)) {
  89. for (port = PORT_A; port < PORT_E; port++)
  90. intel_prepare_ddi_buffers(dev, port, false);
  91. /* DDI E is the suggested one to work in FDI mode, so program is as such by
  92. * default. It will have to be re-programmed in case a digital DP output
  93. * will be detected on it
  94. */
  95. intel_prepare_ddi_buffers(dev, PORT_E, true);
  96. }
  97. }
  98. static const long hsw_ddi_buf_ctl_values[] = {
  99. DDI_BUF_EMP_400MV_0DB_HSW,
  100. DDI_BUF_EMP_400MV_3_5DB_HSW,
  101. DDI_BUF_EMP_400MV_6DB_HSW,
  102. DDI_BUF_EMP_400MV_9_5DB_HSW,
  103. DDI_BUF_EMP_600MV_0DB_HSW,
  104. DDI_BUF_EMP_600MV_3_5DB_HSW,
  105. DDI_BUF_EMP_600MV_6DB_HSW,
  106. DDI_BUF_EMP_800MV_0DB_HSW,
  107. DDI_BUF_EMP_800MV_3_5DB_HSW
  108. };
  109. /* Starting with Haswell, different DDI ports can work in FDI mode for
  110. * connection to the PCH-located connectors. For this, it is necessary to train
  111. * both the DDI port and PCH receiver for the desired DDI buffer settings.
  112. *
  113. * The recommended port to work in FDI mode is DDI E, which we use here. Also,
  114. * please note that when FDI mode is active on DDI E, it shares 2 lines with
  115. * DDI A (which is used for eDP)
  116. */
  117. void hsw_fdi_link_train(struct drm_crtc *crtc)
  118. {
  119. struct drm_device *dev = crtc->dev;
  120. struct drm_i915_private *dev_priv = dev->dev_private;
  121. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  122. int pipe = intel_crtc->pipe;
  123. u32 reg, temp, i;
  124. /* Configure CPU PLL, wait for warmup */
  125. I915_WRITE(SPLL_CTL,
  126. SPLL_PLL_ENABLE |
  127. SPLL_PLL_FREQ_1350MHz |
  128. SPLL_PLL_SCC);
  129. /* Use SPLL to drive the output when in FDI mode */
  130. I915_WRITE(PORT_CLK_SEL(PORT_E),
  131. PORT_CLK_SEL_SPLL);
  132. I915_WRITE(PIPE_CLK_SEL(pipe),
  133. PIPE_CLK_SEL_PORT(PORT_E));
  134. udelay(20);
  135. /* Start the training iterating through available voltages and emphasis */
  136. for (i=0; i < ARRAY_SIZE(hsw_ddi_buf_ctl_values); i++) {
  137. /* Configure DP_TP_CTL with auto-training */
  138. I915_WRITE(DP_TP_CTL(PORT_E),
  139. DP_TP_CTL_FDI_AUTOTRAIN |
  140. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  141. DP_TP_CTL_LINK_TRAIN_PAT1 |
  142. DP_TP_CTL_ENABLE);
  143. /* Configure and enable DDI_BUF_CTL for DDI E with next voltage */
  144. temp = I915_READ(DDI_BUF_CTL(PORT_E));
  145. temp = (temp & ~DDI_BUF_EMP_MASK);
  146. I915_WRITE(DDI_BUF_CTL(PORT_E),
  147. temp |
  148. DDI_BUF_CTL_ENABLE |
  149. DDI_PORT_WIDTH_X2 |
  150. hsw_ddi_buf_ctl_values[i]);
  151. udelay(600);
  152. /* We need to program FDI_RX_MISC with the default TP1 to TP2
  153. * values before enabling the receiver, and configure the delay
  154. * for the FDI timing generator to 90h. Luckily, all the other
  155. * bits are supposed to be zeroed, so we can write those values
  156. * directly.
  157. */
  158. I915_WRITE(FDI_RX_MISC(pipe), FDI_RX_TP1_TO_TP2_48 |
  159. FDI_RX_FDI_DELAY_90);
  160. /* Enable CPU FDI Receiver with auto-training */
  161. reg = FDI_RX_CTL(pipe);
  162. I915_WRITE(reg,
  163. I915_READ(reg) |
  164. FDI_LINK_TRAIN_AUTO |
  165. FDI_RX_ENABLE |
  166. FDI_LINK_TRAIN_PATTERN_1_CPT |
  167. FDI_RX_ENHANCE_FRAME_ENABLE |
  168. FDI_PORT_WIDTH_2X_LPT |
  169. FDI_RX_PLL_ENABLE);
  170. POSTING_READ(reg);
  171. udelay(100);
  172. temp = I915_READ(DP_TP_STATUS(PORT_E));
  173. if (temp & DP_TP_STATUS_AUTOTRAIN_DONE) {
  174. DRM_DEBUG_DRIVER("BUF_CTL training done on %d step\n", i);
  175. /* Enable normal pixel sending for FDI */
  176. I915_WRITE(DP_TP_CTL(PORT_E),
  177. DP_TP_CTL_FDI_AUTOTRAIN |
  178. DP_TP_CTL_LINK_TRAIN_NORMAL |
  179. DP_TP_CTL_ENHANCED_FRAME_ENABLE |
  180. DP_TP_CTL_ENABLE);
  181. /* Enable PIPE_DDI_FUNC_CTL for the pipe to work in FDI mode */
  182. temp = I915_READ(DDI_FUNC_CTL(pipe));
  183. temp &= ~PIPE_DDI_PORT_MASK;
  184. temp |= PIPE_DDI_SELECT_PORT(PORT_E) |
  185. PIPE_DDI_MODE_SELECT_FDI |
  186. PIPE_DDI_FUNC_ENABLE |
  187. PIPE_DDI_PORT_WIDTH_X2;
  188. I915_WRITE(DDI_FUNC_CTL(pipe),
  189. temp);
  190. break;
  191. } else {
  192. DRM_ERROR("Error training BUF_CTL %d\n", i);
  193. /* Disable DP_TP_CTL and FDI_RX_CTL) and retry */
  194. I915_WRITE(DP_TP_CTL(PORT_E),
  195. I915_READ(DP_TP_CTL(PORT_E)) &
  196. ~DP_TP_CTL_ENABLE);
  197. I915_WRITE(FDI_RX_CTL(pipe),
  198. I915_READ(FDI_RX_CTL(pipe)) &
  199. ~FDI_RX_PLL_ENABLE);
  200. continue;
  201. }
  202. }
  203. DRM_DEBUG_KMS("FDI train done.\n");
  204. }
  205. /* For DDI connections, it is possible to support different outputs over the
  206. * same DDI port, such as HDMI or DP or even VGA via FDI. So we don't know by
  207. * the time the output is detected what exactly is on the other end of it. This
  208. * function aims at providing support for this detection and proper output
  209. * configuration.
  210. */
  211. void intel_ddi_init(struct drm_device *dev, enum port port)
  212. {
  213. /* For now, we don't do any proper output detection and assume that we
  214. * handle HDMI only */
  215. switch(port){
  216. case PORT_A:
  217. /* We don't handle eDP and DP yet */
  218. DRM_DEBUG_DRIVER("Found digital output on DDI port A\n");
  219. break;
  220. /* Assume that the ports B, C and D are working in HDMI mode for now */
  221. case PORT_B:
  222. case PORT_C:
  223. case PORT_D:
  224. intel_hdmi_init(dev, DDI_BUF_CTL(port), port);
  225. break;
  226. default:
  227. DRM_DEBUG_DRIVER("No handlers defined for port %d, skipping DDI initialization\n",
  228. port);
  229. break;
  230. }
  231. }
  232. /* WRPLL clock dividers */
  233. struct wrpll_tmds_clock {
  234. u32 clock;
  235. u16 p; /* Post divider */
  236. u16 n2; /* Feedback divider */
  237. u16 r2; /* Reference divider */
  238. };
  239. /* Table of matching values for WRPLL clocks programming for each frequency.
  240. * The code assumes this table is sorted. */
  241. static const struct wrpll_tmds_clock wrpll_tmds_clock_table[] = {
  242. {19750, 38, 25, 18},
  243. {20000, 48, 32, 18},
  244. {21000, 36, 21, 15},
  245. {21912, 42, 29, 17},
  246. {22000, 36, 22, 15},
  247. {23000, 36, 23, 15},
  248. {23500, 40, 40, 23},
  249. {23750, 26, 16, 14},
  250. {24000, 36, 24, 15},
  251. {25000, 36, 25, 15},
  252. {25175, 26, 40, 33},
  253. {25200, 30, 21, 15},
  254. {26000, 36, 26, 15},
  255. {27000, 30, 21, 14},
  256. {27027, 18, 100, 111},
  257. {27500, 30, 29, 19},
  258. {28000, 34, 30, 17},
  259. {28320, 26, 30, 22},
  260. {28322, 32, 42, 25},
  261. {28750, 24, 23, 18},
  262. {29000, 30, 29, 18},
  263. {29750, 32, 30, 17},
  264. {30000, 30, 25, 15},
  265. {30750, 30, 41, 24},
  266. {31000, 30, 31, 18},
  267. {31500, 30, 28, 16},
  268. {32000, 30, 32, 18},
  269. {32500, 28, 32, 19},
  270. {33000, 24, 22, 15},
  271. {34000, 28, 30, 17},
  272. {35000, 26, 32, 19},
  273. {35500, 24, 30, 19},
  274. {36000, 26, 26, 15},
  275. {36750, 26, 46, 26},
  276. {37000, 24, 23, 14},
  277. {37762, 22, 40, 26},
  278. {37800, 20, 21, 15},
  279. {38000, 24, 27, 16},
  280. {38250, 24, 34, 20},
  281. {39000, 24, 26, 15},
  282. {40000, 24, 32, 18},
  283. {40500, 20, 21, 14},
  284. {40541, 22, 147, 89},
  285. {40750, 18, 19, 14},
  286. {41000, 16, 17, 14},
  287. {41500, 22, 44, 26},
  288. {41540, 22, 44, 26},
  289. {42000, 18, 21, 15},
  290. {42500, 22, 45, 26},
  291. {43000, 20, 43, 27},
  292. {43163, 20, 24, 15},
  293. {44000, 18, 22, 15},
  294. {44900, 20, 108, 65},
  295. {45000, 20, 25, 15},
  296. {45250, 20, 52, 31},
  297. {46000, 18, 23, 15},
  298. {46750, 20, 45, 26},
  299. {47000, 20, 40, 23},
  300. {48000, 18, 24, 15},
  301. {49000, 18, 49, 30},
  302. {49500, 16, 22, 15},
  303. {50000, 18, 25, 15},
  304. {50500, 18, 32, 19},
  305. {51000, 18, 34, 20},
  306. {52000, 18, 26, 15},
  307. {52406, 14, 34, 25},
  308. {53000, 16, 22, 14},
  309. {54000, 16, 24, 15},
  310. {54054, 16, 173, 108},
  311. {54500, 14, 24, 17},
  312. {55000, 12, 22, 18},
  313. {56000, 14, 45, 31},
  314. {56250, 16, 25, 15},
  315. {56750, 14, 25, 17},
  316. {57000, 16, 27, 16},
  317. {58000, 16, 43, 25},
  318. {58250, 16, 38, 22},
  319. {58750, 16, 40, 23},
  320. {59000, 14, 26, 17},
  321. {59341, 14, 40, 26},
  322. {59400, 16, 44, 25},
  323. {60000, 16, 32, 18},
  324. {60500, 12, 39, 29},
  325. {61000, 14, 49, 31},
  326. {62000, 14, 37, 23},
  327. {62250, 14, 42, 26},
  328. {63000, 12, 21, 15},
  329. {63500, 14, 28, 17},
  330. {64000, 12, 27, 19},
  331. {65000, 14, 32, 19},
  332. {65250, 12, 29, 20},
  333. {65500, 12, 32, 22},
  334. {66000, 12, 22, 15},
  335. {66667, 14, 38, 22},
  336. {66750, 10, 21, 17},
  337. {67000, 14, 33, 19},
  338. {67750, 14, 58, 33},
  339. {68000, 14, 30, 17},
  340. {68179, 14, 46, 26},
  341. {68250, 14, 46, 26},
  342. {69000, 12, 23, 15},
  343. {70000, 12, 28, 18},
  344. {71000, 12, 30, 19},
  345. {72000, 12, 24, 15},
  346. {73000, 10, 23, 17},
  347. {74000, 12, 23, 14},
  348. {74176, 8, 100, 91},
  349. {74250, 10, 22, 16},
  350. {74481, 12, 43, 26},
  351. {74500, 10, 29, 21},
  352. {75000, 12, 25, 15},
  353. {75250, 10, 39, 28},
  354. {76000, 12, 27, 16},
  355. {77000, 12, 53, 31},
  356. {78000, 12, 26, 15},
  357. {78750, 12, 28, 16},
  358. {79000, 10, 38, 26},
  359. {79500, 10, 28, 19},
  360. {80000, 12, 32, 18},
  361. {81000, 10, 21, 14},
  362. {81081, 6, 100, 111},
  363. {81624, 8, 29, 24},
  364. {82000, 8, 17, 14},
  365. {83000, 10, 40, 26},
  366. {83950, 10, 28, 18},
  367. {84000, 10, 28, 18},
  368. {84750, 6, 16, 17},
  369. {85000, 6, 17, 18},
  370. {85250, 10, 30, 19},
  371. {85750, 10, 27, 17},
  372. {86000, 10, 43, 27},
  373. {87000, 10, 29, 18},
  374. {88000, 10, 44, 27},
  375. {88500, 10, 41, 25},
  376. {89000, 10, 28, 17},
  377. {89012, 6, 90, 91},
  378. {89100, 10, 33, 20},
  379. {90000, 10, 25, 15},
  380. {91000, 10, 32, 19},
  381. {92000, 10, 46, 27},
  382. {93000, 10, 31, 18},
  383. {94000, 10, 40, 23},
  384. {94500, 10, 28, 16},
  385. {95000, 10, 44, 25},
  386. {95654, 10, 39, 22},
  387. {95750, 10, 39, 22},
  388. {96000, 10, 32, 18},
  389. {97000, 8, 23, 16},
  390. {97750, 8, 42, 29},
  391. {98000, 8, 45, 31},
  392. {99000, 8, 22, 15},
  393. {99750, 8, 34, 23},
  394. {100000, 6, 20, 18},
  395. {100500, 6, 19, 17},
  396. {101000, 6, 37, 33},
  397. {101250, 8, 21, 14},
  398. {102000, 6, 17, 15},
  399. {102250, 6, 25, 22},
  400. {103000, 8, 29, 19},
  401. {104000, 8, 37, 24},
  402. {105000, 8, 28, 18},
  403. {106000, 8, 22, 14},
  404. {107000, 8, 46, 29},
  405. {107214, 8, 27, 17},
  406. {108000, 8, 24, 15},
  407. {108108, 8, 173, 108},
  408. {109000, 6, 23, 19},
  409. {110000, 6, 22, 18},
  410. {110013, 6, 22, 18},
  411. {110250, 8, 49, 30},
  412. {110500, 8, 36, 22},
  413. {111000, 8, 23, 14},
  414. {111264, 8, 150, 91},
  415. {111375, 8, 33, 20},
  416. {112000, 8, 63, 38},
  417. {112500, 8, 25, 15},
  418. {113100, 8, 57, 34},
  419. {113309, 8, 42, 25},
  420. {114000, 8, 27, 16},
  421. {115000, 6, 23, 18},
  422. {116000, 8, 43, 25},
  423. {117000, 8, 26, 15},
  424. {117500, 8, 40, 23},
  425. {118000, 6, 38, 29},
  426. {119000, 8, 30, 17},
  427. {119500, 8, 46, 26},
  428. {119651, 8, 39, 22},
  429. {120000, 8, 32, 18},
  430. {121000, 6, 39, 29},
  431. {121250, 6, 31, 23},
  432. {121750, 6, 23, 17},
  433. {122000, 6, 42, 31},
  434. {122614, 6, 30, 22},
  435. {123000, 6, 41, 30},
  436. {123379, 6, 37, 27},
  437. {124000, 6, 51, 37},
  438. {125000, 6, 25, 18},
  439. {125250, 4, 13, 14},
  440. {125750, 4, 27, 29},
  441. {126000, 6, 21, 15},
  442. {127000, 6, 24, 17},
  443. {127250, 6, 41, 29},
  444. {128000, 6, 27, 19},
  445. {129000, 6, 43, 30},
  446. {129859, 4, 25, 26},
  447. {130000, 6, 26, 18},
  448. {130250, 6, 42, 29},
  449. {131000, 6, 32, 22},
  450. {131500, 6, 38, 26},
  451. {131850, 6, 41, 28},
  452. {132000, 6, 22, 15},
  453. {132750, 6, 28, 19},
  454. {133000, 6, 34, 23},
  455. {133330, 6, 37, 25},
  456. {134000, 6, 61, 41},
  457. {135000, 6, 21, 14},
  458. {135250, 6, 167, 111},
  459. {136000, 6, 62, 41},
  460. {137000, 6, 35, 23},
  461. {138000, 6, 23, 15},
  462. {138500, 6, 40, 26},
  463. {138750, 6, 37, 24},
  464. {139000, 6, 34, 22},
  465. {139050, 6, 34, 22},
  466. {139054, 6, 34, 22},
  467. {140000, 6, 28, 18},
  468. {141000, 6, 36, 23},
  469. {141500, 6, 22, 14},
  470. {142000, 6, 30, 19},
  471. {143000, 6, 27, 17},
  472. {143472, 4, 17, 16},
  473. {144000, 6, 24, 15},
  474. {145000, 6, 29, 18},
  475. {146000, 6, 47, 29},
  476. {146250, 6, 26, 16},
  477. {147000, 6, 49, 30},
  478. {147891, 6, 23, 14},
  479. {148000, 6, 23, 14},
  480. {148250, 6, 28, 17},
  481. {148352, 4, 100, 91},
  482. {148500, 6, 33, 20},
  483. {149000, 6, 48, 29},
  484. {150000, 6, 25, 15},
  485. {151000, 4, 19, 17},
  486. {152000, 6, 27, 16},
  487. {152280, 6, 44, 26},
  488. {153000, 6, 34, 20},
  489. {154000, 6, 53, 31},
  490. {155000, 6, 31, 18},
  491. {155250, 6, 50, 29},
  492. {155750, 6, 45, 26},
  493. {156000, 6, 26, 15},
  494. {157000, 6, 61, 35},
  495. {157500, 6, 28, 16},
  496. {158000, 6, 65, 37},
  497. {158250, 6, 44, 25},
  498. {159000, 6, 53, 30},
  499. {159500, 6, 39, 22},
  500. {160000, 6, 32, 18},
  501. {161000, 4, 31, 26},
  502. {162000, 4, 18, 15},
  503. {162162, 4, 131, 109},
  504. {162500, 4, 53, 44},
  505. {163000, 4, 29, 24},
  506. {164000, 4, 17, 14},
  507. {165000, 4, 22, 18},
  508. {166000, 4, 32, 26},
  509. {167000, 4, 26, 21},
  510. {168000, 4, 46, 37},
  511. {169000, 4, 104, 83},
  512. {169128, 4, 64, 51},
  513. {169500, 4, 39, 31},
  514. {170000, 4, 34, 27},
  515. {171000, 4, 19, 15},
  516. {172000, 4, 51, 40},
  517. {172750, 4, 32, 25},
  518. {172800, 4, 32, 25},
  519. {173000, 4, 41, 32},
  520. {174000, 4, 49, 38},
  521. {174787, 4, 22, 17},
  522. {175000, 4, 35, 27},
  523. {176000, 4, 30, 23},
  524. {177000, 4, 38, 29},
  525. {178000, 4, 29, 22},
  526. {178500, 4, 37, 28},
  527. {179000, 4, 53, 40},
  528. {179500, 4, 73, 55},
  529. {180000, 4, 20, 15},
  530. {181000, 4, 55, 41},
  531. {182000, 4, 31, 23},
  532. {183000, 4, 42, 31},
  533. {184000, 4, 30, 22},
  534. {184750, 4, 26, 19},
  535. {185000, 4, 37, 27},
  536. {186000, 4, 51, 37},
  537. {187000, 4, 36, 26},
  538. {188000, 4, 32, 23},
  539. {189000, 4, 21, 15},
  540. {190000, 4, 38, 27},
  541. {190960, 4, 41, 29},
  542. {191000, 4, 41, 29},
  543. {192000, 4, 27, 19},
  544. {192250, 4, 37, 26},
  545. {193000, 4, 20, 14},
  546. {193250, 4, 53, 37},
  547. {194000, 4, 23, 16},
  548. {194208, 4, 23, 16},
  549. {195000, 4, 26, 18},
  550. {196000, 4, 45, 31},
  551. {197000, 4, 35, 24},
  552. {197750, 4, 41, 28},
  553. {198000, 4, 22, 15},
  554. {198500, 4, 25, 17},
  555. {199000, 4, 28, 19},
  556. {200000, 4, 37, 25},
  557. {201000, 4, 61, 41},
  558. {202000, 4, 112, 75},
  559. {202500, 4, 21, 14},
  560. {203000, 4, 146, 97},
  561. {204000, 4, 62, 41},
  562. {204750, 4, 44, 29},
  563. {205000, 4, 38, 25},
  564. {206000, 4, 29, 19},
  565. {207000, 4, 23, 15},
  566. {207500, 4, 40, 26},
  567. {208000, 4, 37, 24},
  568. {208900, 4, 48, 31},
  569. {209000, 4, 48, 31},
  570. {209250, 4, 31, 20},
  571. {210000, 4, 28, 18},
  572. {211000, 4, 25, 16},
  573. {212000, 4, 22, 14},
  574. {213000, 4, 30, 19},
  575. {213750, 4, 38, 24},
  576. {214000, 4, 46, 29},
  577. {214750, 4, 35, 22},
  578. {215000, 4, 43, 27},
  579. {216000, 4, 24, 15},
  580. {217000, 4, 37, 23},
  581. {218000, 4, 42, 26},
  582. {218250, 4, 42, 26},
  583. {218750, 4, 34, 21},
  584. {219000, 4, 47, 29},
  585. {220000, 4, 44, 27},
  586. {220640, 4, 49, 30},
  587. {220750, 4, 36, 22},
  588. {221000, 4, 36, 22},
  589. {222000, 4, 23, 14},
  590. {222525, 4, 28, 17},
  591. {222750, 4, 33, 20},
  592. {227000, 4, 37, 22},
  593. {230250, 4, 29, 17},
  594. {233500, 4, 38, 22},
  595. {235000, 4, 40, 23},
  596. {238000, 4, 30, 17},
  597. {241500, 2, 17, 19},
  598. {245250, 2, 20, 22},
  599. {247750, 2, 22, 24},
  600. {253250, 2, 15, 16},
  601. {256250, 2, 18, 19},
  602. {262500, 2, 31, 32},
  603. {267250, 2, 66, 67},
  604. {268500, 2, 94, 95},
  605. {270000, 2, 14, 14},
  606. {272500, 2, 77, 76},
  607. {273750, 2, 57, 56},
  608. {280750, 2, 24, 23},
  609. {281250, 2, 23, 22},
  610. {286000, 2, 17, 16},
  611. {291750, 2, 26, 24},
  612. {296703, 2, 56, 51},
  613. {297000, 2, 22, 20},
  614. {298000, 2, 21, 19},
  615. };
  616. void intel_ddi_mode_set(struct drm_encoder *encoder,
  617. struct drm_display_mode *mode,
  618. struct drm_display_mode *adjusted_mode)
  619. {
  620. struct drm_device *dev = encoder->dev;
  621. struct drm_i915_private *dev_priv = dev->dev_private;
  622. struct drm_crtc *crtc = encoder->crtc;
  623. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  624. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  625. int port = intel_hdmi->ddi_port;
  626. int pipe = intel_crtc->pipe;
  627. int p, n2, r2;
  628. u32 temp, i;
  629. /* On Haswell, we need to enable the clocks and prepare DDI function to
  630. * work in HDMI mode for this pipe.
  631. */
  632. DRM_DEBUG_KMS("Preparing HDMI DDI mode for Haswell on port %c, pipe %c\n", port_name(port), pipe_name(pipe));
  633. for (i = 0; i < ARRAY_SIZE(wrpll_tmds_clock_table); i++)
  634. if (crtc->mode.clock <= wrpll_tmds_clock_table[i].clock)
  635. break;
  636. if (i == ARRAY_SIZE(wrpll_tmds_clock_table))
  637. i--;
  638. p = wrpll_tmds_clock_table[i].p;
  639. n2 = wrpll_tmds_clock_table[i].n2;
  640. r2 = wrpll_tmds_clock_table[i].r2;
  641. if (wrpll_tmds_clock_table[i].clock != crtc->mode.clock)
  642. DRM_INFO("WR PLL: using settings for %dKHz on %dKHz mode\n",
  643. wrpll_tmds_clock_table[i].clock, crtc->mode.clock);
  644. DRM_DEBUG_KMS("WR PLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
  645. crtc->mode.clock, p, n2, r2);
  646. /* Enable LCPLL if disabled */
  647. temp = I915_READ(LCPLL_CTL);
  648. if (temp & LCPLL_PLL_DISABLE)
  649. I915_WRITE(LCPLL_CTL,
  650. temp & ~LCPLL_PLL_DISABLE);
  651. /* Configure WR PLL 1, program the correct divider values for
  652. * the desired frequency and wait for warmup */
  653. I915_WRITE(WRPLL_CTL1,
  654. WRPLL_PLL_ENABLE |
  655. WRPLL_PLL_SELECT_LCPLL_2700 |
  656. WRPLL_DIVIDER_REFERENCE(r2) |
  657. WRPLL_DIVIDER_FEEDBACK(n2) |
  658. WRPLL_DIVIDER_POST(p));
  659. udelay(20);
  660. /* Use WRPLL1 clock to drive the output to the port, and tell the pipe to use
  661. * this port for connection.
  662. */
  663. I915_WRITE(PORT_CLK_SEL(port),
  664. PORT_CLK_SEL_WRPLL1);
  665. I915_WRITE(PIPE_CLK_SEL(pipe),
  666. PIPE_CLK_SEL_PORT(port));
  667. udelay(20);
  668. if (intel_hdmi->has_audio) {
  669. /* Proper support for digital audio needs a new logic and a new set
  670. * of registers, so we leave it for future patch bombing.
  671. */
  672. DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
  673. pipe_name(intel_crtc->pipe));
  674. /* write eld */
  675. DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
  676. intel_write_eld(encoder, adjusted_mode);
  677. }
  678. /* Enable PIPE_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  679. temp = PIPE_DDI_FUNC_ENABLE | PIPE_DDI_SELECT_PORT(port);
  680. switch (intel_crtc->bpp) {
  681. case 18:
  682. temp |= PIPE_DDI_BPC_6;
  683. break;
  684. case 24:
  685. temp |= PIPE_DDI_BPC_8;
  686. break;
  687. case 30:
  688. temp |= PIPE_DDI_BPC_10;
  689. break;
  690. case 36:
  691. temp |= PIPE_DDI_BPC_12;
  692. break;
  693. default:
  694. WARN(1, "%d bpp unsupported by pipe DDI function\n",
  695. intel_crtc->bpp);
  696. }
  697. if (intel_hdmi->has_hdmi_sink)
  698. temp |= PIPE_DDI_MODE_SELECT_HDMI;
  699. else
  700. temp |= PIPE_DDI_MODE_SELECT_DVI;
  701. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  702. temp |= PIPE_DDI_PVSYNC;
  703. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  704. temp |= PIPE_DDI_PHSYNC;
  705. I915_WRITE(DDI_FUNC_CTL(pipe), temp);
  706. intel_hdmi->set_infoframes(encoder, adjusted_mode);
  707. }
  708. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  709. enum pipe *pipe)
  710. {
  711. struct drm_device *dev = encoder->base.dev;
  712. struct drm_i915_private *dev_priv = dev->dev_private;
  713. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  714. u32 tmp;
  715. int i;
  716. tmp = I915_READ(DDI_BUF_CTL(intel_hdmi->ddi_port));
  717. if (!(tmp & DDI_BUF_CTL_ENABLE))
  718. return false;
  719. for_each_pipe(i) {
  720. tmp = I915_READ(DDI_FUNC_CTL(i));
  721. if ((tmp & PIPE_DDI_PORT_MASK)
  722. == PIPE_DDI_SELECT_PORT(intel_hdmi->ddi_port)) {
  723. *pipe = i;
  724. return true;
  725. }
  726. }
  727. DRM_DEBUG_KMS("No pipe for ddi port %i found\n", intel_hdmi->ddi_port);
  728. return true;
  729. }
  730. void intel_enable_ddi(struct intel_encoder *encoder)
  731. {
  732. struct drm_device *dev = encoder->base.dev;
  733. struct drm_i915_private *dev_priv = dev->dev_private;
  734. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  735. int port = intel_hdmi->ddi_port;
  736. u32 temp;
  737. temp = I915_READ(DDI_BUF_CTL(port));
  738. temp |= DDI_BUF_CTL_ENABLE;
  739. /* Enable DDI_BUF_CTL. In HDMI/DVI mode, the port width,
  740. * and swing/emphasis values are ignored so nothing special needs
  741. * to be done besides enabling the port.
  742. */
  743. I915_WRITE(DDI_BUF_CTL(port), temp);
  744. }
  745. void intel_disable_ddi(struct intel_encoder *encoder)
  746. {
  747. struct drm_device *dev = encoder->base.dev;
  748. struct drm_i915_private *dev_priv = dev->dev_private;
  749. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  750. int port = intel_hdmi->ddi_port;
  751. u32 temp;
  752. temp = I915_READ(DDI_BUF_CTL(port));
  753. temp &= ~DDI_BUF_CTL_ENABLE;
  754. I915_WRITE(DDI_BUF_CTL(port), temp);
  755. }