intel_dp.c 63 KB

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