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;
63 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
67 nouveau_display(dev)->priv = disp;
68 nouveau_display(dev)->dtor = nv04_display_destroy;
69 nouveau_display(dev)->init = nv04_display_init;
70 nouveau_display(dev)->fini = nv04_display_fini;
72 nouveau_hw_save_vga_fonts(dev, 1);
74 nv04_crtc_create(dev, 0);
75 if (nv_two_heads(dev))
76 nv04_crtc_create(dev, 1);
78 for (i = 0; i < dcb->entries; i++) {
79 struct dcb_output *dcbent = &dcb->entry[i];
81 connector = nouveau_connector_create(dev, dcbent->connector);
82 if (IS_ERR(connector))
85 switch (dcbent->type) {
86 case DCB_OUTPUT_ANALOG:
87 ret = nv04_dac_create(connector, dcbent);
91 ret = nv04_dfp_create(connector, dcbent);
94 if (dcbent->location == DCB_LOC_ON_CHIP)
95 ret = nv17_tv_create(connector, dcbent);
97 ret = nv04_tv_create(connector, dcbent);
100 NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
108 list_for_each_entry_safe(connector, ct,
109 &dev->mode_config.connector_list, head) {
110 if (!connector->encoder_ids[0]) {
111 NV_WARN(drm, "%s has no encoders, removing\n",
112 drm_get_connector_name(connector));
113 connector->funcs->destroy(connector);
117 /* Save previous state */
118 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
119 crtc->funcs->save(crtc);
121 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
122 struct drm_encoder_helper_funcs *func = encoder->helper_private;
131 nv04_display_destroy(struct drm_device *dev)
133 struct nv04_display *disp = nv04_display(dev);
134 struct drm_encoder *encoder;
135 struct drm_crtc *crtc;
137 /* Turn every CRTC off. */
138 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
139 struct drm_mode_set modeset = {
143 crtc->funcs->set_config(&modeset);
147 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
148 struct drm_encoder_helper_funcs *func = encoder->helper_private;
150 func->restore(encoder);
153 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
154 crtc->funcs->restore(crtc);
156 nouveau_hw_save_vga_fonts(dev, 0);
158 nouveau_display(dev)->priv = NULL;
163 nv04_display_init(struct drm_device *dev)
165 struct drm_encoder *encoder;
166 struct drm_crtc *crtc;
168 /* meh.. modeset apparently doesn't setup all the regs and depends
169 * on pre-existing state, for now load the state of the card *before*
170 * nouveau was loaded, and then do a modeset.
172 * best thing to do probably is to make save/restore routines not
173 * save/restore "pre-load" state, but more general so we can save
176 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
177 struct drm_encoder_helper_funcs *func = encoder->helper_private;
179 func->restore(encoder);
182 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
183 crtc->funcs->restore(crtc);
189 nv04_display_fini(struct drm_device *dev)
191 /* disable vblank interrupts */
192 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
193 if (nv_two_heads(dev))
194 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);