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