intel_dp.c 80 KB

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