intel_dp.c 89 KB

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