Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1 | /* |
| 2 | * intel_hdmi_audio.c - Intel HDMI audio driver |
| 3 | * |
| 4 | * Copyright (C) 2016 Intel Corp |
| 5 | * Authors: Sailaja Bandarupalli <sailaja.bandarupalli@intel.com> |
| 6 | * Ramesh Babu K V <ramesh.babu@intel.com> |
| 7 | * Vaibhav Agarwal <vaibhav.agarwal@intel.com> |
| 8 | * Jerome Anand <jerome.anand@intel.com> |
| 9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; version 2 of the License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 21 | * ALSA driver for Intel HDMI audio |
| 22 | */ |
| 23 | |
Takashi Iwai | 03c3437 | 2017-02-02 16:19:03 +0100 | [diff] [blame] | 24 | #include <linux/types.h> |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/io.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/module.h> |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 29 | #include <linux/interrupt.h> |
Takashi Iwai | 03c3437 | 2017-02-02 16:19:03 +0100 | [diff] [blame] | 30 | #include <linux/pm_runtime.h> |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 31 | #include <asm/cacheflush.h> |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 32 | #include <sound/core.h> |
Takashi Iwai | 03c3437 | 2017-02-02 16:19:03 +0100 | [diff] [blame] | 33 | #include <sound/asoundef.h> |
| 34 | #include <sound/pcm.h> |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 35 | #include <sound/pcm_params.h> |
| 36 | #include <sound/initval.h> |
| 37 | #include <sound/control.h> |
Takashi Iwai | 03c3437 | 2017-02-02 16:19:03 +0100 | [diff] [blame] | 38 | #include <drm/drm_edid.h> |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 39 | #include <drm/intel_lpe_audio.h> |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 40 | #include "intel_hdmi_audio.h" |
| 41 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 42 | /*standard module options for ALSA. This module supports only one card*/ |
| 43 | static int hdmi_card_index = SNDRV_DEFAULT_IDX1; |
| 44 | static char *hdmi_card_id = SNDRV_DEFAULT_STR1; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 45 | |
| 46 | module_param_named(index, hdmi_card_index, int, 0444); |
| 47 | MODULE_PARM_DESC(index, |
| 48 | "Index value for INTEL Intel HDMI Audio controller."); |
| 49 | module_param_named(id, hdmi_card_id, charp, 0444); |
| 50 | MODULE_PARM_DESC(id, |
| 51 | "ID string for INTEL Intel HDMI Audio controller."); |
| 52 | |
| 53 | /* |
| 54 | * ELD SA bits in the CEA Speaker Allocation data block |
| 55 | */ |
Takashi Iwai | 4a5ddb2 | 2017-02-01 16:45:38 +0100 | [diff] [blame] | 56 | static const int eld_speaker_allocation_bits[] = { |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 57 | [0] = FL | FR, |
| 58 | [1] = LFE, |
| 59 | [2] = FC, |
| 60 | [3] = RL | RR, |
| 61 | [4] = RC, |
| 62 | [5] = FLC | FRC, |
| 63 | [6] = RLC | RRC, |
| 64 | /* the following are not defined in ELD yet */ |
| 65 | [7] = 0, |
| 66 | }; |
| 67 | |
| 68 | /* |
| 69 | * This is an ordered list! |
| 70 | * |
| 71 | * The preceding ones have better chances to be selected by |
| 72 | * hdmi_channel_allocation(). |
| 73 | */ |
| 74 | static struct cea_channel_speaker_allocation channel_allocations[] = { |
| 75 | /* channel: 7 6 5 4 3 2 1 0 */ |
| 76 | { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } }, |
| 77 | /* 2.1 */ |
| 78 | { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } }, |
| 79 | /* Dolby Surround */ |
| 80 | { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } }, |
| 81 | /* surround40 */ |
| 82 | { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } }, |
| 83 | /* surround41 */ |
| 84 | { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } }, |
| 85 | /* surround50 */ |
| 86 | { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } }, |
| 87 | /* surround51 */ |
| 88 | { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } }, |
| 89 | /* 6.1 */ |
| 90 | { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } }, |
| 91 | /* surround71 */ |
| 92 | { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } }, |
| 93 | |
| 94 | { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } }, |
| 95 | { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } }, |
| 96 | { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } }, |
| 97 | { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } }, |
| 98 | { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } }, |
| 99 | { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } }, |
| 100 | { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } }, |
| 101 | { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } }, |
| 102 | { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } }, |
| 103 | { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } }, |
| 104 | { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } }, |
| 105 | { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } }, |
| 106 | { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } }, |
| 107 | { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } }, |
| 108 | { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } }, |
| 109 | { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } }, |
| 110 | { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } }, |
| 111 | { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } }, |
| 112 | { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } }, |
| 113 | { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } }, |
| 114 | { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } }, |
| 115 | { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } }, |
| 116 | { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } }, |
| 117 | }; |
| 118 | |
Takashi Iwai | 4a5ddb2 | 2017-02-01 16:45:38 +0100 | [diff] [blame] | 119 | static const struct channel_map_table map_tables[] = { |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 120 | { SNDRV_CHMAP_FL, 0x00, FL }, |
| 121 | { SNDRV_CHMAP_FR, 0x01, FR }, |
| 122 | { SNDRV_CHMAP_RL, 0x04, RL }, |
| 123 | { SNDRV_CHMAP_RR, 0x05, RR }, |
| 124 | { SNDRV_CHMAP_LFE, 0x02, LFE }, |
| 125 | { SNDRV_CHMAP_FC, 0x03, FC }, |
| 126 | { SNDRV_CHMAP_RLC, 0x06, RLC }, |
| 127 | { SNDRV_CHMAP_RRC, 0x07, RRC }, |
| 128 | {} /* terminator */ |
| 129 | }; |
| 130 | |
| 131 | /* hardware capability structure */ |
| 132 | static const struct snd_pcm_hardware snd_intel_hadstream = { |
| 133 | .info = (SNDRV_PCM_INFO_INTERLEAVED | |
| 134 | SNDRV_PCM_INFO_DOUBLE | |
| 135 | SNDRV_PCM_INFO_MMAP| |
| 136 | SNDRV_PCM_INFO_MMAP_VALID | |
| 137 | SNDRV_PCM_INFO_BATCH), |
| 138 | .formats = (SNDRV_PCM_FMTBIT_S24 | |
| 139 | SNDRV_PCM_FMTBIT_U24), |
| 140 | .rates = SNDRV_PCM_RATE_32000 | |
| 141 | SNDRV_PCM_RATE_44100 | |
| 142 | SNDRV_PCM_RATE_48000 | |
| 143 | SNDRV_PCM_RATE_88200 | |
| 144 | SNDRV_PCM_RATE_96000 | |
| 145 | SNDRV_PCM_RATE_176400 | |
| 146 | SNDRV_PCM_RATE_192000, |
| 147 | .rate_min = HAD_MIN_RATE, |
| 148 | .rate_max = HAD_MAX_RATE, |
| 149 | .channels_min = HAD_MIN_CHANNEL, |
| 150 | .channels_max = HAD_MAX_CHANNEL, |
| 151 | .buffer_bytes_max = HAD_MAX_BUFFER, |
| 152 | .period_bytes_min = HAD_MIN_PERIOD_BYTES, |
| 153 | .period_bytes_max = HAD_MAX_PERIOD_BYTES, |
| 154 | .periods_min = HAD_MIN_PERIODS, |
| 155 | .periods_max = HAD_MAX_PERIODS, |
| 156 | .fifo_size = HAD_FIFO_SIZE, |
| 157 | }; |
| 158 | |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 159 | /* Get the active PCM substream; |
| 160 | * Call had_substream_put() for unreferecing. |
| 161 | * Don't call this inside had_spinlock, as it takes by itself |
| 162 | */ |
| 163 | static struct snd_pcm_substream * |
| 164 | had_substream_get(struct snd_intelhad *intelhaddata) |
| 165 | { |
| 166 | struct snd_pcm_substream *substream; |
| 167 | unsigned long flags; |
| 168 | |
| 169 | spin_lock_irqsave(&intelhaddata->had_spinlock, flags); |
| 170 | substream = intelhaddata->stream_info.substream; |
| 171 | if (substream) |
| 172 | intelhaddata->stream_info.substream_refcount++; |
| 173 | spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); |
| 174 | return substream; |
| 175 | } |
| 176 | |
| 177 | /* Unref the active PCM substream; |
| 178 | * Don't call this inside had_spinlock, as it takes by itself |
| 179 | */ |
| 180 | static void had_substream_put(struct snd_intelhad *intelhaddata) |
| 181 | { |
| 182 | unsigned long flags; |
| 183 | |
| 184 | spin_lock_irqsave(&intelhaddata->had_spinlock, flags); |
| 185 | intelhaddata->stream_info.substream_refcount--; |
| 186 | spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); |
| 187 | } |
| 188 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 189 | /* Register access functions */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 190 | static inline void |
| 191 | mid_hdmi_audio_read(struct snd_intelhad *ctx, u32 reg, u32 *val) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 192 | { |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 193 | *val = ioread32(ctx->mmio_start + ctx->had_config_offset + reg); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 194 | } |
| 195 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 196 | static inline void |
| 197 | mid_hdmi_audio_write(struct snd_intelhad *ctx, u32 reg, u32 val) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 198 | { |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 199 | iowrite32(val, ctx->mmio_start + ctx->had_config_offset + reg); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 200 | } |
| 201 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 202 | static int had_read_register(struct snd_intelhad *intelhaddata, |
| 203 | u32 offset, u32 *data) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 204 | { |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 205 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) |
| 206 | return -ENODEV; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 207 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 208 | mid_hdmi_audio_read(intelhaddata, offset, data); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static void fixup_dp_config(struct snd_intelhad *intelhaddata, |
| 213 | u32 offset, u32 *data) |
| 214 | { |
| 215 | if (intelhaddata->dp_output) { |
| 216 | if (offset == AUD_CONFIG && (*data & AUD_CONFIG_VALID_BIT)) |
| 217 | *data |= AUD_CONFIG_DP_MODE | AUD_CONFIG_BLOCK_BIT; |
| 218 | } |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 219 | } |
| 220 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 221 | static int had_write_register(struct snd_intelhad *intelhaddata, |
| 222 | u32 offset, u32 data) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 223 | { |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 224 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) |
| 225 | return -ENODEV; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 226 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 227 | fixup_dp_config(intelhaddata, offset, &data); |
| 228 | mid_hdmi_audio_write(intelhaddata, offset, data); |
| 229 | return 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 230 | } |
| 231 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 232 | static int had_read_modify(struct snd_intelhad *intelhaddata, u32 offset, |
| 233 | u32 data, u32 mask) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 234 | { |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 235 | u32 val_tmp; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 236 | |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 237 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) |
| 238 | return -ENODEV; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 239 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 240 | mid_hdmi_audio_read(intelhaddata, offset, &val_tmp); |
| 241 | val_tmp &= ~mask; |
| 242 | val_tmp |= (data & mask); |
| 243 | |
| 244 | fixup_dp_config(intelhaddata, offset, &val_tmp); |
| 245 | mid_hdmi_audio_write(intelhaddata, offset, val_tmp); |
| 246 | return 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 247 | } |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 248 | |
| 249 | /* |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 250 | * enable / disable audio configuration |
| 251 | * |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 252 | * The had_read_modify() function should not directly be used on VLV2 for |
| 253 | * updating AUD_CONFIG register. |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 254 | * This is because: |
| 255 | * Bit6 of AUD_CONFIG register is writeonly due to a silicon bug on VLV2 |
| 256 | * HDMI IP. As a result a read-modify of AUD_CONFIG regiter will always |
| 257 | * clear bit6. AUD_CONFIG[6:4] represents the "channels" field of the |
| 258 | * register. This field should be 1xy binary for configuration with 6 or |
| 259 | * more channels. Read-modify of AUD_CONFIG (Eg. for enabling audio) |
| 260 | * causes the "channels" field to be updated as 0xy binary resulting in |
| 261 | * bad audio. The fix is to always write the AUD_CONFIG[6:4] with |
| 262 | * appropriate value when doing read-modify of AUD_CONFIG register. |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 263 | */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 264 | static void snd_intelhad_enable_audio(struct snd_pcm_substream *substream, |
| 265 | struct snd_intelhad *intelhaddata, |
| 266 | bool enable) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 267 | { |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 268 | union aud_cfg cfg_val = {.regval = 0}; |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 269 | u8 channels, data, mask; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 270 | |
| 271 | /* |
| 272 | * If substream is NULL, there is no active stream. |
| 273 | * In this case just set channels to 2 |
| 274 | */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 275 | channels = substream ? substream->runtime->channels : 2; |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 276 | cfg_val.regx.num_ch = channels - 2; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 277 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 278 | data = cfg_val.regval; |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 279 | if (enable) |
| 280 | data |= 1; |
| 281 | mask = AUD_CONFIG_CH_MASK | 1; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 282 | |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 283 | dev_dbg(intelhaddata->dev, "%s : data = %x, mask =%x\n", |
| 284 | __func__, data, mask); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 285 | |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 286 | had_read_modify(intelhaddata, AUD_CONFIG, data, mask); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 287 | } |
| 288 | |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 289 | /* enable / disable the audio interface */ |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 290 | static void snd_intelhad_enable_audio_int(struct snd_intelhad *ctx, bool enable) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 291 | { |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 292 | u32 status_reg; |
| 293 | |
| 294 | if (enable) { |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 295 | mid_hdmi_audio_read(ctx, AUD_HDMI_STATUS, &status_reg); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 296 | status_reg |= HDMI_AUDIO_BUFFER_DONE | HDMI_AUDIO_UNDERRUN; |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 297 | mid_hdmi_audio_write(ctx, AUD_HDMI_STATUS, status_reg); |
| 298 | mid_hdmi_audio_read(ctx, AUD_HDMI_STATUS, &status_reg); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 299 | } |
| 300 | } |
| 301 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 302 | static void snd_intelhad_reset_audio(struct snd_intelhad *intelhaddata, |
| 303 | u8 reset) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 304 | { |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 305 | had_write_register(intelhaddata, AUD_HDMI_STATUS, reset); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 306 | } |
| 307 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 308 | /* |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 309 | * initialize audio channel status registers |
| 310 | * This function is called in the prepare callback |
| 311 | */ |
| 312 | static int had_prog_status_reg(struct snd_pcm_substream *substream, |
| 313 | struct snd_intelhad *intelhaddata) |
| 314 | { |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 315 | union aud_cfg cfg_val = {.regval = 0}; |
| 316 | union aud_ch_status_0 ch_stat0 = {.regval = 0}; |
| 317 | union aud_ch_status_1 ch_stat1 = {.regval = 0}; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 318 | int format; |
| 319 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 320 | ch_stat0.regx.lpcm_id = (intelhaddata->aes_bits & |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 321 | IEC958_AES0_NONAUDIO) >> 1; |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 322 | ch_stat0.regx.clk_acc = (intelhaddata->aes_bits & |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 323 | IEC958_AES3_CON_CLOCK) >> 4; |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 324 | cfg_val.regx.val_bit = ch_stat0.regx.lpcm_id; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 325 | |
| 326 | switch (substream->runtime->rate) { |
| 327 | case AUD_SAMPLE_RATE_32: |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 328 | ch_stat0.regx.samp_freq = CH_STATUS_MAP_32KHZ; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 329 | break; |
| 330 | |
| 331 | case AUD_SAMPLE_RATE_44_1: |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 332 | ch_stat0.regx.samp_freq = CH_STATUS_MAP_44KHZ; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 333 | break; |
| 334 | case AUD_SAMPLE_RATE_48: |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 335 | ch_stat0.regx.samp_freq = CH_STATUS_MAP_48KHZ; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 336 | break; |
| 337 | case AUD_SAMPLE_RATE_88_2: |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 338 | ch_stat0.regx.samp_freq = CH_STATUS_MAP_88KHZ; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 339 | break; |
| 340 | case AUD_SAMPLE_RATE_96: |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 341 | ch_stat0.regx.samp_freq = CH_STATUS_MAP_96KHZ; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 342 | break; |
| 343 | case AUD_SAMPLE_RATE_176_4: |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 344 | ch_stat0.regx.samp_freq = CH_STATUS_MAP_176KHZ; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 345 | break; |
| 346 | case AUD_SAMPLE_RATE_192: |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 347 | ch_stat0.regx.samp_freq = CH_STATUS_MAP_192KHZ; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 348 | break; |
| 349 | |
| 350 | default: |
| 351 | /* control should never come here */ |
| 352 | return -EINVAL; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 353 | } |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 354 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 355 | had_write_register(intelhaddata, |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 356 | AUD_CH_STATUS_0, ch_stat0.regval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 357 | |
| 358 | format = substream->runtime->format; |
| 359 | |
| 360 | if (format == SNDRV_PCM_FORMAT_S16_LE) { |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 361 | ch_stat1.regx.max_wrd_len = MAX_SMPL_WIDTH_20; |
| 362 | ch_stat1.regx.wrd_len = SMPL_WIDTH_16BITS; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 363 | } else if (format == SNDRV_PCM_FORMAT_S24_LE) { |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 364 | ch_stat1.regx.max_wrd_len = MAX_SMPL_WIDTH_24; |
| 365 | ch_stat1.regx.wrd_len = SMPL_WIDTH_24BITS; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 366 | } else { |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 367 | ch_stat1.regx.max_wrd_len = 0; |
| 368 | ch_stat1.regx.wrd_len = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 369 | } |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 370 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 371 | had_write_register(intelhaddata, |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 372 | AUD_CH_STATUS_1, ch_stat1.regval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 373 | return 0; |
| 374 | } |
| 375 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 376 | /* |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 377 | * function to initialize audio |
| 378 | * registers and buffer confgiuration registers |
| 379 | * This function is called in the prepare callback |
| 380 | */ |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 381 | static int snd_intelhad_audio_ctrl(struct snd_pcm_substream *substream, |
| 382 | struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 383 | { |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 384 | union aud_cfg cfg_val = {.regval = 0}; |
| 385 | union aud_buf_config buf_cfg = {.regval = 0}; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 386 | u8 channels; |
| 387 | |
| 388 | had_prog_status_reg(substream, intelhaddata); |
| 389 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 390 | buf_cfg.regx.audio_fifo_watermark = FIFO_THRESHOLD; |
| 391 | buf_cfg.regx.dma_fifo_watermark = DMA_FIFO_THRESHOLD; |
| 392 | buf_cfg.regx.aud_delay = 0; |
| 393 | had_write_register(intelhaddata, AUD_BUF_CONFIG, buf_cfg.regval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 394 | |
| 395 | channels = substream->runtime->channels; |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 396 | cfg_val.regx.num_ch = channels - 2; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 397 | if (channels <= 2) |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 398 | cfg_val.regx.layout = LAYOUT0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 399 | else |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 400 | cfg_val.regx.layout = LAYOUT1; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 401 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 402 | cfg_val.regx.val_bit = 1; |
| 403 | had_write_register(intelhaddata, AUD_CONFIG, cfg_val.regval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 407 | /* |
| 408 | * Compute derived values in channel_allocations[]. |
| 409 | */ |
| 410 | static void init_channel_allocations(void) |
| 411 | { |
| 412 | int i, j; |
| 413 | struct cea_channel_speaker_allocation *p; |
| 414 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 415 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 416 | p = channel_allocations + i; |
| 417 | p->channels = 0; |
| 418 | p->spk_mask = 0; |
| 419 | for (j = 0; j < ARRAY_SIZE(p->speakers); j++) |
| 420 | if (p->speakers[j]) { |
| 421 | p->channels++; |
| 422 | p->spk_mask |= p->speakers[j]; |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | /* |
| 428 | * The transformation takes two steps: |
| 429 | * |
| 430 | * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask |
| 431 | * spk_mask => (channel_allocations[]) => ai->CA |
| 432 | * |
| 433 | * TODO: it could select the wrong CA from multiple candidates. |
| 434 | */ |
| 435 | static int snd_intelhad_channel_allocation(struct snd_intelhad *intelhaddata, |
| 436 | int channels) |
| 437 | { |
| 438 | int i; |
| 439 | int ca = 0; |
| 440 | int spk_mask = 0; |
| 441 | |
| 442 | /* |
| 443 | * CA defaults to 0 for basic stereo audio |
| 444 | */ |
| 445 | if (channels <= 2) |
| 446 | return 0; |
| 447 | |
| 448 | /* |
| 449 | * expand ELD's speaker allocation mask |
| 450 | * |
| 451 | * ELD tells the speaker mask in a compact(paired) form, |
| 452 | * expand ELD's notions to match the ones used by Audio InfoFrame. |
| 453 | */ |
| 454 | |
| 455 | for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { |
Takashi Iwai | df0435d | 2017-02-02 15:37:11 +0100 | [diff] [blame] | 456 | if (intelhaddata->eld[DRM_ELD_SPEAKER] & (1 << i)) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 457 | spk_mask |= eld_speaker_allocation_bits[i]; |
| 458 | } |
| 459 | |
| 460 | /* search for the first working match in the CA table */ |
| 461 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 462 | if (channels == channel_allocations[i].channels && |
| 463 | (spk_mask & channel_allocations[i].spk_mask) == |
| 464 | channel_allocations[i].spk_mask) { |
| 465 | ca = channel_allocations[i].ca_index; |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 470 | dev_dbg(intelhaddata->dev, "select CA 0x%x for %d\n", ca, channels); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 471 | |
| 472 | return ca; |
| 473 | } |
| 474 | |
| 475 | /* from speaker bit mask to ALSA API channel position */ |
| 476 | static int spk_to_chmap(int spk) |
| 477 | { |
Takashi Iwai | 4a5ddb2 | 2017-02-01 16:45:38 +0100 | [diff] [blame] | 478 | const struct channel_map_table *t = map_tables; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 479 | |
| 480 | for (; t->map; t++) { |
| 481 | if (t->spk_mask == spk) |
| 482 | return t->map; |
| 483 | } |
| 484 | return 0; |
| 485 | } |
| 486 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 487 | static void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 488 | { |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 489 | int i, c; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 490 | int spk_mask = 0; |
| 491 | struct snd_pcm_chmap_elem *chmap; |
| 492 | u8 eld_high, eld_high_mask = 0xF0; |
| 493 | u8 high_msb; |
| 494 | |
| 495 | chmap = kzalloc(sizeof(*chmap), GFP_KERNEL); |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 496 | if (!chmap) { |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 497 | intelhaddata->chmap->chmap = NULL; |
| 498 | return; |
| 499 | } |
| 500 | |
Takashi Iwai | df0435d | 2017-02-02 15:37:11 +0100 | [diff] [blame] | 501 | dev_dbg(intelhaddata->dev, "eld speaker = %x\n", |
| 502 | intelhaddata->eld[DRM_ELD_SPEAKER]); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 503 | |
| 504 | /* WA: Fix the max channel supported to 8 */ |
| 505 | |
| 506 | /* |
| 507 | * Sink may support more than 8 channels, if eld_high has more than |
| 508 | * one bit set. SOC supports max 8 channels. |
| 509 | * Refer eld_speaker_allocation_bits, for sink speaker allocation |
| 510 | */ |
| 511 | |
| 512 | /* if 0x2F < eld < 0x4F fall back to 0x2f, else fall back to 0x4F */ |
Takashi Iwai | df0435d | 2017-02-02 15:37:11 +0100 | [diff] [blame] | 513 | eld_high = intelhaddata->eld[DRM_ELD_SPEAKER] & eld_high_mask; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 514 | if ((eld_high & (eld_high-1)) && (eld_high > 0x1F)) { |
| 515 | /* eld_high & (eld_high-1): if more than 1 bit set */ |
| 516 | /* 0x1F: 7 channels */ |
| 517 | for (i = 1; i < 4; i++) { |
| 518 | high_msb = eld_high & (0x80 >> i); |
| 519 | if (high_msb) { |
Takashi Iwai | df0435d | 2017-02-02 15:37:11 +0100 | [diff] [blame] | 520 | intelhaddata->eld[DRM_ELD_SPEAKER] &= |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 521 | high_msb | 0xF; |
| 522 | break; |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) { |
Takashi Iwai | df0435d | 2017-02-02 15:37:11 +0100 | [diff] [blame] | 528 | if (intelhaddata->eld[DRM_ELD_SPEAKER] & (1 << i)) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 529 | spk_mask |= eld_speaker_allocation_bits[i]; |
| 530 | } |
| 531 | |
| 532 | for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) { |
| 533 | if (spk_mask == channel_allocations[i].spk_mask) { |
| 534 | for (c = 0; c < channel_allocations[i].channels; c++) { |
| 535 | chmap->map[c] = spk_to_chmap( |
| 536 | channel_allocations[i].speakers[ |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 537 | (MAX_SPEAKERS - 1) - c]); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 538 | } |
| 539 | chmap->channels = channel_allocations[i].channels; |
| 540 | intelhaddata->chmap->chmap = chmap; |
| 541 | break; |
| 542 | } |
| 543 | } |
| 544 | if (i >= ARRAY_SIZE(channel_allocations)) { |
| 545 | intelhaddata->chmap->chmap = NULL; |
| 546 | kfree(chmap); |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | /* |
| 551 | * ALSA API channel-map control callbacks |
| 552 | */ |
| 553 | static int had_chmap_ctl_info(struct snd_kcontrol *kcontrol, |
| 554 | struct snd_ctl_elem_info *uinfo) |
| 555 | { |
| 556 | struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); |
| 557 | struct snd_intelhad *intelhaddata = info->private_data; |
| 558 | |
| 559 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) |
| 560 | return -ENODEV; |
| 561 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 562 | uinfo->count = HAD_MAX_CHANNEL; |
| 563 | uinfo->value.integer.min = 0; |
| 564 | uinfo->value.integer.max = SNDRV_CHMAP_LAST; |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | static int had_chmap_ctl_get(struct snd_kcontrol *kcontrol, |
| 569 | struct snd_ctl_elem_value *ucontrol) |
| 570 | { |
| 571 | struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol); |
| 572 | struct snd_intelhad *intelhaddata = info->private_data; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 573 | int i; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 574 | const struct snd_pcm_chmap_elem *chmap; |
| 575 | |
| 576 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) |
| 577 | return -ENODEV; |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 578 | |
| 579 | mutex_lock(&intelhaddata->mutex); |
| 580 | if (!intelhaddata->chmap->chmap) { |
| 581 | mutex_unlock(&intelhaddata->mutex); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 582 | return -ENODATA; |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 583 | } |
| 584 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 585 | chmap = intelhaddata->chmap->chmap; |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 586 | for (i = 0; i < chmap->channels; i++) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 587 | ucontrol->value.integer.value[i] = chmap->map[i]; |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 588 | mutex_unlock(&intelhaddata->mutex); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static int had_register_chmap_ctls(struct snd_intelhad *intelhaddata, |
| 594 | struct snd_pcm *pcm) |
| 595 | { |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 596 | int err; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 597 | |
| 598 | err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 599 | NULL, 0, (unsigned long)intelhaddata, |
| 600 | &intelhaddata->chmap); |
| 601 | if (err < 0) |
| 602 | return err; |
| 603 | |
| 604 | intelhaddata->chmap->private_data = intelhaddata; |
Takashi Iwai | e9d65ab | 2017-01-31 16:11:27 +0100 | [diff] [blame] | 605 | intelhaddata->chmap->kctl->info = had_chmap_ctl_info; |
| 606 | intelhaddata->chmap->kctl->get = had_chmap_ctl_get; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 607 | intelhaddata->chmap->chmap = NULL; |
| 608 | return 0; |
| 609 | } |
| 610 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 611 | /* |
| 612 | * snd_intelhad_prog_dip - to initialize Data Island Packets registers |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 613 | * |
| 614 | * @substream:substream for which the prepare function is called |
| 615 | * @intelhaddata:substream private data |
| 616 | * |
| 617 | * This function is called in the prepare callback |
| 618 | */ |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 619 | static void snd_intelhad_prog_dip(struct snd_pcm_substream *substream, |
| 620 | struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 621 | { |
| 622 | int i; |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 623 | union aud_ctrl_st ctrl_state = {.regval = 0}; |
| 624 | union aud_info_frame2 frame2 = {.regval = 0}; |
| 625 | union aud_info_frame3 frame3 = {.regval = 0}; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 626 | u8 checksum = 0; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 627 | u32 info_frame; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 628 | int channels; |
| 629 | |
| 630 | channels = substream->runtime->channels; |
| 631 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 632 | had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.regval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 633 | |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 634 | if (intelhaddata->dp_output) { |
| 635 | info_frame = DP_INFO_FRAME_WORD1; |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 636 | frame2.regval = 1; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 637 | } else { |
| 638 | info_frame = HDMI_INFO_FRAME_WORD1; |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 639 | frame2.regx.chnl_cnt = substream->runtime->channels - 1; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 640 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 641 | frame3.regx.chnl_alloc = snd_intelhad_channel_allocation( |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 642 | intelhaddata, channels); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 643 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 644 | /* Calculte the byte wide checksum for all valid DIP words */ |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 645 | for (i = 0; i < BYTES_PER_WORD; i++) |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 646 | checksum += (info_frame >> (i * 8)) & 0xff; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 647 | for (i = 0; i < BYTES_PER_WORD; i++) |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 648 | checksum += (frame2.regval >> (i * 8)) & 0xff; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 649 | for (i = 0; i < BYTES_PER_WORD; i++) |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 650 | checksum += (frame3.regval >> (i * 8)) & 0xff; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 651 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 652 | frame2.regx.chksum = -(checksum); |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 653 | } |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 654 | |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 655 | had_write_register(intelhaddata, AUD_HDMIW_INFOFR, info_frame); |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 656 | had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame2.regval); |
| 657 | had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame3.regval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 658 | |
| 659 | /* program remaining DIP words with zero */ |
| 660 | for (i = 0; i < HAD_MAX_DIP_WORDS-VALID_DIP_WORDS; i++) |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 661 | had_write_register(intelhaddata, AUD_HDMIW_INFOFR, 0x0); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 662 | |
Takashi Iwai | 7ceba75 | 2017-02-02 15:58:35 +0100 | [diff] [blame] | 663 | ctrl_state.regx.dip_freq = 1; |
| 664 | ctrl_state.regx.dip_en_sta = 1; |
| 665 | had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.regval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 666 | } |
| 667 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 668 | /* |
| 669 | * snd_intelhad_prog_buffer - programs buffer address and length registers |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 670 | * @substream: substream for which the prepare function is called |
| 671 | * @intelhaddata: substream private data |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 672 | * |
| 673 | * This function programs ring buffer address and length into registers. |
| 674 | */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 675 | static int snd_intelhad_prog_buffer(struct snd_pcm_substream *substream, |
| 676 | struct snd_intelhad *intelhaddata, |
| 677 | int start, int end) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 678 | { |
| 679 | u32 ring_buf_addr, ring_buf_size, period_bytes; |
| 680 | u8 i, num_periods; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 681 | |
| 682 | ring_buf_addr = substream->runtime->dma_addr; |
| 683 | ring_buf_size = snd_pcm_lib_buffer_bytes(substream); |
| 684 | intelhaddata->stream_info.ring_buf_size = ring_buf_size; |
| 685 | period_bytes = frames_to_bytes(substream->runtime, |
| 686 | substream->runtime->period_size); |
| 687 | num_periods = substream->runtime->periods; |
| 688 | |
| 689 | /* |
| 690 | * buffer addr should be 64 byte aligned, period bytes |
| 691 | * will be used to calculate addr offset |
| 692 | */ |
| 693 | period_bytes &= ~0x3F; |
| 694 | |
| 695 | /* Hardware supports MAX_PERIODS buffers */ |
| 696 | if (end >= HAD_MAX_PERIODS) |
| 697 | return -EINVAL; |
| 698 | |
| 699 | for (i = start; i <= end; i++) { |
| 700 | /* Program the buf registers with addr and len */ |
| 701 | intelhaddata->buf_info[i].buf_addr = ring_buf_addr + |
| 702 | (i * period_bytes); |
| 703 | if (i < num_periods-1) |
| 704 | intelhaddata->buf_info[i].buf_size = period_bytes; |
| 705 | else |
| 706 | intelhaddata->buf_info[i].buf_size = ring_buf_size - |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 707 | (i * period_bytes); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 708 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 709 | had_write_register(intelhaddata, |
| 710 | AUD_BUF_A_ADDR + (i * HAD_REG_WIDTH), |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 711 | intelhaddata->buf_info[i].buf_addr | |
| 712 | BIT(0) | BIT(1)); |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 713 | had_write_register(intelhaddata, |
| 714 | AUD_BUF_A_LENGTH + (i * HAD_REG_WIDTH), |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 715 | period_bytes); |
| 716 | intelhaddata->buf_info[i].is_valid = true; |
| 717 | } |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 718 | dev_dbg(intelhaddata->dev, "%s:buf[%d-%d] addr=%#x and size=%d\n", |
| 719 | __func__, start, end, |
| 720 | intelhaddata->buf_info[start].buf_addr, |
| 721 | intelhaddata->buf_info[start].buf_size); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 722 | intelhaddata->valid_buf_cnt = num_periods; |
| 723 | return 0; |
| 724 | } |
| 725 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 726 | static int snd_intelhad_read_len(struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 727 | { |
| 728 | int i, retval = 0; |
| 729 | u32 len[4]; |
| 730 | |
| 731 | for (i = 0; i < 4 ; i++) { |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 732 | had_read_register(intelhaddata, |
| 733 | AUD_BUF_A_LENGTH + (i * HAD_REG_WIDTH), |
| 734 | &len[i]); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 735 | if (!len[i]) |
| 736 | retval++; |
| 737 | } |
| 738 | if (retval != 1) { |
| 739 | for (i = 0; i < 4 ; i++) |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 740 | dev_dbg(intelhaddata->dev, "buf[%d] size=%d\n", |
| 741 | i, len[i]); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | return retval; |
| 745 | } |
| 746 | |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 747 | static int had_calculate_maud_value(u32 aud_samp_freq, u32 link_rate) |
| 748 | { |
| 749 | u32 maud_val; |
| 750 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 751 | /* Select maud according to DP 1.2 spec */ |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 752 | if (link_rate == DP_2_7_GHZ) { |
| 753 | switch (aud_samp_freq) { |
| 754 | case AUD_SAMPLE_RATE_32: |
| 755 | maud_val = AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL; |
| 756 | break; |
| 757 | |
| 758 | case AUD_SAMPLE_RATE_44_1: |
| 759 | maud_val = AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL; |
| 760 | break; |
| 761 | |
| 762 | case AUD_SAMPLE_RATE_48: |
| 763 | maud_val = AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL; |
| 764 | break; |
| 765 | |
| 766 | case AUD_SAMPLE_RATE_88_2: |
| 767 | maud_val = AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL; |
| 768 | break; |
| 769 | |
| 770 | case AUD_SAMPLE_RATE_96: |
| 771 | maud_val = AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL; |
| 772 | break; |
| 773 | |
| 774 | case AUD_SAMPLE_RATE_176_4: |
| 775 | maud_val = AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL; |
| 776 | break; |
| 777 | |
| 778 | case HAD_MAX_RATE: |
| 779 | maud_val = HAD_MAX_RATE_DP_2_7_MAUD_VAL; |
| 780 | break; |
| 781 | |
| 782 | default: |
| 783 | maud_val = -EINVAL; |
| 784 | break; |
| 785 | } |
| 786 | } else if (link_rate == DP_1_62_GHZ) { |
| 787 | switch (aud_samp_freq) { |
| 788 | case AUD_SAMPLE_RATE_32: |
| 789 | maud_val = AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL; |
| 790 | break; |
| 791 | |
| 792 | case AUD_SAMPLE_RATE_44_1: |
| 793 | maud_val = AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL; |
| 794 | break; |
| 795 | |
| 796 | case AUD_SAMPLE_RATE_48: |
| 797 | maud_val = AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL; |
| 798 | break; |
| 799 | |
| 800 | case AUD_SAMPLE_RATE_88_2: |
| 801 | maud_val = AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL; |
| 802 | break; |
| 803 | |
| 804 | case AUD_SAMPLE_RATE_96: |
| 805 | maud_val = AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL; |
| 806 | break; |
| 807 | |
| 808 | case AUD_SAMPLE_RATE_176_4: |
| 809 | maud_val = AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL; |
| 810 | break; |
| 811 | |
| 812 | case HAD_MAX_RATE: |
| 813 | maud_val = HAD_MAX_RATE_DP_1_62_MAUD_VAL; |
| 814 | break; |
| 815 | |
| 816 | default: |
| 817 | maud_val = -EINVAL; |
| 818 | break; |
| 819 | } |
| 820 | } else |
| 821 | maud_val = -EINVAL; |
| 822 | |
| 823 | return maud_val; |
| 824 | } |
| 825 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 826 | /* |
| 827 | * snd_intelhad_prog_cts - Program HDMI audio CTS value |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 828 | * |
| 829 | * @aud_samp_freq: sampling frequency of audio data |
| 830 | * @tmds: sampling frequency of the display data |
| 831 | * @n_param: N value, depends on aud_samp_freq |
| 832 | * @intelhaddata:substream private data |
| 833 | * |
| 834 | * Program CTS register based on the audio and display sampling frequency |
| 835 | */ |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 836 | static void snd_intelhad_prog_cts(u32 aud_samp_freq, u32 tmds, |
| 837 | u32 link_rate, u32 n_param, |
| 838 | struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 839 | { |
| 840 | u32 cts_val; |
| 841 | u64 dividend, divisor; |
| 842 | |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 843 | if (intelhaddata->dp_output) { |
| 844 | /* Substitute cts_val with Maud according to DP 1.2 spec*/ |
| 845 | cts_val = had_calculate_maud_value(aud_samp_freq, link_rate); |
| 846 | } else { |
| 847 | /* Calculate CTS according to HDMI 1.3a spec*/ |
| 848 | dividend = (u64)tmds * n_param*1000; |
| 849 | divisor = 128 * aud_samp_freq; |
| 850 | cts_val = div64_u64(dividend, divisor); |
| 851 | } |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 852 | dev_dbg(intelhaddata->dev, "TMDS value=%d, N value=%d, CTS Value=%d\n", |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 853 | tmds, n_param, cts_val); |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 854 | had_write_register(intelhaddata, AUD_HDMI_CTS, (BIT(24) | cts_val)); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | static int had_calculate_n_value(u32 aud_samp_freq) |
| 858 | { |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 859 | int n_val; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 860 | |
| 861 | /* Select N according to HDMI 1.3a spec*/ |
| 862 | switch (aud_samp_freq) { |
| 863 | case AUD_SAMPLE_RATE_32: |
| 864 | n_val = 4096; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 865 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 866 | |
| 867 | case AUD_SAMPLE_RATE_44_1: |
| 868 | n_val = 6272; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 869 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 870 | |
| 871 | case AUD_SAMPLE_RATE_48: |
| 872 | n_val = 6144; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 873 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 874 | |
| 875 | case AUD_SAMPLE_RATE_88_2: |
| 876 | n_val = 12544; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 877 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 878 | |
| 879 | case AUD_SAMPLE_RATE_96: |
| 880 | n_val = 12288; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 881 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 882 | |
| 883 | case AUD_SAMPLE_RATE_176_4: |
| 884 | n_val = 25088; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 885 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 886 | |
| 887 | case HAD_MAX_RATE: |
| 888 | n_val = 24576; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 889 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 890 | |
| 891 | default: |
| 892 | n_val = -EINVAL; |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 893 | break; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 894 | } |
| 895 | return n_val; |
| 896 | } |
| 897 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 898 | /* |
| 899 | * snd_intelhad_prog_n - Program HDMI audio N value |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 900 | * |
| 901 | * @aud_samp_freq: sampling frequency of audio data |
| 902 | * @n_param: N value, depends on aud_samp_freq |
| 903 | * @intelhaddata:substream private data |
| 904 | * |
| 905 | * This function is called in the prepare callback. |
| 906 | * It programs based on the audio and display sampling frequency |
| 907 | */ |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 908 | static int snd_intelhad_prog_n(u32 aud_samp_freq, u32 *n_param, |
| 909 | struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 910 | { |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 911 | int n_val; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 912 | |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 913 | if (intelhaddata->dp_output) { |
| 914 | /* |
| 915 | * According to DP specs, Maud and Naud values hold |
| 916 | * a relationship, which is stated as: |
| 917 | * Maud/Naud = 512 * fs / f_LS_Clk |
| 918 | * where, fs is the sampling frequency of the audio stream |
| 919 | * and Naud is 32768 for Async clock. |
| 920 | */ |
| 921 | |
| 922 | n_val = DP_NAUD_VAL; |
| 923 | } else |
| 924 | n_val = had_calculate_n_value(aud_samp_freq); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 925 | |
| 926 | if (n_val < 0) |
| 927 | return n_val; |
| 928 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 929 | had_write_register(intelhaddata, AUD_N_ENABLE, (BIT(24) | n_val)); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 930 | *n_param = n_val; |
| 931 | return 0; |
| 932 | } |
| 933 | |
Takashi Iwai | 03c3437 | 2017-02-02 16:19:03 +0100 | [diff] [blame] | 934 | #define MAX_CNT 0xFF |
| 935 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 936 | static void snd_intelhad_handle_underrun(struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 937 | { |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 938 | u32 hdmi_status = 0, i = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 939 | |
| 940 | /* Handle Underrun interrupt within Audio Unit */ |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 941 | had_write_register(intelhaddata, AUD_CONFIG, 0); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 942 | /* Reset buffer pointers */ |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 943 | had_write_register(intelhaddata, AUD_HDMI_STATUS, 1); |
| 944 | had_write_register(intelhaddata, AUD_HDMI_STATUS, 0); |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 945 | /* |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 946 | * The interrupt status 'sticky' bits might not be cleared by |
| 947 | * setting '1' to that bit once... |
| 948 | */ |
| 949 | do { /* clear bit30, 31 AUD_HDMI_STATUS */ |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 950 | had_read_register(intelhaddata, AUD_HDMI_STATUS, |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 951 | &hdmi_status); |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 952 | dev_dbg(intelhaddata->dev, "HDMI status =0x%x\n", hdmi_status); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 953 | if (hdmi_status & AUD_CONFIG_MASK_UNDERRUN) { |
| 954 | i++; |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 955 | had_write_register(intelhaddata, |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 956 | AUD_HDMI_STATUS, hdmi_status); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 957 | } else |
| 958 | break; |
| 959 | } while (i < MAX_CNT); |
| 960 | if (i >= MAX_CNT) |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 961 | dev_err(intelhaddata->dev, "Unable to clear UNDERRUN bits\n"); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 962 | } |
| 963 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 964 | /* |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 965 | * snd_intelhad_open - stream initializations are done here |
| 966 | * @substream:substream for which the stream function is called |
| 967 | * |
| 968 | * This function is called whenever a PCM stream is opened |
| 969 | */ |
| 970 | static int snd_intelhad_open(struct snd_pcm_substream *substream) |
| 971 | { |
| 972 | struct snd_intelhad *intelhaddata; |
| 973 | struct snd_pcm_runtime *runtime; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 974 | int retval; |
| 975 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 976 | intelhaddata = snd_pcm_substream_chip(substream); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 977 | runtime = substream->runtime; |
Takashi Iwai | 6ddb3ab | 2017-01-30 18:17:44 +0100 | [diff] [blame] | 978 | intelhaddata->underrun_count = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 979 | |
Takashi Iwai | 182cdf2 | 2017-02-02 14:43:39 +0100 | [diff] [blame] | 980 | pm_runtime_get_sync(intelhaddata->dev); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 981 | |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 982 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 983 | dev_dbg(intelhaddata->dev, "%s: HDMI cable plugged-out\n", |
| 984 | __func__); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 985 | retval = -ENODEV; |
Takashi Iwai | fa5dfe6 | 2017-02-01 22:03:26 +0100 | [diff] [blame] | 986 | goto error; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | /* set the runtime hw parameter with local snd_pcm_hardware struct */ |
| 990 | runtime->hw = snd_intel_hadstream; |
| 991 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 992 | retval = snd_pcm_hw_constraint_integer(runtime, |
| 993 | SNDRV_PCM_HW_PARAM_PERIODS); |
| 994 | if (retval < 0) |
Takashi Iwai | fa5dfe6 | 2017-02-01 22:03:26 +0100 | [diff] [blame] | 995 | goto error; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 996 | |
| 997 | /* Make sure, that the period size is always aligned |
| 998 | * 64byte boundary |
| 999 | */ |
| 1000 | retval = snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 1001 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64); |
| 1002 | if (retval < 0) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1003 | dev_dbg(intelhaddata->dev, "%s:step_size=64 failed,err=%d\n", |
| 1004 | __func__, retval); |
Takashi Iwai | fa5dfe6 | 2017-02-01 22:03:26 +0100 | [diff] [blame] | 1005 | goto error; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1006 | } |
| 1007 | |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1008 | spin_lock_irq(&intelhaddata->had_spinlock); |
| 1009 | intelhaddata->stream_info.substream = substream; |
| 1010 | intelhaddata->stream_info.substream_refcount++; |
| 1011 | spin_unlock_irq(&intelhaddata->had_spinlock); |
| 1012 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1013 | return retval; |
Takashi Iwai | fa5dfe6 | 2017-02-01 22:03:26 +0100 | [diff] [blame] | 1014 | error: |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1015 | pm_runtime_put(intelhaddata->dev); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1016 | return retval; |
| 1017 | } |
| 1018 | |
Takashi Iwai | df76df1 | 2017-01-31 16:04:10 +0100 | [diff] [blame] | 1019 | /* |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1020 | * snd_intelhad_close - to free parameteres when stream is stopped |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1021 | * @substream: substream for which the function is called |
| 1022 | * |
| 1023 | * This function is called by ALSA framework when stream is stopped |
| 1024 | */ |
| 1025 | static int snd_intelhad_close(struct snd_pcm_substream *substream) |
| 1026 | { |
| 1027 | struct snd_intelhad *intelhaddata; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1028 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1029 | intelhaddata = snd_pcm_substream_chip(substream); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1030 | |
| 1031 | intelhaddata->stream_info.buffer_rendered = 0; |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1032 | spin_lock_irq(&intelhaddata->had_spinlock); |
| 1033 | intelhaddata->stream_info.substream = NULL; |
| 1034 | intelhaddata->stream_info.substream_refcount--; |
| 1035 | while (intelhaddata->stream_info.substream_refcount > 0) { |
| 1036 | spin_unlock_irq(&intelhaddata->had_spinlock); |
| 1037 | cpu_relax(); |
| 1038 | spin_lock_irq(&intelhaddata->had_spinlock); |
| 1039 | } |
| 1040 | spin_unlock_irq(&intelhaddata->had_spinlock); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1041 | |
| 1042 | /* Check if following drv_status modification is required - VA */ |
| 1043 | if (intelhaddata->drv_status != HAD_DRV_DISCONNECTED) { |
| 1044 | intelhaddata->drv_status = HAD_DRV_CONNECTED; |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1045 | dev_dbg(intelhaddata->dev, |
| 1046 | "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n", |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1047 | __func__, __LINE__); |
| 1048 | } |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1049 | pm_runtime_put(intelhaddata->dev); |
| 1050 | return 0; |
| 1051 | } |
| 1052 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1053 | /* |
| 1054 | * snd_intelhad_hw_params - to setup the hardware parameters |
| 1055 | * like allocating the buffers |
| 1056 | * @substream: substream for which the function is called |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1057 | * @hw_params: hardware parameters |
| 1058 | * |
| 1059 | * This function is called by ALSA framework when hardware params are set |
| 1060 | */ |
| 1061 | static int snd_intelhad_hw_params(struct snd_pcm_substream *substream, |
| 1062 | struct snd_pcm_hw_params *hw_params) |
| 1063 | { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1064 | struct snd_intelhad *intelhaddata; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1065 | unsigned long addr; |
| 1066 | int pages, buf_size, retval; |
| 1067 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1068 | if (!hw_params) |
| 1069 | return -EINVAL; |
| 1070 | |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1071 | intelhaddata = snd_pcm_substream_chip(substream); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1072 | buf_size = params_buffer_bytes(hw_params); |
| 1073 | retval = snd_pcm_lib_malloc_pages(substream, buf_size); |
| 1074 | if (retval < 0) |
| 1075 | return retval; |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1076 | dev_dbg(intelhaddata->dev, "%s:allocated memory = %d\n", |
| 1077 | __func__, buf_size); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1078 | /* mark the pages as uncached region */ |
| 1079 | addr = (unsigned long) substream->runtime->dma_area; |
| 1080 | pages = (substream->runtime->dma_bytes + PAGE_SIZE - 1) / PAGE_SIZE; |
| 1081 | retval = set_memory_uc(addr, pages); |
| 1082 | if (retval) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1083 | dev_err(intelhaddata->dev, "set_memory_uc failed.Error:%d\n", |
| 1084 | retval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1085 | return retval; |
| 1086 | } |
| 1087 | memset(substream->runtime->dma_area, 0, buf_size); |
| 1088 | |
| 1089 | return retval; |
| 1090 | } |
| 1091 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1092 | /* |
| 1093 | * snd_intelhad_hw_free - to release the resources allocated during |
| 1094 | * hardware params setup |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1095 | * @substream: substream for which the function is called |
| 1096 | * |
| 1097 | * This function is called by ALSA framework before close callback. |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1098 | */ |
| 1099 | static int snd_intelhad_hw_free(struct snd_pcm_substream *substream) |
| 1100 | { |
| 1101 | unsigned long addr; |
| 1102 | u32 pages; |
| 1103 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1104 | /* mark back the pages as cached/writeback region before the free */ |
| 1105 | if (substream->runtime->dma_area != NULL) { |
| 1106 | addr = (unsigned long) substream->runtime->dma_area; |
| 1107 | pages = (substream->runtime->dma_bytes + PAGE_SIZE - 1) / |
| 1108 | PAGE_SIZE; |
| 1109 | set_memory_wb(addr, pages); |
| 1110 | return snd_pcm_lib_free_pages(substream); |
| 1111 | } |
| 1112 | return 0; |
| 1113 | } |
| 1114 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1115 | /* |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1116 | * snd_intelhad_pcm_trigger - stream activities are handled here |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1117 | * @substream: substream for which the stream function is called |
| 1118 | * @cmd: the stream commamd thats requested from upper layer |
| 1119 | * |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1120 | * This function is called whenever an a stream activity is invoked |
| 1121 | */ |
| 1122 | static int snd_intelhad_pcm_trigger(struct snd_pcm_substream *substream, |
| 1123 | int cmd) |
| 1124 | { |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1125 | int retval = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1126 | struct snd_intelhad *intelhaddata; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1127 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1128 | intelhaddata = snd_pcm_substream_chip(substream); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1129 | |
| 1130 | switch (cmd) { |
| 1131 | case SNDRV_PCM_TRIGGER_START: |
Takashi Iwai | 182cdf2 | 2017-02-02 14:43:39 +0100 | [diff] [blame] | 1132 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 1133 | case SNDRV_PCM_TRIGGER_RESUME: |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1134 | /* Disable local INTRs till register prgmng is done */ |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 1135 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1136 | dev_dbg(intelhaddata->dev, |
| 1137 | "_START: HDMI cable plugged-out\n"); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1138 | retval = -ENODEV; |
| 1139 | break; |
| 1140 | } |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1141 | |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1142 | intelhaddata->stream_info.running = true; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1143 | |
| 1144 | /* Enable Audio */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1145 | snd_intelhad_enable_audio_int(intelhaddata, true); |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1146 | snd_intelhad_enable_audio(substream, intelhaddata, true); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1147 | break; |
| 1148 | |
| 1149 | case SNDRV_PCM_TRIGGER_STOP: |
Takashi Iwai | 182cdf2 | 2017-02-02 14:43:39 +0100 | [diff] [blame] | 1150 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 1151 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1152 | spin_lock(&intelhaddata->had_spinlock); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1153 | intelhaddata->curr_buf = 0; |
| 1154 | |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1155 | /* Stop reporting BUFFER_DONE/UNDERRUN to above layers */ |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1156 | |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1157 | intelhaddata->stream_info.running = false; |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1158 | spin_unlock(&intelhaddata->had_spinlock); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1159 | /* Disable Audio */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1160 | snd_intelhad_enable_audio_int(intelhaddata, false); |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1161 | snd_intelhad_enable_audio(substream, intelhaddata, false); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1162 | /* Reset buffer pointers */ |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 1163 | snd_intelhad_reset_audio(intelhaddata, 1); |
| 1164 | snd_intelhad_reset_audio(intelhaddata, 0); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1165 | snd_intelhad_enable_audio_int(intelhaddata, false); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1166 | break; |
| 1167 | |
| 1168 | default: |
| 1169 | retval = -EINVAL; |
| 1170 | } |
| 1171 | return retval; |
| 1172 | } |
| 1173 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1174 | /* |
| 1175 | * snd_intelhad_pcm_prepare - internal preparation before starting a stream |
| 1176 | * @substream: substream for which the function is called |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1177 | * |
| 1178 | * This function is called when a stream is started for internal preparation. |
| 1179 | */ |
| 1180 | static int snd_intelhad_pcm_prepare(struct snd_pcm_substream *substream) |
| 1181 | { |
| 1182 | int retval; |
| 1183 | u32 disp_samp_freq, n_param; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 1184 | u32 link_rate = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1185 | struct snd_intelhad *intelhaddata; |
| 1186 | struct snd_pcm_runtime *runtime; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1187 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1188 | intelhaddata = snd_pcm_substream_chip(substream); |
| 1189 | runtime = substream->runtime; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1190 | |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 1191 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1192 | dev_dbg(intelhaddata->dev, "%s: HDMI cable plugged-out\n", |
| 1193 | __func__); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1194 | retval = -ENODEV; |
| 1195 | goto prep_end; |
| 1196 | } |
| 1197 | |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1198 | dev_dbg(intelhaddata->dev, "period_size=%d\n", |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1199 | (int)frames_to_bytes(runtime, runtime->period_size)); |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1200 | dev_dbg(intelhaddata->dev, "periods=%d\n", runtime->periods); |
| 1201 | dev_dbg(intelhaddata->dev, "buffer_size=%d\n", |
| 1202 | (int)snd_pcm_lib_buffer_bytes(substream)); |
| 1203 | dev_dbg(intelhaddata->dev, "rate=%d\n", runtime->rate); |
| 1204 | dev_dbg(intelhaddata->dev, "channels=%d\n", runtime->channels); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1205 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1206 | intelhaddata->stream_info.buffer_rendered = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1207 | |
| 1208 | /* Get N value in KHz */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1209 | disp_samp_freq = intelhaddata->tmds_clock_speed; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1210 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 1211 | retval = snd_intelhad_prog_n(substream->runtime->rate, &n_param, |
| 1212 | intelhaddata); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1213 | if (retval) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1214 | dev_err(intelhaddata->dev, |
| 1215 | "programming N value failed %#x\n", retval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1216 | goto prep_end; |
| 1217 | } |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 1218 | |
| 1219 | if (intelhaddata->dp_output) |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1220 | link_rate = intelhaddata->link_rate; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 1221 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 1222 | snd_intelhad_prog_cts(substream->runtime->rate, |
| 1223 | disp_samp_freq, link_rate, |
| 1224 | n_param, intelhaddata); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1225 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 1226 | snd_intelhad_prog_dip(substream, intelhaddata); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1227 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 1228 | retval = snd_intelhad_audio_ctrl(substream, intelhaddata); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1229 | |
| 1230 | /* Prog buffer address */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1231 | retval = snd_intelhad_prog_buffer(substream, intelhaddata, |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1232 | HAD_BUF_TYPE_A, HAD_BUF_TYPE_D); |
| 1233 | |
| 1234 | /* |
| 1235 | * Program channel mapping in following order: |
| 1236 | * FL, FR, C, LFE, RL, RR |
| 1237 | */ |
| 1238 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 1239 | had_write_register(intelhaddata, AUD_BUF_CH_SWAP, SWAP_LFE_CENTER); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1240 | |
| 1241 | prep_end: |
| 1242 | return retval; |
| 1243 | } |
| 1244 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1245 | /* |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1246 | * snd_intelhad_pcm_pointer- to send the current buffer pointerprocessed by hw |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1247 | * @substream: substream for which the function is called |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1248 | * |
| 1249 | * This function is called by ALSA framework to get the current hw buffer ptr |
| 1250 | * when a period is elapsed |
| 1251 | */ |
| 1252 | static snd_pcm_uframes_t snd_intelhad_pcm_pointer( |
| 1253 | struct snd_pcm_substream *substream) |
| 1254 | { |
| 1255 | struct snd_intelhad *intelhaddata; |
| 1256 | u32 bytes_rendered = 0; |
| 1257 | u32 t; |
| 1258 | int buf_id; |
| 1259 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1260 | intelhaddata = snd_pcm_substream_chip(substream); |
| 1261 | |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 1262 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) |
| 1263 | return SNDRV_PCM_POS_XRUN; |
| 1264 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1265 | /* Use a hw register to calculate sub-period position reports. |
| 1266 | * This makes PulseAudio happier. |
| 1267 | */ |
| 1268 | |
| 1269 | buf_id = intelhaddata->curr_buf % 4; |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 1270 | had_read_register(intelhaddata, |
| 1271 | AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH), &t); |
Jerome Anand | 232892f | 2017-01-25 04:27:53 +0530 | [diff] [blame] | 1272 | |
| 1273 | if ((t == 0) || (t == ((u32)-1L))) { |
Takashi Iwai | 6ddb3ab | 2017-01-30 18:17:44 +0100 | [diff] [blame] | 1274 | intelhaddata->underrun_count++; |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1275 | dev_dbg(intelhaddata->dev, |
| 1276 | "discovered buffer done for buf %d, count = %d\n", |
Takashi Iwai | 6ddb3ab | 2017-01-30 18:17:44 +0100 | [diff] [blame] | 1277 | buf_id, intelhaddata->underrun_count); |
Jerome Anand | 232892f | 2017-01-25 04:27:53 +0530 | [diff] [blame] | 1278 | |
Takashi Iwai | 6ddb3ab | 2017-01-30 18:17:44 +0100 | [diff] [blame] | 1279 | if (intelhaddata->underrun_count > (HAD_MIN_PERIODS/2)) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1280 | dev_dbg(intelhaddata->dev, |
| 1281 | "assume audio_codec_reset, underrun = %d - do xrun\n", |
Takashi Iwai | 6ddb3ab | 2017-01-30 18:17:44 +0100 | [diff] [blame] | 1282 | intelhaddata->underrun_count); |
| 1283 | intelhaddata->underrun_count = 0; |
Jerome Anand | 232892f | 2017-01-25 04:27:53 +0530 | [diff] [blame] | 1284 | return SNDRV_PCM_POS_XRUN; |
| 1285 | } |
| 1286 | } else { |
| 1287 | /* Reset Counter */ |
Takashi Iwai | 6ddb3ab | 2017-01-30 18:17:44 +0100 | [diff] [blame] | 1288 | intelhaddata->underrun_count = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1289 | } |
Jerome Anand | 232892f | 2017-01-25 04:27:53 +0530 | [diff] [blame] | 1290 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1291 | t = intelhaddata->buf_info[buf_id].buf_size - t; |
| 1292 | |
| 1293 | if (intelhaddata->stream_info.buffer_rendered) |
| 1294 | div_u64_rem(intelhaddata->stream_info.buffer_rendered, |
| 1295 | intelhaddata->stream_info.ring_buf_size, |
| 1296 | &(bytes_rendered)); |
| 1297 | |
Takashi Iwai | 7d9e798 | 2017-02-01 22:25:58 +0100 | [diff] [blame] | 1298 | return bytes_to_frames(substream->runtime, bytes_rendered + t); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1299 | } |
| 1300 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1301 | /* |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1302 | * snd_intelhad_pcm_mmap- mmaps a kernel buffer to user space for copying data |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1303 | * @substream: substream for which the function is called |
| 1304 | * @vma: struct instance of memory VMM memory area |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1305 | * |
| 1306 | * This function is called by OS when a user space component |
| 1307 | * tries to get mmap memory from driver |
| 1308 | */ |
| 1309 | static int snd_intelhad_pcm_mmap(struct snd_pcm_substream *substream, |
| 1310 | struct vm_area_struct *vma) |
| 1311 | { |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1312 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 1313 | return remap_pfn_range(vma, vma->vm_start, |
| 1314 | substream->dma_buffer.addr >> PAGE_SHIFT, |
| 1315 | vma->vm_end - vma->vm_start, vma->vm_page_prot); |
| 1316 | } |
| 1317 | |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1318 | /* process mode change of the running stream; called in mutex */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1319 | static int hdmi_audio_mode_change(struct snd_intelhad *intelhaddata) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1320 | { |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1321 | struct snd_pcm_substream *substream; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1322 | int retval = 0; |
| 1323 | u32 disp_samp_freq, n_param; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 1324 | u32 link_rate = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1325 | |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1326 | substream = had_substream_get(intelhaddata); |
| 1327 | if (!substream) |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1328 | return 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1329 | |
| 1330 | /* Disable Audio */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1331 | snd_intelhad_enable_audio(substream, intelhaddata, false); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1332 | |
| 1333 | /* Update CTS value */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1334 | disp_samp_freq = intelhaddata->tmds_clock_speed; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1335 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 1336 | retval = snd_intelhad_prog_n(substream->runtime->rate, &n_param, |
| 1337 | intelhaddata); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1338 | if (retval) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1339 | dev_err(intelhaddata->dev, |
| 1340 | "programming N value failed %#x\n", retval); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1341 | goto out; |
| 1342 | } |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 1343 | |
| 1344 | if (intelhaddata->dp_output) |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1345 | link_rate = intelhaddata->link_rate; |
Pierre-Louis Bossart | 964ca80 | 2017-01-31 14:16:52 -0600 | [diff] [blame] | 1346 | |
Takashi Iwai | 76296ef | 2017-01-30 16:09:11 +0100 | [diff] [blame] | 1347 | snd_intelhad_prog_cts(substream->runtime->rate, |
| 1348 | disp_samp_freq, link_rate, |
| 1349 | n_param, intelhaddata); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1350 | |
| 1351 | /* Enable Audio */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1352 | snd_intelhad_enable_audio(substream, intelhaddata, true); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1353 | |
| 1354 | out: |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1355 | had_substream_put(intelhaddata); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1356 | return retval; |
| 1357 | } |
| 1358 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1359 | static inline int had_chk_intrmiss(struct snd_intelhad *intelhaddata, |
| 1360 | enum intel_had_aud_buf_type buf_id) |
| 1361 | { |
| 1362 | int i, intr_count = 0; |
| 1363 | enum intel_had_aud_buf_type buff_done; |
| 1364 | u32 buf_size, buf_addr; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1365 | |
| 1366 | buff_done = buf_id; |
| 1367 | |
| 1368 | intr_count = snd_intelhad_read_len(intelhaddata); |
| 1369 | if (intr_count > 1) { |
| 1370 | /* In case of active playback */ |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1371 | dev_err(intelhaddata->dev, |
| 1372 | "Driver detected %d missed buffer done interrupt(s)\n", |
| 1373 | (intr_count - 1)); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1374 | if (intr_count > 3) |
| 1375 | return intr_count; |
| 1376 | |
| 1377 | buf_id += (intr_count - 1); |
| 1378 | /* Reprogram registers*/ |
| 1379 | for (i = buff_done; i < buf_id; i++) { |
| 1380 | int j = i % 4; |
| 1381 | |
| 1382 | buf_size = intelhaddata->buf_info[j].buf_size; |
| 1383 | buf_addr = intelhaddata->buf_info[j].buf_addr; |
| 1384 | had_write_register(intelhaddata, |
| 1385 | AUD_BUF_A_LENGTH + |
| 1386 | (j * HAD_REG_WIDTH), buf_size); |
| 1387 | had_write_register(intelhaddata, |
| 1388 | AUD_BUF_A_ADDR+(j * HAD_REG_WIDTH), |
| 1389 | (buf_addr | BIT(0) | BIT(1))); |
| 1390 | } |
| 1391 | buf_id = buf_id % 4; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1392 | intelhaddata->buff_done = buf_id; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1393 | } |
| 1394 | |
| 1395 | return intr_count; |
| 1396 | } |
| 1397 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1398 | /* called from irq handler */ |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1399 | static int had_process_buffer_done(struct snd_intelhad *intelhaddata) |
| 1400 | { |
| 1401 | u32 len = 1; |
| 1402 | enum intel_had_aud_buf_type buf_id; |
| 1403 | enum intel_had_aud_buf_type buff_done; |
| 1404 | struct pcm_stream_info *stream; |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1405 | struct snd_pcm_substream *substream; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1406 | u32 buf_size; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1407 | int intr_count; |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1408 | unsigned long flags; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1409 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1410 | stream = &intelhaddata->stream_info; |
| 1411 | intr_count = 1; |
| 1412 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1413 | spin_lock_irqsave(&intelhaddata->had_spinlock, flags); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1414 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) { |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1415 | spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1416 | dev_dbg(intelhaddata->dev, |
| 1417 | "%s:Device already disconnected\n", __func__); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1418 | return 0; |
| 1419 | } |
| 1420 | buf_id = intelhaddata->curr_buf; |
| 1421 | intelhaddata->buff_done = buf_id; |
| 1422 | buff_done = intelhaddata->buff_done; |
| 1423 | buf_size = intelhaddata->buf_info[buf_id].buf_size; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1424 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1425 | /* Every debug statement has an implication |
| 1426 | * of ~5msec. Thus, avoid having >3 debug statements |
| 1427 | * for each buffer_done handling. |
| 1428 | */ |
| 1429 | |
| 1430 | /* Check for any intr_miss in case of active playback */ |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1431 | if (stream->running) { |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1432 | intr_count = had_chk_intrmiss(intelhaddata, buf_id); |
| 1433 | if (!intr_count || (intr_count > 3)) { |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1434 | spin_unlock_irqrestore(&intelhaddata->had_spinlock, |
| 1435 | flags); |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1436 | dev_err(intelhaddata->dev, |
| 1437 | "HAD SW state in non-recoverable mode\n"); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1438 | return 0; |
| 1439 | } |
| 1440 | buf_id += (intr_count - 1); |
| 1441 | buf_id = buf_id % 4; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | intelhaddata->buf_info[buf_id].is_valid = true; |
| 1445 | if (intelhaddata->valid_buf_cnt-1 == buf_id) { |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1446 | if (stream->running) |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1447 | intelhaddata->curr_buf = HAD_BUF_TYPE_A; |
| 1448 | } else |
| 1449 | intelhaddata->curr_buf = buf_id + 1; |
| 1450 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1451 | spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1452 | |
Takashi Iwai | 79f439e | 2017-01-31 16:46:44 +0100 | [diff] [blame] | 1453 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1454 | dev_dbg(intelhaddata->dev, "HDMI cable plugged-out\n"); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1455 | return 0; |
| 1456 | } |
| 1457 | |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1458 | /* Reprogram the registers with addr and length */ |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1459 | had_write_register(intelhaddata, |
| 1460 | AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH), |
| 1461 | buf_size); |
| 1462 | had_write_register(intelhaddata, |
| 1463 | AUD_BUF_A_ADDR + (buf_id * HAD_REG_WIDTH), |
| 1464 | intelhaddata->buf_info[buf_id].buf_addr | |
| 1465 | BIT(0) | BIT(1)); |
| 1466 | |
| 1467 | had_read_register(intelhaddata, |
| 1468 | AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH), |
| 1469 | &len); |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1470 | dev_dbg(intelhaddata->dev, "%s:Enabled buf[%d]\n", __func__, buf_id); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1471 | |
| 1472 | /* In case of actual data, |
| 1473 | * report buffer_done to above ALSA layer |
| 1474 | */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1475 | substream = had_substream_get(intelhaddata); |
| 1476 | if (substream) { |
| 1477 | buf_size = intelhaddata->buf_info[buf_id].buf_size; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1478 | intelhaddata->stream_info.buffer_rendered += |
| 1479 | (intr_count * buf_size); |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1480 | snd_pcm_period_elapsed(substream); |
| 1481 | had_substream_put(intelhaddata); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | return 0; |
| 1485 | } |
| 1486 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1487 | /* called from irq handler */ |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1488 | static int had_process_buffer_underrun(struct snd_intelhad *intelhaddata) |
| 1489 | { |
| 1490 | enum intel_had_aud_buf_type buf_id; |
| 1491 | struct pcm_stream_info *stream; |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1492 | struct snd_pcm_substream *substream; |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1493 | unsigned long flags; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1494 | int drv_status; |
| 1495 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1496 | stream = &intelhaddata->stream_info; |
| 1497 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1498 | spin_lock_irqsave(&intelhaddata->had_spinlock, flags); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1499 | buf_id = intelhaddata->curr_buf; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1500 | intelhaddata->buff_done = buf_id; |
| 1501 | drv_status = intelhaddata->drv_status; |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1502 | if (stream->running) |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1503 | intelhaddata->curr_buf = HAD_BUF_TYPE_A; |
| 1504 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1505 | spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1506 | |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1507 | dev_dbg(intelhaddata->dev, "Enter:%s buf_id=%d, stream_running=%d\n", |
| 1508 | __func__, buf_id, stream->running); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1509 | |
| 1510 | snd_intelhad_handle_underrun(intelhaddata); |
| 1511 | |
| 1512 | if (drv_status == HAD_DRV_DISCONNECTED) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1513 | dev_dbg(intelhaddata->dev, |
| 1514 | "%s:Device already disconnected\n", __func__); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1515 | return 0; |
| 1516 | } |
| 1517 | |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1518 | /* Report UNDERRUN error to above layers */ |
| 1519 | substream = had_substream_get(intelhaddata); |
| 1520 | if (substream) { |
| 1521 | snd_pcm_stop_xrun(substream); |
| 1522 | had_substream_put(intelhaddata); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | return 0; |
| 1526 | } |
| 1527 | |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1528 | /* process hot plug, called from wq with mutex locked */ |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1529 | static void had_process_hot_plug(struct snd_intelhad *intelhaddata) |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1530 | { |
| 1531 | enum intel_had_aud_buf_type buf_id; |
| 1532 | struct snd_pcm_substream *substream; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1533 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1534 | spin_lock_irq(&intelhaddata->had_spinlock); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1535 | if (intelhaddata->drv_status == HAD_DRV_CONNECTED) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1536 | dev_dbg(intelhaddata->dev, "Device already connected\n"); |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1537 | spin_unlock_irq(&intelhaddata->had_spinlock); |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1538 | return; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1539 | } |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1540 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1541 | buf_id = intelhaddata->curr_buf; |
| 1542 | intelhaddata->buff_done = buf_id; |
| 1543 | intelhaddata->drv_status = HAD_DRV_CONNECTED; |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1544 | dev_dbg(intelhaddata->dev, |
| 1545 | "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n", |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1546 | __func__, __LINE__); |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1547 | spin_unlock_irq(&intelhaddata->had_spinlock); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1548 | |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1549 | dev_dbg(intelhaddata->dev, "Processing HOT_PLUG, buf_id = %d\n", |
| 1550 | buf_id); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1551 | |
| 1552 | /* Safety check */ |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1553 | substream = had_substream_get(intelhaddata); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1554 | if (substream) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1555 | dev_dbg(intelhaddata->dev, |
| 1556 | "Force to stop the active stream by disconnection\n"); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1557 | /* Set runtime->state to hw_params done */ |
| 1558 | snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1559 | had_substream_put(intelhaddata); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | had_build_channel_allocation_map(intelhaddata); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1565 | /* process hot unplug, called from wq with mutex locked */ |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1566 | static void had_process_hot_unplug(struct snd_intelhad *intelhaddata) |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1567 | { |
| 1568 | enum intel_had_aud_buf_type buf_id; |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1569 | struct snd_pcm_substream *substream; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1570 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1571 | buf_id = intelhaddata->curr_buf; |
| 1572 | |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1573 | substream = had_substream_get(intelhaddata); |
| 1574 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1575 | spin_lock_irq(&intelhaddata->had_spinlock); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1576 | |
| 1577 | if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) { |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1578 | dev_dbg(intelhaddata->dev, "Device already disconnected\n"); |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1579 | spin_unlock_irq(&intelhaddata->had_spinlock); |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1580 | goto out; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1581 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1582 | } |
| 1583 | |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1584 | /* Disable Audio */ |
| 1585 | snd_intelhad_enable_audio_int(intelhaddata, false); |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1586 | snd_intelhad_enable_audio(substream, intelhaddata, false); |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1587 | |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1588 | intelhaddata->drv_status = HAD_DRV_DISCONNECTED; |
Takashi Iwai | c75b047 | 2017-01-31 15:49:15 +0100 | [diff] [blame] | 1589 | dev_dbg(intelhaddata->dev, |
| 1590 | "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n", |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1591 | __func__, __LINE__); |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1592 | spin_unlock_irq(&intelhaddata->had_spinlock); |
Takashi Iwai | 313d9f2 | 2017-02-02 13:00:12 +0100 | [diff] [blame] | 1593 | |
| 1594 | /* Report to above ALSA layer */ |
| 1595 | if (substream) |
| 1596 | snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP); |
| 1597 | |
| 1598 | out: |
| 1599 | if (substream) |
| 1600 | had_substream_put(intelhaddata); |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1601 | kfree(intelhaddata->chmap->chmap); |
| 1602 | intelhaddata->chmap->chmap = NULL; |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | /* PCM operations structure and the calls back for the same */ |
| 1606 | static struct snd_pcm_ops snd_intelhad_playback_ops = { |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1607 | .open = snd_intelhad_open, |
| 1608 | .close = snd_intelhad_close, |
| 1609 | .ioctl = snd_pcm_lib_ioctl, |
| 1610 | .hw_params = snd_intelhad_hw_params, |
| 1611 | .hw_free = snd_intelhad_hw_free, |
| 1612 | .prepare = snd_intelhad_pcm_prepare, |
| 1613 | .trigger = snd_intelhad_pcm_trigger, |
| 1614 | .pointer = snd_intelhad_pcm_pointer, |
| 1615 | .mmap = snd_intelhad_pcm_mmap, |
| 1616 | }; |
| 1617 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1618 | static int had_iec958_info(struct snd_kcontrol *kcontrol, |
| 1619 | struct snd_ctl_elem_info *uinfo) |
| 1620 | { |
| 1621 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1622 | uinfo->count = 1; |
| 1623 | return 0; |
| 1624 | } |
| 1625 | |
| 1626 | static int had_iec958_get(struct snd_kcontrol *kcontrol, |
| 1627 | struct snd_ctl_elem_value *ucontrol) |
| 1628 | { |
| 1629 | struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol); |
| 1630 | |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1631 | mutex_lock(&intelhaddata->mutex); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1632 | ucontrol->value.iec958.status[0] = (intelhaddata->aes_bits >> 0) & 0xff; |
| 1633 | ucontrol->value.iec958.status[1] = (intelhaddata->aes_bits >> 8) & 0xff; |
| 1634 | ucontrol->value.iec958.status[2] = |
| 1635 | (intelhaddata->aes_bits >> 16) & 0xff; |
| 1636 | ucontrol->value.iec958.status[3] = |
| 1637 | (intelhaddata->aes_bits >> 24) & 0xff; |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1638 | mutex_unlock(&intelhaddata->mutex); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1639 | return 0; |
| 1640 | } |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1641 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1642 | static int had_iec958_mask_get(struct snd_kcontrol *kcontrol, |
| 1643 | struct snd_ctl_elem_value *ucontrol) |
| 1644 | { |
| 1645 | ucontrol->value.iec958.status[0] = 0xff; |
| 1646 | ucontrol->value.iec958.status[1] = 0xff; |
| 1647 | ucontrol->value.iec958.status[2] = 0xff; |
| 1648 | ucontrol->value.iec958.status[3] = 0xff; |
| 1649 | return 0; |
| 1650 | } |
Takashi Iwai | 372d855 | 2017-01-31 13:57:58 +0100 | [diff] [blame] | 1651 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1652 | static int had_iec958_put(struct snd_kcontrol *kcontrol, |
| 1653 | struct snd_ctl_elem_value *ucontrol) |
| 1654 | { |
| 1655 | unsigned int val; |
| 1656 | struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1657 | int changed = 0; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1658 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1659 | val = (ucontrol->value.iec958.status[0] << 0) | |
| 1660 | (ucontrol->value.iec958.status[1] << 8) | |
| 1661 | (ucontrol->value.iec958.status[2] << 16) | |
| 1662 | (ucontrol->value.iec958.status[3] << 24); |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1663 | mutex_lock(&intelhaddata->mutex); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1664 | if (intelhaddata->aes_bits != val) { |
| 1665 | intelhaddata->aes_bits = val; |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1666 | changed = 1; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1667 | } |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1668 | mutex_unlock(&intelhaddata->mutex); |
| 1669 | return changed; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1670 | } |
| 1671 | |
Takashi Iwai | 4aedb94 | 2017-02-02 16:38:39 +0100 | [diff] [blame^] | 1672 | static int had_ctl_eld_info(struct snd_kcontrol *kcontrol, |
| 1673 | struct snd_ctl_elem_info *uinfo) |
| 1674 | { |
| 1675 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 1676 | uinfo->count = HDMI_MAX_ELD_BYTES; |
| 1677 | return 0; |
| 1678 | } |
| 1679 | |
| 1680 | static int had_ctl_eld_get(struct snd_kcontrol *kcontrol, |
| 1681 | struct snd_ctl_elem_value *ucontrol) |
| 1682 | { |
| 1683 | struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol); |
| 1684 | |
| 1685 | mutex_lock(&intelhaddata->mutex); |
| 1686 | memcpy(ucontrol->value.bytes.data, intelhaddata->eld, |
| 1687 | HDMI_MAX_ELD_BYTES); |
| 1688 | mutex_unlock(&intelhaddata->mutex); |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
| 1692 | static struct snd_kcontrol_new had_controls[] = { |
| 1693 | { |
| 1694 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1695 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1696 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK), |
| 1697 | .info = had_iec958_info, /* shared */ |
| 1698 | .get = had_iec958_mask_get, |
| 1699 | }, |
| 1700 | { |
| 1701 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1702 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 1703 | .info = had_iec958_info, |
| 1704 | .get = had_iec958_get, |
| 1705 | .put = had_iec958_put, |
| 1706 | }, |
| 1707 | { |
| 1708 | .access = (SNDRV_CTL_ELEM_ACCESS_READ | |
| 1709 | SNDRV_CTL_ELEM_ACCESS_VOLATILE), |
| 1710 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1711 | .name = "ELD", |
| 1712 | .info = had_ctl_eld_info, |
| 1713 | .get = had_ctl_eld_get, |
| 1714 | }, |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1715 | }; |
| 1716 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1717 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1718 | static irqreturn_t display_pipe_interrupt_handler(int irq, void *dev_id) |
| 1719 | { |
| 1720 | struct snd_intelhad *ctx = dev_id; |
| 1721 | u32 audio_stat, audio_reg; |
| 1722 | |
Takashi Iwai | 4151ee8 | 2017-01-31 18:14:15 +0100 | [diff] [blame] | 1723 | audio_reg = AUD_HDMI_STATUS; |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1724 | mid_hdmi_audio_read(ctx, audio_reg, &audio_stat); |
| 1725 | |
| 1726 | if (audio_stat & HDMI_AUDIO_UNDERRUN) { |
| 1727 | mid_hdmi_audio_write(ctx, audio_reg, HDMI_AUDIO_UNDERRUN); |
| 1728 | had_process_buffer_underrun(ctx); |
| 1729 | } |
| 1730 | |
| 1731 | if (audio_stat & HDMI_AUDIO_BUFFER_DONE) { |
| 1732 | mid_hdmi_audio_write(ctx, audio_reg, HDMI_AUDIO_BUFFER_DONE); |
| 1733 | had_process_buffer_done(ctx); |
| 1734 | } |
| 1735 | |
| 1736 | return IRQ_HANDLED; |
| 1737 | } |
| 1738 | |
| 1739 | static void notify_audio_lpe(struct platform_device *pdev) |
| 1740 | { |
| 1741 | struct snd_intelhad *ctx = platform_get_drvdata(pdev); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1742 | |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1743 | schedule_work(&ctx->hdmi_audio_wq); |
| 1744 | } |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1745 | |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1746 | static void had_audio_wq(struct work_struct *work) |
| 1747 | { |
| 1748 | struct snd_intelhad *ctx = |
| 1749 | container_of(work, struct snd_intelhad, hdmi_audio_wq); |
| 1750 | struct intel_hdmi_lpe_audio_pdata *pdata = ctx->dev->platform_data; |
| 1751 | |
Takashi Iwai | 182cdf2 | 2017-02-02 14:43:39 +0100 | [diff] [blame] | 1752 | pm_runtime_get_sync(ctx->dev); |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1753 | mutex_lock(&ctx->mutex); |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1754 | if (!pdata->hdmi_connected) { |
| 1755 | dev_dbg(ctx->dev, "%s: Event: HAD_NOTIFY_HOT_UNPLUG\n", |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1756 | __func__); |
Takashi Iwai | 4aedb94 | 2017-02-02 16:38:39 +0100 | [diff] [blame^] | 1757 | memset(ctx->eld, 0, sizeof(ctx->eld)); /* clear the old ELD */ |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1758 | had_process_hot_unplug(ctx); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1759 | } else { |
| 1760 | struct intel_hdmi_lpe_audio_eld *eld = &pdata->eld; |
| 1761 | |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1762 | dev_dbg(ctx->dev, "%s: HAD_NOTIFY_ELD : port = %d, tmds = %d\n", |
| 1763 | __func__, eld->port_id, pdata->tmds_clock_speed); |
| 1764 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1765 | switch (eld->pipe_id) { |
| 1766 | case 0: |
| 1767 | ctx->had_config_offset = AUDIO_HDMI_CONFIG_A; |
| 1768 | break; |
| 1769 | case 1: |
| 1770 | ctx->had_config_offset = AUDIO_HDMI_CONFIG_B; |
| 1771 | break; |
| 1772 | case 2: |
| 1773 | ctx->had_config_offset = AUDIO_HDMI_CONFIG_C; |
| 1774 | break; |
| 1775 | default: |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1776 | dev_dbg(ctx->dev, "Invalid pipe %d\n", |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1777 | eld->pipe_id); |
| 1778 | break; |
| 1779 | } |
| 1780 | |
Takashi Iwai | df0435d | 2017-02-02 15:37:11 +0100 | [diff] [blame] | 1781 | memcpy(ctx->eld, eld->eld_data, sizeof(ctx->eld)); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1782 | |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1783 | ctx->dp_output = pdata->dp_output; |
| 1784 | ctx->tmds_clock_speed = pdata->tmds_clock_speed; |
| 1785 | ctx->link_rate = pdata->link_rate; |
| 1786 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1787 | had_process_hot_plug(ctx); |
| 1788 | |
Takashi Iwai | 0e9c67d | 2017-02-01 17:53:19 +0100 | [diff] [blame] | 1789 | /* Process mode change if stream is active */ |
Takashi Iwai | f69bd10 | 2017-02-02 14:57:22 +0100 | [diff] [blame] | 1790 | hdmi_audio_mode_change(ctx); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1791 | } |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1792 | mutex_unlock(&ctx->mutex); |
Takashi Iwai | 182cdf2 | 2017-02-02 14:43:39 +0100 | [diff] [blame] | 1793 | pm_runtime_put(ctx->dev); |
| 1794 | } |
| 1795 | |
| 1796 | /* |
| 1797 | * PM callbacks |
| 1798 | */ |
| 1799 | |
| 1800 | static int hdmi_lpe_audio_runtime_suspend(struct device *dev) |
| 1801 | { |
| 1802 | struct snd_intelhad *ctx = dev_get_drvdata(dev); |
| 1803 | struct snd_pcm_substream *substream; |
| 1804 | |
| 1805 | substream = had_substream_get(ctx); |
| 1806 | if (substream) { |
| 1807 | snd_pcm_suspend(substream); |
| 1808 | had_substream_put(ctx); |
| 1809 | } |
| 1810 | |
| 1811 | return 0; |
| 1812 | } |
| 1813 | |
| 1814 | static int hdmi_lpe_audio_suspend(struct device *dev) |
| 1815 | { |
| 1816 | struct snd_intelhad *ctx = dev_get_drvdata(dev); |
| 1817 | int err; |
| 1818 | |
| 1819 | err = hdmi_lpe_audio_runtime_suspend(dev); |
| 1820 | if (!err) |
| 1821 | snd_power_change_state(ctx->card, SNDRV_CTL_POWER_D3hot); |
| 1822 | return err; |
| 1823 | } |
| 1824 | |
| 1825 | static int hdmi_lpe_audio_resume(struct device *dev) |
| 1826 | { |
| 1827 | struct snd_intelhad *ctx = dev_get_drvdata(dev); |
| 1828 | |
| 1829 | snd_power_change_state(ctx->card, SNDRV_CTL_POWER_D0); |
| 1830 | return 0; |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1831 | } |
| 1832 | |
| 1833 | /* release resources */ |
| 1834 | static void hdmi_lpe_audio_free(struct snd_card *card) |
| 1835 | { |
| 1836 | struct snd_intelhad *ctx = card->private_data; |
| 1837 | |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1838 | cancel_work_sync(&ctx->hdmi_audio_wq); |
| 1839 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1840 | if (ctx->mmio_start) |
| 1841 | iounmap(ctx->mmio_start); |
| 1842 | if (ctx->irq >= 0) |
| 1843 | free_irq(ctx->irq, ctx); |
| 1844 | } |
| 1845 | |
| 1846 | /* |
| 1847 | * hdmi_lpe_audio_probe - start bridge with i915 |
| 1848 | * |
| 1849 | * This function is called when the i915 driver creates the |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1850 | * hdmi-lpe-audio platform device. |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1851 | */ |
| 1852 | static int hdmi_lpe_audio_probe(struct platform_device *pdev) |
| 1853 | { |
| 1854 | struct snd_card *card; |
| 1855 | struct snd_intelhad *ctx; |
| 1856 | struct snd_pcm *pcm; |
| 1857 | struct intel_hdmi_lpe_audio_pdata *pdata; |
| 1858 | int irq; |
| 1859 | struct resource *res_mmio; |
Takashi Iwai | 4aedb94 | 2017-02-02 16:38:39 +0100 | [diff] [blame^] | 1860 | int i, ret; |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1861 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1862 | dev_dbg(&pdev->dev, "dma_mask: %p\n", pdev->dev.dma_mask); |
| 1863 | |
| 1864 | pdata = pdev->dev.platform_data; |
| 1865 | if (!pdata) { |
| 1866 | dev_err(&pdev->dev, "%s: quit: pdata not allocated by i915!!\n", __func__); |
| 1867 | return -EINVAL; |
| 1868 | } |
| 1869 | |
| 1870 | /* get resources */ |
| 1871 | irq = platform_get_irq(pdev, 0); |
| 1872 | if (irq < 0) { |
| 1873 | dev_err(&pdev->dev, "Could not get irq resource\n"); |
| 1874 | return -ENODEV; |
| 1875 | } |
| 1876 | |
| 1877 | res_mmio = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1878 | if (!res_mmio) { |
| 1879 | dev_err(&pdev->dev, "Could not get IO_MEM resources\n"); |
| 1880 | return -ENXIO; |
| 1881 | } |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1882 | |
Takashi Iwai | 5647aec | 2017-01-31 08:14:34 +0100 | [diff] [blame] | 1883 | /* create a card instance with ALSA framework */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1884 | ret = snd_card_new(&pdev->dev, hdmi_card_index, hdmi_card_id, |
| 1885 | THIS_MODULE, sizeof(*ctx), &card); |
| 1886 | if (ret) |
| 1887 | return ret; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1888 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1889 | ctx = card->private_data; |
| 1890 | spin_lock_init(&ctx->had_spinlock); |
Takashi Iwai | 8f8d1d7 | 2017-02-01 17:24:02 +0100 | [diff] [blame] | 1891 | mutex_init(&ctx->mutex); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1892 | ctx->drv_status = HAD_DRV_DISCONNECTED; |
| 1893 | ctx->dev = &pdev->dev; |
| 1894 | ctx->card = card; |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1895 | ctx->aes_bits = SNDRV_PCM_DEFAULT_CON_SPDIF; |
| 1896 | strcpy(card->driver, INTEL_HAD); |
| 1897 | strcpy(card->shortname, INTEL_HAD); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1898 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1899 | ctx->irq = -1; |
| 1900 | ctx->tmds_clock_speed = DIS_SAMPLE_RATE_148_5; |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1901 | INIT_WORK(&ctx->hdmi_audio_wq, had_audio_wq); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1902 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1903 | card->private_free = hdmi_lpe_audio_free; |
| 1904 | |
| 1905 | /* assume pipe A as default */ |
| 1906 | ctx->had_config_offset = AUDIO_HDMI_CONFIG_A; |
| 1907 | |
| 1908 | platform_set_drvdata(pdev, ctx); |
| 1909 | |
| 1910 | dev_dbg(&pdev->dev, "%s: mmio_start = 0x%x, mmio_end = 0x%x\n", |
| 1911 | __func__, (unsigned int)res_mmio->start, |
| 1912 | (unsigned int)res_mmio->end); |
| 1913 | |
| 1914 | ctx->mmio_start = ioremap_nocache(res_mmio->start, |
| 1915 | (size_t)(resource_size(res_mmio))); |
| 1916 | if (!ctx->mmio_start) { |
| 1917 | dev_err(&pdev->dev, "Could not get ioremap\n"); |
| 1918 | ret = -EACCES; |
| 1919 | goto err; |
| 1920 | } |
| 1921 | |
| 1922 | /* setup interrupt handler */ |
| 1923 | ret = request_irq(irq, display_pipe_interrupt_handler, 0, |
| 1924 | pdev->name, ctx); |
| 1925 | if (ret < 0) { |
| 1926 | dev_err(&pdev->dev, "request_irq failed\n"); |
| 1927 | goto err; |
| 1928 | } |
| 1929 | |
| 1930 | ctx->irq = irq; |
| 1931 | |
| 1932 | ret = snd_pcm_new(card, INTEL_HAD, PCM_INDEX, MAX_PB_STREAMS, |
| 1933 | MAX_CAP_STREAMS, &pcm); |
| 1934 | if (ret) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1935 | goto err; |
| 1936 | |
| 1937 | /* setup private data which can be retrieved when required */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1938 | pcm->private_data = ctx; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1939 | pcm->info_flags = 0; |
| 1940 | strncpy(pcm->name, card->shortname, strlen(card->shortname)); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1941 | /* setup the ops for playabck */ |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1942 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1943 | &snd_intelhad_playback_ops); |
| 1944 | /* allocate dma pages for ALSA stream operations |
| 1945 | * memory allocated is based on size, not max value |
| 1946 | * thus using same argument for max & size |
| 1947 | */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1948 | snd_pcm_lib_preallocate_pages_for_all(pcm, |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1949 | SNDRV_DMA_TYPE_DEV, NULL, |
| 1950 | HAD_MAX_BUFFER, HAD_MAX_BUFFER); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1951 | |
Takashi Iwai | 4aedb94 | 2017-02-02 16:38:39 +0100 | [diff] [blame^] | 1952 | /* create controls */ |
| 1953 | for (i = 0; i < ARRAY_SIZE(had_controls); i++) { |
| 1954 | ret = snd_ctl_add(card, snd_ctl_new1(&had_controls[i], ctx)); |
| 1955 | if (ret < 0) |
| 1956 | goto err; |
| 1957 | } |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1958 | |
| 1959 | init_channel_allocations(); |
| 1960 | |
| 1961 | /* Register channel map controls */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1962 | ret = had_register_chmap_ctls(ctx, pcm); |
| 1963 | if (ret < 0) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1964 | goto err; |
| 1965 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1966 | ret = snd_card_register(card); |
| 1967 | if (ret) |
Takashi Iwai | 36ec0d9 | 2017-01-31 08:47:05 +0100 | [diff] [blame] | 1968 | goto err; |
| 1969 | |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1970 | spin_lock_irq(&pdata->lpe_audio_slock); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1971 | pdata->notify_audio_lpe = notify_audio_lpe; |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1972 | pdata->notify_pending = false; |
Takashi Iwai | bcce775 | 2017-02-01 17:18:20 +0100 | [diff] [blame] | 1973 | spin_unlock_irq(&pdata->lpe_audio_slock); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1974 | |
| 1975 | pm_runtime_set_active(&pdev->dev); |
| 1976 | pm_runtime_enable(&pdev->dev); |
| 1977 | |
Takashi Iwai | 99b2ab9 | 2017-01-31 16:26:10 +0100 | [diff] [blame] | 1978 | dev_dbg(&pdev->dev, "%s: handle pending notification\n", __func__); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1979 | schedule_work(&ctx->hdmi_audio_wq); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1980 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 1981 | return 0; |
Takashi Iwai | 5647aec | 2017-01-31 08:14:34 +0100 | [diff] [blame] | 1982 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1983 | err: |
| 1984 | snd_card_free(card); |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1985 | return ret; |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1986 | } |
| 1987 | |
Takashi Iwai | 79dda75 | 2017-01-30 17:23:39 +0100 | [diff] [blame] | 1988 | /* |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1989 | * hdmi_lpe_audio_remove - stop bridge with i915 |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1990 | * |
Takashi Iwai | 2e52f5e | 2017-01-31 17:09:13 +0100 | [diff] [blame] | 1991 | * This function is called when the platform device is destroyed. |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1992 | */ |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1993 | static int hdmi_lpe_audio_remove(struct platform_device *pdev) |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1994 | { |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1995 | struct snd_intelhad *ctx = platform_get_drvdata(pdev); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 1996 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 1997 | if (ctx->drv_status != HAD_DRV_DISCONNECTED) |
| 1998 | snd_intelhad_enable_audio_int(ctx, false); |
| 1999 | snd_card_free(ctx->card); |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 2000 | return 0; |
| 2001 | } |
| 2002 | |
Takashi Iwai | 182cdf2 | 2017-02-02 14:43:39 +0100 | [diff] [blame] | 2003 | static const struct dev_pm_ops hdmi_lpe_audio_pm = { |
| 2004 | SET_SYSTEM_SLEEP_PM_OPS(hdmi_lpe_audio_suspend, hdmi_lpe_audio_resume) |
| 2005 | SET_RUNTIME_PM_OPS(hdmi_lpe_audio_runtime_suspend, NULL, NULL) |
| 2006 | }; |
| 2007 | |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 2008 | static struct platform_driver hdmi_lpe_audio_driver = { |
| 2009 | .driver = { |
| 2010 | .name = "hdmi-lpe-audio", |
Takashi Iwai | 182cdf2 | 2017-02-02 14:43:39 +0100 | [diff] [blame] | 2011 | .pm = &hdmi_lpe_audio_pm, |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 2012 | }, |
| 2013 | .probe = hdmi_lpe_audio_probe, |
| 2014 | .remove = hdmi_lpe_audio_remove, |
Takashi Iwai | da86480 | 2017-01-31 13:52:22 +0100 | [diff] [blame] | 2015 | }; |
| 2016 | |
| 2017 | module_platform_driver(hdmi_lpe_audio_driver); |
| 2018 | MODULE_ALIAS("platform:hdmi_lpe_audio"); |
| 2019 | |
Jerome Anand | 5dab11d | 2017-01-25 04:27:52 +0530 | [diff] [blame] | 2020 | MODULE_AUTHOR("Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>"); |
| 2021 | MODULE_AUTHOR("Ramesh Babu K V <ramesh.babu@intel.com>"); |
| 2022 | MODULE_AUTHOR("Vaibhav Agarwal <vaibhav.agarwal@intel.com>"); |
| 2023 | MODULE_AUTHOR("Jerome Anand <jerome.anand@intel.com>"); |
| 2024 | MODULE_DESCRIPTION("Intel HDMI Audio driver"); |
| 2025 | MODULE_LICENSE("GPL v2"); |
| 2026 | MODULE_SUPPORTED_DEVICE("{Intel,Intel_HAD}"); |