intel_dp.c 104 KB

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