intel_dp.c 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780
  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 <linux/export.h>
  30. #include <drm/drmP.h>
  31. #include <drm/drm_crtc.h>
  32. #include <drm/drm_crtc_helper.h>
  33. #include <drm/drm_edid.h>
  34. #include "intel_drv.h"
  35. #include <drm/i915_drm.h>
  36. #include "i915_drv.h"
  37. #define DP_LINK_CHECK_TIMEOUT (10 * 1000)
  38. /**
  39. * is_edp - is the given port attached to an eDP panel (either CPU or PCH)
  40. * @intel_dp: DP struct
  41. *
  42. * If a CPU or PCH DP output is attached to an eDP panel, this function
  43. * will return true, and false otherwise.
  44. */
  45. static bool is_edp(struct intel_dp *intel_dp)
  46. {
  47. return intel_dp->base.type == INTEL_OUTPUT_EDP;
  48. }
  49. /**
  50. * is_pch_edp - is the port on the PCH and attached to an eDP panel?
  51. * @intel_dp: DP struct
  52. *
  53. * Returns true if the given DP struct corresponds to a PCH DP port attached
  54. * to an eDP panel, false otherwise. Helpful for determining whether we
  55. * may need FDI resources for a given DP output or not.
  56. */
  57. static bool is_pch_edp(struct intel_dp *intel_dp)
  58. {
  59. return intel_dp->is_pch_edp;
  60. }
  61. /**
  62. * is_cpu_edp - is the port on the CPU and attached to an eDP panel?
  63. * @intel_dp: DP struct
  64. *
  65. * Returns true if the given DP struct corresponds to a CPU eDP port.
  66. */
  67. static bool is_cpu_edp(struct intel_dp *intel_dp)
  68. {
  69. return is_edp(intel_dp) && !is_pch_edp(intel_dp);
  70. }
  71. static struct intel_dp *intel_attached_dp(struct drm_connector *connector)
  72. {
  73. return container_of(intel_attached_encoder(connector),
  74. struct intel_dp, base);
  75. }
  76. /**
  77. * intel_encoder_is_pch_edp - is the given encoder a PCH attached eDP?
  78. * @encoder: DRM encoder
  79. *
  80. * Return true if @encoder corresponds to a PCH attached eDP panel. Needed
  81. * by intel_display.c.
  82. */
  83. bool intel_encoder_is_pch_edp(struct drm_encoder *encoder)
  84. {
  85. struct intel_dp *intel_dp;
  86. if (!encoder)
  87. return false;
  88. intel_dp = enc_to_intel_dp(encoder);
  89. return is_pch_edp(intel_dp);
  90. }
  91. static void intel_dp_link_down(struct intel_dp *intel_dp);
  92. void
  93. intel_edp_link_config(struct intel_encoder *intel_encoder,
  94. int *lane_num, int *link_bw)
  95. {
  96. struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
  97. *lane_num = intel_dp->lane_count;
  98. if (intel_dp->link_bw == DP_LINK_BW_1_62)
  99. *link_bw = 162000;
  100. else if (intel_dp->link_bw == DP_LINK_BW_2_7)
  101. *link_bw = 270000;
  102. }
  103. int
  104. intel_edp_target_clock(struct intel_encoder *intel_encoder,
  105. struct drm_display_mode *mode)
  106. {
  107. struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
  108. struct intel_connector *intel_connector = intel_dp->attached_connector;
  109. if (intel_connector->panel.fixed_mode)
  110. return intel_connector->panel.fixed_mode->clock;
  111. else
  112. return mode->clock;
  113. }
  114. static int
  115. intel_dp_max_lane_count(struct intel_dp *intel_dp)
  116. {
  117. int max_lane_count = intel_dp->dpcd[DP_MAX_LANE_COUNT] & 0x1f;
  118. switch (max_lane_count) {
  119. case 1: case 2: case 4:
  120. break;
  121. default:
  122. max_lane_count = 4;
  123. }
  124. return max_lane_count;
  125. }
  126. static int
  127. intel_dp_max_link_bw(struct intel_dp *intel_dp)
  128. {
  129. int max_link_bw = intel_dp->dpcd[DP_MAX_LINK_RATE];
  130. switch (max_link_bw) {
  131. case DP_LINK_BW_1_62:
  132. case DP_LINK_BW_2_7:
  133. break;
  134. default:
  135. max_link_bw = DP_LINK_BW_1_62;
  136. break;
  137. }
  138. return max_link_bw;
  139. }
  140. static int
  141. intel_dp_link_clock(uint8_t link_bw)
  142. {
  143. if (link_bw == DP_LINK_BW_2_7)
  144. return 270000;
  145. else
  146. return 162000;
  147. }
  148. /*
  149. * The units on the numbers in the next two are... bizarre. Examples will
  150. * make it clearer; this one parallels an example in the eDP spec.
  151. *
  152. * intel_dp_max_data_rate for one lane of 2.7GHz evaluates as:
  153. *
  154. * 270000 * 1 * 8 / 10 == 216000
  155. *
  156. * The actual data capacity of that configuration is 2.16Gbit/s, so the
  157. * units are decakilobits. ->clock in a drm_display_mode is in kilohertz -
  158. * or equivalently, kilopixels per second - so for 1680x1050R it'd be
  159. * 119000. At 18bpp that's 2142000 kilobits per second.
  160. *
  161. * Thus the strange-looking division by 10 in intel_dp_link_required, to
  162. * get the result in decakilobits instead of kilobits.
  163. */
  164. static int
  165. intel_dp_link_required(int pixel_clock, int bpp)
  166. {
  167. return (pixel_clock * bpp + 9) / 10;
  168. }
  169. static int
  170. intel_dp_max_data_rate(int max_link_clock, int max_lanes)
  171. {
  172. return (max_link_clock * max_lanes * 8) / 10;
  173. }
  174. static bool
  175. intel_dp_adjust_dithering(struct intel_dp *intel_dp,
  176. struct drm_display_mode *mode,
  177. bool adjust_mode)
  178. {
  179. int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_dp));
  180. int max_lanes = intel_dp_max_lane_count(intel_dp);
  181. int max_rate, mode_rate;
  182. mode_rate = intel_dp_link_required(mode->clock, 24);
  183. max_rate = intel_dp_max_data_rate(max_link_clock, max_lanes);
  184. if (mode_rate > max_rate) {
  185. mode_rate = intel_dp_link_required(mode->clock, 18);
  186. if (mode_rate > max_rate)
  187. return false;
  188. if (adjust_mode)
  189. mode->private_flags
  190. |= INTEL_MODE_DP_FORCE_6BPC;
  191. return true;
  192. }
  193. return true;
  194. }
  195. static int
  196. intel_dp_mode_valid(struct drm_connector *connector,
  197. struct drm_display_mode *mode)
  198. {
  199. struct intel_dp *intel_dp = intel_attached_dp(connector);
  200. struct intel_connector *intel_connector = to_intel_connector(connector);
  201. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  202. if (is_edp(intel_dp) && fixed_mode) {
  203. if (mode->hdisplay > fixed_mode->hdisplay)
  204. return MODE_PANEL;
  205. if (mode->vdisplay > fixed_mode->vdisplay)
  206. return MODE_PANEL;
  207. }
  208. if (!intel_dp_adjust_dithering(intel_dp, mode, false))
  209. return MODE_CLOCK_HIGH;
  210. if (mode->clock < 10000)
  211. return MODE_CLOCK_LOW;
  212. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  213. return MODE_H_ILLEGAL;
  214. return MODE_OK;
  215. }
  216. static uint32_t
  217. pack_aux(uint8_t *src, int src_bytes)
  218. {
  219. int i;
  220. uint32_t v = 0;
  221. if (src_bytes > 4)
  222. src_bytes = 4;
  223. for (i = 0; i < src_bytes; i++)
  224. v |= ((uint32_t) src[i]) << ((3-i) * 8);
  225. return v;
  226. }
  227. static void
  228. unpack_aux(uint32_t src, uint8_t *dst, int dst_bytes)
  229. {
  230. int i;
  231. if (dst_bytes > 4)
  232. dst_bytes = 4;
  233. for (i = 0; i < dst_bytes; i++)
  234. dst[i] = src >> ((3-i) * 8);
  235. }
  236. /* hrawclock is 1/4 the FSB frequency */
  237. static int
  238. intel_hrawclk(struct drm_device *dev)
  239. {
  240. struct drm_i915_private *dev_priv = dev->dev_private;
  241. uint32_t clkcfg;
  242. /* There is no CLKCFG reg in Valleyview. VLV hrawclk is 200 MHz */
  243. if (IS_VALLEYVIEW(dev))
  244. return 200;
  245. clkcfg = I915_READ(CLKCFG);
  246. switch (clkcfg & CLKCFG_FSB_MASK) {
  247. case CLKCFG_FSB_400:
  248. return 100;
  249. case CLKCFG_FSB_533:
  250. return 133;
  251. case CLKCFG_FSB_667:
  252. return 166;
  253. case CLKCFG_FSB_800:
  254. return 200;
  255. case CLKCFG_FSB_1067:
  256. return 266;
  257. case CLKCFG_FSB_1333:
  258. return 333;
  259. /* these two are just a guess; one of them might be right */
  260. case CLKCFG_FSB_1600:
  261. case CLKCFG_FSB_1600_ALT:
  262. return 400;
  263. default:
  264. return 133;
  265. }
  266. }
  267. static bool ironlake_edp_have_panel_power(struct intel_dp *intel_dp)
  268. {
  269. struct drm_device *dev = intel_dp->base.base.dev;
  270. struct drm_i915_private *dev_priv = dev->dev_private;
  271. return (I915_READ(PCH_PP_STATUS) & PP_ON) != 0;
  272. }
  273. static bool ironlake_edp_have_panel_vdd(struct intel_dp *intel_dp)
  274. {
  275. struct drm_device *dev = intel_dp->base.base.dev;
  276. struct drm_i915_private *dev_priv = dev->dev_private;
  277. return (I915_READ(PCH_PP_CONTROL) & EDP_FORCE_VDD) != 0;
  278. }
  279. static void
  280. intel_dp_check_edp(struct intel_dp *intel_dp)
  281. {
  282. struct drm_device *dev = intel_dp->base.base.dev;
  283. struct drm_i915_private *dev_priv = dev->dev_private;
  284. if (!is_edp(intel_dp))
  285. return;
  286. if (!ironlake_edp_have_panel_power(intel_dp) && !ironlake_edp_have_panel_vdd(intel_dp)) {
  287. WARN(1, "eDP powered off while attempting aux channel communication.\n");
  288. DRM_DEBUG_KMS("Status 0x%08x Control 0x%08x\n",
  289. I915_READ(PCH_PP_STATUS),
  290. I915_READ(PCH_PP_CONTROL));
  291. }
  292. }
  293. static int
  294. intel_dp_aux_ch(struct intel_dp *intel_dp,
  295. uint8_t *send, int send_bytes,
  296. uint8_t *recv, int recv_size)
  297. {
  298. uint32_t output_reg = intel_dp->output_reg;
  299. struct drm_device *dev = intel_dp->base.base.dev;
  300. struct drm_i915_private *dev_priv = dev->dev_private;
  301. uint32_t ch_ctl = output_reg + 0x10;
  302. uint32_t ch_data = ch_ctl + 4;
  303. int i;
  304. int recv_bytes;
  305. uint32_t status;
  306. uint32_t aux_clock_divider;
  307. int try, precharge;
  308. if (IS_HASWELL(dev)) {
  309. switch (intel_dp->port) {
  310. case PORT_A:
  311. ch_ctl = DPA_AUX_CH_CTL;
  312. ch_data = DPA_AUX_CH_DATA1;
  313. break;
  314. case PORT_B:
  315. ch_ctl = PCH_DPB_AUX_CH_CTL;
  316. ch_data = PCH_DPB_AUX_CH_DATA1;
  317. break;
  318. case PORT_C:
  319. ch_ctl = PCH_DPC_AUX_CH_CTL;
  320. ch_data = PCH_DPC_AUX_CH_DATA1;
  321. break;
  322. case PORT_D:
  323. ch_ctl = PCH_DPD_AUX_CH_CTL;
  324. ch_data = PCH_DPD_AUX_CH_DATA1;
  325. break;
  326. default:
  327. BUG();
  328. }
  329. }
  330. intel_dp_check_edp(intel_dp);
  331. /* The clock divider is based off the hrawclk,
  332. * and would like to run at 2MHz. So, take the
  333. * hrawclk value and divide by 2 and use that
  334. *
  335. * Note that PCH attached eDP panels should use a 125MHz input
  336. * clock divider.
  337. */
  338. if (is_cpu_edp(intel_dp)) {
  339. if (IS_VALLEYVIEW(dev))
  340. aux_clock_divider = 100;
  341. else if (IS_GEN6(dev) || IS_GEN7(dev))
  342. aux_clock_divider = 200; /* SNB & IVB eDP input clock at 400Mhz */
  343. else
  344. aux_clock_divider = 225; /* eDP input clock at 450Mhz */
  345. } else if (HAS_PCH_SPLIT(dev))
  346. aux_clock_divider = 63; /* IRL input clock fixed at 125Mhz */
  347. else
  348. aux_clock_divider = intel_hrawclk(dev) / 2;
  349. if (IS_GEN6(dev))
  350. precharge = 3;
  351. else
  352. precharge = 5;
  353. /* Try to wait for any previous AUX channel activity */
  354. for (try = 0; try < 3; try++) {
  355. status = I915_READ(ch_ctl);
  356. if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  357. break;
  358. msleep(1);
  359. }
  360. if (try == 3) {
  361. WARN(1, "dp_aux_ch not started status 0x%08x\n",
  362. I915_READ(ch_ctl));
  363. return -EBUSY;
  364. }
  365. /* Must try at least 3 times according to DP spec */
  366. for (try = 0; try < 5; try++) {
  367. /* Load the send data into the aux channel data registers */
  368. for (i = 0; i < send_bytes; i += 4)
  369. I915_WRITE(ch_data + i,
  370. pack_aux(send + i, send_bytes - i));
  371. /* Send the command and wait for it to complete */
  372. I915_WRITE(ch_ctl,
  373. DP_AUX_CH_CTL_SEND_BUSY |
  374. DP_AUX_CH_CTL_TIME_OUT_400us |
  375. (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) |
  376. (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) |
  377. (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) |
  378. DP_AUX_CH_CTL_DONE |
  379. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  380. DP_AUX_CH_CTL_RECEIVE_ERROR);
  381. for (;;) {
  382. status = I915_READ(ch_ctl);
  383. if ((status & DP_AUX_CH_CTL_SEND_BUSY) == 0)
  384. break;
  385. udelay(100);
  386. }
  387. /* Clear done status and any errors */
  388. I915_WRITE(ch_ctl,
  389. status |
  390. DP_AUX_CH_CTL_DONE |
  391. DP_AUX_CH_CTL_TIME_OUT_ERROR |
  392. DP_AUX_CH_CTL_RECEIVE_ERROR);
  393. if (status & (DP_AUX_CH_CTL_TIME_OUT_ERROR |
  394. DP_AUX_CH_CTL_RECEIVE_ERROR))
  395. continue;
  396. if (status & DP_AUX_CH_CTL_DONE)
  397. break;
  398. }
  399. if ((status & DP_AUX_CH_CTL_DONE) == 0) {
  400. DRM_ERROR("dp_aux_ch not done status 0x%08x\n", status);
  401. return -EBUSY;
  402. }
  403. /* Check for timeout or receive error.
  404. * Timeouts occur when the sink is not connected
  405. */
  406. if (status & DP_AUX_CH_CTL_RECEIVE_ERROR) {
  407. DRM_ERROR("dp_aux_ch receive error status 0x%08x\n", status);
  408. return -EIO;
  409. }
  410. /* Timeouts occur when the device isn't connected, so they're
  411. * "normal" -- don't fill the kernel log with these */
  412. if (status & DP_AUX_CH_CTL_TIME_OUT_ERROR) {
  413. DRM_DEBUG_KMS("dp_aux_ch timeout status 0x%08x\n", status);
  414. return -ETIMEDOUT;
  415. }
  416. /* Unload any bytes sent back from the other side */
  417. recv_bytes = ((status & DP_AUX_CH_CTL_MESSAGE_SIZE_MASK) >>
  418. DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT);
  419. if (recv_bytes > recv_size)
  420. recv_bytes = recv_size;
  421. for (i = 0; i < recv_bytes; i += 4)
  422. unpack_aux(I915_READ(ch_data + i),
  423. recv + i, recv_bytes - i);
  424. return recv_bytes;
  425. }
  426. /* Write data to the aux channel in native mode */
  427. static int
  428. intel_dp_aux_native_write(struct intel_dp *intel_dp,
  429. uint16_t address, uint8_t *send, int send_bytes)
  430. {
  431. int ret;
  432. uint8_t msg[20];
  433. int msg_bytes;
  434. uint8_t ack;
  435. intel_dp_check_edp(intel_dp);
  436. if (send_bytes > 16)
  437. return -1;
  438. msg[0] = AUX_NATIVE_WRITE << 4;
  439. msg[1] = address >> 8;
  440. msg[2] = address & 0xff;
  441. msg[3] = send_bytes - 1;
  442. memcpy(&msg[4], send, send_bytes);
  443. msg_bytes = send_bytes + 4;
  444. for (;;) {
  445. ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes, &ack, 1);
  446. if (ret < 0)
  447. return ret;
  448. if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK)
  449. break;
  450. else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
  451. udelay(100);
  452. else
  453. return -EIO;
  454. }
  455. return send_bytes;
  456. }
  457. /* Write a single byte to the aux channel in native mode */
  458. static int
  459. intel_dp_aux_native_write_1(struct intel_dp *intel_dp,
  460. uint16_t address, uint8_t byte)
  461. {
  462. return intel_dp_aux_native_write(intel_dp, address, &byte, 1);
  463. }
  464. /* read bytes from a native aux channel */
  465. static int
  466. intel_dp_aux_native_read(struct intel_dp *intel_dp,
  467. uint16_t address, uint8_t *recv, int recv_bytes)
  468. {
  469. uint8_t msg[4];
  470. int msg_bytes;
  471. uint8_t reply[20];
  472. int reply_bytes;
  473. uint8_t ack;
  474. int ret;
  475. intel_dp_check_edp(intel_dp);
  476. msg[0] = AUX_NATIVE_READ << 4;
  477. msg[1] = address >> 8;
  478. msg[2] = address & 0xff;
  479. msg[3] = recv_bytes - 1;
  480. msg_bytes = 4;
  481. reply_bytes = recv_bytes + 1;
  482. for (;;) {
  483. ret = intel_dp_aux_ch(intel_dp, msg, msg_bytes,
  484. reply, reply_bytes);
  485. if (ret == 0)
  486. return -EPROTO;
  487. if (ret < 0)
  488. return ret;
  489. ack = reply[0];
  490. if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) {
  491. memcpy(recv, reply + 1, ret - 1);
  492. return ret - 1;
  493. }
  494. else if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_DEFER)
  495. udelay(100);
  496. else
  497. return -EIO;
  498. }
  499. }
  500. static int
  501. intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode,
  502. uint8_t write_byte, uint8_t *read_byte)
  503. {
  504. struct i2c_algo_dp_aux_data *algo_data = adapter->algo_data;
  505. struct intel_dp *intel_dp = container_of(adapter,
  506. struct intel_dp,
  507. adapter);
  508. uint16_t address = algo_data->address;
  509. uint8_t msg[5];
  510. uint8_t reply[2];
  511. unsigned retry;
  512. int msg_bytes;
  513. int reply_bytes;
  514. int ret;
  515. intel_dp_check_edp(intel_dp);
  516. /* Set up the command byte */
  517. if (mode & MODE_I2C_READ)
  518. msg[0] = AUX_I2C_READ << 4;
  519. else
  520. msg[0] = AUX_I2C_WRITE << 4;
  521. if (!(mode & MODE_I2C_STOP))
  522. msg[0] |= AUX_I2C_MOT << 4;
  523. msg[1] = address >> 8;
  524. msg[2] = address;
  525. switch (mode) {
  526. case MODE_I2C_WRITE:
  527. msg[3] = 0;
  528. msg[4] = write_byte;
  529. msg_bytes = 5;
  530. reply_bytes = 1;
  531. break;
  532. case MODE_I2C_READ:
  533. msg[3] = 0;
  534. msg_bytes = 4;
  535. reply_bytes = 2;
  536. break;
  537. default:
  538. msg_bytes = 3;
  539. reply_bytes = 1;
  540. break;
  541. }
  542. for (retry = 0; retry < 5; retry++) {
  543. ret = intel_dp_aux_ch(intel_dp,
  544. msg, msg_bytes,
  545. reply, reply_bytes);
  546. if (ret < 0) {
  547. DRM_DEBUG_KMS("aux_ch failed %d\n", ret);
  548. return ret;
  549. }
  550. switch (reply[0] & AUX_NATIVE_REPLY_MASK) {
  551. case AUX_NATIVE_REPLY_ACK:
  552. /* I2C-over-AUX Reply field is only valid
  553. * when paired with AUX ACK.
  554. */
  555. break;
  556. case AUX_NATIVE_REPLY_NACK:
  557. DRM_DEBUG_KMS("aux_ch native nack\n");
  558. return -EREMOTEIO;
  559. case AUX_NATIVE_REPLY_DEFER:
  560. udelay(100);
  561. continue;
  562. default:
  563. DRM_ERROR("aux_ch invalid native reply 0x%02x\n",
  564. reply[0]);
  565. return -EREMOTEIO;
  566. }
  567. switch (reply[0] & AUX_I2C_REPLY_MASK) {
  568. case AUX_I2C_REPLY_ACK:
  569. if (mode == MODE_I2C_READ) {
  570. *read_byte = reply[1];
  571. }
  572. return reply_bytes - 1;
  573. case AUX_I2C_REPLY_NACK:
  574. DRM_DEBUG_KMS("aux_i2c nack\n");
  575. return -EREMOTEIO;
  576. case AUX_I2C_REPLY_DEFER:
  577. DRM_DEBUG_KMS("aux_i2c defer\n");
  578. udelay(100);
  579. break;
  580. default:
  581. DRM_ERROR("aux_i2c invalid reply 0x%02x\n", reply[0]);
  582. return -EREMOTEIO;
  583. }
  584. }
  585. DRM_ERROR("too many retries, giving up\n");
  586. return -EREMOTEIO;
  587. }
  588. static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp);
  589. static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync);
  590. static int
  591. intel_dp_i2c_init(struct intel_dp *intel_dp,
  592. struct intel_connector *intel_connector, const char *name)
  593. {
  594. int ret;
  595. DRM_DEBUG_KMS("i2c_init %s\n", name);
  596. intel_dp->algo.running = false;
  597. intel_dp->algo.address = 0;
  598. intel_dp->algo.aux_ch = intel_dp_i2c_aux_ch;
  599. memset(&intel_dp->adapter, '\0', sizeof(intel_dp->adapter));
  600. intel_dp->adapter.owner = THIS_MODULE;
  601. intel_dp->adapter.class = I2C_CLASS_DDC;
  602. strncpy(intel_dp->adapter.name, name, sizeof(intel_dp->adapter.name) - 1);
  603. intel_dp->adapter.name[sizeof(intel_dp->adapter.name) - 1] = '\0';
  604. intel_dp->adapter.algo_data = &intel_dp->algo;
  605. intel_dp->adapter.dev.parent = &intel_connector->base.kdev;
  606. ironlake_edp_panel_vdd_on(intel_dp);
  607. ret = i2c_dp_aux_add_bus(&intel_dp->adapter);
  608. ironlake_edp_panel_vdd_off(intel_dp, false);
  609. return ret;
  610. }
  611. static bool
  612. intel_dp_mode_fixup(struct drm_encoder *encoder,
  613. const struct drm_display_mode *mode,
  614. struct drm_display_mode *adjusted_mode)
  615. {
  616. struct drm_device *dev = encoder->dev;
  617. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  618. struct intel_connector *intel_connector = intel_dp->attached_connector;
  619. int lane_count, clock;
  620. int max_lane_count = intel_dp_max_lane_count(intel_dp);
  621. int max_clock = intel_dp_max_link_bw(intel_dp) == DP_LINK_BW_2_7 ? 1 : 0;
  622. int bpp, mode_rate;
  623. static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 };
  624. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  625. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  626. adjusted_mode);
  627. intel_pch_panel_fitting(dev, DRM_MODE_SCALE_FULLSCREEN,
  628. mode, adjusted_mode);
  629. }
  630. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
  631. return false;
  632. DRM_DEBUG_KMS("DP link computation with max lane count %i "
  633. "max bw %02x pixel clock %iKHz\n",
  634. max_lane_count, bws[max_clock], adjusted_mode->clock);
  635. if (!intel_dp_adjust_dithering(intel_dp, adjusted_mode, true))
  636. return false;
  637. bpp = adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC ? 18 : 24;
  638. mode_rate = intel_dp_link_required(adjusted_mode->clock, bpp);
  639. for (clock = 0; clock <= max_clock; clock++) {
  640. for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
  641. int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
  642. if (mode_rate <= link_avail) {
  643. intel_dp->link_bw = bws[clock];
  644. intel_dp->lane_count = lane_count;
  645. adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
  646. DRM_DEBUG_KMS("DP link bw %02x lane "
  647. "count %d clock %d bpp %d\n",
  648. intel_dp->link_bw, intel_dp->lane_count,
  649. adjusted_mode->clock, bpp);
  650. DRM_DEBUG_KMS("DP link bw required %i available %i\n",
  651. mode_rate, link_avail);
  652. return true;
  653. }
  654. }
  655. }
  656. return false;
  657. }
  658. struct intel_dp_m_n {
  659. uint32_t tu;
  660. uint32_t gmch_m;
  661. uint32_t gmch_n;
  662. uint32_t link_m;
  663. uint32_t link_n;
  664. };
  665. static void
  666. intel_reduce_ratio(uint32_t *num, uint32_t *den)
  667. {
  668. while (*num > 0xffffff || *den > 0xffffff) {
  669. *num >>= 1;
  670. *den >>= 1;
  671. }
  672. }
  673. static void
  674. intel_dp_compute_m_n(int bpp,
  675. int nlanes,
  676. int pixel_clock,
  677. int link_clock,
  678. struct intel_dp_m_n *m_n)
  679. {
  680. m_n->tu = 64;
  681. m_n->gmch_m = (pixel_clock * bpp) >> 3;
  682. m_n->gmch_n = link_clock * nlanes;
  683. intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  684. m_n->link_m = pixel_clock;
  685. m_n->link_n = link_clock;
  686. intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
  687. }
  688. void
  689. intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
  690. struct drm_display_mode *adjusted_mode)
  691. {
  692. struct drm_device *dev = crtc->dev;
  693. struct intel_encoder *encoder;
  694. struct drm_i915_private *dev_priv = dev->dev_private;
  695. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  696. int lane_count = 4;
  697. struct intel_dp_m_n m_n;
  698. int pipe = intel_crtc->pipe;
  699. /*
  700. * Find the lane count in the intel_encoder private
  701. */
  702. for_each_encoder_on_crtc(dev, crtc, encoder) {
  703. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  704. if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
  705. intel_dp->base.type == INTEL_OUTPUT_EDP)
  706. {
  707. lane_count = intel_dp->lane_count;
  708. break;
  709. }
  710. }
  711. /*
  712. * Compute the GMCH and Link ratios. The '3' here is
  713. * the number of bytes_per_pixel post-LUT, which we always
  714. * set up for 8-bits of R/G/B, or 3 bytes total.
  715. */
  716. intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
  717. mode->clock, adjusted_mode->clock, &m_n);
  718. if (IS_HASWELL(dev)) {
  719. I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  720. I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
  721. I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
  722. I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
  723. } else if (HAS_PCH_SPLIT(dev)) {
  724. I915_WRITE(TRANSDATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  725. I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
  726. I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
  727. I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
  728. } else if (IS_VALLEYVIEW(dev)) {
  729. I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  730. I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
  731. I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
  732. I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
  733. } else {
  734. I915_WRITE(PIPE_GMCH_DATA_M(pipe),
  735. TU_SIZE(m_n.tu) | m_n.gmch_m);
  736. I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
  737. I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
  738. I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
  739. }
  740. }
  741. void intel_dp_init_link_config(struct intel_dp *intel_dp)
  742. {
  743. memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
  744. intel_dp->link_configuration[0] = intel_dp->link_bw;
  745. intel_dp->link_configuration[1] = intel_dp->lane_count;
  746. intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
  747. /*
  748. * Check for DPCD version > 1.1 and enhanced framing support
  749. */
  750. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  751. (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
  752. intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
  753. }
  754. }
  755. static void
  756. intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  757. struct drm_display_mode *adjusted_mode)
  758. {
  759. struct drm_device *dev = encoder->dev;
  760. struct drm_i915_private *dev_priv = dev->dev_private;
  761. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  762. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  763. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  764. /*
  765. * There are four kinds of DP registers:
  766. *
  767. * IBX PCH
  768. * SNB CPU
  769. * IVB CPU
  770. * CPT PCH
  771. *
  772. * IBX PCH and CPU are the same for almost everything,
  773. * except that the CPU DP PLL is configured in this
  774. * register
  775. *
  776. * CPT PCH is quite different, having many bits moved
  777. * to the TRANS_DP_CTL register instead. That
  778. * configuration happens (oddly) in ironlake_pch_enable
  779. */
  780. /* Preserve the BIOS-computed detected bit. This is
  781. * supposed to be read-only.
  782. */
  783. intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  784. /* Handle DP bits in common between all three register formats */
  785. intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  786. switch (intel_dp->lane_count) {
  787. case 1:
  788. intel_dp->DP |= DP_PORT_WIDTH_1;
  789. break;
  790. case 2:
  791. intel_dp->DP |= DP_PORT_WIDTH_2;
  792. break;
  793. case 4:
  794. intel_dp->DP |= DP_PORT_WIDTH_4;
  795. break;
  796. }
  797. if (intel_dp->has_audio) {
  798. DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
  799. pipe_name(intel_crtc->pipe));
  800. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  801. intel_write_eld(encoder, adjusted_mode);
  802. }
  803. intel_dp_init_link_config(intel_dp);
  804. /* Split out the IBX/CPU vs CPT settings */
  805. if (is_cpu_edp(intel_dp) && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
  806. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  807. intel_dp->DP |= DP_SYNC_HS_HIGH;
  808. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  809. intel_dp->DP |= DP_SYNC_VS_HIGH;
  810. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  811. if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
  812. intel_dp->DP |= DP_ENHANCED_FRAMING;
  813. intel_dp->DP |= intel_crtc->pipe << 29;
  814. /* don't miss out required setting for eDP */
  815. if (adjusted_mode->clock < 200000)
  816. intel_dp->DP |= DP_PLL_FREQ_160MHZ;
  817. else
  818. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  819. } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
  820. intel_dp->DP |= intel_dp->color_range;
  821. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  822. intel_dp->DP |= DP_SYNC_HS_HIGH;
  823. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  824. intel_dp->DP |= DP_SYNC_VS_HIGH;
  825. intel_dp->DP |= DP_LINK_TRAIN_OFF;
  826. if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
  827. intel_dp->DP |= DP_ENHANCED_FRAMING;
  828. if (intel_crtc->pipe == 1)
  829. intel_dp->DP |= DP_PIPEB_SELECT;
  830. if (is_cpu_edp(intel_dp)) {
  831. /* don't miss out required setting for eDP */
  832. if (adjusted_mode->clock < 200000)
  833. intel_dp->DP |= DP_PLL_FREQ_160MHZ;
  834. else
  835. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  836. }
  837. } else {
  838. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  839. }
  840. }
  841. #define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  842. #define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
  843. #define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  844. #define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  845. #define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
  846. #define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  847. static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
  848. u32 mask,
  849. u32 value)
  850. {
  851. struct drm_device *dev = intel_dp->base.base.dev;
  852. struct drm_i915_private *dev_priv = dev->dev_private;
  853. DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
  854. mask, value,
  855. I915_READ(PCH_PP_STATUS),
  856. I915_READ(PCH_PP_CONTROL));
  857. if (_wait_for((I915_READ(PCH_PP_STATUS) & mask) == value, 5000, 10)) {
  858. DRM_ERROR("Panel status timeout: status %08x control %08x\n",
  859. I915_READ(PCH_PP_STATUS),
  860. I915_READ(PCH_PP_CONTROL));
  861. }
  862. }
  863. static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
  864. {
  865. DRM_DEBUG_KMS("Wait for panel power on\n");
  866. ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
  867. }
  868. static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
  869. {
  870. DRM_DEBUG_KMS("Wait for panel power off time\n");
  871. ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
  872. }
  873. static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
  874. {
  875. DRM_DEBUG_KMS("Wait for panel power cycle\n");
  876. ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
  877. }
  878. /* Read the current pp_control value, unlocking the register if it
  879. * is locked
  880. */
  881. static u32 ironlake_get_pp_control(struct drm_i915_private *dev_priv)
  882. {
  883. u32 control = I915_READ(PCH_PP_CONTROL);
  884. control &= ~PANEL_UNLOCK_MASK;
  885. control |= PANEL_UNLOCK_REGS;
  886. return control;
  887. }
  888. static void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
  889. {
  890. struct drm_device *dev = intel_dp->base.base.dev;
  891. struct drm_i915_private *dev_priv = dev->dev_private;
  892. u32 pp;
  893. if (!is_edp(intel_dp))
  894. return;
  895. DRM_DEBUG_KMS("Turn eDP VDD on\n");
  896. WARN(intel_dp->want_panel_vdd,
  897. "eDP VDD already requested on\n");
  898. intel_dp->want_panel_vdd = true;
  899. if (ironlake_edp_have_panel_vdd(intel_dp)) {
  900. DRM_DEBUG_KMS("eDP VDD already on\n");
  901. return;
  902. }
  903. if (!ironlake_edp_have_panel_power(intel_dp))
  904. ironlake_wait_panel_power_cycle(intel_dp);
  905. pp = ironlake_get_pp_control(dev_priv);
  906. pp |= EDP_FORCE_VDD;
  907. I915_WRITE(PCH_PP_CONTROL, pp);
  908. POSTING_READ(PCH_PP_CONTROL);
  909. DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
  910. I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
  911. /*
  912. * If the panel wasn't on, delay before accessing aux channel
  913. */
  914. if (!ironlake_edp_have_panel_power(intel_dp)) {
  915. DRM_DEBUG_KMS("eDP was not running\n");
  916. msleep(intel_dp->panel_power_up_delay);
  917. }
  918. }
  919. static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
  920. {
  921. struct drm_device *dev = intel_dp->base.base.dev;
  922. struct drm_i915_private *dev_priv = dev->dev_private;
  923. u32 pp;
  924. if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
  925. pp = ironlake_get_pp_control(dev_priv);
  926. pp &= ~EDP_FORCE_VDD;
  927. I915_WRITE(PCH_PP_CONTROL, pp);
  928. POSTING_READ(PCH_PP_CONTROL);
  929. /* Make sure sequencer is idle before allowing subsequent activity */
  930. DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
  931. I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
  932. msleep(intel_dp->panel_power_down_delay);
  933. }
  934. }
  935. static void ironlake_panel_vdd_work(struct work_struct *__work)
  936. {
  937. struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
  938. struct intel_dp, panel_vdd_work);
  939. struct drm_device *dev = intel_dp->base.base.dev;
  940. mutex_lock(&dev->mode_config.mutex);
  941. ironlake_panel_vdd_off_sync(intel_dp);
  942. mutex_unlock(&dev->mode_config.mutex);
  943. }
  944. static void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
  945. {
  946. if (!is_edp(intel_dp))
  947. return;
  948. DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
  949. WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
  950. intel_dp->want_panel_vdd = false;
  951. if (sync) {
  952. ironlake_panel_vdd_off_sync(intel_dp);
  953. } else {
  954. /*
  955. * Queue the timer to fire a long
  956. * time from now (relative to the power down delay)
  957. * to keep the panel power up across a sequence of operations
  958. */
  959. schedule_delayed_work(&intel_dp->panel_vdd_work,
  960. msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
  961. }
  962. }
  963. static void ironlake_edp_panel_on(struct intel_dp *intel_dp)
  964. {
  965. struct drm_device *dev = intel_dp->base.base.dev;
  966. struct drm_i915_private *dev_priv = dev->dev_private;
  967. u32 pp;
  968. if (!is_edp(intel_dp))
  969. return;
  970. DRM_DEBUG_KMS("Turn eDP power on\n");
  971. if (ironlake_edp_have_panel_power(intel_dp)) {
  972. DRM_DEBUG_KMS("eDP power already on\n");
  973. return;
  974. }
  975. ironlake_wait_panel_power_cycle(intel_dp);
  976. pp = ironlake_get_pp_control(dev_priv);
  977. if (IS_GEN5(dev)) {
  978. /* ILK workaround: disable reset around power sequence */
  979. pp &= ~PANEL_POWER_RESET;
  980. I915_WRITE(PCH_PP_CONTROL, pp);
  981. POSTING_READ(PCH_PP_CONTROL);
  982. }
  983. pp |= POWER_TARGET_ON;
  984. if (!IS_GEN5(dev))
  985. pp |= PANEL_POWER_RESET;
  986. I915_WRITE(PCH_PP_CONTROL, pp);
  987. POSTING_READ(PCH_PP_CONTROL);
  988. ironlake_wait_panel_on(intel_dp);
  989. if (IS_GEN5(dev)) {
  990. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  991. I915_WRITE(PCH_PP_CONTROL, pp);
  992. POSTING_READ(PCH_PP_CONTROL);
  993. }
  994. }
  995. static void ironlake_edp_panel_off(struct intel_dp *intel_dp)
  996. {
  997. struct drm_device *dev = intel_dp->base.base.dev;
  998. struct drm_i915_private *dev_priv = dev->dev_private;
  999. u32 pp;
  1000. if (!is_edp(intel_dp))
  1001. return;
  1002. DRM_DEBUG_KMS("Turn eDP power off\n");
  1003. WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
  1004. pp = ironlake_get_pp_control(dev_priv);
  1005. /* We need to switch off panel power _and_ force vdd, for otherwise some
  1006. * panels get very unhappy and cease to work. */
  1007. pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
  1008. I915_WRITE(PCH_PP_CONTROL, pp);
  1009. POSTING_READ(PCH_PP_CONTROL);
  1010. intel_dp->want_panel_vdd = false;
  1011. ironlake_wait_panel_off(intel_dp);
  1012. }
  1013. static void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
  1014. {
  1015. struct drm_device *dev = intel_dp->base.base.dev;
  1016. struct drm_i915_private *dev_priv = dev->dev_private;
  1017. u32 pp;
  1018. if (!is_edp(intel_dp))
  1019. return;
  1020. DRM_DEBUG_KMS("\n");
  1021. /*
  1022. * If we enable the backlight right away following a panel power
  1023. * on, we may see slight flicker as the panel syncs with the eDP
  1024. * link. So delay a bit to make sure the image is solid before
  1025. * allowing it to appear.
  1026. */
  1027. msleep(intel_dp->backlight_on_delay);
  1028. pp = ironlake_get_pp_control(dev_priv);
  1029. pp |= EDP_BLC_ENABLE;
  1030. I915_WRITE(PCH_PP_CONTROL, pp);
  1031. POSTING_READ(PCH_PP_CONTROL);
  1032. }
  1033. static void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
  1034. {
  1035. struct drm_device *dev = intel_dp->base.base.dev;
  1036. struct drm_i915_private *dev_priv = dev->dev_private;
  1037. u32 pp;
  1038. if (!is_edp(intel_dp))
  1039. return;
  1040. DRM_DEBUG_KMS("\n");
  1041. pp = ironlake_get_pp_control(dev_priv);
  1042. pp &= ~EDP_BLC_ENABLE;
  1043. I915_WRITE(PCH_PP_CONTROL, pp);
  1044. POSTING_READ(PCH_PP_CONTROL);
  1045. msleep(intel_dp->backlight_off_delay);
  1046. }
  1047. static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
  1048. {
  1049. struct drm_device *dev = intel_dp->base.base.dev;
  1050. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1051. struct drm_i915_private *dev_priv = dev->dev_private;
  1052. u32 dpa_ctl;
  1053. assert_pipe_disabled(dev_priv,
  1054. to_intel_crtc(crtc)->pipe);
  1055. DRM_DEBUG_KMS("\n");
  1056. dpa_ctl = I915_READ(DP_A);
  1057. WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
  1058. WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
  1059. /* We don't adjust intel_dp->DP while tearing down the link, to
  1060. * facilitate link retraining (e.g. after hotplug). Hence clear all
  1061. * enable bits here to ensure that we don't enable too much. */
  1062. intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
  1063. intel_dp->DP |= DP_PLL_ENABLE;
  1064. I915_WRITE(DP_A, intel_dp->DP);
  1065. POSTING_READ(DP_A);
  1066. udelay(200);
  1067. }
  1068. static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
  1069. {
  1070. struct drm_device *dev = intel_dp->base.base.dev;
  1071. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1072. struct drm_i915_private *dev_priv = dev->dev_private;
  1073. u32 dpa_ctl;
  1074. assert_pipe_disabled(dev_priv,
  1075. to_intel_crtc(crtc)->pipe);
  1076. dpa_ctl = I915_READ(DP_A);
  1077. WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
  1078. "dp pll off, should be on\n");
  1079. WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
  1080. /* We can't rely on the value tracked for the DP register in
  1081. * intel_dp->DP because link_down must not change that (otherwise link
  1082. * re-training will fail. */
  1083. dpa_ctl &= ~DP_PLL_ENABLE;
  1084. I915_WRITE(DP_A, dpa_ctl);
  1085. POSTING_READ(DP_A);
  1086. udelay(200);
  1087. }
  1088. /* If the sink supports it, try to set the power state appropriately */
  1089. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
  1090. {
  1091. int ret, i;
  1092. /* Should have a valid DPCD by this point */
  1093. if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
  1094. return;
  1095. if (mode != DRM_MODE_DPMS_ON) {
  1096. ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
  1097. DP_SET_POWER_D3);
  1098. if (ret != 1)
  1099. DRM_DEBUG_DRIVER("failed to write sink power state\n");
  1100. } else {
  1101. /*
  1102. * When turning on, we need to retry for 1ms to give the sink
  1103. * time to wake up.
  1104. */
  1105. for (i = 0; i < 3; i++) {
  1106. ret = intel_dp_aux_native_write_1(intel_dp,
  1107. DP_SET_POWER,
  1108. DP_SET_POWER_D0);
  1109. if (ret == 1)
  1110. break;
  1111. msleep(1);
  1112. }
  1113. }
  1114. }
  1115. static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
  1116. enum pipe *pipe)
  1117. {
  1118. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1119. struct drm_device *dev = encoder->base.dev;
  1120. struct drm_i915_private *dev_priv = dev->dev_private;
  1121. u32 tmp = I915_READ(intel_dp->output_reg);
  1122. if (!(tmp & DP_PORT_EN))
  1123. return false;
  1124. if (is_cpu_edp(intel_dp) && IS_GEN7(dev)) {
  1125. *pipe = PORT_TO_PIPE_CPT(tmp);
  1126. } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
  1127. *pipe = PORT_TO_PIPE(tmp);
  1128. } else {
  1129. u32 trans_sel;
  1130. u32 trans_dp;
  1131. int i;
  1132. switch (intel_dp->output_reg) {
  1133. case PCH_DP_B:
  1134. trans_sel = TRANS_DP_PORT_SEL_B;
  1135. break;
  1136. case PCH_DP_C:
  1137. trans_sel = TRANS_DP_PORT_SEL_C;
  1138. break;
  1139. case PCH_DP_D:
  1140. trans_sel = TRANS_DP_PORT_SEL_D;
  1141. break;
  1142. default:
  1143. return true;
  1144. }
  1145. for_each_pipe(i) {
  1146. trans_dp = I915_READ(TRANS_DP_CTL(i));
  1147. if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
  1148. *pipe = i;
  1149. return true;
  1150. }
  1151. }
  1152. }
  1153. DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n", intel_dp->output_reg);
  1154. return true;
  1155. }
  1156. static void intel_disable_dp(struct intel_encoder *encoder)
  1157. {
  1158. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1159. /* Make sure the panel is off before trying to change the mode. But also
  1160. * ensure that we have vdd while we switch off the panel. */
  1161. ironlake_edp_panel_vdd_on(intel_dp);
  1162. ironlake_edp_backlight_off(intel_dp);
  1163. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1164. ironlake_edp_panel_off(intel_dp);
  1165. /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
  1166. if (!is_cpu_edp(intel_dp))
  1167. intel_dp_link_down(intel_dp);
  1168. }
  1169. static void intel_post_disable_dp(struct intel_encoder *encoder)
  1170. {
  1171. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1172. if (is_cpu_edp(intel_dp)) {
  1173. intel_dp_link_down(intel_dp);
  1174. ironlake_edp_pll_off(intel_dp);
  1175. }
  1176. }
  1177. static void intel_enable_dp(struct intel_encoder *encoder)
  1178. {
  1179. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1180. struct drm_device *dev = encoder->base.dev;
  1181. struct drm_i915_private *dev_priv = dev->dev_private;
  1182. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  1183. if (WARN_ON(dp_reg & DP_PORT_EN))
  1184. return;
  1185. ironlake_edp_panel_vdd_on(intel_dp);
  1186. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1187. intel_dp_start_link_train(intel_dp);
  1188. ironlake_edp_panel_on(intel_dp);
  1189. ironlake_edp_panel_vdd_off(intel_dp, true);
  1190. intel_dp_complete_link_train(intel_dp);
  1191. ironlake_edp_backlight_on(intel_dp);
  1192. }
  1193. static void intel_pre_enable_dp(struct intel_encoder *encoder)
  1194. {
  1195. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1196. if (is_cpu_edp(intel_dp))
  1197. ironlake_edp_pll_on(intel_dp);
  1198. }
  1199. /*
  1200. * Native read with retry for link status and receiver capability reads for
  1201. * cases where the sink may still be asleep.
  1202. */
  1203. static bool
  1204. intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
  1205. uint8_t *recv, int recv_bytes)
  1206. {
  1207. int ret, i;
  1208. /*
  1209. * Sinks are *supposed* to come up within 1ms from an off state,
  1210. * but we're also supposed to retry 3 times per the spec.
  1211. */
  1212. for (i = 0; i < 3; i++) {
  1213. ret = intel_dp_aux_native_read(intel_dp, address, recv,
  1214. recv_bytes);
  1215. if (ret == recv_bytes)
  1216. return true;
  1217. msleep(1);
  1218. }
  1219. return false;
  1220. }
  1221. /*
  1222. * Fetch AUX CH registers 0x202 - 0x207 which contain
  1223. * link status information
  1224. */
  1225. static bool
  1226. intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  1227. {
  1228. return intel_dp_aux_native_read_retry(intel_dp,
  1229. DP_LANE0_1_STATUS,
  1230. link_status,
  1231. DP_LINK_STATUS_SIZE);
  1232. }
  1233. #if 0
  1234. static char *voltage_names[] = {
  1235. "0.4V", "0.6V", "0.8V", "1.2V"
  1236. };
  1237. static char *pre_emph_names[] = {
  1238. "0dB", "3.5dB", "6dB", "9.5dB"
  1239. };
  1240. static char *link_train_names[] = {
  1241. "pattern 1", "pattern 2", "idle", "off"
  1242. };
  1243. #endif
  1244. /*
  1245. * These are source-specific values; current Intel hardware supports
  1246. * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
  1247. */
  1248. static uint8_t
  1249. intel_dp_voltage_max(struct intel_dp *intel_dp)
  1250. {
  1251. struct drm_device *dev = intel_dp->base.base.dev;
  1252. if (IS_GEN7(dev) && is_cpu_edp(intel_dp))
  1253. return DP_TRAIN_VOLTAGE_SWING_800;
  1254. else if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
  1255. return DP_TRAIN_VOLTAGE_SWING_1200;
  1256. else
  1257. return DP_TRAIN_VOLTAGE_SWING_800;
  1258. }
  1259. static uint8_t
  1260. intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
  1261. {
  1262. struct drm_device *dev = intel_dp->base.base.dev;
  1263. if (IS_HASWELL(dev)) {
  1264. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1265. case DP_TRAIN_VOLTAGE_SWING_400:
  1266. return DP_TRAIN_PRE_EMPHASIS_9_5;
  1267. case DP_TRAIN_VOLTAGE_SWING_600:
  1268. return DP_TRAIN_PRE_EMPHASIS_6;
  1269. case DP_TRAIN_VOLTAGE_SWING_800:
  1270. return DP_TRAIN_PRE_EMPHASIS_3_5;
  1271. case DP_TRAIN_VOLTAGE_SWING_1200:
  1272. default:
  1273. return DP_TRAIN_PRE_EMPHASIS_0;
  1274. }
  1275. } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
  1276. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1277. case DP_TRAIN_VOLTAGE_SWING_400:
  1278. return DP_TRAIN_PRE_EMPHASIS_6;
  1279. case DP_TRAIN_VOLTAGE_SWING_600:
  1280. case DP_TRAIN_VOLTAGE_SWING_800:
  1281. return DP_TRAIN_PRE_EMPHASIS_3_5;
  1282. default:
  1283. return DP_TRAIN_PRE_EMPHASIS_0;
  1284. }
  1285. } else {
  1286. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1287. case DP_TRAIN_VOLTAGE_SWING_400:
  1288. return DP_TRAIN_PRE_EMPHASIS_6;
  1289. case DP_TRAIN_VOLTAGE_SWING_600:
  1290. return DP_TRAIN_PRE_EMPHASIS_6;
  1291. case DP_TRAIN_VOLTAGE_SWING_800:
  1292. return DP_TRAIN_PRE_EMPHASIS_3_5;
  1293. case DP_TRAIN_VOLTAGE_SWING_1200:
  1294. default:
  1295. return DP_TRAIN_PRE_EMPHASIS_0;
  1296. }
  1297. }
  1298. }
  1299. static void
  1300. intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  1301. {
  1302. uint8_t v = 0;
  1303. uint8_t p = 0;
  1304. int lane;
  1305. uint8_t voltage_max;
  1306. uint8_t preemph_max;
  1307. for (lane = 0; lane < intel_dp->lane_count; lane++) {
  1308. uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
  1309. uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
  1310. if (this_v > v)
  1311. v = this_v;
  1312. if (this_p > p)
  1313. p = this_p;
  1314. }
  1315. voltage_max = intel_dp_voltage_max(intel_dp);
  1316. if (v >= voltage_max)
  1317. v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
  1318. preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
  1319. if (p >= preemph_max)
  1320. p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
  1321. for (lane = 0; lane < 4; lane++)
  1322. intel_dp->train_set[lane] = v | p;
  1323. }
  1324. static uint32_t
  1325. intel_dp_signal_levels(uint8_t train_set)
  1326. {
  1327. uint32_t signal_levels = 0;
  1328. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1329. case DP_TRAIN_VOLTAGE_SWING_400:
  1330. default:
  1331. signal_levels |= DP_VOLTAGE_0_4;
  1332. break;
  1333. case DP_TRAIN_VOLTAGE_SWING_600:
  1334. signal_levels |= DP_VOLTAGE_0_6;
  1335. break;
  1336. case DP_TRAIN_VOLTAGE_SWING_800:
  1337. signal_levels |= DP_VOLTAGE_0_8;
  1338. break;
  1339. case DP_TRAIN_VOLTAGE_SWING_1200:
  1340. signal_levels |= DP_VOLTAGE_1_2;
  1341. break;
  1342. }
  1343. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  1344. case DP_TRAIN_PRE_EMPHASIS_0:
  1345. default:
  1346. signal_levels |= DP_PRE_EMPHASIS_0;
  1347. break;
  1348. case DP_TRAIN_PRE_EMPHASIS_3_5:
  1349. signal_levels |= DP_PRE_EMPHASIS_3_5;
  1350. break;
  1351. case DP_TRAIN_PRE_EMPHASIS_6:
  1352. signal_levels |= DP_PRE_EMPHASIS_6;
  1353. break;
  1354. case DP_TRAIN_PRE_EMPHASIS_9_5:
  1355. signal_levels |= DP_PRE_EMPHASIS_9_5;
  1356. break;
  1357. }
  1358. return signal_levels;
  1359. }
  1360. /* Gen6's DP voltage swing and pre-emphasis control */
  1361. static uint32_t
  1362. intel_gen6_edp_signal_levels(uint8_t train_set)
  1363. {
  1364. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1365. DP_TRAIN_PRE_EMPHASIS_MASK);
  1366. switch (signal_levels) {
  1367. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  1368. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  1369. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  1370. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1371. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  1372. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  1373. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
  1374. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  1375. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1376. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1377. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  1378. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  1379. case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
  1380. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  1381. default:
  1382. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  1383. "0x%x\n", signal_levels);
  1384. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  1385. }
  1386. }
  1387. /* Gen7's DP voltage swing and pre-emphasis control */
  1388. static uint32_t
  1389. intel_gen7_edp_signal_levels(uint8_t train_set)
  1390. {
  1391. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1392. DP_TRAIN_PRE_EMPHASIS_MASK);
  1393. switch (signal_levels) {
  1394. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  1395. return EDP_LINK_TRAIN_400MV_0DB_IVB;
  1396. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1397. return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
  1398. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  1399. return EDP_LINK_TRAIN_400MV_6DB_IVB;
  1400. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  1401. return EDP_LINK_TRAIN_600MV_0DB_IVB;
  1402. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1403. return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
  1404. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  1405. return EDP_LINK_TRAIN_800MV_0DB_IVB;
  1406. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1407. return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
  1408. default:
  1409. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  1410. "0x%x\n", signal_levels);
  1411. return EDP_LINK_TRAIN_500MV_0DB_IVB;
  1412. }
  1413. }
  1414. /* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
  1415. static uint32_t
  1416. intel_dp_signal_levels_hsw(uint8_t train_set)
  1417. {
  1418. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1419. DP_TRAIN_PRE_EMPHASIS_MASK);
  1420. switch (signal_levels) {
  1421. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  1422. return DDI_BUF_EMP_400MV_0DB_HSW;
  1423. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1424. return DDI_BUF_EMP_400MV_3_5DB_HSW;
  1425. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  1426. return DDI_BUF_EMP_400MV_6DB_HSW;
  1427. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
  1428. return DDI_BUF_EMP_400MV_9_5DB_HSW;
  1429. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  1430. return DDI_BUF_EMP_600MV_0DB_HSW;
  1431. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1432. return DDI_BUF_EMP_600MV_3_5DB_HSW;
  1433. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
  1434. return DDI_BUF_EMP_600MV_6DB_HSW;
  1435. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  1436. return DDI_BUF_EMP_800MV_0DB_HSW;
  1437. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1438. return DDI_BUF_EMP_800MV_3_5DB_HSW;
  1439. default:
  1440. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  1441. "0x%x\n", signal_levels);
  1442. return DDI_BUF_EMP_400MV_0DB_HSW;
  1443. }
  1444. }
  1445. static bool
  1446. intel_dp_set_link_train(struct intel_dp *intel_dp,
  1447. uint32_t dp_reg_value,
  1448. uint8_t dp_train_pat)
  1449. {
  1450. struct drm_device *dev = intel_dp->base.base.dev;
  1451. struct drm_i915_private *dev_priv = dev->dev_private;
  1452. int ret;
  1453. uint32_t temp;
  1454. if (IS_HASWELL(dev)) {
  1455. temp = I915_READ(DP_TP_CTL(intel_dp->port));
  1456. if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
  1457. temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
  1458. else
  1459. temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
  1460. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  1461. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  1462. case DP_TRAINING_PATTERN_DISABLE:
  1463. temp |= DP_TP_CTL_LINK_TRAIN_IDLE;
  1464. I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
  1465. if (wait_for((I915_READ(DP_TP_STATUS(intel_dp->port)) &
  1466. DP_TP_STATUS_IDLE_DONE), 1))
  1467. DRM_ERROR("Timed out waiting for DP idle patterns\n");
  1468. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  1469. temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
  1470. break;
  1471. case DP_TRAINING_PATTERN_1:
  1472. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1473. break;
  1474. case DP_TRAINING_PATTERN_2:
  1475. temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
  1476. break;
  1477. case DP_TRAINING_PATTERN_3:
  1478. temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
  1479. break;
  1480. }
  1481. I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
  1482. } else if (HAS_PCH_CPT(dev) &&
  1483. (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
  1484. dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
  1485. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  1486. case DP_TRAINING_PATTERN_DISABLE:
  1487. dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
  1488. break;
  1489. case DP_TRAINING_PATTERN_1:
  1490. dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
  1491. break;
  1492. case DP_TRAINING_PATTERN_2:
  1493. dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
  1494. break;
  1495. case DP_TRAINING_PATTERN_3:
  1496. DRM_ERROR("DP training pattern 3 not supported\n");
  1497. dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
  1498. break;
  1499. }
  1500. } else {
  1501. dp_reg_value &= ~DP_LINK_TRAIN_MASK;
  1502. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  1503. case DP_TRAINING_PATTERN_DISABLE:
  1504. dp_reg_value |= DP_LINK_TRAIN_OFF;
  1505. break;
  1506. case DP_TRAINING_PATTERN_1:
  1507. dp_reg_value |= DP_LINK_TRAIN_PAT_1;
  1508. break;
  1509. case DP_TRAINING_PATTERN_2:
  1510. dp_reg_value |= DP_LINK_TRAIN_PAT_2;
  1511. break;
  1512. case DP_TRAINING_PATTERN_3:
  1513. DRM_ERROR("DP training pattern 3 not supported\n");
  1514. dp_reg_value |= DP_LINK_TRAIN_PAT_2;
  1515. break;
  1516. }
  1517. }
  1518. I915_WRITE(intel_dp->output_reg, dp_reg_value);
  1519. POSTING_READ(intel_dp->output_reg);
  1520. intel_dp_aux_native_write_1(intel_dp,
  1521. DP_TRAINING_PATTERN_SET,
  1522. dp_train_pat);
  1523. if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
  1524. DP_TRAINING_PATTERN_DISABLE) {
  1525. ret = intel_dp_aux_native_write(intel_dp,
  1526. DP_TRAINING_LANE0_SET,
  1527. intel_dp->train_set,
  1528. intel_dp->lane_count);
  1529. if (ret != intel_dp->lane_count)
  1530. return false;
  1531. }
  1532. return true;
  1533. }
  1534. /* Enable corresponding port and start training pattern 1 */
  1535. void
  1536. intel_dp_start_link_train(struct intel_dp *intel_dp)
  1537. {
  1538. struct drm_encoder *encoder = &intel_dp->base.base;
  1539. struct drm_device *dev = encoder->dev;
  1540. int i;
  1541. uint8_t voltage;
  1542. bool clock_recovery = false;
  1543. int voltage_tries, loop_tries;
  1544. uint32_t DP = intel_dp->DP;
  1545. if (IS_HASWELL(dev))
  1546. intel_ddi_prepare_link_retrain(encoder);
  1547. /* Write the link configuration data */
  1548. intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
  1549. intel_dp->link_configuration,
  1550. DP_LINK_CONFIGURATION_SIZE);
  1551. DP |= DP_PORT_EN;
  1552. memset(intel_dp->train_set, 0, 4);
  1553. voltage = 0xff;
  1554. voltage_tries = 0;
  1555. loop_tries = 0;
  1556. clock_recovery = false;
  1557. for (;;) {
  1558. /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
  1559. uint8_t link_status[DP_LINK_STATUS_SIZE];
  1560. uint32_t signal_levels;
  1561. if (IS_HASWELL(dev)) {
  1562. signal_levels = intel_dp_signal_levels_hsw(
  1563. intel_dp->train_set[0]);
  1564. DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
  1565. } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
  1566. signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
  1567. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
  1568. } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
  1569. signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
  1570. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
  1571. } else {
  1572. signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
  1573. DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
  1574. }
  1575. DRM_DEBUG_KMS("training pattern 1 signal levels %08x\n",
  1576. signal_levels);
  1577. /* Set training pattern 1 */
  1578. if (!intel_dp_set_link_train(intel_dp, DP,
  1579. DP_TRAINING_PATTERN_1 |
  1580. DP_LINK_SCRAMBLING_DISABLE))
  1581. break;
  1582. drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
  1583. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  1584. DRM_ERROR("failed to get link status\n");
  1585. break;
  1586. }
  1587. if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
  1588. DRM_DEBUG_KMS("clock recovery OK\n");
  1589. clock_recovery = true;
  1590. break;
  1591. }
  1592. /* Check to see if we've tried the max voltage */
  1593. for (i = 0; i < intel_dp->lane_count; i++)
  1594. if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
  1595. break;
  1596. if (i == intel_dp->lane_count && voltage_tries == 5) {
  1597. if (++loop_tries == 5) {
  1598. DRM_DEBUG_KMS("too many full retries, give up\n");
  1599. break;
  1600. }
  1601. memset(intel_dp->train_set, 0, 4);
  1602. voltage_tries = 0;
  1603. continue;
  1604. }
  1605. /* Check to see if we've tried the same voltage 5 times */
  1606. if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) {
  1607. voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
  1608. voltage_tries = 0;
  1609. } else
  1610. ++voltage_tries;
  1611. /* Compute new intel_dp->train_set as requested by target */
  1612. intel_get_adjust_train(intel_dp, link_status);
  1613. }
  1614. intel_dp->DP = DP;
  1615. }
  1616. void
  1617. intel_dp_complete_link_train(struct intel_dp *intel_dp)
  1618. {
  1619. struct drm_device *dev = intel_dp->base.base.dev;
  1620. bool channel_eq = false;
  1621. int tries, cr_tries;
  1622. uint32_t DP = intel_dp->DP;
  1623. /* channel equalization */
  1624. tries = 0;
  1625. cr_tries = 0;
  1626. channel_eq = false;
  1627. for (;;) {
  1628. /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
  1629. uint32_t signal_levels;
  1630. uint8_t link_status[DP_LINK_STATUS_SIZE];
  1631. if (cr_tries > 5) {
  1632. DRM_ERROR("failed to train DP, aborting\n");
  1633. intel_dp_link_down(intel_dp);
  1634. break;
  1635. }
  1636. if (IS_HASWELL(dev)) {
  1637. signal_levels = intel_dp_signal_levels_hsw(intel_dp->train_set[0]);
  1638. DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
  1639. } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
  1640. signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
  1641. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
  1642. } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
  1643. signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
  1644. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
  1645. } else {
  1646. signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
  1647. DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
  1648. }
  1649. /* channel eq pattern */
  1650. if (!intel_dp_set_link_train(intel_dp, DP,
  1651. DP_TRAINING_PATTERN_2 |
  1652. DP_LINK_SCRAMBLING_DISABLE))
  1653. break;
  1654. drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
  1655. if (!intel_dp_get_link_status(intel_dp, link_status))
  1656. break;
  1657. /* Make sure clock is still ok */
  1658. if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
  1659. intel_dp_start_link_train(intel_dp);
  1660. cr_tries++;
  1661. continue;
  1662. }
  1663. if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  1664. channel_eq = true;
  1665. break;
  1666. }
  1667. /* Try 5 times, then try clock recovery if that fails */
  1668. if (tries > 5) {
  1669. intel_dp_link_down(intel_dp);
  1670. intel_dp_start_link_train(intel_dp);
  1671. tries = 0;
  1672. cr_tries++;
  1673. continue;
  1674. }
  1675. /* Compute new intel_dp->train_set as requested by target */
  1676. intel_get_adjust_train(intel_dp, link_status);
  1677. ++tries;
  1678. }
  1679. if (channel_eq)
  1680. DRM_DEBUG_KMS("Channel EQ done. DP Training successfull\n");
  1681. intel_dp_set_link_train(intel_dp, DP, DP_TRAINING_PATTERN_DISABLE);
  1682. }
  1683. static void
  1684. intel_dp_link_down(struct intel_dp *intel_dp)
  1685. {
  1686. struct drm_device *dev = intel_dp->base.base.dev;
  1687. struct drm_i915_private *dev_priv = dev->dev_private;
  1688. uint32_t DP = intel_dp->DP;
  1689. /*
  1690. * DDI code has a strict mode set sequence and we should try to respect
  1691. * it, otherwise we might hang the machine in many different ways. So we
  1692. * really should be disabling the port only on a complete crtc_disable
  1693. * sequence. This function is just called under two conditions on DDI
  1694. * code:
  1695. * - Link train failed while doing crtc_enable, and on this case we
  1696. * really should respect the mode set sequence and wait for a
  1697. * crtc_disable.
  1698. * - Someone turned the monitor off and intel_dp_check_link_status
  1699. * called us. We don't need to disable the whole port on this case, so
  1700. * when someone turns the monitor on again,
  1701. * intel_ddi_prepare_link_retrain will take care of redoing the link
  1702. * train.
  1703. */
  1704. if (IS_HASWELL(dev))
  1705. return;
  1706. if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
  1707. return;
  1708. DRM_DEBUG_KMS("\n");
  1709. if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
  1710. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  1711. I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
  1712. } else {
  1713. DP &= ~DP_LINK_TRAIN_MASK;
  1714. I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
  1715. }
  1716. POSTING_READ(intel_dp->output_reg);
  1717. msleep(17);
  1718. if (HAS_PCH_IBX(dev) &&
  1719. I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
  1720. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1721. /* Hardware workaround: leaving our transcoder select
  1722. * set to transcoder B while it's off will prevent the
  1723. * corresponding HDMI output on transcoder A.
  1724. *
  1725. * Combine this with another hardware workaround:
  1726. * transcoder select bit can only be cleared while the
  1727. * port is enabled.
  1728. */
  1729. DP &= ~DP_PIPEB_SELECT;
  1730. I915_WRITE(intel_dp->output_reg, DP);
  1731. /* Changes to enable or select take place the vblank
  1732. * after being written.
  1733. */
  1734. if (crtc == NULL) {
  1735. /* We can arrive here never having been attached
  1736. * to a CRTC, for instance, due to inheriting
  1737. * random state from the BIOS.
  1738. *
  1739. * If the pipe is not running, play safe and
  1740. * wait for the clocks to stabilise before
  1741. * continuing.
  1742. */
  1743. POSTING_READ(intel_dp->output_reg);
  1744. msleep(50);
  1745. } else
  1746. intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
  1747. }
  1748. DP &= ~DP_AUDIO_OUTPUT_ENABLE;
  1749. I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
  1750. POSTING_READ(intel_dp->output_reg);
  1751. msleep(intel_dp->panel_power_down_delay);
  1752. }
  1753. static bool
  1754. intel_dp_get_dpcd(struct intel_dp *intel_dp)
  1755. {
  1756. if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
  1757. sizeof(intel_dp->dpcd)) == 0)
  1758. return false; /* aux transfer failed */
  1759. if (intel_dp->dpcd[DP_DPCD_REV] == 0)
  1760. return false; /* DPCD not present */
  1761. if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  1762. DP_DWN_STRM_PORT_PRESENT))
  1763. return true; /* native DP sink */
  1764. if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
  1765. return true; /* no per-port downstream info */
  1766. if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
  1767. intel_dp->downstream_ports,
  1768. DP_MAX_DOWNSTREAM_PORTS) == 0)
  1769. return false; /* downstream port status fetch failed */
  1770. return true;
  1771. }
  1772. static void
  1773. intel_dp_probe_oui(struct intel_dp *intel_dp)
  1774. {
  1775. u8 buf[3];
  1776. if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
  1777. return;
  1778. ironlake_edp_panel_vdd_on(intel_dp);
  1779. if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
  1780. DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
  1781. buf[0], buf[1], buf[2]);
  1782. if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
  1783. DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
  1784. buf[0], buf[1], buf[2]);
  1785. ironlake_edp_panel_vdd_off(intel_dp, false);
  1786. }
  1787. static bool
  1788. intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  1789. {
  1790. int ret;
  1791. ret = intel_dp_aux_native_read_retry(intel_dp,
  1792. DP_DEVICE_SERVICE_IRQ_VECTOR,
  1793. sink_irq_vector, 1);
  1794. if (!ret)
  1795. return false;
  1796. return true;
  1797. }
  1798. static void
  1799. intel_dp_handle_test_request(struct intel_dp *intel_dp)
  1800. {
  1801. /* NAK by default */
  1802. intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_ACK);
  1803. }
  1804. /*
  1805. * According to DP spec
  1806. * 5.1.2:
  1807. * 1. Read DPCD
  1808. * 2. Configure link according to Receiver Capabilities
  1809. * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
  1810. * 4. Check link status on receipt of hot-plug interrupt
  1811. */
  1812. static void
  1813. intel_dp_check_link_status(struct intel_dp *intel_dp)
  1814. {
  1815. u8 sink_irq_vector;
  1816. u8 link_status[DP_LINK_STATUS_SIZE];
  1817. if (!intel_dp->base.connectors_active)
  1818. return;
  1819. if (WARN_ON(!intel_dp->base.base.crtc))
  1820. return;
  1821. /* Try to read receiver status if the link appears to be up */
  1822. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  1823. intel_dp_link_down(intel_dp);
  1824. return;
  1825. }
  1826. /* Now read the DPCD to see if it's actually running */
  1827. if (!intel_dp_get_dpcd(intel_dp)) {
  1828. intel_dp_link_down(intel_dp);
  1829. return;
  1830. }
  1831. /* Try to read the source of the interrupt */
  1832. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  1833. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
  1834. /* Clear interrupt source */
  1835. intel_dp_aux_native_write_1(intel_dp,
  1836. DP_DEVICE_SERVICE_IRQ_VECTOR,
  1837. sink_irq_vector);
  1838. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  1839. intel_dp_handle_test_request(intel_dp);
  1840. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  1841. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  1842. }
  1843. if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  1844. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  1845. drm_get_encoder_name(&intel_dp->base.base));
  1846. intel_dp_start_link_train(intel_dp);
  1847. intel_dp_complete_link_train(intel_dp);
  1848. }
  1849. }
  1850. /* XXX this is probably wrong for multiple downstream ports */
  1851. static enum drm_connector_status
  1852. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  1853. {
  1854. uint8_t *dpcd = intel_dp->dpcd;
  1855. bool hpd;
  1856. uint8_t type;
  1857. if (!intel_dp_get_dpcd(intel_dp))
  1858. return connector_status_disconnected;
  1859. /* if there's no downstream port, we're done */
  1860. if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
  1861. return connector_status_connected;
  1862. /* If we're HPD-aware, SINK_COUNT changes dynamically */
  1863. hpd = !!(intel_dp->downstream_ports[0] & DP_DS_PORT_HPD);
  1864. if (hpd) {
  1865. uint8_t reg;
  1866. if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
  1867. &reg, 1))
  1868. return connector_status_unknown;
  1869. return DP_GET_SINK_COUNT(reg) ? connector_status_connected
  1870. : connector_status_disconnected;
  1871. }
  1872. /* If no HPD, poke DDC gently */
  1873. if (drm_probe_ddc(&intel_dp->adapter))
  1874. return connector_status_connected;
  1875. /* Well we tried, say unknown for unreliable port types */
  1876. type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  1877. if (type == DP_DS_PORT_TYPE_VGA || type == DP_DS_PORT_TYPE_NON_EDID)
  1878. return connector_status_unknown;
  1879. /* Anything else is out of spec, warn and ignore */
  1880. DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
  1881. return connector_status_disconnected;
  1882. }
  1883. static enum drm_connector_status
  1884. ironlake_dp_detect(struct intel_dp *intel_dp)
  1885. {
  1886. enum drm_connector_status status;
  1887. /* Can't disconnect eDP, but you can close the lid... */
  1888. if (is_edp(intel_dp)) {
  1889. status = intel_panel_detect(intel_dp->base.base.dev);
  1890. if (status == connector_status_unknown)
  1891. status = connector_status_connected;
  1892. return status;
  1893. }
  1894. return intel_dp_detect_dpcd(intel_dp);
  1895. }
  1896. static enum drm_connector_status
  1897. g4x_dp_detect(struct intel_dp *intel_dp)
  1898. {
  1899. struct drm_device *dev = intel_dp->base.base.dev;
  1900. struct drm_i915_private *dev_priv = dev->dev_private;
  1901. uint32_t bit;
  1902. switch (intel_dp->output_reg) {
  1903. case DP_B:
  1904. bit = DPB_HOTPLUG_LIVE_STATUS;
  1905. break;
  1906. case DP_C:
  1907. bit = DPC_HOTPLUG_LIVE_STATUS;
  1908. break;
  1909. case DP_D:
  1910. bit = DPD_HOTPLUG_LIVE_STATUS;
  1911. break;
  1912. default:
  1913. return connector_status_unknown;
  1914. }
  1915. if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
  1916. return connector_status_disconnected;
  1917. return intel_dp_detect_dpcd(intel_dp);
  1918. }
  1919. static struct edid *
  1920. intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
  1921. {
  1922. struct intel_connector *intel_connector = to_intel_connector(connector);
  1923. /* use cached edid if we have one */
  1924. if (intel_connector->edid) {
  1925. struct edid *edid;
  1926. int size;
  1927. /* invalid edid */
  1928. if (IS_ERR(intel_connector->edid))
  1929. return NULL;
  1930. size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
  1931. edid = kmalloc(size, GFP_KERNEL);
  1932. if (!edid)
  1933. return NULL;
  1934. memcpy(edid, intel_connector->edid, size);
  1935. return edid;
  1936. }
  1937. return drm_get_edid(connector, adapter);
  1938. }
  1939. static int
  1940. intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
  1941. {
  1942. struct intel_connector *intel_connector = to_intel_connector(connector);
  1943. /* use cached edid if we have one */
  1944. if (intel_connector->edid) {
  1945. /* invalid edid */
  1946. if (IS_ERR(intel_connector->edid))
  1947. return 0;
  1948. return intel_connector_update_modes(connector,
  1949. intel_connector->edid);
  1950. }
  1951. return intel_ddc_get_modes(connector, adapter);
  1952. }
  1953. /**
  1954. * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
  1955. *
  1956. * \return true if DP port is connected.
  1957. * \return false if DP port is disconnected.
  1958. */
  1959. static enum drm_connector_status
  1960. intel_dp_detect(struct drm_connector *connector, bool force)
  1961. {
  1962. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1963. struct drm_device *dev = intel_dp->base.base.dev;
  1964. enum drm_connector_status status;
  1965. struct edid *edid = NULL;
  1966. intel_dp->has_audio = false;
  1967. if (HAS_PCH_SPLIT(dev))
  1968. status = ironlake_dp_detect(intel_dp);
  1969. else
  1970. status = g4x_dp_detect(intel_dp);
  1971. DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n",
  1972. intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2],
  1973. intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5],
  1974. intel_dp->dpcd[6], intel_dp->dpcd[7]);
  1975. if (status != connector_status_connected)
  1976. return status;
  1977. intel_dp_probe_oui(intel_dp);
  1978. if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
  1979. intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
  1980. } else {
  1981. edid = intel_dp_get_edid(connector, &intel_dp->adapter);
  1982. if (edid) {
  1983. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  1984. kfree(edid);
  1985. }
  1986. }
  1987. return connector_status_connected;
  1988. }
  1989. static int intel_dp_get_modes(struct drm_connector *connector)
  1990. {
  1991. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1992. struct intel_connector *intel_connector = to_intel_connector(connector);
  1993. struct drm_device *dev = intel_dp->base.base.dev;
  1994. int ret;
  1995. /* We should parse the EDID data and find out if it has an audio sink
  1996. */
  1997. ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
  1998. if (ret)
  1999. return ret;
  2000. /* if eDP has no EDID, fall back to fixed mode */
  2001. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  2002. struct drm_display_mode *mode;
  2003. mode = drm_mode_duplicate(dev,
  2004. intel_connector->panel.fixed_mode);
  2005. if (mode) {
  2006. drm_mode_probed_add(connector, mode);
  2007. return 1;
  2008. }
  2009. }
  2010. return 0;
  2011. }
  2012. static bool
  2013. intel_dp_detect_audio(struct drm_connector *connector)
  2014. {
  2015. struct intel_dp *intel_dp = intel_attached_dp(connector);
  2016. struct edid *edid;
  2017. bool has_audio = false;
  2018. edid = intel_dp_get_edid(connector, &intel_dp->adapter);
  2019. if (edid) {
  2020. has_audio = drm_detect_monitor_audio(edid);
  2021. kfree(edid);
  2022. }
  2023. return has_audio;
  2024. }
  2025. static int
  2026. intel_dp_set_property(struct drm_connector *connector,
  2027. struct drm_property *property,
  2028. uint64_t val)
  2029. {
  2030. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  2031. struct intel_dp *intel_dp = intel_attached_dp(connector);
  2032. int ret;
  2033. ret = drm_connector_property_set_value(connector, property, val);
  2034. if (ret)
  2035. return ret;
  2036. if (property == dev_priv->force_audio_property) {
  2037. int i = val;
  2038. bool has_audio;
  2039. if (i == intel_dp->force_audio)
  2040. return 0;
  2041. intel_dp->force_audio = i;
  2042. if (i == HDMI_AUDIO_AUTO)
  2043. has_audio = intel_dp_detect_audio(connector);
  2044. else
  2045. has_audio = (i == HDMI_AUDIO_ON);
  2046. if (has_audio == intel_dp->has_audio)
  2047. return 0;
  2048. intel_dp->has_audio = has_audio;
  2049. goto done;
  2050. }
  2051. if (property == dev_priv->broadcast_rgb_property) {
  2052. if (val == !!intel_dp->color_range)
  2053. return 0;
  2054. intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
  2055. goto done;
  2056. }
  2057. return -EINVAL;
  2058. done:
  2059. if (intel_dp->base.base.crtc) {
  2060. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  2061. intel_set_mode(crtc, &crtc->mode,
  2062. crtc->x, crtc->y, crtc->fb);
  2063. }
  2064. return 0;
  2065. }
  2066. static void
  2067. intel_dp_destroy(struct drm_connector *connector)
  2068. {
  2069. struct drm_device *dev = connector->dev;
  2070. struct intel_dp *intel_dp = intel_attached_dp(connector);
  2071. struct intel_connector *intel_connector = to_intel_connector(connector);
  2072. if (!IS_ERR_OR_NULL(intel_connector->edid))
  2073. kfree(intel_connector->edid);
  2074. if (is_edp(intel_dp)) {
  2075. intel_panel_destroy_backlight(dev);
  2076. intel_panel_fini(&intel_connector->panel);
  2077. }
  2078. drm_sysfs_connector_remove(connector);
  2079. drm_connector_cleanup(connector);
  2080. kfree(connector);
  2081. }
  2082. static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  2083. {
  2084. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2085. i2c_del_adapter(&intel_dp->adapter);
  2086. drm_encoder_cleanup(encoder);
  2087. if (is_edp(intel_dp)) {
  2088. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  2089. ironlake_panel_vdd_off_sync(intel_dp);
  2090. }
  2091. kfree(intel_dp);
  2092. }
  2093. static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
  2094. .mode_fixup = intel_dp_mode_fixup,
  2095. .mode_set = intel_dp_mode_set,
  2096. .disable = intel_encoder_noop,
  2097. };
  2098. static const struct drm_encoder_helper_funcs intel_dp_helper_funcs_hsw = {
  2099. .mode_fixup = intel_dp_mode_fixup,
  2100. .mode_set = intel_ddi_mode_set,
  2101. .disable = intel_encoder_noop,
  2102. };
  2103. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  2104. .dpms = intel_connector_dpms,
  2105. .detect = intel_dp_detect,
  2106. .fill_modes = drm_helper_probe_single_connector_modes,
  2107. .set_property = intel_dp_set_property,
  2108. .destroy = intel_dp_destroy,
  2109. };
  2110. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  2111. .get_modes = intel_dp_get_modes,
  2112. .mode_valid = intel_dp_mode_valid,
  2113. .best_encoder = intel_best_encoder,
  2114. };
  2115. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  2116. .destroy = intel_dp_encoder_destroy,
  2117. };
  2118. static void
  2119. intel_dp_hot_plug(struct intel_encoder *intel_encoder)
  2120. {
  2121. struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
  2122. intel_dp_check_link_status(intel_dp);
  2123. }
  2124. /* Return which DP Port should be selected for Transcoder DP control */
  2125. int
  2126. intel_trans_dp_port_sel(struct drm_crtc *crtc)
  2127. {
  2128. struct drm_device *dev = crtc->dev;
  2129. struct intel_encoder *encoder;
  2130. for_each_encoder_on_crtc(dev, crtc, encoder) {
  2131. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2132. if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
  2133. intel_dp->base.type == INTEL_OUTPUT_EDP)
  2134. return intel_dp->output_reg;
  2135. }
  2136. return -1;
  2137. }
  2138. /* check the VBT to see whether the eDP is on DP-D port */
  2139. bool intel_dpd_is_edp(struct drm_device *dev)
  2140. {
  2141. struct drm_i915_private *dev_priv = dev->dev_private;
  2142. struct child_device_config *p_child;
  2143. int i;
  2144. if (!dev_priv->child_dev_num)
  2145. return false;
  2146. for (i = 0; i < dev_priv->child_dev_num; i++) {
  2147. p_child = dev_priv->child_dev + i;
  2148. if (p_child->dvo_port == PORT_IDPD &&
  2149. p_child->device_type == DEVICE_TYPE_eDP)
  2150. return true;
  2151. }
  2152. return false;
  2153. }
  2154. static void
  2155. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  2156. {
  2157. intel_attach_force_audio_property(connector);
  2158. intel_attach_broadcast_rgb_property(connector);
  2159. }
  2160. void
  2161. intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
  2162. {
  2163. struct drm_i915_private *dev_priv = dev->dev_private;
  2164. struct drm_connector *connector;
  2165. struct intel_dp *intel_dp;
  2166. struct intel_encoder *intel_encoder;
  2167. struct intel_connector *intel_connector;
  2168. struct drm_display_mode *fixed_mode = NULL;
  2169. const char *name = NULL;
  2170. int type;
  2171. intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
  2172. if (!intel_dp)
  2173. return;
  2174. intel_dp->output_reg = output_reg;
  2175. intel_dp->port = port;
  2176. /* Preserve the current hw state. */
  2177. intel_dp->DP = I915_READ(intel_dp->output_reg);
  2178. intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
  2179. if (!intel_connector) {
  2180. kfree(intel_dp);
  2181. return;
  2182. }
  2183. intel_encoder = &intel_dp->base;
  2184. intel_dp->attached_connector = intel_connector;
  2185. if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
  2186. if (intel_dpd_is_edp(dev))
  2187. intel_dp->is_pch_edp = true;
  2188. /*
  2189. * FIXME : We need to initialize built-in panels before external panels.
  2190. * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
  2191. */
  2192. if (IS_VALLEYVIEW(dev) && output_reg == DP_C) {
  2193. type = DRM_MODE_CONNECTOR_eDP;
  2194. intel_encoder->type = INTEL_OUTPUT_EDP;
  2195. } else if (output_reg == DP_A || is_pch_edp(intel_dp)) {
  2196. type = DRM_MODE_CONNECTOR_eDP;
  2197. intel_encoder->type = INTEL_OUTPUT_EDP;
  2198. } else {
  2199. type = DRM_MODE_CONNECTOR_DisplayPort;
  2200. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  2201. }
  2202. connector = &intel_connector->base;
  2203. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  2204. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  2205. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2206. intel_encoder->cloneable = false;
  2207. INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
  2208. ironlake_panel_vdd_work);
  2209. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  2210. connector->interlace_allowed = true;
  2211. connector->doublescan_allowed = 0;
  2212. drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
  2213. DRM_MODE_ENCODER_TMDS);
  2214. if (IS_HASWELL(dev))
  2215. drm_encoder_helper_add(&intel_encoder->base,
  2216. &intel_dp_helper_funcs_hsw);
  2217. else
  2218. drm_encoder_helper_add(&intel_encoder->base,
  2219. &intel_dp_helper_funcs);
  2220. intel_connector_attach_encoder(intel_connector, intel_encoder);
  2221. drm_sysfs_connector_add(connector);
  2222. if (IS_HASWELL(dev)) {
  2223. intel_encoder->enable = intel_enable_ddi;
  2224. intel_encoder->pre_enable = intel_ddi_pre_enable;
  2225. intel_encoder->disable = intel_disable_ddi;
  2226. intel_encoder->post_disable = intel_ddi_post_disable;
  2227. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  2228. } else {
  2229. intel_encoder->enable = intel_enable_dp;
  2230. intel_encoder->pre_enable = intel_pre_enable_dp;
  2231. intel_encoder->disable = intel_disable_dp;
  2232. intel_encoder->post_disable = intel_post_disable_dp;
  2233. intel_encoder->get_hw_state = intel_dp_get_hw_state;
  2234. }
  2235. intel_connector->get_hw_state = intel_connector_get_hw_state;
  2236. /* Set up the DDC bus. */
  2237. switch (port) {
  2238. case PORT_A:
  2239. name = "DPDDC-A";
  2240. break;
  2241. case PORT_B:
  2242. dev_priv->hotplug_supported_mask |= DPB_HOTPLUG_INT_STATUS;
  2243. name = "DPDDC-B";
  2244. break;
  2245. case PORT_C:
  2246. dev_priv->hotplug_supported_mask |= DPC_HOTPLUG_INT_STATUS;
  2247. name = "DPDDC-C";
  2248. break;
  2249. case PORT_D:
  2250. dev_priv->hotplug_supported_mask |= DPD_HOTPLUG_INT_STATUS;
  2251. name = "DPDDC-D";
  2252. break;
  2253. default:
  2254. WARN(1, "Invalid port %c\n", port_name(port));
  2255. break;
  2256. }
  2257. /* Cache some DPCD data in the eDP case */
  2258. if (is_edp(intel_dp)) {
  2259. struct edp_power_seq cur, vbt;
  2260. u32 pp_on, pp_off, pp_div;
  2261. pp_on = I915_READ(PCH_PP_ON_DELAYS);
  2262. pp_off = I915_READ(PCH_PP_OFF_DELAYS);
  2263. pp_div = I915_READ(PCH_PP_DIVISOR);
  2264. if (!pp_on || !pp_off || !pp_div) {
  2265. DRM_INFO("bad panel power sequencing delays, disabling panel\n");
  2266. intel_dp_encoder_destroy(&intel_dp->base.base);
  2267. intel_dp_destroy(&intel_connector->base);
  2268. return;
  2269. }
  2270. /* Pull timing values out of registers */
  2271. cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  2272. PANEL_POWER_UP_DELAY_SHIFT;
  2273. cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  2274. PANEL_LIGHT_ON_DELAY_SHIFT;
  2275. cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  2276. PANEL_LIGHT_OFF_DELAY_SHIFT;
  2277. cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  2278. PANEL_POWER_DOWN_DELAY_SHIFT;
  2279. cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  2280. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  2281. DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  2282. cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
  2283. vbt = dev_priv->edp.pps;
  2284. DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  2285. vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
  2286. #define get_delay(field) ((max(cur.field, vbt.field) + 9) / 10)
  2287. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  2288. intel_dp->backlight_on_delay = get_delay(t8);
  2289. intel_dp->backlight_off_delay = get_delay(t9);
  2290. intel_dp->panel_power_down_delay = get_delay(t10);
  2291. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  2292. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  2293. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  2294. intel_dp->panel_power_cycle_delay);
  2295. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  2296. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  2297. }
  2298. intel_dp_i2c_init(intel_dp, intel_connector, name);
  2299. if (is_edp(intel_dp)) {
  2300. bool ret;
  2301. struct drm_display_mode *scan;
  2302. struct edid *edid;
  2303. ironlake_edp_panel_vdd_on(intel_dp);
  2304. ret = intel_dp_get_dpcd(intel_dp);
  2305. ironlake_edp_panel_vdd_off(intel_dp, false);
  2306. if (ret) {
  2307. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  2308. dev_priv->no_aux_handshake =
  2309. intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  2310. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  2311. } else {
  2312. /* if this fails, presume the device is a ghost */
  2313. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  2314. intel_dp_encoder_destroy(&intel_dp->base.base);
  2315. intel_dp_destroy(&intel_connector->base);
  2316. return;
  2317. }
  2318. ironlake_edp_panel_vdd_on(intel_dp);
  2319. edid = drm_get_edid(connector, &intel_dp->adapter);
  2320. if (edid) {
  2321. if (drm_add_edid_modes(connector, edid)) {
  2322. drm_mode_connector_update_edid_property(connector, edid);
  2323. drm_edid_to_eld(connector, edid);
  2324. } else {
  2325. kfree(edid);
  2326. edid = ERR_PTR(-EINVAL);
  2327. }
  2328. } else {
  2329. edid = ERR_PTR(-ENOENT);
  2330. }
  2331. intel_connector->edid = edid;
  2332. /* prefer fixed mode from EDID if available */
  2333. list_for_each_entry(scan, &connector->probed_modes, head) {
  2334. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  2335. fixed_mode = drm_mode_duplicate(dev, scan);
  2336. break;
  2337. }
  2338. }
  2339. /* fallback to VBT if available for eDP */
  2340. if (!fixed_mode && dev_priv->lfp_lvds_vbt_mode) {
  2341. fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  2342. if (fixed_mode)
  2343. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  2344. }
  2345. ironlake_edp_panel_vdd_off(intel_dp, false);
  2346. }
  2347. intel_encoder->hot_plug = intel_dp_hot_plug;
  2348. if (is_edp(intel_dp)) {
  2349. intel_panel_init(&intel_connector->panel, fixed_mode);
  2350. intel_panel_setup_backlight(connector);
  2351. }
  2352. intel_dp_add_properties(intel_dp, connector);
  2353. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  2354. * 0xd. Failure to do so will result in spurious interrupts being
  2355. * generated on the port when a cable is not attached.
  2356. */
  2357. if (IS_G4X(dev) && !IS_GM45(dev)) {
  2358. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  2359. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  2360. }
  2361. }