intel_dp.c 104 KB

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