intel_dp.c 75 KB

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