xref: /linux/sound/soc/fsl/fsl_spdif.h (revision 1bfa3eaa4511256ab14555ab2573e6e75194b1fa)
1165a30e4SFabio Estevam /* SPDX-License-Identifier: GPL-2.0 */
2a2388a49SNicolin Chen /*
3a2388a49SNicolin Chen  * fsl_spdif.h - ALSA S/PDIF interface for the Freescale i.MX SoC
4a2388a49SNicolin Chen  *
5a2388a49SNicolin Chen  * Copyright (C) 2013 Freescale Semiconductor, Inc.
6a2388a49SNicolin Chen  *
7a2388a49SNicolin Chen  * Author: Nicolin Chen <b42378@freescale.com>
8a2388a49SNicolin Chen  *
9a2388a49SNicolin Chen  * Based on fsl_ssi.h
10a2388a49SNicolin Chen  * Author: Timur Tabi <timur@freescale.com>
11a2388a49SNicolin Chen  * Copyright 2007-2008 Freescale Semiconductor, Inc.
12a2388a49SNicolin Chen  */
13a2388a49SNicolin Chen 
14a2388a49SNicolin Chen #ifndef _FSL_SPDIF_DAI_H
15a2388a49SNicolin Chen #define _FSL_SPDIF_DAI_H
16a2388a49SNicolin Chen 
17a2388a49SNicolin Chen /* S/PDIF Register Map */
18a2388a49SNicolin Chen #define REG_SPDIF_SCR 			0x0	/* SPDIF Configuration Register */
19a2388a49SNicolin Chen #define REG_SPDIF_SRCD		 	0x4	/* CDText Control Register */
20a2388a49SNicolin Chen #define REG_SPDIF_SRPC			0x8	/* PhaseConfig Register */
21a2388a49SNicolin Chen #define REG_SPDIF_SIE			0xc	/* InterruptEn Register */
22a2388a49SNicolin Chen #define REG_SPDIF_SIS			0x10	/* InterruptStat Register */
23a2388a49SNicolin Chen #define REG_SPDIF_SIC			0x10	/* InterruptClear Register */
24a2388a49SNicolin Chen #define REG_SPDIF_SRL			0x14	/* SPDIFRxLeft Register */
25a2388a49SNicolin Chen #define REG_SPDIF_SRR			0x18	/* SPDIFRxRight Register */
26a2388a49SNicolin Chen #define REG_SPDIF_SRCSH			0x1c	/* SPDIFRxCChannel_h Register */
27a2388a49SNicolin Chen #define REG_SPDIF_SRCSL			0x20	/* SPDIFRxCChannel_l Register */
28a2388a49SNicolin Chen #define REG_SPDIF_SRU			0x24	/* UchannelRx Register */
29a2388a49SNicolin Chen #define REG_SPDIF_SRQ			0x28	/* QchannelRx Register */
30a2388a49SNicolin Chen #define REG_SPDIF_STL			0x2C	/* SPDIFTxLeft Register */
31a2388a49SNicolin Chen #define REG_SPDIF_STR			0x30	/* SPDIFTxRight Register */
32a2388a49SNicolin Chen #define REG_SPDIF_STCSCH		0x34	/* SPDIFTxCChannelCons_h Register */
33a2388a49SNicolin Chen #define REG_SPDIF_STCSCL		0x38	/* SPDIFTxCChannelCons_l Register */
34a2388a49SNicolin Chen #define REG_SPDIF_SRFM			0x44	/* FreqMeas Register */
35a2388a49SNicolin Chen #define REG_SPDIF_STC			0x50	/* SPDIFTxClk Register */
36a2388a49SNicolin Chen 
37a2388a49SNicolin Chen 
38a2388a49SNicolin Chen /* SPDIF Configuration register */
39a2388a49SNicolin Chen #define SCR_RXFIFO_CTL_OFFSET		23
40a2388a49SNicolin Chen #define SCR_RXFIFO_CTL_MASK		(1 << SCR_RXFIFO_CTL_OFFSET)
41a2388a49SNicolin Chen #define SCR_RXFIFO_CTL_ZERO		(1 << SCR_RXFIFO_CTL_OFFSET)
42a2388a49SNicolin Chen #define SCR_RXFIFO_OFF_OFFSET		22
43a2388a49SNicolin Chen #define SCR_RXFIFO_OFF_MASK		(1 << SCR_RXFIFO_OFF_OFFSET)
44a2388a49SNicolin Chen #define SCR_RXFIFO_OFF			(1 << SCR_RXFIFO_OFF_OFFSET)
45a2388a49SNicolin Chen #define SCR_RXFIFO_RST_OFFSET		21
46a2388a49SNicolin Chen #define SCR_RXFIFO_RST_MASK		(1 << SCR_RXFIFO_RST_OFFSET)
47a2388a49SNicolin Chen #define SCR_RXFIFO_RST			(1 << SCR_RXFIFO_RST_OFFSET)
48a2388a49SNicolin Chen #define SCR_RXFIFO_FSEL_OFFSET		19
49a2388a49SNicolin Chen #define SCR_RXFIFO_FSEL_MASK		(0x3 << SCR_RXFIFO_FSEL_OFFSET)
50a2388a49SNicolin Chen #define SCR_RXFIFO_FSEL_IF0		(0x0 << SCR_RXFIFO_FSEL_OFFSET)
51a2388a49SNicolin Chen #define SCR_RXFIFO_FSEL_IF4		(0x1 << SCR_RXFIFO_FSEL_OFFSET)
52a2388a49SNicolin Chen #define SCR_RXFIFO_FSEL_IF8		(0x2 << SCR_RXFIFO_FSEL_OFFSET)
53a2388a49SNicolin Chen #define SCR_RXFIFO_FSEL_IF12		(0x3 << SCR_RXFIFO_FSEL_OFFSET)
54a2388a49SNicolin Chen #define SCR_RXFIFO_AUTOSYNC_OFFSET	18
55a2388a49SNicolin Chen #define SCR_RXFIFO_AUTOSYNC_MASK	(1 << SCR_RXFIFO_AUTOSYNC_OFFSET)
56a2388a49SNicolin Chen #define SCR_RXFIFO_AUTOSYNC		(1 << SCR_RXFIFO_AUTOSYNC_OFFSET)
57a2388a49SNicolin Chen #define SCR_TXFIFO_AUTOSYNC_OFFSET	17
58a2388a49SNicolin Chen #define SCR_TXFIFO_AUTOSYNC_MASK	(1 << SCR_TXFIFO_AUTOSYNC_OFFSET)
59a2388a49SNicolin Chen #define SCR_TXFIFO_AUTOSYNC		(1 << SCR_TXFIFO_AUTOSYNC_OFFSET)
60a2388a49SNicolin Chen #define SCR_TXFIFO_FSEL_OFFSET		15
61a2388a49SNicolin Chen #define SCR_TXFIFO_FSEL_MASK		(0x3 << SCR_TXFIFO_FSEL_OFFSET)
62a2388a49SNicolin Chen #define SCR_TXFIFO_FSEL_IF0		(0x0 << SCR_TXFIFO_FSEL_OFFSET)
63a2388a49SNicolin Chen #define SCR_TXFIFO_FSEL_IF4		(0x1 << SCR_TXFIFO_FSEL_OFFSET)
64a2388a49SNicolin Chen #define SCR_TXFIFO_FSEL_IF8		(0x2 << SCR_TXFIFO_FSEL_OFFSET)
65a2388a49SNicolin Chen #define SCR_TXFIFO_FSEL_IF12		(0x3 << SCR_TXFIFO_FSEL_OFFSET)
66a2388a49SNicolin Chen #define SCR_LOW_POWER			(1 << 13)
67a2388a49SNicolin Chen #define SCR_SOFT_RESET			(1 << 12)
68a2388a49SNicolin Chen #define SCR_TXFIFO_CTRL_OFFSET		10
69a2388a49SNicolin Chen #define SCR_TXFIFO_CTRL_MASK		(0x3 << SCR_TXFIFO_CTRL_OFFSET)
70a2388a49SNicolin Chen #define SCR_TXFIFO_CTRL_ZERO		(0x0 << SCR_TXFIFO_CTRL_OFFSET)
71a2388a49SNicolin Chen #define SCR_TXFIFO_CTRL_NORMAL		(0x1 << SCR_TXFIFO_CTRL_OFFSET)
72a2388a49SNicolin Chen #define SCR_TXFIFO_CTRL_ONESAMPLE	(0x2 << SCR_TXFIFO_CTRL_OFFSET)
73a2388a49SNicolin Chen #define SCR_DMA_RX_EN_OFFSET		9
74a2388a49SNicolin Chen #define SCR_DMA_RX_EN_MASK		(1 << SCR_DMA_RX_EN_OFFSET)
75a2388a49SNicolin Chen #define SCR_DMA_RX_EN			(1 << SCR_DMA_RX_EN_OFFSET)
76a2388a49SNicolin Chen #define SCR_DMA_TX_EN_OFFSET		8
77a2388a49SNicolin Chen #define SCR_DMA_TX_EN_MASK		(1 << SCR_DMA_TX_EN_OFFSET)
78a2388a49SNicolin Chen #define SCR_DMA_TX_EN			(1 << SCR_DMA_TX_EN_OFFSET)
79a2388a49SNicolin Chen #define SCR_VAL_OFFSET			5
80a2388a49SNicolin Chen #define SCR_VAL_MASK			(1 << SCR_VAL_OFFSET)
81a2388a49SNicolin Chen #define SCR_VAL_CLEAR			(1 << SCR_VAL_OFFSET)
82a2388a49SNicolin Chen #define SCR_TXSEL_OFFSET		2
83a2388a49SNicolin Chen #define SCR_TXSEL_MASK			(0x7 << SCR_TXSEL_OFFSET)
84a2388a49SNicolin Chen #define SCR_TXSEL_OFF			(0 << SCR_TXSEL_OFFSET)
85a2388a49SNicolin Chen #define SCR_TXSEL_RX			(1 << SCR_TXSEL_OFFSET)
86a2388a49SNicolin Chen #define SCR_TXSEL_NORMAL		(0x5 << SCR_TXSEL_OFFSET)
87a2388a49SNicolin Chen #define SCR_USRC_SEL_OFFSET		0x0
88a2388a49SNicolin Chen #define SCR_USRC_SEL_MASK		(0x3 << SCR_USRC_SEL_OFFSET)
89a2388a49SNicolin Chen #define SCR_USRC_SEL_NONE		(0x0 << SCR_USRC_SEL_OFFSET)
90a2388a49SNicolin Chen #define SCR_USRC_SEL_RECV		(0x1 << SCR_USRC_SEL_OFFSET)
91a2388a49SNicolin Chen #define SCR_USRC_SEL_CHIP		(0x3 << SCR_USRC_SEL_OFFSET)
92a2388a49SNicolin Chen 
93f3a30baaSNicolin Chen #define SCR_DMA_xX_EN(tx)		(tx ? SCR_DMA_TX_EN : SCR_DMA_RX_EN)
94f3a30baaSNicolin Chen 
95a2388a49SNicolin Chen /* SPDIF CDText control */
96a2388a49SNicolin Chen #define SRCD_CD_USER_OFFSET		1
97a2388a49SNicolin Chen #define SRCD_CD_USER			(1 << SRCD_CD_USER_OFFSET)
98a2388a49SNicolin Chen 
99a2388a49SNicolin Chen /* SPDIF Phase Configuration register */
100a2388a49SNicolin Chen #define SRPC_DPLL_LOCKED		(1 << 6)
101a2388a49SNicolin Chen #define SRPC_CLKSRC_SEL_OFFSET		7
102a2388a49SNicolin Chen #define SRPC_CLKSRC_SEL_MASK		(0xf << SRPC_CLKSRC_SEL_OFFSET)
103a2388a49SNicolin Chen #define SRPC_CLKSRC_SEL_SET(x)		((x << SRPC_CLKSRC_SEL_OFFSET) & SRPC_CLKSRC_SEL_MASK)
104a2388a49SNicolin Chen #define SRPC_CLKSRC_SEL_LOCKED_OFFSET1	5
105a2388a49SNicolin Chen #define SRPC_CLKSRC_SEL_LOCKED_OFFSET2	2
106a2388a49SNicolin Chen #define SRPC_GAINSEL_OFFSET		3
107a2388a49SNicolin Chen #define SRPC_GAINSEL_MASK		(0x7 << SRPC_GAINSEL_OFFSET)
108a2388a49SNicolin Chen #define SRPC_GAINSEL_SET(x)		((x << SRPC_GAINSEL_OFFSET) & SRPC_GAINSEL_MASK)
109a2388a49SNicolin Chen 
110a2388a49SNicolin Chen #define SRPC_CLKSRC_MAX			16
111a2388a49SNicolin Chen 
112a2388a49SNicolin Chen enum spdif_gainsel {
113a2388a49SNicolin Chen 	GAINSEL_MULTI_24 = 0,
114a2388a49SNicolin Chen 	GAINSEL_MULTI_16,
115a2388a49SNicolin Chen 	GAINSEL_MULTI_12,
116a2388a49SNicolin Chen 	GAINSEL_MULTI_8,
117a2388a49SNicolin Chen 	GAINSEL_MULTI_6,
118a2388a49SNicolin Chen 	GAINSEL_MULTI_4,
119a2388a49SNicolin Chen 	GAINSEL_MULTI_3,
120a2388a49SNicolin Chen };
121a2388a49SNicolin Chen #define GAINSEL_MULTI_MAX		(GAINSEL_MULTI_3 + 1)
122a2388a49SNicolin Chen #define SPDIF_DEFAULT_GAINSEL		GAINSEL_MULTI_8
123a2388a49SNicolin Chen 
124a2388a49SNicolin Chen /* SPDIF interrupt mask define */
125a2388a49SNicolin Chen #define INT_DPLL_LOCKED			(1 << 20)
126a2388a49SNicolin Chen #define INT_TXFIFO_UNOV			(1 << 19)
127a2388a49SNicolin Chen #define INT_TXFIFO_RESYNC		(1 << 18)
128a2388a49SNicolin Chen #define INT_CNEW			(1 << 17)
129a2388a49SNicolin Chen #define INT_VAL_NOGOOD			(1 << 16)
130a2388a49SNicolin Chen #define INT_SYM_ERR			(1 << 15)
131a2388a49SNicolin Chen #define INT_BIT_ERR			(1 << 14)
132a2388a49SNicolin Chen #define INT_URX_FUL			(1 << 10)
133a2388a49SNicolin Chen #define INT_URX_OV			(1 << 9)
134a2388a49SNicolin Chen #define INT_QRX_FUL			(1 << 8)
135a2388a49SNicolin Chen #define INT_QRX_OV			(1 << 7)
136a2388a49SNicolin Chen #define INT_UQ_SYNC			(1 << 6)
137a2388a49SNicolin Chen #define INT_UQ_ERR			(1 << 5)
138a2388a49SNicolin Chen #define INT_RXFIFO_UNOV			(1 << 4)
139a2388a49SNicolin Chen #define INT_RXFIFO_RESYNC		(1 << 3)
140a2388a49SNicolin Chen #define INT_LOSS_LOCK			(1 << 2)
141a2388a49SNicolin Chen #define INT_TX_EM			(1 << 1)
142a2388a49SNicolin Chen #define INT_RXFIFO_FUL			(1 << 0)
143a2388a49SNicolin Chen 
144a2388a49SNicolin Chen /* SPDIF Clock register */
145e41a4a79SNicolin Chen #define STC_SYSCLK_DF_OFFSET		11
146e41a4a79SNicolin Chen #define STC_SYSCLK_DF_MASK		(0x1ff << STC_SYSCLK_DF_OFFSET)
147e41a4a79SNicolin Chen #define STC_SYSCLK_DF(x)		((((x) - 1) << STC_SYSCLK_DF_OFFSET) & STC_SYSCLK_DF_MASK)
148a2388a49SNicolin Chen #define STC_TXCLK_SRC_OFFSET		8
149a2388a49SNicolin Chen #define STC_TXCLK_SRC_MASK		(0x7 << STC_TXCLK_SRC_OFFSET)
150a2388a49SNicolin Chen #define STC_TXCLK_SRC_SET(x)		((x << STC_TXCLK_SRC_OFFSET) & STC_TXCLK_SRC_MASK)
151a2388a49SNicolin Chen #define STC_TXCLK_ALL_EN_OFFSET		7
152a2388a49SNicolin Chen #define STC_TXCLK_ALL_EN_MASK		(1 << STC_TXCLK_ALL_EN_OFFSET)
153a2388a49SNicolin Chen #define STC_TXCLK_ALL_EN		(1 << STC_TXCLK_ALL_EN_OFFSET)
154e41a4a79SNicolin Chen #define STC_TXCLK_DF_OFFSET		0
15530c498a1SViorel Suman #define STC_TXCLK_DF_MASK		(0x7f << STC_TXCLK_DF_OFFSET)
156e41a4a79SNicolin Chen #define STC_TXCLK_DF(x)		((((x) - 1) << STC_TXCLK_DF_OFFSET) & STC_TXCLK_DF_MASK)
157a2388a49SNicolin Chen #define STC_TXCLK_SRC_MAX		8
158a2388a49SNicolin Chen 
1599c6344b3SNicolin Chen #define STC_TXCLK_SPDIF_ROOT		1
1609c6344b3SNicolin Chen 
161a2388a49SNicolin Chen /* SPDIF tx rate */
162a2388a49SNicolin Chen enum spdif_txrate {
163a2388a49SNicolin Chen 	SPDIF_TXRATE_32000 = 0,
164a2388a49SNicolin Chen 	SPDIF_TXRATE_44100,
165a2388a49SNicolin Chen 	SPDIF_TXRATE_48000,
166*1bfa3eaaSShengjiu Wang 	SPDIF_TXRATE_88200,
167c7dfeed1SAnssi Hannula 	SPDIF_TXRATE_96000,
168*1bfa3eaaSShengjiu Wang 	SPDIF_TXRATE_176400,
169c7dfeed1SAnssi Hannula 	SPDIF_TXRATE_192000,
170a2388a49SNicolin Chen };
171c7dfeed1SAnssi Hannula #define SPDIF_TXRATE_MAX		(SPDIF_TXRATE_192000 + 1)
172a2388a49SNicolin Chen 
173a2388a49SNicolin Chen 
174a2388a49SNicolin Chen #define SPDIF_CSTATUS_BYTE		6
175a2388a49SNicolin Chen #define SPDIF_UBITS_SIZE		96
176a2388a49SNicolin Chen #define SPDIF_QSUB_SIZE			(SPDIF_UBITS_SIZE / 8)
177a2388a49SNicolin Chen 
178a2388a49SNicolin Chen 
179a2388a49SNicolin Chen #define FSL_SPDIF_RATES_PLAYBACK	(SNDRV_PCM_RATE_32000 |	\
180a2388a49SNicolin Chen 					 SNDRV_PCM_RATE_44100 |	\
181c7dfeed1SAnssi Hannula 					 SNDRV_PCM_RATE_48000 |	\
182*1bfa3eaaSShengjiu Wang 					 SNDRV_PCM_RATE_88200 | \
183c7dfeed1SAnssi Hannula 					 SNDRV_PCM_RATE_96000 |	\
184*1bfa3eaaSShengjiu Wang 					 SNDRV_PCM_RATE_176400 | \
185c7dfeed1SAnssi Hannula 					 SNDRV_PCM_RATE_192000)
186a2388a49SNicolin Chen 
187a2388a49SNicolin Chen #define FSL_SPDIF_RATES_CAPTURE		(SNDRV_PCM_RATE_16000 | \
188a2388a49SNicolin Chen 					 SNDRV_PCM_RATE_32000 |	\
189a2388a49SNicolin Chen 					 SNDRV_PCM_RATE_44100 | \
190a2388a49SNicolin Chen 					 SNDRV_PCM_RATE_48000 |	\
191*1bfa3eaaSShengjiu Wang 					 SNDRV_PCM_RATE_88200 | \
192a2388a49SNicolin Chen 					 SNDRV_PCM_RATE_64000 | \
193*1bfa3eaaSShengjiu Wang 					 SNDRV_PCM_RATE_96000 | \
194*1bfa3eaaSShengjiu Wang 					 SNDRV_PCM_RATE_176400 | \
195*1bfa3eaaSShengjiu Wang 					 SNDRV_PCM_RATE_192000)
196a2388a49SNicolin Chen 
197a2388a49SNicolin Chen #define FSL_SPDIF_FORMATS_PLAYBACK	(SNDRV_PCM_FMTBIT_S16_LE | \
198a2388a49SNicolin Chen 					 SNDRV_PCM_FMTBIT_S20_3LE | \
199a2388a49SNicolin Chen 					 SNDRV_PCM_FMTBIT_S24_LE)
200a2388a49SNicolin Chen 
201a2388a49SNicolin Chen #define FSL_SPDIF_FORMATS_CAPTURE	(SNDRV_PCM_FMTBIT_S24_LE)
202a2388a49SNicolin Chen 
203a2388a49SNicolin Chen #endif /* _FSL_SPDIF_DAI_H */
204