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.) |
Libin Yang | cb42261 | 2015-10-01 17:01:09 +0800 | [diff] [blame] | 53 | * |
Daniel Vetter | 62cacc7 | 2016-08-12 22:48:37 +0200 | [diff] [blame] | 54 | * The struct &i915_audio_component is used to interact between the graphics |
| 55 | * and audio drivers. The struct &i915_audio_component_ops @ops in it is |
Libin Yang | cb42261 | 2015-10-01 17:01:09 +0800 | [diff] [blame] | 56 | * defined in graphics driver and called in audio driver. The |
Daniel Vetter | 62cacc7 | 2016-08-12 22:48:37 +0200 | [diff] [blame] | 57 | * struct &i915_audio_component_audio_ops @audio_ops is called from i915 driver. |
Jani Nikula | 28855d2 | 2014-10-27 16:27:00 +0200 | [diff] [blame] | 58 | */ |
| 59 | |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 60 | /* DP N/M table */ |
| 61 | #define LC_540M 540000 |
| 62 | #define LC_270M 270000 |
| 63 | #define LC_162M 162000 |
| 64 | |
| 65 | struct dp_aud_n_m { |
| 66 | int sample_rate; |
| 67 | int clock; |
| 68 | u16 m; |
| 69 | u16 n; |
| 70 | }; |
| 71 | |
| 72 | /* Values according to DP 1.4 Table 2-104 */ |
| 73 | static const struct dp_aud_n_m dp_aud_n_m[] = { |
| 74 | { 32000, LC_162M, 1024, 10125 }, |
| 75 | { 44100, LC_162M, 784, 5625 }, |
| 76 | { 48000, LC_162M, 512, 3375 }, |
| 77 | { 64000, LC_162M, 2048, 10125 }, |
| 78 | { 88200, LC_162M, 1568, 5625 }, |
| 79 | { 96000, LC_162M, 1024, 3375 }, |
| 80 | { 128000, LC_162M, 4096, 10125 }, |
| 81 | { 176400, LC_162M, 3136, 5625 }, |
| 82 | { 192000, LC_162M, 2048, 3375 }, |
| 83 | { 32000, LC_270M, 1024, 16875 }, |
| 84 | { 44100, LC_270M, 784, 9375 }, |
| 85 | { 48000, LC_270M, 512, 5625 }, |
| 86 | { 64000, LC_270M, 2048, 16875 }, |
| 87 | { 88200, LC_270M, 1568, 9375 }, |
| 88 | { 96000, LC_270M, 1024, 5625 }, |
| 89 | { 128000, LC_270M, 4096, 16875 }, |
| 90 | { 176400, LC_270M, 3136, 9375 }, |
| 91 | { 192000, LC_270M, 2048, 5625 }, |
| 92 | { 32000, LC_540M, 1024, 33750 }, |
| 93 | { 44100, LC_540M, 784, 18750 }, |
| 94 | { 48000, LC_540M, 512, 11250 }, |
| 95 | { 64000, LC_540M, 2048, 33750 }, |
| 96 | { 88200, LC_540M, 1568, 18750 }, |
| 97 | { 96000, LC_540M, 1024, 11250 }, |
| 98 | { 128000, LC_540M, 4096, 33750 }, |
| 99 | { 176400, LC_540M, 3136, 18750 }, |
| 100 | { 192000, LC_540M, 2048, 11250 }, |
| 101 | }; |
| 102 | |
| 103 | static const struct dp_aud_n_m * |
| 104 | audio_config_dp_get_n_m(struct intel_crtc *intel_crtc, int rate) |
| 105 | { |
| 106 | int i; |
| 107 | |
| 108 | for (i = 0; i < ARRAY_SIZE(dp_aud_n_m); i++) { |
| 109 | if (rate == dp_aud_n_m[i].sample_rate && |
| 110 | intel_crtc->config->port_clock == dp_aud_n_m[i].clock) |
| 111 | return &dp_aud_n_m[i]; |
| 112 | } |
| 113 | |
| 114 | return NULL; |
| 115 | } |
| 116 | |
Jani Nikula | 87fcb2a | 2014-10-27 16:26:44 +0200 | [diff] [blame] | 117 | static const struct { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 118 | int clock; |
| 119 | u32 config; |
| 120 | } hdmi_audio_clock[] = { |
Ville Syrjälä | 606bb5e | 2015-10-08 11:43:34 +0300 | [diff] [blame] | 121 | { 25175, AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 }, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 122 | { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */ |
| 123 | { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 }, |
Ville Syrjälä | 606bb5e | 2015-10-08 11:43:34 +0300 | [diff] [blame] | 124 | { 27027, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 }, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 125 | { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 }, |
Ville Syrjälä | 606bb5e | 2015-10-08 11:43:34 +0300 | [diff] [blame] | 126 | { 54054, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 }, |
| 127 | { 74176, AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 }, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 128 | { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 }, |
Ville Syrjälä | 606bb5e | 2015-10-08 11:43:34 +0300 | [diff] [blame] | 129 | { 148352, AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 }, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 130 | { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 }, |
| 131 | }; |
| 132 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 133 | /* HDMI N/CTS table */ |
| 134 | #define TMDS_297M 297000 |
Ville Syrjälä | 606bb5e | 2015-10-08 11:43:34 +0300 | [diff] [blame] | 135 | #define TMDS_296M 296703 |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 136 | static const struct { |
| 137 | int sample_rate; |
| 138 | int clock; |
| 139 | int n; |
| 140 | int cts; |
Jani Nikula | 9eeb730 | 2016-10-10 18:04:07 +0300 | [diff] [blame] | 141 | } hdmi_aud_ncts[] = { |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 142 | { 44100, TMDS_296M, 4459, 234375 }, |
| 143 | { 44100, TMDS_297M, 4704, 247500 }, |
| 144 | { 48000, TMDS_296M, 5824, 281250 }, |
| 145 | { 48000, TMDS_297M, 5120, 247500 }, |
| 146 | { 32000, TMDS_296M, 5824, 421875 }, |
| 147 | { 32000, TMDS_297M, 3072, 222750 }, |
| 148 | { 88200, TMDS_296M, 8918, 234375 }, |
| 149 | { 88200, TMDS_297M, 9408, 247500 }, |
| 150 | { 96000, TMDS_296M, 11648, 281250 }, |
| 151 | { 96000, TMDS_297M, 10240, 247500 }, |
| 152 | { 176400, TMDS_296M, 17836, 234375 }, |
| 153 | { 176400, TMDS_297M, 18816, 247500 }, |
| 154 | { 192000, TMDS_296M, 23296, 281250 }, |
| 155 | { 192000, TMDS_297M, 20480, 247500 }, |
| 156 | }; |
| 157 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 158 | /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */ |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 159 | 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] | 160 | { |
| 161 | int i; |
| 162 | |
| 163 | for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) { |
Ville Syrjälä | aad941d | 2015-09-25 16:38:56 +0300 | [diff] [blame] | 164 | if (adjusted_mode->crtc_clock == hdmi_audio_clock[i].clock) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 165 | break; |
| 166 | } |
| 167 | |
| 168 | if (i == ARRAY_SIZE(hdmi_audio_clock)) { |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 169 | 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] | 170 | adjusted_mode->crtc_clock); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 171 | i = 1; |
| 172 | } |
| 173 | |
| 174 | DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n", |
| 175 | hdmi_audio_clock[i].clock, |
| 176 | hdmi_audio_clock[i].config); |
| 177 | |
| 178 | return hdmi_audio_clock[i].config; |
| 179 | } |
| 180 | |
Jani Nikula | 9eeb730 | 2016-10-10 18:04:07 +0300 | [diff] [blame] | 181 | static int audio_config_hdmi_get_n(const struct drm_display_mode *adjusted_mode, |
| 182 | int rate) |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 183 | { |
| 184 | int i; |
| 185 | |
Jani Nikula | 9eeb730 | 2016-10-10 18:04:07 +0300 | [diff] [blame] | 186 | for (i = 0; i < ARRAY_SIZE(hdmi_aud_ncts); i++) { |
| 187 | if (rate == hdmi_aud_ncts[i].sample_rate && |
| 188 | adjusted_mode->crtc_clock == hdmi_aud_ncts[i].clock) { |
| 189 | return hdmi_aud_ncts[i].n; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | return 0; |
| 193 | } |
| 194 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 195 | static bool intel_eld_uptodate(struct drm_connector *connector, |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 196 | i915_reg_t reg_eldv, uint32_t bits_eldv, |
| 197 | i915_reg_t reg_elda, uint32_t bits_elda, |
| 198 | i915_reg_t reg_edid) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 199 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 200 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 201 | uint8_t *eld = connector->eld; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 202 | uint32_t tmp; |
| 203 | int i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 204 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 205 | tmp = I915_READ(reg_eldv); |
| 206 | tmp &= bits_eldv; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 207 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 208 | if (!tmp) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 209 | return false; |
| 210 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 211 | tmp = I915_READ(reg_elda); |
| 212 | tmp &= ~bits_elda; |
| 213 | I915_WRITE(reg_elda, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 214 | |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 215 | for (i = 0; i < drm_eld_size(eld) / 4; i++) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 216 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 217 | return false; |
| 218 | |
| 219 | return true; |
| 220 | } |
| 221 | |
Jani Nikula | 76d8d3e | 2014-10-27 16:26:57 +0200 | [diff] [blame] | 222 | static void g4x_audio_codec_disable(struct intel_encoder *encoder) |
| 223 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 224 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 76d8d3e | 2014-10-27 16:26:57 +0200 | [diff] [blame] | 225 | uint32_t eldv, tmp; |
| 226 | |
| 227 | DRM_DEBUG_KMS("Disable audio codec\n"); |
| 228 | |
| 229 | tmp = I915_READ(G4X_AUD_VID_DID); |
| 230 | if (tmp == INTEL_AUDIO_DEVBLC || tmp == INTEL_AUDIO_DEVCL) |
| 231 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 232 | else |
| 233 | eldv = G4X_ELDV_DEVCTG; |
| 234 | |
| 235 | /* Invalidate ELD */ |
| 236 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
| 237 | tmp &= ~eldv; |
| 238 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
| 239 | } |
| 240 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 241 | static void g4x_audio_codec_enable(struct drm_connector *connector, |
| 242 | struct intel_encoder *encoder, |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 243 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 244 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 245 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 246 | uint8_t *eld = connector->eld; |
| 247 | uint32_t eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 248 | uint32_t tmp; |
| 249 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 250 | |
Jani Nikula | d5ee08d | 2014-10-27 16:26:58 +0200 | [diff] [blame] | 251 | DRM_DEBUG_KMS("Enable audio codec, %u bytes ELD\n", eld[2]); |
| 252 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 253 | tmp = I915_READ(G4X_AUD_VID_DID); |
| 254 | if (tmp == INTEL_AUDIO_DEVBLC || tmp == INTEL_AUDIO_DEVCL) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 255 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 256 | else |
| 257 | eldv = G4X_ELDV_DEVCTG; |
| 258 | |
| 259 | if (intel_eld_uptodate(connector, |
| 260 | G4X_AUD_CNTL_ST, eldv, |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 261 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR_MASK, |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 262 | G4X_HDMIW_HDMIEDID)) |
| 263 | return; |
| 264 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 265 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 266 | tmp &= ~(eldv | G4X_ELD_ADDR_MASK); |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 267 | len = (tmp >> 9) & 0x1f; /* ELD buffer size */ |
| 268 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 269 | |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 270 | len = min(drm_eld_size(eld) / 4, len); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 271 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 272 | for (i = 0; i < len; i++) |
| 273 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 274 | |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 275 | tmp = I915_READ(G4X_AUD_CNTL_ST); |
| 276 | tmp |= eldv; |
| 277 | I915_WRITE(G4X_AUD_CNTL_ST, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 278 | } |
| 279 | |
Jani Nikula | 12e87f2 | 2016-10-10 18:04:03 +0300 | [diff] [blame] | 280 | static void |
| 281 | hsw_dp_audio_config_update(struct intel_crtc *intel_crtc, enum port port, |
| 282 | const struct drm_display_mode *adjusted_mode) |
| 283 | { |
| 284 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 285 | struct i915_audio_component *acomp = dev_priv->audio_component; |
| 286 | int rate = acomp ? acomp->aud_sample_rate[port] : 0; |
| 287 | const struct dp_aud_n_m *nm = audio_config_dp_get_n_m(intel_crtc, rate); |
Jani Nikula | 12e87f2 | 2016-10-10 18:04:03 +0300 | [diff] [blame] | 288 | enum pipe pipe = intel_crtc->pipe; |
| 289 | u32 tmp; |
| 290 | |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 291 | if (nm) |
| 292 | DRM_DEBUG_KMS("using Maud %u, Naud %u\n", nm->m, nm->n); |
| 293 | else |
| 294 | DRM_DEBUG_KMS("using automatic Maud, Naud\n"); |
| 295 | |
Jani Nikula | 12e87f2 | 2016-10-10 18:04:03 +0300 | [diff] [blame] | 296 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 297 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 298 | tmp &= ~AUD_CONFIG_PIXEL_CLOCK_HDMI_MASK; |
| 299 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
| 300 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 301 | |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 302 | if (nm) { |
| 303 | tmp &= ~AUD_CONFIG_N_MASK; |
| 304 | tmp |= AUD_CONFIG_N(nm->n); |
| 305 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 306 | } |
| 307 | |
Jani Nikula | 12e87f2 | 2016-10-10 18:04:03 +0300 | [diff] [blame] | 308 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 309 | |
| 310 | tmp = I915_READ(HSW_AUD_M_CTS_ENABLE(pipe)); |
| 311 | tmp &= ~AUD_CONFIG_M_MASK; |
| 312 | tmp &= ~AUD_M_CTS_M_VALUE_INDEX; |
| 313 | tmp &= ~AUD_M_CTS_M_PROG_ENABLE; |
| 314 | |
| 315 | if (nm) { |
| 316 | tmp |= nm->m; |
| 317 | tmp |= AUD_M_CTS_M_VALUE_INDEX; |
| 318 | tmp |= AUD_M_CTS_M_PROG_ENABLE; |
| 319 | } |
| 320 | |
| 321 | I915_WRITE(HSW_AUD_M_CTS_ENABLE(pipe), tmp); |
Jani Nikula | 12e87f2 | 2016-10-10 18:04:03 +0300 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | static void |
| 325 | hsw_hdmi_audio_config_update(struct intel_crtc *intel_crtc, enum port port, |
| 326 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 6c26291 | 2016-10-10 18:04:00 +0300 | [diff] [blame] | 327 | { |
| 328 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 329 | struct i915_audio_component *acomp = dev_priv->audio_component; |
Jani Nikula | 3af306d | 2016-10-10 18:04:01 +0300 | [diff] [blame] | 330 | int rate = acomp ? acomp->aud_sample_rate[port] : 0; |
Jani Nikula | 6c26291 | 2016-10-10 18:04:00 +0300 | [diff] [blame] | 331 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 3af306d | 2016-10-10 18:04:01 +0300 | [diff] [blame] | 332 | int n; |
Jani Nikula | 6c26291 | 2016-10-10 18:04:00 +0300 | [diff] [blame] | 333 | u32 tmp; |
| 334 | |
| 335 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 336 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 337 | tmp &= ~AUD_CONFIG_PIXEL_CLOCK_HDMI_MASK; |
Jani Nikula | 6c26291 | 2016-10-10 18:04:00 +0300 | [diff] [blame] | 338 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
Jani Nikula | 12e87f2 | 2016-10-10 18:04:03 +0300 | [diff] [blame] | 339 | tmp |= audio_config_hdmi_pixel_clock(adjusted_mode); |
| 340 | |
Jani Nikula | 9ca89c4 | 2016-10-25 17:54:17 +0300 | [diff] [blame] | 341 | n = audio_config_hdmi_get_n(adjusted_mode, rate); |
| 342 | if (n != 0) { |
| 343 | DRM_DEBUG_KMS("using N %d\n", n); |
| 344 | |
| 345 | tmp &= ~AUD_CONFIG_N_MASK; |
| 346 | tmp |= AUD_CONFIG_N(n); |
| 347 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 348 | } else { |
| 349 | DRM_DEBUG_KMS("using automatic N\n"); |
Jani Nikula | 6c26291 | 2016-10-10 18:04:00 +0300 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 353 | |
Libin Yang | 60abfbb | 2016-11-11 16:46:28 +0800 | [diff] [blame] | 354 | /* |
| 355 | * Let's disable "Enable CTS or M Prog bit" |
| 356 | * and let HW calculate the value |
| 357 | */ |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 358 | tmp = I915_READ(HSW_AUD_M_CTS_ENABLE(pipe)); |
Libin Yang | 60abfbb | 2016-11-11 16:46:28 +0800 | [diff] [blame] | 359 | tmp &= ~AUD_M_CTS_M_PROG_ENABLE; |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 360 | tmp &= ~AUD_M_CTS_M_VALUE_INDEX; |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 361 | I915_WRITE(HSW_AUD_M_CTS_ENABLE(pipe), tmp); |
Jani Nikula | 6c26291 | 2016-10-10 18:04:00 +0300 | [diff] [blame] | 362 | } |
| 363 | |
Jani Nikula | 12e87f2 | 2016-10-10 18:04:03 +0300 | [diff] [blame] | 364 | static void |
| 365 | hsw_audio_config_update(struct intel_crtc *intel_crtc, enum port port, |
| 366 | const struct drm_display_mode *adjusted_mode) |
| 367 | { |
| 368 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
| 369 | hsw_dp_audio_config_update(intel_crtc, port, adjusted_mode); |
| 370 | else |
| 371 | hsw_hdmi_audio_config_update(intel_crtc, port, adjusted_mode); |
| 372 | } |
| 373 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 374 | static void hsw_audio_codec_disable(struct intel_encoder *encoder) |
| 375 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 376 | struct drm_i915_private *dev_priv = to_i915(encoder->base.dev); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 377 | struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc); |
| 378 | enum pipe pipe = intel_crtc->pipe; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 379 | uint32_t tmp; |
| 380 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 381 | DRM_DEBUG_KMS("Disable audio codec on pipe %c\n", pipe_name(pipe)); |
| 382 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 383 | mutex_lock(&dev_priv->av_mutex); |
| 384 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 385 | /* Disable timestamps */ |
| 386 | tmp = I915_READ(HSW_AUD_CFG(pipe)); |
| 387 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 388 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 389 | tmp &= ~AUD_CONFIG_UPPER_N_MASK; |
| 390 | tmp &= ~AUD_CONFIG_LOWER_N_MASK; |
Ville Syrjälä | 2210ce7 | 2016-06-22 21:57:05 +0300 | [diff] [blame] | 391 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 392 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 393 | I915_WRITE(HSW_AUD_CFG(pipe), tmp); |
| 394 | |
| 395 | /* Invalidate ELD */ |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 396 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 397 | tmp &= ~AUDIO_ELD_VALID(pipe); |
Jani Nikula | eb45fa0 | 2014-11-18 12:11:29 +0200 | [diff] [blame] | 398 | tmp &= ~AUDIO_OUTPUT_ENABLE(pipe); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 399 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 400 | |
| 401 | mutex_unlock(&dev_priv->av_mutex); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static void hsw_audio_codec_enable(struct drm_connector *connector, |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 405 | struct intel_encoder *intel_encoder, |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 406 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 407 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 408 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 409 | struct intel_crtc *intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 410 | enum pipe pipe = intel_crtc->pipe; |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 411 | enum port port = intel_encoder->port; |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 412 | const uint8_t *eld = connector->eld; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 413 | uint32_t tmp; |
| 414 | int len, i; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 415 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 416 | 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] | 417 | pipe_name(pipe), drm_eld_size(eld)); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 418 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 419 | mutex_lock(&dev_priv->av_mutex); |
| 420 | |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 421 | /* Enable audio presence detect, invalidate ELD */ |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 422 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 423 | tmp |= AUDIO_OUTPUT_ENABLE(pipe); |
| 424 | tmp &= ~AUDIO_ELD_VALID(pipe); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 425 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 426 | |
| 427 | /* |
| 428 | * FIXME: We're supposed to wait for vblank here, but we have vblanks |
| 429 | * disabled during the mode set. The proper fix would be to push the |
| 430 | * rest of the setup into a vblank work item, queued here, but the |
| 431 | * infrastructure is not there yet. |
| 432 | */ |
| 433 | |
| 434 | /* Reset ELD write address */ |
| 435 | tmp = I915_READ(HSW_AUD_DIP_ELD_CTRL(pipe)); |
| 436 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
| 437 | I915_WRITE(HSW_AUD_DIP_ELD_CTRL(pipe), tmp); |
| 438 | |
| 439 | /* Up to 84 bytes of hw ELD buffer */ |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 440 | len = min(drm_eld_size(eld), 84); |
| 441 | for (i = 0; i < len / 4; i++) |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 442 | I915_WRITE(HSW_AUD_EDID_DATA(pipe), *((uint32_t *)eld + i)); |
| 443 | |
| 444 | /* ELD valid */ |
| 445 | tmp = I915_READ(HSW_AUD_PIN_ELD_CP_VLD); |
Jani Nikula | 82910ac | 2014-10-27 16:26:59 +0200 | [diff] [blame] | 446 | tmp |= AUDIO_ELD_VALID(pipe); |
Jani Nikula | 5fad84a | 2014-11-04 10:30:23 +0200 | [diff] [blame] | 447 | I915_WRITE(HSW_AUD_PIN_ELD_CP_VLD, tmp); |
| 448 | |
| 449 | /* Enable timestamps */ |
Jani Nikula | 6c26291 | 2016-10-10 18:04:00 +0300 | [diff] [blame] | 450 | hsw_audio_config_update(intel_crtc, port, adjusted_mode); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 451 | |
| 452 | mutex_unlock(&dev_priv->av_mutex); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 453 | } |
| 454 | |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 455 | static void ilk_audio_codec_disable(struct intel_encoder *intel_encoder) |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 456 | { |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 457 | struct drm_i915_private *dev_priv = to_i915(intel_encoder->base.dev); |
| 458 | struct intel_crtc *intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 459 | enum pipe pipe = intel_crtc->pipe; |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 460 | enum port port = intel_encoder->port; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 461 | uint32_t tmp, eldv; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 462 | i915_reg_t aud_config, aud_cntrl_st2; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 463 | |
| 464 | DRM_DEBUG_KMS("Disable audio codec on port %c, pipe %c\n", |
| 465 | port_name(port), pipe_name(pipe)); |
| 466 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 467 | if (WARN_ON(port == PORT_A)) |
| 468 | return; |
| 469 | |
Joonas Lahtinen | 2d1fe07 | 2016-04-07 11:08:05 +0300 | [diff] [blame] | 470 | if (HAS_PCH_IBX(dev_priv)) { |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 471 | aud_config = IBX_AUD_CFG(pipe); |
| 472 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
Wayne Boyer | 666a453 | 2015-12-09 12:29:35 -0800 | [diff] [blame] | 473 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 474 | aud_config = VLV_AUD_CFG(pipe); |
| 475 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
| 476 | } else { |
| 477 | aud_config = CPT_AUD_CFG(pipe); |
| 478 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
| 479 | } |
| 480 | |
| 481 | /* Disable timestamps */ |
| 482 | tmp = I915_READ(aud_config); |
| 483 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 484 | tmp |= AUD_CONFIG_N_PROG_ENABLE; |
| 485 | tmp &= ~AUD_CONFIG_UPPER_N_MASK; |
| 486 | tmp &= ~AUD_CONFIG_LOWER_N_MASK; |
Ville Syrjälä | 2210ce7 | 2016-06-22 21:57:05 +0300 | [diff] [blame] | 487 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 488 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 489 | I915_WRITE(aud_config, tmp); |
| 490 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 491 | eldv = IBX_ELD_VALID(port); |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 492 | |
| 493 | /* Invalidate ELD */ |
| 494 | tmp = I915_READ(aud_cntrl_st2); |
| 495 | tmp &= ~eldv; |
| 496 | I915_WRITE(aud_cntrl_st2, tmp); |
| 497 | } |
| 498 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 499 | static void ilk_audio_codec_enable(struct drm_connector *connector, |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 500 | struct intel_encoder *intel_encoder, |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 501 | const struct drm_display_mode *adjusted_mode) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 502 | { |
Chris Wilson | fac5e23 | 2016-07-04 11:34:36 +0100 | [diff] [blame] | 503 | struct drm_i915_private *dev_priv = to_i915(connector->dev); |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 504 | struct intel_crtc *intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 505 | enum pipe pipe = intel_crtc->pipe; |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 506 | enum port port = intel_encoder->port; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 507 | uint8_t *eld = connector->eld; |
Pandiyan, Dhinakaran | 38cb2ec | 2016-08-10 23:41:13 -0700 | [diff] [blame] | 508 | uint32_t tmp, eldv; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 509 | int len, i; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 510 | i915_reg_t hdmiw_hdmiedid, aud_config, aud_cntl_st, aud_cntrl_st2; |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 511 | |
| 512 | 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] | 513 | port_name(port), pipe_name(pipe), drm_eld_size(eld)); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 514 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 515 | if (WARN_ON(port == PORT_A)) |
| 516 | return; |
| 517 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 518 | /* |
| 519 | * FIXME: We're supposed to wait for vblank here, but we have vblanks |
| 520 | * disabled during the mode set. The proper fix would be to push the |
| 521 | * rest of the setup into a vblank work item, queued here, but the |
| 522 | * infrastructure is not there yet. |
| 523 | */ |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 524 | |
Tvrtko Ursulin | 6e26695 | 2016-10-13 11:02:53 +0100 | [diff] [blame] | 525 | if (HAS_PCH_IBX(dev_priv)) { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 526 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 527 | aud_config = IBX_AUD_CFG(pipe); |
| 528 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
| 529 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
Tvrtko Ursulin | 920a14b | 2016-10-14 10:13:44 +0100 | [diff] [blame] | 530 | } else if (IS_VALLEYVIEW(dev_priv) || |
| 531 | IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 532 | hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe); |
| 533 | aud_config = VLV_AUD_CFG(pipe); |
| 534 | aud_cntl_st = VLV_AUD_CNTL_ST(pipe); |
| 535 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
| 536 | } else { |
| 537 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 538 | aud_config = CPT_AUD_CFG(pipe); |
| 539 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
| 540 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
| 541 | } |
| 542 | |
Jani Nikula | d3902c3 | 2015-05-04 17:20:49 +0300 | [diff] [blame] | 543 | eldv = IBX_ELD_VALID(port); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 544 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 545 | /* Invalidate ELD */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 546 | tmp = I915_READ(aud_cntrl_st2); |
| 547 | tmp &= ~eldv; |
| 548 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 549 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 550 | /* Reset ELD write address */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 551 | tmp = I915_READ(aud_cntl_st); |
Jani Nikula | c46f111 | 2014-10-27 16:26:52 +0200 | [diff] [blame] | 552 | tmp &= ~IBX_ELD_ADDRESS_MASK; |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 553 | I915_WRITE(aud_cntl_st, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 554 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 555 | /* Up to 84 bytes of hw ELD buffer */ |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 556 | len = min(drm_eld_size(eld), 84); |
| 557 | for (i = 0; i < len / 4; i++) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 558 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 559 | |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 560 | /* ELD valid */ |
Jani Nikula | f9f682a | 2014-10-27 16:26:45 +0200 | [diff] [blame] | 561 | tmp = I915_READ(aud_cntrl_st2); |
| 562 | tmp |= eldv; |
| 563 | I915_WRITE(aud_cntrl_st2, tmp); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 564 | |
| 565 | /* Enable timestamps */ |
| 566 | tmp = I915_READ(aud_config); |
| 567 | tmp &= ~AUD_CONFIG_N_VALUE_INDEX; |
| 568 | tmp &= ~AUD_CONFIG_N_PROG_ENABLE; |
| 569 | tmp &= ~AUD_CONFIG_PIXEL_CLOCK_HDMI_MASK; |
Ville Syrjälä | 2210ce7 | 2016-06-22 21:57:05 +0300 | [diff] [blame] | 570 | if (intel_crtc_has_dp_encoder(intel_crtc->config)) |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 571 | tmp |= AUD_CONFIG_N_VALUE_INDEX; |
| 572 | else |
Ville Syrjälä | 5e7234c | 2015-09-25 16:37:43 +0300 | [diff] [blame] | 573 | tmp |= audio_config_hdmi_pixel_clock(adjusted_mode); |
Jani Nikula | c6bde93 | 2014-11-04 10:31:28 +0200 | [diff] [blame] | 574 | I915_WRITE(aud_config, tmp); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 575 | } |
| 576 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 577 | /** |
| 578 | * intel_audio_codec_enable - Enable the audio codec for HD audio |
| 579 | * @intel_encoder: encoder on which to enable audio |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 580 | * @crtc_state: pointer to the current crtc state. |
| 581 | * @conn_state: pointer to the current connector state. |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 582 | * |
| 583 | * The enable sequences may only be performed after enabling the transcoder and |
| 584 | * port, and after completed link training. |
| 585 | */ |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 586 | void intel_audio_codec_enable(struct intel_encoder *intel_encoder, |
| 587 | const struct intel_crtc_state *crtc_state, |
| 588 | const struct drm_connector_state *conn_state) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 589 | { |
Jani Nikula | 33d1e7c6 | 2014-10-27 16:26:46 +0200 | [diff] [blame] | 590 | struct drm_encoder *encoder = &intel_encoder->base; |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 591 | const struct drm_display_mode *adjusted_mode = &crtc_state->base.adjusted_mode; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 592 | struct drm_connector *connector; |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 593 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 594 | struct i915_audio_component *acomp = dev_priv->audio_component; |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 595 | enum port port = intel_encoder->port; |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 596 | enum pipe pipe = to_intel_crtc(crtc_state->base.crtc)->pipe; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 597 | |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 598 | connector = conn_state->connector; |
| 599 | if (!connector || !connector->eld[0]) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 600 | return; |
| 601 | |
| 602 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 603 | connector->base.id, |
| 604 | connector->name, |
| 605 | connector->encoder->base.id, |
| 606 | connector->encoder->name); |
| 607 | |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 608 | /* ELD Conn_Type */ |
| 609 | connector->eld[5] &= ~(3 << 2); |
Maarten Lankhorst | bbf35e9 | 2016-11-08 13:55:38 +0100 | [diff] [blame] | 610 | if (intel_crtc_has_dp_encoder(crtc_state)) |
Jani Nikula | 6189b03 | 2014-10-28 13:53:01 +0200 | [diff] [blame] | 611 | connector->eld[5] |= (1 << 2); |
| 612 | |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 613 | connector->eld[6] = drm_av_sync_delay(connector, adjusted_mode) / 2; |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 614 | |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 615 | if (dev_priv->display.audio_codec_enable) |
Ville Syrjälä | 124abe0 | 2015-09-08 13:40:45 +0300 | [diff] [blame] | 616 | dev_priv->display.audio_codec_enable(connector, intel_encoder, |
| 617 | adjusted_mode); |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 618 | |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 619 | mutex_lock(&dev_priv->av_mutex); |
Pandiyan, Dhinakaran | f1a3ace | 2016-09-19 18:24:40 -0700 | [diff] [blame] | 620 | intel_encoder->audio_connector = connector; |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 621 | |
Takashi Iwai | 9dfbffc | 2016-02-24 15:35:22 +0100 | [diff] [blame] | 622 | /* referred in audio callbacks */ |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 623 | dev_priv->av_enc_map[pipe] = intel_encoder; |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 624 | mutex_unlock(&dev_priv->av_mutex); |
| 625 | |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 626 | /* audio drivers expect pipe = -1 to indicate Non-MST cases */ |
| 627 | if (intel_encoder->type != INTEL_OUTPUT_DP_MST) |
| 628 | pipe = -1; |
| 629 | |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 630 | if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 631 | acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr, |
| 632 | (int) port, (int) pipe); |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /** |
| 636 | * intel_audio_codec_disable - Disable the audio codec for HD audio |
Geliang Tang | 95d0be6 | 2015-09-15 06:04:36 -0700 | [diff] [blame] | 637 | * @intel_encoder: encoder on which to disable audio |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 638 | * |
| 639 | * The disable sequences must be performed before disabling the transcoder or |
| 640 | * port. |
| 641 | */ |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 642 | void intel_audio_codec_disable(struct intel_encoder *intel_encoder) |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 643 | { |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 644 | struct drm_encoder *encoder = &intel_encoder->base; |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 645 | struct drm_i915_private *dev_priv = to_i915(encoder->dev); |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 646 | struct i915_audio_component *acomp = dev_priv->audio_component; |
Pandiyan, Dhinakaran | d8dee42 | 2016-09-19 18:24:39 -0700 | [diff] [blame] | 647 | enum port port = intel_encoder->port; |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 648 | struct intel_crtc *crtc = to_intel_crtc(encoder->crtc); |
| 649 | enum pipe pipe = crtc->pipe; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 650 | |
| 651 | if (dev_priv->display.audio_codec_disable) |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 652 | dev_priv->display.audio_codec_disable(intel_encoder); |
| 653 | |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 654 | mutex_lock(&dev_priv->av_mutex); |
Pandiyan, Dhinakaran | f1a3ace | 2016-09-19 18:24:40 -0700 | [diff] [blame] | 655 | intel_encoder->audio_connector = NULL; |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 656 | dev_priv->av_enc_map[pipe] = NULL; |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 657 | mutex_unlock(&dev_priv->av_mutex); |
| 658 | |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 659 | /* audio drivers expect pipe = -1 to indicate Non-MST cases */ |
| 660 | if (intel_encoder->type != INTEL_OUTPUT_DP_MST) |
| 661 | pipe = -1; |
| 662 | |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 663 | if (acomp && acomp->audio_ops && acomp->audio_ops->pin_eld_notify) |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 664 | acomp->audio_ops->pin_eld_notify(acomp->audio_ops->audio_ptr, |
| 665 | (int) port, (int) pipe); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | /** |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 669 | * intel_init_audio_hooks - Set up chip specific audio hooks |
| 670 | * @dev_priv: device private |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 671 | */ |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 672 | void intel_init_audio_hooks(struct drm_i915_private *dev_priv) |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 673 | { |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 674 | if (IS_G4X(dev_priv)) { |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 675 | dev_priv->display.audio_codec_enable = g4x_audio_codec_enable; |
Jani Nikula | 76d8d3e | 2014-10-27 16:26:57 +0200 | [diff] [blame] | 676 | dev_priv->display.audio_codec_disable = g4x_audio_codec_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 677 | } else if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) { |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 678 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 679 | dev_priv->display.audio_codec_disable = ilk_audio_codec_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 680 | } else if (IS_HASWELL(dev_priv) || INTEL_INFO(dev_priv)->gen >= 8) { |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 681 | dev_priv->display.audio_codec_enable = hsw_audio_codec_enable; |
| 682 | dev_priv->display.audio_codec_disable = hsw_audio_codec_disable; |
Imre Deak | 8821294 | 2016-03-16 13:38:53 +0200 | [diff] [blame] | 683 | } else if (HAS_PCH_SPLIT(dev_priv)) { |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 684 | dev_priv->display.audio_codec_enable = ilk_audio_codec_enable; |
Jani Nikula | 495a5bb | 2014-10-27 16:26:55 +0200 | [diff] [blame] | 685 | dev_priv->display.audio_codec_disable = ilk_audio_codec_disable; |
Jani Nikula | 69bfe1a | 2014-10-27 16:26:50 +0200 | [diff] [blame] | 686 | } |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 687 | } |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 688 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 689 | static void i915_audio_component_get_power(struct device *kdev) |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 690 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 691 | intel_display_power_get(kdev_to_i915(kdev), POWER_DOMAIN_AUDIO); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 692 | } |
| 693 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 694 | static void i915_audio_component_put_power(struct device *kdev) |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 695 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 696 | intel_display_power_put(kdev_to_i915(kdev), POWER_DOMAIN_AUDIO); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 697 | } |
| 698 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 699 | static void i915_audio_component_codec_wake_override(struct device *kdev, |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 700 | bool enable) |
| 701 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 702 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 703 | u32 tmp; |
| 704 | |
Rodrigo Vivi | ef11bdb | 2015-10-28 04:16:45 -0700 | [diff] [blame] | 705 | if (!IS_SKYLAKE(dev_priv) && !IS_KABYLAKE(dev_priv)) |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 706 | return; |
| 707 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 708 | i915_audio_component_get_power(kdev); |
Chris Wilson | d838a11 | 2016-08-03 17:09:00 +0100 | [diff] [blame] | 709 | |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 710 | /* |
| 711 | * Enable/disable generating the codec wake signal, overriding the |
| 712 | * internal logic to generate the codec wake to controller. |
| 713 | */ |
| 714 | tmp = I915_READ(HSW_AUD_CHICKENBIT); |
| 715 | tmp &= ~SKL_AUD_CODEC_WAKE_SIGNAL; |
| 716 | I915_WRITE(HSW_AUD_CHICKENBIT, tmp); |
| 717 | usleep_range(1000, 1500); |
| 718 | |
| 719 | if (enable) { |
| 720 | tmp = I915_READ(HSW_AUD_CHICKENBIT); |
| 721 | tmp |= SKL_AUD_CODEC_WAKE_SIGNAL; |
| 722 | I915_WRITE(HSW_AUD_CHICKENBIT, tmp); |
| 723 | usleep_range(1000, 1500); |
| 724 | } |
Chris Wilson | d838a11 | 2016-08-03 17:09:00 +0100 | [diff] [blame] | 725 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 726 | i915_audio_component_put_power(kdev); |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 727 | } |
| 728 | |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 729 | /* Get CDCLK in kHz */ |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 730 | static int i915_audio_component_get_cdclk_freq(struct device *kdev) |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 731 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 732 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 733 | |
| 734 | if (WARN_ON_ONCE(!HAS_DDI(dev_priv))) |
| 735 | return -ENODEV; |
| 736 | |
Ville Syrjälä | 1033f92 | 2016-04-26 19:46:33 +0300 | [diff] [blame] | 737 | return dev_priv->cdclk_freq; |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 738 | } |
| 739 | |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 740 | static struct intel_encoder *get_saved_enc(struct drm_i915_private *dev_priv, |
| 741 | int port, int pipe) |
| 742 | { |
| 743 | |
| 744 | if (WARN_ON(pipe >= I915_MAX_PIPES)) |
| 745 | return NULL; |
| 746 | |
| 747 | /* MST */ |
| 748 | if (pipe >= 0) |
| 749 | return dev_priv->av_enc_map[pipe]; |
| 750 | |
| 751 | /* Non-MST */ |
| 752 | for_each_pipe(dev_priv, pipe) { |
| 753 | struct intel_encoder *encoder; |
| 754 | |
| 755 | encoder = dev_priv->av_enc_map[pipe]; |
| 756 | if (encoder == NULL) |
| 757 | continue; |
| 758 | |
| 759 | if (port == encoder->port) |
| 760 | return encoder; |
| 761 | } |
| 762 | |
| 763 | return NULL; |
| 764 | } |
| 765 | |
| 766 | static int i915_audio_component_sync_audio_rate(struct device *kdev, int port, |
| 767 | int pipe, int rate) |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 768 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 769 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 770 | struct intel_encoder *intel_encoder; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 771 | struct intel_crtc *crtc; |
Jani Nikula | 8f1ec18 | 2016-10-10 18:04:02 +0300 | [diff] [blame] | 772 | struct drm_display_mode *adjusted_mode; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 773 | struct i915_audio_component *acomp = dev_priv->audio_component; |
Takashi Iwai | 0bdf5a0 | 2015-11-30 18:19:39 +0100 | [diff] [blame] | 774 | int err = 0; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 775 | |
Libin Yang | 4bd2d6f | 2016-10-10 18:04:04 +0300 | [diff] [blame] | 776 | if (!HAS_DDI(dev_priv)) |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 777 | return 0; |
| 778 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 779 | i915_audio_component_get_power(kdev); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 780 | mutex_lock(&dev_priv->av_mutex); |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 781 | |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 782 | /* 1. get the pipe */ |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 783 | intel_encoder = get_saved_enc(dev_priv, port, pipe); |
Takashi Iwai | 0bdf5a0 | 2015-11-30 18:19:39 +0100 | [diff] [blame] | 784 | if (!intel_encoder || !intel_encoder->base.crtc || |
Libin Yang | 6014ac1 | 2016-10-25 17:54:18 +0300 | [diff] [blame] | 785 | (intel_encoder->type != INTEL_OUTPUT_HDMI && |
| 786 | intel_encoder->type != INTEL_OUTPUT_DP)) { |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 787 | DRM_DEBUG_KMS("Not valid for port %c\n", port_name(port)); |
Takashi Iwai | 0bdf5a0 | 2015-11-30 18:19:39 +0100 | [diff] [blame] | 788 | err = -ENODEV; |
| 789 | goto unlock; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 790 | } |
Takashi Iwai | 0bdf5a0 | 2015-11-30 18:19:39 +0100 | [diff] [blame] | 791 | |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 792 | /* pipe passed from the audio driver will be -1 for Non-MST case */ |
| 793 | crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 794 | pipe = crtc->pipe; |
| 795 | |
Jani Nikula | 8f1ec18 | 2016-10-10 18:04:02 +0300 | [diff] [blame] | 796 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 797 | |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 798 | /* port must be valid now, otherwise the pipe will be invalid */ |
| 799 | acomp->aud_sample_rate[port] = rate; |
| 800 | |
Jani Nikula | 8f1ec18 | 2016-10-10 18:04:02 +0300 | [diff] [blame] | 801 | hsw_audio_config_update(crtc, port, adjusted_mode); |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 802 | |
Takashi Iwai | 0bdf5a0 | 2015-11-30 18:19:39 +0100 | [diff] [blame] | 803 | unlock: |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 804 | mutex_unlock(&dev_priv->av_mutex); |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 805 | i915_audio_component_put_power(kdev); |
Takashi Iwai | 0bdf5a0 | 2015-11-30 18:19:39 +0100 | [diff] [blame] | 806 | return err; |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 807 | } |
| 808 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 809 | static int i915_audio_component_get_eld(struct device *kdev, int port, |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 810 | int pipe, bool *enabled, |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 811 | unsigned char *buf, int max_bytes) |
| 812 | { |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 813 | struct drm_i915_private *dev_priv = kdev_to_i915(kdev); |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 814 | struct intel_encoder *intel_encoder; |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 815 | const u8 *eld; |
| 816 | int ret = -EINVAL; |
| 817 | |
| 818 | mutex_lock(&dev_priv->av_mutex); |
Pandiyan, Dhinakaran | f931894 | 2016-09-21 13:02:48 -0700 | [diff] [blame] | 819 | |
| 820 | intel_encoder = get_saved_enc(dev_priv, port, pipe); |
| 821 | if (!intel_encoder) { |
| 822 | DRM_DEBUG_KMS("Not valid for port %c\n", port_name(port)); |
| 823 | mutex_unlock(&dev_priv->av_mutex); |
| 824 | return ret; |
| 825 | } |
| 826 | |
| 827 | ret = 0; |
| 828 | *enabled = intel_encoder->audio_connector != NULL; |
| 829 | if (*enabled) { |
| 830 | eld = intel_encoder->audio_connector->eld; |
| 831 | ret = drm_eld_size(eld); |
| 832 | memcpy(buf, eld, min(max_bytes, ret)); |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | mutex_unlock(&dev_priv->av_mutex); |
| 836 | return ret; |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | static const struct i915_audio_component_ops i915_audio_component_ops = { |
| 840 | .owner = THIS_MODULE, |
| 841 | .get_power = i915_audio_component_get_power, |
| 842 | .put_power = i915_audio_component_put_power, |
Lu, Han | 632f3ab | 2015-05-05 09:05:47 +0800 | [diff] [blame] | 843 | .codec_wake_override = i915_audio_component_codec_wake_override, |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 844 | .get_cdclk_freq = i915_audio_component_get_cdclk_freq, |
Libin Yang | 4a21ef7 | 2015-09-02 14:11:39 +0800 | [diff] [blame] | 845 | .sync_audio_rate = i915_audio_component_sync_audio_rate, |
Takashi Iwai | cae666c | 2015-11-12 15:23:41 +0100 | [diff] [blame] | 846 | .get_eld = i915_audio_component_get_eld, |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 847 | }; |
| 848 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 849 | static int i915_audio_component_bind(struct device *i915_kdev, |
| 850 | struct device *hda_kdev, void *data) |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 851 | { |
| 852 | struct i915_audio_component *acomp = data; |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 853 | struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev); |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 854 | int i; |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 855 | |
| 856 | if (WARN_ON(acomp->ops || acomp->dev)) |
| 857 | return -EEXIST; |
| 858 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 859 | drm_modeset_lock_all(&dev_priv->drm); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 860 | acomp->ops = &i915_audio_component_ops; |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 861 | acomp->dev = i915_kdev; |
Libin Yang | 7e8275c | 2015-09-25 09:36:12 +0800 | [diff] [blame] | 862 | BUILD_BUG_ON(MAX_PORTS != I915_MAX_PORTS); |
| 863 | for (i = 0; i < ARRAY_SIZE(acomp->aud_sample_rate); i++) |
| 864 | acomp->aud_sample_rate[i] = 0; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 865 | dev_priv->audio_component = acomp; |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 866 | drm_modeset_unlock_all(&dev_priv->drm); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 867 | |
| 868 | return 0; |
| 869 | } |
| 870 | |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 871 | static void i915_audio_component_unbind(struct device *i915_kdev, |
| 872 | struct device *hda_kdev, void *data) |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 873 | { |
| 874 | struct i915_audio_component *acomp = data; |
David Weinehall | c49d13e | 2016-08-22 13:32:42 +0300 | [diff] [blame] | 875 | struct drm_i915_private *dev_priv = kdev_to_i915(i915_kdev); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 876 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 877 | drm_modeset_lock_all(&dev_priv->drm); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 878 | acomp->ops = NULL; |
| 879 | acomp->dev = NULL; |
David Henningsson | 51e1d83 | 2015-08-19 10:48:56 +0200 | [diff] [blame] | 880 | dev_priv->audio_component = NULL; |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 881 | drm_modeset_unlock_all(&dev_priv->drm); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static const struct component_ops i915_audio_component_bind_ops = { |
| 885 | .bind = i915_audio_component_bind, |
| 886 | .unbind = i915_audio_component_unbind, |
| 887 | }; |
| 888 | |
| 889 | /** |
| 890 | * i915_audio_component_init - initialize and register the audio component |
| 891 | * @dev_priv: i915 device instance |
| 892 | * |
| 893 | * This will register with the component framework a child component which |
| 894 | * will bind dynamically to the snd_hda_intel driver's corresponding master |
| 895 | * component when the latter is registered. During binding the child |
| 896 | * initializes an instance of struct i915_audio_component which it receives |
| 897 | * from the master. The master can then start to use the interface defined by |
| 898 | * this struct. Each side can break the binding at any point by deregistering |
| 899 | * its own component after which each side's component unbind callback is |
| 900 | * called. |
| 901 | * |
| 902 | * We ignore any error during registration and continue with reduced |
| 903 | * functionality (i.e. without HDMI audio). |
| 904 | */ |
| 905 | void i915_audio_component_init(struct drm_i915_private *dev_priv) |
| 906 | { |
| 907 | int ret; |
| 908 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 909 | ret = component_add(dev_priv->drm.dev, &i915_audio_component_bind_ops); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 910 | if (ret < 0) { |
| 911 | DRM_ERROR("failed to add audio component (%d)\n", ret); |
| 912 | /* continue with reduced functionality */ |
| 913 | return; |
| 914 | } |
| 915 | |
| 916 | dev_priv->audio_component_registered = true; |
| 917 | } |
| 918 | |
| 919 | /** |
| 920 | * i915_audio_component_cleanup - deregister the audio component |
| 921 | * @dev_priv: i915 device instance |
| 922 | * |
| 923 | * Deregisters the audio component, breaking any existing binding to the |
| 924 | * corresponding snd_hda_intel driver's master component. |
| 925 | */ |
| 926 | void i915_audio_component_cleanup(struct drm_i915_private *dev_priv) |
| 927 | { |
| 928 | if (!dev_priv->audio_component_registered) |
| 929 | return; |
| 930 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 931 | component_del(dev_priv->drm.dev, &i915_audio_component_bind_ops); |
Imre Deak | 58fddc2 | 2015-01-08 17:54:14 +0200 | [diff] [blame] | 932 | dev_priv->audio_component_registered = false; |
| 933 | } |