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.
26 #include <drm/drm_crtc_helper.h>
28 #include "nouveau_drm.h"
29 #include "nouveau_reg.h"
30 #include "nouveau_hw.h"
31 #include "nouveau_encoder.h"
32 #include "nouveau_connector.h"
35 nv04_display_early_init(struct drm_device *dev)
37 /* ensure vblank interrupts are off, they can't be enabled until
38 * drm_vblank has been initialised
40 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
41 if (nv_two_heads(dev))
42 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
48 nv04_display_late_takedown(struct drm_device *dev)
53 nv04_display_create(struct drm_device *dev)
55 struct nouveau_drm *drm = nouveau_drm(dev);
56 struct dcb_table *dcb = &drm->vbios.dcb;
57 struct drm_connector *connector, *ct;
58 struct drm_encoder *encoder;
59 struct drm_crtc *crtc;
60 struct nv04_display *disp;
65 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
69 nouveau_display(dev)->priv = disp;
70 nouveau_display(dev)->dtor = nv04_display_destroy;
71 nouveau_display(dev)->init = nv04_display_init;
72 nouveau_display(dev)->fini = nv04_display_fini;
74 nouveau_hw_save_vga_fonts(dev, 1);
76 nv04_crtc_create(dev, 0);
77 if (nv_two_heads(dev))
78 nv04_crtc_create(dev, 1);
80 for (i = 0; i < dcb->entries; i++) {
81 struct dcb_output *dcbent = &dcb->entry[i];
83 connector = nouveau_connector_create(dev, dcbent->connector);
84 if (IS_ERR(connector))
87 switch (dcbent->type) {
88 case DCB_OUTPUT_ANALOG:
89 ret = nv04_dac_create(connector, dcbent);
93 ret = nv04_dfp_create(connector, dcbent);
96 if (dcbent->location == DCB_LOC_ON_CHIP)
97 ret = nv17_tv_create(connector, dcbent);
99 ret = nv04_tv_create(connector, dcbent);
102 NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
110 list_for_each_entry_safe(connector, ct,
111 &dev->mode_config.connector_list, head) {
112 if (!connector->encoder_ids[0]) {
113 NV_WARN(drm, "%s has no encoders, removing\n",
114 drm_get_connector_name(connector));
115 connector->funcs->destroy(connector);
119 /* Save previous state */
120 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
121 crtc->funcs->save(crtc);
123 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
124 struct drm_encoder_helper_funcs *func = encoder->helper_private;
133 nv04_display_destroy(struct drm_device *dev)
135 struct nouveau_drm *drm = nouveau_drm(dev);
136 struct nv04_display *disp = nv04_display(dev);
137 struct drm_encoder *encoder;
138 struct drm_crtc *crtc;
142 /* Turn every CRTC off. */
143 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
144 struct drm_mode_set modeset = {
148 crtc->funcs->set_config(&modeset);
152 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
153 struct drm_encoder_helper_funcs *func = encoder->helper_private;
155 func->restore(encoder);
158 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
159 crtc->funcs->restore(crtc);
161 nouveau_hw_save_vga_fonts(dev, 0);
163 nouveau_display(dev)->priv = NULL;
168 nv04_display_init(struct drm_device *dev)
170 struct drm_encoder *encoder;
171 struct drm_crtc *crtc;
173 /* meh.. modeset apparently doesn't setup all the regs and depends
174 * on pre-existing state, for now load the state of the card *before*
175 * nouveau was loaded, and then do a modeset.
177 * best thing to do probably is to make save/restore routines not
178 * save/restore "pre-load" state, but more general so we can save
181 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
182 struct drm_encoder_helper_funcs *func = encoder->helper_private;
184 func->restore(encoder);
187 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
188 crtc->funcs->restore(crtc);
194 nv04_display_fini(struct drm_device *dev)
196 /* disable vblank interrupts */
197 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
198 if (nv_two_heads(dev))
199 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);