2 * Copyright (C) 2008 Maarten Maathuis.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "nv50_display.h"
28 #include "nv50_crtc.h"
29 #include "nv50_output.h"
30 #include "nv50_connector.h"
32 static int nv50_display_pre_init(struct nv50_display *display)
34 struct drm_device *dev = display->dev;
35 struct drm_nouveau_private *dev_priv = dev->dev_private;
41 NV_WRITE(0x00610184, NV_READ(0x00614004));
43 * I think the 0x006101XX range is some kind of main control area that enables things.
46 NV_WRITE(0x00610190 + 0 * 0x10, NV_READ(0x00616100 + 0 * 0x800));
47 NV_WRITE(0x00610190 + 1 * 0x10, NV_READ(0x00616100 + 1 * 0x800));
48 NV_WRITE(0x00610194 + 0 * 0x10, NV_READ(0x00616104 + 0 * 0x800));
49 NV_WRITE(0x00610194 + 1 * 0x10, NV_READ(0x00616104 + 1 * 0x800));
50 NV_WRITE(0x00610198 + 0 * 0x10, NV_READ(0x00616108 + 0 * 0x800));
51 NV_WRITE(0x00610198 + 1 * 0x10, NV_READ(0x00616108 + 1 * 0x800));
52 NV_WRITE(0x0061019c + 0 * 0x10, NV_READ(0x0061610c + 0 * 0x800));
53 NV_WRITE(0x0061019c + 1 * 0x10, NV_READ(0x0061610c + 1 * 0x800));
55 NV_WRITE(0x006101d0 + 0 * 0x4, NV_READ(0x0061a000 + 0 * 0x800));
56 NV_WRITE(0x006101d0 + 1 * 0x4, NV_READ(0x0061a000 + 1 * 0x800));
57 NV_WRITE(0x006101d0 + 2 * 0x4, NV_READ(0x0061a000 + 2 * 0x800));
59 NV_WRITE(0x006101e0 + 0 * 0x4, NV_READ(0x0061c000 + 0 * 0x800));
60 NV_WRITE(0x006101e0 + 1 * 0x4, NV_READ(0x0061c000 + 1 * 0x800));
61 /* Something not yet in use, tv-out maybe. */
62 NV_WRITE(0x006101f0 + 0 * 0x4, NV_READ(0x0061e000 + 0 * 0x800));
63 NV_WRITE(0x006101f0 + 1 * 0x4, NV_READ(0x0061e000 + 1 * 0x800));
64 NV_WRITE(0x006101f0 + 2 * 0x4, NV_READ(0x0061e000 + 2 * 0x800));
66 for (i = 0; i < 3; i++) {
67 NV_WRITE(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(i), 0x00550000 | NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING);
68 NV_WRITE(NV50_PDISPLAY_DAC_REGS_CLK_CTRL1(i), 0x00000001);
71 /* This used to be in crtc unblank, but seems out of place there. */
72 NV_WRITE(NV50_PDISPLAY_UNK_380, 0);
73 /* RAM is clamped to 256 MiB. */
74 ram_amount = nouveau_mem_fb_amount(display->dev);
75 NV50_DEBUG("ram_amount %d\n", ram_amount);
76 if (ram_amount > 256*1024*1024)
77 ram_amount = 256*1024*1024;
78 NV_WRITE(NV50_PDISPLAY_RAM_AMOUNT, ram_amount - 1);
79 NV_WRITE(NV50_PDISPLAY_UNK_388, 0x150000);
80 NV_WRITE(NV50_PDISPLAY_UNK_38C, 0);
82 display->preinit_done = true;
87 static int nv50_display_init(struct nv50_display *display)
89 struct drm_device *dev = display->dev;
90 struct drm_nouveau_private *dev_priv = dev->dev_private;
95 /* The precise purpose is unknown, i suspect it has something to do with text mode. */
96 if (NV_READ(NV50_PDISPLAY_SUPERVISOR) & 0x100) {
97 NV_WRITE(NV50_PDISPLAY_SUPERVISOR, 0x100);
98 NV_WRITE(0x006194e8, NV_READ(0x006194e8) & ~1);
99 while (NV_READ(0x006194e8) & 2);
102 /* taken from nv bug #12637 */
103 NV_WRITE(NV50_PDISPLAY_UNK200_CTRL, 0x2b00);
105 val = NV_READ(NV50_PDISPLAY_UNK200_CTRL);
106 if ((val & 0x9f0000) == 0x20000)
107 NV_WRITE(NV50_PDISPLAY_UNK200_CTRL, val | 0x800000);
109 if ((val & 0x3f0000) == 0x30000)
110 NV_WRITE(NV50_PDISPLAY_UNK200_CTRL, val | 0x200000);
111 } while (val & 0x1e0000);
113 NV_WRITE(NV50_PDISPLAY_CTRL_STATE, NV50_PDISPLAY_CTRL_STATE_ENABLE);
114 NV_WRITE(NV50_PDISPLAY_UNK200_CTRL, 0x1000b03);
115 while (!(NV_READ(NV50_PDISPLAY_UNK200_CTRL) & 0x40000000));
117 /* For the moment this is just a wrapper, which should be replaced with a real fifo at some point. */
118 OUT_MODE(NV50_UNK84, 0);
119 OUT_MODE(NV50_UNK88, 0);
120 OUT_MODE(NV50_CRTC0_BLANK_CTRL, NV50_CRTC0_BLANK_CTRL_BLANK);
121 OUT_MODE(NV50_CRTC0_UNK800, 0);
122 OUT_MODE(NV50_CRTC0_DISPLAY_START, 0);
123 OUT_MODE(NV50_CRTC0_UNK82C, 0);
125 /* enable clock change interrupts. */
126 NV_WRITE(NV50_PDISPLAY_SUPERVISOR_INTR, NV_READ(NV50_PDISPLAY_SUPERVISOR_INTR) | 0x70);
128 /* enable hotplug interrupts */
129 NV_WRITE(NV50_PCONNECTOR_HOTPLUG_INTR, 0x7FFF7FFF);
131 display->init_done = true;
136 static int nv50_display_disable(struct nv50_display *display)
138 struct drm_device *dev = display->dev;
139 struct drm_nouveau_private *dev_priv = dev->dev_private;
140 struct nv50_crtc *crtc = NULL;
145 list_for_each_entry(crtc, &display->crtcs, item) {
146 crtc->blank(crtc, true);
149 display->update(display);
151 /* Almost like ack'ing a vblank interrupt, maybe in the spirit of cleaning up? */
152 list_for_each_entry(crtc, &display->crtcs, item) {
156 if (crtc->index == 1)
157 mask = NV50_PDISPLAY_SUPERVISOR_CRTC1;
159 mask = NV50_PDISPLAY_SUPERVISOR_CRTC0;
161 NV_WRITE(NV50_PDISPLAY_SUPERVISOR, mask);
162 while (!(NV_READ(NV50_PDISPLAY_SUPERVISOR) & mask));
166 NV_WRITE(NV50_PDISPLAY_UNK200_CTRL, 0);
167 NV_WRITE(NV50_PDISPLAY_CTRL_STATE, 0);
168 while ((NV_READ(NV50_PDISPLAY_UNK200_CTRL) & 0x1e0000) != 0);
170 for (i = 0; i < 2; i++) {
171 while (NV_READ(NV50_PDISPLAY_SOR_REGS_DPMS_STATE(i)) & NV50_PDISPLAY_SOR_REGS_DPMS_STATE_WAIT);
174 /* disable clock change interrupts. */
175 NV_WRITE(NV50_PDISPLAY_SUPERVISOR_INTR, NV_READ(NV50_PDISPLAY_SUPERVISOR_INTR) & ~0x70);
177 /* disable hotplug interrupts */
178 NV_WRITE(NV50_PCONNECTOR_HOTPLUG_INTR, 0);
180 display->init_done = false;
185 static int nv50_display_update(struct nv50_display *display)
187 struct drm_device *dev = display->dev;
188 struct drm_nouveau_private *dev_priv = dev->dev_private;
192 OUT_MODE(NV50_UPDATE_DISPLAY, 0);
197 int nv50_display_create(struct drm_device *dev)
199 struct drm_nouveau_private *dev_priv = dev->dev_private;
200 struct nv50_display *display = kzalloc(sizeof(struct nv50_display), GFP_KERNEL);
201 int i, type, output_index, bus;
202 /* DAC0, DAC1, DAC2, SOR0, SOR1*/
203 int or_counter[5] = {0, 0, 0, 0, 0};
204 int i2c_index[5] = {0, 0, 0, 0, 0};
205 uint32_t bus_mask = 0;
206 uint32_t bus_digital = 0, bus_analog = 0;
213 INIT_LIST_HEAD(&display->crtcs);
214 INIT_LIST_HEAD(&display->outputs);
215 INIT_LIST_HEAD(&display->connectors);
217 dev_priv->display_priv = display;
219 for (i = 0; i < 2; i++) {
220 nv50_crtc_create(dev, i);
223 /* we setup the outputs up from the BIOS table */
224 for (i = 0 ; i < dev_priv->dcb_table.entries; i++) {
225 type = dev_priv->dcb_table.entry[i].type;
226 output_index = ffs(dev_priv->dcb_table.entry[i].or) - 1;
227 bus = dev_priv->dcb_table.entry[i].bus;
230 case DCB_OUTPUT_TMDS:
231 case DCB_OUTPUT_LVDS:
232 or_counter[output_index + 3] += 1;
233 i2c_index[output_index + 3] = dev_priv->dcb_table.entry[i].i2c_index;
234 bus_digital |= (1 << bus);
235 nv50_sor_create(dev, i);
237 case DCB_OUTPUT_ANALOG:
238 or_counter[output_index] += 1;
239 i2c_index[output_index] = dev_priv->dcb_table.entry[i].i2c_index;
240 bus_analog |= (1 << bus);
241 nv50_dac_create(dev, i);
249 /* setup the connectors based on the output tables. */
250 for (i = 0 ; i < dev_priv->dcb_table.entries; i++) {
251 int connector_type = 0;
252 type = dev_priv->dcb_table.entry[i].type;
253 bus = dev_priv->dcb_table.entry[i].bus;
256 if (bus_mask & (1 << bus))
259 /* only do it for supported outputs */
260 if (type != DCB_OUTPUT_ANALOG && type != DCB_OUTPUT_TMDS
261 && type != DCB_OUTPUT_LVDS)
265 case DCB_OUTPUT_TMDS:
266 case DCB_OUTPUT_ANALOG:
267 if ((bus_digital & (1 << bus)) && (bus_analog & (1 << bus)))
268 connector_type = CONNECTOR_DVI_I;
269 else if (bus_digital & (1 << bus))
270 connector_type = CONNECTOR_DVI_D;
271 else if (bus_analog & (1 << bus))
272 connector_type = CONNECTOR_VGA;
274 case DCB_OUTPUT_LVDS:
275 connector_type = CONNECTOR_LVDS;
278 connector_type = CONNECTOR_UNKNOWN;
282 if (connector_type == CONNECTOR_UNKNOWN)
285 nv50_connector_create(dev, bus, dev_priv->dcb_table.entry[i].i2c_index, connector_type);
287 bus_mask |= (1 << bus);
292 /* function pointers */
293 display->init = nv50_display_init;
294 display->pre_init = nv50_display_pre_init;
295 display->disable = nv50_display_disable;
296 display->update = nv50_display_update;
301 int nv50_display_destroy(struct drm_device *dev)
303 struct drm_nouveau_private *dev_priv = dev->dev_private;
304 struct nv50_display *display = nv50_get_display(dev);
305 struct nv50_crtc *crtc = NULL;
306 struct nv50_output *output = NULL;
307 struct nv50_connector *connector = NULL;
311 if (display->init_done)
312 display->disable(display);
314 list_for_each_entry(connector, &display->connectors, item) {
315 connector->destroy(connector);
318 list_for_each_entry(output, &display->outputs, item) {
319 output->destroy(output);
322 list_for_each_entry(crtc, &display->crtcs, item) {
327 dev_priv->display_priv = NULL;
332 /* This can be replaced with a real fifo in the future. */
333 void nv50_display_command(struct drm_nouveau_private *dev_priv, uint32_t mthd, uint32_t val)
335 uint32_t counter = 0;
338 DRM_INFO("mthd 0x%03X val 0x%08X\n", mthd, val);
341 NV_WRITE(NV50_PDISPLAY_CTRL_VAL, val);
342 NV_WRITE(NV50_PDISPLAY_CTRL_STATE, NV50_PDISPLAY_CTRL_STATE_PENDING | 0x10000 | mthd | NV50_PDISPLAY_CTRL_STATE_ENABLE);
344 while (NV_READ(NV50_PDISPLAY_CTRL_STATE) & NV50_PDISPLAY_CTRL_STATE_PENDING) {
346 if (counter > 1000000) {
347 DRM_ERROR("You probably need a reboot now\n");
354 struct nv50_display *nv50_get_display(struct drm_device *dev)
356 struct drm_nouveau_private *dev_priv = dev->dev_private;
358 return (struct nv50_display *) dev_priv->display_priv;