blob: 909391d5270cb66cb8e34ca9a20b6282f483ec3c [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
Takashi Iwai03c34372017-02-02 16:19:03 +010024#include <linux/types.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053025#include <linux/platform_device.h>
26#include <linux/io.h>
27#include <linux/slab.h>
28#include <linux/module.h>
Takashi Iwaida864802017-01-31 13:52:22 +010029#include <linux/interrupt.h>
Takashi Iwai03c34372017-02-02 16:19:03 +010030#include <linux/pm_runtime.h>
Takashi Iwai412bbe7d52017-02-02 22:03:22 +010031#include <linux/dma-mapping.h>
Takashi Iwaie2acecf2017-02-11 08:21:56 +010032#include <linux/delay.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053033#include <asm/cacheflush.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053034#include <sound/core.h>
Takashi Iwai03c34372017-02-02 16:19:03 +010035#include <sound/asoundef.h>
36#include <sound/pcm.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053037#include <sound/pcm_params.h>
38#include <sound/initval.h>
39#include <sound/control.h>
Takashi Iwaib9bacf22017-02-14 12:29:38 +010040#include <sound/jack.h>
Takashi Iwai03c34372017-02-02 16:19:03 +010041#include <drm/drm_edid.h>
Takashi Iwaida864802017-01-31 13:52:22 +010042#include <drm/intel_lpe_audio.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053043#include "intel_hdmi_audio.h"
44
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +030045#define for_each_pipe(card_ctx, pipe) \
46 for ((pipe) = 0; (pipe) < (card_ctx)->num_pipes; (pipe)++)
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +030047#define for_each_port(card_ctx, port) \
48 for ((port) = 0; (port) < (card_ctx)->num_ports; (port)++)
49
Jerome Anand5dab11d2017-01-25 04:27:52 +053050/*standard module options for ALSA. This module supports only one card*/
51static int hdmi_card_index = SNDRV_DEFAULT_IDX1;
52static char *hdmi_card_id = SNDRV_DEFAULT_STR1;
Jerome Anand5dab11d2017-01-25 04:27:52 +053053
54module_param_named(index, hdmi_card_index, int, 0444);
55MODULE_PARM_DESC(index,
56 "Index value for INTEL Intel HDMI Audio controller.");
57module_param_named(id, hdmi_card_id, charp, 0444);
58MODULE_PARM_DESC(id,
59 "ID string for INTEL Intel HDMI Audio controller.");
60
61/*
62 * ELD SA bits in the CEA Speaker Allocation data block
63 */
Takashi Iwai4a5ddb22017-02-01 16:45:38 +010064static const int eld_speaker_allocation_bits[] = {
Jerome Anand5dab11d2017-01-25 04:27:52 +053065 [0] = FL | FR,
66 [1] = LFE,
67 [2] = FC,
68 [3] = RL | RR,
69 [4] = RC,
70 [5] = FLC | FRC,
71 [6] = RLC | RRC,
72 /* the following are not defined in ELD yet */
73 [7] = 0,
74};
75
76/*
77 * This is an ordered list!
78 *
79 * The preceding ones have better chances to be selected by
80 * hdmi_channel_allocation().
81 */
82static struct cea_channel_speaker_allocation channel_allocations[] = {
83/* channel: 7 6 5 4 3 2 1 0 */
84{ .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
85 /* 2.1 */
86{ .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
87 /* Dolby Surround */
88{ .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
89 /* surround40 */
90{ .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
91 /* surround41 */
92{ .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
93 /* surround50 */
94{ .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
95 /* surround51 */
96{ .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
97 /* 6.1 */
98{ .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
99 /* surround71 */
100{ .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
101
102{ .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
103{ .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
104{ .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
105{ .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
106{ .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
107{ .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
108{ .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
109{ .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
110{ .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
111{ .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
112{ .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
113{ .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
114{ .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
115{ .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
116{ .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
117{ .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
118{ .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
119{ .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
120{ .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
121{ .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
122{ .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
123{ .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
124{ .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
125};
126
Takashi Iwai4a5ddb22017-02-01 16:45:38 +0100127static const struct channel_map_table map_tables[] = {
Jerome Anand5dab11d2017-01-25 04:27:52 +0530128 { SNDRV_CHMAP_FL, 0x00, FL },
129 { SNDRV_CHMAP_FR, 0x01, FR },
130 { SNDRV_CHMAP_RL, 0x04, RL },
131 { SNDRV_CHMAP_RR, 0x05, RR },
132 { SNDRV_CHMAP_LFE, 0x02, LFE },
133 { SNDRV_CHMAP_FC, 0x03, FC },
134 { SNDRV_CHMAP_RLC, 0x06, RLC },
135 { SNDRV_CHMAP_RRC, 0x07, RRC },
136 {} /* terminator */
137};
138
139/* hardware capability structure */
Takashi Iwaib5562902017-02-04 22:05:33 +0100140static const struct snd_pcm_hardware had_pcm_hardware = {
Jerome Anand5dab11d2017-01-25 04:27:52 +0530141 .info = (SNDRV_PCM_INFO_INTERLEAVED |
Takashi Iwaia9ebdd02017-02-02 21:33:54 +0100142 SNDRV_PCM_INFO_MMAP |
Takashi Iwaie8de9852017-02-07 08:09:12 +0100143 SNDRV_PCM_INFO_MMAP_VALID |
144 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP),
Takashi Iwai3fe2cf72017-02-07 13:53:42 +0100145 .formats = (SNDRV_PCM_FMTBIT_S16_LE |
146 SNDRV_PCM_FMTBIT_S24_LE |
Takashi Iwai85bd8742017-02-07 13:33:17 +0100147 SNDRV_PCM_FMTBIT_S32_LE),
Jerome Anand5dab11d2017-01-25 04:27:52 +0530148 .rates = SNDRV_PCM_RATE_32000 |
149 SNDRV_PCM_RATE_44100 |
150 SNDRV_PCM_RATE_48000 |
151 SNDRV_PCM_RATE_88200 |
152 SNDRV_PCM_RATE_96000 |
153 SNDRV_PCM_RATE_176400 |
154 SNDRV_PCM_RATE_192000,
155 .rate_min = HAD_MIN_RATE,
156 .rate_max = HAD_MAX_RATE,
157 .channels_min = HAD_MIN_CHANNEL,
158 .channels_max = HAD_MAX_CHANNEL,
159 .buffer_bytes_max = HAD_MAX_BUFFER,
160 .period_bytes_min = HAD_MIN_PERIOD_BYTES,
161 .period_bytes_max = HAD_MAX_PERIOD_BYTES,
162 .periods_min = HAD_MIN_PERIODS,
163 .periods_max = HAD_MAX_PERIODS,
164 .fifo_size = HAD_FIFO_SIZE,
165};
166
Takashi Iwai313d9f22017-02-02 13:00:12 +0100167/* Get the active PCM substream;
168 * Call had_substream_put() for unreferecing.
169 * Don't call this inside had_spinlock, as it takes by itself
170 */
171static struct snd_pcm_substream *
172had_substream_get(struct snd_intelhad *intelhaddata)
173{
174 struct snd_pcm_substream *substream;
175 unsigned long flags;
176
177 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
178 substream = intelhaddata->stream_info.substream;
179 if (substream)
180 intelhaddata->stream_info.substream_refcount++;
181 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
182 return substream;
183}
184
185/* Unref the active PCM substream;
186 * Don't call this inside had_spinlock, as it takes by itself
187 */
188static void had_substream_put(struct snd_intelhad *intelhaddata)
189{
190 unsigned long flags;
191
192 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
193 intelhaddata->stream_info.substream_refcount--;
194 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
195}
196
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300197static u32 had_config_offset(int pipe)
Takashi Iwai28ed1252017-02-15 22:02:10 +0100198{
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300199 switch (pipe) {
200 default:
201 case 0:
202 return AUDIO_HDMI_CONFIG_A;
203 case 1:
204 return AUDIO_HDMI_CONFIG_B;
205 case 2:
206 return AUDIO_HDMI_CONFIG_C;
207 }
Takashi Iwai28ed1252017-02-15 22:02:10 +0100208}
209
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300210/* Register access functions */
211static u32 had_read_register_raw(struct snd_intelhad_card *card_ctx,
212 int pipe, u32 reg)
Takashi Iwai28ed1252017-02-15 22:02:10 +0100213{
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300214 return ioread32(card_ctx->mmio_start + had_config_offset(pipe) + reg);
215}
216
217static void had_write_register_raw(struct snd_intelhad_card *card_ctx,
218 int pipe, u32 reg, u32 val)
219{
220 iowrite32(val, card_ctx->mmio_start + had_config_offset(pipe) + reg);
Takashi Iwai28ed1252017-02-15 22:02:10 +0100221}
222
Takashi Iwai83af57d2017-02-03 08:50:06 +0100223static void had_read_register(struct snd_intelhad *ctx, u32 reg, u32 *val)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530224{
Takashi Iwai28ed1252017-02-15 22:02:10 +0100225 if (!ctx->connected)
226 *val = 0;
227 else
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300228 *val = had_read_register_raw(ctx->card_ctx, ctx->pipe, reg);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530229}
230
Takashi Iwai83af57d2017-02-03 08:50:06 +0100231static void had_write_register(struct snd_intelhad *ctx, u32 reg, u32 val)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530232{
Takashi Iwai28ed1252017-02-15 22:02:10 +0100233 if (ctx->connected)
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +0300234 had_write_register_raw(ctx->card_ctx, ctx->pipe, reg, val);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530235}
236
Takashi Iwaida864802017-01-31 13:52:22 +0100237/*
Takashi Iwai313d9f22017-02-02 13:00:12 +0100238 * enable / disable audio configuration
239 *
Takashi Iwai83af57d2017-02-03 08:50:06 +0100240 * The normal read/modify should not directly be used on VLV2 for
Takashi Iwaida864802017-01-31 13:52:22 +0100241 * updating AUD_CONFIG register.
Jerome Anand5dab11d2017-01-25 04:27:52 +0530242 * This is because:
243 * Bit6 of AUD_CONFIG register is writeonly due to a silicon bug on VLV2
244 * HDMI IP. As a result a read-modify of AUD_CONFIG regiter will always
245 * clear bit6. AUD_CONFIG[6:4] represents the "channels" field of the
246 * register. This field should be 1xy binary for configuration with 6 or
247 * more channels. Read-modify of AUD_CONFIG (Eg. for enabling audio)
248 * causes the "channels" field to be updated as 0xy binary resulting in
249 * bad audio. The fix is to always write the AUD_CONFIG[6:4] with
250 * appropriate value when doing read-modify of AUD_CONFIG register.
Jerome Anand5dab11d2017-01-25 04:27:52 +0530251 */
Takashi Iwai40ce4b52017-02-07 16:17:06 +0100252static void had_enable_audio(struct snd_intelhad *intelhaddata,
Takashi Iwaib5562902017-02-04 22:05:33 +0100253 bool enable)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530254{
Takashi Iwai40ce4b52017-02-07 16:17:06 +0100255 /* update the cached value */
256 intelhaddata->aud_config.regx.aud_en = enable;
257 had_write_register(intelhaddata, AUD_CONFIG,
258 intelhaddata->aud_config.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530259}
260
Takashi Iwai075a1d42017-02-07 07:55:27 +0100261/* forcibly ACKs to both BUFFER_DONE and BUFFER_UNDERRUN interrupts */
262static void had_ack_irqs(struct snd_intelhad *ctx)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530263{
Takashi Iwaida864802017-01-31 13:52:22 +0100264 u32 status_reg;
265
Takashi Iwai28ed1252017-02-15 22:02:10 +0100266 if (!ctx->connected)
267 return;
Takashi Iwai075a1d42017-02-07 07:55:27 +0100268 had_read_register(ctx, AUD_HDMI_STATUS, &status_reg);
269 status_reg |= HDMI_AUDIO_BUFFER_DONE | HDMI_AUDIO_UNDERRUN;
270 had_write_register(ctx, AUD_HDMI_STATUS, status_reg);
271 had_read_register(ctx, AUD_HDMI_STATUS, &status_reg);
Takashi Iwaida864802017-01-31 13:52:22 +0100272}
273
Takashi Iwaif4566aa2017-02-04 21:39:56 +0100274/* Reset buffer pointers */
275static void had_reset_audio(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530276{
Takashi Iwai77531be2017-02-07 12:17:23 +0100277 had_write_register(intelhaddata, AUD_HDMI_STATUS,
278 AUD_HDMI_STATUSG_MASK_FUNCRST);
Takashi Iwaif4566aa2017-02-04 21:39:56 +0100279 had_write_register(intelhaddata, AUD_HDMI_STATUS, 0);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530280}
281
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100282/*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530283 * initialize audio channel status registers
284 * This function is called in the prepare callback
285 */
286static int had_prog_status_reg(struct snd_pcm_substream *substream,
287 struct snd_intelhad *intelhaddata)
288{
Takashi Iwai7ceba752017-02-02 15:58:35 +0100289 union aud_cfg cfg_val = {.regval = 0};
290 union aud_ch_status_0 ch_stat0 = {.regval = 0};
291 union aud_ch_status_1 ch_stat1 = {.regval = 0};
Jerome Anand5dab11d2017-01-25 04:27:52 +0530292
Takashi Iwai7ceba752017-02-02 15:58:35 +0100293 ch_stat0.regx.lpcm_id = (intelhaddata->aes_bits &
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100294 IEC958_AES0_NONAUDIO) >> 1;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100295 ch_stat0.regx.clk_acc = (intelhaddata->aes_bits &
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100296 IEC958_AES3_CON_CLOCK) >> 4;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100297 cfg_val.regx.val_bit = ch_stat0.regx.lpcm_id;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530298
299 switch (substream->runtime->rate) {
300 case AUD_SAMPLE_RATE_32:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100301 ch_stat0.regx.samp_freq = CH_STATUS_MAP_32KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530302 break;
303
304 case AUD_SAMPLE_RATE_44_1:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100305 ch_stat0.regx.samp_freq = CH_STATUS_MAP_44KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530306 break;
307 case AUD_SAMPLE_RATE_48:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100308 ch_stat0.regx.samp_freq = CH_STATUS_MAP_48KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530309 break;
310 case AUD_SAMPLE_RATE_88_2:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100311 ch_stat0.regx.samp_freq = CH_STATUS_MAP_88KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530312 break;
313 case AUD_SAMPLE_RATE_96:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100314 ch_stat0.regx.samp_freq = CH_STATUS_MAP_96KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530315 break;
316 case AUD_SAMPLE_RATE_176_4:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100317 ch_stat0.regx.samp_freq = CH_STATUS_MAP_176KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530318 break;
319 case AUD_SAMPLE_RATE_192:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100320 ch_stat0.regx.samp_freq = CH_STATUS_MAP_192KHZ;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530321 break;
322
323 default:
324 /* control should never come here */
325 return -EINVAL;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530326 }
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100327
Takashi Iwai79dda752017-01-30 17:23:39 +0100328 had_write_register(intelhaddata,
Takashi Iwai7ceba752017-02-02 15:58:35 +0100329 AUD_CH_STATUS_0, ch_stat0.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530330
Takashi Iwai85bd8742017-02-07 13:33:17 +0100331 switch (substream->runtime->format) {
Takashi Iwai85bd8742017-02-07 13:33:17 +0100332 case SNDRV_PCM_FORMAT_S16_LE:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100333 ch_stat1.regx.max_wrd_len = MAX_SMPL_WIDTH_20;
334 ch_stat1.regx.wrd_len = SMPL_WIDTH_16BITS;
Takashi Iwai85bd8742017-02-07 13:33:17 +0100335 break;
Takashi Iwai85bd8742017-02-07 13:33:17 +0100336 case SNDRV_PCM_FORMAT_S24_LE:
337 case SNDRV_PCM_FORMAT_S32_LE:
Takashi Iwai7ceba752017-02-02 15:58:35 +0100338 ch_stat1.regx.max_wrd_len = MAX_SMPL_WIDTH_24;
339 ch_stat1.regx.wrd_len = SMPL_WIDTH_24BITS;
Takashi Iwai85bd8742017-02-07 13:33:17 +0100340 break;
341 default:
342 return -EINVAL;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530343 }
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100344
Takashi Iwai79dda752017-01-30 17:23:39 +0100345 had_write_register(intelhaddata,
Takashi Iwai7ceba752017-02-02 15:58:35 +0100346 AUD_CH_STATUS_1, ch_stat1.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530347 return 0;
348}
349
Takashi Iwai76296ef2017-01-30 16:09:11 +0100350/*
Jerome Anand5dab11d2017-01-25 04:27:52 +0530351 * function to initialize audio
352 * registers and buffer confgiuration registers
353 * This function is called in the prepare callback
354 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100355static int had_init_audio_ctrl(struct snd_pcm_substream *substream,
356 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530357{
Takashi Iwai7ceba752017-02-02 15:58:35 +0100358 union aud_cfg cfg_val = {.regval = 0};
359 union aud_buf_config buf_cfg = {.regval = 0};
Jerome Anand5dab11d2017-01-25 04:27:52 +0530360 u8 channels;
361
362 had_prog_status_reg(substream, intelhaddata);
363
Takashi Iwai7ceba752017-02-02 15:58:35 +0100364 buf_cfg.regx.audio_fifo_watermark = FIFO_THRESHOLD;
365 buf_cfg.regx.dma_fifo_watermark = DMA_FIFO_THRESHOLD;
366 buf_cfg.regx.aud_delay = 0;
367 had_write_register(intelhaddata, AUD_BUF_CONFIG, buf_cfg.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530368
369 channels = substream->runtime->channels;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100370 cfg_val.regx.num_ch = channels - 2;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530371 if (channels <= 2)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100372 cfg_val.regx.layout = LAYOUT0;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530373 else
Takashi Iwai7ceba752017-02-02 15:58:35 +0100374 cfg_val.regx.layout = LAYOUT1;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530375
Takashi Iwai3fe2cf72017-02-07 13:53:42 +0100376 if (substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE)
377 cfg_val.regx.packet_mode = 1;
378
Takashi Iwai85bd8742017-02-07 13:33:17 +0100379 if (substream->runtime->format == SNDRV_PCM_FORMAT_S32_LE)
380 cfg_val.regx.left_align = 1;
381
Takashi Iwai7ceba752017-02-02 15:58:35 +0100382 cfg_val.regx.val_bit = 1;
Takashi Iwai83af57d2017-02-03 08:50:06 +0100383
384 /* fix up the DP bits */
385 if (intelhaddata->dp_output) {
386 cfg_val.regx.dp_modei = 1;
387 cfg_val.regx.set = 1;
388 }
389
Takashi Iwai7ceba752017-02-02 15:58:35 +0100390 had_write_register(intelhaddata, AUD_CONFIG, cfg_val.regval);
Takashi Iwai40ce4b52017-02-07 16:17:06 +0100391 intelhaddata->aud_config = cfg_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530392 return 0;
393}
394
Jerome Anand5dab11d2017-01-25 04:27:52 +0530395/*
396 * Compute derived values in channel_allocations[].
397 */
398static void init_channel_allocations(void)
399{
400 int i, j;
401 struct cea_channel_speaker_allocation *p;
402
Jerome Anand5dab11d2017-01-25 04:27:52 +0530403 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
404 p = channel_allocations + i;
405 p->channels = 0;
406 p->spk_mask = 0;
407 for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
408 if (p->speakers[j]) {
409 p->channels++;
410 p->spk_mask |= p->speakers[j];
411 }
412 }
413}
414
415/*
416 * The transformation takes two steps:
417 *
418 * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
419 * spk_mask => (channel_allocations[]) => ai->CA
420 *
421 * TODO: it could select the wrong CA from multiple candidates.
422 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100423static int had_channel_allocation(struct snd_intelhad *intelhaddata,
424 int channels)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530425{
426 int i;
427 int ca = 0;
428 int spk_mask = 0;
429
430 /*
431 * CA defaults to 0 for basic stereo audio
432 */
433 if (channels <= 2)
434 return 0;
435
436 /*
437 * expand ELD's speaker allocation mask
438 *
439 * ELD tells the speaker mask in a compact(paired) form,
440 * expand ELD's notions to match the ones used by Audio InfoFrame.
441 */
442
443 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100444 if (intelhaddata->eld[DRM_ELD_SPEAKER] & (1 << i))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530445 spk_mask |= eld_speaker_allocation_bits[i];
446 }
447
448 /* search for the first working match in the CA table */
449 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
450 if (channels == channel_allocations[i].channels &&
451 (spk_mask & channel_allocations[i].spk_mask) ==
452 channel_allocations[i].spk_mask) {
453 ca = channel_allocations[i].ca_index;
454 break;
455 }
456 }
457
Takashi Iwaic75b0472017-01-31 15:49:15 +0100458 dev_dbg(intelhaddata->dev, "select CA 0x%x for %d\n", ca, channels);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530459
460 return ca;
461}
462
463/* from speaker bit mask to ALSA API channel position */
464static int spk_to_chmap(int spk)
465{
Takashi Iwai4a5ddb22017-02-01 16:45:38 +0100466 const struct channel_map_table *t = map_tables;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530467
468 for (; t->map; t++) {
469 if (t->spk_mask == spk)
470 return t->map;
471 }
472 return 0;
473}
474
Takashi Iwai372d8552017-01-31 13:57:58 +0100475static void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530476{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100477 int i, c;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530478 int spk_mask = 0;
479 struct snd_pcm_chmap_elem *chmap;
480 u8 eld_high, eld_high_mask = 0xF0;
481 u8 high_msb;
482
Takashi Iwai18353192017-02-15 21:42:20 +0100483 kfree(intelhaddata->chmap->chmap);
484 intelhaddata->chmap->chmap = NULL;
485
Jerome Anand5dab11d2017-01-25 04:27:52 +0530486 chmap = kzalloc(sizeof(*chmap), GFP_KERNEL);
Takashi Iwai18353192017-02-15 21:42:20 +0100487 if (!chmap)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530488 return;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530489
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100490 dev_dbg(intelhaddata->dev, "eld speaker = %x\n",
491 intelhaddata->eld[DRM_ELD_SPEAKER]);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530492
493 /* WA: Fix the max channel supported to 8 */
494
495 /*
496 * Sink may support more than 8 channels, if eld_high has more than
497 * one bit set. SOC supports max 8 channels.
498 * Refer eld_speaker_allocation_bits, for sink speaker allocation
499 */
500
501 /* if 0x2F < eld < 0x4F fall back to 0x2f, else fall back to 0x4F */
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100502 eld_high = intelhaddata->eld[DRM_ELD_SPEAKER] & eld_high_mask;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530503 if ((eld_high & (eld_high-1)) && (eld_high > 0x1F)) {
504 /* eld_high & (eld_high-1): if more than 1 bit set */
505 /* 0x1F: 7 channels */
506 for (i = 1; i < 4; i++) {
507 high_msb = eld_high & (0x80 >> i);
508 if (high_msb) {
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100509 intelhaddata->eld[DRM_ELD_SPEAKER] &=
Jerome Anand5dab11d2017-01-25 04:27:52 +0530510 high_msb | 0xF;
511 break;
512 }
513 }
514 }
515
516 for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100517 if (intelhaddata->eld[DRM_ELD_SPEAKER] & (1 << i))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530518 spk_mask |= eld_speaker_allocation_bits[i];
519 }
520
521 for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
522 if (spk_mask == channel_allocations[i].spk_mask) {
523 for (c = 0; c < channel_allocations[i].channels; c++) {
524 chmap->map[c] = spk_to_chmap(
525 channel_allocations[i].speakers[
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100526 (MAX_SPEAKERS - 1) - c]);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530527 }
528 chmap->channels = channel_allocations[i].channels;
529 intelhaddata->chmap->chmap = chmap;
530 break;
531 }
532 }
Takashi Iwai18353192017-02-15 21:42:20 +0100533 if (i >= ARRAY_SIZE(channel_allocations))
Jerome Anand5dab11d2017-01-25 04:27:52 +0530534 kfree(chmap);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530535}
536
537/*
538 * ALSA API channel-map control callbacks
539 */
540static int had_chmap_ctl_info(struct snd_kcontrol *kcontrol,
541 struct snd_ctl_elem_info *uinfo)
542{
Jerome Anand5dab11d2017-01-25 04:27:52 +0530543 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
544 uinfo->count = HAD_MAX_CHANNEL;
545 uinfo->value.integer.min = 0;
546 uinfo->value.integer.max = SNDRV_CHMAP_LAST;
547 return 0;
548}
549
550static int had_chmap_ctl_get(struct snd_kcontrol *kcontrol,
551 struct snd_ctl_elem_value *ucontrol)
552{
553 struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
554 struct snd_intelhad *intelhaddata = info->private_data;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100555 int i;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530556 const struct snd_pcm_chmap_elem *chmap;
557
Takashi Iwaia72ccfb2017-02-15 21:45:06 +0100558 memset(ucontrol->value.integer.value, 0,
559 sizeof(long) * HAD_MAX_CHANNEL);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100560 mutex_lock(&intelhaddata->mutex);
561 if (!intelhaddata->chmap->chmap) {
562 mutex_unlock(&intelhaddata->mutex);
Takashi Iwaia72ccfb2017-02-15 21:45:06 +0100563 return 0;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100564 }
565
Jerome Anand5dab11d2017-01-25 04:27:52 +0530566 chmap = intelhaddata->chmap->chmap;
Takashi Iwaic75b0472017-01-31 15:49:15 +0100567 for (i = 0; i < chmap->channels; i++)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530568 ucontrol->value.integer.value[i] = chmap->map[i];
Takashi Iwai8f8d1d72017-02-01 17:24:02 +0100569 mutex_unlock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530570
571 return 0;
572}
573
574static int had_register_chmap_ctls(struct snd_intelhad *intelhaddata,
575 struct snd_pcm *pcm)
576{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100577 int err;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530578
579 err = snd_pcm_add_chmap_ctls(pcm, SNDRV_PCM_STREAM_PLAYBACK,
580 NULL, 0, (unsigned long)intelhaddata,
581 &intelhaddata->chmap);
582 if (err < 0)
583 return err;
584
585 intelhaddata->chmap->private_data = intelhaddata;
Takashi Iwaie9d65ab2017-01-31 16:11:27 +0100586 intelhaddata->chmap->kctl->info = had_chmap_ctl_info;
587 intelhaddata->chmap->kctl->get = had_chmap_ctl_get;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530588 intelhaddata->chmap->chmap = NULL;
589 return 0;
590}
591
Takashi Iwai76296ef2017-01-30 16:09:11 +0100592/*
Takashi Iwai44684f62017-02-02 17:27:40 +0100593 * Initialize Data Island Packets registers
Jerome Anand5dab11d2017-01-25 04:27:52 +0530594 * This function is called in the prepare callback
595 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100596static void had_prog_dip(struct snd_pcm_substream *substream,
597 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530598{
599 int i;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100600 union aud_ctrl_st ctrl_state = {.regval = 0};
601 union aud_info_frame2 frame2 = {.regval = 0};
602 union aud_info_frame3 frame3 = {.regval = 0};
Jerome Anand5dab11d2017-01-25 04:27:52 +0530603 u8 checksum = 0;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600604 u32 info_frame;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530605 int channels;
Takashi Iwai36ed3462017-02-02 17:06:38 +0100606 int ca;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530607
608 channels = substream->runtime->channels;
609
Takashi Iwai7ceba752017-02-02 15:58:35 +0100610 had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530611
Takashi Iwaib5562902017-02-04 22:05:33 +0100612 ca = had_channel_allocation(intelhaddata, channels);
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600613 if (intelhaddata->dp_output) {
614 info_frame = DP_INFO_FRAME_WORD1;
Takashi Iwai36ed3462017-02-02 17:06:38 +0100615 frame2.regval = (substream->runtime->channels - 1) | (ca << 24);
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600616 } else {
617 info_frame = HDMI_INFO_FRAME_WORD1;
Takashi Iwai7ceba752017-02-02 15:58:35 +0100618 frame2.regx.chnl_cnt = substream->runtime->channels - 1;
Takashi Iwai36ed3462017-02-02 17:06:38 +0100619 frame3.regx.chnl_alloc = ca;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530620
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100621 /* Calculte the byte wide checksum for all valid DIP words */
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600622 for (i = 0; i < BYTES_PER_WORD; i++)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100623 checksum += (info_frame >> (i * 8)) & 0xff;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600624 for (i = 0; i < BYTES_PER_WORD; i++)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100625 checksum += (frame2.regval >> (i * 8)) & 0xff;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600626 for (i = 0; i < BYTES_PER_WORD; i++)
Takashi Iwai7ceba752017-02-02 15:58:35 +0100627 checksum += (frame3.regval >> (i * 8)) & 0xff;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530628
Takashi Iwai7ceba752017-02-02 15:58:35 +0100629 frame2.regx.chksum = -(checksum);
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600630 }
Jerome Anand5dab11d2017-01-25 04:27:52 +0530631
Takashi Iwai4151ee82017-01-31 18:14:15 +0100632 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, info_frame);
Takashi Iwai7ceba752017-02-02 15:58:35 +0100633 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame2.regval);
634 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, frame3.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530635
636 /* program remaining DIP words with zero */
637 for (i = 0; i < HAD_MAX_DIP_WORDS-VALID_DIP_WORDS; i++)
Takashi Iwai4151ee82017-01-31 18:14:15 +0100638 had_write_register(intelhaddata, AUD_HDMIW_INFOFR, 0x0);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530639
Takashi Iwai7ceba752017-02-02 15:58:35 +0100640 ctrl_state.regx.dip_freq = 1;
641 ctrl_state.regx.dip_en_sta = 1;
642 had_write_register(intelhaddata, AUD_CNTL_ST, ctrl_state.regval);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530643}
644
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600645static int had_calculate_maud_value(u32 aud_samp_freq, u32 link_rate)
646{
647 u32 maud_val;
648
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100649 /* Select maud according to DP 1.2 spec */
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600650 if (link_rate == DP_2_7_GHZ) {
651 switch (aud_samp_freq) {
652 case AUD_SAMPLE_RATE_32:
653 maud_val = AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL;
654 break;
655
656 case AUD_SAMPLE_RATE_44_1:
657 maud_val = AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL;
658 break;
659
660 case AUD_SAMPLE_RATE_48:
661 maud_val = AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL;
662 break;
663
664 case AUD_SAMPLE_RATE_88_2:
665 maud_val = AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL;
666 break;
667
668 case AUD_SAMPLE_RATE_96:
669 maud_val = AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL;
670 break;
671
672 case AUD_SAMPLE_RATE_176_4:
673 maud_val = AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL;
674 break;
675
676 case HAD_MAX_RATE:
677 maud_val = HAD_MAX_RATE_DP_2_7_MAUD_VAL;
678 break;
679
680 default:
681 maud_val = -EINVAL;
682 break;
683 }
684 } else if (link_rate == DP_1_62_GHZ) {
685 switch (aud_samp_freq) {
686 case AUD_SAMPLE_RATE_32:
687 maud_val = AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL;
688 break;
689
690 case AUD_SAMPLE_RATE_44_1:
691 maud_val = AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL;
692 break;
693
694 case AUD_SAMPLE_RATE_48:
695 maud_val = AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL;
696 break;
697
698 case AUD_SAMPLE_RATE_88_2:
699 maud_val = AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL;
700 break;
701
702 case AUD_SAMPLE_RATE_96:
703 maud_val = AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL;
704 break;
705
706 case AUD_SAMPLE_RATE_176_4:
707 maud_val = AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL;
708 break;
709
710 case HAD_MAX_RATE:
711 maud_val = HAD_MAX_RATE_DP_1_62_MAUD_VAL;
712 break;
713
714 default:
715 maud_val = -EINVAL;
716 break;
717 }
718 } else
719 maud_val = -EINVAL;
720
721 return maud_val;
722}
723
Takashi Iwai76296ef2017-01-30 16:09:11 +0100724/*
Takashi Iwai44684f62017-02-02 17:27:40 +0100725 * Program HDMI audio CTS value
Jerome Anand5dab11d2017-01-25 04:27:52 +0530726 *
727 * @aud_samp_freq: sampling frequency of audio data
728 * @tmds: sampling frequency of the display data
Takashi Iwaib5562902017-02-04 22:05:33 +0100729 * @link_rate: DP link rate
Jerome Anand5dab11d2017-01-25 04:27:52 +0530730 * @n_param: N value, depends on aud_samp_freq
Takashi Iwaib5562902017-02-04 22:05:33 +0100731 * @intelhaddata: substream private data
Jerome Anand5dab11d2017-01-25 04:27:52 +0530732 *
733 * Program CTS register based on the audio and display sampling frequency
734 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100735static void had_prog_cts(u32 aud_samp_freq, u32 tmds, u32 link_rate,
736 u32 n_param, struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530737{
738 u32 cts_val;
739 u64 dividend, divisor;
740
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600741 if (intelhaddata->dp_output) {
742 /* Substitute cts_val with Maud according to DP 1.2 spec*/
743 cts_val = had_calculate_maud_value(aud_samp_freq, link_rate);
744 } else {
745 /* Calculate CTS according to HDMI 1.3a spec*/
746 dividend = (u64)tmds * n_param*1000;
747 divisor = 128 * aud_samp_freq;
748 cts_val = div64_u64(dividend, divisor);
749 }
Takashi Iwaic75b0472017-01-31 15:49:15 +0100750 dev_dbg(intelhaddata->dev, "TMDS value=%d, N value=%d, CTS Value=%d\n",
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600751 tmds, n_param, cts_val);
Takashi Iwai79dda752017-01-30 17:23:39 +0100752 had_write_register(intelhaddata, AUD_HDMI_CTS, (BIT(24) | cts_val));
Jerome Anand5dab11d2017-01-25 04:27:52 +0530753}
754
755static int had_calculate_n_value(u32 aud_samp_freq)
756{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100757 int n_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530758
759 /* Select N according to HDMI 1.3a spec*/
760 switch (aud_samp_freq) {
761 case AUD_SAMPLE_RATE_32:
762 n_val = 4096;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100763 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530764
765 case AUD_SAMPLE_RATE_44_1:
766 n_val = 6272;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100767 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530768
769 case AUD_SAMPLE_RATE_48:
770 n_val = 6144;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100771 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530772
773 case AUD_SAMPLE_RATE_88_2:
774 n_val = 12544;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100775 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530776
777 case AUD_SAMPLE_RATE_96:
778 n_val = 12288;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100779 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530780
781 case AUD_SAMPLE_RATE_176_4:
782 n_val = 25088;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100783 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530784
785 case HAD_MAX_RATE:
786 n_val = 24576;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100787 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530788
789 default:
790 n_val = -EINVAL;
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100791 break;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530792 }
793 return n_val;
794}
795
Takashi Iwai76296ef2017-01-30 16:09:11 +0100796/*
Takashi Iwai44684f62017-02-02 17:27:40 +0100797 * Program HDMI audio N value
Jerome Anand5dab11d2017-01-25 04:27:52 +0530798 *
799 * @aud_samp_freq: sampling frequency of audio data
800 * @n_param: N value, depends on aud_samp_freq
Takashi Iwaib5562902017-02-04 22:05:33 +0100801 * @intelhaddata: substream private data
Jerome Anand5dab11d2017-01-25 04:27:52 +0530802 *
803 * This function is called in the prepare callback.
804 * It programs based on the audio and display sampling frequency
805 */
Takashi Iwaib5562902017-02-04 22:05:33 +0100806static int had_prog_n(u32 aud_samp_freq, u32 *n_param,
807 struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +0530808{
Takashi Iwai2e52f5e2017-01-31 17:09:13 +0100809 int n_val;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530810
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600811 if (intelhaddata->dp_output) {
812 /*
813 * According to DP specs, Maud and Naud values hold
814 * a relationship, which is stated as:
815 * Maud/Naud = 512 * fs / f_LS_Clk
816 * where, fs is the sampling frequency of the audio stream
817 * and Naud is 32768 for Async clock.
818 */
819
820 n_val = DP_NAUD_VAL;
821 } else
822 n_val = had_calculate_n_value(aud_samp_freq);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530823
824 if (n_val < 0)
825 return n_val;
826
Takashi Iwai79dda752017-01-30 17:23:39 +0100827 had_write_register(intelhaddata, AUD_N_ENABLE, (BIT(24) | n_val));
Jerome Anand5dab11d2017-01-25 04:27:52 +0530828 *n_param = n_val;
829 return 0;
830}
831
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100832/*
833 * PCM ring buffer handling
834 *
835 * The hardware provides a ring buffer with the fixed 4 buffer descriptors
836 * (BDs). The driver maps these 4 BDs onto the PCM ring buffer. The mapping
837 * moves at each period elapsed. The below illustrates how it works:
838 *
839 * At time=0
840 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
841 * BD | 0 | 1 | 2 | 3 |
842 *
843 * At time=1 (period elapsed)
844 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
845 * BD | 1 | 2 | 3 | 0 |
846 *
847 * At time=2 (second period elapsed)
848 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
849 * BD | 2 | 3 | 0 | 1 |
850 *
851 * The bd_head field points to the index of the BD to be read. It's also the
852 * position to be filled at next. The pcm_head and the pcm_filled fields
853 * point to the indices of the current position and of the next position to
854 * be filled, respectively. For PCM buffer there are both _head and _filled
855 * because they may be difference when nperiods > 4. For example, in the
856 * example above at t=1, bd_head=1 and pcm_head=1 while pcm_filled=5:
857 *
858 * pcm_head (=1) --v v-- pcm_filled (=5)
859 * PCM | 0 | 1 | 2 | 3 | 4 | 5 | .... |n-1|
860 * BD | 1 | 2 | 3 | 0 |
861 * bd_head (=1) --^ ^-- next to fill (= bd_head)
862 *
863 * For nperiods < 4, the remaining BDs out of 4 are marked as invalid, so that
864 * the hardware skips those BDs in the loop.
Takashi Iwai8d48c012017-02-07 08:05:46 +0100865 *
866 * An exceptional setup is the case with nperiods=1. Since we have to update
867 * BDs after finishing one BD processing, we'd need at least two BDs, where
868 * both BDs point to the same content, the same address, the same size of the
869 * whole PCM buffer.
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100870 */
871
872#define AUD_BUF_ADDR(x) (AUD_BUF_A_ADDR + (x) * HAD_REG_WIDTH)
873#define AUD_BUF_LEN(x) (AUD_BUF_A_LENGTH + (x) * HAD_REG_WIDTH)
874
875/* Set up a buffer descriptor at the "filled" position */
876static void had_prog_bd(struct snd_pcm_substream *substream,
877 struct snd_intelhad *intelhaddata)
878{
879 int idx = intelhaddata->bd_head;
880 int ofs = intelhaddata->pcmbuf_filled * intelhaddata->period_bytes;
881 u32 addr = substream->runtime->dma_addr + ofs;
882
Takashi Iwaie8de9852017-02-07 08:09:12 +0100883 addr |= AUD_BUF_VALID;
884 if (!substream->runtime->no_period_wakeup)
885 addr |= AUD_BUF_INTR_EN;
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100886 had_write_register(intelhaddata, AUD_BUF_ADDR(idx), addr);
887 had_write_register(intelhaddata, AUD_BUF_LEN(idx),
888 intelhaddata->period_bytes);
889
890 /* advance the indices to the next */
891 intelhaddata->bd_head++;
892 intelhaddata->bd_head %= intelhaddata->num_bds;
893 intelhaddata->pcmbuf_filled++;
894 intelhaddata->pcmbuf_filled %= substream->runtime->periods;
895}
896
897/* invalidate a buffer descriptor with the given index */
898static void had_invalidate_bd(struct snd_intelhad *intelhaddata,
899 int idx)
900{
901 had_write_register(intelhaddata, AUD_BUF_ADDR(idx), 0);
902 had_write_register(intelhaddata, AUD_BUF_LEN(idx), 0);
903}
904
905/* Initial programming of ring buffer */
906static void had_init_ringbuf(struct snd_pcm_substream *substream,
907 struct snd_intelhad *intelhaddata)
908{
909 struct snd_pcm_runtime *runtime = substream->runtime;
910 int i, num_periods;
911
912 num_periods = runtime->periods;
913 intelhaddata->num_bds = min(num_periods, HAD_NUM_OF_RING_BUFS);
Takashi Iwai8d48c012017-02-07 08:05:46 +0100914 /* set the minimum 2 BDs for num_periods=1 */
915 intelhaddata->num_bds = max(intelhaddata->num_bds, 2U);
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100916 intelhaddata->period_bytes =
917 frames_to_bytes(runtime, runtime->period_size);
918 WARN_ON(intelhaddata->period_bytes & 0x3f);
919
920 intelhaddata->bd_head = 0;
921 intelhaddata->pcmbuf_head = 0;
922 intelhaddata->pcmbuf_filled = 0;
923
924 for (i = 0; i < HAD_NUM_OF_RING_BUFS; i++) {
Takashi Iwai8d48c012017-02-07 08:05:46 +0100925 if (i < intelhaddata->num_bds)
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100926 had_prog_bd(substream, intelhaddata);
927 else /* invalidate the rest */
928 had_invalidate_bd(intelhaddata, i);
929 }
930
931 intelhaddata->bd_head = 0; /* reset at head again before starting */
932}
933
934/* process a bd, advance to the next */
935static void had_advance_ringbuf(struct snd_pcm_substream *substream,
936 struct snd_intelhad *intelhaddata)
937{
938 int num_periods = substream->runtime->periods;
939
940 /* reprogram the next buffer */
941 had_prog_bd(substream, intelhaddata);
942
943 /* proceed to next */
944 intelhaddata->pcmbuf_head++;
945 intelhaddata->pcmbuf_head %= num_periods;
946}
947
948/* process the current BD(s);
949 * returns the current PCM buffer byte position, or -EPIPE for underrun.
950 */
951static int had_process_ringbuf(struct snd_pcm_substream *substream,
952 struct snd_intelhad *intelhaddata)
953{
954 int len, processed;
955 unsigned long flags;
956
957 processed = 0;
958 spin_lock_irqsave(&intelhaddata->had_spinlock, flags);
959 for (;;) {
960 /* get the remaining bytes on the buffer */
961 had_read_register(intelhaddata,
962 AUD_BUF_LEN(intelhaddata->bd_head),
963 &len);
964 if (len < 0 || len > intelhaddata->period_bytes) {
965 dev_dbg(intelhaddata->dev, "Invalid buf length %d\n",
966 len);
967 len = -EPIPE;
968 goto out;
969 }
970
971 if (len > 0) /* OK, this is the current buffer */
972 break;
973
974 /* len=0 => already empty, check the next buffer */
975 if (++processed >= intelhaddata->num_bds) {
976 len = -EPIPE; /* all empty? - report underrun */
977 goto out;
978 }
979 had_advance_ringbuf(substream, intelhaddata);
980 }
981
982 len = intelhaddata->period_bytes - len;
983 len += intelhaddata->period_bytes * intelhaddata->pcmbuf_head;
984 out:
985 spin_unlock_irqrestore(&intelhaddata->had_spinlock, flags);
986 return len;
987}
988
989/* called from irq handler */
990static void had_process_buffer_done(struct snd_intelhad *intelhaddata)
991{
992 struct snd_pcm_substream *substream;
993
Takashi Iwaie1b239f32017-02-03 00:01:18 +0100994 substream = had_substream_get(intelhaddata);
995 if (!substream)
996 return; /* no stream? - bail out */
997
Takashi Iwaibe9a2e92017-02-15 22:05:34 +0100998 if (!intelhaddata->connected) {
999 snd_pcm_stop_xrun(substream);
1000 goto out; /* disconnected? - bail out */
1001 }
1002
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001003 /* process or stop the stream */
1004 if (had_process_ringbuf(substream, intelhaddata) < 0)
1005 snd_pcm_stop_xrun(substream);
1006 else
1007 snd_pcm_period_elapsed(substream);
1008
Takashi Iwaibe9a2e92017-02-15 22:05:34 +01001009 out:
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001010 had_substream_put(intelhaddata);
1011}
1012
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001013/*
1014 * The interrupt status 'sticky' bits might not be cleared by
1015 * setting '1' to that bit once...
1016 */
1017static void wait_clear_underrun_bit(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301018{
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001019 int i;
1020 u32 val;
1021
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001022 for (i = 0; i < 100; i++) {
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001023 /* clear bit30, 31 AUD_HDMI_STATUS */
1024 had_read_register(intelhaddata, AUD_HDMI_STATUS, &val);
Takashi Iwai77531be2017-02-07 12:17:23 +01001025 if (!(val & AUD_HDMI_STATUS_MASK_UNDERRUN))
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001026 return;
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001027 udelay(100);
1028 cond_resched();
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001029 had_write_register(intelhaddata, AUD_HDMI_STATUS, val);
1030 }
1031 dev_err(intelhaddata->dev, "Unable to clear UNDERRUN bits\n");
1032}
1033
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001034/* Perform some reset procedure but only when need_reset is set;
1035 * this is called from prepare or hw_free callbacks once after trigger STOP
1036 * or underrun has been processed in order to settle down the h/w state.
1037 */
1038static void had_do_reset(struct snd_intelhad *intelhaddata)
1039{
Takashi Iwai28ed1252017-02-15 22:02:10 +01001040 if (!intelhaddata->need_reset || !intelhaddata->connected)
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001041 return;
1042
1043 /* Reset buffer pointers */
1044 had_reset_audio(intelhaddata);
1045 wait_clear_underrun_bit(intelhaddata);
1046 intelhaddata->need_reset = false;
1047}
1048
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001049/* called from irq handler */
1050static void had_process_buffer_underrun(struct snd_intelhad *intelhaddata)
1051{
1052 struct snd_pcm_substream *substream;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301053
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001054 /* Report UNDERRUN error to above layers */
1055 substream = had_substream_get(intelhaddata);
1056 if (substream) {
1057 snd_pcm_stop_xrun(substream);
1058 had_substream_put(intelhaddata);
1059 }
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001060 intelhaddata->need_reset = true;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301061}
1062
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001063/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001064 * ALSA PCM open callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301065 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001066static int had_pcm_open(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301067{
1068 struct snd_intelhad *intelhaddata;
1069 struct snd_pcm_runtime *runtime;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301070 int retval;
1071
Jerome Anand5dab11d2017-01-25 04:27:52 +05301072 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301073 runtime = substream->runtime;
1074
Takashi Iwai182cdf22017-02-02 14:43:39 +01001075 pm_runtime_get_sync(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301076
Jerome Anand5dab11d2017-01-25 04:27:52 +05301077 /* set the runtime hw parameter with local snd_pcm_hardware struct */
Takashi Iwaib5562902017-02-04 22:05:33 +01001078 runtime->hw = had_pcm_hardware;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301079
Jerome Anand5dab11d2017-01-25 04:27:52 +05301080 retval = snd_pcm_hw_constraint_integer(runtime,
1081 SNDRV_PCM_HW_PARAM_PERIODS);
1082 if (retval < 0)
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001083 goto error;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301084
1085 /* Make sure, that the period size is always aligned
1086 * 64byte boundary
1087 */
1088 retval = snd_pcm_hw_constraint_step(substream->runtime, 0,
1089 SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 64);
Takashi Iwai73997b02017-02-02 17:38:50 +01001090 if (retval < 0)
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001091 goto error;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301092
Takashi Iwai85bd8742017-02-07 13:33:17 +01001093 retval = snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
1094 if (retval < 0)
1095 goto error;
1096
Takashi Iwai73997b02017-02-02 17:38:50 +01001097 /* expose PCM substream */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001098 spin_lock_irq(&intelhaddata->had_spinlock);
1099 intelhaddata->stream_info.substream = substream;
1100 intelhaddata->stream_info.substream_refcount++;
1101 spin_unlock_irq(&intelhaddata->had_spinlock);
1102
Jerome Anand5dab11d2017-01-25 04:27:52 +05301103 return retval;
Takashi Iwaifa5dfe62017-02-01 22:03:26 +01001104 error:
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001105 pm_runtime_mark_last_busy(intelhaddata->dev);
1106 pm_runtime_put_autosuspend(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301107 return retval;
1108}
1109
Takashi Iwaidf76df12017-01-31 16:04:10 +01001110/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001111 * ALSA PCM close callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301112 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001113static int had_pcm_close(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301114{
1115 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301116
Jerome Anand5dab11d2017-01-25 04:27:52 +05301117 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301118
Takashi Iwai73997b02017-02-02 17:38:50 +01001119 /* unreference and sync with the pending PCM accesses */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001120 spin_lock_irq(&intelhaddata->had_spinlock);
1121 intelhaddata->stream_info.substream = NULL;
1122 intelhaddata->stream_info.substream_refcount--;
1123 while (intelhaddata->stream_info.substream_refcount > 0) {
1124 spin_unlock_irq(&intelhaddata->had_spinlock);
1125 cpu_relax();
1126 spin_lock_irq(&intelhaddata->had_spinlock);
1127 }
1128 spin_unlock_irq(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301129
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001130 pm_runtime_mark_last_busy(intelhaddata->dev);
1131 pm_runtime_put_autosuspend(intelhaddata->dev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301132 return 0;
1133}
1134
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001135/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001136 * ALSA PCM hw_params callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301137 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001138static int had_pcm_hw_params(struct snd_pcm_substream *substream,
1139 struct snd_pcm_hw_params *hw_params)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301140{
Takashi Iwaic75b0472017-01-31 15:49:15 +01001141 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301142 unsigned long addr;
1143 int pages, buf_size, retval;
1144
Takashi Iwaic75b0472017-01-31 15:49:15 +01001145 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301146 buf_size = params_buffer_bytes(hw_params);
1147 retval = snd_pcm_lib_malloc_pages(substream, buf_size);
1148 if (retval < 0)
1149 return retval;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001150 dev_dbg(intelhaddata->dev, "%s:allocated memory = %d\n",
1151 __func__, buf_size);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301152 /* mark the pages as uncached region */
1153 addr = (unsigned long) substream->runtime->dma_area;
1154 pages = (substream->runtime->dma_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
1155 retval = set_memory_uc(addr, pages);
1156 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001157 dev_err(intelhaddata->dev, "set_memory_uc failed.Error:%d\n",
1158 retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301159 return retval;
1160 }
1161 memset(substream->runtime->dma_area, 0, buf_size);
1162
1163 return retval;
1164}
1165
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001166/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001167 * ALSA PCM hw_free callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301168 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001169static int had_pcm_hw_free(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301170{
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001171 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301172 unsigned long addr;
1173 u32 pages;
1174
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001175 intelhaddata = snd_pcm_substream_chip(substream);
1176 had_do_reset(intelhaddata);
1177
Jerome Anand5dab11d2017-01-25 04:27:52 +05301178 /* mark back the pages as cached/writeback region before the free */
1179 if (substream->runtime->dma_area != NULL) {
1180 addr = (unsigned long) substream->runtime->dma_area;
1181 pages = (substream->runtime->dma_bytes + PAGE_SIZE - 1) /
1182 PAGE_SIZE;
1183 set_memory_wb(addr, pages);
1184 return snd_pcm_lib_free_pages(substream);
1185 }
1186 return 0;
1187}
1188
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001189/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001190 * ALSA PCM trigger callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301191 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001192static int had_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301193{
Takashi Iwaida864802017-01-31 13:52:22 +01001194 int retval = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301195 struct snd_intelhad *intelhaddata;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301196
Jerome Anand5dab11d2017-01-25 04:27:52 +05301197 intelhaddata = snd_pcm_substream_chip(substream);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301198
Takashi Iwaidf42cb42017-02-12 11:35:44 +01001199 spin_lock(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301200 switch (cmd) {
1201 case SNDRV_PCM_TRIGGER_START:
Takashi Iwai182cdf22017-02-02 14:43:39 +01001202 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1203 case SNDRV_PCM_TRIGGER_RESUME:
Jerome Anand5dab11d2017-01-25 04:27:52 +05301204 /* Enable Audio */
Takashi Iwai075a1d42017-02-07 07:55:27 +01001205 had_ack_irqs(intelhaddata); /* FIXME: do we need this? */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001206 had_enable_audio(intelhaddata, true);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301207 break;
1208
1209 case SNDRV_PCM_TRIGGER_STOP:
Takashi Iwai182cdf22017-02-02 14:43:39 +01001210 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
Jerome Anand5dab11d2017-01-25 04:27:52 +05301211 /* Disable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001212 had_enable_audio(intelhaddata, false);
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001213 intelhaddata->need_reset = true;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301214 break;
1215
1216 default:
1217 retval = -EINVAL;
1218 }
Takashi Iwaidf42cb42017-02-12 11:35:44 +01001219 spin_unlock(&intelhaddata->had_spinlock);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301220 return retval;
1221}
1222
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001223/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001224 * ALSA PCM prepare callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301225 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001226static int had_pcm_prepare(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301227{
1228 int retval;
1229 u32 disp_samp_freq, n_param;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001230 u32 link_rate = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301231 struct snd_intelhad *intelhaddata;
1232 struct snd_pcm_runtime *runtime;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301233
Jerome Anand5dab11d2017-01-25 04:27:52 +05301234 intelhaddata = snd_pcm_substream_chip(substream);
1235 runtime = substream->runtime;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301236
Takashi Iwaic75b0472017-01-31 15:49:15 +01001237 dev_dbg(intelhaddata->dev, "period_size=%d\n",
Jerome Anand5dab11d2017-01-25 04:27:52 +05301238 (int)frames_to_bytes(runtime, runtime->period_size));
Takashi Iwaic75b0472017-01-31 15:49:15 +01001239 dev_dbg(intelhaddata->dev, "periods=%d\n", runtime->periods);
1240 dev_dbg(intelhaddata->dev, "buffer_size=%d\n",
1241 (int)snd_pcm_lib_buffer_bytes(substream));
1242 dev_dbg(intelhaddata->dev, "rate=%d\n", runtime->rate);
1243 dev_dbg(intelhaddata->dev, "channels=%d\n", runtime->channels);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301244
Takashi Iwaie2acecf2017-02-11 08:21:56 +01001245 had_do_reset(intelhaddata);
1246
Jerome Anand5dab11d2017-01-25 04:27:52 +05301247 /* Get N value in KHz */
Takashi Iwaida864802017-01-31 13:52:22 +01001248 disp_samp_freq = intelhaddata->tmds_clock_speed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301249
Takashi Iwaib5562902017-02-04 22:05:33 +01001250 retval = had_prog_n(substream->runtime->rate, &n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301251 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001252 dev_err(intelhaddata->dev,
1253 "programming N value failed %#x\n", retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301254 goto prep_end;
1255 }
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001256
1257 if (intelhaddata->dp_output)
Takashi Iwaida864802017-01-31 13:52:22 +01001258 link_rate = intelhaddata->link_rate;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001259
Takashi Iwaib5562902017-02-04 22:05:33 +01001260 had_prog_cts(substream->runtime->rate, disp_samp_freq, link_rate,
1261 n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301262
Takashi Iwaib5562902017-02-04 22:05:33 +01001263 had_prog_dip(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301264
Takashi Iwaib5562902017-02-04 22:05:33 +01001265 retval = had_init_audio_ctrl(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301266
1267 /* Prog buffer address */
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001268 had_init_ringbuf(substream, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301269
1270 /*
1271 * Program channel mapping in following order:
1272 * FL, FR, C, LFE, RL, RR
1273 */
1274
Takashi Iwai79dda752017-01-30 17:23:39 +01001275 had_write_register(intelhaddata, AUD_BUF_CH_SWAP, SWAP_LFE_CENTER);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301276
1277prep_end:
1278 return retval;
1279}
1280
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001281/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001282 * ALSA PCM pointer callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301283 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001284static snd_pcm_uframes_t had_pcm_pointer(struct snd_pcm_substream *substream)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301285{
1286 struct snd_intelhad *intelhaddata;
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001287 int len;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301288
Jerome Anand5dab11d2017-01-25 04:27:52 +05301289 intelhaddata = snd_pcm_substream_chip(substream);
1290
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001291 if (!intelhaddata->connected)
Takashi Iwai79f439e2017-01-31 16:46:44 +01001292 return SNDRV_PCM_POS_XRUN;
1293
Takashi Iwaie1b239f32017-02-03 00:01:18 +01001294 len = had_process_ringbuf(substream, intelhaddata);
1295 if (len < 0)
1296 return SNDRV_PCM_POS_XRUN;
Takashi Iwai8d48c012017-02-07 08:05:46 +01001297 len = bytes_to_frames(substream->runtime, len);
1298 /* wrapping may happen when periods=1 */
1299 len %= substream->runtime->buffer_size;
1300 return len;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301301}
1302
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001303/*
Takashi Iwai44684f62017-02-02 17:27:40 +01001304 * ALSA PCM mmap callback
Jerome Anand5dab11d2017-01-25 04:27:52 +05301305 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001306static int had_pcm_mmap(struct snd_pcm_substream *substream,
1307 struct vm_area_struct *vma)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301308{
Jerome Anand5dab11d2017-01-25 04:27:52 +05301309 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1310 return remap_pfn_range(vma, vma->vm_start,
1311 substream->dma_buffer.addr >> PAGE_SHIFT,
1312 vma->vm_end - vma->vm_start, vma->vm_page_prot);
1313}
1314
Takashi Iwai73997b02017-02-02 17:38:50 +01001315/*
1316 * ALSA PCM ops
1317 */
Takashi Iwaib5562902017-02-04 22:05:33 +01001318static const struct snd_pcm_ops had_pcm_ops = {
1319 .open = had_pcm_open,
1320 .close = had_pcm_close,
Takashi Iwai73997b02017-02-02 17:38:50 +01001321 .ioctl = snd_pcm_lib_ioctl,
Takashi Iwaib5562902017-02-04 22:05:33 +01001322 .hw_params = had_pcm_hw_params,
1323 .hw_free = had_pcm_hw_free,
1324 .prepare = had_pcm_prepare,
1325 .trigger = had_pcm_trigger,
1326 .pointer = had_pcm_pointer,
1327 .mmap = had_pcm_mmap,
Takashi Iwai73997b02017-02-02 17:38:50 +01001328};
1329
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001330/* process mode change of the running stream; called in mutex */
Takashi Iwaib5562902017-02-04 22:05:33 +01001331static int had_process_mode_change(struct snd_intelhad *intelhaddata)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301332{
Takashi Iwaida864802017-01-31 13:52:22 +01001333 struct snd_pcm_substream *substream;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301334 int retval = 0;
1335 u32 disp_samp_freq, n_param;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001336 u32 link_rate = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301337
Takashi Iwai313d9f22017-02-02 13:00:12 +01001338 substream = had_substream_get(intelhaddata);
1339 if (!substream)
Takashi Iwaida864802017-01-31 13:52:22 +01001340 return 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301341
1342 /* Disable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001343 had_enable_audio(intelhaddata, false);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301344
1345 /* Update CTS value */
Takashi Iwaida864802017-01-31 13:52:22 +01001346 disp_samp_freq = intelhaddata->tmds_clock_speed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301347
Takashi Iwaib5562902017-02-04 22:05:33 +01001348 retval = had_prog_n(substream->runtime->rate, &n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301349 if (retval) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001350 dev_err(intelhaddata->dev,
1351 "programming N value failed %#x\n", retval);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301352 goto out;
1353 }
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001354
1355 if (intelhaddata->dp_output)
Takashi Iwaida864802017-01-31 13:52:22 +01001356 link_rate = intelhaddata->link_rate;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -06001357
Takashi Iwaib5562902017-02-04 22:05:33 +01001358 had_prog_cts(substream->runtime->rate, disp_samp_freq, link_rate,
1359 n_param, intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301360
1361 /* Enable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001362 had_enable_audio(intelhaddata, true);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301363
1364out:
Takashi Iwai313d9f22017-02-02 13:00:12 +01001365 had_substream_put(intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301366 return retval;
1367}
1368
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001369/* process hot plug, called from wq with mutex locked */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001370static void had_process_hot_plug(struct snd_intelhad *intelhaddata)
Takashi Iwai372d8552017-01-31 13:57:58 +01001371{
Takashi Iwai372d8552017-01-31 13:57:58 +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 connected\n");
Takashi Iwaibcce7752017-02-01 17:18:20 +01001377 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001378 return;
Takashi Iwai372d8552017-01-31 13:57:58 +01001379 }
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001380
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001381 /* Disable Audio */
1382 had_enable_audio(intelhaddata, false);
1383
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001384 intelhaddata->connected = true;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001385 dev_dbg(intelhaddata->dev,
1386 "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_CONNECTED\n",
Takashi Iwai372d8552017-01-31 13:57:58 +01001387 __func__, __LINE__);
Takashi Iwaibcce7752017-02-01 17:18:20 +01001388 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai372d8552017-01-31 13:57:58 +01001389
Takashi Iwai2d42c032017-02-15 22:08:21 +01001390 had_build_channel_allocation_map(intelhaddata);
1391
1392 /* Report to above ALSA layer */
Takashi Iwai313d9f22017-02-02 13:00:12 +01001393 substream = had_substream_get(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001394 if (substream) {
Takashi Iwai5def9012017-02-15 21:36:38 +01001395 snd_pcm_stop_xrun(substream);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001396 had_substream_put(intelhaddata);
Takashi Iwai372d8552017-01-31 13:57:58 +01001397 }
1398
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001399 snd_jack_report(intelhaddata->jack, SND_JACK_AVOUT);
Takashi Iwai372d8552017-01-31 13:57:58 +01001400}
1401
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001402/* process hot unplug, called from wq with mutex locked */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001403static void had_process_hot_unplug(struct snd_intelhad *intelhaddata)
Takashi Iwai372d8552017-01-31 13:57:58 +01001404{
Takashi Iwai313d9f22017-02-02 13:00:12 +01001405 struct snd_pcm_substream *substream;
Takashi Iwai372d8552017-01-31 13:57:58 +01001406
Takashi Iwaibcce7752017-02-01 17:18:20 +01001407 spin_lock_irq(&intelhaddata->had_spinlock);
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001408 if (!intelhaddata->connected) {
Takashi Iwaic75b0472017-01-31 15:49:15 +01001409 dev_dbg(intelhaddata->dev, "Device already disconnected\n");
Takashi Iwaibcce7752017-02-01 17:18:20 +01001410 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai2d42c032017-02-15 22:08:21 +01001411 return;
Takashi Iwai372d8552017-01-31 13:57:58 +01001412
Takashi Iwai372d8552017-01-31 13:57:58 +01001413 }
1414
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001415 /* Disable Audio */
Takashi Iwai40ce4b52017-02-07 16:17:06 +01001416 had_enable_audio(intelhaddata, false);
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001417
Takashi Iwai91b0cb02017-02-02 17:46:49 +01001418 intelhaddata->connected = false;
Takashi Iwaic75b0472017-01-31 15:49:15 +01001419 dev_dbg(intelhaddata->dev,
1420 "%s @ %d:DEBUG PLUG/UNPLUG : HAD_DRV_DISCONNECTED\n",
Takashi Iwai372d8552017-01-31 13:57:58 +01001421 __func__, __LINE__);
Takashi Iwaibcce7752017-02-01 17:18:20 +01001422 spin_unlock_irq(&intelhaddata->had_spinlock);
Takashi Iwai313d9f22017-02-02 13:00:12 +01001423
Takashi Iwai372d8552017-01-31 13:57:58 +01001424 kfree(intelhaddata->chmap->chmap);
1425 intelhaddata->chmap->chmap = NULL;
Takashi Iwai2d42c032017-02-15 22:08:21 +01001426
1427 /* Report to above ALSA layer */
1428 substream = had_substream_get(intelhaddata);
1429 if (substream) {
1430 snd_pcm_stop_xrun(substream);
1431 had_substream_put(intelhaddata);
1432 }
1433
1434 snd_jack_report(intelhaddata->jack, 0);
Takashi Iwai372d8552017-01-31 13:57:58 +01001435}
1436
Takashi Iwai73997b02017-02-02 17:38:50 +01001437/*
1438 * ALSA iec958 and ELD controls
1439 */
Jerome Anand5dab11d2017-01-25 04:27:52 +05301440
Jerome Anand5dab11d2017-01-25 04:27:52 +05301441static int had_iec958_info(struct snd_kcontrol *kcontrol,
1442 struct snd_ctl_elem_info *uinfo)
1443{
1444 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1445 uinfo->count = 1;
1446 return 0;
1447}
1448
1449static int had_iec958_get(struct snd_kcontrol *kcontrol,
1450 struct snd_ctl_elem_value *ucontrol)
1451{
1452 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
1453
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001454 mutex_lock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301455 ucontrol->value.iec958.status[0] = (intelhaddata->aes_bits >> 0) & 0xff;
1456 ucontrol->value.iec958.status[1] = (intelhaddata->aes_bits >> 8) & 0xff;
1457 ucontrol->value.iec958.status[2] =
1458 (intelhaddata->aes_bits >> 16) & 0xff;
1459 ucontrol->value.iec958.status[3] =
1460 (intelhaddata->aes_bits >> 24) & 0xff;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001461 mutex_unlock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301462 return 0;
1463}
Takashi Iwai372d8552017-01-31 13:57:58 +01001464
Jerome Anand5dab11d2017-01-25 04:27:52 +05301465static int had_iec958_mask_get(struct snd_kcontrol *kcontrol,
1466 struct snd_ctl_elem_value *ucontrol)
1467{
1468 ucontrol->value.iec958.status[0] = 0xff;
1469 ucontrol->value.iec958.status[1] = 0xff;
1470 ucontrol->value.iec958.status[2] = 0xff;
1471 ucontrol->value.iec958.status[3] = 0xff;
1472 return 0;
1473}
Takashi Iwai372d8552017-01-31 13:57:58 +01001474
Jerome Anand5dab11d2017-01-25 04:27:52 +05301475static int had_iec958_put(struct snd_kcontrol *kcontrol,
1476 struct snd_ctl_elem_value *ucontrol)
1477{
1478 unsigned int val;
1479 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001480 int changed = 0;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301481
Jerome Anand5dab11d2017-01-25 04:27:52 +05301482 val = (ucontrol->value.iec958.status[0] << 0) |
1483 (ucontrol->value.iec958.status[1] << 8) |
1484 (ucontrol->value.iec958.status[2] << 16) |
1485 (ucontrol->value.iec958.status[3] << 24);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001486 mutex_lock(&intelhaddata->mutex);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301487 if (intelhaddata->aes_bits != val) {
1488 intelhaddata->aes_bits = val;
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001489 changed = 1;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301490 }
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001491 mutex_unlock(&intelhaddata->mutex);
1492 return changed;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301493}
1494
Takashi Iwai4aedb942017-02-02 16:38:39 +01001495static int had_ctl_eld_info(struct snd_kcontrol *kcontrol,
1496 struct snd_ctl_elem_info *uinfo)
1497{
1498 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
1499 uinfo->count = HDMI_MAX_ELD_BYTES;
1500 return 0;
1501}
1502
1503static int had_ctl_eld_get(struct snd_kcontrol *kcontrol,
1504 struct snd_ctl_elem_value *ucontrol)
1505{
1506 struct snd_intelhad *intelhaddata = snd_kcontrol_chip(kcontrol);
1507
1508 mutex_lock(&intelhaddata->mutex);
1509 memcpy(ucontrol->value.bytes.data, intelhaddata->eld,
1510 HDMI_MAX_ELD_BYTES);
1511 mutex_unlock(&intelhaddata->mutex);
1512 return 0;
1513}
1514
Takashi Iwai73997b02017-02-02 17:38:50 +01001515static const struct snd_kcontrol_new had_controls[] = {
Takashi Iwai4aedb942017-02-02 16:38:39 +01001516 {
1517 .access = SNDRV_CTL_ELEM_ACCESS_READ,
1518 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1519 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, MASK),
1520 .info = had_iec958_info, /* shared */
1521 .get = had_iec958_mask_get,
1522 },
1523 {
1524 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1525 .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
1526 .info = had_iec958_info,
1527 .get = had_iec958_get,
1528 .put = had_iec958_put,
1529 },
1530 {
1531 .access = (SNDRV_CTL_ELEM_ACCESS_READ |
1532 SNDRV_CTL_ELEM_ACCESS_VOLATILE),
1533 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
1534 .name = "ELD",
1535 .info = had_ctl_eld_info,
1536 .get = had_ctl_eld_get,
1537 },
Jerome Anand5dab11d2017-01-25 04:27:52 +05301538};
1539
Takashi Iwai73997b02017-02-02 17:38:50 +01001540/*
1541 * audio interrupt handler
1542 */
Takashi Iwaida864802017-01-31 13:52:22 +01001543static irqreturn_t display_pipe_interrupt_handler(int irq, void *dev_id)
1544{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001545 struct snd_intelhad_card *card_ctx = dev_id;
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001546 u32 audio_stat[3] = {};
1547 int pipe, port;
1548
1549 for_each_pipe(card_ctx, pipe) {
1550 /* use raw register access to ack IRQs even while disconnected */
1551 audio_stat[pipe] = had_read_register_raw(card_ctx, pipe,
1552 AUD_HDMI_STATUS) &
1553 (HDMI_AUDIO_UNDERRUN | HDMI_AUDIO_BUFFER_DONE);
1554
1555 if (audio_stat[pipe])
1556 had_write_register_raw(card_ctx, pipe,
1557 AUD_HDMI_STATUS, audio_stat[pipe]);
1558 }
Takashi Iwaida864802017-01-31 13:52:22 +01001559
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001560 for_each_port(card_ctx, port) {
1561 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001562 int pipe = ctx->pipe;
Takashi Iwaida864802017-01-31 13:52:22 +01001563
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001564 if (pipe < 0)
1565 continue;
Takashi Iwaida864802017-01-31 13:52:22 +01001566
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001567 if (audio_stat[pipe] & HDMI_AUDIO_BUFFER_DONE)
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001568 had_process_buffer_done(ctx);
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001569 if (audio_stat[pipe] & HDMI_AUDIO_UNDERRUN)
1570 had_process_buffer_underrun(ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001571 }
1572
1573 return IRQ_HANDLED;
1574}
1575
Takashi Iwai73997b02017-02-02 17:38:50 +01001576/*
1577 * monitor plug/unplug notification from i915; just kick off the work
1578 */
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001579static void notify_audio_lpe(struct platform_device *pdev, int port)
Takashi Iwaida864802017-01-31 13:52:22 +01001580{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001581 struct snd_intelhad_card *card_ctx = platform_get_drvdata(pdev);
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001582 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
Takashi Iwaida864802017-01-31 13:52:22 +01001583
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001584 schedule_work(&ctx->hdmi_audio_wq);
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001585}
Takashi Iwaida864802017-01-31 13:52:22 +01001586
Takashi Iwai73997b02017-02-02 17:38:50 +01001587/* the work to handle monitor hot plug/unplug */
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001588static void had_audio_wq(struct work_struct *work)
1589{
1590 struct snd_intelhad *ctx =
1591 container_of(work, struct snd_intelhad, hdmi_audio_wq);
1592 struct intel_hdmi_lpe_audio_pdata *pdata = ctx->dev->platform_data;
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001593 struct intel_hdmi_lpe_audio_port_pdata *ppdata = &pdata->port[ctx->port];
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001594
Takashi Iwai182cdf22017-02-02 14:43:39 +01001595 pm_runtime_get_sync(ctx->dev);
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001596 mutex_lock(&ctx->mutex);
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001597 if (ppdata->pipe < 0) {
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001598 dev_dbg(ctx->dev, "%s: Event: HAD_NOTIFY_HOT_UNPLUG : port = %d\n",
1599 __func__, ctx->port);
1600
Takashi Iwai4aedb942017-02-02 16:38:39 +01001601 memset(ctx->eld, 0, sizeof(ctx->eld)); /* clear the old ELD */
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001602
1603 ctx->dp_output = false;
1604 ctx->tmds_clock_speed = 0;
1605 ctx->link_rate = 0;
1606
1607 /* Shut down the stream */
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001608 had_process_hot_unplug(ctx);
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001609
1610 ctx->pipe = -1;
Takashi Iwaida864802017-01-31 13:52:22 +01001611 } else {
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001612 dev_dbg(ctx->dev, "%s: HAD_NOTIFY_ELD : port = %d, tmds = %d\n",
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001613 __func__, ctx->port, ppdata->ls_clock);
Takashi Iwaida864802017-01-31 13:52:22 +01001614
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001615 memcpy(ctx->eld, ppdata->eld, sizeof(ctx->eld));
Takashi Iwaida864802017-01-31 13:52:22 +01001616
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001617 ctx->dp_output = ppdata->dp_output;
Ville Syrjäläc98ec5b2017-04-27 19:02:24 +03001618 if (ctx->dp_output) {
1619 ctx->tmds_clock_speed = 0;
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001620 ctx->link_rate = ppdata->ls_clock;
Ville Syrjäläc98ec5b2017-04-27 19:02:24 +03001621 } else {
Ville Syrjäläa8562e42017-04-27 19:02:27 +03001622 ctx->tmds_clock_speed = ppdata->ls_clock;
Ville Syrjäläc98ec5b2017-04-27 19:02:24 +03001623 ctx->link_rate = 0;
1624 }
Takashi Iwai0e9c67d2017-02-01 17:53:19 +01001625
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001626 /*
1627 * Shut down the stream before we change
1628 * the pipe assignment for this pcm device
1629 */
Takashi Iwaida864802017-01-31 13:52:22 +01001630 had_process_hot_plug(ctx);
1631
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001632 ctx->pipe = ppdata->pipe;
1633
1634 /* Restart the stream if necessary */
Takashi Iwaib5562902017-02-04 22:05:33 +01001635 had_process_mode_change(ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001636 }
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001637
Takashi Iwai8f8d1d72017-02-01 17:24:02 +01001638 mutex_unlock(&ctx->mutex);
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001639 pm_runtime_mark_last_busy(ctx->dev);
1640 pm_runtime_put_autosuspend(ctx->dev);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001641}
1642
1643/*
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001644 * Jack interface
1645 */
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001646static int had_create_jack(struct snd_intelhad *ctx,
1647 struct snd_pcm *pcm)
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001648{
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001649 char hdmi_str[32];
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001650 int err;
1651
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001652 snprintf(hdmi_str, sizeof(hdmi_str),
1653 "HDMI/DP,pcm=%d", pcm->device);
1654
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001655 err = snd_jack_new(ctx->card_ctx->card, hdmi_str,
1656 SND_JACK_AVOUT, &ctx->jack,
Takashi Iwaib9bacf22017-02-14 12:29:38 +01001657 true, false);
1658 if (err < 0)
1659 return err;
1660 ctx->jack->private_data = ctx;
1661 return 0;
1662}
1663
1664/*
Takashi Iwai182cdf22017-02-02 14:43:39 +01001665 * PM callbacks
1666 */
1667
1668static int hdmi_lpe_audio_runtime_suspend(struct device *dev)
1669{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001670 struct snd_intelhad_card *card_ctx = dev_get_drvdata(dev);
1671 int port;
Takashi Iwai182cdf22017-02-02 14:43:39 +01001672
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001673 for_each_port(card_ctx, port) {
1674 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
1675 struct snd_pcm_substream *substream;
1676
1677 substream = had_substream_get(ctx);
1678 if (substream) {
1679 snd_pcm_suspend(substream);
1680 had_substream_put(ctx);
1681 }
Takashi Iwai182cdf22017-02-02 14:43:39 +01001682 }
1683
1684 return 0;
1685}
1686
Arnd Bergmann1df98922017-02-07 14:38:51 +01001687static int __maybe_unused hdmi_lpe_audio_suspend(struct device *dev)
Takashi Iwai182cdf22017-02-02 14:43:39 +01001688{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001689 struct snd_intelhad_card *card_ctx = dev_get_drvdata(dev);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001690 int err;
1691
1692 err = hdmi_lpe_audio_runtime_suspend(dev);
1693 if (!err)
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001694 snd_power_change_state(card_ctx->card, SNDRV_CTL_POWER_D3hot);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001695 return err;
1696}
1697
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001698static int hdmi_lpe_audio_runtime_resume(struct device *dev)
1699{
1700 pm_runtime_mark_last_busy(dev);
1701 return 0;
1702}
1703
Arnd Bergmann1df98922017-02-07 14:38:51 +01001704static int __maybe_unused hdmi_lpe_audio_resume(struct device *dev)
Takashi Iwai182cdf22017-02-02 14:43:39 +01001705{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001706 struct snd_intelhad_card *card_ctx = dev_get_drvdata(dev);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001707
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001708 hdmi_lpe_audio_runtime_resume(dev);
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001709 snd_power_change_state(card_ctx->card, SNDRV_CTL_POWER_D0);
Takashi Iwai182cdf22017-02-02 14:43:39 +01001710 return 0;
Takashi Iwaida864802017-01-31 13:52:22 +01001711}
1712
1713/* release resources */
1714static void hdmi_lpe_audio_free(struct snd_card *card)
1715{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001716 struct snd_intelhad_card *card_ctx = card->private_data;
1717 struct intel_hdmi_lpe_audio_pdata *pdata = card_ctx->dev->platform_data;
1718 int port;
Ville Syrjälä8d5c3032017-04-27 19:02:21 +03001719
1720 spin_lock_irq(&pdata->lpe_audio_slock);
1721 pdata->notify_audio_lpe = NULL;
1722 spin_unlock_irq(&pdata->lpe_audio_slock);
Takashi Iwaida864802017-01-31 13:52:22 +01001723
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001724 for_each_port(card_ctx, port) {
1725 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001726
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001727 cancel_work_sync(&ctx->hdmi_audio_wq);
1728 }
1729
1730 if (card_ctx->mmio_start)
1731 iounmap(card_ctx->mmio_start);
1732 if (card_ctx->irq >= 0)
1733 free_irq(card_ctx->irq, card_ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001734}
1735
1736/*
1737 * hdmi_lpe_audio_probe - start bridge with i915
1738 *
1739 * This function is called when the i915 driver creates the
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001740 * hdmi-lpe-audio platform device.
Takashi Iwaida864802017-01-31 13:52:22 +01001741 */
1742static int hdmi_lpe_audio_probe(struct platform_device *pdev)
1743{
1744 struct snd_card *card;
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001745 struct snd_intelhad_card *card_ctx;
Takashi Iwaida864802017-01-31 13:52:22 +01001746 struct snd_pcm *pcm;
1747 struct intel_hdmi_lpe_audio_pdata *pdata;
1748 int irq;
1749 struct resource *res_mmio;
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001750 int port, ret;
Takashi Iwaida864802017-01-31 13:52:22 +01001751
Takashi Iwaida864802017-01-31 13:52:22 +01001752 pdata = pdev->dev.platform_data;
1753 if (!pdata) {
1754 dev_err(&pdev->dev, "%s: quit: pdata not allocated by i915!!\n", __func__);
1755 return -EINVAL;
1756 }
1757
1758 /* get resources */
1759 irq = platform_get_irq(pdev, 0);
1760 if (irq < 0) {
1761 dev_err(&pdev->dev, "Could not get irq resource\n");
1762 return -ENODEV;
1763 }
1764
1765 res_mmio = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1766 if (!res_mmio) {
1767 dev_err(&pdev->dev, "Could not get IO_MEM resources\n");
1768 return -ENXIO;
1769 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301770
Takashi Iwai5647aec2017-01-31 08:14:34 +01001771 /* create a card instance with ALSA framework */
Takashi Iwaida864802017-01-31 13:52:22 +01001772 ret = snd_card_new(&pdev->dev, hdmi_card_index, hdmi_card_id,
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001773 THIS_MODULE, sizeof(*card_ctx), &card);
Takashi Iwaida864802017-01-31 13:52:22 +01001774 if (ret)
1775 return ret;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301776
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001777 card_ctx = card->private_data;
1778 card_ctx->dev = &pdev->dev;
1779 card_ctx->card = card;
Takashi Iwaida864802017-01-31 13:52:22 +01001780 strcpy(card->driver, INTEL_HAD);
Takashi Iwai873ab032017-02-07 12:14:04 +01001781 strcpy(card->shortname, "Intel HDMI/DP LPE Audio");
1782 strcpy(card->longname, "Intel HDMI/DP LPE Audio");
Jerome Anand5dab11d2017-01-25 04:27:52 +05301783
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001784 card_ctx->irq = -1;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301785
Takashi Iwaida864802017-01-31 13:52:22 +01001786 card->private_free = hdmi_lpe_audio_free;
1787
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001788 platform_set_drvdata(pdev, card_ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001789
1790 dev_dbg(&pdev->dev, "%s: mmio_start = 0x%x, mmio_end = 0x%x\n",
1791 __func__, (unsigned int)res_mmio->start,
1792 (unsigned int)res_mmio->end);
1793
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001794 card_ctx->mmio_start = ioremap_nocache(res_mmio->start,
1795 (size_t)(resource_size(res_mmio)));
1796 if (!card_ctx->mmio_start) {
Takashi Iwaida864802017-01-31 13:52:22 +01001797 dev_err(&pdev->dev, "Could not get ioremap\n");
1798 ret = -EACCES;
1799 goto err;
1800 }
1801
1802 /* setup interrupt handler */
1803 ret = request_irq(irq, display_pipe_interrupt_handler, 0,
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001804 pdev->name, card_ctx);
Takashi Iwaida864802017-01-31 13:52:22 +01001805 if (ret < 0) {
1806 dev_err(&pdev->dev, "request_irq failed\n");
1807 goto err;
1808 }
1809
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001810 card_ctx->irq = irq;
Takashi Iwai412bbe7d52017-02-02 22:03:22 +01001811
1812 /* only 32bit addressable */
1813 dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
1814 dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
1815
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001816 init_channel_allocations();
Jerome Anand5dab11d2017-01-25 04:27:52 +05301817
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001818 card_ctx->num_pipes = pdata->num_pipes;
1819 card_ctx->num_ports = pdata->num_ports;
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001820
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001821 for_each_port(card_ctx, port) {
1822 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
1823 int i;
1824
1825 ctx->card_ctx = card_ctx;
1826 ctx->dev = card_ctx->dev;
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001827 ctx->port = port;
1828 ctx->pipe = -1;
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001829
1830 INIT_WORK(&ctx->hdmi_audio_wq, had_audio_wq);
1831
Ville Syrjälä8a2d6ae2017-04-27 19:02:30 +03001832 ret = snd_pcm_new(card, INTEL_HAD, port, MAX_PB_STREAMS,
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001833 MAX_CAP_STREAMS, &pcm);
1834 if (ret)
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001835 goto err;
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001836
1837 /* setup private data which can be retrieved when required */
1838 pcm->private_data = ctx;
1839 pcm->info_flags = 0;
1840 strncpy(pcm->name, card->shortname, strlen(card->shortname));
1841 /* setup the ops for playabck */
1842 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &had_pcm_ops);
1843
1844 /* allocate dma pages;
1845 * try to allocate 600k buffer as default which is large enough
1846 */
1847 snd_pcm_lib_preallocate_pages_for_all(pcm,
1848 SNDRV_DMA_TYPE_DEV, NULL,
1849 HAD_DEFAULT_BUFFER, HAD_MAX_BUFFER);
1850
1851 /* create controls */
1852 for (i = 0; i < ARRAY_SIZE(had_controls); i++) {
1853 struct snd_kcontrol *kctl;
1854
1855 kctl = snd_ctl_new1(&had_controls[i], ctx);
1856 if (!kctl) {
1857 ret = -ENOMEM;
1858 goto err;
1859 }
1860
1861 kctl->id.device = pcm->device;
1862
1863 ret = snd_ctl_add(card, kctl);
1864 if (ret < 0)
1865 goto err;
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001866 }
1867
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001868 /* Register channel map controls */
1869 ret = had_register_chmap_ctls(ctx, pcm);
1870 if (ret < 0)
1871 goto err;
Ville Syrjäläbb4ac5a2017-04-27 19:02:28 +03001872
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001873 ret = had_create_jack(ctx, pcm);
Takashi Iwai4aedb942017-02-02 16:38:39 +01001874 if (ret < 0)
1875 goto err;
1876 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301877
Takashi Iwaida864802017-01-31 13:52:22 +01001878 ret = snd_card_register(card);
1879 if (ret)
Takashi Iwai36ec0d92017-01-31 08:47:05 +01001880 goto err;
1881
Takashi Iwaibcce7752017-02-01 17:18:20 +01001882 spin_lock_irq(&pdata->lpe_audio_slock);
Takashi Iwaida864802017-01-31 13:52:22 +01001883 pdata->notify_audio_lpe = notify_audio_lpe;
Takashi Iwaibcce7752017-02-01 17:18:20 +01001884 spin_unlock_irq(&pdata->lpe_audio_slock);
Takashi Iwaida864802017-01-31 13:52:22 +01001885
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001886 pm_runtime_use_autosuspend(&pdev->dev);
1887 pm_runtime_mark_last_busy(&pdev->dev);
Takashi Iwaida864802017-01-31 13:52:22 +01001888 pm_runtime_set_active(&pdev->dev);
Takashi Iwaida864802017-01-31 13:52:22 +01001889
Takashi Iwai99b2ab92017-01-31 16:26:10 +01001890 dev_dbg(&pdev->dev, "%s: handle pending notification\n", __func__);
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001891 for_each_port(card_ctx, port) {
1892 struct snd_intelhad *ctx = &card_ctx->pcm_ctx[port];
1893
1894 schedule_work(&ctx->hdmi_audio_wq);
1895 }
Jerome Anand5dab11d2017-01-25 04:27:52 +05301896
Takashi Iwai79dda752017-01-30 17:23:39 +01001897 return 0;
Takashi Iwai5647aec2017-01-31 08:14:34 +01001898
Jerome Anand5dab11d2017-01-25 04:27:52 +05301899err:
1900 snd_card_free(card);
Takashi Iwaida864802017-01-31 13:52:22 +01001901 return ret;
Jerome Anand5dab11d2017-01-25 04:27:52 +05301902}
1903
Takashi Iwai79dda752017-01-30 17:23:39 +01001904/*
Takashi Iwaida864802017-01-31 13:52:22 +01001905 * hdmi_lpe_audio_remove - stop bridge with i915
Jerome Anand5dab11d2017-01-25 04:27:52 +05301906 *
Takashi Iwai2e52f5e2017-01-31 17:09:13 +01001907 * This function is called when the platform device is destroyed.
Jerome Anand5dab11d2017-01-25 04:27:52 +05301908 */
Takashi Iwaida864802017-01-31 13:52:22 +01001909static int hdmi_lpe_audio_remove(struct platform_device *pdev)
Jerome Anand5dab11d2017-01-25 04:27:52 +05301910{
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001911 struct snd_intelhad_card *card_ctx = platform_get_drvdata(pdev);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301912
Ville Syrjäläb4eb0d52017-04-27 19:02:29 +03001913 snd_card_free(card_ctx->card);
Jerome Anand5dab11d2017-01-25 04:27:52 +05301914 return 0;
1915}
1916
Takashi Iwai182cdf22017-02-02 14:43:39 +01001917static const struct dev_pm_ops hdmi_lpe_audio_pm = {
1918 SET_SYSTEM_SLEEP_PM_OPS(hdmi_lpe_audio_suspend, hdmi_lpe_audio_resume)
Takashi Iwai3002b9f2017-02-13 09:52:44 +01001919 SET_RUNTIME_PM_OPS(hdmi_lpe_audio_runtime_suspend,
1920 hdmi_lpe_audio_runtime_resume, NULL)
Takashi Iwai182cdf22017-02-02 14:43:39 +01001921};
1922
Takashi Iwaida864802017-01-31 13:52:22 +01001923static struct platform_driver hdmi_lpe_audio_driver = {
1924 .driver = {
1925 .name = "hdmi-lpe-audio",
Takashi Iwai182cdf22017-02-02 14:43:39 +01001926 .pm = &hdmi_lpe_audio_pm,
Takashi Iwaida864802017-01-31 13:52:22 +01001927 },
1928 .probe = hdmi_lpe_audio_probe,
1929 .remove = hdmi_lpe_audio_remove,
Takashi Iwaida864802017-01-31 13:52:22 +01001930};
1931
1932module_platform_driver(hdmi_lpe_audio_driver);
1933MODULE_ALIAS("platform:hdmi_lpe_audio");
1934
Jerome Anand5dab11d2017-01-25 04:27:52 +05301935MODULE_AUTHOR("Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>");
1936MODULE_AUTHOR("Ramesh Babu K V <ramesh.babu@intel.com>");
1937MODULE_AUTHOR("Vaibhav Agarwal <vaibhav.agarwal@intel.com>");
1938MODULE_AUTHOR("Jerome Anand <jerome.anand@intel.com>");
1939MODULE_DESCRIPTION("Intel HDMI Audio driver");
1940MODULE_LICENSE("GPL v2");
1941MODULE_SUPPORTED_DEVICE("{Intel,Intel_HAD}");