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