xref: /linux/sound/x86/intel_hdmi_lpe_audio.h (revision 8d48c0163d1ab0f56a18ebe9898a34ebcfdfaa1a)
1287599cfSJerome Anand /*
2287599cfSJerome Anand  *   intel_hdmi_lpe_audio.h - Intel HDMI LPE audio driver
3287599cfSJerome Anand  *
4287599cfSJerome Anand  *  Copyright (C) 2016 Intel Corp
5287599cfSJerome Anand  *  Authors:	Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>
6287599cfSJerome Anand  *		Ramesh Babu K V <ramesh.babu@intel.com>
7287599cfSJerome Anand  *		Vaibhav Agarwal <vaibhav.agarwal@intel.com>
8287599cfSJerome Anand  *		Jerome Anand <jerome.anand@intel.com>
9287599cfSJerome Anand  *		Aravind Siddappaji <aravindx.siddappaji@intel.com>
10287599cfSJerome Anand  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11287599cfSJerome Anand  *
12287599cfSJerome Anand  *  This program is free software; you can redistribute it and/or modify
13287599cfSJerome Anand  *  it under the terms of the GNU General Public License as published by
14287599cfSJerome Anand  *  the Free Software Foundation; version 2 of the License.
15287599cfSJerome Anand  *
16287599cfSJerome Anand  *  This program is distributed in the hope that it will be useful, but
17287599cfSJerome Anand  *  WITHOUT ANY WARRANTY; without even the implied warranty of
18287599cfSJerome Anand  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19287599cfSJerome Anand  *  General Public License for more details.
20287599cfSJerome Anand  *
21287599cfSJerome Anand  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22287599cfSJerome Anand  */
23287599cfSJerome Anand #ifndef __INTEL_HDMI_LPE_AUDIO_H
24287599cfSJerome Anand #define __INTEL_HDMI_LPE_AUDIO_H
25287599cfSJerome Anand 
26287599cfSJerome Anand #define HAD_MIN_CHANNEL		2
27287599cfSJerome Anand #define HAD_MAX_CHANNEL		8
28287599cfSJerome Anand #define HAD_NUM_OF_RING_BUFS	4
29287599cfSJerome Anand 
30e1b239f3STakashi Iwai /* max 20bit address, aligned to 64 */
31e1b239f3STakashi Iwai #define HAD_MAX_BUFFER		((1024 * 1024 - 1) & ~0x3f)
32e1b239f3STakashi Iwai #define HAD_DEFAULT_BUFFER	(600 * 1024) /* default prealloc size */
33e1b239f3STakashi Iwai #define HAD_MAX_PERIODS		256	/* arbitrary, but should suffice */
34*8d48c016STakashi Iwai #define HAD_MIN_PERIODS		1
35e1b239f3STakashi Iwai #define HAD_MAX_PERIOD_BYTES	((HAD_MAX_BUFFER / HAD_MIN_PERIODS) & ~0x3f)
36e1b239f3STakashi Iwai #define HAD_MIN_PERIOD_BYTES	1024	/* might be smaller */
37287599cfSJerome Anand #define HAD_FIFO_SIZE		0 /* fifo not being used */
38287599cfSJerome Anand #define MAX_SPEAKERS		8
39287599cfSJerome Anand 
40287599cfSJerome Anand #define AUD_SAMPLE_RATE_32	32000
41287599cfSJerome Anand #define AUD_SAMPLE_RATE_44_1	44100
42287599cfSJerome Anand #define AUD_SAMPLE_RATE_48	48000
43287599cfSJerome Anand #define AUD_SAMPLE_RATE_88_2	88200
44287599cfSJerome Anand #define AUD_SAMPLE_RATE_96	96000
45287599cfSJerome Anand #define AUD_SAMPLE_RATE_176_4	176400
46287599cfSJerome Anand #define AUD_SAMPLE_RATE_192	192000
47287599cfSJerome Anand 
48287599cfSJerome Anand #define HAD_MIN_RATE		AUD_SAMPLE_RATE_32
49287599cfSJerome Anand #define HAD_MAX_RATE		AUD_SAMPLE_RATE_192
50287599cfSJerome Anand 
51287599cfSJerome Anand #define DIS_SAMPLE_RATE_25_2	25200
52287599cfSJerome Anand #define DIS_SAMPLE_RATE_27	27000
53287599cfSJerome Anand #define DIS_SAMPLE_RATE_54	54000
54287599cfSJerome Anand #define DIS_SAMPLE_RATE_74_25	74250
55287599cfSJerome Anand #define DIS_SAMPLE_RATE_148_5	148500
56287599cfSJerome Anand #define HAD_REG_WIDTH		0x08
57287599cfSJerome Anand #define HAD_MAX_DIP_WORDS		16
58287599cfSJerome Anand 
59964ca808SPierre-Louis Bossart /* DP Link Rates */
60964ca808SPierre-Louis Bossart #define DP_2_7_GHZ			270000
61964ca808SPierre-Louis Bossart #define DP_1_62_GHZ			162000
62964ca808SPierre-Louis Bossart 
63964ca808SPierre-Louis Bossart /* Maud Values */
64964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL		1988
65964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL		2740
66964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL		2982
67964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL		5480
68964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL		5965
69964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL		10961
70964ca808SPierre-Louis Bossart #define HAD_MAX_RATE_DP_2_7_MAUD_VAL			11930
71964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL		3314
72964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL		4567
73964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL		4971
74964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL		9134
75964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL		9942
76964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL		18268
77964ca808SPierre-Louis Bossart #define HAD_MAX_RATE_DP_1_62_MAUD_VAL			19884
78964ca808SPierre-Louis Bossart 
79964ca808SPierre-Louis Bossart /* Naud Value */
80964ca808SPierre-Louis Bossart #define DP_NAUD_VAL					32768
81964ca808SPierre-Louis Bossart 
82287599cfSJerome Anand /* HDMI Controller register offsets - audio domain common */
83287599cfSJerome Anand /* Base address for below regs = 0x65000 */
84287599cfSJerome Anand enum hdmi_ctrl_reg_offset_common {
85287599cfSJerome Anand 	AUDIO_HDMI_CONFIG_A = 0x000,
86287599cfSJerome Anand 	AUDIO_HDMI_CONFIG_B = 0x800,
87287599cfSJerome Anand 	AUDIO_HDMI_CONFIG_C = 0x900,
88287599cfSJerome Anand };
89287599cfSJerome Anand /* HDMI controller register offsets */
904151ee84STakashi Iwai enum hdmi_ctrl_reg_offset {
91287599cfSJerome Anand 	AUD_CONFIG		= 0x0,
92287599cfSJerome Anand 	AUD_CH_STATUS_0		= 0x08,
93287599cfSJerome Anand 	AUD_CH_STATUS_1		= 0x0C,
94287599cfSJerome Anand 	AUD_HDMI_CTS		= 0x10,
95287599cfSJerome Anand 	AUD_N_ENABLE		= 0x14,
96287599cfSJerome Anand 	AUD_SAMPLE_RATE		= 0x18,
97287599cfSJerome Anand 	AUD_BUF_CONFIG		= 0x20,
98287599cfSJerome Anand 	AUD_BUF_CH_SWAP		= 0x24,
99287599cfSJerome Anand 	AUD_BUF_A_ADDR		= 0x40,
100287599cfSJerome Anand 	AUD_BUF_A_LENGTH	= 0x44,
101287599cfSJerome Anand 	AUD_BUF_B_ADDR		= 0x48,
102287599cfSJerome Anand 	AUD_BUF_B_LENGTH	= 0x4c,
103287599cfSJerome Anand 	AUD_BUF_C_ADDR		= 0x50,
104287599cfSJerome Anand 	AUD_BUF_C_LENGTH	= 0x54,
105287599cfSJerome Anand 	AUD_BUF_D_ADDR		= 0x58,
106287599cfSJerome Anand 	AUD_BUF_D_LENGTH	= 0x5c,
107287599cfSJerome Anand 	AUD_CNTL_ST		= 0x60,
1084151ee84STakashi Iwai 	AUD_HDMI_STATUS		= 0x64, /* v2 */
1094151ee84STakashi Iwai 	AUD_HDMIW_INFOFR	= 0x68, /* v2 */
110287599cfSJerome Anand };
111287599cfSJerome Anand 
1127ceba75fSTakashi Iwai /* Audio configuration */
113287599cfSJerome Anand union aud_cfg {
114287599cfSJerome Anand 	struct {
115287599cfSJerome Anand 		u32 aud_en:1;
11677531beeSTakashi Iwai 		u32 layout:1;		/* LAYOUT[01], see below */
117287599cfSJerome Anand 		u32 fmt:2;
118287599cfSJerome Anand 		u32 num_ch:3;
119287599cfSJerome Anand 		u32 set:1;
120287599cfSJerome Anand 		u32 flat:1;
121287599cfSJerome Anand 		u32 val_bit:1;
122287599cfSJerome Anand 		u32 user_bit:1;
12377531beeSTakashi Iwai 		u32 underrun:1;		/* 0: send null packets,
12477531beeSTakashi Iwai 					 * 1: send silence stream
12577531beeSTakashi Iwai 					 */
12677531beeSTakashi Iwai 		u32 packet_mode:1;	/* 0: 32bit container, 1: 16bit */
12777531beeSTakashi Iwai 		u32 left_align:1;	/* 0: MSB bits 0-23, 1: bits 8-31 */
12877531beeSTakashi Iwai 		u32 bogus_sample:1;	/* bogus sample for odd channels */
12977531beeSTakashi Iwai 		u32 dp_modei:1;		/* 0: HDMI, 1: DP */
130287599cfSJerome Anand 		u32 rsvd:16;
1317ceba75fSTakashi Iwai 	} regx;
1327ceba75fSTakashi Iwai 	u32 regval;
133287599cfSJerome Anand };
134287599cfSJerome Anand 
13503c34377STakashi Iwai #define AUD_CONFIG_VALID_BIT			(1 << 9)
13603c34377STakashi Iwai #define AUD_CONFIG_DP_MODE			(1 << 15)
13777531beeSTakashi Iwai #define AUD_CONFIG_CH_MASK	0x70
13877531beeSTakashi Iwai #define LAYOUT0			0		/* interleaved stereo */
13977531beeSTakashi Iwai #define LAYOUT1			1		/* for channels > 2 */
14003c34377STakashi Iwai 
1417ceba75fSTakashi Iwai /* Audio Channel Status 0 Attributes */
142287599cfSJerome Anand union aud_ch_status_0 {
143287599cfSJerome Anand 	struct {
144287599cfSJerome Anand 		u32 ch_status:1;
145287599cfSJerome Anand 		u32 lpcm_id:1;
146287599cfSJerome Anand 		u32 cp_info:1;
147287599cfSJerome Anand 		u32 format:3;
148287599cfSJerome Anand 		u32 mode:2;
149287599cfSJerome Anand 		u32 ctg_code:8;
150287599cfSJerome Anand 		u32 src_num:4;
151287599cfSJerome Anand 		u32 ch_num:4;
15277531beeSTakashi Iwai 		u32 samp_freq:4;	/* CH_STATUS_MAP_XXX */
153287599cfSJerome Anand 		u32 clk_acc:2;
154287599cfSJerome Anand 		u32 rsvd:2;
1557ceba75fSTakashi Iwai 	} regx;
1567ceba75fSTakashi Iwai 	u32 regval;
157287599cfSJerome Anand };
158287599cfSJerome Anand 
15977531beeSTakashi Iwai /* samp_freq values - Sampling rate as per IEC60958 Ver 3 */
16077531beeSTakashi Iwai #define CH_STATUS_MAP_32KHZ	0x3
16177531beeSTakashi Iwai #define CH_STATUS_MAP_44KHZ	0x0
16277531beeSTakashi Iwai #define CH_STATUS_MAP_48KHZ	0x2
16377531beeSTakashi Iwai #define CH_STATUS_MAP_88KHZ	0x8
16477531beeSTakashi Iwai #define CH_STATUS_MAP_96KHZ	0xA
16577531beeSTakashi Iwai #define CH_STATUS_MAP_176KHZ	0xC
16677531beeSTakashi Iwai #define CH_STATUS_MAP_192KHZ	0xE
16777531beeSTakashi Iwai 
1687ceba75fSTakashi Iwai /* Audio Channel Status 1 Attributes */
169287599cfSJerome Anand union aud_ch_status_1 {
170287599cfSJerome Anand 	struct {
171287599cfSJerome Anand 		u32 max_wrd_len:1;
172287599cfSJerome Anand 		u32 wrd_len:3;
173287599cfSJerome Anand 		u32 rsvd:28;
1747ceba75fSTakashi Iwai 	} regx;
1757ceba75fSTakashi Iwai 	u32 regval;
176287599cfSJerome Anand };
177287599cfSJerome Anand 
17877531beeSTakashi Iwai #define MAX_SMPL_WIDTH_20	0x0
17977531beeSTakashi Iwai #define MAX_SMPL_WIDTH_24	0x1
18077531beeSTakashi Iwai #define SMPL_WIDTH_16BITS	0x1
18177531beeSTakashi Iwai #define SMPL_WIDTH_24BITS	0x5
18277531beeSTakashi Iwai 
1837ceba75fSTakashi Iwai /* CTS register */
184287599cfSJerome Anand union aud_hdmi_cts {
185287599cfSJerome Anand 	struct {
186287599cfSJerome Anand 		u32 cts_val:24;
187287599cfSJerome Anand 		u32 en_cts_prog:1;
188287599cfSJerome Anand 		u32 rsvd:7;
1897ceba75fSTakashi Iwai 	} regx;
1907ceba75fSTakashi Iwai 	u32 regval;
191287599cfSJerome Anand };
192287599cfSJerome Anand 
1937ceba75fSTakashi Iwai /* N register */
194287599cfSJerome Anand union aud_hdmi_n_enable {
195287599cfSJerome Anand 	struct {
196287599cfSJerome Anand 		u32 n_val:24;
197287599cfSJerome Anand 		u32 en_n_prog:1;
198287599cfSJerome Anand 		u32 rsvd:7;
1997ceba75fSTakashi Iwai 	} regx;
2007ceba75fSTakashi Iwai 	u32 regval;
201287599cfSJerome Anand };
202287599cfSJerome Anand 
2037ceba75fSTakashi Iwai /* Audio Buffer configurations */
204287599cfSJerome Anand union aud_buf_config {
205287599cfSJerome Anand 	struct {
206287599cfSJerome Anand 		u32 audio_fifo_watermark:8;
207287599cfSJerome Anand 		u32 dma_fifo_watermark:3;
208287599cfSJerome Anand 		u32 rsvd0:5;
209287599cfSJerome Anand 		u32 aud_delay:8;
210287599cfSJerome Anand 		u32 rsvd1:8;
2117ceba75fSTakashi Iwai 	} regx;
2127ceba75fSTakashi Iwai 	u32 regval;
213287599cfSJerome Anand };
214287599cfSJerome Anand 
21577531beeSTakashi Iwai #define FIFO_THRESHOLD		0xFE
21677531beeSTakashi Iwai #define DMA_FIFO_THRESHOLD	0x7
21777531beeSTakashi Iwai 
2187ceba75fSTakashi Iwai /* Audio Sample Swapping offset */
219287599cfSJerome Anand union aud_buf_ch_swap {
220287599cfSJerome Anand 	struct {
221287599cfSJerome Anand 		u32 first_0:3;
222287599cfSJerome Anand 		u32 second_0:3;
223287599cfSJerome Anand 		u32 first_1:3;
224287599cfSJerome Anand 		u32 second_1:3;
225287599cfSJerome Anand 		u32 first_2:3;
226287599cfSJerome Anand 		u32 second_2:3;
227287599cfSJerome Anand 		u32 first_3:3;
228287599cfSJerome Anand 		u32 second_3:3;
229287599cfSJerome Anand 		u32 rsvd:8;
2307ceba75fSTakashi Iwai 	} regx;
2317ceba75fSTakashi Iwai 	u32 regval;
232287599cfSJerome Anand };
233287599cfSJerome Anand 
23477531beeSTakashi Iwai #define SWAP_LFE_CENTER		0x00fac4c8	/* octal 76543210 */
23577531beeSTakashi Iwai 
2367ceba75fSTakashi Iwai /* Address for Audio Buffer */
237287599cfSJerome Anand union aud_buf_addr {
238287599cfSJerome Anand 	struct {
239287599cfSJerome Anand 		u32 valid:1;
240287599cfSJerome Anand 		u32 intr_en:1;
241287599cfSJerome Anand 		u32 rsvd:4;
242287599cfSJerome Anand 		u32 addr:26;
2437ceba75fSTakashi Iwai 	} regx;
2447ceba75fSTakashi Iwai 	u32 regval;
245287599cfSJerome Anand };
246287599cfSJerome Anand 
247e1b239f3STakashi Iwai #define AUD_BUF_VALID		(1U << 0)
248e1b239f3STakashi Iwai #define AUD_BUF_INTR_EN		(1U << 1)
249e1b239f3STakashi Iwai 
2507ceba75fSTakashi Iwai /* Length of Audio Buffer */
251287599cfSJerome Anand union aud_buf_len {
252287599cfSJerome Anand 	struct {
253287599cfSJerome Anand 		u32 buf_len:20;
254287599cfSJerome Anand 		u32 rsvd:12;
2557ceba75fSTakashi Iwai 	} regx;
2567ceba75fSTakashi Iwai 	u32 regval;
257287599cfSJerome Anand };
258287599cfSJerome Anand 
2597ceba75fSTakashi Iwai /* Audio Control State Register offset */
260287599cfSJerome Anand union aud_ctrl_st {
261287599cfSJerome Anand 	struct {
262287599cfSJerome Anand 		u32 ram_addr:4;
263287599cfSJerome Anand 		u32 eld_ack:1;
264287599cfSJerome Anand 		u32 eld_addr:4;
265287599cfSJerome Anand 		u32 eld_buf_size:5;
266287599cfSJerome Anand 		u32 eld_valid:1;
267287599cfSJerome Anand 		u32 cp_ready:1;
268287599cfSJerome Anand 		u32 dip_freq:2;
269287599cfSJerome Anand 		u32 dip_idx:3;
270287599cfSJerome Anand 		u32 dip_en_sta:4;
271287599cfSJerome Anand 		u32 rsvd:7;
2727ceba75fSTakashi Iwai 	} regx;
2737ceba75fSTakashi Iwai 	u32 regval;
274287599cfSJerome Anand };
275287599cfSJerome Anand 
2767ceba75fSTakashi Iwai /* Audio HDMI Widget Data Island Packet offset */
277287599cfSJerome Anand union aud_info_frame1 {
278287599cfSJerome Anand 	struct {
279287599cfSJerome Anand 		u32 pkt_type:8;
280287599cfSJerome Anand 		u32 ver_num:8;
281287599cfSJerome Anand 		u32 len:5;
282287599cfSJerome Anand 		u32 rsvd:11;
2837ceba75fSTakashi Iwai 	} regx;
2847ceba75fSTakashi Iwai 	u32 regval;
285287599cfSJerome Anand };
286287599cfSJerome Anand 
28777531beeSTakashi Iwai #define HDMI_INFO_FRAME_WORD1	0x000a0184
28877531beeSTakashi Iwai #define DP_INFO_FRAME_WORD1	0x00441b84
28977531beeSTakashi Iwai 
2907ceba75fSTakashi Iwai /* DIP frame 2 */
291287599cfSJerome Anand union aud_info_frame2 {
292287599cfSJerome Anand 	struct {
293287599cfSJerome Anand 		u32 chksum:8;
294287599cfSJerome Anand 		u32 chnl_cnt:3;
295287599cfSJerome Anand 		u32 rsvd0:1;
296287599cfSJerome Anand 		u32 coding_type:4;
297287599cfSJerome Anand 		u32 smpl_size:2;
298287599cfSJerome Anand 		u32 smpl_freq:3;
299287599cfSJerome Anand 		u32 rsvd1:3;
300287599cfSJerome Anand 		u32 format:8;
3017ceba75fSTakashi Iwai 	} regx;
3027ceba75fSTakashi Iwai 	u32 regval;
303287599cfSJerome Anand };
304287599cfSJerome Anand 
3057ceba75fSTakashi Iwai /* DIP frame 3 */
306287599cfSJerome Anand union aud_info_frame3 {
307287599cfSJerome Anand 	struct {
308287599cfSJerome Anand 		u32 chnl_alloc:8;
309287599cfSJerome Anand 		u32 rsvd0:3;
310287599cfSJerome Anand 		u32 lsv:4;
311287599cfSJerome Anand 		u32 dm_inh:1;
312287599cfSJerome Anand 		u32 rsvd1:16;
3137ceba75fSTakashi Iwai 	} regx;
3147ceba75fSTakashi Iwai 	u32 regval;
315287599cfSJerome Anand };
316287599cfSJerome Anand 
31777531beeSTakashi Iwai #define VALID_DIP_WORDS		3
31877531beeSTakashi Iwai 
31903c34377STakashi Iwai /* AUD_HDMI_STATUS bits */
32003c34377STakashi Iwai #define HDMI_AUDIO_UNDERRUN		(1U << 31)
32103c34377STakashi Iwai #define HDMI_AUDIO_BUFFER_DONE		(1U << 29)
322287599cfSJerome Anand 
32303c34377STakashi Iwai /* AUD_HDMI_STATUS register mask */
32477531beeSTakashi Iwai #define AUD_HDMI_STATUS_MASK_UNDERRUN	0xC0000000
32577531beeSTakashi Iwai #define AUD_HDMI_STATUS_MASK_SRDBG	0x00000002
32677531beeSTakashi Iwai #define AUD_HDMI_STATUSG_MASK_FUNCRST	0x00000001
327287599cfSJerome Anand 
328287599cfSJerome Anand #endif
329