intel_dp.c 75 KB

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