intel_ddi.c 28 KB

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