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_output.h"
29 static int nv50_dac_validate_mode(struct nv50_output *output, struct nouveau_hw_mode *mode)
33 if (mode->clock > 400000)
34 return MODE_CLOCK_HIGH;
36 if (mode->clock < 25000)
37 return MODE_CLOCK_LOW;
42 static int nv50_dac_execute_mode(struct nv50_output *output, bool disconnect)
44 struct drm_nouveau_private *dev_priv = output->dev->dev_private;
45 struct nv50_crtc *crtc = output->crtc;
46 struct nouveau_hw_mode *desired_mode = NULL;
48 uint32_t offset = nv50_output_or_offset(output) * 0x80;
50 uint32_t mode_ctl = NV50_DAC_MODE_CTRL_OFF;
51 uint32_t mode_ctl2 = 0;
53 NV50_DEBUG("or %d\n", nv50_output_or_offset(output));
56 NV50_DEBUG("Disconnecting DAC\n");
57 OUT_MODE(NV50_DAC0_MODE_CTRL + offset, mode_ctl);
61 desired_mode = (crtc->use_native_mode ? crtc->native_mode :
65 mode_ctl |= NV50_DAC_MODE_CTRL_CRTC1;
67 mode_ctl |= NV50_DAC_MODE_CTRL_CRTC0;
69 /* Lacking a working tv-out, this is not a 100% sure. */
70 if (output->type == OUTPUT_DAC) {
72 } else if (output->type == OUTPUT_TV) {
76 if (desired_mode->flags & V_NHSYNC)
77 mode_ctl2 |= NV50_DAC_MODE_CTRL2_NHSYNC;
79 if (desired_mode->flags & V_NVSYNC)
80 mode_ctl2 |= NV50_DAC_MODE_CTRL2_NVSYNC;
82 OUT_MODE(NV50_DAC0_MODE_CTRL + offset, mode_ctl);
83 OUT_MODE(NV50_DAC0_MODE_CTRL2 + offset, mode_ctl2);
88 static int nv50_dac_set_clock_mode(struct nv50_output *output)
90 struct drm_nouveau_private *dev_priv = output->dev->dev_private;
92 NV50_DEBUG("or %d\n", nv50_output_or_offset(output));
94 NV_WRITE(NV50_PDISPLAY_DAC_CLK_CLK_CTRL2(nv50_output_or_offset(output)), 0);
99 static int nv50_dac_set_power_mode(struct nv50_output *output, int mode)
101 struct drm_nouveau_private *dev_priv = output->dev->dev_private;
103 int or = nv50_output_or_offset(output);
105 NV50_DEBUG("or %d\n", or);
107 /* wait for it to be done */
108 while (NV_READ(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or)) & NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING);
110 val = NV_READ(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or)) & ~0x7F;
112 if (mode != DPMSModeOn)
113 val |= NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_BLANKED;
116 case DPMSModeStandby:
117 val |= NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_HSYNC_OFF;
119 case DPMSModeSuspend:
120 val |= NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_VSYNC_OFF;
123 val |= NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_OFF;
124 val |= NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_HSYNC_OFF;
125 val |= NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_VSYNC_OFF;
131 NV_WRITE(NV50_PDISPLAY_DAC_REGS_DPMS_CTRL(or), val | NV50_PDISPLAY_DAC_REGS_DPMS_CTRL_PENDING);
136 static int nv50_dac_destroy(struct nv50_output *output)
138 struct drm_device *dev = output->dev;
139 struct drm_nouveau_private *dev_priv = dev->dev_private;
140 struct nv50_display *display = nv50_get_display(dev);
144 if (!display || !output)
147 list_del(&output->head);
149 kfree(output->native_mode);
150 if (dev_priv->free_output)
151 dev_priv->free_output(output);
156 int nv50_dac_create(struct drm_device *dev, int dcb_entry)
158 struct drm_nouveau_private *dev_priv = dev->dev_private;
159 struct nv50_output *output = NULL;
160 struct nv50_display *display = NULL;
161 struct dcb_entry *entry = NULL;
166 /* This allows the public layer to do it's thing. */
167 if (dev_priv->alloc_output)
168 output = dev_priv->alloc_output(dev);
175 display = nv50_get_display(dev);
181 entry = &dev_priv->dcb_table.entry[dcb_entry];
187 switch (entry->type) {
188 case DCB_OUTPUT_ANALOG:
189 output->type = OUTPUT_DAC;
190 DRM_INFO("Detected a DAC output\n");
197 output->dcb_entry = dcb_entry;
198 output->bus = entry->bus;
200 list_add_tail(&output->head, &display->outputs);
202 output->native_mode = kzalloc(sizeof(struct nouveau_hw_mode), GFP_KERNEL);
203 if (!output->native_mode) {
208 /* Set function pointers. */
209 output->validate_mode = nv50_dac_validate_mode;
210 output->execute_mode = nv50_dac_execute_mode;
211 output->set_clock_mode = nv50_dac_set_clock_mode;
212 output->set_power_mode = nv50_dac_set_power_mode;
213 output->detect = NULL; /* TODO */
214 output->destroy = nv50_dac_destroy;
219 if (output->native_mode)
220 kfree(output->native_mode);
221 if (dev_priv->free_output)
222 dev_priv->free_output(output);