]> Pileus Git - ~andy/linux/blob - drivers/gpu/drm/nouveau/nv04_display.c
drm/nouveau: implement devinit subdev, and new init table parser
[~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_drv.h"
30 #include "nouveau_fb.h"
31 #include "nouveau_hw.h"
32 #include "nouveau_encoder.h"
33 #include "nouveau_connector.h"
34
35 static void nv04_vblank_crtc0_isr(struct drm_device *);
36 static void nv04_vblank_crtc1_isr(struct drm_device *);
37
38 int
39 nv04_display_early_init(struct drm_device *dev)
40 {
41         /* ensure vblank interrupts are off, they can't be enabled until
42          * drm_vblank has been initialised
43          */
44         NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
45         if (nv_two_heads(dev))
46                 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
47
48         return 0;
49 }
50
51 void
52 nv04_display_late_takedown(struct drm_device *dev)
53 {
54 }
55
56 int
57 nv04_display_create(struct drm_device *dev)
58 {
59         struct drm_nouveau_private *dev_priv = dev->dev_private;
60         struct dcb_table *dcb = &dev_priv->vbios.dcb;
61         struct drm_connector *connector, *ct;
62         struct drm_encoder *encoder;
63         struct drm_crtc *crtc;
64         int i, ret;
65
66         NV_DEBUG_KMS(dev, "\n");
67
68         nouveau_hw_save_vga_fonts(dev, 1);
69
70         nv04_crtc_create(dev, 0);
71         if (nv_two_heads(dev))
72                 nv04_crtc_create(dev, 1);
73
74         for (i = 0; i < dcb->entries; i++) {
75                 struct dcb_output *dcbent = &dcb->entry[i];
76
77                 connector = nouveau_connector_create(dev, dcbent->connector);
78                 if (IS_ERR(connector))
79                         continue;
80
81                 switch (dcbent->type) {
82                 case DCB_OUTPUT_ANALOG:
83                         ret = nv04_dac_create(connector, dcbent);
84                         break;
85                 case DCB_OUTPUT_LVDS:
86                 case DCB_OUTPUT_TMDS:
87                         ret = nv04_dfp_create(connector, dcbent);
88                         break;
89                 case DCB_OUTPUT_TV:
90                         if (dcbent->location == DCB_LOC_ON_CHIP)
91                                 ret = nv17_tv_create(connector, dcbent);
92                         else
93                                 ret = nv04_tv_create(connector, dcbent);
94                         break;
95                 default:
96                         NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
97                         continue;
98                 }
99
100                 if (ret)
101                         continue;
102         }
103
104         list_for_each_entry_safe(connector, ct,
105                                  &dev->mode_config.connector_list, head) {
106                 if (!connector->encoder_ids[0]) {
107                         NV_WARN(dev, "%s has no encoders, removing\n",
108                                 drm_get_connector_name(connector));
109                         connector->funcs->destroy(connector);
110                 }
111         }
112
113         /* Save previous state */
114         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
115                 crtc->funcs->save(crtc);
116
117         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
118                 struct drm_encoder_helper_funcs *func = encoder->helper_private;
119
120                 func->save(encoder);
121         }
122
123         nouveau_irq_register(dev, 24, nv04_vblank_crtc0_isr);
124         nouveau_irq_register(dev, 25, nv04_vblank_crtc1_isr);
125         return 0;
126 }
127
128 void
129 nv04_display_destroy(struct drm_device *dev)
130 {
131         struct drm_encoder *encoder;
132         struct drm_crtc *crtc;
133
134         NV_DEBUG_KMS(dev, "\n");
135
136         nouveau_irq_unregister(dev, 24);
137         nouveau_irq_unregister(dev, 25);
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
161 int
162 nv04_display_init(struct drm_device *dev)
163 {
164         struct drm_encoder *encoder;
165         struct drm_crtc *crtc;
166
167         /* meh.. modeset apparently doesn't setup all the regs and depends
168          * on pre-existing state, for now load the state of the card *before*
169          * nouveau was loaded, and then do a modeset.
170          *
171          * best thing to do probably is to make save/restore routines not
172          * save/restore "pre-load" state, but more general so we can save
173          * on suspend too.
174          */
175         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
176                 struct drm_encoder_helper_funcs *func = encoder->helper_private;
177
178                 func->restore(encoder);
179         }
180
181         list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
182                 crtc->funcs->restore(crtc);
183
184         return 0;
185 }
186
187 void
188 nv04_display_fini(struct drm_device *dev)
189 {
190         /* disable vblank interrupts */
191         NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
192         if (nv_two_heads(dev))
193                 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
194 }
195
196 static void
197 nv04_vblank_crtc0_isr(struct drm_device *dev)
198 {
199         nv_wr32(dev, NV_CRTC0_INTSTAT, NV_CRTC_INTR_VBLANK);
200         drm_handle_vblank(dev, 0);
201 }
202
203 static void
204 nv04_vblank_crtc1_isr(struct drm_device *dev)
205 {
206         nv_wr32(dev, NV_CRTC1_INTSTAT, NV_CRTC_INTR_VBLANK);
207         drm_handle_vblank(dev, 1);
208 }