intel_hdmi.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210
  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 "intel_drv.h"
  37. #include <drm/i915_drm.h>
  38. #include "i915_drv.h"
  39. static struct drm_device *intel_hdmi_to_dev(struct intel_hdmi *intel_hdmi)
  40. {
  41. return hdmi_to_dig_port(intel_hdmi)->base.base.dev;
  42. }
  43. static void
  44. assert_hdmi_port_disabled(struct intel_hdmi *intel_hdmi)
  45. {
  46. struct drm_device *dev = intel_hdmi_to_dev(intel_hdmi);
  47. struct drm_i915_private *dev_priv = dev->dev_private;
  48. uint32_t enabled_bits;
  49. enabled_bits = HAS_DDI(dev) ? DDI_BUF_CTL_ENABLE : SDVO_ENABLE;
  50. WARN(I915_READ(intel_hdmi->hdmi_reg) & enabled_bits,
  51. "HDMI port enabled, expecting disabled\n");
  52. }
  53. struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder)
  54. {
  55. struct intel_digital_port *intel_dig_port =
  56. container_of(encoder, struct intel_digital_port, base.base);
  57. return &intel_dig_port->hdmi;
  58. }
  59. static struct intel_hdmi *intel_attached_hdmi(struct drm_connector *connector)
  60. {
  61. return enc_to_intel_hdmi(&intel_attached_encoder(connector)->base);
  62. }
  63. static u32 g4x_infoframe_index(enum hdmi_infoframe_type type)
  64. {
  65. switch (type) {
  66. case HDMI_INFOFRAME_TYPE_AVI:
  67. return VIDEO_DIP_SELECT_AVI;
  68. case HDMI_INFOFRAME_TYPE_SPD:
  69. return VIDEO_DIP_SELECT_SPD;
  70. case HDMI_INFOFRAME_TYPE_VENDOR:
  71. return VIDEO_DIP_SELECT_VENDOR;
  72. default:
  73. DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
  74. return 0;
  75. }
  76. }
  77. static u32 g4x_infoframe_enable(enum hdmi_infoframe_type type)
  78. {
  79. switch (type) {
  80. case HDMI_INFOFRAME_TYPE_AVI:
  81. return VIDEO_DIP_ENABLE_AVI;
  82. case HDMI_INFOFRAME_TYPE_SPD:
  83. return VIDEO_DIP_ENABLE_SPD;
  84. case HDMI_INFOFRAME_TYPE_VENDOR:
  85. return VIDEO_DIP_ENABLE_VENDOR;
  86. default:
  87. DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
  88. return 0;
  89. }
  90. }
  91. static u32 hsw_infoframe_enable(enum hdmi_infoframe_type type)
  92. {
  93. switch (type) {
  94. case HDMI_INFOFRAME_TYPE_AVI:
  95. return VIDEO_DIP_ENABLE_AVI_HSW;
  96. case HDMI_INFOFRAME_TYPE_SPD:
  97. return VIDEO_DIP_ENABLE_SPD_HSW;
  98. case HDMI_INFOFRAME_TYPE_VENDOR:
  99. return VIDEO_DIP_ENABLE_VS_HSW;
  100. default:
  101. DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
  102. return 0;
  103. }
  104. }
  105. static u32 hsw_dip_data_reg(struct drm_i915_private *dev_priv,
  106. enum transcoder cpu_transcoder,
  107. enum hdmi_infoframe_type type,
  108. int i)
  109. {
  110. switch (type) {
  111. case HDMI_INFOFRAME_TYPE_AVI:
  112. return HSW_TVIDEO_DIP_AVI_DATA(cpu_transcoder, i);
  113. case HDMI_INFOFRAME_TYPE_SPD:
  114. return HSW_TVIDEO_DIP_SPD_DATA(cpu_transcoder, i);
  115. case HDMI_INFOFRAME_TYPE_VENDOR:
  116. return HSW_TVIDEO_DIP_VS_DATA(cpu_transcoder, i);
  117. default:
  118. DRM_DEBUG_DRIVER("unknown info frame type %d\n", type);
  119. return 0;
  120. }
  121. }
  122. static void g4x_write_infoframe(struct drm_encoder *encoder,
  123. enum hdmi_infoframe_type type,
  124. const void *frame, ssize_t len)
  125. {
  126. const uint32_t *data = frame;
  127. struct drm_device *dev = encoder->dev;
  128. struct drm_i915_private *dev_priv = dev->dev_private;
  129. u32 val = I915_READ(VIDEO_DIP_CTL);
  130. int i;
  131. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  132. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  133. val |= g4x_infoframe_index(type);
  134. val &= ~g4x_infoframe_enable(type);
  135. I915_WRITE(VIDEO_DIP_CTL, val);
  136. mmiowb();
  137. for (i = 0; i < len; i += 4) {
  138. I915_WRITE(VIDEO_DIP_DATA, *data);
  139. data++;
  140. }
  141. /* Write every possible data byte to force correct ECC calculation. */
  142. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  143. I915_WRITE(VIDEO_DIP_DATA, 0);
  144. mmiowb();
  145. val |= g4x_infoframe_enable(type);
  146. val &= ~VIDEO_DIP_FREQ_MASK;
  147. val |= VIDEO_DIP_FREQ_VSYNC;
  148. I915_WRITE(VIDEO_DIP_CTL, val);
  149. POSTING_READ(VIDEO_DIP_CTL);
  150. }
  151. static bool g4x_infoframe_enabled(struct drm_encoder *encoder)
  152. {
  153. struct drm_device *dev = encoder->dev;
  154. struct drm_i915_private *dev_priv = dev->dev_private;
  155. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  156. u32 val = I915_READ(VIDEO_DIP_CTL);
  157. if ((val & VIDEO_DIP_ENABLE) == 0)
  158. return false;
  159. if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
  160. return false;
  161. return val & (VIDEO_DIP_ENABLE_AVI |
  162. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
  163. }
  164. static void ibx_write_infoframe(struct drm_encoder *encoder,
  165. enum hdmi_infoframe_type type,
  166. const void *frame, ssize_t len)
  167. {
  168. const uint32_t *data = frame;
  169. struct drm_device *dev = encoder->dev;
  170. struct drm_i915_private *dev_priv = dev->dev_private;
  171. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  172. int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  173. u32 val = I915_READ(reg);
  174. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  175. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  176. val |= g4x_infoframe_index(type);
  177. val &= ~g4x_infoframe_enable(type);
  178. I915_WRITE(reg, val);
  179. mmiowb();
  180. for (i = 0; i < len; i += 4) {
  181. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  182. data++;
  183. }
  184. /* Write every possible data byte to force correct ECC calculation. */
  185. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  186. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  187. mmiowb();
  188. val |= g4x_infoframe_enable(type);
  189. val &= ~VIDEO_DIP_FREQ_MASK;
  190. val |= VIDEO_DIP_FREQ_VSYNC;
  191. I915_WRITE(reg, val);
  192. POSTING_READ(reg);
  193. }
  194. static bool ibx_infoframe_enabled(struct drm_encoder *encoder)
  195. {
  196. struct drm_device *dev = encoder->dev;
  197. struct drm_i915_private *dev_priv = dev->dev_private;
  198. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  199. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  200. int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  201. u32 val = I915_READ(reg);
  202. if ((val & VIDEO_DIP_ENABLE) == 0)
  203. return false;
  204. if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
  205. return false;
  206. return val & (VIDEO_DIP_ENABLE_AVI |
  207. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  208. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  209. }
  210. static void cpt_write_infoframe(struct drm_encoder *encoder,
  211. enum hdmi_infoframe_type type,
  212. const void *frame, ssize_t len)
  213. {
  214. const uint32_t *data = frame;
  215. struct drm_device *dev = encoder->dev;
  216. struct drm_i915_private *dev_priv = dev->dev_private;
  217. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  218. int i, reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  219. u32 val = I915_READ(reg);
  220. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  221. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  222. val |= g4x_infoframe_index(type);
  223. /* The DIP control register spec says that we need to update the AVI
  224. * infoframe without clearing its enable bit */
  225. if (type != HDMI_INFOFRAME_TYPE_AVI)
  226. val &= ~g4x_infoframe_enable(type);
  227. I915_WRITE(reg, val);
  228. mmiowb();
  229. for (i = 0; i < len; i += 4) {
  230. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  231. data++;
  232. }
  233. /* Write every possible data byte to force correct ECC calculation. */
  234. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  235. I915_WRITE(TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  236. mmiowb();
  237. val |= g4x_infoframe_enable(type);
  238. val &= ~VIDEO_DIP_FREQ_MASK;
  239. val |= VIDEO_DIP_FREQ_VSYNC;
  240. I915_WRITE(reg, val);
  241. POSTING_READ(reg);
  242. }
  243. static bool cpt_infoframe_enabled(struct drm_encoder *encoder)
  244. {
  245. struct drm_device *dev = encoder->dev;
  246. struct drm_i915_private *dev_priv = dev->dev_private;
  247. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  248. int reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  249. u32 val = I915_READ(reg);
  250. if ((val & VIDEO_DIP_ENABLE) == 0)
  251. return false;
  252. return val & (VIDEO_DIP_ENABLE_AVI |
  253. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  254. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  255. }
  256. static void vlv_write_infoframe(struct drm_encoder *encoder,
  257. enum hdmi_infoframe_type type,
  258. const void *frame, ssize_t len)
  259. {
  260. const uint32_t *data = frame;
  261. struct drm_device *dev = encoder->dev;
  262. struct drm_i915_private *dev_priv = dev->dev_private;
  263. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  264. int i, reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
  265. u32 val = I915_READ(reg);
  266. WARN(!(val & VIDEO_DIP_ENABLE), "Writing DIP with CTL reg disabled\n");
  267. val &= ~(VIDEO_DIP_SELECT_MASK | 0xf); /* clear DIP data offset */
  268. val |= g4x_infoframe_index(type);
  269. val &= ~g4x_infoframe_enable(type);
  270. I915_WRITE(reg, val);
  271. mmiowb();
  272. for (i = 0; i < len; i += 4) {
  273. I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), *data);
  274. data++;
  275. }
  276. /* Write every possible data byte to force correct ECC calculation. */
  277. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  278. I915_WRITE(VLV_TVIDEO_DIP_DATA(intel_crtc->pipe), 0);
  279. mmiowb();
  280. val |= g4x_infoframe_enable(type);
  281. val &= ~VIDEO_DIP_FREQ_MASK;
  282. val |= VIDEO_DIP_FREQ_VSYNC;
  283. I915_WRITE(reg, val);
  284. POSTING_READ(reg);
  285. }
  286. static bool vlv_infoframe_enabled(struct drm_encoder *encoder)
  287. {
  288. struct drm_device *dev = encoder->dev;
  289. struct drm_i915_private *dev_priv = dev->dev_private;
  290. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  291. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  292. int reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
  293. u32 val = I915_READ(reg);
  294. if ((val & VIDEO_DIP_ENABLE) == 0)
  295. return false;
  296. if ((val & VIDEO_DIP_PORT_MASK) != VIDEO_DIP_PORT(intel_dig_port->port))
  297. return false;
  298. return val & (VIDEO_DIP_ENABLE_AVI |
  299. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  300. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  301. }
  302. static void hsw_write_infoframe(struct drm_encoder *encoder,
  303. enum hdmi_infoframe_type type,
  304. const void *frame, ssize_t len)
  305. {
  306. const uint32_t *data = frame;
  307. struct drm_device *dev = encoder->dev;
  308. struct drm_i915_private *dev_priv = dev->dev_private;
  309. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  310. enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder;
  311. u32 ctl_reg = HSW_TVIDEO_DIP_CTL(cpu_transcoder);
  312. u32 data_reg;
  313. int i;
  314. u32 val = I915_READ(ctl_reg);
  315. data_reg = hsw_dip_data_reg(dev_priv, cpu_transcoder, type, 0);
  316. if (data_reg == 0)
  317. return;
  318. val &= ~hsw_infoframe_enable(type);
  319. I915_WRITE(ctl_reg, val);
  320. mmiowb();
  321. for (i = 0; i < len; i += 4) {
  322. I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
  323. type, i >> 2), *data);
  324. data++;
  325. }
  326. /* Write every possible data byte to force correct ECC calculation. */
  327. for (; i < VIDEO_DIP_DATA_SIZE; i += 4)
  328. I915_WRITE(hsw_dip_data_reg(dev_priv, cpu_transcoder,
  329. type, i >> 2), 0);
  330. mmiowb();
  331. val |= hsw_infoframe_enable(type);
  332. I915_WRITE(ctl_reg, val);
  333. POSTING_READ(ctl_reg);
  334. }
  335. static bool hsw_infoframe_enabled(struct drm_encoder *encoder)
  336. {
  337. struct drm_device *dev = encoder->dev;
  338. struct drm_i915_private *dev_priv = dev->dev_private;
  339. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  340. u32 ctl_reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
  341. u32 val = I915_READ(ctl_reg);
  342. return val & (VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
  343. VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
  344. VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
  345. }
  346. /*
  347. * The data we write to the DIP data buffer registers is 1 byte bigger than the
  348. * HDMI infoframe size because of an ECC/reserved byte at position 3 (starting
  349. * at 0). It's also a byte used by DisplayPort so the same DIP registers can be
  350. * used for both technologies.
  351. *
  352. * DW0: Reserved/ECC/DP | HB2 | HB1 | HB0
  353. * DW1: DB3 | DB2 | DB1 | DB0
  354. * DW2: DB7 | DB6 | DB5 | DB4
  355. * DW3: ...
  356. *
  357. * (HB is Header Byte, DB is Data Byte)
  358. *
  359. * The hdmi pack() functions don't know about that hardware specific hole so we
  360. * trick them by giving an offset into the buffer and moving back the header
  361. * bytes by one.
  362. */
  363. static void intel_write_infoframe(struct drm_encoder *encoder,
  364. union hdmi_infoframe *frame)
  365. {
  366. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  367. uint8_t buffer[VIDEO_DIP_DATA_SIZE];
  368. ssize_t len;
  369. /* see comment above for the reason for this offset */
  370. len = hdmi_infoframe_pack(frame, buffer + 1, sizeof(buffer) - 1);
  371. if (len < 0)
  372. return;
  373. /* Insert the 'hole' (see big comment above) at position 3 */
  374. buffer[0] = buffer[1];
  375. buffer[1] = buffer[2];
  376. buffer[2] = buffer[3];
  377. buffer[3] = 0;
  378. len++;
  379. intel_hdmi->write_infoframe(encoder, frame->any.type, buffer, len);
  380. }
  381. static void intel_hdmi_set_avi_infoframe(struct drm_encoder *encoder,
  382. const struct drm_display_mode *adjusted_mode)
  383. {
  384. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  385. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  386. union hdmi_infoframe frame;
  387. int ret;
  388. ret = drm_hdmi_avi_infoframe_from_display_mode(&frame.avi,
  389. adjusted_mode);
  390. if (ret < 0) {
  391. DRM_ERROR("couldn't fill AVI infoframe\n");
  392. return;
  393. }
  394. if (intel_hdmi->rgb_quant_range_selectable) {
  395. if (intel_crtc->config->limited_color_range)
  396. frame.avi.quantization_range =
  397. HDMI_QUANTIZATION_RANGE_LIMITED;
  398. else
  399. frame.avi.quantization_range =
  400. HDMI_QUANTIZATION_RANGE_FULL;
  401. }
  402. intel_write_infoframe(encoder, &frame);
  403. }
  404. static void intel_hdmi_set_spd_infoframe(struct drm_encoder *encoder)
  405. {
  406. union hdmi_infoframe frame;
  407. int ret;
  408. ret = hdmi_spd_infoframe_init(&frame.spd, "Intel", "Integrated gfx");
  409. if (ret < 0) {
  410. DRM_ERROR("couldn't fill SPD infoframe\n");
  411. return;
  412. }
  413. frame.spd.sdi = HDMI_SPD_SDI_PC;
  414. intel_write_infoframe(encoder, &frame);
  415. }
  416. static void
  417. intel_hdmi_set_hdmi_infoframe(struct drm_encoder *encoder,
  418. const struct drm_display_mode *adjusted_mode)
  419. {
  420. union hdmi_infoframe frame;
  421. int ret;
  422. ret = drm_hdmi_vendor_infoframe_from_display_mode(&frame.vendor.hdmi,
  423. adjusted_mode);
  424. if (ret < 0)
  425. return;
  426. intel_write_infoframe(encoder, &frame);
  427. }
  428. static void g4x_set_infoframes(struct drm_encoder *encoder,
  429. bool enable,
  430. const struct drm_display_mode *adjusted_mode)
  431. {
  432. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  433. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  434. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  435. u32 reg = VIDEO_DIP_CTL;
  436. u32 val = I915_READ(reg);
  437. u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
  438. assert_hdmi_port_disabled(intel_hdmi);
  439. /* If the registers were not initialized yet, they might be zeroes,
  440. * which means we're selecting the AVI DIP and we're setting its
  441. * frequency to once. This seems to really confuse the HW and make
  442. * things stop working (the register spec says the AVI always needs to
  443. * be sent every VSync). So here we avoid writing to the register more
  444. * than we need and also explicitly select the AVI DIP and explicitly
  445. * set its frequency to every VSync. Avoiding to write it twice seems to
  446. * be enough to solve the problem, but being defensive shouldn't hurt us
  447. * either. */
  448. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  449. if (!enable) {
  450. if (!(val & VIDEO_DIP_ENABLE))
  451. return;
  452. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  453. DRM_DEBUG_KMS("video DIP still enabled on port %c\n",
  454. (val & VIDEO_DIP_PORT_MASK) >> 29);
  455. return;
  456. }
  457. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  458. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
  459. I915_WRITE(reg, val);
  460. POSTING_READ(reg);
  461. return;
  462. }
  463. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  464. if (val & VIDEO_DIP_ENABLE) {
  465. DRM_DEBUG_KMS("video DIP already enabled on port %c\n",
  466. (val & VIDEO_DIP_PORT_MASK) >> 29);
  467. return;
  468. }
  469. val &= ~VIDEO_DIP_PORT_MASK;
  470. val |= port;
  471. }
  472. val |= VIDEO_DIP_ENABLE;
  473. val &= ~(VIDEO_DIP_ENABLE_AVI |
  474. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_SPD);
  475. I915_WRITE(reg, val);
  476. POSTING_READ(reg);
  477. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  478. intel_hdmi_set_spd_infoframe(encoder);
  479. intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
  480. }
  481. static bool hdmi_sink_is_deep_color(struct drm_encoder *encoder)
  482. {
  483. struct drm_device *dev = encoder->dev;
  484. struct drm_connector *connector;
  485. WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
  486. /*
  487. * HDMI cloning is only supported on g4x which doesn't
  488. * support deep color or GCP infoframes anyway so no
  489. * need to worry about multiple HDMI sinks here.
  490. */
  491. list_for_each_entry(connector, &dev->mode_config.connector_list, head)
  492. if (connector->encoder == encoder)
  493. return connector->display_info.bpc > 8;
  494. return false;
  495. }
  496. /*
  497. * Determine if default_phase=1 can be indicated in the GCP infoframe.
  498. *
  499. * From HDMI specification 1.4a:
  500. * - The first pixel of each Video Data Period shall always have a pixel packing phase of 0
  501. * - The first pixel following each Video Data Period shall have a pixel packing phase of 0
  502. * - The PP bits shall be constant for all GCPs and will be equal to the last packing phase
  503. * - The first pixel following every transition of HSYNC or VSYNC shall have a pixel packing
  504. * phase of 0
  505. */
  506. static bool gcp_default_phase_possible(int pipe_bpp,
  507. const struct drm_display_mode *mode)
  508. {
  509. unsigned int pixels_per_group;
  510. switch (pipe_bpp) {
  511. case 30:
  512. /* 4 pixels in 5 clocks */
  513. pixels_per_group = 4;
  514. break;
  515. case 36:
  516. /* 2 pixels in 3 clocks */
  517. pixels_per_group = 2;
  518. break;
  519. case 48:
  520. /* 1 pixel in 2 clocks */
  521. pixels_per_group = 1;
  522. break;
  523. default:
  524. /* phase information not relevant for 8bpc */
  525. return false;
  526. }
  527. return mode->crtc_hdisplay % pixels_per_group == 0 &&
  528. mode->crtc_htotal % pixels_per_group == 0 &&
  529. mode->crtc_hblank_start % pixels_per_group == 0 &&
  530. mode->crtc_hblank_end % pixels_per_group == 0 &&
  531. mode->crtc_hsync_start % pixels_per_group == 0 &&
  532. mode->crtc_hsync_end % pixels_per_group == 0 &&
  533. ((mode->flags & DRM_MODE_FLAG_INTERLACE) == 0 ||
  534. mode->crtc_htotal/2 % pixels_per_group == 0);
  535. }
  536. static bool intel_hdmi_set_gcp_infoframe(struct drm_encoder *encoder)
  537. {
  538. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  539. struct intel_crtc *crtc = to_intel_crtc(encoder->crtc);
  540. u32 reg, val = 0;
  541. if (HAS_DDI(dev_priv))
  542. reg = HSW_TVIDEO_DIP_GCP(crtc->config->cpu_transcoder);
  543. else if (IS_VALLEYVIEW(dev_priv))
  544. reg = VLV_TVIDEO_DIP_GCP(crtc->pipe);
  545. else if (HAS_PCH_SPLIT(dev_priv->dev))
  546. reg = TVIDEO_DIP_GCP(crtc->pipe);
  547. else
  548. return false;
  549. /* Indicate color depth whenever the sink supports deep color */
  550. if (hdmi_sink_is_deep_color(encoder))
  551. val |= GCP_COLOR_INDICATION;
  552. /* Enable default_phase whenever the display mode is suitably aligned */
  553. if (gcp_default_phase_possible(crtc->config->pipe_bpp,
  554. &crtc->config->base.adjusted_mode))
  555. val |= GCP_DEFAULT_PHASE_ENABLE;
  556. I915_WRITE(reg, val);
  557. return val != 0;
  558. }
  559. static void ibx_set_infoframes(struct drm_encoder *encoder,
  560. bool enable,
  561. const struct drm_display_mode *adjusted_mode)
  562. {
  563. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  564. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  565. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  566. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  567. u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  568. u32 val = I915_READ(reg);
  569. u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
  570. assert_hdmi_port_disabled(intel_hdmi);
  571. /* See the big comment in g4x_set_infoframes() */
  572. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  573. if (!enable) {
  574. if (!(val & VIDEO_DIP_ENABLE))
  575. return;
  576. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  577. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  578. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  579. I915_WRITE(reg, val);
  580. POSTING_READ(reg);
  581. return;
  582. }
  583. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  584. WARN(val & VIDEO_DIP_ENABLE,
  585. "DIP already enabled on port %c\n",
  586. (val & VIDEO_DIP_PORT_MASK) >> 29);
  587. val &= ~VIDEO_DIP_PORT_MASK;
  588. val |= port;
  589. }
  590. val |= VIDEO_DIP_ENABLE;
  591. val &= ~(VIDEO_DIP_ENABLE_AVI |
  592. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  593. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  594. if (intel_hdmi_set_gcp_infoframe(encoder))
  595. val |= VIDEO_DIP_ENABLE_GCP;
  596. I915_WRITE(reg, val);
  597. POSTING_READ(reg);
  598. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  599. intel_hdmi_set_spd_infoframe(encoder);
  600. intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
  601. }
  602. static void cpt_set_infoframes(struct drm_encoder *encoder,
  603. bool enable,
  604. const struct drm_display_mode *adjusted_mode)
  605. {
  606. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  607. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  608. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  609. u32 reg = TVIDEO_DIP_CTL(intel_crtc->pipe);
  610. u32 val = I915_READ(reg);
  611. assert_hdmi_port_disabled(intel_hdmi);
  612. /* See the big comment in g4x_set_infoframes() */
  613. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  614. if (!enable) {
  615. if (!(val & VIDEO_DIP_ENABLE))
  616. return;
  617. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  618. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  619. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  620. I915_WRITE(reg, val);
  621. POSTING_READ(reg);
  622. return;
  623. }
  624. /* Set both together, unset both together: see the spec. */
  625. val |= VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI;
  626. val &= ~(VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  627. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  628. if (intel_hdmi_set_gcp_infoframe(encoder))
  629. val |= VIDEO_DIP_ENABLE_GCP;
  630. I915_WRITE(reg, val);
  631. POSTING_READ(reg);
  632. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  633. intel_hdmi_set_spd_infoframe(encoder);
  634. intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
  635. }
  636. static void vlv_set_infoframes(struct drm_encoder *encoder,
  637. bool enable,
  638. const struct drm_display_mode *adjusted_mode)
  639. {
  640. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  641. struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder);
  642. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  643. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  644. u32 reg = VLV_TVIDEO_DIP_CTL(intel_crtc->pipe);
  645. u32 val = I915_READ(reg);
  646. u32 port = VIDEO_DIP_PORT(intel_dig_port->port);
  647. assert_hdmi_port_disabled(intel_hdmi);
  648. /* See the big comment in g4x_set_infoframes() */
  649. val |= VIDEO_DIP_SELECT_AVI | VIDEO_DIP_FREQ_VSYNC;
  650. if (!enable) {
  651. if (!(val & VIDEO_DIP_ENABLE))
  652. return;
  653. val &= ~(VIDEO_DIP_ENABLE | VIDEO_DIP_ENABLE_AVI |
  654. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  655. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  656. I915_WRITE(reg, val);
  657. POSTING_READ(reg);
  658. return;
  659. }
  660. if (port != (val & VIDEO_DIP_PORT_MASK)) {
  661. WARN(val & VIDEO_DIP_ENABLE,
  662. "DIP already enabled on port %c\n",
  663. (val & VIDEO_DIP_PORT_MASK) >> 29);
  664. val &= ~VIDEO_DIP_PORT_MASK;
  665. val |= port;
  666. }
  667. val |= VIDEO_DIP_ENABLE;
  668. val &= ~(VIDEO_DIP_ENABLE_AVI |
  669. VIDEO_DIP_ENABLE_VENDOR | VIDEO_DIP_ENABLE_GAMUT |
  670. VIDEO_DIP_ENABLE_SPD | VIDEO_DIP_ENABLE_GCP);
  671. if (intel_hdmi_set_gcp_infoframe(encoder))
  672. val |= VIDEO_DIP_ENABLE_GCP;
  673. I915_WRITE(reg, val);
  674. POSTING_READ(reg);
  675. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  676. intel_hdmi_set_spd_infoframe(encoder);
  677. intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
  678. }
  679. static void hsw_set_infoframes(struct drm_encoder *encoder,
  680. bool enable,
  681. const struct drm_display_mode *adjusted_mode)
  682. {
  683. struct drm_i915_private *dev_priv = encoder->dev->dev_private;
  684. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  685. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(encoder);
  686. u32 reg = HSW_TVIDEO_DIP_CTL(intel_crtc->config->cpu_transcoder);
  687. u32 val = I915_READ(reg);
  688. assert_hdmi_port_disabled(intel_hdmi);
  689. val &= ~(VIDEO_DIP_ENABLE_VSC_HSW | VIDEO_DIP_ENABLE_AVI_HSW |
  690. VIDEO_DIP_ENABLE_GCP_HSW | VIDEO_DIP_ENABLE_VS_HSW |
  691. VIDEO_DIP_ENABLE_GMP_HSW | VIDEO_DIP_ENABLE_SPD_HSW);
  692. if (!enable) {
  693. I915_WRITE(reg, val);
  694. POSTING_READ(reg);
  695. return;
  696. }
  697. if (intel_hdmi_set_gcp_infoframe(encoder))
  698. val |= VIDEO_DIP_ENABLE_GCP_HSW;
  699. I915_WRITE(reg, val);
  700. POSTING_READ(reg);
  701. intel_hdmi_set_avi_infoframe(encoder, adjusted_mode);
  702. intel_hdmi_set_spd_infoframe(encoder);
  703. intel_hdmi_set_hdmi_infoframe(encoder, adjusted_mode);
  704. }
  705. static void intel_hdmi_prepare(struct intel_encoder *encoder)
  706. {
  707. struct drm_device *dev = encoder->base.dev;
  708. struct drm_i915_private *dev_priv = dev->dev_private;
  709. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  710. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  711. const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
  712. u32 hdmi_val;
  713. hdmi_val = SDVO_ENCODING_HDMI;
  714. if (!HAS_PCH_SPLIT(dev) && crtc->config->limited_color_range)
  715. hdmi_val |= HDMI_COLOR_RANGE_16_235;
  716. if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC)
  717. hdmi_val |= SDVO_VSYNC_ACTIVE_HIGH;
  718. if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC)
  719. hdmi_val |= SDVO_HSYNC_ACTIVE_HIGH;
  720. if (crtc->config->pipe_bpp > 24)
  721. hdmi_val |= HDMI_COLOR_FORMAT_12bpc;
  722. else
  723. hdmi_val |= SDVO_COLOR_FORMAT_8bpc;
  724. if (crtc->config->has_hdmi_sink)
  725. hdmi_val |= HDMI_MODE_SELECT_HDMI;
  726. if (HAS_PCH_CPT(dev))
  727. hdmi_val |= SDVO_PIPE_SEL_CPT(crtc->pipe);
  728. else if (IS_CHERRYVIEW(dev))
  729. hdmi_val |= SDVO_PIPE_SEL_CHV(crtc->pipe);
  730. else
  731. hdmi_val |= SDVO_PIPE_SEL(crtc->pipe);
  732. I915_WRITE(intel_hdmi->hdmi_reg, hdmi_val);
  733. POSTING_READ(intel_hdmi->hdmi_reg);
  734. }
  735. static bool intel_hdmi_get_hw_state(struct intel_encoder *encoder,
  736. enum pipe *pipe)
  737. {
  738. struct drm_device *dev = encoder->base.dev;
  739. struct drm_i915_private *dev_priv = dev->dev_private;
  740. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  741. enum intel_display_power_domain power_domain;
  742. u32 tmp;
  743. power_domain = intel_display_port_power_domain(encoder);
  744. if (!intel_display_power_is_enabled(dev_priv, power_domain))
  745. return false;
  746. tmp = I915_READ(intel_hdmi->hdmi_reg);
  747. if (!(tmp & SDVO_ENABLE))
  748. return false;
  749. if (HAS_PCH_CPT(dev))
  750. *pipe = PORT_TO_PIPE_CPT(tmp);
  751. else if (IS_CHERRYVIEW(dev))
  752. *pipe = SDVO_PORT_TO_PIPE_CHV(tmp);
  753. else
  754. *pipe = PORT_TO_PIPE(tmp);
  755. return true;
  756. }
  757. static void intel_hdmi_get_config(struct intel_encoder *encoder,
  758. struct intel_crtc_state *pipe_config)
  759. {
  760. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  761. struct drm_device *dev = encoder->base.dev;
  762. struct drm_i915_private *dev_priv = dev->dev_private;
  763. u32 tmp, flags = 0;
  764. int dotclock;
  765. tmp = I915_READ(intel_hdmi->hdmi_reg);
  766. if (tmp & SDVO_HSYNC_ACTIVE_HIGH)
  767. flags |= DRM_MODE_FLAG_PHSYNC;
  768. else
  769. flags |= DRM_MODE_FLAG_NHSYNC;
  770. if (tmp & SDVO_VSYNC_ACTIVE_HIGH)
  771. flags |= DRM_MODE_FLAG_PVSYNC;
  772. else
  773. flags |= DRM_MODE_FLAG_NVSYNC;
  774. if (tmp & HDMI_MODE_SELECT_HDMI)
  775. pipe_config->has_hdmi_sink = true;
  776. if (intel_hdmi->infoframe_enabled(&encoder->base))
  777. pipe_config->has_infoframe = true;
  778. if (tmp & SDVO_AUDIO_ENABLE)
  779. pipe_config->has_audio = true;
  780. if (!HAS_PCH_SPLIT(dev) &&
  781. tmp & HDMI_COLOR_RANGE_16_235)
  782. pipe_config->limited_color_range = true;
  783. pipe_config->base.adjusted_mode.flags |= flags;
  784. if ((tmp & SDVO_COLOR_FORMAT_MASK) == HDMI_COLOR_FORMAT_12bpc)
  785. dotclock = pipe_config->port_clock * 2 / 3;
  786. else
  787. dotclock = pipe_config->port_clock;
  788. if (pipe_config->pixel_multiplier)
  789. dotclock /= pipe_config->pixel_multiplier;
  790. if (HAS_PCH_SPLIT(dev_priv->dev))
  791. ironlake_check_encoder_dotclock(pipe_config, dotclock);
  792. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  793. }
  794. static void intel_enable_hdmi_audio(struct intel_encoder *encoder)
  795. {
  796. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  797. WARN_ON(!crtc->config->has_hdmi_sink);
  798. DRM_DEBUG_DRIVER("Enabling HDMI audio on pipe %c\n",
  799. pipe_name(crtc->pipe));
  800. intel_audio_codec_enable(encoder);
  801. }
  802. static void g4x_enable_hdmi(struct intel_encoder *encoder)
  803. {
  804. struct drm_device *dev = encoder->base.dev;
  805. struct drm_i915_private *dev_priv = dev->dev_private;
  806. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  807. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  808. u32 temp;
  809. temp = I915_READ(intel_hdmi->hdmi_reg);
  810. temp |= SDVO_ENABLE;
  811. if (crtc->config->has_audio)
  812. temp |= SDVO_AUDIO_ENABLE;
  813. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  814. POSTING_READ(intel_hdmi->hdmi_reg);
  815. if (crtc->config->has_audio)
  816. intel_enable_hdmi_audio(encoder);
  817. }
  818. static void ibx_enable_hdmi(struct intel_encoder *encoder)
  819. {
  820. struct drm_device *dev = encoder->base.dev;
  821. struct drm_i915_private *dev_priv = dev->dev_private;
  822. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  823. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  824. u32 temp;
  825. temp = I915_READ(intel_hdmi->hdmi_reg);
  826. temp |= SDVO_ENABLE;
  827. if (crtc->config->has_audio)
  828. temp |= SDVO_AUDIO_ENABLE;
  829. /*
  830. * HW workaround, need to write this twice for issue
  831. * that may result in first write getting masked.
  832. */
  833. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  834. POSTING_READ(intel_hdmi->hdmi_reg);
  835. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  836. POSTING_READ(intel_hdmi->hdmi_reg);
  837. /*
  838. * HW workaround, need to toggle enable bit off and on
  839. * for 12bpc with pixel repeat.
  840. *
  841. * FIXME: BSpec says this should be done at the end of
  842. * of the modeset sequence, so not sure if this isn't too soon.
  843. */
  844. if (crtc->config->pipe_bpp > 24 &&
  845. crtc->config->pixel_multiplier > 1) {
  846. I915_WRITE(intel_hdmi->hdmi_reg, temp & ~SDVO_ENABLE);
  847. POSTING_READ(intel_hdmi->hdmi_reg);
  848. /*
  849. * HW workaround, need to write this twice for issue
  850. * that may result in first write getting masked.
  851. */
  852. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  853. POSTING_READ(intel_hdmi->hdmi_reg);
  854. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  855. POSTING_READ(intel_hdmi->hdmi_reg);
  856. }
  857. if (crtc->config->has_audio)
  858. intel_enable_hdmi_audio(encoder);
  859. }
  860. static void cpt_enable_hdmi(struct intel_encoder *encoder)
  861. {
  862. struct drm_device *dev = encoder->base.dev;
  863. struct drm_i915_private *dev_priv = dev->dev_private;
  864. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  865. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  866. enum pipe pipe = crtc->pipe;
  867. u32 temp;
  868. temp = I915_READ(intel_hdmi->hdmi_reg);
  869. temp |= SDVO_ENABLE;
  870. if (crtc->config->has_audio)
  871. temp |= SDVO_AUDIO_ENABLE;
  872. /*
  873. * WaEnableHDMI8bpcBefore12bpc:snb,ivb
  874. *
  875. * The procedure for 12bpc is as follows:
  876. * 1. disable HDMI clock gating
  877. * 2. enable HDMI with 8bpc
  878. * 3. enable HDMI with 12bpc
  879. * 4. enable HDMI clock gating
  880. */
  881. if (crtc->config->pipe_bpp > 24) {
  882. I915_WRITE(TRANS_CHICKEN1(pipe),
  883. I915_READ(TRANS_CHICKEN1(pipe)) |
  884. TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
  885. temp &= ~SDVO_COLOR_FORMAT_MASK;
  886. temp |= SDVO_COLOR_FORMAT_8bpc;
  887. }
  888. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  889. POSTING_READ(intel_hdmi->hdmi_reg);
  890. if (crtc->config->pipe_bpp > 24) {
  891. temp &= ~SDVO_COLOR_FORMAT_MASK;
  892. temp |= HDMI_COLOR_FORMAT_12bpc;
  893. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  894. POSTING_READ(intel_hdmi->hdmi_reg);
  895. I915_WRITE(TRANS_CHICKEN1(pipe),
  896. I915_READ(TRANS_CHICKEN1(pipe)) &
  897. ~TRANS_CHICKEN1_HDMIUNIT_GC_DISABLE);
  898. }
  899. if (crtc->config->has_audio)
  900. intel_enable_hdmi_audio(encoder);
  901. }
  902. static void vlv_enable_hdmi(struct intel_encoder *encoder)
  903. {
  904. }
  905. static void intel_disable_hdmi(struct intel_encoder *encoder)
  906. {
  907. struct drm_device *dev = encoder->base.dev;
  908. struct drm_i915_private *dev_priv = dev->dev_private;
  909. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  910. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  911. u32 temp;
  912. temp = I915_READ(intel_hdmi->hdmi_reg);
  913. temp &= ~(SDVO_ENABLE | SDVO_AUDIO_ENABLE);
  914. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  915. POSTING_READ(intel_hdmi->hdmi_reg);
  916. /*
  917. * HW workaround for IBX, we need to move the port
  918. * to transcoder A after disabling it to allow the
  919. * matching DP port to be enabled on transcoder A.
  920. */
  921. if (HAS_PCH_IBX(dev) && crtc->pipe == PIPE_B) {
  922. temp &= ~SDVO_PIPE_B_SELECT;
  923. temp |= SDVO_ENABLE;
  924. /*
  925. * HW workaround, need to write this twice for issue
  926. * that may result in first write getting masked.
  927. */
  928. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  929. POSTING_READ(intel_hdmi->hdmi_reg);
  930. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  931. POSTING_READ(intel_hdmi->hdmi_reg);
  932. temp &= ~SDVO_ENABLE;
  933. I915_WRITE(intel_hdmi->hdmi_reg, temp);
  934. POSTING_READ(intel_hdmi->hdmi_reg);
  935. }
  936. intel_hdmi->set_infoframes(&encoder->base, false, NULL);
  937. }
  938. static void g4x_disable_hdmi(struct intel_encoder *encoder)
  939. {
  940. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  941. if (crtc->config->has_audio)
  942. intel_audio_codec_disable(encoder);
  943. intel_disable_hdmi(encoder);
  944. }
  945. static void pch_disable_hdmi(struct intel_encoder *encoder)
  946. {
  947. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  948. if (crtc->config->has_audio)
  949. intel_audio_codec_disable(encoder);
  950. }
  951. static void pch_post_disable_hdmi(struct intel_encoder *encoder)
  952. {
  953. intel_disable_hdmi(encoder);
  954. }
  955. static int hdmi_port_clock_limit(struct intel_hdmi *hdmi, bool respect_dvi_limit)
  956. {
  957. struct drm_device *dev = intel_hdmi_to_dev(hdmi);
  958. if ((respect_dvi_limit && !hdmi->has_hdmi_sink) || IS_G4X(dev))
  959. return 165000;
  960. else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8)
  961. return 300000;
  962. else
  963. return 225000;
  964. }
  965. static enum drm_mode_status
  966. hdmi_port_clock_valid(struct intel_hdmi *hdmi,
  967. int clock, bool respect_dvi_limit)
  968. {
  969. struct drm_device *dev = intel_hdmi_to_dev(hdmi);
  970. if (clock < 25000)
  971. return MODE_CLOCK_LOW;
  972. if (clock > hdmi_port_clock_limit(hdmi, respect_dvi_limit))
  973. return MODE_CLOCK_HIGH;
  974. /* BXT DPLL can't generate 223-240 MHz */
  975. if (IS_BROXTON(dev) && clock > 223333 && clock < 240000)
  976. return MODE_CLOCK_RANGE;
  977. /* CHV DPLL can't generate 216-240 MHz */
  978. if (IS_CHERRYVIEW(dev) && clock > 216000 && clock < 240000)
  979. return MODE_CLOCK_RANGE;
  980. return MODE_OK;
  981. }
  982. static enum drm_mode_status
  983. intel_hdmi_mode_valid(struct drm_connector *connector,
  984. struct drm_display_mode *mode)
  985. {
  986. struct intel_hdmi *hdmi = intel_attached_hdmi(connector);
  987. struct drm_device *dev = intel_hdmi_to_dev(hdmi);
  988. enum drm_mode_status status;
  989. int clock;
  990. if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
  991. return MODE_NO_DBLESCAN;
  992. clock = mode->clock;
  993. if (mode->flags & DRM_MODE_FLAG_DBLCLK)
  994. clock *= 2;
  995. /* check if we can do 8bpc */
  996. status = hdmi_port_clock_valid(hdmi, clock, true);
  997. /* if we can't do 8bpc we may still be able to do 12bpc */
  998. if (!HAS_GMCH_DISPLAY(dev) && status != MODE_OK)
  999. status = hdmi_port_clock_valid(hdmi, clock * 3 / 2, true);
  1000. return status;
  1001. }
  1002. static bool hdmi_12bpc_possible(struct intel_crtc_state *crtc_state)
  1003. {
  1004. struct drm_device *dev = crtc_state->base.crtc->dev;
  1005. struct drm_atomic_state *state;
  1006. struct intel_encoder *encoder;
  1007. struct drm_connector *connector;
  1008. struct drm_connector_state *connector_state;
  1009. int count = 0, count_hdmi = 0;
  1010. int i;
  1011. if (HAS_GMCH_DISPLAY(dev))
  1012. return false;
  1013. state = crtc_state->base.state;
  1014. for_each_connector_in_state(state, connector, connector_state, i) {
  1015. if (connector_state->crtc != crtc_state->base.crtc)
  1016. continue;
  1017. encoder = to_intel_encoder(connector_state->best_encoder);
  1018. count_hdmi += encoder->type == INTEL_OUTPUT_HDMI;
  1019. count++;
  1020. }
  1021. /*
  1022. * HDMI 12bpc affects the clocks, so it's only possible
  1023. * when not cloning with other encoder types.
  1024. */
  1025. return count_hdmi > 0 && count_hdmi == count;
  1026. }
  1027. bool intel_hdmi_compute_config(struct intel_encoder *encoder,
  1028. struct intel_crtc_state *pipe_config)
  1029. {
  1030. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1031. struct drm_device *dev = encoder->base.dev;
  1032. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  1033. int clock_8bpc = pipe_config->base.adjusted_mode.crtc_clock;
  1034. int clock_12bpc = clock_8bpc * 3 / 2;
  1035. int desired_bpp;
  1036. pipe_config->has_hdmi_sink = intel_hdmi->has_hdmi_sink;
  1037. if (pipe_config->has_hdmi_sink)
  1038. pipe_config->has_infoframe = true;
  1039. if (intel_hdmi->color_range_auto) {
  1040. /* See CEA-861-E - 5.1 Default Encoding Parameters */
  1041. pipe_config->limited_color_range =
  1042. pipe_config->has_hdmi_sink &&
  1043. drm_match_cea_mode(adjusted_mode) > 1;
  1044. } else {
  1045. pipe_config->limited_color_range =
  1046. intel_hdmi->limited_color_range;
  1047. }
  1048. if (adjusted_mode->flags & DRM_MODE_FLAG_DBLCLK) {
  1049. pipe_config->pixel_multiplier = 2;
  1050. clock_8bpc *= 2;
  1051. clock_12bpc *= 2;
  1052. }
  1053. if (HAS_PCH_SPLIT(dev) && !HAS_DDI(dev))
  1054. pipe_config->has_pch_encoder = true;
  1055. if (pipe_config->has_hdmi_sink && intel_hdmi->has_audio)
  1056. pipe_config->has_audio = true;
  1057. /*
  1058. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  1059. * through, clamp it down. Note that g4x/vlv don't support 12bpc hdmi
  1060. * outputs. We also need to check that the higher clock still fits
  1061. * within limits.
  1062. */
  1063. if (pipe_config->pipe_bpp > 8*3 && pipe_config->has_hdmi_sink &&
  1064. hdmi_port_clock_valid(intel_hdmi, clock_12bpc, false) == MODE_OK &&
  1065. hdmi_12bpc_possible(pipe_config)) {
  1066. DRM_DEBUG_KMS("picking bpc to 12 for HDMI output\n");
  1067. desired_bpp = 12*3;
  1068. /* Need to adjust the port link by 1.5x for 12bpc. */
  1069. pipe_config->port_clock = clock_12bpc;
  1070. } else {
  1071. DRM_DEBUG_KMS("picking bpc to 8 for HDMI output\n");
  1072. desired_bpp = 8*3;
  1073. pipe_config->port_clock = clock_8bpc;
  1074. }
  1075. if (!pipe_config->bw_constrained) {
  1076. DRM_DEBUG_KMS("forcing pipe bpc to %i for HDMI\n", desired_bpp);
  1077. pipe_config->pipe_bpp = desired_bpp;
  1078. }
  1079. if (hdmi_port_clock_valid(intel_hdmi, pipe_config->port_clock,
  1080. false) != MODE_OK) {
  1081. DRM_DEBUG_KMS("unsupported HDMI clock, rejecting mode\n");
  1082. return false;
  1083. }
  1084. /* Set user selected PAR to incoming mode's member */
  1085. adjusted_mode->picture_aspect_ratio = intel_hdmi->aspect_ratio;
  1086. return true;
  1087. }
  1088. static void
  1089. intel_hdmi_unset_edid(struct drm_connector *connector)
  1090. {
  1091. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  1092. intel_hdmi->has_hdmi_sink = false;
  1093. intel_hdmi->has_audio = false;
  1094. intel_hdmi->rgb_quant_range_selectable = false;
  1095. kfree(to_intel_connector(connector)->detect_edid);
  1096. to_intel_connector(connector)->detect_edid = NULL;
  1097. }
  1098. static bool
  1099. intel_hdmi_set_edid(struct drm_connector *connector)
  1100. {
  1101. struct drm_i915_private *dev_priv = to_i915(connector->dev);
  1102. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  1103. struct edid *edid;
  1104. bool connected = false;
  1105. intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
  1106. edid = drm_get_edid(connector,
  1107. intel_gmbus_get_adapter(dev_priv,
  1108. intel_hdmi->ddc_bus));
  1109. intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
  1110. to_intel_connector(connector)->detect_edid = edid;
  1111. if (edid && edid->input & DRM_EDID_INPUT_DIGITAL) {
  1112. intel_hdmi->rgb_quant_range_selectable =
  1113. drm_rgb_quant_range_selectable(edid);
  1114. intel_hdmi->has_audio = drm_detect_monitor_audio(edid);
  1115. if (intel_hdmi->force_audio != HDMI_AUDIO_AUTO)
  1116. intel_hdmi->has_audio =
  1117. intel_hdmi->force_audio == HDMI_AUDIO_ON;
  1118. if (intel_hdmi->force_audio != HDMI_AUDIO_OFF_DVI)
  1119. intel_hdmi->has_hdmi_sink =
  1120. drm_detect_hdmi_monitor(edid);
  1121. connected = true;
  1122. }
  1123. return connected;
  1124. }
  1125. static enum drm_connector_status
  1126. intel_hdmi_detect(struct drm_connector *connector, bool force)
  1127. {
  1128. enum drm_connector_status status;
  1129. struct drm_i915_private *dev_priv = to_i915(connector->dev);
  1130. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  1131. connector->base.id, connector->name);
  1132. intel_display_power_get(dev_priv, POWER_DOMAIN_GMBUS);
  1133. intel_hdmi_unset_edid(connector);
  1134. if (intel_hdmi_set_edid(connector)) {
  1135. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  1136. hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
  1137. status = connector_status_connected;
  1138. } else
  1139. status = connector_status_disconnected;
  1140. intel_display_power_put(dev_priv, POWER_DOMAIN_GMBUS);
  1141. return status;
  1142. }
  1143. static void
  1144. intel_hdmi_force(struct drm_connector *connector)
  1145. {
  1146. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  1147. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  1148. connector->base.id, connector->name);
  1149. intel_hdmi_unset_edid(connector);
  1150. if (connector->status != connector_status_connected)
  1151. return;
  1152. intel_hdmi_set_edid(connector);
  1153. hdmi_to_dig_port(intel_hdmi)->base.type = INTEL_OUTPUT_HDMI;
  1154. }
  1155. static int intel_hdmi_get_modes(struct drm_connector *connector)
  1156. {
  1157. struct edid *edid;
  1158. edid = to_intel_connector(connector)->detect_edid;
  1159. if (edid == NULL)
  1160. return 0;
  1161. return intel_connector_update_modes(connector, edid);
  1162. }
  1163. static bool
  1164. intel_hdmi_detect_audio(struct drm_connector *connector)
  1165. {
  1166. bool has_audio = false;
  1167. struct edid *edid;
  1168. edid = to_intel_connector(connector)->detect_edid;
  1169. if (edid && edid->input & DRM_EDID_INPUT_DIGITAL)
  1170. has_audio = drm_detect_monitor_audio(edid);
  1171. return has_audio;
  1172. }
  1173. static int
  1174. intel_hdmi_set_property(struct drm_connector *connector,
  1175. struct drm_property *property,
  1176. uint64_t val)
  1177. {
  1178. struct intel_hdmi *intel_hdmi = intel_attached_hdmi(connector);
  1179. struct intel_digital_port *intel_dig_port =
  1180. hdmi_to_dig_port(intel_hdmi);
  1181. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  1182. int ret;
  1183. ret = drm_object_property_set_value(&connector->base, property, val);
  1184. if (ret)
  1185. return ret;
  1186. if (property == dev_priv->force_audio_property) {
  1187. enum hdmi_force_audio i = val;
  1188. bool has_audio;
  1189. if (i == intel_hdmi->force_audio)
  1190. return 0;
  1191. intel_hdmi->force_audio = i;
  1192. if (i == HDMI_AUDIO_AUTO)
  1193. has_audio = intel_hdmi_detect_audio(connector);
  1194. else
  1195. has_audio = (i == HDMI_AUDIO_ON);
  1196. if (i == HDMI_AUDIO_OFF_DVI)
  1197. intel_hdmi->has_hdmi_sink = 0;
  1198. intel_hdmi->has_audio = has_audio;
  1199. goto done;
  1200. }
  1201. if (property == dev_priv->broadcast_rgb_property) {
  1202. bool old_auto = intel_hdmi->color_range_auto;
  1203. bool old_range = intel_hdmi->limited_color_range;
  1204. switch (val) {
  1205. case INTEL_BROADCAST_RGB_AUTO:
  1206. intel_hdmi->color_range_auto = true;
  1207. break;
  1208. case INTEL_BROADCAST_RGB_FULL:
  1209. intel_hdmi->color_range_auto = false;
  1210. intel_hdmi->limited_color_range = false;
  1211. break;
  1212. case INTEL_BROADCAST_RGB_LIMITED:
  1213. intel_hdmi->color_range_auto = false;
  1214. intel_hdmi->limited_color_range = true;
  1215. break;
  1216. default:
  1217. return -EINVAL;
  1218. }
  1219. if (old_auto == intel_hdmi->color_range_auto &&
  1220. old_range == intel_hdmi->limited_color_range)
  1221. return 0;
  1222. goto done;
  1223. }
  1224. if (property == connector->dev->mode_config.aspect_ratio_property) {
  1225. switch (val) {
  1226. case DRM_MODE_PICTURE_ASPECT_NONE:
  1227. intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
  1228. break;
  1229. case DRM_MODE_PICTURE_ASPECT_4_3:
  1230. intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_4_3;
  1231. break;
  1232. case DRM_MODE_PICTURE_ASPECT_16_9:
  1233. intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_16_9;
  1234. break;
  1235. default:
  1236. return -EINVAL;
  1237. }
  1238. goto done;
  1239. }
  1240. return -EINVAL;
  1241. done:
  1242. if (intel_dig_port->base.base.crtc)
  1243. intel_crtc_restore_mode(intel_dig_port->base.base.crtc);
  1244. return 0;
  1245. }
  1246. static void intel_hdmi_pre_enable(struct intel_encoder *encoder)
  1247. {
  1248. struct intel_hdmi *intel_hdmi = enc_to_intel_hdmi(&encoder->base);
  1249. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  1250. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  1251. intel_hdmi_prepare(encoder);
  1252. intel_hdmi->set_infoframes(&encoder->base,
  1253. intel_crtc->config->has_hdmi_sink,
  1254. adjusted_mode);
  1255. }
  1256. static void vlv_hdmi_pre_enable(struct intel_encoder *encoder)
  1257. {
  1258. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1259. struct intel_hdmi *intel_hdmi = &dport->hdmi;
  1260. struct drm_device *dev = encoder->base.dev;
  1261. struct drm_i915_private *dev_priv = dev->dev_private;
  1262. struct intel_crtc *intel_crtc =
  1263. to_intel_crtc(encoder->base.crtc);
  1264. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  1265. enum dpio_channel port = vlv_dport_to_channel(dport);
  1266. int pipe = intel_crtc->pipe;
  1267. u32 val;
  1268. /* Enable clock channels for this port */
  1269. mutex_lock(&dev_priv->sb_lock);
  1270. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(port));
  1271. val = 0;
  1272. if (pipe)
  1273. val |= (1<<21);
  1274. else
  1275. val &= ~(1<<21);
  1276. val |= 0x001000c4;
  1277. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW8(port), val);
  1278. /* HDMI 1.0V-2dB */
  1279. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), 0);
  1280. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW4(port), 0x2b245f5f);
  1281. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW2(port), 0x5578b83a);
  1282. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW3(port), 0x0c782040);
  1283. vlv_dpio_write(dev_priv, pipe, VLV_TX3_DW4(port), 0x2b247878);
  1284. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW11(port), 0x00030000);
  1285. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), 0x00002000);
  1286. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
  1287. /* Program lane clock */
  1288. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW14(port), 0x00760018);
  1289. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW23(port), 0x00400888);
  1290. mutex_unlock(&dev_priv->sb_lock);
  1291. intel_hdmi->set_infoframes(&encoder->base,
  1292. intel_crtc->config->has_hdmi_sink,
  1293. adjusted_mode);
  1294. g4x_enable_hdmi(encoder);
  1295. vlv_wait_port_ready(dev_priv, dport, 0x0);
  1296. }
  1297. static void vlv_hdmi_pre_pll_enable(struct intel_encoder *encoder)
  1298. {
  1299. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1300. struct drm_device *dev = encoder->base.dev;
  1301. struct drm_i915_private *dev_priv = dev->dev_private;
  1302. struct intel_crtc *intel_crtc =
  1303. to_intel_crtc(encoder->base.crtc);
  1304. enum dpio_channel port = vlv_dport_to_channel(dport);
  1305. int pipe = intel_crtc->pipe;
  1306. intel_hdmi_prepare(encoder);
  1307. /* Program Tx lane resets to default */
  1308. mutex_lock(&dev_priv->sb_lock);
  1309. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port),
  1310. DPIO_PCS_TX_LANE2_RESET |
  1311. DPIO_PCS_TX_LANE1_RESET);
  1312. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port),
  1313. DPIO_PCS_CLK_CRI_RXEB_EIOS_EN |
  1314. DPIO_PCS_CLK_CRI_RXDIGFILTSG_EN |
  1315. (1<<DPIO_PCS_CLK_DATAWIDTH_SHIFT) |
  1316. DPIO_PCS_CLK_SOFT_RESET);
  1317. /* Fix up inter-pair skew failure */
  1318. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW12(port), 0x00750f00);
  1319. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW11(port), 0x00001500);
  1320. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW14(port), 0x40400000);
  1321. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW9(port), 0x00002000);
  1322. vlv_dpio_write(dev_priv, pipe, VLV_TX_DW5(port), DPIO_TX_OCALINIT_EN);
  1323. mutex_unlock(&dev_priv->sb_lock);
  1324. }
  1325. static void chv_data_lane_soft_reset(struct intel_encoder *encoder,
  1326. bool reset)
  1327. {
  1328. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1329. enum dpio_channel ch = vlv_dport_to_channel(enc_to_dig_port(&encoder->base));
  1330. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  1331. enum pipe pipe = crtc->pipe;
  1332. uint32_t val;
  1333. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW0(ch));
  1334. if (reset)
  1335. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  1336. else
  1337. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  1338. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW0(ch), val);
  1339. if (crtc->config->lane_count > 2) {
  1340. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW0(ch));
  1341. if (reset)
  1342. val &= ~(DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET);
  1343. else
  1344. val |= DPIO_PCS_TX_LANE2_RESET | DPIO_PCS_TX_LANE1_RESET;
  1345. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW0(ch), val);
  1346. }
  1347. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW1(ch));
  1348. val |= CHV_PCS_REQ_SOFTRESET_EN;
  1349. if (reset)
  1350. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  1351. else
  1352. val |= DPIO_PCS_CLK_SOFT_RESET;
  1353. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW1(ch), val);
  1354. if (crtc->config->lane_count > 2) {
  1355. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW1(ch));
  1356. val |= CHV_PCS_REQ_SOFTRESET_EN;
  1357. if (reset)
  1358. val &= ~DPIO_PCS_CLK_SOFT_RESET;
  1359. else
  1360. val |= DPIO_PCS_CLK_SOFT_RESET;
  1361. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW1(ch), val);
  1362. }
  1363. }
  1364. static void chv_hdmi_pre_pll_enable(struct intel_encoder *encoder)
  1365. {
  1366. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1367. struct drm_device *dev = encoder->base.dev;
  1368. struct drm_i915_private *dev_priv = dev->dev_private;
  1369. struct intel_crtc *intel_crtc =
  1370. to_intel_crtc(encoder->base.crtc);
  1371. enum dpio_channel ch = vlv_dport_to_channel(dport);
  1372. enum pipe pipe = intel_crtc->pipe;
  1373. u32 val;
  1374. intel_hdmi_prepare(encoder);
  1375. /*
  1376. * Must trick the second common lane into life.
  1377. * Otherwise we can't even access the PLL.
  1378. */
  1379. if (ch == DPIO_CH0 && pipe == PIPE_B)
  1380. dport->release_cl2_override =
  1381. !chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, true);
  1382. chv_phy_powergate_lanes(encoder, true, 0x0);
  1383. mutex_lock(&dev_priv->sb_lock);
  1384. /* Assert data lane reset */
  1385. chv_data_lane_soft_reset(encoder, true);
  1386. /* program left/right clock distribution */
  1387. if (pipe != PIPE_B) {
  1388. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1389. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1390. if (ch == DPIO_CH0)
  1391. val |= CHV_BUFLEFTENA1_FORCE;
  1392. if (ch == DPIO_CH1)
  1393. val |= CHV_BUFRIGHTENA1_FORCE;
  1394. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1395. } else {
  1396. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1397. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1398. if (ch == DPIO_CH0)
  1399. val |= CHV_BUFLEFTENA2_FORCE;
  1400. if (ch == DPIO_CH1)
  1401. val |= CHV_BUFRIGHTENA2_FORCE;
  1402. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1403. }
  1404. /* program clock channel usage */
  1405. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW8(ch));
  1406. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  1407. if (pipe != PIPE_B)
  1408. val &= ~CHV_PCS_USEDCLKCHANNEL;
  1409. else
  1410. val |= CHV_PCS_USEDCLKCHANNEL;
  1411. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW8(ch), val);
  1412. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW8(ch));
  1413. val |= CHV_PCS_USEDCLKCHANNEL_OVRRIDE;
  1414. if (pipe != PIPE_B)
  1415. val &= ~CHV_PCS_USEDCLKCHANNEL;
  1416. else
  1417. val |= CHV_PCS_USEDCLKCHANNEL;
  1418. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW8(ch), val);
  1419. /*
  1420. * This a a bit weird since generally CL
  1421. * matches the pipe, but here we need to
  1422. * pick the CL based on the port.
  1423. */
  1424. val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW19(ch));
  1425. if (pipe != PIPE_B)
  1426. val &= ~CHV_CMN_USEDCLKCHANNEL;
  1427. else
  1428. val |= CHV_CMN_USEDCLKCHANNEL;
  1429. vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW19(ch), val);
  1430. mutex_unlock(&dev_priv->sb_lock);
  1431. }
  1432. static void chv_hdmi_post_pll_disable(struct intel_encoder *encoder)
  1433. {
  1434. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  1435. enum pipe pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  1436. u32 val;
  1437. mutex_lock(&dev_priv->sb_lock);
  1438. /* disable left/right clock distribution */
  1439. if (pipe != PIPE_B) {
  1440. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0);
  1441. val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK);
  1442. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val);
  1443. } else {
  1444. val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1);
  1445. val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK);
  1446. vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val);
  1447. }
  1448. mutex_unlock(&dev_priv->sb_lock);
  1449. /*
  1450. * Leave the power down bit cleared for at least one
  1451. * lane so that chv_powergate_phy_ch() will power
  1452. * on something when the channel is otherwise unused.
  1453. * When the port is off and the override is removed
  1454. * the lanes power down anyway, so otherwise it doesn't
  1455. * really matter what the state of power down bits is
  1456. * after this.
  1457. */
  1458. chv_phy_powergate_lanes(encoder, false, 0x0);
  1459. }
  1460. static void vlv_hdmi_post_disable(struct intel_encoder *encoder)
  1461. {
  1462. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1463. struct drm_i915_private *dev_priv = encoder->base.dev->dev_private;
  1464. struct intel_crtc *intel_crtc =
  1465. to_intel_crtc(encoder->base.crtc);
  1466. enum dpio_channel port = vlv_dport_to_channel(dport);
  1467. int pipe = intel_crtc->pipe;
  1468. /* Reset lanes to avoid HDMI flicker (VLV w/a) */
  1469. mutex_lock(&dev_priv->sb_lock);
  1470. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW0(port), 0x00000000);
  1471. vlv_dpio_write(dev_priv, pipe, VLV_PCS_DW1(port), 0x00e00060);
  1472. mutex_unlock(&dev_priv->sb_lock);
  1473. }
  1474. static void chv_hdmi_post_disable(struct intel_encoder *encoder)
  1475. {
  1476. struct drm_device *dev = encoder->base.dev;
  1477. struct drm_i915_private *dev_priv = dev->dev_private;
  1478. mutex_lock(&dev_priv->sb_lock);
  1479. /* Assert data lane reset */
  1480. chv_data_lane_soft_reset(encoder, true);
  1481. mutex_unlock(&dev_priv->sb_lock);
  1482. }
  1483. static void chv_hdmi_pre_enable(struct intel_encoder *encoder)
  1484. {
  1485. struct intel_digital_port *dport = enc_to_dig_port(&encoder->base);
  1486. struct intel_hdmi *intel_hdmi = &dport->hdmi;
  1487. struct drm_device *dev = encoder->base.dev;
  1488. struct drm_i915_private *dev_priv = dev->dev_private;
  1489. struct intel_crtc *intel_crtc =
  1490. to_intel_crtc(encoder->base.crtc);
  1491. const struct drm_display_mode *adjusted_mode = &intel_crtc->config->base.adjusted_mode;
  1492. enum dpio_channel ch = vlv_dport_to_channel(dport);
  1493. int pipe = intel_crtc->pipe;
  1494. int data, i, stagger;
  1495. u32 val;
  1496. mutex_lock(&dev_priv->sb_lock);
  1497. /* allow hardware to manage TX FIFO reset source */
  1498. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  1499. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  1500. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  1501. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  1502. val &= ~DPIO_LANEDESKEW_STRAP_OVRD;
  1503. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  1504. /* Program Tx latency optimal setting */
  1505. for (i = 0; i < 4; i++) {
  1506. /* Set the upar bit */
  1507. data = (i == 1) ? 0x0 : 0x1;
  1508. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW14(ch, i),
  1509. data << DPIO_UPAR_SHIFT);
  1510. }
  1511. /* Data lane stagger programming */
  1512. if (intel_crtc->config->port_clock > 270000)
  1513. stagger = 0x18;
  1514. else if (intel_crtc->config->port_clock > 135000)
  1515. stagger = 0xd;
  1516. else if (intel_crtc->config->port_clock > 67500)
  1517. stagger = 0x7;
  1518. else if (intel_crtc->config->port_clock > 33750)
  1519. stagger = 0x4;
  1520. else
  1521. stagger = 0x2;
  1522. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW11(ch));
  1523. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  1524. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW11(ch), val);
  1525. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW11(ch));
  1526. val |= DPIO_TX2_STAGGER_MASK(0x1f);
  1527. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW11(ch), val);
  1528. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW12(ch),
  1529. DPIO_LANESTAGGER_STRAP(stagger) |
  1530. DPIO_LANESTAGGER_STRAP_OVRD |
  1531. DPIO_TX1_STAGGER_MASK(0x1f) |
  1532. DPIO_TX1_STAGGER_MULT(6) |
  1533. DPIO_TX2_STAGGER_MULT(0));
  1534. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW12(ch),
  1535. DPIO_LANESTAGGER_STRAP(stagger) |
  1536. DPIO_LANESTAGGER_STRAP_OVRD |
  1537. DPIO_TX1_STAGGER_MASK(0x1f) |
  1538. DPIO_TX1_STAGGER_MULT(7) |
  1539. DPIO_TX2_STAGGER_MULT(5));
  1540. /* Deassert data lane reset */
  1541. chv_data_lane_soft_reset(encoder, false);
  1542. /* Clear calc init */
  1543. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  1544. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  1545. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  1546. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  1547. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  1548. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  1549. val &= ~(DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3);
  1550. val &= ~(DPIO_PCS_TX1DEEMP_MASK | DPIO_PCS_TX2DEEMP_MASK);
  1551. val |= DPIO_PCS_TX1DEEMP_9P5 | DPIO_PCS_TX2DEEMP_9P5;
  1552. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  1553. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW9(ch));
  1554. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  1555. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  1556. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW9(ch), val);
  1557. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW9(ch));
  1558. val &= ~(DPIO_PCS_TX1MARGIN_MASK | DPIO_PCS_TX2MARGIN_MASK);
  1559. val |= DPIO_PCS_TX1MARGIN_000 | DPIO_PCS_TX2MARGIN_000;
  1560. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW9(ch), val);
  1561. /* FIXME: Program the support xxx V-dB */
  1562. /* Use 800mV-0dB */
  1563. for (i = 0; i < 4; i++) {
  1564. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW4(ch, i));
  1565. val &= ~DPIO_SWING_DEEMPH9P5_MASK;
  1566. val |= 128 << DPIO_SWING_DEEMPH9P5_SHIFT;
  1567. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW4(ch, i), val);
  1568. }
  1569. for (i = 0; i < 4; i++) {
  1570. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW2(ch, i));
  1571. val &= ~DPIO_SWING_MARGIN000_MASK;
  1572. val |= 102 << DPIO_SWING_MARGIN000_SHIFT;
  1573. /*
  1574. * Supposedly this value shouldn't matter when unique transition
  1575. * scale is disabled, but in fact it does matter. Let's just
  1576. * always program the same value and hope it's OK.
  1577. */
  1578. val &= ~(0xff << DPIO_UNIQ_TRANS_SCALE_SHIFT);
  1579. val |= 0x9a << DPIO_UNIQ_TRANS_SCALE_SHIFT;
  1580. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW2(ch, i), val);
  1581. }
  1582. /*
  1583. * The document said it needs to set bit 27 for ch0 and bit 26
  1584. * for ch1. Might be a typo in the doc.
  1585. * For now, for this unique transition scale selection, set bit
  1586. * 27 for ch0 and ch1.
  1587. */
  1588. for (i = 0; i < 4; i++) {
  1589. val = vlv_dpio_read(dev_priv, pipe, CHV_TX_DW3(ch, i));
  1590. val &= ~DPIO_TX_UNIQ_TRANS_SCALE_EN;
  1591. vlv_dpio_write(dev_priv, pipe, CHV_TX_DW3(ch, i), val);
  1592. }
  1593. /* Start swing calculation */
  1594. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS01_DW10(ch));
  1595. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  1596. vlv_dpio_write(dev_priv, pipe, VLV_PCS01_DW10(ch), val);
  1597. val = vlv_dpio_read(dev_priv, pipe, VLV_PCS23_DW10(ch));
  1598. val |= DPIO_PCS_SWING_CALC_TX0_TX2 | DPIO_PCS_SWING_CALC_TX1_TX3;
  1599. vlv_dpio_write(dev_priv, pipe, VLV_PCS23_DW10(ch), val);
  1600. mutex_unlock(&dev_priv->sb_lock);
  1601. intel_hdmi->set_infoframes(&encoder->base,
  1602. intel_crtc->config->has_hdmi_sink,
  1603. adjusted_mode);
  1604. g4x_enable_hdmi(encoder);
  1605. vlv_wait_port_ready(dev_priv, dport, 0x0);
  1606. /* Second common lane will stay alive on its own now */
  1607. if (dport->release_cl2_override) {
  1608. chv_phy_powergate_ch(dev_priv, DPIO_PHY0, DPIO_CH1, false);
  1609. dport->release_cl2_override = false;
  1610. }
  1611. }
  1612. static void intel_hdmi_destroy(struct drm_connector *connector)
  1613. {
  1614. kfree(to_intel_connector(connector)->detect_edid);
  1615. drm_connector_cleanup(connector);
  1616. kfree(connector);
  1617. }
  1618. static const struct drm_connector_funcs intel_hdmi_connector_funcs = {
  1619. .dpms = drm_atomic_helper_connector_dpms,
  1620. .detect = intel_hdmi_detect,
  1621. .force = intel_hdmi_force,
  1622. .fill_modes = drm_helper_probe_single_connector_modes,
  1623. .set_property = intel_hdmi_set_property,
  1624. .atomic_get_property = intel_connector_atomic_get_property,
  1625. .destroy = intel_hdmi_destroy,
  1626. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1627. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  1628. };
  1629. static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = {
  1630. .get_modes = intel_hdmi_get_modes,
  1631. .mode_valid = intel_hdmi_mode_valid,
  1632. .best_encoder = intel_best_encoder,
  1633. };
  1634. static const struct drm_encoder_funcs intel_hdmi_enc_funcs = {
  1635. .destroy = intel_encoder_destroy,
  1636. };
  1637. static void
  1638. intel_hdmi_add_properties(struct intel_hdmi *intel_hdmi, struct drm_connector *connector)
  1639. {
  1640. intel_attach_force_audio_property(connector);
  1641. intel_attach_broadcast_rgb_property(connector);
  1642. intel_hdmi->color_range_auto = true;
  1643. intel_attach_aspect_ratio_property(connector);
  1644. intel_hdmi->aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
  1645. }
  1646. static u8 intel_hdmi_ddc_pin(struct drm_i915_private *dev_priv,
  1647. enum port port)
  1648. {
  1649. const struct ddi_vbt_port_info *info =
  1650. &dev_priv->vbt.ddi_port_info[port];
  1651. u8 ddc_pin;
  1652. if (info->alternate_ddc_pin) {
  1653. DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (VBT)\n",
  1654. info->alternate_ddc_pin, port_name(port));
  1655. return info->alternate_ddc_pin;
  1656. }
  1657. switch (port) {
  1658. case PORT_B:
  1659. if (IS_BROXTON(dev_priv))
  1660. ddc_pin = GMBUS_PIN_1_BXT;
  1661. else
  1662. ddc_pin = GMBUS_PIN_DPB;
  1663. break;
  1664. case PORT_C:
  1665. if (IS_BROXTON(dev_priv))
  1666. ddc_pin = GMBUS_PIN_2_BXT;
  1667. else
  1668. ddc_pin = GMBUS_PIN_DPC;
  1669. break;
  1670. case PORT_D:
  1671. if (IS_CHERRYVIEW(dev_priv))
  1672. ddc_pin = GMBUS_PIN_DPD_CHV;
  1673. else
  1674. ddc_pin = GMBUS_PIN_DPD;
  1675. break;
  1676. default:
  1677. MISSING_CASE(port);
  1678. ddc_pin = GMBUS_PIN_DPB;
  1679. break;
  1680. }
  1681. DRM_DEBUG_KMS("Using DDC pin 0x%x for port %c (platform default)\n",
  1682. ddc_pin, port_name(port));
  1683. return ddc_pin;
  1684. }
  1685. void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
  1686. struct intel_connector *intel_connector)
  1687. {
  1688. struct drm_connector *connector = &intel_connector->base;
  1689. struct intel_hdmi *intel_hdmi = &intel_dig_port->hdmi;
  1690. struct intel_encoder *intel_encoder = &intel_dig_port->base;
  1691. struct drm_device *dev = intel_encoder->base.dev;
  1692. struct drm_i915_private *dev_priv = dev->dev_private;
  1693. enum port port = intel_dig_port->port;
  1694. DRM_DEBUG_KMS("Adding HDMI connector on port %c\n",
  1695. port_name(port));
  1696. drm_connector_init(dev, connector, &intel_hdmi_connector_funcs,
  1697. DRM_MODE_CONNECTOR_HDMIA);
  1698. drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs);
  1699. connector->interlace_allowed = 1;
  1700. connector->doublescan_allowed = 0;
  1701. connector->stereo_allowed = 1;
  1702. intel_hdmi->ddc_bus = intel_hdmi_ddc_pin(dev_priv, port);
  1703. switch (port) {
  1704. case PORT_B:
  1705. /*
  1706. * On BXT A0/A1, sw needs to activate DDIA HPD logic and
  1707. * interrupts to check the external panel connection.
  1708. */
  1709. if (IS_BROXTON(dev_priv) && (INTEL_REVID(dev) < BXT_REVID_B0))
  1710. intel_encoder->hpd_pin = HPD_PORT_A;
  1711. else
  1712. intel_encoder->hpd_pin = HPD_PORT_B;
  1713. break;
  1714. case PORT_C:
  1715. intel_encoder->hpd_pin = HPD_PORT_C;
  1716. break;
  1717. case PORT_D:
  1718. intel_encoder->hpd_pin = HPD_PORT_D;
  1719. break;
  1720. case PORT_E:
  1721. intel_encoder->hpd_pin = HPD_PORT_E;
  1722. break;
  1723. default:
  1724. MISSING_CASE(port);
  1725. return;
  1726. }
  1727. if (IS_VALLEYVIEW(dev)) {
  1728. intel_hdmi->write_infoframe = vlv_write_infoframe;
  1729. intel_hdmi->set_infoframes = vlv_set_infoframes;
  1730. intel_hdmi->infoframe_enabled = vlv_infoframe_enabled;
  1731. } else if (IS_G4X(dev)) {
  1732. intel_hdmi->write_infoframe = g4x_write_infoframe;
  1733. intel_hdmi->set_infoframes = g4x_set_infoframes;
  1734. intel_hdmi->infoframe_enabled = g4x_infoframe_enabled;
  1735. } else if (HAS_DDI(dev)) {
  1736. intel_hdmi->write_infoframe = hsw_write_infoframe;
  1737. intel_hdmi->set_infoframes = hsw_set_infoframes;
  1738. intel_hdmi->infoframe_enabled = hsw_infoframe_enabled;
  1739. } else if (HAS_PCH_IBX(dev)) {
  1740. intel_hdmi->write_infoframe = ibx_write_infoframe;
  1741. intel_hdmi->set_infoframes = ibx_set_infoframes;
  1742. intel_hdmi->infoframe_enabled = ibx_infoframe_enabled;
  1743. } else {
  1744. intel_hdmi->write_infoframe = cpt_write_infoframe;
  1745. intel_hdmi->set_infoframes = cpt_set_infoframes;
  1746. intel_hdmi->infoframe_enabled = cpt_infoframe_enabled;
  1747. }
  1748. if (HAS_DDI(dev))
  1749. intel_connector->get_hw_state = intel_ddi_connector_get_hw_state;
  1750. else
  1751. intel_connector->get_hw_state = intel_connector_get_hw_state;
  1752. intel_connector->unregister = intel_connector_unregister;
  1753. intel_hdmi_add_properties(intel_hdmi, connector);
  1754. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1755. drm_connector_register(connector);
  1756. intel_hdmi->attached_connector = intel_connector;
  1757. /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written
  1758. * 0xd. Failure to do so will result in spurious interrupts being
  1759. * generated on the port when a cable is not attached.
  1760. */
  1761. if (IS_G4X(dev) && !IS_GM45(dev)) {
  1762. u32 temp = I915_READ(PEG_BAND_GAP_DATA);
  1763. I915_WRITE(PEG_BAND_GAP_DATA, (temp & ~0xf) | 0xd);
  1764. }
  1765. }
  1766. void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port)
  1767. {
  1768. struct intel_digital_port *intel_dig_port;
  1769. struct intel_encoder *intel_encoder;
  1770. struct intel_connector *intel_connector;
  1771. intel_dig_port = kzalloc(sizeof(*intel_dig_port), GFP_KERNEL);
  1772. if (!intel_dig_port)
  1773. return;
  1774. intel_connector = intel_connector_alloc();
  1775. if (!intel_connector) {
  1776. kfree(intel_dig_port);
  1777. return;
  1778. }
  1779. intel_encoder = &intel_dig_port->base;
  1780. drm_encoder_init(dev, &intel_encoder->base, &intel_hdmi_enc_funcs,
  1781. DRM_MODE_ENCODER_TMDS);
  1782. intel_encoder->compute_config = intel_hdmi_compute_config;
  1783. if (HAS_PCH_SPLIT(dev)) {
  1784. intel_encoder->disable = pch_disable_hdmi;
  1785. intel_encoder->post_disable = pch_post_disable_hdmi;
  1786. } else {
  1787. intel_encoder->disable = g4x_disable_hdmi;
  1788. }
  1789. intel_encoder->get_hw_state = intel_hdmi_get_hw_state;
  1790. intel_encoder->get_config = intel_hdmi_get_config;
  1791. if (IS_CHERRYVIEW(dev)) {
  1792. intel_encoder->pre_pll_enable = chv_hdmi_pre_pll_enable;
  1793. intel_encoder->pre_enable = chv_hdmi_pre_enable;
  1794. intel_encoder->enable = vlv_enable_hdmi;
  1795. intel_encoder->post_disable = chv_hdmi_post_disable;
  1796. intel_encoder->post_pll_disable = chv_hdmi_post_pll_disable;
  1797. } else if (IS_VALLEYVIEW(dev)) {
  1798. intel_encoder->pre_pll_enable = vlv_hdmi_pre_pll_enable;
  1799. intel_encoder->pre_enable = vlv_hdmi_pre_enable;
  1800. intel_encoder->enable = vlv_enable_hdmi;
  1801. intel_encoder->post_disable = vlv_hdmi_post_disable;
  1802. } else {
  1803. intel_encoder->pre_enable = intel_hdmi_pre_enable;
  1804. if (HAS_PCH_CPT(dev))
  1805. intel_encoder->enable = cpt_enable_hdmi;
  1806. else if (HAS_PCH_IBX(dev))
  1807. intel_encoder->enable = ibx_enable_hdmi;
  1808. else
  1809. intel_encoder->enable = g4x_enable_hdmi;
  1810. }
  1811. intel_encoder->type = INTEL_OUTPUT_HDMI;
  1812. if (IS_CHERRYVIEW(dev)) {
  1813. if (port == PORT_D)
  1814. intel_encoder->crtc_mask = 1 << 2;
  1815. else
  1816. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  1817. } else {
  1818. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  1819. }
  1820. intel_encoder->cloneable = 1 << INTEL_OUTPUT_ANALOG;
  1821. /*
  1822. * BSpec is unclear about HDMI+HDMI cloning on g4x, but it seems
  1823. * to work on real hardware. And since g4x can send infoframes to
  1824. * only one port anyway, nothing is lost by allowing it.
  1825. */
  1826. if (IS_G4X(dev))
  1827. intel_encoder->cloneable |= 1 << INTEL_OUTPUT_HDMI;
  1828. intel_dig_port->port = port;
  1829. intel_dig_port->hdmi.hdmi_reg = hdmi_reg;
  1830. intel_dig_port->dp.output_reg = 0;
  1831. intel_hdmi_init_connector(intel_dig_port, intel_connector);
  1832. }