intel_hdmi.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149
  1. /*
  2. * Copyright 2006 Dave Airlie <airlied@linux.ie>
  3. * Copyright © 2006-2009 Intel Corporation
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors:
  25. * Eric Anholt <eric@anholt.net>
  26. * Jesse Barnes <jesse.barnes@intel.com>
  27. */
  28. #include <linux/i2c.h>
  29. #include <linux/slab.h>
  30. #include <linux/delay.h>
  31. #include <linux/hdmi.h>
  32. #include <drm/drmP.h>
  33. #include <drm/drm_atomic_helper.h>
  34. #include <drm/drm_crtc.h>
  35. #include <drm/drm_edid.h>
  36. #include <drm/drm_scdc_helper.h>
  37. #include "intel_drv.h"
  38. #include <drm/i915_drm.h>
  39. #include <drm/intel_lpe_audio.h>
  40. #include "i915_drv.h"
  41. static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
  42. {
  43. return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
  44. }
  45. static void
  46. assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
  47. {
  48. struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
  49. struct drm_i915_private *dev_priv = to_i915(dev);
  50. uint32_t enabled_bits;
  51. enabled_bits = HAS_DDI(dev_priv) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
  52. WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
  53. "HDMI port enabled, expecting disabled\n");
  54. }
  55. struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
  56. {
  57. struct intel_digital_port *intel_dig_port =
  58. container_of(encoder, struct intel_digital_port, base.base);
  59. return &intel_dig_port->hdmi;
  60. }
  61. static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
  62. {
  63. return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
  64. }
  65. static u32 g4x_infoframe_index(unsigned int type)
  66. {
  67. switch (type) {
  68. case HDMI_INFOFRAME_TYPE_AVI:
  69. return VIDEO_DIP_SELECT_AVI;
  70. case HDMI_INFOFRAME_TYPE_SPD:
  71. return VIDEO_DIP_SELECT_SPD;
  72. case HDMI_INFOFRAME_TYPE_VENDOR:
  73. return VIDEO_DIP_SELECT_VENDOR;
  74. default:
  75. MISSING_CASE(type);
  76. return 0;
  77. }
  78. }
  79. static u32 g4x_infoframe_enable(unsigned int type)
  80. {
  81. switch (type) {
  82. case HDMI_INFOFRAME_TYPE_AVI:
  83. return VIDEO_DIP_ENABLE_AVI;
  84. case HDMI_INFOFRAME_TYPE_SPD:
  85. return VIDEO_DIP_ENABLE_SPD;
  86. case HDMI_INFOFRAME_TYPE_VENDOR:
  87. return VIDEO_DIP_ENABLE_VENDOR;
  88. default:
  89. MISSING_CASE(type);
  90. return 0;
  91. }
  92. }
  93. static u32 hsw_infoframe_enable(unsigned int type)
  94. {
  95. switch (type) {
  96. case DP_SDP_VSC:
  97. return VIDEO_DIP_ENABLE_VSC_HSW;
  98. case HDMI_INFOFRAME_TYPE_AVI:
  99. return VIDEO_DIP_ENABLE_AVI_HSW;
  100. case HDMI_INFOFRAME_TYPE_SPD:
  101. return VIDEO_DIP_ENABLE_SPD_HSW;
  102. case HDMI_INFOFRAME_TYPE_VENDOR:
  103. return VIDEO_DIP_ENABLE_VS_HSW;
  104. default:
  105. MISSING_CASE(type);
  106. return 0;
  107. }
  108. }
  109. static i915_reg_t
  110. hsw_dip_data_reg(struct drm_i915_private *dev_priv,
  111. enum transcoder cpu_transcoder,
  112. unsigned int type,
  113. int i)
  114. {
  115. switch (type) {
  116. case DP_SDP_VSC:
  117. return HSW_TVIDEO_DIP_VSC_DATA(cpu_transcoder, i);
  118. case HDMI_INFOFRAME_TYPE_AVI:
  119. return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
  120. case HDMI_INFOFRAME_TYPE_SPD:
  121. return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
  122. case HDMI_INFOFRAME_TYPE_VENDOR:
  123. return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
  124. default:
  125. MISSING_CASE(type);
  126. return INVALID_MMIO_REG;
  127. }
  128. }
  129. static void g4x_write_infoframe(struct drm_encoder *encoder,
  130. const struct intel_crtc_state *crtc_state,
  131. unsigned int type,
  132. const void *frame, ssize_t len)
  133. {
  134. const uint32_t *data = frame;
  135. struct drm_device *dev = encoder->dev;
  136. struct drm_i915_private *dev_priv = to_i915(dev);
  137. u32 val = I915_READ(VIDEO_DIP_CTL);
  138. int i;
  139. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  140. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  141. val |= g4x_infoframe_index(type);
  142. val &= ~g4x_infoframe_enable(type);
  143. I915_WRITE(VIDEO_DIP_CTL, val);
  144. mmiowb();
  145. for (i = 0; i < len; i += 4) {
  146. I915_WRITE(VIDEO_DIP_DATA, *data);
  147. data++;
  148. }
  149. /* Write every possible data byte to force correct ECC calculation. */
  150. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  151. I915_WRITE(VIDEO_DIP_DATA, 0);
  152. mmiowb();
  153. val |= g4x_infoframe_enable(type);
  154. val &= ~VIDEO_DIP_FREQ_MASK;
  155. val |= VIDEO_DIP_FREQ_VSYNC;
  156. I915_WRITE(VIDEO_DIP_CTL, val);
  157. POSTING_READ(VIDEO_DIP_CTL);
  158. }
  159. static bool g4x_infoframe_enabled(struct drm_encoder *encoder,
  160. const struct intel_crtc_state *pipe_config)
  161. {
  162. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  163. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  164. u32 val = I915_READ(VIDEO_DIP_CTL);
  165. if ((val & VIDEO_DIP_ENABLE) == 0)
  166. return false;
  167. if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->base.port))
  168. return false;
  169. return val & (VIDEO_DIP_ENABLE_AVI |
  170. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
  171. }
  172. static void ibx_write_infoframe(struct drm_encoder *encoder,
  173. const struct intel_crtc_state *crtc_state,
  174. unsigned int type,
  175. const void *frame, ssize_t len)
  176. {
  177. const uint32_t *data = frame;
  178. struct drm_device *dev = encoder->dev;
  179. struct drm_i915_private *dev_priv = to_i915(dev);
  180. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  181. i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  182. u32 val = I915_READ(reg);
  183. int i;
  184. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  185. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  186. val |= g4x_infoframe_index(type);
  187. val &= ~g4x_infoframe_enable(type);
  188. I915_WRITE(reg, val);
  189. mmiowb();
  190. for (i = 0; i < len; i += 4) {
  191. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  192. data++;
  193. }
  194. /* Write every possible data byte to force correct ECC calculation. */
  195. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  196. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  197. mmiowb();
  198. val |= g4x_infoframe_enable(type);
  199. val &= ~VIDEO_DIP_FREQ_MASK;
  200. val |= VIDEO_DIP_FREQ_VSYNC;
  201. I915_WRITE(reg, val);
  202. POSTING_READ(reg);
  203. }
  204. static bool ibx_infoframe_enabled(struct drm_encoder *encoder,
  205. const struct intel_crtc_state *pipe_config)
  206. {
  207. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  208. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  209. enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
  210. i915_reg_t reg = TVIDEO_DIP_CTL(pipe);
  211. u32 val = I915_READ(reg);
  212. if ((val & VIDEO_DIP_ENABLE) == 0)
  213. return false;
  214. if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->base.port))
  215. return false;
  216. return val & (VIDEO_DIP_ENABLE_AVI |
  217. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  218. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  219. }
  220. static void cpt_write_infoframe(struct drm_encoder *encoder,
  221. const struct intel_crtc_state *crtc_state,
  222. unsigned int type,
  223. const void *frame, ssize_t len)
  224. {
  225. const uint32_t *data = frame;
  226. struct drm_device *dev = encoder->dev;
  227. struct drm_i915_private *dev_priv = to_i915(dev);
  228. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  229. i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  230. u32 val = I915_READ(reg);
  231. int i;
  232. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  233. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  234. val |= g4x_infoframe_index(type);
  235. /* The DIP control register spec says that we need to update the AVI
  236. * infoframe without clearing its enable bit */
  237. if (type != HDMI_INFOFRAME_TYPE_AVI)
  238. val &= ~g4x_infoframe_enable(type);
  239. I915_WRITE(reg, val);
  240. mmiowb();
  241. for (i = 0; i < len; i += 4) {
  242. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  243. data++;
  244. }
  245. /* Write every possible data byte to force correct ECC calculation. */
  246. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  247. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  248. mmiowb();
  249. val |= g4x_infoframe_enable(type);
  250. val &= ~VIDEO_DIP_FREQ_MASK;
  251. val |= VIDEO_DIP_FREQ_VSYNC;
  252. I915_WRITE(reg, val);
  253. POSTING_READ(reg);
  254. }
  255. static bool cpt_infoframe_enabled(struct drm_encoder *encoder,
  256. const struct intel_crtc_state *pipe_config)
  257. {
  258. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  259. enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
  260. u32 val = I915_READ(TVIDEO_DIP_CTL(pipe));
  261. if ((val & VIDEO_DIP_ENABLE) == 0)
  262. return false;
  263. return val & (VIDEO_DIP_ENABLE_AVI |
  264. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  265. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  266. }
  267. static void vlv_write_infoframe(struct drm_encoder *encoder,
  268. const struct intel_crtc_state *crtc_state,
  269. unsigned int type,
  270. const void *frame, ssize_t len)
  271. {
  272. const uint32_t *data = frame;
  273. struct drm_device *dev = encoder->dev;
  274. struct drm_i915_private *dev_priv = to_i915(dev);
  275. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  276. i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
  277. u32 val = I915_READ(reg);
  278. int i;
  279. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  280. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  281. val |= g4x_infoframe_index(type);
  282. val &= ~g4x_infoframe_enable(type);
  283. I915_WRITE(reg, val);
  284. mmiowb();
  285. for (i = 0; i < len; i += 4) {
  286. I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  287. data++;
  288. }
  289. /* Write every possible data byte to force correct ECC calculation. */
  290. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  291. I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  292. mmiowb();
  293. val |= g4x_infoframe_enable(type);
  294. val &= ~VIDEO_DIP_FREQ_MASK;
  295. val |= VIDEO_DIP_FREQ_VSYNC;
  296. I915_WRITE(reg, val);
  297. POSTING_READ(reg);
  298. }
  299. static bool vlv_infoframe_enabled(struct drm_encoder *encoder,
  300. const struct intel_crtc_state *pipe_config)
  301. {
  302. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  303. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  304. enum pipe pipe = to_intel_crtc(pipe_config->base.crtc)->pipe;
  305. u32 val = I915_READ(VLV_TVIDEO_DIP_CTL(pipe));
  306. if ((val & VIDEO_DIP_ENABLE) == 0)
  307. return false;
  308. if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->base.port))
  309. return false;
  310. return val & (VIDEO_DIP_ENABLE_AVI |
  311. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  312. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  313. }
  314. static void hsw_write_infoframe(struct drm_encoder *encoder,
  315. const struct intel_crtc_state *crtc_state,
  316. unsigned int type,
  317. const void *frame, ssize_t len)
  318. {
  319. const uint32_t *data = frame;
  320. struct drm_device *dev = encoder->dev;
  321. struct drm_i915_private *dev_priv = to_i915(dev);
  322. enum transcoder cpu_transcoder = crtc_state->cpu_transcoder;
  323. i915_reg_t ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
  324. i915_reg_t data_reg;
  325. int data_size = type == DP_SDP_VSC ?
  326. VIDEO_DIP_VSC_DATA_SIZE : VIDEO_DIP_DATA_SIZE;
  327. int i;
  328. u32 val = I915_READ(ctl_reg);
  329. data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
  330. val &= ~hsw_infoframe_enable(type);
  331. I915_WRITE(ctl_reg, val);
  332. mmiowb();
  333. for (i = 0; i < len; i += 4) {
  334. I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
  335. type, i >> 2), *data);
  336. data++;
  337. }
  338. /* Write every possible data byte to force correct ECC calculation. */
  339. for (; i < data_size; i += 4)
  340. I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
  341. type, i >> 2), 0);
  342. mmiowb();
  343. val |= hsw_infoframe_enable(type);
  344. I915_WRITE(ctl_reg, val);
  345. POSTING_READ(ctl_reg);
  346. }
  347. static bool hsw_infoframe_enabled(struct drm_encoder *encoder,
  348. const struct intel_crtc_state *pipe_config)
  349. {
  350. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  351. u32 val = I915_READ(HSW_TVIDEO_DIP_CTL(pipe_config->cpu_transcoder));
  352. return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
  353. VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
  354. VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
  355. }
  356. /*
  357. * The data we write to the DIP data buffer registers is 1 byte bigger than the
  358. * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
  359. * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
  360. * used for both technologies.
  361. *
  362. * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
  363. * DW1: DB3 | DB2 | DB1 | DB0
  364. * DW2: DB7 | DB6 | DB5 | DB4
  365. * DW3: ...
  366. *
  367. * (HB is Header Byte, DB is Data Byte)
  368. *
  369. * The hdmi pack() functions don't know about that hardware specific hole so we
  370. * trick them by giving an offset into the buffer and moving back the header
  371. * bytes by one.
  372. */
  373. static void intel_write_infoframe(struct drm_encoder *encoder,
  374. const struct intel_crtc_state *crtc_state,
  375. union hdmi_infoframe *frame)
  376. {
  377. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  378. uint8_t buffer[VIDEO_DIP_DATA_SIZE];
  379. ssize_t len;
  380. /* see comment above for the reason for this offset */
  381. len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
  382. if (len < 0)
  383. return;
  384. /* Insert the 'hole' (see big comment above) at position 3 */
  385. buffer[0] = buffer[1];
  386. buffer[1] = buffer[2];
  387. buffer[2] = buffer[3];
  388. buffer[3] = 0;
  389. len++;
  390. intel_dig_port->write_infoframe(encoder, crtc_state, frame->any.type, buffer, len);
  391. }
  392. static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
  393. const struct intel_crtc_state *crtc_state)
  394. {
  395. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  396. const struct drm_display_mode *adjusted_mode =
  397. &crtc_state->base.adjusted_mode;
  398. struct drm_connector *connector = &intel_hdmi->attached_connector->base;
  399. bool is_hdmi2_sink = connector->display_info.hdmi.scdc.supported;
  400. union hdmi_infoframe frame;
  401. int ret;
  402. ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
  403. adjusted_mode,
  404. is_hdmi2_sink);
  405. if (ret < 0) {
  406. DRM_ERROR("couldn't fill AVI infoframe\n");
  407. return;
  408. }
  409. if (crtc_state->ycbcr420)
  410. frame.avi.colorspace = HDMI_COLORSPACE_YUV420;
  411. else
  412. frame.avi.colorspace = HDMI_COLORSPACE_RGB;
  413. drm_hdmi_avi_infoframe_quant_range(&frame.avi, adjusted_mode,
  414. crtc_state->limited_color_range ?
  415. HDMI_QUANTIZATION_RANGE_LIMITED :
  416. HDMI_QUANTIZATION_RANGE_FULL,
  417. intel_hdmi->rgb_quant_range_selectable,
  418. is_hdmi2_sink);
  419. /* TODO: handle pixel repetition for YCBCR420 outputs */
  420. intel_write_infoframe(encoder, crtc_state, &frame);
  421. }
  422. static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder,
  423. const struct intel_crtc_state *crtc_state)
  424. {
  425. union hdmi_infoframe frame;
  426. int ret;
  427. ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
  428. if (ret < 0) {
  429. DRM_ERROR("couldn't fill SPD infoframe\n");
  430. return;
  431. }
  432. frame.spd.sdi = HDMI_SPD_SDI_PC;
  433. intel_write_infoframe(encoder, crtc_state, &frame);
  434. }
  435. static void
  436. intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
  437. const struct intel_crtc_state *crtc_state,
  438. const struct drm_connector_state *conn_state)
  439. {
  440. union hdmi_infoframe frame;
  441. int ret;
  442. ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
  443. conn_state->connector,
  444. &crtc_state->base.adjusted_mode);
  445. if (ret < 0)
  446. return;
  447. intel_write_infoframe(encoder, crtc_state, &frame);
  448. }
  449. static void g4x_set_infoframes(struct drm_encoder *encoder,
  450. bool enable,
  451. const struct intel_crtc_state *crtc_state,
  452. const struct drm_connector_state *conn_state)
  453. {
  454. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  455. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  456. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  457. i915_reg_t reg = VIDEO_DIP_CTL;
  458. u32 val = I915_READ(reg);
  459. u32 port = VIDEO_DIP_PORT(intel_dig_port->base.port);
  460. assert_hdmi_port_disabled(intel_hdmi);
  461. /* If the registers were not initialized yet, they might be zeroes,
  462. * which means we're selecting the AVI DIP and we're setting its
  463. * frequency to once. This seems to really confuse the HW and make
  464. * things stop working (the register spec says the AVI always needs to
  465. * be sent every VSync). So here we avoid writing to the register more
  466. * than we need and also explicitly select the AVI DIP and explicitly
  467. * set its frequency to every VSync. Avoiding to write it twice seems to
  468. * be enough to solve the problem, but being defensive shouldn't hurt us
  469. * either. */
  470. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  471. if (!enable) {
  472. if (!(val & VIDEO_DIP_ENABLE))
  473. return;
  474. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  475. DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
  476. (val & VIDEO_DIP_PORT_MASK) >> 29);
  477. return;
  478. }
  479. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  480. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
  481. I915_WRITE(reg, val);
  482. POSTING_READ(reg);
  483. return;
  484. }
  485. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  486. if (val & VIDEO_DIP_ENABLE) {
  487. DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
  488. (val & VIDEO_DIP_PORT_MASK) >> 29);
  489. return;
  490. }
  491. val &= ~VIDEO_DIP_PORT_MASK;
  492. val |= port;
  493. }
  494. val |= VIDEO_DIP_ENABLE;
  495. val &= ~(VIDEO_DIP_ENABLE_AVI |
  496. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
  497. I915_WRITE(reg, val);
  498. POSTING_READ(reg);
  499. intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  500. intel_hdmi_set_spd_infoframe(encoder, crtc_state);
  501. intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  502. }
  503. static bool hdmi_sink_is_deep_color(const struct drm_connector_state *conn_state)
  504. {
  505. struct drm_connector *connector = conn_state->connector;
  506. /*
  507. * HDMI cloning is only supported on g4x which doesn't
  508. * support deep color or GCP infoframes anyway so no
  509. * need to worry about multiple HDMI sinks here.
  510. */
  511. return connector->display_info.bpc > 8;
  512. }
  513. /*
  514. * Determine if default_phase=1 can be indicated in the GCP infoframe.
  515. *
  516. * From HDMI specification 1.4a:
  517. * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
  518. * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
  519. * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
  520. * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
  521. * phase of 0
  522. */
  523. static bool gcp_default_phase_possible(int pipe_bpp,
  524. const struct drm_display_mode *mode)
  525. {
  526. unsigned int pixels_per_group;
  527. switch (pipe_bpp) {
  528. case 30:
  529. /* 4 pixels in 5 clocks */
  530. pixels_per_group = 4;
  531. break;
  532. case 36:
  533. /* 2 pixels in 3 clocks */
  534. pixels_per_group = 2;
  535. break;
  536. case 48:
  537. /* 1 pixel in 2 clocks */
  538. pixels_per_group = 1;
  539. break;
  540. default:
  541. /* phase information not relevant for 8bpc */
  542. return false;
  543. }
  544. return mode->crtc_hdisplay % pixels_per_group == 0 &&
  545. mode->crtc_htotal % pixels_per_group == 0 &&
  546. mode->crtc_hblank_start % pixels_per_group == 0 &&
  547. mode->crtc_hblank_end % pixels_per_group == 0 &&
  548. mode->crtc_hsync_start % pixels_per_group == 0 &&
  549. mode->crtc_hsync_end % pixels_per_group == 0 &&
  550. ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
  551. mode->crtc_htotal/2 % pixels_per_group == 0);
  552. }
  553. static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder,
  554. const struct intel_crtc_state *crtc_state,
  555. const struct drm_connector_state *conn_state)
  556. {
  557. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  558. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  559. i915_reg_t reg;
  560. u32 val = 0;
  561. if (HAS_DDI(dev_priv))
  562. reg = HSW_TVIDEO_DIP_GCP(crtc_state->cpu_transcoder);
  563. else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
  564. reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
  565. else if (HAS_PCH_SPLIT(dev_priv))
  566. reg = TVIDEO_DIP_GCP(crtc->pipe);
  567. else
  568. return false;
  569. /* Indicate color depth whenever the sink supports deep color */
  570. if (hdmi_sink_is_deep_color(conn_state))
  571. val |= GCP_COLOR_INDICATION;
  572. /* Enable default_phase whenever the display mode is suitably aligned */
  573. if (gcp_default_phase_possible(crtc_state->pipe_bpp,
  574. &crtc_state->base.adjusted_mode))
  575. val |= GCP_DEFAULT_PHASE_ENABLE;
  576. I915_WRITE(reg, val);
  577. return val != 0;
  578. }
  579. static void ibx_set_infoframes(struct drm_encoder *encoder,
  580. bool enable,
  581. const struct intel_crtc_state *crtc_state,
  582. const struct drm_connector_state *conn_state)
  583. {
  584. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  585. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  586. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  587. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  588. i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  589. u32 val = I915_READ(reg);
  590. u32 port = VIDEO_DIP_PORT(intel_dig_port->base.port);
  591. assert_hdmi_port_disabled(intel_hdmi);
  592. /* See the big comment in g4x_set_infoframes() */
  593. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  594. if (!enable) {
  595. if (!(val & VIDEO_DIP_ENABLE))
  596. return;
  597. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  598. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  599. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  600. I915_WRITE(reg, val);
  601. POSTING_READ(reg);
  602. return;
  603. }
  604. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  605. WARN(val & VIDEO_DIP_ENABLE,
  606. "DIP already enabled on port %c\n",
  607. (val & VIDEO_DIP_PORT_MASK) >> 29);
  608. val &= ~VIDEO_DIP_PORT_MASK;
  609. val |= port;
  610. }
  611. val |= VIDEO_DIP_ENABLE;
  612. val &= ~(VIDEO_DIP_ENABLE_AVI |
  613. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  614. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  615. if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
  616. val |= VIDEO_DIP_ENABLE_GCP;
  617. I915_WRITE(reg, val);
  618. POSTING_READ(reg);
  619. intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  620. intel_hdmi_set_spd_infoframe(encoder, crtc_state);
  621. intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  622. }
  623. static void cpt_set_infoframes(struct drm_encoder *encoder,
  624. bool enable,
  625. const struct intel_crtc_state *crtc_state,
  626. const struct drm_connector_state *conn_state)
  627. {
  628. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  629. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  630. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  631. i915_reg_t reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  632. u32 val = I915_READ(reg);
  633. assert_hdmi_port_disabled(intel_hdmi);
  634. /* See the big comment in g4x_set_infoframes() */
  635. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  636. if (!enable) {
  637. if (!(val & VIDEO_DIP_ENABLE))
  638. return;
  639. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  640. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  641. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  642. I915_WRITE(reg, val);
  643. POSTING_READ(reg);
  644. return;
  645. }
  646. /* Set both together, unset both together: see the spec. */
  647. val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
  648. val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  649. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  650. if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
  651. val |= VIDEO_DIP_ENABLE_GCP;
  652. I915_WRITE(reg, val);
  653. POSTING_READ(reg);
  654. intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  655. intel_hdmi_set_spd_infoframe(encoder, crtc_state);
  656. intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  657. }
  658. static void vlv_set_infoframes(struct drm_encoder *encoder,
  659. bool enable,
  660. const struct intel_crtc_state *crtc_state,
  661. const struct drm_connector_state *conn_state)
  662. {
  663. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  664. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  665. struct intel_crtc *intel_crtc = to_intel_crtc(crtc_state->base.crtc);
  666. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  667. i915_reg_t reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
  668. u32 val = I915_READ(reg);
  669. u32 port = VIDEO_DIP_PORT(intel_dig_port->base.port);
  670. assert_hdmi_port_disabled(intel_hdmi);
  671. /* See the big comment in g4x_set_infoframes() */
  672. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  673. if (!enable) {
  674. if (!(val & VIDEO_DIP_ENABLE))
  675. return;
  676. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  677. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  678. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  679. I915_WRITE(reg, val);
  680. POSTING_READ(reg);
  681. return;
  682. }
  683. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  684. WARN(val & VIDEO_DIP_ENABLE,
  685. "DIP already enabled on port %c\n",
  686. (val & VIDEO_DIP_PORT_MASK) >> 29);
  687. val &= ~VIDEO_DIP_PORT_MASK;
  688. val |= port;
  689. }
  690. val |= VIDEO_DIP_ENABLE;
  691. val &= ~(VIDEO_DIP_ENABLE_AVI |
  692. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  693. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  694. if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
  695. val |= VIDEO_DIP_ENABLE_GCP;
  696. I915_WRITE(reg, val);
  697. POSTING_READ(reg);
  698. intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  699. intel_hdmi_set_spd_infoframe(encoder, crtc_state);
  700. intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  701. }
  702. static void hsw_set_infoframes(struct drm_encoder *encoder,
  703. bool enable,
  704. const struct intel_crtc_state *crtc_state,
  705. const struct drm_connector_state *conn_state)
  706. {
  707. struct drm_i915_private *dev_priv = to_i915(encoder->dev);
  708. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  709. i915_reg_t reg = HSW_TVIDEO_DIP_CTL(crtc_state->cpu_transcoder);
  710. u32 val = I915_READ(reg);
  711. assert_hdmi_port_disabled(intel_hdmi);
  712. val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
  713. VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
  714. VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
  715. if (!enable) {
  716. I915_WRITE(reg, val);
  717. POSTING_READ(reg);
  718. return;
  719. }
  720. if (intel_hdmi_set_gcp_infoframe(encoder, crtc_state, conn_state))
  721. val |= VIDEO_DIP_ENABLE_GCP_HSW;
  722. I915_WRITE(reg, val);
  723. POSTING_READ(reg);
  724. intel_hdmi_set_avi_infoframe(encoder, crtc_state);
  725. intel_hdmi_set_spd_infoframe(encoder, crtc_state);
  726. intel_hdmi_set_hdmi_infoframe(encoder, crtc_state, conn_state);
  727. }
  728. void intel_dp_dual_mode_set_tmds_output(struct intel_hdmi *hdmi, bool enable)
  729. {
  730. struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
  731. struct i2c_adapter *adapter =
  732. intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
  733. if (hdmi->dp_dual_mode.type < DRM_DP_DUAL_MODE_TYPE2_DVI)
  734. return;
  735. DRM_DEBUG_KMS("%s DP dual mode adaptor TMDS output\n",
  736. enable ? "Enabling" : "Disabling");
  737. drm_dp_dual_mode_set_tmds_output(hdmi->dp_dual_mode.type,
  738. adapter, enable);
  739. }
  740. static void intel_hdmi_prepare(struct intel_encoder *encoder,
  741. const struct intel_crtc_state *crtc_state)
  742. {
  743. struct drm_device *dev = encoder->base.dev;
  744. struct drm_i915_private *dev_priv = to_i915(dev);
  745. struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc);
  746. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  747. const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode;
  748. u32 hdmi_val;
  749. intel_dp_dual_mode_set_tmds_output(intel_hdmi, true);
  750. hdmi_val = SDVO_ENCODING_HDMI;
  751. if (!HAS_PCH_SPLIT(dev_priv) && crtc_state->limited_color_range)
  752. hdmi_val |= HDMI_COLOR_RANGE_16_235;
  753. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  754. hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
  755. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  756. hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
  757. if (crtc_state->pipe_bpp > 24)
  758. hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
  759. else
  760. hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
  761. if (crtc_state->has_hdmi_sink)
  762. hdmi_val |= HDMI_MODE_SELECT_HDMI;
  763. if (HAS_PCH_CPT(dev_priv))
  764. hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
  765. else if (IS_CHERRYVIEW(dev_priv))
  766. hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
  767. else
  768. hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
  769. I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
  770. POSTING_READ(intel_hdmi->hdmi_reg);
  771. }
  772. static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
  773. enum pipe *pipe)
  774. {
  775. struct drm_device *dev = encoder->base.dev;
  776. struct drm_i915_private *dev_priv = to_i915(dev);
  777. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  778. u32 tmp;
  779. bool ret;
  780. if (!intel_display_power_get_if_enabled(dev_priv,
  781. encoder->power_domain))
  782. return false;
  783. ret = false;
  784. tmp = I915_READ(intel_hdmi->hdmi_reg);
  785. if (!(tmp & SDVO_ENABLE))
  786. goto out;
  787. if (HAS_PCH_CPT(dev_priv))
  788. *pipe = PORT_TO_PIPE_CPT(tmp);
  789. else if (IS_CHERRYVIEW(dev_priv))
  790. *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
  791. else
  792. *pipe = PORT_TO_PIPE(tmp);
  793. ret = true;
  794. out:
  795. intel_display_power_put(dev_priv, encoder->power_domain);
  796. return ret;
  797. }
  798. static void intel_hdmi_get_config(struct intel_encoder *encoder,
  799. struct intel_crtc_state *pipe_config)
  800. {
  801. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  802. struct intel_digital_port *intel_dig_port = hdmi_to_dig_port(intel_hdmi);
  803. struct drm_device *dev = encoder->base.dev;
  804. struct drm_i915_private *dev_priv = to_i915(dev);
  805. u32 tmp, flags = 0;
  806. int dotclock;
  807. pipe_config->output_types |= BIT(INTEL_OUTPUT_HDMI);
  808. tmp = I915_READ(intel_hdmi->hdmi_reg);
  809. if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
  810. flags |= DRM_MODE_FLAG_PHSYNC;
  811. else
  812. flags |= DRM_MODE_FLAG_NHSYNC;
  813. if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
  814. flags |= DRM_MODE_FLAG_PVSYNC;
  815. else
  816. flags |= DRM_MODE_FLAG_NVSYNC;
  817. if (tmp & HDMI_MODE_SELECT_HDMI)
  818. pipe_config->has_hdmi_sink = true;
  819. if (intel_dig_port->infoframe_enabled(&encoder->base, pipe_config))
  820. pipe_config->has_infoframe = true;
  821. if (tmp & SDVO_AUDIO_ENABLE)
  822. pipe_config->has_audio = true;
  823. if (!HAS_PCH_SPLIT(dev_priv) &&
  824. tmp & HDMI_COLOR_RANGE_16_235)
  825. pipe_config->limited_color_range = true;
  826. pipe_config->base.adjusted_mode.flags |= flags;
  827. if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
  828. dotclock = pipe_config->port_clock * 2 / 3;
  829. else
  830. dotclock = pipe_config->port_clock;
  831. if (pipe_config->pixel_multiplier)
  832. dotclock /= pipe_config->pixel_multiplier;
  833. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  834. pipe_config->lane_count = 4;
  835. }
  836. static void intel_enable_hdmi_audio(struct intel_encoder *encoder,
  837. const struct intel_crtc_state *pipe_config,
  838. const struct drm_connector_state *conn_state)
  839. {
  840. struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  841. WARN_ON(!pipe_config->has_hdmi_sink);
  842. DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
  843. pipe_name(crtc->pipe));
  844. intel_audio_codec_enable(encoder, pipe_config, conn_state);
  845. }
  846. static void g4x_enable_hdmi(struct intel_encoder *encoder,
  847. const struct intel_crtc_state *pipe_config,
  848. const struct drm_connector_state *conn_state)
  849. {
  850. struct drm_device *dev = encoder->base.dev;
  851. struct drm_i915_private *dev_priv = to_i915(dev);
  852. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  853. u32 temp;
  854. temp = I915_READ(intel_hdmi->hdmi_reg);
  855. temp |= SDVO_ENABLE;
  856. if (pipe_config->has_audio)
  857. temp |= SDVO_AUDIO_ENABLE;
  858. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  859. POSTING_READ(intel_hdmi->hdmi_reg);
  860. if (pipe_config->has_audio)
  861. intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
  862. }
  863. static void ibx_enable_hdmi(struct intel_encoder *encoder,
  864. const struct intel_crtc_state *pipe_config,
  865. const struct drm_connector_state *conn_state)
  866. {
  867. struct drm_device *dev = encoder->base.dev;
  868. struct drm_i915_private *dev_priv = to_i915(dev);
  869. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  870. u32 temp;
  871. temp = I915_READ(intel_hdmi->hdmi_reg);
  872. temp |= SDVO_ENABLE;
  873. if (pipe_config->has_audio)
  874. temp |= SDVO_AUDIO_ENABLE;
  875. /*
  876. * HW workaround, need to write this twice for issue
  877. * that may result in first write getting masked.
  878. */
  879. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  880. POSTING_READ(intel_hdmi->hdmi_reg);
  881. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  882. POSTING_READ(intel_hdmi->hdmi_reg);
  883. /*
  884. * HW workaround, need to toggle enable bit off and on
  885. * for 12bpc with pixel repeat.
  886. *
  887. * FIXME: BSpec says this should be done at the end of
  888. * of the modeset sequence, so not sure if this isn't too soon.
  889. */
  890. if (pipe_config->pipe_bpp > 24 &&
  891. pipe_config->pixel_multiplier > 1) {
  892. I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
  893. POSTING_READ(intel_hdmi->hdmi_reg);
  894. /*
  895. * HW workaround, need to write this twice for issue
  896. * that may result in first write getting masked.
  897. */
  898. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  899. POSTING_READ(intel_hdmi->hdmi_reg);
  900. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  901. POSTING_READ(intel_hdmi->hdmi_reg);
  902. }
  903. if (pipe_config->has_audio)
  904. intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
  905. }
  906. static void cpt_enable_hdmi(struct intel_encoder *encoder,
  907. const struct intel_crtc_state *pipe_config,
  908. const struct drm_connector_state *conn_state)
  909. {
  910. struct drm_device *dev = encoder->base.dev;
  911. struct drm_i915_private *dev_priv = to_i915(dev);
  912. struct intel_crtc *crtc = to_intel_crtc(pipe_config->base.crtc);
  913. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  914. enum pipe pipe = crtc->pipe;
  915. u32 temp;
  916. temp = I915_READ(intel_hdmi->hdmi_reg);
  917. temp |= SDVO_ENABLE;
  918. if (pipe_config->has_audio)
  919. temp |= SDVO_AUDIO_ENABLE;
  920. /*
  921. * WaEnableHDMI8bpcBefore12bpc:snb,ivb
  922. *
  923. * The procedure for 12bpc is as follows:
  924. * 1. disable HDMI clock gating
  925. * 2. enable HDMI with 8bpc
  926. * 3. enable HDMI with 12bpc
  927. * 4. enable HDMI clock gating
  928. */
  929. if (pipe_config->pipe_bpp > 24) {
  930. I915_WRITE(TRANS_CHICKEN1(pipe),
  931. I915_READ(TRANS_CHICKEN1(pipe)) |
  932. TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
  933. temp &= ~SDVO_COLOR_FORMAT_MASK;
  934. temp |= SDVO_COLOR_FORMAT_8bpc;
  935. }
  936. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  937. POSTING_READ(intel_hdmi->hdmi_reg);
  938. if (pipe_config->pipe_bpp > 24) {
  939. temp &= ~SDVO_COLOR_FORMAT_MASK;
  940. temp |= HDMI_COLOR_FORMAT_12bpc;
  941. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  942. POSTING_READ(intel_hdmi->hdmi_reg);
  943. I915_WRITE(TRANS_CHICKEN1(pipe),
  944. I915_READ(TRANS_CHICKEN1(pipe)) &
  945. ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
  946. }
  947. if (pipe_config->has_audio)
  948. intel_enable_hdmi_audio(encoder, pipe_config, conn_state);
  949. }
  950. static void vlv_enable_hdmi(struct intel_encoder *encoder,
  951. const struct intel_crtc_state *pipe_config,
  952. const struct drm_connector_state *conn_state)
  953. {
  954. }
  955. static void intel_disable_hdmi(struct intel_encoder *encoder,
  956. const struct intel_crtc_state *old_crtc_state,
  957. const struct drm_connector_state *old_conn_state)
  958. {
  959. struct drm_device *dev = encoder->base.dev;
  960. struct drm_i915_private *dev_priv = to_i915(dev);
  961. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  962. struct intel_digital_port *intel_dig_port =
  963. hdmi_to_dig_port(intel_hdmi);
  964. struct intel_crtc *crtc = to_intel_crtc(old_crtc_state->base.crtc);
  965. u32 temp;
  966. temp = I915_READ(intel_hdmi->hdmi_reg);
  967. temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
  968. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  969. POSTING_READ(intel_hdmi->hdmi_reg);
  970. /*
  971. * HW workaround for IBX, we need to move the port
  972. * to transcoder A after disabling it to allow the
  973. * matching DP port to be enabled on transcoder A.
  974. */
  975. if (HAS_PCH_IBX(dev_priv) && crtc->pipe == PIPE_B) {
  976. /*
  977. * We get CPU/PCH FIFO underruns on the other pipe when
  978. * doing the workaround. Sweep them under the rug.
  979. */
  980. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  981. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, false);
  982. temp &= ~SDVO_PIPE_B_SELECT;
  983. temp |= SDVO_ENABLE;
  984. /*
  985. * HW workaround, need to write this twice for issue
  986. * that may result in first write getting masked.
  987. */
  988. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  989. POSTING_READ(intel_hdmi->hdmi_reg);
  990. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  991. POSTING_READ(intel_hdmi->hdmi_reg);
  992. temp &= ~SDVO_ENABLE;
  993. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  994. POSTING_READ(intel_hdmi->hdmi_reg);
  995. intel_wait_for_vblank_if_active(dev_priv, PIPE_A);
  996. intel_set_cpu_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  997. intel_set_pch_fifo_underrun_reporting(dev_priv, PIPE_A, true);
  998. }
  999. intel_dig_port->set_infoframes(&encoder->base, false,
  1000. old_crtc_state, old_conn_state);
  1001. intel_dp_dual_mode_set_tmds_output(intel_hdmi, false);
  1002. }
  1003. static void g4x_disable_hdmi(struct intel_encoder *encoder,
  1004. const struct intel_crtc_state *old_crtc_state,
  1005. const struct drm_connector_state *old_conn_state)
  1006. {
  1007. if (old_crtc_state->has_audio)
  1008. intel_audio_codec_disable(encoder,
  1009. old_crtc_state, old_conn_state);
  1010. intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
  1011. }
  1012. static void pch_disable_hdmi(struct intel_encoder *encoder,
  1013. const struct intel_crtc_state *old_crtc_state,
  1014. const struct drm_connector_state *old_conn_state)
  1015. {
  1016. if (old_crtc_state->has_audio)
  1017. intel_audio_codec_disable(encoder,
  1018. old_crtc_state, old_conn_state);
  1019. }
  1020. static void pch_post_disable_hdmi(struct intel_encoder *encoder,
  1021. const struct intel_crtc_state *old_crtc_state,
  1022. const struct drm_connector_state *old_conn_state)
  1023. {
  1024. intel_disable_hdmi(encoder, old_crtc_state, old_conn_state);
  1025. }
  1026. static int intel_hdmi_source_max_tmds_clock(struct intel_encoder *encoder)
  1027. {
  1028. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1029. const struct ddi_vbt_port_info *info =
  1030. &dev_priv->vbt.ddi_port_info[encoder->port];
  1031. int max_tmds_clock;
  1032. if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
  1033. max_tmds_clock = 594000;
  1034. else if (INTEL_GEN(dev_priv) >= 8 || IS_HASWELL(dev_priv))
  1035. max_tmds_clock = 300000;
  1036. else if (INTEL_GEN(dev_priv) >= 5)
  1037. max_tmds_clock = 225000;
  1038. else
  1039. max_tmds_clock = 165000;
  1040. if (info->max_tmds_clock)
  1041. max_tmds_clock = min(max_tmds_clock, info->max_tmds_clock);
  1042. return max_tmds_clock;
  1043. }
  1044. static int hdmi_port_clock_limit(struct intel_hdmi *hdmi,
  1045. bool respect_downstream_limits,
  1046. bool force_dvi)
  1047. {
  1048. struct intel_encoder *encoder = &hdmi_to_dig_port(hdmi)->base;
  1049. int max_tmds_clock = intel_hdmi_source_max_tmds_clock(encoder);
  1050. if (respect_downstream_limits) {
  1051. struct intel_connector *connector = hdmi->attached_connector;
  1052. const struct drm_display_info *info = &connector->base.display_info;
  1053. if (hdmi->dp_dual_mode.max_tmds_clock)
  1054. max_tmds_clock = min(max_tmds_clock,
  1055. hdmi->dp_dual_mode.max_tmds_clock);
  1056. if (info->max_tmds_clock)
  1057. max_tmds_clock = min(max_tmds_clock,
  1058. info->max_tmds_clock);
  1059. else if (!hdmi->has_hdmi_sink || force_dvi)
  1060. max_tmds_clock = min(max_tmds_clock, 165000);
  1061. }
  1062. return max_tmds_clock;
  1063. }
  1064. static enum drm_mode_status
  1065. hdmi_port_clock_valid(struct intel_hdmi *hdmi,
  1066. int clock, bool respect_downstream_limits,
  1067. bool force_dvi)
  1068. {
  1069. struct drm_i915_private *dev_priv = to_i915(intel_hdmi_to_dev(hdmi));
  1070. if (clock < 25000)
  1071. return MODE_CLOCK_LOW;
  1072. if (clock > hdmi_port_clock_limit(hdmi, respect_downstream_limits, force_dvi))
  1073. return MODE_CLOCK_HIGH;
  1074. /* BXT DPLL can't generate 223-240 MHz */
  1075. if (IS_GEN9_LP(dev_priv) && clock > 223333 && clock < 240000)
  1076. return MODE_CLOCK_RANGE;
  1077. /* CHV DPLL can't generate 216-240 MHz */
  1078. if (IS_CHERRYVIEW(dev_priv) && clock > 216000 && clock < 240000)
  1079. return MODE_CLOCK_RANGE;
  1080. return MODE_OK;
  1081. }
  1082. static enum drm_mode_status
  1083. intel_hdmi_mode_valid(struct drm_connector *connector,
  1084. struct drm_display_mode *mode)
  1085. {
  1086. struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
  1087. struct drm_device *dev = intel_hdmi_to_dev(hdmi);
  1088. struct drm_i915_private *dev_priv = to_i915(dev);
  1089. enum drm_mode_status status;
  1090. int clock;
  1091. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  1092. bool force_dvi =
  1093. READ_ONCE(to_intel_digital_connector_state(connector->state)->force_audio) == HDMI_AUDIO_OFF_DVI;
  1094. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  1095. return MODE_NO_DBLESCAN;
  1096. clock = mode->clock;
  1097. if ((mode->flags & DRM_MODE_FLAG_3D_MASK) == DRM_MODE_FLAG_3D_FRAME_PACKING)
  1098. clock *= 2;
  1099. if (clock > max_dotclk)
  1100. return MODE_CLOCK_HIGH;
  1101. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  1102. clock *= 2;
  1103. if (drm_mode_is_420_only(&connector->display_info, mode))
  1104. clock /= 2;
  1105. /* check if we can do 8bpc */
  1106. status = hdmi_port_clock_valid(hdmi, clock, true, force_dvi);
  1107. /* if we can't do 8bpc we may still be able to do 12bpc */
  1108. if (!HAS_GMCH_DISPLAY(dev_priv) && status != MODE_OK && hdmi->has_hdmi_sink && !force_dvi)
  1109. status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true, force_dvi);
  1110. return status;
  1111. }
  1112. static bool hdmi_12bpc_possible(const struct intel_crtc_state *crtc_state)
  1113. {
  1114. struct drm_i915_private *dev_priv =
  1115. to_i915(crtc_state->base.crtc->dev);
  1116. struct drm_atomic_state *state = crtc_state->base.state;
  1117. struct drm_connector_state *connector_state;
  1118. struct drm_connector *connector;
  1119. int i;
  1120. if (HAS_GMCH_DISPLAY(dev_priv))
  1121. return false;
  1122. if (crtc_state->pipe_bpp <= 8*3)
  1123. return false;
  1124. if (!crtc_state->has_hdmi_sink)
  1125. return false;
  1126. /*
  1127. * HDMI 12bpc affects the clocks, so it's only possible
  1128. * when not cloning with other encoder types.
  1129. */
  1130. if (crtc_state->output_types != 1 << INTEL_OUTPUT_HDMI)
  1131. return false;
  1132. for_each_new_connector_in_state(state, connector, connector_state, i) {
  1133. const struct drm_display_info *info = &connector->display_info;
  1134. if (connector_state->crtc != crtc_state->base.crtc)
  1135. continue;
  1136. if (crtc_state->ycbcr420) {
  1137. const struct drm_hdmi_info *hdmi = &info->hdmi;
  1138. if (!(hdmi->y420_dc_modes & DRM_EDID_YCBCR420_DC_36))
  1139. return false;
  1140. } else {
  1141. if (!(info->edid_hdmi_dc_modes & DRM_EDID_HDMI_DC_36))
  1142. return false;
  1143. }
  1144. }
  1145. /* Display WA #1139: glk */
  1146. if (IS_GLK_REVID(dev_priv, 0, GLK_REVID_A1) &&
  1147. crtc_state->base.adjusted_mode.htotal > 5460)
  1148. return false;
  1149. return true;
  1150. }
  1151. static bool
  1152. intel_hdmi_ycbcr420_config(struct drm_connector *connector,
  1153. struct intel_crtc_state *config,
  1154. int *clock_12bpc, int *clock_8bpc)
  1155. {
  1156. struct intel_crtc *intel_crtc = to_intel_crtc(config->base.crtc);
  1157. if (!connector->ycbcr_420_allowed) {
  1158. DRM_ERROR("Platform doesn't support YCBCR420 output\n");
  1159. return false;
  1160. }
  1161. /* YCBCR420 TMDS rate requirement is half the pixel clock */
  1162. config->port_clock /= 2;
  1163. *clock_12bpc /= 2;
  1164. *clock_8bpc /= 2;
  1165. config->ycbcr420 = true;
  1166. /* YCBCR 420 output conversion needs a scaler */
  1167. if (skl_update_scaler_crtc(config)) {
  1168. DRM_DEBUG_KMS("Scaler allocation for output failed\n");
  1169. return false;
  1170. }
  1171. intel_pch_panel_fitting(intel_crtc, config,
  1172. DRM_MODE_SCALE_FULLSCREEN);
  1173. return true;
  1174. }
  1175. bool intel_hdmi_compute_config(struct intel_encoder *encoder,
  1176. struct intel_crtc_state *pipe_config,
  1177. struct drm_connector_state *conn_state)
  1178. {
  1179. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1180. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1181. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  1182. struct drm_connector *connector = conn_state->connector;
  1183. struct drm_scdc *scdc = &connector->display_info.hdmi.scdc;
  1184. struct intel_digital_connector_state *intel_conn_state =
  1185. to_intel_digital_connector_state(conn_state);
  1186. int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
  1187. int clock_12bpc = clock_8bpc * 3 / 2;
  1188. int desired_bpp;
  1189. bool force_dvi = intel_conn_state->force_audio == HDMI_AUDIO_OFF_DVI;
  1190. pipe_config->has_hdmi_sink = !force_dvi && intel_hdmi->has_hdmi_sink;
  1191. if (pipe_config->has_hdmi_sink)
  1192. pipe_config->has_infoframe = true;
  1193. if (intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_AUTO) {
  1194. /* See CEA-861-E - 5.1 Default Encoding Parameters */
  1195. pipe_config->limited_color_range =
  1196. pipe_config->has_hdmi_sink &&
  1197. drm_default_rgb_quant_range(adjusted_mode) ==
  1198. HDMI_QUANTIZATION_RANGE_LIMITED;
  1199. } else {
  1200. pipe_config->limited_color_range =
  1201. intel_conn_state->broadcast_rgb == INTEL_BROADCAST_RGB_LIMITED;
  1202. }
  1203. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
  1204. pipe_config->pixel_multiplier = 2;
  1205. clock_8bpc *= 2;
  1206. clock_12bpc *= 2;
  1207. }
  1208. if (drm_mode_is_420_only(&connector->display_info, adjusted_mode)) {
  1209. if (!intel_hdmi_ycbcr420_config(connector, pipe_config,
  1210. &clock_12bpc, &clock_8bpc)) {
  1211. DRM_ERROR("Can't support YCBCR420 output\n");
  1212. return false;
  1213. }
  1214. }
  1215. if (HAS_PCH_SPLIT(dev_priv) && !HAS_DDI(dev_priv))
  1216. pipe_config->has_pch_encoder = true;
  1217. if (pipe_config->has_hdmi_sink) {
  1218. if (intel_conn_state->force_audio == HDMI_AUDIO_AUTO)
  1219. pipe_config->has_audio = intel_hdmi->has_audio;
  1220. else
  1221. pipe_config->has_audio =
  1222. intel_conn_state->force_audio == HDMI_AUDIO_ON;
  1223. }
  1224. /*
  1225. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  1226. * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
  1227. * outputs. We also need to check that the higher clock still fits
  1228. * within limits.
  1229. */
  1230. if (hdmi_12bpc_possible(pipe_config) &&
  1231. hdmi_port_clock_valid(intel_hdmi, clock_12bpc, true, force_dvi) == MODE_OK) {
  1232. DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
  1233. desired_bpp = 12*3;
  1234. /* Need to adjust the port link by 1.5x for 12bpc. */
  1235. pipe_config->port_clock = clock_12bpc;
  1236. } else {
  1237. DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
  1238. desired_bpp = 8*3;
  1239. pipe_config->port_clock = clock_8bpc;
  1240. }
  1241. if (!pipe_config->bw_constrained) {
  1242. DRM_DEBUG_KMS("forcing pipe bpp to %i for HDMI\n", desired_bpp);
  1243. pipe_config->pipe_bpp = desired_bpp;
  1244. }
  1245. if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
  1246. false, force_dvi) != MODE_OK) {
  1247. DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
  1248. return false;
  1249. }
  1250. /* Set user selected PAR to incoming mode's member */
  1251. adjusted_mode->picture_aspect_ratio = conn_state->picture_aspect_ratio;
  1252. pipe_config->lane_count = 4;
  1253. if (scdc->scrambling.supported && (INTEL_GEN(dev_priv) >= 10 ||
  1254. IS_GEMINILAKE(dev_priv))) {
  1255. if (scdc->scrambling.low_rates)
  1256. pipe_config->hdmi_scrambling = true;
  1257. if (pipe_config->port_clock > 340000) {
  1258. pipe_config->hdmi_scrambling = true;
  1259. pipe_config->hdmi_high_tmds_clock_ratio = true;
  1260. }
  1261. }
  1262. return true;
  1263. }
  1264. static void
  1265. intel_hdmi_unset_edid(struct drm_connector *connector)
  1266. {
  1267. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  1268. intel_hdmi->has_hdmi_sink = false;
  1269. intel_hdmi->has_audio = false;
  1270. intel_hdmi->rgb_quant_range_selectable = false;
  1271. intel_hdmi->dp_dual_mode.type = DRM_DP_DUAL_MODE_NONE;
  1272. intel_hdmi->dp_dual_mode.max_tmds_clock = 0;
  1273. kfree(to_intel_connector(connector)->detect_edid);
  1274. to_intel_connector(connector)->detect_edid = NULL;
  1275. }
  1276. static void
  1277. intel_hdmi_dp_dual_mode_detect(struct drm_connector *connector, bool has_edid)
  1278. {
  1279. struct drm_i915_private *dev_priv = to_i915(connector->dev);
  1280. struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
  1281. enum port port = hdmi_to_dig_port(hdmi)->base.port;
  1282. struct i2c_adapter *adapter =
  1283. intel_gmbus_get_adapter(dev_priv, hdmi->ddc_bus);
  1284. enum drm_dp_dual_mode_type type = drm_dp_dual_mode_detect(adapter);
  1285. /*
  1286. * Type 1 DVI adaptors are not required to implement any
  1287. * registers, so we can't always detect their presence.
  1288. * Ideally we should be able to check the state of the
  1289. * CONFIG1 pin, but no such luck on our hardware.
  1290. *
  1291. * The only method left to us is to check the VBT to see
  1292. * if the port is a dual mode capable DP port. But let's
  1293. * only do that when we sucesfully read the EDID, to avoid
  1294. * confusing log messages about DP dual mode adaptors when
  1295. * there's nothing connected to the port.
  1296. */
  1297. if (type == DRM_DP_DUAL_MODE_UNKNOWN) {
  1298. if (has_edid &&
  1299. intel_bios_is_port_dp_dual_mode(dev_priv, port)) {
  1300. DRM_DEBUG_KMS("Assuming DP dual mode adaptor presence based on VBT\n");
  1301. type = DRM_DP_DUAL_MODE_TYPE1_DVI;
  1302. } else {
  1303. type = DRM_DP_DUAL_MODE_NONE;
  1304. }
  1305. }
  1306. if (type == DRM_DP_DUAL_MODE_NONE)
  1307. return;
  1308. hdmi->dp_dual_mode.type = type;
  1309. hdmi->dp_dual_mode.max_tmds_clock =
  1310. drm_dp_dual_mode_max_tmds_clock(type, adapter);
  1311. DRM_DEBUG_KMS("DP dual mode adaptor (%s) detected (max TMDS clock: %d kHz)\n",
  1312. drm_dp_get_dual_mode_type_name(type),
  1313. hdmi->dp_dual_mode.max_tmds_clock);
  1314. }
  1315. static bool
  1316. intel_hdmi_set_edid(struct drm_connector *connector)
  1317. {
  1318. struct drm_i915_private *dev_priv = to_i915(connector->dev);
  1319. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  1320. struct edid *edid;
  1321. bool connected = false;
  1322. intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
  1323. edid = drm_get_edid(connector,
  1324. intel_gmbus_get_adapter(dev_priv,
  1325. intel_hdmi->ddc_bus));
  1326. intel_hdmi_dp_dual_mode_detect(connector, edid != NULL);
  1327. intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
  1328. to_intel_connector(connector)->detect_edid = edid;
  1329. if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
  1330. intel_hdmi->rgb_quant_range_selectable =
  1331. drm_rgb_quant_range_selectable(edid);
  1332. intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
  1333. intel_hdmi->has_hdmi_sink = drm_detect_hdmi_monitor(edid);
  1334. connected = true;
  1335. }
  1336. return connected;
  1337. }
  1338. static enum drm_connector_status
  1339. intel_hdmi_detect(struct drm_connector *connector, bool force)
  1340. {
  1341. enum drm_connector_status status;
  1342. struct drm_i915_private *dev_priv = to_i915(connector->dev);
  1343. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  1344. connector->base.id, connector->name);
  1345. intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
  1346. intel_hdmi_unset_edid(connector);
  1347. if (intel_hdmi_set_edid(connector))
  1348. status = connector_status_connected;
  1349. else
  1350. status = connector_status_disconnected;
  1351. intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
  1352. return status;
  1353. }
  1354. static void
  1355. intel_hdmi_force(struct drm_connector *connector)
  1356. {
  1357. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  1358. connector->base.id, connector->name);
  1359. intel_hdmi_unset_edid(connector);
  1360. if (connector->status != connector_status_connected)
  1361. return;
  1362. intel_hdmi_set_edid(connector);
  1363. }
  1364. static int intel_hdmi_get_modes(struct drm_connector *connector)
  1365. {
  1366. struct edid *edid;
  1367. edid = to_intel_connector(connector)->detect_edid;
  1368. if (edid == NULL)
  1369. return 0;
  1370. return intel_connector_update_modes(connector, edid);
  1371. }
  1372. static void intel_hdmi_pre_enable(struct intel_encoder *encoder,
  1373. const struct intel_crtc_state *pipe_config,
  1374. const struct drm_connector_state *conn_state)
  1375. {
  1376. struct intel_digital_port *intel_dig_port =
  1377. enc_to_dig_port(&encoder->base);
  1378. intel_hdmi_prepare(encoder, pipe_config);
  1379. intel_dig_port->set_infoframes(&encoder->base,
  1380. pipe_config->has_infoframe,
  1381. pipe_config, conn_state);
  1382. }
  1383. static void vlv_hdmi_pre_enable(struct intel_encoder *encoder,
  1384. const struct intel_crtc_state *pipe_config,
  1385. const struct drm_connector_state *conn_state)
  1386. {
  1387. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1388. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1389. vlv_phy_pre_encoder_enable(encoder, pipe_config);
  1390. /* HDMI 1.0V-2dB */
  1391. vlv_set_phy_signal_level(encoder, 0x2b245f5f, 0x00002000, 0x5578b83a,
  1392. 0x2b247878);
  1393. dport->set_infoframes(&encoder->base,
  1394. pipe_config->has_infoframe,
  1395. pipe_config, conn_state);
  1396. g4x_enable_hdmi(encoder, pipe_config, conn_state);
  1397. vlv_wait_port_ready(dev_priv, dport, 0x0);
  1398. }
  1399. static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
  1400. const struct intel_crtc_state *pipe_config,
  1401. const struct drm_connector_state *conn_state)
  1402. {
  1403. intel_hdmi_prepare(encoder, pipe_config);
  1404. vlv_phy_pre_pll_enable(encoder, pipe_config);
  1405. }
  1406. static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder,
  1407. const struct intel_crtc_state *pipe_config,
  1408. const struct drm_connector_state *conn_state)
  1409. {
  1410. intel_hdmi_prepare(encoder, pipe_config);
  1411. chv_phy_pre_pll_enable(encoder, pipe_config);
  1412. }
  1413. static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder,
  1414. const struct intel_crtc_state *old_crtc_state,
  1415. const struct drm_connector_state *old_conn_state)
  1416. {
  1417. chv_phy_post_pll_disable(encoder, old_crtc_state);
  1418. }
  1419. static void vlv_hdmi_post_disable(struct intel_encoder *encoder,
  1420. const struct intel_crtc_state *old_crtc_state,
  1421. const struct drm_connector_state *old_conn_state)
  1422. {
  1423. /* Reset lanes to avoid HDMI flicker (VLV w/a) */
  1424. vlv_phy_reset_lanes(encoder, old_crtc_state);
  1425. }
  1426. static void chv_hdmi_post_disable(struct intel_encoder *encoder,
  1427. const struct intel_crtc_state *old_crtc_state,
  1428. const struct drm_connector_state *old_conn_state)
  1429. {
  1430. struct drm_device *dev = encoder->base.dev;
  1431. struct drm_i915_private *dev_priv = to_i915(dev);
  1432. mutex_lock(&dev_priv->sb_lock);
  1433. /* Assert data lane reset */
  1434. chv_data_lane_soft_reset(encoder, old_crtc_state, true);
  1435. mutex_unlock(&dev_priv->sb_lock);
  1436. }
  1437. static void chv_hdmi_pre_enable(struct intel_encoder *encoder,
  1438. const struct intel_crtc_state *pipe_config,
  1439. const struct drm_connector_state *conn_state)
  1440. {
  1441. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1442. struct drm_device *dev = encoder->base.dev;
  1443. struct drm_i915_private *dev_priv = to_i915(dev);
  1444. chv_phy_pre_encoder_enable(encoder, pipe_config);
  1445. /* FIXME: Program the support xxx V-dB */
  1446. /* Use 800mV-0dB */
  1447. chv_set_phy_signal_level(encoder, 128, 102, false);
  1448. dport->set_infoframes(&encoder->base,
  1449. pipe_config->has_infoframe,
  1450. pipe_config, conn_state);
  1451. g4x_enable_hdmi(encoder, pipe_config, conn_state);
  1452. vlv_wait_port_ready(dev_priv, dport, 0x0);
  1453. /* Second common lane will stay alive on its own now */
  1454. chv_phy_release_cl2_override(encoder);
  1455. }
  1456. static void intel_hdmi_destroy(struct drm_connector *connector)
  1457. {
  1458. kfree(to_intel_connector(connector)->detect_edid);
  1459. drm_connector_cleanup(connector);
  1460. kfree(connector);
  1461. }
  1462. static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
  1463. .detect = intel_hdmi_detect,
  1464. .force = intel_hdmi_force,
  1465. .fill_modes = drm_helper_probe_single_connector_modes,
  1466. .atomic_get_property = intel_digital_connector_atomic_get_property,
  1467. .atomic_set_property = intel_digital_connector_atomic_set_property,
  1468. .late_register = intel_connector_register,
  1469. .early_unregister = intel_connector_unregister,
  1470. .destroy = intel_hdmi_destroy,
  1471. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1472. .atomic_duplicate_state = intel_digital_connector_duplicate_state,
  1473. };
  1474. static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
  1475. .get_modes = intel_hdmi_get_modes,
  1476. .mode_valid = intel_hdmi_mode_valid,
  1477. .atomic_check = intel_digital_connector_atomic_check,
  1478. };
  1479. static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
  1480. .destroy = intel_encoder_destroy,
  1481. };
  1482. static void
  1483. intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
  1484. {
  1485. intel_attach_force_audio_property(connector);
  1486. intel_attach_broadcast_rgb_property(connector);
  1487. intel_attach_aspect_ratio_property(connector);
  1488. connector->state->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
  1489. }
  1490. /*
  1491. * intel_hdmi_handle_sink_scrambling: handle sink scrambling/clock ratio setup
  1492. * @encoder: intel_encoder
  1493. * @connector: drm_connector
  1494. * @high_tmds_clock_ratio = bool to indicate if the function needs to set
  1495. * or reset the high tmds clock ratio for scrambling
  1496. * @scrambling: bool to Indicate if the function needs to set or reset
  1497. * sink scrambling
  1498. *
  1499. * This function handles scrambling on HDMI 2.0 capable sinks.
  1500. * If required clock rate is > 340 Mhz && scrambling is supported by sink
  1501. * it enables scrambling. This should be called before enabling the HDMI
  1502. * 2.0 port, as the sink can choose to disable the scrambling if it doesn't
  1503. * detect a scrambled clock within 100 ms.
  1504. */
  1505. void intel_hdmi_handle_sink_scrambling(struct intel_encoder *encoder,
  1506. struct drm_connector *connector,
  1507. bool high_tmds_clock_ratio,
  1508. bool scrambling)
  1509. {
  1510. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1511. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1512. struct drm_scrambling *sink_scrambling =
  1513. &connector->display_info.hdmi.scdc.scrambling;
  1514. struct i2c_adapter *adptr = intel_gmbus_get_adapter(dev_priv,
  1515. intel_hdmi->ddc_bus);
  1516. bool ret;
  1517. if (!sink_scrambling->supported)
  1518. return;
  1519. DRM_DEBUG_KMS("Setting sink scrambling for enc:%s connector:%s\n",
  1520. encoder->base.name, connector->name);
  1521. /* Set TMDS bit clock ratio to 1/40 or 1/10 */
  1522. ret = drm_scdc_set_high_tmds_clock_ratio(adptr, high_tmds_clock_ratio);
  1523. if (!ret) {
  1524. DRM_ERROR("Set TMDS ratio failed\n");
  1525. return;
  1526. }
  1527. /* Enable/disable sink scrambling */
  1528. ret = drm_scdc_set_scrambling(adptr, scrambling);
  1529. if (!ret) {
  1530. DRM_ERROR("Set sink scrambling failed\n");
  1531. return;
  1532. }
  1533. DRM_DEBUG_KMS("sink scrambling handled\n");
  1534. }
  1535. static u8 chv_port_to_ddc_pin(struct drm_i915_private *dev_priv, enum port port)
  1536. {
  1537. u8 ddc_pin;
  1538. switch (port) {
  1539. case PORT_B:
  1540. ddc_pin = GMBUS_PIN_DPB;
  1541. break;
  1542. case PORT_C:
  1543. ddc_pin = GMBUS_PIN_DPC;
  1544. break;
  1545. case PORT_D:
  1546. ddc_pin = GMBUS_PIN_DPD_CHV;
  1547. break;
  1548. default:
  1549. MISSING_CASE(port);
  1550. ddc_pin = GMBUS_PIN_DPB;
  1551. break;
  1552. }
  1553. return ddc_pin;
  1554. }
  1555. static u8 bxt_port_to_ddc_pin(struct drm_i915_private *dev_priv, enum port port)
  1556. {
  1557. u8 ddc_pin;
  1558. switch (port) {
  1559. case PORT_B:
  1560. ddc_pin = GMBUS_PIN_1_BXT;
  1561. break;
  1562. case PORT_C:
  1563. ddc_pin = GMBUS_PIN_2_BXT;
  1564. break;
  1565. default:
  1566. MISSING_CASE(port);
  1567. ddc_pin = GMBUS_PIN_1_BXT;
  1568. break;
  1569. }
  1570. return ddc_pin;
  1571. }
  1572. static u8 cnp_port_to_ddc_pin(struct drm_i915_private *dev_priv,
  1573. enum port port)
  1574. {
  1575. u8 ddc_pin;
  1576. switch (port) {
  1577. case PORT_B:
  1578. ddc_pin = GMBUS_PIN_1_BXT;
  1579. break;
  1580. case PORT_C:
  1581. ddc_pin = GMBUS_PIN_2_BXT;
  1582. break;
  1583. case PORT_D:
  1584. ddc_pin = GMBUS_PIN_4_CNP;
  1585. break;
  1586. default:
  1587. MISSING_CASE(port);
  1588. ddc_pin = GMBUS_PIN_1_BXT;
  1589. break;
  1590. }
  1591. return ddc_pin;
  1592. }
  1593. static u8 g4x_port_to_ddc_pin(struct drm_i915_private *dev_priv,
  1594. enum port port)
  1595. {
  1596. u8 ddc_pin;
  1597. switch (port) {
  1598. case PORT_B:
  1599. ddc_pin = GMBUS_PIN_DPB;
  1600. break;
  1601. case PORT_C:
  1602. ddc_pin = GMBUS_PIN_DPC;
  1603. break;
  1604. case PORT_D:
  1605. ddc_pin = GMBUS_PIN_DPD;
  1606. break;
  1607. default:
  1608. MISSING_CASE(port);
  1609. ddc_pin = GMBUS_PIN_DPB;
  1610. break;
  1611. }
  1612. return ddc_pin;
  1613. }
  1614. static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
  1615. enum port port)
  1616. {
  1617. const struct ddi_vbt_port_info *info =
  1618. &dev_priv->vbt.ddi_port_info[port];
  1619. u8 ddc_pin;
  1620. if (info->alternate_ddc_pin) {
  1621. DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
  1622. info->alternate_ddc_pin, port_name(port));
  1623. return info->alternate_ddc_pin;
  1624. }
  1625. if (IS_CHERRYVIEW(dev_priv))
  1626. ddc_pin = chv_port_to_ddc_pin(dev_priv, port);
  1627. else if (IS_GEN9_LP(dev_priv))
  1628. ddc_pin = bxt_port_to_ddc_pin(dev_priv, port);
  1629. else if (HAS_PCH_CNP(dev_priv))
  1630. ddc_pin = cnp_port_to_ddc_pin(dev_priv, port);
  1631. else
  1632. ddc_pin = g4x_port_to_ddc_pin(dev_priv, port);
  1633. DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
  1634. ddc_pin, port_name(port));
  1635. return ddc_pin;
  1636. }
  1637. void intel_infoframe_init(struct intel_digital_port *intel_dig_port)
  1638. {
  1639. struct drm_i915_private *dev_priv =
  1640. to_i915(intel_dig_port->base.base.dev);
  1641. if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) {
  1642. intel_dig_port->write_infoframe = vlv_write_infoframe;
  1643. intel_dig_port->set_infoframes = vlv_set_infoframes;
  1644. intel_dig_port->infoframe_enabled = vlv_infoframe_enabled;
  1645. } else if (IS_G4X(dev_priv)) {
  1646. intel_dig_port->write_infoframe = g4x_write_infoframe;
  1647. intel_dig_port->set_infoframes = g4x_set_infoframes;
  1648. intel_dig_port->infoframe_enabled = g4x_infoframe_enabled;
  1649. } else if (HAS_DDI(dev_priv)) {
  1650. intel_dig_port->write_infoframe = hsw_write_infoframe;
  1651. intel_dig_port->set_infoframes = hsw_set_infoframes;
  1652. intel_dig_port->infoframe_enabled = hsw_infoframe_enabled;
  1653. } else if (HAS_PCH_IBX(dev_priv)) {
  1654. intel_dig_port->write_infoframe = ibx_write_infoframe;
  1655. intel_dig_port->set_infoframes = ibx_set_infoframes;
  1656. intel_dig_port->infoframe_enabled = ibx_infoframe_enabled;
  1657. } else {
  1658. intel_dig_port->write_infoframe = cpt_write_infoframe;
  1659. intel_dig_port->set_infoframes = cpt_set_infoframes;
  1660. intel_dig_port->infoframe_enabled = cpt_infoframe_enabled;
  1661. }
  1662. }
  1663. void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
  1664. struct intel_connector *intel_connector)
  1665. {
  1666. struct drm_connector *connector = &intel_connector->base;
  1667. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  1668. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1669. struct drm_device *dev = intel_encoder->base.dev;
  1670. struct drm_i915_private *dev_priv = to_i915(dev);
  1671. enum port port = intel_encoder->port;
  1672. DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
  1673. port_name(port));
  1674. if (WARN(intel_dig_port->max_lanes < 4,
  1675. "Not enough lanes (%d) for HDMI on port %c\n",
  1676. intel_dig_port->max_lanes, port_name(port)))
  1677. return;
  1678. drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
  1679. DRM_MODE_CONNECTOR_HDMIA);
  1680. drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
  1681. connector->interlace_allowed = 1;
  1682. connector->doublescan_allowed = 0;
  1683. connector->stereo_allowed = 1;
  1684. if (INTEL_GEN(dev_priv) >= 10 || IS_GEMINILAKE(dev_priv))
  1685. connector->ycbcr_420_allowed = true;
  1686. intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
  1687. if (WARN_ON(port == PORT_A))
  1688. return;
  1689. intel_encoder->hpd_pin = intel_hpd_pin(port);
  1690. if (HAS_DDI(dev_priv))
  1691. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  1692. else
  1693. intel_connector->get_hw_state = intel_connector_get_hw_state;
  1694. intel_hdmi_add_properties(intel_hdmi, connector);
  1695. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1696. intel_hdmi->attached_connector = intel_connector;
  1697. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  1698. * 0xd. Failure to do so will result in spurious interrupts being
  1699. * generated on the port when a cable is not attached.
  1700. */
  1701. if (IS_G4X(dev_priv) && !IS_GM45(dev_priv)) {
  1702. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  1703. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  1704. }
  1705. }
  1706. void intel_hdmi_init(struct drm_i915_private *dev_priv,
  1707. i915_reg_t hdmi_reg, enum port port)
  1708. {
  1709. struct intel_digital_port *intel_dig_port;
  1710. struct intel_encoder *intel_encoder;
  1711. struct intel_connector *intel_connector;
  1712. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  1713. if (!intel_dig_port)
  1714. return;
  1715. intel_connector = intel_connector_alloc();
  1716. if (!intel_connector) {
  1717. kfree(intel_dig_port);
  1718. return;
  1719. }
  1720. intel_encoder = &intel_dig_port->base;
  1721. drm_encoder_init(&dev_priv->drm, &intel_encoder->base,
  1722. &intel_hdmi_enc_funcs, DRM_MODE_ENCODER_TMDS,
  1723. "HDMI %c", port_name(port));
  1724. intel_encoder->compute_config = intel_hdmi_compute_config;
  1725. if (HAS_PCH_SPLIT(dev_priv)) {
  1726. intel_encoder->disable = pch_disable_hdmi;
  1727. intel_encoder->post_disable = pch_post_disable_hdmi;
  1728. } else {
  1729. intel_encoder->disable = g4x_disable_hdmi;
  1730. }
  1731. intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
  1732. intel_encoder->get_config = intel_hdmi_get_config;
  1733. if (IS_CHERRYVIEW(dev_priv)) {
  1734. intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
  1735. intel_encoder->pre_enable = chv_hdmi_pre_enable;
  1736. intel_encoder->enable = vlv_enable_hdmi;
  1737. intel_encoder->post_disable = chv_hdmi_post_disable;
  1738. intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
  1739. } else if (IS_VALLEYVIEW(dev_priv)) {
  1740. intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
  1741. intel_encoder->pre_enable = vlv_hdmi_pre_enable;
  1742. intel_encoder->enable = vlv_enable_hdmi;
  1743. intel_encoder->post_disable = vlv_hdmi_post_disable;
  1744. } else {
  1745. intel_encoder->pre_enable = intel_hdmi_pre_enable;
  1746. if (HAS_PCH_CPT(dev_priv))
  1747. intel_encoder->enable = cpt_enable_hdmi;
  1748. else if (HAS_PCH_IBX(dev_priv))
  1749. intel_encoder->enable = ibx_enable_hdmi;
  1750. else
  1751. intel_encoder->enable = g4x_enable_hdmi;
  1752. }
  1753. intel_encoder->type = INTEL_OUTPUT_HDMI;
  1754. intel_encoder->power_domain = intel_port_to_power_domain(port);
  1755. intel_encoder->port = port;
  1756. if (IS_CHERRYVIEW(dev_priv)) {
  1757. if (port == PORT_D)
  1758. intel_encoder->crtc_mask = 1 << 2;
  1759. else
  1760. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  1761. } else {
  1762. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1763. }
  1764. intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
  1765. /*
  1766. * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
  1767. * to work on real hardware. And since g4x can send infoframes to
  1768. * only one port anyway, nothing is lost by allowing it.
  1769. */
  1770. if (IS_G4X(dev_priv))
  1771. intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
  1772. intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
  1773. intel_dig_port->dp.output_reg = INVALID_MMIO_REG;
  1774. intel_dig_port->max_lanes = 4;
  1775. intel_infoframe_init(intel_dig_port);
  1776. intel_hdmi_init_connector(intel_dig_port, intel_connector);
  1777. }