intel_dp.c 76 KB

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