intel_dp.c 77 KB

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