2 * Copyright 2009 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <drm/drm_crtc_helper.h>
28 #include "nouveau_drv.h"
29 #include "nouveau_reg.h"
31 #include "nouveau_encoder.h"
32 #include "nouveau_connector.h"
35 nv04_display_fini(struct drm_device *dev)
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);
44 nv04_display_init(struct drm_device *dev)
46 struct nouveau_encoder *encoder;
47 struct nouveau_crtc *crtc;
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.
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
57 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
58 crtc->save(&crtc->base);
60 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.base.head)
61 encoder->enc_save(&encoder->base.base);
67 nv04_display_destroy(struct drm_device *dev)
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;
75 list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.base.head)
76 encoder->enc_restore(&encoder->base.base);
78 list_for_each_entry(nv_crtc, &dev->mode_config.crtc_list, base.head)
79 nv_crtc->restore(&nv_crtc->base);
81 nouveau_hw_save_vga_fonts(dev, 0);
83 nouveau_display(dev)->priv = NULL;
86 nvif_object_unmap(&drm->client.device.object);
90 nv04_display_create(struct drm_device *dev)
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;
102 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
106 nvif_object_map(&drm->client.device.object, NULL, 0);
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;
113 /* Pre-nv50 doesn't support atomic, so don't expose the ioctls */
114 dev->driver->driver_features &= ~DRIVER_ATOMIC;
116 nouveau_hw_save_vga_fonts(dev, 1);
118 nv04_crtc_create(dev, 0);
119 if (nv_two_heads(dev))
120 nv04_crtc_create(dev, 1);
122 for (i = 0; i < dcb->entries; i++) {
123 struct dcb_output *dcbent = &dcb->entry[i];
125 connector = nouveau_connector_create(dev, dcbent);
126 if (IS_ERR(connector))
129 switch (dcbent->type) {
130 case DCB_OUTPUT_ANALOG:
131 ret = nv04_dac_create(connector, dcbent);
133 case DCB_OUTPUT_LVDS:
134 case DCB_OUTPUT_TMDS:
135 ret = nv04_dfp_create(connector, dcbent);
138 if (dcbent->location == DCB_LOC_ON_CHIP)
139 ret = nv17_tv_create(connector, dcbent);
141 ret = nv04_tv_create(connector, dcbent);
144 NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
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",
157 connector->funcs->destroy(connector);
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;
168 /* Save previous state */
169 list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head)
170 crtc->save(&crtc->base);
172 list_for_each_entry(nv_encoder, &dev->mode_config.encoder_list, base.base.head)
173 nv_encoder->enc_save(&nv_encoder->base.base);
175 nouveau_overlay_init(dev);