intel_hdmi.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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 <drm/drmP.h>
  32. #include <drm/drm_crtc.h>
  33. #include <drm/drm_edid.h>
  34. #include "intel_drv.h"
  35. #include <drm/i915_drm.h>
  36. #include "i915_drv.h"
  37. static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
  38. {
  39. return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
  40. }
  41. static void
  42. assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
  43. {
  44. struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
  45. struct drm_i915_private *dev_priv = dev->dev_private;
  46. uint32_t enabled_bits;
  47. enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
  48. WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
  49. "HDMI port enabled, expecting disabled\n");
  50. }
  51. struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
  52. {
  53. struct intel_digital_port *intel_dig_port =
  54. container_of(encoder, struct intel_digital_port, base.base);
  55. return &intel_dig_port->hdmi;
  56. }
  57. static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
  58. {
  59. return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
  60. }
  61. void intel_dip_infoframe_csum(struct dip_infoframe *frame)
  62. {
  63. uint8_t *data = (uint8_t *)frame;
  64. uint8_t sum = 0;
  65. unsigned i;
  66. frame->checksum = 0;
  67. frame->ecc = 0;
  68. for (i = 0; i < frame->len + DIP_HEADER_SIZE; i++)
  69. sum += data[i];
  70. frame->checksum = 0x100 - sum;
  71. }
  72. static u32 g4x_infoframe_index(struct dip_infoframe *frame)
  73. {
  74. switch (frame->type) {
  75. case DIP_TYPE_AVI:
  76. return VIDEO_DIP_SELECT_AVI;
  77. case DIP_TYPE_SPD:
  78. return VIDEO_DIP_SELECT_SPD;
  79. default:
  80. DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
  81. return 0;
  82. }
  83. }
  84. static u32 g4x_infoframe_enable(struct dip_infoframe *frame)
  85. {
  86. switch (frame->type) {
  87. case DIP_TYPE_AVI:
  88. return VIDEO_DIP_ENABLE_AVI;
  89. case DIP_TYPE_SPD:
  90. return VIDEO_DIP_ENABLE_SPD;
  91. default:
  92. DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
  93. return 0;
  94. }
  95. }
  96. static u32 hsw_infoframe_enable(struct dip_infoframe *frame)
  97. {
  98. switch (frame->type) {
  99. case DIP_TYPE_AVI:
  100. return VIDEO_DIP_ENABLE_AVI_HSW;
  101. case DIP_TYPE_SPD:
  102. return VIDEO_DIP_ENABLE_SPD_HSW;
  103. default:
  104. DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
  105. return 0;
  106. }
  107. }
  108. static u32 hsw_infoframe_data_reg(struct dip_infoframe *frame,
  109. enum transcoder cpu_transcoder)
  110. {
  111. switch (frame->type) {
  112. case DIP_TYPE_AVI:
  113. return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder);
  114. case DIP_TYPE_SPD:
  115. return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder);
  116. default:
  117. DRM_DEBUG_DRIVER("unknown info frame type %d\n", frame->type);
  118. return 0;
  119. }
  120. }
  121. static void g4x_write_infoframe(struct drm_encoder *encoder,
  122. struct dip_infoframe *frame)
  123. {
  124. uint32_t *data = (uint32_t *)frame;
  125. struct drm_device *dev = encoder->dev;
  126. struct drm_i915_private *dev_priv = dev->dev_private;
  127. u32 val = I915_READ(VIDEO_DIP_CTL);
  128. unsigned i, len = DIP_HEADER_SIZE + frame->len;
  129. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  130. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  131. val |= g4x_infoframe_index(frame);
  132. val &= ~g4x_infoframe_enable(frame);
  133. I915_WRITE(VIDEO_DIP_CTL, val);
  134. mmiowb();
  135. for (i = 0; i < len; i += 4) {
  136. I915_WRITE(VIDEO_DIP_DATA, *data);
  137. data++;
  138. }
  139. /* Write every possible data byte to force correct ECC calculation. */
  140. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  141. I915_WRITE(VIDEO_DIP_DATA, 0);
  142. mmiowb();
  143. val |= g4x_infoframe_enable(frame);
  144. val &= ~VIDEO_DIP_FREQ_MASK;
  145. val |= VIDEO_DIP_FREQ_VSYNC;
  146. I915_WRITE(VIDEO_DIP_CTL, val);
  147. POSTING_READ(VIDEO_DIP_CTL);
  148. }
  149. static void ibx_write_infoframe(struct drm_encoder *encoder,
  150. struct dip_infoframe *frame)
  151. {
  152. uint32_t *data = (uint32_t *)frame;
  153. struct drm_device *dev = encoder->dev;
  154. struct drm_i915_private *dev_priv = dev->dev_private;
  155. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  156. int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  157. unsigned i, len = DIP_HEADER_SIZE + frame->len;
  158. u32 val = I915_READ(reg);
  159. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  160. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  161. val |= g4x_infoframe_index(frame);
  162. val &= ~g4x_infoframe_enable(frame);
  163. I915_WRITE(reg, val);
  164. mmiowb();
  165. for (i = 0; i < len; i += 4) {
  166. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  167. data++;
  168. }
  169. /* Write every possible data byte to force correct ECC calculation. */
  170. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  171. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  172. mmiowb();
  173. val |= g4x_infoframe_enable(frame);
  174. val &= ~VIDEO_DIP_FREQ_MASK;
  175. val |= VIDEO_DIP_FREQ_VSYNC;
  176. I915_WRITE(reg, val);
  177. POSTING_READ(reg);
  178. }
  179. static void cpt_write_infoframe(struct drm_encoder *encoder,
  180. struct dip_infoframe *frame)
  181. {
  182. uint32_t *data = (uint32_t *)frame;
  183. struct drm_device *dev = encoder->dev;
  184. struct drm_i915_private *dev_priv = dev->dev_private;
  185. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  186. int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  187. unsigned i, len = DIP_HEADER_SIZE + frame->len;
  188. u32 val = I915_READ(reg);
  189. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  190. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  191. val |= g4x_infoframe_index(frame);
  192. /* The DIP control register spec says that we need to update the AVI
  193. * infoframe without clearing its enable bit */
  194. if (frame->type != DIP_TYPE_AVI)
  195. val &= ~g4x_infoframe_enable(frame);
  196. I915_WRITE(reg, val);
  197. mmiowb();
  198. for (i = 0; i < len; i += 4) {
  199. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  200. data++;
  201. }
  202. /* Write every possible data byte to force correct ECC calculation. */
  203. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  204. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  205. mmiowb();
  206. val |= g4x_infoframe_enable(frame);
  207. val &= ~VIDEO_DIP_FREQ_MASK;
  208. val |= VIDEO_DIP_FREQ_VSYNC;
  209. I915_WRITE(reg, val);
  210. POSTING_READ(reg);
  211. }
  212. static void vlv_write_infoframe(struct drm_encoder *encoder,
  213. struct dip_infoframe *frame)
  214. {
  215. uint32_t *data = (uint32_t *)frame;
  216. struct drm_device *dev = encoder->dev;
  217. struct drm_i915_private *dev_priv = dev->dev_private;
  218. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  219. int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
  220. unsigned i, len = DIP_HEADER_SIZE + frame->len;
  221. u32 val = I915_READ(reg);
  222. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  223. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  224. val |= g4x_infoframe_index(frame);
  225. val &= ~g4x_infoframe_enable(frame);
  226. I915_WRITE(reg, val);
  227. mmiowb();
  228. for (i = 0; i < len; i += 4) {
  229. I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  230. data++;
  231. }
  232. /* Write every possible data byte to force correct ECC calculation. */
  233. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  234. I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  235. mmiowb();
  236. val |= g4x_infoframe_enable(frame);
  237. val &= ~VIDEO_DIP_FREQ_MASK;
  238. val |= VIDEO_DIP_FREQ_VSYNC;
  239. I915_WRITE(reg, val);
  240. POSTING_READ(reg);
  241. }
  242. static void hsw_write_infoframe(struct drm_encoder *encoder,
  243. struct dip_infoframe *frame)
  244. {
  245. uint32_t *data = (uint32_t *)frame;
  246. struct drm_device *dev = encoder->dev;
  247. struct drm_i915_private *dev_priv = dev->dev_private;
  248. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  249. u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
  250. u32 data_reg = hsw_infoframe_data_reg(frame, intel_crtc->config.cpu_transcoder);
  251. unsigned int i, len = DIP_HEADER_SIZE + frame->len;
  252. u32 val = I915_READ(ctl_reg);
  253. if (data_reg == 0)
  254. return;
  255. val &= ~hsw_infoframe_enable(frame);
  256. I915_WRITE(ctl_reg, val);
  257. mmiowb();
  258. for (i = 0; i < len; i += 4) {
  259. I915_WRITE(data_reg + i, *data);
  260. data++;
  261. }
  262. /* Write every possible data byte to force correct ECC calculation. */
  263. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  264. I915_WRITE(data_reg + i, 0);
  265. mmiowb();
  266. val |= hsw_infoframe_enable(frame);
  267. I915_WRITE(ctl_reg, val);
  268. POSTING_READ(ctl_reg);
  269. }
  270. static void intel_set_infoframe(struct drm_encoder *encoder,
  271. struct dip_infoframe *frame)
  272. {
  273. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  274. intel_dip_infoframe_csum(frame);
  275. intel_hdmi->write_infoframe(encoder, frame);
  276. }
  277. static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
  278. struct drm_display_mode *adjusted_mode)
  279. {
  280. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  281. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  282. struct dip_infoframe avi_if = {
  283. .type = DIP_TYPE_AVI,
  284. .ver = DIP_VERSION_AVI,
  285. .len = DIP_LEN_AVI,
  286. };
  287. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK)
  288. avi_if.body.avi.YQ_CN_PR |= DIP_AVI_PR_2;
  289. if (intel_hdmi->rgb_quant_range_selectable) {
  290. if (intel_crtc->config.limited_color_range)
  291. avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_LIMITED;
  292. else
  293. avi_if.body.avi.ITC_EC_Q_SC |= DIP_AVI_RGB_QUANT_RANGE_FULL;
  294. }
  295. avi_if.body.avi.VIC = drm_match_cea_mode(adjusted_mode);
  296. intel_set_infoframe(encoder, &avi_if);
  297. }
  298. static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
  299. {
  300. struct dip_infoframe spd_if;
  301. memset(&spd_if, 0, sizeof(spd_if));
  302. spd_if.type = DIP_TYPE_SPD;
  303. spd_if.ver = DIP_VERSION_SPD;
  304. spd_if.len = DIP_LEN_SPD;
  305. strcpy(spd_if.body.spd.vn, "Intel");
  306. strcpy(spd_if.body.spd.pd, "Integrated gfx");
  307. spd_if.body.spd.sdi = DIP_SPD_PC;
  308. intel_set_infoframe(encoder, &spd_if);
  309. }
  310. static void g4x_set_infoframes(struct drm_encoder *encoder,
  311. struct drm_display_mode *adjusted_mode)
  312. {
  313. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  314. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  315. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  316. u32 reg = VIDEO_DIP_CTL;
  317. u32 val = I915_READ(reg);
  318. u32 port;
  319. assert_hdmi_port_disabled(intel_hdmi);
  320. /* If the registers were not initialized yet, they might be zeroes,
  321. * which means we're selecting the AVI DIP and we're setting its
  322. * frequency to once. This seems to really confuse the HW and make
  323. * things stop working (the register spec says the AVI always needs to
  324. * be sent every VSync). So here we avoid writing to the register more
  325. * than we need and also explicitly select the AVI DIP and explicitly
  326. * set its frequency to every VSync. Avoiding to write it twice seems to
  327. * be enough to solve the problem, but being defensive shouldn't hurt us
  328. * either. */
  329. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  330. if (!intel_hdmi->has_hdmi_sink) {
  331. if (!(val & VIDEO_DIP_ENABLE))
  332. return;
  333. val &= ~VIDEO_DIP_ENABLE;
  334. I915_WRITE(reg, val);
  335. POSTING_READ(reg);
  336. return;
  337. }
  338. switch (intel_dig_port->port) {
  339. case PORT_B:
  340. port = VIDEO_DIP_PORT_B;
  341. break;
  342. case PORT_C:
  343. port = VIDEO_DIP_PORT_C;
  344. break;
  345. default:
  346. BUG();
  347. return;
  348. }
  349. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  350. if (val & VIDEO_DIP_ENABLE) {
  351. val &= ~VIDEO_DIP_ENABLE;
  352. I915_WRITE(reg, val);
  353. POSTING_READ(reg);
  354. }
  355. val &= ~VIDEO_DIP_PORT_MASK;
  356. val |= port;
  357. }
  358. val |= VIDEO_DIP_ENABLE;
  359. val &= ~VIDEO_DIP_ENABLE_VENDOR;
  360. I915_WRITE(reg, val);
  361. POSTING_READ(reg);
  362. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  363. intel_hdmi_set_spd_infoframe(encoder);
  364. }
  365. static void ibx_set_infoframes(struct drm_encoder *encoder,
  366. struct drm_display_mode *adjusted_mode)
  367. {
  368. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  369. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  370. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  371. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  372. u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  373. u32 val = I915_READ(reg);
  374. u32 port;
  375. assert_hdmi_port_disabled(intel_hdmi);
  376. /* See the big comment in g4x_set_infoframes() */
  377. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  378. if (!intel_hdmi->has_hdmi_sink) {
  379. if (!(val & VIDEO_DIP_ENABLE))
  380. return;
  381. val &= ~VIDEO_DIP_ENABLE;
  382. I915_WRITE(reg, val);
  383. POSTING_READ(reg);
  384. return;
  385. }
  386. switch (intel_dig_port->port) {
  387. case PORT_B:
  388. port = VIDEO_DIP_PORT_B;
  389. break;
  390. case PORT_C:
  391. port = VIDEO_DIP_PORT_C;
  392. break;
  393. case PORT_D:
  394. port = VIDEO_DIP_PORT_D;
  395. break;
  396. default:
  397. BUG();
  398. return;
  399. }
  400. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  401. if (val & VIDEO_DIP_ENABLE) {
  402. val &= ~VIDEO_DIP_ENABLE;
  403. I915_WRITE(reg, val);
  404. POSTING_READ(reg);
  405. }
  406. val &= ~VIDEO_DIP_PORT_MASK;
  407. val |= port;
  408. }
  409. val |= VIDEO_DIP_ENABLE;
  410. val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  411. VIDEO_DIP_ENABLE_GCP);
  412. I915_WRITE(reg, val);
  413. POSTING_READ(reg);
  414. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  415. intel_hdmi_set_spd_infoframe(encoder);
  416. }
  417. static void cpt_set_infoframes(struct drm_encoder *encoder,
  418. struct drm_display_mode *adjusted_mode)
  419. {
  420. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  421. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  422. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  423. u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  424. u32 val = I915_READ(reg);
  425. assert_hdmi_port_disabled(intel_hdmi);
  426. /* See the big comment in g4x_set_infoframes() */
  427. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  428. if (!intel_hdmi->has_hdmi_sink) {
  429. if (!(val & VIDEO_DIP_ENABLE))
  430. return;
  431. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI);
  432. I915_WRITE(reg, val);
  433. POSTING_READ(reg);
  434. return;
  435. }
  436. /* Set both together, unset both together: see the spec. */
  437. val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
  438. val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  439. VIDEO_DIP_ENABLE_GCP);
  440. I915_WRITE(reg, val);
  441. POSTING_READ(reg);
  442. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  443. intel_hdmi_set_spd_infoframe(encoder);
  444. }
  445. static void vlv_set_infoframes(struct drm_encoder *encoder,
  446. struct drm_display_mode *adjusted_mode)
  447. {
  448. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  449. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  450. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  451. u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
  452. u32 val = I915_READ(reg);
  453. assert_hdmi_port_disabled(intel_hdmi);
  454. /* See the big comment in g4x_set_infoframes() */
  455. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  456. if (!intel_hdmi->has_hdmi_sink) {
  457. if (!(val & VIDEO_DIP_ENABLE))
  458. return;
  459. val &= ~VIDEO_DIP_ENABLE;
  460. I915_WRITE(reg, val);
  461. POSTING_READ(reg);
  462. return;
  463. }
  464. val |= VIDEO_DIP_ENABLE;
  465. val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  466. VIDEO_DIP_ENABLE_GCP);
  467. I915_WRITE(reg, val);
  468. POSTING_READ(reg);
  469. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  470. intel_hdmi_set_spd_infoframe(encoder);
  471. }
  472. static void hsw_set_infoframes(struct drm_encoder *encoder,
  473. struct drm_display_mode *adjusted_mode)
  474. {
  475. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  476. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  477. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  478. u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config.cpu_transcoder);
  479. u32 val = I915_READ(reg);
  480. assert_hdmi_port_disabled(intel_hdmi);
  481. if (!intel_hdmi->has_hdmi_sink) {
  482. I915_WRITE(reg, 0);
  483. POSTING_READ(reg);
  484. return;
  485. }
  486. val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_GCP_HSW |
  487. VIDEO_DIP_ENABLE_VS_HSW | VIDEO_DIP_ENABLE_GMP_HSW);
  488. I915_WRITE(reg, val);
  489. POSTING_READ(reg);
  490. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  491. intel_hdmi_set_spd_infoframe(encoder);
  492. }
  493. static void intel_hdmi_mode_set(struct drm_encoder *encoder,
  494. struct drm_display_mode *mode,
  495. struct drm_display_mode *adjusted_mode)
  496. {
  497. struct drm_device *dev = encoder->dev;
  498. struct drm_i915_private *dev_priv = dev->dev_private;
  499. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  500. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  501. u32 hdmi_val;
  502. hdmi_val = SDVO_ENCODING_HDMI;
  503. if (!HAS_PCH_SPLIT(dev) && !IS_VALLEYVIEW(dev))
  504. hdmi_val |= intel_hdmi->color_range;
  505. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  506. hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
  507. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  508. hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
  509. if (intel_crtc->config.pipe_bpp > 24)
  510. hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
  511. else
  512. hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
  513. /* Required on CPT */
  514. if (intel_hdmi->has_hdmi_sink && HAS_PCH_CPT(dev))
  515. hdmi_val |= HDMI_MODE_SELECT_HDMI;
  516. if (intel_hdmi->has_audio) {
  517. DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
  518. pipe_name(intel_crtc->pipe));
  519. hdmi_val |= SDVO_AUDIO_ENABLE;
  520. hdmi_val |= HDMI_MODE_SELECT_HDMI;
  521. intel_write_eld(encoder, adjusted_mode);
  522. }
  523. if (HAS_PCH_CPT(dev))
  524. hdmi_val |= SDVO_PIPE_SEL_CPT(intel_crtc->pipe);
  525. else
  526. hdmi_val |= SDVO_PIPE_SEL(intel_crtc->pipe);
  527. I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
  528. POSTING_READ(intel_hdmi->hdmi_reg);
  529. intel_hdmi->set_infoframes(encoder, adjusted_mode);
  530. }
  531. static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
  532. enum pipe *pipe)
  533. {
  534. struct drm_device *dev = encoder->base.dev;
  535. struct drm_i915_private *dev_priv = dev->dev_private;
  536. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  537. u32 tmp;
  538. tmp = I915_READ(intel_hdmi->hdmi_reg);
  539. if (!(tmp & SDVO_ENABLE))
  540. return false;
  541. if (HAS_PCH_CPT(dev))
  542. *pipe = PORT_TO_PIPE_CPT(tmp);
  543. else
  544. *pipe = PORT_TO_PIPE(tmp);
  545. return true;
  546. }
  547. static void intel_enable_hdmi(struct intel_encoder *encoder)
  548. {
  549. struct drm_device *dev = encoder->base.dev;
  550. struct drm_i915_private *dev_priv = dev->dev_private;
  551. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  552. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  553. u32 temp;
  554. u32 enable_bits = SDVO_ENABLE;
  555. if (intel_hdmi->has_audio)
  556. enable_bits |= SDVO_AUDIO_ENABLE;
  557. temp = I915_READ(intel_hdmi->hdmi_reg);
  558. /* HW workaround for IBX, we need to move the port to transcoder A
  559. * before disabling it, so restore the transcoder select bit here. */
  560. if (HAS_PCH_IBX(dev))
  561. enable_bits |= SDVO_PIPE_SEL(intel_crtc->pipe);
  562. /* HW workaround, need to toggle enable bit off and on for 12bpc, but
  563. * we do this anyway which shows more stable in testing.
  564. */
  565. if (HAS_PCH_SPLIT(dev)) {
  566. I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
  567. POSTING_READ(intel_hdmi->hdmi_reg);
  568. }
  569. temp |= enable_bits;
  570. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  571. POSTING_READ(intel_hdmi->hdmi_reg);
  572. /* HW workaround, need to write this twice for issue that may result
  573. * in first write getting masked.
  574. */
  575. if (HAS_PCH_SPLIT(dev)) {
  576. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  577. POSTING_READ(intel_hdmi->hdmi_reg);
  578. }
  579. if (IS_VALLEYVIEW(dev)) {
  580. struct intel_digital_port *dport =
  581. enc_to_dig_port(&encoder->base);
  582. int channel = vlv_dport_to_channel(dport);
  583. vlv_wait_port_ready(dev_priv, channel);
  584. }
  585. }
  586. static void intel_disable_hdmi(struct intel_encoder *encoder)
  587. {
  588. struct drm_device *dev = encoder->base.dev;
  589. struct drm_i915_private *dev_priv = dev->dev_private;
  590. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  591. u32 temp;
  592. u32 enable_bits = SDVO_ENABLE | SDVO_AUDIO_ENABLE;
  593. temp = I915_READ(intel_hdmi->hdmi_reg);
  594. /* HW workaround for IBX, we need to move the port to transcoder A
  595. * before disabling it. */
  596. if (HAS_PCH_IBX(dev)) {
  597. struct drm_crtc *crtc = encoder->base.crtc;
  598. int pipe = crtc ? to_intel_crtc(crtc)->pipe : -1;
  599. if (temp & SDVO_PIPE_B_SELECT) {
  600. temp &= ~SDVO_PIPE_B_SELECT;
  601. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  602. POSTING_READ(intel_hdmi->hdmi_reg);
  603. /* Again we need to write this twice. */
  604. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  605. POSTING_READ(intel_hdmi->hdmi_reg);
  606. /* Transcoder selection bits only update
  607. * effectively on vblank. */
  608. if (crtc)
  609. intel_wait_for_vblank(dev, pipe);
  610. else
  611. msleep(50);
  612. }
  613. }
  614. /* HW workaround, need to toggle enable bit off and on for 12bpc, but
  615. * we do this anyway which shows more stable in testing.
  616. */
  617. if (HAS_PCH_SPLIT(dev)) {
  618. I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
  619. POSTING_READ(intel_hdmi->hdmi_reg);
  620. }
  621. temp &= ~enable_bits;
  622. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  623. POSTING_READ(intel_hdmi->hdmi_reg);
  624. /* HW workaround, need to write this twice for issue that may result
  625. * in first write getting masked.
  626. */
  627. if (HAS_PCH_SPLIT(dev)) {
  628. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  629. POSTING_READ(intel_hdmi->hdmi_reg);
  630. }
  631. }
  632. static int intel_hdmi_mode_valid(struct drm_connector *connector,
  633. struct drm_display_mode *mode)
  634. {
  635. if (mode->clock > 165000)
  636. return MODE_CLOCK_HIGH;
  637. if (mode->clock < 20000)
  638. return MODE_CLOCK_LOW;
  639. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  640. return MODE_NO_DBLESCAN;
  641. return MODE_OK;
  642. }
  643. bool intel_hdmi_compute_config(struct intel_encoder *encoder,
  644. struct intel_crtc_config *pipe_config)
  645. {
  646. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  647. struct drm_device *dev = encoder->base.dev;
  648. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  649. if (intel_hdmi->color_range_auto) {
  650. /* See CEA-861-E - 5.1 Default Encoding Parameters */
  651. if (intel_hdmi->has_hdmi_sink &&
  652. drm_match_cea_mode(adjusted_mode) > 1)
  653. intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
  654. else
  655. intel_hdmi->color_range = 0;
  656. }
  657. if (intel_hdmi->color_range)
  658. pipe_config->limited_color_range = true;
  659. if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
  660. pipe_config->has_pch_encoder = true;
  661. /*
  662. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  663. * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
  664. * outputs.
  665. */
  666. if (pipe_config->pipe_bpp > 8*3 && HAS_PCH_SPLIT(dev)) {
  667. DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
  668. pipe_config->pipe_bpp = 12*3;
  669. } else {
  670. DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
  671. pipe_config->pipe_bpp = 8*3;
  672. }
  673. return true;
  674. }
  675. static enum drm_connector_status
  676. intel_hdmi_detect(struct drm_connector *connector, bool force)
  677. {
  678. struct drm_device *dev = connector->dev;
  679. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  680. struct intel_digital_port *intel_dig_port =
  681. hdmi_to_dig_port(intel_hdmi);
  682. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  683. struct drm_i915_private *dev_priv = dev->dev_private;
  684. struct edid *edid;
  685. enum drm_connector_status status = connector_status_disconnected;
  686. intel_hdmi->has_hdmi_sink = false;
  687. intel_hdmi->has_audio = false;
  688. intel_hdmi->rgb_quant_range_selectable = false;
  689. edid = drm_get_edid(connector,
  690. intel_gmbus_get_adapter(dev_priv,
  691. intel_hdmi->ddc_bus));
  692. if (edid) {
  693. if (edid->input & DRM_EDID_INPUT_DIGITAL) {
  694. status = connector_status_connected;
  695. if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
  696. intel_hdmi->has_hdmi_sink =
  697. drm_detect_hdmi_monitor(edid);
  698. intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
  699. intel_hdmi->rgb_quant_range_selectable =
  700. drm_rgb_quant_range_selectable(edid);
  701. }
  702. kfree(edid);
  703. }
  704. if (status == connector_status_connected) {
  705. if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
  706. intel_hdmi->has_audio =
  707. (intel_hdmi->force_audio == HDMI_AUDIO_ON);
  708. intel_encoder->type = INTEL_OUTPUT_HDMI;
  709. }
  710. return status;
  711. }
  712. static int intel_hdmi_get_modes(struct drm_connector *connector)
  713. {
  714. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  715. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  716. /* We should parse the EDID data and find out if it's an HDMI sink so
  717. * we can send audio to it.
  718. */
  719. return intel_ddc_get_modes(connector,
  720. intel_gmbus_get_adapter(dev_priv,
  721. intel_hdmi->ddc_bus));
  722. }
  723. static bool
  724. intel_hdmi_detect_audio(struct drm_connector *connector)
  725. {
  726. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  727. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  728. struct edid *edid;
  729. bool has_audio = false;
  730. edid = drm_get_edid(connector,
  731. intel_gmbus_get_adapter(dev_priv,
  732. intel_hdmi->ddc_bus));
  733. if (edid) {
  734. if (edid->input & DRM_EDID_INPUT_DIGITAL)
  735. has_audio = drm_detect_monitor_audio(edid);
  736. kfree(edid);
  737. }
  738. return has_audio;
  739. }
  740. static int
  741. intel_hdmi_set_property(struct drm_connector *connector,
  742. struct drm_property *property,
  743. uint64_t val)
  744. {
  745. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  746. struct intel_digital_port *intel_dig_port =
  747. hdmi_to_dig_port(intel_hdmi);
  748. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  749. int ret;
  750. ret = drm_object_property_set_value(&connector->base, property, val);
  751. if (ret)
  752. return ret;
  753. if (property == dev_priv->force_audio_property) {
  754. enum hdmi_force_audio i = val;
  755. bool has_audio;
  756. if (i == intel_hdmi->force_audio)
  757. return 0;
  758. intel_hdmi->force_audio = i;
  759. if (i == HDMI_AUDIO_AUTO)
  760. has_audio = intel_hdmi_detect_audio(connector);
  761. else
  762. has_audio = (i == HDMI_AUDIO_ON);
  763. if (i == HDMI_AUDIO_OFF_DVI)
  764. intel_hdmi->has_hdmi_sink = 0;
  765. intel_hdmi->has_audio = has_audio;
  766. goto done;
  767. }
  768. if (property == dev_priv->broadcast_rgb_property) {
  769. switch (val) {
  770. case INTEL_BROADCAST_RGB_AUTO:
  771. intel_hdmi->color_range_auto = true;
  772. break;
  773. case INTEL_BROADCAST_RGB_FULL:
  774. intel_hdmi->color_range_auto = false;
  775. intel_hdmi->color_range = 0;
  776. break;
  777. case INTEL_BROADCAST_RGB_LIMITED:
  778. intel_hdmi->color_range_auto = false;
  779. intel_hdmi->color_range = HDMI_COLOR_RANGE_16_235;
  780. break;
  781. default:
  782. return -EINVAL;
  783. }
  784. goto done;
  785. }
  786. return -EINVAL;
  787. done:
  788. if (intel_dig_port->base.base.crtc)
  789. intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
  790. return 0;
  791. }
  792. static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
  793. {
  794. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  795. struct drm_device *dev = encoder->base.dev;
  796. struct drm_i915_private *dev_priv = dev->dev_private;
  797. struct intel_crtc *intel_crtc =
  798. to_intel_crtc(encoder->base.crtc);
  799. int port = vlv_dport_to_channel(dport);
  800. int pipe = intel_crtc->pipe;
  801. u32 val;
  802. if (!IS_VALLEYVIEW(dev))
  803. return;
  804. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  805. /* Enable clock channels for this port */
  806. val = intel_dpio_read(dev_priv, DPIO_DATA_LANE_A(port));
  807. val = 0;
  808. if (pipe)
  809. val |= (1<<21);
  810. else
  811. val &= ~(1<<21);
  812. val |= 0x001000c4;
  813. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL(port), val);
  814. /* HDMI 1.0V-2dB */
  815. intel_dpio_write(dev_priv, DPIO_TX_OCALINIT(port), 0);
  816. intel_dpio_write(dev_priv, DPIO_TX_SWING_CTL4(port),
  817. 0x2b245f5f);
  818. intel_dpio_write(dev_priv, DPIO_TX_SWING_CTL2(port),
  819. 0x5578b83a);
  820. intel_dpio_write(dev_priv, DPIO_TX_SWING_CTL3(port),
  821. 0x0c782040);
  822. intel_dpio_write(dev_priv, DPIO_TX3_SWING_CTL4(port),
  823. 0x2b247878);
  824. intel_dpio_write(dev_priv, DPIO_PCS_STAGGER0(port), 0x00030000);
  825. intel_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
  826. 0x00002000);
  827. intel_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
  828. DPIO_TX_OCALINIT_EN);
  829. /* Program lane clock */
  830. intel_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF0(port),
  831. 0x00760018);
  832. intel_dpio_write(dev_priv, DPIO_PCS_CLOCKBUF8(port),
  833. 0x00400888);
  834. }
  835. static void intel_hdmi_pre_pll_enable(struct intel_encoder *encoder)
  836. {
  837. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  838. struct drm_device *dev = encoder->base.dev;
  839. struct drm_i915_private *dev_priv = dev->dev_private;
  840. int port = vlv_dport_to_channel(dport);
  841. if (!IS_VALLEYVIEW(dev))
  842. return;
  843. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  844. /* Program Tx lane resets to default */
  845. intel_dpio_write(dev_priv, DPIO_PCS_TX(port),
  846. DPIO_PCS_TX_LANE2_RESET |
  847. DPIO_PCS_TX_LANE1_RESET);
  848. intel_dpio_write(dev_priv, DPIO_PCS_CLK(port),
  849. DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
  850. DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
  851. (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
  852. DPIO_PCS_CLK_SOFT_RESET);
  853. /* Fix up inter-pair skew failure */
  854. intel_dpio_write(dev_priv, DPIO_PCS_STAGGER1(port), 0x00750f00);
  855. intel_dpio_write(dev_priv, DPIO_TX_CTL(port), 0x00001500);
  856. intel_dpio_write(dev_priv, DPIO_TX_LANE(port), 0x40400000);
  857. intel_dpio_write(dev_priv, DPIO_PCS_CTL_OVER1(port),
  858. 0x00002000);
  859. intel_dpio_write(dev_priv, DPIO_TX_OCALINIT(port),
  860. DPIO_TX_OCALINIT_EN);
  861. }
  862. static void intel_hdmi_post_disable(struct intel_encoder *encoder)
  863. {
  864. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  865. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  866. int port = vlv_dport_to_channel(dport);
  867. /* Reset lanes to avoid HDMI flicker (VLV w/a) */
  868. mutex_lock(&dev_priv->dpio_lock);
  869. intel_dpio_write(dev_priv, DPIO_PCS_TX(port), 0x00000000);
  870. intel_dpio_write(dev_priv, DPIO_PCS_CLK(port), 0x00e00060);
  871. mutex_unlock(&dev_priv->dpio_lock);
  872. }
  873. static void intel_hdmi_destroy(struct drm_connector *connector)
  874. {
  875. drm_sysfs_connector_remove(connector);
  876. drm_connector_cleanup(connector);
  877. kfree(connector);
  878. }
  879. static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = {
  880. .mode_set = intel_hdmi_mode_set,
  881. };
  882. static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
  883. .dpms = intel_connector_dpms,
  884. .detect = intel_hdmi_detect,
  885. .fill_modes = drm_helper_probe_single_connector_modes,
  886. .set_property = intel_hdmi_set_property,
  887. .destroy = intel_hdmi_destroy,
  888. };
  889. static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
  890. .get_modes = intel_hdmi_get_modes,
  891. .mode_valid = intel_hdmi_mode_valid,
  892. .best_encoder = intel_best_encoder,
  893. };
  894. static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
  895. .destroy = intel_encoder_destroy,
  896. };
  897. static void
  898. intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
  899. {
  900. intel_attach_force_audio_property(connector);
  901. intel_attach_broadcast_rgb_property(connector);
  902. intel_hdmi->color_range_auto = true;
  903. }
  904. void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
  905. struct intel_connector *intel_connector)
  906. {
  907. struct drm_connector *connector = &intel_connector->base;
  908. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  909. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  910. struct drm_device *dev = intel_encoder->base.dev;
  911. struct drm_i915_private *dev_priv = dev->dev_private;
  912. enum port port = intel_dig_port->port;
  913. drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
  914. DRM_MODE_CONNECTOR_HDMIA);
  915. drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
  916. connector->interlace_allowed = 1;
  917. connector->doublescan_allowed = 0;
  918. switch (port) {
  919. case PORT_B:
  920. intel_hdmi->ddc_bus = GMBUS_PORT_DPB;
  921. intel_encoder->hpd_pin = HPD_PORT_B;
  922. break;
  923. case PORT_C:
  924. intel_hdmi->ddc_bus = GMBUS_PORT_DPC;
  925. intel_encoder->hpd_pin = HPD_PORT_C;
  926. break;
  927. case PORT_D:
  928. intel_hdmi->ddc_bus = GMBUS_PORT_DPD;
  929. intel_encoder->hpd_pin = HPD_PORT_D;
  930. break;
  931. case PORT_A:
  932. intel_encoder->hpd_pin = HPD_PORT_A;
  933. /* Internal port only for eDP. */
  934. default:
  935. BUG();
  936. }
  937. if (IS_VALLEYVIEW(dev)) {
  938. intel_hdmi->write_infoframe = vlv_write_infoframe;
  939. intel_hdmi->set_infoframes = vlv_set_infoframes;
  940. } else if (!HAS_PCH_SPLIT(dev)) {
  941. intel_hdmi->write_infoframe = g4x_write_infoframe;
  942. intel_hdmi->set_infoframes = g4x_set_infoframes;
  943. } else if (HAS_DDI(dev)) {
  944. intel_hdmi->write_infoframe = hsw_write_infoframe;
  945. intel_hdmi->set_infoframes = hsw_set_infoframes;
  946. } else if (HAS_PCH_IBX(dev)) {
  947. intel_hdmi->write_infoframe = ibx_write_infoframe;
  948. intel_hdmi->set_infoframes = ibx_set_infoframes;
  949. } else {
  950. intel_hdmi->write_infoframe = cpt_write_infoframe;
  951. intel_hdmi->set_infoframes = cpt_set_infoframes;
  952. }
  953. if (HAS_DDI(dev))
  954. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  955. else
  956. intel_connector->get_hw_state = intel_connector_get_hw_state;
  957. intel_hdmi_add_properties(intel_hdmi, connector);
  958. intel_connector_attach_encoder(intel_connector, intel_encoder);
  959. drm_sysfs_connector_add(connector);
  960. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  961. * 0xd. Failure to do so will result in spurious interrupts being
  962. * generated on the port when a cable is not attached.
  963. */
  964. if (IS_G4X(dev) && !IS_GM45(dev)) {
  965. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  966. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  967. }
  968. }
  969. void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
  970. {
  971. struct intel_digital_port *intel_dig_port;
  972. struct intel_encoder *intel_encoder;
  973. struct drm_encoder *encoder;
  974. struct intel_connector *intel_connector;
  975. intel_dig_port = kzalloc(sizeof(struct intel_digital_port), GFP_KERNEL);
  976. if (!intel_dig_port)
  977. return;
  978. intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
  979. if (!intel_connector) {
  980. kfree(intel_dig_port);
  981. return;
  982. }
  983. intel_encoder = &intel_dig_port->base;
  984. encoder = &intel_encoder->base;
  985. drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
  986. DRM_MODE_ENCODER_TMDS);
  987. drm_encoder_helper_add(&intel_encoder->base, &intel_hdmi_helper_funcs);
  988. intel_encoder->compute_config = intel_hdmi_compute_config;
  989. intel_encoder->enable = intel_enable_hdmi;
  990. intel_encoder->disable = intel_disable_hdmi;
  991. intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
  992. if (IS_VALLEYVIEW(dev)) {
  993. intel_encoder->pre_enable = intel_hdmi_pre_enable;
  994. intel_encoder->pre_pll_enable = intel_hdmi_pre_pll_enable;
  995. intel_encoder->post_disable = intel_hdmi_post_disable;
  996. }
  997. intel_encoder->type = INTEL_OUTPUT_HDMI;
  998. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  999. intel_encoder->cloneable = false;
  1000. intel_dig_port->port = port;
  1001. intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
  1002. intel_dig_port->dp.output_reg = 0;
  1003. intel_hdmi_init_connector(intel_dig_port, intel_connector);
  1004. }