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