intel_ddi.c 23 KB

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