intel_dp.c 89 KB

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