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_early_init(struct drm_device *dev)
38 /* ensure vblank interrupts are off, they can't be enabled until
39 * drm_vblank has been initialised
41 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
42 if (nv_two_heads(dev))
43 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
49 nv04_display_late_takedown(struct drm_device *dev)
54 nv04_display_create(struct drm_device *dev)
56 struct drm_nouveau_private *dev_priv = dev->dev_private;
57 struct dcb_table *dcb = &dev_priv->vbios.dcb;
58 struct drm_connector *connector, *ct;
59 struct drm_encoder *encoder;
60 struct drm_crtc *crtc;
61 struct nv04_display *disp;
64 NV_DEBUG_KMS(dev, "\n");
66 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
67 dev_priv->engine.display.priv = disp;
71 nouveau_hw_save_vga_fonts(dev, 1);
73 nv04_crtc_create(dev, 0);
74 if (nv_two_heads(dev))
75 nv04_crtc_create(dev, 1);
77 for (i = 0; i < dcb->entries; i++) {
78 struct dcb_output *dcbent = &dcb->entry[i];
80 connector = nouveau_connector_create(dev, dcbent->connector);
81 if (IS_ERR(connector))
84 switch (dcbent->type) {
85 case DCB_OUTPUT_ANALOG:
86 ret = nv04_dac_create(connector, dcbent);
90 ret = nv04_dfp_create(connector, dcbent);
93 if (dcbent->location == DCB_LOC_ON_CHIP)
94 ret = nv17_tv_create(connector, dcbent);
96 ret = nv04_tv_create(connector, dcbent);
99 NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
107 list_for_each_entry_safe(connector, ct,
108 &dev->mode_config.connector_list, head) {
109 if (!connector->encoder_ids[0]) {
110 NV_WARN(dev, "%s has no encoders, removing\n",
111 drm_get_connector_name(connector));
112 connector->funcs->destroy(connector);
116 /* Save previous state */
117 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
118 crtc->funcs->save(crtc);
120 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
121 struct drm_encoder_helper_funcs *func = encoder->helper_private;
130 nv04_display_destroy(struct drm_device *dev)
132 struct drm_nouveau_private *dev_priv = dev->dev_private;
133 struct nv04_display *disp = nv04_display(dev);
134 struct drm_encoder *encoder;
135 struct drm_crtc *crtc;
137 NV_DEBUG_KMS(dev, "\n");
139 /* Turn every CRTC off. */
140 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
141 struct drm_mode_set modeset = {
145 crtc->funcs->set_config(&modeset);
149 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
150 struct drm_encoder_helper_funcs *func = encoder->helper_private;
152 func->restore(encoder);
155 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
156 crtc->funcs->restore(crtc);
158 nouveau_hw_save_vga_fonts(dev, 0);
160 dev_priv->engine.display.priv = NULL;
165 nv04_display_init(struct drm_device *dev)
167 struct drm_encoder *encoder;
168 struct drm_crtc *crtc;
170 /* meh.. modeset apparently doesn't setup all the regs and depends
171 * on pre-existing state, for now load the state of the card *before*
172 * nouveau was loaded, and then do a modeset.
174 * best thing to do probably is to make save/restore routines not
175 * save/restore "pre-load" state, but more general so we can save
178 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
179 struct drm_encoder_helper_funcs *func = encoder->helper_private;
181 func->restore(encoder);
184 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
185 crtc->funcs->restore(crtc);
191 nv04_display_fini(struct drm_device *dev)
193 /* disable vblank interrupts */
194 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
195 if (nv_two_heads(dev))
196 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);