xref: /linux/sound/x86/intel_hdmi_lpe_audio.h (revision 8e8e69d67e5fad1a1edf97acebd649a6c8f1febd)
1*8e8e69d6SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2287599cfSJerome Anand /*
3287599cfSJerome Anand  *   intel_hdmi_lpe_audio.h - Intel HDMI LPE audio driver
4287599cfSJerome Anand  *
5287599cfSJerome Anand  *  Copyright (C) 2016 Intel Corp
6287599cfSJerome Anand  *  Authors:	Sailaja Bandarupalli <sailaja.bandarupalli@intel.com>
7287599cfSJerome Anand  *		Ramesh Babu K V <ramesh.babu@intel.com>
8287599cfSJerome Anand  *		Vaibhav Agarwal <vaibhav.agarwal@intel.com>
9287599cfSJerome Anand  *		Jerome Anand <jerome.anand@intel.com>
10287599cfSJerome Anand  *		Aravind Siddappaji <aravindx.siddappaji@intel.com>
11287599cfSJerome Anand  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12287599cfSJerome Anand  *
13287599cfSJerome Anand  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14287599cfSJerome Anand  */
15287599cfSJerome Anand #ifndef __INTEL_HDMI_LPE_AUDIO_H
16287599cfSJerome Anand #define __INTEL_HDMI_LPE_AUDIO_H
17287599cfSJerome Anand 
18287599cfSJerome Anand #define HAD_MIN_CHANNEL		2
19287599cfSJerome Anand #define HAD_MAX_CHANNEL		8
20287599cfSJerome Anand #define HAD_NUM_OF_RING_BUFS	4
21287599cfSJerome Anand 
22e1b239f3STakashi Iwai /* max 20bit address, aligned to 64 */
23e1b239f3STakashi Iwai #define HAD_MAX_BUFFER		((1024 * 1024 - 1) & ~0x3f)
24e1b239f3STakashi Iwai #define HAD_DEFAULT_BUFFER	(600 * 1024) /* default prealloc size */
25e1b239f3STakashi Iwai #define HAD_MAX_PERIODS		256	/* arbitrary, but should suffice */
268d48c016STakashi Iwai #define HAD_MIN_PERIODS		1
27e1b239f3STakashi Iwai #define HAD_MAX_PERIOD_BYTES	((HAD_MAX_BUFFER / HAD_MIN_PERIODS) & ~0x3f)
28e1b239f3STakashi Iwai #define HAD_MIN_PERIOD_BYTES	1024	/* might be smaller */
29287599cfSJerome Anand #define HAD_FIFO_SIZE		0 /* fifo not being used */
30287599cfSJerome Anand #define MAX_SPEAKERS		8
31287599cfSJerome Anand 
32287599cfSJerome Anand #define AUD_SAMPLE_RATE_32	32000
33287599cfSJerome Anand #define AUD_SAMPLE_RATE_44_1	44100
34287599cfSJerome Anand #define AUD_SAMPLE_RATE_48	48000
35287599cfSJerome Anand #define AUD_SAMPLE_RATE_88_2	88200
36287599cfSJerome Anand #define AUD_SAMPLE_RATE_96	96000
37287599cfSJerome Anand #define AUD_SAMPLE_RATE_176_4	176400
38287599cfSJerome Anand #define AUD_SAMPLE_RATE_192	192000
39287599cfSJerome Anand 
40287599cfSJerome Anand #define HAD_MIN_RATE		AUD_SAMPLE_RATE_32
41287599cfSJerome Anand #define HAD_MAX_RATE		AUD_SAMPLE_RATE_192
42287599cfSJerome Anand 
43287599cfSJerome Anand #define DIS_SAMPLE_RATE_25_2	25200
44287599cfSJerome Anand #define DIS_SAMPLE_RATE_27	27000
45287599cfSJerome Anand #define DIS_SAMPLE_RATE_54	54000
46287599cfSJerome Anand #define DIS_SAMPLE_RATE_74_25	74250
47287599cfSJerome Anand #define DIS_SAMPLE_RATE_148_5	148500
48287599cfSJerome Anand #define HAD_REG_WIDTH		0x08
49287599cfSJerome Anand #define HAD_MAX_DIP_WORDS		16
50287599cfSJerome Anand 
51964ca808SPierre-Louis Bossart /* DP Link Rates */
52964ca808SPierre-Louis Bossart #define DP_2_7_GHZ			270000
53964ca808SPierre-Louis Bossart #define DP_1_62_GHZ			162000
54964ca808SPierre-Louis Bossart 
55964ca808SPierre-Louis Bossart /* Maud Values */
56964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_32_DP_2_7_MAUD_VAL		1988
57964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_44_1_DP_2_7_MAUD_VAL		2740
58964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_48_DP_2_7_MAUD_VAL		2982
59964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_88_2_DP_2_7_MAUD_VAL		5480
60964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_96_DP_2_7_MAUD_VAL		5965
61964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_176_4_DP_2_7_MAUD_VAL		10961
62964ca808SPierre-Louis Bossart #define HAD_MAX_RATE_DP_2_7_MAUD_VAL			11930
63964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_32_DP_1_62_MAUD_VAL		3314
64964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_44_1_DP_1_62_MAUD_VAL		4567
65964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_48_DP_1_62_MAUD_VAL		4971
66964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_88_2_DP_1_62_MAUD_VAL		9134
67964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_96_DP_1_62_MAUD_VAL		9942
68964ca808SPierre-Louis Bossart #define AUD_SAMPLE_RATE_176_4_DP_1_62_MAUD_VAL		18268
69964ca808SPierre-Louis Bossart #define HAD_MAX_RATE_DP_1_62_MAUD_VAL			19884
70964ca808SPierre-Louis Bossart 
71964ca808SPierre-Louis Bossart /* Naud Value */
72964ca808SPierre-Louis Bossart #define DP_NAUD_VAL					32768
73964ca808SPierre-Louis Bossart 
74287599cfSJerome Anand /* HDMI Controller register offsets - audio domain common */
75287599cfSJerome Anand /* Base address for below regs = 0x65000 */
76287599cfSJerome Anand enum hdmi_ctrl_reg_offset_common {
77287599cfSJerome Anand 	AUDIO_HDMI_CONFIG_A = 0x000,
78287599cfSJerome Anand 	AUDIO_HDMI_CONFIG_B = 0x800,
79287599cfSJerome Anand 	AUDIO_HDMI_CONFIG_C = 0x900,
80287599cfSJerome Anand };
81287599cfSJerome Anand /* HDMI controller register offsets */
824151ee84STakashi Iwai enum hdmi_ctrl_reg_offset {
83287599cfSJerome Anand 	AUD_CONFIG		= 0x0,
84287599cfSJerome Anand 	AUD_CH_STATUS_0		= 0x08,
85287599cfSJerome Anand 	AUD_CH_STATUS_1		= 0x0C,
86287599cfSJerome Anand 	AUD_HDMI_CTS		= 0x10,
87287599cfSJerome Anand 	AUD_N_ENABLE		= 0x14,
88287599cfSJerome Anand 	AUD_SAMPLE_RATE		= 0x18,
89287599cfSJerome Anand 	AUD_BUF_CONFIG		= 0x20,
90287599cfSJerome Anand 	AUD_BUF_CH_SWAP		= 0x24,
91287599cfSJerome Anand 	AUD_BUF_A_ADDR		= 0x40,
92287599cfSJerome Anand 	AUD_BUF_A_LENGTH	= 0x44,
93287599cfSJerome Anand 	AUD_BUF_B_ADDR		= 0x48,
94287599cfSJerome Anand 	AUD_BUF_B_LENGTH	= 0x4c,
95287599cfSJerome Anand 	AUD_BUF_C_ADDR		= 0x50,
96287599cfSJerome Anand 	AUD_BUF_C_LENGTH	= 0x54,
97287599cfSJerome Anand 	AUD_BUF_D_ADDR		= 0x58,
98287599cfSJerome Anand 	AUD_BUF_D_LENGTH	= 0x5c,
99287599cfSJerome Anand 	AUD_CNTL_ST		= 0x60,
1004151ee84STakashi Iwai 	AUD_HDMI_STATUS		= 0x64, /* v2 */
1014151ee84STakashi Iwai 	AUD_HDMIW_INFOFR	= 0x68, /* v2 */
102287599cfSJerome Anand };
103287599cfSJerome Anand 
1047ceba75fSTakashi Iwai /* Audio configuration */
105287599cfSJerome Anand union aud_cfg {
106287599cfSJerome Anand 	struct {
107287599cfSJerome Anand 		u32 aud_en:1;
10877531beeSTakashi Iwai 		u32 layout:1;		/* LAYOUT[01], see below */
109287599cfSJerome Anand 		u32 fmt:2;
110287599cfSJerome Anand 		u32 num_ch:3;
111287599cfSJerome Anand 		u32 set:1;
112287599cfSJerome Anand 		u32 flat:1;
113287599cfSJerome Anand 		u32 val_bit:1;
114287599cfSJerome Anand 		u32 user_bit:1;
11577531beeSTakashi Iwai 		u32 underrun:1;		/* 0: send null packets,
11677531beeSTakashi Iwai 					 * 1: send silence stream
11777531beeSTakashi Iwai 					 */
11877531beeSTakashi Iwai 		u32 packet_mode:1;	/* 0: 32bit container, 1: 16bit */
11977531beeSTakashi Iwai 		u32 left_align:1;	/* 0: MSB bits 0-23, 1: bits 8-31 */
12077531beeSTakashi Iwai 		u32 bogus_sample:1;	/* bogus sample for odd channels */
12177531beeSTakashi Iwai 		u32 dp_modei:1;		/* 0: HDMI, 1: DP */
122287599cfSJerome Anand 		u32 rsvd:16;
1237ceba75fSTakashi Iwai 	} regx;
1247ceba75fSTakashi Iwai 	u32 regval;
125287599cfSJerome Anand };
126287599cfSJerome Anand 
12703c34377STakashi Iwai #define AUD_CONFIG_VALID_BIT			(1 << 9)
12803c34377STakashi Iwai #define AUD_CONFIG_DP_MODE			(1 << 15)
12977531beeSTakashi Iwai #define AUD_CONFIG_CH_MASK	0x70
13077531beeSTakashi Iwai #define LAYOUT0			0		/* interleaved stereo */
13177531beeSTakashi Iwai #define LAYOUT1			1		/* for channels > 2 */
13203c34377STakashi Iwai 
1337ceba75fSTakashi Iwai /* Audio Channel Status 0 Attributes */
134287599cfSJerome Anand union aud_ch_status_0 {
135287599cfSJerome Anand 	struct {
136287599cfSJerome Anand 		u32 ch_status:1;
137287599cfSJerome Anand 		u32 lpcm_id:1;
138287599cfSJerome Anand 		u32 cp_info:1;
139287599cfSJerome Anand 		u32 format:3;
140287599cfSJerome Anand 		u32 mode:2;
141287599cfSJerome Anand 		u32 ctg_code:8;
142287599cfSJerome Anand 		u32 src_num:4;
143287599cfSJerome Anand 		u32 ch_num:4;
14477531beeSTakashi Iwai 		u32 samp_freq:4;	/* CH_STATUS_MAP_XXX */
145287599cfSJerome Anand 		u32 clk_acc:2;
146287599cfSJerome Anand 		u32 rsvd:2;
1477ceba75fSTakashi Iwai 	} regx;
1487ceba75fSTakashi Iwai 	u32 regval;
149287599cfSJerome Anand };
150287599cfSJerome Anand 
15177531beeSTakashi Iwai /* samp_freq values - Sampling rate as per IEC60958 Ver 3 */
15277531beeSTakashi Iwai #define CH_STATUS_MAP_32KHZ	0x3
15377531beeSTakashi Iwai #define CH_STATUS_MAP_44KHZ	0x0
15477531beeSTakashi Iwai #define CH_STATUS_MAP_48KHZ	0x2
15577531beeSTakashi Iwai #define CH_STATUS_MAP_88KHZ	0x8
15677531beeSTakashi Iwai #define CH_STATUS_MAP_96KHZ	0xA
15777531beeSTakashi Iwai #define CH_STATUS_MAP_176KHZ	0xC
15877531beeSTakashi Iwai #define CH_STATUS_MAP_192KHZ	0xE
15977531beeSTakashi Iwai 
1607ceba75fSTakashi Iwai /* Audio Channel Status 1 Attributes */
161287599cfSJerome Anand union aud_ch_status_1 {
162287599cfSJerome Anand 	struct {
163287599cfSJerome Anand 		u32 max_wrd_len:1;
164287599cfSJerome Anand 		u32 wrd_len:3;
165287599cfSJerome Anand 		u32 rsvd:28;
1667ceba75fSTakashi Iwai 	} regx;
1677ceba75fSTakashi Iwai 	u32 regval;
168287599cfSJerome Anand };
169287599cfSJerome Anand 
17077531beeSTakashi Iwai #define MAX_SMPL_WIDTH_20	0x0
17177531beeSTakashi Iwai #define MAX_SMPL_WIDTH_24	0x1
17277531beeSTakashi Iwai #define SMPL_WIDTH_16BITS	0x1
17377531beeSTakashi Iwai #define SMPL_WIDTH_24BITS	0x5
17477531beeSTakashi Iwai 
1757ceba75fSTakashi Iwai /* CTS register */
176287599cfSJerome Anand union aud_hdmi_cts {
177287599cfSJerome Anand 	struct {
178287599cfSJerome Anand 		u32 cts_val:24;
179287599cfSJerome Anand 		u32 en_cts_prog:1;
180287599cfSJerome Anand 		u32 rsvd:7;
1817ceba75fSTakashi Iwai 	} regx;
1827ceba75fSTakashi Iwai 	u32 regval;
183287599cfSJerome Anand };
184287599cfSJerome Anand 
1857ceba75fSTakashi Iwai /* N register */
186287599cfSJerome Anand union aud_hdmi_n_enable {
187287599cfSJerome Anand 	struct {
188287599cfSJerome Anand 		u32 n_val:24;
189287599cfSJerome Anand 		u32 en_n_prog:1;
190287599cfSJerome Anand 		u32 rsvd:7;
1917ceba75fSTakashi Iwai 	} regx;
1927ceba75fSTakashi Iwai 	u32 regval;
193287599cfSJerome Anand };
194287599cfSJerome Anand 
1957ceba75fSTakashi Iwai /* Audio Buffer configurations */
196287599cfSJerome Anand union aud_buf_config {
197287599cfSJerome Anand 	struct {
198287599cfSJerome Anand 		u32 audio_fifo_watermark:8;
199287599cfSJerome Anand 		u32 dma_fifo_watermark:3;
200287599cfSJerome Anand 		u32 rsvd0:5;
201287599cfSJerome Anand 		u32 aud_delay:8;
202287599cfSJerome Anand 		u32 rsvd1:8;
2037ceba75fSTakashi Iwai 	} regx;
2047ceba75fSTakashi Iwai 	u32 regval;
205287599cfSJerome Anand };
206287599cfSJerome Anand 
20777531beeSTakashi Iwai #define FIFO_THRESHOLD		0xFE
20877531beeSTakashi Iwai #define DMA_FIFO_THRESHOLD	0x7
20977531beeSTakashi Iwai 
2107ceba75fSTakashi Iwai /* Audio Sample Swapping offset */
211287599cfSJerome Anand union aud_buf_ch_swap {
212287599cfSJerome Anand 	struct {
213287599cfSJerome Anand 		u32 first_0:3;
214287599cfSJerome Anand 		u32 second_0:3;
215287599cfSJerome Anand 		u32 first_1:3;
216287599cfSJerome Anand 		u32 second_1:3;
217287599cfSJerome Anand 		u32 first_2:3;
218287599cfSJerome Anand 		u32 second_2:3;
219287599cfSJerome Anand 		u32 first_3:3;
220287599cfSJerome Anand 		u32 second_3:3;
221287599cfSJerome Anand 		u32 rsvd:8;
2227ceba75fSTakashi Iwai 	} regx;
2237ceba75fSTakashi Iwai 	u32 regval;
224287599cfSJerome Anand };
225287599cfSJerome Anand 
22677531beeSTakashi Iwai #define SWAP_LFE_CENTER		0x00fac4c8	/* octal 76543210 */
22777531beeSTakashi Iwai 
2287ceba75fSTakashi Iwai /* Address for Audio Buffer */
229287599cfSJerome Anand union aud_buf_addr {
230287599cfSJerome Anand 	struct {
231287599cfSJerome Anand 		u32 valid:1;
232287599cfSJerome Anand 		u32 intr_en:1;
233287599cfSJerome Anand 		u32 rsvd:4;
234287599cfSJerome Anand 		u32 addr:26;
2357ceba75fSTakashi Iwai 	} regx;
2367ceba75fSTakashi Iwai 	u32 regval;
237287599cfSJerome Anand };
238287599cfSJerome Anand 
239e1b239f3STakashi Iwai #define AUD_BUF_VALID		(1U << 0)
240e1b239f3STakashi Iwai #define AUD_BUF_INTR_EN		(1U << 1)
241e1b239f3STakashi Iwai 
2427ceba75fSTakashi Iwai /* Length of Audio Buffer */
243287599cfSJerome Anand union aud_buf_len {
244287599cfSJerome Anand 	struct {
245287599cfSJerome Anand 		u32 buf_len:20;
246287599cfSJerome Anand 		u32 rsvd:12;
2477ceba75fSTakashi Iwai 	} regx;
2487ceba75fSTakashi Iwai 	u32 regval;
249287599cfSJerome Anand };
250287599cfSJerome Anand 
2517ceba75fSTakashi Iwai /* Audio Control State Register offset */
252287599cfSJerome Anand union aud_ctrl_st {
253287599cfSJerome Anand 	struct {
254287599cfSJerome Anand 		u32 ram_addr:4;
255287599cfSJerome Anand 		u32 eld_ack:1;
256287599cfSJerome Anand 		u32 eld_addr:4;
257287599cfSJerome Anand 		u32 eld_buf_size:5;
258287599cfSJerome Anand 		u32 eld_valid:1;
259287599cfSJerome Anand 		u32 cp_ready:1;
260287599cfSJerome Anand 		u32 dip_freq:2;
261287599cfSJerome Anand 		u32 dip_idx:3;
262287599cfSJerome Anand 		u32 dip_en_sta:4;
263287599cfSJerome Anand 		u32 rsvd:7;
2647ceba75fSTakashi Iwai 	} regx;
2657ceba75fSTakashi Iwai 	u32 regval;
266287599cfSJerome Anand };
267287599cfSJerome Anand 
2687ceba75fSTakashi Iwai /* Audio HDMI Widget Data Island Packet offset */
269287599cfSJerome Anand union aud_info_frame1 {
270287599cfSJerome Anand 	struct {
271287599cfSJerome Anand 		u32 pkt_type:8;
272287599cfSJerome Anand 		u32 ver_num:8;
273287599cfSJerome Anand 		u32 len:5;
274287599cfSJerome Anand 		u32 rsvd:11;
2757ceba75fSTakashi Iwai 	} regx;
2767ceba75fSTakashi Iwai 	u32 regval;
277287599cfSJerome Anand };
278287599cfSJerome Anand 
27977531beeSTakashi Iwai #define HDMI_INFO_FRAME_WORD1	0x000a0184
28077531beeSTakashi Iwai #define DP_INFO_FRAME_WORD1	0x00441b84
28177531beeSTakashi Iwai 
2827ceba75fSTakashi Iwai /* DIP frame 2 */
283287599cfSJerome Anand union aud_info_frame2 {
284287599cfSJerome Anand 	struct {
285287599cfSJerome Anand 		u32 chksum:8;
286287599cfSJerome Anand 		u32 chnl_cnt:3;
287287599cfSJerome Anand 		u32 rsvd0:1;
288287599cfSJerome Anand 		u32 coding_type:4;
289287599cfSJerome Anand 		u32 smpl_size:2;
290287599cfSJerome Anand 		u32 smpl_freq:3;
291287599cfSJerome Anand 		u32 rsvd1:3;
292287599cfSJerome Anand 		u32 format:8;
2937ceba75fSTakashi Iwai 	} regx;
2947ceba75fSTakashi Iwai 	u32 regval;
295287599cfSJerome Anand };
296287599cfSJerome Anand 
2977ceba75fSTakashi Iwai /* DIP frame 3 */
298287599cfSJerome Anand union aud_info_frame3 {
299287599cfSJerome Anand 	struct {
300287599cfSJerome Anand 		u32 chnl_alloc:8;
301287599cfSJerome Anand 		u32 rsvd0:3;
302287599cfSJerome Anand 		u32 lsv:4;
303287599cfSJerome Anand 		u32 dm_inh:1;
304287599cfSJerome Anand 		u32 rsvd1:16;
3057ceba75fSTakashi Iwai 	} regx;
3067ceba75fSTakashi Iwai 	u32 regval;
307287599cfSJerome Anand };
308287599cfSJerome Anand 
30977531beeSTakashi Iwai #define VALID_DIP_WORDS		3
31077531beeSTakashi Iwai 
31103c34377STakashi Iwai /* AUD_HDMI_STATUS bits */
31203c34377STakashi Iwai #define HDMI_AUDIO_UNDERRUN		(1U << 31)
31303c34377STakashi Iwai #define HDMI_AUDIO_BUFFER_DONE		(1U << 29)
314287599cfSJerome Anand 
31503c34377STakashi Iwai /* AUD_HDMI_STATUS register mask */
31677531beeSTakashi Iwai #define AUD_HDMI_STATUS_MASK_UNDERRUN	0xC0000000
31777531beeSTakashi Iwai #define AUD_HDMI_STATUS_MASK_SRDBG	0x00000002
31877531beeSTakashi Iwai #define AUD_HDMI_STATUSG_MASK_FUNCRST	0x00000001
319287599cfSJerome Anand 
320287599cfSJerome Anand #endif
321