intel_dp.c 62 KB

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