intel_dp.c 78 KB

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