18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * fsl_spdif.h - ALSA S/PDIF interface for the Freescale i.MX SoC
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2013 Freescale Semiconductor, Inc.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Nicolin Chen <b42378@freescale.com>
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Based on fsl_ssi.h
108c2ecf20Sopenharmony_ci * Author: Timur Tabi <timur@freescale.com>
118c2ecf20Sopenharmony_ci * Copyright 2007-2008 Freescale Semiconductor, Inc.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef _FSL_SPDIF_DAI_H
158c2ecf20Sopenharmony_ci#define _FSL_SPDIF_DAI_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/* S/PDIF Register Map */
188c2ecf20Sopenharmony_ci#define REG_SPDIF_SCR 			0x0	/* SPDIF Configuration Register */
198c2ecf20Sopenharmony_ci#define REG_SPDIF_SRCD		 	0x4	/* CDText Control Register */
208c2ecf20Sopenharmony_ci#define REG_SPDIF_SRPC			0x8	/* PhaseConfig Register */
218c2ecf20Sopenharmony_ci#define REG_SPDIF_SIE			0xc	/* InterruptEn Register */
228c2ecf20Sopenharmony_ci#define REG_SPDIF_SIS			0x10	/* InterruptStat Register */
238c2ecf20Sopenharmony_ci#define REG_SPDIF_SIC			0x10	/* InterruptClear Register */
248c2ecf20Sopenharmony_ci#define REG_SPDIF_SRL			0x14	/* SPDIFRxLeft Register */
258c2ecf20Sopenharmony_ci#define REG_SPDIF_SRR			0x18	/* SPDIFRxRight Register */
268c2ecf20Sopenharmony_ci#define REG_SPDIF_SRCSH			0x1c	/* SPDIFRxCChannel_h Register */
278c2ecf20Sopenharmony_ci#define REG_SPDIF_SRCSL			0x20	/* SPDIFRxCChannel_l Register */
288c2ecf20Sopenharmony_ci#define REG_SPDIF_SRU			0x24	/* UchannelRx Register */
298c2ecf20Sopenharmony_ci#define REG_SPDIF_SRQ			0x28	/* QchannelRx Register */
308c2ecf20Sopenharmony_ci#define REG_SPDIF_STL			0x2C	/* SPDIFTxLeft Register */
318c2ecf20Sopenharmony_ci#define REG_SPDIF_STR			0x30	/* SPDIFTxRight Register */
328c2ecf20Sopenharmony_ci#define REG_SPDIF_STCSCH		0x34	/* SPDIFTxCChannelCons_h Register */
338c2ecf20Sopenharmony_ci#define REG_SPDIF_STCSCL		0x38	/* SPDIFTxCChannelCons_l Register */
348c2ecf20Sopenharmony_ci#define REG_SPDIF_SRFM			0x44	/* FreqMeas Register */
358c2ecf20Sopenharmony_ci#define REG_SPDIF_STC			0x50	/* SPDIFTxClk Register */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* SPDIF Configuration register */
398c2ecf20Sopenharmony_ci#define SCR_RXFIFO_CTL_OFFSET		23
408c2ecf20Sopenharmony_ci#define SCR_RXFIFO_CTL_MASK		(1 << SCR_RXFIFO_CTL_OFFSET)
418c2ecf20Sopenharmony_ci#define SCR_RXFIFO_CTL_ZERO		(1 << SCR_RXFIFO_CTL_OFFSET)
428c2ecf20Sopenharmony_ci#define SCR_RXFIFO_OFF_OFFSET		22
438c2ecf20Sopenharmony_ci#define SCR_RXFIFO_OFF_MASK		(1 << SCR_RXFIFO_OFF_OFFSET)
448c2ecf20Sopenharmony_ci#define SCR_RXFIFO_OFF			(1 << SCR_RXFIFO_OFF_OFFSET)
458c2ecf20Sopenharmony_ci#define SCR_RXFIFO_RST_OFFSET		21
468c2ecf20Sopenharmony_ci#define SCR_RXFIFO_RST_MASK		(1 << SCR_RXFIFO_RST_OFFSET)
478c2ecf20Sopenharmony_ci#define SCR_RXFIFO_RST			(1 << SCR_RXFIFO_RST_OFFSET)
488c2ecf20Sopenharmony_ci#define SCR_RXFIFO_FSEL_OFFSET		19
498c2ecf20Sopenharmony_ci#define SCR_RXFIFO_FSEL_MASK		(0x3 << SCR_RXFIFO_FSEL_OFFSET)
508c2ecf20Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF0		(0x0 << SCR_RXFIFO_FSEL_OFFSET)
518c2ecf20Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF4		(0x1 << SCR_RXFIFO_FSEL_OFFSET)
528c2ecf20Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF8		(0x2 << SCR_RXFIFO_FSEL_OFFSET)
538c2ecf20Sopenharmony_ci#define SCR_RXFIFO_FSEL_IF12		(0x3 << SCR_RXFIFO_FSEL_OFFSET)
548c2ecf20Sopenharmony_ci#define SCR_RXFIFO_AUTOSYNC_OFFSET	18
558c2ecf20Sopenharmony_ci#define SCR_RXFIFO_AUTOSYNC_MASK	(1 << SCR_RXFIFO_AUTOSYNC_OFFSET)
568c2ecf20Sopenharmony_ci#define SCR_RXFIFO_AUTOSYNC		(1 << SCR_RXFIFO_AUTOSYNC_OFFSET)
578c2ecf20Sopenharmony_ci#define SCR_TXFIFO_AUTOSYNC_OFFSET	17
588c2ecf20Sopenharmony_ci#define SCR_TXFIFO_AUTOSYNC_MASK	(1 << SCR_TXFIFO_AUTOSYNC_OFFSET)
598c2ecf20Sopenharmony_ci#define SCR_TXFIFO_AUTOSYNC		(1 << SCR_TXFIFO_AUTOSYNC_OFFSET)
608c2ecf20Sopenharmony_ci#define SCR_TXFIFO_FSEL_OFFSET		15
618c2ecf20Sopenharmony_ci#define SCR_TXFIFO_FSEL_MASK		(0x3 << SCR_TXFIFO_FSEL_OFFSET)
628c2ecf20Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF0		(0x0 << SCR_TXFIFO_FSEL_OFFSET)
638c2ecf20Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF4		(0x1 << SCR_TXFIFO_FSEL_OFFSET)
648c2ecf20Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF8		(0x2 << SCR_TXFIFO_FSEL_OFFSET)
658c2ecf20Sopenharmony_ci#define SCR_TXFIFO_FSEL_IF12		(0x3 << SCR_TXFIFO_FSEL_OFFSET)
668c2ecf20Sopenharmony_ci#define SCR_LOW_POWER			(1 << 13)
678c2ecf20Sopenharmony_ci#define SCR_SOFT_RESET			(1 << 12)
688c2ecf20Sopenharmony_ci#define SCR_TXFIFO_CTRL_OFFSET		10
698c2ecf20Sopenharmony_ci#define SCR_TXFIFO_CTRL_MASK		(0x3 << SCR_TXFIFO_CTRL_OFFSET)
708c2ecf20Sopenharmony_ci#define SCR_TXFIFO_CTRL_ZERO		(0x0 << SCR_TXFIFO_CTRL_OFFSET)
718c2ecf20Sopenharmony_ci#define SCR_TXFIFO_CTRL_NORMAL		(0x1 << SCR_TXFIFO_CTRL_OFFSET)
728c2ecf20Sopenharmony_ci#define SCR_TXFIFO_CTRL_ONESAMPLE	(0x2 << SCR_TXFIFO_CTRL_OFFSET)
738c2ecf20Sopenharmony_ci#define SCR_DMA_RX_EN_OFFSET		9
748c2ecf20Sopenharmony_ci#define SCR_DMA_RX_EN_MASK		(1 << SCR_DMA_RX_EN_OFFSET)
758c2ecf20Sopenharmony_ci#define SCR_DMA_RX_EN			(1 << SCR_DMA_RX_EN_OFFSET)
768c2ecf20Sopenharmony_ci#define SCR_DMA_TX_EN_OFFSET		8
778c2ecf20Sopenharmony_ci#define SCR_DMA_TX_EN_MASK		(1 << SCR_DMA_TX_EN_OFFSET)
788c2ecf20Sopenharmony_ci#define SCR_DMA_TX_EN			(1 << SCR_DMA_TX_EN_OFFSET)
798c2ecf20Sopenharmony_ci#define SCR_VAL_OFFSET			5
808c2ecf20Sopenharmony_ci#define SCR_VAL_MASK			(1 << SCR_VAL_OFFSET)
818c2ecf20Sopenharmony_ci#define SCR_VAL_CLEAR			(1 << SCR_VAL_OFFSET)
828c2ecf20Sopenharmony_ci#define SCR_TXSEL_OFFSET		2
838c2ecf20Sopenharmony_ci#define SCR_TXSEL_MASK			(0x7 << SCR_TXSEL_OFFSET)
848c2ecf20Sopenharmony_ci#define SCR_TXSEL_OFF			(0 << SCR_TXSEL_OFFSET)
858c2ecf20Sopenharmony_ci#define SCR_TXSEL_RX			(1 << SCR_TXSEL_OFFSET)
868c2ecf20Sopenharmony_ci#define SCR_TXSEL_NORMAL		(0x5 << SCR_TXSEL_OFFSET)
878c2ecf20Sopenharmony_ci#define SCR_USRC_SEL_OFFSET		0x0
888c2ecf20Sopenharmony_ci#define SCR_USRC_SEL_MASK		(0x3 << SCR_USRC_SEL_OFFSET)
898c2ecf20Sopenharmony_ci#define SCR_USRC_SEL_NONE		(0x0 << SCR_USRC_SEL_OFFSET)
908c2ecf20Sopenharmony_ci#define SCR_USRC_SEL_RECV		(0x1 << SCR_USRC_SEL_OFFSET)
918c2ecf20Sopenharmony_ci#define SCR_USRC_SEL_CHIP		(0x3 << SCR_USRC_SEL_OFFSET)
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define SCR_DMA_xX_EN(tx)		(tx ? SCR_DMA_TX_EN : SCR_DMA_RX_EN)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci/* SPDIF CDText control */
968c2ecf20Sopenharmony_ci#define SRCD_CD_USER_OFFSET		1
978c2ecf20Sopenharmony_ci#define SRCD_CD_USER			(1 << SRCD_CD_USER_OFFSET)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci/* SPDIF Phase Configuration register */
1008c2ecf20Sopenharmony_ci#define SRPC_DPLL_LOCKED		(1 << 6)
1018c2ecf20Sopenharmony_ci#define SRPC_CLKSRC_SEL_OFFSET		7
1028c2ecf20Sopenharmony_ci#define SRPC_CLKSRC_SEL_MASK		(0xf << SRPC_CLKSRC_SEL_OFFSET)
1038c2ecf20Sopenharmony_ci#define SRPC_CLKSRC_SEL_SET(x)		((x << SRPC_CLKSRC_SEL_OFFSET) & SRPC_CLKSRC_SEL_MASK)
1048c2ecf20Sopenharmony_ci#define SRPC_CLKSRC_SEL_LOCKED_OFFSET1	5
1058c2ecf20Sopenharmony_ci#define SRPC_CLKSRC_SEL_LOCKED_OFFSET2	2
1068c2ecf20Sopenharmony_ci#define SRPC_GAINSEL_OFFSET		3
1078c2ecf20Sopenharmony_ci#define SRPC_GAINSEL_MASK		(0x7 << SRPC_GAINSEL_OFFSET)
1088c2ecf20Sopenharmony_ci#define SRPC_GAINSEL_SET(x)		((x << SRPC_GAINSEL_OFFSET) & SRPC_GAINSEL_MASK)
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define SRPC_CLKSRC_MAX			16
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cienum spdif_gainsel {
1138c2ecf20Sopenharmony_ci	GAINSEL_MULTI_24 = 0,
1148c2ecf20Sopenharmony_ci	GAINSEL_MULTI_16,
1158c2ecf20Sopenharmony_ci	GAINSEL_MULTI_12,
1168c2ecf20Sopenharmony_ci	GAINSEL_MULTI_8,
1178c2ecf20Sopenharmony_ci	GAINSEL_MULTI_6,
1188c2ecf20Sopenharmony_ci	GAINSEL_MULTI_4,
1198c2ecf20Sopenharmony_ci	GAINSEL_MULTI_3,
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci#define GAINSEL_MULTI_MAX		(GAINSEL_MULTI_3 + 1)
1228c2ecf20Sopenharmony_ci#define SPDIF_DEFAULT_GAINSEL		GAINSEL_MULTI_8
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/* SPDIF interrupt mask define */
1258c2ecf20Sopenharmony_ci#define INT_DPLL_LOCKED			(1 << 20)
1268c2ecf20Sopenharmony_ci#define INT_TXFIFO_UNOV			(1 << 19)
1278c2ecf20Sopenharmony_ci#define INT_TXFIFO_RESYNC		(1 << 18)
1288c2ecf20Sopenharmony_ci#define INT_CNEW			(1 << 17)
1298c2ecf20Sopenharmony_ci#define INT_VAL_NOGOOD			(1 << 16)
1308c2ecf20Sopenharmony_ci#define INT_SYM_ERR			(1 << 15)
1318c2ecf20Sopenharmony_ci#define INT_BIT_ERR			(1 << 14)
1328c2ecf20Sopenharmony_ci#define INT_URX_FUL			(1 << 10)
1338c2ecf20Sopenharmony_ci#define INT_URX_OV			(1 << 9)
1348c2ecf20Sopenharmony_ci#define INT_QRX_FUL			(1 << 8)
1358c2ecf20Sopenharmony_ci#define INT_QRX_OV			(1 << 7)
1368c2ecf20Sopenharmony_ci#define INT_UQ_SYNC			(1 << 6)
1378c2ecf20Sopenharmony_ci#define INT_UQ_ERR			(1 << 5)
1388c2ecf20Sopenharmony_ci#define INT_RXFIFO_UNOV			(1 << 4)
1398c2ecf20Sopenharmony_ci#define INT_RXFIFO_RESYNC		(1 << 3)
1408c2ecf20Sopenharmony_ci#define INT_LOSS_LOCK			(1 << 2)
1418c2ecf20Sopenharmony_ci#define INT_TX_EM			(1 << 1)
1428c2ecf20Sopenharmony_ci#define INT_RXFIFO_FUL			(1 << 0)
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci/* SPDIF Clock register */
1458c2ecf20Sopenharmony_ci#define STC_SYSCLK_DF_OFFSET		11
1468c2ecf20Sopenharmony_ci#define STC_SYSCLK_DF_MASK		(0x1ff << STC_SYSCLK_DF_OFFSET)
1478c2ecf20Sopenharmony_ci#define STC_SYSCLK_DF(x)		((((x) - 1) << STC_SYSCLK_DF_OFFSET) & STC_SYSCLK_DF_MASK)
1488c2ecf20Sopenharmony_ci#define STC_TXCLK_SRC_OFFSET		8
1498c2ecf20Sopenharmony_ci#define STC_TXCLK_SRC_MASK		(0x7 << STC_TXCLK_SRC_OFFSET)
1508c2ecf20Sopenharmony_ci#define STC_TXCLK_SRC_SET(x)		((x << STC_TXCLK_SRC_OFFSET) & STC_TXCLK_SRC_MASK)
1518c2ecf20Sopenharmony_ci#define STC_TXCLK_ALL_EN_OFFSET		7
1528c2ecf20Sopenharmony_ci#define STC_TXCLK_ALL_EN_MASK		(1 << STC_TXCLK_ALL_EN_OFFSET)
1538c2ecf20Sopenharmony_ci#define STC_TXCLK_ALL_EN		(1 << STC_TXCLK_ALL_EN_OFFSET)
1548c2ecf20Sopenharmony_ci#define STC_TXCLK_DF_OFFSET		0
1558c2ecf20Sopenharmony_ci#define STC_TXCLK_DF_MASK		(0x7f << STC_TXCLK_DF_OFFSET)
1568c2ecf20Sopenharmony_ci#define STC_TXCLK_DF(x)		((((x) - 1) << STC_TXCLK_DF_OFFSET) & STC_TXCLK_DF_MASK)
1578c2ecf20Sopenharmony_ci#define STC_TXCLK_SRC_MAX		8
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci#define STC_TXCLK_SPDIF_ROOT		1
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci/* SPDIF tx rate */
1628c2ecf20Sopenharmony_cienum spdif_txrate {
1638c2ecf20Sopenharmony_ci	SPDIF_TXRATE_32000 = 0,
1648c2ecf20Sopenharmony_ci	SPDIF_TXRATE_44100,
1658c2ecf20Sopenharmony_ci	SPDIF_TXRATE_48000,
1668c2ecf20Sopenharmony_ci	SPDIF_TXRATE_96000,
1678c2ecf20Sopenharmony_ci	SPDIF_TXRATE_192000,
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci#define SPDIF_TXRATE_MAX		(SPDIF_TXRATE_192000 + 1)
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#define SPDIF_CSTATUS_BYTE		6
1738c2ecf20Sopenharmony_ci#define SPDIF_UBITS_SIZE		96
1748c2ecf20Sopenharmony_ci#define SPDIF_QSUB_SIZE			(SPDIF_UBITS_SIZE / 8)
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#define FSL_SPDIF_RATES_PLAYBACK	(SNDRV_PCM_RATE_32000 |	\
1788c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_44100 |	\
1798c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_48000 |	\
1808c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_96000 |	\
1818c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_192000)
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci#define FSL_SPDIF_RATES_CAPTURE		(SNDRV_PCM_RATE_16000 | \
1848c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_32000 |	\
1858c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_44100 | \
1868c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_48000 |	\
1878c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_64000 | \
1888c2ecf20Sopenharmony_ci					 SNDRV_PCM_RATE_96000)
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#define FSL_SPDIF_FORMATS_PLAYBACK	(SNDRV_PCM_FMTBIT_S16_LE | \
1918c2ecf20Sopenharmony_ci					 SNDRV_PCM_FMTBIT_S20_3LE | \
1928c2ecf20Sopenharmony_ci					 SNDRV_PCM_FMTBIT_S24_LE)
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci#define FSL_SPDIF_FORMATS_CAPTURE	(SNDRV_PCM_FMTBIT_S24_LE)
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ci#endif /* _FSL_SPDIF_DAI_H */
197