intel_tv.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753
  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 "drmP.h"
  32. #include "drm.h"
  33. #include "drm_crtc.h"
  34. #include "drm_edid.h"
  35. #include "intel_drv.h"
  36. #include "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_priv {
  44. int type;
  45. char *tv_format;
  46. int margin[4];
  47. u32 save_TV_H_CTL_1;
  48. u32 save_TV_H_CTL_2;
  49. u32 save_TV_H_CTL_3;
  50. u32 save_TV_V_CTL_1;
  51. u32 save_TV_V_CTL_2;
  52. u32 save_TV_V_CTL_3;
  53. u32 save_TV_V_CTL_4;
  54. u32 save_TV_V_CTL_5;
  55. u32 save_TV_V_CTL_6;
  56. u32 save_TV_V_CTL_7;
  57. u32 save_TV_SC_CTL_1, save_TV_SC_CTL_2, save_TV_SC_CTL_3;
  58. u32 save_TV_CSC_Y;
  59. u32 save_TV_CSC_Y2;
  60. u32 save_TV_CSC_U;
  61. u32 save_TV_CSC_U2;
  62. u32 save_TV_CSC_V;
  63. u32 save_TV_CSC_V2;
  64. u32 save_TV_CLR_KNOBS;
  65. u32 save_TV_CLR_LEVEL;
  66. u32 save_TV_WIN_POS;
  67. u32 save_TV_WIN_SIZE;
  68. u32 save_TV_FILTER_CTL_1;
  69. u32 save_TV_FILTER_CTL_2;
  70. u32 save_TV_FILTER_CTL_3;
  71. u32 save_TV_H_LUMA[60];
  72. u32 save_TV_H_CHROMA[60];
  73. u32 save_TV_V_LUMA[43];
  74. u32 save_TV_V_CHROMA[43];
  75. u32 save_TV_DAC;
  76. u32 save_TV_CTL;
  77. };
  78. struct video_levels {
  79. int blank, black, burst;
  80. };
  81. struct color_conversion {
  82. u16 ry, gy, by, ay;
  83. u16 ru, gu, bu, au;
  84. u16 rv, gv, bv, av;
  85. };
  86. static const u32 filter_table[] = {
  87. 0xB1403000, 0x2E203500, 0x35002E20, 0x3000B140,
  88. 0x35A0B160, 0x2DC02E80, 0xB1403480, 0xB1603000,
  89. 0x2EA03640, 0x34002D80, 0x3000B120, 0x36E0B160,
  90. 0x2D202EF0, 0xB1203380, 0xB1603000, 0x2F303780,
  91. 0x33002CC0, 0x3000B100, 0x3820B160, 0x2C802F50,
  92. 0xB10032A0, 0xB1603000, 0x2F9038C0, 0x32202C20,
  93. 0x3000B0E0, 0x3980B160, 0x2BC02FC0, 0xB0E031C0,
  94. 0xB1603000, 0x2FF03A20, 0x31602B60, 0xB020B0C0,
  95. 0x3AE0B160, 0x2B001810, 0xB0C03120, 0xB140B020,
  96. 0x18283BA0, 0x30C02A80, 0xB020B0A0, 0x3C60B140,
  97. 0x2A201838, 0xB0A03080, 0xB120B020, 0x18383D20,
  98. 0x304029C0, 0xB040B080, 0x3DE0B100, 0x29601848,
  99. 0xB0803000, 0xB100B040, 0x18483EC0, 0xB0402900,
  100. 0xB040B060, 0x3F80B0C0, 0x28801858, 0xB060B080,
  101. 0xB0A0B060, 0x18602820, 0xB0A02820, 0x0000B060,
  102. 0xB1403000, 0x2E203500, 0x35002E20, 0x3000B140,
  103. 0x35A0B160, 0x2DC02E80, 0xB1403480, 0xB1603000,
  104. 0x2EA03640, 0x34002D80, 0x3000B120, 0x36E0B160,
  105. 0x2D202EF0, 0xB1203380, 0xB1603000, 0x2F303780,
  106. 0x33002CC0, 0x3000B100, 0x3820B160, 0x2C802F50,
  107. 0xB10032A0, 0xB1603000, 0x2F9038C0, 0x32202C20,
  108. 0x3000B0E0, 0x3980B160, 0x2BC02FC0, 0xB0E031C0,
  109. 0xB1603000, 0x2FF03A20, 0x31602B60, 0xB020B0C0,
  110. 0x3AE0B160, 0x2B001810, 0xB0C03120, 0xB140B020,
  111. 0x18283BA0, 0x30C02A80, 0xB020B0A0, 0x3C60B140,
  112. 0x2A201838, 0xB0A03080, 0xB120B020, 0x18383D20,
  113. 0x304029C0, 0xB040B080, 0x3DE0B100, 0x29601848,
  114. 0xB0803000, 0xB100B040, 0x18483EC0, 0xB0402900,
  115. 0xB040B060, 0x3F80B0C0, 0x28801858, 0xB060B080,
  116. 0xB0A0B060, 0x18602820, 0xB0A02820, 0x0000B060,
  117. 0x36403000, 0x2D002CC0, 0x30003640, 0x2D0036C0,
  118. 0x35C02CC0, 0x37403000, 0x2C802D40, 0x30003540,
  119. 0x2D8037C0, 0x34C02C40, 0x38403000, 0x2BC02E00,
  120. 0x30003440, 0x2E2038C0, 0x34002B80, 0x39803000,
  121. 0x2B402E40, 0x30003380, 0x2E603A00, 0x33402B00,
  122. 0x3A803040, 0x2A802EA0, 0x30403300, 0x2EC03B40,
  123. 0x32802A40, 0x3C003040, 0x2A002EC0, 0x30803240,
  124. 0x2EC03C80, 0x320029C0, 0x3D403080, 0x29402F00,
  125. 0x308031C0, 0x2F203DC0, 0x31802900, 0x3E8030C0,
  126. 0x28802F40, 0x30C03140, 0x2F203F40, 0x31402840,
  127. 0x28003100, 0x28002F00, 0x00003100, 0x36403000,
  128. 0x2D002CC0, 0x30003640, 0x2D0036C0,
  129. 0x35C02CC0, 0x37403000, 0x2C802D40, 0x30003540,
  130. 0x2D8037C0, 0x34C02C40, 0x38403000, 0x2BC02E00,
  131. 0x30003440, 0x2E2038C0, 0x34002B80, 0x39803000,
  132. 0x2B402E40, 0x30003380, 0x2E603A00, 0x33402B00,
  133. 0x3A803040, 0x2A802EA0, 0x30403300, 0x2EC03B40,
  134. 0x32802A40, 0x3C003040, 0x2A002EC0, 0x30803240,
  135. 0x2EC03C80, 0x320029C0, 0x3D403080, 0x29402F00,
  136. 0x308031C0, 0x2F203DC0, 0x31802900, 0x3E8030C0,
  137. 0x28802F40, 0x30C03140, 0x2F203F40, 0x31402840,
  138. 0x28003100, 0x28002F00, 0x00003100,
  139. };
  140. /*
  141. * Color conversion values have 3 separate fixed point formats:
  142. *
  143. * 10 bit fields (ay, au)
  144. * 1.9 fixed point (b.bbbbbbbbb)
  145. * 11 bit fields (ry, by, ru, gu, gv)
  146. * exp.mantissa (ee.mmmmmmmmm)
  147. * ee = 00 = 10^-1 (0.mmmmmmmmm)
  148. * ee = 01 = 10^-2 (0.0mmmmmmmmm)
  149. * ee = 10 = 10^-3 (0.00mmmmmmmmm)
  150. * ee = 11 = 10^-4 (0.000mmmmmmmmm)
  151. * 12 bit fields (gy, rv, bu)
  152. * exp.mantissa (eee.mmmmmmmmm)
  153. * eee = 000 = 10^-1 (0.mmmmmmmmm)
  154. * eee = 001 = 10^-2 (0.0mmmmmmmmm)
  155. * eee = 010 = 10^-3 (0.00mmmmmmmmm)
  156. * eee = 011 = 10^-4 (0.000mmmmmmmmm)
  157. * eee = 100 = reserved
  158. * eee = 101 = reserved
  159. * eee = 110 = reserved
  160. * eee = 111 = 10^0 (m.mmmmmmmm) (only usable for 1.0 representation)
  161. *
  162. * Saturation and contrast are 8 bits, with their own representation:
  163. * 8 bit field (saturation, contrast)
  164. * exp.mantissa (ee.mmmmmm)
  165. * ee = 00 = 10^-1 (0.mmmmmm)
  166. * ee = 01 = 10^0 (m.mmmmm)
  167. * ee = 10 = 10^1 (mm.mmmm)
  168. * ee = 11 = 10^2 (mmm.mmm)
  169. *
  170. * Simple conversion function:
  171. *
  172. * static u32
  173. * float_to_csc_11(float f)
  174. * {
  175. * u32 exp;
  176. * u32 mant;
  177. * u32 ret;
  178. *
  179. * if (f < 0)
  180. * f = -f;
  181. *
  182. * if (f >= 1) {
  183. * exp = 0x7;
  184. * mant = 1 << 8;
  185. * } else {
  186. * for (exp = 0; exp < 3 && f < 0.5; exp++)
  187. * f *= 2.0;
  188. * mant = (f * (1 << 9) + 0.5);
  189. * if (mant >= (1 << 9))
  190. * mant = (1 << 9) - 1;
  191. * }
  192. * ret = (exp << 9) | mant;
  193. * return ret;
  194. * }
  195. */
  196. /*
  197. * Behold, magic numbers! If we plant them they might grow a big
  198. * s-video cable to the sky... or something.
  199. *
  200. * Pre-converted to appropriate hex value.
  201. */
  202. /*
  203. * PAL & NTSC values for composite & s-video connections
  204. */
  205. static const struct color_conversion ntsc_m_csc_composite = {
  206. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0104,
  207. .ru = 0x0733, .gu = 0x052d, .bu = 0x05c7, .au = 0x0200,
  208. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0200,
  209. };
  210. static const struct video_levels ntsc_m_levels_composite = {
  211. .blank = 225, .black = 267, .burst = 113,
  212. };
  213. static const struct color_conversion ntsc_m_csc_svideo = {
  214. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0133,
  215. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0200,
  216. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0200,
  217. };
  218. static const struct video_levels ntsc_m_levels_svideo = {
  219. .blank = 266, .black = 316, .burst = 133,
  220. };
  221. static const struct color_conversion ntsc_j_csc_composite = {
  222. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0119,
  223. .ru = 0x074c, .gu = 0x0546, .bu = 0x05ec, .au = 0x0200,
  224. .rv = 0x035a, .gv = 0x0322, .bv = 0x06e1, .av = 0x0200,
  225. };
  226. static const struct video_levels ntsc_j_levels_composite = {
  227. .blank = 225, .black = 225, .burst = 113,
  228. };
  229. static const struct color_conversion ntsc_j_csc_svideo = {
  230. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x014c,
  231. .ru = 0x0788, .gu = 0x0581, .bu = 0x0322, .au = 0x0200,
  232. .rv = 0x0399, .gv = 0x0356, .bv = 0x070a, .av = 0x0200,
  233. };
  234. static const struct video_levels ntsc_j_levels_svideo = {
  235. .blank = 266, .black = 266, .burst = 133,
  236. };
  237. static const struct color_conversion pal_csc_composite = {
  238. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0113,
  239. .ru = 0x0745, .gu = 0x053f, .bu = 0x05e1, .au = 0x0200,
  240. .rv = 0x0353, .gv = 0x031c, .bv = 0x06dc, .av = 0x0200,
  241. };
  242. static const struct video_levels pal_levels_composite = {
  243. .blank = 237, .black = 237, .burst = 118,
  244. };
  245. static const struct color_conversion pal_csc_svideo = {
  246. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0145,
  247. .ru = 0x0780, .gu = 0x0579, .bu = 0x031c, .au = 0x0200,
  248. .rv = 0x0390, .gv = 0x034f, .bv = 0x0705, .av = 0x0200,
  249. };
  250. static const struct video_levels pal_levels_svideo = {
  251. .blank = 280, .black = 280, .burst = 139,
  252. };
  253. static const struct color_conversion pal_m_csc_composite = {
  254. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0104,
  255. .ru = 0x0733, .gu = 0x052d, .bu = 0x05c7, .au = 0x0200,
  256. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0200,
  257. };
  258. static const struct video_levels pal_m_levels_composite = {
  259. .blank = 225, .black = 267, .burst = 113,
  260. };
  261. static const struct color_conversion pal_m_csc_svideo = {
  262. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0133,
  263. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0200,
  264. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0200,
  265. };
  266. static const struct video_levels pal_m_levels_svideo = {
  267. .blank = 266, .black = 316, .burst = 133,
  268. };
  269. static const struct color_conversion pal_n_csc_composite = {
  270. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0104,
  271. .ru = 0x0733, .gu = 0x052d, .bu = 0x05c7, .au = 0x0200,
  272. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0200,
  273. };
  274. static const struct video_levels pal_n_levels_composite = {
  275. .blank = 225, .black = 267, .burst = 118,
  276. };
  277. static const struct color_conversion pal_n_csc_svideo = {
  278. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0133,
  279. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0200,
  280. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0200,
  281. };
  282. static const struct video_levels pal_n_levels_svideo = {
  283. .blank = 266, .black = 316, .burst = 139,
  284. };
  285. /*
  286. * Component connections
  287. */
  288. static const struct color_conversion sdtv_csc_yprpb = {
  289. .ry = 0x0332, .gy = 0x012d, .by = 0x07d3, .ay = 0x0145,
  290. .ru = 0x0559, .gu = 0x0353, .bu = 0x0100, .au = 0x0200,
  291. .rv = 0x0100, .gv = 0x03ad, .bv = 0x074d, .av = 0x0200,
  292. };
  293. static const struct color_conversion sdtv_csc_rgb = {
  294. .ry = 0x0000, .gy = 0x0f00, .by = 0x0000, .ay = 0x0166,
  295. .ru = 0x0000, .gu = 0x0000, .bu = 0x0f00, .au = 0x0166,
  296. .rv = 0x0f00, .gv = 0x0000, .bv = 0x0000, .av = 0x0166,
  297. };
  298. static const struct color_conversion hdtv_csc_yprpb = {
  299. .ry = 0x05b3, .gy = 0x016e, .by = 0x0728, .ay = 0x0145,
  300. .ru = 0x07d5, .gu = 0x038b, .bu = 0x0100, .au = 0x0200,
  301. .rv = 0x0100, .gv = 0x03d1, .bv = 0x06bc, .av = 0x0200,
  302. };
  303. static const struct color_conversion hdtv_csc_rgb = {
  304. .ry = 0x0000, .gy = 0x0f00, .by = 0x0000, .ay = 0x0166,
  305. .ru = 0x0000, .gu = 0x0000, .bu = 0x0f00, .au = 0x0166,
  306. .rv = 0x0f00, .gv = 0x0000, .bv = 0x0000, .av = 0x0166,
  307. };
  308. static const struct video_levels component_levels = {
  309. .blank = 279, .black = 279, .burst = 0,
  310. };
  311. struct tv_mode {
  312. char *name;
  313. int clock;
  314. int refresh; /* in millihertz (for precision) */
  315. u32 oversample;
  316. int hsync_end, hblank_start, hblank_end, htotal;
  317. bool progressive, trilevel_sync, component_only;
  318. int vsync_start_f1, vsync_start_f2, vsync_len;
  319. bool veq_ena;
  320. int veq_start_f1, veq_start_f2, veq_len;
  321. int vi_end_f1, vi_end_f2, nbr_end;
  322. bool burst_ena;
  323. int hburst_start, hburst_len;
  324. int vburst_start_f1, vburst_end_f1;
  325. int vburst_start_f2, vburst_end_f2;
  326. int vburst_start_f3, vburst_end_f3;
  327. int vburst_start_f4, vburst_end_f4;
  328. /*
  329. * subcarrier programming
  330. */
  331. int dda2_size, dda3_size, dda1_inc, dda2_inc, dda3_inc;
  332. u32 sc_reset;
  333. bool pal_burst;
  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. int 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 = 29970,
  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 = 29970,
  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 = 8,
  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 = 29970,
  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 = 29970,
  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 = 25000,
  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 = 25000,
  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@59.94Hz",
  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 = "480p@60Hz",
  595. .clock = 107520,
  596. .refresh = 60000,
  597. .oversample = TV_OVERSAMPLE_4X,
  598. .component_only = 1,
  599. .hsync_end = 64, .hblank_end = 122,
  600. .hblank_start = 842, .htotal = 856,
  601. .progressive = true,.trilevel_sync = false,
  602. .vsync_start_f1 = 12, .vsync_start_f2 = 12,
  603. .vsync_len = 12,
  604. .veq_ena = false,
  605. .vi_end_f1 = 44, .vi_end_f2 = 44,
  606. .nbr_end = 479,
  607. .burst_ena = false,
  608. .filter_table = filter_table,
  609. },
  610. {
  611. .name = "576p",
  612. .clock = 107520,
  613. .refresh = 50000,
  614. .oversample = TV_OVERSAMPLE_4X,
  615. .component_only = 1,
  616. .hsync_end = 64, .hblank_end = 139,
  617. .hblank_start = 859, .htotal = 863,
  618. .progressive = true, .trilevel_sync = false,
  619. .vsync_start_f1 = 10, .vsync_start_f2 = 10,
  620. .vsync_len = 10,
  621. .veq_ena = false,
  622. .vi_end_f1 = 48, .vi_end_f2 = 48,
  623. .nbr_end = 575,
  624. .burst_ena = false,
  625. .filter_table = filter_table,
  626. },
  627. {
  628. .name = "720p@60Hz",
  629. .clock = 148800,
  630. .refresh = 60000,
  631. .oversample = TV_OVERSAMPLE_2X,
  632. .component_only = 1,
  633. .hsync_end = 80, .hblank_end = 300,
  634. .hblank_start = 1580, .htotal = 1649,
  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. },
  644. {
  645. .name = "720p@59.94Hz",
  646. .clock = 148800,
  647. .refresh = 59940,
  648. .oversample = TV_OVERSAMPLE_2X,
  649. .component_only = 1,
  650. .hsync_end = 80, .hblank_end = 300,
  651. .hblank_start = 1580, .htotal = 1651,
  652. .progressive = true, .trilevel_sync = true,
  653. .vsync_start_f1 = 10, .vsync_start_f2 = 10,
  654. .vsync_len = 10,
  655. .veq_ena = false,
  656. .vi_end_f1 = 29, .vi_end_f2 = 29,
  657. .nbr_end = 719,
  658. .burst_ena = false,
  659. .filter_table = filter_table,
  660. },
  661. {
  662. .name = "720p@50Hz",
  663. .clock = 148800,
  664. .refresh = 50000,
  665. .oversample = TV_OVERSAMPLE_2X,
  666. .component_only = 1,
  667. .hsync_end = 80, .hblank_end = 300,
  668. .hblank_start = 1580, .htotal = 1979,
  669. .progressive = true, .trilevel_sync = true,
  670. .vsync_start_f1 = 10, .vsync_start_f2 = 10,
  671. .vsync_len = 10,
  672. .veq_ena = false,
  673. .vi_end_f1 = 29, .vi_end_f2 = 29,
  674. .nbr_end = 719,
  675. .burst_ena = false,
  676. .filter_table = filter_table,
  677. .max_srcw = 800
  678. },
  679. {
  680. .name = "1080i@50Hz",
  681. .clock = 148800,
  682. .refresh = 25000,
  683. .oversample = TV_OVERSAMPLE_2X,
  684. .component_only = 1,
  685. .hsync_end = 88, .hblank_end = 235,
  686. .hblank_start = 2155, .htotal = 2639,
  687. .progressive = false, .trilevel_sync = true,
  688. .vsync_start_f1 = 4, .vsync_start_f2 = 5,
  689. .vsync_len = 10,
  690. .veq_ena = true, .veq_start_f1 = 4,
  691. .veq_start_f2 = 4, .veq_len = 10,
  692. .vi_end_f1 = 21, .vi_end_f2 = 22,
  693. .nbr_end = 539,
  694. .burst_ena = false,
  695. .filter_table = filter_table,
  696. },
  697. {
  698. .name = "1080i@60Hz",
  699. .clock = 148800,
  700. .refresh = 30000,
  701. .oversample = TV_OVERSAMPLE_2X,
  702. .component_only = 1,
  703. .hsync_end = 88, .hblank_end = 235,
  704. .hblank_start = 2155, .htotal = 2199,
  705. .progressive = false, .trilevel_sync = true,
  706. .vsync_start_f1 = 4, .vsync_start_f2 = 5,
  707. .vsync_len = 10,
  708. .veq_ena = true, .veq_start_f1 = 4,
  709. .veq_start_f2 = 4, .veq_len = 10,
  710. .vi_end_f1 = 21, .vi_end_f2 = 22,
  711. .nbr_end = 539,
  712. .burst_ena = false,
  713. .filter_table = filter_table,
  714. },
  715. {
  716. .name = "1080i@59.94Hz",
  717. .clock = 148800,
  718. .refresh = 29970,
  719. .oversample = TV_OVERSAMPLE_2X,
  720. .component_only = 1,
  721. .hsync_end = 88, .hblank_end = 235,
  722. .hblank_start = 2155, .htotal = 2201,
  723. .progressive = false, .trilevel_sync = true,
  724. .vsync_start_f1 = 4, .vsync_start_f2 = 5,
  725. .vsync_len = 10,
  726. .veq_ena = true, .veq_start_f1 = 4,
  727. .veq_start_f2 = 4, .veq_len = 10,
  728. .vi_end_f1 = 21, .vi_end_f2 = 22,
  729. .nbr_end = 539,
  730. .burst_ena = false,
  731. .filter_table = filter_table,
  732. },
  733. };
  734. #define NUM_TV_MODES sizeof(tv_modes) / sizeof (tv_modes[0])
  735. static void
  736. intel_tv_dpms(struct drm_encoder *encoder, int mode)
  737. {
  738. struct drm_device *dev = encoder->dev;
  739. struct drm_i915_private *dev_priv = dev->dev_private;
  740. switch(mode) {
  741. case DRM_MODE_DPMS_ON:
  742. I915_WRITE(TV_CTL, I915_READ(TV_CTL) | TV_ENC_ENABLE);
  743. break;
  744. case DRM_MODE_DPMS_STANDBY:
  745. case DRM_MODE_DPMS_SUSPEND:
  746. case DRM_MODE_DPMS_OFF:
  747. I915_WRITE(TV_CTL, I915_READ(TV_CTL) & ~TV_ENC_ENABLE);
  748. break;
  749. }
  750. }
  751. static void
  752. intel_tv_save(struct drm_connector *connector)
  753. {
  754. struct drm_device *dev = connector->dev;
  755. struct drm_i915_private *dev_priv = dev->dev_private;
  756. struct intel_output *intel_output = to_intel_output(connector);
  757. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  758. int i;
  759. tv_priv->save_TV_H_CTL_1 = I915_READ(TV_H_CTL_1);
  760. tv_priv->save_TV_H_CTL_2 = I915_READ(TV_H_CTL_2);
  761. tv_priv->save_TV_H_CTL_3 = I915_READ(TV_H_CTL_3);
  762. tv_priv->save_TV_V_CTL_1 = I915_READ(TV_V_CTL_1);
  763. tv_priv->save_TV_V_CTL_2 = I915_READ(TV_V_CTL_2);
  764. tv_priv->save_TV_V_CTL_3 = I915_READ(TV_V_CTL_3);
  765. tv_priv->save_TV_V_CTL_4 = I915_READ(TV_V_CTL_4);
  766. tv_priv->save_TV_V_CTL_5 = I915_READ(TV_V_CTL_5);
  767. tv_priv->save_TV_V_CTL_6 = I915_READ(TV_V_CTL_6);
  768. tv_priv->save_TV_V_CTL_7 = I915_READ(TV_V_CTL_7);
  769. tv_priv->save_TV_SC_CTL_1 = I915_READ(TV_SC_CTL_1);
  770. tv_priv->save_TV_SC_CTL_2 = I915_READ(TV_SC_CTL_2);
  771. tv_priv->save_TV_SC_CTL_3 = I915_READ(TV_SC_CTL_3);
  772. tv_priv->save_TV_CSC_Y = I915_READ(TV_CSC_Y);
  773. tv_priv->save_TV_CSC_Y2 = I915_READ(TV_CSC_Y2);
  774. tv_priv->save_TV_CSC_U = I915_READ(TV_CSC_U);
  775. tv_priv->save_TV_CSC_U2 = I915_READ(TV_CSC_U2);
  776. tv_priv->save_TV_CSC_V = I915_READ(TV_CSC_V);
  777. tv_priv->save_TV_CSC_V2 = I915_READ(TV_CSC_V2);
  778. tv_priv->save_TV_CLR_KNOBS = I915_READ(TV_CLR_KNOBS);
  779. tv_priv->save_TV_CLR_LEVEL = I915_READ(TV_CLR_LEVEL);
  780. tv_priv->save_TV_WIN_POS = I915_READ(TV_WIN_POS);
  781. tv_priv->save_TV_WIN_SIZE = I915_READ(TV_WIN_SIZE);
  782. tv_priv->save_TV_FILTER_CTL_1 = I915_READ(TV_FILTER_CTL_1);
  783. tv_priv->save_TV_FILTER_CTL_2 = I915_READ(TV_FILTER_CTL_2);
  784. tv_priv->save_TV_FILTER_CTL_3 = I915_READ(TV_FILTER_CTL_3);
  785. for (i = 0; i < 60; i++)
  786. tv_priv->save_TV_H_LUMA[i] = I915_READ(TV_H_LUMA_0 + (i <<2));
  787. for (i = 0; i < 60; i++)
  788. tv_priv->save_TV_H_CHROMA[i] = I915_READ(TV_H_CHROMA_0 + (i <<2));
  789. for (i = 0; i < 43; i++)
  790. tv_priv->save_TV_V_LUMA[i] = I915_READ(TV_V_LUMA_0 + (i <<2));
  791. for (i = 0; i < 43; i++)
  792. tv_priv->save_TV_V_CHROMA[i] = I915_READ(TV_V_CHROMA_0 + (i <<2));
  793. tv_priv->save_TV_DAC = I915_READ(TV_DAC);
  794. tv_priv->save_TV_CTL = I915_READ(TV_CTL);
  795. }
  796. static void
  797. intel_tv_restore(struct drm_connector *connector)
  798. {
  799. struct drm_device *dev = connector->dev;
  800. struct drm_i915_private *dev_priv = dev->dev_private;
  801. struct intel_output *intel_output = to_intel_output(connector);
  802. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  803. struct drm_crtc *crtc = connector->encoder->crtc;
  804. struct intel_crtc *intel_crtc;
  805. int i;
  806. /* FIXME: No CRTC? */
  807. if (!crtc)
  808. return;
  809. intel_crtc = to_intel_crtc(crtc);
  810. I915_WRITE(TV_H_CTL_1, tv_priv->save_TV_H_CTL_1);
  811. I915_WRITE(TV_H_CTL_2, tv_priv->save_TV_H_CTL_2);
  812. I915_WRITE(TV_H_CTL_3, tv_priv->save_TV_H_CTL_3);
  813. I915_WRITE(TV_V_CTL_1, tv_priv->save_TV_V_CTL_1);
  814. I915_WRITE(TV_V_CTL_2, tv_priv->save_TV_V_CTL_2);
  815. I915_WRITE(TV_V_CTL_3, tv_priv->save_TV_V_CTL_3);
  816. I915_WRITE(TV_V_CTL_4, tv_priv->save_TV_V_CTL_4);
  817. I915_WRITE(TV_V_CTL_5, tv_priv->save_TV_V_CTL_5);
  818. I915_WRITE(TV_V_CTL_6, tv_priv->save_TV_V_CTL_6);
  819. I915_WRITE(TV_V_CTL_7, tv_priv->save_TV_V_CTL_7);
  820. I915_WRITE(TV_SC_CTL_1, tv_priv->save_TV_SC_CTL_1);
  821. I915_WRITE(TV_SC_CTL_2, tv_priv->save_TV_SC_CTL_2);
  822. I915_WRITE(TV_SC_CTL_3, tv_priv->save_TV_SC_CTL_3);
  823. I915_WRITE(TV_CSC_Y, tv_priv->save_TV_CSC_Y);
  824. I915_WRITE(TV_CSC_Y2, tv_priv->save_TV_CSC_Y2);
  825. I915_WRITE(TV_CSC_U, tv_priv->save_TV_CSC_U);
  826. I915_WRITE(TV_CSC_U2, tv_priv->save_TV_CSC_U2);
  827. I915_WRITE(TV_CSC_V, tv_priv->save_TV_CSC_V);
  828. I915_WRITE(TV_CSC_V2, tv_priv->save_TV_CSC_V2);
  829. I915_WRITE(TV_CLR_KNOBS, tv_priv->save_TV_CLR_KNOBS);
  830. I915_WRITE(TV_CLR_LEVEL, tv_priv->save_TV_CLR_LEVEL);
  831. {
  832. int pipeconf_reg = (intel_crtc->pipe == 0) ?
  833. PIPEACONF : PIPEBCONF;
  834. int dspcntr_reg = (intel_crtc->plane == 0) ?
  835. DSPACNTR : DSPBCNTR;
  836. int pipeconf = I915_READ(pipeconf_reg);
  837. int dspcntr = I915_READ(dspcntr_reg);
  838. int dspbase_reg = (intel_crtc->plane == 0) ?
  839. DSPAADDR : DSPBADDR;
  840. /* Pipe must be off here */
  841. I915_WRITE(dspcntr_reg, dspcntr & ~DISPLAY_PLANE_ENABLE);
  842. /* Flush the plane changes */
  843. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  844. if (!IS_I9XX(dev)) {
  845. /* Wait for vblank for the disable to take effect */
  846. intel_wait_for_vblank(dev);
  847. }
  848. I915_WRITE(pipeconf_reg, pipeconf & ~PIPEACONF_ENABLE);
  849. /* Wait for vblank for the disable to take effect. */
  850. intel_wait_for_vblank(dev);
  851. /* Filter ctl must be set before TV_WIN_SIZE */
  852. I915_WRITE(TV_FILTER_CTL_1, tv_priv->save_TV_FILTER_CTL_1);
  853. I915_WRITE(TV_FILTER_CTL_2, tv_priv->save_TV_FILTER_CTL_2);
  854. I915_WRITE(TV_FILTER_CTL_3, tv_priv->save_TV_FILTER_CTL_3);
  855. I915_WRITE(TV_WIN_POS, tv_priv->save_TV_WIN_POS);
  856. I915_WRITE(TV_WIN_SIZE, tv_priv->save_TV_WIN_SIZE);
  857. I915_WRITE(pipeconf_reg, pipeconf);
  858. I915_WRITE(dspcntr_reg, dspcntr);
  859. /* Flush the plane changes */
  860. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  861. }
  862. for (i = 0; i < 60; i++)
  863. I915_WRITE(TV_H_LUMA_0 + (i <<2), tv_priv->save_TV_H_LUMA[i]);
  864. for (i = 0; i < 60; i++)
  865. I915_WRITE(TV_H_CHROMA_0 + (i <<2), tv_priv->save_TV_H_CHROMA[i]);
  866. for (i = 0; i < 43; i++)
  867. I915_WRITE(TV_V_LUMA_0 + (i <<2), tv_priv->save_TV_V_LUMA[i]);
  868. for (i = 0; i < 43; i++)
  869. I915_WRITE(TV_V_CHROMA_0 + (i <<2), tv_priv->save_TV_V_CHROMA[i]);
  870. I915_WRITE(TV_DAC, tv_priv->save_TV_DAC);
  871. I915_WRITE(TV_CTL, tv_priv->save_TV_CTL);
  872. }
  873. static const struct tv_mode *
  874. intel_tv_mode_lookup (char *tv_format)
  875. {
  876. int i;
  877. for (i = 0; i < sizeof(tv_modes) / sizeof (tv_modes[0]); i++) {
  878. const struct tv_mode *tv_mode = &tv_modes[i];
  879. if (!strcmp(tv_format, tv_mode->name))
  880. return tv_mode;
  881. }
  882. return NULL;
  883. }
  884. static const struct tv_mode *
  885. intel_tv_mode_find (struct intel_output *intel_output)
  886. {
  887. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  888. return intel_tv_mode_lookup(tv_priv->tv_format);
  889. }
  890. static enum drm_mode_status
  891. intel_tv_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode)
  892. {
  893. struct intel_output *intel_output = to_intel_output(connector);
  894. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output);
  895. /* Ensure TV refresh is close to desired refresh */
  896. if (tv_mode && abs(tv_mode->refresh - drm_mode_vrefresh(mode)) < 10)
  897. return MODE_OK;
  898. return MODE_CLOCK_RANGE;
  899. }
  900. static bool
  901. intel_tv_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
  902. struct drm_display_mode *adjusted_mode)
  903. {
  904. struct drm_device *dev = encoder->dev;
  905. struct drm_mode_config *drm_config = &dev->mode_config;
  906. struct intel_output *intel_output = enc_to_intel_output(encoder);
  907. const struct tv_mode *tv_mode = intel_tv_mode_find (intel_output);
  908. struct drm_encoder *other_encoder;
  909. if (!tv_mode)
  910. return false;
  911. /* FIXME: lock encoder list */
  912. list_for_each_entry(other_encoder, &drm_config->encoder_list, head) {
  913. if (other_encoder != encoder &&
  914. other_encoder->crtc == encoder->crtc)
  915. return false;
  916. }
  917. adjusted_mode->clock = tv_mode->clock;
  918. return true;
  919. }
  920. static void
  921. intel_tv_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  922. struct drm_display_mode *adjusted_mode)
  923. {
  924. struct drm_device *dev = encoder->dev;
  925. struct drm_i915_private *dev_priv = dev->dev_private;
  926. struct drm_crtc *crtc = encoder->crtc;
  927. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  928. struct intel_output *intel_output = enc_to_intel_output(encoder);
  929. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  930. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output);
  931. u32 tv_ctl;
  932. u32 hctl1, hctl2, hctl3;
  933. u32 vctl1, vctl2, vctl3, vctl4, vctl5, vctl6, vctl7;
  934. u32 scctl1, scctl2, scctl3;
  935. int i, j;
  936. const struct video_levels *video_levels;
  937. const struct color_conversion *color_conversion;
  938. bool burst_ena;
  939. if (!tv_mode)
  940. return; /* can't happen (mode_prepare prevents this) */
  941. tv_ctl = I915_READ(TV_CTL);
  942. tv_ctl &= TV_CTL_SAVE;
  943. switch (tv_priv->type) {
  944. default:
  945. case DRM_MODE_CONNECTOR_Unknown:
  946. case DRM_MODE_CONNECTOR_Composite:
  947. tv_ctl |= TV_ENC_OUTPUT_COMPOSITE;
  948. video_levels = tv_mode->composite_levels;
  949. color_conversion = tv_mode->composite_color;
  950. burst_ena = tv_mode->burst_ena;
  951. break;
  952. case DRM_MODE_CONNECTOR_Component:
  953. tv_ctl |= TV_ENC_OUTPUT_COMPONENT;
  954. video_levels = &component_levels;
  955. if (tv_mode->burst_ena)
  956. color_conversion = &sdtv_csc_yprpb;
  957. else
  958. color_conversion = &hdtv_csc_yprpb;
  959. burst_ena = false;
  960. break;
  961. case DRM_MODE_CONNECTOR_SVIDEO:
  962. tv_ctl |= TV_ENC_OUTPUT_SVIDEO;
  963. video_levels = tv_mode->svideo_levels;
  964. color_conversion = tv_mode->svideo_color;
  965. burst_ena = tv_mode->burst_ena;
  966. break;
  967. }
  968. hctl1 = (tv_mode->hsync_end << TV_HSYNC_END_SHIFT) |
  969. (tv_mode->htotal << TV_HTOTAL_SHIFT);
  970. hctl2 = (tv_mode->hburst_start << 16) |
  971. (tv_mode->hburst_len << TV_HBURST_LEN_SHIFT);
  972. if (burst_ena)
  973. hctl2 |= TV_BURST_ENA;
  974. hctl3 = (tv_mode->hblank_start << TV_HBLANK_START_SHIFT) |
  975. (tv_mode->hblank_end << TV_HBLANK_END_SHIFT);
  976. vctl1 = (tv_mode->nbr_end << TV_NBR_END_SHIFT) |
  977. (tv_mode->vi_end_f1 << TV_VI_END_F1_SHIFT) |
  978. (tv_mode->vi_end_f2 << TV_VI_END_F2_SHIFT);
  979. vctl2 = (tv_mode->vsync_len << TV_VSYNC_LEN_SHIFT) |
  980. (tv_mode->vsync_start_f1 << TV_VSYNC_START_F1_SHIFT) |
  981. (tv_mode->vsync_start_f2 << TV_VSYNC_START_F2_SHIFT);
  982. vctl3 = (tv_mode->veq_len << TV_VEQ_LEN_SHIFT) |
  983. (tv_mode->veq_start_f1 << TV_VEQ_START_F1_SHIFT) |
  984. (tv_mode->veq_start_f2 << TV_VEQ_START_F2_SHIFT);
  985. if (tv_mode->veq_ena)
  986. vctl3 |= TV_EQUAL_ENA;
  987. vctl4 = (tv_mode->vburst_start_f1 << TV_VBURST_START_F1_SHIFT) |
  988. (tv_mode->vburst_end_f1 << TV_VBURST_END_F1_SHIFT);
  989. vctl5 = (tv_mode->vburst_start_f2 << TV_VBURST_START_F2_SHIFT) |
  990. (tv_mode->vburst_end_f2 << TV_VBURST_END_F2_SHIFT);
  991. vctl6 = (tv_mode->vburst_start_f3 << TV_VBURST_START_F3_SHIFT) |
  992. (tv_mode->vburst_end_f3 << TV_VBURST_END_F3_SHIFT);
  993. vctl7 = (tv_mode->vburst_start_f4 << TV_VBURST_START_F4_SHIFT) |
  994. (tv_mode->vburst_end_f4 << TV_VBURST_END_F4_SHIFT);
  995. if (intel_crtc->pipe == 1)
  996. tv_ctl |= TV_ENC_PIPEB_SELECT;
  997. tv_ctl |= tv_mode->oversample;
  998. if (tv_mode->progressive)
  999. tv_ctl |= TV_PROGRESSIVE;
  1000. if (tv_mode->trilevel_sync)
  1001. tv_ctl |= TV_TRILEVEL_SYNC;
  1002. if (tv_mode->pal_burst)
  1003. tv_ctl |= TV_PAL_BURST;
  1004. scctl1 = 0;
  1005. /* dda1 implies valid video levels */
  1006. if (tv_mode->dda1_inc) {
  1007. scctl1 |= TV_SC_DDA1_EN;
  1008. }
  1009. if (tv_mode->dda2_inc)
  1010. scctl1 |= TV_SC_DDA2_EN;
  1011. if (tv_mode->dda3_inc)
  1012. scctl1 |= TV_SC_DDA3_EN;
  1013. scctl1 |= tv_mode->sc_reset;
  1014. scctl1 |= video_levels->burst << TV_BURST_LEVEL_SHIFT;
  1015. scctl1 |= tv_mode->dda1_inc << TV_SCDDA1_INC_SHIFT;
  1016. scctl2 = tv_mode->dda2_size << TV_SCDDA2_SIZE_SHIFT |
  1017. tv_mode->dda2_inc << TV_SCDDA2_INC_SHIFT;
  1018. scctl3 = tv_mode->dda3_size << TV_SCDDA3_SIZE_SHIFT |
  1019. tv_mode->dda3_inc << TV_SCDDA3_INC_SHIFT;
  1020. /* Enable two fixes for the chips that need them. */
  1021. if (dev->pci_device < 0x2772)
  1022. tv_ctl |= TV_ENC_C0_FIX | TV_ENC_SDP_FIX;
  1023. I915_WRITE(TV_H_CTL_1, hctl1);
  1024. I915_WRITE(TV_H_CTL_2, hctl2);
  1025. I915_WRITE(TV_H_CTL_3, hctl3);
  1026. I915_WRITE(TV_V_CTL_1, vctl1);
  1027. I915_WRITE(TV_V_CTL_2, vctl2);
  1028. I915_WRITE(TV_V_CTL_3, vctl3);
  1029. I915_WRITE(TV_V_CTL_4, vctl4);
  1030. I915_WRITE(TV_V_CTL_5, vctl5);
  1031. I915_WRITE(TV_V_CTL_6, vctl6);
  1032. I915_WRITE(TV_V_CTL_7, vctl7);
  1033. I915_WRITE(TV_SC_CTL_1, scctl1);
  1034. I915_WRITE(TV_SC_CTL_2, scctl2);
  1035. I915_WRITE(TV_SC_CTL_3, scctl3);
  1036. if (color_conversion) {
  1037. I915_WRITE(TV_CSC_Y, (color_conversion->ry << 16) |
  1038. color_conversion->gy);
  1039. I915_WRITE(TV_CSC_Y2,(color_conversion->by << 16) |
  1040. color_conversion->ay);
  1041. I915_WRITE(TV_CSC_U, (color_conversion->ru << 16) |
  1042. color_conversion->gu);
  1043. I915_WRITE(TV_CSC_U2, (color_conversion->bu << 16) |
  1044. color_conversion->au);
  1045. I915_WRITE(TV_CSC_V, (color_conversion->rv << 16) |
  1046. color_conversion->gv);
  1047. I915_WRITE(TV_CSC_V2, (color_conversion->bv << 16) |
  1048. color_conversion->av);
  1049. }
  1050. if (IS_I965G(dev))
  1051. I915_WRITE(TV_CLR_KNOBS, 0x00404000);
  1052. else
  1053. I915_WRITE(TV_CLR_KNOBS, 0x00606000);
  1054. if (video_levels)
  1055. I915_WRITE(TV_CLR_LEVEL,
  1056. ((video_levels->black << TV_BLACK_LEVEL_SHIFT) |
  1057. (video_levels->blank << TV_BLANK_LEVEL_SHIFT)));
  1058. {
  1059. int pipeconf_reg = (intel_crtc->pipe == 0) ?
  1060. PIPEACONF : PIPEBCONF;
  1061. int dspcntr_reg = (intel_crtc->plane == 0) ?
  1062. DSPACNTR : DSPBCNTR;
  1063. int pipeconf = I915_READ(pipeconf_reg);
  1064. int dspcntr = I915_READ(dspcntr_reg);
  1065. int dspbase_reg = (intel_crtc->plane == 0) ?
  1066. DSPAADDR : DSPBADDR;
  1067. int xpos = 0x0, ypos = 0x0;
  1068. unsigned int xsize, ysize;
  1069. /* Pipe must be off here */
  1070. I915_WRITE(dspcntr_reg, dspcntr & ~DISPLAY_PLANE_ENABLE);
  1071. /* Flush the plane changes */
  1072. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1073. /* Wait for vblank for the disable to take effect */
  1074. if (!IS_I9XX(dev))
  1075. intel_wait_for_vblank(dev);
  1076. I915_WRITE(pipeconf_reg, pipeconf & ~PIPEACONF_ENABLE);
  1077. /* Wait for vblank for the disable to take effect. */
  1078. intel_wait_for_vblank(dev);
  1079. /* Filter ctl must be set before TV_WIN_SIZE */
  1080. I915_WRITE(TV_FILTER_CTL_1, TV_AUTO_SCALE);
  1081. xsize = tv_mode->hblank_start - tv_mode->hblank_end;
  1082. if (tv_mode->progressive)
  1083. ysize = tv_mode->nbr_end + 1;
  1084. else
  1085. ysize = 2*tv_mode->nbr_end + 1;
  1086. xpos += tv_priv->margin[TV_MARGIN_LEFT];
  1087. ypos += tv_priv->margin[TV_MARGIN_TOP];
  1088. xsize -= (tv_priv->margin[TV_MARGIN_LEFT] +
  1089. tv_priv->margin[TV_MARGIN_RIGHT]);
  1090. ysize -= (tv_priv->margin[TV_MARGIN_TOP] +
  1091. tv_priv->margin[TV_MARGIN_BOTTOM]);
  1092. I915_WRITE(TV_WIN_POS, (xpos<<16)|ypos);
  1093. I915_WRITE(TV_WIN_SIZE, (xsize<<16)|ysize);
  1094. I915_WRITE(pipeconf_reg, pipeconf);
  1095. I915_WRITE(dspcntr_reg, dspcntr);
  1096. /* Flush the plane changes */
  1097. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1098. }
  1099. j = 0;
  1100. for (i = 0; i < 60; i++)
  1101. I915_WRITE(TV_H_LUMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1102. for (i = 0; i < 60; i++)
  1103. I915_WRITE(TV_H_CHROMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1104. for (i = 0; i < 43; i++)
  1105. I915_WRITE(TV_V_LUMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1106. for (i = 0; i < 43; i++)
  1107. I915_WRITE(TV_V_CHROMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1108. I915_WRITE(TV_DAC, 0);
  1109. I915_WRITE(TV_CTL, tv_ctl);
  1110. }
  1111. static const struct drm_display_mode reported_modes[] = {
  1112. {
  1113. .name = "NTSC 480i",
  1114. .clock = 107520,
  1115. .hdisplay = 1280,
  1116. .hsync_start = 1368,
  1117. .hsync_end = 1496,
  1118. .htotal = 1712,
  1119. .vdisplay = 1024,
  1120. .vsync_start = 1027,
  1121. .vsync_end = 1034,
  1122. .vtotal = 1104,
  1123. .type = DRM_MODE_TYPE_DRIVER,
  1124. },
  1125. };
  1126. /**
  1127. * Detects TV presence by checking for load.
  1128. *
  1129. * Requires that the current pipe's DPLL is active.
  1130. * \return true if TV is connected.
  1131. * \return false if TV is disconnected.
  1132. */
  1133. static int
  1134. intel_tv_detect_type (struct drm_crtc *crtc, struct intel_output *intel_output)
  1135. {
  1136. struct drm_encoder *encoder = &intel_output->enc;
  1137. struct drm_device *dev = encoder->dev;
  1138. struct drm_i915_private *dev_priv = dev->dev_private;
  1139. unsigned long irqflags;
  1140. u32 tv_ctl, save_tv_ctl;
  1141. u32 tv_dac, save_tv_dac;
  1142. int type = DRM_MODE_CONNECTOR_Unknown;
  1143. tv_dac = I915_READ(TV_DAC);
  1144. /* Disable TV interrupts around load detect or we'll recurse */
  1145. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  1146. i915_disable_pipestat(dev_priv, 0, PIPE_HOTPLUG_INTERRUPT_ENABLE |
  1147. PIPE_HOTPLUG_TV_INTERRUPT_ENABLE);
  1148. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  1149. /*
  1150. * Detect TV by polling)
  1151. */
  1152. save_tv_dac = tv_dac;
  1153. tv_ctl = I915_READ(TV_CTL);
  1154. save_tv_ctl = tv_ctl;
  1155. tv_ctl &= ~TV_ENC_ENABLE;
  1156. tv_ctl &= ~TV_TEST_MODE_MASK;
  1157. tv_ctl |= TV_TEST_MODE_MONITOR_DETECT;
  1158. tv_dac &= ~TVDAC_SENSE_MASK;
  1159. tv_dac &= ~DAC_A_MASK;
  1160. tv_dac &= ~DAC_B_MASK;
  1161. tv_dac &= ~DAC_C_MASK;
  1162. tv_dac |= (TVDAC_STATE_CHG_EN |
  1163. TVDAC_A_SENSE_CTL |
  1164. TVDAC_B_SENSE_CTL |
  1165. TVDAC_C_SENSE_CTL |
  1166. DAC_CTL_OVERRIDE |
  1167. DAC_A_0_7_V |
  1168. DAC_B_0_7_V |
  1169. DAC_C_0_7_V);
  1170. I915_WRITE(TV_CTL, tv_ctl);
  1171. I915_WRITE(TV_DAC, tv_dac);
  1172. intel_wait_for_vblank(dev);
  1173. tv_dac = I915_READ(TV_DAC);
  1174. I915_WRITE(TV_DAC, save_tv_dac);
  1175. I915_WRITE(TV_CTL, save_tv_ctl);
  1176. intel_wait_for_vblank(dev);
  1177. /*
  1178. * A B C
  1179. * 0 1 1 Composite
  1180. * 1 0 X svideo
  1181. * 0 0 0 Component
  1182. */
  1183. if ((tv_dac & TVDAC_SENSE_MASK) == (TVDAC_B_SENSE | TVDAC_C_SENSE)) {
  1184. DRM_DEBUG("Detected Composite TV connection\n");
  1185. type = DRM_MODE_CONNECTOR_Composite;
  1186. } else if ((tv_dac & (TVDAC_A_SENSE|TVDAC_B_SENSE)) == TVDAC_A_SENSE) {
  1187. DRM_DEBUG("Detected S-Video TV connection\n");
  1188. type = DRM_MODE_CONNECTOR_SVIDEO;
  1189. } else if ((tv_dac & TVDAC_SENSE_MASK) == 0) {
  1190. DRM_DEBUG("Detected Component TV connection\n");
  1191. type = DRM_MODE_CONNECTOR_Component;
  1192. } else {
  1193. DRM_DEBUG("No TV connection detected\n");
  1194. type = -1;
  1195. }
  1196. /* Restore interrupt config */
  1197. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  1198. i915_enable_pipestat(dev_priv, 0, PIPE_HOTPLUG_INTERRUPT_ENABLE |
  1199. PIPE_HOTPLUG_TV_INTERRUPT_ENABLE);
  1200. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  1201. return type;
  1202. }
  1203. /**
  1204. * Detect the TV connection.
  1205. *
  1206. * Currently this always returns CONNECTOR_STATUS_UNKNOWN, as we need to be sure
  1207. * we have a pipe programmed in order to probe the TV.
  1208. */
  1209. static enum drm_connector_status
  1210. intel_tv_detect(struct drm_connector *connector)
  1211. {
  1212. struct drm_crtc *crtc;
  1213. struct drm_display_mode mode;
  1214. struct intel_output *intel_output = to_intel_output(connector);
  1215. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  1216. struct drm_encoder *encoder = &intel_output->enc;
  1217. int dpms_mode;
  1218. int type = tv_priv->type;
  1219. mode = reported_modes[0];
  1220. drm_mode_set_crtcinfo(&mode, CRTC_INTERLACE_HALVE_V);
  1221. if (encoder->crtc && encoder->crtc->enabled) {
  1222. type = intel_tv_detect_type(encoder->crtc, intel_output);
  1223. } else {
  1224. crtc = intel_get_load_detect_pipe(intel_output, &mode, &dpms_mode);
  1225. if (crtc) {
  1226. type = intel_tv_detect_type(crtc, intel_output);
  1227. intel_release_load_detect_pipe(intel_output, dpms_mode);
  1228. } else
  1229. type = -1;
  1230. }
  1231. tv_priv->type = type;
  1232. if (type < 0)
  1233. return connector_status_disconnected;
  1234. return connector_status_connected;
  1235. }
  1236. static struct input_res {
  1237. char *name;
  1238. int w, h;
  1239. } input_res_table[] =
  1240. {
  1241. {"640x480", 640, 480},
  1242. {"800x600", 800, 600},
  1243. {"1024x768", 1024, 768},
  1244. {"1280x1024", 1280, 1024},
  1245. {"848x480", 848, 480},
  1246. {"1280x720", 1280, 720},
  1247. {"1920x1080", 1920, 1080},
  1248. };
  1249. /**
  1250. * Stub get_modes function.
  1251. *
  1252. * This should probably return a set of fixed modes, unless we can figure out
  1253. * how to probe modes off of TV connections.
  1254. */
  1255. static int
  1256. intel_tv_get_modes(struct drm_connector *connector)
  1257. {
  1258. struct drm_display_mode *mode_ptr;
  1259. struct intel_output *intel_output = to_intel_output(connector);
  1260. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output);
  1261. int j, count = 0;
  1262. u64 tmp;
  1263. for (j = 0; j < sizeof(input_res_table) / sizeof(input_res_table[0]);
  1264. j++) {
  1265. struct input_res *input = &input_res_table[j];
  1266. unsigned int hactive_s = input->w;
  1267. unsigned int vactive_s = input->h;
  1268. if (tv_mode->max_srcw && input->w > tv_mode->max_srcw)
  1269. continue;
  1270. if (input->w > 1024 && (!tv_mode->progressive
  1271. && !tv_mode->component_only))
  1272. continue;
  1273. mode_ptr = drm_mode_create(connector->dev);
  1274. if (!mode_ptr)
  1275. continue;
  1276. strncpy(mode_ptr->name, input->name, DRM_DISPLAY_MODE_LEN);
  1277. mode_ptr->hdisplay = hactive_s;
  1278. mode_ptr->hsync_start = hactive_s + 1;
  1279. mode_ptr->hsync_end = hactive_s + 64;
  1280. if (mode_ptr->hsync_end <= mode_ptr->hsync_start)
  1281. mode_ptr->hsync_end = mode_ptr->hsync_start + 1;
  1282. mode_ptr->htotal = hactive_s + 96;
  1283. mode_ptr->vdisplay = vactive_s;
  1284. mode_ptr->vsync_start = vactive_s + 1;
  1285. mode_ptr->vsync_end = vactive_s + 32;
  1286. if (mode_ptr->vsync_end <= mode_ptr->vsync_start)
  1287. mode_ptr->vsync_end = mode_ptr->vsync_start + 1;
  1288. mode_ptr->vtotal = vactive_s + 33;
  1289. tmp = (u64) tv_mode->refresh * mode_ptr->vtotal;
  1290. tmp *= mode_ptr->htotal;
  1291. tmp = div_u64(tmp, 1000000);
  1292. mode_ptr->clock = (int) tmp;
  1293. mode_ptr->type = DRM_MODE_TYPE_DRIVER;
  1294. drm_mode_probed_add(connector, mode_ptr);
  1295. count++;
  1296. }
  1297. return count;
  1298. }
  1299. static void
  1300. intel_tv_destroy (struct drm_connector *connector)
  1301. {
  1302. struct intel_output *intel_output = to_intel_output(connector);
  1303. drm_sysfs_connector_remove(connector);
  1304. drm_connector_cleanup(connector);
  1305. kfree(intel_output);
  1306. }
  1307. static int
  1308. intel_tv_set_property(struct drm_connector *connector, struct drm_property *property,
  1309. uint64_t val)
  1310. {
  1311. struct drm_device *dev = connector->dev;
  1312. struct intel_output *intel_output = to_intel_output(connector);
  1313. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  1314. struct drm_encoder *encoder = &intel_output->enc;
  1315. struct drm_crtc *crtc = encoder->crtc;
  1316. int ret = 0;
  1317. bool changed = false;
  1318. ret = drm_connector_property_set_value(connector, property, val);
  1319. if (ret < 0)
  1320. goto out;
  1321. if (property == dev->mode_config.tv_left_margin_property &&
  1322. tv_priv->margin[TV_MARGIN_LEFT] != val) {
  1323. tv_priv->margin[TV_MARGIN_LEFT] = val;
  1324. changed = true;
  1325. } else if (property == dev->mode_config.tv_right_margin_property &&
  1326. tv_priv->margin[TV_MARGIN_RIGHT] != val) {
  1327. tv_priv->margin[TV_MARGIN_RIGHT] = val;
  1328. changed = true;
  1329. } else if (property == dev->mode_config.tv_top_margin_property &&
  1330. tv_priv->margin[TV_MARGIN_TOP] != val) {
  1331. tv_priv->margin[TV_MARGIN_TOP] = val;
  1332. changed = true;
  1333. } else if (property == dev->mode_config.tv_bottom_margin_property &&
  1334. tv_priv->margin[TV_MARGIN_BOTTOM] != val) {
  1335. tv_priv->margin[TV_MARGIN_BOTTOM] = val;
  1336. changed = true;
  1337. } else if (property == dev->mode_config.tv_mode_property) {
  1338. if (val >= NUM_TV_MODES) {
  1339. ret = -EINVAL;
  1340. goto out;
  1341. }
  1342. if (!strcmp(tv_priv->tv_format, tv_modes[val].name))
  1343. goto out;
  1344. tv_priv->tv_format = tv_modes[val].name;
  1345. changed = true;
  1346. } else {
  1347. ret = -EINVAL;
  1348. goto out;
  1349. }
  1350. if (changed && crtc)
  1351. drm_crtc_helper_set_mode(crtc, &crtc->mode, crtc->x,
  1352. crtc->y, crtc->fb);
  1353. out:
  1354. return ret;
  1355. }
  1356. static const struct drm_encoder_helper_funcs intel_tv_helper_funcs = {
  1357. .dpms = intel_tv_dpms,
  1358. .mode_fixup = intel_tv_mode_fixup,
  1359. .prepare = intel_encoder_prepare,
  1360. .mode_set = intel_tv_mode_set,
  1361. .commit = intel_encoder_commit,
  1362. };
  1363. static const struct drm_connector_funcs intel_tv_connector_funcs = {
  1364. .dpms = drm_helper_connector_dpms,
  1365. .save = intel_tv_save,
  1366. .restore = intel_tv_restore,
  1367. .detect = intel_tv_detect,
  1368. .destroy = intel_tv_destroy,
  1369. .set_property = intel_tv_set_property,
  1370. .fill_modes = drm_helper_probe_single_connector_modes,
  1371. };
  1372. static const struct drm_connector_helper_funcs intel_tv_connector_helper_funcs = {
  1373. .mode_valid = intel_tv_mode_valid,
  1374. .get_modes = intel_tv_get_modes,
  1375. .best_encoder = intel_best_encoder,
  1376. };
  1377. static void intel_tv_enc_destroy(struct drm_encoder *encoder)
  1378. {
  1379. drm_encoder_cleanup(encoder);
  1380. }
  1381. static const struct drm_encoder_funcs intel_tv_enc_funcs = {
  1382. .destroy = intel_tv_enc_destroy,
  1383. };
  1384. void
  1385. intel_tv_init(struct drm_device *dev)
  1386. {
  1387. struct drm_i915_private *dev_priv = dev->dev_private;
  1388. struct drm_connector *connector;
  1389. struct intel_output *intel_output;
  1390. struct intel_tv_priv *tv_priv;
  1391. u32 tv_dac_on, tv_dac_off, save_tv_dac;
  1392. char **tv_format_names;
  1393. int i, initial_mode = 0;
  1394. if ((I915_READ(TV_CTL) & TV_FUSE_STATE_MASK) == TV_FUSE_STATE_DISABLED)
  1395. return;
  1396. /* Even if we have an encoder we may not have a connector */
  1397. if (!dev_priv->int_tv_support)
  1398. return;
  1399. /*
  1400. * Sanity check the TV output by checking to see if the
  1401. * DAC register holds a value
  1402. */
  1403. save_tv_dac = I915_READ(TV_DAC);
  1404. I915_WRITE(TV_DAC, save_tv_dac | TVDAC_STATE_CHG_EN);
  1405. tv_dac_on = I915_READ(TV_DAC);
  1406. I915_WRITE(TV_DAC, save_tv_dac & ~TVDAC_STATE_CHG_EN);
  1407. tv_dac_off = I915_READ(TV_DAC);
  1408. I915_WRITE(TV_DAC, save_tv_dac);
  1409. /*
  1410. * If the register does not hold the state change enable
  1411. * bit, (either as a 0 or a 1), assume it doesn't really
  1412. * exist
  1413. */
  1414. if ((tv_dac_on & TVDAC_STATE_CHG_EN) == 0 ||
  1415. (tv_dac_off & TVDAC_STATE_CHG_EN) != 0)
  1416. return;
  1417. intel_output = kzalloc(sizeof(struct intel_output) +
  1418. sizeof(struct intel_tv_priv), GFP_KERNEL);
  1419. if (!intel_output) {
  1420. return;
  1421. }
  1422. connector = &intel_output->base;
  1423. drm_connector_init(dev, connector, &intel_tv_connector_funcs,
  1424. DRM_MODE_CONNECTOR_SVIDEO);
  1425. drm_encoder_init(dev, &intel_output->enc, &intel_tv_enc_funcs,
  1426. DRM_MODE_ENCODER_TVDAC);
  1427. drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc);
  1428. tv_priv = (struct intel_tv_priv *)(intel_output + 1);
  1429. intel_output->type = INTEL_OUTPUT_TVOUT;
  1430. intel_output->enc.possible_crtcs = ((1 << 0) | (1 << 1));
  1431. intel_output->enc.possible_clones = (1 << INTEL_OUTPUT_TVOUT);
  1432. intel_output->dev_priv = tv_priv;
  1433. tv_priv->type = DRM_MODE_CONNECTOR_Unknown;
  1434. /* BIOS margin values */
  1435. tv_priv->margin[TV_MARGIN_LEFT] = 54;
  1436. tv_priv->margin[TV_MARGIN_TOP] = 36;
  1437. tv_priv->margin[TV_MARGIN_RIGHT] = 46;
  1438. tv_priv->margin[TV_MARGIN_BOTTOM] = 37;
  1439. tv_priv->tv_format = kstrdup(tv_modes[initial_mode].name, GFP_KERNEL);
  1440. drm_encoder_helper_add(&intel_output->enc, &intel_tv_helper_funcs);
  1441. drm_connector_helper_add(connector, &intel_tv_connector_helper_funcs);
  1442. connector->interlace_allowed = false;
  1443. connector->doublescan_allowed = false;
  1444. /* Create TV properties then attach current values */
  1445. tv_format_names = kmalloc(sizeof(char *) * NUM_TV_MODES,
  1446. GFP_KERNEL);
  1447. if (!tv_format_names)
  1448. goto out;
  1449. for (i = 0; i < NUM_TV_MODES; i++)
  1450. tv_format_names[i] = tv_modes[i].name;
  1451. drm_mode_create_tv_properties(dev, NUM_TV_MODES, tv_format_names);
  1452. drm_connector_attach_property(connector, dev->mode_config.tv_mode_property,
  1453. initial_mode);
  1454. drm_connector_attach_property(connector,
  1455. dev->mode_config.tv_left_margin_property,
  1456. tv_priv->margin[TV_MARGIN_LEFT]);
  1457. drm_connector_attach_property(connector,
  1458. dev->mode_config.tv_top_margin_property,
  1459. tv_priv->margin[TV_MARGIN_TOP]);
  1460. drm_connector_attach_property(connector,
  1461. dev->mode_config.tv_right_margin_property,
  1462. tv_priv->margin[TV_MARGIN_RIGHT]);
  1463. drm_connector_attach_property(connector,
  1464. dev->mode_config.tv_bottom_margin_property,
  1465. tv_priv->margin[TV_MARGIN_BOTTOM]);
  1466. out:
  1467. drm_sysfs_connector_add(connector);
  1468. }