2 * Copyright 2009 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "drm_crtc_helper.h"
29 #include "nouveau_drv.h"
30 #include "nouveau_fb.h"
31 #include "nouveau_hw.h"
32 #include "nouveau_encoder.h"
33 #include "nouveau_connector.h"
35 static void nv04_vblank_crtc0_isr(struct drm_device
*);
36 static void nv04_vblank_crtc1_isr(struct drm_device
*);
39 nv04_display_store_initial_head_owner(struct drm_device
*dev
)
41 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
43 if (dev_priv
->chipset
!= 0x11) {
44 dev_priv
->crtc_owner
= NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_44
);
48 /* reading CR44 is broken on nv11, so we attempt to infer it */
49 if (nvReadMC(dev
, NV_PBUS_DEBUG_1
) & (1 << 28)) /* heads tied, restore both */
50 dev_priv
->crtc_owner
= 0x4;
52 uint8_t slaved_on_A
, slaved_on_B
;
56 slaved_on_B
= NVReadVgaCrtc(dev
, 1, NV_CIO_CRE_PIXEL_INDEX
) &
59 tvB
= !(NVReadVgaCrtc(dev
, 1, NV_CIO_CRE_LCD__INDEX
) &
60 MASK(NV_CIO_CRE_LCD_LCD_SELECT
));
62 slaved_on_A
= NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_PIXEL_INDEX
) &
65 tvA
= !(NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_LCD__INDEX
) &
66 MASK(NV_CIO_CRE_LCD_LCD_SELECT
));
68 if (slaved_on_A
&& !tvA
)
69 dev_priv
->crtc_owner
= 0x0;
70 else if (slaved_on_B
&& !tvB
)
71 dev_priv
->crtc_owner
= 0x3;
73 dev_priv
->crtc_owner
= 0x0;
75 dev_priv
->crtc_owner
= 0x3;
77 dev_priv
->crtc_owner
= 0x0;
82 nv04_display_early_init(struct drm_device
*dev
)
84 /* Make the I2C buses accessible. */
85 if (!nv_gf4_disp_arch(dev
)) {
86 uint32_t pmc_enable
= nv_rd32(dev
, NV03_PMC_ENABLE
);
88 if (!(pmc_enable
& 1))
89 nv_wr32(dev
, NV03_PMC_ENABLE
, pmc_enable
| 1);
92 /* Unlock the VGA CRTCs. */
93 NVLockVgaCrtcs(dev
, false);
95 /* Make sure the CRTCs aren't in slaved mode. */
96 if (nv_two_heads(dev
)) {
97 nv04_display_store_initial_head_owner(dev
);
105 nv04_display_late_takedown(struct drm_device
*dev
)
107 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
109 if (nv_two_heads(dev
))
110 NVSetOwner(dev
, dev_priv
->crtc_owner
);
112 NVLockVgaCrtcs(dev
, true);
116 nv04_display_create(struct drm_device
*dev
)
118 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
119 struct dcb_table
*dcb
= &dev_priv
->vbios
.dcb
;
120 struct drm_connector
*connector
, *ct
;
121 struct drm_encoder
*encoder
;
122 struct drm_crtc
*crtc
;
125 NV_DEBUG_KMS(dev
, "\n");
127 nouveau_hw_save_vga_fonts(dev
, 1);
129 nv04_crtc_create(dev
, 0);
130 if (nv_two_heads(dev
))
131 nv04_crtc_create(dev
, 1);
133 for (i
= 0; i
< dcb
->entries
; i
++) {
134 struct dcb_entry
*dcbent
= &dcb
->entry
[i
];
136 connector
= nouveau_connector_create(dev
, dcbent
->connector
);
137 if (IS_ERR(connector
))
140 switch (dcbent
->type
) {
142 ret
= nv04_dac_create(connector
, dcbent
);
146 ret
= nv04_dfp_create(connector
, dcbent
);
149 if (dcbent
->location
== DCB_LOC_ON_CHIP
)
150 ret
= nv17_tv_create(connector
, dcbent
);
152 ret
= nv04_tv_create(connector
, dcbent
);
155 NV_WARN(dev
, "DCB type %d not known\n", dcbent
->type
);
163 list_for_each_entry_safe(connector
, ct
,
164 &dev
->mode_config
.connector_list
, head
) {
165 if (!connector
->encoder_ids
[0]) {
166 NV_WARN(dev
, "%s has no encoders, removing\n",
167 drm_get_connector_name(connector
));
168 connector
->funcs
->destroy(connector
);
172 /* Save previous state */
173 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
174 crtc
->funcs
->save(crtc
);
176 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
177 struct drm_encoder_helper_funcs
*func
= encoder
->helper_private
;
182 nouveau_irq_register(dev
, 24, nv04_vblank_crtc0_isr
);
183 nouveau_irq_register(dev
, 25, nv04_vblank_crtc1_isr
);
188 nv04_display_destroy(struct drm_device
*dev
)
190 struct drm_encoder
*encoder
;
191 struct drm_crtc
*crtc
;
193 NV_DEBUG_KMS(dev
, "\n");
195 nouveau_irq_unregister(dev
, 24);
196 nouveau_irq_unregister(dev
, 25);
198 /* Turn every CRTC off. */
199 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
200 struct drm_mode_set modeset
= {
204 crtc
->funcs
->set_config(&modeset
);
208 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
209 struct drm_encoder_helper_funcs
*func
= encoder
->helper_private
;
211 func
->restore(encoder
);
214 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
215 crtc
->funcs
->restore(crtc
);
217 nouveau_hw_save_vga_fonts(dev
, 0);
221 nv04_display_init(struct drm_device
*dev
)
223 struct drm_encoder
*encoder
;
224 struct drm_crtc
*crtc
;
226 /* meh.. modeset apparently doesn't setup all the regs and depends
227 * on pre-existing state, for now load the state of the card *before*
228 * nouveau was loaded, and then do a modeset.
230 * best thing to do probably is to make save/restore routines not
231 * save/restore "pre-load" state, but more general so we can save
234 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
235 struct drm_encoder_helper_funcs
*func
= encoder
->helper_private
;
237 func
->restore(encoder
);
240 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
241 crtc
->funcs
->restore(crtc
);
247 nv04_display_fini(struct drm_device
*dev
)
252 nv04_vblank_crtc0_isr(struct drm_device
*dev
)
254 nv_wr32(dev
, NV_CRTC0_INTSTAT
, NV_CRTC_INTR_VBLANK
);
255 drm_handle_vblank(dev
, 0);
259 nv04_vblank_crtc1_isr(struct drm_device
*dev
)
261 nv_wr32(dev
, NV_CRTC1_INTSTAT
, NV_CRTC_INTR_VBLANK
);
262 drm_handle_vblank(dev
, 1);