]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/nv04_display.c
6ab936376c40e5e3c5ef721050ef62a9f72cd16e
[karo-tx-linux.git] / 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_drv.h"
30 #include "nouveau_fb.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 drm_nouveau_private *dev_priv = dev->dev_private;
57         struct dcb_table *dcb = &dev_priv->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_KMS(dev, "\n");
65
66         disp = kzalloc(sizeof(*disp), GFP_KERNEL);
67         dev_priv->engine.display.priv = disp;
68         if (!disp)
69                 return -ENOMEM;
70
71         nouveau_hw_save_vga_fonts(dev, 1);
72
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++) {
78                 struct dcb_output *dcbent = &dcb->entry[i];
79
80                 connector = nouveau_connector_create(dev, dcbent->connector);
81                 if (IS_ERR(connector))
82                         continue;
83
84                 switch (dcbent->type) {
85                 case DCB_OUTPUT_ANALOG:
86                         ret = nv04_dac_create(connector, dcbent);
87                         break;
88                 case DCB_OUTPUT_LVDS:
89                 case DCB_OUTPUT_TMDS:
90                         ret = nv04_dfp_create(connector, dcbent);
91                         break;
92                 case DCB_OUTPUT_TV:
93                         if (dcbent->location == DCB_LOC_ON_CHIP)
94                                 ret = nv17_tv_create(connector, dcbent);
95                         else
96                                 ret = nv04_tv_create(connector, dcbent);
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;
105         }
106
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         }
115
116         /* Save previous state */
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 {
132         struct drm_nouveau_private *dev_priv = dev->dev_private;
133         struct nv04_display *disp = nv04_display(dev);
134         struct drm_encoder *encoder;
135         struct drm_crtc *crtc;
136
137         NV_DEBUG_KMS(dev, "\n");
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 */
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
158         nouveau_hw_save_vga_fonts(dev, 0);
159
160         dev_priv->engine.display.priv = NULL;
161         kfree(disp);
162 }
163
164 int
165 nv04_display_init(struct drm_device *dev)
166 {
167         struct drm_encoder *encoder;
168         struct drm_crtc *crtc;
169
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);
186
187         return 0;
188 }
189
190 void
191 nv04_display_fini(struct drm_device *dev)
192 {
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);
197 }