intel_ddi.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  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_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  620. int port = intel_hdmi->ddi_port;
  621. int pipe = intel_crtc->pipe;
  622. /* On Haswell, we need to enable the clocks and prepare DDI function to
  623. * work in HDMI mode for this pipe.
  624. */
  625. DRM_DEBUG_KMS("Preparing HDMI DDI mode for Haswell on port %c, pipe %c\n", port_name(port), pipe_name(pipe));
  626. if (intel_hdmi->has_audio) {
  627. /* Proper support for digital audio needs a new logic and a new set
  628. * of registers, so we leave it for future patch bombing.
  629. */
  630. DRM_DEBUG_DRIVER("HDMI audio on pipe %c on DDI\n",
  631. pipe_name(intel_crtc->pipe));
  632. /* write eld */
  633. DRM_DEBUG_DRIVER("HDMI audio: write eld information\n");
  634. intel_write_eld(encoder, adjusted_mode);
  635. }
  636. intel_hdmi->set_infoframes(encoder, adjusted_mode);
  637. }
  638. static struct intel_encoder *
  639. intel_ddi_get_crtc_encoder(struct drm_crtc *crtc)
  640. {
  641. struct drm_device *dev = crtc->dev;
  642. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  643. struct intel_encoder *intel_encoder, *ret = NULL;
  644. int num_encoders = 0;
  645. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  646. ret = intel_encoder;
  647. num_encoders++;
  648. }
  649. if (num_encoders != 1)
  650. WARN(1, "%d encoders on crtc for pipe %d\n", num_encoders,
  651. intel_crtc->pipe);
  652. BUG_ON(ret == NULL);
  653. return ret;
  654. }
  655. void intel_ddi_put_crtc_pll(struct drm_crtc *crtc)
  656. {
  657. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  658. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  659. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  660. uint32_t val;
  661. switch (intel_crtc->ddi_pll_sel) {
  662. case PORT_CLK_SEL_SPLL:
  663. plls->spll_refcount--;
  664. if (plls->spll_refcount == 0) {
  665. DRM_DEBUG_KMS("Disabling SPLL\n");
  666. val = I915_READ(SPLL_CTL);
  667. WARN_ON(!(val & SPLL_PLL_ENABLE));
  668. I915_WRITE(SPLL_CTL, val & ~SPLL_PLL_ENABLE);
  669. POSTING_READ(SPLL_CTL);
  670. }
  671. break;
  672. case PORT_CLK_SEL_WRPLL1:
  673. plls->wrpll1_refcount--;
  674. if (plls->wrpll1_refcount == 0) {
  675. DRM_DEBUG_KMS("Disabling WRPLL 1\n");
  676. val = I915_READ(WRPLL_CTL1);
  677. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  678. I915_WRITE(WRPLL_CTL1, val & ~WRPLL_PLL_ENABLE);
  679. POSTING_READ(WRPLL_CTL1);
  680. }
  681. break;
  682. case PORT_CLK_SEL_WRPLL2:
  683. plls->wrpll2_refcount--;
  684. if (plls->wrpll2_refcount == 0) {
  685. DRM_DEBUG_KMS("Disabling WRPLL 2\n");
  686. val = I915_READ(WRPLL_CTL2);
  687. WARN_ON(!(val & WRPLL_PLL_ENABLE));
  688. I915_WRITE(WRPLL_CTL2, val & ~WRPLL_PLL_ENABLE);
  689. POSTING_READ(WRPLL_CTL2);
  690. }
  691. break;
  692. }
  693. WARN(plls->spll_refcount < 0, "Invalid SPLL refcount\n");
  694. WARN(plls->wrpll1_refcount < 0, "Invalid WRPLL1 refcount\n");
  695. WARN(plls->wrpll2_refcount < 0, "Invalid WRPLL2 refcount\n");
  696. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_NONE;
  697. }
  698. static void intel_ddi_calculate_wrpll(int clock, int *p, int *n2, int *r2)
  699. {
  700. u32 i;
  701. for (i = 0; i < ARRAY_SIZE(wrpll_tmds_clock_table); i++)
  702. if (clock <= wrpll_tmds_clock_table[i].clock)
  703. break;
  704. if (i == ARRAY_SIZE(wrpll_tmds_clock_table))
  705. i--;
  706. *p = wrpll_tmds_clock_table[i].p;
  707. *n2 = wrpll_tmds_clock_table[i].n2;
  708. *r2 = wrpll_tmds_clock_table[i].r2;
  709. if (wrpll_tmds_clock_table[i].clock != clock)
  710. DRM_INFO("WRPLL: using settings for %dKHz on %dKHz mode\n",
  711. wrpll_tmds_clock_table[i].clock, clock);
  712. DRM_DEBUG_KMS("WRPLL: %dKHz refresh rate with p=%d, n2=%d r2=%d\n",
  713. clock, *p, *n2, *r2);
  714. }
  715. bool intel_ddi_pll_mode_set(struct drm_crtc *crtc, int clock)
  716. {
  717. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  718. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  719. struct drm_encoder *encoder = &intel_encoder->base;
  720. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  721. struct intel_ddi_plls *plls = &dev_priv->ddi_plls;
  722. int type = intel_encoder->type;
  723. enum pipe pipe = intel_crtc->pipe;
  724. uint32_t reg, val;
  725. /* TODO: reuse PLLs when possible (compare values) */
  726. intel_ddi_put_crtc_pll(crtc);
  727. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  728. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  729. switch (intel_dp->link_bw) {
  730. case DP_LINK_BW_1_62:
  731. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_810;
  732. break;
  733. case DP_LINK_BW_2_7:
  734. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_1350;
  735. break;
  736. case DP_LINK_BW_5_4:
  737. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_LCPLL_2700;
  738. break;
  739. default:
  740. DRM_ERROR("Link bandwidth %d unsupported\n",
  741. intel_dp->link_bw);
  742. return false;
  743. }
  744. /* We don't need to turn any PLL on because we'll use LCPLL. */
  745. return true;
  746. } else if (type == INTEL_OUTPUT_HDMI) {
  747. int p, n2, r2;
  748. if (plls->wrpll1_refcount == 0) {
  749. DRM_DEBUG_KMS("Using WRPLL 1 on pipe %c\n",
  750. pipe_name(pipe));
  751. plls->wrpll1_refcount++;
  752. reg = WRPLL_CTL1;
  753. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL1;
  754. } else if (plls->wrpll2_refcount == 0) {
  755. DRM_DEBUG_KMS("Using WRPLL 2 on pipe %c\n",
  756. pipe_name(pipe));
  757. plls->wrpll2_refcount++;
  758. reg = WRPLL_CTL2;
  759. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_WRPLL2;
  760. } else {
  761. DRM_ERROR("No WRPLLs available!\n");
  762. return false;
  763. }
  764. WARN(I915_READ(reg) & WRPLL_PLL_ENABLE,
  765. "WRPLL already enabled\n");
  766. intel_ddi_calculate_wrpll(clock, &p, &n2, &r2);
  767. val = WRPLL_PLL_ENABLE | WRPLL_PLL_SELECT_LCPLL_2700 |
  768. WRPLL_DIVIDER_REFERENCE(r2) | WRPLL_DIVIDER_FEEDBACK(n2) |
  769. WRPLL_DIVIDER_POST(p);
  770. } else if (type == INTEL_OUTPUT_ANALOG) {
  771. if (plls->spll_refcount == 0) {
  772. DRM_DEBUG_KMS("Using SPLL on pipe %c\n",
  773. pipe_name(pipe));
  774. plls->spll_refcount++;
  775. reg = SPLL_CTL;
  776. intel_crtc->ddi_pll_sel = PORT_CLK_SEL_SPLL;
  777. }
  778. WARN(I915_READ(reg) & SPLL_PLL_ENABLE,
  779. "SPLL already enabled\n");
  780. val = SPLL_PLL_ENABLE | SPLL_PLL_FREQ_1350MHz | SPLL_PLL_SSC;
  781. } else {
  782. WARN(1, "Invalid DDI encoder type %d\n", type);
  783. return false;
  784. }
  785. I915_WRITE(reg, val);
  786. udelay(20);
  787. return true;
  788. }
  789. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc)
  790. {
  791. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  792. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  793. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  794. enum pipe pipe = intel_crtc->pipe;
  795. int type = intel_encoder->type;
  796. uint32_t temp;
  797. if (type == INTEL_OUTPUT_DISPLAYPORT || type == INTEL_OUTPUT_EDP) {
  798. temp = PIPE_MSA_SYNC_CLK;
  799. switch (intel_crtc->bpp) {
  800. case 18:
  801. temp |= PIPE_MSA_6_BPC;
  802. break;
  803. case 24:
  804. temp |= PIPE_MSA_8_BPC;
  805. break;
  806. case 30:
  807. temp |= PIPE_MSA_10_BPC;
  808. break;
  809. case 36:
  810. temp |= PIPE_MSA_12_BPC;
  811. break;
  812. default:
  813. temp |= PIPE_MSA_8_BPC;
  814. WARN(1, "%d bpp unsupported by pipe DDI function\n",
  815. intel_crtc->bpp);
  816. }
  817. I915_WRITE(PIPE_MSA_MISC(pipe), temp);
  818. }
  819. }
  820. void intel_ddi_enable_pipe_func(struct drm_crtc *crtc)
  821. {
  822. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  823. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  824. struct drm_encoder *encoder = &intel_encoder->base;
  825. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  826. enum pipe pipe = intel_crtc->pipe;
  827. int type = intel_encoder->type;
  828. uint32_t temp;
  829. /* Enable PIPE_DDI_FUNC_CTL for the pipe to work in HDMI mode */
  830. temp = PIPE_DDI_FUNC_ENABLE;
  831. switch (intel_crtc->bpp) {
  832. case 18:
  833. temp |= PIPE_DDI_BPC_6;
  834. break;
  835. case 24:
  836. temp |= PIPE_DDI_BPC_8;
  837. break;
  838. case 30:
  839. temp |= PIPE_DDI_BPC_10;
  840. break;
  841. case 36:
  842. temp |= PIPE_DDI_BPC_12;
  843. break;
  844. default:
  845. WARN(1, "%d bpp unsupported by pipe DDI function\n",
  846. intel_crtc->bpp);
  847. }
  848. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  849. temp |= PIPE_DDI_PVSYNC;
  850. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  851. temp |= PIPE_DDI_PHSYNC;
  852. if (type == INTEL_OUTPUT_HDMI) {
  853. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  854. if (intel_hdmi->has_hdmi_sink)
  855. temp |= PIPE_DDI_MODE_SELECT_HDMI;
  856. else
  857. temp |= PIPE_DDI_MODE_SELECT_DVI;
  858. temp |= PIPE_DDI_SELECT_PORT(intel_hdmi->ddi_port);
  859. } else if (type == INTEL_OUTPUT_ANALOG) {
  860. temp |= PIPE_DDI_MODE_SELECT_FDI;
  861. temp |= PIPE_DDI_SELECT_PORT(PORT_E);
  862. } else if (type == INTEL_OUTPUT_DISPLAYPORT ||
  863. type == INTEL_OUTPUT_EDP) {
  864. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  865. temp |= PIPE_DDI_MODE_SELECT_DP_SST;
  866. temp |= PIPE_DDI_SELECT_PORT(intel_dp->port);
  867. switch (intel_dp->lane_count) {
  868. case 1:
  869. temp |= PIPE_DDI_PORT_WIDTH_X1;
  870. break;
  871. case 2:
  872. temp |= PIPE_DDI_PORT_WIDTH_X2;
  873. break;
  874. case 4:
  875. temp |= PIPE_DDI_PORT_WIDTH_X4;
  876. break;
  877. default:
  878. temp |= PIPE_DDI_PORT_WIDTH_X4;
  879. WARN(1, "Unsupported lane count %d\n",
  880. intel_dp->lane_count);
  881. }
  882. } else {
  883. WARN(1, "Invalid encoder type %d for pipe %d\n",
  884. intel_encoder->type, pipe);
  885. }
  886. I915_WRITE(DDI_FUNC_CTL(pipe), temp);
  887. }
  888. void intel_ddi_disable_pipe_func(struct drm_i915_private *dev_priv,
  889. enum pipe pipe)
  890. {
  891. uint32_t reg = DDI_FUNC_CTL(pipe);
  892. uint32_t val = I915_READ(reg);
  893. val &= ~(PIPE_DDI_FUNC_ENABLE | PIPE_DDI_PORT_MASK);
  894. val |= PIPE_DDI_PORT_NONE;
  895. I915_WRITE(reg, val);
  896. }
  897. bool intel_ddi_get_hw_state(struct intel_encoder *encoder,
  898. enum pipe *pipe)
  899. {
  900. struct drm_device *dev = encoder->base.dev;
  901. struct drm_i915_private *dev_priv = dev->dev_private;
  902. enum port port = intel_ddi_get_encoder_port(encoder);
  903. u32 tmp;
  904. int i;
  905. tmp = I915_READ(DDI_BUF_CTL(port));
  906. if (!(tmp & DDI_BUF_CTL_ENABLE))
  907. return false;
  908. for_each_pipe(i) {
  909. tmp = I915_READ(DDI_FUNC_CTL(i));
  910. if ((tmp & PIPE_DDI_PORT_MASK)
  911. == PIPE_DDI_SELECT_PORT(port)) {
  912. *pipe = i;
  913. return true;
  914. }
  915. }
  916. DRM_DEBUG_KMS("No pipe for ddi port %i found\n", port);
  917. return true;
  918. }
  919. static uint32_t intel_ddi_get_crtc_pll(struct drm_i915_private *dev_priv,
  920. enum pipe pipe)
  921. {
  922. uint32_t temp, ret;
  923. enum port port;
  924. int i;
  925. temp = I915_READ(DDI_FUNC_CTL(pipe));
  926. temp &= PIPE_DDI_PORT_MASK;
  927. for (i = PORT_A; i <= PORT_E; i++)
  928. if (temp == PIPE_DDI_SELECT_PORT(i))
  929. port = i;
  930. ret = I915_READ(PORT_CLK_SEL(port));
  931. DRM_DEBUG_KMS("Pipe %c connected to port %c using clock 0x%08x\n",
  932. pipe_name(pipe), port_name(port), ret);
  933. return ret;
  934. }
  935. void intel_ddi_setup_hw_pll_state(struct drm_device *dev)
  936. {
  937. struct drm_i915_private *dev_priv = dev->dev_private;
  938. enum pipe pipe;
  939. struct intel_crtc *intel_crtc;
  940. for_each_pipe(pipe) {
  941. intel_crtc =
  942. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  943. if (!intel_crtc->active)
  944. continue;
  945. intel_crtc->ddi_pll_sel = intel_ddi_get_crtc_pll(dev_priv,
  946. pipe);
  947. switch (intel_crtc->ddi_pll_sel) {
  948. case PORT_CLK_SEL_SPLL:
  949. dev_priv->ddi_plls.spll_refcount++;
  950. break;
  951. case PORT_CLK_SEL_WRPLL1:
  952. dev_priv->ddi_plls.wrpll1_refcount++;
  953. break;
  954. case PORT_CLK_SEL_WRPLL2:
  955. dev_priv->ddi_plls.wrpll2_refcount++;
  956. break;
  957. }
  958. }
  959. }
  960. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc)
  961. {
  962. struct drm_crtc *crtc = &intel_crtc->base;
  963. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  964. struct intel_encoder *intel_encoder = intel_ddi_get_crtc_encoder(crtc);
  965. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  966. I915_WRITE(PIPE_CLK_SEL(intel_crtc->pipe), PIPE_CLK_SEL_PORT(port));
  967. }
  968. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc)
  969. {
  970. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  971. I915_WRITE(PIPE_CLK_SEL(intel_crtc->pipe), PIPE_CLK_SEL_DISABLED);
  972. }
  973. void intel_ddi_pre_enable(struct intel_encoder *intel_encoder)
  974. {
  975. struct drm_crtc *crtc = intel_encoder->base.crtc;
  976. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  977. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  978. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  979. WARN_ON(intel_crtc->ddi_pll_sel == PORT_CLK_SEL_NONE);
  980. I915_WRITE(PORT_CLK_SEL(port), intel_crtc->ddi_pll_sel);
  981. }
  982. static void intel_wait_ddi_buf_idle(struct drm_i915_private *dev_priv,
  983. enum port port)
  984. {
  985. uint32_t reg = DDI_BUF_CTL(port);
  986. int i;
  987. for (i = 0; i < 8; i++) {
  988. udelay(1);
  989. if (I915_READ(reg) & DDI_BUF_IS_IDLE)
  990. return;
  991. }
  992. DRM_ERROR("Timeout waiting for DDI BUF %c idle bit\n", port_name(port));
  993. }
  994. void intel_ddi_post_disable(struct intel_encoder *intel_encoder)
  995. {
  996. struct drm_encoder *encoder = &intel_encoder->base;
  997. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  998. enum port port = intel_ddi_get_encoder_port(intel_encoder);
  999. uint32_t val;
  1000. val = I915_READ(DDI_BUF_CTL(port));
  1001. if (val & DDI_BUF_CTL_ENABLE) {
  1002. val &= ~DDI_BUF_CTL_ENABLE;
  1003. I915_WRITE(DDI_BUF_CTL(port), val);
  1004. intel_wait_ddi_buf_idle(dev_priv, port);
  1005. }
  1006. I915_WRITE(PORT_CLK_SEL(port), PORT_CLK_SEL_NONE);
  1007. }
  1008. void intel_enable_ddi(struct intel_encoder *encoder)
  1009. {
  1010. struct drm_device *dev = encoder->base.dev;
  1011. struct drm_i915_private *dev_priv = dev->dev_private;
  1012. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1013. int port = intel_hdmi->ddi_port;
  1014. /* Enable DDI_BUF_CTL. In HDMI/DVI mode, the port width,
  1015. * and swing/emphasis values are ignored so nothing special needs
  1016. * to be done besides enabling the port.
  1017. */
  1018. I915_WRITE(DDI_BUF_CTL(port), DDI_BUF_CTL_ENABLE);
  1019. }
  1020. void intel_disable_ddi(struct intel_encoder *encoder)
  1021. {
  1022. /* This will be needed in the future, so leave it here for now */
  1023. }
  1024. static int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv)
  1025. {
  1026. if (I915_READ(HSW_FUSE_STRAP) & HSW_CDCLK_LIMIT)
  1027. return 450;
  1028. else if ((I915_READ(LCPLL_CTL) & LCPLL_CLK_FREQ_MASK) ==
  1029. LCPLL_CLK_FREQ_450)
  1030. return 450;
  1031. else
  1032. return 540;
  1033. }
  1034. void intel_ddi_pll_init(struct drm_device *dev)
  1035. {
  1036. struct drm_i915_private *dev_priv = dev->dev_private;
  1037. uint32_t val = I915_READ(LCPLL_CTL);
  1038. /* The LCPLL register should be turned on by the BIOS. For now let's
  1039. * just check its state and print errors in case something is wrong.
  1040. * Don't even try to turn it on.
  1041. */
  1042. DRM_DEBUG_KMS("CDCLK running at %dMHz\n",
  1043. intel_ddi_get_cdclk_freq(dev_priv));
  1044. if (val & LCPLL_CD_SOURCE_FCLK)
  1045. DRM_ERROR("CDCLK source is not LCPLL\n");
  1046. if (val & LCPLL_PLL_DISABLE)
  1047. DRM_ERROR("LCPLL is disabled\n");
  1048. }