intel_dp.c 77 KB

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