18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (C) 2009 Francisco Jerez. 38c2ecf20Sopenharmony_ci * All Rights Reserved. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining 68c2ecf20Sopenharmony_ci * a copy of this software and associated documentation files (the 78c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including 88c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish, 98c2ecf20Sopenharmony_ci * distribute, sublicense, and/or sell copies of the Software, and to 108c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to 118c2ecf20Sopenharmony_ci * the following conditions: 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the 148c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial 158c2ecf20Sopenharmony_ci * portions of the Software. 168c2ecf20Sopenharmony_ci * 178c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 188c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 198c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 208c2ecf20Sopenharmony_ci * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 218c2ecf20Sopenharmony_ci * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 228c2ecf20Sopenharmony_ci * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 238c2ecf20Sopenharmony_ci * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci */ 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#include <drm/drm_crtc_helper.h> 288c2ecf20Sopenharmony_ci#include "nouveau_drv.h" 298c2ecf20Sopenharmony_ci#include "nouveau_encoder.h" 308c2ecf20Sopenharmony_ci#include "nouveau_crtc.h" 318c2ecf20Sopenharmony_ci#include "hw.h" 328c2ecf20Sopenharmony_ci#include "tvnv17.h" 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ciconst char * const nv17_tv_norm_names[NUM_TV_NORMS] = { 358c2ecf20Sopenharmony_ci [TV_NORM_PAL] = "PAL", 368c2ecf20Sopenharmony_ci [TV_NORM_PAL_M] = "PAL-M", 378c2ecf20Sopenharmony_ci [TV_NORM_PAL_N] = "PAL-N", 388c2ecf20Sopenharmony_ci [TV_NORM_PAL_NC] = "PAL-Nc", 398c2ecf20Sopenharmony_ci [TV_NORM_NTSC_M] = "NTSC-M", 408c2ecf20Sopenharmony_ci [TV_NORM_NTSC_J] = "NTSC-J", 418c2ecf20Sopenharmony_ci [TV_NORM_HD480I] = "hd480i", 428c2ecf20Sopenharmony_ci [TV_NORM_HD480P] = "hd480p", 438c2ecf20Sopenharmony_ci [TV_NORM_HD576I] = "hd576i", 448c2ecf20Sopenharmony_ci [TV_NORM_HD576P] = "hd576p", 458c2ecf20Sopenharmony_ci [TV_NORM_HD720P] = "hd720p", 468c2ecf20Sopenharmony_ci [TV_NORM_HD1080I] = "hd1080i" 478c2ecf20Sopenharmony_ci}; 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* TV standard specific parameters */ 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_cistruct nv17_tv_norm_params nv17_tv_norms[NUM_TV_NORMS] = { 528c2ecf20Sopenharmony_ci [TV_NORM_PAL] = { TV_ENC_MODE, { 538c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 576, 50000, { 548c2ecf20Sopenharmony_ci 0x2a, 0x9, 0x8a, 0xcb, 0x0, 0x0, 0xb, 0x18, 558c2ecf20Sopenharmony_ci 0x7e, 0x40, 0x8a, 0x35, 0x27, 0x0, 0x34, 0x3, 568c2ecf20Sopenharmony_ci 0x3e, 0x3, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x9c, 578c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x3, 588c2ecf20Sopenharmony_ci 0xd3, 0x4, 0xd4, 0x1, 0x2, 0x0, 0xa, 0x5, 598c2ecf20Sopenharmony_ci 0x0, 0x1a, 0xff, 0x3, 0x18, 0xf, 0x78, 0x0, 608c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x49, 0x10, 0x0, 0x9b, 618c2ecf20Sopenharmony_ci 0xbd, 0x15, 0x5, 0x15, 0x3e, 0x3, 0x0, 0x0 628c2ecf20Sopenharmony_ci } } } }, 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci [TV_NORM_PAL_M] = { TV_ENC_MODE, { 658c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 480, 59940, { 668c2ecf20Sopenharmony_ci 0x21, 0xe6, 0xef, 0xe3, 0x0, 0x0, 0xb, 0x18, 678c2ecf20Sopenharmony_ci 0x7e, 0x44, 0x76, 0x32, 0x25, 0x0, 0x3c, 0x0, 688c2ecf20Sopenharmony_ci 0x3c, 0x0, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x83, 698c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x1, 708c2ecf20Sopenharmony_ci 0xc5, 0x4, 0xc5, 0x1, 0x2, 0x0, 0xa, 0x5, 718c2ecf20Sopenharmony_ci 0x0, 0x18, 0xff, 0x3, 0x20, 0xf, 0x78, 0x0, 728c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x40, 0x10, 0x0, 0x9c, 738c2ecf20Sopenharmony_ci 0xc8, 0x15, 0x5, 0x15, 0x3c, 0x0, 0x0, 0x0 748c2ecf20Sopenharmony_ci } } } }, 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci [TV_NORM_PAL_N] = { TV_ENC_MODE, { 778c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 576, 50000, { 788c2ecf20Sopenharmony_ci 0x2a, 0x9, 0x8a, 0xcb, 0x0, 0x0, 0xb, 0x18, 798c2ecf20Sopenharmony_ci 0x7e, 0x40, 0x8a, 0x32, 0x25, 0x0, 0x3c, 0x0, 808c2ecf20Sopenharmony_ci 0x3c, 0x0, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x9c, 818c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x1, 828c2ecf20Sopenharmony_ci 0xc5, 0x4, 0xc5, 0x1, 0x2, 0x0, 0xa, 0x5, 838c2ecf20Sopenharmony_ci 0x0, 0x1a, 0xff, 0x3, 0x18, 0xf, 0x78, 0x0, 848c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x49, 0x10, 0x0, 0x9b, 858c2ecf20Sopenharmony_ci 0xbd, 0x15, 0x5, 0x15, 0x3c, 0x0, 0x0, 0x0 868c2ecf20Sopenharmony_ci } } } }, 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci [TV_NORM_PAL_NC] = { TV_ENC_MODE, { 898c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 576, 50000, { 908c2ecf20Sopenharmony_ci 0x21, 0xf6, 0x94, 0x46, 0x0, 0x0, 0xb, 0x18, 918c2ecf20Sopenharmony_ci 0x7e, 0x44, 0x8a, 0x35, 0x27, 0x0, 0x34, 0x3, 928c2ecf20Sopenharmony_ci 0x3e, 0x3, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x9c, 938c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x3, 948c2ecf20Sopenharmony_ci 0xd3, 0x4, 0xd4, 0x1, 0x2, 0x0, 0xa, 0x5, 958c2ecf20Sopenharmony_ci 0x0, 0x1a, 0xff, 0x3, 0x18, 0xf, 0x78, 0x0, 968c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x49, 0x10, 0x0, 0x9b, 978c2ecf20Sopenharmony_ci 0xbd, 0x15, 0x5, 0x15, 0x3e, 0x3, 0x0, 0x0 988c2ecf20Sopenharmony_ci } } } }, 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci [TV_NORM_NTSC_M] = { TV_ENC_MODE, { 1018c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 480, 59940, { 1028c2ecf20Sopenharmony_ci 0x21, 0xf0, 0x7c, 0x1f, 0x0, 0x0, 0xb, 0x18, 1038c2ecf20Sopenharmony_ci 0x7e, 0x44, 0x76, 0x48, 0x0, 0x0, 0x3c, 0x0, 1048c2ecf20Sopenharmony_ci 0x3c, 0x0, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x83, 1058c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x1, 1068c2ecf20Sopenharmony_ci 0xc5, 0x4, 0xc5, 0x1, 0x2, 0x0, 0xa, 0x5, 1078c2ecf20Sopenharmony_ci 0x0, 0x16, 0xff, 0x3, 0x20, 0xf, 0x78, 0x0, 1088c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x4, 0x10, 0x0, 0x9c, 1098c2ecf20Sopenharmony_ci 0xc8, 0x15, 0x5, 0x15, 0x3c, 0x0, 0x0, 0x0 1108c2ecf20Sopenharmony_ci } } } }, 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci [TV_NORM_NTSC_J] = { TV_ENC_MODE, { 1138c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 480, 59940, { 1148c2ecf20Sopenharmony_ci 0x21, 0xf0, 0x7c, 0x1f, 0x0, 0x0, 0xb, 0x18, 1158c2ecf20Sopenharmony_ci 0x7e, 0x44, 0x76, 0x48, 0x0, 0x0, 0x32, 0x0, 1168c2ecf20Sopenharmony_ci 0x3c, 0x0, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x83, 1178c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x1, 1188c2ecf20Sopenharmony_ci 0xcf, 0x4, 0xcf, 0x1, 0x2, 0x0, 0xa, 0x5, 1198c2ecf20Sopenharmony_ci 0x0, 0x16, 0xff, 0x3, 0x20, 0xf, 0x78, 0x0, 1208c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x4, 0x10, 0x0, 0xa4, 1218c2ecf20Sopenharmony_ci 0xc8, 0x15, 0x5, 0x15, 0x3c, 0x0, 0x0, 0x0 1228c2ecf20Sopenharmony_ci } } } }, 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci [TV_NORM_HD480I] = { TV_ENC_MODE, { 1258c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 480, 59940, { 1268c2ecf20Sopenharmony_ci 0x21, 0xf0, 0x7c, 0x1f, 0x0, 0x0, 0xb, 0x18, 1278c2ecf20Sopenharmony_ci 0x7e, 0x44, 0x76, 0x48, 0x0, 0x0, 0x32, 0x0, 1288c2ecf20Sopenharmony_ci 0x3c, 0x0, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x83, 1298c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x1, 1308c2ecf20Sopenharmony_ci 0xcf, 0x4, 0xcf, 0x1, 0x2, 0x0, 0xa, 0x5, 1318c2ecf20Sopenharmony_ci 0x0, 0x16, 0xff, 0x3, 0x20, 0xf, 0x78, 0x0, 1328c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x4, 0x10, 0x0, 0xa4, 1338c2ecf20Sopenharmony_ci 0xc8, 0x15, 0x5, 0x15, 0x3c, 0x0, 0x0, 0x0 1348c2ecf20Sopenharmony_ci } } } }, 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci [TV_NORM_HD576I] = { TV_ENC_MODE, { 1378c2ecf20Sopenharmony_ci .tv_enc_mode = { 720, 576, 50000, { 1388c2ecf20Sopenharmony_ci 0x2a, 0x9, 0x8a, 0xcb, 0x0, 0x0, 0xb, 0x18, 1398c2ecf20Sopenharmony_ci 0x7e, 0x40, 0x8a, 0x35, 0x27, 0x0, 0x34, 0x3, 1408c2ecf20Sopenharmony_ci 0x3e, 0x3, 0x17, 0x21, 0x1b, 0x1b, 0x24, 0x9c, 1418c2ecf20Sopenharmony_ci 0x1, 0x0, 0xf, 0xf, 0x60, 0x5, 0xd3, 0x3, 1428c2ecf20Sopenharmony_ci 0xd3, 0x4, 0xd4, 0x1, 0x2, 0x0, 0xa, 0x5, 1438c2ecf20Sopenharmony_ci 0x0, 0x1a, 0xff, 0x3, 0x18, 0xf, 0x78, 0x0, 1448c2ecf20Sopenharmony_ci 0x0, 0xb4, 0x0, 0x15, 0x49, 0x10, 0x0, 0x9b, 1458c2ecf20Sopenharmony_ci 0xbd, 0x15, 0x5, 0x15, 0x3e, 0x3, 0x0, 0x0 1468c2ecf20Sopenharmony_ci } } } }, 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci [TV_NORM_HD480P] = { CTV_ENC_MODE, { 1508c2ecf20Sopenharmony_ci .ctv_enc_mode = { 1518c2ecf20Sopenharmony_ci .mode = { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 27000, 1528c2ecf20Sopenharmony_ci 720, 735, 743, 858, 0, 480, 490, 494, 525, 0, 1538c2ecf20Sopenharmony_ci DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, 1548c2ecf20Sopenharmony_ci .ctv_regs = { 0x3540000, 0x0, 0x0, 0x314, 1558c2ecf20Sopenharmony_ci 0x354003a, 0x40000, 0x6f0344, 0x18100000, 1568c2ecf20Sopenharmony_ci 0x10160004, 0x10060005, 0x1006000c, 0x10060020, 1578c2ecf20Sopenharmony_ci 0x10060021, 0x140e0022, 0x10060202, 0x1802020a, 1588c2ecf20Sopenharmony_ci 0x1810020b, 0x10000fff, 0x10000fff, 0x10000fff, 1598c2ecf20Sopenharmony_ci 0x10000fff, 0x10000fff, 0x10000fff, 0x70, 1608c2ecf20Sopenharmony_ci 0x3ff0000, 0x57, 0x2e001e, 0x258012c, 1618c2ecf20Sopenharmony_ci 0xa0aa04ec, 0x30, 0x80960019, 0x12c0300, 1628c2ecf20Sopenharmony_ci 0x2019, 0x600, 0x32060019, 0x0, 0x0, 0x400 1638c2ecf20Sopenharmony_ci } } } }, 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci [TV_NORM_HD576P] = { CTV_ENC_MODE, { 1668c2ecf20Sopenharmony_ci .ctv_enc_mode = { 1678c2ecf20Sopenharmony_ci .mode = { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 27000, 1688c2ecf20Sopenharmony_ci 720, 730, 738, 864, 0, 576, 581, 585, 625, 0, 1698c2ecf20Sopenharmony_ci DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, 1708c2ecf20Sopenharmony_ci .ctv_regs = { 0x3540000, 0x0, 0x0, 0x314, 1718c2ecf20Sopenharmony_ci 0x354003a, 0x40000, 0x6f0344, 0x18100000, 1728c2ecf20Sopenharmony_ci 0x10060001, 0x10060009, 0x10060026, 0x10060027, 1738c2ecf20Sopenharmony_ci 0x140e0028, 0x10060268, 0x1810026d, 0x10000fff, 1748c2ecf20Sopenharmony_ci 0x10000fff, 0x10000fff, 0x10000fff, 0x10000fff, 1758c2ecf20Sopenharmony_ci 0x10000fff, 0x10000fff, 0x10000fff, 0x69, 1768c2ecf20Sopenharmony_ci 0x3ff0000, 0x57, 0x2e001e, 0x258012c, 1778c2ecf20Sopenharmony_ci 0xa0aa04ec, 0x30, 0x80960019, 0x12c0300, 1788c2ecf20Sopenharmony_ci 0x2019, 0x600, 0x32060019, 0x0, 0x0, 0x400 1798c2ecf20Sopenharmony_ci } } } }, 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci [TV_NORM_HD720P] = { CTV_ENC_MODE, { 1828c2ecf20Sopenharmony_ci .ctv_enc_mode = { 1838c2ecf20Sopenharmony_ci .mode = { DRM_MODE("1280x720", DRM_MODE_TYPE_DRIVER, 74250, 1848c2ecf20Sopenharmony_ci 1280, 1349, 1357, 1650, 0, 720, 725, 730, 750, 0, 1858c2ecf20Sopenharmony_ci DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, 1868c2ecf20Sopenharmony_ci .ctv_regs = { 0x1260394, 0x0, 0x0, 0x622, 1878c2ecf20Sopenharmony_ci 0x66b0021, 0x6004a, 0x1210626, 0x8170000, 1888c2ecf20Sopenharmony_ci 0x70004, 0x70016, 0x70017, 0x40f0018, 1898c2ecf20Sopenharmony_ci 0x702e8, 0x81702ed, 0xfff, 0xfff, 1908c2ecf20Sopenharmony_ci 0xfff, 0xfff, 0xfff, 0xfff, 1918c2ecf20Sopenharmony_ci 0xfff, 0xfff, 0xfff, 0x0, 1928c2ecf20Sopenharmony_ci 0x2e40001, 0x58, 0x2e001e, 0x258012c, 1938c2ecf20Sopenharmony_ci 0xa0aa04ec, 0x30, 0x810c0039, 0x12c0300, 1948c2ecf20Sopenharmony_ci 0xc0002039, 0x600, 0x32060039, 0x0, 0x0, 0x0 1958c2ecf20Sopenharmony_ci } } } }, 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci [TV_NORM_HD1080I] = { CTV_ENC_MODE, { 1988c2ecf20Sopenharmony_ci .ctv_enc_mode = { 1998c2ecf20Sopenharmony_ci .mode = { DRM_MODE("1920x1080", DRM_MODE_TYPE_DRIVER, 74250, 2008c2ecf20Sopenharmony_ci 1920, 1961, 2049, 2200, 0, 1080, 1084, 1088, 1125, 0, 2018c2ecf20Sopenharmony_ci DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC 2028c2ecf20Sopenharmony_ci | DRM_MODE_FLAG_INTERLACE) }, 2038c2ecf20Sopenharmony_ci .ctv_regs = { 0xac0420, 0x44c0478, 0x4a4, 0x4fc0868, 2048c2ecf20Sopenharmony_ci 0x8940028, 0x60054, 0xe80870, 0xbf70000, 2058c2ecf20Sopenharmony_ci 0xbc70004, 0x70005, 0x70012, 0x70013, 2068c2ecf20Sopenharmony_ci 0x40f0014, 0x70230, 0xbf70232, 0xbf70233, 2078c2ecf20Sopenharmony_ci 0x1c70237, 0x70238, 0x70244, 0x70245, 2088c2ecf20Sopenharmony_ci 0x40f0246, 0x70462, 0x1f70464, 0x0, 2098c2ecf20Sopenharmony_ci 0x2e40001, 0x58, 0x2e001e, 0x258012c, 2108c2ecf20Sopenharmony_ci 0xa0aa04ec, 0x30, 0x815f004c, 0x12c0300, 2118c2ecf20Sopenharmony_ci 0xc000204c, 0x600, 0x3206004c, 0x0, 0x0, 0x0 2128c2ecf20Sopenharmony_ci } } } } 2138c2ecf20Sopenharmony_ci}; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci/* 2168c2ecf20Sopenharmony_ci * The following is some guesswork on how the TV encoder flicker 2178c2ecf20Sopenharmony_ci * filter/rescaler works: 2188c2ecf20Sopenharmony_ci * 2198c2ecf20Sopenharmony_ci * It seems to use some sort of resampling filter, it is controlled 2208c2ecf20Sopenharmony_ci * through the registers at NV_PTV_HFILTER and NV_PTV_VFILTER, they 2218c2ecf20Sopenharmony_ci * control the horizontal and vertical stage respectively, there is 2228c2ecf20Sopenharmony_ci * also NV_PTV_HFILTER2 the blob fills identically to NV_PTV_HFILTER, 2238c2ecf20Sopenharmony_ci * but they seem to do nothing. A rough guess might be that they could 2248c2ecf20Sopenharmony_ci * be used to independently control the filtering of each interlaced 2258c2ecf20Sopenharmony_ci * field, but I don't know how they are enabled. The whole filtering 2268c2ecf20Sopenharmony_ci * process seems to be disabled with bits 26:27 of PTV_200, but we 2278c2ecf20Sopenharmony_ci * aren't doing that. 2288c2ecf20Sopenharmony_ci * 2298c2ecf20Sopenharmony_ci * The layout of both register sets is the same: 2308c2ecf20Sopenharmony_ci * 2318c2ecf20Sopenharmony_ci * A: [BASE+0x18]...[BASE+0x0] [BASE+0x58]..[BASE+0x40] 2328c2ecf20Sopenharmony_ci * B: [BASE+0x34]...[BASE+0x1c] [BASE+0x74]..[BASE+0x5c] 2338c2ecf20Sopenharmony_ci * 2348c2ecf20Sopenharmony_ci * Each coefficient is stored in bits [31],[15:9] in two's complement 2358c2ecf20Sopenharmony_ci * format. They seem to be some kind of weights used in a low-pass 2368c2ecf20Sopenharmony_ci * filter. Both A and B coefficients are applied to the 14 nearest 2378c2ecf20Sopenharmony_ci * samples on each side (Listed from nearest to furthermost. They 2388c2ecf20Sopenharmony_ci * roughly cover 2 framebuffer pixels on each side). They are 2398c2ecf20Sopenharmony_ci * probably multiplied with some more hardwired weights before being 2408c2ecf20Sopenharmony_ci * used: B-coefficients are applied the same on both sides, 2418c2ecf20Sopenharmony_ci * A-coefficients are inverted before being applied to the opposite 2428c2ecf20Sopenharmony_ci * side. 2438c2ecf20Sopenharmony_ci * 2448c2ecf20Sopenharmony_ci * After all the hassle, I got the following formula by empirical 2458c2ecf20Sopenharmony_ci * means... 2468c2ecf20Sopenharmony_ci */ 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci#define calc_overscan(o) interpolate(0x100, 0xe1, 0xc1, o) 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci#define id1 (1LL << 8) 2518c2ecf20Sopenharmony_ci#define id2 (1LL << 16) 2528c2ecf20Sopenharmony_ci#define id3 (1LL << 24) 2538c2ecf20Sopenharmony_ci#define id4 (1LL << 32) 2548c2ecf20Sopenharmony_ci#define id5 (1LL << 48) 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_cistatic struct filter_params{ 2578c2ecf20Sopenharmony_ci int64_t k1; 2588c2ecf20Sopenharmony_ci int64_t ki; 2598c2ecf20Sopenharmony_ci int64_t ki2; 2608c2ecf20Sopenharmony_ci int64_t ki3; 2618c2ecf20Sopenharmony_ci int64_t kr; 2628c2ecf20Sopenharmony_ci int64_t kir; 2638c2ecf20Sopenharmony_ci int64_t ki2r; 2648c2ecf20Sopenharmony_ci int64_t ki3r; 2658c2ecf20Sopenharmony_ci int64_t kf; 2668c2ecf20Sopenharmony_ci int64_t kif; 2678c2ecf20Sopenharmony_ci int64_t ki2f; 2688c2ecf20Sopenharmony_ci int64_t ki3f; 2698c2ecf20Sopenharmony_ci int64_t krf; 2708c2ecf20Sopenharmony_ci int64_t kirf; 2718c2ecf20Sopenharmony_ci int64_t ki2rf; 2728c2ecf20Sopenharmony_ci int64_t ki3rf; 2738c2ecf20Sopenharmony_ci} fparams[2][4] = { 2748c2ecf20Sopenharmony_ci /* Horizontal filter parameters */ 2758c2ecf20Sopenharmony_ci { 2768c2ecf20Sopenharmony_ci {64.311690 * id5, -39.516924 * id5, 6.586143 * id5, 0.000002 * id5, 2778c2ecf20Sopenharmony_ci 0.051285 * id4, 26.168746 * id4, -4.361449 * id4, -0.000001 * id4, 2788c2ecf20Sopenharmony_ci 9.308169 * id3, 78.180965 * id3, -13.030158 * id3, -0.000001 * id3, 2798c2ecf20Sopenharmony_ci -8.801540 * id1, -46.572890 * id1, 7.762145 * id1, -0.000000 * id1}, 2808c2ecf20Sopenharmony_ci {-44.565569 * id5, -68.081246 * id5, 39.812074 * id5, -4.009316 * id5, 2818c2ecf20Sopenharmony_ci 29.832207 * id4, 50.047322 * id4, -25.380017 * id4, 2.546422 * id4, 2828c2ecf20Sopenharmony_ci 104.605622 * id3, 141.908641 * id3, -74.322319 * id3, 7.484316 * id3, 2838c2ecf20Sopenharmony_ci -37.081621 * id1, -90.397510 * id1, 42.784229 * id1, -4.289952 * id1}, 2848c2ecf20Sopenharmony_ci {-56.793244 * id5, 31.153584 * id5, -5.192247 * id5, -0.000003 * id5, 2858c2ecf20Sopenharmony_ci 33.541131 * id4, -34.149302 * id4, 5.691537 * id4, 0.000002 * id4, 2868c2ecf20Sopenharmony_ci 87.196610 * id3, -88.995169 * id3, 14.832456 * id3, 0.000012 * id3, 2878c2ecf20Sopenharmony_ci 17.288138 * id1, 71.864786 * id1, -11.977408 * id1, -0.000009 * id1}, 2888c2ecf20Sopenharmony_ci {51.787796 * id5, 21.211771 * id5, -18.993730 * id5, 1.853310 * id5, 2898c2ecf20Sopenharmony_ci -41.470726 * id4, -17.775823 * id4, 13.057821 * id4, -1.15823 * id4, 2908c2ecf20Sopenharmony_ci -154.235673 * id3, -44.878641 * id3, 40.656077 * id3, -3.695595 * id3, 2918c2ecf20Sopenharmony_ci 112.201065 * id1, 39.992155 * id1, -25.155714 * id1, 2.113984 * id1}, 2928c2ecf20Sopenharmony_ci }, 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci /* Vertical filter parameters */ 2958c2ecf20Sopenharmony_ci { 2968c2ecf20Sopenharmony_ci {67.601979 * id5, 0.428319 * id5, -0.071318 * id5, -0.000012 * id5, 2978c2ecf20Sopenharmony_ci -3.402339 * id4, 0.000209 * id4, -0.000092 * id4, 0.000010 * id4, 2988c2ecf20Sopenharmony_ci -9.180996 * id3, 6.111270 * id3, -1.024457 * id3, 0.001043 * id3, 2998c2ecf20Sopenharmony_ci 6.060315 * id1, -0.017425 * id1, 0.007830 * id1, -0.000869 * id1}, 3008c2ecf20Sopenharmony_ci {6.755647 * id5, 5.841348 * id5, 1.469734 * id5, -0.149656 * id5, 3018c2ecf20Sopenharmony_ci 8.293120 * id4, -1.192888 * id4, -0.947652 * id4, 0.094507 * id4, 3028c2ecf20Sopenharmony_ci 37.526655 * id3, 10.257875 * id3, -10.823275 * id3, 1.081497 * id3, 3038c2ecf20Sopenharmony_ci -2.361928 * id1, -2.059432 * id1, 1.840671 * id1, -0.168100 * id1}, 3048c2ecf20Sopenharmony_ci {-14.780391 * id5, -16.042148 * id5, 2.673692 * id5, -0.000000 * id5, 3058c2ecf20Sopenharmony_ci 39.541978 * id4, 5.680053 * id4, -0.946676 * id4, 0.000000 * id4, 3068c2ecf20Sopenharmony_ci 152.994486 * id3, 12.625439 * id3, -2.119579 * id3, 0.002708 * id3, 3078c2ecf20Sopenharmony_ci -38.125089 * id1, -0.855880 * id1, 0.155359 * id1, -0.002245 * id1}, 3088c2ecf20Sopenharmony_ci {-27.476193 * id5, -1.454976 * id5, 1.286557 * id5, 0.025346 * id5, 3098c2ecf20Sopenharmony_ci 20.687300 * id4, 3.014003 * id4, -0.557786 * id4, -0.01311 * id4, 3108c2ecf20Sopenharmony_ci 60.008737 * id3, -0.738273 * id3, 5.408217 * id3, -0.796798 * id3, 3118c2ecf20Sopenharmony_ci -17.296835 * id1, 4.438577 * id1, -2.809420 * id1, 0.385491 * id1}, 3128c2ecf20Sopenharmony_ci } 3138c2ecf20Sopenharmony_ci}; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_cistatic void tv_setup_filter(struct drm_encoder *encoder) 3168c2ecf20Sopenharmony_ci{ 3178c2ecf20Sopenharmony_ci struct nv17_tv_encoder *tv_enc = to_tv_enc(encoder); 3188c2ecf20Sopenharmony_ci struct nv17_tv_norm_params *tv_norm = get_tv_norm(encoder); 3198c2ecf20Sopenharmony_ci struct drm_display_mode *mode = &encoder->crtc->mode; 3208c2ecf20Sopenharmony_ci uint32_t (*filters[])[4][7] = {&tv_enc->state.hfilter, 3218c2ecf20Sopenharmony_ci &tv_enc->state.vfilter}; 3228c2ecf20Sopenharmony_ci int i, j, k; 3238c2ecf20Sopenharmony_ci int32_t overscan = calc_overscan(tv_enc->overscan); 3248c2ecf20Sopenharmony_ci int64_t flicker = (tv_enc->flicker - 50) * (id3 / 100); 3258c2ecf20Sopenharmony_ci uint64_t rs[] = {mode->hdisplay * id3, 3268c2ecf20Sopenharmony_ci mode->vdisplay * id3}; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci do_div(rs[0], overscan * tv_norm->tv_enc_mode.hdisplay); 3298c2ecf20Sopenharmony_ci do_div(rs[1], overscan * tv_norm->tv_enc_mode.vdisplay); 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci for (k = 0; k < 2; k++) { 3328c2ecf20Sopenharmony_ci rs[k] = max((int64_t)rs[k], id2); 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci for (j = 0; j < 4; j++) { 3358c2ecf20Sopenharmony_ci struct filter_params *p = &fparams[k][j]; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci for (i = 0; i < 7; i++) { 3388c2ecf20Sopenharmony_ci int64_t c = (p->k1 + p->ki*i + p->ki2*i*i + 3398c2ecf20Sopenharmony_ci p->ki3*i*i*i) 3408c2ecf20Sopenharmony_ci + (p->kr + p->kir*i + p->ki2r*i*i + 3418c2ecf20Sopenharmony_ci p->ki3r*i*i*i) * rs[k] 3428c2ecf20Sopenharmony_ci + (p->kf + p->kif*i + p->ki2f*i*i + 3438c2ecf20Sopenharmony_ci p->ki3f*i*i*i) * flicker 3448c2ecf20Sopenharmony_ci + (p->krf + p->kirf*i + p->ki2rf*i*i + 3458c2ecf20Sopenharmony_ci p->ki3rf*i*i*i) * flicker * rs[k]; 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci (*filters[k])[j][i] = (c + id5/2) >> 39 3488c2ecf20Sopenharmony_ci & (0x1 << 31 | 0x7f << 9); 3498c2ecf20Sopenharmony_ci } 3508c2ecf20Sopenharmony_ci } 3518c2ecf20Sopenharmony_ci } 3528c2ecf20Sopenharmony_ci} 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci/* Hardware state saving/restoring */ 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_cistatic void tv_save_filter(struct drm_device *dev, uint32_t base, 3578c2ecf20Sopenharmony_ci uint32_t regs[4][7]) 3588c2ecf20Sopenharmony_ci{ 3598c2ecf20Sopenharmony_ci int i, j; 3608c2ecf20Sopenharmony_ci uint32_t offsets[] = { base, base + 0x1c, base + 0x40, base + 0x5c }; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 3638c2ecf20Sopenharmony_ci for (j = 0; j < 7; j++) 3648c2ecf20Sopenharmony_ci regs[i][j] = nv_read_ptv(dev, offsets[i]+4*j); 3658c2ecf20Sopenharmony_ci } 3668c2ecf20Sopenharmony_ci} 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_cistatic void tv_load_filter(struct drm_device *dev, uint32_t base, 3698c2ecf20Sopenharmony_ci uint32_t regs[4][7]) 3708c2ecf20Sopenharmony_ci{ 3718c2ecf20Sopenharmony_ci int i, j; 3728c2ecf20Sopenharmony_ci uint32_t offsets[] = { base, base + 0x1c, base + 0x40, base + 0x5c }; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci for (i = 0; i < 4; i++) { 3758c2ecf20Sopenharmony_ci for (j = 0; j < 7; j++) 3768c2ecf20Sopenharmony_ci nv_write_ptv(dev, offsets[i]+4*j, regs[i][j]); 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci} 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_civoid nv17_tv_state_save(struct drm_device *dev, struct nv17_tv_state *state) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci int i; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci for (i = 0; i < 0x40; i++) 3858c2ecf20Sopenharmony_ci state->tv_enc[i] = nv_read_tv_enc(dev, i); 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci tv_save_filter(dev, NV_PTV_HFILTER, state->hfilter); 3888c2ecf20Sopenharmony_ci tv_save_filter(dev, NV_PTV_HFILTER2, state->hfilter2); 3898c2ecf20Sopenharmony_ci tv_save_filter(dev, NV_PTV_VFILTER, state->vfilter); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 200); 3928c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 204); 3938c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 208); 3948c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 20c); 3958c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 304); 3968c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 500); 3978c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 504); 3988c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 508); 3998c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 600); 4008c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 604); 4018c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 608); 4028c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 60c); 4038c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 610); 4048c2ecf20Sopenharmony_ci nv_save_ptv(dev, state, 614); 4058c2ecf20Sopenharmony_ci} 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_civoid nv17_tv_state_load(struct drm_device *dev, struct nv17_tv_state *state) 4088c2ecf20Sopenharmony_ci{ 4098c2ecf20Sopenharmony_ci int i; 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci for (i = 0; i < 0x40; i++) 4128c2ecf20Sopenharmony_ci nv_write_tv_enc(dev, i, state->tv_enc[i]); 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci tv_load_filter(dev, NV_PTV_HFILTER, state->hfilter); 4158c2ecf20Sopenharmony_ci tv_load_filter(dev, NV_PTV_HFILTER2, state->hfilter2); 4168c2ecf20Sopenharmony_ci tv_load_filter(dev, NV_PTV_VFILTER, state->vfilter); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 200); 4198c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 204); 4208c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 208); 4218c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 20c); 4228c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 304); 4238c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 500); 4248c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 504); 4258c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 508); 4268c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 600); 4278c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 604); 4288c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 608); 4298c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 60c); 4308c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 610); 4318c2ecf20Sopenharmony_ci nv_load_ptv(dev, state, 614); 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci /* This is required for some settings to kick in. */ 4348c2ecf20Sopenharmony_ci nv_write_tv_enc(dev, 0x3e, 1); 4358c2ecf20Sopenharmony_ci nv_write_tv_enc(dev, 0x3e, 0); 4368c2ecf20Sopenharmony_ci} 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci/* Timings similar to the ones the blob sets */ 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ciconst struct drm_display_mode nv17_tv_modes[] = { 4418c2ecf20Sopenharmony_ci { DRM_MODE("320x200", DRM_MODE_TYPE_DRIVER, 0, 4428c2ecf20Sopenharmony_ci 320, 344, 392, 560, 0, 200, 200, 202, 220, 0, 4438c2ecf20Sopenharmony_ci DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC 4448c2ecf20Sopenharmony_ci | DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_CLKDIV2) }, 4458c2ecf20Sopenharmony_ci { DRM_MODE("320x240", DRM_MODE_TYPE_DRIVER, 0, 4468c2ecf20Sopenharmony_ci 320, 344, 392, 560, 0, 240, 240, 246, 263, 0, 4478c2ecf20Sopenharmony_ci DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC 4488c2ecf20Sopenharmony_ci | DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_CLKDIV2) }, 4498c2ecf20Sopenharmony_ci { DRM_MODE("400x300", DRM_MODE_TYPE_DRIVER, 0, 4508c2ecf20Sopenharmony_ci 400, 432, 496, 640, 0, 300, 300, 303, 314, 0, 4518c2ecf20Sopenharmony_ci DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC 4528c2ecf20Sopenharmony_ci | DRM_MODE_FLAG_DBLSCAN | DRM_MODE_FLAG_CLKDIV2) }, 4538c2ecf20Sopenharmony_ci { DRM_MODE("640x480", DRM_MODE_TYPE_DRIVER, 0, 4548c2ecf20Sopenharmony_ci 640, 672, 768, 880, 0, 480, 480, 492, 525, 0, 4558c2ecf20Sopenharmony_ci DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, 4568c2ecf20Sopenharmony_ci { DRM_MODE("720x480", DRM_MODE_TYPE_DRIVER, 0, 4578c2ecf20Sopenharmony_ci 720, 752, 872, 960, 0, 480, 480, 493, 525, 0, 4588c2ecf20Sopenharmony_ci DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, 4598c2ecf20Sopenharmony_ci { DRM_MODE("720x576", DRM_MODE_TYPE_DRIVER, 0, 4608c2ecf20Sopenharmony_ci 720, 776, 856, 960, 0, 576, 576, 588, 597, 0, 4618c2ecf20Sopenharmony_ci DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, 4628c2ecf20Sopenharmony_ci { DRM_MODE("800x600", DRM_MODE_TYPE_DRIVER, 0, 4638c2ecf20Sopenharmony_ci 800, 840, 920, 1040, 0, 600, 600, 604, 618, 0, 4648c2ecf20Sopenharmony_ci DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, 4658c2ecf20Sopenharmony_ci { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 0, 4668c2ecf20Sopenharmony_ci 1024, 1064, 1200, 1344, 0, 768, 768, 777, 806, 0, 4678c2ecf20Sopenharmony_ci DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC) }, 4688c2ecf20Sopenharmony_ci {} 4698c2ecf20Sopenharmony_ci}; 4708c2ecf20Sopenharmony_ci 4718c2ecf20Sopenharmony_civoid nv17_tv_update_properties(struct drm_encoder *encoder) 4728c2ecf20Sopenharmony_ci{ 4738c2ecf20Sopenharmony_ci struct drm_device *dev = encoder->dev; 4748c2ecf20Sopenharmony_ci struct nv17_tv_encoder *tv_enc = to_tv_enc(encoder); 4758c2ecf20Sopenharmony_ci struct nv17_tv_state *regs = &tv_enc->state; 4768c2ecf20Sopenharmony_ci struct nv17_tv_norm_params *tv_norm = get_tv_norm(encoder); 4778c2ecf20Sopenharmony_ci int subconnector = tv_enc->select_subconnector ? 4788c2ecf20Sopenharmony_ci tv_enc->select_subconnector : 4798c2ecf20Sopenharmony_ci tv_enc->subconnector; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci switch (subconnector) { 4828c2ecf20Sopenharmony_ci case DRM_MODE_SUBCONNECTOR_Composite: 4838c2ecf20Sopenharmony_ci { 4848c2ecf20Sopenharmony_ci regs->ptv_204 = 0x2; 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci /* The composite connector may be found on either pin. */ 4878c2ecf20Sopenharmony_ci if (tv_enc->pin_mask & 0x4) 4888c2ecf20Sopenharmony_ci regs->ptv_204 |= 0x010000; 4898c2ecf20Sopenharmony_ci else if (tv_enc->pin_mask & 0x2) 4908c2ecf20Sopenharmony_ci regs->ptv_204 |= 0x100000; 4918c2ecf20Sopenharmony_ci else 4928c2ecf20Sopenharmony_ci regs->ptv_204 |= 0x110000; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci regs->tv_enc[0x7] = 0x10; 4958c2ecf20Sopenharmony_ci break; 4968c2ecf20Sopenharmony_ci } 4978c2ecf20Sopenharmony_ci case DRM_MODE_SUBCONNECTOR_SVIDEO: 4988c2ecf20Sopenharmony_ci regs->ptv_204 = 0x11012; 4998c2ecf20Sopenharmony_ci regs->tv_enc[0x7] = 0x18; 5008c2ecf20Sopenharmony_ci break; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci case DRM_MODE_SUBCONNECTOR_Component: 5038c2ecf20Sopenharmony_ci regs->ptv_204 = 0x111333; 5048c2ecf20Sopenharmony_ci regs->tv_enc[0x7] = 0x14; 5058c2ecf20Sopenharmony_ci break; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci case DRM_MODE_SUBCONNECTOR_SCART: 5088c2ecf20Sopenharmony_ci regs->ptv_204 = 0x111012; 5098c2ecf20Sopenharmony_ci regs->tv_enc[0x7] = 0x18; 5108c2ecf20Sopenharmony_ci break; 5118c2ecf20Sopenharmony_ci } 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci regs->tv_enc[0x20] = interpolate(0, tv_norm->tv_enc_mode.tv_enc[0x20], 5148c2ecf20Sopenharmony_ci 255, tv_enc->saturation); 5158c2ecf20Sopenharmony_ci regs->tv_enc[0x22] = interpolate(0, tv_norm->tv_enc_mode.tv_enc[0x22], 5168c2ecf20Sopenharmony_ci 255, tv_enc->saturation); 5178c2ecf20Sopenharmony_ci regs->tv_enc[0x25] = tv_enc->hue * 255 / 100; 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci nv_load_ptv(dev, regs, 204); 5208c2ecf20Sopenharmony_ci nv_load_tv_enc(dev, regs, 7); 5218c2ecf20Sopenharmony_ci nv_load_tv_enc(dev, regs, 20); 5228c2ecf20Sopenharmony_ci nv_load_tv_enc(dev, regs, 22); 5238c2ecf20Sopenharmony_ci nv_load_tv_enc(dev, regs, 25); 5248c2ecf20Sopenharmony_ci} 5258c2ecf20Sopenharmony_ci 5268c2ecf20Sopenharmony_civoid nv17_tv_update_rescaler(struct drm_encoder *encoder) 5278c2ecf20Sopenharmony_ci{ 5288c2ecf20Sopenharmony_ci struct drm_device *dev = encoder->dev; 5298c2ecf20Sopenharmony_ci struct nv17_tv_encoder *tv_enc = to_tv_enc(encoder); 5308c2ecf20Sopenharmony_ci struct nv17_tv_state *regs = &tv_enc->state; 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci regs->ptv_208 = 0x40 | (calc_overscan(tv_enc->overscan) << 8); 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci tv_setup_filter(encoder); 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci nv_load_ptv(dev, regs, 208); 5378c2ecf20Sopenharmony_ci tv_load_filter(dev, NV_PTV_HFILTER, regs->hfilter); 5388c2ecf20Sopenharmony_ci tv_load_filter(dev, NV_PTV_HFILTER2, regs->hfilter2); 5398c2ecf20Sopenharmony_ci tv_load_filter(dev, NV_PTV_VFILTER, regs->vfilter); 5408c2ecf20Sopenharmony_ci} 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_civoid nv17_ctv_update_rescaler(struct drm_encoder *encoder) 5438c2ecf20Sopenharmony_ci{ 5448c2ecf20Sopenharmony_ci struct drm_device *dev = encoder->dev; 5458c2ecf20Sopenharmony_ci struct nv17_tv_encoder *tv_enc = to_tv_enc(encoder); 5468c2ecf20Sopenharmony_ci int head = nouveau_crtc(encoder->crtc)->index; 5478c2ecf20Sopenharmony_ci struct nv04_crtc_reg *regs = &nv04_display(dev)->mode_reg.crtc_reg[head]; 5488c2ecf20Sopenharmony_ci struct drm_display_mode *crtc_mode = &encoder->crtc->mode; 5498c2ecf20Sopenharmony_ci struct drm_display_mode *output_mode = 5508c2ecf20Sopenharmony_ci &get_tv_norm(encoder)->ctv_enc_mode.mode; 5518c2ecf20Sopenharmony_ci int overscan, hmargin, vmargin, hratio, vratio; 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci /* The rescaler doesn't do the right thing for interlaced modes. */ 5548c2ecf20Sopenharmony_ci if (output_mode->flags & DRM_MODE_FLAG_INTERLACE) 5558c2ecf20Sopenharmony_ci overscan = 100; 5568c2ecf20Sopenharmony_ci else 5578c2ecf20Sopenharmony_ci overscan = tv_enc->overscan; 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci hmargin = (output_mode->hdisplay - crtc_mode->hdisplay) / 2; 5608c2ecf20Sopenharmony_ci vmargin = (output_mode->vdisplay - crtc_mode->vdisplay) / 2; 5618c2ecf20Sopenharmony_ci 5628c2ecf20Sopenharmony_ci hmargin = interpolate(0, min(hmargin, output_mode->hdisplay/20), 5638c2ecf20Sopenharmony_ci hmargin, overscan); 5648c2ecf20Sopenharmony_ci vmargin = interpolate(0, min(vmargin, output_mode->vdisplay/20), 5658c2ecf20Sopenharmony_ci vmargin, overscan); 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci hratio = crtc_mode->hdisplay * 0x800 / 5688c2ecf20Sopenharmony_ci (output_mode->hdisplay - 2*hmargin); 5698c2ecf20Sopenharmony_ci vratio = crtc_mode->vdisplay * 0x800 / 5708c2ecf20Sopenharmony_ci (output_mode->vdisplay - 2*vmargin) & ~3; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci regs->fp_horiz_regs[FP_VALID_START] = hmargin; 5738c2ecf20Sopenharmony_ci regs->fp_horiz_regs[FP_VALID_END] = output_mode->hdisplay - hmargin - 1; 5748c2ecf20Sopenharmony_ci regs->fp_vert_regs[FP_VALID_START] = vmargin; 5758c2ecf20Sopenharmony_ci regs->fp_vert_regs[FP_VALID_END] = output_mode->vdisplay - vmargin - 1; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci regs->fp_debug_1 = NV_PRAMDAC_FP_DEBUG_1_YSCALE_TESTMODE_ENABLE | 5788c2ecf20Sopenharmony_ci XLATE(vratio, 0, NV_PRAMDAC_FP_DEBUG_1_YSCALE_VALUE) | 5798c2ecf20Sopenharmony_ci NV_PRAMDAC_FP_DEBUG_1_XSCALE_TESTMODE_ENABLE | 5808c2ecf20Sopenharmony_ci XLATE(hratio, 0, NV_PRAMDAC_FP_DEBUG_1_XSCALE_VALUE); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_HVALID_START, 5838c2ecf20Sopenharmony_ci regs->fp_horiz_regs[FP_VALID_START]); 5848c2ecf20Sopenharmony_ci NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_HVALID_END, 5858c2ecf20Sopenharmony_ci regs->fp_horiz_regs[FP_VALID_END]); 5868c2ecf20Sopenharmony_ci NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_VVALID_START, 5878c2ecf20Sopenharmony_ci regs->fp_vert_regs[FP_VALID_START]); 5888c2ecf20Sopenharmony_ci NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_VVALID_END, 5898c2ecf20Sopenharmony_ci regs->fp_vert_regs[FP_VALID_END]); 5908c2ecf20Sopenharmony_ci NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_DEBUG_1, regs->fp_debug_1); 5918c2ecf20Sopenharmony_ci} 592