intel_dp.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830
  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, DRM_MODE_SCALE_FULLSCREEN,
  613. mode, adjusted_mode);
  614. }
  615. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
  616. return false;
  617. DRM_DEBUG_KMS("DP link computation with max lane count %i "
  618. "max bw %02x pixel clock %iKHz\n",
  619. max_lane_count, bws[max_clock], adjusted_mode->clock);
  620. if (!intel_dp_adjust_dithering(intel_dp, adjusted_mode, true))
  621. return false;
  622. bpp = adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC ? 18 : 24;
  623. mode_rate = intel_dp_link_required(adjusted_mode->clock, bpp);
  624. for (clock = 0; clock <= max_clock; clock++) {
  625. for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) {
  626. int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count);
  627. if (mode_rate <= link_avail) {
  628. intel_dp->link_bw = bws[clock];
  629. intel_dp->lane_count = lane_count;
  630. adjusted_mode->clock = intel_dp_link_clock(intel_dp->link_bw);
  631. DRM_DEBUG_KMS("DP link bw %02x lane "
  632. "count %d clock %d bpp %d\n",
  633. intel_dp->link_bw, intel_dp->lane_count,
  634. adjusted_mode->clock, bpp);
  635. DRM_DEBUG_KMS("DP link bw required %i available %i\n",
  636. mode_rate, link_avail);
  637. return true;
  638. }
  639. }
  640. }
  641. return false;
  642. }
  643. struct intel_dp_m_n {
  644. uint32_t tu;
  645. uint32_t gmch_m;
  646. uint32_t gmch_n;
  647. uint32_t link_m;
  648. uint32_t link_n;
  649. };
  650. static void
  651. intel_reduce_ratio(uint32_t *num, uint32_t *den)
  652. {
  653. while (*num > 0xffffff || *den > 0xffffff) {
  654. *num >>= 1;
  655. *den >>= 1;
  656. }
  657. }
  658. static void
  659. intel_dp_compute_m_n(int bpp,
  660. int nlanes,
  661. int pixel_clock,
  662. int link_clock,
  663. struct intel_dp_m_n *m_n)
  664. {
  665. m_n->tu = 64;
  666. m_n->gmch_m = (pixel_clock * bpp) >> 3;
  667. m_n->gmch_n = link_clock * nlanes;
  668. intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  669. m_n->link_m = pixel_clock;
  670. m_n->link_n = link_clock;
  671. intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
  672. }
  673. void
  674. intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode,
  675. struct drm_display_mode *adjusted_mode)
  676. {
  677. struct drm_device *dev = crtc->dev;
  678. struct intel_encoder *encoder;
  679. struct drm_i915_private *dev_priv = dev->dev_private;
  680. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  681. int lane_count = 4;
  682. struct intel_dp_m_n m_n;
  683. int pipe = intel_crtc->pipe;
  684. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  685. /*
  686. * Find the lane count in the intel_encoder private
  687. */
  688. for_each_encoder_on_crtc(dev, crtc, encoder) {
  689. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  690. if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
  691. intel_dp->base.type == INTEL_OUTPUT_EDP)
  692. {
  693. lane_count = intel_dp->lane_count;
  694. break;
  695. }
  696. }
  697. /*
  698. * Compute the GMCH and Link ratios. The '3' here is
  699. * the number of bytes_per_pixel post-LUT, which we always
  700. * set up for 8-bits of R/G/B, or 3 bytes total.
  701. */
  702. intel_dp_compute_m_n(intel_crtc->bpp, lane_count,
  703. mode->clock, adjusted_mode->clock, &m_n);
  704. if (IS_HASWELL(dev)) {
  705. I915_WRITE(PIPE_DATA_M1(cpu_transcoder),
  706. TU_SIZE(m_n.tu) | m_n.gmch_m);
  707. I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
  708. I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
  709. I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
  710. } else if (HAS_PCH_SPLIT(dev)) {
  711. I915_WRITE(TRANSDATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  712. I915_WRITE(TRANSDATA_N1(pipe), m_n.gmch_n);
  713. I915_WRITE(TRANSDPLINK_M1(pipe), m_n.link_m);
  714. I915_WRITE(TRANSDPLINK_N1(pipe), m_n.link_n);
  715. } else if (IS_VALLEYVIEW(dev)) {
  716. I915_WRITE(PIPE_DATA_M1(pipe), TU_SIZE(m_n.tu) | m_n.gmch_m);
  717. I915_WRITE(PIPE_DATA_N1(pipe), m_n.gmch_n);
  718. I915_WRITE(PIPE_LINK_M1(pipe), m_n.link_m);
  719. I915_WRITE(PIPE_LINK_N1(pipe), m_n.link_n);
  720. } else {
  721. I915_WRITE(PIPE_GMCH_DATA_M(pipe),
  722. TU_SIZE(m_n.tu) | m_n.gmch_m);
  723. I915_WRITE(PIPE_GMCH_DATA_N(pipe), m_n.gmch_n);
  724. I915_WRITE(PIPE_DP_LINK_M(pipe), m_n.link_m);
  725. I915_WRITE(PIPE_DP_LINK_N(pipe), m_n.link_n);
  726. }
  727. }
  728. void intel_dp_init_link_config(struct intel_dp *intel_dp)
  729. {
  730. memset(intel_dp->link_configuration, 0, DP_LINK_CONFIGURATION_SIZE);
  731. intel_dp->link_configuration[0] = intel_dp->link_bw;
  732. intel_dp->link_configuration[1] = intel_dp->lane_count;
  733. intel_dp->link_configuration[8] = DP_SET_ANSI_8B10B;
  734. /*
  735. * Check for DPCD version > 1.1 and enhanced framing support
  736. */
  737. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  738. (intel_dp->dpcd[DP_MAX_LANE_COUNT] & DP_ENHANCED_FRAME_CAP)) {
  739. intel_dp->link_configuration[1] |= DP_LANE_COUNT_ENHANCED_FRAME_EN;
  740. }
  741. }
  742. static void
  743. intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  744. struct drm_display_mode *adjusted_mode)
  745. {
  746. struct drm_device *dev = encoder->dev;
  747. struct drm_i915_private *dev_priv = dev->dev_private;
  748. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  749. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  750. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  751. /*
  752. * There are four kinds of DP registers:
  753. *
  754. * IBX PCH
  755. * SNB CPU
  756. * IVB CPU
  757. * CPT PCH
  758. *
  759. * IBX PCH and CPU are the same for almost everything,
  760. * except that the CPU DP PLL is configured in this
  761. * register
  762. *
  763. * CPT PCH is quite different, having many bits moved
  764. * to the TRANS_DP_CTL register instead. That
  765. * configuration happens (oddly) in ironlake_pch_enable
  766. */
  767. /* Preserve the BIOS-computed detected bit. This is
  768. * supposed to be read-only.
  769. */
  770. intel_dp->DP = I915_READ(intel_dp->output_reg) & DP_DETECTED;
  771. /* Handle DP bits in common between all three register formats */
  772. intel_dp->DP |= DP_VOLTAGE_0_4 | DP_PRE_EMPHASIS_0;
  773. switch (intel_dp->lane_count) {
  774. case 1:
  775. intel_dp->DP |= DP_PORT_WIDTH_1;
  776. break;
  777. case 2:
  778. intel_dp->DP |= DP_PORT_WIDTH_2;
  779. break;
  780. case 4:
  781. intel_dp->DP |= DP_PORT_WIDTH_4;
  782. break;
  783. }
  784. if (intel_dp->has_audio) {
  785. DRM_DEBUG_DRIVER("Enabling DP audio on pipe %c\n",
  786. pipe_name(intel_crtc->pipe));
  787. intel_dp->DP |= DP_AUDIO_OUTPUT_ENABLE;
  788. intel_write_eld(encoder, adjusted_mode);
  789. }
  790. intel_dp_init_link_config(intel_dp);
  791. /* Split out the IBX/CPU vs CPT settings */
  792. if (is_cpu_edp(intel_dp) && IS_GEN7(dev) && !IS_VALLEYVIEW(dev)) {
  793. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  794. intel_dp->DP |= DP_SYNC_HS_HIGH;
  795. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  796. intel_dp->DP |= DP_SYNC_VS_HIGH;
  797. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  798. if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
  799. intel_dp->DP |= DP_ENHANCED_FRAMING;
  800. intel_dp->DP |= intel_crtc->pipe << 29;
  801. /* don't miss out required setting for eDP */
  802. if (adjusted_mode->clock < 200000)
  803. intel_dp->DP |= DP_PLL_FREQ_160MHZ;
  804. else
  805. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  806. } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
  807. intel_dp->DP |= intel_dp->color_range;
  808. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  809. intel_dp->DP |= DP_SYNC_HS_HIGH;
  810. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  811. intel_dp->DP |= DP_SYNC_VS_HIGH;
  812. intel_dp->DP |= DP_LINK_TRAIN_OFF;
  813. if (intel_dp->link_configuration[1] & DP_LANE_COUNT_ENHANCED_FRAME_EN)
  814. intel_dp->DP |= DP_ENHANCED_FRAMING;
  815. if (intel_crtc->pipe == 1)
  816. intel_dp->DP |= DP_PIPEB_SELECT;
  817. if (is_cpu_edp(intel_dp)) {
  818. /* don't miss out required setting for eDP */
  819. if (adjusted_mode->clock < 200000)
  820. intel_dp->DP |= DP_PLL_FREQ_160MHZ;
  821. else
  822. intel_dp->DP |= DP_PLL_FREQ_270MHZ;
  823. }
  824. } else {
  825. intel_dp->DP |= DP_LINK_TRAIN_OFF_CPT;
  826. }
  827. }
  828. #define IDLE_ON_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  829. #define IDLE_ON_VALUE (PP_ON | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_ON_IDLE)
  830. #define IDLE_OFF_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | 0 | PP_SEQUENCE_STATE_MASK)
  831. #define IDLE_OFF_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  832. #define IDLE_CYCLE_MASK (PP_ON | 0 | PP_SEQUENCE_MASK | PP_CYCLE_DELAY_ACTIVE | PP_SEQUENCE_STATE_MASK)
  833. #define IDLE_CYCLE_VALUE (0 | 0 | PP_SEQUENCE_NONE | 0 | PP_SEQUENCE_STATE_OFF_IDLE)
  834. static void ironlake_wait_panel_status(struct intel_dp *intel_dp,
  835. u32 mask,
  836. u32 value)
  837. {
  838. struct drm_device *dev = intel_dp->base.base.dev;
  839. struct drm_i915_private *dev_priv = dev->dev_private;
  840. DRM_DEBUG_KMS("mask %08x value %08x status %08x control %08x\n",
  841. mask, value,
  842. I915_READ(PCH_PP_STATUS),
  843. I915_READ(PCH_PP_CONTROL));
  844. if (_wait_for((I915_READ(PCH_PP_STATUS) & mask) == value, 5000, 10)) {
  845. DRM_ERROR("Panel status timeout: status %08x control %08x\n",
  846. I915_READ(PCH_PP_STATUS),
  847. I915_READ(PCH_PP_CONTROL));
  848. }
  849. }
  850. static void ironlake_wait_panel_on(struct intel_dp *intel_dp)
  851. {
  852. DRM_DEBUG_KMS("Wait for panel power on\n");
  853. ironlake_wait_panel_status(intel_dp, IDLE_ON_MASK, IDLE_ON_VALUE);
  854. }
  855. static void ironlake_wait_panel_off(struct intel_dp *intel_dp)
  856. {
  857. DRM_DEBUG_KMS("Wait for panel power off time\n");
  858. ironlake_wait_panel_status(intel_dp, IDLE_OFF_MASK, IDLE_OFF_VALUE);
  859. }
  860. static void ironlake_wait_panel_power_cycle(struct intel_dp *intel_dp)
  861. {
  862. DRM_DEBUG_KMS("Wait for panel power cycle\n");
  863. ironlake_wait_panel_status(intel_dp, IDLE_CYCLE_MASK, IDLE_CYCLE_VALUE);
  864. }
  865. /* Read the current pp_control value, unlocking the register if it
  866. * is locked
  867. */
  868. static u32 ironlake_get_pp_control(struct drm_i915_private *dev_priv)
  869. {
  870. u32 control = I915_READ(PCH_PP_CONTROL);
  871. control &= ~PANEL_UNLOCK_MASK;
  872. control |= PANEL_UNLOCK_REGS;
  873. return control;
  874. }
  875. void ironlake_edp_panel_vdd_on(struct intel_dp *intel_dp)
  876. {
  877. struct drm_device *dev = intel_dp->base.base.dev;
  878. struct drm_i915_private *dev_priv = dev->dev_private;
  879. u32 pp;
  880. if (!is_edp(intel_dp))
  881. return;
  882. DRM_DEBUG_KMS("Turn eDP VDD on\n");
  883. WARN(intel_dp->want_panel_vdd,
  884. "eDP VDD already requested on\n");
  885. intel_dp->want_panel_vdd = true;
  886. if (ironlake_edp_have_panel_vdd(intel_dp)) {
  887. DRM_DEBUG_KMS("eDP VDD already on\n");
  888. return;
  889. }
  890. if (!ironlake_edp_have_panel_power(intel_dp))
  891. ironlake_wait_panel_power_cycle(intel_dp);
  892. pp = ironlake_get_pp_control(dev_priv);
  893. pp |= EDP_FORCE_VDD;
  894. I915_WRITE(PCH_PP_CONTROL, pp);
  895. POSTING_READ(PCH_PP_CONTROL);
  896. DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
  897. I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
  898. /*
  899. * If the panel wasn't on, delay before accessing aux channel
  900. */
  901. if (!ironlake_edp_have_panel_power(intel_dp)) {
  902. DRM_DEBUG_KMS("eDP was not running\n");
  903. msleep(intel_dp->panel_power_up_delay);
  904. }
  905. }
  906. static void ironlake_panel_vdd_off_sync(struct intel_dp *intel_dp)
  907. {
  908. struct drm_device *dev = intel_dp->base.base.dev;
  909. struct drm_i915_private *dev_priv = dev->dev_private;
  910. u32 pp;
  911. if (!intel_dp->want_panel_vdd && ironlake_edp_have_panel_vdd(intel_dp)) {
  912. pp = ironlake_get_pp_control(dev_priv);
  913. pp &= ~EDP_FORCE_VDD;
  914. I915_WRITE(PCH_PP_CONTROL, pp);
  915. POSTING_READ(PCH_PP_CONTROL);
  916. /* Make sure sequencer is idle before allowing subsequent activity */
  917. DRM_DEBUG_KMS("PCH_PP_STATUS: 0x%08x PCH_PP_CONTROL: 0x%08x\n",
  918. I915_READ(PCH_PP_STATUS), I915_READ(PCH_PP_CONTROL));
  919. msleep(intel_dp->panel_power_down_delay);
  920. }
  921. }
  922. static void ironlake_panel_vdd_work(struct work_struct *__work)
  923. {
  924. struct intel_dp *intel_dp = container_of(to_delayed_work(__work),
  925. struct intel_dp, panel_vdd_work);
  926. struct drm_device *dev = intel_dp->base.base.dev;
  927. mutex_lock(&dev->mode_config.mutex);
  928. ironlake_panel_vdd_off_sync(intel_dp);
  929. mutex_unlock(&dev->mode_config.mutex);
  930. }
  931. void ironlake_edp_panel_vdd_off(struct intel_dp *intel_dp, bool sync)
  932. {
  933. if (!is_edp(intel_dp))
  934. return;
  935. DRM_DEBUG_KMS("Turn eDP VDD off %d\n", intel_dp->want_panel_vdd);
  936. WARN(!intel_dp->want_panel_vdd, "eDP VDD not forced on");
  937. intel_dp->want_panel_vdd = false;
  938. if (sync) {
  939. ironlake_panel_vdd_off_sync(intel_dp);
  940. } else {
  941. /*
  942. * Queue the timer to fire a long
  943. * time from now (relative to the power down delay)
  944. * to keep the panel power up across a sequence of operations
  945. */
  946. schedule_delayed_work(&intel_dp->panel_vdd_work,
  947. msecs_to_jiffies(intel_dp->panel_power_cycle_delay * 5));
  948. }
  949. }
  950. void ironlake_edp_panel_on(struct intel_dp *intel_dp)
  951. {
  952. struct drm_device *dev = intel_dp->base.base.dev;
  953. struct drm_i915_private *dev_priv = dev->dev_private;
  954. u32 pp;
  955. if (!is_edp(intel_dp))
  956. return;
  957. DRM_DEBUG_KMS("Turn eDP power on\n");
  958. if (ironlake_edp_have_panel_power(intel_dp)) {
  959. DRM_DEBUG_KMS("eDP power already on\n");
  960. return;
  961. }
  962. ironlake_wait_panel_power_cycle(intel_dp);
  963. pp = ironlake_get_pp_control(dev_priv);
  964. if (IS_GEN5(dev)) {
  965. /* ILK workaround: disable reset around power sequence */
  966. pp &= ~PANEL_POWER_RESET;
  967. I915_WRITE(PCH_PP_CONTROL, pp);
  968. POSTING_READ(PCH_PP_CONTROL);
  969. }
  970. pp |= POWER_TARGET_ON;
  971. if (!IS_GEN5(dev))
  972. pp |= PANEL_POWER_RESET;
  973. I915_WRITE(PCH_PP_CONTROL, pp);
  974. POSTING_READ(PCH_PP_CONTROL);
  975. ironlake_wait_panel_on(intel_dp);
  976. if (IS_GEN5(dev)) {
  977. pp |= PANEL_POWER_RESET; /* restore panel reset bit */
  978. I915_WRITE(PCH_PP_CONTROL, pp);
  979. POSTING_READ(PCH_PP_CONTROL);
  980. }
  981. }
  982. void ironlake_edp_panel_off(struct intel_dp *intel_dp)
  983. {
  984. struct drm_device *dev = intel_dp->base.base.dev;
  985. struct drm_i915_private *dev_priv = dev->dev_private;
  986. u32 pp;
  987. if (!is_edp(intel_dp))
  988. return;
  989. DRM_DEBUG_KMS("Turn eDP power off\n");
  990. WARN(!intel_dp->want_panel_vdd, "Need VDD to turn off panel\n");
  991. pp = ironlake_get_pp_control(dev_priv);
  992. /* We need to switch off panel power _and_ force vdd, for otherwise some
  993. * panels get very unhappy and cease to work. */
  994. pp &= ~(POWER_TARGET_ON | EDP_FORCE_VDD | PANEL_POWER_RESET | EDP_BLC_ENABLE);
  995. I915_WRITE(PCH_PP_CONTROL, pp);
  996. POSTING_READ(PCH_PP_CONTROL);
  997. intel_dp->want_panel_vdd = false;
  998. ironlake_wait_panel_off(intel_dp);
  999. }
  1000. void ironlake_edp_backlight_on(struct intel_dp *intel_dp)
  1001. {
  1002. struct drm_device *dev = intel_dp->base.base.dev;
  1003. struct drm_i915_private *dev_priv = dev->dev_private;
  1004. int pipe = to_intel_crtc(intel_dp->base.base.crtc)->pipe;
  1005. u32 pp;
  1006. if (!is_edp(intel_dp))
  1007. return;
  1008. DRM_DEBUG_KMS("\n");
  1009. /*
  1010. * If we enable the backlight right away following a panel power
  1011. * on, we may see slight flicker as the panel syncs with the eDP
  1012. * link. So delay a bit to make sure the image is solid before
  1013. * allowing it to appear.
  1014. */
  1015. msleep(intel_dp->backlight_on_delay);
  1016. pp = ironlake_get_pp_control(dev_priv);
  1017. pp |= EDP_BLC_ENABLE;
  1018. I915_WRITE(PCH_PP_CONTROL, pp);
  1019. POSTING_READ(PCH_PP_CONTROL);
  1020. intel_panel_enable_backlight(dev, pipe);
  1021. }
  1022. void ironlake_edp_backlight_off(struct intel_dp *intel_dp)
  1023. {
  1024. struct drm_device *dev = intel_dp->base.base.dev;
  1025. struct drm_i915_private *dev_priv = dev->dev_private;
  1026. u32 pp;
  1027. if (!is_edp(intel_dp))
  1028. return;
  1029. intel_panel_disable_backlight(dev);
  1030. DRM_DEBUG_KMS("\n");
  1031. pp = ironlake_get_pp_control(dev_priv);
  1032. pp &= ~EDP_BLC_ENABLE;
  1033. I915_WRITE(PCH_PP_CONTROL, pp);
  1034. POSTING_READ(PCH_PP_CONTROL);
  1035. msleep(intel_dp->backlight_off_delay);
  1036. }
  1037. static void ironlake_edp_pll_on(struct intel_dp *intel_dp)
  1038. {
  1039. struct drm_device *dev = intel_dp->base.base.dev;
  1040. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1041. struct drm_i915_private *dev_priv = dev->dev_private;
  1042. u32 dpa_ctl;
  1043. assert_pipe_disabled(dev_priv,
  1044. to_intel_crtc(crtc)->pipe);
  1045. DRM_DEBUG_KMS("\n");
  1046. dpa_ctl = I915_READ(DP_A);
  1047. WARN(dpa_ctl & DP_PLL_ENABLE, "dp pll on, should be off\n");
  1048. WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
  1049. /* We don't adjust intel_dp->DP while tearing down the link, to
  1050. * facilitate link retraining (e.g. after hotplug). Hence clear all
  1051. * enable bits here to ensure that we don't enable too much. */
  1052. intel_dp->DP &= ~(DP_PORT_EN | DP_AUDIO_OUTPUT_ENABLE);
  1053. intel_dp->DP |= DP_PLL_ENABLE;
  1054. I915_WRITE(DP_A, intel_dp->DP);
  1055. POSTING_READ(DP_A);
  1056. udelay(200);
  1057. }
  1058. static void ironlake_edp_pll_off(struct intel_dp *intel_dp)
  1059. {
  1060. struct drm_device *dev = intel_dp->base.base.dev;
  1061. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1062. struct drm_i915_private *dev_priv = dev->dev_private;
  1063. u32 dpa_ctl;
  1064. assert_pipe_disabled(dev_priv,
  1065. to_intel_crtc(crtc)->pipe);
  1066. dpa_ctl = I915_READ(DP_A);
  1067. WARN((dpa_ctl & DP_PLL_ENABLE) == 0,
  1068. "dp pll off, should be on\n");
  1069. WARN(dpa_ctl & DP_PORT_EN, "dp port still on, should be off\n");
  1070. /* We can't rely on the value tracked for the DP register in
  1071. * intel_dp->DP because link_down must not change that (otherwise link
  1072. * re-training will fail. */
  1073. dpa_ctl &= ~DP_PLL_ENABLE;
  1074. I915_WRITE(DP_A, dpa_ctl);
  1075. POSTING_READ(DP_A);
  1076. udelay(200);
  1077. }
  1078. /* If the sink supports it, try to set the power state appropriately */
  1079. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode)
  1080. {
  1081. int ret, i;
  1082. /* Should have a valid DPCD by this point */
  1083. if (intel_dp->dpcd[DP_DPCD_REV] < 0x11)
  1084. return;
  1085. if (mode != DRM_MODE_DPMS_ON) {
  1086. ret = intel_dp_aux_native_write_1(intel_dp, DP_SET_POWER,
  1087. DP_SET_POWER_D3);
  1088. if (ret != 1)
  1089. DRM_DEBUG_DRIVER("failed to write sink power state\n");
  1090. } else {
  1091. /*
  1092. * When turning on, we need to retry for 1ms to give the sink
  1093. * time to wake up.
  1094. */
  1095. for (i = 0; i < 3; i++) {
  1096. ret = intel_dp_aux_native_write_1(intel_dp,
  1097. DP_SET_POWER,
  1098. DP_SET_POWER_D0);
  1099. if (ret == 1)
  1100. break;
  1101. msleep(1);
  1102. }
  1103. }
  1104. }
  1105. static bool intel_dp_get_hw_state(struct intel_encoder *encoder,
  1106. enum pipe *pipe)
  1107. {
  1108. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1109. struct drm_device *dev = encoder->base.dev;
  1110. struct drm_i915_private *dev_priv = dev->dev_private;
  1111. u32 tmp = I915_READ(intel_dp->output_reg);
  1112. if (!(tmp & DP_PORT_EN))
  1113. return false;
  1114. if (is_cpu_edp(intel_dp) && IS_GEN7(dev)) {
  1115. *pipe = PORT_TO_PIPE_CPT(tmp);
  1116. } else if (!HAS_PCH_CPT(dev) || is_cpu_edp(intel_dp)) {
  1117. *pipe = PORT_TO_PIPE(tmp);
  1118. } else {
  1119. u32 trans_sel;
  1120. u32 trans_dp;
  1121. int i;
  1122. switch (intel_dp->output_reg) {
  1123. case PCH_DP_B:
  1124. trans_sel = TRANS_DP_PORT_SEL_B;
  1125. break;
  1126. case PCH_DP_C:
  1127. trans_sel = TRANS_DP_PORT_SEL_C;
  1128. break;
  1129. case PCH_DP_D:
  1130. trans_sel = TRANS_DP_PORT_SEL_D;
  1131. break;
  1132. default:
  1133. return true;
  1134. }
  1135. for_each_pipe(i) {
  1136. trans_dp = I915_READ(TRANS_DP_CTL(i));
  1137. if ((trans_dp & TRANS_DP_PORT_SEL_MASK) == trans_sel) {
  1138. *pipe = i;
  1139. return true;
  1140. }
  1141. }
  1142. }
  1143. DRM_DEBUG_KMS("No pipe for dp port 0x%x found\n", intel_dp->output_reg);
  1144. return true;
  1145. }
  1146. static void intel_disable_dp(struct intel_encoder *encoder)
  1147. {
  1148. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1149. /* Make sure the panel is off before trying to change the mode. But also
  1150. * ensure that we have vdd while we switch off the panel. */
  1151. ironlake_edp_panel_vdd_on(intel_dp);
  1152. ironlake_edp_backlight_off(intel_dp);
  1153. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1154. ironlake_edp_panel_off(intel_dp);
  1155. /* cpu edp my only be disable _after_ the cpu pipe/plane is disabled. */
  1156. if (!is_cpu_edp(intel_dp))
  1157. intel_dp_link_down(intel_dp);
  1158. }
  1159. static void intel_post_disable_dp(struct intel_encoder *encoder)
  1160. {
  1161. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1162. if (is_cpu_edp(intel_dp)) {
  1163. intel_dp_link_down(intel_dp);
  1164. ironlake_edp_pll_off(intel_dp);
  1165. }
  1166. }
  1167. static void intel_enable_dp(struct intel_encoder *encoder)
  1168. {
  1169. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1170. struct drm_device *dev = encoder->base.dev;
  1171. struct drm_i915_private *dev_priv = dev->dev_private;
  1172. uint32_t dp_reg = I915_READ(intel_dp->output_reg);
  1173. if (WARN_ON(dp_reg & DP_PORT_EN))
  1174. return;
  1175. ironlake_edp_panel_vdd_on(intel_dp);
  1176. intel_dp_sink_dpms(intel_dp, DRM_MODE_DPMS_ON);
  1177. intel_dp_start_link_train(intel_dp);
  1178. ironlake_edp_panel_on(intel_dp);
  1179. ironlake_edp_panel_vdd_off(intel_dp, true);
  1180. intel_dp_complete_link_train(intel_dp);
  1181. ironlake_edp_backlight_on(intel_dp);
  1182. }
  1183. static void intel_pre_enable_dp(struct intel_encoder *encoder)
  1184. {
  1185. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  1186. if (is_cpu_edp(intel_dp))
  1187. ironlake_edp_pll_on(intel_dp);
  1188. }
  1189. /*
  1190. * Native read with retry for link status and receiver capability reads for
  1191. * cases where the sink may still be asleep.
  1192. */
  1193. static bool
  1194. intel_dp_aux_native_read_retry(struct intel_dp *intel_dp, uint16_t address,
  1195. uint8_t *recv, int recv_bytes)
  1196. {
  1197. int ret, i;
  1198. /*
  1199. * Sinks are *supposed* to come up within 1ms from an off state,
  1200. * but we're also supposed to retry 3 times per the spec.
  1201. */
  1202. for (i = 0; i < 3; i++) {
  1203. ret = intel_dp_aux_native_read(intel_dp, address, recv,
  1204. recv_bytes);
  1205. if (ret == recv_bytes)
  1206. return true;
  1207. msleep(1);
  1208. }
  1209. return false;
  1210. }
  1211. /*
  1212. * Fetch AUX CH registers 0x202 - 0x207 which contain
  1213. * link status information
  1214. */
  1215. static bool
  1216. intel_dp_get_link_status(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  1217. {
  1218. return intel_dp_aux_native_read_retry(intel_dp,
  1219. DP_LANE0_1_STATUS,
  1220. link_status,
  1221. DP_LINK_STATUS_SIZE);
  1222. }
  1223. #if 0
  1224. static char *voltage_names[] = {
  1225. "0.4V", "0.6V", "0.8V", "1.2V"
  1226. };
  1227. static char *pre_emph_names[] = {
  1228. "0dB", "3.5dB", "6dB", "9.5dB"
  1229. };
  1230. static char *link_train_names[] = {
  1231. "pattern 1", "pattern 2", "idle", "off"
  1232. };
  1233. #endif
  1234. /*
  1235. * These are source-specific values; current Intel hardware supports
  1236. * a maximum voltage of 800mV and a maximum pre-emphasis of 6dB
  1237. */
  1238. static uint8_t
  1239. intel_dp_voltage_max(struct intel_dp *intel_dp)
  1240. {
  1241. struct drm_device *dev = intel_dp->base.base.dev;
  1242. if (IS_GEN7(dev) && is_cpu_edp(intel_dp))
  1243. return DP_TRAIN_VOLTAGE_SWING_800;
  1244. else if (HAS_PCH_CPT(dev) && !is_cpu_edp(intel_dp))
  1245. return DP_TRAIN_VOLTAGE_SWING_1200;
  1246. else
  1247. return DP_TRAIN_VOLTAGE_SWING_800;
  1248. }
  1249. static uint8_t
  1250. intel_dp_pre_emphasis_max(struct intel_dp *intel_dp, uint8_t voltage_swing)
  1251. {
  1252. struct drm_device *dev = intel_dp->base.base.dev;
  1253. if (IS_HASWELL(dev)) {
  1254. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1255. case DP_TRAIN_VOLTAGE_SWING_400:
  1256. return DP_TRAIN_PRE_EMPHASIS_9_5;
  1257. case DP_TRAIN_VOLTAGE_SWING_600:
  1258. return DP_TRAIN_PRE_EMPHASIS_6;
  1259. case DP_TRAIN_VOLTAGE_SWING_800:
  1260. return DP_TRAIN_PRE_EMPHASIS_3_5;
  1261. case DP_TRAIN_VOLTAGE_SWING_1200:
  1262. default:
  1263. return DP_TRAIN_PRE_EMPHASIS_0;
  1264. }
  1265. } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
  1266. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1267. case DP_TRAIN_VOLTAGE_SWING_400:
  1268. return DP_TRAIN_PRE_EMPHASIS_6;
  1269. case DP_TRAIN_VOLTAGE_SWING_600:
  1270. case DP_TRAIN_VOLTAGE_SWING_800:
  1271. return DP_TRAIN_PRE_EMPHASIS_3_5;
  1272. default:
  1273. return DP_TRAIN_PRE_EMPHASIS_0;
  1274. }
  1275. } else {
  1276. switch (voltage_swing & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1277. case DP_TRAIN_VOLTAGE_SWING_400:
  1278. return DP_TRAIN_PRE_EMPHASIS_6;
  1279. case DP_TRAIN_VOLTAGE_SWING_600:
  1280. return DP_TRAIN_PRE_EMPHASIS_6;
  1281. case DP_TRAIN_VOLTAGE_SWING_800:
  1282. return DP_TRAIN_PRE_EMPHASIS_3_5;
  1283. case DP_TRAIN_VOLTAGE_SWING_1200:
  1284. default:
  1285. return DP_TRAIN_PRE_EMPHASIS_0;
  1286. }
  1287. }
  1288. }
  1289. static void
  1290. intel_get_adjust_train(struct intel_dp *intel_dp, uint8_t link_status[DP_LINK_STATUS_SIZE])
  1291. {
  1292. uint8_t v = 0;
  1293. uint8_t p = 0;
  1294. int lane;
  1295. uint8_t voltage_max;
  1296. uint8_t preemph_max;
  1297. for (lane = 0; lane < intel_dp->lane_count; lane++) {
  1298. uint8_t this_v = drm_dp_get_adjust_request_voltage(link_status, lane);
  1299. uint8_t this_p = drm_dp_get_adjust_request_pre_emphasis(link_status, lane);
  1300. if (this_v > v)
  1301. v = this_v;
  1302. if (this_p > p)
  1303. p = this_p;
  1304. }
  1305. voltage_max = intel_dp_voltage_max(intel_dp);
  1306. if (v >= voltage_max)
  1307. v = voltage_max | DP_TRAIN_MAX_SWING_REACHED;
  1308. preemph_max = intel_dp_pre_emphasis_max(intel_dp, v);
  1309. if (p >= preemph_max)
  1310. p = preemph_max | DP_TRAIN_MAX_PRE_EMPHASIS_REACHED;
  1311. for (lane = 0; lane < 4; lane++)
  1312. intel_dp->train_set[lane] = v | p;
  1313. }
  1314. static uint32_t
  1315. intel_dp_signal_levels(uint8_t train_set)
  1316. {
  1317. uint32_t signal_levels = 0;
  1318. switch (train_set & DP_TRAIN_VOLTAGE_SWING_MASK) {
  1319. case DP_TRAIN_VOLTAGE_SWING_400:
  1320. default:
  1321. signal_levels |= DP_VOLTAGE_0_4;
  1322. break;
  1323. case DP_TRAIN_VOLTAGE_SWING_600:
  1324. signal_levels |= DP_VOLTAGE_0_6;
  1325. break;
  1326. case DP_TRAIN_VOLTAGE_SWING_800:
  1327. signal_levels |= DP_VOLTAGE_0_8;
  1328. break;
  1329. case DP_TRAIN_VOLTAGE_SWING_1200:
  1330. signal_levels |= DP_VOLTAGE_1_2;
  1331. break;
  1332. }
  1333. switch (train_set & DP_TRAIN_PRE_EMPHASIS_MASK) {
  1334. case DP_TRAIN_PRE_EMPHASIS_0:
  1335. default:
  1336. signal_levels |= DP_PRE_EMPHASIS_0;
  1337. break;
  1338. case DP_TRAIN_PRE_EMPHASIS_3_5:
  1339. signal_levels |= DP_PRE_EMPHASIS_3_5;
  1340. break;
  1341. case DP_TRAIN_PRE_EMPHASIS_6:
  1342. signal_levels |= DP_PRE_EMPHASIS_6;
  1343. break;
  1344. case DP_TRAIN_PRE_EMPHASIS_9_5:
  1345. signal_levels |= DP_PRE_EMPHASIS_9_5;
  1346. break;
  1347. }
  1348. return signal_levels;
  1349. }
  1350. /* Gen6's DP voltage swing and pre-emphasis control */
  1351. static uint32_t
  1352. intel_gen6_edp_signal_levels(uint8_t train_set)
  1353. {
  1354. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1355. DP_TRAIN_PRE_EMPHASIS_MASK);
  1356. switch (signal_levels) {
  1357. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  1358. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  1359. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  1360. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1361. return EDP_LINK_TRAIN_400MV_3_5DB_SNB_B;
  1362. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  1363. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
  1364. return EDP_LINK_TRAIN_400_600MV_6DB_SNB_B;
  1365. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1366. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1367. return EDP_LINK_TRAIN_600_800MV_3_5DB_SNB_B;
  1368. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  1369. case DP_TRAIN_VOLTAGE_SWING_1200 | DP_TRAIN_PRE_EMPHASIS_0:
  1370. return EDP_LINK_TRAIN_800_1200MV_0DB_SNB_B;
  1371. default:
  1372. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  1373. "0x%x\n", signal_levels);
  1374. return EDP_LINK_TRAIN_400_600MV_0DB_SNB_B;
  1375. }
  1376. }
  1377. /* Gen7's DP voltage swing and pre-emphasis control */
  1378. static uint32_t
  1379. intel_gen7_edp_signal_levels(uint8_t train_set)
  1380. {
  1381. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1382. DP_TRAIN_PRE_EMPHASIS_MASK);
  1383. switch (signal_levels) {
  1384. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  1385. return EDP_LINK_TRAIN_400MV_0DB_IVB;
  1386. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1387. return EDP_LINK_TRAIN_400MV_3_5DB_IVB;
  1388. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  1389. return EDP_LINK_TRAIN_400MV_6DB_IVB;
  1390. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  1391. return EDP_LINK_TRAIN_600MV_0DB_IVB;
  1392. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1393. return EDP_LINK_TRAIN_600MV_3_5DB_IVB;
  1394. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  1395. return EDP_LINK_TRAIN_800MV_0DB_IVB;
  1396. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1397. return EDP_LINK_TRAIN_800MV_3_5DB_IVB;
  1398. default:
  1399. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  1400. "0x%x\n", signal_levels);
  1401. return EDP_LINK_TRAIN_500MV_0DB_IVB;
  1402. }
  1403. }
  1404. /* Gen7.5's (HSW) DP voltage swing and pre-emphasis control */
  1405. static uint32_t
  1406. intel_dp_signal_levels_hsw(uint8_t train_set)
  1407. {
  1408. int signal_levels = train_set & (DP_TRAIN_VOLTAGE_SWING_MASK |
  1409. DP_TRAIN_PRE_EMPHASIS_MASK);
  1410. switch (signal_levels) {
  1411. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0:
  1412. return DDI_BUF_EMP_400MV_0DB_HSW;
  1413. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1414. return DDI_BUF_EMP_400MV_3_5DB_HSW;
  1415. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6:
  1416. return DDI_BUF_EMP_400MV_6DB_HSW;
  1417. case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_9_5:
  1418. return DDI_BUF_EMP_400MV_9_5DB_HSW;
  1419. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_0:
  1420. return DDI_BUF_EMP_600MV_0DB_HSW;
  1421. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1422. return DDI_BUF_EMP_600MV_3_5DB_HSW;
  1423. case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_6:
  1424. return DDI_BUF_EMP_600MV_6DB_HSW;
  1425. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0:
  1426. return DDI_BUF_EMP_800MV_0DB_HSW;
  1427. case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_3_5:
  1428. return DDI_BUF_EMP_800MV_3_5DB_HSW;
  1429. default:
  1430. DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level:"
  1431. "0x%x\n", signal_levels);
  1432. return DDI_BUF_EMP_400MV_0DB_HSW;
  1433. }
  1434. }
  1435. static bool
  1436. intel_dp_set_link_train(struct intel_dp *intel_dp,
  1437. uint32_t dp_reg_value,
  1438. uint8_t dp_train_pat)
  1439. {
  1440. struct drm_device *dev = intel_dp->base.base.dev;
  1441. struct drm_i915_private *dev_priv = dev->dev_private;
  1442. int ret;
  1443. uint32_t temp;
  1444. if (IS_HASWELL(dev)) {
  1445. temp = I915_READ(DP_TP_CTL(intel_dp->port));
  1446. if (dp_train_pat & DP_LINK_SCRAMBLING_DISABLE)
  1447. temp |= DP_TP_CTL_SCRAMBLE_DISABLE;
  1448. else
  1449. temp &= ~DP_TP_CTL_SCRAMBLE_DISABLE;
  1450. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  1451. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  1452. case DP_TRAINING_PATTERN_DISABLE:
  1453. temp |= DP_TP_CTL_LINK_TRAIN_IDLE;
  1454. I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
  1455. if (wait_for((I915_READ(DP_TP_STATUS(intel_dp->port)) &
  1456. DP_TP_STATUS_IDLE_DONE), 1))
  1457. DRM_ERROR("Timed out waiting for DP idle patterns\n");
  1458. temp &= ~DP_TP_CTL_LINK_TRAIN_MASK;
  1459. temp |= DP_TP_CTL_LINK_TRAIN_NORMAL;
  1460. break;
  1461. case DP_TRAINING_PATTERN_1:
  1462. temp |= DP_TP_CTL_LINK_TRAIN_PAT1;
  1463. break;
  1464. case DP_TRAINING_PATTERN_2:
  1465. temp |= DP_TP_CTL_LINK_TRAIN_PAT2;
  1466. break;
  1467. case DP_TRAINING_PATTERN_3:
  1468. temp |= DP_TP_CTL_LINK_TRAIN_PAT3;
  1469. break;
  1470. }
  1471. I915_WRITE(DP_TP_CTL(intel_dp->port), temp);
  1472. } else if (HAS_PCH_CPT(dev) &&
  1473. (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
  1474. dp_reg_value &= ~DP_LINK_TRAIN_MASK_CPT;
  1475. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  1476. case DP_TRAINING_PATTERN_DISABLE:
  1477. dp_reg_value |= DP_LINK_TRAIN_OFF_CPT;
  1478. break;
  1479. case DP_TRAINING_PATTERN_1:
  1480. dp_reg_value |= DP_LINK_TRAIN_PAT_1_CPT;
  1481. break;
  1482. case DP_TRAINING_PATTERN_2:
  1483. dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
  1484. break;
  1485. case DP_TRAINING_PATTERN_3:
  1486. DRM_ERROR("DP training pattern 3 not supported\n");
  1487. dp_reg_value |= DP_LINK_TRAIN_PAT_2_CPT;
  1488. break;
  1489. }
  1490. } else {
  1491. dp_reg_value &= ~DP_LINK_TRAIN_MASK;
  1492. switch (dp_train_pat & DP_TRAINING_PATTERN_MASK) {
  1493. case DP_TRAINING_PATTERN_DISABLE:
  1494. dp_reg_value |= DP_LINK_TRAIN_OFF;
  1495. break;
  1496. case DP_TRAINING_PATTERN_1:
  1497. dp_reg_value |= DP_LINK_TRAIN_PAT_1;
  1498. break;
  1499. case DP_TRAINING_PATTERN_2:
  1500. dp_reg_value |= DP_LINK_TRAIN_PAT_2;
  1501. break;
  1502. case DP_TRAINING_PATTERN_3:
  1503. DRM_ERROR("DP training pattern 3 not supported\n");
  1504. dp_reg_value |= DP_LINK_TRAIN_PAT_2;
  1505. break;
  1506. }
  1507. }
  1508. I915_WRITE(intel_dp->output_reg, dp_reg_value);
  1509. POSTING_READ(intel_dp->output_reg);
  1510. intel_dp_aux_native_write_1(intel_dp,
  1511. DP_TRAINING_PATTERN_SET,
  1512. dp_train_pat);
  1513. if ((dp_train_pat & DP_TRAINING_PATTERN_MASK) !=
  1514. DP_TRAINING_PATTERN_DISABLE) {
  1515. ret = intel_dp_aux_native_write(intel_dp,
  1516. DP_TRAINING_LANE0_SET,
  1517. intel_dp->train_set,
  1518. intel_dp->lane_count);
  1519. if (ret != intel_dp->lane_count)
  1520. return false;
  1521. }
  1522. return true;
  1523. }
  1524. /* Enable corresponding port and start training pattern 1 */
  1525. void
  1526. intel_dp_start_link_train(struct intel_dp *intel_dp)
  1527. {
  1528. struct drm_encoder *encoder = &intel_dp->base.base;
  1529. struct drm_device *dev = encoder->dev;
  1530. int i;
  1531. uint8_t voltage;
  1532. bool clock_recovery = false;
  1533. int voltage_tries, loop_tries;
  1534. uint32_t DP = intel_dp->DP;
  1535. if (IS_HASWELL(dev))
  1536. intel_ddi_prepare_link_retrain(encoder);
  1537. /* Write the link configuration data */
  1538. intel_dp_aux_native_write(intel_dp, DP_LINK_BW_SET,
  1539. intel_dp->link_configuration,
  1540. DP_LINK_CONFIGURATION_SIZE);
  1541. DP |= DP_PORT_EN;
  1542. memset(intel_dp->train_set, 0, 4);
  1543. voltage = 0xff;
  1544. voltage_tries = 0;
  1545. loop_tries = 0;
  1546. clock_recovery = false;
  1547. for (;;) {
  1548. /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
  1549. uint8_t link_status[DP_LINK_STATUS_SIZE];
  1550. uint32_t signal_levels;
  1551. if (IS_HASWELL(dev)) {
  1552. signal_levels = intel_dp_signal_levels_hsw(
  1553. intel_dp->train_set[0]);
  1554. DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
  1555. } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
  1556. signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
  1557. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
  1558. } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
  1559. signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
  1560. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
  1561. } else {
  1562. signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
  1563. DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
  1564. }
  1565. DRM_DEBUG_KMS("training pattern 1 signal levels %08x\n",
  1566. signal_levels);
  1567. /* Set training pattern 1 */
  1568. if (!intel_dp_set_link_train(intel_dp, DP,
  1569. DP_TRAINING_PATTERN_1 |
  1570. DP_LINK_SCRAMBLING_DISABLE))
  1571. break;
  1572. drm_dp_link_train_clock_recovery_delay(intel_dp->dpcd);
  1573. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  1574. DRM_ERROR("failed to get link status\n");
  1575. break;
  1576. }
  1577. if (drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
  1578. DRM_DEBUG_KMS("clock recovery OK\n");
  1579. clock_recovery = true;
  1580. break;
  1581. }
  1582. /* Check to see if we've tried the max voltage */
  1583. for (i = 0; i < intel_dp->lane_count; i++)
  1584. if ((intel_dp->train_set[i] & DP_TRAIN_MAX_SWING_REACHED) == 0)
  1585. break;
  1586. if (i == intel_dp->lane_count && voltage_tries == 5) {
  1587. if (++loop_tries == 5) {
  1588. DRM_DEBUG_KMS("too many full retries, give up\n");
  1589. break;
  1590. }
  1591. memset(intel_dp->train_set, 0, 4);
  1592. voltage_tries = 0;
  1593. continue;
  1594. }
  1595. /* Check to see if we've tried the same voltage 5 times */
  1596. if ((intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK) != voltage) {
  1597. voltage = intel_dp->train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK;
  1598. voltage_tries = 0;
  1599. } else
  1600. ++voltage_tries;
  1601. /* Compute new intel_dp->train_set as requested by target */
  1602. intel_get_adjust_train(intel_dp, link_status);
  1603. }
  1604. intel_dp->DP = DP;
  1605. }
  1606. void
  1607. intel_dp_complete_link_train(struct intel_dp *intel_dp)
  1608. {
  1609. struct drm_device *dev = intel_dp->base.base.dev;
  1610. bool channel_eq = false;
  1611. int tries, cr_tries;
  1612. uint32_t DP = intel_dp->DP;
  1613. /* channel equalization */
  1614. tries = 0;
  1615. cr_tries = 0;
  1616. channel_eq = false;
  1617. for (;;) {
  1618. /* Use intel_dp->train_set[0] to set the voltage and pre emphasis values */
  1619. uint32_t signal_levels;
  1620. uint8_t link_status[DP_LINK_STATUS_SIZE];
  1621. if (cr_tries > 5) {
  1622. DRM_ERROR("failed to train DP, aborting\n");
  1623. intel_dp_link_down(intel_dp);
  1624. break;
  1625. }
  1626. if (IS_HASWELL(dev)) {
  1627. signal_levels = intel_dp_signal_levels_hsw(intel_dp->train_set[0]);
  1628. DP = (DP & ~DDI_BUF_EMP_MASK) | signal_levels;
  1629. } else if (IS_GEN7(dev) && is_cpu_edp(intel_dp) && !IS_VALLEYVIEW(dev)) {
  1630. signal_levels = intel_gen7_edp_signal_levels(intel_dp->train_set[0]);
  1631. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_IVB) | signal_levels;
  1632. } else if (IS_GEN6(dev) && is_cpu_edp(intel_dp)) {
  1633. signal_levels = intel_gen6_edp_signal_levels(intel_dp->train_set[0]);
  1634. DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels;
  1635. } else {
  1636. signal_levels = intel_dp_signal_levels(intel_dp->train_set[0]);
  1637. DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels;
  1638. }
  1639. /* channel eq pattern */
  1640. if (!intel_dp_set_link_train(intel_dp, DP,
  1641. DP_TRAINING_PATTERN_2 |
  1642. DP_LINK_SCRAMBLING_DISABLE))
  1643. break;
  1644. drm_dp_link_train_channel_eq_delay(intel_dp->dpcd);
  1645. if (!intel_dp_get_link_status(intel_dp, link_status))
  1646. break;
  1647. /* Make sure clock is still ok */
  1648. if (!drm_dp_clock_recovery_ok(link_status, intel_dp->lane_count)) {
  1649. intel_dp_start_link_train(intel_dp);
  1650. cr_tries++;
  1651. continue;
  1652. }
  1653. if (drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  1654. channel_eq = true;
  1655. break;
  1656. }
  1657. /* Try 5 times, then try clock recovery if that fails */
  1658. if (tries > 5) {
  1659. intel_dp_link_down(intel_dp);
  1660. intel_dp_start_link_train(intel_dp);
  1661. tries = 0;
  1662. cr_tries++;
  1663. continue;
  1664. }
  1665. /* Compute new intel_dp->train_set as requested by target */
  1666. intel_get_adjust_train(intel_dp, link_status);
  1667. ++tries;
  1668. }
  1669. if (channel_eq)
  1670. DRM_DEBUG_KMS("Channel EQ done. DP Training successfull\n");
  1671. intel_dp_set_link_train(intel_dp, DP, DP_TRAINING_PATTERN_DISABLE);
  1672. }
  1673. static void
  1674. intel_dp_link_down(struct intel_dp *intel_dp)
  1675. {
  1676. struct drm_device *dev = intel_dp->base.base.dev;
  1677. struct drm_i915_private *dev_priv = dev->dev_private;
  1678. uint32_t DP = intel_dp->DP;
  1679. /*
  1680. * DDI code has a strict mode set sequence and we should try to respect
  1681. * it, otherwise we might hang the machine in many different ways. So we
  1682. * really should be disabling the port only on a complete crtc_disable
  1683. * sequence. This function is just called under two conditions on DDI
  1684. * code:
  1685. * - Link train failed while doing crtc_enable, and on this case we
  1686. * really should respect the mode set sequence and wait for a
  1687. * crtc_disable.
  1688. * - Someone turned the monitor off and intel_dp_check_link_status
  1689. * called us. We don't need to disable the whole port on this case, so
  1690. * when someone turns the monitor on again,
  1691. * intel_ddi_prepare_link_retrain will take care of redoing the link
  1692. * train.
  1693. */
  1694. if (IS_HASWELL(dev))
  1695. return;
  1696. if (WARN_ON((I915_READ(intel_dp->output_reg) & DP_PORT_EN) == 0))
  1697. return;
  1698. DRM_DEBUG_KMS("\n");
  1699. if (HAS_PCH_CPT(dev) && (IS_GEN7(dev) || !is_cpu_edp(intel_dp))) {
  1700. DP &= ~DP_LINK_TRAIN_MASK_CPT;
  1701. I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT);
  1702. } else {
  1703. DP &= ~DP_LINK_TRAIN_MASK;
  1704. I915_WRITE(intel_dp->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE);
  1705. }
  1706. POSTING_READ(intel_dp->output_reg);
  1707. msleep(17);
  1708. if (HAS_PCH_IBX(dev) &&
  1709. I915_READ(intel_dp->output_reg) & DP_PIPEB_SELECT) {
  1710. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  1711. /* Hardware workaround: leaving our transcoder select
  1712. * set to transcoder B while it's off will prevent the
  1713. * corresponding HDMI output on transcoder A.
  1714. *
  1715. * Combine this with another hardware workaround:
  1716. * transcoder select bit can only be cleared while the
  1717. * port is enabled.
  1718. */
  1719. DP &= ~DP_PIPEB_SELECT;
  1720. I915_WRITE(intel_dp->output_reg, DP);
  1721. /* Changes to enable or select take place the vblank
  1722. * after being written.
  1723. */
  1724. if (crtc == NULL) {
  1725. /* We can arrive here never having been attached
  1726. * to a CRTC, for instance, due to inheriting
  1727. * random state from the BIOS.
  1728. *
  1729. * If the pipe is not running, play safe and
  1730. * wait for the clocks to stabilise before
  1731. * continuing.
  1732. */
  1733. POSTING_READ(intel_dp->output_reg);
  1734. msleep(50);
  1735. } else
  1736. intel_wait_for_vblank(dev, to_intel_crtc(crtc)->pipe);
  1737. }
  1738. DP &= ~DP_AUDIO_OUTPUT_ENABLE;
  1739. I915_WRITE(intel_dp->output_reg, DP & ~DP_PORT_EN);
  1740. POSTING_READ(intel_dp->output_reg);
  1741. msleep(intel_dp->panel_power_down_delay);
  1742. }
  1743. static bool
  1744. intel_dp_get_dpcd(struct intel_dp *intel_dp)
  1745. {
  1746. if (intel_dp_aux_native_read_retry(intel_dp, 0x000, intel_dp->dpcd,
  1747. sizeof(intel_dp->dpcd)) == 0)
  1748. return false; /* aux transfer failed */
  1749. if (intel_dp->dpcd[DP_DPCD_REV] == 0)
  1750. return false; /* DPCD not present */
  1751. if (!(intel_dp->dpcd[DP_DOWNSTREAMPORT_PRESENT] &
  1752. DP_DWN_STRM_PORT_PRESENT))
  1753. return true; /* native DP sink */
  1754. if (intel_dp->dpcd[DP_DPCD_REV] == 0x10)
  1755. return true; /* no per-port downstream info */
  1756. if (intel_dp_aux_native_read_retry(intel_dp, DP_DOWNSTREAM_PORT_0,
  1757. intel_dp->downstream_ports,
  1758. DP_MAX_DOWNSTREAM_PORTS) == 0)
  1759. return false; /* downstream port status fetch failed */
  1760. return true;
  1761. }
  1762. static void
  1763. intel_dp_probe_oui(struct intel_dp *intel_dp)
  1764. {
  1765. u8 buf[3];
  1766. if (!(intel_dp->dpcd[DP_DOWN_STREAM_PORT_COUNT] & DP_OUI_SUPPORT))
  1767. return;
  1768. ironlake_edp_panel_vdd_on(intel_dp);
  1769. if (intel_dp_aux_native_read_retry(intel_dp, DP_SINK_OUI, buf, 3))
  1770. DRM_DEBUG_KMS("Sink OUI: %02hx%02hx%02hx\n",
  1771. buf[0], buf[1], buf[2]);
  1772. if (intel_dp_aux_native_read_retry(intel_dp, DP_BRANCH_OUI, buf, 3))
  1773. DRM_DEBUG_KMS("Branch OUI: %02hx%02hx%02hx\n",
  1774. buf[0], buf[1], buf[2]);
  1775. ironlake_edp_panel_vdd_off(intel_dp, false);
  1776. }
  1777. static bool
  1778. intel_dp_get_sink_irq(struct intel_dp *intel_dp, u8 *sink_irq_vector)
  1779. {
  1780. int ret;
  1781. ret = intel_dp_aux_native_read_retry(intel_dp,
  1782. DP_DEVICE_SERVICE_IRQ_VECTOR,
  1783. sink_irq_vector, 1);
  1784. if (!ret)
  1785. return false;
  1786. return true;
  1787. }
  1788. static void
  1789. intel_dp_handle_test_request(struct intel_dp *intel_dp)
  1790. {
  1791. /* NAK by default */
  1792. intel_dp_aux_native_write_1(intel_dp, DP_TEST_RESPONSE, DP_TEST_NAK);
  1793. }
  1794. /*
  1795. * According to DP spec
  1796. * 5.1.2:
  1797. * 1. Read DPCD
  1798. * 2. Configure link according to Receiver Capabilities
  1799. * 3. Use Link Training from 2.5.3.3 and 3.5.1.3
  1800. * 4. Check link status on receipt of hot-plug interrupt
  1801. */
  1802. static void
  1803. intel_dp_check_link_status(struct intel_dp *intel_dp)
  1804. {
  1805. u8 sink_irq_vector;
  1806. u8 link_status[DP_LINK_STATUS_SIZE];
  1807. if (!intel_dp->base.connectors_active)
  1808. return;
  1809. if (WARN_ON(!intel_dp->base.base.crtc))
  1810. return;
  1811. /* Try to read receiver status if the link appears to be up */
  1812. if (!intel_dp_get_link_status(intel_dp, link_status)) {
  1813. intel_dp_link_down(intel_dp);
  1814. return;
  1815. }
  1816. /* Now read the DPCD to see if it's actually running */
  1817. if (!intel_dp_get_dpcd(intel_dp)) {
  1818. intel_dp_link_down(intel_dp);
  1819. return;
  1820. }
  1821. /* Try to read the source of the interrupt */
  1822. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11 &&
  1823. intel_dp_get_sink_irq(intel_dp, &sink_irq_vector)) {
  1824. /* Clear interrupt source */
  1825. intel_dp_aux_native_write_1(intel_dp,
  1826. DP_DEVICE_SERVICE_IRQ_VECTOR,
  1827. sink_irq_vector);
  1828. if (sink_irq_vector & DP_AUTOMATED_TEST_REQUEST)
  1829. intel_dp_handle_test_request(intel_dp);
  1830. if (sink_irq_vector & (DP_CP_IRQ | DP_SINK_SPECIFIC_IRQ))
  1831. DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
  1832. }
  1833. if (!drm_dp_channel_eq_ok(link_status, intel_dp->lane_count)) {
  1834. DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
  1835. drm_get_encoder_name(&intel_dp->base.base));
  1836. intel_dp_start_link_train(intel_dp);
  1837. intel_dp_complete_link_train(intel_dp);
  1838. }
  1839. }
  1840. /* XXX this is probably wrong for multiple downstream ports */
  1841. static enum drm_connector_status
  1842. intel_dp_detect_dpcd(struct intel_dp *intel_dp)
  1843. {
  1844. uint8_t *dpcd = intel_dp->dpcd;
  1845. bool hpd;
  1846. uint8_t type;
  1847. if (!intel_dp_get_dpcd(intel_dp))
  1848. return connector_status_disconnected;
  1849. /* if there's no downstream port, we're done */
  1850. if (!(dpcd[DP_DOWNSTREAMPORT_PRESENT] & DP_DWN_STRM_PORT_PRESENT))
  1851. return connector_status_connected;
  1852. /* If we're HPD-aware, SINK_COUNT changes dynamically */
  1853. hpd = !!(intel_dp->downstream_ports[0] & DP_DS_PORT_HPD);
  1854. if (hpd) {
  1855. uint8_t reg;
  1856. if (!intel_dp_aux_native_read_retry(intel_dp, DP_SINK_COUNT,
  1857. &reg, 1))
  1858. return connector_status_unknown;
  1859. return DP_GET_SINK_COUNT(reg) ? connector_status_connected
  1860. : connector_status_disconnected;
  1861. }
  1862. /* If no HPD, poke DDC gently */
  1863. if (drm_probe_ddc(&intel_dp->adapter))
  1864. return connector_status_connected;
  1865. /* Well we tried, say unknown for unreliable port types */
  1866. type = intel_dp->downstream_ports[0] & DP_DS_PORT_TYPE_MASK;
  1867. if (type == DP_DS_PORT_TYPE_VGA || type == DP_DS_PORT_TYPE_NON_EDID)
  1868. return connector_status_unknown;
  1869. /* Anything else is out of spec, warn and ignore */
  1870. DRM_DEBUG_KMS("Broken DP branch device, ignoring\n");
  1871. return connector_status_disconnected;
  1872. }
  1873. static enum drm_connector_status
  1874. ironlake_dp_detect(struct intel_dp *intel_dp)
  1875. {
  1876. enum drm_connector_status status;
  1877. /* Can't disconnect eDP, but you can close the lid... */
  1878. if (is_edp(intel_dp)) {
  1879. status = intel_panel_detect(intel_dp->base.base.dev);
  1880. if (status == connector_status_unknown)
  1881. status = connector_status_connected;
  1882. return status;
  1883. }
  1884. return intel_dp_detect_dpcd(intel_dp);
  1885. }
  1886. static enum drm_connector_status
  1887. g4x_dp_detect(struct intel_dp *intel_dp)
  1888. {
  1889. struct drm_device *dev = intel_dp->base.base.dev;
  1890. struct drm_i915_private *dev_priv = dev->dev_private;
  1891. uint32_t bit;
  1892. switch (intel_dp->output_reg) {
  1893. case DP_B:
  1894. bit = DPB_HOTPLUG_LIVE_STATUS;
  1895. break;
  1896. case DP_C:
  1897. bit = DPC_HOTPLUG_LIVE_STATUS;
  1898. break;
  1899. case DP_D:
  1900. bit = DPD_HOTPLUG_LIVE_STATUS;
  1901. break;
  1902. default:
  1903. return connector_status_unknown;
  1904. }
  1905. if ((I915_READ(PORT_HOTPLUG_STAT) & bit) == 0)
  1906. return connector_status_disconnected;
  1907. return intel_dp_detect_dpcd(intel_dp);
  1908. }
  1909. static struct edid *
  1910. intel_dp_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
  1911. {
  1912. struct intel_connector *intel_connector = to_intel_connector(connector);
  1913. /* use cached edid if we have one */
  1914. if (intel_connector->edid) {
  1915. struct edid *edid;
  1916. int size;
  1917. /* invalid edid */
  1918. if (IS_ERR(intel_connector->edid))
  1919. return NULL;
  1920. size = (intel_connector->edid->extensions + 1) * EDID_LENGTH;
  1921. edid = kmalloc(size, GFP_KERNEL);
  1922. if (!edid)
  1923. return NULL;
  1924. memcpy(edid, intel_connector->edid, size);
  1925. return edid;
  1926. }
  1927. return drm_get_edid(connector, adapter);
  1928. }
  1929. static int
  1930. intel_dp_get_edid_modes(struct drm_connector *connector, struct i2c_adapter *adapter)
  1931. {
  1932. struct intel_connector *intel_connector = to_intel_connector(connector);
  1933. /* use cached edid if we have one */
  1934. if (intel_connector->edid) {
  1935. /* invalid edid */
  1936. if (IS_ERR(intel_connector->edid))
  1937. return 0;
  1938. return intel_connector_update_modes(connector,
  1939. intel_connector->edid);
  1940. }
  1941. return intel_ddc_get_modes(connector, adapter);
  1942. }
  1943. /**
  1944. * Uses CRT_HOTPLUG_EN and CRT_HOTPLUG_STAT to detect DP connection.
  1945. *
  1946. * \return true if DP port is connected.
  1947. * \return false if DP port is disconnected.
  1948. */
  1949. static enum drm_connector_status
  1950. intel_dp_detect(struct drm_connector *connector, bool force)
  1951. {
  1952. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1953. struct drm_device *dev = intel_dp->base.base.dev;
  1954. enum drm_connector_status status;
  1955. struct edid *edid = NULL;
  1956. intel_dp->has_audio = false;
  1957. if (HAS_PCH_SPLIT(dev))
  1958. status = ironlake_dp_detect(intel_dp);
  1959. else
  1960. status = g4x_dp_detect(intel_dp);
  1961. DRM_DEBUG_KMS("DPCD: %02hx%02hx%02hx%02hx%02hx%02hx%02hx%02hx\n",
  1962. intel_dp->dpcd[0], intel_dp->dpcd[1], intel_dp->dpcd[2],
  1963. intel_dp->dpcd[3], intel_dp->dpcd[4], intel_dp->dpcd[5],
  1964. intel_dp->dpcd[6], intel_dp->dpcd[7]);
  1965. if (status != connector_status_connected)
  1966. return status;
  1967. intel_dp_probe_oui(intel_dp);
  1968. if (intel_dp->force_audio != HDMI_AUDIO_AUTO) {
  1969. intel_dp->has_audio = (intel_dp->force_audio == HDMI_AUDIO_ON);
  1970. } else {
  1971. edid = intel_dp_get_edid(connector, &intel_dp->adapter);
  1972. if (edid) {
  1973. intel_dp->has_audio = drm_detect_monitor_audio(edid);
  1974. kfree(edid);
  1975. }
  1976. }
  1977. return connector_status_connected;
  1978. }
  1979. static int intel_dp_get_modes(struct drm_connector *connector)
  1980. {
  1981. struct intel_dp *intel_dp = intel_attached_dp(connector);
  1982. struct intel_connector *intel_connector = to_intel_connector(connector);
  1983. struct drm_device *dev = intel_dp->base.base.dev;
  1984. int ret;
  1985. /* We should parse the EDID data and find out if it has an audio sink
  1986. */
  1987. ret = intel_dp_get_edid_modes(connector, &intel_dp->adapter);
  1988. if (ret)
  1989. return ret;
  1990. /* if eDP has no EDID, fall back to fixed mode */
  1991. if (is_edp(intel_dp) && intel_connector->panel.fixed_mode) {
  1992. struct drm_display_mode *mode;
  1993. mode = drm_mode_duplicate(dev,
  1994. intel_connector->panel.fixed_mode);
  1995. if (mode) {
  1996. drm_mode_probed_add(connector, mode);
  1997. return 1;
  1998. }
  1999. }
  2000. return 0;
  2001. }
  2002. static bool
  2003. intel_dp_detect_audio(struct drm_connector *connector)
  2004. {
  2005. struct intel_dp *intel_dp = intel_attached_dp(connector);
  2006. struct edid *edid;
  2007. bool has_audio = false;
  2008. edid = intel_dp_get_edid(connector, &intel_dp->adapter);
  2009. if (edid) {
  2010. has_audio = drm_detect_monitor_audio(edid);
  2011. kfree(edid);
  2012. }
  2013. return has_audio;
  2014. }
  2015. static int
  2016. intel_dp_set_property(struct drm_connector *connector,
  2017. struct drm_property *property,
  2018. uint64_t val)
  2019. {
  2020. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  2021. struct intel_dp *intel_dp = intel_attached_dp(connector);
  2022. int ret;
  2023. ret = drm_connector_property_set_value(connector, property, val);
  2024. if (ret)
  2025. return ret;
  2026. if (property == dev_priv->force_audio_property) {
  2027. int i = val;
  2028. bool has_audio;
  2029. if (i == intel_dp->force_audio)
  2030. return 0;
  2031. intel_dp->force_audio = i;
  2032. if (i == HDMI_AUDIO_AUTO)
  2033. has_audio = intel_dp_detect_audio(connector);
  2034. else
  2035. has_audio = (i == HDMI_AUDIO_ON);
  2036. if (has_audio == intel_dp->has_audio)
  2037. return 0;
  2038. intel_dp->has_audio = has_audio;
  2039. goto done;
  2040. }
  2041. if (property == dev_priv->broadcast_rgb_property) {
  2042. if (val == !!intel_dp->color_range)
  2043. return 0;
  2044. intel_dp->color_range = val ? DP_COLOR_RANGE_16_235 : 0;
  2045. goto done;
  2046. }
  2047. return -EINVAL;
  2048. done:
  2049. if (intel_dp->base.base.crtc) {
  2050. struct drm_crtc *crtc = intel_dp->base.base.crtc;
  2051. intel_set_mode(crtc, &crtc->mode,
  2052. crtc->x, crtc->y, crtc->fb);
  2053. }
  2054. return 0;
  2055. }
  2056. static void
  2057. intel_dp_destroy(struct drm_connector *connector)
  2058. {
  2059. struct drm_device *dev = connector->dev;
  2060. struct intel_dp *intel_dp = intel_attached_dp(connector);
  2061. struct intel_connector *intel_connector = to_intel_connector(connector);
  2062. if (!IS_ERR_OR_NULL(intel_connector->edid))
  2063. kfree(intel_connector->edid);
  2064. if (is_edp(intel_dp)) {
  2065. intel_panel_destroy_backlight(dev);
  2066. intel_panel_fini(&intel_connector->panel);
  2067. }
  2068. drm_sysfs_connector_remove(connector);
  2069. drm_connector_cleanup(connector);
  2070. kfree(connector);
  2071. }
  2072. static void intel_dp_encoder_destroy(struct drm_encoder *encoder)
  2073. {
  2074. struct intel_dp *intel_dp = enc_to_intel_dp(encoder);
  2075. i2c_del_adapter(&intel_dp->adapter);
  2076. drm_encoder_cleanup(encoder);
  2077. if (is_edp(intel_dp)) {
  2078. cancel_delayed_work_sync(&intel_dp->panel_vdd_work);
  2079. ironlake_panel_vdd_off_sync(intel_dp);
  2080. }
  2081. kfree(intel_dp);
  2082. }
  2083. static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = {
  2084. .mode_fixup = intel_dp_mode_fixup,
  2085. .mode_set = intel_dp_mode_set,
  2086. .disable = intel_encoder_noop,
  2087. };
  2088. static const struct drm_encoder_helper_funcs intel_dp_helper_funcs_hsw = {
  2089. .mode_fixup = intel_dp_mode_fixup,
  2090. .mode_set = intel_ddi_mode_set,
  2091. .disable = intel_encoder_noop,
  2092. };
  2093. static const struct drm_connector_funcs intel_dp_connector_funcs = {
  2094. .dpms = intel_connector_dpms,
  2095. .detect = intel_dp_detect,
  2096. .fill_modes = drm_helper_probe_single_connector_modes,
  2097. .set_property = intel_dp_set_property,
  2098. .destroy = intel_dp_destroy,
  2099. };
  2100. static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = {
  2101. .get_modes = intel_dp_get_modes,
  2102. .mode_valid = intel_dp_mode_valid,
  2103. .best_encoder = intel_best_encoder,
  2104. };
  2105. static const struct drm_encoder_funcs intel_dp_enc_funcs = {
  2106. .destroy = intel_dp_encoder_destroy,
  2107. };
  2108. static void
  2109. intel_dp_hot_plug(struct intel_encoder *intel_encoder)
  2110. {
  2111. struct intel_dp *intel_dp = container_of(intel_encoder, struct intel_dp, base);
  2112. intel_dp_check_link_status(intel_dp);
  2113. }
  2114. /* Return which DP Port should be selected for Transcoder DP control */
  2115. int
  2116. intel_trans_dp_port_sel(struct drm_crtc *crtc)
  2117. {
  2118. struct drm_device *dev = crtc->dev;
  2119. struct intel_encoder *encoder;
  2120. for_each_encoder_on_crtc(dev, crtc, encoder) {
  2121. struct intel_dp *intel_dp = enc_to_intel_dp(&encoder->base);
  2122. if (intel_dp->base.type == INTEL_OUTPUT_DISPLAYPORT ||
  2123. intel_dp->base.type == INTEL_OUTPUT_EDP)
  2124. return intel_dp->output_reg;
  2125. }
  2126. return -1;
  2127. }
  2128. /* check the VBT to see whether the eDP is on DP-D port */
  2129. bool intel_dpd_is_edp(struct drm_device *dev)
  2130. {
  2131. struct drm_i915_private *dev_priv = dev->dev_private;
  2132. struct child_device_config *p_child;
  2133. int i;
  2134. if (!dev_priv->child_dev_num)
  2135. return false;
  2136. for (i = 0; i < dev_priv->child_dev_num; i++) {
  2137. p_child = dev_priv->child_dev + i;
  2138. if (p_child->dvo_port == PORT_IDPD &&
  2139. p_child->device_type == DEVICE_TYPE_eDP)
  2140. return true;
  2141. }
  2142. return false;
  2143. }
  2144. static void
  2145. intel_dp_add_properties(struct intel_dp *intel_dp, struct drm_connector *connector)
  2146. {
  2147. intel_attach_force_audio_property(connector);
  2148. intel_attach_broadcast_rgb_property(connector);
  2149. }
  2150. static void
  2151. intel_dp_init_panel_power_sequencer(struct drm_device *dev,
  2152. struct intel_dp *intel_dp)
  2153. {
  2154. struct drm_i915_private *dev_priv = dev->dev_private;
  2155. struct edp_power_seq cur, vbt, spec, final;
  2156. u32 pp_on, pp_off, pp_div, pp;
  2157. /* Workaround: Need to write PP_CONTROL with the unlock key as
  2158. * the very first thing. */
  2159. pp = ironlake_get_pp_control(dev_priv);
  2160. I915_WRITE(PCH_PP_CONTROL, pp);
  2161. pp_on = I915_READ(PCH_PP_ON_DELAYS);
  2162. pp_off = I915_READ(PCH_PP_OFF_DELAYS);
  2163. pp_div = I915_READ(PCH_PP_DIVISOR);
  2164. /* Pull timing values out of registers */
  2165. cur.t1_t3 = (pp_on & PANEL_POWER_UP_DELAY_MASK) >>
  2166. PANEL_POWER_UP_DELAY_SHIFT;
  2167. cur.t8 = (pp_on & PANEL_LIGHT_ON_DELAY_MASK) >>
  2168. PANEL_LIGHT_ON_DELAY_SHIFT;
  2169. cur.t9 = (pp_off & PANEL_LIGHT_OFF_DELAY_MASK) >>
  2170. PANEL_LIGHT_OFF_DELAY_SHIFT;
  2171. cur.t10 = (pp_off & PANEL_POWER_DOWN_DELAY_MASK) >>
  2172. PANEL_POWER_DOWN_DELAY_SHIFT;
  2173. cur.t11_t12 = ((pp_div & PANEL_POWER_CYCLE_DELAY_MASK) >>
  2174. PANEL_POWER_CYCLE_DELAY_SHIFT) * 1000;
  2175. DRM_DEBUG_KMS("cur t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  2176. cur.t1_t3, cur.t8, cur.t9, cur.t10, cur.t11_t12);
  2177. vbt = dev_priv->edp.pps;
  2178. /* Upper limits from eDP 1.3 spec. Note that we use the clunky units of
  2179. * our hw here, which are all in 100usec. */
  2180. spec.t1_t3 = 210 * 10;
  2181. spec.t8 = 50 * 10; /* no limit for t8, use t7 instead */
  2182. spec.t9 = 50 * 10; /* no limit for t9, make it symmetric with t8 */
  2183. spec.t10 = 500 * 10;
  2184. /* This one is special and actually in units of 100ms, but zero
  2185. * based in the hw (so we need to add 100 ms). But the sw vbt
  2186. * table multiplies it with 1000 to make it in units of 100usec,
  2187. * too. */
  2188. spec.t11_t12 = (510 + 100) * 10;
  2189. DRM_DEBUG_KMS("vbt t1_t3 %d t8 %d t9 %d t10 %d t11_t12 %d\n",
  2190. vbt.t1_t3, vbt.t8, vbt.t9, vbt.t10, vbt.t11_t12);
  2191. /* Use the max of the register settings and vbt. If both are
  2192. * unset, fall back to the spec limits. */
  2193. #define assign_final(field) final.field = (max(cur.field, vbt.field) == 0 ? \
  2194. spec.field : \
  2195. max(cur.field, vbt.field))
  2196. assign_final(t1_t3);
  2197. assign_final(t8);
  2198. assign_final(t9);
  2199. assign_final(t10);
  2200. assign_final(t11_t12);
  2201. #undef assign_final
  2202. #define get_delay(field) (DIV_ROUND_UP(final.field, 10))
  2203. intel_dp->panel_power_up_delay = get_delay(t1_t3);
  2204. intel_dp->backlight_on_delay = get_delay(t8);
  2205. intel_dp->backlight_off_delay = get_delay(t9);
  2206. intel_dp->panel_power_down_delay = get_delay(t10);
  2207. intel_dp->panel_power_cycle_delay = get_delay(t11_t12);
  2208. #undef get_delay
  2209. /* And finally store the new values in the power sequencer. */
  2210. pp_on = (final.t1_t3 << PANEL_POWER_UP_DELAY_SHIFT) |
  2211. (final.t8 << PANEL_LIGHT_ON_DELAY_SHIFT);
  2212. pp_off = (final.t9 << PANEL_LIGHT_OFF_DELAY_SHIFT) |
  2213. (final.t10 << PANEL_POWER_DOWN_DELAY_SHIFT);
  2214. /* Compute the divisor for the pp clock, simply match the Bspec
  2215. * formula. */
  2216. pp_div = ((100 * intel_pch_rawclk(dev))/2 - 1)
  2217. << PP_REFERENCE_DIVIDER_SHIFT;
  2218. pp_div |= (DIV_ROUND_UP(final.t11_t12, 1000)
  2219. << PANEL_POWER_CYCLE_DELAY_SHIFT);
  2220. /* Haswell doesn't have any port selection bits for the panel
  2221. * power sequencer any more. */
  2222. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) {
  2223. if (is_cpu_edp(intel_dp))
  2224. pp_on |= PANEL_POWER_PORT_DP_A;
  2225. else
  2226. pp_on |= PANEL_POWER_PORT_DP_D;
  2227. }
  2228. I915_WRITE(PCH_PP_ON_DELAYS, pp_on);
  2229. I915_WRITE(PCH_PP_OFF_DELAYS, pp_off);
  2230. I915_WRITE(PCH_PP_DIVISOR, pp_div);
  2231. DRM_DEBUG_KMS("panel power up delay %d, power down delay %d, power cycle delay %d\n",
  2232. intel_dp->panel_power_up_delay, intel_dp->panel_power_down_delay,
  2233. intel_dp->panel_power_cycle_delay);
  2234. DRM_DEBUG_KMS("backlight on delay %d, off delay %d\n",
  2235. intel_dp->backlight_on_delay, intel_dp->backlight_off_delay);
  2236. DRM_DEBUG_KMS("panel power sequencer register settings: PP_ON %#x, PP_OFF %#x, PP_DIV %#x\n",
  2237. I915_READ(PCH_PP_ON_DELAYS),
  2238. I915_READ(PCH_PP_OFF_DELAYS),
  2239. I915_READ(PCH_PP_DIVISOR));
  2240. }
  2241. void
  2242. intel_dp_init(struct drm_device *dev, int output_reg, enum port port)
  2243. {
  2244. struct drm_i915_private *dev_priv = dev->dev_private;
  2245. struct drm_connector *connector;
  2246. struct intel_dp *intel_dp;
  2247. struct intel_encoder *intel_encoder;
  2248. struct intel_connector *intel_connector;
  2249. struct drm_display_mode *fixed_mode = NULL;
  2250. const char *name = NULL;
  2251. int type;
  2252. intel_dp = kzalloc(sizeof(struct intel_dp), GFP_KERNEL);
  2253. if (!intel_dp)
  2254. return;
  2255. intel_dp->output_reg = output_reg;
  2256. intel_dp->port = port;
  2257. /* Preserve the current hw state. */
  2258. intel_dp->DP = I915_READ(intel_dp->output_reg);
  2259. intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
  2260. if (!intel_connector) {
  2261. kfree(intel_dp);
  2262. return;
  2263. }
  2264. intel_encoder = &intel_dp->base;
  2265. intel_dp->attached_connector = intel_connector;
  2266. if (HAS_PCH_SPLIT(dev) && output_reg == PCH_DP_D)
  2267. if (intel_dpd_is_edp(dev))
  2268. intel_dp->is_pch_edp = true;
  2269. /*
  2270. * FIXME : We need to initialize built-in panels before external panels.
  2271. * For X0, DP_C is fixed as eDP. Revisit this as part of VLV eDP cleanup
  2272. */
  2273. if (IS_VALLEYVIEW(dev) && output_reg == DP_C) {
  2274. type = DRM_MODE_CONNECTOR_eDP;
  2275. intel_encoder->type = INTEL_OUTPUT_EDP;
  2276. } else if (output_reg == DP_A || is_pch_edp(intel_dp)) {
  2277. type = DRM_MODE_CONNECTOR_eDP;
  2278. intel_encoder->type = INTEL_OUTPUT_EDP;
  2279. } else {
  2280. type = DRM_MODE_CONNECTOR_DisplayPort;
  2281. intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT;
  2282. }
  2283. connector = &intel_connector->base;
  2284. drm_connector_init(dev, connector, &intel_dp_connector_funcs, type);
  2285. drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs);
  2286. connector->polled = DRM_CONNECTOR_POLL_HPD;
  2287. intel_encoder->cloneable = false;
  2288. INIT_DELAYED_WORK(&intel_dp->panel_vdd_work,
  2289. ironlake_panel_vdd_work);
  2290. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  2291. connector->interlace_allowed = true;
  2292. connector->doublescan_allowed = 0;
  2293. drm_encoder_init(dev, &intel_encoder->base, &intel_dp_enc_funcs,
  2294. DRM_MODE_ENCODER_TMDS);
  2295. if (IS_HASWELL(dev))
  2296. drm_encoder_helper_add(&intel_encoder->base,
  2297. &intel_dp_helper_funcs_hsw);
  2298. else
  2299. drm_encoder_helper_add(&intel_encoder->base,
  2300. &intel_dp_helper_funcs);
  2301. intel_connector_attach_encoder(intel_connector, intel_encoder);
  2302. drm_sysfs_connector_add(connector);
  2303. if (IS_HASWELL(dev)) {
  2304. intel_encoder->enable = intel_enable_ddi;
  2305. intel_encoder->pre_enable = intel_ddi_pre_enable;
  2306. intel_encoder->disable = intel_disable_ddi;
  2307. intel_encoder->post_disable = intel_ddi_post_disable;
  2308. intel_encoder->get_hw_state = intel_ddi_get_hw_state;
  2309. } else {
  2310. intel_encoder->enable = intel_enable_dp;
  2311. intel_encoder->pre_enable = intel_pre_enable_dp;
  2312. intel_encoder->disable = intel_disable_dp;
  2313. intel_encoder->post_disable = intel_post_disable_dp;
  2314. intel_encoder->get_hw_state = intel_dp_get_hw_state;
  2315. }
  2316. intel_connector->get_hw_state = intel_connector_get_hw_state;
  2317. /* Set up the DDC bus. */
  2318. switch (port) {
  2319. case PORT_A:
  2320. name = "DPDDC-A";
  2321. break;
  2322. case PORT_B:
  2323. dev_priv->hotplug_supported_mask |= DPB_HOTPLUG_INT_STATUS;
  2324. name = "DPDDC-B";
  2325. break;
  2326. case PORT_C:
  2327. dev_priv->hotplug_supported_mask |= DPC_HOTPLUG_INT_STATUS;
  2328. name = "DPDDC-C";
  2329. break;
  2330. case PORT_D:
  2331. dev_priv->hotplug_supported_mask |= DPD_HOTPLUG_INT_STATUS;
  2332. name = "DPDDC-D";
  2333. break;
  2334. default:
  2335. WARN(1, "Invalid port %c\n", port_name(port));
  2336. break;
  2337. }
  2338. if (is_edp(intel_dp))
  2339. intel_dp_init_panel_power_sequencer(dev, intel_dp);
  2340. intel_dp_i2c_init(intel_dp, intel_connector, name);
  2341. /* Cache DPCD and EDID for edp. */
  2342. if (is_edp(intel_dp)) {
  2343. bool ret;
  2344. struct drm_display_mode *scan;
  2345. struct edid *edid;
  2346. ironlake_edp_panel_vdd_on(intel_dp);
  2347. ret = intel_dp_get_dpcd(intel_dp);
  2348. ironlake_edp_panel_vdd_off(intel_dp, false);
  2349. if (ret) {
  2350. if (intel_dp->dpcd[DP_DPCD_REV] >= 0x11)
  2351. dev_priv->no_aux_handshake =
  2352. intel_dp->dpcd[DP_MAX_DOWNSPREAD] &
  2353. DP_NO_AUX_HANDSHAKE_LINK_TRAINING;
  2354. } else {
  2355. /* if this fails, presume the device is a ghost */
  2356. DRM_INFO("failed to retrieve link info, disabling eDP\n");
  2357. intel_dp_encoder_destroy(&intel_dp->base.base);
  2358. intel_dp_destroy(&intel_connector->base);
  2359. return;
  2360. }
  2361. ironlake_edp_panel_vdd_on(intel_dp);
  2362. edid = drm_get_edid(connector, &intel_dp->adapter);
  2363. if (edid) {
  2364. if (drm_add_edid_modes(connector, edid)) {
  2365. drm_mode_connector_update_edid_property(connector, edid);
  2366. drm_edid_to_eld(connector, edid);
  2367. } else {
  2368. kfree(edid);
  2369. edid = ERR_PTR(-EINVAL);
  2370. }
  2371. } else {
  2372. edid = ERR_PTR(-ENOENT);
  2373. }
  2374. intel_connector->edid = edid;
  2375. /* prefer fixed mode from EDID if available */
  2376. list_for_each_entry(scan, &connector->probed_modes, head) {
  2377. if ((scan->type & DRM_MODE_TYPE_PREFERRED)) {
  2378. fixed_mode = drm_mode_duplicate(dev, scan);
  2379. break;
  2380. }
  2381. }
  2382. /* fallback to VBT if available for eDP */
  2383. if (!fixed_mode && dev_priv->lfp_lvds_vbt_mode) {
  2384. fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  2385. if (fixed_mode)
  2386. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  2387. }
  2388. ironlake_edp_panel_vdd_off(intel_dp, false);
  2389. }
  2390. intel_encoder->hot_plug = intel_dp_hot_plug;
  2391. if (is_edp(intel_dp)) {
  2392. intel_panel_init(&intel_connector->panel, fixed_mode);
  2393. intel_panel_setup_backlight(connector);
  2394. }
  2395. intel_dp_add_properties(intel_dp, connector);
  2396. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  2397. * 0xd. Failure to do so will result in spurious interrupts being
  2398. * generated on the port when a cable is not attached.
  2399. */
  2400. if (IS_G4X(dev) && !IS_GM45(dev)) {
  2401. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  2402. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  2403. }
  2404. }