intel_dp.c 104 KB

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