intel_dp.c 89 KB

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