intel_dp.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240
  1. /*
  2. * Copyright © 2008 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. * Keith Packard <keithp@keithp.com>
  25. *
  26. */
  27. #include <linux/i2c.h>
  28. #include <linux/slab.h>
  29. #include "drmP.h"
  30. #include "drm.h"
  31. #include "drm_crtc.h"
  32. #include "drm_crtc_helper.h"
  33. #include "intel_drv.h"
  34. #include "i915_drm.h"
  35. #include "i915_drv.h"
  36. #include "drm_dp_helper.h"
  37. #define DP_LINK_STATUS_SIZE 6
  38. #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
  39. #define DP_LINK_CONFIGURATION_SIZE 9
  40. struct intel_dp {
  41. struct intel_encoder base;
  42. uint32_t output_reg;
  43. uint32_t DP;
  44. uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE];
  45. bool has_audio;
  46. int force_audio;
  47. uint32_t color_range;
  48. int dpms_mode;
  49. uint8_t link_bw;
  50. uint8_t lane_count;
  51. uint8_t dpcd[8];
  52. struct i2c_adapter adapter;
  53. struct i2c_algo_dp_aux_data algo;
  54. bool is_pch_edp;
  55. uint8_t train_set[4];
  56. uint8_t link_status[DP_LINK_STATUS_SIZE];
  57. int panel_power_up_delay;
  58. int panel_power_down_delay;
  59. int panel_power_cycle_delay;
  60. int backlight_on_delay;
  61. int backlight_off_delay;
  62. struct drm_display_mode *panel_fixed_mode; /* for eDP */
  63. };
  64. /**
  65. * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
  66. * @intel_dp: DP struct
  67. *
  68. * If a CPU or PCH DP output is attached to an eDP panel, this function
  69. * will return true, and false otherwise.
  70. */
  71. static bool is_edp(struct intel_dp *intel_dp)
  72. {
  73. return intel_dp->base.type == INTEL_OUTPUT_EDP;
  74. }
  75. /**
  76. * is_pch_edp - is the port on the PCH and attached to an eDP panel?
  77. * @intel_dp: DP struct
  78. *
  79. * Returns true if the given DP struct corresponds to a PCH DP port attached
  80. * to an eDP panel, false otherwise. Helpful for determining whether we
  81. * may need FDI resources for a given DP output or not.
  82. */
  83. static bool is_pch_edp(struct intel_dp *intel_dp)
  84. {
  85. return intel_dp->is_pch_edp;
  86. }
  87. static struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
  88. {
  89. return container_of(encoder, struct intel_dp, base.base);
  90. }
  91. static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
  92. {
  93. return container_of(intel_attached_encoder(connector),
  94. struct intel_dp, base);
  95. }
  96. /**
  97. * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
  98. * @encoder: DRM encoder
  99. *
  100. * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
  101. * by intel_display.c.
  102. */
  103. bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
  104. {
  105. struct intel_dp *intel_dp;
  106. if (!encoder)
  107. return false;
  108. intel_dp = enc_to_intel_dp(encoder);
  109. return is_pch_edp(intel_dp);
  110. }
  111. static void intel_dp_start_link_train(struct intel_dp *intel_dp);
  112. static void intel_dp_complete_link_train(struct intel_dp *intel_dp);
  113. static void intel_dp_link_down(struct intel_dp *intel_dp);
  114. void
  115. intel_edp_link_config (struct intel_encoder *intel_encoder,
  116. int *lane_num, int *link_bw)
  117. {
  118. struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
  119. *lane_num = intel_dp->lane_count;
  120. if (intel_dp->link_bw == DP_LINK_BW_1_62)
  121. *link_bw = 162000;
  122. else if (intel_dp->link_bw == DP_LINK_BW_2_7)
  123. *link_bw = 270000;
  124. }
  125. static int
  126. intel_dp_max_lane_count(struct intel_dp *intel_dp)
  127. {
  128. int max_lane_count = 4;
  129. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11) {
  130. max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f;
  131. switch (max_lane_count) {
  132. case 1: case 2: case 4:
  133. break;
  134. default:
  135. max_lane_count = 4;
  136. }
  137. }
  138. return max_lane_count;
  139. }
  140. static int
  141. intel_dp_max_link_bw(struct intel_dp *intel_dp)
  142. {
  143. int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
  144. switch (max_link_bw) {
  145. case DP_LINK_BW_1_62:
  146. case DP_LINK_BW_2_7:
  147. break;
  148. default:
  149. max_link_bw = DP_LINK_BW_1_62;
  150. break;
  151. }
  152. return max_link_bw;
  153. }
  154. static int
  155. intel_dp_link_clock(uint8_t link_bw)
  156. {
  157. if (link_bw == DP_LINK_BW_2_7)
  158. return 270000;
  159. else
  160. return 162000;
  161. }
  162. /* I think this is a fiction */
  163. static int
  164. intel_dp_link_required(struct drm_device *dev, struct intel_dp *intel_dp, int pixel_clock)
  165. {
  166. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  167. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  168. int bpp = 24;
  169. if (intel_crtc)
  170. bpp = intel_crtc->bpp;
  171. return (pixel_clock * bpp + 7) / 8;
  172. }
  173. static int
  174. intel_dp_max_data_rate(int max_link_clock, int max_lanes)
  175. {
  176. return (max_link_clock * max_lanes * 8) / 10;
  177. }
  178. static int
  179. intel_dp_mode_valid(struct drm_connector *connector,
  180. struct drm_display_mode *mode)
  181. {
  182. struct intel_dp *intel_dp = intel_attached_dp(connector);
  183. int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
  184. int max_lanes = intel_dp_max_lane_count(intel_dp);
  185. if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
  186. if (mode->hdisplay > intel_dp->panel_fixed_mode->hdisplay)
  187. return MODE_PANEL;
  188. if (mode->vdisplay > intel_dp->panel_fixed_mode->vdisplay)
  189. return MODE_PANEL;
  190. }
  191. /* only refuse the mode on non eDP since we have seen some weird eDP panels
  192. which are outside spec tolerances but somehow work by magic */
  193. if (!is_edp(intel_dp) &&
  194. (intel_dp_link_required(connector->dev, intel_dp, mode->clock)
  195. > intel_dp_max_data_rate(max_link_clock, max_lanes)))
  196. return MODE_CLOCK_HIGH;
  197. if (mode->clock < 10000)
  198. return MODE_CLOCK_LOW;
  199. return MODE_OK;
  200. }
  201. static uint32_t
  202. pack_aux(uint8_t *src, int src_bytes)
  203. {
  204. int i;
  205. uint32_t v = 0;
  206. if (src_bytes > 4)
  207. src_bytes = 4;
  208. for (i = 0; i < src_bytes; i++)
  209. v |= ((uint32_t) src[i]) << ((3-i) * 8);
  210. return v;
  211. }
  212. static void
  213. unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
  214. {
  215. int i;
  216. if (dst_bytes > 4)
  217. dst_bytes = 4;
  218. for (i = 0; i < dst_bytes; i++)
  219. dst[i] = src >> ((3-i) * 8);
  220. }
  221. /* hrawclock is 1/4 the FSB frequency */
  222. static int
  223. intel_hrawclk(struct drm_device *dev)
  224. {
  225. struct drm_i915_private *dev_priv = dev->dev_private;
  226. uint32_t clkcfg;
  227. clkcfg = I915_READ(CLKCFG);
  228. switch (clkcfg & CLKCFG_FSB_MASK) {
  229. case CLKCFG_FSB_400:
  230. return 100;
  231. case CLKCFG_FSB_533:
  232. return 133;
  233. case CLKCFG_FSB_667:
  234. return 166;
  235. case CLKCFG_FSB_800:
  236. return 200;
  237. case CLKCFG_FSB_1067:
  238. return 266;
  239. case CLKCFG_FSB_1333:
  240. return 333;
  241. /* these two are just a guess; one of them might be right */
  242. case CLKCFG_FSB_1600:
  243. case CLKCFG_FSB_1600_ALT:
  244. return 400;
  245. default:
  246. return 133;
  247. }
  248. }
  249. static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
  250. {
  251. struct drm_device *dev = intel_dp->base.base.dev;
  252. struct drm_i915_private *dev_priv = dev->dev_private;
  253. return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0;
  254. }
  255. static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
  256. {
  257. struct drm_device *dev = intel_dp->base.base.dev;
  258. struct drm_i915_private *dev_priv = dev->dev_private;
  259. return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0;
  260. }
  261. static void
  262. intel_dp_check_edp(struct intel_dp *intel_dp)
  263. {
  264. struct drm_device *dev = intel_dp->base.base.dev;
  265. struct drm_i915_private *dev_priv = dev->dev_private;
  266. if (!is_edp(intel_dp))
  267. return;
  268. if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
  269. WARN(1, "eDP powered off while attempting aux channel communication.\n");
  270. DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
  271. I915_READ(PCH_PP_STATUS),
  272. I915_READ(PCH_PP_CONTROL));
  273. }
  274. }
  275. static int
  276. intel_dp_aux_ch(struct intel_dp *intel_dp,
  277. uint8_t *send, int send_bytes,
  278. uint8_t *recv, int recv_size)
  279. {
  280. uint32_t output_reg = intel_dp->output_reg;
  281. struct drm_device *dev = intel_dp->base.base.dev;
  282. struct drm_i915_private *dev_priv = dev->dev_private;
  283. uint32_t ch_ctl = output_reg + 0x10;
  284. uint32_t ch_data = ch_ctl + 4;
  285. int i;
  286. int recv_bytes;
  287. uint32_t status;
  288. uint32_t aux_clock_divider;
  289. int try, precharge;
  290. intel_dp_check_edp(intel_dp);
  291. /* The clock divider is based off the hrawclk,
  292. * and would like to run at 2MHz. So, take the
  293. * hrawclk value and divide by 2 and use that
  294. *
  295. * Note that PCH attached eDP panels should use a 125MHz input
  296. * clock divider.
  297. */
  298. if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
  299. if (IS_GEN6(dev))
  300. aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */
  301. else
  302. aux_clock_divider = 225; /* eDP input clock at 450Mhz */
  303. } else if (HAS_PCH_SPLIT(dev))
  304. aux_clock_divider = 62; /* IRL input clock fixed at 125Mhz */
  305. else
  306. aux_clock_divider = intel_hrawclk(dev) / 2;
  307. if (IS_GEN6(dev))
  308. precharge = 3;
  309. else
  310. precharge = 5;
  311. /* Try to wait for any previous AUX channel activity */
  312. for (try = 0; try < 3; try++) {
  313. status = I915_READ(ch_ctl);
  314. if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  315. break;
  316. msleep(1);
  317. }
  318. if (try == 3) {
  319. WARN(1, "dp_aux_ch not started status 0x%08x\n",
  320. I915_READ(ch_ctl));
  321. return -EBUSY;
  322. }
  323. /* Must try at least 3 times according to DP spec */
  324. for (try = 0; try < 5; try++) {
  325. /* Load the send data into the aux channel data registers */
  326. for (i = 0; i < send_bytes; i += 4)
  327. I915_WRITE(ch_data + i,
  328. pack_aux(send + i, send_bytes - i));
  329. /* Send the command and wait for it to complete */
  330. I915_WRITE(ch_ctl,
  331. DP_AUX_CH_CTL_SEND_BUSY |
  332. DP_AUX_CH_CTL_TIME_OUT_400us |
  333. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  334. (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
  335. (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
  336. DP_AUX_CH_CTL_DONE |
  337. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  338. DP_AUX_CH_CTL_RECEIVE_ERROR);
  339. for (;;) {
  340. status = I915_READ(ch_ctl);
  341. if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  342. break;
  343. udelay(100);
  344. }
  345. /* Clear done status and any errors */
  346. I915_WRITE(ch_ctl,
  347. status |
  348. DP_AUX_CH_CTL_DONE |
  349. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  350. DP_AUX_CH_CTL_RECEIVE_ERROR);
  351. if (status & DP_AUX_CH_CTL_DONE)
  352. break;
  353. }
  354. if ((status & DP_AUX_CH_CTL_DONE) == 0) {
  355. DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
  356. return -EBUSY;
  357. }
  358. /* Check for timeout or receive error.
  359. * Timeouts occur when the sink is not connected
  360. */
  361. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  362. DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
  363. return -EIO;
  364. }
  365. /* Timeouts occur when the device isn't connected, so they're
  366. * "normal" -- don't fill the kernel log with these */
  367. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
  368. DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
  369. return -ETIMEDOUT;
  370. }
  371. /* Unload any bytes sent back from the other side */
  372. recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
  373. DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
  374. if (recv_bytes > recv_size)
  375. recv_bytes = recv_size;
  376. for (i = 0; i < recv_bytes; i += 4)
  377. unpack_aux(I915_READ(ch_data + i),
  378. recv + i, recv_bytes - i);
  379. return recv_bytes;
  380. }
  381. /* Write data to the aux channel in native mode */
  382. static int
  383. intel_dp_aux_native_write(struct intel_dp *intel_dp,
  384. uint16_t address, uint8_t *send, int send_bytes)
  385. {
  386. int ret;
  387. uint8_t msg[20];
  388. int msg_bytes;
  389. uint8_t ack;
  390. intel_dp_check_edp(intel_dp);
  391. if (send_bytes > 16)
  392. return -1;
  393. msg[0] = AUX_NATIVE_WRITE << 4;
  394. msg[1] = address >> 8;
  395. msg[2] = address & 0xff;
  396. msg[3] = send_bytes - 1;
  397. memcpy(&msg[4], send, send_bytes);
  398. msg_bytes = send_bytes + 4;
  399. for (;;) {
  400. ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
  401. if (ret < 0)
  402. return ret;
  403. if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
  404. break;
  405. else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
  406. udelay(100);
  407. else
  408. return -EIO;
  409. }
  410. return send_bytes;
  411. }
  412. /* Write a single byte to the aux channel in native mode */
  413. static int
  414. intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
  415. uint16_t address, uint8_t byte)
  416. {
  417. return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
  418. }
  419. /* read bytes from a native aux channel */
  420. static int
  421. intel_dp_aux_native_read(struct intel_dp *intel_dp,
  422. uint16_t address, uint8_t *recv, int recv_bytes)
  423. {
  424. uint8_t msg[4];
  425. int msg_bytes;
  426. uint8_t reply[20];
  427. int reply_bytes;
  428. uint8_t ack;
  429. int ret;
  430. intel_dp_check_edp(intel_dp);
  431. msg[0] = AUX_NATIVE_READ << 4;
  432. msg[1] = address >> 8;
  433. msg[2] = address & 0xff;
  434. msg[3] = recv_bytes - 1;
  435. msg_bytes = 4;
  436. reply_bytes = recv_bytes + 1;
  437. for (;;) {
  438. ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
  439. reply, reply_bytes);
  440. if (ret == 0)
  441. return -EPROTO;
  442. if (ret < 0)
  443. return ret;
  444. ack = reply[0];
  445. if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
  446. memcpy(recv, reply + 1, ret - 1);
  447. return ret - 1;
  448. }
  449. else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
  450. udelay(100);
  451. else
  452. return -EIO;
  453. }
  454. }
  455. static int
  456. intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
  457. uint8_t write_byte, uint8_t *read_byte)
  458. {
  459. struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
  460. struct intel_dp *intel_dp = container_of(adapter,
  461. struct intel_dp,
  462. adapter);
  463. uint16_t address = algo_data->address;
  464. uint8_t msg[5];
  465. uint8_t reply[2];
  466. unsigned retry;
  467. int msg_bytes;
  468. int reply_bytes;
  469. int ret;
  470. intel_dp_check_edp(intel_dp);
  471. /* Set up the command byte */
  472. if (mode & MODE_I2C_READ)
  473. msg[0] = AUX_I2C_READ << 4;
  474. else
  475. msg[0] = AUX_I2C_WRITE << 4;
  476. if (!(mode & MODE_I2C_STOP))
  477. msg[0] |= AUX_I2C_MOT << 4;
  478. msg[1] = address >> 8;
  479. msg[2] = address;
  480. switch (mode) {
  481. case MODE_I2C_WRITE:
  482. msg[3] = 0;
  483. msg[4] = write_byte;
  484. msg_bytes = 5;
  485. reply_bytes = 1;
  486. break;
  487. case MODE_I2C_READ:
  488. msg[3] = 0;
  489. msg_bytes = 4;
  490. reply_bytes = 2;
  491. break;
  492. default:
  493. msg_bytes = 3;
  494. reply_bytes = 1;
  495. break;
  496. }
  497. for (retry = 0; retry < 5; retry++) {
  498. ret = intel_dp_aux_ch(intel_dp,
  499. msg, msg_bytes,
  500. reply, reply_bytes);
  501. if (ret < 0) {
  502. DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
  503. return ret;
  504. }
  505. switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
  506. case AUX_NATIVE_REPLY_ACK:
  507. /* I2C-over-AUX Reply field is only valid
  508. * when paired with AUX ACK.
  509. */
  510. break;
  511. case AUX_NATIVE_REPLY_NACK:
  512. DRM_DEBUG_KMS("aux_ch native nack\n");
  513. return -EREMOTEIO;
  514. case AUX_NATIVE_REPLY_DEFER:
  515. udelay(100);
  516. continue;
  517. default:
  518. DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
  519. reply[0]);
  520. return -EREMOTEIO;
  521. }
  522. switch (reply[0] & AUX_I2C_REPLY_MASK) {
  523. case AUX_I2C_REPLY_ACK:
  524. if (mode == MODE_I2C_READ) {
  525. *read_byte = reply[1];
  526. }
  527. return reply_bytes - 1;
  528. case AUX_I2C_REPLY_NACK:
  529. DRM_DEBUG_KMS("aux_i2c nack\n");
  530. return -EREMOTEIO;
  531. case AUX_I2C_REPLY_DEFER:
  532. DRM_DEBUG_KMS("aux_i2c defer\n");
  533. udelay(100);
  534. break;
  535. default:
  536. DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
  537. return -EREMOTEIO;
  538. }
  539. }
  540. DRM_ERROR("too many retries, giving up\n");
  541. return -EREMOTEIO;
  542. }
  543. static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp);
  544. static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp);
  545. static int
  546. intel_dp_i2c_init(struct intel_dp *intel_dp,
  547. struct intel_connector *intel_connector, const char *name)
  548. {
  549. int ret;
  550. DRM_DEBUG_KMS("i2c_init %s\n", name);
  551. intel_dp->algo.running = false;
  552. intel_dp->algo.address = 0;
  553. intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
  554. memset(&intel_dp->adapter, '\0', sizeof (intel_dp->adapter));
  555. intel_dp->adapter.owner = THIS_MODULE;
  556. intel_dp->adapter.class = I2C_CLASS_DDC;
  557. strncpy (intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
  558. intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
  559. intel_dp->adapter.algo_data = &intel_dp->algo;
  560. intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
  561. ironlake_edp_panel_vdd_on(intel_dp);
  562. ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
  563. ironlake_edp_panel_vdd_off(intel_dp);
  564. return ret;
  565. }
  566. static bool
  567. intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
  568. struct drm_display_mode *adjusted_mode)
  569. {
  570. struct drm_device *dev = encoder->dev;
  571. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  572. int lane_count, clock;
  573. int max_lane_count = intel_dp_max_lane_count(intel_dp);
  574. int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
  575. static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
  576. if (is_edp(intel_dp) && intel_dp->panel_fixed_mode) {
  577. intel_fixed_panel_mode(intel_dp->panel_fixed_mode, adjusted_mode);
  578. intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
  579. mode, adjusted_mode);
  580. /*
  581. * the mode->clock is used to calculate the Data&Link M/N
  582. * of the pipe. For the eDP the fixed clock should be used.
  583. */
  584. mode->clock = intel_dp->panel_fixed_mode->clock;
  585. }
  586. for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
  587. for (clock = 0; clock <= max_clock; clock++) {
  588. int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
  589. if (intel_dp_link_required(encoder->dev, intel_dp, mode->clock)
  590. <= link_avail) {
  591. intel_dp->link_bw = bws[clock];
  592. intel_dp->lane_count = lane_count;
  593. adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
  594. DRM_DEBUG_KMS("Display port link bw %02x lane "
  595. "count %d clock %d\n",
  596. intel_dp->link_bw, intel_dp->lane_count,
  597. adjusted_mode->clock);
  598. return true;
  599. }
  600. }
  601. }
  602. if (is_edp(intel_dp)) {
  603. /* okay we failed just pick the highest */
  604. intel_dp->lane_count = max_lane_count;
  605. intel_dp->link_bw = bws[max_clock];
  606. adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
  607. DRM_DEBUG_KMS("Force picking display port link bw %02x lane "
  608. "count %d clock %d\n",
  609. intel_dp->link_bw, intel_dp->lane_count,
  610. adjusted_mode->clock);
  611. return true;
  612. }
  613. return false;
  614. }
  615. struct intel_dp_m_n {
  616. uint32_t tu;
  617. uint32_t gmch_m;
  618. uint32_t gmch_n;
  619. uint32_t link_m;
  620. uint32_t link_n;
  621. };
  622. static void
  623. intel_reduce_ratio(uint32_t *num, uint32_t *den)
  624. {
  625. while (*num > 0xffffff || *den > 0xffffff) {
  626. *num >>= 1;
  627. *den >>= 1;
  628. }
  629. }
  630. static void
  631. intel_dp_compute_m_n(int bpp,
  632. int nlanes,
  633. int pixel_clock,
  634. int link_clock,
  635. struct intel_dp_m_n *m_n)
  636. {
  637. m_n->tu = 64;
  638. m_n->gmch_m = (pixel_clock * bpp) >> 3;
  639. m_n->gmch_n = link_clock * nlanes;
  640. intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  641. m_n->link_m = pixel_clock;
  642. m_n->link_n = link_clock;
  643. intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
  644. }
  645. void
  646. intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
  647. struct drm_display_mode *adjusted_mode)
  648. {
  649. struct drm_device *dev = crtc->dev;
  650. struct drm_mode_config *mode_config = &dev->mode_config;
  651. struct drm_encoder *encoder;
  652. struct drm_i915_private *dev_priv = dev->dev_private;
  653. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  654. int lane_count = 4;
  655. struct intel_dp_m_n m_n;
  656. int pipe = intel_crtc->pipe;
  657. /*
  658. * Find the lane count in the intel_encoder private
  659. */
  660. list_for_each_entry(encoder, &mode_config->encoder_list, head) {
  661. struct intel_dp *intel_dp;
  662. if (encoder->crtc != crtc)
  663. continue;
  664. intel_dp = enc_to_intel_dp(encoder);
  665. if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT) {
  666. lane_count = intel_dp->lane_count;
  667. break;
  668. } else if (is_edp(intel_dp)) {
  669. lane_count = dev_priv->edp.lanes;
  670. break;
  671. }
  672. }
  673. /*
  674. * Compute the GMCH and Link ratios. The '3' here is
  675. * the number of bytes_per_pixel post-LUT, which we always
  676. * set up for 8-bits of R/G/B, or 3 bytes total.
  677. */
  678. intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
  679. mode->clock, adjusted_mode->clock, &m_n);
  680. if (HAS_PCH_SPLIT(dev)) {
  681. I915_WRITE(TRANSDATA_M1(pipe),
  682. ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
  683. m_n.gmch_m);
  684. I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
  685. I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
  686. I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
  687. } else {
  688. I915_WRITE(PIPE_GMCH_DATA_M(pipe),
  689. ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) |
  690. m_n.gmch_m);
  691. I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
  692. I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
  693. I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
  694. }
  695. }
  696. static void ironlake_edp_pll_on(struct drm_encoder *encoder);
  697. static void ironlake_edp_pll_off(struct drm_encoder *encoder);
  698. static void
  699. intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  700. struct drm_display_mode *adjusted_mode)
  701. {
  702. struct drm_device *dev = encoder->dev;
  703. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  704. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  705. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  706. /* Turn on the eDP PLL if needed */
  707. if (is_edp(intel_dp)) {
  708. if (!is_pch_edp(intel_dp))
  709. ironlake_edp_pll_on(encoder);
  710. else
  711. ironlake_edp_pll_off(encoder);
  712. }
  713. intel_dp->DP = DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  714. intel_dp->DP |= intel_dp->color_range;
  715. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  716. intel_dp->DP |= DP_SYNC_HS_HIGH;
  717. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  718. intel_dp->DP |= DP_SYNC_VS_HIGH;
  719. if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
  720. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  721. else
  722. intel_dp->DP |= DP_LINK_TRAIN_OFF;
  723. switch (intel_dp->lane_count) {
  724. case 1:
  725. intel_dp->DP |= DP_PORT_WIDTH_1;
  726. break;
  727. case 2:
  728. intel_dp->DP |= DP_PORT_WIDTH_2;
  729. break;
  730. case 4:
  731. intel_dp->DP |= DP_PORT_WIDTH_4;
  732. break;
  733. }
  734. if (intel_dp->has_audio)
  735. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  736. memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
  737. intel_dp->link_configuration[0] = intel_dp->link_bw;
  738. intel_dp->link_configuration[1] = intel_dp->lane_count;
  739. intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
  740. /*
  741. * Check for DPCD version > 1.1 and enhanced framing support
  742. */
  743. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  744. (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
  745. intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
  746. intel_dp->DP |= DP_ENHANCED_FRAMING;
  747. }
  748. /* CPT DP's pipe select is decided in TRANS_DP_CTL */
  749. if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev))
  750. intel_dp->DP |= DP_PIPEB_SELECT;
  751. if (is_edp(intel_dp) && !is_pch_edp(intel_dp)) {
  752. /* don't miss out required setting for eDP */
  753. intel_dp->DP |= DP_PLL_ENABLE;
  754. if (adjusted_mode->clock < 200000)
  755. intel_dp->DP |= DP_PLL_FREQ_160MHZ;
  756. else
  757. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  758. }
  759. }
  760. static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
  761. {
  762. struct drm_device *dev = intel_dp->base.base.dev;
  763. struct drm_i915_private *dev_priv = dev->dev_private;
  764. u32 pp;
  765. if (!is_edp(intel_dp))
  766. return;
  767. DRM_DEBUG_KMS("Turn eDP VDD on\n");
  768. pp = I915_READ(PCH_PP_CONTROL);
  769. pp &= ~PANEL_UNLOCK_MASK;
  770. pp |= PANEL_UNLOCK_REGS;
  771. pp |= EDP_FORCE_VDD;
  772. I915_WRITE(PCH_PP_CONTROL, pp);
  773. POSTING_READ(PCH_PP_CONTROL);
  774. DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
  775. I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
  776. /*
  777. * If the panel wasn't on, delay before accessing aux channel
  778. */
  779. if (!ironlake_edp_have_panel_power(intel_dp)) {
  780. msleep(intel_dp->panel_power_up_delay);
  781. DRM_DEBUG_KMS("eDP VDD was not on\n");
  782. }
  783. }
  784. static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp)
  785. {
  786. struct drm_device *dev = intel_dp->base.base.dev;
  787. struct drm_i915_private *dev_priv = dev->dev_private;
  788. u32 pp;
  789. if (!is_edp(intel_dp))
  790. return;
  791. DRM_DEBUG_KMS("Turn eDP VDD off\n");
  792. pp = I915_READ(PCH_PP_CONTROL);
  793. pp &= ~PANEL_UNLOCK_MASK;
  794. pp |= PANEL_UNLOCK_REGS;
  795. pp &= ~EDP_FORCE_VDD;
  796. I915_WRITE(PCH_PP_CONTROL, pp);
  797. POSTING_READ(PCH_PP_CONTROL);
  798. /* Make sure sequencer is idle before allowing subsequent activity */
  799. DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
  800. I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
  801. msleep(intel_dp->panel_power_cycle_delay);
  802. }
  803. /* Returns true if the panel was already on when called */
  804. static void ironlake_edp_panel_on (struct intel_dp *intel_dp)
  805. {
  806. struct drm_device *dev = intel_dp->base.base.dev;
  807. struct drm_i915_private *dev_priv = dev->dev_private;
  808. u32 pp, idle_on_mask = PP_ON | PP_SEQUENCE_STATE_ON_IDLE;
  809. if (!is_edp(intel_dp))
  810. return true;
  811. if (ironlake_edp_have_panel_power(intel_dp))
  812. return;
  813. pp = I915_READ(PCH_PP_CONTROL);
  814. pp &= ~PANEL_UNLOCK_MASK;
  815. pp |= PANEL_UNLOCK_REGS;
  816. /* ILK workaround: disable reset around power sequence */
  817. pp &= ~PANEL_POWER_RESET;
  818. I915_WRITE(PCH_PP_CONTROL, pp);
  819. POSTING_READ(PCH_PP_CONTROL);
  820. pp |= POWER_TARGET_ON;
  821. I915_WRITE(PCH_PP_CONTROL, pp);
  822. POSTING_READ(PCH_PP_CONTROL);
  823. if (wait_for((I915_READ(PCH_PP_STATUS) & idle_on_mask) == idle_on_mask,
  824. 5000))
  825. DRM_ERROR("panel on wait timed out: 0x%08x\n",
  826. I915_READ(PCH_PP_STATUS));
  827. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  828. I915_WRITE(PCH_PP_CONTROL, pp);
  829. POSTING_READ(PCH_PP_CONTROL);
  830. }
  831. static void ironlake_edp_panel_off(struct drm_encoder *encoder)
  832. {
  833. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  834. struct drm_device *dev = encoder->dev;
  835. struct drm_i915_private *dev_priv = dev->dev_private;
  836. u32 pp, idle_off_mask = PP_ON | PP_SEQUENCE_MASK |
  837. PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK;
  838. if (!is_edp(intel_dp))
  839. return;
  840. pp = I915_READ(PCH_PP_CONTROL);
  841. pp &= ~PANEL_UNLOCK_MASK;
  842. pp |= PANEL_UNLOCK_REGS;
  843. /* ILK workaround: disable reset around power sequence */
  844. pp &= ~PANEL_POWER_RESET;
  845. I915_WRITE(PCH_PP_CONTROL, pp);
  846. POSTING_READ(PCH_PP_CONTROL);
  847. pp &= ~POWER_TARGET_ON;
  848. I915_WRITE(PCH_PP_CONTROL, pp);
  849. POSTING_READ(PCH_PP_CONTROL);
  850. msleep(intel_dp->panel_power_cycle_delay);
  851. if (wait_for((I915_READ(PCH_PP_STATUS) & idle_off_mask) == 0, 5000))
  852. DRM_ERROR("panel off wait timed out: 0x%08x\n",
  853. I915_READ(PCH_PP_STATUS));
  854. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  855. I915_WRITE(PCH_PP_CONTROL, pp);
  856. POSTING_READ(PCH_PP_CONTROL);
  857. }
  858. static void ironlake_edp_backlight_on (struct intel_dp *intel_dp)
  859. {
  860. struct drm_device *dev = intel_dp->base.base.dev;
  861. struct drm_i915_private *dev_priv = dev->dev_private;
  862. u32 pp;
  863. if (!is_edp(intel_dp))
  864. return;
  865. DRM_DEBUG_KMS("\n");
  866. /*
  867. * If we enable the backlight right away following a panel power
  868. * on, we may see slight flicker as the panel syncs with the eDP
  869. * link. So delay a bit to make sure the image is solid before
  870. * allowing it to appear.
  871. */
  872. msleep(intel_dp->backlight_on_delay);
  873. pp = I915_READ(PCH_PP_CONTROL);
  874. pp &= ~PANEL_UNLOCK_MASK;
  875. pp |= PANEL_UNLOCK_REGS;
  876. pp |= EDP_BLC_ENABLE;
  877. I915_WRITE(PCH_PP_CONTROL, pp);
  878. POSTING_READ(PCH_PP_CONTROL);
  879. }
  880. static void ironlake_edp_backlight_off (struct intel_dp *intel_dp)
  881. {
  882. struct drm_device *dev = intel_dp->base.base.dev;
  883. struct drm_i915_private *dev_priv = dev->dev_private;
  884. u32 pp;
  885. if (!is_edp(intel_dp))
  886. return;
  887. DRM_DEBUG_KMS("\n");
  888. pp = I915_READ(PCH_PP_CONTROL);
  889. pp &= ~PANEL_UNLOCK_MASK;
  890. pp |= PANEL_UNLOCK_REGS;
  891. pp &= ~EDP_BLC_ENABLE;
  892. I915_WRITE(PCH_PP_CONTROL, pp);
  893. POSTING_READ(PCH_PP_CONTROL);
  894. msleep(intel_dp->backlight_off_delay);
  895. }
  896. static void ironlake_edp_pll_on(struct drm_encoder *encoder)
  897. {
  898. struct drm_device *dev = encoder->dev;
  899. struct drm_i915_private *dev_priv = dev->dev_private;
  900. u32 dpa_ctl;
  901. DRM_DEBUG_KMS("\n");
  902. dpa_ctl = I915_READ(DP_A);
  903. dpa_ctl |= DP_PLL_ENABLE;
  904. I915_WRITE(DP_A, dpa_ctl);
  905. POSTING_READ(DP_A);
  906. udelay(200);
  907. }
  908. static void ironlake_edp_pll_off(struct drm_encoder *encoder)
  909. {
  910. struct drm_device *dev = encoder->dev;
  911. struct drm_i915_private *dev_priv = dev->dev_private;
  912. u32 dpa_ctl;
  913. dpa_ctl = I915_READ(DP_A);
  914. dpa_ctl &= ~DP_PLL_ENABLE;
  915. I915_WRITE(DP_A, dpa_ctl);
  916. POSTING_READ(DP_A);
  917. udelay(200);
  918. }
  919. /* If the sink supports it, try to set the power state appropriately */
  920. static void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
  921. {
  922. int ret, i;
  923. /* Should have a valid DPCD by this point */
  924. if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
  925. return;
  926. if (mode != DRM_MODE_DPMS_ON) {
  927. ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
  928. DP_SET_POWER_D3);
  929. if (ret != 1)
  930. DRM_DEBUG_DRIVER("failed to write sink power state\n");
  931. } else {
  932. /*
  933. * When turning on, we need to retry for 1ms to give the sink
  934. * time to wake up.
  935. */
  936. for (i = 0; i < 3; i++) {
  937. ret = intel_dp_aux_native_write_1(intel_dp,
  938. DP_SET_POWER,
  939. DP_SET_POWER_D0);
  940. if (ret == 1)
  941. break;
  942. msleep(1);
  943. }
  944. }
  945. }
  946. static void intel_dp_prepare(struct drm_encoder *encoder)
  947. {
  948. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  949. /* Wake up the sink first */
  950. ironlake_edp_panel_vdd_on(intel_dp);
  951. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  952. ironlake_edp_panel_vdd_off(intel_dp);
  953. /* Make sure the panel is off before trying to
  954. * change the mode
  955. */
  956. ironlake_edp_backlight_off(intel_dp);
  957. intel_dp_link_down(intel_dp);
  958. ironlake_edp_panel_off(encoder);
  959. }
  960. static void intel_dp_commit(struct drm_encoder *encoder)
  961. {
  962. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  963. ironlake_edp_panel_vdd_on(intel_dp);
  964. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  965. intel_dp_start_link_train(intel_dp);
  966. ironlake_edp_panel_on(intel_dp);
  967. ironlake_edp_panel_vdd_off(intel_dp);
  968. intel_dp_complete_link_train(intel_dp);
  969. ironlake_edp_backlight_on(intel_dp);
  970. intel_dp->dpms_mode = DRM_MODE_DPMS_ON;
  971. }
  972. static void
  973. intel_dp_dpms(struct drm_encoder *encoder, int mode)
  974. {
  975. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  976. struct drm_device *dev = encoder->dev;
  977. struct drm_i915_private *dev_priv = dev->dev_private;
  978. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  979. if (mode != DRM_MODE_DPMS_ON) {
  980. ironlake_edp_panel_vdd_on(intel_dp);
  981. if (is_edp(intel_dp))
  982. ironlake_edp_backlight_off(intel_dp);
  983. intel_dp_sink_dpms(intel_dp, mode);
  984. intel_dp_link_down(intel_dp);
  985. ironlake_edp_panel_off(encoder);
  986. if (is_edp(intel_dp) && !is_pch_edp(intel_dp))
  987. ironlake_edp_pll_off(encoder);
  988. ironlake_edp_panel_vdd_off(intel_dp);
  989. } else {
  990. ironlake_edp_panel_vdd_on(intel_dp);
  991. intel_dp_sink_dpms(intel_dp, mode);
  992. if (!(dp_reg & DP_PORT_EN)) {
  993. intel_dp_start_link_train(intel_dp);
  994. ironlake_edp_panel_on(intel_dp);
  995. ironlake_edp_panel_vdd_off(intel_dp);
  996. intel_dp_complete_link_train(intel_dp);
  997. ironlake_edp_backlight_on(intel_dp);
  998. } else
  999. ironlake_edp_panel_vdd_off(intel_dp);
  1000. }
  1001. intel_dp->dpms_mode = mode;
  1002. }
  1003. /*
  1004. * Native read with retry for link status and receiver capability reads for
  1005. * cases where the sink may still be asleep.
  1006. */
  1007. static bool
  1008. intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
  1009. uint8_t *recv, int recv_bytes)
  1010. {
  1011. int ret, i;
  1012. /*
  1013. * Sinks are *supposed* to come up within 1ms from an off state,
  1014. * but we're also supposed to retry 3 times per the spec.
  1015. */
  1016. for (i = 0; i < 3; i++) {
  1017. ret = intel_dp_aux_native_read(intel_dp, address, recv,
  1018. recv_bytes);
  1019. if (ret == recv_bytes)
  1020. return true;
  1021. msleep(1);
  1022. }
  1023. return false;
  1024. }
  1025. /*
  1026. * Fetch AUX CH registers 0x202 - 0x207 which contain
  1027. * link status information
  1028. */
  1029. static bool
  1030. intel_dp_get_link_status(struct intel_dp *intel_dp)
  1031. {
  1032. return intel_dp_aux_native_read_retry(intel_dp,
  1033. DP_LANE0_1_STATUS,
  1034. intel_dp->link_status,
  1035. DP_LINK_STATUS_SIZE);
  1036. }
  1037. static uint8_t
  1038. intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
  1039. int r)
  1040. {
  1041. return link_status[r - DP_LANE0_1_STATUS];
  1042. }
  1043. static uint8_t
  1044. intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE],
  1045. int lane)
  1046. {
  1047. int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
  1048. int s = ((lane & 1) ?
  1049. DP_ADJUST_VOLTAGE_SWING_LANE1_SHIFT :
  1050. DP_ADJUST_VOLTAGE_SWING_LANE0_SHIFT);
  1051. uint8_t l = intel_dp_link_status(link_status, i);
  1052. return ((l >> s) & 3) << DP_TRAIN_VOLTAGE_SWING_SHIFT;
  1053. }
  1054. static uint8_t
  1055. intel_get_adjust_request_pre_emphasis(uint8_t link_status[DP_LINK_STATUS_SIZE],
  1056. int lane)
  1057. {
  1058. int i = DP_ADJUST_REQUEST_LANE0_1 + (lane >> 1);
  1059. int s = ((lane & 1) ?
  1060. DP_ADJUST_PRE_EMPHASIS_LANE1_SHIFT :
  1061. DP_ADJUST_PRE_EMPHASIS_LANE0_SHIFT);
  1062. uint8_t l = intel_dp_link_status(link_status, i);
  1063. return ((l >> s) & 3) << DP_TRAIN_PRE_EMPHASIS_SHIFT;
  1064. }
  1065. #if 0
  1066. static char *voltage_names[] = {
  1067. "0.4V", "0.6V", "0.8V", "1.2V"
  1068. };
  1069. static char *pre_emph_names[] = {
  1070. "0dB", "3.5dB", "6dB", "9.5dB"
  1071. };
  1072. static char *link_train_names[] = {
  1073. "pattern 1", "pattern 2", "idle", "off"
  1074. };
  1075. #endif
  1076. /*
  1077. * These are source-specific values; current Intel hardware supports
  1078. * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
  1079. */
  1080. #define I830_DP_VOLTAGE_MAX DP_TRAIN_VOLTAGE_SWING_800
  1081. static uint8_t
  1082. intel_dp_pre_emphasis_max(uint8_t voltage_swing)
  1083. {
  1084. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1085. case DP_TRAIN_VOLTAGE_SWING_400:
  1086. return DP_TRAIN_PRE_EMPHASIS_6;
  1087. case DP_TRAIN_VOLTAGE_SWING_600:
  1088. return DP_TRAIN_PRE_EMPHASIS_6;
  1089. case DP_TRAIN_VOLTAGE_SWING_800:
  1090. return DP_TRAIN_PRE_EMPHASIS_3_5;
  1091. case DP_TRAIN_VOLTAGE_SWING_1200:
  1092. default:
  1093. return DP_TRAIN_PRE_EMPHASIS_0;
  1094. }
  1095. }
  1096. static void
  1097. intel_get_adjust_train(struct intel_dp *intel_dp)
  1098. {
  1099. uint8_t v = 0;
  1100. uint8_t p = 0;
  1101. int lane;
  1102. for (lane = 0; lane < intel_dp->lane_count; lane++) {
  1103. uint8_t this_v = intel_get_adjust_request_voltage(intel_dp->link_status, lane);
  1104. uint8_t this_p = intel_get_adjust_request_pre_emphasis(intel_dp->link_status, lane);
  1105. if (this_v > v)
  1106. v = this_v;
  1107. if (this_p > p)
  1108. p = this_p;
  1109. }
  1110. if (v >= I830_DP_VOLTAGE_MAX)
  1111. v = I830_DP_VOLTAGE_MAX | DP_TRAIN_MAX_SWING_REACHED;
  1112. if (p >= intel_dp_pre_emphasis_max(v))
  1113. p = intel_dp_pre_emphasis_max(v) | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
  1114. for (lane = 0; lane < 4; lane++)
  1115. intel_dp->train_set[lane] = v | p;
  1116. }
  1117. static uint32_t
  1118. intel_dp_signal_levels(uint8_t train_set, int lane_count)
  1119. {
  1120. uint32_t signal_levels = 0;
  1121. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1122. case DP_TRAIN_VOLTAGE_SWING_400:
  1123. default:
  1124. signal_levels |= DP_VOLTAGE_0_4;
  1125. break;
  1126. case DP_TRAIN_VOLTAGE_SWING_600:
  1127. signal_levels |= DP_VOLTAGE_0_6;
  1128. break;
  1129. case DP_TRAIN_VOLTAGE_SWING_800:
  1130. signal_levels |= DP_VOLTAGE_0_8;
  1131. break;
  1132. case DP_TRAIN_VOLTAGE_SWING_1200:
  1133. signal_levels |= DP_VOLTAGE_1_2;
  1134. break;
  1135. }
  1136. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  1137. case DP_TRAIN_PRE_EMPHASIS_0:
  1138. default:
  1139. signal_levels |= DP_PRE_EMPHASIS_0;
  1140. break;
  1141. case DP_TRAIN_PRE_EMPHASIS_3_5:
  1142. signal_levels |= DP_PRE_EMPHASIS_3_5;
  1143. break;
  1144. case DP_TRAIN_PRE_EMPHASIS_6:
  1145. signal_levels |= DP_PRE_EMPHASIS_6;
  1146. break;
  1147. case DP_TRAIN_PRE_EMPHASIS_9_5:
  1148. signal_levels |= DP_PRE_EMPHASIS_9_5;
  1149. break;
  1150. }
  1151. return signal_levels;
  1152. }
  1153. /* Gen6's DP voltage swing and pre-emphasis control */
  1154. static uint32_t
  1155. intel_gen6_edp_signal_levels(uint8_t train_set)
  1156. {
  1157. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1158. DP_TRAIN_PRE_EMPHASIS_MASK);
  1159. switch (signal_levels) {
  1160. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  1161. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  1162. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  1163. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1164. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  1165. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  1166. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
  1167. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  1168. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1169. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1170. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  1171. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  1172. case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
  1173. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  1174. default:
  1175. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  1176. "0x%x\n", signal_levels);
  1177. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  1178. }
  1179. }
  1180. static uint8_t
  1181. intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE],
  1182. int lane)
  1183. {
  1184. int i = DP_LANE0_1_STATUS + (lane >> 1);
  1185. int s = (lane & 1) * 4;
  1186. uint8_t l = intel_dp_link_status(link_status, i);
  1187. return (l >> s) & 0xf;
  1188. }
  1189. /* Check for clock recovery is done on all channels */
  1190. static bool
  1191. intel_clock_recovery_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count)
  1192. {
  1193. int lane;
  1194. uint8_t lane_status;
  1195. for (lane = 0; lane < lane_count; lane++) {
  1196. lane_status = intel_get_lane_status(link_status, lane);
  1197. if ((lane_status & DP_LANE_CR_DONE) == 0)
  1198. return false;
  1199. }
  1200. return true;
  1201. }
  1202. /* Check to see if channel eq is done on all channels */
  1203. #define CHANNEL_EQ_BITS (DP_LANE_CR_DONE|\
  1204. DP_LANE_CHANNEL_EQ_DONE|\
  1205. DP_LANE_SYMBOL_LOCKED)
  1206. static bool
  1207. intel_channel_eq_ok(struct intel_dp *intel_dp)
  1208. {
  1209. uint8_t lane_align;
  1210. uint8_t lane_status;
  1211. int lane;
  1212. lane_align = intel_dp_link_status(intel_dp->link_status,
  1213. DP_LANE_ALIGN_STATUS_UPDATED);
  1214. if ((lane_align & DP_INTERLANE_ALIGN_DONE) == 0)
  1215. return false;
  1216. for (lane = 0; lane < intel_dp->lane_count; lane++) {
  1217. lane_status = intel_get_lane_status(intel_dp->link_status, lane);
  1218. if ((lane_status & CHANNEL_EQ_BITS) != CHANNEL_EQ_BITS)
  1219. return false;
  1220. }
  1221. return true;
  1222. }
  1223. static bool
  1224. intel_dp_set_link_train(struct intel_dp *intel_dp,
  1225. uint32_t dp_reg_value,
  1226. uint8_t dp_train_pat)
  1227. {
  1228. struct drm_device *dev = intel_dp->base.base.dev;
  1229. struct drm_i915_private *dev_priv = dev->dev_private;
  1230. int ret;
  1231. I915_WRITE(intel_dp->output_reg, dp_reg_value);
  1232. POSTING_READ(intel_dp->output_reg);
  1233. intel_dp_aux_native_write_1(intel_dp,
  1234. DP_TRAINING_PATTERN_SET,
  1235. dp_train_pat);
  1236. ret = intel_dp_aux_native_write(intel_dp,
  1237. DP_TRAINING_LANE0_SET,
  1238. intel_dp->train_set, 4);
  1239. if (ret != 4)
  1240. return false;
  1241. return true;
  1242. }
  1243. /* Enable corresponding port and start training pattern 1 */
  1244. static void
  1245. intel_dp_start_link_train(struct intel_dp *intel_dp)
  1246. {
  1247. struct drm_device *dev = intel_dp->base.base.dev;
  1248. struct drm_i915_private *dev_priv = dev->dev_private;
  1249. struct intel_crtc *intel_crtc = to_intel_crtc(intel_dp->base.base.crtc);
  1250. int i;
  1251. uint8_t voltage;
  1252. bool clock_recovery = false;
  1253. int tries;
  1254. u32 reg;
  1255. uint32_t DP = intel_dp->DP;
  1256. /*
  1257. * On CPT we have to enable the port in training pattern 1, which
  1258. * will happen below in intel_dp_set_link_train. Otherwise, enable
  1259. * the port and wait for it to become active.
  1260. */
  1261. if (!HAS_PCH_CPT(dev)) {
  1262. I915_WRITE(intel_dp->output_reg, intel_dp->DP);
  1263. POSTING_READ(intel_dp->output_reg);
  1264. intel_wait_for_vblank(dev, intel_crtc->pipe);
  1265. }
  1266. /* Write the link configuration data */
  1267. intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
  1268. intel_dp->link_configuration,
  1269. DP_LINK_CONFIGURATION_SIZE);
  1270. DP |= DP_PORT_EN;
  1271. if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
  1272. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  1273. else
  1274. DP &= ~DP_LINK_TRAIN_MASK;
  1275. memset(intel_dp->train_set, 0, 4);
  1276. voltage = 0xff;
  1277. tries = 0;
  1278. clock_recovery = false;
  1279. for (;;) {
  1280. /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
  1281. uint32_t signal_levels;
  1282. if (IS_GEN6(dev) && is_edp(intel_dp)) {
  1283. signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
  1284. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
  1285. } else {
  1286. signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
  1287. DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
  1288. }
  1289. if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
  1290. reg = DP | DP_LINK_TRAIN_PAT_1_CPT;
  1291. else
  1292. reg = DP | DP_LINK_TRAIN_PAT_1;
  1293. if (!intel_dp_set_link_train(intel_dp, reg,
  1294. DP_TRAINING_PATTERN_1 |
  1295. DP_LINK_SCRAMBLING_DISABLE))
  1296. break;
  1297. /* Set training pattern 1 */
  1298. udelay(100);
  1299. if (!intel_dp_get_link_status(intel_dp))
  1300. break;
  1301. if (intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
  1302. clock_recovery = true;
  1303. break;
  1304. }
  1305. /* Check to see if we've tried the max voltage */
  1306. for (i = 0; i < intel_dp->lane_count; i++)
  1307. if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
  1308. break;
  1309. if (i == intel_dp->lane_count)
  1310. break;
  1311. /* Check to see if we've tried the same voltage 5 times */
  1312. if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) == voltage) {
  1313. ++tries;
  1314. if (tries == 5)
  1315. break;
  1316. } else
  1317. tries = 0;
  1318. voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
  1319. /* Compute new intel_dp->train_set as requested by target */
  1320. intel_get_adjust_train(intel_dp);
  1321. }
  1322. intel_dp->DP = DP;
  1323. }
  1324. static void
  1325. intel_dp_complete_link_train(struct intel_dp *intel_dp)
  1326. {
  1327. struct drm_device *dev = intel_dp->base.base.dev;
  1328. struct drm_i915_private *dev_priv = dev->dev_private;
  1329. bool channel_eq = false;
  1330. int tries, cr_tries;
  1331. u32 reg;
  1332. uint32_t DP = intel_dp->DP;
  1333. /* channel equalization */
  1334. tries = 0;
  1335. cr_tries = 0;
  1336. channel_eq = false;
  1337. for (;;) {
  1338. /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
  1339. uint32_t signal_levels;
  1340. if (cr_tries > 5) {
  1341. DRM_ERROR("failed to train DP, aborting\n");
  1342. intel_dp_link_down(intel_dp);
  1343. break;
  1344. }
  1345. if (IS_GEN6(dev) && is_edp(intel_dp)) {
  1346. signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
  1347. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
  1348. } else {
  1349. signal_levels = intel_dp_signal_levels(intel_dp->train_set[0], intel_dp->lane_count);
  1350. DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
  1351. }
  1352. if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
  1353. reg = DP | DP_LINK_TRAIN_PAT_2_CPT;
  1354. else
  1355. reg = DP | DP_LINK_TRAIN_PAT_2;
  1356. /* channel eq pattern */
  1357. if (!intel_dp_set_link_train(intel_dp, reg,
  1358. DP_TRAINING_PATTERN_2 |
  1359. DP_LINK_SCRAMBLING_DISABLE))
  1360. break;
  1361. udelay(400);
  1362. if (!intel_dp_get_link_status(intel_dp))
  1363. break;
  1364. /* Make sure clock is still ok */
  1365. if (!intel_clock_recovery_ok(intel_dp->link_status, intel_dp->lane_count)) {
  1366. intel_dp_start_link_train(intel_dp);
  1367. cr_tries++;
  1368. continue;
  1369. }
  1370. if (intel_channel_eq_ok(intel_dp)) {
  1371. channel_eq = true;
  1372. break;
  1373. }
  1374. /* Try 5 times, then try clock recovery if that fails */
  1375. if (tries > 5) {
  1376. intel_dp_link_down(intel_dp);
  1377. intel_dp_start_link_train(intel_dp);
  1378. tries = 0;
  1379. cr_tries++;
  1380. continue;
  1381. }
  1382. /* Compute new intel_dp->train_set as requested by target */
  1383. intel_get_adjust_train(intel_dp);
  1384. ++tries;
  1385. }
  1386. if (HAS_PCH_CPT(dev) && !is_edp(intel_dp))
  1387. reg = DP | DP_LINK_TRAIN_OFF_CPT;
  1388. else
  1389. reg = DP | DP_LINK_TRAIN_OFF;
  1390. I915_WRITE(intel_dp->output_reg, reg);
  1391. POSTING_READ(intel_dp->output_reg);
  1392. intel_dp_aux_native_write_1(intel_dp,
  1393. DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE);
  1394. }
  1395. static void
  1396. intel_dp_link_down(struct intel_dp *intel_dp)
  1397. {
  1398. struct drm_device *dev = intel_dp->base.base.dev;
  1399. struct drm_i915_private *dev_priv = dev->dev_private;
  1400. uint32_t DP = intel_dp->DP;
  1401. if ((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0)
  1402. return;
  1403. DRM_DEBUG_KMS("\n");
  1404. if (is_edp(intel_dp)) {
  1405. DP &= ~DP_PLL_ENABLE;
  1406. I915_WRITE(intel_dp->output_reg, DP);
  1407. POSTING_READ(intel_dp->output_reg);
  1408. udelay(100);
  1409. }
  1410. if (HAS_PCH_CPT(dev) && !is_edp(intel_dp)) {
  1411. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  1412. I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
  1413. } else {
  1414. DP &= ~DP_LINK_TRAIN_MASK;
  1415. I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
  1416. }
  1417. POSTING_READ(intel_dp->output_reg);
  1418. msleep(17);
  1419. if (is_edp(intel_dp))
  1420. DP |= DP_LINK_TRAIN_OFF;
  1421. if (!HAS_PCH_CPT(dev) &&
  1422. I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
  1423. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1424. /* Hardware workaround: leaving our transcoder select
  1425. * set to transcoder B while it's off will prevent the
  1426. * corresponding HDMI output on transcoder A.
  1427. *
  1428. * Combine this with another hardware workaround:
  1429. * transcoder select bit can only be cleared while the
  1430. * port is enabled.
  1431. */
  1432. DP &= ~DP_PIPEB_SELECT;
  1433. I915_WRITE(intel_dp->output_reg, DP);
  1434. /* Changes to enable or select take place the vblank
  1435. * after being written.
  1436. */
  1437. if (crtc == NULL) {
  1438. /* We can arrive here never having been attached
  1439. * to a CRTC, for instance, due to inheriting
  1440. * random state from the BIOS.
  1441. *
  1442. * If the pipe is not running, play safe and
  1443. * wait for the clocks to stabilise before
  1444. * continuing.
  1445. */
  1446. POSTING_READ(intel_dp->output_reg);
  1447. msleep(50);
  1448. } else
  1449. intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
  1450. }
  1451. I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
  1452. POSTING_READ(intel_dp->output_reg);
  1453. msleep(intel_dp->panel_power_down_delay);
  1454. }
  1455. static bool
  1456. intel_dp_get_dpcd(struct intel_dp *intel_dp)
  1457. {
  1458. if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
  1459. sizeof (intel_dp->dpcd)) &&
  1460. (intel_dp->dpcd[DP_DPCD_REV] != 0)) {
  1461. return true;
  1462. }
  1463. return false;
  1464. }
  1465. /*
  1466. * According to DP spec
  1467. * 5.1.2:
  1468. * 1. Read DPCD
  1469. * 2. Configure link according to Receiver Capabilities
  1470. * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
  1471. * 4. Check link status on receipt of hot-plug interrupt
  1472. */
  1473. static void
  1474. intel_dp_check_link_status(struct intel_dp *intel_dp)
  1475. {
  1476. if (intel_dp->dpms_mode != DRM_MODE_DPMS_ON)
  1477. return;
  1478. if (!intel_dp->base.base.crtc)
  1479. return;
  1480. /* Try to read receiver status if the link appears to be up */
  1481. if (!intel_dp_get_link_status(intel_dp)) {
  1482. intel_dp_link_down(intel_dp);
  1483. return;
  1484. }
  1485. /* Now read the DPCD to see if it's actually running */
  1486. if (!intel_dp_get_dpcd(intel_dp)) {
  1487. intel_dp_link_down(intel_dp);
  1488. return;
  1489. }
  1490. if (!intel_channel_eq_ok(intel_dp)) {
  1491. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  1492. drm_get_encoder_name(&intel_dp->base.base));
  1493. intel_dp_start_link_train(intel_dp);
  1494. intel_dp_complete_link_train(intel_dp);
  1495. }
  1496. }
  1497. static enum drm_connector_status
  1498. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  1499. {
  1500. if (intel_dp_get_dpcd(intel_dp))
  1501. return connector_status_connected;
  1502. return connector_status_disconnected;
  1503. }
  1504. static enum drm_connector_status
  1505. ironlake_dp_detect(struct intel_dp *intel_dp)
  1506. {
  1507. enum drm_connector_status status;
  1508. /* Can't disconnect eDP, but you can close the lid... */
  1509. if (is_edp(intel_dp)) {
  1510. status = intel_panel_detect(intel_dp->base.base.dev);
  1511. if (status == connector_status_unknown)
  1512. status = connector_status_connected;
  1513. return status;
  1514. }
  1515. return intel_dp_detect_dpcd(intel_dp);
  1516. }
  1517. static enum drm_connector_status
  1518. g4x_dp_detect(struct intel_dp *intel_dp)
  1519. {
  1520. struct drm_device *dev = intel_dp->base.base.dev;
  1521. struct drm_i915_private *dev_priv = dev->dev_private;
  1522. uint32_t temp, bit;
  1523. switch (intel_dp->output_reg) {
  1524. case DP_B:
  1525. bit = DPB_HOTPLUG_INT_STATUS;
  1526. break;
  1527. case DP_C:
  1528. bit = DPC_HOTPLUG_INT_STATUS;
  1529. break;
  1530. case DP_D:
  1531. bit = DPD_HOTPLUG_INT_STATUS;
  1532. break;
  1533. default:
  1534. return connector_status_unknown;
  1535. }
  1536. temp = I915_READ(PORT_HOTPLUG_STAT);
  1537. if ((temp & bit) == 0)
  1538. return connector_status_disconnected;
  1539. return intel_dp_detect_dpcd(intel_dp);
  1540. }
  1541. static struct edid *
  1542. intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
  1543. {
  1544. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1545. struct edid *edid;
  1546. ironlake_edp_panel_vdd_on(intel_dp);
  1547. edid = drm_get_edid(connector, adapter);
  1548. ironlake_edp_panel_vdd_off(intel_dp);
  1549. return edid;
  1550. }
  1551. static int
  1552. intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
  1553. {
  1554. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1555. int ret;
  1556. ironlake_edp_panel_vdd_on(intel_dp);
  1557. ret = intel_ddc_get_modes(connector, adapter);
  1558. ironlake_edp_panel_vdd_off(intel_dp);
  1559. return ret;
  1560. }
  1561. /**
  1562. * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
  1563. *
  1564. * \return true if DP port is connected.
  1565. * \return false if DP port is disconnected.
  1566. */
  1567. static enum drm_connector_status
  1568. intel_dp_detect(struct drm_connector *connector, bool force)
  1569. {
  1570. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1571. struct drm_device *dev = intel_dp->base.base.dev;
  1572. enum drm_connector_status status;
  1573. struct edid *edid = NULL;
  1574. intel_dp->has_audio = false;
  1575. if (HAS_PCH_SPLIT(dev))
  1576. status = ironlake_dp_detect(intel_dp);
  1577. else
  1578. status = g4x_dp_detect(intel_dp);
  1579. DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n",
  1580. intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2],
  1581. intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5],
  1582. intel_dp->dpcd[6], intel_dp->dpcd[7]);
  1583. if (status != connector_status_connected)
  1584. return status;
  1585. if (intel_dp->force_audio) {
  1586. intel_dp->has_audio = intel_dp->force_audio > 0;
  1587. } else {
  1588. edid = intel_dp_get_edid(connector, &intel_dp->adapter);
  1589. if (edid) {
  1590. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  1591. connector->display_info.raw_edid = NULL;
  1592. kfree(edid);
  1593. }
  1594. }
  1595. return connector_status_connected;
  1596. }
  1597. static int intel_dp_get_modes(struct drm_connector *connector)
  1598. {
  1599. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1600. struct drm_device *dev = intel_dp->base.base.dev;
  1601. struct drm_i915_private *dev_priv = dev->dev_private;
  1602. int ret;
  1603. /* We should parse the EDID data and find out if it has an audio sink
  1604. */
  1605. ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
  1606. if (ret) {
  1607. if (is_edp(intel_dp) && !intel_dp->panel_fixed_mode) {
  1608. struct drm_display_mode *newmode;
  1609. list_for_each_entry(newmode, &connector->probed_modes,
  1610. head) {
  1611. if ((newmode->type & DRM_MODE_TYPE_PREFERRED)) {
  1612. intel_dp->panel_fixed_mode =
  1613. drm_mode_duplicate(dev, newmode);
  1614. break;
  1615. }
  1616. }
  1617. }
  1618. return ret;
  1619. }
  1620. /* if eDP has no EDID, try to use fixed panel mode from VBT */
  1621. if (is_edp(intel_dp)) {
  1622. /* initialize panel mode from VBT if available for eDP */
  1623. if (intel_dp->panel_fixed_mode == NULL && dev_priv->lfp_lvds_vbt_mode != NULL) {
  1624. intel_dp->panel_fixed_mode =
  1625. drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  1626. if (intel_dp->panel_fixed_mode) {
  1627. intel_dp->panel_fixed_mode->type |=
  1628. DRM_MODE_TYPE_PREFERRED;
  1629. }
  1630. }
  1631. if (intel_dp->panel_fixed_mode) {
  1632. struct drm_display_mode *mode;
  1633. mode = drm_mode_duplicate(dev, intel_dp->panel_fixed_mode);
  1634. drm_mode_probed_add(connector, mode);
  1635. return 1;
  1636. }
  1637. }
  1638. return 0;
  1639. }
  1640. static bool
  1641. intel_dp_detect_audio(struct drm_connector *connector)
  1642. {
  1643. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1644. struct edid *edid;
  1645. bool has_audio = false;
  1646. edid = intel_dp_get_edid(connector, &intel_dp->adapter);
  1647. if (edid) {
  1648. has_audio = drm_detect_monitor_audio(edid);
  1649. connector->display_info.raw_edid = NULL;
  1650. kfree(edid);
  1651. }
  1652. return has_audio;
  1653. }
  1654. static int
  1655. intel_dp_set_property(struct drm_connector *connector,
  1656. struct drm_property *property,
  1657. uint64_t val)
  1658. {
  1659. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1660. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1661. int ret;
  1662. ret = drm_connector_property_set_value(connector, property, val);
  1663. if (ret)
  1664. return ret;
  1665. if (property == dev_priv->force_audio_property) {
  1666. int i = val;
  1667. bool has_audio;
  1668. if (i == intel_dp->force_audio)
  1669. return 0;
  1670. intel_dp->force_audio = i;
  1671. if (i == 0)
  1672. has_audio = intel_dp_detect_audio(connector);
  1673. else
  1674. has_audio = i > 0;
  1675. if (has_audio == intel_dp->has_audio)
  1676. return 0;
  1677. intel_dp->has_audio = has_audio;
  1678. goto done;
  1679. }
  1680. if (property == dev_priv->broadcast_rgb_property) {
  1681. if (val == !!intel_dp->color_range)
  1682. return 0;
  1683. intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
  1684. goto done;
  1685. }
  1686. return -EINVAL;
  1687. done:
  1688. if (intel_dp->base.base.crtc) {
  1689. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1690. drm_crtc_helper_set_mode(crtc, &crtc->mode,
  1691. crtc->x, crtc->y,
  1692. crtc->fb);
  1693. }
  1694. return 0;
  1695. }
  1696. static void
  1697. intel_dp_destroy (struct drm_connector *connector)
  1698. {
  1699. struct drm_device *dev = connector->dev;
  1700. if (intel_dpd_is_edp(dev))
  1701. intel_panel_destroy_backlight(dev);
  1702. drm_sysfs_connector_remove(connector);
  1703. drm_connector_cleanup(connector);
  1704. kfree(connector);
  1705. }
  1706. static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  1707. {
  1708. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  1709. i2c_del_adapter(&intel_dp->adapter);
  1710. drm_encoder_cleanup(encoder);
  1711. kfree(intel_dp);
  1712. }
  1713. static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
  1714. .dpms = intel_dp_dpms,
  1715. .mode_fixup = intel_dp_mode_fixup,
  1716. .prepare = intel_dp_prepare,
  1717. .mode_set = intel_dp_mode_set,
  1718. .commit = intel_dp_commit,
  1719. };
  1720. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  1721. .dpms = drm_helper_connector_dpms,
  1722. .detect = intel_dp_detect,
  1723. .fill_modes = drm_helper_probe_single_connector_modes,
  1724. .set_property = intel_dp_set_property,
  1725. .destroy = intel_dp_destroy,
  1726. };
  1727. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  1728. .get_modes = intel_dp_get_modes,
  1729. .mode_valid = intel_dp_mode_valid,
  1730. .best_encoder = intel_best_encoder,
  1731. };
  1732. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  1733. .destroy = intel_dp_encoder_destroy,
  1734. };
  1735. static void
  1736. intel_dp_hot_plug(struct intel_encoder *intel_encoder)
  1737. {
  1738. struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
  1739. intel_dp_check_link_status(intel_dp);
  1740. }
  1741. /* Return which DP Port should be selected for Transcoder DP control */
  1742. int
  1743. intel_trans_dp_port_sel (struct drm_crtc *crtc)
  1744. {
  1745. struct drm_device *dev = crtc->dev;
  1746. struct drm_mode_config *mode_config = &dev->mode_config;
  1747. struct drm_encoder *encoder;
  1748. list_for_each_entry(encoder, &mode_config->encoder_list, head) {
  1749. struct intel_dp *intel_dp;
  1750. if (encoder->crtc != crtc)
  1751. continue;
  1752. intel_dp = enc_to_intel_dp(encoder);
  1753. if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT)
  1754. return intel_dp->output_reg;
  1755. }
  1756. return -1;
  1757. }
  1758. /* check the VBT to see whether the eDP is on DP-D port */
  1759. bool intel_dpd_is_edp(struct drm_device *dev)
  1760. {
  1761. struct drm_i915_private *dev_priv = dev->dev_private;
  1762. struct child_device_config *p_child;
  1763. int i;
  1764. if (!dev_priv->child_dev_num)
  1765. return false;
  1766. for (i = 0; i < dev_priv->child_dev_num; i++) {
  1767. p_child = dev_priv->child_dev + i;
  1768. if (p_child->dvo_port == PORT_IDPD &&
  1769. p_child->device_type == DEVICE_TYPE_eDP)
  1770. return true;
  1771. }
  1772. return false;
  1773. }
  1774. static void
  1775. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  1776. {
  1777. intel_attach_force_audio_property(connector);
  1778. intel_attach_broadcast_rgb_property(connector);
  1779. }
  1780. void
  1781. intel_dp_init(struct drm_device *dev, int output_reg)
  1782. {
  1783. struct drm_i915_private *dev_priv = dev->dev_private;
  1784. struct drm_connector *connector;
  1785. struct intel_dp *intel_dp;
  1786. struct intel_encoder *intel_encoder;
  1787. struct intel_connector *intel_connector;
  1788. const char *name = NULL;
  1789. int type;
  1790. intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
  1791. if (!intel_dp)
  1792. return;
  1793. intel_dp->output_reg = output_reg;
  1794. intel_dp->dpms_mode = -1;
  1795. intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
  1796. if (!intel_connector) {
  1797. kfree(intel_dp);
  1798. return;
  1799. }
  1800. intel_encoder = &intel_dp->base;
  1801. if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
  1802. if (intel_dpd_is_edp(dev))
  1803. intel_dp->is_pch_edp = true;
  1804. if (output_reg == DP_A || is_pch_edp(intel_dp)) {
  1805. type = DRM_MODE_CONNECTOR_eDP;
  1806. intel_encoder->type = INTEL_OUTPUT_EDP;
  1807. } else {
  1808. type = DRM_MODE_CONNECTOR_DisplayPort;
  1809. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  1810. }
  1811. connector = &intel_connector->base;
  1812. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  1813. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  1814. connector->polled = DRM_CONNECTOR_POLL_HPD;
  1815. if (output_reg == DP_B || output_reg == PCH_DP_B)
  1816. intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT);
  1817. else if (output_reg == DP_C || output_reg == PCH_DP_C)
  1818. intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT);
  1819. else if (output_reg == DP_D || output_reg == PCH_DP_D)
  1820. intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT);
  1821. if (is_edp(intel_dp))
  1822. intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT);
  1823. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  1824. connector->interlace_allowed = true;
  1825. connector->doublescan_allowed = 0;
  1826. drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
  1827. DRM_MODE_ENCODER_TMDS);
  1828. drm_encoder_helper_add(&intel_encoder->base, &intel_dp_helper_funcs);
  1829. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1830. drm_sysfs_connector_add(connector);
  1831. /* Set up the DDC bus. */
  1832. switch (output_reg) {
  1833. case DP_A:
  1834. name = "DPDDC-A";
  1835. break;
  1836. case DP_B:
  1837. case PCH_DP_B:
  1838. dev_priv->hotplug_supported_mask |=
  1839. HDMIB_HOTPLUG_INT_STATUS;
  1840. name = "DPDDC-B";
  1841. break;
  1842. case DP_C:
  1843. case PCH_DP_C:
  1844. dev_priv->hotplug_supported_mask |=
  1845. HDMIC_HOTPLUG_INT_STATUS;
  1846. name = "DPDDC-C";
  1847. break;
  1848. case DP_D:
  1849. case PCH_DP_D:
  1850. dev_priv->hotplug_supported_mask |=
  1851. HDMID_HOTPLUG_INT_STATUS;
  1852. name = "DPDDC-D";
  1853. break;
  1854. }
  1855. /* Cache some DPCD data in the eDP case */
  1856. if (is_edp(intel_dp)) {
  1857. bool ret;
  1858. struct edp_power_seq cur, vbt;
  1859. u32 pp_on, pp_off, pp_div;
  1860. pp_on = I915_READ(PCH_PP_ON_DELAYS);
  1861. pp_off = I915_READ(PCH_PP_OFF_DELAYS);
  1862. pp_div = I915_READ(PCH_PP_DIVISOR);
  1863. /* Pull timing values out of registers */
  1864. cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  1865. PANEL_POWER_UP_DELAY_SHIFT;
  1866. cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  1867. PANEL_LIGHT_ON_DELAY_SHIFT;
  1868. cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  1869. PANEL_LIGHT_OFF_DELAY_SHIFT;
  1870. cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  1871. PANEL_POWER_DOWN_DELAY_SHIFT;
  1872. cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  1873. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  1874. DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  1875. cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
  1876. vbt = dev_priv->edp.pps;
  1877. DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  1878. vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
  1879. #define get_delay(field) ((max(cur.field, vbt.field) + 9) / 10)
  1880. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  1881. intel_dp->backlight_on_delay = get_delay(t8);
  1882. intel_dp->backlight_off_delay = get_delay(t9);
  1883. intel_dp->panel_power_down_delay = get_delay(t10);
  1884. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  1885. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  1886. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  1887. intel_dp->panel_power_cycle_delay);
  1888. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  1889. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  1890. ironlake_edp_panel_vdd_on(intel_dp);
  1891. ret = intel_dp_get_dpcd(intel_dp);
  1892. ironlake_edp_panel_vdd_off(intel_dp);
  1893. if (ret) {
  1894. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  1895. dev_priv->no_aux_handshake =
  1896. intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  1897. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  1898. } else {
  1899. /* if this fails, presume the device is a ghost */
  1900. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  1901. intel_dp_encoder_destroy(&intel_dp->base.base);
  1902. intel_dp_destroy(&intel_connector->base);
  1903. return;
  1904. }
  1905. }
  1906. intel_dp_i2c_init(intel_dp, intel_connector, name);
  1907. intel_encoder->hot_plug = intel_dp_hot_plug;
  1908. if (is_edp(intel_dp)) {
  1909. dev_priv->int_edp_connector = connector;
  1910. intel_panel_setup_backlight(dev);
  1911. }
  1912. intel_dp_add_properties(intel_dp, connector);
  1913. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  1914. * 0xd. Failure to do so will result in spurious interrupts being
  1915. * generated on the port when a cable is not attached.
  1916. */
  1917. if (IS_G4X(dev) && !IS_GM45(dev)) {
  1918. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  1919. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  1920. }
  1921. }