intel_dp.c 64 KB

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