intel_dp.c 90 KB

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