intel_dp.c 107 KB

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