blob: 4ccaa8b18566a1d076feb90cebd95d68c2848d12 [file] [log] [blame]
Jerome Anand5dab11d2017-01-25 04:27:52 +05301/*
2 * Copyright (C) 2016 Intel Corporation
3 * Authors: Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>
4 * Ramesh Babu K V <ramesh.babu@intel.com>
5 * Vaibhav Agarwal <vaibhav.agarwal@intel.com>
6 * Jerome Anand <jerome.anand@intel.com>
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files
10 * (the "Software"), to deal in the Software without restriction,
11 * including without limitation the rights to use, copy, modify, merge,
12 * publish, distribute, sublicense, and/or sell copies of the Software,
13 * and to permit persons to whom the Software is furnished to do so,
14 * subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial
18 * portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 */
29
30#ifndef _INTEL_HDMI_AUDIO_H_
31#define _INTEL_HDMI_AUDIO_H_
32
33#include <linux/types.h>
34#include <sound/initval.h>
35#include <linux/version.h>
36#include <linux/pm_runtime.h>
37#include <sound/asoundef.h>
38#include <sound/control.h>
39#include <sound/pcm.h>
Takashi Iwaidf0435d2017-02-02 15:37:11 +010040#include <drm/drm_edid.h>
Jerome Anand5dab11d2017-01-25 04:27:52 +053041#include "intel_hdmi_lpe_audio.h"
42
43#define PCM_INDEX 0
44#define MAX_PB_STREAMS 1
45#define MAX_CAP_STREAMS 0
46#define HDMI_AUDIO_DRIVER "hdmi-audio"
47
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -060048#define HDMI_INFO_FRAME_WORD1 0x000a0184
49#define DP_INFO_FRAME_WORD1 0x00441b84
Jerome Anand5dab11d2017-01-25 04:27:52 +053050#define FIFO_THRESHOLD 0xFE
51#define DMA_FIFO_THRESHOLD 0x7
52#define BYTES_PER_WORD 0x4
53
54/* Sampling rate as per IEC60958 Ver 3 */
55#define CH_STATUS_MAP_32KHZ 0x3
56#define CH_STATUS_MAP_44KHZ 0x0
57#define CH_STATUS_MAP_48KHZ 0x2
58#define CH_STATUS_MAP_88KHZ 0x8
59#define CH_STATUS_MAP_96KHZ 0xA
60#define CH_STATUS_MAP_176KHZ 0xC
61#define CH_STATUS_MAP_192KHZ 0xE
62
63#define MAX_SMPL_WIDTH_20 0x0
64#define MAX_SMPL_WIDTH_24 0x1
65#define SMPL_WIDTH_16BITS 0x1
66#define SMPL_WIDTH_24BITS 0x5
67#define CHANNEL_ALLOCATION 0x1F
68#define MASK_BYTE0 0x000000FF
69#define VALID_DIP_WORDS 3
70#define LAYOUT0 0
71#define LAYOUT1 1
72#define SWAP_LFE_CENTER 0x00fac4c8
Takashi Iwai4151ee82017-01-31 18:14:15 +010073#define AUD_CONFIG_CH_MASK 0x70
Jerome Anand5dab11d2017-01-25 04:27:52 +053074
75struct pcm_stream_info {
Takashi Iwai313d9f22017-02-02 13:00:12 +010076 struct snd_pcm_substream *substream;
Jerome Anand5dab11d2017-01-25 04:27:52 +053077 u64 buffer_rendered;
78 u32 ring_buf_size;
Takashi Iwai313d9f22017-02-02 13:00:12 +010079 int substream_refcount;
Takashi Iwaif69bd102017-02-02 14:57:22 +010080 bool running;
Jerome Anand5dab11d2017-01-25 04:27:52 +053081};
82
83struct ring_buf_info {
84 u32 buf_addr;
85 u32 buf_size;
86 u8 is_valid;
87};
88
Jerome Anand5dab11d2017-01-25 04:27:52 +053089/**
90 * struct snd_intelhad - intelhad driver structure
91 *
92 * @card: ptr to hold card details
Jerome Anand5dab11d2017-01-25 04:27:52 +053093 * @drv_status: driver status
94 * @buf_info: ring buffer info
95 * @stream_info: stream information
Takashi Iwaida864802017-01-31 13:52:22 +010096 * @eld: holds ELD info
Jerome Anand5dab11d2017-01-25 04:27:52 +053097 * @curr_buf: pointer to hold current active ring buf
98 * @valid_buf_cnt: ring buffer count for stream
99 * @had_spinlock: driver lock
100 * @aes_bits: IEC958 status bits
101 * @buff_done: id of current buffer done intr
102 * @dev: platoform device handle
Jerome Anand5dab11d2017-01-25 04:27:52 +0530103 * @chmap: holds channel map info
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +0100104 * @underrun_count: PCM stream underrun counter
Jerome Anand5dab11d2017-01-25 04:27:52 +0530105 */
106struct snd_intelhad {
107 struct snd_card *card;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530108 enum had_drv_status drv_status;
109 struct ring_buf_info buf_info[HAD_NUM_OF_RING_BUFS];
110 struct pcm_stream_info stream_info;
Takashi Iwaidf0435d2017-02-02 15:37:11 +0100111 unsigned char eld[HDMI_MAX_ELD_BYTES];
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600112 bool dp_output;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530113 enum intel_had_aud_buf_type curr_buf;
114 int valid_buf_cnt;
115 unsigned int aes_bits;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530116 spinlock_t had_spinlock;
117 enum intel_had_aud_buf_type buff_done;
118 struct device *dev;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530119 struct snd_pcm_chmap *chmap;
Takashi Iwai6ddb3ab2017-01-30 18:17:44 +0100120 int underrun_count;
Takashi Iwaida864802017-01-31 13:52:22 +0100121 int tmds_clock_speed;
122 int link_rate;
123
124 /* internal stuff */
125 int irq;
126 void __iomem *mmio_start;
127 unsigned int had_config_offset;
Takashi Iwaida864802017-01-31 13:52:22 +0100128 struct work_struct hdmi_audio_wq;
Takashi Iwai0e9c67d2017-02-01 17:53:19 +0100129 struct mutex mutex; /* for protecting chmap and eld */
Jerome Anand5dab11d2017-01-25 04:27:52 +0530130};
131
Jerome Anand5dab11d2017-01-25 04:27:52 +0530132#endif /* _INTEL_HDMI_AUDIO_ */