intel_dp.c 82 KB

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