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"
36 nv04_display_store_initial_head_owner(struct drm_device
*dev
)
38 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
40 if (dev_priv
->chipset
!= 0x11) {
41 dev_priv
->crtc_owner
= NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_44
);
45 /* reading CR44 is broken on nv11, so we attempt to infer it */
46 if (nvReadMC(dev
, NV_PBUS_DEBUG_1
) & (1 << 28)) /* heads tied, restore both */
47 dev_priv
->crtc_owner
= 0x4;
49 uint8_t slaved_on_A
, slaved_on_B
;
53 slaved_on_B
= NVReadVgaCrtc(dev
, 1, NV_CIO_CRE_PIXEL_INDEX
) &
56 tvB
= !(NVReadVgaCrtc(dev
, 1, NV_CIO_CRE_LCD__INDEX
) &
57 MASK(NV_CIO_CRE_LCD_LCD_SELECT
));
59 slaved_on_A
= NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_PIXEL_INDEX
) &
62 tvA
= !(NVReadVgaCrtc(dev
, 0, NV_CIO_CRE_LCD__INDEX
) &
63 MASK(NV_CIO_CRE_LCD_LCD_SELECT
));
65 if (slaved_on_A
&& !tvA
)
66 dev_priv
->crtc_owner
= 0x0;
67 else if (slaved_on_B
&& !tvB
)
68 dev_priv
->crtc_owner
= 0x3;
70 dev_priv
->crtc_owner
= 0x0;
72 dev_priv
->crtc_owner
= 0x3;
74 dev_priv
->crtc_owner
= 0x0;
79 nv04_display_early_init(struct drm_device
*dev
)
81 /* Make the I2C buses accessible. */
82 if (!nv_gf4_disp_arch(dev
)) {
83 uint32_t pmc_enable
= nv_rd32(dev
, NV03_PMC_ENABLE
);
85 if (!(pmc_enable
& 1))
86 nv_wr32(dev
, NV03_PMC_ENABLE
, pmc_enable
| 1);
89 /* Unlock the VGA CRTCs. */
90 NVLockVgaCrtcs(dev
, false);
92 /* Make sure the CRTCs aren't in slaved mode. */
93 if (nv_two_heads(dev
)) {
94 nv04_display_store_initial_head_owner(dev
);
102 nv04_display_late_takedown(struct drm_device
*dev
)
104 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
106 if (nv_two_heads(dev
))
107 NVSetOwner(dev
, dev_priv
->crtc_owner
);
109 NVLockVgaCrtcs(dev
, true);
113 nv04_display_create(struct drm_device
*dev
)
115 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
116 struct dcb_table
*dcb
= &dev_priv
->vbios
.dcb
;
117 struct drm_connector
*connector
, *ct
;
118 struct drm_encoder
*encoder
;
119 struct drm_crtc
*crtc
;
122 NV_DEBUG_KMS(dev
, "\n");
124 nouveau_hw_save_vga_fonts(dev
, 1);
126 drm_mode_config_init(dev
);
127 drm_mode_create_scaling_mode_property(dev
);
128 drm_mode_create_dithering_property(dev
);
130 dev
->mode_config
.funcs
= (void *)&nouveau_mode_config_funcs
;
132 dev
->mode_config
.min_width
= 0;
133 dev
->mode_config
.min_height
= 0;
134 switch (dev_priv
->card_type
) {
136 dev
->mode_config
.max_width
= 2048;
137 dev
->mode_config
.max_height
= 2048;
140 dev
->mode_config
.max_width
= 4096;
141 dev
->mode_config
.max_height
= 4096;
145 dev
->mode_config
.fb_base
= dev_priv
->fb_phys
;
147 nv04_crtc_create(dev
, 0);
148 if (nv_two_heads(dev
))
149 nv04_crtc_create(dev
, 1);
151 for (i
= 0; i
< dcb
->entries
; i
++) {
152 struct dcb_entry
*dcbent
= &dcb
->entry
[i
];
154 connector
= nouveau_connector_create(dev
, dcbent
->connector
);
155 if (IS_ERR(connector
))
158 switch (dcbent
->type
) {
160 ret
= nv04_dac_create(connector
, dcbent
);
164 ret
= nv04_dfp_create(connector
, dcbent
);
167 if (dcbent
->location
== DCB_LOC_ON_CHIP
)
168 ret
= nv17_tv_create(connector
, dcbent
);
170 ret
= nv04_tv_create(connector
, dcbent
);
173 NV_WARN(dev
, "DCB type %d not known\n", dcbent
->type
);
181 list_for_each_entry_safe(connector
, ct
,
182 &dev
->mode_config
.connector_list
, head
) {
183 if (!connector
->encoder_ids
[0]) {
184 NV_WARN(dev
, "%s has no encoders, removing\n",
185 drm_get_connector_name(connector
));
186 connector
->funcs
->destroy(connector
);
190 /* Save previous state */
191 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
192 crtc
->funcs
->save(crtc
);
194 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
195 struct drm_encoder_helper_funcs
*func
= encoder
->helper_private
;
204 nv04_display_destroy(struct drm_device
*dev
)
206 struct drm_encoder
*encoder
;
207 struct drm_crtc
*crtc
;
209 NV_DEBUG_KMS(dev
, "\n");
211 /* Turn every CRTC off. */
212 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
213 struct drm_mode_set modeset
= {
217 crtc
->funcs
->set_config(&modeset
);
221 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
222 struct drm_encoder_helper_funcs
*func
= encoder
->helper_private
;
224 func
->restore(encoder
);
227 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
228 crtc
->funcs
->restore(crtc
);
230 drm_mode_config_cleanup(dev
);
232 nouveau_hw_save_vga_fonts(dev
, 0);
236 nv04_display_init(struct drm_device
*dev
)
238 struct drm_encoder
*encoder
;
239 struct drm_crtc
*crtc
;
241 /* meh.. modeset apparently doesn't setup all the regs and depends
242 * on pre-existing state, for now load the state of the card *before*
243 * nouveau was loaded, and then do a modeset.
245 * best thing to do probably is to make save/restore routines not
246 * save/restore "pre-load" state, but more general so we can save
249 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
250 struct drm_encoder_helper_funcs
*func
= encoder
->helper_private
;
252 func
->restore(encoder
);
255 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
256 crtc
->funcs
->restore(crtc
);