blob: 9f9fcd2749f224d8ec09e8fae677991f60cc0c9f [file] [log] [blame]
Thomas Gleixner8e8e69d2019-05-29 07:17:59 -07001// SPDX-License-Identifier: GPL-2.0-only
Jerome Anand5dab11d2017-01-25 04:27:52 +05302/*
3 * intel_hdmi_audio.c - Intel HDMI audio driver
4 *
5 * Copyright (C) 2016 Intel Corp
6 * Authors: Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>
7 * Ramesh Babu K V <ramesh.babu@intel.com>
8 * Vaibhav Agarwal <vaibhav.agarwal@intel.com>
9 * Jerome Anand <jerome.anand@intel.com>
10 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 *
Jerome Anand5dab11d2017-01-25 04:27:52 +053012 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
13 * ALSA driver for Intel HDMI audio
14 */
15
Takashi Iwai03c34372017-02-02 16:19:03 +010016#include <linux/types.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053017#include <linux/platform_device.h>
18#include <linux/io.h>
19#include <linux/slab.h>
20#include <linux/module.h>
Takashi Iwaida864802017-01-31 13:52:22 +010021#include <linux/interrupt.h>
Takashi Iwai03c34372017-02-02 16:19:03 +010022#include <linux/pm_runtime.h>
Takashi Iwai412bbe7d52017-02-02 22:03:22 +010023#include <linux/dma-mapping.h>
Takashi Iwaie2acecf2017-02-11 08:21:56 +010024#include <linux/delay.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053025#include <sound/core.h>
Takashi Iwai03c34372017-02-02 16:19:03 +010026#include <sound/asoundef.h>
27#include <sound/pcm.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053028#include <sound/pcm_params.h>
29#include <sound/initval.h>
30#include <sound/control.h>
Takashi Iwaib9bacf22017-02-14 12:29:38 +010031#include <sound/jack.h>
Takashi Iwai03c34372017-02-02 16:19:03 +010032#include <drm/drm_edid.h>
Takashi Iwaida864802017-01-31 13:52:22 +010033#include <drm/intel_lpe_audio.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053034#include "intel_hdmi_audio.h"
35
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +030036#define for_each_pipe(card_ctx, pipe) \
37 for ((pipe) = 0; (pipe) < (card_ctx)->num_pipes; (pipe)++)
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +030038#define for_each_port(card_ctx, port) \
39 for ((port) = 0; (port) < (card_ctx)->num_ports; (port)++)
40
Jerome Anand5dab11d2017-01-25 04:27:52 +053041/*standard module options for ALSA. This module supports only one card*/
42static int hdmi_card_index = SNDRV_DEFAULT_IDX1;
43static char *hdmi_card_id = SNDRV_DEFAULT_STR1;
Takashi Iwai7229b122018-02-20 17:33:45 +010044static bool single_port;
Jerome Anand5dab11d2017-01-25 04:27:52 +053045
46module_param_named(index, hdmi_card_index, int, 0444);
47MODULE_PARM_DESC(index,
48 "Index value for INTEL Intel HDMI Audio controller.");
49module_param_named(id, hdmi_card_id, charp, 0444);
50MODULE_PARM_DESC(id,
51 "ID string for INTEL Intel HDMI Audio controller.");
Takashi Iwai7229b122018-02-20 17:33:45 +010052module_param(single_port, bool, 0444);
53MODULE_PARM_DESC(single_port,
54 "Single-port mode (for compatibility)");
Jerome Anand5dab11d2017-01-25 04:27:52 +053055
56/*
57 * ELD SA bits in the CEA Speaker Allocation data block
58 */
Takashi Iwai4a5ddb22017-02-01 16:45:38 +010059static const int eld_speaker_allocation_bits[] = {
Jerome Anand5dab11d2017-01-25 04:27:52 +053060 [0] = FL | FR,
61 [1] = LFE,
62 [2] = FC,
63 [3] = RL | RR,
64 [4] = RC,
65 [5] = FLC | FRC,
66 [6] = RLC | RRC,
67 /* the following are not defined in ELD yet */
68 [7] = 0,
69};
70
71/*
72 * This is an ordered list!
73 *
74 * The preceding ones have better chances to be selected by
75 * hdmi_channel_allocation().
76 */
77static struct cea_channel_speaker_allocation channel_allocations[] = {
78/* channel: 7 6 5 4 3 2 1 0 */
79{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
80 /* 2.1 */
81{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
82 /* Dolby Surround */
83{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
84 /* surround40 */
85{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
86 /* surround41 */
87{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
88 /* surround50 */
89{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
90 /* surround51 */
91{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
92 /* 6.1 */
93{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
94 /* surround71 */
95{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
96
97{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
98{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
99{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
100{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
101{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
102{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
103{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
104{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
105{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
106{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
107{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
108{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
109{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
110{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
111{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
112{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
113{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
114{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
115{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
116{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
117{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
118{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
119{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
120};
121
Takashi Iwai4a5ddb22017-02-01 16:45:38 +0100122static const struct channel_map_table map_tables[] = {
Jerome Anand5dab11d2017-01-25 04:27:52 +0530123 { SNDRV_CHMAP_FL, 0x00, FL },
124 { SNDRV_CHMAP_FR, 0x01, FR },
125 { SNDRV_CHMAP_RL, 0x04, RL },
126 { SNDRV_CHMAP_RR, 0x05, RR },
127 { SNDRV_CHMAP_LFE, 0x02, LFE },
128 { SNDRV_CHMAP_FC, 0x03, FC },
129 { SNDRV_CHMAP_RLC, 0x06, RLC },
130 { SNDRV_CHMAP_RRC, 0x07, RRC },
131 {} /* terminator */
132};
133
134/* hardware capability structure */
Takashi Iwaib5562902017-02-04 22:05:33 +0100135static const struct snd_pcm_hardware had_pcm_hardware = {
Jerome Anand5dab11d2017-01-25 04:27:52 +0530136 .info = (SNDRV_PCM_INFO_INTERLEAVED |
Takashi Iwaia9ebdd02017-02-02 21:33:54 +0100137 SNDRV_PCM_INFO_MMAP |
Takashi Iwaie8de9852017-02-07 08:09:12 +0100138 SNDRV_PCM_INFO_MMAP_VALID |
139 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
Takashi Iwai3fe2cf72017-02-07 13:53:42 +0100140 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
141 SNDRV_PCM_FMTBIT_S24_LE |
Takashi Iwai85bd8742017-02-07 13:33:17 +0100142 SNDRV_PCM_FMTBIT_S32_LE),
Jerome Anand5dab11d2017-01-25 04:27:52 +0530143 .rates = SNDRV_PCM_RATE_32000 |
144 SNDRV_PCM_RATE_44100 |
145 SNDRV_PCM_RATE_48000 |
146 SNDRV_PCM_RATE_88200 |
147 SNDRV_PCM_RATE_96000 |
148 SNDRV_PCM_RATE_176400 |
149 SNDRV_PCM_RATE_192000,
150 .rate_min = HAD_MIN_RATE,
151 .rate_max = HAD_MAX_RATE,
152 .channels_min = HAD_MIN_CHANNEL,
153 .channels_max = HAD_MAX_CHANNEL,
154 .buffer_bytes_max = HAD_MAX_BUFFER,
155 .period_bytes_min = HAD_MIN_PERIOD_BYTES,
156 .period_bytes_max = HAD_MAX_PERIOD_BYTES,
157 .periods_min = HAD_MIN_PERIODS,
158 .periods_max = HAD_MAX_PERIODS,
159 .fifo_size = HAD_FIFO_SIZE,
160};
161
Takashi Iwai313d9f22017-02-02 13:00:12 +0100162/* Get the active PCM substream;
163 * Call had_substream_put() for unreferecing.
164 * Don't call this inside had_spinlock, as it takes by itself
165 */
166static struct snd_pcm_substream *
167had_substream_get(struct snd_intelhad *intelhaddata)
168{
169 struct snd_pcm_substream *substream;
170 unsigned long flags;
171
172 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
173 substream = intelhaddata->stream_info.substream;
174 if (substream)
175 intelhaddata->stream_info.substream_refcount++;
176 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
177 return substream;
178}
179
180/* Unref the active PCM substream;
181 * Don't call this inside had_spinlock, as it takes by itself
182 */
183static void had_substream_put(struct snd_intelhad *intelhaddata)
184{
185 unsigned long flags;
186
187 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
188 intelhaddata->stream_info.substream_refcount--;
189 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
190}
191
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300192static u32 had_config_offset(int pipe)
Takashi Iwai28ed1252017-02-15 22:02:10 +0100193{
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300194 switch (pipe) {
195 default:
196 case 0:
197 return AUDIO_HDMI_CONFIG_A;
198 case 1:
199 return AUDIO_HDMI_CONFIG_B;
200 case 2:
201 return AUDIO_HDMI_CONFIG_C;
202 }
Takashi Iwai28ed1252017-02-15 22:02:10 +0100203}
204
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300205/* Register access functions */
206static u32 had_read_register_raw(struct snd_intelhad_card *card_ctx,
207 int pipe, u32 reg)
Takashi Iwai28ed1252017-02-15 22:02:10 +0100208{
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300209 return ioread32(card_ctx->mmio_start + had_config_offset(pipe) + reg);
210}
211
212static void had_write_register_raw(struct snd_intelhad_card *card_ctx,
213 int pipe, u32 reg, u32 val)
214{
215 iowrite32(val, card_ctx->mmio_start + had_config_offset(pipe) + reg);
Takashi Iwai28ed1252017-02-15 22:02:10 +0100216}
217
Takashi Iwai83af57d2017-02-03 08:50:06 +0100218static void had_read_register(struct snd_intelhad *ctx, u32 reg, u32 *val)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530219{
Takashi Iwai28ed1252017-02-15 22:02:10 +0100220 if (!ctx->connected)
221 *val = 0;
222 else
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300223 *val = had_read_register_raw(ctx->card_ctx, ctx->pipe, reg);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530224}
225
Takashi Iwai83af57d2017-02-03 08:50:06 +0100226static void had_write_register(struct snd_intelhad *ctx, u32 reg, u32 val)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530227{
Takashi Iwai28ed1252017-02-15 22:02:10 +0100228 if (ctx->connected)
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300229 had_write_register_raw(ctx->card_ctx, ctx->pipe, reg, val);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530230}
231
Takashi Iwaida864802017-01-31 13:52:22 +0100232/*
Takashi Iwai313d9f22017-02-02 13:00:12 +0100233 * enable / disable audio configuration
234 *
Takashi Iwai83af57d2017-02-03 08:50:06 +0100235 * The normal read/modify should not directly be used on VLV2 for
Takashi Iwaida864802017-01-31 13:52:22 +0100236 * updating AUD_CONFIG register.
Jerome Anand5dab11d2017-01-25 04:27:52 +0530237 * This is because:
238 * Bit6 of AUD_CONFIG register is writeonly due to a silicon bug on VLV2
239 * HDMI IP. As a result a read-modify of AUD_CONFIG regiter will always
240 * clear bit6. AUD_CONFIG[6:4] represents the "channels" field of the
241 * register. This field should be 1xy binary for configuration with 6 or
242 * more channels. Read-modify of AUD_CONFIG (Eg. for enabling audio)
243 * causes the "channels" field to be updated as 0xy binary resulting in
244 * bad audio. The fix is to always write the AUD_CONFIG[6:4] with
245 * appropriate value when doing read-modify of AUD_CONFIG register.
Jerome Anand5dab11d2017-01-25 04:27:52 +0530246 */
Takashi Iwai40ce4b52017-02-07 16:17:06 +0100247static void had_enable_audio(struct snd_intelhad *intelhaddata,
Takashi Iwaib5562902017-02-04 22:05:33 +0100248 bool enable)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530249{
Takashi Iwai40ce4b52017-02-07 16:17:06 +0100250 /* update the cached value */
251 intelhaddata->aud_config.regx.aud_en = enable;
252 had_write_register(intelhaddata, AUD_CONFIG,
253 intelhaddata->aud_config.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530254}
255
Takashi Iwai075a1d42017-02-07 07:55:27 +0100256/* forcibly ACKs to both BUFFER_DONE and BUFFER_UNDERRUN interrupts */
257static void had_ack_irqs(struct snd_intelhad *ctx)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530258{
Takashi Iwaida864802017-01-31 13:52:22 +0100259 u32 status_reg;
260
Takashi Iwai28ed1252017-02-15 22:02:10 +0100261 if (!ctx->connected)
262 return;
Takashi Iwai075a1d42017-02-07 07:55:27 +0100263 had_read_register(ctx, AUD_HDMI_STATUS, &status_reg);
264 status_reg |= HDMI_AUDIO_BUFFER_DONE | HDMI_AUDIO_UNDERRUN;
265 had_write_register(ctx, AUD_HDMI_STATUS, status_reg);
266 had_read_register(ctx, AUD_HDMI_STATUS, &status_reg);
Takashi Iwaida864802017-01-31 13:52:22 +0100267}
268
Takashi Iwaif4566aa2017-02-04 21:39:56 +0100269/* Reset buffer pointers */
270static void had_reset_audio(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530271{
Takashi Iwai77531be2017-02-07 12:17:23 +0100272 had_write_register(intelhaddata, AUD_HDMI_STATUS,
273 AUD_HDMI_STATUSG_MASK_FUNCRST);
Takashi Iwaif4566aa2017-02-04 21:39:56 +0100274 had_write_register(intelhaddata, AUD_HDMI_STATUS, 0);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530275}
276
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100277/*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530278 * initialize audio channel status registers
279 * This function is called in the prepare callback
280 */
281static int had_prog_status_reg(struct snd_pcm_substream *substream,
282 struct snd_intelhad *intelhaddata)
283{
Takashi Iwai7ceba752017-02-02 15:58:35 +0100284 union aud_ch_status_0 ch_stat0 = {.regval = 0};
285 union aud_ch_status_1 ch_stat1 = {.regval = 0};
Jerome Anand5dab11d2017-01-25 04:27:52 +0530286
Takashi Iwai7ceba752017-02-02 15:58:35 +0100287 ch_stat0.regx.lpcm_id = (intelhaddata->aes_bits &
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100288 IEC958_AES0_NONAUDIO) >> 1;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100289 ch_stat0.regx.clk_acc = (intelhaddata->aes_bits &
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100290 IEC958_AES3_CON_CLOCK) >> 4;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530291
292 switch (substream->runtime->rate) {
293 case AUD_SAMPLE_RATE_32:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100294 ch_stat0.regx.samp_freq = CH_STATUS_MAP_32KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530295 break;
296
297 case AUD_SAMPLE_RATE_44_1:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100298 ch_stat0.regx.samp_freq = CH_STATUS_MAP_44KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530299 break;
300 case AUD_SAMPLE_RATE_48:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100301 ch_stat0.regx.samp_freq = CH_STATUS_MAP_48KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530302 break;
303 case AUD_SAMPLE_RATE_88_2:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100304 ch_stat0.regx.samp_freq = CH_STATUS_MAP_88KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530305 break;
306 case AUD_SAMPLE_RATE_96:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100307 ch_stat0.regx.samp_freq = CH_STATUS_MAP_96KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530308 break;
309 case AUD_SAMPLE_RATE_176_4:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100310 ch_stat0.regx.samp_freq = CH_STATUS_MAP_176KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530311 break;
312 case AUD_SAMPLE_RATE_192:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100313 ch_stat0.regx.samp_freq = CH_STATUS_MAP_192KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530314 break;
315
316 default:
317 /* control should never come here */
318 return -EINVAL;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530319 }
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100320
Takashi Iwai79dda752017-01-30 17:23:39 +0100321 had_write_register(intelhaddata,
Takashi Iwai7ceba752017-02-02 15:58:35 +0100322 AUD_CH_STATUS_0, ch_stat0.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530323
Takashi Iwai85bd8742017-02-07 13:33:17 +0100324 switch (substream->runtime->format) {
Takashi Iwai85bd8742017-02-07 13:33:17 +0100325 case SNDRV_PCM_FORMAT_S16_LE:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100326 ch_stat1.regx.max_wrd_len = MAX_SMPL_WIDTH_20;
327 ch_stat1.regx.wrd_len = SMPL_WIDTH_16BITS;
Takashi Iwai85bd8742017-02-07 13:33:17 +0100328 break;
Takashi Iwai85bd8742017-02-07 13:33:17 +0100329 case SNDRV_PCM_FORMAT_S24_LE:
330 case SNDRV_PCM_FORMAT_S32_LE:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100331 ch_stat1.regx.max_wrd_len = MAX_SMPL_WIDTH_24;
332 ch_stat1.regx.wrd_len = SMPL_WIDTH_24BITS;
Takashi Iwai85bd8742017-02-07 13:33:17 +0100333 break;
334 default:
335 return -EINVAL;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530336 }
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100337
Takashi Iwai79dda752017-01-30 17:23:39 +0100338 had_write_register(intelhaddata,
Takashi Iwai7ceba752017-02-02 15:58:35 +0100339 AUD_CH_STATUS_1, ch_stat1.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530340 return 0;
341}
342
Takashi Iwai76296ef2017-01-30 16:09:11 +0100343/*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530344 * function to initialize audio
345 * registers and buffer confgiuration registers
346 * This function is called in the prepare callback
347 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100348static int had_init_audio_ctrl(struct snd_pcm_substream *substream,
349 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530350{
Takashi Iwai7ceba752017-02-02 15:58:35 +0100351 union aud_cfg cfg_val = {.regval = 0};
352 union aud_buf_config buf_cfg = {.regval = 0};
Jerome Anand5dab11d2017-01-25 04:27:52 +0530353 u8 channels;
354
355 had_prog_status_reg(substream, intelhaddata);
356
Takashi Iwai7ceba752017-02-02 15:58:35 +0100357 buf_cfg.regx.audio_fifo_watermark = FIFO_THRESHOLD;
358 buf_cfg.regx.dma_fifo_watermark = DMA_FIFO_THRESHOLD;
359 buf_cfg.regx.aud_delay = 0;
360 had_write_register(intelhaddata, AUD_BUF_CONFIG, buf_cfg.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530361
362 channels = substream->runtime->channels;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100363 cfg_val.regx.num_ch = channels - 2;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530364 if (channels <= 2)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100365 cfg_val.regx.layout = LAYOUT0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530366 else
Takashi Iwai7ceba752017-02-02 15:58:35 +0100367 cfg_val.regx.layout = LAYOUT1;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530368
Takashi Iwai3fe2cf72017-02-07 13:53:42 +0100369 if (substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE)
370 cfg_val.regx.packet_mode = 1;
371
Takashi Iwai85bd8742017-02-07 13:33:17 +0100372 if (substream->runtime->format == SNDRV_PCM_FORMAT_S32_LE)
373 cfg_val.regx.left_align = 1;
374
Takashi Iwai7ceba752017-02-02 15:58:35 +0100375 cfg_val.regx.val_bit = 1;
Takashi Iwai83af57d2017-02-03 08:50:06 +0100376
377 /* fix up the DP bits */
378 if (intelhaddata->dp_output) {
379 cfg_val.regx.dp_modei = 1;
380 cfg_val.regx.set = 1;
381 }
382
Takashi Iwai7ceba752017-02-02 15:58:35 +0100383 had_write_register(intelhaddata, AUD_CONFIG, cfg_val.regval);
Takashi Iwai40ce4b52017-02-07 16:17:06 +0100384 intelhaddata->aud_config = cfg_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530385 return 0;
386}
387
Jerome Anand5dab11d2017-01-25 04:27:52 +0530388/*
389 * Compute derived values in channel_allocations[].
390 */
391static void init_channel_allocations(void)
392{
393 int i, j;
394 struct cea_channel_speaker_allocation *p;
395
Jerome Anand5dab11d2017-01-25 04:27:52 +0530396 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
397 p = channel_allocations + i;
398 p->channels = 0;
399 p->spk_mask = 0;
400 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
401 if (p->speakers[j]) {
402 p->channels++;
403 p->spk_mask |= p->speakers[j];
404 }
405 }
406}
407
408/*
409 * The transformation takes two steps:
410 *
411 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
412 * spk_mask => (channel_allocations[]) => ai->CA
413 *
414 * TODO: it could select the wrong CA from multiple candidates.
415 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100416static int had_channel_allocation(struct snd_intelhad *intelhaddata,
417 int channels)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530418{
419 int i;
420 int ca = 0;
421 int spk_mask = 0;
422
423 /*
424 * CA defaults to 0 for basic stereo audio
425 */
426 if (channels <= 2)
427 return 0;
428
429 /*
430 * expand ELD's speaker allocation mask
431 *
432 * ELD tells the speaker mask in a compact(paired) form,
433 * expand ELD's notions to match the ones used by Audio InfoFrame.
434 */
435
436 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100437 if (intelhaddata->eld[DRM_ELD_SPEAKER] & (1 << i))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530438 spk_mask |= eld_speaker_allocation_bits[i];
439 }
440
441 /* search for the first working match in the CA table */
442 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
443 if (channels == channel_allocations[i].channels &&
444 (spk_mask & channel_allocations[i].spk_mask) ==
445 channel_allocations[i].spk_mask) {
446 ca = channel_allocations[i].ca_index;
447 break;
448 }
449 }
450
Takashi Iwaic75b0472017-01-31 15:49:15 +0100451 dev_dbg(intelhaddata->dev, "select CA 0x%x for %d\n", ca, channels);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530452
453 return ca;
454}
455
456/* from speaker bit mask to ALSA API channel position */
457static int spk_to_chmap(int spk)
458{
Takashi Iwai4a5ddb22017-02-01 16:45:38 +0100459 const struct channel_map_table *t = map_tables;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530460
461 for (; t->map; t++) {
462 if (t->spk_mask == spk)
463 return t->map;
464 }
465 return 0;
466}
467
Takashi Iwai372d8552017-01-31 13:57:58 +0100468static void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530469{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100470 int i, c;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530471 int spk_mask = 0;
472 struct snd_pcm_chmap_elem *chmap;
473 u8 eld_high, eld_high_mask = 0xF0;
474 u8 high_msb;
475
Takashi Iwai18353192017-02-15 21:42:20 +0100476 kfree(intelhaddata->chmap->chmap);
477 intelhaddata->chmap->chmap = NULL;
478
Jerome Anand5dab11d2017-01-25 04:27:52 +0530479 chmap = kzalloc(sizeof(*chmap), GFP_KERNEL);
Takashi Iwai18353192017-02-15 21:42:20 +0100480 if (!chmap)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530481 return;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530482
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100483 dev_dbg(intelhaddata->dev, "eld speaker = %x\n",
484 intelhaddata->eld[DRM_ELD_SPEAKER]);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530485
486 /* WA: Fix the max channel supported to 8 */
487
488 /*
489 * Sink may support more than 8 channels, if eld_high has more than
490 * one bit set. SOC supports max 8 channels.
491 * Refer eld_speaker_allocation_bits, for sink speaker allocation
492 */
493
494 /* if 0x2F < eld < 0x4F fall back to 0x2f, else fall back to 0x4F */
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100495 eld_high = intelhaddata->eld[DRM_ELD_SPEAKER] & eld_high_mask;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530496 if ((eld_high & (eld_high-1)) && (eld_high > 0x1F)) {
497 /* eld_high & (eld_high-1): if more than 1 bit set */
498 /* 0x1F: 7 channels */
499 for (i = 1; i < 4; i++) {
500 high_msb = eld_high & (0x80 >> i);
501 if (high_msb) {
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100502 intelhaddata->eld[DRM_ELD_SPEAKER] &=
Jerome Anand5dab11d2017-01-25 04:27:52 +0530503 high_msb | 0xF;
504 break;
505 }
506 }
507 }
508
509 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100510 if (intelhaddata->eld[DRM_ELD_SPEAKER] & (1 << i))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530511 spk_mask |= eld_speaker_allocation_bits[i];
512 }
513
514 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
515 if (spk_mask == channel_allocations[i].spk_mask) {
516 for (c = 0; c < channel_allocations[i].channels; c++) {
517 chmap->map[c] = spk_to_chmap(
518 channel_allocations[i].speakers[
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100519 (MAX_SPEAKERS - 1) - c]);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530520 }
521 chmap->channels = channel_allocations[i].channels;
522 intelhaddata->chmap->chmap = chmap;
523 break;
524 }
525 }
Takashi Iwai18353192017-02-15 21:42:20 +0100526 if (i >= ARRAY_SIZE(channel_allocations))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530527 kfree(chmap);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530528}
529
530/*
531 * ALSA API channel-map control callbacks
532 */
533static int had_chmap_ctl_info(struct snd_kcontrol *kcontrol,
534 struct snd_ctl_elem_info *uinfo)
535{
Jerome Anand5dab11d2017-01-25 04:27:52 +0530536 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
537 uinfo->count = HAD_MAX_CHANNEL;
538 uinfo->value.integer.min = 0;
539 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
540 return 0;
541}
542
543static int had_chmap_ctl_get(struct snd_kcontrol *kcontrol,
544 struct snd_ctl_elem_value *ucontrol)
545{
546 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
547 struct snd_intelhad *intelhaddata = info->private_data;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100548 int i;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530549 const struct snd_pcm_chmap_elem *chmap;
550
Takashi Iwaia72ccfb2017-02-15 21:45:06 +0100551 memset(ucontrol->value.integer.value, 0,
552 sizeof(long) * HAD_MAX_CHANNEL);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100553 mutex_lock(&intelhaddata->mutex);
554 if (!intelhaddata->chmap->chmap) {
555 mutex_unlock(&intelhaddata->mutex);
Takashi Iwaia72ccfb2017-02-15 21:45:06 +0100556 return 0;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100557 }
558
Jerome Anand5dab11d2017-01-25 04:27:52 +0530559 chmap = intelhaddata->chmap->chmap;
Takashi Iwaic75b0472017-01-31 15:49:15 +0100560 for (i = 0; i < chmap->channels; i++)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530561 ucontrol->value.integer.value[i] = chmap->map[i];
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100562 mutex_unlock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530563
564 return 0;
565}
566
567static int had_register_chmap_ctls(struct snd_intelhad *intelhaddata,
568 struct snd_pcm *pcm)
569{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100570 int err;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530571
572 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
573 NULL, 0, (unsigned long)intelhaddata,
574 &intelhaddata->chmap);
575 if (err < 0)
576 return err;
577
578 intelhaddata->chmap->private_data = intelhaddata;
Takashi Iwaie9d65ab2017-01-31 16:11:27 +0100579 intelhaddata->chmap->kctl->info = had_chmap_ctl_info;
580 intelhaddata->chmap->kctl->get = had_chmap_ctl_get;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530581 intelhaddata->chmap->chmap = NULL;
582 return 0;
583}
584
Takashi Iwai76296ef2017-01-30 16:09:11 +0100585/*
Takashi Iwai44684f62017-02-02 17:27:40 +0100586 * Initialize Data Island Packets registers
Jerome Anand5dab11d2017-01-25 04:27:52 +0530587 * This function is called in the prepare callback
588 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100589static void had_prog_dip(struct snd_pcm_substream *substream,
590 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530591{
592 int i;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100593 union aud_ctrl_st ctrl_state = {.regval = 0};
594 union aud_info_frame2 frame2 = {.regval = 0};
595 union aud_info_frame3 frame3 = {.regval = 0};
Jerome Anand5dab11d2017-01-25 04:27:52 +0530596 u8 checksum = 0;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600597 u32 info_frame;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530598 int channels;
Takashi Iwai36ed3462017-02-02 17:06:38 +0100599 int ca;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530600
601 channels = substream->runtime->channels;
602
Takashi Iwai7ceba752017-02-02 15:58:35 +0100603 had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530604
Takashi Iwaib5562902017-02-04 22:05:33 +0100605 ca = had_channel_allocation(intelhaddata, channels);
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600606 if (intelhaddata->dp_output) {
607 info_frame = DP_INFO_FRAME_WORD1;
Takashi Iwai36ed3462017-02-02 17:06:38 +0100608 frame2.regval = (substream->runtime->channels - 1) | (ca << 24);
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600609 } else {
610 info_frame = HDMI_INFO_FRAME_WORD1;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100611 frame2.regx.chnl_cnt = substream->runtime->channels - 1;
Takashi Iwai36ed3462017-02-02 17:06:38 +0100612 frame3.regx.chnl_alloc = ca;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530613
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100614 /* Calculte the byte wide checksum for all valid DIP words */
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600615 for (i = 0; i < BYTES_PER_WORD; i++)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100616 checksum += (info_frame >> (i * 8)) & 0xff;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600617 for (i = 0; i < BYTES_PER_WORD; i++)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100618 checksum += (frame2.regval >> (i * 8)) & 0xff;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600619 for (i = 0; i < BYTES_PER_WORD; i++)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100620 checksum += (frame3.regval >> (i * 8)) & 0xff;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530621
Takashi Iwai7ceba752017-02-02 15:58:35 +0100622 frame2.regx.chksum = -(checksum);
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600623 }
Jerome Anand5dab11d2017-01-25 04:27:52 +0530624
Takashi Iwai4151ee82017-01-31 18:14:15 +0100625 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, info_frame);
Takashi Iwai7ceba752017-02-02 15:58:35 +0100626 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame2.regval);
627 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame3.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530628
629 /* program remaining DIP words with zero */
630 for (i = 0; i < HAD_MAX_DIP_WORDS-VALID_DIP_WORDS; i++)
Takashi Iwai4151ee82017-01-31 18:14:15 +0100631 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, 0x0);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530632
Takashi Iwai7ceba752017-02-02 15:58:35 +0100633 ctrl_state.regx.dip_freq = 1;
634 ctrl_state.regx.dip_en_sta = 1;
635 had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530636}
637
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600638static int had_calculate_maud_value(u32 aud_samp_freq, u32 link_rate)
639{
640 u32 maud_val;
641
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100642 /* Select maud according to DP 1.2 spec */
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600643 if (link_rate == DP_2_7_GHZ) {
644 switch (aud_samp_freq) {
645 case AUD_SAMPLE_RATE_32:
646 maud_val = AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL;
647 break;
648
649 case AUD_SAMPLE_RATE_44_1:
650 maud_val = AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL;
651 break;
652
653 case AUD_SAMPLE_RATE_48:
654 maud_val = AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL;
655 break;
656
657 case AUD_SAMPLE_RATE_88_2:
658 maud_val = AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL;
659 break;
660
661 case AUD_SAMPLE_RATE_96:
662 maud_val = AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL;
663 break;
664
665 case AUD_SAMPLE_RATE_176_4:
666 maud_val = AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL;
667 break;
668
669 case HAD_MAX_RATE:
670 maud_val = HAD_MAX_RATE_DP_2_7_MAUD_VAL;
671 break;
672
673 default:
674 maud_val = -EINVAL;
675 break;
676 }
677 } else if (link_rate == DP_1_62_GHZ) {
678 switch (aud_samp_freq) {
679 case AUD_SAMPLE_RATE_32:
680 maud_val = AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL;
681 break;
682
683 case AUD_SAMPLE_RATE_44_1:
684 maud_val = AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL;
685 break;
686
687 case AUD_SAMPLE_RATE_48:
688 maud_val = AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL;
689 break;
690
691 case AUD_SAMPLE_RATE_88_2:
692 maud_val = AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL;
693 break;
694
695 case AUD_SAMPLE_RATE_96:
696 maud_val = AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL;
697 break;
698
699 case AUD_SAMPLE_RATE_176_4:
700 maud_val = AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL;
701 break;
702
703 case HAD_MAX_RATE:
704 maud_val = HAD_MAX_RATE_DP_1_62_MAUD_VAL;
705 break;
706
707 default:
708 maud_val = -EINVAL;
709 break;
710 }
711 } else
712 maud_val = -EINVAL;
713
714 return maud_val;
715}
716
Takashi Iwai76296ef2017-01-30 16:09:11 +0100717/*
Takashi Iwai44684f62017-02-02 17:27:40 +0100718 * Program HDMI audio CTS value
Jerome Anand5dab11d2017-01-25 04:27:52 +0530719 *
720 * @aud_samp_freq: sampling frequency of audio data
721 * @tmds: sampling frequency of the display data
Takashi Iwaib5562902017-02-04 22:05:33 +0100722 * @link_rate: DP link rate
Jerome Anand5dab11d2017-01-25 04:27:52 +0530723 * @n_param: N value, depends on aud_samp_freq
Takashi Iwaib5562902017-02-04 22:05:33 +0100724 * @intelhaddata: substream private data
Jerome Anand5dab11d2017-01-25 04:27:52 +0530725 *
726 * Program CTS register based on the audio and display sampling frequency
727 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100728static void had_prog_cts(u32 aud_samp_freq, u32 tmds, u32 link_rate,
729 u32 n_param, struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530730{
731 u32 cts_val;
732 u64 dividend, divisor;
733
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600734 if (intelhaddata->dp_output) {
735 /* Substitute cts_val with Maud according to DP 1.2 spec*/
736 cts_val = had_calculate_maud_value(aud_samp_freq, link_rate);
737 } else {
738 /* Calculate CTS according to HDMI 1.3a spec*/
739 dividend = (u64)tmds * n_param*1000;
740 divisor = 128 * aud_samp_freq;
741 cts_val = div64_u64(dividend, divisor);
742 }
Takashi Iwaic75b0472017-01-31 15:49:15 +0100743 dev_dbg(intelhaddata->dev, "TMDS value=%d, N value=%d, CTS Value=%d\n",
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600744 tmds, n_param, cts_val);
Takashi Iwai79dda752017-01-30 17:23:39 +0100745 had_write_register(intelhaddata, AUD_HDMI_CTS, (BIT(24) | cts_val));
Jerome Anand5dab11d2017-01-25 04:27:52 +0530746}
747
748static int had_calculate_n_value(u32 aud_samp_freq)
749{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100750 int n_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530751
752 /* Select N according to HDMI 1.3a spec*/
753 switch (aud_samp_freq) {
754 case AUD_SAMPLE_RATE_32:
755 n_val = 4096;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100756 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530757
758 case AUD_SAMPLE_RATE_44_1:
759 n_val = 6272;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100760 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530761
762 case AUD_SAMPLE_RATE_48:
763 n_val = 6144;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100764 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530765
766 case AUD_SAMPLE_RATE_88_2:
767 n_val = 12544;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100768 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530769
770 case AUD_SAMPLE_RATE_96:
771 n_val = 12288;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100772 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530773
774 case AUD_SAMPLE_RATE_176_4:
775 n_val = 25088;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100776 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530777
778 case HAD_MAX_RATE:
779 n_val = 24576;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100780 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530781
782 default:
783 n_val = -EINVAL;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100784 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530785 }
786 return n_val;
787}
788
Takashi Iwai76296ef2017-01-30 16:09:11 +0100789/*
Takashi Iwai44684f62017-02-02 17:27:40 +0100790 * Program HDMI audio N value
Jerome Anand5dab11d2017-01-25 04:27:52 +0530791 *
792 * @aud_samp_freq: sampling frequency of audio data
793 * @n_param: N value, depends on aud_samp_freq
Takashi Iwaib5562902017-02-04 22:05:33 +0100794 * @intelhaddata: substream private data
Jerome Anand5dab11d2017-01-25 04:27:52 +0530795 *
796 * This function is called in the prepare callback.
797 * It programs based on the audio and display sampling frequency
798 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100799static int had_prog_n(u32 aud_samp_freq, u32 *n_param,
800 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530801{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100802 int n_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530803
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600804 if (intelhaddata->dp_output) {
805 /*
806 * According to DP specs, Maud and Naud values hold
807 * a relationship, which is stated as:
808 * Maud/Naud = 512 * fs / f_LS_Clk
809 * where, fs is the sampling frequency of the audio stream
810 * and Naud is 32768 for Async clock.
811 */
812
813 n_val = DP_NAUD_VAL;
814 } else
815 n_val = had_calculate_n_value(aud_samp_freq);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530816
817 if (n_val < 0)
818 return n_val;
819
Takashi Iwai79dda752017-01-30 17:23:39 +0100820 had_write_register(intelhaddata, AUD_N_ENABLE, (BIT(24) | n_val));
Jerome Anand5dab11d2017-01-25 04:27:52 +0530821 *n_param = n_val;
822 return 0;
823}
824
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100825/*
826 * PCM ring buffer handling
827 *
828 * The hardware provides a ring buffer with the fixed 4 buffer descriptors
829 * (BDs). The driver maps these 4 BDs onto the PCM ring buffer. The mapping
830 * moves at each period elapsed. The below illustrates how it works:
831 *
832 * At time=0
833 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
834 * BD | 0 | 1 | 2 | 3 |
835 *
836 * At time=1 (period elapsed)
837 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
838 * BD | 1 | 2 | 3 | 0 |
839 *
840 * At time=2 (second period elapsed)
841 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
842 * BD | 2 | 3 | 0 | 1 |
843 *
844 * The bd_head field points to the index of the BD to be read. It's also the
845 * position to be filled at next. The pcm_head and the pcm_filled fields
846 * point to the indices of the current position and of the next position to
847 * be filled, respectively. For PCM buffer there are both _head and _filled
848 * because they may be difference when nperiods > 4. For example, in the
849 * example above at t=1, bd_head=1 and pcm_head=1 while pcm_filled=5:
850 *
851 * pcm_head (=1) --v v-- pcm_filled (=5)
852 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
853 * BD | 1 | 2 | 3 | 0 |
854 * bd_head (=1) --^ ^-- next to fill (= bd_head)
855 *
856 * For nperiods < 4, the remaining BDs out of 4 are marked as invalid, so that
857 * the hardware skips those BDs in the loop.
Takashi Iwai8d48c012017-02-07 08:05:46 +0100858 *
859 * An exceptional setup is the case with nperiods=1. Since we have to update
860 * BDs after finishing one BD processing, we'd need at least two BDs, where
861 * both BDs point to the same content, the same address, the same size of the
862 * whole PCM buffer.
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100863 */
864
865#define AUD_BUF_ADDR(x) (AUD_BUF_A_ADDR + (x) * HAD_REG_WIDTH)
866#define AUD_BUF_LEN(x) (AUD_BUF_A_LENGTH + (x) * HAD_REG_WIDTH)
867
868/* Set up a buffer descriptor at the "filled" position */
869static void had_prog_bd(struct snd_pcm_substream *substream,
870 struct snd_intelhad *intelhaddata)
871{
872 int idx = intelhaddata->bd_head;
873 int ofs = intelhaddata->pcmbuf_filled * intelhaddata->period_bytes;
874 u32 addr = substream->runtime->dma_addr + ofs;
875
Takashi Iwaie8de9852017-02-07 08:09:12 +0100876 addr |= AUD_BUF_VALID;
877 if (!substream->runtime->no_period_wakeup)
878 addr |= AUD_BUF_INTR_EN;
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100879 had_write_register(intelhaddata, AUD_BUF_ADDR(idx), addr);
880 had_write_register(intelhaddata, AUD_BUF_LEN(idx),
881 intelhaddata->period_bytes);
882
883 /* advance the indices to the next */
884 intelhaddata->bd_head++;
885 intelhaddata->bd_head %= intelhaddata->num_bds;
886 intelhaddata->pcmbuf_filled++;
887 intelhaddata->pcmbuf_filled %= substream->runtime->periods;
888}
889
890/* invalidate a buffer descriptor with the given index */
891static void had_invalidate_bd(struct snd_intelhad *intelhaddata,
892 int idx)
893{
894 had_write_register(intelhaddata, AUD_BUF_ADDR(idx), 0);
895 had_write_register(intelhaddata, AUD_BUF_LEN(idx), 0);
896}
897
898/* Initial programming of ring buffer */
899static void had_init_ringbuf(struct snd_pcm_substream *substream,
900 struct snd_intelhad *intelhaddata)
901{
902 struct snd_pcm_runtime *runtime = substream->runtime;
903 int i, num_periods;
904
905 num_periods = runtime->periods;
906 intelhaddata->num_bds = min(num_periods, HAD_NUM_OF_RING_BUFS);
Takashi Iwai8d48c012017-02-07 08:05:46 +0100907 /* set the minimum 2 BDs for num_periods=1 */
908 intelhaddata->num_bds = max(intelhaddata->num_bds, 2U);
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100909 intelhaddata->period_bytes =
910 frames_to_bytes(runtime, runtime->period_size);
911 WARN_ON(intelhaddata->period_bytes & 0x3f);
912
913 intelhaddata->bd_head = 0;
914 intelhaddata->pcmbuf_head = 0;
915 intelhaddata->pcmbuf_filled = 0;
916
917 for (i = 0; i < HAD_NUM_OF_RING_BUFS; i++) {
Takashi Iwai8d48c012017-02-07 08:05:46 +0100918 if (i < intelhaddata->num_bds)
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100919 had_prog_bd(substream, intelhaddata);
920 else /* invalidate the rest */
921 had_invalidate_bd(intelhaddata, i);
922 }
923
924 intelhaddata->bd_head = 0; /* reset at head again before starting */
925}
926
927/* process a bd, advance to the next */
928static void had_advance_ringbuf(struct snd_pcm_substream *substream,
929 struct snd_intelhad *intelhaddata)
930{
931 int num_periods = substream->runtime->periods;
932
933 /* reprogram the next buffer */
934 had_prog_bd(substream, intelhaddata);
935
936 /* proceed to next */
937 intelhaddata->pcmbuf_head++;
938 intelhaddata->pcmbuf_head %= num_periods;
939}
940
941/* process the current BD(s);
942 * returns the current PCM buffer byte position, or -EPIPE for underrun.
943 */
944static int had_process_ringbuf(struct snd_pcm_substream *substream,
945 struct snd_intelhad *intelhaddata)
946{
947 int len, processed;
948 unsigned long flags;
949
950 processed = 0;
951 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
952 for (;;) {
953 /* get the remaining bytes on the buffer */
954 had_read_register(intelhaddata,
955 AUD_BUF_LEN(intelhaddata->bd_head),
956 &len);
957 if (len < 0 || len > intelhaddata->period_bytes) {
958 dev_dbg(intelhaddata->dev, "Invalid buf length %d\n",
959 len);
960 len = -EPIPE;
961 goto out;
962 }
963
964 if (len > 0) /* OK, this is the current buffer */
965 break;
966
967 /* len=0 => already empty, check the next buffer */
968 if (++processed >= intelhaddata->num_bds) {
969 len = -EPIPE; /* all empty? - report underrun */
970 goto out;
971 }
972 had_advance_ringbuf(substream, intelhaddata);
973 }
974
975 len = intelhaddata->period_bytes - len;
976 len += intelhaddata->period_bytes * intelhaddata->pcmbuf_head;
977 out:
978 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
979 return len;
980}
981
982/* called from irq handler */
983static void had_process_buffer_done(struct snd_intelhad *intelhaddata)
984{
985 struct snd_pcm_substream *substream;
986
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100987 substream = had_substream_get(intelhaddata);
988 if (!substream)
989 return; /* no stream? - bail out */
990
Takashi Iwaibe9a2e92017-02-15 22:05:34 +0100991 if (!intelhaddata->connected) {
992 snd_pcm_stop_xrun(substream);
993 goto out; /* disconnected? - bail out */
994 }
995
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100996 /* process or stop the stream */
997 if (had_process_ringbuf(substream, intelhaddata) < 0)
998 snd_pcm_stop_xrun(substream);
999 else
1000 snd_pcm_period_elapsed(substream);
1001
Takashi Iwaibe9a2e92017-02-15 22:05:34 +01001002 out:
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001003 had_substream_put(intelhaddata);
1004}
1005
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001006/*
1007 * The interrupt status 'sticky' bits might not be cleared by
1008 * setting '1' to that bit once...
1009 */
1010static void wait_clear_underrun_bit(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301011{
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001012 int i;
1013 u32 val;
1014
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001015 for (i = 0; i < 100; i++) {
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001016 /* clear bit30, 31 AUD_HDMI_STATUS */
1017 had_read_register(intelhaddata, AUD_HDMI_STATUS, &val);
Takashi Iwai77531be2017-02-07 12:17:23 +01001018 if (!(val & AUD_HDMI_STATUS_MASK_UNDERRUN))
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001019 return;
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001020 udelay(100);
1021 cond_resched();
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001022 had_write_register(intelhaddata, AUD_HDMI_STATUS, val);
1023 }
1024 dev_err(intelhaddata->dev, "Unable to clear UNDERRUN bits\n");
1025}
1026
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001027/* Perform some reset procedure but only when need_reset is set;
1028 * this is called from prepare or hw_free callbacks once after trigger STOP
1029 * or underrun has been processed in order to settle down the h/w state.
1030 */
1031static void had_do_reset(struct snd_intelhad *intelhaddata)
1032{
Takashi Iwai28ed1252017-02-15 22:02:10 +01001033 if (!intelhaddata->need_reset || !intelhaddata->connected)
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001034 return;
1035
1036 /* Reset buffer pointers */
1037 had_reset_audio(intelhaddata);
1038 wait_clear_underrun_bit(intelhaddata);
1039 intelhaddata->need_reset = false;
1040}
1041
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001042/* called from irq handler */
1043static void had_process_buffer_underrun(struct snd_intelhad *intelhaddata)
1044{
1045 struct snd_pcm_substream *substream;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301046
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001047 /* Report UNDERRUN error to above layers */
1048 substream = had_substream_get(intelhaddata);
1049 if (substream) {
1050 snd_pcm_stop_xrun(substream);
1051 had_substream_put(intelhaddata);
1052 }
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001053 intelhaddata->need_reset = true;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301054}
1055
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001056/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001057 * ALSA PCM open callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301058 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001059static int had_pcm_open(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301060{
1061 struct snd_intelhad *intelhaddata;
1062 struct snd_pcm_runtime *runtime;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301063 int retval;
1064
Jerome Anand5dab11d2017-01-25 04:27:52 +05301065 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301066 runtime = substream->runtime;
1067
Takashi Iwai182cdf22017-02-02 14:43:39 +01001068 pm_runtime_get_sync(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301069
Jerome Anand5dab11d2017-01-25 04:27:52 +05301070 /* set the runtime hw parameter with local snd_pcm_hardware struct */
Takashi Iwaib5562902017-02-04 22:05:33 +01001071 runtime->hw = had_pcm_hardware;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301072
Jerome Anand5dab11d2017-01-25 04:27:52 +05301073 retval = snd_pcm_hw_constraint_integer(runtime,
1074 SNDRV_PCM_HW_PARAM_PERIODS);
1075 if (retval < 0)
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001076 goto error;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301077
1078 /* Make sure, that the period size is always aligned
1079 * 64byte boundary
1080 */
1081 retval = snd_pcm_hw_constraint_step(substream->runtime, 0,
1082 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64);
Takashi Iwai73997b02017-02-02 17:38:50 +01001083 if (retval < 0)
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001084 goto error;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301085
Takashi Iwai85bd8742017-02-07 13:33:17 +01001086 retval = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1087 if (retval < 0)
1088 goto error;
1089
Takashi Iwai73997b02017-02-02 17:38:50 +01001090 /* expose PCM substream */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001091 spin_lock_irq(&intelhaddata->had_spinlock);
1092 intelhaddata->stream_info.substream = substream;
1093 intelhaddata->stream_info.substream_refcount++;
1094 spin_unlock_irq(&intelhaddata->had_spinlock);
1095
Jerome Anand5dab11d2017-01-25 04:27:52 +05301096 return retval;
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001097 error:
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001098 pm_runtime_mark_last_busy(intelhaddata->dev);
1099 pm_runtime_put_autosuspend(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301100 return retval;
1101}
1102
Takashi Iwaidf76df12017-01-31 16:04:10 +01001103/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001104 * ALSA PCM close callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301105 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001106static int had_pcm_close(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301107{
1108 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301109
Jerome Anand5dab11d2017-01-25 04:27:52 +05301110 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301111
Takashi Iwai73997b02017-02-02 17:38:50 +01001112 /* unreference and sync with the pending PCM accesses */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001113 spin_lock_irq(&intelhaddata->had_spinlock);
1114 intelhaddata->stream_info.substream = NULL;
1115 intelhaddata->stream_info.substream_refcount--;
1116 while (intelhaddata->stream_info.substream_refcount > 0) {
1117 spin_unlock_irq(&intelhaddata->had_spinlock);
1118 cpu_relax();
1119 spin_lock_irq(&intelhaddata->had_spinlock);
1120 }
1121 spin_unlock_irq(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301122
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001123 pm_runtime_mark_last_busy(intelhaddata->dev);
1124 pm_runtime_put_autosuspend(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301125 return 0;
1126}
1127
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001128/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001129 * ALSA PCM hw_params callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301130 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001131static int had_pcm_hw_params(struct snd_pcm_substream *substream,
1132 struct snd_pcm_hw_params *hw_params)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301133{
Takashi Iwaic75b0472017-01-31 15:49:15 +01001134 struct snd_intelhad *intelhaddata;
Takashi Iwaicc6c6912019-12-09 10:49:43 +01001135 int buf_size;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301136
Takashi Iwaic75b0472017-01-31 15:49:15 +01001137 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301138 buf_size = params_buffer_bytes(hw_params);
Takashi Iwaic75b0472017-01-31 15:49:15 +01001139 dev_dbg(intelhaddata->dev, "%s:allocated memory = %d\n",
1140 __func__, buf_size);
Takashi Iwaicc6c6912019-12-09 10:49:43 +01001141 return 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301142}
1143
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001144/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001145 * ALSA PCM hw_free callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301146 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001147static int had_pcm_hw_free(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301148{
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001149 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301150
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001151 intelhaddata = snd_pcm_substream_chip(substream);
1152 had_do_reset(intelhaddata);
1153
Takashi Iwaicc6c6912019-12-09 10:49:43 +01001154 return 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301155}
1156
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001157/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001158 * ALSA PCM trigger callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301159 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001160static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301161{
Takashi Iwaida864802017-01-31 13:52:22 +01001162 int retval = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301163 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301164
Jerome Anand5dab11d2017-01-25 04:27:52 +05301165 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301166
Takashi Iwaidf42cb42017-02-12 11:35:44 +01001167 spin_lock(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301168 switch (cmd) {
1169 case SNDRV_PCM_TRIGGER_START:
Takashi Iwai182cdf22017-02-02 14:43:39 +01001170 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1171 case SNDRV_PCM_TRIGGER_RESUME:
Jerome Anand5dab11d2017-01-25 04:27:52 +05301172 /* Enable Audio */
Takashi Iwai075a1d42017-02-07 07:55:27 +01001173 had_ack_irqs(intelhaddata); /* FIXME: do we need this? */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001174 had_enable_audio(intelhaddata, true);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301175 break;
1176
1177 case SNDRV_PCM_TRIGGER_STOP:
Takashi Iwai182cdf22017-02-02 14:43:39 +01001178 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Jerome Anand5dab11d2017-01-25 04:27:52 +05301179 /* Disable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001180 had_enable_audio(intelhaddata, false);
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001181 intelhaddata->need_reset = true;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301182 break;
1183
1184 default:
1185 retval = -EINVAL;
1186 }
Takashi Iwaidf42cb42017-02-12 11:35:44 +01001187 spin_unlock(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301188 return retval;
1189}
1190
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001191/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001192 * ALSA PCM prepare callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301193 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001194static int had_pcm_prepare(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301195{
1196 int retval;
1197 u32 disp_samp_freq, n_param;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001198 u32 link_rate = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301199 struct snd_intelhad *intelhaddata;
1200 struct snd_pcm_runtime *runtime;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301201
Jerome Anand5dab11d2017-01-25 04:27:52 +05301202 intelhaddata = snd_pcm_substream_chip(substream);
1203 runtime = substream->runtime;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301204
Takashi Iwaic75b0472017-01-31 15:49:15 +01001205 dev_dbg(intelhaddata->dev, "period_size=%d\n",
Jerome Anand5dab11d2017-01-25 04:27:52 +05301206 (int)frames_to_bytes(runtime, runtime->period_size));
Takashi Iwaic75b0472017-01-31 15:49:15 +01001207 dev_dbg(intelhaddata->dev, "periods=%d\n", runtime->periods);
1208 dev_dbg(intelhaddata->dev, "buffer_size=%d\n",
1209 (int)snd_pcm_lib_buffer_bytes(substream));
1210 dev_dbg(intelhaddata->dev, "rate=%d\n", runtime->rate);
1211 dev_dbg(intelhaddata->dev, "channels=%d\n", runtime->channels);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301212
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001213 had_do_reset(intelhaddata);
1214
Jerome Anand5dab11d2017-01-25 04:27:52 +05301215 /* Get N value in KHz */
Takashi Iwaida864802017-01-31 13:52:22 +01001216 disp_samp_freq = intelhaddata->tmds_clock_speed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301217
Takashi Iwaib5562902017-02-04 22:05:33 +01001218 retval = had_prog_n(substream->runtime->rate, &n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301219 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001220 dev_err(intelhaddata->dev,
1221 "programming N value failed %#x\n", retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301222 goto prep_end;
1223 }
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001224
1225 if (intelhaddata->dp_output)
Takashi Iwaida864802017-01-31 13:52:22 +01001226 link_rate = intelhaddata->link_rate;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001227
Takashi Iwaib5562902017-02-04 22:05:33 +01001228 had_prog_cts(substream->runtime->rate, disp_samp_freq, link_rate,
1229 n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301230
Takashi Iwaib5562902017-02-04 22:05:33 +01001231 had_prog_dip(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301232
Takashi Iwaib5562902017-02-04 22:05:33 +01001233 retval = had_init_audio_ctrl(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301234
1235 /* Prog buffer address */
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001236 had_init_ringbuf(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301237
1238 /*
1239 * Program channel mapping in following order:
1240 * FL, FR, C, LFE, RL, RR
1241 */
1242
Takashi Iwai79dda752017-01-30 17:23:39 +01001243 had_write_register(intelhaddata, AUD_BUF_CH_SWAP, SWAP_LFE_CENTER);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301244
1245prep_end:
1246 return retval;
1247}
1248
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001249/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001250 * ALSA PCM pointer callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301251 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001252static snd_pcm_uframes_t had_pcm_pointer(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301253{
1254 struct snd_intelhad *intelhaddata;
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001255 int len;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301256
Jerome Anand5dab11d2017-01-25 04:27:52 +05301257 intelhaddata = snd_pcm_substream_chip(substream);
1258
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001259 if (!intelhaddata->connected)
Takashi Iwai79f439e2017-01-31 16:46:44 +01001260 return SNDRV_PCM_POS_XRUN;
1261
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001262 len = had_process_ringbuf(substream, intelhaddata);
1263 if (len < 0)
1264 return SNDRV_PCM_POS_XRUN;
Takashi Iwai8d48c012017-02-07 08:05:46 +01001265 len = bytes_to_frames(substream->runtime, len);
1266 /* wrapping may happen when periods=1 */
1267 len %= substream->runtime->buffer_size;
1268 return len;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301269}
1270
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001271/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001272 * ALSA PCM mmap callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301273 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001274static int had_pcm_mmap(struct snd_pcm_substream *substream,
1275 struct vm_area_struct *vma)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301276{
Jerome Anand5dab11d2017-01-25 04:27:52 +05301277 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1278 return remap_pfn_range(vma, vma->vm_start,
1279 substream->dma_buffer.addr >> PAGE_SHIFT,
1280 vma->vm_end - vma->vm_start, vma->vm_page_prot);
1281}
1282
Takashi Iwai73997b02017-02-02 17:38:50 +01001283/*
1284 * ALSA PCM ops
1285 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001286static const struct snd_pcm_ops had_pcm_ops = {
1287 .open = had_pcm_open,
1288 .close = had_pcm_close,
Takashi Iwaib5562902017-02-04 22:05:33 +01001289 .hw_params = had_pcm_hw_params,
1290 .hw_free = had_pcm_hw_free,
1291 .prepare = had_pcm_prepare,
1292 .trigger = had_pcm_trigger,
1293 .pointer = had_pcm_pointer,
1294 .mmap = had_pcm_mmap,
Takashi Iwai73997b02017-02-02 17:38:50 +01001295};
1296
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001297/* process mode change of the running stream; called in mutex */
Takashi Iwaib5562902017-02-04 22:05:33 +01001298static int had_process_mode_change(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301299{
Takashi Iwaida864802017-01-31 13:52:22 +01001300 struct snd_pcm_substream *substream;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301301 int retval = 0;
1302 u32 disp_samp_freq, n_param;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001303 u32 link_rate = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301304
Takashi Iwai313d9f22017-02-02 13:00:12 +01001305 substream = had_substream_get(intelhaddata);
1306 if (!substream)
Takashi Iwaida864802017-01-31 13:52:22 +01001307 return 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301308
1309 /* Disable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001310 had_enable_audio(intelhaddata, false);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301311
1312 /* Update CTS value */
Takashi Iwaida864802017-01-31 13:52:22 +01001313 disp_samp_freq = intelhaddata->tmds_clock_speed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301314
Takashi Iwaib5562902017-02-04 22:05:33 +01001315 retval = had_prog_n(substream->runtime->rate, &n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301316 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001317 dev_err(intelhaddata->dev,
1318 "programming N value failed %#x\n", retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301319 goto out;
1320 }
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001321
1322 if (intelhaddata->dp_output)
Takashi Iwaida864802017-01-31 13:52:22 +01001323 link_rate = intelhaddata->link_rate;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001324
Takashi Iwaib5562902017-02-04 22:05:33 +01001325 had_prog_cts(substream->runtime->rate, disp_samp_freq, link_rate,
1326 n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301327
1328 /* Enable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001329 had_enable_audio(intelhaddata, true);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301330
1331out:
Takashi Iwai313d9f22017-02-02 13:00:12 +01001332 had_substream_put(intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301333 return retval;
1334}
1335
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001336/* process hot plug, called from wq with mutex locked */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001337static void had_process_hot_plug(struct snd_intelhad *intelhaddata)
Takashi Iwai372d8552017-01-31 13:57:58 +01001338{
Takashi Iwai372d8552017-01-31 13:57:58 +01001339 struct snd_pcm_substream *substream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001340
Takashi Iwaibcce7752017-02-01 17:18:20 +01001341 spin_lock_irq(&intelhaddata->had_spinlock);
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001342 if (intelhaddata->connected) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001343 dev_dbg(intelhaddata->dev, "Device already connected\n");
Takashi Iwaibcce7752017-02-01 17:18:20 +01001344 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001345 return;
Takashi Iwai372d8552017-01-31 13:57:58 +01001346 }
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001347
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001348 /* Disable Audio */
1349 had_enable_audio(intelhaddata, false);
1350
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001351 intelhaddata->connected = true;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001352 dev_dbg(intelhaddata->dev,
1353 "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n",
Takashi Iwai372d8552017-01-31 13:57:58 +01001354 __func__, __LINE__);
Takashi Iwaibcce7752017-02-01 17:18:20 +01001355 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai372d8552017-01-31 13:57:58 +01001356
Takashi Iwai2d42c032017-02-15 22:08:21 +01001357 had_build_channel_allocation_map(intelhaddata);
1358
1359 /* Report to above ALSA layer */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001360 substream = had_substream_get(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001361 if (substream) {
Takashi Iwai5def9012017-02-15 21:36:38 +01001362 snd_pcm_stop_xrun(substream);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001363 had_substream_put(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001364 }
1365
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001366 snd_jack_report(intelhaddata->jack, SND_JACK_AVOUT);
Takashi Iwai372d8552017-01-31 13:57:58 +01001367}
1368
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001369/* process hot unplug, called from wq with mutex locked */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001370static void had_process_hot_unplug(struct snd_intelhad *intelhaddata)
Takashi Iwai372d8552017-01-31 13:57:58 +01001371{
Takashi Iwai313d9f22017-02-02 13:00:12 +01001372 struct snd_pcm_substream *substream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001373
Takashi Iwaibcce7752017-02-01 17:18:20 +01001374 spin_lock_irq(&intelhaddata->had_spinlock);
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001375 if (!intelhaddata->connected) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001376 dev_dbg(intelhaddata->dev, "Device already disconnected\n");
Takashi Iwaibcce7752017-02-01 17:18:20 +01001377 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai2d42c032017-02-15 22:08:21 +01001378 return;
Takashi Iwai372d8552017-01-31 13:57:58 +01001379
Takashi Iwai372d8552017-01-31 13:57:58 +01001380 }
1381
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001382 /* Disable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001383 had_enable_audio(intelhaddata, false);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001384
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001385 intelhaddata->connected = false;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001386 dev_dbg(intelhaddata->dev,
1387 "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n",
Takashi Iwai372d8552017-01-31 13:57:58 +01001388 __func__, __LINE__);
Takashi Iwaibcce7752017-02-01 17:18:20 +01001389 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001390
Takashi Iwai372d8552017-01-31 13:57:58 +01001391 kfree(intelhaddata->chmap->chmap);
1392 intelhaddata->chmap->chmap = NULL;
Takashi Iwai2d42c032017-02-15 22:08:21 +01001393
1394 /* Report to above ALSA layer */
1395 substream = had_substream_get(intelhaddata);
1396 if (substream) {
1397 snd_pcm_stop_xrun(substream);
1398 had_substream_put(intelhaddata);
1399 }
1400
1401 snd_jack_report(intelhaddata->jack, 0);
Takashi Iwai372d8552017-01-31 13:57:58 +01001402}
1403
Takashi Iwai73997b02017-02-02 17:38:50 +01001404/*
1405 * ALSA iec958 and ELD controls
1406 */
Jerome Anand5dab11d2017-01-25 04:27:52 +05301407
Jerome Anand5dab11d2017-01-25 04:27:52 +05301408static int had_iec958_info(struct snd_kcontrol *kcontrol,
1409 struct snd_ctl_elem_info *uinfo)
1410{
1411 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1412 uinfo->count = 1;
1413 return 0;
1414}
1415
1416static int had_iec958_get(struct snd_kcontrol *kcontrol,
1417 struct snd_ctl_elem_value *ucontrol)
1418{
1419 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
1420
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001421 mutex_lock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301422 ucontrol->value.iec958.status[0] = (intelhaddata->aes_bits >> 0) & 0xff;
1423 ucontrol->value.iec958.status[1] = (intelhaddata->aes_bits >> 8) & 0xff;
1424 ucontrol->value.iec958.status[2] =
1425 (intelhaddata->aes_bits >> 16) & 0xff;
1426 ucontrol->value.iec958.status[3] =
1427 (intelhaddata->aes_bits >> 24) & 0xff;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001428 mutex_unlock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301429 return 0;
1430}
Takashi Iwai372d8552017-01-31 13:57:58 +01001431
Jerome Anand5dab11d2017-01-25 04:27:52 +05301432static int had_iec958_mask_get(struct snd_kcontrol *kcontrol,
1433 struct snd_ctl_elem_value *ucontrol)
1434{
1435 ucontrol->value.iec958.status[0] = 0xff;
1436 ucontrol->value.iec958.status[1] = 0xff;
1437 ucontrol->value.iec958.status[2] = 0xff;
1438 ucontrol->value.iec958.status[3] = 0xff;
1439 return 0;
1440}
Takashi Iwai372d8552017-01-31 13:57:58 +01001441
Jerome Anand5dab11d2017-01-25 04:27:52 +05301442static int had_iec958_put(struct snd_kcontrol *kcontrol,
1443 struct snd_ctl_elem_value *ucontrol)
1444{
1445 unsigned int val;
1446 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001447 int changed = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301448
Jerome Anand5dab11d2017-01-25 04:27:52 +05301449 val = (ucontrol->value.iec958.status[0] << 0) |
1450 (ucontrol->value.iec958.status[1] << 8) |
1451 (ucontrol->value.iec958.status[2] << 16) |
1452 (ucontrol->value.iec958.status[3] << 24);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001453 mutex_lock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301454 if (intelhaddata->aes_bits != val) {
1455 intelhaddata->aes_bits = val;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001456 changed = 1;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301457 }
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001458 mutex_unlock(&intelhaddata->mutex);
1459 return changed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301460}
1461
Takashi Iwai4aedb942017-02-02 16:38:39 +01001462static int had_ctl_eld_info(struct snd_kcontrol *kcontrol,
1463 struct snd_ctl_elem_info *uinfo)
1464{
1465 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1466 uinfo->count = HDMI_MAX_ELD_BYTES;
1467 return 0;
1468}
1469
1470static int had_ctl_eld_get(struct snd_kcontrol *kcontrol,
1471 struct snd_ctl_elem_value *ucontrol)
1472{
1473 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
1474
1475 mutex_lock(&intelhaddata->mutex);
1476 memcpy(ucontrol->value.bytes.data, intelhaddata->eld,
1477 HDMI_MAX_ELD_BYTES);
1478 mutex_unlock(&intelhaddata->mutex);
1479 return 0;
1480}
1481
Takashi Iwai73997b02017-02-02 17:38:50 +01001482static const struct snd_kcontrol_new had_controls[] = {
Takashi Iwai4aedb942017-02-02 16:38:39 +01001483 {
1484 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1485 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1486 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1487 .info = had_iec958_info, /* shared */
1488 .get = had_iec958_mask_get,
1489 },
1490 {
1491 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1492 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1493 .info = had_iec958_info,
1494 .get = had_iec958_get,
1495 .put = had_iec958_put,
1496 },
1497 {
1498 .access = (SNDRV_CTL_ELEM_ACCESS_READ |
1499 SNDRV_CTL_ELEM_ACCESS_VOLATILE),
1500 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1501 .name = "ELD",
1502 .info = had_ctl_eld_info,
1503 .get = had_ctl_eld_get,
1504 },
Jerome Anand5dab11d2017-01-25 04:27:52 +05301505};
1506
Takashi Iwai73997b02017-02-02 17:38:50 +01001507/*
1508 * audio interrupt handler
1509 */
Takashi Iwaida864802017-01-31 13:52:22 +01001510static irqreturn_t display_pipe_interrupt_handler(int irq, void *dev_id)
1511{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001512 struct snd_intelhad_card *card_ctx = dev_id;
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001513 u32 audio_stat[3] = {};
1514 int pipe, port;
Takashi Iwaida864802017-01-31 13:52:22 +01001515
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001516 for_each_pipe(card_ctx, pipe) {
1517 /* use raw register access to ack IRQs even while disconnected */
1518 audio_stat[pipe] = had_read_register_raw(card_ctx, pipe,
1519 AUD_HDMI_STATUS) &
1520 (HDMI_AUDIO_UNDERRUN | HDMI_AUDIO_BUFFER_DONE);
Takashi Iwaida864802017-01-31 13:52:22 +01001521
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001522 if (audio_stat[pipe])
1523 had_write_register_raw(card_ctx, pipe,
1524 AUD_HDMI_STATUS, audio_stat[pipe]);
Takashi Iwaida864802017-01-31 13:52:22 +01001525 }
1526
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001527 for_each_port(card_ctx, port) {
1528 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001529 int pipe = ctx->pipe;
Takashi Iwaida864802017-01-31 13:52:22 +01001530
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001531 if (pipe < 0)
1532 continue;
Takashi Iwaida864802017-01-31 13:52:22 +01001533
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001534 if (audio_stat[pipe] & HDMI_AUDIO_BUFFER_DONE)
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001535 had_process_buffer_done(ctx);
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001536 if (audio_stat[pipe] & HDMI_AUDIO_UNDERRUN)
1537 had_process_buffer_underrun(ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001538 }
1539
1540 return IRQ_HANDLED;
1541}
1542
Takashi Iwai73997b02017-02-02 17:38:50 +01001543/*
1544 * monitor plug/unplug notification from i915; just kick off the work
1545 */
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001546static void notify_audio_lpe(struct platform_device *pdev, int port)
Takashi Iwaida864802017-01-31 13:52:22 +01001547{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001548 struct snd_intelhad_card *card_ctx = platform_get_drvdata(pdev);
Takashi Iwai7229b122018-02-20 17:33:45 +01001549 struct snd_intelhad *ctx;
1550
1551 ctx = &card_ctx->pcm_ctx[single_port ? 0 : port];
1552 if (single_port)
1553 ctx->port = port;
Takashi Iwaida864802017-01-31 13:52:22 +01001554
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001555 schedule_work(&ctx->hdmi_audio_wq);
1556}
Takashi Iwaida864802017-01-31 13:52:22 +01001557
Takashi Iwai73997b02017-02-02 17:38:50 +01001558/* the work to handle monitor hot plug/unplug */
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001559static void had_audio_wq(struct work_struct *work)
1560{
1561 struct snd_intelhad *ctx =
1562 container_of(work, struct snd_intelhad, hdmi_audio_wq);
1563 struct intel_hdmi_lpe_audio_pdata *pdata = ctx->dev->platform_data;
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001564 struct intel_hdmi_lpe_audio_port_pdata *ppdata = &pdata->port[ctx->port];
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001565
Takashi Iwai182cdf22017-02-02 14:43:39 +01001566 pm_runtime_get_sync(ctx->dev);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001567 mutex_lock(&ctx->mutex);
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001568 if (ppdata->pipe < 0) {
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001569 dev_dbg(ctx->dev, "%s: Event: HAD_NOTIFY_HOT_UNPLUG : port = %d\n",
1570 __func__, ctx->port);
1571
Takashi Iwai4aedb942017-02-02 16:38:39 +01001572 memset(ctx->eld, 0, sizeof(ctx->eld)); /* clear the old ELD */
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001573
1574 ctx->dp_output = false;
1575 ctx->tmds_clock_speed = 0;
1576 ctx->link_rate = 0;
1577
1578 /* Shut down the stream */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001579 had_process_hot_unplug(ctx);
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001580
1581 ctx->pipe = -1;
Takashi Iwaida864802017-01-31 13:52:22 +01001582 } else {
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001583 dev_dbg(ctx->dev, "%s: HAD_NOTIFY_ELD : port = %d, tmds = %d\n",
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001584 __func__, ctx->port, ppdata->ls_clock);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001585
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001586 memcpy(ctx->eld, ppdata->eld, sizeof(ctx->eld));
Takashi Iwaida864802017-01-31 13:52:22 +01001587
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001588 ctx->dp_output = ppdata->dp_output;
Ville Syrjäläc98ec5b2017-04-27 19:02:24 +03001589 if (ctx->dp_output) {
1590 ctx->tmds_clock_speed = 0;
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001591 ctx->link_rate = ppdata->ls_clock;
Ville Syrjäläc98ec5b2017-04-27 19:02:24 +03001592 } else {
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001593 ctx->tmds_clock_speed = ppdata->ls_clock;
Ville Syrjäläc98ec5b2017-04-27 19:02:24 +03001594 ctx->link_rate = 0;
Takashi Iwaida864802017-01-31 13:52:22 +01001595 }
1596
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001597 /*
1598 * Shut down the stream before we change
1599 * the pipe assignment for this pcm device
1600 */
Takashi Iwaida864802017-01-31 13:52:22 +01001601 had_process_hot_plug(ctx);
1602
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001603 ctx->pipe = ppdata->pipe;
1604
1605 /* Restart the stream if necessary */
Takashi Iwaib5562902017-02-04 22:05:33 +01001606 had_process_mode_change(ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001607 }
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001608
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001609 mutex_unlock(&ctx->mutex);
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001610 pm_runtime_mark_last_busy(ctx->dev);
1611 pm_runtime_put_autosuspend(ctx->dev);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001612}
1613
1614/*
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001615 * Jack interface
1616 */
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001617static int had_create_jack(struct snd_intelhad *ctx,
1618 struct snd_pcm *pcm)
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001619{
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001620 char hdmi_str[32];
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001621 int err;
1622
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001623 snprintf(hdmi_str, sizeof(hdmi_str),
1624 "HDMI/DP,pcm=%d", pcm->device);
1625
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001626 err = snd_jack_new(ctx->card_ctx->card, hdmi_str,
1627 SND_JACK_AVOUT, &ctx->jack,
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001628 true, false);
1629 if (err < 0)
1630 return err;
1631 ctx->jack->private_data = ctx;
1632 return 0;
1633}
1634
1635/*
Takashi Iwai182cdf22017-02-02 14:43:39 +01001636 * PM callbacks
1637 */
1638
Ville Syrjälä00194572018-10-24 18:48:25 +03001639static int __maybe_unused hdmi_lpe_audio_suspend(struct device *dev)
Takashi Iwai182cdf22017-02-02 14:43:39 +01001640{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001641 struct snd_intelhad_card *card_ctx = dev_get_drvdata(dev);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001642
Ville Syrjälä00194572018-10-24 18:48:25 +03001643 snd_power_change_state(card_ctx->card, SNDRV_CTL_POWER_D3hot);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001644
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001645 return 0;
1646}
1647
Arnd Bergmann1df98922017-02-07 14:38:51 +01001648static int __maybe_unused hdmi_lpe_audio_resume(struct device *dev)
Takashi Iwai182cdf22017-02-02 14:43:39 +01001649{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001650 struct snd_intelhad_card *card_ctx = dev_get_drvdata(dev);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001651
Ville Syrjälä00194572018-10-24 18:48:25 +03001652 pm_runtime_mark_last_busy(dev);
1653
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001654 snd_power_change_state(card_ctx->card, SNDRV_CTL_POWER_D0);
Ville Syrjälä00194572018-10-24 18:48:25 +03001655
Takashi Iwai182cdf22017-02-02 14:43:39 +01001656 return 0;
Takashi Iwaida864802017-01-31 13:52:22 +01001657}
1658
1659/* release resources */
1660static void hdmi_lpe_audio_free(struct snd_card *card)
1661{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001662 struct snd_intelhad_card *card_ctx = card->private_data;
1663 struct intel_hdmi_lpe_audio_pdata *pdata = card_ctx->dev->platform_data;
1664 int port;
Takashi Iwaida864802017-01-31 13:52:22 +01001665
Ville Syrjälä8d5c3032017-04-27 19:02:21 +03001666 spin_lock_irq(&pdata->lpe_audio_slock);
1667 pdata->notify_audio_lpe = NULL;
1668 spin_unlock_irq(&pdata->lpe_audio_slock);
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001669
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001670 for_each_port(card_ctx, port) {
1671 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
Takashi Iwaida864802017-01-31 13:52:22 +01001672
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001673 cancel_work_sync(&ctx->hdmi_audio_wq);
1674 }
1675
1676 if (card_ctx->mmio_start)
1677 iounmap(card_ctx->mmio_start);
1678 if (card_ctx->irq >= 0)
1679 free_irq(card_ctx->irq, card_ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001680}
1681
1682/*
1683 * hdmi_lpe_audio_probe - start bridge with i915
1684 *
1685 * This function is called when the i915 driver creates the
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001686 * hdmi-lpe-audio platform device.
Takashi Iwaida864802017-01-31 13:52:22 +01001687 */
1688static int hdmi_lpe_audio_probe(struct platform_device *pdev)
1689{
1690 struct snd_card *card;
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001691 struct snd_intelhad_card *card_ctx;
Takashi Iwaic77a6ed2018-02-28 08:46:00 +01001692 struct snd_intelhad *ctx;
Takashi Iwaida864802017-01-31 13:52:22 +01001693 struct snd_pcm *pcm;
1694 struct intel_hdmi_lpe_audio_pdata *pdata;
1695 int irq;
1696 struct resource *res_mmio;
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001697 int port, ret;
Takashi Iwaida864802017-01-31 13:52:22 +01001698
Takashi Iwaida864802017-01-31 13:52:22 +01001699 pdata = pdev->dev.platform_data;
1700 if (!pdata) {
1701 dev_err(&pdev->dev, "%s: quit: pdata not allocated by i915!!\n", __func__);
1702 return -EINVAL;
1703 }
1704
1705 /* get resources */
1706 irq = platform_get_irq(pdev, 0);
YueHaibing0a671dc2019-10-25 17:39:05 +08001707 if (irq < 0)
Gustavo A. R. Silva19671582017-06-30 15:18:41 -05001708 return irq;
Takashi Iwaida864802017-01-31 13:52:22 +01001709
1710 res_mmio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1711 if (!res_mmio) {
1712 dev_err(&pdev->dev, "Could not get IO_MEM resources\n");
1713 return -ENXIO;
1714 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301715
Takashi Iwai5647aec2017-01-31 08:14:34 +01001716 /* create a card instance with ALSA framework */
Takashi Iwaida864802017-01-31 13:52:22 +01001717 ret = snd_card_new(&pdev->dev, hdmi_card_index, hdmi_card_id,
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001718 THIS_MODULE, sizeof(*card_ctx), &card);
Takashi Iwaida864802017-01-31 13:52:22 +01001719 if (ret)
1720 return ret;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301721
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001722 card_ctx = card->private_data;
1723 card_ctx->dev = &pdev->dev;
1724 card_ctx->card = card;
Takashi Iwaida864802017-01-31 13:52:22 +01001725 strcpy(card->driver, INTEL_HAD);
Takashi Iwai873ab032017-02-07 12:14:04 +01001726 strcpy(card->shortname, "Intel HDMI/DP LPE Audio");
1727 strcpy(card->longname, "Intel HDMI/DP LPE Audio");
Jerome Anand5dab11d2017-01-25 04:27:52 +05301728
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001729 card_ctx->irq = -1;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301730
Takashi Iwaida864802017-01-31 13:52:22 +01001731 card->private_free = hdmi_lpe_audio_free;
1732
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001733 platform_set_drvdata(pdev, card_ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001734
Takashi Iwaic77a6ed2018-02-28 08:46:00 +01001735 card_ctx->num_pipes = pdata->num_pipes;
1736 card_ctx->num_ports = single_port ? 1 : pdata->num_ports;
1737
1738 for_each_port(card_ctx, port) {
1739 ctx = &card_ctx->pcm_ctx[port];
1740 ctx->card_ctx = card_ctx;
1741 ctx->dev = card_ctx->dev;
1742 ctx->port = single_port ? -1 : port;
1743 ctx->pipe = -1;
1744
1745 spin_lock_init(&ctx->had_spinlock);
1746 mutex_init(&ctx->mutex);
1747 INIT_WORK(&ctx->hdmi_audio_wq, had_audio_wq);
1748 }
1749
Takashi Iwaida864802017-01-31 13:52:22 +01001750 dev_dbg(&pdev->dev, "%s: mmio_start = 0x%x, mmio_end = 0x%x\n",
1751 __func__, (unsigned int)res_mmio->start,
1752 (unsigned int)res_mmio->end);
1753
Christoph Hellwig4bdc0d62020-01-06 09:43:50 +01001754 card_ctx->mmio_start = ioremap(res_mmio->start,
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001755 (size_t)(resource_size(res_mmio)));
1756 if (!card_ctx->mmio_start) {
Takashi Iwaida864802017-01-31 13:52:22 +01001757 dev_err(&pdev->dev, "Could not get ioremap\n");
1758 ret = -EACCES;
1759 goto err;
1760 }
1761
1762 /* setup interrupt handler */
1763 ret = request_irq(irq, display_pipe_interrupt_handler, 0,
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001764 pdev->name, card_ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001765 if (ret < 0) {
1766 dev_err(&pdev->dev, "request_irq failed\n");
1767 goto err;
1768 }
1769
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001770 card_ctx->irq = irq;
Takashi Iwai412bbe7d52017-02-02 22:03:22 +01001771
1772 /* only 32bit addressable */
1773 dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
1774 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
1775
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001776 init_channel_allocations();
Jerome Anand5dab11d2017-01-25 04:27:52 +05301777
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001778 card_ctx->num_pipes = pdata->num_pipes;
Takashi Iwai7229b122018-02-20 17:33:45 +01001779 card_ctx->num_ports = single_port ? 1 : pdata->num_ports;
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001780
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001781 for_each_port(card_ctx, port) {
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001782 int i;
1783
Takashi Iwaic77a6ed2018-02-28 08:46:00 +01001784 ctx = &card_ctx->pcm_ctx[port];
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001785 ret = snd_pcm_new(card, INTEL_HAD, port, MAX_PB_STREAMS,
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001786 MAX_CAP_STREAMS, &pcm);
1787 if (ret)
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001788 goto err;
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001789
1790 /* setup private data which can be retrieved when required */
1791 pcm->private_data = ctx;
1792 pcm->info_flags = 0;
Takashi Iwaic2882482018-06-27 14:59:00 +02001793 strlcpy(pcm->name, card->shortname, strlen(card->shortname));
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001794 /* setup the ops for playabck */
1795 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &had_pcm_ops);
1796
1797 /* allocate dma pages;
1798 * try to allocate 600k buffer as default which is large enough
1799 */
Takashi Iwaicc6c6912019-12-09 10:49:43 +01001800 snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV_UC,
1801 card->dev, HAD_DEFAULT_BUFFER,
1802 HAD_MAX_BUFFER);
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001803
1804 /* create controls */
1805 for (i = 0; i < ARRAY_SIZE(had_controls); i++) {
1806 struct snd_kcontrol *kctl;
1807
1808 kctl = snd_ctl_new1(&had_controls[i], ctx);
1809 if (!kctl) {
1810 ret = -ENOMEM;
1811 goto err;
1812 }
1813
1814 kctl->id.device = pcm->device;
1815
1816 ret = snd_ctl_add(card, kctl);
1817 if (ret < 0)
1818 goto err;
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001819 }
1820
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001821 /* Register channel map controls */
1822 ret = had_register_chmap_ctls(ctx, pcm);
1823 if (ret < 0)
1824 goto err;
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001825
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001826 ret = had_create_jack(ctx, pcm);
Takashi Iwai4aedb942017-02-02 16:38:39 +01001827 if (ret < 0)
1828 goto err;
1829 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301830
Takashi Iwaida864802017-01-31 13:52:22 +01001831 ret = snd_card_register(card);
1832 if (ret)
Takashi Iwai36ec0d92017-01-31 08:47:05 +01001833 goto err;
1834
Takashi Iwaibcce7752017-02-01 17:18:20 +01001835 spin_lock_irq(&pdata->lpe_audio_slock);
Takashi Iwaida864802017-01-31 13:52:22 +01001836 pdata->notify_audio_lpe = notify_audio_lpe;
Takashi Iwaibcce7752017-02-01 17:18:20 +01001837 spin_unlock_irq(&pdata->lpe_audio_slock);
Takashi Iwaida864802017-01-31 13:52:22 +01001838
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001839 pm_runtime_use_autosuspend(&pdev->dev);
1840 pm_runtime_mark_last_busy(&pdev->dev);
Takashi Iwaida864802017-01-31 13:52:22 +01001841
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001842 dev_dbg(&pdev->dev, "%s: handle pending notification\n", __func__);
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001843 for_each_port(card_ctx, port) {
1844 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
1845
1846 schedule_work(&ctx->hdmi_audio_wq);
1847 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301848
Takashi Iwai79dda752017-01-30 17:23:39 +01001849 return 0;
Takashi Iwai5647aec2017-01-31 08:14:34 +01001850
Jerome Anand5dab11d2017-01-25 04:27:52 +05301851err:
1852 snd_card_free(card);
Takashi Iwaida864802017-01-31 13:52:22 +01001853 return ret;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301854}
1855
Takashi Iwai79dda752017-01-30 17:23:39 +01001856/*
Takashi Iwaida864802017-01-31 13:52:22 +01001857 * hdmi_lpe_audio_remove - stop bridge with i915
Jerome Anand5dab11d2017-01-25 04:27:52 +05301858 *
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001859 * This function is called when the platform device is destroyed.
Jerome Anand5dab11d2017-01-25 04:27:52 +05301860 */
Takashi Iwaida864802017-01-31 13:52:22 +01001861static int hdmi_lpe_audio_remove(struct platform_device *pdev)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301862{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001863 struct snd_intelhad_card *card_ctx = platform_get_drvdata(pdev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301864
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001865 snd_card_free(card_ctx->card);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301866 return 0;
1867}
1868
Takashi Iwai182cdf22017-02-02 14:43:39 +01001869static const struct dev_pm_ops hdmi_lpe_audio_pm = {
1870 SET_SYSTEM_SLEEP_PM_OPS(hdmi_lpe_audio_suspend, hdmi_lpe_audio_resume)
Takashi Iwai182cdf22017-02-02 14:43:39 +01001871};
1872
Takashi Iwaida864802017-01-31 13:52:22 +01001873static struct platform_driver hdmi_lpe_audio_driver = {
1874 .driver = {
1875 .name = "hdmi-lpe-audio",
Takashi Iwai182cdf22017-02-02 14:43:39 +01001876 .pm = &hdmi_lpe_audio_pm,
Takashi Iwaida864802017-01-31 13:52:22 +01001877 },
1878 .probe = hdmi_lpe_audio_probe,
1879 .remove = hdmi_lpe_audio_remove,
Takashi Iwaida864802017-01-31 13:52:22 +01001880};
1881
1882module_platform_driver(hdmi_lpe_audio_driver);
1883MODULE_ALIAS("platform:hdmi_lpe_audio");
1884
Jerome Anand5dab11d2017-01-25 04:27:52 +05301885MODULE_AUTHOR("Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>");
1886MODULE_AUTHOR("Ramesh Babu K V <ramesh.babu@intel.com>");
1887MODULE_AUTHOR("Vaibhav Agarwal <vaibhav.agarwal@intel.com>");
1888MODULE_AUTHOR("Jerome Anand <jerome.anand@intel.com>");
1889MODULE_DESCRIPTION("Intel HDMI Audio driver");
1890MODULE_LICENSE("GPL v2");
1891MODULE_SUPPORTED_DEVICE("{Intel,Intel_HAD}");