intel_dp.c 77 KB

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