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 | ||
760285e7 DH |
25 | #include <drm/drmP.h> |
26 | #include <drm/drm_crtc_helper.h> | |
6ee73861 | 27 | |
77145f1c BS |
28 | #include "nouveau_drm.h" |
29 | #include "nouveau_reg.h" | |
6ee73861 BS |
30 | #include "nouveau_hw.h" |
31 | #include "nouveau_encoder.h" | |
32 | #include "nouveau_connector.h" | |
33 | ||
c88c2e06 FJ |
34 | int |
35 | nv04_display_early_init(struct drm_device *dev) | |
36 | { | |
afada5e0 BS |
37 | /* ensure vblank interrupts are off, they can't be enabled until |
38 | * drm_vblank has been initialised | |
39 | */ | |
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); | |
43 | ||
c88c2e06 FJ |
44 | return 0; |
45 | } | |
46 | ||
47 | void | |
48 | nv04_display_late_takedown(struct drm_device *dev) | |
49 | { | |
c88c2e06 FJ |
50 | } |
51 | ||
6ee73861 BS |
52 | int |
53 | nv04_display_create(struct drm_device *dev) | |
54 | { | |
77145f1c BS |
55 | struct nouveau_drm *drm = nouveau_drm(dev); |
56 | struct dcb_table *dcb = &drm->vbios.dcb; | |
8f1a6086 | 57 | struct drm_connector *connector, *ct; |
6ee73861 BS |
58 | struct drm_encoder *encoder; |
59 | struct drm_crtc *crtc; | |
017e6e29 | 60 | struct nv04_display *disp; |
6ee73861 BS |
61 | int i, ret; |
62 | ||
77145f1c | 63 | NV_DEBUG(drm, "\n"); |
6ee73861 | 64 | |
017e6e29 | 65 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
017e6e29 BS |
66 | if (!disp) |
67 | return -ENOMEM; | |
68 | ||
77145f1c BS |
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; | |
6ee73861 | 73 | |
95f158ea | 74 | nouveau_hw_save_vga_fonts(dev, 1); |
6ee73861 | 75 | |
6ee73861 BS |
76 | nv04_crtc_create(dev, 0); |
77 | if (nv_two_heads(dev)) | |
78 | nv04_crtc_create(dev, 1); | |
79 | ||
80 | for (i = 0; i < dcb->entries; i++) { | |
cb75d97e | 81 | struct dcb_output *dcbent = &dcb->entry[i]; |
6ee73861 | 82 | |
8f1a6086 BS |
83 | connector = nouveau_connector_create(dev, dcbent->connector); |
84 | if (IS_ERR(connector)) | |
85 | continue; | |
86 | ||
6ee73861 | 87 | switch (dcbent->type) { |
cb75d97e | 88 | case DCB_OUTPUT_ANALOG: |
8f1a6086 | 89 | ret = nv04_dac_create(connector, dcbent); |
6ee73861 | 90 | break; |
cb75d97e BS |
91 | case DCB_OUTPUT_LVDS: |
92 | case DCB_OUTPUT_TMDS: | |
8f1a6086 | 93 | ret = nv04_dfp_create(connector, dcbent); |
6ee73861 | 94 | break; |
cb75d97e | 95 | case DCB_OUTPUT_TV: |
6ee73861 | 96 | if (dcbent->location == DCB_LOC_ON_CHIP) |
8f1a6086 | 97 | ret = nv17_tv_create(connector, dcbent); |
6ee73861 | 98 | else |
8f1a6086 | 99 | ret = nv04_tv_create(connector, dcbent); |
6ee73861 BS |
100 | break; |
101 | default: | |
77145f1c | 102 | NV_WARN(drm, "DCB type %d not known\n", dcbent->type); |
6ee73861 BS |
103 | continue; |
104 | } | |
105 | ||
106 | if (ret) | |
107 | continue; | |
6ee73861 BS |
108 | } |
109 | ||
8f1a6086 BS |
110 | list_for_each_entry_safe(connector, ct, |
111 | &dev->mode_config.connector_list, head) { | |
112 | if (!connector->encoder_ids[0]) { | |
77145f1c | 113 | NV_WARN(drm, "%s has no encoders, removing\n", |
8f1a6086 BS |
114 | drm_get_connector_name(connector)); |
115 | connector->funcs->destroy(connector); | |
116 | } | |
117 | } | |
6ee73861 BS |
118 | |
119 | /* Save previous state */ | |
6ee73861 BS |
120 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
121 | crtc->funcs->save(crtc); | |
122 | ||
123 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
124 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
125 | ||
126 | func->save(encoder); | |
127 | } | |
128 | ||
129 | return 0; | |
130 | } | |
131 | ||
132 | void | |
133 | nv04_display_destroy(struct drm_device *dev) | |
134 | { | |
77145f1c | 135 | struct nouveau_drm *drm = nouveau_drm(dev); |
017e6e29 | 136 | struct nv04_display *disp = nv04_display(dev); |
6ee73861 BS |
137 | struct drm_encoder *encoder; |
138 | struct drm_crtc *crtc; | |
139 | ||
77145f1c | 140 | NV_DEBUG(drm, "\n"); |
e4cbadca | 141 | |
6ee73861 BS |
142 | /* Turn every CRTC off. */ |
143 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
144 | struct drm_mode_set modeset = { | |
145 | .crtc = crtc, | |
146 | }; | |
147 | ||
148 | crtc->funcs->set_config(&modeset); | |
149 | } | |
150 | ||
151 | /* Restore state */ | |
6ee73861 BS |
152 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
153 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
154 | ||
155 | func->restore(encoder); | |
156 | } | |
157 | ||
158 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) | |
159 | crtc->funcs->restore(crtc); | |
160 | ||
95f158ea | 161 | nouveau_hw_save_vga_fonts(dev, 0); |
017e6e29 | 162 | |
77145f1c | 163 | nouveau_display(dev)->priv = NULL; |
017e6e29 | 164 | kfree(disp); |
6ee73861 BS |
165 | } |
166 | ||
c88c2e06 FJ |
167 | int |
168 | nv04_display_init(struct drm_device *dev) | |
6ee73861 | 169 | { |
6ee73861 BS |
170 | struct drm_encoder *encoder; |
171 | struct drm_crtc *crtc; | |
172 | ||
6ee73861 BS |
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. | |
176 | * | |
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 | |
179 | * on suspend too. | |
180 | */ | |
181 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
182 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
183 | ||
184 | func->restore(encoder); | |
185 | } | |
186 | ||
187 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) | |
188 | crtc->funcs->restore(crtc); | |
c88c2e06 FJ |
189 | |
190 | return 0; | |
6ee73861 BS |
191 | } |
192 | ||
2a44e499 BS |
193 | void |
194 | nv04_display_fini(struct drm_device *dev) | |
195 | { | |
afada5e0 BS |
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); | |
2a44e499 | 200 | } |