intel_dp.c 80 KB

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