]> Pileus Git - ~andy/linux/blob - drivers/gpu/drm/nouveau/nv04_display.c
Merge branch 'drm-nouveau-next' of git://anongit.freedesktop.org/git/nouveau/linux...
[~andy/linux] / drivers / gpu / drm / nouveau / nv04_display.c
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_drm.h"
30 #include "nouveau_reg.h"
31 #include "nouveau_hw.h"
32 #include "nouveau_encoder.h"
33 #include "nouveau_connector.h"
34
35 int
36 nv04_display_early_init(struct drm_device *dev)
37 {
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
45         return 0;
46 }
47
48 void
49 nv04_display_late_takedown(struct drm_device *dev)
50 {
51 }
52
53 int
54 nv04_display_create(struct drm_device *dev)
55 {
56         struct nouveau_drm *drm = nouveau_drm(dev);
57         struct dcb_table *dcb = &drm->vbios.dcb;
58         struct drm_connector *connector, *ct;
59         struct drm_encoder *encoder;
60         struct drm_crtc *crtc;
61         struct nv04_display *disp;
62         int i, ret;
63
64         NV_DEBUG(drm, "\n");
65
66         disp = kzalloc(sizeof(*disp), GFP_KERNEL);
67         if (!disp)
68                 return -ENOMEM;
69
70         nouveau_display(dev)->priv = disp;
71         nouveau_display(dev)->dtor = nv04_display_destroy;
72         nouveau_display(dev)->init = nv04_display_init;
73         nouveau_display(dev)->fini = nv04_display_fini;
74
75         nouveau_hw_save_vga_fonts(dev, 1);
76
77         nv04_crtc_create(dev, 0);
78         if (nv_two_heads(dev))
79                 nv04_crtc_create(dev, 1);
80
81         for (i = 0; i < dcb->entries; i++) {
82                 struct dcb_output *dcbent = &dcb->entry[i];
83
84                 connector = nouveau_connector_create(dev, dcbent->connector);
85                 if (IS_ERR(connector))
86                         continue;
87
88                 switch (dcbent->type) {
89                 case DCB_OUTPUT_ANALOG:
90                         ret = nv04_dac_create(connector, dcbent);
91                         break;
92                 case DCB_OUTPUT_LVDS:
93                 case DCB_OUTPUT_TMDS:
94                         ret = nv04_dfp_create(connector, dcbent);
95                         break;
96                 case DCB_OUTPUT_TV:
97                         if (dcbent->location == DCB_LOC_ON_CHIP)
98                                 ret = nv17_tv_create(connector, dcbent);
99                         else
100                                 ret = nv04_tv_create(connector, dcbent);
101                         break;
102                 default:
103                         NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
104                         continue;
105                 }
106
107                 if (ret)
108                         continue;
109         }
110
111         list_for_each_entry_safe(connector, ct,
112                                  &dev->mode_config.connector_list, head) {
113                 if (!connector->encoder_ids[0]) {
114                         NV_WARN(drm, "%s has no encoders, removing\n",
115                                 drm_get_connector_name(connector));
116                         connector->funcs->destroy(connector);
117                 }
118         }
119
120         /* Save previous state */
121         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
122                 crtc->funcs->save(crtc);
123
124         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
125                 struct drm_encoder_helper_funcs *func = encoder->helper_private;
126
127                 func->save(encoder);
128         }
129
130         return 0;
131 }
132
133 void
134 nv04_display_destroy(struct drm_device *dev)
135 {
136         struct nouveau_drm *drm = nouveau_drm(dev);
137         struct nv04_display *disp = nv04_display(dev);
138         struct drm_encoder *encoder;
139         struct drm_crtc *crtc;
140
141         NV_DEBUG(drm, "\n");
142
143         /* Turn every CRTC off. */
144         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
145                 struct drm_mode_set modeset = {
146                         .crtc = crtc,
147                 };
148
149                 crtc->funcs->set_config(&modeset);
150         }
151
152         /* Restore state */
153         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
154                 struct drm_encoder_helper_funcs *func = encoder->helper_private;
155
156                 func->restore(encoder);
157         }
158
159         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
160                 crtc->funcs->restore(crtc);
161
162         nouveau_hw_save_vga_fonts(dev, 0);
163
164         nouveau_display(dev)->priv = NULL;
165         kfree(disp);
166 }
167
168 int
169 nv04_display_init(struct drm_device *dev)
170 {
171         struct drm_encoder *encoder;
172         struct drm_crtc *crtc;
173
174         /* meh.. modeset apparently doesn't setup all the regs and depends
175          * on pre-existing state, for now load the state of the card *before*
176          * nouveau was loaded, and then do a modeset.
177          *
178          * best thing to do probably is to make save/restore routines not
179          * save/restore "pre-load" state, but more general so we can save
180          * on suspend too.
181          */
182         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
183                 struct drm_encoder_helper_funcs *func = encoder->helper_private;
184
185                 func->restore(encoder);
186         }
187
188         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
189                 crtc->funcs->restore(crtc);
190
191         return 0;
192 }
193
194 void
195 nv04_display_fini(struct drm_device *dev)
196 {
197         /* disable vblank interrupts */
198         NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
199         if (nv_two_heads(dev))
200                 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
201 }