intel_tv.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725
  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 = 0x0f00,
  208. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0f00,
  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 = 0x0134,
  215. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0f00,
  216. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0f00,
  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 = 0x0f00,
  224. .rv = 0x035a, .gv = 0x0322, .bv = 0x06e1, .av = 0x0f00,
  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 = 0x0f00,
  232. .rv = 0x0399, .gv = 0x0356, .bv = 0x070a, .av = 0x0f00,
  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 = 0x0f00,
  240. .rv = 0x0353, .gv = 0x031c, .bv = 0x06dc, .av = 0x0f00,
  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 = 0x0f00,
  248. .rv = 0x0390, .gv = 0x034f, .bv = 0x0705, .av = 0x0f00,
  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 = 0x0f00,
  256. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0f00,
  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 = 0x0134,
  263. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0f00,
  264. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0f00,
  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 = 0x0f00,
  272. .rv = 0x0340, .gv = 0x030c, .bv = 0x06d0, .av = 0x0f00,
  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 = 0x0134,
  279. .ru = 0x076a, .gu = 0x0564, .bu = 0x030d, .au = 0x0f00,
  280. .rv = 0x037a, .gv = 0x033d, .bv = 0x06f6, .av = 0x0f00,
  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 = 0x0146,
  290. .ru = 0x0559, .gu = 0x0353, .bu = 0x0100, .au = 0x0f00,
  291. .rv = 0x0100, .gv = 0x03ad, .bv = 0x074d, .av = 0x0f00,
  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 = 0x0146,
  300. .ru = 0x07d5, .gu = 0x038b, .bu = 0x0100, .au = 0x0f00,
  301. .rv = 0x0100, .gv = 0x03d1, .bv = 0x06bc, .av = 0x0f00,
  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. const static struct tv_mode tv_modes[] = {
  372. {
  373. .name = "NTSC-M",
  374. .clock = 107520,
  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 = 136,
  396. .dda2_inc = 7624, .dda2_size = 20013,
  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 = 107520,
  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 = 18557, .dda2_size = 20625,
  431. .dda3_inc = 0, .dda3_size = 0,
  432. .sc_reset = TV_SC_RESET_EVERY_8,
  433. .pal_burst = true,
  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 = 107520,
  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 = 136,
  464. .dda2_inc = 7624, .dda2_size = 20013,
  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 = 107520,
  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 = 136,
  498. .dda2_inc = 7624, .dda2_size = 20013,
  499. .dda3_inc = 0, .dda3_size = 0,
  500. .sc_reset = TV_SC_RESET_EVERY_4,
  501. .pal_burst = false,
  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 = 107520,
  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 = 168,
  532. .dda2_inc = 18557, .dda2_size = 20625,
  533. .dda3_inc = 0, .dda3_size = 0,
  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 = 107520,
  546. .refresh = 25000,
  547. .oversample = TV_OVERSAMPLE_8X,
  548. .component_only = 0,
  549. .hsync_end = 64, .hblank_end = 128,
  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 = 18557, .dda2_size = 20625,
  567. .dda3_inc = 0, .dda3_size = 0,
  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 = 496,
  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 = 496,
  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 = 2200,
  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)) < 1)
  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 = 0;
  942. switch (tv_priv->type) {
  943. default:
  944. case DRM_MODE_CONNECTOR_Unknown:
  945. case DRM_MODE_CONNECTOR_Composite:
  946. tv_ctl |= TV_ENC_OUTPUT_COMPOSITE;
  947. video_levels = tv_mode->composite_levels;
  948. color_conversion = tv_mode->composite_color;
  949. burst_ena = tv_mode->burst_ena;
  950. break;
  951. case DRM_MODE_CONNECTOR_Component:
  952. tv_ctl |= TV_ENC_OUTPUT_COMPONENT;
  953. video_levels = &component_levels;
  954. if (tv_mode->burst_ena)
  955. color_conversion = &sdtv_csc_yprpb;
  956. else
  957. color_conversion = &hdtv_csc_yprpb;
  958. burst_ena = false;
  959. break;
  960. case DRM_MODE_CONNECTOR_SVIDEO:
  961. tv_ctl |= TV_ENC_OUTPUT_SVIDEO;
  962. video_levels = tv_mode->svideo_levels;
  963. color_conversion = tv_mode->svideo_color;
  964. burst_ena = tv_mode->burst_ena;
  965. break;
  966. }
  967. hctl1 = (tv_mode->hsync_end << TV_HSYNC_END_SHIFT) |
  968. (tv_mode->htotal << TV_HTOTAL_SHIFT);
  969. hctl2 = (tv_mode->hburst_start << 16) |
  970. (tv_mode->hburst_len << TV_HBURST_LEN_SHIFT);
  971. if (burst_ena)
  972. hctl2 |= TV_BURST_ENA;
  973. hctl3 = (tv_mode->hblank_start << TV_HBLANK_START_SHIFT) |
  974. (tv_mode->hblank_end << TV_HBLANK_END_SHIFT);
  975. vctl1 = (tv_mode->nbr_end << TV_NBR_END_SHIFT) |
  976. (tv_mode->vi_end_f1 << TV_VI_END_F1_SHIFT) |
  977. (tv_mode->vi_end_f2 << TV_VI_END_F2_SHIFT);
  978. vctl2 = (tv_mode->vsync_len << TV_VSYNC_LEN_SHIFT) |
  979. (tv_mode->vsync_start_f1 << TV_VSYNC_START_F1_SHIFT) |
  980. (tv_mode->vsync_start_f2 << TV_VSYNC_START_F2_SHIFT);
  981. vctl3 = (tv_mode->veq_len << TV_VEQ_LEN_SHIFT) |
  982. (tv_mode->veq_start_f1 << TV_VEQ_START_F1_SHIFT) |
  983. (tv_mode->veq_start_f2 << TV_VEQ_START_F2_SHIFT);
  984. if (tv_mode->veq_ena)
  985. vctl3 |= TV_EQUAL_ENA;
  986. vctl4 = (tv_mode->vburst_start_f1 << TV_VBURST_START_F1_SHIFT) |
  987. (tv_mode->vburst_end_f1 << TV_VBURST_END_F1_SHIFT);
  988. vctl5 = (tv_mode->vburst_start_f2 << TV_VBURST_START_F2_SHIFT) |
  989. (tv_mode->vburst_end_f2 << TV_VBURST_END_F2_SHIFT);
  990. vctl6 = (tv_mode->vburst_start_f3 << TV_VBURST_START_F3_SHIFT) |
  991. (tv_mode->vburst_end_f3 << TV_VBURST_END_F3_SHIFT);
  992. vctl7 = (tv_mode->vburst_start_f4 << TV_VBURST_START_F4_SHIFT) |
  993. (tv_mode->vburst_end_f4 << TV_VBURST_END_F4_SHIFT);
  994. if (intel_crtc->pipe == 1)
  995. tv_ctl |= TV_ENC_PIPEB_SELECT;
  996. tv_ctl |= tv_mode->oversample;
  997. if (tv_mode->progressive)
  998. tv_ctl |= TV_PROGRESSIVE;
  999. if (tv_mode->trilevel_sync)
  1000. tv_ctl |= TV_TRILEVEL_SYNC;
  1001. if (tv_mode->pal_burst)
  1002. tv_ctl |= TV_PAL_BURST;
  1003. scctl1 = 0;
  1004. /* dda1 implies valid video levels */
  1005. if (tv_mode->dda1_inc) {
  1006. scctl1 |= TV_SC_DDA1_EN;
  1007. scctl1 |= video_levels->burst << TV_BURST_LEVEL_SHIFT;
  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 |= tv_mode->dda1_inc << TV_SCDDA1_INC_SHIFT;
  1015. scctl2 = tv_mode->dda2_size << TV_SCDDA2_SIZE_SHIFT |
  1016. tv_mode->dda2_inc << TV_SCDDA2_INC_SHIFT;
  1017. scctl3 = tv_mode->dda3_size << TV_SCDDA3_SIZE_SHIFT |
  1018. tv_mode->dda3_inc << TV_SCDDA3_INC_SHIFT;
  1019. /* Enable two fixes for the chips that need them. */
  1020. if (dev->pci_device < 0x2772)
  1021. tv_ctl |= TV_ENC_C0_FIX | TV_ENC_SDP_FIX;
  1022. I915_WRITE(TV_H_CTL_1, hctl1);
  1023. I915_WRITE(TV_H_CTL_2, hctl2);
  1024. I915_WRITE(TV_H_CTL_3, hctl3);
  1025. I915_WRITE(TV_V_CTL_1, vctl1);
  1026. I915_WRITE(TV_V_CTL_2, vctl2);
  1027. I915_WRITE(TV_V_CTL_3, vctl3);
  1028. I915_WRITE(TV_V_CTL_4, vctl4);
  1029. I915_WRITE(TV_V_CTL_5, vctl5);
  1030. I915_WRITE(TV_V_CTL_6, vctl6);
  1031. I915_WRITE(TV_V_CTL_7, vctl7);
  1032. I915_WRITE(TV_SC_CTL_1, scctl1);
  1033. I915_WRITE(TV_SC_CTL_2, scctl2);
  1034. I915_WRITE(TV_SC_CTL_3, scctl3);
  1035. if (color_conversion) {
  1036. I915_WRITE(TV_CSC_Y, (color_conversion->ry << 16) |
  1037. color_conversion->gy);
  1038. I915_WRITE(TV_CSC_Y2,(color_conversion->by << 16) |
  1039. color_conversion->ay);
  1040. I915_WRITE(TV_CSC_U, (color_conversion->ru << 16) |
  1041. color_conversion->gu);
  1042. I915_WRITE(TV_CSC_U2, (color_conversion->bu << 16) |
  1043. color_conversion->au);
  1044. I915_WRITE(TV_CSC_V, (color_conversion->rv << 16) |
  1045. color_conversion->gv);
  1046. I915_WRITE(TV_CSC_V2, (color_conversion->bv << 16) |
  1047. color_conversion->av);
  1048. }
  1049. I915_WRITE(TV_CLR_KNOBS, 0x00606000);
  1050. if (video_levels)
  1051. I915_WRITE(TV_CLR_LEVEL,
  1052. ((video_levels->black << TV_BLACK_LEVEL_SHIFT) |
  1053. (video_levels->blank << TV_BLANK_LEVEL_SHIFT)));
  1054. {
  1055. int pipeconf_reg = (intel_crtc->pipe == 0) ?
  1056. PIPEACONF : PIPEBCONF;
  1057. int dspcntr_reg = (intel_crtc->plane == 0) ?
  1058. DSPACNTR : DSPBCNTR;
  1059. int pipeconf = I915_READ(pipeconf_reg);
  1060. int dspcntr = I915_READ(dspcntr_reg);
  1061. int dspbase_reg = (intel_crtc->plane == 0) ?
  1062. DSPAADDR : DSPBADDR;
  1063. int xpos = 0x0, ypos = 0x0;
  1064. unsigned int xsize, ysize;
  1065. /* Pipe must be off here */
  1066. I915_WRITE(dspcntr_reg, dspcntr & ~DISPLAY_PLANE_ENABLE);
  1067. /* Flush the plane changes */
  1068. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1069. /* Wait for vblank for the disable to take effect */
  1070. if (!IS_I9XX(dev))
  1071. intel_wait_for_vblank(dev);
  1072. I915_WRITE(pipeconf_reg, pipeconf & ~PIPEACONF_ENABLE);
  1073. /* Wait for vblank for the disable to take effect. */
  1074. intel_wait_for_vblank(dev);
  1075. /* Filter ctl must be set before TV_WIN_SIZE */
  1076. I915_WRITE(TV_FILTER_CTL_1, TV_AUTO_SCALE);
  1077. xsize = tv_mode->hblank_start - tv_mode->hblank_end;
  1078. if (tv_mode->progressive)
  1079. ysize = tv_mode->nbr_end + 1;
  1080. else
  1081. ysize = 2*tv_mode->nbr_end + 1;
  1082. xpos += tv_priv->margin[TV_MARGIN_LEFT];
  1083. ypos += tv_priv->margin[TV_MARGIN_TOP];
  1084. xsize -= (tv_priv->margin[TV_MARGIN_LEFT] +
  1085. tv_priv->margin[TV_MARGIN_RIGHT]);
  1086. ysize -= (tv_priv->margin[TV_MARGIN_TOP] +
  1087. tv_priv->margin[TV_MARGIN_BOTTOM]);
  1088. I915_WRITE(TV_WIN_POS, (xpos<<16)|ypos);
  1089. I915_WRITE(TV_WIN_SIZE, (xsize<<16)|ysize);
  1090. I915_WRITE(pipeconf_reg, pipeconf);
  1091. I915_WRITE(dspcntr_reg, dspcntr);
  1092. /* Flush the plane changes */
  1093. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  1094. }
  1095. j = 0;
  1096. for (i = 0; i < 60; i++)
  1097. I915_WRITE(TV_H_LUMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1098. for (i = 0; i < 60; i++)
  1099. I915_WRITE(TV_H_CHROMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1100. for (i = 0; i < 43; i++)
  1101. I915_WRITE(TV_V_LUMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1102. for (i = 0; i < 43; i++)
  1103. I915_WRITE(TV_V_CHROMA_0 + (i<<2), tv_mode->filter_table[j++]);
  1104. I915_WRITE(TV_DAC, 0);
  1105. I915_WRITE(TV_CTL, tv_ctl);
  1106. }
  1107. static const struct drm_display_mode reported_modes[] = {
  1108. {
  1109. .name = "NTSC 480i",
  1110. .clock = 107520,
  1111. .hdisplay = 1280,
  1112. .hsync_start = 1368,
  1113. .hsync_end = 1496,
  1114. .htotal = 1712,
  1115. .vdisplay = 1024,
  1116. .vsync_start = 1027,
  1117. .vsync_end = 1034,
  1118. .vtotal = 1104,
  1119. .type = DRM_MODE_TYPE_DRIVER,
  1120. },
  1121. };
  1122. /**
  1123. * Detects TV presence by checking for load.
  1124. *
  1125. * Requires that the current pipe's DPLL is active.
  1126. * \return true if TV is connected.
  1127. * \return false if TV is disconnected.
  1128. */
  1129. static int
  1130. intel_tv_detect_type (struct drm_crtc *crtc, struct intel_output *intel_output)
  1131. {
  1132. struct drm_encoder *encoder = &intel_output->enc;
  1133. struct drm_device *dev = encoder->dev;
  1134. struct drm_i915_private *dev_priv = dev->dev_private;
  1135. unsigned long irqflags;
  1136. u32 tv_ctl, save_tv_ctl;
  1137. u32 tv_dac, save_tv_dac;
  1138. int type = DRM_MODE_CONNECTOR_Unknown;
  1139. tv_dac = I915_READ(TV_DAC);
  1140. /* Disable TV interrupts around load detect or we'll recurse */
  1141. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  1142. i915_disable_pipestat(dev_priv, 0, PIPE_HOTPLUG_INTERRUPT_ENABLE |
  1143. PIPE_HOTPLUG_TV_INTERRUPT_ENABLE);
  1144. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  1145. /*
  1146. * Detect TV by polling)
  1147. */
  1148. if (intel_output->load_detect_temp) {
  1149. /* TV not currently running, prod it with destructive detect */
  1150. save_tv_dac = tv_dac;
  1151. tv_ctl = I915_READ(TV_CTL);
  1152. save_tv_ctl = tv_ctl;
  1153. tv_ctl &= ~TV_ENC_ENABLE;
  1154. tv_ctl &= ~TV_TEST_MODE_MASK;
  1155. tv_ctl |= TV_TEST_MODE_MONITOR_DETECT;
  1156. tv_dac &= ~TVDAC_SENSE_MASK;
  1157. tv_dac |= (TVDAC_STATE_CHG_EN |
  1158. TVDAC_A_SENSE_CTL |
  1159. TVDAC_B_SENSE_CTL |
  1160. TVDAC_C_SENSE_CTL |
  1161. DAC_CTL_OVERRIDE |
  1162. DAC_A_0_7_V |
  1163. DAC_B_0_7_V |
  1164. DAC_C_0_7_V);
  1165. I915_WRITE(TV_CTL, tv_ctl);
  1166. I915_WRITE(TV_DAC, tv_dac);
  1167. intel_wait_for_vblank(dev);
  1168. tv_dac = I915_READ(TV_DAC);
  1169. I915_WRITE(TV_DAC, save_tv_dac);
  1170. I915_WRITE(TV_CTL, save_tv_ctl);
  1171. }
  1172. /*
  1173. * A B C
  1174. * 0 1 1 Composite
  1175. * 1 0 X svideo
  1176. * 0 0 0 Component
  1177. */
  1178. if ((tv_dac & TVDAC_SENSE_MASK) == (TVDAC_B_SENSE | TVDAC_C_SENSE)) {
  1179. DRM_DEBUG("Detected Composite TV connection\n");
  1180. type = DRM_MODE_CONNECTOR_Composite;
  1181. } else if ((tv_dac & (TVDAC_A_SENSE|TVDAC_B_SENSE)) == TVDAC_A_SENSE) {
  1182. DRM_DEBUG("Detected S-Video TV connection\n");
  1183. type = DRM_MODE_CONNECTOR_SVIDEO;
  1184. } else if ((tv_dac & TVDAC_SENSE_MASK) == 0) {
  1185. DRM_DEBUG("Detected Component TV connection\n");
  1186. type = DRM_MODE_CONNECTOR_Component;
  1187. } else {
  1188. DRM_DEBUG("No TV connection detected\n");
  1189. type = -1;
  1190. }
  1191. /* Restore interrupt config */
  1192. spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags);
  1193. i915_enable_pipestat(dev_priv, 0, PIPE_HOTPLUG_INTERRUPT_ENABLE |
  1194. PIPE_HOTPLUG_TV_INTERRUPT_ENABLE);
  1195. spin_unlock_irqrestore(&dev_priv->user_irq_lock, irqflags);
  1196. return type;
  1197. }
  1198. /**
  1199. * Detect the TV connection.
  1200. *
  1201. * Currently this always returns CONNECTOR_STATUS_UNKNOWN, as we need to be sure
  1202. * we have a pipe programmed in order to probe the TV.
  1203. */
  1204. static enum drm_connector_status
  1205. intel_tv_detect(struct drm_connector *connector)
  1206. {
  1207. struct drm_crtc *crtc;
  1208. struct drm_display_mode mode;
  1209. struct intel_output *intel_output = to_intel_output(connector);
  1210. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  1211. struct drm_encoder *encoder = &intel_output->enc;
  1212. int dpms_mode;
  1213. int type = tv_priv->type;
  1214. mode = reported_modes[0];
  1215. drm_mode_set_crtcinfo(&mode, CRTC_INTERLACE_HALVE_V);
  1216. if (encoder->crtc) {
  1217. type = intel_tv_detect_type(encoder->crtc, intel_output);
  1218. } else {
  1219. crtc = intel_get_load_detect_pipe(intel_output, &mode, &dpms_mode);
  1220. if (crtc) {
  1221. type = intel_tv_detect_type(crtc, intel_output);
  1222. intel_release_load_detect_pipe(intel_output, dpms_mode);
  1223. } else
  1224. type = -1;
  1225. }
  1226. if (type < 0)
  1227. return connector_status_disconnected;
  1228. return connector_status_connected;
  1229. }
  1230. static struct input_res {
  1231. char *name;
  1232. int w, h;
  1233. } input_res_table[] =
  1234. {
  1235. {"640x480", 640, 480},
  1236. {"800x600", 800, 600},
  1237. {"1024x768", 1024, 768},
  1238. {"1280x1024", 1280, 1024},
  1239. {"848x480", 848, 480},
  1240. {"1280x720", 1280, 720},
  1241. {"1920x1080", 1920, 1080},
  1242. };
  1243. /**
  1244. * Stub get_modes function.
  1245. *
  1246. * This should probably return a set of fixed modes, unless we can figure out
  1247. * how to probe modes off of TV connections.
  1248. */
  1249. static int
  1250. intel_tv_get_modes(struct drm_connector *connector)
  1251. {
  1252. struct drm_display_mode *mode_ptr;
  1253. struct intel_output *intel_output = to_intel_output(connector);
  1254. const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output);
  1255. int j;
  1256. for (j = 0; j < sizeof(input_res_table) / sizeof(input_res_table[0]);
  1257. j++) {
  1258. struct input_res *input = &input_res_table[j];
  1259. unsigned int hactive_s = input->w;
  1260. unsigned int vactive_s = input->h;
  1261. if (tv_mode->max_srcw && input->w > tv_mode->max_srcw)
  1262. continue;
  1263. if (input->w > 1024 && (!tv_mode->progressive
  1264. && !tv_mode->component_only))
  1265. continue;
  1266. mode_ptr = drm_calloc(1, sizeof(struct drm_display_mode),
  1267. DRM_MEM_DRIVER);
  1268. strncpy(mode_ptr->name, input->name, DRM_DISPLAY_MODE_LEN);
  1269. mode_ptr->hdisplay = hactive_s;
  1270. mode_ptr->hsync_start = hactive_s + 1;
  1271. mode_ptr->hsync_end = hactive_s + 64;
  1272. if (mode_ptr->hsync_end <= mode_ptr->hsync_start)
  1273. mode_ptr->hsync_end = mode_ptr->hsync_start + 1;
  1274. mode_ptr->htotal = hactive_s + 96;
  1275. mode_ptr->vdisplay = vactive_s;
  1276. mode_ptr->vsync_start = vactive_s + 1;
  1277. mode_ptr->vsync_end = vactive_s + 32;
  1278. if (mode_ptr->vsync_end <= mode_ptr->vsync_start)
  1279. mode_ptr->vsync_end = mode_ptr->vsync_start + 1;
  1280. mode_ptr->vtotal = vactive_s + 33;
  1281. mode_ptr->clock = (int) (tv_mode->refresh *
  1282. mode_ptr->vtotal *
  1283. mode_ptr->htotal / 1000) / 1000;
  1284. mode_ptr->type = DRM_MODE_TYPE_DRIVER;
  1285. drm_mode_probed_add(connector, mode_ptr);
  1286. }
  1287. return 0;
  1288. }
  1289. static void
  1290. intel_tv_destroy (struct drm_connector *connector)
  1291. {
  1292. struct intel_output *intel_output = to_intel_output(connector);
  1293. drm_sysfs_connector_remove(connector);
  1294. drm_connector_cleanup(connector);
  1295. drm_free(intel_output, sizeof(struct intel_output) + sizeof(struct intel_tv_priv),
  1296. DRM_MEM_DRIVER);
  1297. }
  1298. static int
  1299. intel_tv_set_property(struct drm_connector *connector, struct drm_property *property,
  1300. uint64_t val)
  1301. {
  1302. struct drm_device *dev = connector->dev;
  1303. struct intel_output *intel_output = to_intel_output(connector);
  1304. struct intel_tv_priv *tv_priv = intel_output->dev_priv;
  1305. int ret = 0;
  1306. ret = drm_connector_property_set_value(connector, property, val);
  1307. if (ret < 0)
  1308. goto out;
  1309. if (property == dev->mode_config.tv_left_margin_property)
  1310. tv_priv->margin[TV_MARGIN_LEFT] = val;
  1311. else if (property == dev->mode_config.tv_right_margin_property)
  1312. tv_priv->margin[TV_MARGIN_RIGHT] = val;
  1313. else if (property == dev->mode_config.tv_top_margin_property)
  1314. tv_priv->margin[TV_MARGIN_TOP] = val;
  1315. else if (property == dev->mode_config.tv_bottom_margin_property)
  1316. tv_priv->margin[TV_MARGIN_BOTTOM] = val;
  1317. else if (property == dev->mode_config.tv_mode_property) {
  1318. if (val >= NUM_TV_MODES) {
  1319. ret = -EINVAL;
  1320. goto out;
  1321. }
  1322. tv_priv->tv_format = tv_modes[val].name;
  1323. intel_tv_mode_set(&intel_output->enc, NULL, NULL);
  1324. } else {
  1325. ret = -EINVAL;
  1326. goto out;
  1327. }
  1328. intel_tv_mode_set(&intel_output->enc, NULL, NULL);
  1329. out:
  1330. return ret;
  1331. }
  1332. static const struct drm_encoder_helper_funcs intel_tv_helper_funcs = {
  1333. .dpms = intel_tv_dpms,
  1334. .mode_fixup = intel_tv_mode_fixup,
  1335. .prepare = intel_encoder_prepare,
  1336. .mode_set = intel_tv_mode_set,
  1337. .commit = intel_encoder_commit,
  1338. };
  1339. static const struct drm_connector_funcs intel_tv_connector_funcs = {
  1340. .save = intel_tv_save,
  1341. .restore = intel_tv_restore,
  1342. .detect = intel_tv_detect,
  1343. .destroy = intel_tv_destroy,
  1344. .set_property = intel_tv_set_property,
  1345. .fill_modes = drm_helper_probe_single_connector_modes,
  1346. };
  1347. static const struct drm_connector_helper_funcs intel_tv_connector_helper_funcs = {
  1348. .mode_valid = intel_tv_mode_valid,
  1349. .get_modes = intel_tv_get_modes,
  1350. .best_encoder = intel_best_encoder,
  1351. };
  1352. static void intel_tv_enc_destroy(struct drm_encoder *encoder)
  1353. {
  1354. drm_encoder_cleanup(encoder);
  1355. }
  1356. static const struct drm_encoder_funcs intel_tv_enc_funcs = {
  1357. .destroy = intel_tv_enc_destroy,
  1358. };
  1359. void
  1360. intel_tv_init(struct drm_device *dev)
  1361. {
  1362. struct drm_i915_private *dev_priv = dev->dev_private;
  1363. struct drm_connector *connector;
  1364. struct intel_output *intel_output;
  1365. struct intel_tv_priv *tv_priv;
  1366. u32 tv_dac_on, tv_dac_off, save_tv_dac;
  1367. char **tv_format_names;
  1368. int i, initial_mode = 0;
  1369. if ((I915_READ(TV_CTL) & TV_FUSE_STATE_MASK) == TV_FUSE_STATE_DISABLED)
  1370. return;
  1371. /* Even if we have an encoder we may not have a connector */
  1372. if (!dev_priv->int_tv_support)
  1373. return;
  1374. /*
  1375. * Sanity check the TV output by checking to see if the
  1376. * DAC register holds a value
  1377. */
  1378. save_tv_dac = I915_READ(TV_DAC);
  1379. I915_WRITE(TV_DAC, save_tv_dac | TVDAC_STATE_CHG_EN);
  1380. tv_dac_on = I915_READ(TV_DAC);
  1381. I915_WRITE(TV_DAC, save_tv_dac & ~TVDAC_STATE_CHG_EN);
  1382. tv_dac_off = I915_READ(TV_DAC);
  1383. I915_WRITE(TV_DAC, save_tv_dac);
  1384. /*
  1385. * If the register does not hold the state change enable
  1386. * bit, (either as a 0 or a 1), assume it doesn't really
  1387. * exist
  1388. */
  1389. if ((tv_dac_on & TVDAC_STATE_CHG_EN) == 0 ||
  1390. (tv_dac_off & TVDAC_STATE_CHG_EN) != 0)
  1391. return;
  1392. intel_output = drm_calloc(1, sizeof(struct intel_output) +
  1393. sizeof(struct intel_tv_priv), DRM_MEM_DRIVER);
  1394. if (!intel_output) {
  1395. return;
  1396. }
  1397. connector = &intel_output->base;
  1398. drm_connector_init(dev, connector, &intel_tv_connector_funcs,
  1399. DRM_MODE_CONNECTOR_SVIDEO);
  1400. drm_encoder_init(dev, &intel_output->enc, &intel_tv_enc_funcs,
  1401. DRM_MODE_ENCODER_TVDAC);
  1402. drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc);
  1403. tv_priv = (struct intel_tv_priv *)(intel_output + 1);
  1404. intel_output->type = INTEL_OUTPUT_TVOUT;
  1405. intel_output->enc.possible_crtcs = ((1 << 0) | (1 << 1));
  1406. intel_output->enc.possible_clones = (1 << INTEL_OUTPUT_TVOUT);
  1407. intel_output->dev_priv = tv_priv;
  1408. tv_priv->type = DRM_MODE_CONNECTOR_Unknown;
  1409. /* BIOS margin values */
  1410. tv_priv->margin[TV_MARGIN_LEFT] = 54;
  1411. tv_priv->margin[TV_MARGIN_TOP] = 36;
  1412. tv_priv->margin[TV_MARGIN_RIGHT] = 46;
  1413. tv_priv->margin[TV_MARGIN_BOTTOM] = 37;
  1414. tv_priv->tv_format = kstrdup(tv_modes[initial_mode].name, GFP_KERNEL);
  1415. drm_encoder_helper_add(&intel_output->enc, &intel_tv_helper_funcs);
  1416. drm_connector_helper_add(connector, &intel_tv_connector_helper_funcs);
  1417. connector->interlace_allowed = false;
  1418. connector->doublescan_allowed = false;
  1419. /* Create TV properties then attach current values */
  1420. tv_format_names = drm_alloc(sizeof(char *) * NUM_TV_MODES,
  1421. DRM_MEM_DRIVER);
  1422. if (!tv_format_names)
  1423. goto out;
  1424. for (i = 0; i < NUM_TV_MODES; i++)
  1425. tv_format_names[i] = tv_modes[i].name;
  1426. drm_mode_create_tv_properties(dev, NUM_TV_MODES, tv_format_names);
  1427. drm_connector_attach_property(connector, dev->mode_config.tv_mode_property,
  1428. initial_mode);
  1429. drm_connector_attach_property(connector,
  1430. dev->mode_config.tv_left_margin_property,
  1431. tv_priv->margin[TV_MARGIN_LEFT]);
  1432. drm_connector_attach_property(connector,
  1433. dev->mode_config.tv_top_margin_property,
  1434. tv_priv->margin[TV_MARGIN_TOP]);
  1435. drm_connector_attach_property(connector,
  1436. dev->mode_config.tv_right_margin_property,
  1437. tv_priv->margin[TV_MARGIN_RIGHT]);
  1438. drm_connector_attach_property(connector,
  1439. dev->mode_config.tv_bottom_margin_property,
  1440. tv_priv->margin[TV_MARGIN_BOTTOM]);
  1441. out:
  1442. drm_sysfs_connector_add(connector);
  1443. }