intel_dp.c 89 KB

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