intel_dp.c 82 KB

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