intel_dp.c 88 KB

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