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_create(struct drm_device *dev)
81 struct drm_nouveau_private *dev_priv = dev->dev_private;
82 struct dcb_table *dcb = &dev_priv->vbios.dcb;
83 struct drm_connector *connector, *ct;
84 struct drm_encoder *encoder;
85 struct drm_crtc *crtc;
88 NV_DEBUG_KMS(dev, "\n");
90 NVLockVgaCrtcs(dev, false);
92 if (nv_two_heads(dev)) {
93 nv04_display_store_initial_head_owner(dev);
97 nouveau_hw_save_vga_fonts(dev, 1);
99 drm_mode_config_init(dev);
100 drm_mode_create_scaling_mode_property(dev);
101 drm_mode_create_dithering_property(dev);
103 dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
105 dev->mode_config.min_width = 0;
106 dev->mode_config.min_height = 0;
107 switch (dev_priv->card_type) {
109 dev->mode_config.max_width = 2048;
110 dev->mode_config.max_height = 2048;
113 dev->mode_config.max_width = 4096;
114 dev->mode_config.max_height = 4096;
118 dev->mode_config.fb_base = dev_priv->fb_phys;
120 nv04_crtc_create(dev, 0);
121 if (nv_two_heads(dev))
122 nv04_crtc_create(dev, 1);
124 for (i = 0; i < dcb->entries; i++) {
125 struct dcb_entry *dcbent = &dcb->entry[i];
127 connector = nouveau_connector_create(dev, dcbent->connector);
128 if (IS_ERR(connector))
131 switch (dcbent->type) {
133 ret = nv04_dac_create(connector, dcbent);
137 ret = nv04_dfp_create(connector, dcbent);
140 if (dcbent->location == DCB_LOC_ON_CHIP)
141 ret = nv17_tv_create(connector, dcbent);
143 ret = nv04_tv_create(connector, dcbent);
146 NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
154 list_for_each_entry_safe(connector, ct,
155 &dev->mode_config.connector_list, head) {
156 if (!connector->encoder_ids[0]) {
157 NV_WARN(dev, "%s has no encoders, removing\n",
158 drm_get_connector_name(connector));
159 connector->funcs->destroy(connector);
163 /* Save previous state */
164 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
165 crtc->funcs->save(crtc);
167 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
168 struct drm_encoder_helper_funcs *func = encoder->helper_private;
177 nv04_display_destroy(struct drm_device *dev)
179 struct drm_nouveau_private *dev_priv = dev->dev_private;
180 struct drm_encoder *encoder;
181 struct drm_crtc *crtc;
183 NV_DEBUG_KMS(dev, "\n");
185 /* Turn every CRTC off. */
186 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
187 struct drm_mode_set modeset = {
191 crtc->funcs->set_config(&modeset);
195 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
196 struct drm_encoder_helper_funcs *func = encoder->helper_private;
198 func->restore(encoder);
201 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
202 crtc->funcs->restore(crtc);
204 drm_mode_config_cleanup(dev);
206 nouveau_hw_save_vga_fonts(dev, 0);
208 if (nv_two_heads(dev))
209 NVSetOwner(dev, dev_priv->crtc_owner);
210 NVLockVgaCrtcs(dev, true);
214 nv04_display_restore(struct drm_device *dev)
216 struct drm_encoder *encoder;
217 struct drm_crtc *crtc;
219 NVLockVgaCrtcs(dev, false);
221 /* meh.. modeset apparently doesn't setup all the regs and depends
222 * on pre-existing state, for now load the state of the card *before*
223 * nouveau was loaded, and then do a modeset.
225 * best thing to do probably is to make save/restore routines not
226 * save/restore "pre-load" state, but more general so we can save
229 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
230 struct drm_encoder_helper_funcs *func = encoder->helper_private;
232 func->restore(encoder);
235 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
236 crtc->funcs->restore(crtc);