Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 Maarten Maathuis. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 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: |
| 12 | * |
| 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. |
| 16 | * |
| 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. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include "drmP.h" |
| 28 | #include "drm_crtc_helper.h" |
| 29 | |
| 30 | #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO) |
| 31 | #include "nouveau_reg.h" |
| 32 | #include "nouveau_drv.h" |
| 33 | #include "nouveau_dma.h" |
| 34 | #include "nouveau_encoder.h" |
| 35 | #include "nouveau_connector.h" |
| 36 | #include "nouveau_crtc.h" |
| 37 | #include "nv50_display.h" |
| 38 | |
| 39 | static void |
Ben Skeggs | ec7fc4a | 2010-07-01 15:33:45 +1000 | [diff] [blame] | 40 | nv50_dac_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 41 | { |
Ben Skeggs | ec7fc4a | 2010-07-01 15:33:45 +1000 | [diff] [blame] | 42 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 43 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 44 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 45 | int ret; |
| 46 | |
Ben Skeggs | ec7fc4a | 2010-07-01 15:33:45 +1000 | [diff] [blame] | 47 | if (!nv_encoder->crtc) |
| 48 | return; |
Ben Skeggs | 835aadb | 2010-07-05 15:19:16 +1000 | [diff] [blame] | 49 | nv50_crtc_blank(nouveau_crtc(nv_encoder->crtc), true); |
Ben Skeggs | ec7fc4a | 2010-07-01 15:33:45 +1000 | [diff] [blame] | 50 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 51 | NV_DEBUG_KMS(dev, "Disconnecting DAC %d\n", nv_encoder->or); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 52 | |
Ben Skeggs | 835aadb | 2010-07-05 15:19:16 +1000 | [diff] [blame] | 53 | ret = RING_SPACE(evo, 4); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 54 | if (ret) { |
| 55 | NV_ERROR(dev, "no space while disconnecting DAC\n"); |
| 56 | return; |
| 57 | } |
| 58 | BEGIN_RING(evo, 0, NV50_EVO_DAC(nv_encoder->or, MODE_CTRL), 1); |
Ben Skeggs | 835aadb | 2010-07-05 15:19:16 +1000 | [diff] [blame] | 59 | OUT_RING (evo, 0); |
| 60 | BEGIN_RING(evo, 0, NV50_EVO_UPDATE, 1); |
| 61 | OUT_RING (evo, 0); |
Ben Skeggs | ec7fc4a | 2010-07-01 15:33:45 +1000 | [diff] [blame] | 62 | |
| 63 | nv_encoder->crtc = NULL; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static enum drm_connector_status |
| 67 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
| 68 | { |
| 69 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 70 | struct drm_device *dev = encoder->dev; |
| 71 | struct drm_nouveau_private *dev_priv = dev->dev_private; |
| 72 | enum drm_connector_status status = connector_status_disconnected; |
| 73 | uint32_t dpms_state, load_pattern, load_state; |
| 74 | int or = nv_encoder->or; |
| 75 | |
| 76 | nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL1(or), 0x00000001); |
| 77 | dpms_state = nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or)); |
| 78 | |
| 79 | nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), |
| 80 | 0x00150000 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING); |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 81 | if (!nv_wait(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 82 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING, 0)) { |
| 83 | NV_ERROR(dev, "timeout: DAC_DPMS_CTRL_PENDING(%d) == 0\n", or); |
| 84 | NV_ERROR(dev, "DAC_DPMS_CTRL(%d) = 0x%08x\n", or, |
| 85 | nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or))); |
| 86 | return status; |
| 87 | } |
| 88 | |
| 89 | /* Use bios provided value if possible. */ |
Ben Skeggs | 04a39c5 | 2010-02-24 10:03:05 +1000 | [diff] [blame] | 90 | if (dev_priv->vbios.dactestval) { |
| 91 | load_pattern = dev_priv->vbios.dactestval; |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 92 | NV_DEBUG_KMS(dev, "Using bios provided load_pattern of %d\n", |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 93 | load_pattern); |
| 94 | } else { |
| 95 | load_pattern = 340; |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 96 | NV_DEBUG_KMS(dev, "Using default load_pattern of %d\n", |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 97 | load_pattern); |
| 98 | } |
| 99 | |
| 100 | nv_wr32(dev, NV50_PDISPLAY_DAC_LOAD_CTRL(or), |
| 101 | NV50_PDISPLAY_DAC_LOAD_CTRL_ACTIVE | load_pattern); |
| 102 | mdelay(45); /* give it some time to process */ |
| 103 | load_state = nv_rd32(dev, NV50_PDISPLAY_DAC_LOAD_CTRL(or)); |
| 104 | |
| 105 | nv_wr32(dev, NV50_PDISPLAY_DAC_LOAD_CTRL(or), 0); |
| 106 | nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), dpms_state | |
| 107 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING); |
| 108 | |
| 109 | if ((load_state & NV50_PDISPLAY_DAC_LOAD_CTRL_PRESENT) == |
| 110 | NV50_PDISPLAY_DAC_LOAD_CTRL_PRESENT) |
| 111 | status = connector_status_connected; |
| 112 | |
| 113 | if (status == connector_status_connected) |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 114 | NV_DEBUG_KMS(dev, "Load was detected on output with or %d\n", or); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 115 | else |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 116 | NV_DEBUG_KMS(dev, "Load was not detected on output with or %d\n", or); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 117 | |
| 118 | return status; |
| 119 | } |
| 120 | |
| 121 | static void |
| 122 | nv50_dac_dpms(struct drm_encoder *encoder, int mode) |
| 123 | { |
| 124 | struct drm_device *dev = encoder->dev; |
| 125 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 126 | uint32_t val; |
| 127 | int or = nv_encoder->or; |
| 128 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 129 | NV_DEBUG_KMS(dev, "or %d mode %d\n", or, mode); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 130 | |
| 131 | /* wait for it to be done */ |
Francisco Jerez | 4b5c152 | 2010-09-07 17:34:44 +0200 | [diff] [blame] | 132 | if (!nv_wait(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 133 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING, 0)) { |
| 134 | NV_ERROR(dev, "timeout: DAC_DPMS_CTRL_PENDING(%d) == 0\n", or); |
| 135 | NV_ERROR(dev, "DAC_DPMS_CTRL(%d) = 0x%08x\n", or, |
| 136 | nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or))); |
| 137 | return; |
| 138 | } |
| 139 | |
| 140 | val = nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or)) & ~0x7F; |
| 141 | |
| 142 | if (mode != DRM_MODE_DPMS_ON) |
| 143 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_BLANKED; |
| 144 | |
| 145 | switch (mode) { |
| 146 | case DRM_MODE_DPMS_STANDBY: |
| 147 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_HSYNC_OFF; |
| 148 | break; |
| 149 | case DRM_MODE_DPMS_SUSPEND: |
| 150 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_VSYNC_OFF; |
| 151 | break; |
| 152 | case DRM_MODE_DPMS_OFF: |
| 153 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_OFF; |
| 154 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_HSYNC_OFF; |
| 155 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_VSYNC_OFF; |
| 156 | break; |
| 157 | default: |
| 158 | break; |
| 159 | } |
| 160 | |
| 161 | nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), val | |
| 162 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING); |
| 163 | } |
| 164 | |
| 165 | static void |
| 166 | nv50_dac_save(struct drm_encoder *encoder) |
| 167 | { |
| 168 | NV_ERROR(encoder->dev, "!!\n"); |
| 169 | } |
| 170 | |
| 171 | static void |
| 172 | nv50_dac_restore(struct drm_encoder *encoder) |
| 173 | { |
| 174 | NV_ERROR(encoder->dev, "!!\n"); |
| 175 | } |
| 176 | |
| 177 | static bool |
| 178 | nv50_dac_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, |
| 179 | struct drm_display_mode *adjusted_mode) |
| 180 | { |
| 181 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 182 | struct nouveau_connector *connector; |
| 183 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 184 | NV_DEBUG_KMS(encoder->dev, "or %d\n", nv_encoder->or); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 185 | |
| 186 | connector = nouveau_encoder_connector_get(nv_encoder); |
| 187 | if (!connector) { |
| 188 | NV_ERROR(encoder->dev, "Encoder has no connector\n"); |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | if (connector->scaling_mode != DRM_MODE_SCALE_NONE && |
| 193 | connector->native_mode) { |
| 194 | int id = adjusted_mode->base.id; |
| 195 | *adjusted_mode = *connector->native_mode; |
| 196 | adjusted_mode->base.id = id; |
| 197 | } |
| 198 | |
| 199 | return true; |
| 200 | } |
| 201 | |
| 202 | static void |
| 203 | nv50_dac_prepare(struct drm_encoder *encoder) |
| 204 | { |
| 205 | } |
| 206 | |
| 207 | static void |
| 208 | nv50_dac_commit(struct drm_encoder *encoder) |
| 209 | { |
| 210 | } |
| 211 | |
| 212 | static void |
| 213 | nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, |
| 214 | struct drm_display_mode *adjusted_mode) |
| 215 | { |
| 216 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 217 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 59c0f57 | 2011-02-01 10:24:41 +1000 | [diff] [blame] | 218 | struct nouveau_channel *evo = nv50_display(dev)->master; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 219 | struct nouveau_crtc *crtc = nouveau_crtc(encoder->crtc); |
| 220 | uint32_t mode_ctl = 0, mode_ctl2 = 0; |
| 221 | int ret; |
| 222 | |
Ben Skeggs | 0441292 | 2010-07-02 13:47:38 +1000 | [diff] [blame] | 223 | NV_DEBUG_KMS(dev, "or %d type %d crtc %d\n", |
| 224 | nv_encoder->or, nv_encoder->dcb->type, crtc->index); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 225 | |
| 226 | nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON); |
| 227 | |
| 228 | if (crtc->index == 1) |
| 229 | mode_ctl |= NV50_EVO_DAC_MODE_CTRL_CRTC1; |
| 230 | else |
| 231 | mode_ctl |= NV50_EVO_DAC_MODE_CTRL_CRTC0; |
| 232 | |
| 233 | /* Lacking a working tv-out, this is not a 100% sure. */ |
| 234 | if (nv_encoder->dcb->type == OUTPUT_ANALOG) |
| 235 | mode_ctl |= 0x40; |
| 236 | else |
| 237 | if (nv_encoder->dcb->type == OUTPUT_TV) |
| 238 | mode_ctl |= 0x100; |
| 239 | |
| 240 | if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 241 | mode_ctl2 |= NV50_EVO_DAC_MODE_CTRL2_NHSYNC; |
| 242 | |
| 243 | if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 244 | mode_ctl2 |= NV50_EVO_DAC_MODE_CTRL2_NVSYNC; |
| 245 | |
| 246 | ret = RING_SPACE(evo, 3); |
| 247 | if (ret) { |
| 248 | NV_ERROR(dev, "no space while connecting DAC\n"); |
| 249 | return; |
| 250 | } |
| 251 | BEGIN_RING(evo, 0, NV50_EVO_DAC(nv_encoder->or, MODE_CTRL), 2); |
| 252 | OUT_RING(evo, mode_ctl); |
| 253 | OUT_RING(evo, mode_ctl2); |
Ben Skeggs | ec7fc4a | 2010-07-01 15:33:45 +1000 | [diff] [blame] | 254 | |
| 255 | nv_encoder->crtc = encoder->crtc; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 256 | } |
| 257 | |
Ben Skeggs | 2107cce | 2010-07-07 11:05:48 +1000 | [diff] [blame] | 258 | static struct drm_crtc * |
| 259 | nv50_dac_crtc_get(struct drm_encoder *encoder) |
| 260 | { |
| 261 | return nouveau_encoder(encoder)->crtc; |
| 262 | } |
| 263 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 264 | static const struct drm_encoder_helper_funcs nv50_dac_helper_funcs = { |
| 265 | .dpms = nv50_dac_dpms, |
| 266 | .save = nv50_dac_save, |
| 267 | .restore = nv50_dac_restore, |
| 268 | .mode_fixup = nv50_dac_mode_fixup, |
| 269 | .prepare = nv50_dac_prepare, |
| 270 | .commit = nv50_dac_commit, |
| 271 | .mode_set = nv50_dac_mode_set, |
Ben Skeggs | 2107cce | 2010-07-07 11:05:48 +1000 | [diff] [blame] | 272 | .get_crtc = nv50_dac_crtc_get, |
Ben Skeggs | ec7fc4a | 2010-07-01 15:33:45 +1000 | [diff] [blame] | 273 | .detect = nv50_dac_detect, |
| 274 | .disable = nv50_dac_disconnect |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 275 | }; |
| 276 | |
| 277 | static void |
| 278 | nv50_dac_destroy(struct drm_encoder *encoder) |
| 279 | { |
| 280 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 281 | |
| 282 | if (!encoder) |
| 283 | return; |
| 284 | |
Maarten Maathuis | ef2bb50 | 2009-12-13 16:53:12 +0100 | [diff] [blame] | 285 | NV_DEBUG_KMS(encoder->dev, "\n"); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 286 | |
| 287 | drm_encoder_cleanup(encoder); |
| 288 | kfree(nv_encoder); |
| 289 | } |
| 290 | |
| 291 | static const struct drm_encoder_funcs nv50_dac_encoder_funcs = { |
| 292 | .destroy = nv50_dac_destroy, |
| 293 | }; |
| 294 | |
| 295 | int |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 296 | nv50_dac_create(struct drm_connector *connector, struct dcb_entry *entry) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 297 | { |
| 298 | struct nouveau_encoder *nv_encoder; |
| 299 | struct drm_encoder *encoder; |
| 300 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 301 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 302 | if (!nv_encoder) |
| 303 | return -ENOMEM; |
| 304 | encoder = to_drm_encoder(nv_encoder); |
| 305 | |
| 306 | nv_encoder->dcb = entry; |
| 307 | nv_encoder->or = ffs(entry->or) - 1; |
| 308 | |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 309 | drm_encoder_init(connector->dev, encoder, &nv50_dac_encoder_funcs, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 310 | DRM_MODE_ENCODER_DAC); |
| 311 | drm_encoder_helper_add(encoder, &nv50_dac_helper_funcs); |
| 312 | |
| 313 | encoder->possible_crtcs = entry->heads; |
| 314 | encoder->possible_clones = 0; |
Ben Skeggs | 8f1a608 | 2010-06-28 14:35:50 +1000 | [diff] [blame] | 315 | |
| 316 | drm_mode_connector_attach_encoder(connector, encoder); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 317 | return 0; |
| 318 | } |
| 319 | |