intel_dp.c 111 KB

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