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