Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2014 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | |
| 26 | #include <drm/drmP.h> |
| 27 | #include <drm/drm_edid.h> |
| 28 | #include "intel_drv.h" |
| 29 | #include "i915_drv.h" |
| 30 | |
Jani Nikula | 28855d2 | 2014-10-27 16:27:00 +0200 | [diff] [blame^] | 31 | /** |
| 32 | * DOC: High Definition Audio over HDMI and Display Port |
| 33 | * |
| 34 | * The graphics and audio drivers together support High Definition Audio over |
| 35 | * HDMI and Display Port. The audio programming sequences are divided into audio |
| 36 | * codec and controller enable and disable sequences. The graphics driver |
| 37 | * handles the audio codec sequences, while the audio driver handles the audio |
| 38 | * controller sequences. |
| 39 | * |
| 40 | * The disable sequences must be performed before disabling the transcoder or |
| 41 | * port. The enable sequences may only be performed after enabling the |
| 42 | * transcoder and port, and after completed link training. |
| 43 | * |
| 44 | * The codec and controller sequences could be done either parallel or serial, |
| 45 | * but generally the ELDV/PD change in the codec sequence indicates to the audio |
| 46 | * driver that the controller sequence should start. Indeed, most of the |
| 47 | * co-operation between the graphics and audio drivers is handled via audio |
| 48 | * related registers. (The notable exception is the power management, not |
| 49 | * covered here.) |
| 50 | */ |
| 51 | |
Jani Nikula | 87fcb2a | 2014-10-27 16:26:44 +0200 | [diff] [blame] | 52 | static const struct { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 53 | int clock; |
| 54 | u32 config; |
| 55 | } hdmi_audio_clock[] = { |
| 56 | { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 }, |
| 57 | { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */ |
| 58 | { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 }, |
| 59 | { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 }, |
| 60 | { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 }, |
| 61 | { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 }, |
| 62 | { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 }, |
| 63 | { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 }, |
| 64 | { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 }, |
| 65 | { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 }, |
| 66 | }; |
| 67 | |
| 68 | /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */ |
| 69 | static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode) |
| 70 | { |
| 71 | int i; |
| 72 | |
| 73 | for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) { |
| 74 | if (mode->clock == hdmi_audio_clock[i].clock) |
| 75 | break; |
| 76 | } |
| 77 | |
| 78 | if (i == ARRAY_SIZE(hdmi_audio_clock)) { |
| 79 | DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock); |
| 80 | i = 1; |
| 81 | } |
| 82 | |
| 83 | DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n", |
| 84 | hdmi_audio_clock[i].clock, |
| 85 | hdmi_audio_clock[i].config); |
| 86 | |
| 87 | return hdmi_audio_clock[i].config; |
| 88 | } |
| 89 | |
| 90 | static bool intel_eld_uptodate(struct drm_connector *connector, |
| 91 | int reg_eldv, uint32_t bits_eldv, |
| 92 | int reg_elda, uint32_t bits_elda, |
| 93 | int reg_edid) |
| 94 | { |
| 95 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 96 | uint8_t *eld = connector->eld; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 97 | uint32_t tmp; |
| 98 | int i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 99 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 100 | tmp = I915_READ(reg_eldv); |
| 101 | tmp &= bits_eldv; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 102 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 103 | if (!tmp) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 104 | return false; |
| 105 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 106 | tmp = I915_READ(reg_elda); |
| 107 | tmp &= ~bits_elda; |
| 108 | I915_WRITE(reg_elda, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 109 | |
| 110 | for (i = 0; i < eld[2]; i++) |
| 111 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 112 | return false; |
| 113 | |
| 114 | return true; |
| 115 | } |
| 116 | |
Jani Nikula | 76d8d3e | 2014-10-27 16:26:57 +0200 | [diff] [blame] | 117 | static void g4x_audio_codec_disable(struct intel_encoder *encoder) |
| 118 | { |
| 119 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 120 | uint32_t eldv, tmp; |
| 121 | |
| 122 | DRM_DEBUG_KMS("Disable audio codec\n"); |
| 123 | |
| 124 | tmp = I915_READ(G4X_AUD_VID_DID); |
| 125 | if (tmp == INTEL_AUDIO_DEVBLC || tmp == INTEL_AUDIO_DEVCL) |
| 126 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 127 | else |
| 128 | eldv = G4X_ELDV_DEVCTG; |
| 129 | |
| 130 | /* Invalidate ELD */ |
| 131 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
| 132 | tmp &= ~eldv; |
| 133 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
| 134 | } |
| 135 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 136 | static void g4x_audio_codec_enable(struct drm_connector *connector, |
| 137 | struct intel_encoder *encoder, |
| 138 | struct drm_display_mode *mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 139 | { |
| 140 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 141 | uint8_t *eld = connector->eld; |
| 142 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 143 | uint32_t tmp; |
| 144 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 145 | |
Jani Nikula | d5ee08d | 2014-10-27 16:26:58 +0200 | [diff] [blame] | 146 | DRM_DEBUG_KMS("Enable audio codec, %u bytes ELD\n", eld[2]); |
| 147 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 148 | tmp = I915_READ(G4X_AUD_VID_DID); |
| 149 | if (tmp == INTEL_AUDIO_DEVBLC || tmp == INTEL_AUDIO_DEVCL) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 150 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 151 | else |
| 152 | eldv = G4X_ELDV_DEVCTG; |
| 153 | |
| 154 | if (intel_eld_uptodate(connector, |
| 155 | G4X_AUD_CNTL_ST, eldv, |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 156 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR_MASK, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 157 | G4X_HDMIW_HDMIEDID)) |
| 158 | return; |
| 159 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 160 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 161 | tmp &= ~(eldv | G4X_ELD_ADDR_MASK); |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 162 | len = (tmp >> 9) & 0x1f; /* ELD buffer size */ |
| 163 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 164 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 165 | len = min_t(int, eld[2], len); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 166 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 167 | for (i = 0; i < len; i++) |
| 168 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 169 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 170 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
| 171 | tmp |= eldv; |
| 172 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 175 | static void hsw_audio_codec_disable(struct intel_encoder *encoder) |
| 176 | { |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 177 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 178 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 179 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 180 | uint32_t tmp; |
| 181 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 182 | DRM_DEBUG_KMS("Disable audio codec on pipe %c\n", pipe_name(pipe)); |
| 183 | |
| 184 | /* Disable timestamps */ |
| 185 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 186 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 187 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 188 | tmp &= ~AUD_CONFIG_UPPER_N_MASK; |
| 189 | tmp &= ~AUD_CONFIG_LOWER_N_MASK; |
| 190 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 191 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 192 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
| 193 | |
| 194 | /* Invalidate ELD */ |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 195 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 196 | tmp &= ~AUDIO_ELD_VALID(pipe); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 197 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
| 198 | } |
| 199 | |
| 200 | static void hsw_audio_codec_enable(struct drm_connector *connector, |
| 201 | struct intel_encoder *encoder, |
| 202 | struct drm_display_mode *mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 203 | { |
| 204 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 205 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 206 | enum pipe pipe = intel_crtc->pipe; |
| 207 | const uint8_t *eld = connector->eld; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 208 | uint32_t tmp; |
| 209 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 210 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 211 | DRM_DEBUG_KMS("Enable audio codec on pipe %c, %u bytes ELD\n", |
| 212 | pipe_name(pipe), eld[2]); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 213 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 214 | /* Enable audio presence detect, invalidate ELD */ |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 215 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 216 | tmp |= AUDIO_OUTPUT_ENABLE(pipe); |
| 217 | tmp &= ~AUDIO_ELD_VALID(pipe); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 218 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * FIXME: We're supposed to wait for vblank here, but we have vblanks |
| 222 | * disabled during the mode set. The proper fix would be to push the |
| 223 | * rest of the setup into a vblank work item, queued here, but the |
| 224 | * infrastructure is not there yet. |
| 225 | */ |
| 226 | |
| 227 | /* Reset ELD write address */ |
| 228 | tmp = I915_READ(HSW_AUD_DIP_ELD_CTRL(pipe)); |
| 229 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
| 230 | I915_WRITE(HSW_AUD_DIP_ELD_CTRL(pipe), tmp); |
| 231 | |
| 232 | /* Up to 84 bytes of hw ELD buffer */ |
| 233 | len = min_t(int, eld[2], 21); |
| 234 | for (i = 0; i < len; i++) |
| 235 | I915_WRITE(HSW_AUD_EDID_DATA(pipe), *((uint32_t *)eld + i)); |
| 236 | |
| 237 | /* ELD valid */ |
| 238 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 239 | tmp |= AUDIO_ELD_VALID(pipe); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 240 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
| 241 | |
| 242 | /* Enable timestamps */ |
| 243 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 244 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 245 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
| 246 | tmp &= ~AUD_CONFIG_PIXEL_CLOCK_HDMI_MASK; |
| 247 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 248 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 249 | else |
| 250 | tmp |= audio_config_hdmi_pixel_clock(mode); |
| 251 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 254 | static void ilk_audio_codec_disable(struct intel_encoder *encoder) |
| 255 | { |
| 256 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 257 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 258 | struct intel_digital_port *intel_dig_port = |
| 259 | enc_to_dig_port(&encoder->base); |
| 260 | enum port port = intel_dig_port->port; |
| 261 | enum pipe pipe = intel_crtc->pipe; |
| 262 | uint32_t tmp, eldv; |
| 263 | int aud_config; |
| 264 | int aud_cntrl_st2; |
| 265 | |
| 266 | DRM_DEBUG_KMS("Disable audio codec on port %c, pipe %c\n", |
| 267 | port_name(port), pipe_name(pipe)); |
| 268 | |
| 269 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 270 | aud_config = IBX_AUD_CFG(pipe); |
| 271 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
| 272 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 273 | aud_config = VLV_AUD_CFG(pipe); |
| 274 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
| 275 | } else { |
| 276 | aud_config = CPT_AUD_CFG(pipe); |
| 277 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
| 278 | } |
| 279 | |
| 280 | /* Disable timestamps */ |
| 281 | tmp = I915_READ(aud_config); |
| 282 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 283 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 284 | tmp &= ~AUD_CONFIG_UPPER_N_MASK; |
| 285 | tmp &= ~AUD_CONFIG_LOWER_N_MASK; |
| 286 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 287 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 288 | I915_WRITE(aud_config, tmp); |
| 289 | |
| 290 | if (WARN_ON(!port)) { |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 291 | eldv = IBX_ELD_VALID(PORT_B) | IBX_ELD_VALID(PORT_C) | |
| 292 | IBX_ELD_VALID(PORT_D); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 293 | } else { |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 294 | eldv = IBX_ELD_VALID(port); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /* Invalidate ELD */ |
| 298 | tmp = I915_READ(aud_cntrl_st2); |
| 299 | tmp &= ~eldv; |
| 300 | I915_WRITE(aud_cntrl_st2, tmp); |
| 301 | } |
| 302 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 303 | static void ilk_audio_codec_enable(struct drm_connector *connector, |
| 304 | struct intel_encoder *encoder, |
| 305 | struct drm_display_mode *mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 306 | { |
| 307 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 308 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 309 | struct intel_digital_port *intel_dig_port = |
| 310 | enc_to_dig_port(&encoder->base); |
| 311 | enum port port = intel_dig_port->port; |
| 312 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 313 | uint8_t *eld = connector->eld; |
| 314 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 315 | uint32_t tmp; |
| 316 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 317 | int hdmiw_hdmiedid; |
| 318 | int aud_config; |
| 319 | int aud_cntl_st; |
| 320 | int aud_cntrl_st2; |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 321 | |
| 322 | DRM_DEBUG_KMS("Enable audio codec on port %c, pipe %c, %u bytes ELD\n", |
| 323 | port_name(port), pipe_name(pipe), eld[2]); |
| 324 | |
| 325 | /* |
| 326 | * FIXME: We're supposed to wait for vblank here, but we have vblanks |
| 327 | * disabled during the mode set. The proper fix would be to push the |
| 328 | * rest of the setup into a vblank work item, queued here, but the |
| 329 | * infrastructure is not there yet. |
| 330 | */ |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 331 | |
| 332 | if (HAS_PCH_IBX(connector->dev)) { |
| 333 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 334 | aud_config = IBX_AUD_CFG(pipe); |
| 335 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
| 336 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
| 337 | } else if (IS_VALLEYVIEW(connector->dev)) { |
| 338 | hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe); |
| 339 | aud_config = VLV_AUD_CFG(pipe); |
| 340 | aud_cntl_st = VLV_AUD_CNTL_ST(pipe); |
| 341 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
| 342 | } else { |
| 343 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 344 | aud_config = CPT_AUD_CFG(pipe); |
| 345 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
| 346 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
| 347 | } |
| 348 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 349 | if (WARN_ON(!port)) { |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 350 | eldv = IBX_ELD_VALID(PORT_B) | IBX_ELD_VALID(PORT_C) | |
| 351 | IBX_ELD_VALID(PORT_D); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 352 | } else { |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 353 | eldv = IBX_ELD_VALID(port); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 354 | } |
| 355 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 356 | /* Invalidate ELD */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 357 | tmp = I915_READ(aud_cntrl_st2); |
| 358 | tmp &= ~eldv; |
| 359 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 360 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 361 | /* Reset ELD write address */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 362 | tmp = I915_READ(aud_cntl_st); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 363 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 364 | I915_WRITE(aud_cntl_st, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 365 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 366 | /* Up to 84 bytes of hw ELD buffer */ |
| 367 | len = min_t(int, eld[2], 21); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 368 | for (i = 0; i < len; i++) |
| 369 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 370 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 371 | /* ELD valid */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 372 | tmp = I915_READ(aud_cntrl_st2); |
| 373 | tmp |= eldv; |
| 374 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 375 | |
| 376 | /* Enable timestamps */ |
| 377 | tmp = I915_READ(aud_config); |
| 378 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 379 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
| 380 | tmp &= ~AUD_CONFIG_PIXEL_CLOCK_HDMI_MASK; |
| 381 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 382 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 383 | else |
| 384 | tmp |= audio_config_hdmi_pixel_clock(mode); |
| 385 | I915_WRITE(aud_config, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 386 | } |
| 387 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 388 | /** |
| 389 | * intel_audio_codec_enable - Enable the audio codec for HD audio |
| 390 | * @intel_encoder: encoder on which to enable audio |
| 391 | * |
| 392 | * The enable sequences may only be performed after enabling the transcoder and |
| 393 | * port, and after completed link training. |
| 394 | */ |
| 395 | void intel_audio_codec_enable(struct intel_encoder *intel_encoder) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 396 | { |
Jani Nikula | 33d1e7c6 | 2014-10-27 16:26:46 +0200 | [diff] [blame] | 397 | struct drm_encoder *encoder = &intel_encoder->base; |
| 398 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
| 399 | struct drm_display_mode *mode = &crtc->config.adjusted_mode; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 400 | struct drm_connector *connector; |
| 401 | struct drm_device *dev = encoder->dev; |
| 402 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 403 | |
| 404 | connector = drm_select_eld(encoder, mode); |
| 405 | if (!connector) |
| 406 | return; |
| 407 | |
| 408 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 409 | connector->base.id, |
| 410 | connector->name, |
| 411 | connector->encoder->base.id, |
| 412 | connector->encoder->name); |
| 413 | |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 414 | /* ELD Conn_Type */ |
| 415 | connector->eld[5] &= ~(3 << 2); |
| 416 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 417 | connector->eld[5] |= (1 << 2); |
| 418 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 419 | connector->eld[6] = drm_av_sync_delay(connector, mode) / 2; |
| 420 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 421 | if (dev_priv->display.audio_codec_enable) |
| 422 | dev_priv->display.audio_codec_enable(connector, intel_encoder, mode); |
| 423 | } |
| 424 | |
| 425 | /** |
| 426 | * intel_audio_codec_disable - Disable the audio codec for HD audio |
| 427 | * @encoder: encoder on which to disable audio |
| 428 | * |
| 429 | * The disable sequences must be performed before disabling the transcoder or |
| 430 | * port. |
| 431 | */ |
| 432 | void intel_audio_codec_disable(struct intel_encoder *encoder) |
| 433 | { |
| 434 | struct drm_device *dev = encoder->base.dev; |
| 435 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 436 | |
| 437 | if (dev_priv->display.audio_codec_disable) |
| 438 | dev_priv->display.audio_codec_disable(encoder); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /** |
| 442 | * intel_init_audio - Set up chip specific audio functions |
| 443 | * @dev: drm device |
| 444 | */ |
| 445 | void intel_init_audio(struct drm_device *dev) |
| 446 | { |
| 447 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 448 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 449 | if (IS_G4X(dev)) { |
| 450 | dev_priv->display.audio_codec_enable = g4x_audio_codec_enable; |
Jani Nikula | 76d8d3e | 2014-10-27 16:26:57 +0200 | [diff] [blame] | 451 | dev_priv->display.audio_codec_disable = g4x_audio_codec_disable; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 452 | } else if (IS_VALLEYVIEW(dev)) { |
| 453 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 454 | dev_priv->display.audio_codec_disable = ilk_audio_codec_disable; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 455 | } else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) { |
| 456 | dev_priv->display.audio_codec_enable = hsw_audio_codec_enable; |
| 457 | dev_priv->display.audio_codec_disable = hsw_audio_codec_disable; |
| 458 | } else if (HAS_PCH_SPLIT(dev)) { |
| 459 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 460 | dev_priv->display.audio_codec_disable = ilk_audio_codec_disable; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 461 | } |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 462 | } |