blob: 04ff7f14fe12a1fc3bd9bd67365e4f0c2284c29a [file] [log] [blame]
Jerome Anand5dab11d2017-01-25 04:27:52 +05301/*
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
Jerome Anand5dab11d2017-01-25 04:27:52 +053024#include <linux/platform_device.h>
25#include <linux/io.h>
26#include <linux/slab.h>
27#include <linux/module.h>
Takashi Iwaida864802017-01-31 13:52:22 +010028#include <linux/interrupt.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053029#include <linux/acpi.h>
30#include <asm/cacheflush.h>
31#include <sound/pcm.h>
32#include <sound/core.h>
33#include <sound/pcm_params.h>
34#include <sound/initval.h>
35#include <sound/control.h>
36#include <sound/initval.h>
Takashi Iwaida864802017-01-31 13:52:22 +010037#include <drm/intel_lpe_audio.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053038#include "intel_hdmi_audio.h"
39
Jerome Anand5dab11d2017-01-25 04:27:52 +053040/*standard module options for ALSA. This module supports only one card*/
41static int hdmi_card_index = SNDRV_DEFAULT_IDX1;
42static char *hdmi_card_id = SNDRV_DEFAULT_STR1;
Jerome Anand5dab11d2017-01-25 04:27:52 +053043
44module_param_named(index, hdmi_card_index, int, 0444);
45MODULE_PARM_DESC(index,
46 "Index value for INTEL Intel HDMI Audio controller.");
47module_param_named(id, hdmi_card_id, charp, 0444);
48MODULE_PARM_DESC(id,
49 "ID string for INTEL Intel HDMI Audio controller.");
50
51/*
52 * ELD SA bits in the CEA Speaker Allocation data block
53 */
Takashi Iwai4a5ddb22017-02-01 16:45:38 +010054static const int eld_speaker_allocation_bits[] = {
Jerome Anand5dab11d2017-01-25 04:27:52 +053055 [0] = FL | FR,
56 [1] = LFE,
57 [2] = FC,
58 [3] = RL | RR,
59 [4] = RC,
60 [5] = FLC | FRC,
61 [6] = RLC | RRC,
62 /* the following are not defined in ELD yet */
63 [7] = 0,
64};
65
66/*
67 * This is an ordered list!
68 *
69 * The preceding ones have better chances to be selected by
70 * hdmi_channel_allocation().
71 */
72static struct cea_channel_speaker_allocation channel_allocations[] = {
73/* channel: 7 6 5 4 3 2 1 0 */
74{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
75 /* 2.1 */
76{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
77 /* Dolby Surround */
78{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
79 /* surround40 */
80{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
81 /* surround41 */
82{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
83 /* surround50 */
84{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
85 /* surround51 */
86{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
87 /* 6.1 */
88{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
89 /* surround71 */
90{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
91
92{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
93{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
94{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
95{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
96{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
97{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
98{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
99{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
100{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
101{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
102{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
103{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
104{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
105{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
106{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
107{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
108{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
109{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
110{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
111{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
112{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
113{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
114{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
115};
116
Takashi Iwai4a5ddb22017-02-01 16:45:38 +0100117static const struct channel_map_table map_tables[] = {
Jerome Anand5dab11d2017-01-25 04:27:52 +0530118 { SNDRV_CHMAP_FL, 0x00, FL },
119 { SNDRV_CHMAP_FR, 0x01, FR },
120 { SNDRV_CHMAP_RL, 0x04, RL },
121 { SNDRV_CHMAP_RR, 0x05, RR },
122 { SNDRV_CHMAP_LFE, 0x02, LFE },
123 { SNDRV_CHMAP_FC, 0x03, FC },
124 { SNDRV_CHMAP_RLC, 0x06, RLC },
125 { SNDRV_CHMAP_RRC, 0x07, RRC },
126 {} /* terminator */
127};
128
129/* hardware capability structure */
130static const struct snd_pcm_hardware snd_intel_hadstream = {
131 .info = (SNDRV_PCM_INFO_INTERLEAVED |
132 SNDRV_PCM_INFO_DOUBLE |
133 SNDRV_PCM_INFO_MMAP|
134 SNDRV_PCM_INFO_MMAP_VALID |
135 SNDRV_PCM_INFO_BATCH),
136 .formats = (SNDRV_PCM_FMTBIT_S24 |
137 SNDRV_PCM_FMTBIT_U24),
138 .rates = SNDRV_PCM_RATE_32000 |
139 SNDRV_PCM_RATE_44100 |
140 SNDRV_PCM_RATE_48000 |
141 SNDRV_PCM_RATE_88200 |
142 SNDRV_PCM_RATE_96000 |
143 SNDRV_PCM_RATE_176400 |
144 SNDRV_PCM_RATE_192000,
145 .rate_min = HAD_MIN_RATE,
146 .rate_max = HAD_MAX_RATE,
147 .channels_min = HAD_MIN_CHANNEL,
148 .channels_max = HAD_MAX_CHANNEL,
149 .buffer_bytes_max = HAD_MAX_BUFFER,
150 .period_bytes_min = HAD_MIN_PERIOD_BYTES,
151 .period_bytes_max = HAD_MAX_PERIOD_BYTES,
152 .periods_min = HAD_MIN_PERIODS,
153 .periods_max = HAD_MAX_PERIODS,
154 .fifo_size = HAD_FIFO_SIZE,
155};
156
Takashi Iwai313d9f22017-02-02 13:00:12 +0100157/* Get the active PCM substream;
158 * Call had_substream_put() for unreferecing.
159 * Don't call this inside had_spinlock, as it takes by itself
160 */
161static struct snd_pcm_substream *
162had_substream_get(struct snd_intelhad *intelhaddata)
163{
164 struct snd_pcm_substream *substream;
165 unsigned long flags;
166
167 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
168 substream = intelhaddata->stream_info.substream;
169 if (substream)
170 intelhaddata->stream_info.substream_refcount++;
171 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
172 return substream;
173}
174
175/* Unref the active PCM substream;
176 * Don't call this inside had_spinlock, as it takes by itself
177 */
178static void had_substream_put(struct snd_intelhad *intelhaddata)
179{
180 unsigned long flags;
181
182 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
183 intelhaddata->stream_info.substream_refcount--;
184 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
185}
186
Jerome Anand5dab11d2017-01-25 04:27:52 +0530187/* Register access functions */
Takashi Iwaida864802017-01-31 13:52:22 +0100188static inline void
189mid_hdmi_audio_read(struct snd_intelhad *ctx, u32 reg, u32 *val)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530190{
Takashi Iwaida864802017-01-31 13:52:22 +0100191 *val = ioread32(ctx->mmio_start + ctx->had_config_offset + reg);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530192}
193
Takashi Iwaida864802017-01-31 13:52:22 +0100194static inline void
195mid_hdmi_audio_write(struct snd_intelhad *ctx, u32 reg, u32 val)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530196{
Takashi Iwaida864802017-01-31 13:52:22 +0100197 iowrite32(val, ctx->mmio_start + ctx->had_config_offset + reg);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530198}
199
Takashi Iwai372d8552017-01-31 13:57:58 +0100200static int had_read_register(struct snd_intelhad *intelhaddata,
201 u32 offset, u32 *data)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530202{
Takashi Iwai79f439e2017-01-31 16:46:44 +0100203 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
204 return -ENODEV;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530205
Takashi Iwaida864802017-01-31 13:52:22 +0100206 mid_hdmi_audio_read(intelhaddata, offset, data);
207 return 0;
208}
209
210static void fixup_dp_config(struct snd_intelhad *intelhaddata,
211 u32 offset, u32 *data)
212{
213 if (intelhaddata->dp_output) {
214 if (offset == AUD_CONFIG && (*data & AUD_CONFIG_VALID_BIT))
215 *data |= AUD_CONFIG_DP_MODE | AUD_CONFIG_BLOCK_BIT;
216 }
Jerome Anand5dab11d2017-01-25 04:27:52 +0530217}
218
Takashi Iwai372d8552017-01-31 13:57:58 +0100219static int had_write_register(struct snd_intelhad *intelhaddata,
220 u32 offset, u32 data)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530221{
Takashi Iwai79f439e2017-01-31 16:46:44 +0100222 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
223 return -ENODEV;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530224
Takashi Iwaida864802017-01-31 13:52:22 +0100225 fixup_dp_config(intelhaddata, offset, &data);
226 mid_hdmi_audio_write(intelhaddata, offset, data);
227 return 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530228}
229
Takashi Iwai372d8552017-01-31 13:57:58 +0100230static int had_read_modify(struct snd_intelhad *intelhaddata, u32 offset,
231 u32 data, u32 mask)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530232{
Takashi Iwaida864802017-01-31 13:52:22 +0100233 u32 val_tmp;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530234
Takashi Iwai79f439e2017-01-31 16:46:44 +0100235 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
236 return -ENODEV;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530237
Takashi Iwaida864802017-01-31 13:52:22 +0100238 mid_hdmi_audio_read(intelhaddata, offset, &val_tmp);
239 val_tmp &= ~mask;
240 val_tmp |= (data & mask);
241
242 fixup_dp_config(intelhaddata, offset, &val_tmp);
243 mid_hdmi_audio_write(intelhaddata, offset, val_tmp);
244 return 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530245}
Takashi Iwaida864802017-01-31 13:52:22 +0100246
247/*
Takashi Iwai313d9f22017-02-02 13:00:12 +0100248 * enable / disable audio configuration
249 *
Takashi Iwaida864802017-01-31 13:52:22 +0100250 * The had_read_modify() function should not directly be used on VLV2 for
251 * updating AUD_CONFIG register.
Jerome Anand5dab11d2017-01-25 04:27:52 +0530252 * This is because:
253 * Bit6 of AUD_CONFIG register is writeonly due to a silicon bug on VLV2
254 * HDMI IP. As a result a read-modify of AUD_CONFIG regiter will always
255 * clear bit6. AUD_CONFIG[6:4] represents the "channels" field of the
256 * register. This field should be 1xy binary for configuration with 6 or
257 * more channels. Read-modify of AUD_CONFIG (Eg. for enabling audio)
258 * causes the "channels" field to be updated as 0xy binary resulting in
259 * bad audio. The fix is to always write the AUD_CONFIG[6:4] with
260 * appropriate value when doing read-modify of AUD_CONFIG register.
Jerome Anand5dab11d2017-01-25 04:27:52 +0530261 */
Takashi Iwai313d9f22017-02-02 13:00:12 +0100262static void snd_intelhad_enable_audio(struct snd_pcm_substream *substream,
263 struct snd_intelhad *intelhaddata,
264 bool enable)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530265{
266 union aud_cfg cfg_val = {.cfg_regval = 0};
Takashi Iwai313d9f22017-02-02 13:00:12 +0100267 u8 channels, data, mask;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530268
269 /*
270 * If substream is NULL, there is no active stream.
271 * In this case just set channels to 2
272 */
Takashi Iwai313d9f22017-02-02 13:00:12 +0100273 channels = substream ? substream->runtime->channels : 2;
Takashi Iwai4151ee82017-01-31 18:14:15 +0100274 cfg_val.cfg_regx.num_ch = channels - 2;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530275
Takashi Iwai313d9f22017-02-02 13:00:12 +0100276 data = cfg_val.cfg_regval;
277 if (enable)
278 data |= 1;
279 mask = AUD_CONFIG_CH_MASK | 1;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530280
Takashi Iwaic75b0472017-01-31 15:49:15 +0100281 dev_dbg(intelhaddata->dev, "%s : data = %x, mask =%x\n",
282 __func__, data, mask);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530283
Takashi Iwai313d9f22017-02-02 13:00:12 +0100284 had_read_modify(intelhaddata, AUD_CONFIG, data, mask);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530285}
286
Takashi Iwai313d9f22017-02-02 13:00:12 +0100287/* enable / disable the audio interface */
Takashi Iwai372d8552017-01-31 13:57:58 +0100288static void snd_intelhad_enable_audio_int(struct snd_intelhad *ctx, bool enable)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530289{
Takashi Iwaida864802017-01-31 13:52:22 +0100290 u32 status_reg;
291
292 if (enable) {
Takashi Iwai4151ee82017-01-31 18:14:15 +0100293 mid_hdmi_audio_read(ctx, AUD_HDMI_STATUS, &status_reg);
Takashi Iwaida864802017-01-31 13:52:22 +0100294 status_reg |= HDMI_AUDIO_BUFFER_DONE | HDMI_AUDIO_UNDERRUN;
Takashi Iwai4151ee82017-01-31 18:14:15 +0100295 mid_hdmi_audio_write(ctx, AUD_HDMI_STATUS, status_reg);
296 mid_hdmi_audio_read(ctx, AUD_HDMI_STATUS, &status_reg);
Takashi Iwaida864802017-01-31 13:52:22 +0100297 }
298}
299
Takashi Iwai79dda752017-01-30 17:23:39 +0100300static void snd_intelhad_reset_audio(struct snd_intelhad *intelhaddata,
301 u8 reset)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530302{
Takashi Iwai4151ee82017-01-31 18:14:15 +0100303 had_write_register(intelhaddata, AUD_HDMI_STATUS, reset);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530304}
305
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100306/*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530307 * initialize audio channel status registers
308 * This function is called in the prepare callback
309 */
310static int had_prog_status_reg(struct snd_pcm_substream *substream,
311 struct snd_intelhad *intelhaddata)
312{
313 union aud_cfg cfg_val = {.cfg_regval = 0};
314 union aud_ch_status_0 ch_stat0 = {.status_0_regval = 0};
315 union aud_ch_status_1 ch_stat1 = {.status_1_regval = 0};
316 int format;
317
Jerome Anand5dab11d2017-01-25 04:27:52 +0530318 ch_stat0.status_0_regx.lpcm_id = (intelhaddata->aes_bits &
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100319 IEC958_AES0_NONAUDIO) >> 1;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530320 ch_stat0.status_0_regx.clk_acc = (intelhaddata->aes_bits &
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100321 IEC958_AES3_CON_CLOCK) >> 4;
Takashi Iwai4151ee82017-01-31 18:14:15 +0100322 cfg_val.cfg_regx.val_bit = ch_stat0.status_0_regx.lpcm_id;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530323
324 switch (substream->runtime->rate) {
325 case AUD_SAMPLE_RATE_32:
326 ch_stat0.status_0_regx.samp_freq = CH_STATUS_MAP_32KHZ;
327 break;
328
329 case AUD_SAMPLE_RATE_44_1:
330 ch_stat0.status_0_regx.samp_freq = CH_STATUS_MAP_44KHZ;
331 break;
332 case AUD_SAMPLE_RATE_48:
333 ch_stat0.status_0_regx.samp_freq = CH_STATUS_MAP_48KHZ;
334 break;
335 case AUD_SAMPLE_RATE_88_2:
336 ch_stat0.status_0_regx.samp_freq = CH_STATUS_MAP_88KHZ;
337 break;
338 case AUD_SAMPLE_RATE_96:
339 ch_stat0.status_0_regx.samp_freq = CH_STATUS_MAP_96KHZ;
340 break;
341 case AUD_SAMPLE_RATE_176_4:
342 ch_stat0.status_0_regx.samp_freq = CH_STATUS_MAP_176KHZ;
343 break;
344 case AUD_SAMPLE_RATE_192:
345 ch_stat0.status_0_regx.samp_freq = CH_STATUS_MAP_192KHZ;
346 break;
347
348 default:
349 /* control should never come here */
350 return -EINVAL;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530351 }
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100352
Takashi Iwai79dda752017-01-30 17:23:39 +0100353 had_write_register(intelhaddata,
354 AUD_CH_STATUS_0, ch_stat0.status_0_regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530355
356 format = substream->runtime->format;
357
358 if (format == SNDRV_PCM_FORMAT_S16_LE) {
359 ch_stat1.status_1_regx.max_wrd_len = MAX_SMPL_WIDTH_20;
360 ch_stat1.status_1_regx.wrd_len = SMPL_WIDTH_16BITS;
361 } else if (format == SNDRV_PCM_FORMAT_S24_LE) {
362 ch_stat1.status_1_regx.max_wrd_len = MAX_SMPL_WIDTH_24;
363 ch_stat1.status_1_regx.wrd_len = SMPL_WIDTH_24BITS;
364 } else {
365 ch_stat1.status_1_regx.max_wrd_len = 0;
366 ch_stat1.status_1_regx.wrd_len = 0;
367 }
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100368
Takashi Iwai79dda752017-01-30 17:23:39 +0100369 had_write_register(intelhaddata,
370 AUD_CH_STATUS_1, ch_stat1.status_1_regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530371 return 0;
372}
373
Takashi Iwai76296ef2017-01-30 16:09:11 +0100374/*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530375 * function to initialize audio
376 * registers and buffer confgiuration registers
377 * This function is called in the prepare callback
378 */
Takashi Iwai76296ef2017-01-30 16:09:11 +0100379static int snd_intelhad_audio_ctrl(struct snd_pcm_substream *substream,
380 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530381{
382 union aud_cfg cfg_val = {.cfg_regval = 0};
383 union aud_buf_config buf_cfg = {.buf_cfgval = 0};
384 u8 channels;
385
386 had_prog_status_reg(substream, intelhaddata);
387
Takashi Iwai4151ee82017-01-31 18:14:15 +0100388 buf_cfg.buf_cfg_regx.audio_fifo_watermark = FIFO_THRESHOLD;
389 buf_cfg.buf_cfg_regx.dma_fifo_watermark = DMA_FIFO_THRESHOLD;
390 buf_cfg.buf_cfg_regx.aud_delay = 0;
Takashi Iwai79dda752017-01-30 17:23:39 +0100391 had_write_register(intelhaddata, AUD_BUF_CONFIG, buf_cfg.buf_cfgval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530392
393 channels = substream->runtime->channels;
Takashi Iwai4151ee82017-01-31 18:14:15 +0100394 cfg_val.cfg_regx.num_ch = channels - 2;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530395 if (channels <= 2)
Takashi Iwai4151ee82017-01-31 18:14:15 +0100396 cfg_val.cfg_regx.layout = LAYOUT0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530397 else
Takashi Iwai4151ee82017-01-31 18:14:15 +0100398 cfg_val.cfg_regx.layout = LAYOUT1;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530399
Takashi Iwai4151ee82017-01-31 18:14:15 +0100400 cfg_val.cfg_regx.val_bit = 1;
Takashi Iwai79dda752017-01-30 17:23:39 +0100401 had_write_register(intelhaddata, AUD_CONFIG, cfg_val.cfg_regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530402 return 0;
403}
404
Jerome Anand5dab11d2017-01-25 04:27:52 +0530405/*
406 * Compute derived values in channel_allocations[].
407 */
408static void init_channel_allocations(void)
409{
410 int i, j;
411 struct cea_channel_speaker_allocation *p;
412
Jerome Anand5dab11d2017-01-25 04:27:52 +0530413 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
414 p = channel_allocations + i;
415 p->channels = 0;
416 p->spk_mask = 0;
417 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
418 if (p->speakers[j]) {
419 p->channels++;
420 p->spk_mask |= p->speakers[j];
421 }
422 }
423}
424
425/*
426 * The transformation takes two steps:
427 *
428 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
429 * spk_mask => (channel_allocations[]) => ai->CA
430 *
431 * TODO: it could select the wrong CA from multiple candidates.
432 */
433static int snd_intelhad_channel_allocation(struct snd_intelhad *intelhaddata,
434 int channels)
435{
436 int i;
437 int ca = 0;
438 int spk_mask = 0;
439
440 /*
441 * CA defaults to 0 for basic stereo audio
442 */
443 if (channels <= 2)
444 return 0;
445
446 /*
447 * expand ELD's speaker allocation mask
448 *
449 * ELD tells the speaker mask in a compact(paired) form,
450 * expand ELD's notions to match the ones used by Audio InfoFrame.
451 */
452
453 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
Takashi Iwaida864802017-01-31 13:52:22 +0100454 if (intelhaddata->eld.speaker_allocation_block & (1 << i))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530455 spk_mask |= eld_speaker_allocation_bits[i];
456 }
457
458 /* search for the first working match in the CA table */
459 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
460 if (channels == channel_allocations[i].channels &&
461 (spk_mask & channel_allocations[i].spk_mask) ==
462 channel_allocations[i].spk_mask) {
463 ca = channel_allocations[i].ca_index;
464 break;
465 }
466 }
467
Takashi Iwaic75b0472017-01-31 15:49:15 +0100468 dev_dbg(intelhaddata->dev, "select CA 0x%x for %d\n", ca, channels);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530469
470 return ca;
471}
472
473/* from speaker bit mask to ALSA API channel position */
474static int spk_to_chmap(int spk)
475{
Takashi Iwai4a5ddb22017-02-01 16:45:38 +0100476 const struct channel_map_table *t = map_tables;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530477
478 for (; t->map; t++) {
479 if (t->spk_mask == spk)
480 return t->map;
481 }
482 return 0;
483}
484
Takashi Iwai372d8552017-01-31 13:57:58 +0100485static void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530486{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100487 int i, c;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530488 int spk_mask = 0;
489 struct snd_pcm_chmap_elem *chmap;
490 u8 eld_high, eld_high_mask = 0xF0;
491 u8 high_msb;
492
493 chmap = kzalloc(sizeof(*chmap), GFP_KERNEL);
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100494 if (!chmap) {
Jerome Anand5dab11d2017-01-25 04:27:52 +0530495 intelhaddata->chmap->chmap = NULL;
496 return;
497 }
498
Takashi Iwaic75b0472017-01-31 15:49:15 +0100499 dev_dbg(intelhaddata->dev, "eld.speaker_allocation_block = %x\n",
Takashi Iwaida864802017-01-31 13:52:22 +0100500 intelhaddata->eld.speaker_allocation_block);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530501
502 /* WA: Fix the max channel supported to 8 */
503
504 /*
505 * Sink may support more than 8 channels, if eld_high has more than
506 * one bit set. SOC supports max 8 channels.
507 * Refer eld_speaker_allocation_bits, for sink speaker allocation
508 */
509
510 /* if 0x2F < eld < 0x4F fall back to 0x2f, else fall back to 0x4F */
Takashi Iwaida864802017-01-31 13:52:22 +0100511 eld_high = intelhaddata->eld.speaker_allocation_block & eld_high_mask;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530512 if ((eld_high & (eld_high-1)) && (eld_high > 0x1F)) {
513 /* eld_high & (eld_high-1): if more than 1 bit set */
514 /* 0x1F: 7 channels */
515 for (i = 1; i < 4; i++) {
516 high_msb = eld_high & (0x80 >> i);
517 if (high_msb) {
Takashi Iwaida864802017-01-31 13:52:22 +0100518 intelhaddata->eld.speaker_allocation_block &=
Jerome Anand5dab11d2017-01-25 04:27:52 +0530519 high_msb | 0xF;
520 break;
521 }
522 }
523 }
524
525 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
Takashi Iwaida864802017-01-31 13:52:22 +0100526 if (intelhaddata->eld.speaker_allocation_block & (1 << i))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530527 spk_mask |= eld_speaker_allocation_bits[i];
528 }
529
530 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
531 if (spk_mask == channel_allocations[i].spk_mask) {
532 for (c = 0; c < channel_allocations[i].channels; c++) {
533 chmap->map[c] = spk_to_chmap(
534 channel_allocations[i].speakers[
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100535 (MAX_SPEAKERS - 1) - c]);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530536 }
537 chmap->channels = channel_allocations[i].channels;
538 intelhaddata->chmap->chmap = chmap;
539 break;
540 }
541 }
542 if (i >= ARRAY_SIZE(channel_allocations)) {
543 intelhaddata->chmap->chmap = NULL;
544 kfree(chmap);
545 }
546}
547
548/*
549 * ALSA API channel-map control callbacks
550 */
551static int had_chmap_ctl_info(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_info *uinfo)
553{
554 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
555 struct snd_intelhad *intelhaddata = info->private_data;
556
557 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
558 return -ENODEV;
559 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
560 uinfo->count = HAD_MAX_CHANNEL;
561 uinfo->value.integer.min = 0;
562 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
563 return 0;
564}
565
566static int had_chmap_ctl_get(struct snd_kcontrol *kcontrol,
567 struct snd_ctl_elem_value *ucontrol)
568{
569 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
570 struct snd_intelhad *intelhaddata = info->private_data;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100571 int i;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530572 const struct snd_pcm_chmap_elem *chmap;
573
574 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
575 return -ENODEV;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100576
577 mutex_lock(&intelhaddata->mutex);
578 if (!intelhaddata->chmap->chmap) {
579 mutex_unlock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530580 return -ENODATA;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100581 }
582
Jerome Anand5dab11d2017-01-25 04:27:52 +0530583 chmap = intelhaddata->chmap->chmap;
Takashi Iwaic75b0472017-01-31 15:49:15 +0100584 for (i = 0; i < chmap->channels; i++)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530585 ucontrol->value.integer.value[i] = chmap->map[i];
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100586 mutex_unlock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530587
588 return 0;
589}
590
591static int had_register_chmap_ctls(struct snd_intelhad *intelhaddata,
592 struct snd_pcm *pcm)
593{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100594 int err;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530595
596 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
597 NULL, 0, (unsigned long)intelhaddata,
598 &intelhaddata->chmap);
599 if (err < 0)
600 return err;
601
602 intelhaddata->chmap->private_data = intelhaddata;
Takashi Iwaie9d65ab2017-01-31 16:11:27 +0100603 intelhaddata->chmap->kctl->info = had_chmap_ctl_info;
604 intelhaddata->chmap->kctl->get = had_chmap_ctl_get;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530605 intelhaddata->chmap->chmap = NULL;
606 return 0;
607}
608
Takashi Iwai76296ef2017-01-30 16:09:11 +0100609/*
610 * snd_intelhad_prog_dip - to initialize Data Island Packets registers
Jerome Anand5dab11d2017-01-25 04:27:52 +0530611 *
612 * @substream:substream for which the prepare function is called
613 * @intelhaddata:substream private data
614 *
615 * This function is called in the prepare callback
616 */
Takashi Iwai76296ef2017-01-30 16:09:11 +0100617static void snd_intelhad_prog_dip(struct snd_pcm_substream *substream,
618 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530619{
620 int i;
621 union aud_ctrl_st ctrl_state = {.ctrl_val = 0};
622 union aud_info_frame2 frame2 = {.fr2_val = 0};
623 union aud_info_frame3 frame3 = {.fr3_val = 0};
624 u8 checksum = 0;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600625 u32 info_frame;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530626 int channels;
627
628 channels = substream->runtime->channels;
629
Takashi Iwai79dda752017-01-30 17:23:39 +0100630 had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.ctrl_val);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530631
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600632 if (intelhaddata->dp_output) {
633 info_frame = DP_INFO_FRAME_WORD1;
634 frame2.fr2_val = 1;
635 } else {
636 info_frame = HDMI_INFO_FRAME_WORD1;
637 frame2.fr2_regx.chnl_cnt = substream->runtime->channels - 1;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530638
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600639 frame3.fr3_regx.chnl_alloc = snd_intelhad_channel_allocation(
640 intelhaddata, channels);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530641
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100642 /* Calculte the byte wide checksum for all valid DIP words */
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600643 for (i = 0; i < BYTES_PER_WORD; i++)
644 checksum += (info_frame >> i*BITS_PER_BYTE) & MASK_BYTE0;
645 for (i = 0; i < BYTES_PER_WORD; i++)
646 checksum += (frame2.fr2_val >> i*BITS_PER_BYTE) & MASK_BYTE0;
647 for (i = 0; i < BYTES_PER_WORD; i++)
648 checksum += (frame3.fr3_val >> i*BITS_PER_BYTE) & MASK_BYTE0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530649
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600650 frame2.fr2_regx.chksum = -(checksum);
651 }
Jerome Anand5dab11d2017-01-25 04:27:52 +0530652
Takashi Iwai4151ee82017-01-31 18:14:15 +0100653 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, info_frame);
654 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame2.fr2_val);
655 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame3.fr3_val);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530656
657 /* program remaining DIP words with zero */
658 for (i = 0; i < HAD_MAX_DIP_WORDS-VALID_DIP_WORDS; i++)
Takashi Iwai4151ee82017-01-31 18:14:15 +0100659 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, 0x0);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530660
661 ctrl_state.ctrl_regx.dip_freq = 1;
662 ctrl_state.ctrl_regx.dip_en_sta = 1;
Takashi Iwai79dda752017-01-30 17:23:39 +0100663 had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.ctrl_val);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530664}
665
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100666/*
667 * snd_intelhad_prog_buffer - programs buffer address and length registers
Takashi Iwai313d9f22017-02-02 13:00:12 +0100668 * @substream: substream for which the prepare function is called
669 * @intelhaddata: substream private data
Jerome Anand5dab11d2017-01-25 04:27:52 +0530670 *
671 * This function programs ring buffer address and length into registers.
672 */
Takashi Iwai313d9f22017-02-02 13:00:12 +0100673static int snd_intelhad_prog_buffer(struct snd_pcm_substream *substream,
674 struct snd_intelhad *intelhaddata,
675 int start, int end)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530676{
677 u32 ring_buf_addr, ring_buf_size, period_bytes;
678 u8 i, num_periods;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530679
680 ring_buf_addr = substream->runtime->dma_addr;
681 ring_buf_size = snd_pcm_lib_buffer_bytes(substream);
682 intelhaddata->stream_info.ring_buf_size = ring_buf_size;
683 period_bytes = frames_to_bytes(substream->runtime,
684 substream->runtime->period_size);
685 num_periods = substream->runtime->periods;
686
687 /*
688 * buffer addr should be 64 byte aligned, period bytes
689 * will be used to calculate addr offset
690 */
691 period_bytes &= ~0x3F;
692
693 /* Hardware supports MAX_PERIODS buffers */
694 if (end >= HAD_MAX_PERIODS)
695 return -EINVAL;
696
697 for (i = start; i <= end; i++) {
698 /* Program the buf registers with addr and len */
699 intelhaddata->buf_info[i].buf_addr = ring_buf_addr +
700 (i * period_bytes);
701 if (i < num_periods-1)
702 intelhaddata->buf_info[i].buf_size = period_bytes;
703 else
704 intelhaddata->buf_info[i].buf_size = ring_buf_size -
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100705 (i * period_bytes);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530706
Takashi Iwai79dda752017-01-30 17:23:39 +0100707 had_write_register(intelhaddata,
708 AUD_BUF_A_ADDR + (i * HAD_REG_WIDTH),
Jerome Anand5dab11d2017-01-25 04:27:52 +0530709 intelhaddata->buf_info[i].buf_addr |
710 BIT(0) | BIT(1));
Takashi Iwai79dda752017-01-30 17:23:39 +0100711 had_write_register(intelhaddata,
712 AUD_BUF_A_LENGTH + (i * HAD_REG_WIDTH),
Jerome Anand5dab11d2017-01-25 04:27:52 +0530713 period_bytes);
714 intelhaddata->buf_info[i].is_valid = true;
715 }
Takashi Iwaic75b0472017-01-31 15:49:15 +0100716 dev_dbg(intelhaddata->dev, "%s:buf[%d-%d] addr=%#x and size=%d\n",
717 __func__, start, end,
718 intelhaddata->buf_info[start].buf_addr,
719 intelhaddata->buf_info[start].buf_size);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530720 intelhaddata->valid_buf_cnt = num_periods;
721 return 0;
722}
723
Takashi Iwai372d8552017-01-31 13:57:58 +0100724static int snd_intelhad_read_len(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530725{
726 int i, retval = 0;
727 u32 len[4];
728
729 for (i = 0; i < 4 ; i++) {
Takashi Iwai79dda752017-01-30 17:23:39 +0100730 had_read_register(intelhaddata,
731 AUD_BUF_A_LENGTH + (i * HAD_REG_WIDTH),
732 &len[i]);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530733 if (!len[i])
734 retval++;
735 }
736 if (retval != 1) {
737 for (i = 0; i < 4 ; i++)
Takashi Iwaic75b0472017-01-31 15:49:15 +0100738 dev_dbg(intelhaddata->dev, "buf[%d] size=%d\n",
739 i, len[i]);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530740 }
741
742 return retval;
743}
744
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600745static int had_calculate_maud_value(u32 aud_samp_freq, u32 link_rate)
746{
747 u32 maud_val;
748
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100749 /* Select maud according to DP 1.2 spec */
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600750 if (link_rate == DP_2_7_GHZ) {
751 switch (aud_samp_freq) {
752 case AUD_SAMPLE_RATE_32:
753 maud_val = AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL;
754 break;
755
756 case AUD_SAMPLE_RATE_44_1:
757 maud_val = AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL;
758 break;
759
760 case AUD_SAMPLE_RATE_48:
761 maud_val = AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL;
762 break;
763
764 case AUD_SAMPLE_RATE_88_2:
765 maud_val = AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL;
766 break;
767
768 case AUD_SAMPLE_RATE_96:
769 maud_val = AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL;
770 break;
771
772 case AUD_SAMPLE_RATE_176_4:
773 maud_val = AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL;
774 break;
775
776 case HAD_MAX_RATE:
777 maud_val = HAD_MAX_RATE_DP_2_7_MAUD_VAL;
778 break;
779
780 default:
781 maud_val = -EINVAL;
782 break;
783 }
784 } else if (link_rate == DP_1_62_GHZ) {
785 switch (aud_samp_freq) {
786 case AUD_SAMPLE_RATE_32:
787 maud_val = AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL;
788 break;
789
790 case AUD_SAMPLE_RATE_44_1:
791 maud_val = AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL;
792 break;
793
794 case AUD_SAMPLE_RATE_48:
795 maud_val = AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL;
796 break;
797
798 case AUD_SAMPLE_RATE_88_2:
799 maud_val = AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL;
800 break;
801
802 case AUD_SAMPLE_RATE_96:
803 maud_val = AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL;
804 break;
805
806 case AUD_SAMPLE_RATE_176_4:
807 maud_val = AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL;
808 break;
809
810 case HAD_MAX_RATE:
811 maud_val = HAD_MAX_RATE_DP_1_62_MAUD_VAL;
812 break;
813
814 default:
815 maud_val = -EINVAL;
816 break;
817 }
818 } else
819 maud_val = -EINVAL;
820
821 return maud_val;
822}
823
Takashi Iwai76296ef2017-01-30 16:09:11 +0100824/*
825 * snd_intelhad_prog_cts - Program HDMI audio CTS value
Jerome Anand5dab11d2017-01-25 04:27:52 +0530826 *
827 * @aud_samp_freq: sampling frequency of audio data
828 * @tmds: sampling frequency of the display data
829 * @n_param: N value, depends on aud_samp_freq
830 * @intelhaddata:substream private data
831 *
832 * Program CTS register based on the audio and display sampling frequency
833 */
Takashi Iwai76296ef2017-01-30 16:09:11 +0100834static void snd_intelhad_prog_cts(u32 aud_samp_freq, u32 tmds,
835 u32 link_rate, u32 n_param,
836 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530837{
838 u32 cts_val;
839 u64 dividend, divisor;
840
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600841 if (intelhaddata->dp_output) {
842 /* Substitute cts_val with Maud according to DP 1.2 spec*/
843 cts_val = had_calculate_maud_value(aud_samp_freq, link_rate);
844 } else {
845 /* Calculate CTS according to HDMI 1.3a spec*/
846 dividend = (u64)tmds * n_param*1000;
847 divisor = 128 * aud_samp_freq;
848 cts_val = div64_u64(dividend, divisor);
849 }
Takashi Iwaic75b0472017-01-31 15:49:15 +0100850 dev_dbg(intelhaddata->dev, "TMDS value=%d, N value=%d, CTS Value=%d\n",
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600851 tmds, n_param, cts_val);
Takashi Iwai79dda752017-01-30 17:23:39 +0100852 had_write_register(intelhaddata, AUD_HDMI_CTS, (BIT(24) | cts_val));
Jerome Anand5dab11d2017-01-25 04:27:52 +0530853}
854
855static int had_calculate_n_value(u32 aud_samp_freq)
856{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100857 int n_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530858
859 /* Select N according to HDMI 1.3a spec*/
860 switch (aud_samp_freq) {
861 case AUD_SAMPLE_RATE_32:
862 n_val = 4096;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100863 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530864
865 case AUD_SAMPLE_RATE_44_1:
866 n_val = 6272;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100867 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530868
869 case AUD_SAMPLE_RATE_48:
870 n_val = 6144;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100871 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530872
873 case AUD_SAMPLE_RATE_88_2:
874 n_val = 12544;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100875 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530876
877 case AUD_SAMPLE_RATE_96:
878 n_val = 12288;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100879 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530880
881 case AUD_SAMPLE_RATE_176_4:
882 n_val = 25088;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100883 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530884
885 case HAD_MAX_RATE:
886 n_val = 24576;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100887 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530888
889 default:
890 n_val = -EINVAL;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100891 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530892 }
893 return n_val;
894}
895
Takashi Iwai76296ef2017-01-30 16:09:11 +0100896/*
897 * snd_intelhad_prog_n - Program HDMI audio N value
Jerome Anand5dab11d2017-01-25 04:27:52 +0530898 *
899 * @aud_samp_freq: sampling frequency of audio data
900 * @n_param: N value, depends on aud_samp_freq
901 * @intelhaddata:substream private data
902 *
903 * This function is called in the prepare callback.
904 * It programs based on the audio and display sampling frequency
905 */
Takashi Iwai76296ef2017-01-30 16:09:11 +0100906static int snd_intelhad_prog_n(u32 aud_samp_freq, u32 *n_param,
907 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530908{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100909 int n_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530910
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600911 if (intelhaddata->dp_output) {
912 /*
913 * According to DP specs, Maud and Naud values hold
914 * a relationship, which is stated as:
915 * Maud/Naud = 512 * fs / f_LS_Clk
916 * where, fs is the sampling frequency of the audio stream
917 * and Naud is 32768 for Async clock.
918 */
919
920 n_val = DP_NAUD_VAL;
921 } else
922 n_val = had_calculate_n_value(aud_samp_freq);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530923
924 if (n_val < 0)
925 return n_val;
926
Takashi Iwai79dda752017-01-30 17:23:39 +0100927 had_write_register(intelhaddata, AUD_N_ENABLE, (BIT(24) | n_val));
Jerome Anand5dab11d2017-01-25 04:27:52 +0530928 *n_param = n_val;
929 return 0;
930}
931
Takashi Iwai372d8552017-01-31 13:57:58 +0100932static void snd_intelhad_handle_underrun(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530933{
Takashi Iwai79f439e2017-01-31 16:46:44 +0100934 u32 hdmi_status = 0, i = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530935
936 /* Handle Underrun interrupt within Audio Unit */
Takashi Iwai79dda752017-01-30 17:23:39 +0100937 had_write_register(intelhaddata, AUD_CONFIG, 0);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530938 /* Reset buffer pointers */
Takashi Iwai4151ee82017-01-31 18:14:15 +0100939 had_write_register(intelhaddata, AUD_HDMI_STATUS, 1);
940 had_write_register(intelhaddata, AUD_HDMI_STATUS, 0);
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100941 /*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530942 * The interrupt status 'sticky' bits might not be cleared by
943 * setting '1' to that bit once...
944 */
945 do { /* clear bit30, 31 AUD_HDMI_STATUS */
Takashi Iwai4151ee82017-01-31 18:14:15 +0100946 had_read_register(intelhaddata, AUD_HDMI_STATUS,
Takashi Iwai79dda752017-01-30 17:23:39 +0100947 &hdmi_status);
Takashi Iwaic75b0472017-01-31 15:49:15 +0100948 dev_dbg(intelhaddata->dev, "HDMI status =0x%x\n", hdmi_status);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530949 if (hdmi_status & AUD_CONFIG_MASK_UNDERRUN) {
950 i++;
Takashi Iwai79dda752017-01-30 17:23:39 +0100951 had_write_register(intelhaddata,
Takashi Iwai4151ee82017-01-31 18:14:15 +0100952 AUD_HDMI_STATUS, hdmi_status);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530953 } else
954 break;
955 } while (i < MAX_CNT);
956 if (i >= MAX_CNT)
Takashi Iwaic75b0472017-01-31 15:49:15 +0100957 dev_err(intelhaddata->dev, "Unable to clear UNDERRUN bits\n");
Jerome Anand5dab11d2017-01-25 04:27:52 +0530958}
959
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100960/*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530961 * snd_intelhad_open - stream initializations are done here
962 * @substream:substream for which the stream function is called
963 *
964 * This function is called whenever a PCM stream is opened
965 */
966static int snd_intelhad_open(struct snd_pcm_substream *substream)
967{
968 struct snd_intelhad *intelhaddata;
969 struct snd_pcm_runtime *runtime;
Takashi Iwai5647aec2017-01-31 08:14:34 +0100970 struct had_stream_data *had_stream;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530971 int retval;
972
Jerome Anand5dab11d2017-01-25 04:27:52 +0530973 intelhaddata = snd_pcm_substream_chip(substream);
Takashi Iwai5647aec2017-01-31 08:14:34 +0100974 had_stream = &intelhaddata->stream_data;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530975 runtime = substream->runtime;
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +0100976 intelhaddata->underrun_count = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530977
Takashi Iwai182cdf22017-02-02 14:43:39 +0100978 pm_runtime_get_sync(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530979
Takashi Iwai79f439e2017-01-31 16:46:44 +0100980 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
Takashi Iwaic75b0472017-01-31 15:49:15 +0100981 dev_dbg(intelhaddata->dev, "%s: HDMI cable plugged-out\n",
982 __func__);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530983 retval = -ENODEV;
Takashi Iwaifa5dfe62017-02-01 22:03:26 +0100984 goto error;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530985 }
986
987 /* set the runtime hw parameter with local snd_pcm_hardware struct */
988 runtime->hw = snd_intel_hadstream;
989
Jerome Anand5dab11d2017-01-25 04:27:52 +0530990 retval = snd_pcm_hw_constraint_integer(runtime,
991 SNDRV_PCM_HW_PARAM_PERIODS);
992 if (retval < 0)
Takashi Iwaifa5dfe62017-02-01 22:03:26 +0100993 goto error;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530994
995 /* Make sure, that the period size is always aligned
996 * 64byte boundary
997 */
998 retval = snd_pcm_hw_constraint_step(substream->runtime, 0,
999 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64);
1000 if (retval < 0) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001001 dev_dbg(intelhaddata->dev, "%s:step_size=64 failed,err=%d\n",
1002 __func__, retval);
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001003 goto error;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301004 }
1005
Takashi Iwai313d9f22017-02-02 13:00:12 +01001006 spin_lock_irq(&intelhaddata->had_spinlock);
1007 intelhaddata->stream_info.substream = substream;
1008 intelhaddata->stream_info.substream_refcount++;
1009 spin_unlock_irq(&intelhaddata->had_spinlock);
1010
Jerome Anand5dab11d2017-01-25 04:27:52 +05301011 return retval;
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001012 error:
Jerome Anand5dab11d2017-01-25 04:27:52 +05301013 pm_runtime_put(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301014 return retval;
1015}
1016
Takashi Iwaidf76df12017-01-31 16:04:10 +01001017/*
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001018 * snd_intelhad_close - to free parameteres when stream is stopped
Jerome Anand5dab11d2017-01-25 04:27:52 +05301019 * @substream: substream for which the function is called
1020 *
1021 * This function is called by ALSA framework when stream is stopped
1022 */
1023static int snd_intelhad_close(struct snd_pcm_substream *substream)
1024{
1025 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301026
Jerome Anand5dab11d2017-01-25 04:27:52 +05301027 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301028
1029 intelhaddata->stream_info.buffer_rendered = 0;
Takashi Iwai313d9f22017-02-02 13:00:12 +01001030 spin_lock_irq(&intelhaddata->had_spinlock);
1031 intelhaddata->stream_info.substream = NULL;
1032 intelhaddata->stream_info.substream_refcount--;
1033 while (intelhaddata->stream_info.substream_refcount > 0) {
1034 spin_unlock_irq(&intelhaddata->had_spinlock);
1035 cpu_relax();
1036 spin_lock_irq(&intelhaddata->had_spinlock);
1037 }
1038 spin_unlock_irq(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301039
1040 /* Check if following drv_status modification is required - VA */
1041 if (intelhaddata->drv_status != HAD_DRV_DISCONNECTED) {
1042 intelhaddata->drv_status = HAD_DRV_CONNECTED;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001043 dev_dbg(intelhaddata->dev,
1044 "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n",
Jerome Anand5dab11d2017-01-25 04:27:52 +05301045 __func__, __LINE__);
1046 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301047 pm_runtime_put(intelhaddata->dev);
1048 return 0;
1049}
1050
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001051/*
1052 * snd_intelhad_hw_params - to setup the hardware parameters
1053 * like allocating the buffers
1054 * @substream: substream for which the function is called
Jerome Anand5dab11d2017-01-25 04:27:52 +05301055 * @hw_params: hardware parameters
1056 *
1057 * This function is called by ALSA framework when hardware params are set
1058 */
1059static int snd_intelhad_hw_params(struct snd_pcm_substream *substream,
1060 struct snd_pcm_hw_params *hw_params)
1061{
Takashi Iwaic75b0472017-01-31 15:49:15 +01001062 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301063 unsigned long addr;
1064 int pages, buf_size, retval;
1065
Jerome Anand5dab11d2017-01-25 04:27:52 +05301066 if (!hw_params)
1067 return -EINVAL;
1068
Takashi Iwaic75b0472017-01-31 15:49:15 +01001069 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301070 buf_size = params_buffer_bytes(hw_params);
1071 retval = snd_pcm_lib_malloc_pages(substream, buf_size);
1072 if (retval < 0)
1073 return retval;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001074 dev_dbg(intelhaddata->dev, "%s:allocated memory = %d\n",
1075 __func__, buf_size);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301076 /* mark the pages as uncached region */
1077 addr = (unsigned long) substream->runtime->dma_area;
1078 pages = (substream->runtime->dma_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
1079 retval = set_memory_uc(addr, pages);
1080 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001081 dev_err(intelhaddata->dev, "set_memory_uc failed.Error:%d\n",
1082 retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301083 return retval;
1084 }
1085 memset(substream->runtime->dma_area, 0, buf_size);
1086
1087 return retval;
1088}
1089
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001090/*
1091 * snd_intelhad_hw_free - to release the resources allocated during
1092 * hardware params setup
Jerome Anand5dab11d2017-01-25 04:27:52 +05301093 * @substream: substream for which the function is called
1094 *
1095 * This function is called by ALSA framework before close callback.
Jerome Anand5dab11d2017-01-25 04:27:52 +05301096 */
1097static int snd_intelhad_hw_free(struct snd_pcm_substream *substream)
1098{
1099 unsigned long addr;
1100 u32 pages;
1101
Jerome Anand5dab11d2017-01-25 04:27:52 +05301102 /* mark back the pages as cached/writeback region before the free */
1103 if (substream->runtime->dma_area != NULL) {
1104 addr = (unsigned long) substream->runtime->dma_area;
1105 pages = (substream->runtime->dma_bytes + PAGE_SIZE - 1) /
1106 PAGE_SIZE;
1107 set_memory_wb(addr, pages);
1108 return snd_pcm_lib_free_pages(substream);
1109 }
1110 return 0;
1111}
1112
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001113/*
Jerome Anand5dab11d2017-01-25 04:27:52 +05301114 * snd_intelhad_pcm_trigger - stream activities are handled here
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001115 * @substream: substream for which the stream function is called
1116 * @cmd: the stream commamd thats requested from upper layer
1117 *
Jerome Anand5dab11d2017-01-25 04:27:52 +05301118 * This function is called whenever an a stream activity is invoked
1119 */
1120static int snd_intelhad_pcm_trigger(struct snd_pcm_substream *substream,
1121 int cmd)
1122{
Takashi Iwaida864802017-01-31 13:52:22 +01001123 int retval = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301124 struct snd_intelhad *intelhaddata;
Takashi Iwai5647aec2017-01-31 08:14:34 +01001125 struct had_stream_data *had_stream;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301126
Jerome Anand5dab11d2017-01-25 04:27:52 +05301127 intelhaddata = snd_pcm_substream_chip(substream);
Takashi Iwai5647aec2017-01-31 08:14:34 +01001128 had_stream = &intelhaddata->stream_data;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301129
1130 switch (cmd) {
1131 case SNDRV_PCM_TRIGGER_START:
Takashi Iwai182cdf22017-02-02 14:43:39 +01001132 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1133 case SNDRV_PCM_TRIGGER_RESUME:
Jerome Anand5dab11d2017-01-25 04:27:52 +05301134 /* Disable local INTRs till register prgmng is done */
Takashi Iwai79f439e2017-01-31 16:46:44 +01001135 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001136 dev_dbg(intelhaddata->dev,
1137 "_START: HDMI cable plugged-out\n");
Jerome Anand5dab11d2017-01-25 04:27:52 +05301138 retval = -ENODEV;
1139 break;
1140 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301141
1142 had_stream->stream_type = HAD_RUNNING_STREAM;
1143
1144 /* Enable Audio */
Takashi Iwaida864802017-01-31 13:52:22 +01001145 snd_intelhad_enable_audio_int(intelhaddata, true);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001146 snd_intelhad_enable_audio(substream, intelhaddata, true);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301147 break;
1148
1149 case SNDRV_PCM_TRIGGER_STOP:
Takashi Iwai182cdf22017-02-02 14:43:39 +01001150 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1151 case SNDRV_PCM_TRIGGER_SUSPEND:
Takashi Iwaibcce7752017-02-01 17:18:20 +01001152 spin_lock(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301153 intelhaddata->curr_buf = 0;
1154
Takashi Iwaic75b0472017-01-31 15:49:15 +01001155 /* Stop reporting BUFFER_DONE/UNDERRUN to above layers */
Jerome Anand5dab11d2017-01-25 04:27:52 +05301156
1157 had_stream->stream_type = HAD_INIT;
Takashi Iwaibcce7752017-02-01 17:18:20 +01001158 spin_unlock(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301159 /* Disable Audio */
Takashi Iwaida864802017-01-31 13:52:22 +01001160 snd_intelhad_enable_audio_int(intelhaddata, false);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001161 snd_intelhad_enable_audio(substream, intelhaddata, false);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301162 /* Reset buffer pointers */
Takashi Iwai79dda752017-01-30 17:23:39 +01001163 snd_intelhad_reset_audio(intelhaddata, 1);
1164 snd_intelhad_reset_audio(intelhaddata, 0);
Takashi Iwaida864802017-01-31 13:52:22 +01001165 snd_intelhad_enable_audio_int(intelhaddata, false);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301166 break;
1167
1168 default:
1169 retval = -EINVAL;
1170 }
1171 return retval;
1172}
1173
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001174/*
1175 * snd_intelhad_pcm_prepare - internal preparation before starting a stream
1176 * @substream: substream for which the function is called
Jerome Anand5dab11d2017-01-25 04:27:52 +05301177 *
1178 * This function is called when a stream is started for internal preparation.
1179 */
1180static int snd_intelhad_pcm_prepare(struct snd_pcm_substream *substream)
1181{
1182 int retval;
1183 u32 disp_samp_freq, n_param;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001184 u32 link_rate = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301185 struct snd_intelhad *intelhaddata;
1186 struct snd_pcm_runtime *runtime;
Takashi Iwai5647aec2017-01-31 08:14:34 +01001187 struct had_stream_data *had_stream;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301188
Jerome Anand5dab11d2017-01-25 04:27:52 +05301189 intelhaddata = snd_pcm_substream_chip(substream);
1190 runtime = substream->runtime;
Takashi Iwai5647aec2017-01-31 08:14:34 +01001191 had_stream = &intelhaddata->stream_data;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301192
Takashi Iwai79f439e2017-01-31 16:46:44 +01001193 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001194 dev_dbg(intelhaddata->dev, "%s: HDMI cable plugged-out\n",
1195 __func__);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301196 retval = -ENODEV;
1197 goto prep_end;
1198 }
1199
Takashi Iwaic75b0472017-01-31 15:49:15 +01001200 dev_dbg(intelhaddata->dev, "period_size=%d\n",
Jerome Anand5dab11d2017-01-25 04:27:52 +05301201 (int)frames_to_bytes(runtime, runtime->period_size));
Takashi Iwaic75b0472017-01-31 15:49:15 +01001202 dev_dbg(intelhaddata->dev, "periods=%d\n", runtime->periods);
1203 dev_dbg(intelhaddata->dev, "buffer_size=%d\n",
1204 (int)snd_pcm_lib_buffer_bytes(substream));
1205 dev_dbg(intelhaddata->dev, "rate=%d\n", runtime->rate);
1206 dev_dbg(intelhaddata->dev, "channels=%d\n", runtime->channels);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301207
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001208 intelhaddata->stream_info.buffer_rendered = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301209
1210 /* Get N value in KHz */
Takashi Iwaida864802017-01-31 13:52:22 +01001211 disp_samp_freq = intelhaddata->tmds_clock_speed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301212
Takashi Iwai76296ef2017-01-30 16:09:11 +01001213 retval = snd_intelhad_prog_n(substream->runtime->rate, &n_param,
1214 intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301215 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001216 dev_err(intelhaddata->dev,
1217 "programming N value failed %#x\n", retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301218 goto prep_end;
1219 }
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001220
1221 if (intelhaddata->dp_output)
Takashi Iwaida864802017-01-31 13:52:22 +01001222 link_rate = intelhaddata->link_rate;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001223
Takashi Iwai76296ef2017-01-30 16:09:11 +01001224 snd_intelhad_prog_cts(substream->runtime->rate,
1225 disp_samp_freq, link_rate,
1226 n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301227
Takashi Iwai76296ef2017-01-30 16:09:11 +01001228 snd_intelhad_prog_dip(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301229
Takashi Iwai76296ef2017-01-30 16:09:11 +01001230 retval = snd_intelhad_audio_ctrl(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301231
1232 /* Prog buffer address */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001233 retval = snd_intelhad_prog_buffer(substream, intelhaddata,
Jerome Anand5dab11d2017-01-25 04:27:52 +05301234 HAD_BUF_TYPE_A, HAD_BUF_TYPE_D);
1235
1236 /*
1237 * Program channel mapping in following order:
1238 * FL, FR, C, LFE, RL, RR
1239 */
1240
Takashi Iwai79dda752017-01-30 17:23:39 +01001241 had_write_register(intelhaddata, AUD_BUF_CH_SWAP, SWAP_LFE_CENTER);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301242
1243prep_end:
1244 return retval;
1245}
1246
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001247/*
Jerome Anand5dab11d2017-01-25 04:27:52 +05301248 * snd_intelhad_pcm_pointer- to send the current buffer pointerprocessed by hw
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001249 * @substream: substream for which the function is called
Jerome Anand5dab11d2017-01-25 04:27:52 +05301250 *
1251 * This function is called by ALSA framework to get the current hw buffer ptr
1252 * when a period is elapsed
1253 */
1254static snd_pcm_uframes_t snd_intelhad_pcm_pointer(
1255 struct snd_pcm_substream *substream)
1256{
1257 struct snd_intelhad *intelhaddata;
1258 u32 bytes_rendered = 0;
1259 u32 t;
1260 int buf_id;
1261
Jerome Anand5dab11d2017-01-25 04:27:52 +05301262 intelhaddata = snd_pcm_substream_chip(substream);
1263
Takashi Iwai79f439e2017-01-31 16:46:44 +01001264 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED)
1265 return SNDRV_PCM_POS_XRUN;
1266
Jerome Anand5dab11d2017-01-25 04:27:52 +05301267 /* Use a hw register to calculate sub-period position reports.
1268 * This makes PulseAudio happier.
1269 */
1270
1271 buf_id = intelhaddata->curr_buf % 4;
Takashi Iwai79dda752017-01-30 17:23:39 +01001272 had_read_register(intelhaddata,
1273 AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH), &t);
Jerome Anand232892f2017-01-25 04:27:53 +05301274
1275 if ((t == 0) || (t == ((u32)-1L))) {
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +01001276 intelhaddata->underrun_count++;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001277 dev_dbg(intelhaddata->dev,
1278 "discovered buffer done for buf %d, count = %d\n",
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +01001279 buf_id, intelhaddata->underrun_count);
Jerome Anand232892f2017-01-25 04:27:53 +05301280
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +01001281 if (intelhaddata->underrun_count > (HAD_MIN_PERIODS/2)) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001282 dev_dbg(intelhaddata->dev,
1283 "assume audio_codec_reset, underrun = %d - do xrun\n",
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +01001284 intelhaddata->underrun_count);
1285 intelhaddata->underrun_count = 0;
Jerome Anand232892f2017-01-25 04:27:53 +05301286 return SNDRV_PCM_POS_XRUN;
1287 }
1288 } else {
1289 /* Reset Counter */
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +01001290 intelhaddata->underrun_count = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301291 }
Jerome Anand232892f2017-01-25 04:27:53 +05301292
Jerome Anand5dab11d2017-01-25 04:27:52 +05301293 t = intelhaddata->buf_info[buf_id].buf_size - t;
1294
1295 if (intelhaddata->stream_info.buffer_rendered)
1296 div_u64_rem(intelhaddata->stream_info.buffer_rendered,
1297 intelhaddata->stream_info.ring_buf_size,
1298 &(bytes_rendered));
1299
Takashi Iwai7d9e7982017-02-01 22:25:58 +01001300 return bytes_to_frames(substream->runtime, bytes_rendered + t);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301301}
1302
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001303/*
Jerome Anand5dab11d2017-01-25 04:27:52 +05301304 * snd_intelhad_pcm_mmap- mmaps a kernel buffer to user space for copying data
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001305 * @substream: substream for which the function is called
1306 * @vma: struct instance of memory VMM memory area
Jerome Anand5dab11d2017-01-25 04:27:52 +05301307 *
1308 * This function is called by OS when a user space component
1309 * tries to get mmap memory from driver
1310 */
1311static int snd_intelhad_pcm_mmap(struct snd_pcm_substream *substream,
1312 struct vm_area_struct *vma)
1313{
Jerome Anand5dab11d2017-01-25 04:27:52 +05301314 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1315 return remap_pfn_range(vma, vma->vm_start,
1316 substream->dma_buffer.addr >> PAGE_SHIFT,
1317 vma->vm_end - vma->vm_start, vma->vm_page_prot);
1318}
1319
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001320/* process mode change of the running stream; called in mutex */
Takashi Iwaida864802017-01-31 13:52:22 +01001321static int hdmi_audio_mode_change(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301322{
Takashi Iwaida864802017-01-31 13:52:22 +01001323 struct snd_pcm_substream *substream;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301324 int retval = 0;
1325 u32 disp_samp_freq, n_param;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001326 u32 link_rate = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301327
Takashi Iwai313d9f22017-02-02 13:00:12 +01001328 substream = had_substream_get(intelhaddata);
1329 if (!substream)
Takashi Iwaida864802017-01-31 13:52:22 +01001330 return 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301331
1332 /* Disable Audio */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001333 snd_intelhad_enable_audio(substream, intelhaddata, false);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301334
1335 /* Update CTS value */
Takashi Iwaida864802017-01-31 13:52:22 +01001336 disp_samp_freq = intelhaddata->tmds_clock_speed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301337
Takashi Iwai76296ef2017-01-30 16:09:11 +01001338 retval = snd_intelhad_prog_n(substream->runtime->rate, &n_param,
1339 intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301340 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001341 dev_err(intelhaddata->dev,
1342 "programming N value failed %#x\n", retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301343 goto out;
1344 }
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001345
1346 if (intelhaddata->dp_output)
Takashi Iwaida864802017-01-31 13:52:22 +01001347 link_rate = intelhaddata->link_rate;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001348
Takashi Iwai76296ef2017-01-30 16:09:11 +01001349 snd_intelhad_prog_cts(substream->runtime->rate,
1350 disp_samp_freq, link_rate,
1351 n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301352
1353 /* Enable Audio */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001354 snd_intelhad_enable_audio(substream, intelhaddata, true);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301355
1356out:
Takashi Iwai313d9f22017-02-02 13:00:12 +01001357 had_substream_put(intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301358 return retval;
1359}
1360
Takashi Iwai372d8552017-01-31 13:57:58 +01001361static inline int had_chk_intrmiss(struct snd_intelhad *intelhaddata,
1362 enum intel_had_aud_buf_type buf_id)
1363{
1364 int i, intr_count = 0;
1365 enum intel_had_aud_buf_type buff_done;
1366 u32 buf_size, buf_addr;
1367 struct had_stream_data *had_stream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001368
1369 had_stream = &intelhaddata->stream_data;
1370
1371 buff_done = buf_id;
1372
1373 intr_count = snd_intelhad_read_len(intelhaddata);
1374 if (intr_count > 1) {
1375 /* In case of active playback */
Takashi Iwaic75b0472017-01-31 15:49:15 +01001376 dev_err(intelhaddata->dev,
1377 "Driver detected %d missed buffer done interrupt(s)\n",
1378 (intr_count - 1));
Takashi Iwai372d8552017-01-31 13:57:58 +01001379 if (intr_count > 3)
1380 return intr_count;
1381
1382 buf_id += (intr_count - 1);
1383 /* Reprogram registers*/
1384 for (i = buff_done; i < buf_id; i++) {
1385 int j = i % 4;
1386
1387 buf_size = intelhaddata->buf_info[j].buf_size;
1388 buf_addr = intelhaddata->buf_info[j].buf_addr;
1389 had_write_register(intelhaddata,
1390 AUD_BUF_A_LENGTH +
1391 (j * HAD_REG_WIDTH), buf_size);
1392 had_write_register(intelhaddata,
1393 AUD_BUF_A_ADDR+(j * HAD_REG_WIDTH),
1394 (buf_addr | BIT(0) | BIT(1)));
1395 }
1396 buf_id = buf_id % 4;
Takashi Iwai372d8552017-01-31 13:57:58 +01001397 intelhaddata->buff_done = buf_id;
Takashi Iwai372d8552017-01-31 13:57:58 +01001398 }
1399
1400 return intr_count;
1401}
1402
Takashi Iwaibcce7752017-02-01 17:18:20 +01001403/* called from irq handler */
Takashi Iwai372d8552017-01-31 13:57:58 +01001404static int had_process_buffer_done(struct snd_intelhad *intelhaddata)
1405{
1406 u32 len = 1;
1407 enum intel_had_aud_buf_type buf_id;
1408 enum intel_had_aud_buf_type buff_done;
1409 struct pcm_stream_info *stream;
Takashi Iwai313d9f22017-02-02 13:00:12 +01001410 struct snd_pcm_substream *substream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001411 u32 buf_size;
1412 struct had_stream_data *had_stream;
1413 int intr_count;
Takashi Iwaibcce7752017-02-01 17:18:20 +01001414 unsigned long flags;
Takashi Iwai372d8552017-01-31 13:57:58 +01001415
1416 had_stream = &intelhaddata->stream_data;
1417 stream = &intelhaddata->stream_info;
1418 intr_count = 1;
1419
Takashi Iwaibcce7752017-02-01 17:18:20 +01001420 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
Takashi Iwai372d8552017-01-31 13:57:58 +01001421 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
Takashi Iwaibcce7752017-02-01 17:18:20 +01001422 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
Takashi Iwaic75b0472017-01-31 15:49:15 +01001423 dev_dbg(intelhaddata->dev,
1424 "%s:Device already disconnected\n", __func__);
Takashi Iwai372d8552017-01-31 13:57:58 +01001425 return 0;
1426 }
1427 buf_id = intelhaddata->curr_buf;
1428 intelhaddata->buff_done = buf_id;
1429 buff_done = intelhaddata->buff_done;
1430 buf_size = intelhaddata->buf_info[buf_id].buf_size;
Takashi Iwai372d8552017-01-31 13:57:58 +01001431
Takashi Iwai372d8552017-01-31 13:57:58 +01001432 /* Every debug statement has an implication
1433 * of ~5msec. Thus, avoid having >3 debug statements
1434 * for each buffer_done handling.
1435 */
1436
1437 /* Check for any intr_miss in case of active playback */
1438 if (had_stream->stream_type == HAD_RUNNING_STREAM) {
Takashi Iwai372d8552017-01-31 13:57:58 +01001439 intr_count = had_chk_intrmiss(intelhaddata, buf_id);
1440 if (!intr_count || (intr_count > 3)) {
Takashi Iwaibcce7752017-02-01 17:18:20 +01001441 spin_unlock_irqrestore(&intelhaddata->had_spinlock,
1442 flags);
Takashi Iwaic75b0472017-01-31 15:49:15 +01001443 dev_err(intelhaddata->dev,
1444 "HAD SW state in non-recoverable mode\n");
Takashi Iwai372d8552017-01-31 13:57:58 +01001445 return 0;
1446 }
1447 buf_id += (intr_count - 1);
1448 buf_id = buf_id % 4;
Takashi Iwai372d8552017-01-31 13:57:58 +01001449 }
1450
1451 intelhaddata->buf_info[buf_id].is_valid = true;
1452 if (intelhaddata->valid_buf_cnt-1 == buf_id) {
1453 if (had_stream->stream_type >= HAD_RUNNING_STREAM)
1454 intelhaddata->curr_buf = HAD_BUF_TYPE_A;
1455 } else
1456 intelhaddata->curr_buf = buf_id + 1;
1457
Takashi Iwaibcce7752017-02-01 17:18:20 +01001458 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
Takashi Iwai372d8552017-01-31 13:57:58 +01001459
Takashi Iwai79f439e2017-01-31 16:46:44 +01001460 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001461 dev_dbg(intelhaddata->dev, "HDMI cable plugged-out\n");
Takashi Iwai372d8552017-01-31 13:57:58 +01001462 return 0;
1463 }
1464
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001465 /* Reprogram the registers with addr and length */
Takashi Iwai372d8552017-01-31 13:57:58 +01001466 had_write_register(intelhaddata,
1467 AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH),
1468 buf_size);
1469 had_write_register(intelhaddata,
1470 AUD_BUF_A_ADDR + (buf_id * HAD_REG_WIDTH),
1471 intelhaddata->buf_info[buf_id].buf_addr |
1472 BIT(0) | BIT(1));
1473
1474 had_read_register(intelhaddata,
1475 AUD_BUF_A_LENGTH + (buf_id * HAD_REG_WIDTH),
1476 &len);
Takashi Iwaic75b0472017-01-31 15:49:15 +01001477 dev_dbg(intelhaddata->dev, "%s:Enabled buf[%d]\n", __func__, buf_id);
Takashi Iwai372d8552017-01-31 13:57:58 +01001478
1479 /* In case of actual data,
1480 * report buffer_done to above ALSA layer
1481 */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001482 substream = had_substream_get(intelhaddata);
1483 if (substream) {
1484 buf_size = intelhaddata->buf_info[buf_id].buf_size;
Takashi Iwai372d8552017-01-31 13:57:58 +01001485 intelhaddata->stream_info.buffer_rendered +=
1486 (intr_count * buf_size);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001487 snd_pcm_period_elapsed(substream);
1488 had_substream_put(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001489 }
1490
1491 return 0;
1492}
1493
Takashi Iwaibcce7752017-02-01 17:18:20 +01001494/* called from irq handler */
Takashi Iwai372d8552017-01-31 13:57:58 +01001495static int had_process_buffer_underrun(struct snd_intelhad *intelhaddata)
1496{
1497 enum intel_had_aud_buf_type buf_id;
1498 struct pcm_stream_info *stream;
1499 struct had_stream_data *had_stream;
Takashi Iwai313d9f22017-02-02 13:00:12 +01001500 struct snd_pcm_substream *substream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001501 enum had_status_stream stream_type;
Takashi Iwaibcce7752017-02-01 17:18:20 +01001502 unsigned long flags;
Takashi Iwai372d8552017-01-31 13:57:58 +01001503 int drv_status;
1504
1505 had_stream = &intelhaddata->stream_data;
1506 stream = &intelhaddata->stream_info;
1507
Takashi Iwaibcce7752017-02-01 17:18:20 +01001508 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
Takashi Iwai372d8552017-01-31 13:57:58 +01001509 buf_id = intelhaddata->curr_buf;
1510 stream_type = had_stream->stream_type;
1511 intelhaddata->buff_done = buf_id;
1512 drv_status = intelhaddata->drv_status;
1513 if (stream_type == HAD_RUNNING_STREAM)
1514 intelhaddata->curr_buf = HAD_BUF_TYPE_A;
1515
Takashi Iwaibcce7752017-02-01 17:18:20 +01001516 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
Takashi Iwai372d8552017-01-31 13:57:58 +01001517
Takashi Iwaic75b0472017-01-31 15:49:15 +01001518 dev_dbg(intelhaddata->dev, "Enter:%s buf_id=%d, stream_type=%d\n",
Takashi Iwai372d8552017-01-31 13:57:58 +01001519 __func__, buf_id, stream_type);
1520
1521 snd_intelhad_handle_underrun(intelhaddata);
1522
1523 if (drv_status == HAD_DRV_DISCONNECTED) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001524 dev_dbg(intelhaddata->dev,
1525 "%s:Device already disconnected\n", __func__);
Takashi Iwai372d8552017-01-31 13:57:58 +01001526 return 0;
1527 }
1528
1529 if (stream_type == HAD_RUNNING_STREAM) {
1530 /* Report UNDERRUN error to above layers */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001531 substream = had_substream_get(intelhaddata);
1532 if (substream) {
1533 snd_pcm_stop_xrun(substream);
1534 had_substream_put(intelhaddata);
1535 }
Takashi Iwai372d8552017-01-31 13:57:58 +01001536 }
1537
1538 return 0;
1539}
1540
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001541/* process hot plug, called from wq with mutex locked */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001542static void had_process_hot_plug(struct snd_intelhad *intelhaddata)
Takashi Iwai372d8552017-01-31 13:57:58 +01001543{
1544 enum intel_had_aud_buf_type buf_id;
1545 struct snd_pcm_substream *substream;
1546 struct had_stream_data *had_stream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001547
Takashi Iwai372d8552017-01-31 13:57:58 +01001548 had_stream = &intelhaddata->stream_data;
1549
Takashi Iwaibcce7752017-02-01 17:18:20 +01001550 spin_lock_irq(&intelhaddata->had_spinlock);
Takashi Iwai372d8552017-01-31 13:57:58 +01001551 if (intelhaddata->drv_status == HAD_DRV_CONNECTED) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001552 dev_dbg(intelhaddata->dev, "Device already connected\n");
Takashi Iwaibcce7752017-02-01 17:18:20 +01001553 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001554 return;
Takashi Iwai372d8552017-01-31 13:57:58 +01001555 }
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001556
Takashi Iwai372d8552017-01-31 13:57:58 +01001557 buf_id = intelhaddata->curr_buf;
1558 intelhaddata->buff_done = buf_id;
1559 intelhaddata->drv_status = HAD_DRV_CONNECTED;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001560 dev_dbg(intelhaddata->dev,
1561 "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n",
Takashi Iwai372d8552017-01-31 13:57:58 +01001562 __func__, __LINE__);
Takashi Iwaibcce7752017-02-01 17:18:20 +01001563 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai372d8552017-01-31 13:57:58 +01001564
Takashi Iwaic75b0472017-01-31 15:49:15 +01001565 dev_dbg(intelhaddata->dev, "Processing HOT_PLUG, buf_id = %d\n",
1566 buf_id);
Takashi Iwai372d8552017-01-31 13:57:58 +01001567
1568 /* Safety check */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001569 substream = had_substream_get(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001570 if (substream) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001571 dev_dbg(intelhaddata->dev,
1572 "Force to stop the active stream by disconnection\n");
Takashi Iwai372d8552017-01-31 13:57:58 +01001573 /* Set runtime->state to hw_params done */
1574 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001575 had_substream_put(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001576 }
1577
1578 had_build_channel_allocation_map(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001579}
1580
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001581/* process hot unplug, called from wq with mutex locked */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001582static void had_process_hot_unplug(struct snd_intelhad *intelhaddata)
Takashi Iwai372d8552017-01-31 13:57:58 +01001583{
1584 enum intel_had_aud_buf_type buf_id;
1585 struct had_stream_data *had_stream;
Takashi Iwai313d9f22017-02-02 13:00:12 +01001586 struct snd_pcm_substream *substream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001587
Takashi Iwai372d8552017-01-31 13:57:58 +01001588 had_stream = &intelhaddata->stream_data;
1589 buf_id = intelhaddata->curr_buf;
1590
Takashi Iwai313d9f22017-02-02 13:00:12 +01001591 substream = had_substream_get(intelhaddata);
1592
Takashi Iwaibcce7752017-02-01 17:18:20 +01001593 spin_lock_irq(&intelhaddata->had_spinlock);
Takashi Iwai372d8552017-01-31 13:57:58 +01001594
1595 if (intelhaddata->drv_status == HAD_DRV_DISCONNECTED) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001596 dev_dbg(intelhaddata->dev, "Device already disconnected\n");
Takashi Iwaibcce7752017-02-01 17:18:20 +01001597 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001598 goto out;
Takashi Iwai372d8552017-01-31 13:57:58 +01001599
Takashi Iwai372d8552017-01-31 13:57:58 +01001600 }
1601
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001602 /* Disable Audio */
1603 snd_intelhad_enable_audio_int(intelhaddata, false);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001604 snd_intelhad_enable_audio(substream, intelhaddata, false);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001605
Takashi Iwai372d8552017-01-31 13:57:58 +01001606 intelhaddata->drv_status = HAD_DRV_DISCONNECTED;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001607 dev_dbg(intelhaddata->dev,
1608 "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n",
Takashi Iwai372d8552017-01-31 13:57:58 +01001609 __func__, __LINE__);
Takashi Iwai372d8552017-01-31 13:57:58 +01001610 had_stream->stream_type = HAD_INIT;
Takashi Iwaibcce7752017-02-01 17:18:20 +01001611 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001612
1613 /* Report to above ALSA layer */
1614 if (substream)
1615 snd_pcm_stop(substream, SNDRV_PCM_STATE_SETUP);
1616
1617 out:
1618 if (substream)
1619 had_substream_put(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001620 kfree(intelhaddata->chmap->chmap);
1621 intelhaddata->chmap->chmap = NULL;
Takashi Iwai372d8552017-01-31 13:57:58 +01001622}
1623
1624/* PCM operations structure and the calls back for the same */
1625static struct snd_pcm_ops snd_intelhad_playback_ops = {
Jerome Anand5dab11d2017-01-25 04:27:52 +05301626 .open = snd_intelhad_open,
1627 .close = snd_intelhad_close,
1628 .ioctl = snd_pcm_lib_ioctl,
1629 .hw_params = snd_intelhad_hw_params,
1630 .hw_free = snd_intelhad_hw_free,
1631 .prepare = snd_intelhad_pcm_prepare,
1632 .trigger = snd_intelhad_pcm_trigger,
1633 .pointer = snd_intelhad_pcm_pointer,
1634 .mmap = snd_intelhad_pcm_mmap,
1635};
1636
Jerome Anand5dab11d2017-01-25 04:27:52 +05301637static int had_iec958_info(struct snd_kcontrol *kcontrol,
1638 struct snd_ctl_elem_info *uinfo)
1639{
1640 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1641 uinfo->count = 1;
1642 return 0;
1643}
1644
1645static int had_iec958_get(struct snd_kcontrol *kcontrol,
1646 struct snd_ctl_elem_value *ucontrol)
1647{
1648 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
1649
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001650 mutex_lock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301651 ucontrol->value.iec958.status[0] = (intelhaddata->aes_bits >> 0) & 0xff;
1652 ucontrol->value.iec958.status[1] = (intelhaddata->aes_bits >> 8) & 0xff;
1653 ucontrol->value.iec958.status[2] =
1654 (intelhaddata->aes_bits >> 16) & 0xff;
1655 ucontrol->value.iec958.status[3] =
1656 (intelhaddata->aes_bits >> 24) & 0xff;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001657 mutex_unlock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301658 return 0;
1659}
Takashi Iwai372d8552017-01-31 13:57:58 +01001660
Jerome Anand5dab11d2017-01-25 04:27:52 +05301661static int had_iec958_mask_get(struct snd_kcontrol *kcontrol,
1662 struct snd_ctl_elem_value *ucontrol)
1663{
1664 ucontrol->value.iec958.status[0] = 0xff;
1665 ucontrol->value.iec958.status[1] = 0xff;
1666 ucontrol->value.iec958.status[2] = 0xff;
1667 ucontrol->value.iec958.status[3] = 0xff;
1668 return 0;
1669}
Takashi Iwai372d8552017-01-31 13:57:58 +01001670
Jerome Anand5dab11d2017-01-25 04:27:52 +05301671static int had_iec958_put(struct snd_kcontrol *kcontrol,
1672 struct snd_ctl_elem_value *ucontrol)
1673{
1674 unsigned int val;
1675 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001676 int changed = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301677
Jerome Anand5dab11d2017-01-25 04:27:52 +05301678 val = (ucontrol->value.iec958.status[0] << 0) |
1679 (ucontrol->value.iec958.status[1] << 8) |
1680 (ucontrol->value.iec958.status[2] << 16) |
1681 (ucontrol->value.iec958.status[3] << 24);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001682 mutex_lock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301683 if (intelhaddata->aes_bits != val) {
1684 intelhaddata->aes_bits = val;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001685 changed = 1;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301686 }
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001687 mutex_unlock(&intelhaddata->mutex);
1688 return changed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301689}
1690
1691static struct snd_kcontrol_new had_control_iec958_mask = {
1692 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1693 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1694 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1695 .info = had_iec958_info, /* shared */
1696 .get = had_iec958_mask_get,
1697};
1698
1699static struct snd_kcontrol_new had_control_iec958 = {
1700 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1701 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1702 .info = had_iec958_info,
1703 .get = had_iec958_get,
1704 .put = had_iec958_put
1705};
1706
Takashi Iwaida864802017-01-31 13:52:22 +01001707static irqreturn_t display_pipe_interrupt_handler(int irq, void *dev_id)
1708{
1709 struct snd_intelhad *ctx = dev_id;
1710 u32 audio_stat, audio_reg;
1711
Takashi Iwai4151ee82017-01-31 18:14:15 +01001712 audio_reg = AUD_HDMI_STATUS;
Takashi Iwaida864802017-01-31 13:52:22 +01001713 mid_hdmi_audio_read(ctx, audio_reg, &audio_stat);
1714
1715 if (audio_stat & HDMI_AUDIO_UNDERRUN) {
1716 mid_hdmi_audio_write(ctx, audio_reg, HDMI_AUDIO_UNDERRUN);
1717 had_process_buffer_underrun(ctx);
1718 }
1719
1720 if (audio_stat & HDMI_AUDIO_BUFFER_DONE) {
1721 mid_hdmi_audio_write(ctx, audio_reg, HDMI_AUDIO_BUFFER_DONE);
1722 had_process_buffer_done(ctx);
1723 }
1724
1725 return IRQ_HANDLED;
1726}
1727
1728static void notify_audio_lpe(struct platform_device *pdev)
1729{
1730 struct snd_intelhad *ctx = platform_get_drvdata(pdev);
Takashi Iwaida864802017-01-31 13:52:22 +01001731
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001732 schedule_work(&ctx->hdmi_audio_wq);
1733}
Takashi Iwaida864802017-01-31 13:52:22 +01001734
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001735static void had_audio_wq(struct work_struct *work)
1736{
1737 struct snd_intelhad *ctx =
1738 container_of(work, struct snd_intelhad, hdmi_audio_wq);
1739 struct intel_hdmi_lpe_audio_pdata *pdata = ctx->dev->platform_data;
1740
Takashi Iwai182cdf22017-02-02 14:43:39 +01001741 pm_runtime_get_sync(ctx->dev);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001742 mutex_lock(&ctx->mutex);
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001743 if (!pdata->hdmi_connected) {
1744 dev_dbg(ctx->dev, "%s: Event: HAD_NOTIFY_HOT_UNPLUG\n",
Takashi Iwaida864802017-01-31 13:52:22 +01001745 __func__);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001746 had_process_hot_unplug(ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001747 } else {
1748 struct intel_hdmi_lpe_audio_eld *eld = &pdata->eld;
1749
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001750 dev_dbg(ctx->dev, "%s: HAD_NOTIFY_ELD : port = %d, tmds = %d\n",
1751 __func__, eld->port_id, pdata->tmds_clock_speed);
1752
Takashi Iwaida864802017-01-31 13:52:22 +01001753 switch (eld->pipe_id) {
1754 case 0:
1755 ctx->had_config_offset = AUDIO_HDMI_CONFIG_A;
1756 break;
1757 case 1:
1758 ctx->had_config_offset = AUDIO_HDMI_CONFIG_B;
1759 break;
1760 case 2:
1761 ctx->had_config_offset = AUDIO_HDMI_CONFIG_C;
1762 break;
1763 default:
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001764 dev_dbg(ctx->dev, "Invalid pipe %d\n",
Takashi Iwaida864802017-01-31 13:52:22 +01001765 eld->pipe_id);
1766 break;
1767 }
1768
1769 memcpy(&ctx->eld, eld->eld_data, sizeof(ctx->eld));
1770
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001771 ctx->dp_output = pdata->dp_output;
1772 ctx->tmds_clock_speed = pdata->tmds_clock_speed;
1773 ctx->link_rate = pdata->link_rate;
1774
Takashi Iwaida864802017-01-31 13:52:22 +01001775 had_process_hot_plug(ctx);
1776
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001777 /* Process mode change if stream is active */
1778 if (ctx->stream_data.stream_type == HAD_RUNNING_STREAM)
1779 hdmi_audio_mode_change(ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001780 }
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001781 mutex_unlock(&ctx->mutex);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001782 pm_runtime_put(ctx->dev);
1783}
1784
1785/*
1786 * PM callbacks
1787 */
1788
1789static int hdmi_lpe_audio_runtime_suspend(struct device *dev)
1790{
1791 struct snd_intelhad *ctx = dev_get_drvdata(dev);
1792 struct snd_pcm_substream *substream;
1793
1794 substream = had_substream_get(ctx);
1795 if (substream) {
1796 snd_pcm_suspend(substream);
1797 had_substream_put(ctx);
1798 }
1799
1800 return 0;
1801}
1802
1803static int hdmi_lpe_audio_suspend(struct device *dev)
1804{
1805 struct snd_intelhad *ctx = dev_get_drvdata(dev);
1806 int err;
1807
1808 err = hdmi_lpe_audio_runtime_suspend(dev);
1809 if (!err)
1810 snd_power_change_state(ctx->card, SNDRV_CTL_POWER_D3hot);
1811 return err;
1812}
1813
1814static int hdmi_lpe_audio_resume(struct device *dev)
1815{
1816 struct snd_intelhad *ctx = dev_get_drvdata(dev);
1817
1818 snd_power_change_state(ctx->card, SNDRV_CTL_POWER_D0);
1819 return 0;
Takashi Iwaida864802017-01-31 13:52:22 +01001820}
1821
1822/* release resources */
1823static void hdmi_lpe_audio_free(struct snd_card *card)
1824{
1825 struct snd_intelhad *ctx = card->private_data;
1826
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001827 cancel_work_sync(&ctx->hdmi_audio_wq);
1828
Takashi Iwaida864802017-01-31 13:52:22 +01001829 if (ctx->mmio_start)
1830 iounmap(ctx->mmio_start);
1831 if (ctx->irq >= 0)
1832 free_irq(ctx->irq, ctx);
1833}
1834
1835/*
1836 * hdmi_lpe_audio_probe - start bridge with i915
1837 *
1838 * This function is called when the i915 driver creates the
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001839 * hdmi-lpe-audio platform device.
Takashi Iwaida864802017-01-31 13:52:22 +01001840 */
1841static int hdmi_lpe_audio_probe(struct platform_device *pdev)
1842{
1843 struct snd_card *card;
1844 struct snd_intelhad *ctx;
1845 struct snd_pcm *pcm;
1846 struct intel_hdmi_lpe_audio_pdata *pdata;
1847 int irq;
1848 struct resource *res_mmio;
1849 int ret;
Takashi Iwaida864802017-01-31 13:52:22 +01001850
Takashi Iwaida864802017-01-31 13:52:22 +01001851 dev_dbg(&pdev->dev, "dma_mask: %p\n", pdev->dev.dma_mask);
1852
1853 pdata = pdev->dev.platform_data;
1854 if (!pdata) {
1855 dev_err(&pdev->dev, "%s: quit: pdata not allocated by i915!!\n", __func__);
1856 return -EINVAL;
1857 }
1858
1859 /* get resources */
1860 irq = platform_get_irq(pdev, 0);
1861 if (irq < 0) {
1862 dev_err(&pdev->dev, "Could not get irq resource\n");
1863 return -ENODEV;
1864 }
1865
1866 res_mmio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1867 if (!res_mmio) {
1868 dev_err(&pdev->dev, "Could not get IO_MEM resources\n");
1869 return -ENXIO;
1870 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301871
Takashi Iwai5647aec2017-01-31 08:14:34 +01001872 /* create a card instance with ALSA framework */
Takashi Iwaida864802017-01-31 13:52:22 +01001873 ret = snd_card_new(&pdev->dev, hdmi_card_index, hdmi_card_id,
1874 THIS_MODULE, sizeof(*ctx), &card);
1875 if (ret)
1876 return ret;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301877
Takashi Iwaida864802017-01-31 13:52:22 +01001878 ctx = card->private_data;
1879 spin_lock_init(&ctx->had_spinlock);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001880 mutex_init(&ctx->mutex);
Takashi Iwaida864802017-01-31 13:52:22 +01001881 ctx->drv_status = HAD_DRV_DISCONNECTED;
1882 ctx->dev = &pdev->dev;
1883 ctx->card = card;
Takashi Iwaida864802017-01-31 13:52:22 +01001884 ctx->aes_bits = SNDRV_PCM_DEFAULT_CON_SPDIF;
1885 strcpy(card->driver, INTEL_HAD);
1886 strcpy(card->shortname, INTEL_HAD);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301887
Takashi Iwaida864802017-01-31 13:52:22 +01001888 ctx->irq = -1;
1889 ctx->tmds_clock_speed = DIS_SAMPLE_RATE_148_5;
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001890 INIT_WORK(&ctx->hdmi_audio_wq, had_audio_wq);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301891
Takashi Iwaida864802017-01-31 13:52:22 +01001892 card->private_free = hdmi_lpe_audio_free;
1893
1894 /* assume pipe A as default */
1895 ctx->had_config_offset = AUDIO_HDMI_CONFIG_A;
1896
1897 platform_set_drvdata(pdev, ctx);
1898
1899 dev_dbg(&pdev->dev, "%s: mmio_start = 0x%x, mmio_end = 0x%x\n",
1900 __func__, (unsigned int)res_mmio->start,
1901 (unsigned int)res_mmio->end);
1902
1903 ctx->mmio_start = ioremap_nocache(res_mmio->start,
1904 (size_t)(resource_size(res_mmio)));
1905 if (!ctx->mmio_start) {
1906 dev_err(&pdev->dev, "Could not get ioremap\n");
1907 ret = -EACCES;
1908 goto err;
1909 }
1910
1911 /* setup interrupt handler */
1912 ret = request_irq(irq, display_pipe_interrupt_handler, 0,
1913 pdev->name, ctx);
1914 if (ret < 0) {
1915 dev_err(&pdev->dev, "request_irq failed\n");
1916 goto err;
1917 }
1918
1919 ctx->irq = irq;
1920
1921 ret = snd_pcm_new(card, INTEL_HAD, PCM_INDEX, MAX_PB_STREAMS,
1922 MAX_CAP_STREAMS, &pcm);
1923 if (ret)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301924 goto err;
1925
1926 /* setup private data which can be retrieved when required */
Takashi Iwaida864802017-01-31 13:52:22 +01001927 pcm->private_data = ctx;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301928 pcm->info_flags = 0;
1929 strncpy(pcm->name, card->shortname, strlen(card->shortname));
Takashi Iwaida864802017-01-31 13:52:22 +01001930 /* setup the ops for playabck */
Jerome Anand5dab11d2017-01-25 04:27:52 +05301931 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
1932 &snd_intelhad_playback_ops);
1933 /* allocate dma pages for ALSA stream operations
1934 * memory allocated is based on size, not max value
1935 * thus using same argument for max & size
1936 */
Takashi Iwaida864802017-01-31 13:52:22 +01001937 snd_pcm_lib_preallocate_pages_for_all(pcm,
Jerome Anand5dab11d2017-01-25 04:27:52 +05301938 SNDRV_DMA_TYPE_DEV, NULL,
1939 HAD_MAX_BUFFER, HAD_MAX_BUFFER);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301940
Jerome Anand5dab11d2017-01-25 04:27:52 +05301941 /* IEC958 controls */
Takashi Iwaida864802017-01-31 13:52:22 +01001942 ret = snd_ctl_add(card, snd_ctl_new1(&had_control_iec958_mask, ctx));
1943 if (ret < 0)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301944 goto err;
Takashi Iwaida864802017-01-31 13:52:22 +01001945 ret = snd_ctl_add(card, snd_ctl_new1(&had_control_iec958, ctx));
1946 if (ret < 0)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301947 goto err;
1948
1949 init_channel_allocations();
1950
1951 /* Register channel map controls */
Takashi Iwaida864802017-01-31 13:52:22 +01001952 ret = had_register_chmap_ctls(ctx, pcm);
1953 if (ret < 0)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301954 goto err;
1955
Takashi Iwaida864802017-01-31 13:52:22 +01001956 ret = snd_card_register(card);
1957 if (ret)
Takashi Iwai36ec0d92017-01-31 08:47:05 +01001958 goto err;
1959
Takashi Iwaibcce7752017-02-01 17:18:20 +01001960 spin_lock_irq(&pdata->lpe_audio_slock);
Takashi Iwaida864802017-01-31 13:52:22 +01001961 pdata->notify_audio_lpe = notify_audio_lpe;
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001962 pdata->notify_pending = false;
Takashi Iwaibcce7752017-02-01 17:18:20 +01001963 spin_unlock_irq(&pdata->lpe_audio_slock);
Takashi Iwaida864802017-01-31 13:52:22 +01001964
1965 pm_runtime_set_active(&pdev->dev);
1966 pm_runtime_enable(&pdev->dev);
1967
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001968 dev_dbg(&pdev->dev, "%s: handle pending notification\n", __func__);
Takashi Iwaida864802017-01-31 13:52:22 +01001969 schedule_work(&ctx->hdmi_audio_wq);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301970
Takashi Iwai79dda752017-01-30 17:23:39 +01001971 return 0;
Takashi Iwai5647aec2017-01-31 08:14:34 +01001972
Jerome Anand5dab11d2017-01-25 04:27:52 +05301973err:
1974 snd_card_free(card);
Takashi Iwaida864802017-01-31 13:52:22 +01001975 return ret;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301976}
1977
Takashi Iwai79dda752017-01-30 17:23:39 +01001978/*
Takashi Iwaida864802017-01-31 13:52:22 +01001979 * hdmi_lpe_audio_remove - stop bridge with i915
Jerome Anand5dab11d2017-01-25 04:27:52 +05301980 *
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001981 * This function is called when the platform device is destroyed.
Jerome Anand5dab11d2017-01-25 04:27:52 +05301982 */
Takashi Iwaida864802017-01-31 13:52:22 +01001983static int hdmi_lpe_audio_remove(struct platform_device *pdev)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301984{
Takashi Iwaida864802017-01-31 13:52:22 +01001985 struct snd_intelhad *ctx = platform_get_drvdata(pdev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301986
Takashi Iwaida864802017-01-31 13:52:22 +01001987 if (ctx->drv_status != HAD_DRV_DISCONNECTED)
1988 snd_intelhad_enable_audio_int(ctx, false);
1989 snd_card_free(ctx->card);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301990 return 0;
1991}
1992
Takashi Iwai182cdf22017-02-02 14:43:39 +01001993static const struct dev_pm_ops hdmi_lpe_audio_pm = {
1994 SET_SYSTEM_SLEEP_PM_OPS(hdmi_lpe_audio_suspend, hdmi_lpe_audio_resume)
1995 SET_RUNTIME_PM_OPS(hdmi_lpe_audio_runtime_suspend, NULL, NULL)
1996};
1997
Takashi Iwaida864802017-01-31 13:52:22 +01001998static struct platform_driver hdmi_lpe_audio_driver = {
1999 .driver = {
2000 .name = "hdmi-lpe-audio",
Takashi Iwai182cdf22017-02-02 14:43:39 +01002001 .pm = &hdmi_lpe_audio_pm,
Takashi Iwaida864802017-01-31 13:52:22 +01002002 },
2003 .probe = hdmi_lpe_audio_probe,
2004 .remove = hdmi_lpe_audio_remove,
Takashi Iwaida864802017-01-31 13:52:22 +01002005};
2006
2007module_platform_driver(hdmi_lpe_audio_driver);
2008MODULE_ALIAS("platform:hdmi_lpe_audio");
2009
Jerome Anand5dab11d2017-01-25 04:27:52 +05302010MODULE_AUTHOR("Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>");
2011MODULE_AUTHOR("Ramesh Babu K V <ramesh.babu@intel.com>");
2012MODULE_AUTHOR("Vaibhav Agarwal <vaibhav.agarwal@intel.com>");
2013MODULE_AUTHOR("Jerome Anand <jerome.anand@intel.com>");
2014MODULE_DESCRIPTION("Intel HDMI Audio driver");
2015MODULE_LICENSE("GPL v2");
2016MODULE_SUPPORTED_DEVICE("{Intel,Intel_HAD}");