11a646342SBen Skeggs /* 21a646342SBen Skeggs * Copyright 2003 NVIDIA, Corporation 31a646342SBen Skeggs * Copyright 2006 Dave Airlie 41a646342SBen Skeggs * Copyright 2007 Maarten Maathuis 51a646342SBen Skeggs * Copyright 2007-2009 Stuart Bennett 61a646342SBen Skeggs * 71a646342SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a 81a646342SBen Skeggs * copy of this software and associated documentation files (the "Software"), 91a646342SBen Skeggs * to deal in the Software without restriction, including without limitation 101a646342SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense, 111a646342SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the 121a646342SBen Skeggs * Software is furnished to do so, subject to the following conditions: 131a646342SBen Skeggs * 141a646342SBen Skeggs * The above copyright notice and this permission notice (including the next 151a646342SBen Skeggs * paragraph) shall be included in all copies or substantial portions of the 161a646342SBen Skeggs * Software. 171a646342SBen Skeggs * 181a646342SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 191a646342SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 201a646342SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 211a646342SBen Skeggs * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 221a646342SBen Skeggs * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 231a646342SBen Skeggs * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 241a646342SBen Skeggs * DEALINGS IN THE SOFTWARE. 251a646342SBen Skeggs */ 261a646342SBen Skeggs 271a646342SBen Skeggs #include <drm/drmP.h> 281a646342SBen Skeggs #include <drm/drm_crtc_helper.h> 291a646342SBen Skeggs 304dc28134SBen Skeggs #include "nouveau_drv.h" 311a646342SBen Skeggs #include "nouveau_reg.h" 321a646342SBen Skeggs #include "nouveau_encoder.h" 331a646342SBen Skeggs #include "nouveau_connector.h" 341a646342SBen Skeggs #include "nouveau_crtc.h" 351a646342SBen Skeggs #include "hw.h" 361a646342SBen Skeggs #include "nvreg.h" 371a646342SBen Skeggs 381a646342SBen Skeggs #include <drm/i2c/sil164.h> 391a646342SBen Skeggs 401a646342SBen Skeggs #include <subdev/i2c.h> 411a646342SBen Skeggs 421a646342SBen Skeggs #define FP_TG_CONTROL_ON (NV_PRAMDAC_FP_TG_CONTROL_DISPEN_POS | \ 431a646342SBen Skeggs NV_PRAMDAC_FP_TG_CONTROL_HSYNC_POS | \ 441a646342SBen Skeggs NV_PRAMDAC_FP_TG_CONTROL_VSYNC_POS) 451a646342SBen Skeggs #define FP_TG_CONTROL_OFF (NV_PRAMDAC_FP_TG_CONTROL_DISPEN_DISABLE | \ 461a646342SBen Skeggs NV_PRAMDAC_FP_TG_CONTROL_HSYNC_DISABLE | \ 471a646342SBen Skeggs NV_PRAMDAC_FP_TG_CONTROL_VSYNC_DISABLE) 481a646342SBen Skeggs 491a646342SBen Skeggs static inline bool is_fpc_off(uint32_t fpc) 501a646342SBen Skeggs { 511a646342SBen Skeggs return ((fpc & (FP_TG_CONTROL_ON | FP_TG_CONTROL_OFF)) == 521a646342SBen Skeggs FP_TG_CONTROL_OFF); 531a646342SBen Skeggs } 541a646342SBen Skeggs 551a646342SBen Skeggs int nv04_dfp_get_bound_head(struct drm_device *dev, struct dcb_output *dcbent) 561a646342SBen Skeggs { 571a646342SBen Skeggs /* special case of nv_read_tmds to find crtc associated with an output. 581a646342SBen Skeggs * this does not give a correct answer for off-chip dvi, but there's no 591a646342SBen Skeggs * use for such an answer anyway 601a646342SBen Skeggs */ 611a646342SBen Skeggs int ramdac = (dcbent->or & DCB_OUTPUT_C) >> 2; 621a646342SBen Skeggs 631a646342SBen Skeggs NVWriteRAMDAC(dev, ramdac, NV_PRAMDAC_FP_TMDS_CONTROL, 641a646342SBen Skeggs NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE | 0x4); 651a646342SBen Skeggs return ((NVReadRAMDAC(dev, ramdac, NV_PRAMDAC_FP_TMDS_DATA) & 0x8) >> 3) ^ ramdac; 661a646342SBen Skeggs } 671a646342SBen Skeggs 681a646342SBen Skeggs void nv04_dfp_bind_head(struct drm_device *dev, struct dcb_output *dcbent, 691a646342SBen Skeggs int head, bool dl) 701a646342SBen Skeggs { 711a646342SBen Skeggs /* The BIOS scripts don't do this for us, sadly 721a646342SBen Skeggs * Luckily we do know the values ;-) 731a646342SBen Skeggs * 741a646342SBen Skeggs * head < 0 indicates we wish to force a setting with the overrideval 751a646342SBen Skeggs * (for VT restore etc.) 761a646342SBen Skeggs */ 771a646342SBen Skeggs 781a646342SBen Skeggs int ramdac = (dcbent->or & DCB_OUTPUT_C) >> 2; 791a646342SBen Skeggs uint8_t tmds04 = 0x80; 801a646342SBen Skeggs 811a646342SBen Skeggs if (head != ramdac) 821a646342SBen Skeggs tmds04 = 0x88; 831a646342SBen Skeggs 841a646342SBen Skeggs if (dcbent->type == DCB_OUTPUT_LVDS) 851a646342SBen Skeggs tmds04 |= 0x01; 861a646342SBen Skeggs 871a646342SBen Skeggs nv_write_tmds(dev, dcbent->or, 0, 0x04, tmds04); 881a646342SBen Skeggs 891a646342SBen Skeggs if (dl) /* dual link */ 901a646342SBen Skeggs nv_write_tmds(dev, dcbent->or, 1, 0x04, tmds04 ^ 0x08); 911a646342SBen Skeggs } 921a646342SBen Skeggs 931a646342SBen Skeggs void nv04_dfp_disable(struct drm_device *dev, int head) 941a646342SBen Skeggs { 951a646342SBen Skeggs struct nv04_crtc_reg *crtcstate = nv04_display(dev)->mode_reg.crtc_reg; 961a646342SBen Skeggs 971a646342SBen Skeggs if (NVReadRAMDAC(dev, head, NV_PRAMDAC_FP_TG_CONTROL) & 981a646342SBen Skeggs FP_TG_CONTROL_ON) { 991a646342SBen Skeggs /* digital remnants must be cleaned before new crtc 1001a646342SBen Skeggs * values programmed. delay is time for the vga stuff 1011a646342SBen Skeggs * to realise it's in control again 1021a646342SBen Skeggs */ 1031a646342SBen Skeggs NVWriteRAMDAC(dev, head, NV_PRAMDAC_FP_TG_CONTROL, 1041a646342SBen Skeggs FP_TG_CONTROL_OFF); 1051a646342SBen Skeggs msleep(50); 1061a646342SBen Skeggs } 1071a646342SBen Skeggs /* don't inadvertently turn it on when state written later */ 1081a646342SBen Skeggs crtcstate[head].fp_control = FP_TG_CONTROL_OFF; 1091a646342SBen Skeggs crtcstate[head].CRTC[NV_CIO_CRE_LCD__INDEX] &= 1101a646342SBen Skeggs ~NV_CIO_CRE_LCD_ROUTE_MASK; 1111a646342SBen Skeggs } 1121a646342SBen Skeggs 1131a646342SBen Skeggs void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode) 1141a646342SBen Skeggs { 1151a646342SBen Skeggs struct drm_device *dev = encoder->dev; 1161a646342SBen Skeggs struct drm_crtc *crtc; 1171a646342SBen Skeggs struct nouveau_crtc *nv_crtc; 1181a646342SBen Skeggs uint32_t *fpc; 1191a646342SBen Skeggs 1201a646342SBen Skeggs if (mode == DRM_MODE_DPMS_ON) { 1211a646342SBen Skeggs nv_crtc = nouveau_crtc(encoder->crtc); 1221a646342SBen Skeggs fpc = &nv04_display(dev)->mode_reg.crtc_reg[nv_crtc->index].fp_control; 1231a646342SBen Skeggs 1241a646342SBen Skeggs if (is_fpc_off(*fpc)) { 1251a646342SBen Skeggs /* using saved value is ok, as (is_digital && dpms_on && 1261a646342SBen Skeggs * fp_control==OFF) is (at present) *only* true when 1271a646342SBen Skeggs * fpc's most recent change was by below "off" code 1281a646342SBen Skeggs */ 1291a646342SBen Skeggs *fpc = nv_crtc->dpms_saved_fp_control; 1301a646342SBen Skeggs } 1311a646342SBen Skeggs 1321a646342SBen Skeggs nv_crtc->fp_users |= 1 << nouveau_encoder(encoder)->dcb->index; 1331a646342SBen Skeggs NVWriteRAMDAC(dev, nv_crtc->index, NV_PRAMDAC_FP_TG_CONTROL, *fpc); 1341a646342SBen Skeggs } else { 1351a646342SBen Skeggs list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { 1361a646342SBen Skeggs nv_crtc = nouveau_crtc(crtc); 1371a646342SBen Skeggs fpc = &nv04_display(dev)->mode_reg.crtc_reg[nv_crtc->index].fp_control; 1381a646342SBen Skeggs 1391a646342SBen Skeggs nv_crtc->fp_users &= ~(1 << nouveau_encoder(encoder)->dcb->index); 1401a646342SBen Skeggs if (!is_fpc_off(*fpc) && !nv_crtc->fp_users) { 1411a646342SBen Skeggs nv_crtc->dpms_saved_fp_control = *fpc; 1421a646342SBen Skeggs /* cut the FP output */ 1431a646342SBen Skeggs *fpc &= ~FP_TG_CONTROL_ON; 1441a646342SBen Skeggs *fpc |= FP_TG_CONTROL_OFF; 1451a646342SBen Skeggs NVWriteRAMDAC(dev, nv_crtc->index, 1461a646342SBen Skeggs NV_PRAMDAC_FP_TG_CONTROL, *fpc); 1471a646342SBen Skeggs } 1481a646342SBen Skeggs } 1491a646342SBen Skeggs } 1501a646342SBen Skeggs } 1511a646342SBen Skeggs 1521a646342SBen Skeggs static struct drm_encoder *get_tmds_slave(struct drm_encoder *encoder) 1531a646342SBen Skeggs { 1541a646342SBen Skeggs struct drm_device *dev = encoder->dev; 1551a646342SBen Skeggs struct dcb_output *dcb = nouveau_encoder(encoder)->dcb; 1561a646342SBen Skeggs struct drm_encoder *slave; 1571a646342SBen Skeggs 1581a646342SBen Skeggs if (dcb->type != DCB_OUTPUT_TMDS || dcb->location == DCB_LOC_ON_CHIP) 1591a646342SBen Skeggs return NULL; 1601a646342SBen Skeggs 1611a646342SBen Skeggs /* Some BIOSes (e.g. the one in a Quadro FX1000) report several 1621a646342SBen Skeggs * TMDS transmitters at the same I2C address, in the same I2C 1631a646342SBen Skeggs * bus. This can still work because in that case one of them is 1641a646342SBen Skeggs * always hard-wired to a reasonable configuration using straps, 1651a646342SBen Skeggs * and the other one needs to be programmed. 1661a646342SBen Skeggs * 1671a646342SBen Skeggs * I don't think there's a way to know which is which, even the 1681a646342SBen Skeggs * blob programs the one exposed via I2C for *both* heads, so 1691a646342SBen Skeggs * let's do the same. 1701a646342SBen Skeggs */ 1711a646342SBen Skeggs list_for_each_entry(slave, &dev->mode_config.encoder_list, head) { 1721a646342SBen Skeggs struct dcb_output *slave_dcb = nouveau_encoder(slave)->dcb; 1731a646342SBen Skeggs 1741a646342SBen Skeggs if (slave_dcb->type == DCB_OUTPUT_TMDS && get_slave_funcs(slave) && 1751a646342SBen Skeggs slave_dcb->tmdsconf.slave_addr == dcb->tmdsconf.slave_addr) 1761a646342SBen Skeggs return slave; 1771a646342SBen Skeggs } 1781a646342SBen Skeggs 1791a646342SBen Skeggs return NULL; 1801a646342SBen Skeggs } 1811a646342SBen Skeggs 1821a646342SBen Skeggs static bool nv04_dfp_mode_fixup(struct drm_encoder *encoder, 1831a646342SBen Skeggs const struct drm_display_mode *mode, 1841a646342SBen Skeggs struct drm_display_mode *adjusted_mode) 1851a646342SBen Skeggs { 1861a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 1871a646342SBen Skeggs struct nouveau_connector *nv_connector = nouveau_encoder_connector_get(nv_encoder); 1881a646342SBen Skeggs 1891a646342SBen Skeggs if (!nv_connector->native_mode || 1901a646342SBen Skeggs nv_connector->scaling_mode == DRM_MODE_SCALE_NONE || 1911a646342SBen Skeggs mode->hdisplay > nv_connector->native_mode->hdisplay || 1921a646342SBen Skeggs mode->vdisplay > nv_connector->native_mode->vdisplay) { 1931a646342SBen Skeggs nv_encoder->mode = *adjusted_mode; 1941a646342SBen Skeggs 1951a646342SBen Skeggs } else { 1961a646342SBen Skeggs nv_encoder->mode = *nv_connector->native_mode; 1971a646342SBen Skeggs adjusted_mode->clock = nv_connector->native_mode->clock; 1981a646342SBen Skeggs } 1991a646342SBen Skeggs 2001a646342SBen Skeggs return true; 2011a646342SBen Skeggs } 2021a646342SBen Skeggs 2031a646342SBen Skeggs static void nv04_dfp_prepare_sel_clk(struct drm_device *dev, 2041a646342SBen Skeggs struct nouveau_encoder *nv_encoder, int head) 2051a646342SBen Skeggs { 2061a646342SBen Skeggs struct nv04_mode_state *state = &nv04_display(dev)->mode_reg; 2071a646342SBen Skeggs uint32_t bits1618 = nv_encoder->dcb->or & DCB_OUTPUT_A ? 0x10000 : 0x40000; 2081a646342SBen Skeggs 2091a646342SBen Skeggs if (nv_encoder->dcb->location != DCB_LOC_ON_CHIP) 2101a646342SBen Skeggs return; 2111a646342SBen Skeggs 2121a646342SBen Skeggs /* SEL_CLK is only used on the primary ramdac 2131a646342SBen Skeggs * It toggles spread spectrum PLL output and sets the bindings of PLLs 2141a646342SBen Skeggs * to heads on digital outputs 2151a646342SBen Skeggs */ 2161a646342SBen Skeggs if (head) 2171a646342SBen Skeggs state->sel_clk |= bits1618; 2181a646342SBen Skeggs else 2191a646342SBen Skeggs state->sel_clk &= ~bits1618; 2201a646342SBen Skeggs 2211a646342SBen Skeggs /* nv30: 2221a646342SBen Skeggs * bit 0 NVClk spread spectrum on/off 2231a646342SBen Skeggs * bit 2 MemClk spread spectrum on/off 2241a646342SBen Skeggs * bit 4 PixClk1 spread spectrum on/off toggle 2251a646342SBen Skeggs * bit 6 PixClk2 spread spectrum on/off toggle 2261a646342SBen Skeggs * 2271a646342SBen Skeggs * nv40 (observations from bios behaviour and mmio traces): 2281a646342SBen Skeggs * bits 4&6 as for nv30 2291a646342SBen Skeggs * bits 5&7 head dependent as for bits 4&6, but do not appear with 4&6; 2301a646342SBen Skeggs * maybe a different spread mode 2311a646342SBen Skeggs * bits 8&10 seen on dual-link dvi outputs, purpose unknown (set by POST scripts) 2321a646342SBen Skeggs * The logic behind turning spread spectrum on/off in the first place, 2331a646342SBen Skeggs * and which bit-pair to use, is unclear on nv40 (for earlier cards, the fp table 2341a646342SBen Skeggs * entry has the necessary info) 2351a646342SBen Skeggs */ 2361a646342SBen Skeggs if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS && nv04_display(dev)->saved_reg.sel_clk & 0xf0) { 2371a646342SBen Skeggs int shift = (nv04_display(dev)->saved_reg.sel_clk & 0x50) ? 0 : 1; 2381a646342SBen Skeggs 2391a646342SBen Skeggs state->sel_clk &= ~0xf0; 2401a646342SBen Skeggs state->sel_clk |= (head ? 0x40 : 0x10) << shift; 2411a646342SBen Skeggs } 2421a646342SBen Skeggs } 2431a646342SBen Skeggs 2441a646342SBen Skeggs static void nv04_dfp_prepare(struct drm_encoder *encoder) 2451a646342SBen Skeggs { 2461a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 247d58ded76SJani Nikula const struct drm_encoder_helper_funcs *helper = encoder->helper_private; 2481a646342SBen Skeggs struct drm_device *dev = encoder->dev; 2491a646342SBen Skeggs int head = nouveau_crtc(encoder->crtc)->index; 2501a646342SBen Skeggs struct nv04_crtc_reg *crtcstate = nv04_display(dev)->mode_reg.crtc_reg; 2511a646342SBen Skeggs uint8_t *cr_lcd = &crtcstate[head].CRTC[NV_CIO_CRE_LCD__INDEX]; 2521a646342SBen Skeggs uint8_t *cr_lcd_oth = &crtcstate[head ^ 1].CRTC[NV_CIO_CRE_LCD__INDEX]; 2531a646342SBen Skeggs 2541a646342SBen Skeggs helper->dpms(encoder, DRM_MODE_DPMS_OFF); 2551a646342SBen Skeggs 2561a646342SBen Skeggs nv04_dfp_prepare_sel_clk(dev, nv_encoder, head); 2571a646342SBen Skeggs 2581a646342SBen Skeggs *cr_lcd = (*cr_lcd & ~NV_CIO_CRE_LCD_ROUTE_MASK) | 0x3; 2591a646342SBen Skeggs 2601a646342SBen Skeggs if (nv_two_heads(dev)) { 2611a646342SBen Skeggs if (nv_encoder->dcb->location == DCB_LOC_ON_CHIP) 2621a646342SBen Skeggs *cr_lcd |= head ? 0x0 : 0x8; 2631a646342SBen Skeggs else { 2641a646342SBen Skeggs *cr_lcd |= (nv_encoder->dcb->or << 4) & 0x30; 2651a646342SBen Skeggs if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS) 2661a646342SBen Skeggs *cr_lcd |= 0x30; 2671a646342SBen Skeggs if ((*cr_lcd & 0x30) == (*cr_lcd_oth & 0x30)) { 2681a646342SBen Skeggs /* avoid being connected to both crtcs */ 2691a646342SBen Skeggs *cr_lcd_oth &= ~0x30; 2701a646342SBen Skeggs NVWriteVgaCrtc(dev, head ^ 1, 2711a646342SBen Skeggs NV_CIO_CRE_LCD__INDEX, 2721a646342SBen Skeggs *cr_lcd_oth); 2731a646342SBen Skeggs } 2741a646342SBen Skeggs } 2751a646342SBen Skeggs } 2761a646342SBen Skeggs } 2771a646342SBen Skeggs 2781a646342SBen Skeggs 2791a646342SBen Skeggs static void nv04_dfp_mode_set(struct drm_encoder *encoder, 2801a646342SBen Skeggs struct drm_display_mode *mode, 2811a646342SBen Skeggs struct drm_display_mode *adjusted_mode) 2821a646342SBen Skeggs { 2831a646342SBen Skeggs struct drm_device *dev = encoder->dev; 284a01ca78cSBen Skeggs struct nvif_object *device = &nouveau_drm(dev)->device.object; 2851a646342SBen Skeggs struct nouveau_drm *drm = nouveau_drm(dev); 2861a646342SBen Skeggs struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); 2871a646342SBen Skeggs struct nv04_crtc_reg *regp = &nv04_display(dev)->mode_reg.crtc_reg[nv_crtc->index]; 2881a646342SBen Skeggs struct nv04_crtc_reg *savep = &nv04_display(dev)->saved_reg.crtc_reg[nv_crtc->index]; 2891a646342SBen Skeggs struct nouveau_connector *nv_connector = nouveau_crtc_connector_get(nv_crtc); 2901a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 2911a646342SBen Skeggs struct drm_display_mode *output_mode = &nv_encoder->mode; 2921a646342SBen Skeggs struct drm_connector *connector = &nv_connector->base; 293*d92df868SVille Syrjälä const struct drm_framebuffer *fb = encoder->crtc->primary->fb; 2941a646342SBen Skeggs uint32_t mode_ratio, panel_ratio; 2951a646342SBen Skeggs 2961a646342SBen Skeggs NV_DEBUG(drm, "Output mode on CRTC %d:\n", nv_crtc->index); 2971a646342SBen Skeggs drm_mode_debug_printmodeline(output_mode); 2981a646342SBen Skeggs 2991a646342SBen Skeggs /* Initialize the FP registers in this CRTC. */ 3001a646342SBen Skeggs regp->fp_horiz_regs[FP_DISPLAY_END] = output_mode->hdisplay - 1; 3011a646342SBen Skeggs regp->fp_horiz_regs[FP_TOTAL] = output_mode->htotal - 1; 3021a646342SBen Skeggs if (!nv_gf4_disp_arch(dev) || 3031a646342SBen Skeggs (output_mode->hsync_start - output_mode->hdisplay) >= 3041a646342SBen Skeggs drm->vbios.digital_min_front_porch) 3051a646342SBen Skeggs regp->fp_horiz_regs[FP_CRTC] = output_mode->hdisplay; 3061a646342SBen Skeggs else 3071a646342SBen Skeggs regp->fp_horiz_regs[FP_CRTC] = output_mode->hsync_start - drm->vbios.digital_min_front_porch - 1; 3081a646342SBen Skeggs regp->fp_horiz_regs[FP_SYNC_START] = output_mode->hsync_start - 1; 3091a646342SBen Skeggs regp->fp_horiz_regs[FP_SYNC_END] = output_mode->hsync_end - 1; 3101a646342SBen Skeggs regp->fp_horiz_regs[FP_VALID_START] = output_mode->hskew; 3111a646342SBen Skeggs regp->fp_horiz_regs[FP_VALID_END] = output_mode->hdisplay - 1; 3121a646342SBen Skeggs 3131a646342SBen Skeggs regp->fp_vert_regs[FP_DISPLAY_END] = output_mode->vdisplay - 1; 3141a646342SBen Skeggs regp->fp_vert_regs[FP_TOTAL] = output_mode->vtotal - 1; 3151a646342SBen Skeggs regp->fp_vert_regs[FP_CRTC] = output_mode->vtotal - 5 - 1; 3161a646342SBen Skeggs regp->fp_vert_regs[FP_SYNC_START] = output_mode->vsync_start - 1; 3171a646342SBen Skeggs regp->fp_vert_regs[FP_SYNC_END] = output_mode->vsync_end - 1; 3181a646342SBen Skeggs regp->fp_vert_regs[FP_VALID_START] = 0; 3191a646342SBen Skeggs regp->fp_vert_regs[FP_VALID_END] = output_mode->vdisplay - 1; 3201a646342SBen Skeggs 3211a646342SBen Skeggs /* bit26: a bit seen on some g7x, no as yet discernable purpose */ 3221a646342SBen Skeggs regp->fp_control = NV_PRAMDAC_FP_TG_CONTROL_DISPEN_POS | 3231a646342SBen Skeggs (savep->fp_control & (1 << 26 | NV_PRAMDAC_FP_TG_CONTROL_READ_PROG)); 3241a646342SBen Skeggs /* Deal with vsync/hsync polarity */ 3251a646342SBen Skeggs /* LVDS screens do set this, but modes with +ve syncs are very rare */ 3261a646342SBen Skeggs if (output_mode->flags & DRM_MODE_FLAG_PVSYNC) 3271a646342SBen Skeggs regp->fp_control |= NV_PRAMDAC_FP_TG_CONTROL_VSYNC_POS; 3281a646342SBen Skeggs if (output_mode->flags & DRM_MODE_FLAG_PHSYNC) 3291a646342SBen Skeggs regp->fp_control |= NV_PRAMDAC_FP_TG_CONTROL_HSYNC_POS; 3301a646342SBen Skeggs /* panel scaling first, as native would get set otherwise */ 3311a646342SBen Skeggs if (nv_connector->scaling_mode == DRM_MODE_SCALE_NONE || 3321a646342SBen Skeggs nv_connector->scaling_mode == DRM_MODE_SCALE_CENTER) /* panel handles it */ 3331a646342SBen Skeggs regp->fp_control |= NV_PRAMDAC_FP_TG_CONTROL_MODE_CENTER; 3341a646342SBen Skeggs else if (adjusted_mode->hdisplay == output_mode->hdisplay && 3351a646342SBen Skeggs adjusted_mode->vdisplay == output_mode->vdisplay) /* native mode */ 3361a646342SBen Skeggs regp->fp_control |= NV_PRAMDAC_FP_TG_CONTROL_MODE_NATIVE; 3371a646342SBen Skeggs else /* gpu needs to scale */ 3381a646342SBen Skeggs regp->fp_control |= NV_PRAMDAC_FP_TG_CONTROL_MODE_SCALE; 339db2bec18SBen Skeggs if (nvif_rd32(device, NV_PEXTDEV_BOOT_0) & NV_PEXTDEV_BOOT_0_STRAP_FP_IFACE_12BIT) 3401a646342SBen Skeggs regp->fp_control |= NV_PRAMDAC_FP_TG_CONTROL_WIDTH_12; 3411a646342SBen Skeggs if (nv_encoder->dcb->location != DCB_LOC_ON_CHIP && 3421a646342SBen Skeggs output_mode->clock > 165000) 3431a646342SBen Skeggs regp->fp_control |= (2 << 24); 3441a646342SBen Skeggs if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS) { 3451a646342SBen Skeggs bool duallink = false, dummy; 3461a646342SBen Skeggs if (nv_connector->edid && 3471a646342SBen Skeggs nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) { 3481a646342SBen Skeggs duallink = (((u8 *)nv_connector->edid)[121] == 2); 3491a646342SBen Skeggs } else { 3501a646342SBen Skeggs nouveau_bios_parse_lvds_table(dev, output_mode->clock, 3511a646342SBen Skeggs &duallink, &dummy); 3521a646342SBen Skeggs } 3531a646342SBen Skeggs 3541a646342SBen Skeggs if (duallink) 3551a646342SBen Skeggs regp->fp_control |= (8 << 28); 3561a646342SBen Skeggs } else 3571a646342SBen Skeggs if (output_mode->clock > 165000) 3581a646342SBen Skeggs regp->fp_control |= (8 << 28); 3591a646342SBen Skeggs 3601a646342SBen Skeggs regp->fp_debug_0 = NV_PRAMDAC_FP_DEBUG_0_YWEIGHT_ROUND | 3611a646342SBen Skeggs NV_PRAMDAC_FP_DEBUG_0_XWEIGHT_ROUND | 3621a646342SBen Skeggs NV_PRAMDAC_FP_DEBUG_0_YINTERP_BILINEAR | 3631a646342SBen Skeggs NV_PRAMDAC_FP_DEBUG_0_XINTERP_BILINEAR | 3641a646342SBen Skeggs NV_RAMDAC_FP_DEBUG_0_TMDS_ENABLED | 3651a646342SBen Skeggs NV_PRAMDAC_FP_DEBUG_0_YSCALE_ENABLE | 3661a646342SBen Skeggs NV_PRAMDAC_FP_DEBUG_0_XSCALE_ENABLE; 3671a646342SBen Skeggs 3681a646342SBen Skeggs /* We want automatic scaling */ 3691a646342SBen Skeggs regp->fp_debug_1 = 0; 3701a646342SBen Skeggs /* This can override HTOTAL and VTOTAL */ 3711a646342SBen Skeggs regp->fp_debug_2 = 0; 3721a646342SBen Skeggs 3731a646342SBen Skeggs /* Use 20.12 fixed point format to avoid floats */ 3741a646342SBen Skeggs mode_ratio = (1 << 12) * adjusted_mode->hdisplay / adjusted_mode->vdisplay; 3751a646342SBen Skeggs panel_ratio = (1 << 12) * output_mode->hdisplay / output_mode->vdisplay; 3761a646342SBen Skeggs /* if ratios are equal, SCALE_ASPECT will automatically (and correctly) 3771a646342SBen Skeggs * get treated the same as SCALE_FULLSCREEN */ 3781a646342SBen Skeggs if (nv_connector->scaling_mode == DRM_MODE_SCALE_ASPECT && 3791a646342SBen Skeggs mode_ratio != panel_ratio) { 3801a646342SBen Skeggs uint32_t diff, scale; 3811a646342SBen Skeggs bool divide_by_2 = nv_gf4_disp_arch(dev); 3821a646342SBen Skeggs 3831a646342SBen Skeggs if (mode_ratio < panel_ratio) { 3841a646342SBen Skeggs /* vertical needs to expand to glass size (automatic) 3851a646342SBen Skeggs * horizontal needs to be scaled at vertical scale factor 3861a646342SBen Skeggs * to maintain aspect */ 3871a646342SBen Skeggs 3881a646342SBen Skeggs scale = (1 << 12) * adjusted_mode->vdisplay / output_mode->vdisplay; 3891a646342SBen Skeggs regp->fp_debug_1 = NV_PRAMDAC_FP_DEBUG_1_XSCALE_TESTMODE_ENABLE | 3901a646342SBen Skeggs XLATE(scale, divide_by_2, NV_PRAMDAC_FP_DEBUG_1_XSCALE_VALUE); 3911a646342SBen Skeggs 3921a646342SBen Skeggs /* restrict area of screen used, horizontally */ 3931a646342SBen Skeggs diff = output_mode->hdisplay - 3941a646342SBen Skeggs output_mode->vdisplay * mode_ratio / (1 << 12); 3951a646342SBen Skeggs regp->fp_horiz_regs[FP_VALID_START] += diff / 2; 3961a646342SBen Skeggs regp->fp_horiz_regs[FP_VALID_END] -= diff / 2; 3971a646342SBen Skeggs } 3981a646342SBen Skeggs 3991a646342SBen Skeggs if (mode_ratio > panel_ratio) { 4001a646342SBen Skeggs /* horizontal needs to expand to glass size (automatic) 4011a646342SBen Skeggs * vertical needs to be scaled at horizontal scale factor 4021a646342SBen Skeggs * to maintain aspect */ 4031a646342SBen Skeggs 4041a646342SBen Skeggs scale = (1 << 12) * adjusted_mode->hdisplay / output_mode->hdisplay; 4051a646342SBen Skeggs regp->fp_debug_1 = NV_PRAMDAC_FP_DEBUG_1_YSCALE_TESTMODE_ENABLE | 4061a646342SBen Skeggs XLATE(scale, divide_by_2, NV_PRAMDAC_FP_DEBUG_1_YSCALE_VALUE); 4071a646342SBen Skeggs 4081a646342SBen Skeggs /* restrict area of screen used, vertically */ 4091a646342SBen Skeggs diff = output_mode->vdisplay - 4101a646342SBen Skeggs (1 << 12) * output_mode->hdisplay / mode_ratio; 4111a646342SBen Skeggs regp->fp_vert_regs[FP_VALID_START] += diff / 2; 4121a646342SBen Skeggs regp->fp_vert_regs[FP_VALID_END] -= diff / 2; 4131a646342SBen Skeggs } 4141a646342SBen Skeggs } 4151a646342SBen Skeggs 4161a646342SBen Skeggs /* Output property. */ 4171a646342SBen Skeggs if ((nv_connector->dithering_mode == DITHERING_MODE_ON) || 4181a646342SBen Skeggs (nv_connector->dithering_mode == DITHERING_MODE_AUTO && 419*d92df868SVille Syrjälä fb->depth > connector->display_info.bpc * 3)) { 420967e7bdeSBen Skeggs if (drm->device.info.chipset == 0x11) 4211a646342SBen Skeggs regp->dither = savep->dither | 0x00010000; 4221a646342SBen Skeggs else { 4231a646342SBen Skeggs int i; 4241a646342SBen Skeggs regp->dither = savep->dither | 0x00000001; 4251a646342SBen Skeggs for (i = 0; i < 3; i++) { 4261a646342SBen Skeggs regp->dither_regs[i] = 0xe4e4e4e4; 4271a646342SBen Skeggs regp->dither_regs[i + 3] = 0x44444444; 4281a646342SBen Skeggs } 4291a646342SBen Skeggs } 4301a646342SBen Skeggs } else { 431967e7bdeSBen Skeggs if (drm->device.info.chipset != 0x11) { 4321a646342SBen Skeggs /* reset them */ 4331a646342SBen Skeggs int i; 4341a646342SBen Skeggs for (i = 0; i < 3; i++) { 4351a646342SBen Skeggs regp->dither_regs[i] = savep->dither_regs[i]; 4361a646342SBen Skeggs regp->dither_regs[i + 3] = savep->dither_regs[i + 3]; 4371a646342SBen Skeggs } 4381a646342SBen Skeggs } 4391a646342SBen Skeggs regp->dither = savep->dither; 4401a646342SBen Skeggs } 4411a646342SBen Skeggs 4421a646342SBen Skeggs regp->fp_margin_color = 0; 4431a646342SBen Skeggs } 4441a646342SBen Skeggs 4451a646342SBen Skeggs static void nv04_dfp_commit(struct drm_encoder *encoder) 4461a646342SBen Skeggs { 4471a646342SBen Skeggs struct drm_device *dev = encoder->dev; 4481a646342SBen Skeggs struct nouveau_drm *drm = nouveau_drm(dev); 449d58ded76SJani Nikula const struct drm_encoder_helper_funcs *helper = encoder->helper_private; 4501a646342SBen Skeggs struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); 4511a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 4521a646342SBen Skeggs struct dcb_output *dcbe = nv_encoder->dcb; 4531a646342SBen Skeggs int head = nouveau_crtc(encoder->crtc)->index; 4541a646342SBen Skeggs struct drm_encoder *slave_encoder; 4551a646342SBen Skeggs 4561a646342SBen Skeggs if (dcbe->type == DCB_OUTPUT_TMDS) 4571a646342SBen Skeggs run_tmds_table(dev, dcbe, head, nv_encoder->mode.clock); 4581a646342SBen Skeggs else if (dcbe->type == DCB_OUTPUT_LVDS) 4591a646342SBen Skeggs call_lvds_script(dev, dcbe, head, LVDS_RESET, nv_encoder->mode.clock); 4601a646342SBen Skeggs 4611a646342SBen Skeggs /* update fp_control state for any changes made by scripts, 4621a646342SBen Skeggs * so correct value is written at DPMS on */ 4631a646342SBen Skeggs nv04_display(dev)->mode_reg.crtc_reg[head].fp_control = 4641a646342SBen Skeggs NVReadRAMDAC(dev, head, NV_PRAMDAC_FP_TG_CONTROL); 4651a646342SBen Skeggs 4661a646342SBen Skeggs /* This could use refinement for flatpanels, but it should work this way */ 467967e7bdeSBen Skeggs if (drm->device.info.chipset < 0x44) 4681a646342SBen Skeggs NVWriteRAMDAC(dev, 0, NV_PRAMDAC_TEST_CONTROL + nv04_dac_output_offset(encoder), 0xf0000000); 4691a646342SBen Skeggs else 4701a646342SBen Skeggs NVWriteRAMDAC(dev, 0, NV_PRAMDAC_TEST_CONTROL + nv04_dac_output_offset(encoder), 0x00100000); 4711a646342SBen Skeggs 4721a646342SBen Skeggs /* Init external transmitters */ 4731a646342SBen Skeggs slave_encoder = get_tmds_slave(encoder); 4741a646342SBen Skeggs if (slave_encoder) 4751a646342SBen Skeggs get_slave_funcs(slave_encoder)->mode_set( 4761a646342SBen Skeggs slave_encoder, &nv_encoder->mode, &nv_encoder->mode); 4771a646342SBen Skeggs 4781a646342SBen Skeggs helper->dpms(encoder, DRM_MODE_DPMS_ON); 4791a646342SBen Skeggs 4801a646342SBen Skeggs NV_DEBUG(drm, "Output %s is running on CRTC %d using output %c\n", 4818c6c361aSJani Nikula nouveau_encoder_connector_get(nv_encoder)->base.name, 4821a646342SBen Skeggs nv_crtc->index, '@' + ffs(nv_encoder->dcb->or)); 4831a646342SBen Skeggs } 4841a646342SBen Skeggs 4851a646342SBen Skeggs static void nv04_dfp_update_backlight(struct drm_encoder *encoder, int mode) 4861a646342SBen Skeggs { 4871a646342SBen Skeggs #ifdef __powerpc__ 4881a646342SBen Skeggs struct drm_device *dev = encoder->dev; 48992cffd56SDave Airlie struct nvif_object *device = &nouveau_drm(dev)->device.object; 4901a646342SBen Skeggs 4911a646342SBen Skeggs /* BIOS scripts usually take care of the backlight, thanks 4921a646342SBen Skeggs * Apple for your consistency. 4931a646342SBen Skeggs */ 494ffbab09bSVille Syrjälä if (dev->pdev->device == 0x0174 || dev->pdev->device == 0x0179 || 495ffbab09bSVille Syrjälä dev->pdev->device == 0x0189 || dev->pdev->device == 0x0329) { 4961a646342SBen Skeggs if (mode == DRM_MODE_DPMS_ON) { 4972ebfa1bcSBen Skeggs nvif_mask(device, NV_PBUS_DEBUG_DUALHEAD_CTL, 1 << 31, 1 << 31); 4982ebfa1bcSBen Skeggs nvif_mask(device, NV_PCRTC_GPIO_EXT, 3, 1); 4991a646342SBen Skeggs } else { 5002ebfa1bcSBen Skeggs nvif_mask(device, NV_PBUS_DEBUG_DUALHEAD_CTL, 1 << 31, 0); 5012ebfa1bcSBen Skeggs nvif_mask(device, NV_PCRTC_GPIO_EXT, 3, 0); 5021a646342SBen Skeggs } 5031a646342SBen Skeggs } 5041a646342SBen Skeggs #endif 5051a646342SBen Skeggs } 5061a646342SBen Skeggs 5071a646342SBen Skeggs static inline bool is_powersaving_dpms(int mode) 5081a646342SBen Skeggs { 5091a646342SBen Skeggs return mode != DRM_MODE_DPMS_ON && mode != NV_DPMS_CLEARED; 5101a646342SBen Skeggs } 5111a646342SBen Skeggs 5121a646342SBen Skeggs static void nv04_lvds_dpms(struct drm_encoder *encoder, int mode) 5131a646342SBen Skeggs { 5141a646342SBen Skeggs struct drm_device *dev = encoder->dev; 5151a646342SBen Skeggs struct drm_crtc *crtc = encoder->crtc; 5161a646342SBen Skeggs struct nouveau_drm *drm = nouveau_drm(dev); 5171a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 5181a646342SBen Skeggs bool was_powersaving = is_powersaving_dpms(nv_encoder->last_dpms); 5191a646342SBen Skeggs 5201a646342SBen Skeggs if (nv_encoder->last_dpms == mode) 5211a646342SBen Skeggs return; 5221a646342SBen Skeggs nv_encoder->last_dpms = mode; 5231a646342SBen Skeggs 5241a646342SBen Skeggs NV_DEBUG(drm, "Setting dpms mode %d on lvds encoder (output %d)\n", 5251a646342SBen Skeggs mode, nv_encoder->dcb->index); 5261a646342SBen Skeggs 5271a646342SBen Skeggs if (was_powersaving && is_powersaving_dpms(mode)) 5281a646342SBen Skeggs return; 5291a646342SBen Skeggs 5301a646342SBen Skeggs if (nv_encoder->dcb->lvdsconf.use_power_scripts) { 5311a646342SBen Skeggs /* when removing an output, crtc may not be set, but PANEL_OFF 5321a646342SBen Skeggs * must still be run 5331a646342SBen Skeggs */ 5341a646342SBen Skeggs int head = crtc ? nouveau_crtc(crtc)->index : 5351a646342SBen Skeggs nv04_dfp_get_bound_head(dev, nv_encoder->dcb); 5361a646342SBen Skeggs 5371a646342SBen Skeggs if (mode == DRM_MODE_DPMS_ON) { 5381a646342SBen Skeggs call_lvds_script(dev, nv_encoder->dcb, head, 5391a646342SBen Skeggs LVDS_PANEL_ON, nv_encoder->mode.clock); 5401a646342SBen Skeggs } else 5411a646342SBen Skeggs /* pxclk of 0 is fine for PANEL_OFF, and for a 5421a646342SBen Skeggs * disconnected LVDS encoder there is no native_mode 5431a646342SBen Skeggs */ 5441a646342SBen Skeggs call_lvds_script(dev, nv_encoder->dcb, head, 5451a646342SBen Skeggs LVDS_PANEL_OFF, 0); 5461a646342SBen Skeggs } 5471a646342SBen Skeggs 5481a646342SBen Skeggs nv04_dfp_update_backlight(encoder, mode); 5491a646342SBen Skeggs nv04_dfp_update_fp_control(encoder, mode); 5501a646342SBen Skeggs 5511a646342SBen Skeggs if (mode == DRM_MODE_DPMS_ON) 5521a646342SBen Skeggs nv04_dfp_prepare_sel_clk(dev, nv_encoder, nouveau_crtc(crtc)->index); 5531a646342SBen Skeggs else { 5541a646342SBen Skeggs nv04_display(dev)->mode_reg.sel_clk = NVReadRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK); 5551a646342SBen Skeggs nv04_display(dev)->mode_reg.sel_clk &= ~0xf0; 5561a646342SBen Skeggs } 5571a646342SBen Skeggs NVWriteRAMDAC(dev, 0, NV_PRAMDAC_SEL_CLK, nv04_display(dev)->mode_reg.sel_clk); 5581a646342SBen Skeggs } 5591a646342SBen Skeggs 5601a646342SBen Skeggs static void nv04_tmds_dpms(struct drm_encoder *encoder, int mode) 5611a646342SBen Skeggs { 5621a646342SBen Skeggs struct nouveau_drm *drm = nouveau_drm(encoder->dev); 5631a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 5641a646342SBen Skeggs 5651a646342SBen Skeggs if (nv_encoder->last_dpms == mode) 5661a646342SBen Skeggs return; 5671a646342SBen Skeggs nv_encoder->last_dpms = mode; 5681a646342SBen Skeggs 5691a646342SBen Skeggs NV_DEBUG(drm, "Setting dpms mode %d on tmds encoder (output %d)\n", 5701a646342SBen Skeggs mode, nv_encoder->dcb->index); 5711a646342SBen Skeggs 5721a646342SBen Skeggs nv04_dfp_update_backlight(encoder, mode); 5731a646342SBen Skeggs nv04_dfp_update_fp_control(encoder, mode); 5741a646342SBen Skeggs } 5751a646342SBen Skeggs 5761a646342SBen Skeggs static void nv04_dfp_save(struct drm_encoder *encoder) 5771a646342SBen Skeggs { 5781a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 5791a646342SBen Skeggs struct drm_device *dev = encoder->dev; 5801a646342SBen Skeggs 5811a646342SBen Skeggs if (nv_two_heads(dev)) 5821a646342SBen Skeggs nv_encoder->restore.head = 5831a646342SBen Skeggs nv04_dfp_get_bound_head(dev, nv_encoder->dcb); 5841a646342SBen Skeggs } 5851a646342SBen Skeggs 5861a646342SBen Skeggs static void nv04_dfp_restore(struct drm_encoder *encoder) 5871a646342SBen Skeggs { 5881a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 5891a646342SBen Skeggs struct drm_device *dev = encoder->dev; 5901a646342SBen Skeggs int head = nv_encoder->restore.head; 5911a646342SBen Skeggs 5921a646342SBen Skeggs if (nv_encoder->dcb->type == DCB_OUTPUT_LVDS) { 5931a646342SBen Skeggs struct nouveau_connector *connector = 5941a646342SBen Skeggs nouveau_encoder_connector_get(nv_encoder); 5951a646342SBen Skeggs 5961a646342SBen Skeggs if (connector && connector->native_mode) 5971a646342SBen Skeggs call_lvds_script(dev, nv_encoder->dcb, head, 5981a646342SBen Skeggs LVDS_PANEL_ON, 5991a646342SBen Skeggs connector->native_mode->clock); 6001a646342SBen Skeggs 6011a646342SBen Skeggs } else if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS) { 6021a646342SBen Skeggs int clock = nouveau_hw_pllvals_to_clk 6031a646342SBen Skeggs (&nv04_display(dev)->saved_reg.crtc_reg[head].pllvals); 6041a646342SBen Skeggs 6051a646342SBen Skeggs run_tmds_table(dev, nv_encoder->dcb, head, clock); 6061a646342SBen Skeggs } 6071a646342SBen Skeggs 6081a646342SBen Skeggs nv_encoder->last_dpms = NV_DPMS_CLEARED; 6091a646342SBen Skeggs } 6101a646342SBen Skeggs 6111a646342SBen Skeggs static void nv04_dfp_destroy(struct drm_encoder *encoder) 6121a646342SBen Skeggs { 6131a646342SBen Skeggs struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); 6141a646342SBen Skeggs 6151a646342SBen Skeggs if (get_slave_funcs(encoder)) 6161a646342SBen Skeggs get_slave_funcs(encoder)->destroy(encoder); 6171a646342SBen Skeggs 6181a646342SBen Skeggs drm_encoder_cleanup(encoder); 6191a646342SBen Skeggs kfree(nv_encoder); 6201a646342SBen Skeggs } 6211a646342SBen Skeggs 6221a646342SBen Skeggs static void nv04_tmds_slave_init(struct drm_encoder *encoder) 6231a646342SBen Skeggs { 6241a646342SBen Skeggs struct drm_device *dev = encoder->dev; 6251a646342SBen Skeggs struct dcb_output *dcb = nouveau_encoder(encoder)->dcb; 6261a646342SBen Skeggs struct nouveau_drm *drm = nouveau_drm(dev); 627be83cd4eSBen Skeggs struct nvkm_i2c *i2c = nvxx_i2c(&drm->device); 6282aa5eac5SBen Skeggs struct nvkm_i2c_bus *bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_PRI); 6292aa5eac5SBen Skeggs struct nvkm_i2c_bus_probe info[] = { 6309e2b734fSMartin Peres { 6311a646342SBen Skeggs { 6321a646342SBen Skeggs .type = "sil164", 6331a646342SBen Skeggs .addr = (dcb->tmdsconf.slave_addr == 0x7 ? 0x3a : 0x38), 6341a646342SBen Skeggs .platform_data = &(struct sil164_encoder_params) { 6351a646342SBen Skeggs SIL164_INPUT_EDGE_RISING 6361a646342SBen Skeggs } 6379e2b734fSMartin Peres }, 0 6381a646342SBen Skeggs }, 6391a646342SBen Skeggs { } 6401a646342SBen Skeggs }; 6411a646342SBen Skeggs int type; 6421a646342SBen Skeggs 6432aa5eac5SBen Skeggs if (!nv_gf4_disp_arch(dev) || !bus || get_tmds_slave(encoder)) 6441a646342SBen Skeggs return; 6451a646342SBen Skeggs 6462aa5eac5SBen Skeggs type = nvkm_i2c_bus_probe(bus, "TMDS transmitter", info, NULL, NULL); 6471a646342SBen Skeggs if (type < 0) 6481a646342SBen Skeggs return; 6491a646342SBen Skeggs 6501a646342SBen Skeggs drm_i2c_encoder_init(dev, to_encoder_slave(encoder), 6512aa5eac5SBen Skeggs &bus->i2c, &info[type].dev); 6521a646342SBen Skeggs } 6531a646342SBen Skeggs 6541a646342SBen Skeggs static const struct drm_encoder_helper_funcs nv04_lvds_helper_funcs = { 6551a646342SBen Skeggs .dpms = nv04_lvds_dpms, 6561a646342SBen Skeggs .mode_fixup = nv04_dfp_mode_fixup, 6571a646342SBen Skeggs .prepare = nv04_dfp_prepare, 6581a646342SBen Skeggs .commit = nv04_dfp_commit, 6591a646342SBen Skeggs .mode_set = nv04_dfp_mode_set, 6601a646342SBen Skeggs .detect = NULL, 6611a646342SBen Skeggs }; 6621a646342SBen Skeggs 6631a646342SBen Skeggs static const struct drm_encoder_helper_funcs nv04_tmds_helper_funcs = { 6641a646342SBen Skeggs .dpms = nv04_tmds_dpms, 6651a646342SBen Skeggs .mode_fixup = nv04_dfp_mode_fixup, 6661a646342SBen Skeggs .prepare = nv04_dfp_prepare, 6671a646342SBen Skeggs .commit = nv04_dfp_commit, 6681a646342SBen Skeggs .mode_set = nv04_dfp_mode_set, 6691a646342SBen Skeggs .detect = NULL, 6701a646342SBen Skeggs }; 6711a646342SBen Skeggs 6721a646342SBen Skeggs static const struct drm_encoder_funcs nv04_dfp_funcs = { 6731a646342SBen Skeggs .destroy = nv04_dfp_destroy, 6741a646342SBen Skeggs }; 6751a646342SBen Skeggs 6761a646342SBen Skeggs int 6771a646342SBen Skeggs nv04_dfp_create(struct drm_connector *connector, struct dcb_output *entry) 6781a646342SBen Skeggs { 6791a646342SBen Skeggs const struct drm_encoder_helper_funcs *helper; 6801a646342SBen Skeggs struct nouveau_encoder *nv_encoder = NULL; 6811a646342SBen Skeggs struct drm_encoder *encoder; 6821a646342SBen Skeggs int type; 6831a646342SBen Skeggs 6841a646342SBen Skeggs switch (entry->type) { 6851a646342SBen Skeggs case DCB_OUTPUT_TMDS: 6861a646342SBen Skeggs type = DRM_MODE_ENCODER_TMDS; 6871a646342SBen Skeggs helper = &nv04_tmds_helper_funcs; 6881a646342SBen Skeggs break; 6891a646342SBen Skeggs case DCB_OUTPUT_LVDS: 6901a646342SBen Skeggs type = DRM_MODE_ENCODER_LVDS; 6911a646342SBen Skeggs helper = &nv04_lvds_helper_funcs; 6921a646342SBen Skeggs break; 6931a646342SBen Skeggs default: 6941a646342SBen Skeggs return -EINVAL; 6951a646342SBen Skeggs } 6961a646342SBen Skeggs 6971a646342SBen Skeggs nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); 6981a646342SBen Skeggs if (!nv_encoder) 6991a646342SBen Skeggs return -ENOMEM; 7001a646342SBen Skeggs 701129b7820SDaniel Vetter nv_encoder->enc_save = nv04_dfp_save; 702129b7820SDaniel Vetter nv_encoder->enc_restore = nv04_dfp_restore; 703129b7820SDaniel Vetter 7041a646342SBen Skeggs encoder = to_drm_encoder(nv_encoder); 7051a646342SBen Skeggs 7061a646342SBen Skeggs nv_encoder->dcb = entry; 7071a646342SBen Skeggs nv_encoder->or = ffs(entry->or) - 1; 7081a646342SBen Skeggs 70913a3d91fSVille Syrjälä drm_encoder_init(connector->dev, encoder, &nv04_dfp_funcs, type, NULL); 7101a646342SBen Skeggs drm_encoder_helper_add(encoder, helper); 7111a646342SBen Skeggs 7121a646342SBen Skeggs encoder->possible_crtcs = entry->heads; 7131a646342SBen Skeggs encoder->possible_clones = 0; 7141a646342SBen Skeggs 7151a646342SBen Skeggs if (entry->type == DCB_OUTPUT_TMDS && 7161a646342SBen Skeggs entry->location != DCB_LOC_ON_CHIP) 7171a646342SBen Skeggs nv04_tmds_slave_init(encoder); 7181a646342SBen Skeggs 7191a646342SBen Skeggs drm_mode_connector_attach_encoder(connector, encoder); 7201a646342SBen Skeggs return 0; 7211a646342SBen Skeggs } 722