intel_dp.c 106 KB

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