ca4212dca94ecaf411f918b9e40086c66e26103e
[linux-2.6-microblaze.git] / sound / x86 / intel_hdmi_lpe_audio.h
1 /*
2  *   intel_hdmi_lpe_audio.h - Intel HDMI LPE 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  *              Aravind Siddappaji <aravindx.siddappaji@intel.com>
10  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11  *
12  *  This program is free software; you can redistribute it and/or modify
13  *  it under the terms of the GNU General Public License as published by
14  *  the Free Software Foundation; version 2 of the License.
15  *
16  *  This program is distributed in the hope that it will be useful, but
17  *  WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  *  General Public License for more details.
20  *
21  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22  */
23 #ifndef __INTEL_HDMI_LPE_AUDIO_H
24 #define __INTEL_HDMI_LPE_AUDIO_H
25
26 #define HAD_MAX_DEVICES         1
27 #define HAD_MIN_CHANNEL         2
28 #define HAD_MAX_CHANNEL         8
29 #define HAD_NUM_OF_RING_BUFS    4
30
31 /* max 20bit address, aligned to 64 */
32 #define HAD_MAX_BUFFER          ((1024 * 1024 - 1) & ~0x3f)
33 #define HAD_DEFAULT_BUFFER      (600 * 1024) /* default prealloc size */
34 #define HAD_MAX_PERIODS         256     /* arbitrary, but should suffice */
35 #define HAD_MIN_PERIODS         2
36 #define HAD_MAX_PERIOD_BYTES    ((HAD_MAX_BUFFER / HAD_MIN_PERIODS) & ~0x3f)
37 #define HAD_MIN_PERIOD_BYTES    1024    /* might be smaller */
38 #define HAD_FIFO_SIZE           0 /* fifo not being used */
39 #define MAX_SPEAKERS            8
40
41 #define AUD_SAMPLE_RATE_32      32000
42 #define AUD_SAMPLE_RATE_44_1    44100
43 #define AUD_SAMPLE_RATE_48      48000
44 #define AUD_SAMPLE_RATE_88_2    88200
45 #define AUD_SAMPLE_RATE_96      96000
46 #define AUD_SAMPLE_RATE_176_4   176400
47 #define AUD_SAMPLE_RATE_192     192000
48
49 #define HAD_MIN_RATE            AUD_SAMPLE_RATE_32
50 #define HAD_MAX_RATE            AUD_SAMPLE_RATE_192
51
52 #define DIS_SAMPLE_RATE_25_2    25200
53 #define DIS_SAMPLE_RATE_27      27000
54 #define DIS_SAMPLE_RATE_54      54000
55 #define DIS_SAMPLE_RATE_74_25   74250
56 #define DIS_SAMPLE_RATE_148_5   148500
57 #define HAD_REG_WIDTH           0x08
58 #define HAD_MAX_HW_BUFS         0x04
59 #define HAD_MAX_DIP_WORDS               16
60 #define INTEL_HAD               "IntelHdmiLpeAudio"
61
62 /* DP Link Rates */
63 #define DP_2_7_GHZ                      270000
64 #define DP_1_62_GHZ                     162000
65
66 /* Maud Values */
67 #define AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL              1988
68 #define AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL            2740
69 #define AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL              2982
70 #define AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL            5480
71 #define AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL              5965
72 #define AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL           10961
73 #define HAD_MAX_RATE_DP_2_7_MAUD_VAL                    11930
74 #define AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL             3314
75 #define AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL           4567
76 #define AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL             4971
77 #define AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL           9134
78 #define AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL             9942
79 #define AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL          18268
80 #define HAD_MAX_RATE_DP_1_62_MAUD_VAL                   19884
81
82 /* Naud Value */
83 #define DP_NAUD_VAL                                     32768
84
85 /* HDMI Controller register offsets - audio domain common */
86 /* Base address for below regs = 0x65000 */
87 enum hdmi_ctrl_reg_offset_common {
88         AUDIO_HDMI_CONFIG_A = 0x000,
89         AUDIO_HDMI_CONFIG_B = 0x800,
90         AUDIO_HDMI_CONFIG_C = 0x900,
91 };
92 /* HDMI controller register offsets */
93 enum hdmi_ctrl_reg_offset {
94         AUD_CONFIG              = 0x0,
95         AUD_CH_STATUS_0         = 0x08,
96         AUD_CH_STATUS_1         = 0x0C,
97         AUD_HDMI_CTS            = 0x10,
98         AUD_N_ENABLE            = 0x14,
99         AUD_SAMPLE_RATE         = 0x18,
100         AUD_BUF_CONFIG          = 0x20,
101         AUD_BUF_CH_SWAP         = 0x24,
102         AUD_BUF_A_ADDR          = 0x40,
103         AUD_BUF_A_LENGTH        = 0x44,
104         AUD_BUF_B_ADDR          = 0x48,
105         AUD_BUF_B_LENGTH        = 0x4c,
106         AUD_BUF_C_ADDR          = 0x50,
107         AUD_BUF_C_LENGTH        = 0x54,
108         AUD_BUF_D_ADDR          = 0x58,
109         AUD_BUF_D_LENGTH        = 0x5c,
110         AUD_CNTL_ST             = 0x60,
111         AUD_HDMI_STATUS         = 0x64, /* v2 */
112         AUD_HDMIW_INFOFR        = 0x68, /* v2 */
113 };
114
115 /*
116  *      CEA speaker placement:
117  *
118  *      FL  FLC   FC   FRC   FR
119  *
120  *                                              LFE
121  *
122  *      RL  RLC   RC   RRC   RR
123  *
124  *      The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M
125  *      corresponds to CEA RL/RR; The SMPTE channel _assignment_ C/LFE is
126  *      swapped to CEA LFE/FC.
127  */
128 enum cea_speaker_placement {
129         FL  = (1 <<  0),        /* Front Left           */
130         FC  = (1 <<  1),        /* Front Center         */
131         FR  = (1 <<  2),        /* Front Right          */
132         FLC = (1 <<  3),        /* Front Left Center    */
133         FRC = (1 <<  4),        /* Front Right Center   */
134         RL  = (1 <<  5),        /* Rear Left            */
135         RC  = (1 <<  6),        /* Rear Center          */
136         RR  = (1 <<  7),        /* Rear Right           */
137         RLC = (1 <<  8),        /* Rear Left Center     */
138         RRC = (1 <<  9),        /* Rear Right Center    */
139         LFE = (1 << 10),        /* Low Frequency Effect */
140 };
141
142 struct cea_channel_speaker_allocation {
143         int ca_index;
144         int speakers[8];
145
146         /* derived values, just for convenience */
147         int channels;
148         int spk_mask;
149 };
150
151 struct channel_map_table {
152         unsigned char map;              /* ALSA API channel map position */
153         unsigned char cea_slot;         /* CEA slot value */
154         int spk_mask;                   /* speaker position bit mask */
155 };
156
157 /* Audio configuration */
158 union aud_cfg {
159         struct {
160                 u32 aud_en:1;
161                 u32 layout:1;
162                 u32 fmt:2;
163                 u32 num_ch:3;
164                 u32 set:1;
165                 u32 flat:1;
166                 u32 val_bit:1;
167                 u32 user_bit:1;
168                 u32 underrun:1;
169                 u32 packet_mode:1;
170                 u32 left_align:1;
171                 u32 bogus_sample:1;
172                 u32 dp_modei:1;
173                 u32 rsvd:16;
174         } regx;
175         u32 regval;
176 };
177
178 #define AUD_CONFIG_BLOCK_BIT                    (1 << 7)
179 #define AUD_CONFIG_VALID_BIT                    (1 << 9)
180 #define AUD_CONFIG_DP_MODE                      (1 << 15)
181
182 /* Audio Channel Status 0 Attributes */
183 union aud_ch_status_0 {
184         struct {
185                 u32 ch_status:1;
186                 u32 lpcm_id:1;
187                 u32 cp_info:1;
188                 u32 format:3;
189                 u32 mode:2;
190                 u32 ctg_code:8;
191                 u32 src_num:4;
192                 u32 ch_num:4;
193                 u32 samp_freq:4;
194                 u32 clk_acc:2;
195                 u32 rsvd:2;
196         } regx;
197         u32 regval;
198 };
199
200 /* Audio Channel Status 1 Attributes */
201 union aud_ch_status_1 {
202         struct {
203                 u32 max_wrd_len:1;
204                 u32 wrd_len:3;
205                 u32 rsvd:28;
206         } regx;
207         u32 regval;
208 };
209
210 /* CTS register */
211 union aud_hdmi_cts {
212         struct {
213                 u32 cts_val:24;
214                 u32 en_cts_prog:1;
215                 u32 rsvd:7;
216         } regx;
217         u32 regval;
218 };
219
220 /* N register */
221 union aud_hdmi_n_enable {
222         struct {
223                 u32 n_val:24;
224                 u32 en_n_prog:1;
225                 u32 rsvd:7;
226         } regx;
227         u32 regval;
228 };
229
230 /* Audio Buffer configurations */
231 union aud_buf_config {
232         struct {
233                 u32 audio_fifo_watermark:8;
234                 u32 dma_fifo_watermark:3;
235                 u32 rsvd0:5;
236                 u32 aud_delay:8;
237                 u32 rsvd1:8;
238         } regx;
239         u32 regval;
240 };
241
242 /* Audio Sample Swapping offset */
243 union aud_buf_ch_swap {
244         struct {
245                 u32 first_0:3;
246                 u32 second_0:3;
247                 u32 first_1:3;
248                 u32 second_1:3;
249                 u32 first_2:3;
250                 u32 second_2:3;
251                 u32 first_3:3;
252                 u32 second_3:3;
253                 u32 rsvd:8;
254         } regx;
255         u32 regval;
256 };
257
258 /* Address for Audio Buffer */
259 union aud_buf_addr {
260         struct {
261                 u32 valid:1;
262                 u32 intr_en:1;
263                 u32 rsvd:4;
264                 u32 addr:26;
265         } regx;
266         u32 regval;
267 };
268
269 #define AUD_BUF_VALID           (1U << 0)
270 #define AUD_BUF_INTR_EN         (1U << 1)
271
272 /* Length of Audio Buffer */
273 union aud_buf_len {
274         struct {
275                 u32 buf_len:20;
276                 u32 rsvd:12;
277         } regx;
278         u32 regval;
279 };
280
281 /* Audio Control State Register offset */
282 union aud_ctrl_st {
283         struct {
284                 u32 ram_addr:4;
285                 u32 eld_ack:1;
286                 u32 eld_addr:4;
287                 u32 eld_buf_size:5;
288                 u32 eld_valid:1;
289                 u32 cp_ready:1;
290                 u32 dip_freq:2;
291                 u32 dip_idx:3;
292                 u32 dip_en_sta:4;
293                 u32 rsvd:7;
294         } regx;
295         u32 regval;
296 };
297
298 /* Audio HDMI Widget Data Island Packet offset */
299 union aud_info_frame1 {
300         struct {
301                 u32 pkt_type:8;
302                 u32 ver_num:8;
303                 u32 len:5;
304                 u32 rsvd:11;
305         } regx;
306         u32 regval;
307 };
308
309 /* DIP frame 2 */
310 union aud_info_frame2 {
311         struct {
312                 u32 chksum:8;
313                 u32 chnl_cnt:3;
314                 u32 rsvd0:1;
315                 u32 coding_type:4;
316                 u32 smpl_size:2;
317                 u32 smpl_freq:3;
318                 u32 rsvd1:3;
319                 u32 format:8;
320         } regx;
321         u32 regval;
322 };
323
324 /* DIP frame 3 */
325 union aud_info_frame3 {
326         struct {
327                 u32 chnl_alloc:8;
328                 u32 rsvd0:3;
329                 u32 lsv:4;
330                 u32 dm_inh:1;
331                 u32 rsvd1:16;
332         } regx;
333         u32 regval;
334 };
335
336 /* AUD_HDMI_STATUS bits */
337 #define HDMI_AUDIO_UNDERRUN             (1U << 31)
338 #define HDMI_AUDIO_BUFFER_DONE          (1U << 29)
339
340 /* AUD_HDMI_STATUS register mask */
341 #define AUD_CONFIG_MASK_UNDERRUN        0xC0000000
342 #define AUD_CONFIG_MASK_SRDBG           0x00000002
343 #define AUD_CONFIG_MASK_FUNCRST         0x00000001
344
345 #endif