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 | 87fcb2a | 2014-10-27 16:26:44 +0200 | [diff] [blame] | 31 | static const struct { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 32 | int clock; |
| 33 | u32 config; |
| 34 | } hdmi_audio_clock[] = { |
| 35 | { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 }, |
| 36 | { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */ |
| 37 | { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 }, |
| 38 | { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 }, |
| 39 | { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 }, |
| 40 | { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 }, |
| 41 | { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 }, |
| 42 | { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 }, |
| 43 | { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 }, |
| 44 | { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 }, |
| 45 | }; |
| 46 | |
| 47 | /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */ |
| 48 | static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode) |
| 49 | { |
| 50 | int i; |
| 51 | |
| 52 | for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) { |
| 53 | if (mode->clock == hdmi_audio_clock[i].clock) |
| 54 | break; |
| 55 | } |
| 56 | |
| 57 | if (i == ARRAY_SIZE(hdmi_audio_clock)) { |
| 58 | DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock); |
| 59 | i = 1; |
| 60 | } |
| 61 | |
| 62 | DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n", |
| 63 | hdmi_audio_clock[i].clock, |
| 64 | hdmi_audio_clock[i].config); |
| 65 | |
| 66 | return hdmi_audio_clock[i].config; |
| 67 | } |
| 68 | |
| 69 | static bool intel_eld_uptodate(struct drm_connector *connector, |
| 70 | int reg_eldv, uint32_t bits_eldv, |
| 71 | int reg_elda, uint32_t bits_elda, |
| 72 | int reg_edid) |
| 73 | { |
| 74 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 75 | uint8_t *eld = connector->eld; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 76 | uint32_t tmp; |
| 77 | int i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 78 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 79 | tmp = I915_READ(reg_eldv); |
| 80 | tmp &= bits_eldv; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 81 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 82 | if (!tmp) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 83 | return false; |
| 84 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 85 | tmp = I915_READ(reg_elda); |
| 86 | tmp &= ~bits_elda; |
| 87 | I915_WRITE(reg_elda, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 88 | |
| 89 | for (i = 0; i < eld[2]; i++) |
| 90 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 91 | return false; |
| 92 | |
| 93 | return true; |
| 94 | } |
| 95 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 96 | static void g4x_audio_codec_enable(struct drm_connector *connector, |
| 97 | struct intel_encoder *encoder, |
| 98 | struct drm_display_mode *mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 99 | { |
| 100 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 101 | uint8_t *eld = connector->eld; |
| 102 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 103 | uint32_t tmp; |
| 104 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 105 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 106 | tmp = I915_READ(G4X_AUD_VID_DID); |
| 107 | if (tmp == INTEL_AUDIO_DEVBLC || tmp == INTEL_AUDIO_DEVCL) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 108 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 109 | else |
| 110 | eldv = G4X_ELDV_DEVCTG; |
| 111 | |
| 112 | if (intel_eld_uptodate(connector, |
| 113 | G4X_AUD_CNTL_ST, eldv, |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame^] | 114 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR_MASK, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 115 | G4X_HDMIW_HDMIEDID)) |
| 116 | return; |
| 117 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 118 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame^] | 119 | tmp &= ~(eldv | G4X_ELD_ADDR_MASK); |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 120 | len = (tmp >> 9) & 0x1f; /* ELD buffer size */ |
| 121 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 122 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 123 | len = min_t(int, eld[2], len); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 124 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 125 | for (i = 0; i < len; i++) |
| 126 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 127 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 128 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
| 129 | tmp |= eldv; |
| 130 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 133 | static void hsw_audio_codec_disable(struct intel_encoder *encoder) |
| 134 | { |
| 135 | struct drm_device *dev = encoder->base.dev; |
| 136 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 137 | struct drm_crtc *crtc = encoder->base.crtc; |
| 138 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
| 139 | uint32_t tmp; |
| 140 | |
| 141 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
| 142 | tmp &= ~((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4)); |
| 143 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
| 144 | } |
| 145 | |
| 146 | static void hsw_audio_codec_enable(struct drm_connector *connector, |
| 147 | struct intel_encoder *encoder, |
| 148 | struct drm_display_mode *mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 149 | { |
| 150 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 151 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 152 | uint8_t *eld = connector->eld; |
| 153 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 154 | uint32_t tmp; |
| 155 | int len, i; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 156 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 157 | enum port port; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 158 | int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe); |
| 159 | int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe); |
| 160 | int aud_config = HSW_AUD_CFG(pipe); |
| 161 | int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD; |
| 162 | |
| 163 | /* Audio output enable */ |
| 164 | DRM_DEBUG_DRIVER("HDMI audio: enable codec\n"); |
| 165 | tmp = I915_READ(aud_cntrl_st2); |
| 166 | tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4)); |
| 167 | I915_WRITE(aud_cntrl_st2, tmp); |
| 168 | POSTING_READ(aud_cntrl_st2); |
| 169 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 170 | /* Set ELD valid state */ |
| 171 | tmp = I915_READ(aud_cntrl_st2); |
| 172 | DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp); |
| 173 | tmp |= (AUDIO_ELD_VALID_A << (pipe * 4)); |
| 174 | I915_WRITE(aud_cntrl_st2, tmp); |
| 175 | tmp = I915_READ(aud_cntrl_st2); |
| 176 | DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp); |
| 177 | |
| 178 | /* Enable HDMI mode */ |
| 179 | tmp = I915_READ(aud_config); |
| 180 | DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp); |
| 181 | /* clear N_programing_enable and N_value_index */ |
| 182 | tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE); |
| 183 | I915_WRITE(aud_config, tmp); |
| 184 | |
| 185 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
| 186 | |
| 187 | eldv = AUDIO_ELD_VALID_A << (pipe * 4); |
| 188 | |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 189 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 190 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 191 | else |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 192 | I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode)); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 193 | |
| 194 | if (intel_eld_uptodate(connector, |
| 195 | aud_cntrl_st2, eldv, |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame^] | 196 | aud_cntl_st, IBX_ELD_ADDRESS_MASK, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 197 | hdmiw_hdmiedid)) |
| 198 | return; |
| 199 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 200 | tmp = I915_READ(aud_cntrl_st2); |
| 201 | tmp &= ~eldv; |
| 202 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 203 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 204 | tmp = I915_READ(aud_cntl_st); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame^] | 205 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 206 | I915_WRITE(aud_cntl_st, tmp); |
| 207 | port = (tmp >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */ |
| 208 | DRM_DEBUG_DRIVER("port num:%d\n", port); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 209 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 210 | len = min_t(int, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 211 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 212 | for (i = 0; i < len; i++) |
| 213 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 214 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 215 | tmp = I915_READ(aud_cntrl_st2); |
| 216 | tmp |= eldv; |
| 217 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 218 | |
| 219 | /* XXX: Transitional */ |
| 220 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
| 221 | tmp |= ((AUDIO_OUTPUT_ENABLE_A | AUDIO_ELD_VALID_A) << (pipe * 4)); |
| 222 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 225 | static void ilk_audio_codec_enable(struct drm_connector *connector, |
| 226 | struct intel_encoder *encoder, |
| 227 | struct drm_display_mode *mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 228 | { |
| 229 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 230 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 231 | uint8_t *eld = connector->eld; |
| 232 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 233 | uint32_t tmp; |
| 234 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 235 | int hdmiw_hdmiedid; |
| 236 | int aud_config; |
| 237 | int aud_cntl_st; |
| 238 | int aud_cntrl_st2; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 239 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 240 | enum port port; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 241 | |
| 242 | if (HAS_PCH_IBX(connector->dev)) { |
| 243 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 244 | aud_config = IBX_AUD_CFG(pipe); |
| 245 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
| 246 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
| 247 | } else if (IS_VALLEYVIEW(connector->dev)) { |
| 248 | hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe); |
| 249 | aud_config = VLV_AUD_CFG(pipe); |
| 250 | aud_cntl_st = VLV_AUD_CNTL_ST(pipe); |
| 251 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
| 252 | } else { |
| 253 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 254 | aud_config = CPT_AUD_CFG(pipe); |
| 255 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
| 256 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
| 257 | } |
| 258 | |
| 259 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
| 260 | |
| 261 | if (IS_VALLEYVIEW(connector->dev)) { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 262 | struct intel_digital_port *intel_dig_port; |
| 263 | |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 264 | intel_dig_port = enc_to_dig_port(&encoder->base); |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 265 | port = intel_dig_port->port; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 266 | } else { |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 267 | tmp = I915_READ(aud_cntl_st); |
| 268 | port = (tmp >> 29) & DIP_PORT_SEL_MASK; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 269 | /* DIP_Port_Select, 0x1 = PortB */ |
| 270 | } |
| 271 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 272 | if (!port) { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 273 | DRM_DEBUG_DRIVER("Audio directed to unknown port\n"); |
| 274 | /* operate blindly on all ports */ |
| 275 | eldv = IBX_ELD_VALIDB; |
| 276 | eldv |= IBX_ELD_VALIDB << 4; |
| 277 | eldv |= IBX_ELD_VALIDB << 8; |
| 278 | } else { |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 279 | DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(port)); |
| 280 | eldv = IBX_ELD_VALIDB << ((port - 1) * 4); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 281 | } |
| 282 | |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 283 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 284 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 285 | else |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 286 | I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode)); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 287 | |
| 288 | if (intel_eld_uptodate(connector, |
| 289 | aud_cntrl_st2, eldv, |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame^] | 290 | aud_cntl_st, IBX_ELD_ADDRESS_MASK, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 291 | hdmiw_hdmiedid)) |
| 292 | return; |
| 293 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 294 | tmp = I915_READ(aud_cntrl_st2); |
| 295 | tmp &= ~eldv; |
| 296 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 297 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 298 | tmp = I915_READ(aud_cntl_st); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame^] | 299 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 300 | I915_WRITE(aud_cntl_st, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 301 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 302 | len = min_t(int, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 303 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 304 | for (i = 0; i < len; i++) |
| 305 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 306 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 307 | tmp = I915_READ(aud_cntrl_st2); |
| 308 | tmp |= eldv; |
| 309 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 310 | } |
| 311 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 312 | /** |
| 313 | * intel_audio_codec_enable - Enable the audio codec for HD audio |
| 314 | * @intel_encoder: encoder on which to enable audio |
| 315 | * |
| 316 | * The enable sequences may only be performed after enabling the transcoder and |
| 317 | * port, and after completed link training. |
| 318 | */ |
| 319 | void intel_audio_codec_enable(struct intel_encoder *intel_encoder) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 320 | { |
Jani Nikula | 33d1e7c6 | 2014-10-27 16:26:46 +0200 | [diff] [blame] | 321 | struct drm_encoder *encoder = &intel_encoder->base; |
| 322 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
| 323 | struct drm_display_mode *mode = &crtc->config.adjusted_mode; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 324 | struct drm_connector *connector; |
| 325 | struct drm_device *dev = encoder->dev; |
| 326 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 327 | |
| 328 | connector = drm_select_eld(encoder, mode); |
| 329 | if (!connector) |
| 330 | return; |
| 331 | |
| 332 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 333 | connector->base.id, |
| 334 | connector->name, |
| 335 | connector->encoder->base.id, |
| 336 | connector->encoder->name); |
| 337 | |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 338 | /* ELD Conn_Type */ |
| 339 | connector->eld[5] &= ~(3 << 2); |
| 340 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 341 | connector->eld[5] |= (1 << 2); |
| 342 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 343 | connector->eld[6] = drm_av_sync_delay(connector, mode) / 2; |
| 344 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 345 | if (dev_priv->display.audio_codec_enable) |
| 346 | dev_priv->display.audio_codec_enable(connector, intel_encoder, mode); |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * intel_audio_codec_disable - Disable the audio codec for HD audio |
| 351 | * @encoder: encoder on which to disable audio |
| 352 | * |
| 353 | * The disable sequences must be performed before disabling the transcoder or |
| 354 | * port. |
| 355 | */ |
| 356 | void intel_audio_codec_disable(struct intel_encoder *encoder) |
| 357 | { |
| 358 | struct drm_device *dev = encoder->base.dev; |
| 359 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 360 | |
| 361 | if (dev_priv->display.audio_codec_disable) |
| 362 | dev_priv->display.audio_codec_disable(encoder); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | /** |
| 366 | * intel_init_audio - Set up chip specific audio functions |
| 367 | * @dev: drm device |
| 368 | */ |
| 369 | void intel_init_audio(struct drm_device *dev) |
| 370 | { |
| 371 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 372 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 373 | if (IS_G4X(dev)) { |
| 374 | dev_priv->display.audio_codec_enable = g4x_audio_codec_enable; |
| 375 | } else if (IS_VALLEYVIEW(dev)) { |
| 376 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
| 377 | } else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) { |
| 378 | dev_priv->display.audio_codec_enable = hsw_audio_codec_enable; |
| 379 | dev_priv->display.audio_codec_disable = hsw_audio_codec_disable; |
| 380 | } else if (HAS_PCH_SPLIT(dev)) { |
| 381 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
| 382 | } |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 383 | } |