]> Pileus Git - ~andy/linux/blob - drivers/gpu/drm/nouveau/nv04_display.c
Merge tag 'tags/disintegrate-tile-20121009' into for-linus
[~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 <drm/drmP.h>
26 #include <drm/drm_crtc_helper.h>
27
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"
33
34 int
35 nv04_display_early_init(struct drm_device *dev)
36 {
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
44         return 0;
45 }
46
47 void
48 nv04_display_late_takedown(struct drm_device *dev)
49 {
50 }
51
52 int
53 nv04_display_create(struct drm_device *dev)
54 {
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;
61         int i, ret;
62
63         NV_DEBUG(drm, "\n");
64
65         disp = kzalloc(sizeof(*disp), GFP_KERNEL);
66         if (!disp)
67                 return -ENOMEM;
68
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;
73
74         nouveau_hw_save_vga_fonts(dev, 1);
75
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++) {
81                 struct dcb_output *dcbent = &dcb->entry[i];
82
83                 connector = nouveau_connector_create(dev, dcbent->connector);
84                 if (IS_ERR(connector))
85                         continue;
86
87                 switch (dcbent->type) {
88                 case DCB_OUTPUT_ANALOG:
89                         ret = nv04_dac_create(connector, dcbent);
90                         break;
91                 case DCB_OUTPUT_LVDS:
92                 case DCB_OUTPUT_TMDS:
93                         ret = nv04_dfp_create(connector, dcbent);
94                         break;
95                 case DCB_OUTPUT_TV:
96                         if (dcbent->location == DCB_LOC_ON_CHIP)
97                                 ret = nv17_tv_create(connector, dcbent);
98                         else
99                                 ret = nv04_tv_create(connector, dcbent);
100                         break;
101                 default:
102                         NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
103                         continue;
104                 }
105
106                 if (ret)
107                         continue;
108         }
109
110         list_for_each_entry_safe(connector, ct,
111                                  &dev->mode_config.connector_list, head) {
112                 if (!connector->encoder_ids[0]) {
113                         NV_WARN(drm, "%s has no encoders, removing\n",
114                                 drm_get_connector_name(connector));
115                         connector->funcs->destroy(connector);
116                 }
117         }
118
119         /* Save previous state */
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 {
135         struct nouveau_drm *drm = nouveau_drm(dev);
136         struct nv04_display *disp = nv04_display(dev);
137         struct drm_encoder *encoder;
138         struct drm_crtc *crtc;
139
140         NV_DEBUG(drm, "\n");
141
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 */
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
161         nouveau_hw_save_vga_fonts(dev, 0);
162
163         nouveau_display(dev)->priv = NULL;
164         kfree(disp);
165 }
166
167 int
168 nv04_display_init(struct drm_device *dev)
169 {
170         struct drm_encoder *encoder;
171         struct drm_crtc *crtc;
172
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);
189
190         return 0;
191 }
192
193 void
194 nv04_display_fini(struct drm_device *dev)
195 {
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);
200 }