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> |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 25 | #include <linux/component.h> |
| 26 | #include <drm/i915_component.h> |
| 27 | #include "intel_drv.h" |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 28 | |
| 29 | #include <drm/drmP.h> |
| 30 | #include <drm/drm_edid.h> |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 31 | #include "i915_drv.h" |
| 32 | |
Jani Nikula | 28855d2 | 2014-10-27 16:27:00 +0200 | [diff] [blame] | 33 | /** |
| 34 | * DOC: High Definition Audio over HDMI and Display Port |
| 35 | * |
| 36 | * The graphics and audio drivers together support High Definition Audio over |
| 37 | * HDMI and Display Port. The audio programming sequences are divided into audio |
| 38 | * codec and controller enable and disable sequences. The graphics driver |
| 39 | * handles the audio codec sequences, while the audio driver handles the audio |
| 40 | * controller sequences. |
| 41 | * |
| 42 | * The disable sequences must be performed before disabling the transcoder or |
| 43 | * port. The enable sequences may only be performed after enabling the |
Jani Nikula | 3e6da4a | 2015-07-02 16:05:27 +0300 | [diff] [blame] | 44 | * transcoder and port, and after completed link training. Therefore the audio |
| 45 | * enable/disable sequences are part of the modeset sequence. |
Jani Nikula | 28855d2 | 2014-10-27 16:27:00 +0200 | [diff] [blame] | 46 | * |
| 47 | * The codec and controller sequences could be done either parallel or serial, |
| 48 | * but generally the ELDV/PD change in the codec sequence indicates to the audio |
| 49 | * driver that the controller sequence should start. Indeed, most of the |
| 50 | * co-operation between the graphics and audio drivers is handled via audio |
| 51 | * related registers. (The notable exception is the power management, not |
| 52 | * covered here.) |
| 53 | */ |
| 54 | |
Jani Nikula | 87fcb2a | 2014-10-27 16:26:44 +0200 | [diff] [blame] | 55 | static const struct { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 56 | int clock; |
| 57 | u32 config; |
| 58 | } hdmi_audio_clock[] = { |
| 59 | { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 }, |
| 60 | { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */ |
| 61 | { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 }, |
| 62 | { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 }, |
| 63 | { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 }, |
| 64 | { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 }, |
| 65 | { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 }, |
| 66 | { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 }, |
| 67 | { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 }, |
| 68 | { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 }, |
| 69 | }; |
| 70 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 71 | /* HDMI N/CTS table */ |
| 72 | #define TMDS_297M 297000 |
| 73 | #define TMDS_296M DIV_ROUND_UP(297000 * 1000, 1001) |
| 74 | static const struct { |
| 75 | int sample_rate; |
| 76 | int clock; |
| 77 | int n; |
| 78 | int cts; |
| 79 | } aud_ncts[] = { |
| 80 | { 44100, TMDS_296M, 4459, 234375 }, |
| 81 | { 44100, TMDS_297M, 4704, 247500 }, |
| 82 | { 48000, TMDS_296M, 5824, 281250 }, |
| 83 | { 48000, TMDS_297M, 5120, 247500 }, |
| 84 | { 32000, TMDS_296M, 5824, 421875 }, |
| 85 | { 32000, TMDS_297M, 3072, 222750 }, |
| 86 | { 88200, TMDS_296M, 8918, 234375 }, |
| 87 | { 88200, TMDS_297M, 9408, 247500 }, |
| 88 | { 96000, TMDS_296M, 11648, 281250 }, |
| 89 | { 96000, TMDS_297M, 10240, 247500 }, |
| 90 | { 176400, TMDS_296M, 17836, 234375 }, |
| 91 | { 176400, TMDS_297M, 18816, 247500 }, |
| 92 | { 192000, TMDS_296M, 23296, 281250 }, |
| 93 | { 192000, TMDS_297M, 20480, 247500 }, |
| 94 | }; |
| 95 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 96 | /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */ |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 97 | static u32 audio_config_hdmi_pixel_clock(const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 98 | { |
| 99 | int i; |
| 100 | |
| 101 | for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) { |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 102 | if (adjusted_mode->crtc_clock == hdmi_audio_clock[i].clock) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 103 | break; |
| 104 | } |
| 105 | |
| 106 | if (i == ARRAY_SIZE(hdmi_audio_clock)) { |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 107 | DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 108 | adjusted_mode->crtc_clock); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 109 | i = 1; |
| 110 | } |
| 111 | |
| 112 | DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n", |
| 113 | hdmi_audio_clock[i].clock, |
| 114 | hdmi_audio_clock[i].config); |
| 115 | |
| 116 | return hdmi_audio_clock[i].config; |
| 117 | } |
| 118 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 119 | static int audio_config_get_n(const struct drm_display_mode *mode, int rate) |
| 120 | { |
| 121 | int i; |
| 122 | |
| 123 | for (i = 0; i < ARRAY_SIZE(aud_ncts); i++) { |
| 124 | if ((rate == aud_ncts[i].sample_rate) && |
| 125 | (mode->clock == aud_ncts[i].clock)) { |
| 126 | return aud_ncts[i].n; |
| 127 | } |
| 128 | } |
| 129 | return 0; |
| 130 | } |
| 131 | |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 132 | static uint32_t audio_config_setup_n_reg(int n, uint32_t val) |
| 133 | { |
| 134 | int n_low, n_up; |
| 135 | uint32_t tmp = val; |
| 136 | |
| 137 | n_low = n & 0xfff; |
| 138 | n_up = (n >> 12) & 0xff; |
| 139 | tmp &= ~(AUD_CONFIG_UPPER_N_MASK | AUD_CONFIG_LOWER_N_MASK); |
| 140 | tmp |= ((n_up << AUD_CONFIG_UPPER_N_SHIFT) | |
| 141 | (n_low << AUD_CONFIG_LOWER_N_SHIFT) | |
| 142 | AUD_CONFIG_N_PROG_ENABLE); |
| 143 | return tmp; |
| 144 | } |
| 145 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 146 | /* check whether N/CTS/M need be set manually */ |
| 147 | static bool audio_rate_need_prog(struct intel_crtc *crtc, |
Takashi Iwai | 87f77ef | 2015-09-30 09:39:01 +0200 | [diff] [blame] | 148 | const struct drm_display_mode *mode) |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 149 | { |
| 150 | if (((mode->clock == TMDS_297M) || |
| 151 | (mode->clock == TMDS_296M)) && |
| 152 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
| 153 | return true; |
| 154 | else |
| 155 | return false; |
| 156 | } |
| 157 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 158 | static bool intel_eld_uptodate(struct drm_connector *connector, |
| 159 | int reg_eldv, uint32_t bits_eldv, |
| 160 | int reg_elda, uint32_t bits_elda, |
| 161 | int reg_edid) |
| 162 | { |
| 163 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 164 | uint8_t *eld = connector->eld; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 165 | uint32_t tmp; |
| 166 | int i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 167 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 168 | tmp = I915_READ(reg_eldv); |
| 169 | tmp &= bits_eldv; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 170 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 171 | if (!tmp) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 172 | return false; |
| 173 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 174 | tmp = I915_READ(reg_elda); |
| 175 | tmp &= ~bits_elda; |
| 176 | I915_WRITE(reg_elda, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 177 | |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 178 | for (i = 0; i < drm_eld_size(eld) / 4; i++) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 179 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 180 | return false; |
| 181 | |
| 182 | return true; |
| 183 | } |
| 184 | |
Jani Nikula | 76d8d3e | 2014-10-27 16:26:57 +0200 | [diff] [blame] | 185 | static void g4x_audio_codec_disable(struct intel_encoder *encoder) |
| 186 | { |
| 187 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 188 | uint32_t eldv, tmp; |
| 189 | |
| 190 | DRM_DEBUG_KMS("Disable audio codec\n"); |
| 191 | |
| 192 | tmp = I915_READ(G4X_AUD_VID_DID); |
| 193 | if (tmp == INTEL_AUDIO_DEVBLC || tmp == INTEL_AUDIO_DEVCL) |
| 194 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 195 | else |
| 196 | eldv = G4X_ELDV_DEVCTG; |
| 197 | |
| 198 | /* Invalidate ELD */ |
| 199 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
| 200 | tmp &= ~eldv; |
| 201 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
| 202 | } |
| 203 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 204 | static void g4x_audio_codec_enable(struct drm_connector *connector, |
| 205 | struct intel_encoder *encoder, |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 206 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 207 | { |
| 208 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 209 | uint8_t *eld = connector->eld; |
| 210 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 211 | uint32_t tmp; |
| 212 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 213 | |
Jani Nikula | d5ee08d | 2014-10-27 16:26:58 +0200 | [diff] [blame] | 214 | DRM_DEBUG_KMS("Enable audio codec, %u bytes ELD\n", eld[2]); |
| 215 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 216 | tmp = I915_READ(G4X_AUD_VID_DID); |
| 217 | if (tmp == INTEL_AUDIO_DEVBLC || tmp == INTEL_AUDIO_DEVCL) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 218 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 219 | else |
| 220 | eldv = G4X_ELDV_DEVCTG; |
| 221 | |
| 222 | if (intel_eld_uptodate(connector, |
| 223 | G4X_AUD_CNTL_ST, eldv, |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 224 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR_MASK, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 225 | G4X_HDMIW_HDMIEDID)) |
| 226 | return; |
| 227 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 228 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 229 | tmp &= ~(eldv | G4X_ELD_ADDR_MASK); |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 230 | len = (tmp >> 9) & 0x1f; /* ELD buffer size */ |
| 231 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 232 | |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 233 | len = min(drm_eld_size(eld) / 4, len); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 234 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 235 | for (i = 0; i < len; i++) |
| 236 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 237 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 238 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
| 239 | tmp |= eldv; |
| 240 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 243 | static void hsw_audio_codec_disable(struct intel_encoder *encoder) |
| 244 | { |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 245 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 246 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 247 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 248 | uint32_t tmp; |
| 249 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 250 | DRM_DEBUG_KMS("Disable audio codec on pipe %c\n", pipe_name(pipe)); |
| 251 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 252 | mutex_lock(&dev_priv->av_mutex); |
| 253 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 254 | /* Disable timestamps */ |
| 255 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 256 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 257 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 258 | tmp &= ~AUD_CONFIG_UPPER_N_MASK; |
| 259 | tmp &= ~AUD_CONFIG_LOWER_N_MASK; |
| 260 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 261 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 262 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
| 263 | |
| 264 | /* Invalidate ELD */ |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 265 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 266 | tmp &= ~AUDIO_ELD_VALID(pipe); |
Jani Nikula | eb45fa0 | 2014-11-18 12:11:29 +0200 | [diff] [blame] | 267 | tmp &= ~AUDIO_OUTPUT_ENABLE(pipe); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 268 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 269 | |
| 270 | mutex_unlock(&dev_priv->av_mutex); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static void hsw_audio_codec_enable(struct drm_connector *connector, |
| 274 | struct intel_encoder *encoder, |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 275 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 276 | { |
| 277 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 278 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 279 | enum pipe pipe = intel_crtc->pipe; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 280 | struct i915_audio_component *acomp = dev_priv->audio_component; |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 281 | const uint8_t *eld = connector->eld; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 282 | struct intel_digital_port *intel_dig_port = |
| 283 | enc_to_dig_port(&encoder->base); |
| 284 | enum port port = intel_dig_port->port; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 285 | uint32_t tmp; |
| 286 | int len, i; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 287 | int n, rate; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 288 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 289 | DRM_DEBUG_KMS("Enable audio codec on pipe %c, %u bytes ELD\n", |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 290 | pipe_name(pipe), drm_eld_size(eld)); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 291 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 292 | mutex_lock(&dev_priv->av_mutex); |
| 293 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 294 | /* Enable audio presence detect, invalidate ELD */ |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 295 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 296 | tmp |= AUDIO_OUTPUT_ENABLE(pipe); |
| 297 | tmp &= ~AUDIO_ELD_VALID(pipe); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 298 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 299 | |
| 300 | /* |
| 301 | * FIXME: We're supposed to wait for vblank here, but we have vblanks |
| 302 | * disabled during the mode set. The proper fix would be to push the |
| 303 | * rest of the setup into a vblank work item, queued here, but the |
| 304 | * infrastructure is not there yet. |
| 305 | */ |
| 306 | |
| 307 | /* Reset ELD write address */ |
| 308 | tmp = I915_READ(HSW_AUD_DIP_ELD_CTRL(pipe)); |
| 309 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
| 310 | I915_WRITE(HSW_AUD_DIP_ELD_CTRL(pipe), tmp); |
| 311 | |
| 312 | /* Up to 84 bytes of hw ELD buffer */ |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 313 | len = min(drm_eld_size(eld), 84); |
| 314 | for (i = 0; i < len / 4; i++) |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 315 | I915_WRITE(HSW_AUD_EDID_DATA(pipe), *((uint32_t *)eld + i)); |
| 316 | |
| 317 | /* ELD valid */ |
| 318 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 319 | tmp |= AUDIO_ELD_VALID(pipe); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 320 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
| 321 | |
| 322 | /* Enable timestamps */ |
| 323 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 324 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 325 | tmp &= ~AUD_CONFIG_PIXEL_CLOCK_HDMI_MASK; |
| 326 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 327 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 328 | else |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 329 | tmp |= audio_config_hdmi_pixel_clock(adjusted_mode); |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 330 | |
| 331 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
Daniel Vetter | 2844659 | 2015-10-07 15:34:15 +0200 | [diff] [blame^] | 332 | if (audio_rate_need_prog(intel_crtc, adjusted_mode)) { |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 333 | if (!acomp) |
| 334 | rate = 0; |
| 335 | else if (port >= PORT_A && port <= PORT_E) |
| 336 | rate = acomp->aud_sample_rate[port]; |
| 337 | else { |
| 338 | DRM_ERROR("invalid port: %d\n", port); |
| 339 | rate = 0; |
| 340 | } |
Daniel Vetter | 2844659 | 2015-10-07 15:34:15 +0200 | [diff] [blame^] | 341 | n = audio_config_get_n(adjusted_mode, rate); |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 342 | if (n != 0) |
| 343 | tmp = audio_config_setup_n_reg(n, tmp); |
| 344 | else |
| 345 | DRM_DEBUG_KMS("no suitable N value is found\n"); |
| 346 | } |
| 347 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 348 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 349 | |
| 350 | mutex_unlock(&dev_priv->av_mutex); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 351 | } |
| 352 | |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 353 | static void ilk_audio_codec_disable(struct intel_encoder *encoder) |
| 354 | { |
| 355 | struct drm_i915_private *dev_priv = encoder->base.dev->dev_private; |
| 356 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 357 | struct intel_digital_port *intel_dig_port = |
| 358 | enc_to_dig_port(&encoder->base); |
| 359 | enum port port = intel_dig_port->port; |
| 360 | enum pipe pipe = intel_crtc->pipe; |
| 361 | uint32_t tmp, eldv; |
| 362 | int aud_config; |
| 363 | int aud_cntrl_st2; |
| 364 | |
| 365 | DRM_DEBUG_KMS("Disable audio codec on port %c, pipe %c\n", |
| 366 | port_name(port), pipe_name(pipe)); |
| 367 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 368 | if (WARN_ON(port == PORT_A)) |
| 369 | return; |
| 370 | |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 371 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 372 | aud_config = IBX_AUD_CFG(pipe); |
| 373 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
| 374 | } else if (IS_VALLEYVIEW(dev_priv)) { |
| 375 | aud_config = VLV_AUD_CFG(pipe); |
| 376 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
| 377 | } else { |
| 378 | aud_config = CPT_AUD_CFG(pipe); |
| 379 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
| 380 | } |
| 381 | |
| 382 | /* Disable timestamps */ |
| 383 | tmp = I915_READ(aud_config); |
| 384 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 385 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 386 | tmp &= ~AUD_CONFIG_UPPER_N_MASK; |
| 387 | tmp &= ~AUD_CONFIG_LOWER_N_MASK; |
| 388 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 389 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 390 | I915_WRITE(aud_config, tmp); |
| 391 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 392 | eldv = IBX_ELD_VALID(port); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 393 | |
| 394 | /* Invalidate ELD */ |
| 395 | tmp = I915_READ(aud_cntrl_st2); |
| 396 | tmp &= ~eldv; |
| 397 | I915_WRITE(aud_cntrl_st2, tmp); |
| 398 | } |
| 399 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 400 | static void ilk_audio_codec_enable(struct drm_connector *connector, |
| 401 | struct intel_encoder *encoder, |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 402 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 403 | { |
| 404 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
Jani Nikula | 820d2d7 | 2014-10-27 16:26:47 +0200 | [diff] [blame] | 405 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 406 | struct intel_digital_port *intel_dig_port = |
| 407 | enc_to_dig_port(&encoder->base); |
| 408 | enum port port = intel_dig_port->port; |
| 409 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 410 | uint8_t *eld = connector->eld; |
| 411 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 412 | uint32_t tmp; |
| 413 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 414 | int hdmiw_hdmiedid; |
| 415 | int aud_config; |
| 416 | int aud_cntl_st; |
| 417 | int aud_cntrl_st2; |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 418 | |
| 419 | DRM_DEBUG_KMS("Enable audio codec on port %c, pipe %c, %u bytes ELD\n", |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 420 | port_name(port), pipe_name(pipe), drm_eld_size(eld)); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 421 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 422 | if (WARN_ON(port == PORT_A)) |
| 423 | return; |
| 424 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 425 | /* |
| 426 | * FIXME: We're supposed to wait for vblank here, but we have vblanks |
| 427 | * disabled during the mode set. The proper fix would be to push the |
| 428 | * rest of the setup into a vblank work item, queued here, but the |
| 429 | * infrastructure is not there yet. |
| 430 | */ |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 431 | |
| 432 | if (HAS_PCH_IBX(connector->dev)) { |
| 433 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 434 | aud_config = IBX_AUD_CFG(pipe); |
| 435 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
| 436 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
| 437 | } else if (IS_VALLEYVIEW(connector->dev)) { |
| 438 | hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe); |
| 439 | aud_config = VLV_AUD_CFG(pipe); |
| 440 | aud_cntl_st = VLV_AUD_CNTL_ST(pipe); |
| 441 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
| 442 | } else { |
| 443 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 444 | aud_config = CPT_AUD_CFG(pipe); |
| 445 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
| 446 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
| 447 | } |
| 448 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 449 | eldv = IBX_ELD_VALID(port); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 450 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 451 | /* Invalidate ELD */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 452 | tmp = I915_READ(aud_cntrl_st2); |
| 453 | tmp &= ~eldv; |
| 454 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 455 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 456 | /* Reset ELD write address */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 457 | tmp = I915_READ(aud_cntl_st); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 458 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 459 | I915_WRITE(aud_cntl_st, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 460 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 461 | /* Up to 84 bytes of hw ELD buffer */ |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 462 | len = min(drm_eld_size(eld), 84); |
| 463 | for (i = 0; i < len / 4; i++) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 464 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 465 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 466 | /* ELD valid */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 467 | tmp = I915_READ(aud_cntrl_st2); |
| 468 | tmp |= eldv; |
| 469 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 470 | |
| 471 | /* Enable timestamps */ |
| 472 | tmp = I915_READ(aud_config); |
| 473 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 474 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
| 475 | tmp &= ~AUD_CONFIG_PIXEL_CLOCK_HDMI_MASK; |
| 476 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 477 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 478 | else |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 479 | tmp |= audio_config_hdmi_pixel_clock(adjusted_mode); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 480 | I915_WRITE(aud_config, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 483 | /** |
| 484 | * intel_audio_codec_enable - Enable the audio codec for HD audio |
| 485 | * @intel_encoder: encoder on which to enable audio |
| 486 | * |
| 487 | * The enable sequences may only be performed after enabling the transcoder and |
| 488 | * port, and after completed link training. |
| 489 | */ |
| 490 | void intel_audio_codec_enable(struct intel_encoder *intel_encoder) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 491 | { |
Jani Nikula | 33d1e7c6 | 2014-10-27 16:26:46 +0200 | [diff] [blame] | 492 | struct drm_encoder *encoder = &intel_encoder->base; |
| 493 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
Ville Syrjälä | 7c5f93b | 2015-09-08 13:40:49 +0300 | [diff] [blame] | 494 | const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 495 | struct drm_connector *connector; |
| 496 | struct drm_device *dev = encoder->dev; |
| 497 | struct drm_i915_private *dev_priv = dev->dev_private; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 498 | struct i915_audio_component *acomp = dev_priv->audio_component; |
| 499 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 500 | enum port port = intel_dig_port->port; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 501 | |
Ville Syrjälä | 9e5a3b5 | 2015-09-07 18:22:57 +0300 | [diff] [blame] | 502 | connector = drm_select_eld(encoder); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 503 | if (!connector) |
| 504 | return; |
| 505 | |
| 506 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 507 | connector->base.id, |
| 508 | connector->name, |
| 509 | connector->encoder->base.id, |
| 510 | connector->encoder->name); |
| 511 | |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 512 | /* ELD Conn_Type */ |
| 513 | connector->eld[5] &= ~(3 << 2); |
| 514 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 515 | connector->eld[5] |= (1 << 2); |
| 516 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 517 | connector->eld[6] = drm_av_sync_delay(connector, adjusted_mode) / 2; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 518 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 519 | if (dev_priv->display.audio_codec_enable) |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 520 | dev_priv->display.audio_codec_enable(connector, intel_encoder, |
| 521 | adjusted_mode); |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 522 | |
| 523 | if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) |
David Henningsson | f0675d4 | 2015-09-03 11:51:34 +0200 | [diff] [blame] | 524 | acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr, (int) port); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /** |
| 528 | * intel_audio_codec_disable - Disable the audio codec for HD audio |
Geliang Tang | 95d0be6 | 2015-09-15 06:04:36 -0700 | [diff] [blame] | 529 | * @intel_encoder: encoder on which to disable audio |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 530 | * |
| 531 | * The disable sequences must be performed before disabling the transcoder or |
| 532 | * port. |
| 533 | */ |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 534 | void intel_audio_codec_disable(struct intel_encoder *intel_encoder) |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 535 | { |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 536 | struct drm_encoder *encoder = &intel_encoder->base; |
| 537 | struct drm_device *dev = encoder->dev; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 538 | struct drm_i915_private *dev_priv = dev->dev_private; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 539 | struct i915_audio_component *acomp = dev_priv->audio_component; |
| 540 | struct intel_digital_port *intel_dig_port = enc_to_dig_port(encoder); |
| 541 | enum port port = intel_dig_port->port; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 542 | |
| 543 | if (dev_priv->display.audio_codec_disable) |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 544 | dev_priv->display.audio_codec_disable(intel_encoder); |
| 545 | |
| 546 | if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) |
David Henningsson | f0675d4 | 2015-09-03 11:51:34 +0200 | [diff] [blame] | 547 | acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr, (int) port); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | /** |
| 551 | * intel_init_audio - Set up chip specific audio functions |
| 552 | * @dev: drm device |
| 553 | */ |
| 554 | void intel_init_audio(struct drm_device *dev) |
| 555 | { |
| 556 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 557 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 558 | if (IS_G4X(dev)) { |
| 559 | dev_priv->display.audio_codec_enable = g4x_audio_codec_enable; |
Jani Nikula | 76d8d3e | 2014-10-27 16:26:57 +0200 | [diff] [blame] | 560 | dev_priv->display.audio_codec_disable = g4x_audio_codec_disable; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 561 | } else if (IS_VALLEYVIEW(dev)) { |
| 562 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 563 | dev_priv->display.audio_codec_disable = ilk_audio_codec_disable; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 564 | } else if (IS_HASWELL(dev) || INTEL_INFO(dev)->gen >= 8) { |
| 565 | dev_priv->display.audio_codec_enable = hsw_audio_codec_enable; |
| 566 | dev_priv->display.audio_codec_disable = hsw_audio_codec_disable; |
| 567 | } else if (HAS_PCH_SPLIT(dev)) { |
| 568 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 569 | dev_priv->display.audio_codec_disable = ilk_audio_codec_disable; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 570 | } |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 571 | } |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 572 | |
| 573 | static void i915_audio_component_get_power(struct device *dev) |
| 574 | { |
| 575 | intel_display_power_get(dev_to_i915(dev), POWER_DOMAIN_AUDIO); |
| 576 | } |
| 577 | |
| 578 | static void i915_audio_component_put_power(struct device *dev) |
| 579 | { |
| 580 | intel_display_power_put(dev_to_i915(dev), POWER_DOMAIN_AUDIO); |
| 581 | } |
| 582 | |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 583 | static void i915_audio_component_codec_wake_override(struct device *dev, |
| 584 | bool enable) |
| 585 | { |
| 586 | struct drm_i915_private *dev_priv = dev_to_i915(dev); |
| 587 | u32 tmp; |
| 588 | |
| 589 | if (!IS_SKYLAKE(dev_priv)) |
| 590 | return; |
| 591 | |
| 592 | /* |
| 593 | * Enable/disable generating the codec wake signal, overriding the |
| 594 | * internal logic to generate the codec wake to controller. |
| 595 | */ |
| 596 | tmp = I915_READ(HSW_AUD_CHICKENBIT); |
| 597 | tmp &= ~SKL_AUD_CODEC_WAKE_SIGNAL; |
| 598 | I915_WRITE(HSW_AUD_CHICKENBIT, tmp); |
| 599 | usleep_range(1000, 1500); |
| 600 | |
| 601 | if (enable) { |
| 602 | tmp = I915_READ(HSW_AUD_CHICKENBIT); |
| 603 | tmp |= SKL_AUD_CODEC_WAKE_SIGNAL; |
| 604 | I915_WRITE(HSW_AUD_CHICKENBIT, tmp); |
| 605 | usleep_range(1000, 1500); |
| 606 | } |
| 607 | } |
| 608 | |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 609 | /* Get CDCLK in kHz */ |
| 610 | static int i915_audio_component_get_cdclk_freq(struct device *dev) |
| 611 | { |
| 612 | struct drm_i915_private *dev_priv = dev_to_i915(dev); |
| 613 | int ret; |
| 614 | |
| 615 | if (WARN_ON_ONCE(!HAS_DDI(dev_priv))) |
| 616 | return -ENODEV; |
| 617 | |
| 618 | intel_display_power_get(dev_priv, POWER_DOMAIN_AUDIO); |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 619 | ret = dev_priv->display.get_display_clock_speed(dev_priv->dev); |
| 620 | |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 621 | intel_display_power_put(dev_priv, POWER_DOMAIN_AUDIO); |
| 622 | |
| 623 | return ret; |
| 624 | } |
| 625 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 626 | static int i915_audio_component_sync_audio_rate(struct device *dev, |
| 627 | int port, int rate) |
| 628 | { |
| 629 | struct drm_i915_private *dev_priv = dev_to_i915(dev); |
| 630 | struct drm_device *drm_dev = dev_priv->dev; |
| 631 | struct intel_encoder *intel_encoder; |
| 632 | struct intel_digital_port *intel_dig_port; |
| 633 | struct intel_crtc *crtc; |
| 634 | struct drm_display_mode *mode; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 635 | struct i915_audio_component *acomp = dev_priv->audio_component; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 636 | enum pipe pipe = -1; |
| 637 | u32 tmp; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 638 | int n; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 639 | |
| 640 | /* HSW, BDW SKL need this fix */ |
| 641 | if (!IS_SKYLAKE(dev_priv) && |
| 642 | !IS_BROADWELL(dev_priv) && |
| 643 | !IS_HASWELL(dev_priv)) |
| 644 | return 0; |
| 645 | |
| 646 | mutex_lock(&dev_priv->av_mutex); |
| 647 | /* 1. get the pipe */ |
| 648 | for_each_intel_encoder(drm_dev, intel_encoder) { |
| 649 | if (intel_encoder->type != INTEL_OUTPUT_HDMI) |
| 650 | continue; |
| 651 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 652 | if (port == intel_dig_port->port) { |
| 653 | crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 654 | if (!crtc) { |
| 655 | DRM_DEBUG_KMS("%s: crtc is NULL\n", __func__); |
| 656 | continue; |
| 657 | } |
| 658 | pipe = crtc->pipe; |
| 659 | break; |
| 660 | } |
| 661 | } |
| 662 | |
| 663 | if (pipe == INVALID_PIPE) { |
| 664 | DRM_DEBUG_KMS("no pipe for the port %c\n", port_name(port)); |
| 665 | mutex_unlock(&dev_priv->av_mutex); |
| 666 | return -ENODEV; |
| 667 | } |
| 668 | DRM_DEBUG_KMS("pipe %c connects port %c\n", |
| 669 | pipe_name(pipe), port_name(port)); |
| 670 | mode = &crtc->config->base.adjusted_mode; |
| 671 | |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 672 | /* port must be valid now, otherwise the pipe will be invalid */ |
| 673 | acomp->aud_sample_rate[port] = rate; |
| 674 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 675 | /* 2. check whether to set the N/CTS/M manually or not */ |
| 676 | if (!audio_rate_need_prog(crtc, mode)) { |
| 677 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 678 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
| 679 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
| 680 | mutex_unlock(&dev_priv->av_mutex); |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | n = audio_config_get_n(mode, rate); |
| 685 | if (n == 0) { |
| 686 | DRM_DEBUG_KMS("Using automatic mode for N value on port %c\n", |
| 687 | port_name(port)); |
| 688 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 689 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
| 690 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
| 691 | mutex_unlock(&dev_priv->av_mutex); |
| 692 | return 0; |
| 693 | } |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 694 | |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 695 | /* 3. set the N/CTS/M */ |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 696 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 697 | tmp = audio_config_setup_n_reg(n, tmp); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 698 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
| 699 | |
| 700 | mutex_unlock(&dev_priv->av_mutex); |
| 701 | return 0; |
| 702 | } |
| 703 | |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 704 | static const struct i915_audio_component_ops i915_audio_component_ops = { |
| 705 | .owner = THIS_MODULE, |
| 706 | .get_power = i915_audio_component_get_power, |
| 707 | .put_power = i915_audio_component_put_power, |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 708 | .codec_wake_override = i915_audio_component_codec_wake_override, |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 709 | .get_cdclk_freq = i915_audio_component_get_cdclk_freq, |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 710 | .sync_audio_rate = i915_audio_component_sync_audio_rate, |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 711 | }; |
| 712 | |
| 713 | static int i915_audio_component_bind(struct device *i915_dev, |
| 714 | struct device *hda_dev, void *data) |
| 715 | { |
| 716 | struct i915_audio_component *acomp = data; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 717 | struct drm_i915_private *dev_priv = dev_to_i915(i915_dev); |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 718 | int i; |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 719 | |
| 720 | if (WARN_ON(acomp->ops || acomp->dev)) |
| 721 | return -EEXIST; |
| 722 | |
David Henningsson | d5f362a | 2015-09-03 11:51:35 +0200 | [diff] [blame] | 723 | drm_modeset_lock_all(dev_priv->dev); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 724 | acomp->ops = &i915_audio_component_ops; |
| 725 | acomp->dev = i915_dev; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 726 | BUILD_BUG_ON(MAX_PORTS != I915_MAX_PORTS); |
| 727 | for (i = 0; i < ARRAY_SIZE(acomp->aud_sample_rate); i++) |
| 728 | acomp->aud_sample_rate[i] = 0; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 729 | dev_priv->audio_component = acomp; |
David Henningsson | d5f362a | 2015-09-03 11:51:35 +0200 | [diff] [blame] | 730 | drm_modeset_unlock_all(dev_priv->dev); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 731 | |
| 732 | return 0; |
| 733 | } |
| 734 | |
| 735 | static void i915_audio_component_unbind(struct device *i915_dev, |
| 736 | struct device *hda_dev, void *data) |
| 737 | { |
| 738 | struct i915_audio_component *acomp = data; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 739 | struct drm_i915_private *dev_priv = dev_to_i915(i915_dev); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 740 | |
David Henningsson | d5f362a | 2015-09-03 11:51:35 +0200 | [diff] [blame] | 741 | drm_modeset_lock_all(dev_priv->dev); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 742 | acomp->ops = NULL; |
| 743 | acomp->dev = NULL; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 744 | dev_priv->audio_component = NULL; |
David Henningsson | d5f362a | 2015-09-03 11:51:35 +0200 | [diff] [blame] | 745 | drm_modeset_unlock_all(dev_priv->dev); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | static const struct component_ops i915_audio_component_bind_ops = { |
| 749 | .bind = i915_audio_component_bind, |
| 750 | .unbind = i915_audio_component_unbind, |
| 751 | }; |
| 752 | |
| 753 | /** |
| 754 | * i915_audio_component_init - initialize and register the audio component |
| 755 | * @dev_priv: i915 device instance |
| 756 | * |
| 757 | * This will register with the component framework a child component which |
| 758 | * will bind dynamically to the snd_hda_intel driver's corresponding master |
| 759 | * component when the latter is registered. During binding the child |
| 760 | * initializes an instance of struct i915_audio_component which it receives |
| 761 | * from the master. The master can then start to use the interface defined by |
| 762 | * this struct. Each side can break the binding at any point by deregistering |
| 763 | * its own component after which each side's component unbind callback is |
| 764 | * called. |
| 765 | * |
| 766 | * We ignore any error during registration and continue with reduced |
| 767 | * functionality (i.e. without HDMI audio). |
| 768 | */ |
| 769 | void i915_audio_component_init(struct drm_i915_private *dev_priv) |
| 770 | { |
| 771 | int ret; |
| 772 | |
| 773 | ret = component_add(dev_priv->dev->dev, &i915_audio_component_bind_ops); |
| 774 | if (ret < 0) { |
| 775 | DRM_ERROR("failed to add audio component (%d)\n", ret); |
| 776 | /* continue with reduced functionality */ |
| 777 | return; |
| 778 | } |
| 779 | |
| 780 | dev_priv->audio_component_registered = true; |
| 781 | } |
| 782 | |
| 783 | /** |
| 784 | * i915_audio_component_cleanup - deregister the audio component |
| 785 | * @dev_priv: i915 device instance |
| 786 | * |
| 787 | * Deregisters the audio component, breaking any existing binding to the |
| 788 | * corresponding snd_hda_intel driver's master component. |
| 789 | */ |
| 790 | void i915_audio_component_cleanup(struct drm_i915_private *dev_priv) |
| 791 | { |
| 792 | if (!dev_priv->audio_component_registered) |
| 793 | return; |
| 794 | |
| 795 | component_del(dev_priv->dev->dev, &i915_audio_component_bind_ops); |
| 796 | dev_priv->audio_component_registered = false; |
| 797 | } |