intel_tv.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  1. /*
  2. * Copyright © 2006-2008 Intel Corporation
  3. * Jesse Barnes <jesse.barnes@intel.com>
  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. *
  27. */
  28. /** @file
  29. * Integrated TV-out support for the 915GM and 945GM.
  30. */
  31. #include <drm/drmP.h>
  32. #include <drm/drm_atomic_helper.h>
  33. #include <drm/drm_crtc.h>
  34. #include <drm/drm_edid.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. enum tv_margin {
  39. TV_MARGIN_LEFT, TV_MARGIN_TOP,
  40. TV_MARGIN_RIGHT, TV_MARGIN_BOTTOM
  41. };
  42. /** Private structure for the integrated TV support */
  43. struct intel_tv {
  44. struct intel_encoder base;
  45. int type;
  46. const char *tv_format;
  47. int margin[4];
  48. u32 save_TV_H_CTL_1;
  49. u32 save_TV_H_CTL_2;
  50. u32 save_TV_H_CTL_3;
  51. u32 save_TV_V_CTL_1;
  52. u32 save_TV_V_CTL_2;
  53. u32 save_TV_V_CTL_3;
  54. u32 save_TV_V_CTL_4;
  55. u32 save_TV_V_CTL_5;
  56. u32 save_TV_V_CTL_6;
  57. u32 save_TV_V_CTL_7;
  58. u32 save_TV_SC_CTL_1, save_TV_SC_CTL_2, save_TV_SC_CTL_3;
  59. u32 save_TV_CSC_Y;
  60. u32 save_TV_CSC_Y2;
  61. u32 save_TV_CSC_U;
  62. u32 save_TV_CSC_U2;
  63. u32 save_TV_CSC_V;
  64. u32 save_TV_CSC_V2;
  65. u32 save_TV_CLR_KNOBS;
  66. u32 save_TV_CLR_LEVEL;
  67. u32 save_TV_WIN_POS;
  68. u32 save_TV_WIN_SIZE;
  69. u32 save_TV_FILTER_CTL_1;
  70. u32 save_TV_FILTER_CTL_2;
  71. u32 save_TV_FILTER_CTL_3;
  72. u32 save_TV_H_LUMA[60];
  73. u32 save_TV_H_CHROMA[60];
  74. u32 save_TV_V_LUMA[43];
  75. u32 save_TV_V_CHROMA[43];
  76. u32 save_TV_DAC;
  77. u32 save_TV_CTL;
  78. };
  79. struct video_levels {
  80. u16 blank, black;
  81. u8 burst;
  82. };
  83. struct color_conversion {
  84. u16 ry, gy, by, ay;
  85. u16 ru, gu, bu, au;
  86. u16 rv, gv, bv, av;
  87. };
  88. static const u32 filter_table[] = {
  89. 0xB1403000, 0x2E203500, 0x35002E20, 0x3000B140,
  90. 0x35A0B160, 0x2DC02E80, 0xB1403480, 0xB1603000,
  91. 0x2EA03640, 0x34002D80, 0x3000B120, 0x36E0B160,
  92. 0x2D202EF0, 0xB1203380, 0xB1603000, 0x2F303780,
  93. 0x33002CC0, 0x3000B100, 0x3820B160, 0x2C802F50,
  94. 0xB10032A0, 0xB1603000, 0x2F9038C0, 0x32202C20,
  95. 0x3000B0E0, 0x3980B160, 0x2BC02FC0, 0xB0E031C0,
  96. 0xB1603000, 0x2FF03A20, 0x31602B60, 0xB020B0C0,
  97. 0x3AE0B160, 0x2B001810, 0xB0C03120, 0xB140B020,
  98. 0x18283BA0, 0x30C02A80, 0xB020B0A0, 0x3C60B140,
  99. 0x2A201838, 0xB0A03080, 0xB120B020, 0x18383D20,
  100. 0x304029C0, 0xB040B080, 0x3DE0B100, 0x29601848,
  101. 0xB0803000, 0xB100B040, 0x18483EC0, 0xB0402900,
  102. 0xB040B060, 0x3F80B0C0, 0x28801858, 0xB060B080,
  103. 0xB0A0B060, 0x18602820, 0xB0A02820, 0x0000B060,
  104. 0xB1403000, 0x2E203500, 0x35002E20, 0x3000B140,
  105. 0x35A0B160, 0x2DC02E80, 0xB1403480, 0xB1603000,
  106. 0x2EA03640, 0x34002D80, 0x3000B120, 0x36E0B160,
  107. 0x2D202EF0, 0xB1203380, 0xB1603000, 0x2F303780,
  108. 0x33002CC0, 0x3000B100, 0x3820B160, 0x2C802F50,
  109. 0xB10032A0, 0xB1603000, 0x2F9038C0, 0x32202C20,
  110. 0x3000B0E0, 0x3980B160, 0x2BC02FC0, 0xB0E031C0,
  111. 0xB1603000, 0x2FF03A20, 0x31602B60, 0xB020B0C0,
  112. 0x3AE0B160, 0x2B001810, 0xB0C03120, 0xB140B020,
  113. 0x18283BA0, 0x30C02A80, 0xB020B0A0, 0x3C60B140,
  114. 0x2A201838, 0xB0A03080, 0xB120B020, 0x18383D20,
  115. 0x304029C0, 0xB040B080, 0x3DE0B100, 0x29601848,
  116. 0xB0803000, 0xB100B040, 0x18483EC0, 0xB0402900,
  117. 0xB040B060, 0x3F80B0C0, 0x28801858, 0xB060B080,
  118. 0xB0A0B060, 0x18602820, 0xB0A02820, 0x0000B060,
  119. 0x36403000, 0x2D002CC0, 0x30003640, 0x2D0036C0,
  120. 0x35C02CC0, 0x37403000, 0x2C802D40, 0x30003540,
  121. 0x2D8037C0, 0x34C02C40, 0x38403000, 0x2BC02E00,
  122. 0x30003440, 0x2E2038C0, 0x34002B80, 0x39803000,
  123. 0x2B402E40, 0x30003380, 0x2E603A00, 0x33402B00,
  124. 0x3A803040, 0x2A802EA0, 0x30403300, 0x2EC03B40,
  125. 0x32802A40, 0x3C003040, 0x2A002EC0, 0x30803240,
  126. 0x2EC03C80, 0x320029C0, 0x3D403080, 0x29402F00,
  127. 0x308031C0, 0x2F203DC0, 0x31802900, 0x3E8030C0,
  128. 0x28802F40, 0x30C03140, 0x2F203F40, 0x31402840,
  129. 0x28003100, 0x28002F00, 0x00003100, 0x36403000,
  130. 0x2D002CC0, 0x30003640, 0x2D0036C0,
  131. 0x35C02CC0, 0x37403000, 0x2C802D40, 0x30003540,
  132. 0x2D8037C0, 0x34C02C40, 0x38403000, 0x2BC02E00,
  133. 0x30003440, 0x2E2038C0, 0x34002B80, 0x39803000,
  134. 0x2B402E40, 0x30003380, 0x2E603A00, 0x33402B00,
  135. 0x3A803040, 0x2A802EA0, 0x30403300, 0x2EC03B40,
  136. 0x32802A40, 0x3C003040, 0x2A002EC0, 0x30803240,
  137. 0x2EC03C80, 0x320029C0, 0x3D403080, 0x29402F00,
  138. 0x308031C0, 0x2F203DC0, 0x31802900, 0x3E8030C0,
  139. 0x28802F40, 0x30C03140, 0x2F203F40, 0x31402840,
  140. 0x28003100, 0x28002F00, 0x00003100,
  141. };
  142. /*
  143. * Color conversion values have 3 separate fixed point formats:
  144. *
  145. * 10 bit fields (ay, au)
  146. * 1.9 fixed point (b.bbbbbbbbb)
  147. * 11 bit fields (ry, by, ru, gu, gv)
  148. * exp.mantissa (ee.mmmmmmmmm)
  149. * ee = 00 = 10^-1 (0.mmmmmmmmm)
  150. * ee = 01 = 10^-2 (0.0mmmmmmmmm)
  151. * ee = 10 = 10^-3 (0.00mmmmmmmmm)
  152. * ee = 11 = 10^-4 (0.000mmmmmmmmm)
  153. * 12 bit fields (gy, rv, bu)
  154. * exp.mantissa (eee.mmmmmmmmm)
  155. * eee = 000 = 10^-1 (0.mmmmmmmmm)
  156. * eee = 001 = 10^-2 (0.0mmmmmmmmm)
  157. * eee = 010 = 10^-3 (0.00mmmmmmmmm)
  158. * eee = 011 = 10^-4 (0.000mmmmmmmmm)
  159. * eee = 100 = reserved
  160. * eee = 101 = reserved
  161. * eee = 110 = reserved
  162. * eee = 111 = 10^0 (m.mmmmmmmm) (only usable for 1.0 representation)
  163. *
  164. * Saturation and contrast are 8 bits, with their own representation:
  165. * 8 bit field (saturation, contrast)
  166. * exp.mantissa (ee.mmmmmm)
  167. * ee = 00 = 10^-1 (0.mmmmmm)
  168. * ee = 01 = 10^0 (m.mmmmm)
  169. * ee = 10 = 10^1 (mm.mmmm)
  170. * ee = 11 = 10^2 (mmm.mmm)
  171. *
  172. * Simple conversion function:
  173. *
  174. * static u32
  175. * float_to_csc_11(float f)
  176. * {
  177. * u32 exp;
  178. * u32 mant;
  179. * u32 ret;
  180. *
  181. * if (f < 0)
  182. * f = -f;
  183. *
  184. * if (f >= 1) {
  185. * exp = 0x7;
  186. * mant = 1 << 8;
  187. * } else {
  188. * for (exp = 0; exp < 3 && f < 0.5; exp++)
  189. * f *= 2.0;
  190. * mant = (f * (1 << 9) + 0.5);
  191. * if (mant >= (1 << 9))
  192. * mant = (1 << 9) - 1;
  193. * }
  194. * ret = (exp << 9) | mant;
  195. * return ret;
  196. * }
  197. */
  198. /*
  199. * Behold, magic numbers! If we plant them they might grow a big
  200. * s-video cable to the sky... or something.
  201. *
  202. * Pre-converted to appropriate hex value.
  203. */
  204. /*
  205. * PAL & NTSC values for composite & s-video connections
  206. */
  207. static const struct color_conversion ntsc_m_csc_composite = {
  208. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0104,
  209. .ru = 0x0733, .gu = 0x052d, .bu = 0x05c7, .au = 0x0200,
  210. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0200,
  211. };
  212. static const struct video_levels ntsc_m_levels_composite = {
  213. .blank = 225, .black = 267, .burst = 113,
  214. };
  215. static const struct color_conversion ntsc_m_csc_svideo = {
  216. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0133,
  217. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0200,
  218. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0200,
  219. };
  220. static const struct video_levels ntsc_m_levels_svideo = {
  221. .blank = 266, .black = 316, .burst = 133,
  222. };
  223. static const struct color_conversion ntsc_j_csc_composite = {
  224. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0119,
  225. .ru = 0x074c, .gu = 0x0546, .bu = 0x05ec, .au = 0x0200,
  226. .rv = 0x035a, .gv = 0x0322, .bv = 0x06e1, .av = 0x0200,
  227. };
  228. static const struct video_levels ntsc_j_levels_composite = {
  229. .blank = 225, .black = 225, .burst = 113,
  230. };
  231. static const struct color_conversion ntsc_j_csc_svideo = {
  232. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x014c,
  233. .ru = 0x0788, .gu = 0x0581, .bu = 0x0322, .au = 0x0200,
  234. .rv = 0x0399, .gv = 0x0356, .bv = 0x070a, .av = 0x0200,
  235. };
  236. static const struct video_levels ntsc_j_levels_svideo = {
  237. .blank = 266, .black = 266, .burst = 133,
  238. };
  239. static const struct color_conversion pal_csc_composite = {
  240. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0113,
  241. .ru = 0x0745, .gu = 0x053f, .bu = 0x05e1, .au = 0x0200,
  242. .rv = 0x0353, .gv = 0x031c, .bv = 0x06dc, .av = 0x0200,
  243. };
  244. static const struct video_levels pal_levels_composite = {
  245. .blank = 237, .black = 237, .burst = 118,
  246. };
  247. static const struct color_conversion pal_csc_svideo = {
  248. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0145,
  249. .ru = 0x0780, .gu = 0x0579, .bu = 0x031c, .au = 0x0200,
  250. .rv = 0x0390, .gv = 0x034f, .bv = 0x0705, .av = 0x0200,
  251. };
  252. static const struct video_levels pal_levels_svideo = {
  253. .blank = 280, .black = 280, .burst = 139,
  254. };
  255. static const struct color_conversion pal_m_csc_composite = {
  256. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0104,
  257. .ru = 0x0733, .gu = 0x052d, .bu = 0x05c7, .au = 0x0200,
  258. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0200,
  259. };
  260. static const struct video_levels pal_m_levels_composite = {
  261. .blank = 225, .black = 267, .burst = 113,
  262. };
  263. static const struct color_conversion pal_m_csc_svideo = {
  264. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0133,
  265. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0200,
  266. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0200,
  267. };
  268. static const struct video_levels pal_m_levels_svideo = {
  269. .blank = 266, .black = 316, .burst = 133,
  270. };
  271. static const struct color_conversion pal_n_csc_composite = {
  272. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0104,
  273. .ru = 0x0733, .gu = 0x052d, .bu = 0x05c7, .au = 0x0200,
  274. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0200,
  275. };
  276. static const struct video_levels pal_n_levels_composite = {
  277. .blank = 225, .black = 267, .burst = 118,
  278. };
  279. static const struct color_conversion pal_n_csc_svideo = {
  280. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0133,
  281. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0200,
  282. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0200,
  283. };
  284. static const struct video_levels pal_n_levels_svideo = {
  285. .blank = 266, .black = 316, .burst = 139,
  286. };
  287. /*
  288. * Component connections
  289. */
  290. static const struct color_conversion sdtv_csc_yprpb = {
  291. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0145,
  292. .ru = 0x0559, .gu = 0x0353, .bu = 0x0100, .au = 0x0200,
  293. .rv = 0x0100, .gv = 0x03ad, .bv = 0x074d, .av = 0x0200,
  294. };
  295. static const struct color_conversion hdtv_csc_yprpb = {
  296. .ry = 0x05b3, .gy = 0x016e, .by = 0x0728, .ay = 0x0145,
  297. .ru = 0x07d5, .gu = 0x038b, .bu = 0x0100, .au = 0x0200,
  298. .rv = 0x0100, .gv = 0x03d1, .bv = 0x06bc, .av = 0x0200,
  299. };
  300. static const struct video_levels component_levels = {
  301. .blank = 279, .black = 279, .burst = 0,
  302. };
  303. struct tv_mode {
  304. const char *name;
  305. u32 clock;
  306. u16 refresh; /* in millihertz (for precision) */
  307. u32 oversample;
  308. u8 hsync_end;
  309. u16 hblank_start, hblank_end, htotal;
  310. bool progressive : 1, trilevel_sync : 1, component_only : 1;
  311. u8 vsync_start_f1, vsync_start_f2, vsync_len;
  312. bool veq_ena : 1;
  313. u8 veq_start_f1, veq_start_f2, veq_len;
  314. u8 vi_end_f1, vi_end_f2;
  315. u16 nbr_end;
  316. bool burst_ena : 1;
  317. u8 hburst_start, hburst_len;
  318. u8 vburst_start_f1;
  319. u16 vburst_end_f1;
  320. u8 vburst_start_f2;
  321. u16 vburst_end_f2;
  322. u8 vburst_start_f3;
  323. u16 vburst_end_f3;
  324. u8 vburst_start_f4;
  325. u16 vburst_end_f4;
  326. /*
  327. * subcarrier programming
  328. */
  329. u16 dda2_size, dda3_size;
  330. u8 dda1_inc;
  331. u16 dda2_inc, dda3_inc;
  332. u32 sc_reset;
  333. bool pal_burst : 1;
  334. /*
  335. * blank/black levels
  336. */
  337. const struct video_levels *composite_levels, *svideo_levels;
  338. const struct color_conversion *composite_color, *svideo_color;
  339. const u32 *filter_table;
  340. u16 max_srcw;
  341. };
  342. /*
  343. * Sub carrier DDA
  344. *
  345. * I think this works as follows:
  346. *
  347. * subcarrier freq = pixel_clock * (dda1_inc + dda2_inc / dda2_size) / 4096
  348. *
  349. * Presumably, when dda3 is added in, it gets to adjust the dda2_inc value
  350. *
  351. * So,
  352. * dda1_ideal = subcarrier/pixel * 4096
  353. * dda1_inc = floor (dda1_ideal)
  354. * dda2 = dda1_ideal - dda1_inc
  355. *
  356. * then pick a ratio for dda2 that gives the closest approximation. If
  357. * you can't get close enough, you can play with dda3 as well. This
  358. * seems likely to happen when dda2 is small as the jumps would be larger
  359. *
  360. * To invert this,
  361. *
  362. * pixel_clock = subcarrier * 4096 / (dda1_inc + dda2_inc / dda2_size)
  363. *
  364. * The constants below were all computed using a 107.520MHz clock
  365. */
  366. /**
  367. * Register programming values for TV modes.
  368. *
  369. * These values account for -1s required.
  370. */
  371. static const struct tv_mode tv_modes[] = {
  372. {
  373. .name = "NTSC-M",
  374. .clock = 108000,
  375. .refresh = 59940,
  376. .oversample = TV_OVERSAMPLE_8X,
  377. .component_only = 0,
  378. /* 525 Lines, 60 Fields, 15.734KHz line, Sub-Carrier 3.580MHz */
  379. .hsync_end = 64, .hblank_end = 124,
  380. .hblank_start = 836, .htotal = 857,
  381. .progressive = false, .trilevel_sync = false,
  382. .vsync_start_f1 = 6, .vsync_start_f2 = 7,
  383. .vsync_len = 6,
  384. .veq_ena = true, .veq_start_f1 = 0,
  385. .veq_start_f2 = 1, .veq_len = 18,
  386. .vi_end_f1 = 20, .vi_end_f2 = 21,
  387. .nbr_end = 240,
  388. .burst_ena = true,
  389. .hburst_start = 72, .hburst_len = 34,
  390. .vburst_start_f1 = 9, .vburst_end_f1 = 240,
  391. .vburst_start_f2 = 10, .vburst_end_f2 = 240,
  392. .vburst_start_f3 = 9, .vburst_end_f3 = 240,
  393. .vburst_start_f4 = 10, .vburst_end_f4 = 240,
  394. /* desired 3.5800000 actual 3.5800000 clock 107.52 */
  395. .dda1_inc = 135,
  396. .dda2_inc = 20800, .dda2_size = 27456,
  397. .dda3_inc = 0, .dda3_size = 0,
  398. .sc_reset = TV_SC_RESET_EVERY_4,
  399. .pal_burst = false,
  400. .composite_levels = &ntsc_m_levels_composite,
  401. .composite_color = &ntsc_m_csc_composite,
  402. .svideo_levels = &ntsc_m_levels_svideo,
  403. .svideo_color = &ntsc_m_csc_svideo,
  404. .filter_table = filter_table,
  405. },
  406. {
  407. .name = "NTSC-443",
  408. .clock = 108000,
  409. .refresh = 59940,
  410. .oversample = TV_OVERSAMPLE_8X,
  411. .component_only = 0,
  412. /* 525 Lines, 60 Fields, 15.734KHz line, Sub-Carrier 4.43MHz */
  413. .hsync_end = 64, .hblank_end = 124,
  414. .hblank_start = 836, .htotal = 857,
  415. .progressive = false, .trilevel_sync = false,
  416. .vsync_start_f1 = 6, .vsync_start_f2 = 7,
  417. .vsync_len = 6,
  418. .veq_ena = true, .veq_start_f1 = 0,
  419. .veq_start_f2 = 1, .veq_len = 18,
  420. .vi_end_f1 = 20, .vi_end_f2 = 21,
  421. .nbr_end = 240,
  422. .burst_ena = true,
  423. .hburst_start = 72, .hburst_len = 34,
  424. .vburst_start_f1 = 9, .vburst_end_f1 = 240,
  425. .vburst_start_f2 = 10, .vburst_end_f2 = 240,
  426. .vburst_start_f3 = 9, .vburst_end_f3 = 240,
  427. .vburst_start_f4 = 10, .vburst_end_f4 = 240,
  428. /* desired 4.4336180 actual 4.4336180 clock 107.52 */
  429. .dda1_inc = 168,
  430. .dda2_inc = 4093, .dda2_size = 27456,
  431. .dda3_inc = 310, .dda3_size = 525,
  432. .sc_reset = TV_SC_RESET_NEVER,
  433. .pal_burst = false,
  434. .composite_levels = &ntsc_m_levels_composite,
  435. .composite_color = &ntsc_m_csc_composite,
  436. .svideo_levels = &ntsc_m_levels_svideo,
  437. .svideo_color = &ntsc_m_csc_svideo,
  438. .filter_table = filter_table,
  439. },
  440. {
  441. .name = "NTSC-J",
  442. .clock = 108000,
  443. .refresh = 59940,
  444. .oversample = TV_OVERSAMPLE_8X,
  445. .component_only = 0,
  446. /* 525 Lines, 60 Fields, 15.734KHz line, Sub-Carrier 3.580MHz */
  447. .hsync_end = 64, .hblank_end = 124,
  448. .hblank_start = 836, .htotal = 857,
  449. .progressive = false, .trilevel_sync = false,
  450. .vsync_start_f1 = 6, .vsync_start_f2 = 7,
  451. .vsync_len = 6,
  452. .veq_ena = true, .veq_start_f1 = 0,
  453. .veq_start_f2 = 1, .veq_len = 18,
  454. .vi_end_f1 = 20, .vi_end_f2 = 21,
  455. .nbr_end = 240,
  456. .burst_ena = true,
  457. .hburst_start = 72, .hburst_len = 34,
  458. .vburst_start_f1 = 9, .vburst_end_f1 = 240,
  459. .vburst_start_f2 = 10, .vburst_end_f2 = 240,
  460. .vburst_start_f3 = 9, .vburst_end_f3 = 240,
  461. .vburst_start_f4 = 10, .vburst_end_f4 = 240,
  462. /* desired 3.5800000 actual 3.5800000 clock 107.52 */
  463. .dda1_inc = 135,
  464. .dda2_inc = 20800, .dda2_size = 27456,
  465. .dda3_inc = 0, .dda3_size = 0,
  466. .sc_reset = TV_SC_RESET_EVERY_4,
  467. .pal_burst = false,
  468. .composite_levels = &ntsc_j_levels_composite,
  469. .composite_color = &ntsc_j_csc_composite,
  470. .svideo_levels = &ntsc_j_levels_svideo,
  471. .svideo_color = &ntsc_j_csc_svideo,
  472. .filter_table = filter_table,
  473. },
  474. {
  475. .name = "PAL-M",
  476. .clock = 108000,
  477. .refresh = 59940,
  478. .oversample = TV_OVERSAMPLE_8X,
  479. .component_only = 0,
  480. /* 525 Lines, 60 Fields, 15.734KHz line, Sub-Carrier 3.580MHz */
  481. .hsync_end = 64, .hblank_end = 124,
  482. .hblank_start = 836, .htotal = 857,
  483. .progressive = false, .trilevel_sync = false,
  484. .vsync_start_f1 = 6, .vsync_start_f2 = 7,
  485. .vsync_len = 6,
  486. .veq_ena = true, .veq_start_f1 = 0,
  487. .veq_start_f2 = 1, .veq_len = 18,
  488. .vi_end_f1 = 20, .vi_end_f2 = 21,
  489. .nbr_end = 240,
  490. .burst_ena = true,
  491. .hburst_start = 72, .hburst_len = 34,
  492. .vburst_start_f1 = 9, .vburst_end_f1 = 240,
  493. .vburst_start_f2 = 10, .vburst_end_f2 = 240,
  494. .vburst_start_f3 = 9, .vburst_end_f3 = 240,
  495. .vburst_start_f4 = 10, .vburst_end_f4 = 240,
  496. /* desired 3.5800000 actual 3.5800000 clock 107.52 */
  497. .dda1_inc = 135,
  498. .dda2_inc = 16704, .dda2_size = 27456,
  499. .dda3_inc = 0, .dda3_size = 0,
  500. .sc_reset = TV_SC_RESET_EVERY_8,
  501. .pal_burst = true,
  502. .composite_levels = &pal_m_levels_composite,
  503. .composite_color = &pal_m_csc_composite,
  504. .svideo_levels = &pal_m_levels_svideo,
  505. .svideo_color = &pal_m_csc_svideo,
  506. .filter_table = filter_table,
  507. },
  508. {
  509. /* 625 Lines, 50 Fields, 15.625KHz line, Sub-Carrier 4.434MHz */
  510. .name = "PAL-N",
  511. .clock = 108000,
  512. .refresh = 50000,
  513. .oversample = TV_OVERSAMPLE_8X,
  514. .component_only = 0,
  515. .hsync_end = 64, .hblank_end = 128,
  516. .hblank_start = 844, .htotal = 863,
  517. .progressive = false, .trilevel_sync = false,
  518. .vsync_start_f1 = 6, .vsync_start_f2 = 7,
  519. .vsync_len = 6,
  520. .veq_ena = true, .veq_start_f1 = 0,
  521. .veq_start_f2 = 1, .veq_len = 18,
  522. .vi_end_f1 = 24, .vi_end_f2 = 25,
  523. .nbr_end = 286,
  524. .burst_ena = true,
  525. .hburst_start = 73, .hburst_len = 34,
  526. .vburst_start_f1 = 8, .vburst_end_f1 = 285,
  527. .vburst_start_f2 = 8, .vburst_end_f2 = 286,
  528. .vburst_start_f3 = 9, .vburst_end_f3 = 286,
  529. .vburst_start_f4 = 9, .vburst_end_f4 = 285,
  530. /* desired 4.4336180 actual 4.4336180 clock 107.52 */
  531. .dda1_inc = 135,
  532. .dda2_inc = 23578, .dda2_size = 27648,
  533. .dda3_inc = 134, .dda3_size = 625,
  534. .sc_reset = TV_SC_RESET_EVERY_8,
  535. .pal_burst = true,
  536. .composite_levels = &pal_n_levels_composite,
  537. .composite_color = &pal_n_csc_composite,
  538. .svideo_levels = &pal_n_levels_svideo,
  539. .svideo_color = &pal_n_csc_svideo,
  540. .filter_table = filter_table,
  541. },
  542. {
  543. /* 625 Lines, 50 Fields, 15.625KHz line, Sub-Carrier 4.434MHz */
  544. .name = "PAL",
  545. .clock = 108000,
  546. .refresh = 50000,
  547. .oversample = TV_OVERSAMPLE_8X,
  548. .component_only = 0,
  549. .hsync_end = 64, .hblank_end = 142,
  550. .hblank_start = 844, .htotal = 863,
  551. .progressive = false, .trilevel_sync = false,
  552. .vsync_start_f1 = 5, .vsync_start_f2 = 6,
  553. .vsync_len = 5,
  554. .veq_ena = true, .veq_start_f1 = 0,
  555. .veq_start_f2 = 1, .veq_len = 15,
  556. .vi_end_f1 = 24, .vi_end_f2 = 25,
  557. .nbr_end = 286,
  558. .burst_ena = true,
  559. .hburst_start = 73, .hburst_len = 32,
  560. .vburst_start_f1 = 8, .vburst_end_f1 = 285,
  561. .vburst_start_f2 = 8, .vburst_end_f2 = 286,
  562. .vburst_start_f3 = 9, .vburst_end_f3 = 286,
  563. .vburst_start_f4 = 9, .vburst_end_f4 = 285,
  564. /* desired 4.4336180 actual 4.4336180 clock 107.52 */
  565. .dda1_inc = 168,
  566. .dda2_inc = 4122, .dda2_size = 27648,
  567. .dda3_inc = 67, .dda3_size = 625,
  568. .sc_reset = TV_SC_RESET_EVERY_8,
  569. .pal_burst = true,
  570. .composite_levels = &pal_levels_composite,
  571. .composite_color = &pal_csc_composite,
  572. .svideo_levels = &pal_levels_svideo,
  573. .svideo_color = &pal_csc_svideo,
  574. .filter_table = filter_table,
  575. },
  576. {
  577. .name = "480p",
  578. .clock = 107520,
  579. .refresh = 59940,
  580. .oversample = TV_OVERSAMPLE_4X,
  581. .component_only = 1,
  582. .hsync_end = 64, .hblank_end = 122,
  583. .hblank_start = 842, .htotal = 857,
  584. .progressive = true, .trilevel_sync = false,
  585. .vsync_start_f1 = 12, .vsync_start_f2 = 12,
  586. .vsync_len = 12,
  587. .veq_ena = false,
  588. .vi_end_f1 = 44, .vi_end_f2 = 44,
  589. .nbr_end = 479,
  590. .burst_ena = false,
  591. .filter_table = filter_table,
  592. },
  593. {
  594. .name = "576p",
  595. .clock = 107520,
  596. .refresh = 50000,
  597. .oversample = TV_OVERSAMPLE_4X,
  598. .component_only = 1,
  599. .hsync_end = 64, .hblank_end = 139,
  600. .hblank_start = 859, .htotal = 863,
  601. .progressive = true, .trilevel_sync = false,
  602. .vsync_start_f1 = 10, .vsync_start_f2 = 10,
  603. .vsync_len = 10,
  604. .veq_ena = false,
  605. .vi_end_f1 = 48, .vi_end_f2 = 48,
  606. .nbr_end = 575,
  607. .burst_ena = false,
  608. .filter_table = filter_table,
  609. },
  610. {
  611. .name = "720p@60Hz",
  612. .clock = 148800,
  613. .refresh = 60000,
  614. .oversample = TV_OVERSAMPLE_2X,
  615. .component_only = 1,
  616. .hsync_end = 80, .hblank_end = 300,
  617. .hblank_start = 1580, .htotal = 1649,
  618. .progressive = true, .trilevel_sync = true,
  619. .vsync_start_f1 = 10, .vsync_start_f2 = 10,
  620. .vsync_len = 10,
  621. .veq_ena = false,
  622. .vi_end_f1 = 29, .vi_end_f2 = 29,
  623. .nbr_end = 719,
  624. .burst_ena = false,
  625. .filter_table = filter_table,
  626. },
  627. {
  628. .name = "720p@50Hz",
  629. .clock = 148800,
  630. .refresh = 50000,
  631. .oversample = TV_OVERSAMPLE_2X,
  632. .component_only = 1,
  633. .hsync_end = 80, .hblank_end = 300,
  634. .hblank_start = 1580, .htotal = 1979,
  635. .progressive = true, .trilevel_sync = true,
  636. .vsync_start_f1 = 10, .vsync_start_f2 = 10,
  637. .vsync_len = 10,
  638. .veq_ena = false,
  639. .vi_end_f1 = 29, .vi_end_f2 = 29,
  640. .nbr_end = 719,
  641. .burst_ena = false,
  642. .filter_table = filter_table,
  643. .max_srcw = 800
  644. },
  645. {
  646. .name = "1080i@50Hz",
  647. .clock = 148800,
  648. .refresh = 50000,
  649. .oversample = TV_OVERSAMPLE_2X,
  650. .component_only = 1,
  651. .hsync_end = 88, .hblank_end = 235,
  652. .hblank_start = 2155, .htotal = 2639,
  653. .progressive = false, .trilevel_sync = true,
  654. .vsync_start_f1 = 4, .vsync_start_f2 = 5,
  655. .vsync_len = 10,
  656. .veq_ena = true, .veq_start_f1 = 4,
  657. .veq_start_f2 = 4, .veq_len = 10,
  658. .vi_end_f1 = 21, .vi_end_f2 = 22,
  659. .nbr_end = 539,
  660. .burst_ena = false,
  661. .filter_table = filter_table,
  662. },
  663. {
  664. .name = "1080i@60Hz",
  665. .clock = 148800,
  666. .refresh = 60000,
  667. .oversample = TV_OVERSAMPLE_2X,
  668. .component_only = 1,
  669. .hsync_end = 88, .hblank_end = 235,
  670. .hblank_start = 2155, .htotal = 2199,
  671. .progressive = false, .trilevel_sync = true,
  672. .vsync_start_f1 = 4, .vsync_start_f2 = 5,
  673. .vsync_len = 10,
  674. .veq_ena = true, .veq_start_f1 = 4,
  675. .veq_start_f2 = 4, .veq_len = 10,
  676. .vi_end_f1 = 21, .vi_end_f2 = 22,
  677. .nbr_end = 539,
  678. .burst_ena = false,
  679. .filter_table = filter_table,
  680. },
  681. };
  682. static struct intel_tv *enc_to_tv(struct intel_encoder *encoder)
  683. {
  684. return container_of(encoder, struct intel_tv, base);
  685. }
  686. static struct intel_tv *intel_attached_tv(struct drm_connector *connector)
  687. {
  688. return enc_to_tv(intel_attached_encoder(connector));
  689. }
  690. static bool
  691. intel_tv_get_hw_state(struct intel_encoder *encoder, enum pipe *pipe)
  692. {
  693. struct drm_device *dev = encoder->base.dev;
  694. struct drm_i915_private *dev_priv = to_i915(dev);
  695. u32 tmp = I915_READ(TV_CTL);
  696. if (!(tmp & TV_ENC_ENABLE))
  697. return false;
  698. *pipe = PORT_TO_PIPE(tmp);
  699. return true;
  700. }
  701. static void
  702. intel_enable_tv(struct intel_encoder *encoder,
  703. struct intel_crtc_state *pipe_config,
  704. struct drm_connector_state *conn_state)
  705. {
  706. struct drm_device *dev = encoder->base.dev;
  707. struct drm_i915_private *dev_priv = to_i915(dev);
  708. /* Prevents vblank waits from timing out in intel_tv_detect_type() */
  709. intel_wait_for_vblank(dev_priv,
  710. to_intel_crtc(encoder->base.crtc)->pipe);
  711. I915_WRITE(TV_CTL, I915_READ(TV_CTL) | TV_ENC_ENABLE);
  712. }
  713. static void
  714. intel_disable_tv(struct intel_encoder *encoder,
  715. struct intel_crtc_state *old_crtc_state,
  716. struct drm_connector_state *old_conn_state)
  717. {
  718. struct drm_device *dev = encoder->base.dev;
  719. struct drm_i915_private *dev_priv = to_i915(dev);
  720. I915_WRITE(TV_CTL, I915_READ(TV_CTL) & ~TV_ENC_ENABLE);
  721. }
  722. static const struct tv_mode *
  723. intel_tv_mode_lookup(const char *tv_format)
  724. {
  725. int i;
  726. for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
  727. const struct tv_mode *tv_mode = &tv_modes[i];
  728. if (!strcmp(tv_format, tv_mode->name))
  729. return tv_mode;
  730. }
  731. return NULL;
  732. }
  733. static const struct tv_mode *
  734. intel_tv_mode_find(struct intel_tv *intel_tv)
  735. {
  736. return intel_tv_mode_lookup(intel_tv->tv_format);
  737. }
  738. static enum drm_mode_status
  739. intel_tv_mode_valid(struct drm_connector *connector,
  740. struct drm_display_mode *mode)
  741. {
  742. struct intel_tv *intel_tv = intel_attached_tv(connector);
  743. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv);
  744. int max_dotclk = to_i915(connector->dev)->max_dotclk_freq;
  745. if (mode->clock > max_dotclk)
  746. return MODE_CLOCK_HIGH;
  747. /* Ensure TV refresh is close to desired refresh */
  748. if (tv_mode && abs(tv_mode->refresh - drm_mode_vrefresh(mode) * 1000)
  749. < 1000)
  750. return MODE_OK;
  751. return MODE_CLOCK_RANGE;
  752. }
  753. static void
  754. intel_tv_get_config(struct intel_encoder *encoder,
  755. struct intel_crtc_state *pipe_config)
  756. {
  757. pipe_config->base.adjusted_mode.crtc_clock = pipe_config->port_clock;
  758. }
  759. static bool
  760. intel_tv_compute_config(struct intel_encoder *encoder,
  761. struct intel_crtc_state *pipe_config,
  762. struct drm_connector_state *conn_state)
  763. {
  764. struct intel_tv *intel_tv = enc_to_tv(encoder);
  765. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv);
  766. if (!tv_mode)
  767. return false;
  768. pipe_config->base.adjusted_mode.crtc_clock = tv_mode->clock;
  769. DRM_DEBUG_KMS("forcing bpc to 8 for TV\n");
  770. pipe_config->pipe_bpp = 8*3;
  771. /* TV has it's own notion of sync and other mode flags, so clear them. */
  772. pipe_config->base.adjusted_mode.flags = 0;
  773. /*
  774. * FIXME: We don't check whether the input mode is actually what we want
  775. * or whether userspace is doing something stupid.
  776. */
  777. return true;
  778. }
  779. static void
  780. set_tv_mode_timings(struct drm_i915_private *dev_priv,
  781. const struct tv_mode *tv_mode,
  782. bool burst_ena)
  783. {
  784. u32 hctl1, hctl2, hctl3;
  785. u32 vctl1, vctl2, vctl3, vctl4, vctl5, vctl6, vctl7;
  786. hctl1 = (tv_mode->hsync_end << TV_HSYNC_END_SHIFT) |
  787. (tv_mode->htotal << TV_HTOTAL_SHIFT);
  788. hctl2 = (tv_mode->hburst_start << 16) |
  789. (tv_mode->hburst_len << TV_HBURST_LEN_SHIFT);
  790. if (burst_ena)
  791. hctl2 |= TV_BURST_ENA;
  792. hctl3 = (tv_mode->hblank_start << TV_HBLANK_START_SHIFT) |
  793. (tv_mode->hblank_end << TV_HBLANK_END_SHIFT);
  794. vctl1 = (tv_mode->nbr_end << TV_NBR_END_SHIFT) |
  795. (tv_mode->vi_end_f1 << TV_VI_END_F1_SHIFT) |
  796. (tv_mode->vi_end_f2 << TV_VI_END_F2_SHIFT);
  797. vctl2 = (tv_mode->vsync_len << TV_VSYNC_LEN_SHIFT) |
  798. (tv_mode->vsync_start_f1 << TV_VSYNC_START_F1_SHIFT) |
  799. (tv_mode->vsync_start_f2 << TV_VSYNC_START_F2_SHIFT);
  800. vctl3 = (tv_mode->veq_len << TV_VEQ_LEN_SHIFT) |
  801. (tv_mode->veq_start_f1 << TV_VEQ_START_F1_SHIFT) |
  802. (tv_mode->veq_start_f2 << TV_VEQ_START_F2_SHIFT);
  803. if (tv_mode->veq_ena)
  804. vctl3 |= TV_EQUAL_ENA;
  805. vctl4 = (tv_mode->vburst_start_f1 << TV_VBURST_START_F1_SHIFT) |
  806. (tv_mode->vburst_end_f1 << TV_VBURST_END_F1_SHIFT);
  807. vctl5 = (tv_mode->vburst_start_f2 << TV_VBURST_START_F2_SHIFT) |
  808. (tv_mode->vburst_end_f2 << TV_VBURST_END_F2_SHIFT);
  809. vctl6 = (tv_mode->vburst_start_f3 << TV_VBURST_START_F3_SHIFT) |
  810. (tv_mode->vburst_end_f3 << TV_VBURST_END_F3_SHIFT);
  811. vctl7 = (tv_mode->vburst_start_f4 << TV_VBURST_START_F4_SHIFT) |
  812. (tv_mode->vburst_end_f4 << TV_VBURST_END_F4_SHIFT);
  813. I915_WRITE(TV_H_CTL_1, hctl1);
  814. I915_WRITE(TV_H_CTL_2, hctl2);
  815. I915_WRITE(TV_H_CTL_3, hctl3);
  816. I915_WRITE(TV_V_CTL_1, vctl1);
  817. I915_WRITE(TV_V_CTL_2, vctl2);
  818. I915_WRITE(TV_V_CTL_3, vctl3);
  819. I915_WRITE(TV_V_CTL_4, vctl4);
  820. I915_WRITE(TV_V_CTL_5, vctl5);
  821. I915_WRITE(TV_V_CTL_6, vctl6);
  822. I915_WRITE(TV_V_CTL_7, vctl7);
  823. }
  824. static void set_color_conversion(struct drm_i915_private *dev_priv,
  825. const struct color_conversion *color_conversion)
  826. {
  827. if (!color_conversion)
  828. return;
  829. I915_WRITE(TV_CSC_Y, (color_conversion->ry << 16) |
  830. color_conversion->gy);
  831. I915_WRITE(TV_CSC_Y2, (color_conversion->by << 16) |
  832. color_conversion->ay);
  833. I915_WRITE(TV_CSC_U, (color_conversion->ru << 16) |
  834. color_conversion->gu);
  835. I915_WRITE(TV_CSC_U2, (color_conversion->bu << 16) |
  836. color_conversion->au);
  837. I915_WRITE(TV_CSC_V, (color_conversion->rv << 16) |
  838. color_conversion->gv);
  839. I915_WRITE(TV_CSC_V2, (color_conversion->bv << 16) |
  840. color_conversion->av);
  841. }
  842. static void intel_tv_pre_enable(struct intel_encoder *encoder,
  843. struct intel_crtc_state *pipe_config,
  844. struct drm_connector_state *conn_state)
  845. {
  846. struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
  847. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  848. struct intel_tv *intel_tv = enc_to_tv(encoder);
  849. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv);
  850. u32 tv_ctl;
  851. u32 scctl1, scctl2, scctl3;
  852. int i, j;
  853. const struct video_levels *video_levels;
  854. const struct color_conversion *color_conversion;
  855. bool burst_ena;
  856. int xpos = 0x0, ypos = 0x0;
  857. unsigned int xsize, ysize;
  858. if (!tv_mode)
  859. return; /* can't happen (mode_prepare prevents this) */
  860. tv_ctl = I915_READ(TV_CTL);
  861. tv_ctl &= TV_CTL_SAVE;
  862. switch (intel_tv->type) {
  863. default:
  864. case DRM_MODE_CONNECTOR_Unknown:
  865. case DRM_MODE_CONNECTOR_Composite:
  866. tv_ctl |= TV_ENC_OUTPUT_COMPOSITE;
  867. video_levels = tv_mode->composite_levels;
  868. color_conversion = tv_mode->composite_color;
  869. burst_ena = tv_mode->burst_ena;
  870. break;
  871. case DRM_MODE_CONNECTOR_Component:
  872. tv_ctl |= TV_ENC_OUTPUT_COMPONENT;
  873. video_levels = &component_levels;
  874. if (tv_mode->burst_ena)
  875. color_conversion = &sdtv_csc_yprpb;
  876. else
  877. color_conversion = &hdtv_csc_yprpb;
  878. burst_ena = false;
  879. break;
  880. case DRM_MODE_CONNECTOR_SVIDEO:
  881. tv_ctl |= TV_ENC_OUTPUT_SVIDEO;
  882. video_levels = tv_mode->svideo_levels;
  883. color_conversion = tv_mode->svideo_color;
  884. burst_ena = tv_mode->burst_ena;
  885. break;
  886. }
  887. if (intel_crtc->pipe == 1)
  888. tv_ctl |= TV_ENC_PIPEB_SELECT;
  889. tv_ctl |= tv_mode->oversample;
  890. if (tv_mode->progressive)
  891. tv_ctl |= TV_PROGRESSIVE;
  892. if (tv_mode->trilevel_sync)
  893. tv_ctl |= TV_TRILEVEL_SYNC;
  894. if (tv_mode->pal_burst)
  895. tv_ctl |= TV_PAL_BURST;
  896. scctl1 = 0;
  897. if (tv_mode->dda1_inc)
  898. scctl1 |= TV_SC_DDA1_EN;
  899. if (tv_mode->dda2_inc)
  900. scctl1 |= TV_SC_DDA2_EN;
  901. if (tv_mode->dda3_inc)
  902. scctl1 |= TV_SC_DDA3_EN;
  903. scctl1 |= tv_mode->sc_reset;
  904. if (video_levels)
  905. scctl1 |= video_levels->burst << TV_BURST_LEVEL_SHIFT;
  906. scctl1 |= tv_mode->dda1_inc << TV_SCDDA1_INC_SHIFT;
  907. scctl2 = tv_mode->dda2_size << TV_SCDDA2_SIZE_SHIFT |
  908. tv_mode->dda2_inc << TV_SCDDA2_INC_SHIFT;
  909. scctl3 = tv_mode->dda3_size << TV_SCDDA3_SIZE_SHIFT |
  910. tv_mode->dda3_inc << TV_SCDDA3_INC_SHIFT;
  911. /* Enable two fixes for the chips that need them. */
  912. if (IS_I915GM(dev_priv))
  913. tv_ctl |= TV_ENC_C0_FIX | TV_ENC_SDP_FIX;
  914. set_tv_mode_timings(dev_priv, tv_mode, burst_ena);
  915. I915_WRITE(TV_SC_CTL_1, scctl1);
  916. I915_WRITE(TV_SC_CTL_2, scctl2);
  917. I915_WRITE(TV_SC_CTL_3, scctl3);
  918. set_color_conversion(dev_priv, color_conversion);
  919. if (INTEL_GEN(dev_priv) >= 4)
  920. I915_WRITE(TV_CLR_KNOBS, 0x00404000);
  921. else
  922. I915_WRITE(TV_CLR_KNOBS, 0x00606000);
  923. if (video_levels)
  924. I915_WRITE(TV_CLR_LEVEL,
  925. ((video_levels->black << TV_BLACK_LEVEL_SHIFT) |
  926. (video_levels->blank << TV_BLANK_LEVEL_SHIFT)));
  927. assert_pipe_disabled(dev_priv, intel_crtc->pipe);
  928. /* Filter ctl must be set before TV_WIN_SIZE */
  929. I915_WRITE(TV_FILTER_CTL_1, TV_AUTO_SCALE);
  930. xsize = tv_mode->hblank_start - tv_mode->hblank_end;
  931. if (tv_mode->progressive)
  932. ysize = tv_mode->nbr_end + 1;
  933. else
  934. ysize = 2*tv_mode->nbr_end + 1;
  935. xpos += intel_tv->margin[TV_MARGIN_LEFT];
  936. ypos += intel_tv->margin[TV_MARGIN_TOP];
  937. xsize -= (intel_tv->margin[TV_MARGIN_LEFT] +
  938. intel_tv->margin[TV_MARGIN_RIGHT]);
  939. ysize -= (intel_tv->margin[TV_MARGIN_TOP] +
  940. intel_tv->margin[TV_MARGIN_BOTTOM]);
  941. I915_WRITE(TV_WIN_POS, (xpos<<16)|ypos);
  942. I915_WRITE(TV_WIN_SIZE, (xsize<<16)|ysize);
  943. j = 0;
  944. for (i = 0; i < 60; i++)
  945. I915_WRITE(TV_H_LUMA(i), tv_mode->filter_table[j++]);
  946. for (i = 0; i < 60; i++)
  947. I915_WRITE(TV_H_CHROMA(i), tv_mode->filter_table[j++]);
  948. for (i = 0; i < 43; i++)
  949. I915_WRITE(TV_V_LUMA(i), tv_mode->filter_table[j++]);
  950. for (i = 0; i < 43; i++)
  951. I915_WRITE(TV_V_CHROMA(i), tv_mode->filter_table[j++]);
  952. I915_WRITE(TV_DAC, I915_READ(TV_DAC) & TV_DAC_SAVE);
  953. I915_WRITE(TV_CTL, tv_ctl);
  954. }
  955. static const struct drm_display_mode reported_modes[] = {
  956. {
  957. .name = "NTSC 480i",
  958. .clock = 107520,
  959. .hdisplay = 1280,
  960. .hsync_start = 1368,
  961. .hsync_end = 1496,
  962. .htotal = 1712,
  963. .vdisplay = 1024,
  964. .vsync_start = 1027,
  965. .vsync_end = 1034,
  966. .vtotal = 1104,
  967. .type = DRM_MODE_TYPE_DRIVER,
  968. },
  969. };
  970. /**
  971. * Detects TV presence by checking for load.
  972. *
  973. * Requires that the current pipe's DPLL is active.
  974. * \return true if TV is connected.
  975. * \return false if TV is disconnected.
  976. */
  977. static int
  978. intel_tv_detect_type(struct intel_tv *intel_tv,
  979. struct drm_connector *connector)
  980. {
  981. struct drm_crtc *crtc = connector->state->crtc;
  982. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  983. struct drm_device *dev = connector->dev;
  984. struct drm_i915_private *dev_priv = to_i915(dev);
  985. u32 tv_ctl, save_tv_ctl;
  986. u32 tv_dac, save_tv_dac;
  987. int type;
  988. /* Disable TV interrupts around load detect or we'll recurse */
  989. if (connector->polled & DRM_CONNECTOR_POLL_HPD) {
  990. spin_lock_irq(&dev_priv->irq_lock);
  991. i915_disable_pipestat(dev_priv, 0,
  992. PIPE_HOTPLUG_INTERRUPT_STATUS |
  993. PIPE_HOTPLUG_TV_INTERRUPT_STATUS);
  994. spin_unlock_irq(&dev_priv->irq_lock);
  995. }
  996. save_tv_dac = tv_dac = I915_READ(TV_DAC);
  997. save_tv_ctl = tv_ctl = I915_READ(TV_CTL);
  998. /* Poll for TV detection */
  999. tv_ctl &= ~(TV_ENC_ENABLE | TV_TEST_MODE_MASK);
  1000. tv_ctl |= TV_TEST_MODE_MONITOR_DETECT;
  1001. if (intel_crtc->pipe == 1)
  1002. tv_ctl |= TV_ENC_PIPEB_SELECT;
  1003. else
  1004. tv_ctl &= ~TV_ENC_PIPEB_SELECT;
  1005. tv_dac &= ~(TVDAC_SENSE_MASK | DAC_A_MASK | DAC_B_MASK | DAC_C_MASK);
  1006. tv_dac |= (TVDAC_STATE_CHG_EN |
  1007. TVDAC_A_SENSE_CTL |
  1008. TVDAC_B_SENSE_CTL |
  1009. TVDAC_C_SENSE_CTL |
  1010. DAC_CTL_OVERRIDE |
  1011. DAC_A_0_7_V |
  1012. DAC_B_0_7_V |
  1013. DAC_C_0_7_V);
  1014. /*
  1015. * The TV sense state should be cleared to zero on cantiga platform. Otherwise
  1016. * the TV is misdetected. This is hardware requirement.
  1017. */
  1018. if (IS_GM45(dev_priv))
  1019. tv_dac &= ~(TVDAC_STATE_CHG_EN | TVDAC_A_SENSE_CTL |
  1020. TVDAC_B_SENSE_CTL | TVDAC_C_SENSE_CTL);
  1021. I915_WRITE(TV_CTL, tv_ctl);
  1022. I915_WRITE(TV_DAC, tv_dac);
  1023. POSTING_READ(TV_DAC);
  1024. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  1025. type = -1;
  1026. tv_dac = I915_READ(TV_DAC);
  1027. DRM_DEBUG_KMS("TV detected: %x, %x\n", tv_ctl, tv_dac);
  1028. /*
  1029. * A B C
  1030. * 0 1 1 Composite
  1031. * 1 0 X svideo
  1032. * 0 0 0 Component
  1033. */
  1034. if ((tv_dac & TVDAC_SENSE_MASK) == (TVDAC_B_SENSE | TVDAC_C_SENSE)) {
  1035. DRM_DEBUG_KMS("Detected Composite TV connection\n");
  1036. type = DRM_MODE_CONNECTOR_Composite;
  1037. } else if ((tv_dac & (TVDAC_A_SENSE|TVDAC_B_SENSE)) == TVDAC_A_SENSE) {
  1038. DRM_DEBUG_KMS("Detected S-Video TV connection\n");
  1039. type = DRM_MODE_CONNECTOR_SVIDEO;
  1040. } else if ((tv_dac & TVDAC_SENSE_MASK) == 0) {
  1041. DRM_DEBUG_KMS("Detected Component TV connection\n");
  1042. type = DRM_MODE_CONNECTOR_Component;
  1043. } else {
  1044. DRM_DEBUG_KMS("Unrecognised TV connection\n");
  1045. type = -1;
  1046. }
  1047. I915_WRITE(TV_DAC, save_tv_dac & ~TVDAC_STATE_CHG_EN);
  1048. I915_WRITE(TV_CTL, save_tv_ctl);
  1049. POSTING_READ(TV_CTL);
  1050. /* For unknown reasons the hw barfs if we don't do this vblank wait. */
  1051. intel_wait_for_vblank(dev_priv, intel_crtc->pipe);
  1052. /* Restore interrupt config */
  1053. if (connector->polled & DRM_CONNECTOR_POLL_HPD) {
  1054. spin_lock_irq(&dev_priv->irq_lock);
  1055. i915_enable_pipestat(dev_priv, 0,
  1056. PIPE_HOTPLUG_INTERRUPT_STATUS |
  1057. PIPE_HOTPLUG_TV_INTERRUPT_STATUS);
  1058. spin_unlock_irq(&dev_priv->irq_lock);
  1059. }
  1060. return type;
  1061. }
  1062. /*
  1063. * Here we set accurate tv format according to connector type
  1064. * i.e Component TV should not be assigned by NTSC or PAL
  1065. */
  1066. static void intel_tv_find_better_format(struct drm_connector *connector)
  1067. {
  1068. struct intel_tv *intel_tv = intel_attached_tv(connector);
  1069. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv);
  1070. int i;
  1071. if ((intel_tv->type == DRM_MODE_CONNECTOR_Component) ==
  1072. tv_mode->component_only)
  1073. return;
  1074. for (i = 0; i < ARRAY_SIZE(tv_modes); i++) {
  1075. tv_mode = tv_modes + i;
  1076. if ((intel_tv->type == DRM_MODE_CONNECTOR_Component) ==
  1077. tv_mode->component_only)
  1078. break;
  1079. }
  1080. intel_tv->tv_format = tv_mode->name;
  1081. drm_object_property_set_value(&connector->base,
  1082. connector->dev->mode_config.tv_mode_property, i);
  1083. }
  1084. /**
  1085. * Detect the TV connection.
  1086. *
  1087. * Currently this always returns CONNECTOR_STATUS_UNKNOWN, as we need to be sure
  1088. * we have a pipe programmed in order to probe the TV.
  1089. */
  1090. static enum drm_connector_status
  1091. intel_tv_detect(struct drm_connector *connector, bool force)
  1092. {
  1093. struct drm_display_mode mode;
  1094. struct intel_tv *intel_tv = intel_attached_tv(connector);
  1095. enum drm_connector_status status;
  1096. int type;
  1097. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] force=%d\n",
  1098. connector->base.id, connector->name,
  1099. force);
  1100. mode = reported_modes[0];
  1101. if (force) {
  1102. struct intel_load_detect_pipe tmp;
  1103. struct drm_modeset_acquire_ctx ctx;
  1104. drm_modeset_acquire_init(&ctx, 0);
  1105. if (intel_get_load_detect_pipe(connector, &mode, &tmp, &ctx)) {
  1106. type = intel_tv_detect_type(intel_tv, connector);
  1107. intel_release_load_detect_pipe(connector, &tmp, &ctx);
  1108. status = type < 0 ?
  1109. connector_status_disconnected :
  1110. connector_status_connected;
  1111. } else
  1112. status = connector_status_unknown;
  1113. drm_modeset_drop_locks(&ctx);
  1114. drm_modeset_acquire_fini(&ctx);
  1115. } else
  1116. return connector->status;
  1117. if (status != connector_status_connected)
  1118. return status;
  1119. intel_tv->type = type;
  1120. intel_tv_find_better_format(connector);
  1121. return connector_status_connected;
  1122. }
  1123. static const struct input_res {
  1124. const char *name;
  1125. int w, h;
  1126. } input_res_table[] = {
  1127. {"640x480", 640, 480},
  1128. {"800x600", 800, 600},
  1129. {"1024x768", 1024, 768},
  1130. {"1280x1024", 1280, 1024},
  1131. {"848x480", 848, 480},
  1132. {"1280x720", 1280, 720},
  1133. {"1920x1080", 1920, 1080},
  1134. };
  1135. /*
  1136. * Chose preferred mode according to line number of TV format
  1137. */
  1138. static void
  1139. intel_tv_chose_preferred_modes(struct drm_connector *connector,
  1140. struct drm_display_mode *mode_ptr)
  1141. {
  1142. struct intel_tv *intel_tv = intel_attached_tv(connector);
  1143. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv);
  1144. if (tv_mode->nbr_end < 480 && mode_ptr->vdisplay == 480)
  1145. mode_ptr->type |= DRM_MODE_TYPE_PREFERRED;
  1146. else if (tv_mode->nbr_end > 480) {
  1147. if (tv_mode->progressive == true && tv_mode->nbr_end < 720) {
  1148. if (mode_ptr->vdisplay == 720)
  1149. mode_ptr->type |= DRM_MODE_TYPE_PREFERRED;
  1150. } else if (mode_ptr->vdisplay == 1080)
  1151. mode_ptr->type |= DRM_MODE_TYPE_PREFERRED;
  1152. }
  1153. }
  1154. /**
  1155. * Stub get_modes function.
  1156. *
  1157. * This should probably return a set of fixed modes, unless we can figure out
  1158. * how to probe modes off of TV connections.
  1159. */
  1160. static int
  1161. intel_tv_get_modes(struct drm_connector *connector)
  1162. {
  1163. struct drm_display_mode *mode_ptr;
  1164. struct intel_tv *intel_tv = intel_attached_tv(connector);
  1165. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_tv);
  1166. int j, count = 0;
  1167. u64 tmp;
  1168. for (j = 0; j < ARRAY_SIZE(input_res_table);
  1169. j++) {
  1170. const struct input_res *input = &input_res_table[j];
  1171. unsigned int hactive_s = input->w;
  1172. unsigned int vactive_s = input->h;
  1173. if (tv_mode->max_srcw && input->w > tv_mode->max_srcw)
  1174. continue;
  1175. if (input->w > 1024 && (!tv_mode->progressive
  1176. && !tv_mode->component_only))
  1177. continue;
  1178. mode_ptr = drm_mode_create(connector->dev);
  1179. if (!mode_ptr)
  1180. continue;
  1181. strncpy(mode_ptr->name, input->name, DRM_DISPLAY_MODE_LEN);
  1182. mode_ptr->name[DRM_DISPLAY_MODE_LEN - 1] = '\0';
  1183. mode_ptr->hdisplay = hactive_s;
  1184. mode_ptr->hsync_start = hactive_s + 1;
  1185. mode_ptr->hsync_end = hactive_s + 64;
  1186. if (mode_ptr->hsync_end <= mode_ptr->hsync_start)
  1187. mode_ptr->hsync_end = mode_ptr->hsync_start + 1;
  1188. mode_ptr->htotal = hactive_s + 96;
  1189. mode_ptr->vdisplay = vactive_s;
  1190. mode_ptr->vsync_start = vactive_s + 1;
  1191. mode_ptr->vsync_end = vactive_s + 32;
  1192. if (mode_ptr->vsync_end <= mode_ptr->vsync_start)
  1193. mode_ptr->vsync_end = mode_ptr->vsync_start + 1;
  1194. mode_ptr->vtotal = vactive_s + 33;
  1195. tmp = (u64) tv_mode->refresh * mode_ptr->vtotal;
  1196. tmp *= mode_ptr->htotal;
  1197. tmp = div_u64(tmp, 1000000);
  1198. mode_ptr->clock = (int) tmp;
  1199. mode_ptr->type = DRM_MODE_TYPE_DRIVER;
  1200. intel_tv_chose_preferred_modes(connector, mode_ptr);
  1201. drm_mode_probed_add(connector, mode_ptr);
  1202. count++;
  1203. }
  1204. return count;
  1205. }
  1206. static void
  1207. intel_tv_destroy(struct drm_connector *connector)
  1208. {
  1209. drm_connector_cleanup(connector);
  1210. kfree(connector);
  1211. }
  1212. static int
  1213. intel_tv_set_property(struct drm_connector *connector, struct drm_property *property,
  1214. uint64_t val)
  1215. {
  1216. struct drm_device *dev = connector->dev;
  1217. struct intel_tv *intel_tv = intel_attached_tv(connector);
  1218. struct drm_crtc *crtc = intel_tv->base.base.crtc;
  1219. int ret = 0;
  1220. bool changed = false;
  1221. ret = drm_object_property_set_value(&connector->base, property, val);
  1222. if (ret < 0)
  1223. goto out;
  1224. if (property == dev->mode_config.tv_left_margin_property &&
  1225. intel_tv->margin[TV_MARGIN_LEFT] != val) {
  1226. intel_tv->margin[TV_MARGIN_LEFT] = val;
  1227. changed = true;
  1228. } else if (property == dev->mode_config.tv_right_margin_property &&
  1229. intel_tv->margin[TV_MARGIN_RIGHT] != val) {
  1230. intel_tv->margin[TV_MARGIN_RIGHT] = val;
  1231. changed = true;
  1232. } else if (property == dev->mode_config.tv_top_margin_property &&
  1233. intel_tv->margin[TV_MARGIN_TOP] != val) {
  1234. intel_tv->margin[TV_MARGIN_TOP] = val;
  1235. changed = true;
  1236. } else if (property == dev->mode_config.tv_bottom_margin_property &&
  1237. intel_tv->margin[TV_MARGIN_BOTTOM] != val) {
  1238. intel_tv->margin[TV_MARGIN_BOTTOM] = val;
  1239. changed = true;
  1240. } else if (property == dev->mode_config.tv_mode_property) {
  1241. if (val >= ARRAY_SIZE(tv_modes)) {
  1242. ret = -EINVAL;
  1243. goto out;
  1244. }
  1245. if (!strcmp(intel_tv->tv_format, tv_modes[val].name))
  1246. goto out;
  1247. intel_tv->tv_format = tv_modes[val].name;
  1248. changed = true;
  1249. } else {
  1250. ret = -EINVAL;
  1251. goto out;
  1252. }
  1253. if (changed && crtc)
  1254. intel_crtc_restore_mode(crtc);
  1255. out:
  1256. return ret;
  1257. }
  1258. static const struct drm_connector_funcs intel_tv_connector_funcs = {
  1259. .dpms = drm_atomic_helper_connector_dpms,
  1260. .detect = intel_tv_detect,
  1261. .late_register = intel_connector_register,
  1262. .early_unregister = intel_connector_unregister,
  1263. .destroy = intel_tv_destroy,
  1264. .set_property = intel_tv_set_property,
  1265. .atomic_get_property = intel_connector_atomic_get_property,
  1266. .fill_modes = drm_helper_probe_single_connector_modes,
  1267. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  1268. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  1269. };
  1270. static const struct drm_connector_helper_funcs intel_tv_connector_helper_funcs = {
  1271. .mode_valid = intel_tv_mode_valid,
  1272. .get_modes = intel_tv_get_modes,
  1273. };
  1274. static const struct drm_encoder_funcs intel_tv_enc_funcs = {
  1275. .destroy = intel_encoder_destroy,
  1276. };
  1277. void
  1278. intel_tv_init(struct drm_i915_private *dev_priv)
  1279. {
  1280. struct drm_device *dev = &dev_priv->drm;
  1281. struct drm_connector *connector;
  1282. struct intel_tv *intel_tv;
  1283. struct intel_encoder *intel_encoder;
  1284. struct intel_connector *intel_connector;
  1285. u32 tv_dac_on, tv_dac_off, save_tv_dac;
  1286. const char *tv_format_names[ARRAY_SIZE(tv_modes)];
  1287. int i, initial_mode = 0;
  1288. if ((I915_READ(TV_CTL) & TV_FUSE_STATE_MASK) == TV_FUSE_STATE_DISABLED)
  1289. return;
  1290. if (!intel_bios_is_tv_present(dev_priv)) {
  1291. DRM_DEBUG_KMS("Integrated TV is not present.\n");
  1292. return;
  1293. }
  1294. /*
  1295. * Sanity check the TV output by checking to see if the
  1296. * DAC register holds a value
  1297. */
  1298. save_tv_dac = I915_READ(TV_DAC);
  1299. I915_WRITE(TV_DAC, save_tv_dac | TVDAC_STATE_CHG_EN);
  1300. tv_dac_on = I915_READ(TV_DAC);
  1301. I915_WRITE(TV_DAC, save_tv_dac & ~TVDAC_STATE_CHG_EN);
  1302. tv_dac_off = I915_READ(TV_DAC);
  1303. I915_WRITE(TV_DAC, save_tv_dac);
  1304. /*
  1305. * If the register does not hold the state change enable
  1306. * bit, (either as a 0 or a 1), assume it doesn't really
  1307. * exist
  1308. */
  1309. if ((tv_dac_on & TVDAC_STATE_CHG_EN) == 0 ||
  1310. (tv_dac_off & TVDAC_STATE_CHG_EN) != 0)
  1311. return;
  1312. intel_tv = kzalloc(sizeof(*intel_tv), GFP_KERNEL);
  1313. if (!intel_tv) {
  1314. return;
  1315. }
  1316. intel_connector = intel_connector_alloc();
  1317. if (!intel_connector) {
  1318. kfree(intel_tv);
  1319. return;
  1320. }
  1321. intel_encoder = &intel_tv->base;
  1322. connector = &intel_connector->base;
  1323. /* The documentation, for the older chipsets at least, recommend
  1324. * using a polling method rather than hotplug detection for TVs.
  1325. * This is because in order to perform the hotplug detection, the PLLs
  1326. * for the TV must be kept alive increasing power drain and starving
  1327. * bandwidth from other encoders. Notably for instance, it causes
  1328. * pipe underruns on Crestline when this encoder is supposedly idle.
  1329. *
  1330. * More recent chipsets favour HDMI rather than integrated S-Video.
  1331. */
  1332. intel_connector->polled = DRM_CONNECTOR_POLL_CONNECT;
  1333. drm_connector_init(dev, connector, &intel_tv_connector_funcs,
  1334. DRM_MODE_CONNECTOR_SVIDEO);
  1335. drm_encoder_init(dev, &intel_encoder->base, &intel_tv_enc_funcs,
  1336. DRM_MODE_ENCODER_TVDAC, "TV");
  1337. intel_encoder->compute_config = intel_tv_compute_config;
  1338. intel_encoder->get_config = intel_tv_get_config;
  1339. intel_encoder->pre_enable = intel_tv_pre_enable;
  1340. intel_encoder->enable = intel_enable_tv;
  1341. intel_encoder->disable = intel_disable_tv;
  1342. intel_encoder->get_hw_state = intel_tv_get_hw_state;
  1343. intel_connector->get_hw_state = intel_connector_get_hw_state;
  1344. intel_connector_attach_encoder(intel_connector, intel_encoder);
  1345. intel_encoder->type = INTEL_OUTPUT_TVOUT;
  1346. intel_encoder->port = PORT_NONE;
  1347. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  1348. intel_encoder->cloneable = 0;
  1349. intel_encoder->base.possible_crtcs = ((1 << 0) | (1 << 1));
  1350. intel_tv->type = DRM_MODE_CONNECTOR_Unknown;
  1351. /* BIOS margin values */
  1352. intel_tv->margin[TV_MARGIN_LEFT] = 54;
  1353. intel_tv->margin[TV_MARGIN_TOP] = 36;
  1354. intel_tv->margin[TV_MARGIN_RIGHT] = 46;
  1355. intel_tv->margin[TV_MARGIN_BOTTOM] = 37;
  1356. intel_tv->tv_format = tv_modes[initial_mode].name;
  1357. drm_connector_helper_add(connector, &intel_tv_connector_helper_funcs);
  1358. connector->interlace_allowed = false;
  1359. connector->doublescan_allowed = false;
  1360. /* Create TV properties then attach current values */
  1361. for (i = 0; i < ARRAY_SIZE(tv_modes); i++)
  1362. tv_format_names[i] = tv_modes[i].name;
  1363. drm_mode_create_tv_properties(dev,
  1364. ARRAY_SIZE(tv_modes),
  1365. tv_format_names);
  1366. drm_object_attach_property(&connector->base, dev->mode_config.tv_mode_property,
  1367. initial_mode);
  1368. drm_object_attach_property(&connector->base,
  1369. dev->mode_config.tv_left_margin_property,
  1370. intel_tv->margin[TV_MARGIN_LEFT]);
  1371. drm_object_attach_property(&connector->base,
  1372. dev->mode_config.tv_top_margin_property,
  1373. intel_tv->margin[TV_MARGIN_TOP]);
  1374. drm_object_attach_property(&connector->base,
  1375. dev->mode_config.tv_right_margin_property,
  1376. intel_tv->margin[TV_MARGIN_RIGHT]);
  1377. drm_object_attach_property(&connector->base,
  1378. dev->mode_config.tv_bottom_margin_property,
  1379. intel_tv->margin[TV_MARGIN_BOTTOM]);
  1380. }