intel_dp.c 82 KB

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