1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <core/object.h>
26#include <core/class.h>
27
28#include <drm/drmP.h>
29#include <drm/drm_crtc_helper.h>
30
31#include "nouveau_drm.h"
32#include "nouveau_reg.h"
33#include "hw.h"
34#include "nouveau_encoder.h"
35#include "nouveau_connector.h"
36
37#include <subdev/i2c.h>
38
39int
40nv04_display_early_init(struct drm_device *dev)
41{
42
43
44
45 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
46 if (nv_two_heads(dev))
47 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
48
49 return 0;
50}
51
52void
53nv04_display_late_takedown(struct drm_device *dev)
54{
55}
56
57int
58nv04_display_create(struct drm_device *dev)
59{
60 struct nouveau_drm *drm = nouveau_drm(dev);
61 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
62 struct dcb_table *dcb = &drm->vbios.dcb;
63 struct drm_connector *connector, *ct;
64 struct drm_encoder *encoder;
65 struct drm_crtc *crtc;
66 struct nv04_display *disp;
67 int i, ret;
68
69 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
70 if (!disp)
71 return -ENOMEM;
72
73 nouveau_display(dev)->priv = disp;
74 nouveau_display(dev)->dtor = nv04_display_destroy;
75 nouveau_display(dev)->init = nv04_display_init;
76 nouveau_display(dev)->fini = nv04_display_fini;
77
78 nouveau_hw_save_vga_fonts(dev, 1);
79
80 ret = nouveau_object_new(nv_object(drm), NVDRM_DEVICE, 0xd1500000,
81 NV04_DISP_CLASS, NULL, 0, &disp->core);
82 if (ret)
83 return ret;
84
85 nv04_crtc_create(dev, 0);
86 if (nv_two_heads(dev))
87 nv04_crtc_create(dev, 1);
88
89 for (i = 0; i < dcb->entries; i++) {
90 struct dcb_output *dcbent = &dcb->entry[i];
91
92 connector = nouveau_connector_create(dev, dcbent->connector);
93 if (IS_ERR(connector))
94 continue;
95
96 switch (dcbent->type) {
97 case DCB_OUTPUT_ANALOG:
98 ret = nv04_dac_create(connector, dcbent);
99 break;
100 case DCB_OUTPUT_LVDS:
101 case DCB_OUTPUT_TMDS:
102 ret = nv04_dfp_create(connector, dcbent);
103 break;
104 case DCB_OUTPUT_TV:
105 if (dcbent->location == DCB_LOC_ON_CHIP)
106 ret = nv17_tv_create(connector, dcbent);
107 else
108 ret = nv04_tv_create(connector, dcbent);
109 break;
110 default:
111 NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
112 continue;
113 }
114
115 if (ret)
116 continue;
117 }
118
119 list_for_each_entry_safe(connector, ct,
120 &dev->mode_config.connector_list, head) {
121 if (!connector->encoder_ids[0]) {
122 NV_WARN(drm, "%s has no encoders, removing\n",
123 drm_get_connector_name(connector));
124 connector->funcs->destroy(connector);
125 }
126 }
127
128 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
129 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
130 nv_encoder->i2c = i2c->find(i2c, nv_encoder->dcb->i2c_index);
131 }
132
133
134 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
135 crtc->funcs->save(crtc);
136
137 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
138 struct drm_encoder_helper_funcs *func = encoder->helper_private;
139
140 func->save(encoder);
141 }
142
143 return 0;
144}
145
146void
147nv04_display_destroy(struct drm_device *dev)
148{
149 struct nv04_display *disp = nv04_display(dev);
150 struct drm_encoder *encoder;
151 struct drm_crtc *crtc;
152
153
154 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
155 struct drm_mode_set modeset = {
156 .crtc = crtc,
157 };
158
159 drm_mode_set_config_internal(&modeset);
160 }
161
162
163 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
164 struct drm_encoder_helper_funcs *func = encoder->helper_private;
165
166 func->restore(encoder);
167 }
168
169 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
170 crtc->funcs->restore(crtc);
171
172 nouveau_hw_save_vga_fonts(dev, 0);
173
174 nouveau_display(dev)->priv = NULL;
175 kfree(disp);
176}
177
178int
179nv04_display_init(struct drm_device *dev)
180{
181 struct drm_encoder *encoder;
182 struct drm_crtc *crtc;
183
184
185
186
187
188
189
190
191
192 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
193 struct drm_encoder_helper_funcs *func = encoder->helper_private;
194
195 func->restore(encoder);
196 }
197
198 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
199 crtc->funcs->restore(crtc);
200
201 return 0;
202}
203
204void
205nv04_display_fini(struct drm_device *dev)
206{
207
208 NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
209 if (nv_two_heads(dev))
210 NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
211}
212