intel_dp.c 63 KB

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