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 | ||
21a5ace0 BS |
25 | #include <core/object.h> |
26 | #include <core/class.h> | |
27 | ||
760285e7 DH |
28 | #include <drm/drmP.h> |
29 | #include <drm/drm_crtc_helper.h> | |
6ee73861 | 30 | |
77145f1c BS |
31 | #include "nouveau_drm.h" |
32 | #include "nouveau_reg.h" | |
1a646342 | 33 | #include "hw.h" |
6ee73861 BS |
34 | #include "nouveau_encoder.h" |
35 | #include "nouveau_connector.h" | |
36 | ||
5ed50209 BS |
37 | #include <subdev/i2c.h> |
38 | ||
c88c2e06 FJ |
39 | int |
40 | nv04_display_early_init(struct drm_device *dev) | |
41 | { | |
afada5e0 BS |
42 | /* ensure vblank interrupts are off, they can't be enabled until |
43 | * drm_vblank has been initialised | |
44 | */ | |
45 | NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0); | |
46 | if (nv_two_heads(dev)) | |
47 | NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0); | |
48 | ||
c88c2e06 FJ |
49 | return 0; |
50 | } | |
51 | ||
52 | void | |
53 | nv04_display_late_takedown(struct drm_device *dev) | |
54 | { | |
c88c2e06 FJ |
55 | } |
56 | ||
6ee73861 BS |
57 | int |
58 | nv04_display_create(struct drm_device *dev) | |
59 | { | |
77145f1c | 60 | struct nouveau_drm *drm = nouveau_drm(dev); |
5ed50209 | 61 | struct nouveau_i2c *i2c = nouveau_i2c(drm->device); |
77145f1c | 62 | struct dcb_table *dcb = &drm->vbios.dcb; |
8f1a6086 | 63 | struct drm_connector *connector, *ct; |
6ee73861 BS |
64 | struct drm_encoder *encoder; |
65 | struct drm_crtc *crtc; | |
017e6e29 | 66 | struct nv04_display *disp; |
6ee73861 BS |
67 | int i, ret; |
68 | ||
017e6e29 | 69 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
017e6e29 BS |
70 | if (!disp) |
71 | return -ENOMEM; | |
72 | ||
77145f1c BS |
73 | nouveau_display(dev)->priv = disp; |
74 | nouveau_display(dev)->dtor = nv04_display_destroy; | |
75 | nouveau_display(dev)->init = nv04_display_init; | |
76 | nouveau_display(dev)->fini = nv04_display_fini; | |
6ee73861 | 77 | |
95f158ea | 78 | nouveau_hw_save_vga_fonts(dev, 1); |
6ee73861 | 79 | |
21a5ace0 BS |
80 | ret = nouveau_object_new(nv_object(drm), NVDRM_DEVICE, 0xd1500000, |
81 | NV04_DISP_CLASS, NULL, 0, &disp->core); | |
82 | if (ret) | |
83 | return ret; | |
84 | ||
6ee73861 BS |
85 | nv04_crtc_create(dev, 0); |
86 | if (nv_two_heads(dev)) | |
87 | nv04_crtc_create(dev, 1); | |
88 | ||
89 | for (i = 0; i < dcb->entries; i++) { | |
cb75d97e | 90 | struct dcb_output *dcbent = &dcb->entry[i]; |
6ee73861 | 91 | |
8f1a6086 BS |
92 | connector = nouveau_connector_create(dev, dcbent->connector); |
93 | if (IS_ERR(connector)) | |
94 | continue; | |
95 | ||
6ee73861 | 96 | switch (dcbent->type) { |
cb75d97e | 97 | case DCB_OUTPUT_ANALOG: |
8f1a6086 | 98 | ret = nv04_dac_create(connector, dcbent); |
6ee73861 | 99 | break; |
cb75d97e BS |
100 | case DCB_OUTPUT_LVDS: |
101 | case DCB_OUTPUT_TMDS: | |
8f1a6086 | 102 | ret = nv04_dfp_create(connector, dcbent); |
6ee73861 | 103 | break; |
cb75d97e | 104 | case DCB_OUTPUT_TV: |
6ee73861 | 105 | if (dcbent->location == DCB_LOC_ON_CHIP) |
8f1a6086 | 106 | ret = nv17_tv_create(connector, dcbent); |
6ee73861 | 107 | else |
8f1a6086 | 108 | ret = nv04_tv_create(connector, dcbent); |
6ee73861 BS |
109 | break; |
110 | default: | |
77145f1c | 111 | NV_WARN(drm, "DCB type %d not known\n", dcbent->type); |
6ee73861 BS |
112 | continue; |
113 | } | |
114 | ||
115 | if (ret) | |
116 | continue; | |
6ee73861 BS |
117 | } |
118 | ||
8f1a6086 BS |
119 | list_for_each_entry_safe(connector, ct, |
120 | &dev->mode_config.connector_list, head) { | |
121 | if (!connector->encoder_ids[0]) { | |
77145f1c | 122 | NV_WARN(drm, "%s has no encoders, removing\n", |
8f1a6086 BS |
123 | drm_get_connector_name(connector)); |
124 | connector->funcs->destroy(connector); | |
125 | } | |
126 | } | |
6ee73861 | 127 | |
5ed50209 BS |
128 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
129 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); | |
130 | nv_encoder->i2c = i2c->find(i2c, nv_encoder->dcb->i2c_index); | |
131 | } | |
132 | ||
6ee73861 | 133 | /* Save previous state */ |
6ee73861 BS |
134 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
135 | crtc->funcs->save(crtc); | |
136 | ||
137 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
138 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
139 | ||
140 | func->save(encoder); | |
141 | } | |
142 | ||
143 | return 0; | |
144 | } | |
145 | ||
146 | void | |
147 | nv04_display_destroy(struct drm_device *dev) | |
148 | { | |
017e6e29 | 149 | struct nv04_display *disp = nv04_display(dev); |
6ee73861 BS |
150 | struct drm_encoder *encoder; |
151 | struct drm_crtc *crtc; | |
152 | ||
6ee73861 BS |
153 | /* Turn every CRTC off. */ |
154 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { | |
155 | struct drm_mode_set modeset = { | |
156 | .crtc = crtc, | |
157 | }; | |
158 | ||
2d13b679 | 159 | drm_mode_set_config_internal(&modeset); |
6ee73861 BS |
160 | } |
161 | ||
162 | /* Restore state */ | |
6ee73861 BS |
163 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
164 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
165 | ||
166 | func->restore(encoder); | |
167 | } | |
168 | ||
169 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) | |
170 | crtc->funcs->restore(crtc); | |
171 | ||
95f158ea | 172 | nouveau_hw_save_vga_fonts(dev, 0); |
017e6e29 | 173 | |
77145f1c | 174 | nouveau_display(dev)->priv = NULL; |
017e6e29 | 175 | kfree(disp); |
6ee73861 BS |
176 | } |
177 | ||
c88c2e06 FJ |
178 | int |
179 | nv04_display_init(struct drm_device *dev) | |
6ee73861 | 180 | { |
6ee73861 BS |
181 | struct drm_encoder *encoder; |
182 | struct drm_crtc *crtc; | |
183 | ||
6ee73861 BS |
184 | /* meh.. modeset apparently doesn't setup all the regs and depends |
185 | * on pre-existing state, for now load the state of the card *before* | |
186 | * nouveau was loaded, and then do a modeset. | |
187 | * | |
188 | * best thing to do probably is to make save/restore routines not | |
189 | * save/restore "pre-load" state, but more general so we can save | |
190 | * on suspend too. | |
191 | */ | |
192 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { | |
193 | struct drm_encoder_helper_funcs *func = encoder->helper_private; | |
194 | ||
195 | func->restore(encoder); | |
196 | } | |
197 | ||
198 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) | |
199 | crtc->funcs->restore(crtc); | |
c88c2e06 FJ |
200 | |
201 | return 0; | |
6ee73861 BS |
202 | } |
203 | ||
2a44e499 BS |
204 | void |
205 | nv04_display_fini(struct drm_device *dev) | |
206 | { | |
afada5e0 BS |
207 | /* disable vblank interrupts */ |
208 | NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0); | |
209 | if (nv_two_heads(dev)) | |
210 | NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0); | |
2a44e499 | 211 | } |