intel_dp.c 90 KB

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