Commit | Line | Data |
---|---|---|
6ee73861 BS |
1 | /* |
2 | * Copyright 2009 Red Hat Inc. | |
3 | * | |
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: | |
10 | * | |
11 | * The above copyright notice and this permission notice shall be included in | |
12 | * all copies or substantial portions of the Software. | |
13 | * | |
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. | |
21 | * | |
22 | * Author: Ben Skeggs | |
23 | */ | |
24 | ||
25 | #include "drmP.h" | |
26 | #include "drm.h" | |
27 | #include "drm_crtc_helper.h" | |
28 | ||
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" | |
34 | ||
c88c2e06 FJ |
35 | int |
36 | nv04_display_early_init(struct drm_device *dev) | |
37 | { | |
afada5e0 BS |
38 | /* ensure vblank interrupts are off, they can't be enabled until |
39 | * drm_vblank has been initialised | |
40 | */ | |
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); | |
44 | ||
c88c2e06 FJ |
45 | return 0; |
46 | } | |
47 | ||
48 | void | |
49 | nv04_display_late_takedown(struct drm_device *dev) | |
50 | { | |
c88c2e06 FJ |
51 | } |
52 | ||
6ee73861 BS |
53 | int |
54 | nv04_display_create(struct drm_device *dev) | |
55 | { | |
56 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
04a39c57 | 57 | struct dcb_table *dcb = &dev_priv->vbios.dcb; |
8f1a6086 | 58 | struct drm_connector *connector, *ct; |
6ee73861 BS |
59 | struct drm_encoder *encoder; |
60 | struct drm_crtc *crtc; | |
017e6e29 | 61 | struct nv04_display *disp; |
6ee73861 BS |
62 | int i, ret; |
63 | ||
ef2bb506 | 64 | NV_DEBUG_KMS(dev, "\n"); |
6ee73861 | 65 | |
017e6e29 BS |
66 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
67 | dev_priv->engine.display.priv = disp; | |
68 | if (!disp) | |
69 | return -ENOMEM; | |
70 | ||
95f158ea | 71 | nouveau_hw_save_vga_fonts(dev, 1); |
6ee73861 | 72 | |
6ee73861 BS |
73 | nv04_crtc_create(dev, 0); |
74 | if (nv_two_heads(dev)) | |
75 | nv04_crtc_create(dev, 1); | |
76 | ||
77 | for (i = 0; i < dcb->entries; i++) { | |
cb75d97e | 78 | struct dcb_output *dcbent = &dcb->entry[i]; |
6ee73861 | 79 | |
8f1a6086 BS |
80 | connector = nouveau_connector_create(dev, dcbent->connector); |
81 | if (IS_ERR(connector)) | |
82 | continue; | |
83 | ||
6ee73861 | 84 | switch (dcbent->type) { |
cb75d97e | 85 | case DCB_OUTPUT_ANALOG: |
8f1a6086 | 86 | ret = nv04_dac_create(connector, dcbent); |
6ee73861 | 87 | break; |
cb75d97e BS |
88 | case DCB_OUTPUT_LVDS: |
89 | case DCB_OUTPUT_TMDS: | |
8f1a6086 | 90 | ret = nv04_dfp_create(connector, dcbent); |
6ee73861 | 91 | break; |
cb75d97e | 92 | case DCB_OUTPUT_TV: |
6ee73861 | 93 | if (dcbent->location == DCB_LOC_ON_CHIP) |
8f1a6086 | 94 | ret = nv17_tv_create(connector, dcbent); |
6ee73861 | 95 | else |
8f1a6086 | 96 | ret = nv04_tv_create(connector, dcbent); |
6ee73861 BS |
97 | break; |
98 | default: | |
99 | NV_WARN(dev, "DCB type %d not known\n", dcbent->type); | |
100 | continue; | |
101 | } | |
102 | ||
103 | if (ret) | |
104 | continue; | |
6ee73861 BS |
105 | } |
106 | ||
8f1a6086 BS |
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); | |
113 | } | |
114 | } | |
6ee73861 BS |
115 | |
116 | /* Save previous state */ | |
6ee73861 BS |
117 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
118 | crtc->funcs->save(crtc); | |
119 | ||
120 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
121 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
122 | ||
123 | func->save(encoder); | |
124 | } | |
125 | ||
126 | return 0; | |
127 | } | |
128 | ||
129 | void | |
130 | nv04_display_destroy(struct drm_device *dev) | |
131 | { | |
017e6e29 BS |
132 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
133 | struct nv04_display *disp = nv04_display(dev); | |
6ee73861 BS |
134 | struct drm_encoder *encoder; |
135 | struct drm_crtc *crtc; | |
136 | ||
ef2bb506 | 137 | NV_DEBUG_KMS(dev, "\n"); |
6ee73861 BS |
138 | |
139 | /* Turn every CRTC off. */ | |
140 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
141 | struct drm_mode_set modeset = { | |
142 | .crtc = crtc, | |
143 | }; | |
144 | ||
145 | crtc->funcs->set_config(&modeset); | |
146 | } | |
147 | ||
148 | /* Restore state */ | |
6ee73861 BS |
149 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
150 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
151 | ||
152 | func->restore(encoder); | |
153 | } | |
154 | ||
155 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) | |
156 | crtc->funcs->restore(crtc); | |
157 | ||
95f158ea | 158 | nouveau_hw_save_vga_fonts(dev, 0); |
017e6e29 BS |
159 | |
160 | dev_priv->engine.display.priv = NULL; | |
161 | kfree(disp); | |
6ee73861 BS |
162 | } |
163 | ||
c88c2e06 FJ |
164 | int |
165 | nv04_display_init(struct drm_device *dev) | |
6ee73861 | 166 | { |
6ee73861 BS |
167 | struct drm_encoder *encoder; |
168 | struct drm_crtc *crtc; | |
169 | ||
6ee73861 BS |
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. | |
173 | * | |
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 | |
176 | * on suspend too. | |
177 | */ | |
178 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
179 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
180 | ||
181 | func->restore(encoder); | |
182 | } | |
183 | ||
184 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) | |
185 | crtc->funcs->restore(crtc); | |
c88c2e06 FJ |
186 | |
187 | return 0; | |
6ee73861 BS |
188 | } |
189 | ||
2a44e499 BS |
190 | void |
191 | nv04_display_fini(struct drm_device *dev) | |
192 | { | |
afada5e0 BS |
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); | |
2a44e499 | 197 | } |