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_destroy(struct nv50_output *output)
101 struct drm_device *dev = output->dev;
102 struct drm_nouveau_private *dev_priv = dev->dev_private;
103 struct nv50_display *display = nv50_get_display(dev);
107 if (!display || !output)
110 list_del(&output->head);
112 kfree(output->native_mode);
113 if (dev_priv->free_output)
114 dev_priv->free_output(output);
119 int nv50_dac_create(struct drm_device *dev, int dcb_entry)
121 struct drm_nouveau_private *dev_priv = dev->dev_private;
122 struct nv50_output *output = NULL;
123 struct nv50_display *display = NULL;
124 struct dcb_entry *entry = NULL;
129 /* This allows the public layer to do it's thing. */
130 if (dev_priv->alloc_output)
131 output = dev_priv->alloc_output(dev);
138 display = nv50_get_display(dev);
144 entry = &dev_priv->dcb_table.entry[dcb_entry];
150 switch (entry->type) {
151 case DCB_OUTPUT_ANALOG:
152 output->type = OUTPUT_DAC;
153 DRM_INFO("Detected a DAC output\n");
160 output->dcb_entry = dcb_entry;
161 output->bus = entry->bus;
163 list_add_tail(&output->head, &display->outputs);
165 output->native_mode = kzalloc(sizeof(struct nouveau_hw_mode), GFP_KERNEL);
166 if (!output->native_mode) {
171 /* Set function pointers. */
172 output->validate_mode = nv50_dac_validate_mode;
173 output->execute_mode = nv50_dac_execute_mode;
174 output->set_clock_mode = nv50_dac_set_clock_mode;
175 output->detect = NULL; /* TODO */
176 output->destroy = nv50_dac_destroy;
181 if (output->native_mode)
182 kfree(output->native_mode);
183 if (dev_priv->free_output)
184 dev_priv->free_output(output);