blob: 034b3873ffa1eb60e71a38accbb15e2f78a83496 [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>
40#include "intel_hdmi_lpe_audio.h"
41
42#define PCM_INDEX 0
43#define MAX_PB_STREAMS 1
44#define MAX_CAP_STREAMS 0
45#define HDMI_AUDIO_DRIVER "hdmi-audio"
46
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -060047#define HDMI_INFO_FRAME_WORD1 0x000a0184
48#define DP_INFO_FRAME_WORD1 0x00441b84
Jerome Anand5dab11d2017-01-25 04:27:52 +053049#define FIFO_THRESHOLD 0xFE
50#define DMA_FIFO_THRESHOLD 0x7
51#define BYTES_PER_WORD 0x4
52
53/* Sampling rate as per IEC60958 Ver 3 */
54#define CH_STATUS_MAP_32KHZ 0x3
55#define CH_STATUS_MAP_44KHZ 0x0
56#define CH_STATUS_MAP_48KHZ 0x2
57#define CH_STATUS_MAP_88KHZ 0x8
58#define CH_STATUS_MAP_96KHZ 0xA
59#define CH_STATUS_MAP_176KHZ 0xC
60#define CH_STATUS_MAP_192KHZ 0xE
61
62#define MAX_SMPL_WIDTH_20 0x0
63#define MAX_SMPL_WIDTH_24 0x1
64#define SMPL_WIDTH_16BITS 0x1
65#define SMPL_WIDTH_24BITS 0x5
66#define CHANNEL_ALLOCATION 0x1F
67#define MASK_BYTE0 0x000000FF
68#define VALID_DIP_WORDS 3
69#define LAYOUT0 0
70#define LAYOUT1 1
71#define SWAP_LFE_CENTER 0x00fac4c8
72#define AUD_CONFIG_CH_MASK_V2 0x70
73
74struct pcm_stream_info {
75 int str_id;
76 void *had_substream;
77 void (*period_elapsed)(void *had_substream);
78 u32 buffer_ptr;
79 u64 buffer_rendered;
80 u32 ring_buf_size;
81 int sfreq;
82};
83
84struct ring_buf_info {
85 u32 buf_addr;
86 u32 buf_size;
87 u8 is_valid;
88};
89
90struct had_stream_pvt {
91 enum had_stream_status stream_status;
92 int stream_ops;
93 ssize_t dbg_cum_bytes;
94};
95
96struct had_pvt_data {
97 enum had_status_stream stream_type;
98};
99
100struct had_callback_ops {
101 had_event_call_back intel_had_event_call_back;
102};
103
104/**
105 * struct snd_intelhad - intelhad driver structure
106 *
107 * @card: ptr to hold card details
108 * @card_index: sound card index
109 * @card_id: detected sound card id
110 * @reg_ops: register operations to program registers
111 * @query_ops: caps call backs for get/set operations
112 * @drv_status: driver status
113 * @buf_info: ring buffer info
114 * @stream_info: stream information
115 * @eeld: holds EELD info
116 * @curr_buf: pointer to hold current active ring buf
117 * @valid_buf_cnt: ring buffer count for stream
118 * @had_spinlock: driver lock
119 * @aes_bits: IEC958 status bits
120 * @buff_done: id of current buffer done intr
121 * @dev: platoform device handle
122 * @kctl: holds kctl ptrs used for channel map
123 * @chmap: holds channel map info
124 * @audio_reg_base: hdmi audio register base offset
125 * @hw_silence: flag indicates SoC support for HW silence/Keep alive
126 * @ops: holds ops functions based on platform
127 */
128struct snd_intelhad {
129 struct snd_card *card;
130 int card_index;
131 char *card_id;
132 struct hdmi_audio_registers_ops reg_ops;
133 struct hdmi_audio_query_set_ops query_ops;
134 enum had_drv_status drv_status;
135 struct ring_buf_info buf_info[HAD_NUM_OF_RING_BUFS];
136 struct pcm_stream_info stream_info;
137 union otm_hdmi_eld_t eeld;
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600138 bool dp_output;
Jerome Anand5dab11d2017-01-25 04:27:52 +0530139 enum intel_had_aud_buf_type curr_buf;
140 int valid_buf_cnt;
141 unsigned int aes_bits;
142 int flag_underrun;
143 struct had_pvt_data *private_data;
144 spinlock_t had_spinlock;
145 enum intel_had_aud_buf_type buff_done;
146 struct device *dev;
147 struct snd_kcontrol *kctl;
148 struct snd_pcm_chmap *chmap;
149 unsigned int *audio_reg_base;
150 unsigned int audio_cfg_offset;
151 bool hw_silence;
152 struct had_ops *ops;
153};
154
155struct had_ops {
156 void (*enable_audio)(struct snd_pcm_substream *substream,
157 u8 enable);
158 void (*reset_audio)(u8 reset);
159 int (*prog_n)(u32 aud_samp_freq, u32 *n_param,
160 struct snd_intelhad *intelhaddata);
Pierre-Louis Bossart964ca802017-01-31 14:16:52 -0600161 void (*prog_cts)(u32 aud_samp_freq, u32 tmds, u32 link_rate,
162 u32 n_param, struct snd_intelhad *intelhaddata);
Jerome Anand5dab11d2017-01-25 04:27:52 +0530163 int (*audio_ctrl)(struct snd_pcm_substream *substream,
164 struct snd_intelhad *intelhaddata);
165 void (*prog_dip)(struct snd_pcm_substream *substream,
166 struct snd_intelhad *intelhaddata);
167 void (*handle_underrun)(struct snd_intelhad *intelhaddata);
168};
169
170
171int had_event_handler(enum had_event_type event_type, void *data);
172
173int hdmi_audio_query(void *drv_data, struct hdmi_audio_event event);
174int hdmi_audio_suspend(void *drv_data, struct hdmi_audio_event event);
175int hdmi_audio_resume(void *drv_data);
176int hdmi_audio_mode_change(struct snd_pcm_substream *substream);
177extern struct snd_pcm_ops snd_intelhad_playback_ops;
178
179int snd_intelhad_init_audio_ctrl(struct snd_pcm_substream *substream,
180 struct snd_intelhad *intelhaddata,
181 int flag_silence);
182int snd_intelhad_prog_buffer(struct snd_intelhad *intelhaddata,
183 int start, int end);
184int snd_intelhad_invd_buffer(int start, int end);
185int snd_intelhad_read_len(struct snd_intelhad *intelhaddata);
186void had_build_channel_allocation_map(struct snd_intelhad *intelhaddata);
187
188/* Register access functions */
189int had_get_hwstate(struct snd_intelhad *intelhaddata);
190int had_get_caps(enum had_caps_list query_element, void *capabilties);
191int had_set_caps(enum had_caps_list set_element, void *capabilties);
192int had_read_register(u32 reg_addr, u32 *data);
193int had_write_register(u32 reg_addr, u32 data);
194int had_read_modify(u32 reg_addr, u32 data, u32 mask);
195
196int hdmi_audio_probe(void *devptr);
197int hdmi_audio_remove(void *pdev);
198
199#endif /* _INTEL_HDMI_AUDIO_ */