intel_dp.c 106 KB

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