OSDN Git Service

drm/nouveau/kms: display destroy/init/fini hooks can be static
[tomoyo/tomoyo-test1.git] / drivers / gpu / drm / nouveau / dispnv04 / disp.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_drv.h"
29 #include "nouveau_reg.h"
30 #include "hw.h"
31 #include "nouveau_encoder.h"
32 #include "nouveau_connector.h"
33
34 static void
35 nv04_display_fini(struct drm_device *dev)
36 {
37         /* Disable vblank interrupts. */
38         NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
39         if (nv_two_heads(dev))
40                 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
41 }
42
43 static int
44 nv04_display_init(struct drm_device *dev)
45 {
46         struct nouveau_encoder *encoder;
47         struct nouveau_crtc *crtc;
48
49         /* meh.. modeset apparently doesn't setup all the regs and depends
50          * on pre-existing state, for now load the state of the card *before*
51          * nouveau was loaded, and then do a modeset.
52          *
53          * best thing to do probably is to make save/restore routines not
54          * save/restore "pre-load" state, but more general so we can save
55          * on suspend too.
56          */
57         list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
58                 crtc->save(&crtc->base);
59
60         list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.base.head)
61                 encoder->enc_save(&encoder->base.base);
62
63         return 0;
64 }
65
66 static void
67 nv04_display_destroy(struct drm_device *dev)
68 {
69         struct nv04_display *disp = nv04_display(dev);
70         struct nouveau_drm *drm = nouveau_drm(dev);
71         struct nouveau_encoder *encoder;
72         struct nouveau_crtc *nv_crtc;
73
74         /* Restore state */
75         list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.base.head)
76                 encoder->enc_restore(&encoder->base.base);
77
78         list_for_each_entry(nv_crtc, &dev->mode_config.crtc_list, base.head)
79                 nv_crtc->restore(&nv_crtc->base);
80
81         nouveau_hw_save_vga_fonts(dev, 0);
82
83         nouveau_display(dev)->priv = NULL;
84         kfree(disp);
85
86         nvif_object_unmap(&drm->client.device.object);
87 }
88
89 int
90 nv04_display_create(struct drm_device *dev)
91 {
92         struct nouveau_drm *drm = nouveau_drm(dev);
93         struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
94         struct dcb_table *dcb = &drm->vbios.dcb;
95         struct drm_connector *connector, *ct;
96         struct drm_encoder *encoder;
97         struct nouveau_encoder *nv_encoder;
98         struct nouveau_crtc *crtc;
99         struct nv04_display *disp;
100         int i, ret;
101
102         disp = kzalloc(sizeof(*disp), GFP_KERNEL);
103         if (!disp)
104                 return -ENOMEM;
105
106         nvif_object_map(&drm->client.device.object, NULL, 0);
107
108         nouveau_display(dev)->priv = disp;
109         nouveau_display(dev)->dtor = nv04_display_destroy;
110         nouveau_display(dev)->init = nv04_display_init;
111         nouveau_display(dev)->fini = nv04_display_fini;
112
113         /* Pre-nv50 doesn't support atomic, so don't expose the ioctls */
114         dev->driver->driver_features &= ~DRIVER_ATOMIC;
115
116         nouveau_hw_save_vga_fonts(dev, 1);
117
118         nv04_crtc_create(dev, 0);
119         if (nv_two_heads(dev))
120                 nv04_crtc_create(dev, 1);
121
122         for (i = 0; i < dcb->entries; i++) {
123                 struct dcb_output *dcbent = &dcb->entry[i];
124
125                 connector = nouveau_connector_create(dev, dcbent);
126                 if (IS_ERR(connector))
127                         continue;
128
129                 switch (dcbent->type) {
130                 case DCB_OUTPUT_ANALOG:
131                         ret = nv04_dac_create(connector, dcbent);
132                         break;
133                 case DCB_OUTPUT_LVDS:
134                 case DCB_OUTPUT_TMDS:
135                         ret = nv04_dfp_create(connector, dcbent);
136                         break;
137                 case DCB_OUTPUT_TV:
138                         if (dcbent->location == DCB_LOC_ON_CHIP)
139                                 ret = nv17_tv_create(connector, dcbent);
140                         else
141                                 ret = nv04_tv_create(connector, dcbent);
142                         break;
143                 default:
144                         NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
145                         continue;
146                 }
147
148                 if (ret)
149                         continue;
150         }
151
152         list_for_each_entry_safe(connector, ct,
153                                  &dev->mode_config.connector_list, head) {
154                 if (!connector->encoder_ids[0]) {
155                         NV_WARN(drm, "%s has no encoders, removing\n",
156                                 connector->name);
157                         connector->funcs->destroy(connector);
158                 }
159         }
160
161         list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
162                 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
163                 struct nvkm_i2c_bus *bus =
164                         nvkm_i2c_bus_find(i2c, nv_encoder->dcb->i2c_index);
165                 nv_encoder->i2c = bus ? &bus->i2c : NULL;
166         }
167
168         /* Save previous state */
169         list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
170                 crtc->save(&crtc->base);
171
172         list_for_each_entry(nv_encoder, &dev->mode_config.encoder_list, base.base.head)
173                 nv_encoder->enc_save(&nv_encoder->base.base);
174
175         nouveau_overlay_init(dev);
176
177         return 0;
178 }