intel_ddi.c 19 KB

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