intel_dp.c 82 KB

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